| 41 /* |
41 /* |
| 42 #include <gtk/gtktreeprivate.h> |
42 #include <gtk/gtktreeprivate.h> |
| 43 */ |
43 */ |
| 44 #include <gtk/gtkvseparator.h> |
44 #include <gtk/gtkvseparator.h> |
| 45 #include <gtk/gtkwindow.h> |
45 #include <gtk/gtkwindow.h> |
| |
46 #include <gtk/gtkversion.h> |
| 46 |
47 |
| 47 #include <gdk/gdkkeysyms.h> |
48 #include <gdk/gdkkeysyms.h> |
| 48 |
49 |
| 49 #include <gobject/gvaluecollector.h> |
50 #include <gobject/gvaluecollector.h> |
| 50 |
51 |
| 231 static void gtk_combo_box_menu_hide (GtkWidget *menu, |
232 static void gtk_combo_box_menu_hide (GtkWidget *menu, |
| 232 gpointer user_data); |
233 gpointer user_data); |
| 233 |
234 |
| 234 static void gtk_combo_box_set_popup_widget (GtkComboBox *combo_box, |
235 static void gtk_combo_box_set_popup_widget (GtkComboBox *combo_box, |
| 235 GtkWidget *popup); |
236 GtkWidget *popup); |
| |
237 #if GTK_CHECK_VERSION(2,2,0) |
| 236 static void gtk_combo_box_menu_position_below (GtkMenu *menu, |
238 static void gtk_combo_box_menu_position_below (GtkMenu *menu, |
| 237 gint *x, |
239 gint *x, |
| 238 gint *y, |
240 gint *y, |
| 239 gint *push_in, |
241 gint *push_in, |
| 240 gpointer user_data); |
242 gpointer user_data); |
| 290 GtkTreePath *path, |
293 GtkTreePath *path, |
| 291 GtkTreeIter *iter, |
294 GtkTreeIter *iter, |
| 292 gpointer data); |
295 gpointer data); |
| 293 |
296 |
| 294 /* list */ |
297 /* list */ |
| |
298 #if GTK_CHECK_VERSION(2,2,0) |
| 295 static void gtk_combo_box_list_position (GtkComboBox *combo_box, |
299 static void gtk_combo_box_list_position (GtkComboBox *combo_box, |
| 296 gint *x, |
300 gint *x, |
| 297 gint *y, |
301 gint *y, |
| 298 gint *width, |
302 gint *width, |
| 299 gint *height); |
303 gint *height); |
| |
304 #endif |
| 300 static void gtk_combo_box_list_setup (GtkComboBox *combo_box); |
305 static void gtk_combo_box_list_setup (GtkComboBox *combo_box); |
| 301 static void gtk_combo_box_list_destroy (GtkComboBox *combo_box); |
306 static void gtk_combo_box_list_destroy (GtkComboBox *combo_box); |
| 302 |
307 |
| 303 static void gtk_combo_box_list_remove_grabs (GtkComboBox *combo_box); |
308 static void gtk_combo_box_list_remove_grabs (GtkComboBox *combo_box); |
| 304 |
309 |
| 907 { |
912 { |
| 908 if (!combo_box->priv->popup_window) |
913 if (!combo_box->priv->popup_window) |
| 909 { |
914 { |
| 910 combo_box->priv->popup_window = gtk_window_new (GTK_WINDOW_POPUP); |
915 combo_box->priv->popup_window = gtk_window_new (GTK_WINDOW_POPUP); |
| 911 gtk_window_set_resizable (GTK_WINDOW (combo_box->priv->popup_window), FALSE); |
916 gtk_window_set_resizable (GTK_WINDOW (combo_box->priv->popup_window), FALSE); |
| |
917 #if GTK_CHECK_VERSION(2,2,0) |
| 912 gtk_window_set_screen (GTK_WINDOW (combo_box->priv->popup_window), |
918 gtk_window_set_screen (GTK_WINDOW (combo_box->priv->popup_window), |
| 913 gtk_widget_get_screen (GTK_WIDGET (combo_box))); |
919 gtk_widget_get_screen (GTK_WIDGET (combo_box))); |
| |
920 #endif |
| 914 |
921 |
| 915 combo_box->priv->popup_frame = gtk_frame_new (NULL); |
922 combo_box->priv->popup_frame = gtk_frame_new (NULL); |
| 916 gtk_frame_set_shadow_type (GTK_FRAME (combo_box->priv->popup_frame), |
923 gtk_frame_set_shadow_type (GTK_FRAME (combo_box->priv->popup_frame), |
| 917 GTK_SHADOW_ETCHED_IN); |
924 GTK_SHADOW_ETCHED_IN); |
| 918 gtk_container_add (GTK_CONTAINER (combo_box->priv->popup_window), |
925 gtk_container_add (GTK_CONTAINER (combo_box->priv->popup_window), |
| 1146 * Since: 2.4 |
1155 * Since: 2.4 |
| 1147 **/ |
1156 **/ |
| 1148 void |
1157 void |
| 1149 gtk_combo_box_popup (GtkComboBox *combo_box) |
1158 gtk_combo_box_popup (GtkComboBox *combo_box) |
| 1150 { |
1159 { |
| 1151 gint x, y, width, height; |
1160 gint x, y, width; |
| |
1161 #if GTK_CHECK_VERSION(2,2,0) |
| |
1162 gint height; |
| |
1163 #endif |
| 1152 |
1164 |
| 1153 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box)); |
1165 g_return_if_fail (GTK_IS_COMBO_BOX (combo_box)); |
| 1154 |
1166 |
| 1155 if (GTK_WIDGET_MAPPED (combo_box->priv->popup_widget)) |
1167 if (GTK_WIDGET_MAPPED (combo_box->priv->popup_widget)) |
| 1156 return; |
1168 return; |
| 1171 MAX (width, requisition.width), -1); |
1183 MAX (width, requisition.width), -1); |
| 1172 } |
1184 } |
| 1173 |
1185 |
| 1174 gtk_menu_popup (GTK_MENU (combo_box->priv->popup_widget), |
1186 gtk_menu_popup (GTK_MENU (combo_box->priv->popup_widget), |
| 1175 NULL, NULL, |
1187 NULL, NULL, |
| 1176 gtk_combo_box_menu_position, combo_box, |
1188 #if GTK_CHECK_VERSION(2,2,0) |
| 1177 0, 0); |
1189 gtk_combo_box_menu_position, |
| |
1190 #else |
| |
1191 NULL, |
| |
1192 #endif |
| |
1193 combo_box, 0, 0); |
| 1178 return; |
1194 return; |
| 1179 } |
1195 } |
| 1180 |
1196 |
| 1181 gtk_widget_show_all (combo_box->priv->popup_frame); |
1197 gtk_widget_show_all (combo_box->priv->popup_frame); |
| |
1198 #if GTK_CHECK_VERSION(2,2,0) |
| 1182 gtk_combo_box_list_position (combo_box, &x, &y, &width, &height); |
1199 gtk_combo_box_list_position (combo_box, &x, &y, &width, &height); |
| |
1200 #endif |
| 1183 |
1201 |
| 1184 gtk_widget_set_size_request (combo_box->priv->popup_window, width, -1); |
1202 gtk_widget_set_size_request (combo_box->priv->popup_window, width, -1); |
| 1185 gtk_window_move (GTK_WINDOW (combo_box->priv->popup_window), x, y); |
1203 gtk_window_move (GTK_WINDOW (combo_box->priv->popup_window), x, y); |
| 1186 |
1204 |
| 1187 /* popup */ |
1205 /* popup */ |
| 1276 !gtk_tree_model_get_iter_first (combo_box->priv->model, &iter)) |
1294 !gtk_tree_model_get_iter_first (combo_box->priv->model, &iter)) |
| 1277 return; |
1295 return; |
| 1278 |
1296 |
| 1279 combo_box->priv->width = 0; |
1297 combo_box->priv->width = 0; |
| 1280 |
1298 |
| |
1299 #if GTK_CHECK_VERSION(2,2,0) |
| 1281 path = gtk_tree_path_new_from_indices (0, -1); |
1300 path = gtk_tree_path_new_from_indices (0, -1); |
| |
1301 #else |
| |
1302 path = gtk_tree_path_new_first(); |
| |
1303 #endif |
| 1282 |
1304 |
| 1283 if (combo_box->priv->cell_view) |
1305 if (combo_box->priv->cell_view) |
| 1284 gtk_widget_style_get (combo_box->priv->cell_view, |
1306 gtk_widget_style_get (combo_box->priv->cell_view, |
| 1285 "focus-line-width", &padding, |
1307 "focus-line-width", &padding, |
| 1286 NULL); |
1308 NULL); |
| 1743 menu = combo_box->priv->popup_widget; |
1765 menu = combo_box->priv->popup_widget; |
| 1744 |
1766 |
| 1745 for (i = 0; i < items; i++) |
1767 for (i = 0; i < items; i++) |
| 1746 { |
1768 { |
| 1747 GtkTreePath *path; |
1769 GtkTreePath *path; |
| 1748 |
1770 #if GTK_CHECK_VERSION(2,2,0) |
| 1749 path = gtk_tree_path_new_from_indices (i, -1); |
1771 path = gtk_tree_path_new_from_indices (i, -1); |
| |
1772 #else |
| |
1773 char buf[32]; |
| |
1774 g_snprintf(buf, sizeof(buf), "%d", i); |
| |
1775 path = gtk_tree_path_new_from_string(buf); |
| |
1776 #endif |
| 1750 tmp = gtk_cell_view_menu_item_new_from_model (combo_box->priv->model, |
1777 tmp = gtk_cell_view_menu_item_new_from_model (combo_box->priv->model, |
| 1751 path); |
1778 path); |
| 1752 g_signal_connect (tmp, "activate", |
1779 g_signal_connect (tmp, "activate", |
| 1753 G_CALLBACK (gtk_combo_box_menu_item_activate), |
1780 G_CALLBACK (gtk_combo_box_menu_item_activate), |
| 1754 combo_box); |
1781 combo_box); |
| 1981 MAX (width, requisition.width), -1); |
2008 MAX (width, requisition.width), -1); |
| 1982 } |
2009 } |
| 1983 |
2010 |
| 1984 gtk_menu_popup (GTK_MENU (combo_box->priv->popup_widget), |
2011 gtk_menu_popup (GTK_MENU (combo_box->priv->popup_widget), |
| 1985 NULL, NULL, |
2012 NULL, NULL, |
| 1986 gtk_combo_box_menu_position, combo_box, |
2013 #if GTK_CHECK_VERSION(2,2,0) |
| 1987 event->button, event->time); |
2014 gtk_combo_box_menu_position, |
| |
2015 #else |
| |
2016 NULL, |
| |
2017 #endif |
| |
2018 combo_box, event->button, event->time); |
| 1988 |
2019 |
| 1989 return TRUE; |
2020 return TRUE; |
| 1990 } |
2021 } |
| 1991 |
2022 |
| 1992 return FALSE; |
2023 return FALSE; |
| 2289 |
2320 |
| 2290 if (combo_box->priv->active_item != -1) |
2321 if (combo_box->priv->active_item != -1) |
| 2291 { |
2322 { |
| 2292 GtkTreePath *path; |
2323 GtkTreePath *path; |
| 2293 |
2324 |
| |
2325 #if GTK_CHECK_VERSION(2,2,0) |
| 2294 path = gtk_tree_path_new_from_indices (combo_box->priv->active_item, -1); |
2326 path = gtk_tree_path_new_from_indices (combo_box->priv->active_item, -1); |
| |
2327 #else |
| |
2328 char buf[32]; |
| |
2329 g_snprintf(buf, sizeof(buf), "%d", combo_box->priv->active_item); |
| |
2330 path = gtk_tree_path_new_from_string(buf); |
| |
2331 #endif |
| 2295 if (path) |
2332 if (path) |
| 2296 { |
2333 { |
| 2297 gtk_tree_view_set_cursor (GTK_TREE_VIEW (combo_box->priv->tree_view), |
2334 gtk_tree_view_set_cursor (GTK_TREE_VIEW (combo_box->priv->tree_view), |
| 2298 path, NULL, FALSE); |
2335 path, NULL, FALSE); |
| 2299 gtk_tree_path_free (path); |
2336 gtk_tree_path_free (path); |
| 3193 if (combo_box->priv->cell_view) |
3230 if (combo_box->priv->cell_view) |
| 3194 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (combo_box->priv->cell_view), NULL); |
3231 gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (combo_box->priv->cell_view), NULL); |
| 3195 } |
3232 } |
| 3196 else |
3233 else |
| 3197 { |
3234 { |
| |
3235 #if GTK_CHECK_VERSION(2,2,0) |
| 3198 path = gtk_tree_path_new_from_indices (index, -1); |
3236 path = gtk_tree_path_new_from_indices (index, -1); |
| |
3237 #else |
| |
3238 char buf[32]; |
| |
3239 g_snprintf(buf, sizeof(buf), "%d", index); |
| |
3240 path = gtk_tree_path_new_from_string(buf); |
| |
3241 #endif |
| 3199 |
3242 |
| 3200 if (combo_box->priv->tree_view) |
3243 if (combo_box->priv->tree_view) |
| 3201 gtk_tree_view_set_cursor (GTK_TREE_VIEW (combo_box->priv->tree_view), path, NULL, FALSE); |
3244 gtk_tree_view_set_cursor (GTK_TREE_VIEW (combo_box->priv->tree_view), path, NULL, FALSE); |
| 3202 else |
3245 else |
| 3203 { |
3246 { |
| 3233 GtkTreeIter *iter) |
3276 GtkTreeIter *iter) |
| 3234 { |
3277 { |
| 3235 GtkTreePath *path; |
3278 GtkTreePath *path; |
| 3236 gint active; |
3279 gint active; |
| 3237 gboolean retval; |
3280 gboolean retval; |
| |
3281 #if !GTK_CHECK_VERSION(2,2,0) |
| |
3282 char buf[32]; |
| |
3283 #endif |
| 3238 |
3284 |
| 3239 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), FALSE); |
3285 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), FALSE); |
| 3240 |
3286 |
| 3241 active = gtk_combo_box_get_active (combo_box); |
3287 active = gtk_combo_box_get_active (combo_box); |
| 3242 if (active < 0) |
3288 if (active < 0) |
| 3243 return FALSE; |
3289 return FALSE; |
| 3244 |
3290 |
| |
3291 #if GTK_CHECK_VERSION(2,2,0) |
| 3245 path = gtk_tree_path_new_from_indices (active, -1); |
3292 path = gtk_tree_path_new_from_indices (active, -1); |
| |
3293 #else |
| |
3294 g_snprintf(buf, sizeof(buf), "%d", active); |
| |
3295 path = gtk_tree_path_new_from_string(buf); |
| |
3296 #endif |
| 3246 retval = gtk_tree_model_get_iter (gtk_combo_box_get_model (combo_box), |
3297 retval = gtk_tree_model_get_iter (gtk_combo_box_get_model (combo_box), |
| 3247 iter, path); |
3298 iter, path); |
| 3248 gtk_tree_path_free (path); |
3299 gtk_tree_path_free (path); |
| 3249 |
3300 |
| 3250 return retval; |
3301 return retval; |