comparison gtk3/dw.c @ 779:d67d2f626c33

More code and cleanups for listboxes/combobox and event handling... Fixed the ok and cancel buttons on the color chooser.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sun, 20 Mar 2011 23:40:34 +0000
parents 99ce0ea1f271
children fda93b441c4d
comparison
equal deleted inserted replaced
778:99ce0ea1f271 779:d67d2f626c33
140 140
141 #define DEFAULT_SIZE_WIDTH 12 141 #define DEFAULT_SIZE_WIDTH 12
142 #define DEFAULT_SIZE_HEIGHT 6 142 #define DEFAULT_SIZE_HEIGHT 6
143 #define DEFAULT_TITLEBAR_HEIGHT 22 143 #define DEFAULT_TITLEBAR_HEIGHT 22
144 144
145 static GdkVisual *_dw_cmap = NULL;
146
147 /* Signal forwarder prototypes */ 145 /* Signal forwarder prototypes */
148 static gint _button_press_event(GtkWidget *widget, GdkEventButton *event, gpointer data); 146 static gint _button_press_event(GtkWidget *widget, GdkEventButton *event, gpointer data);
149 static gint _button_release_event(GtkWidget *widget, GdkEventButton *event, gpointer data); 147 static gint _button_release_event(GtkWidget *widget, GdkEventButton *event, gpointer data);
150 static gint _motion_notify_event(GtkWidget *widget, GdkEventMotion *event, gpointer data); 148 static gint _motion_notify_event(GtkWidget *widget, GdkEventMotion *event, gpointer data);
151 static gint _delete_event(GtkWidget *widget, GdkEvent *event, gpointer data); 149 static gint _delete_event(GtkWidget *widget, GdkEvent *event, gpointer data);
152 static gint _key_press_event(GtkWidget *widget, GdkEventKey *event, gpointer data); 150 static gint _key_press_event(GtkWidget *widget, GdkEventKey *event, gpointer data);
153 static gint _generic_event(GtkWidget *widget, gpointer data); 151 static gint _generic_event(GtkWidget *widget, gpointer data);
154 static gint _configure_event(GtkWidget *widget, GdkEventConfigure *event, gpointer data); 152 static gint _configure_event(GtkWidget *widget, GdkEventConfigure *event, gpointer data);
155 static gint _activate_event(GtkWidget *widget, gpointer data); 153 static gint _activate_event(GtkWidget *widget, gpointer data);
156 static gint _container_select_event(GtkWidget *widget, GdkEventButton *event, gpointer data); 154 static gint _container_select_event(GtkWidget *widget, GdkEventButton *event, gpointer data);
157 static gint _container_context_event(GtkWidget *widget, GdkEventButton *event, gpointer data);
158 static gint _item_select_event(GtkWidget *widget, GtkWidget *child, gpointer data); 155 static gint _item_select_event(GtkWidget *widget, GtkWidget *child, gpointer data);
159 static gint _expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data); 156 static gint _expose_event(GtkWidget *widget, cairo_t *cr, gpointer data);
160 static gint _set_focus_event(GtkWindow *window, GtkWidget *widget, gpointer data); 157 static gint _set_focus_event(GtkWindow *window, GtkWidget *widget, gpointer data);
161 static gint _tree_context_event(GtkWidget *widget, GdkEventButton *event, gpointer data); 158 static gint _tree_context_event(GtkWidget *widget, GdkEventButton *event, gpointer data);
162 static gint _value_changed_event(GtkAdjustment *adjustment, gpointer user_data); 159 static gint _value_changed_event(GtkAdjustment *adjustment, gpointer user_data);
163 static gint _tree_select_event(GtkTreeSelection *sel, gpointer data); 160 static gint _tree_select_event(GtkTreeSelection *sel, gpointer data);
164 static gint _tree_expand_event(GtkTreeView *treeview, GtkTreeIter *arg1, GtkTreePath *arg2, gpointer data); 161 static gint _tree_expand_event(GtkTreeView *treeview, GtkTreeIter *arg1, GtkTreePath *arg2, gpointer data);
250 { _delete_event, DW_SIGNAL_DELETE }, 247 { _delete_event, DW_SIGNAL_DELETE },
251 { _expose_event, DW_SIGNAL_EXPOSE }, 248 { _expose_event, DW_SIGNAL_EXPOSE },
252 { _activate_event, "activate" }, 249 { _activate_event, "activate" },
253 { _generic_event, DW_SIGNAL_CLICKED }, 250 { _generic_event, DW_SIGNAL_CLICKED },
254 { _container_select_event, DW_SIGNAL_ITEM_ENTER }, 251 { _container_select_event, DW_SIGNAL_ITEM_ENTER },
255 { _container_context_event, DW_SIGNAL_ITEM_CONTEXT }, 252 { _tree_context_event, DW_SIGNAL_ITEM_CONTEXT },
256 { _tree_context_event, "tree-context" },
257 { _item_select_event, DW_SIGNAL_LIST_SELECT }, 253 { _item_select_event, DW_SIGNAL_LIST_SELECT },
258 { _tree_select_event, DW_SIGNAL_ITEM_SELECT }, 254 { _tree_select_event, DW_SIGNAL_ITEM_SELECT },
259 { _set_focus_event, DW_SIGNAL_SET_FOCUS }, 255 { _set_focus_event, DW_SIGNAL_SET_FOCUS },
260 { _value_changed_event, DW_SIGNAL_VALUE_CHANGED }, 256 { _value_changed_event, DW_SIGNAL_VALUE_CHANGED },
261 { _switch_page_event, DW_SIGNAL_SWITCH_PAGE }, 257 { _switch_page_event, DW_SIGNAL_SWITCH_PAGE },
334 330
335 static void gtk_mdi_class_init(GtkMdiClass *klass); 331 static void gtk_mdi_class_init(GtkMdiClass *klass);
336 static void gtk_mdi_init(GtkMdi *mdi); 332 static void gtk_mdi_init(GtkMdi *mdi);
337 333
338 static void gtk_mdi_realize(GtkWidget *widget); 334 static void gtk_mdi_realize(GtkWidget *widget);
335 static void gtk_mdi_size_allocate(GtkWidget *widget, GtkAllocation *allocation);
336 #if 0
339 static void gtk_mdi_size_request(GtkWidget *widget, GtkRequisition *requisition); 337 static void gtk_mdi_size_request(GtkWidget *widget, GtkRequisition *requisition);
340 static void gtk_mdi_size_allocate(GtkWidget *widget, GtkAllocation *allocation);
341 static gint gtk_mdi_expose(GtkWidget *widget, GdkEventExpose *event); 338 static gint gtk_mdi_expose(GtkWidget *widget, GdkEventExpose *event);
339 #endif
342 340
343 /* Callbacks */ 341 /* Callbacks */
344 static gboolean move_child_callback(GtkWidget *widget, GdkEvent *event, gpointer data); 342 static gboolean move_child_callback(GtkWidget *widget, GdkEvent *event, gpointer data);
345 static gboolean resize_child_callback(GtkWidget *widget, GdkEvent *event, gpointer data); 343 static gboolean resize_child_callback(GtkWidget *widget, GdkEvent *event, gpointer data);
346 static gboolean iconify_child_callback(GtkWidget *widget, GdkEvent *event, gpointer data); 344 static gboolean iconify_child_callback(GtkWidget *widget, GdkEvent *event, gpointer data);
745 gdk_window_set_user_data (gtk_widget_get_window(widget), widget); 743 gdk_window_set_user_data (gtk_widget_get_window(widget), widget);
746 744
747 gtk_style_set_background (gtk_widget_get_style(widget), gtk_widget_get_window(widget), GTK_STATE_NORMAL); 745 gtk_style_set_background (gtk_widget_get_style(widget), gtk_widget_get_window(widget), GTK_STATE_NORMAL);
748 } 746 }
749 747
748 #if 0
750 static void gtk_mdi_size_request (GtkWidget *widget, GtkRequisition *requisition) 749 static void gtk_mdi_size_request (GtkWidget *widget, GtkRequisition *requisition)
751 { 750 {
752 GtkMdi *mdi; 751 GtkMdi *mdi;
753 GtkMdiChild *child; 752 GtkMdiChild *child;
754 GList *children; 753 GList *children;
768 { 767 {
769 gtk_widget_size_request(child->widget, &child_requisition); 768 gtk_widget_size_request(child->widget, &child_requisition);
770 } 769 }
771 } 770 }
772 } 771 }
772 #endif
773 773
774 static void gtk_mdi_size_allocate(GtkWidget *widget, GtkAllocation *allocation) 774 static void gtk_mdi_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
775 { 775 {
776 GtkMdi *mdi; 776 GtkMdi *mdi;
777 GtkMdiChild *child; 777 GtkMdiChild *child;
850 gtk_widget_size_allocate (child->widget, &child_allocation); 850 gtk_widget_size_allocate (child->widget, &child_allocation);
851 } 851 }
852 } 852 }
853 } 853 }
854 854
855 #if 0 /* TODO: Is this needed... propogate expose is no longer supported */
855 static gint gtk_mdi_expose(GtkWidget *widget, GdkEventExpose *event) 856 static gint gtk_mdi_expose(GtkWidget *widget, GdkEventExpose *event)
856 { 857 {
857 #if 0 /* TODO: Is this needed... propogate expose is no longer supported */
858 GtkMdiChild *child; 858 GtkMdiChild *child;
859 GList *children; 859 GList *children;
860 GtkMdi *mdi; 860 GtkMdi *mdi;
861 861
862 g_return_val_if_fail (widget != NULL, FALSE); 862 g_return_val_if_fail (widget != NULL, FALSE);
869 child = (GtkMdiChild *) children->data; 869 child = (GtkMdiChild *) children->data;
870 gtk_container_propagate_expose (GTK_CONTAINER (mdi), 870 gtk_container_propagate_expose (GTK_CONTAINER (mdi),
871 child->widget, 871 child->widget,
872 event); 872 event);
873 } 873 }
874 return FALSE;
875 }
874 #endif 876 #endif
875 return FALSE;
876 }
877 877
878 static void gtk_mdi_add(GtkContainer *container, GtkWidget *widget) 878 static void gtk_mdi_add(GtkContainer *container, GtkWidget *widget)
879 { 879 {
880 GtkWidget *label; 880 GtkWidget *label;
881 label = gtk_label_new (""); 881 label = gtk_label_new ("");
1433 retval = sizefunc(work.window, event->width, event->height, work.data); 1433 retval = sizefunc(work.window, event->width, event->height, work.data);
1434 } 1434 }
1435 return retval; 1435 return retval;
1436 } 1436 }
1437 1437
1438 static gint _expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data) 1438 static gint _expose_event(GtkWidget *widget, cairo_t *cr, gpointer data)
1439 { 1439 {
1440 SignalHandler work = _get_signal_handler(widget, data); 1440 SignalHandler work = _get_signal_handler(widget, data);
1441 int retval = FALSE; 1441 int retval = FALSE;
1442 1442
1443 if ( dbgfp != NULL ) _dw_log("%s %d: %s\n",__FILE__,__LINE__,__func__); 1443 if ( dbgfp != NULL ) _dw_log("%s %d: %s\n",__FILE__,__LINE__,__func__);
1444 if(work.window) 1444 if(work.window)
1445 { 1445 {
1446 DWExpose exp; 1446 DWExpose exp;
1447 int (*exposefunc)(HWND, DWExpose *, void *) = work.func; 1447 int (*exposefunc)(HWND, DWExpose *, void *) = work.func;
1448 1448
1449 exp.x = event->area.x; 1449 exp.x = exp.y = 0;
1450 exp.y = event->area.y; 1450 exp.width = egtk_widget_get_allocated_width(widget);
1451 exp.width = event->area.width; 1451 exp.height = gtk_widget_get_allocated_height(widget);
1452 exp.height = event->area.height;
1453 retval = exposefunc(work.window, &exp, work.data); 1452 retval = exposefunc(work.window, &exp, work.data);
1454 } 1453 }
1455 return retval; 1454 return retval;
1456 } 1455 }
1457 1456
1495 } 1494 }
1496 item++; 1495 item++;
1497 list = list->next; 1496 list = list->next;
1498 } 1497 }
1499 _dw_recursing = 0; 1498 _dw_recursing = 0;
1500 }
1501 #endif
1502 return retval;
1503 }
1504
1505 static gint _container_context_event(GtkWidget *widget, GdkEventButton *event, gpointer data)
1506 {
1507 SignalHandler work = _get_signal_handler(widget, data);
1508 int retval = FALSE;
1509
1510 #if 0
1511 if ( dbgfp != NULL ) _dw_log("%s %d: %s\n",__FILE__,__LINE__,__func__);
1512 if(work.window)
1513 {
1514 if(event->button == 3)
1515 {
1516 int (*contextfunc)(HWND, char *, int, int, void *, void *) = work.func;
1517 char *text;
1518 int row, col;
1519
1520 gtk_clist_get_selection_info(GTK_CLIST(widget), event->x, event->y, &row, &col);
1521
1522 text = (char *)gtk_clist_get_row_data(GTK_CLIST(widget), row);
1523 retval = contextfunc(work.window, text, event->x, event->y, work.data, NULL);
1524 }
1525 } 1499 }
1526 #endif 1500 #endif
1527 return retval; 1501 return retval;
1528 } 1502 }
1529 1503
3564 DW_MUTEX_UNLOCK; 3538 DW_MUTEX_UNLOCK;
3565 return 0; 3539 return 0;
3566 } 3540 }
3567 g_object_set_data(G_OBJECT(tmp), "_dw_tree_type", (gpointer)_DW_TREE_TYPE_CONTAINER); 3541 g_object_set_data(G_OBJECT(tmp), "_dw_tree_type", (gpointer)_DW_TREE_TYPE_CONTAINER);
3568 g_object_set_data(G_OBJECT(tmp), "_dw_multi_sel", GINT_TO_POINTER(multi)); 3542 g_object_set_data(G_OBJECT(tmp), "_dw_multi_sel", GINT_TO_POINTER(multi));
3569 g_object_set_data(G_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id));
3570 DW_MUTEX_UNLOCK; 3543 DW_MUTEX_UNLOCK;
3571 return tmp; 3544 return tmp;
3572 } 3545 }
3573 3546
3574 /* 3547 /*
3593 return 0; 3566 return 0;
3594 } 3567 }
3595 store = gtk_tree_store_new(4, G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_POINTER, G_TYPE_POINTER); 3568 store = gtk_tree_store_new(4, G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_POINTER, G_TYPE_POINTER);
3596 tree = _tree_setup(tmp, GTK_TREE_MODEL(store)); 3569 tree = _tree_setup(tmp, GTK_TREE_MODEL(store));
3597 g_object_set_data(G_OBJECT(tmp), "_dw_tree_type", (gpointer)_DW_TREE_TYPE_TREE); 3570 g_object_set_data(G_OBJECT(tmp), "_dw_tree_type", (gpointer)_DW_TREE_TYPE_TREE);
3598 g_object_set_data(G_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id));
3599 col = gtk_tree_view_column_new(); 3571 col = gtk_tree_view_column_new();
3600 3572
3601 rend = gtk_cell_renderer_pixbuf_new(); 3573 rend = gtk_cell_renderer_pixbuf_new();
3602 gtk_tree_view_column_pack_start(col, rend, FALSE); 3574 gtk_tree_view_column_pack_start(col, rend, FALSE);
3603 gtk_tree_view_column_add_attribute(col, rend, "pixbuf", 1); 3575 gtk_tree_view_column_add_attribute(col, rend, "pixbuf", 1);
3758 gint cid; 3730 gint cid;
3759 3731
3760 DW_MUTEX_LOCK; 3732 DW_MUTEX_LOCK;
3761 store = gtk_list_store_new(1, G_TYPE_STRING); 3733 store = gtk_list_store_new(1, G_TYPE_STRING);
3762 tmp = gtk_combo_box_new_with_model_and_entry(GTK_TREE_MODEL(store)); 3734 tmp = gtk_combo_box_new_with_model_and_entry(GTK_TREE_MODEL(store));
3763 renderer = gtk_cell_renderer_text_new (); 3735 gtk_combo_box_set_entry_text_column(GTK_COMBO_BOX(tmp), 0);
3764 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT(tmp), renderer, TRUE);
3765 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT(tmp), renderer, "text", 0, NULL);
3766 gtk_combo_box_set_id_column(GTK_COMBO_BOX(tmp), 0);
3767 gtk_widget_show(tmp); 3736 gtk_widget_show(tmp);
3768 g_object_set_data(G_OBJECT(tmp), "_dw_tree_type", (gpointer)_DW_TREE_TYPE_COMBOBOX); 3737 g_object_set_data(G_OBJECT(tmp), "_dw_tree_type", (gpointer)_DW_TREE_TYPE_COMBOBOX);
3769 g_object_set_data(G_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id)); 3738 g_object_set_data(G_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id));
3770 DW_MUTEX_UNLOCK; 3739 DW_MUTEX_UNLOCK;
3771 return tmp; 3740 return tmp;
4075 return 0; 4044 return 0;
4076 } 4045 }
4077 store = gtk_list_store_new(1, G_TYPE_STRING); 4046 store = gtk_list_store_new(1, G_TYPE_STRING);
4078 tree = _tree_setup(tmp, GTK_TREE_MODEL(store)); 4047 tree = _tree_setup(tmp, GTK_TREE_MODEL(store));
4079 g_object_set_data(G_OBJECT(tmp), "_dw_tree_type", (gpointer)_DW_TREE_TYPE_LISTBOX); 4048 g_object_set_data(G_OBJECT(tmp), "_dw_tree_type", (gpointer)_DW_TREE_TYPE_LISTBOX);
4080 g_object_set_data(G_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id));
4081 4049
4082 col = gtk_tree_view_column_new(); 4050 col = gtk_tree_view_column_new();
4083 rend = gtk_cell_renderer_text_new(); 4051 rend = gtk_cell_renderer_text_new();
4084 gtk_tree_view_column_pack_start(col, rend, TRUE); 4052 gtk_tree_view_column_pack_start(col, rend, TRUE);
4085 gtk_tree_view_column_add_attribute(col, rend, "text", 0); 4053 gtk_tree_view_column_add_attribute(col, rend, "text", 0);
4210 * NULL if you use the id param) 4178 * NULL if you use the id param)
4211 * len: length of data 4179 * len: length of data
4212 */ 4180 */
4213 void dw_window_set_bitmap_from_data(HWND handle, unsigned long id, char *data, int len) 4181 void dw_window_set_bitmap_from_data(HWND handle, unsigned long id, char *data, int len)
4214 { 4182 {
4215 GdkPixbuf *tmp; 4183 GdkPixbuf *tmp = NULL;
4216 int _locked_by_me = FALSE; 4184 int _locked_by_me = FALSE;
4217 char *file; 4185 char *file;
4218 FILE *fp; 4186 FILE *fp;
4219 4187
4220 if (!id && !data) 4188 if (!id && !data)
5907 * column: Zero based column. 5875 * column: Zero based column.
5908 */ 5876 */
5909 int dw_container_get_column_type(HWND handle, int column) 5877 int dw_container_get_column_type(HWND handle, int column)
5910 { 5878 {
5911 char numbuf[10]; 5879 char numbuf[10];
5912 int flag, rc; 5880 int flag, rc = 0;
5913 #if 0 5881 #if 0
5914 GtkWidget *clist; 5882 GtkWidget *clist;
5915 int _locked_by_me = FALSE; 5883 int _locked_by_me = FALSE;
5916 5884
5917 DW_MUTEX_LOCK; 5885 DW_MUTEX_LOCK;
6217 * Returns: 6185 * Returns:
6218 * The selected color or the current color if cancelled. 6186 * The selected color or the current color if cancelled.
6219 */ 6187 */
6220 unsigned long API dw_color_choose(unsigned long value) 6188 unsigned long API dw_color_choose(unsigned long value)
6221 { 6189 {
6222 GtkWidget *colorw; 6190 GtkWidget *colorw, *ok_button, *cancel_button;
6223 int _locked_by_me = FALSE; 6191 int _locked_by_me = FALSE;
6224 DWDialog *dwwait; 6192 DWDialog *dwwait;
6225 GtkColorSelection *colorsel; 6193 GtkColorSelection *colorsel;
6226 GdkColor color = _internal_color(value); 6194 GdkColor color = _internal_color(value);
6227 GObject *part; 6195 GObject *part;
6243 colorw = gtk_color_selection_dialog_new("Select Color"); 6211 colorw = gtk_color_selection_dialog_new("Select Color");
6244 6212
6245 dwwait = dw_dialog_new((void *)colorw); 6213 dwwait = dw_dialog_new((void *)colorw);
6246 6214
6247 colorsel = (GtkColorSelection *)gtk_color_selection_dialog_get_color_selection(GTK_COLOR_SELECTION_DIALOG(colorw)); 6215 colorsel = (GtkColorSelection *)gtk_color_selection_dialog_get_color_selection(GTK_COLOR_SELECTION_DIALOG(colorw));
6248 #if 0 /* TODO */ 6216 g_object_get(G_OBJECT(colorw), "ok-button", &ok_button, "cancel-button", &cancel_button, NULL);
6249 part = gtk_buildable_get_internal_child(GTK_BUILDABLE(colorsel, 6217 g_signal_connect(G_OBJECT(ok_button), "clicked", G_CALLBACK(_gtk_color_ok), dwwait);
6250 g_signal_connect(G_OBJECT(colorsel->ok_button), "clicked", G_CALLBACK(_gtk_color_ok), dwwait); 6218 g_signal_connect(G_OBJECT(cancel_button), "clicked", G_CALLBACK(_gtk_color_cancel), dwwait);
6251 g_signal_connect(G_OBJECT(colorsel->cancel_button), "clicked", G_CALLBACK(_gtk_color_cancel), dwwait);
6252 #endif
6253 6219
6254 gtk_color_selection_set_previous_color(colorsel,&color); 6220 gtk_color_selection_set_previous_color(colorsel,&color);
6255 gtk_color_selection_set_current_color(colorsel,&color); 6221 gtk_color_selection_set_current_color(colorsel,&color);
6256 gtk_color_selection_set_has_palette(colorsel,TRUE); 6222 gtk_color_selection_set_has_palette(colorsel,TRUE);
6257 6223
8247 if(handle2) 8213 if(handle2)
8248 { 8214 {
8249 GtkTreeIter iter; 8215 GtkTreeIter iter;
8250 8216
8251 /* Make sure it is the correct tree type */ 8217 /* Make sure it is the correct tree type */
8252 if(GTK_IS_TREE_VIEW(handle2) && g_object_get_data(G_OBJECT(handle2), "_dw_tree_type") == _DW_TREE_TYPE_LISTBOX) 8218 if(GTK_IS_TREE_VIEW(handle2) && g_object_get_data(G_OBJECT(handle2), "_dw_tree_type") == GINT_TO_POINTER(_DW_TREE_TYPE_LISTBOX))
8253 store = (GtkTreeStore *)gtk_tree_view_get_model(GTK_TREE_VIEW(handle2)); 8219 store = (GtkListStore *)gtk_tree_view_get_model(GTK_TREE_VIEW(handle2));
8254 else if(GTK_IS_COMBO_BOX(handle2)) 8220 else if(GTK_IS_COMBO_BOX(handle2))
8255 store = (GtkTreeStore *)gtk_combo_box_get_model(GTK_COMBO_BOX(handle2)); 8221 store = (GtkListStore *)gtk_combo_box_get_model(GTK_COMBO_BOX(handle2));
8256 8222
8257 if(!store) 8223 if(!store)
8258 { 8224 {
8259 DW_MUTEX_UNLOCK; 8225 DW_MUTEX_UNLOCK;
8260 return; 8226 return;
8300 { 8266 {
8301 int z; 8267 int z;
8302 GtkTreeIter iter; 8268 GtkTreeIter iter;
8303 8269
8304 /* Make sure it is the correct tree type */ 8270 /* Make sure it is the correct tree type */
8305 if(GTK_IS_TREE_VIEW(handle2) && g_object_get_data(G_OBJECT(handle2), "_dw_tree_type") == _DW_TREE_TYPE_LISTBOX) 8271 if(GTK_IS_TREE_VIEW(handle2) && g_object_get_data(G_OBJECT(handle2), "_dw_tree_type") == GINT_TO_POINTER(_DW_TREE_TYPE_LISTBOX))
8306 store = (GtkTreeStore *)gtk_tree_view_get_model(GTK_TREE_VIEW(handle2)); 8272 store = (GtkListStore *)gtk_tree_view_get_model(GTK_TREE_VIEW(handle2));
8307 else if(GTK_IS_COMBO_BOX(handle2)) 8273 else if(GTK_IS_COMBO_BOX(handle2))
8308 store = (GtkTreeStore *)gtk_combo_box_get_model(GTK_COMBO_BOX(handle2)); 8274 store = (GtkListStore *)gtk_combo_box_get_model(GTK_COMBO_BOX(handle2));
8309 8275
8310 if(!store) 8276 if(!store)
8311 { 8277 {
8312 DW_MUTEX_UNLOCK; 8278 DW_MUTEX_UNLOCK;
8313 return; 8279 return;
8343 handle2 = tmp; 8309 handle2 = tmp;
8344 } 8310 }
8345 if(handle2) 8311 if(handle2)
8346 { 8312 {
8347 /* Make sure it is the correct tree type */ 8313 /* Make sure it is the correct tree type */
8348 if(GTK_IS_TREE_VIEW(handle2) && g_object_get_data(G_OBJECT(handle2), "_dw_tree_type") == _DW_TREE_TYPE_LISTBOX) 8314 if(GTK_IS_TREE_VIEW(handle2) && g_object_get_data(G_OBJECT(handle2), "_dw_tree_type") == GINT_TO_POINTER(_DW_TREE_TYPE_LISTBOX))
8349 store = (GtkTreeStore *)gtk_tree_view_get_model(GTK_TREE_VIEW(handle2)); 8315 store = (GtkListStore *)gtk_tree_view_get_model(GTK_TREE_VIEW(handle2));
8350 else if(GTK_IS_COMBO_BOX(handle2)) 8316 else if(GTK_IS_COMBO_BOX(handle2))
8351 store = (GtkTreeStore *)gtk_combo_box_get_model(GTK_COMBO_BOX(handle2)); 8317 store = (GtkListStore *)gtk_combo_box_get_model(GTK_COMBO_BOX(handle2));
8352 8318
8353 if(!store) 8319 if(!store)
8354 { 8320 {
8355 DW_MUTEX_UNLOCK; 8321 DW_MUTEX_UNLOCK;
8356 return; 8322 return;
8370 { 8336 {
8371 GtkWidget *handle2 = handle; 8337 GtkWidget *handle2 = handle;
8372 GtkListStore *store = NULL; 8338 GtkListStore *store = NULL;
8373 int _locked_by_me = FALSE; 8339 int _locked_by_me = FALSE;
8374 int retval = 0; 8340 int retval = 0;
8341
8342 DW_MUTEX_LOCK;
8343 /* Get the inner handle for scrolled controls */
8344 if(GTK_IS_SCROLLED_WINDOW(handle))
8345 {
8346 GtkWidget *tmp = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_user");
8347 if(tmp)
8348 handle2 = tmp;
8349 }
8350 if(handle2)
8351 {
8352 /* Make sure it is the correct tree type */
8353 if(GTK_IS_TREE_VIEW(handle2) && g_object_get_data(G_OBJECT(handle2), "_dw_tree_type") == GINT_TO_POINTER(_DW_TREE_TYPE_LISTBOX))
8354 store = (GtkListStore *)gtk_tree_view_get_model(GTK_TREE_VIEW(handle2));
8355 else if(GTK_IS_COMBO_BOX(handle2))
8356 store = (GtkListStore *)gtk_combo_box_get_model(GTK_COMBO_BOX(handle2));
8357
8358 if(store)
8359 {
8360 /* Get the number of children at the top level */
8361 retval = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(store), NULL);
8362 }
8363 }
8364 DW_MUTEX_UNLOCK;
8365 return retval;
8366 }
8367
8368 /*
8369 * Sets the topmost item in the viewport.
8370 * Parameters:
8371 * handle: Handle to the listbox to be cleared.
8372 * top: Index to the top item.
8373 */
8374 void dw_listbox_set_top(HWND handle, int top)
8375 {
8376 GtkWidget *handle2 = handle;
8377 int _locked_by_me = FALSE;
8378
8379 DW_MUTEX_LOCK;
8380 if(GTK_IS_SCROLLED_WINDOW(handle))
8381 {
8382 GtkWidget *tmp = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_user");
8383 if(tmp)
8384 handle2 = tmp;
8385 }
8386 #if 0
8387 if(GTK_IS_LIST(handle2))
8388 {
8389 int count = dw_listbox_count(handle);
8390 GtkAdjustment *adj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(handle));
8391 float pos, ratio;
8392
8393 if(count)
8394 {
8395 ratio = (float)top/(float)count;
8396
8397 pos = (ratio * (float)(adj->upper - adj->lower)) + adj->lower;
8398
8399 gtk_adjustment_set_value(adj, pos);
8400 }
8401 }
8402 #endif
8403 DW_MUTEX_UNLOCK;
8404 }
8405
8406 /*
8407 * Copies the given index item's text into buffer.
8408 * Parameters:
8409 * handle: Handle to the listbox to be queried.
8410 * index: Index into the list to be queried.
8411 * buffer: Buffer where text will be copied.
8412 * length: Length of the buffer (including NULL).
8413 */
8414 void dw_listbox_get_text(HWND handle, unsigned int index, char *buffer, unsigned int length)
8415 {
8416 GtkWidget *handle2 = handle;
8417 GtkListStore *store = NULL;
8418 int _locked_by_me = FALSE;
8419
8420 DW_MUTEX_LOCK;
8421 /* Get the inner handle for scrolled controls */
8422 if(GTK_IS_SCROLLED_WINDOW(handle))
8423 {
8424 GtkWidget *tmp = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_user");
8425 if(tmp)
8426 handle2 = tmp;
8427 }
8428 if(handle2)
8429 {
8430 /* Make sure it is the correct tree type */
8431 if(GTK_IS_TREE_VIEW(handle2) && g_object_get_data(G_OBJECT(handle2), "_dw_tree_type") == GINT_TO_POINTER(_DW_TREE_TYPE_LISTBOX))
8432 store = (GtkListStore *)gtk_tree_view_get_model(GTK_TREE_VIEW(handle2));
8433 else if(GTK_IS_COMBO_BOX(handle2))
8434 store = (GtkListStore *)gtk_combo_box_get_model(GTK_COMBO_BOX(handle2));
8435
8436 if(store && index < gtk_tree_model_iter_n_children(GTK_TREE_MODEL(store), NULL))
8437 {
8438 GtkTreeIter iter;
8439
8440 /* Get the nth child at the top level */
8441 if(gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(store), &iter, NULL, index))
8442 {
8443 /* Get the text */
8444 gchar *text;
8445 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, 0, &text, -1);
8446 strncpy(buffer, text, length);
8447 DW_MUTEX_UNLOCK;
8448 return;
8449 }
8450 }
8451 }
8452 buffer[0] = '\0';
8453 DW_MUTEX_UNLOCK;
8454 }
8455
8456 /*
8457 * Sets the text of a given listbox entry.
8458 * Parameters:
8459 * handle: Handle to the listbox to be queried.
8460 * index: Index into the list to be queried.
8461 * buffer: Buffer where text will be copied.
8462 */
8463 void dw_listbox_set_text(HWND handle, unsigned int index, char *buffer)
8464 {
8465 GtkWidget *handle2 = handle;
8466 GtkListStore *store = NULL;
8467 int _locked_by_me = FALSE;
8468
8469 DW_MUTEX_LOCK;
8470 /* Get the inner handle for scrolled controls */
8471 if(GTK_IS_SCROLLED_WINDOW(handle))
8472 {
8473 GtkWidget *tmp = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_user");
8474 if(tmp)
8475 handle2 = tmp;
8476 }
8477 if(handle2)
8478 {
8479 /* Make sure it is the correct tree type */
8480 if(GTK_IS_TREE_VIEW(handle2) && g_object_get_data(G_OBJECT(handle2), "_dw_tree_type") == GINT_TO_POINTER(_DW_TREE_TYPE_LISTBOX))
8481 store = (GtkListStore *)gtk_tree_view_get_model(GTK_TREE_VIEW(handle2));
8482 else if(GTK_IS_COMBO_BOX(handle2))
8483 store = (GtkListStore *)gtk_combo_box_get_model(GTK_COMBO_BOX(handle2));
8484
8485 if(store && index < gtk_tree_model_iter_n_children(GTK_TREE_MODEL(store), NULL))
8486 {
8487 GtkTreeIter iter;
8488
8489 /* Get the nth child at the top level */
8490 if (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(store), &iter, NULL, index))
8491 {
8492 /* Update the text */
8493 gtk_list_store_set(store, &iter, buffer);
8494 }
8495 }
8496 }
8497 DW_MUTEX_UNLOCK;
8498 }
8499
8500 /*
8501 * Returns the index to the current selected item or -1 when done.
8502 * Parameters:
8503 * handle: Handle to the listbox to be queried.
8504 * where: Either the previous return or -1 to restart.
8505 */
8506 int dw_listbox_selected_multi(HWND handle, int where)
8507 {
8508 GtkWidget *handle2 = handle;
8509 int retval = DW_LIT_NONE;
8510 int _locked_by_me = FALSE;
8511
8512 DW_MUTEX_LOCK;
8513 if(GTK_IS_SCROLLED_WINDOW(handle))
8514 {
8515 GtkWidget *tmp = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_user");
8516 if(tmp)
8517 handle2 = tmp;
8518 }
8519 #if 0
8520 if(GTK_IS_LIST(handle2))
8521 {
8522 int counter = 0;
8523 GList *list = GTK_LIST(handle2)->children;
8524
8525 while(list)
8526 {
8527 GtkItem *item = (GtkItem *)list->data;
8528
8529 if(item &&
8530 item->bin.container.widget.state == GTK_STATE_SELECTED
8531 && counter > where)
8532 {
8533 retval = counter;
8534 break;
8535 }
8536
8537
8538 list = list->next;
8539 counter++;
8540 }
8541 }
8542 #endif
8543 DW_MUTEX_UNLOCK;
8544 return retval;
8545 }
8546
8547 /*
8548 * Returns the index to the item in the list currently selected.
8549 * Parameters:
8550 * handle: Handle to the listbox to be queried.
8551 */
8552 unsigned int dw_listbox_selected(HWND handle)
8553 {
8554 GtkWidget *handle2 = handle;
8555 GtkListStore *store = NULL;
8556 int _locked_by_me = FALSE;
8557 unsigned int retval = 0;
8558
8559 DW_MUTEX_LOCK;
8560 /* Get the inner handle for scrolled controls */
8561 if(GTK_IS_SCROLLED_WINDOW(handle))
8562 {
8563 GtkWidget *tmp = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_user");
8564 if(tmp)
8565 handle2 = tmp;
8566 }
8567 if(handle2)
8568 {
8569 /* Make sure it is the correct tree type */
8570 if(GTK_IS_TREE_VIEW(handle2) && g_object_get_data(G_OBJECT(handle2), "_dw_tree_type") == GINT_TO_POINTER(_DW_TREE_TYPE_LISTBOX))
8571 store = (GtkListStore *)gtk_tree_view_get_model(GTK_TREE_VIEW(handle2));
8572 else if(GTK_IS_COMBO_BOX(handle2))
8573 store = (GtkListStore *)gtk_combo_box_get_model(GTK_COMBO_BOX(handle2));
8574
8575 if(store)
8576 {
8577 GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(handle2));
8578 GList *list = gtk_tree_selection_get_selected_rows(sel, NULL);
8579 if(list)
8580 {
8581 GtkTreePath *path = g_list_nth_data(list, 0);
8582 gint *indices = gtk_tree_path_get_indices(path);
8583
8584 if(indices)
8585 {
8586 retval = indices[0];
8587 }
8588
8589 g_list_foreach(list, (GFunc) gtk_tree_path_free, NULL);
8590 g_list_free(list);
8591 }
8592 }
8593 }
8594 DW_MUTEX_UNLOCK;
8595 return retval;
8596 }
8597
8598 /*
8599 * Sets the selection state of a given index.
8600 * Parameters:
8601 * handle: Handle to the listbox to be set.
8602 * index: Item index.
8603 * state: TRUE if selected FALSE if unselected.
8604 */
8605 void dw_listbox_select(HWND handle, int index, int state)
8606 {
8607 GtkWidget *handle2 = handle;
8608 GtkListStore *store = NULL;
8609 int _locked_by_me = FALSE;
8610
8611 DW_MUTEX_LOCK;
8612 /* Get the inner handle for scrolled controls */
8613 if(GTK_IS_SCROLLED_WINDOW(handle))
8614 {
8615 GtkWidget *tmp = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_user");
8616 if(tmp)
8617 handle2 = tmp;
8618 }
8619 if(handle2)
8620 {
8621 /* Make sure it is the correct tree type */
8622 if(GTK_IS_TREE_VIEW(handle2) && g_object_get_data(G_OBJECT(handle2), "_dw_tree_type") == GINT_TO_POINTER(_DW_TREE_TYPE_LISTBOX))
8623 store = (GtkListStore *)gtk_tree_view_get_model(GTK_TREE_VIEW(handle2));
8624 else if(GTK_IS_COMBO_BOX(handle2))
8625 store = (GtkListStore *)gtk_combo_box_get_model(GTK_COMBO_BOX(handle2));
8626
8627 if(store && index < gtk_tree_model_iter_n_children(GTK_TREE_MODEL(store), NULL))
8628 {
8629 GtkTreeIter iter;
8630
8631 /* Get the nth child at the top level */
8632 if (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(store), &iter, NULL, index))
8633 {
8634 GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(handle2));
8635 if(state)
8636 {
8637 /* Select the item */
8638 gtk_tree_selection_select_iter(sel, &iter);
8639 }
8640 else
8641 {
8642 /* Deselect the item */
8643 gtk_tree_selection_deselect_iter(sel, &iter);
8644 }
8645 }
8646 }
8647 }
8648 DW_MUTEX_UNLOCK;
8649 }
8650
8651 /*
8652 * Deletes the item with given index from the list.
8653 * Parameters:
8654 * handle: Handle to the listbox to be set.
8655 * index: Item index.
8656 */
8657 void dw_listbox_delete(HWND handle, int index)
8658 {
8659 GtkWidget *handle2 = handle;
8660 GtkListStore *store = NULL;
8661 int _locked_by_me = FALSE;
8375 8662
8376 DW_MUTEX_LOCK; 8663 DW_MUTEX_LOCK;
8377 /* Get the inner handle for scrolled controls */ 8664 /* Get the inner handle for scrolled controls */
8378 if(GTK_IS_SCROLLED_WINDOW(handle)) 8665 if(GTK_IS_SCROLLED_WINDOW(handle))
8379 { 8666 {
8389 else if(GTK_IS_COMBO_BOX(handle2)) 8676 else if(GTK_IS_COMBO_BOX(handle2))
8390 store = (GtkTreeStore *)gtk_combo_box_get_model(GTK_COMBO_BOX(handle2)); 8677 store = (GtkTreeStore *)gtk_combo_box_get_model(GTK_COMBO_BOX(handle2));
8391 8678
8392 if(store) 8679 if(store)
8393 { 8680 {
8394 /* Get the number of children at the top level */
8395 retval = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(store), NULL);
8396 }
8397 }
8398 DW_MUTEX_UNLOCK;
8399 return retval;
8400 }
8401
8402 /*
8403 * Sets the topmost item in the viewport.
8404 * Parameters:
8405 * handle: Handle to the listbox to be cleared.
8406 * top: Index to the top item.
8407 */
8408 void dw_listbox_set_top(HWND handle, int top)
8409 {
8410 GtkWidget *handle2 = handle;
8411 int _locked_by_me = FALSE;
8412
8413 DW_MUTEX_LOCK;
8414 if(GTK_IS_SCROLLED_WINDOW(handle))
8415 {
8416 GtkWidget *tmp = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_user");
8417 if(tmp)
8418 handle2 = tmp;
8419 }
8420 #if 0
8421 if(GTK_IS_LIST(handle2))
8422 {
8423 int count = dw_listbox_count(handle);
8424 GtkAdjustment *adj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(handle));
8425 float pos, ratio;
8426
8427 if(count)
8428 {
8429 ratio = (float)top/(float)count;
8430
8431 pos = (ratio * (float)(adj->upper - adj->lower)) + adj->lower;
8432
8433 gtk_adjustment_set_value(adj, pos);
8434 }
8435 }
8436 #endif
8437 DW_MUTEX_UNLOCK;
8438 }
8439
8440 /*
8441 * Copies the given index item's text into buffer.
8442 * Parameters:
8443 * handle: Handle to the listbox to be queried.
8444 * index: Index into the list to be queried.
8445 * buffer: Buffer where text will be copied.
8446 * length: Length of the buffer (including NULL).
8447 */
8448 void dw_listbox_get_text(HWND handle, unsigned int index, char *buffer, unsigned int length)
8449 {
8450 GtkWidget *handle2 = handle;
8451 GtkListStore *store = NULL;
8452 int _locked_by_me = FALSE;
8453
8454 DW_MUTEX_LOCK;
8455 /* Get the inner handle for scrolled controls */
8456 if(GTK_IS_SCROLLED_WINDOW(handle))
8457 {
8458 GtkWidget *tmp = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_user");
8459 if(tmp)
8460 handle2 = tmp;
8461 }
8462 if(handle2)
8463 {
8464 /* Make sure it is the correct tree type */
8465 if(GTK_IS_TREE_VIEW(handle2) && g_object_get_data(G_OBJECT(handle2), "_dw_tree_type") == _DW_TREE_TYPE_LISTBOX)
8466 store = (GtkTreeStore *)gtk_tree_view_get_model(GTK_TREE_VIEW(handle2));
8467 else if(GTK_IS_COMBO_BOX(handle2))
8468 store = (GtkTreeStore *)gtk_combo_box_get_model(GTK_COMBO_BOX(handle2));
8469
8470 if(store)
8471 {
8472 GtkTreePath *path = gtk_tree_path_new_from_indices(index);
8473 GtkTreeIter iter; 8681 GtkTreeIter iter;
8474 GValue value;
8475 char *out;
8476 8682
8477 /* Get the number of children at the top level */ 8683 /* Get the nth child at the top level */
8478 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, path); 8684 if (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(store), &iter, NULL, index))
8479 gtk_tree_model_get_value(GTK_TREE_MODEL(store), &iter, 0, &value);
8480 out = g_value_get_string(&value);
8481 strncpy(buffer, out, length);
8482 g_object_unref(G_OBJECT(path));
8483 }
8484 }
8485 DW_MUTEX_UNLOCK;
8486 }
8487
8488 /*
8489 * Sets the text of a given listbox entry.
8490 * Parameters:
8491 * handle: Handle to the listbox to be queried.
8492 * index: Index into the list to be queried.
8493 * buffer: Buffer where text will be copied.
8494 */
8495 void dw_listbox_set_text(HWND handle, unsigned int index, char *buffer)
8496 {
8497 GtkWidget *handle2 = handle;
8498 GtkListStore *store = NULL;
8499 int _locked_by_me = FALSE;
8500
8501 DW_MUTEX_LOCK;
8502 /* Get the inner handle for scrolled controls */
8503 if(GTK_IS_SCROLLED_WINDOW(handle))
8504 {
8505 GtkWidget *tmp = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_user");
8506 if(tmp)
8507 handle2 = tmp;
8508 }
8509 if(handle2)
8510 {
8511 /* Make sure it is the correct tree type */
8512 if(GTK_IS_TREE_VIEW(handle2) && g_object_get_data(G_OBJECT(handle2), "_dw_tree_type") == _DW_TREE_TYPE_LISTBOX)
8513 store = (GtkTreeStore *)gtk_tree_view_get_model(GTK_TREE_VIEW(handle2));
8514 else if(GTK_IS_COMBO_BOX(handle2))
8515 store = (GtkTreeStore *)gtk_combo_box_get_model(GTK_COMBO_BOX(handle2));
8516
8517 if(store)
8518 {
8519 GtkTreePath *path = gtk_tree_path_new_from_indices(index);
8520 GtkTreeIter iter;
8521 GValue value;
8522 char *out;
8523
8524 /* Get the number of children at the top level */
8525 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, path);
8526 gtk_list_store_set(store, &iter, buffer);
8527 g_object_unref(G_OBJECT(path));
8528 }
8529 }
8530 DW_MUTEX_UNLOCK;
8531 }
8532
8533 /*
8534 * Returns the index to the current selected item or -1 when done.
8535 * Parameters:
8536 * handle: Handle to the listbox to be queried.
8537 * where: Either the previous return or -1 to restart.
8538 */
8539 int dw_listbox_selected_multi(HWND handle, int where)
8540 {
8541 GtkWidget *handle2 = handle;
8542 int retval = DW_LIT_NONE;
8543 int _locked_by_me = FALSE;
8544
8545 DW_MUTEX_LOCK;
8546 if(GTK_IS_SCROLLED_WINDOW(handle))
8547 {
8548 GtkWidget *tmp = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_user");
8549 if(tmp)
8550 handle2 = tmp;
8551 }
8552 #if 0
8553 if(GTK_IS_LIST(handle2))
8554 {
8555 int counter = 0;
8556 GList *list = GTK_LIST(handle2)->children;
8557
8558 while(list)
8559 {
8560 GtkItem *item = (GtkItem *)list->data;
8561
8562 if(item &&
8563 item->bin.container.widget.state == GTK_STATE_SELECTED
8564 && counter > where)
8565 { 8685 {
8566 retval = counter; 8686 gtk_list_store_remove(store, &iter);
8567 break;
8568 } 8687 }
8569
8570
8571 list = list->next;
8572 counter++;
8573 }
8574 }
8575 #endif
8576 DW_MUTEX_UNLOCK;
8577 return retval;
8578 }
8579
8580 /*
8581 * Returns the index to the item in the list currently selected.
8582 * Parameters:
8583 * handle: Handle to the listbox to be queried.
8584 */
8585 unsigned int dw_listbox_selected(HWND handle)
8586 {
8587 GtkWidget *handle2 = handle;
8588 int retval = DW_LIT_NONE;
8589 int _locked_by_me = FALSE;
8590
8591 DW_MUTEX_LOCK;
8592 if(GTK_IS_SCROLLED_WINDOW(handle))
8593 {
8594 GtkWidget *tmp = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_user");
8595 if(tmp)
8596 handle2 = tmp;
8597 }
8598 #if 0
8599 else if(GTK_IS_COMBO_BOX(handle))
8600 {
8601 retval = (unsigned int)g_object_get_data(G_OBJECT(handle), "_dw_item");
8602 DW_MUTEX_UNLOCK;
8603 return retval;
8604 }
8605 if(GTK_IS_LIST(handle2))
8606 {
8607 int counter = 0;
8608 GList *list = GTK_LIST(handle2)->children;
8609
8610 while(list)
8611 {
8612 GtkItem *item = (GtkItem *)list->data;
8613
8614 if(item && item->bin.container.widget.state == GTK_STATE_SELECTED)
8615 {
8616 retval = counter;
8617 break;
8618 }
8619
8620 list = list->next;
8621 counter++;
8622 }
8623 }
8624 #endif
8625 DW_MUTEX_UNLOCK;
8626 return retval;
8627 }
8628
8629 /*
8630 * Sets the selection state of a given index.
8631 * Parameters:
8632 * handle: Handle to the listbox to be set.
8633 * index: Item index.
8634 * state: TRUE if selected FALSE if unselected.
8635 */
8636 void dw_listbox_select(HWND handle, int index, int state)
8637 {
8638 GtkWidget *handle2 = handle;
8639 int _locked_by_me = FALSE;
8640
8641 DW_MUTEX_LOCK;
8642 if(GTK_IS_SCROLLED_WINDOW(handle))
8643 {
8644 GtkWidget *tmp = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_user");
8645 if(tmp)
8646 handle2 = tmp;
8647 }
8648 #if 0
8649 else if(GTK_IS_COMBO_BOX(handle))
8650 {
8651 handle2 = GTK_COMBO_BOX(handle)->list;
8652 }
8653 if(GTK_IS_LIST(handle2))
8654 {
8655 if(state)
8656 gtk_list_select_item(GTK_LIST(handle2), index);
8657 else
8658 gtk_list_unselect_item(GTK_LIST(handle2), index);
8659 }
8660 #endif
8661 DW_MUTEX_UNLOCK;
8662 }
8663
8664 /*
8665 * Deletes the item with given index from the list.
8666 * Parameters:
8667 * handle: Handle to the listbox to be set.
8668 * index: Item index.
8669 */
8670 void dw_listbox_delete(HWND handle, int index)
8671 {
8672 GtkWidget *handle2 = handle;
8673 GtkListStore *store = NULL;
8674 int _locked_by_me = FALSE;
8675
8676 DW_MUTEX_LOCK;
8677 /* Get the inner handle for scrolled controls */
8678 if(GTK_IS_SCROLLED_WINDOW(handle))
8679 {
8680 GtkWidget *tmp = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_user");
8681 if(tmp)
8682 handle2 = tmp;
8683 }
8684 if(handle2)
8685 {
8686 /* Make sure it is the correct tree type */
8687 if(GTK_IS_TREE_VIEW(handle2) && g_object_get_data(G_OBJECT(handle2), "_dw_tree_type") == _DW_TREE_TYPE_LISTBOX)
8688 store = (GtkTreeStore *)gtk_tree_view_get_model(GTK_TREE_VIEW(handle2));
8689 else if(GTK_IS_COMBO_BOX(handle2))
8690 store = (GtkTreeStore *)gtk_combo_box_get_model(GTK_COMBO_BOX(handle2));
8691
8692 if(store)
8693 {
8694 GtkTreePath *path = gtk_tree_path_new_from_indices(index);
8695 GtkTreeIter iter;
8696 GValue value;
8697 char *out;
8698
8699 /* Get the number of children at the top level */
8700 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, path);
8701 gtk_list_store_remove(store, &iter);
8702 g_object_unref(G_OBJECT(path));
8703 } 8688 }
8704 } 8689 }
8705 DW_MUTEX_UNLOCK; 8690 DW_MUTEX_UNLOCK;
8706 } 8691 }
8707 8692
9938 if (GTK_IS_SCROLLED_WINDOW(thiswindow)) 9923 if (GTK_IS_SCROLLED_WINDOW(thiswindow))
9939 { 9924 {
9940 thiswindow = (HWND)g_object_get_data(G_OBJECT(window), "_dw_user"); 9925 thiswindow = (HWND)g_object_get_data(G_OBJECT(window), "_dw_user");
9941 } 9926 }
9942 9927
9943 if (GTK_IS_MENU_ITEM(thiswindow) && strcmp(signame, DW_SIGNAL_CLICKED) == 0) 9928 if (strcmp(signame, DW_SIGNAL_EXPOSE) == 0)
9929 {
9930 thisname = "draw";
9931 }
9932 else if (GTK_IS_MENU_ITEM(thiswindow) && strcmp(signame, DW_SIGNAL_CLICKED) == 0)
9944 { 9933 {
9945 thisname = "activate"; 9934 thisname = "activate";
9946 thisfunc = _findsigfunc(thisname); 9935 thisfunc = _findsigfunc(thisname);
9947 } 9936 }
9948 else if (GTK_IS_TREE_VIEW(thiswindow) && strcmp(signame, DW_SIGNAL_ITEM_CONTEXT) == 0) 9937 else if (GTK_IS_TREE_VIEW(thiswindow) && strcmp(signame, DW_SIGNAL_ITEM_CONTEXT) == 0)
9949 { 9938 {
9950 thisfunc = _findsigfunc("tree-context");
9951
9952 sigid = _set_signal_handler(thiswindow, window, sigfunc, data, thisfunc); 9939 sigid = _set_signal_handler(thiswindow, window, sigfunc, data, thisfunc);
9953 cid = g_signal_connect(G_OBJECT(thiswindow), "button_press_event", G_CALLBACK(thisfunc), (gpointer)sigid); 9940 cid = g_signal_connect(G_OBJECT(thiswindow), "button_press_event", G_CALLBACK(thisfunc), (gpointer)sigid);
9954 _set_signal_handler_id(thiswindow, sigid, cid); 9941 _set_signal_handler_id(thiswindow, sigid, cid);
9955 9942
9956 #if 0
9957 sigid = _set_signal_handler(window, window, sigfunc, data, thisfunc);
9958 cid = g_signal_connect(G_OBJECT(window), "button_press_event", GTK_SIGNAL_FUNC(thisfunc), (gpointer)sigid);
9959 _set_signal_handler_id(window, sigid, cid);
9960 #endif
9961
9962 DW_MUTEX_UNLOCK; 9943 DW_MUTEX_UNLOCK;
9963 return; 9944 return;
9964 } 9945 }
9965 else if (GTK_IS_TREE_VIEW(thiswindow) && strcmp(signame, DW_SIGNAL_ITEM_SELECT) == 0) 9946 else if ((GTK_IS_TREE_VIEW(thiswindow) || GTK_IS_COMBO_BOX(thiswindow))
9966 { 9947 && (strcmp(signame, DW_SIGNAL_ITEM_SELECT) == 0 || strcmp(signame, DW_SIGNAL_LIST_SELECT) == 0))
9967 GtkWidget *treeview = thiswindow; 9948 {
9968 9949 GtkWidget *widget = thiswindow;
9969 thiswindow = (GtkWidget *)gtk_tree_view_get_selection(GTK_TREE_VIEW(thiswindow)); 9950
9970 thisname = "changed"; 9951 thisname = "changed";
9971 9952
9972 sigid = _set_signal_handler(treeview, window, sigfunc, data, thisfunc); 9953 sigid = _set_signal_handler(widget, window, sigfunc, data, thisfunc);
9973 cid = g_signal_connect(G_OBJECT(thiswindow), thisname, (GCallback)thisfunc, (gpointer)sigid); 9954 if(GTK_IS_TREE_VIEW(thiswindow))
9974 _set_signal_handler_id(treeview, sigid, cid); 9955 {
9956 thiswindow = (GtkWidget *)gtk_tree_view_get_selection(GTK_TREE_VIEW(thiswindow));
9957 cid = g_signal_connect(G_OBJECT(thiswindow), thisname, G_CALLBACK(thisfunc), (gpointer)sigid);
9958 _set_signal_handler_id(widget, sigid, cid);
9959 }
9960
9975 DW_MUTEX_UNLOCK; 9961 DW_MUTEX_UNLOCK;
9976 return; 9962 return;
9977 } 9963 }
9978 else if (GTK_IS_TREE_VIEW(thiswindow) && strcmp(signame, DW_SIGNAL_TREE_EXPAND) == 0) 9964 else if (GTK_IS_TREE_VIEW(thiswindow) && strcmp(signame, DW_SIGNAL_TREE_EXPAND) == 0)
9979 { 9965 {