Mercurial > dwindows
comparison gtk3/dw.c @ 1873:15d24b5300ec
Third GTK3 round of changes to split string and data
in the container control.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 08 Aug 2013 20:28:57 +0000 |
parents | c836603d3f14 |
children | fb137f7f91e4 |
comparison
equal
deleted
inserted
replaced
1872:eae36372d64d | 1873:15d24b5300ec |
---|---|
1475 gtk_tree_model_get(store, &iter, 0, &text, 2, &itemdata, 3, &item, -1); | 1475 gtk_tree_model_get(store, &iter, 0, &text, 2, &itemdata, 3, &item, -1); |
1476 retval = treeselectfunc(work.window, (HTREEITEM)item, text, work.data, itemdata); | 1476 retval = treeselectfunc(work.window, (HTREEITEM)item, text, work.data, itemdata); |
1477 } | 1477 } |
1478 else if(g_object_get_data(G_OBJECT(widget), "_dw_tree_type") == GINT_TO_POINTER(_DW_TREE_TYPE_CONTAINER)) | 1478 else if(g_object_get_data(G_OBJECT(widget), "_dw_tree_type") == GINT_TO_POINTER(_DW_TREE_TYPE_CONTAINER)) |
1479 { | 1479 { |
1480 gtk_tree_model_get(store, &iter, 0, &text, -1); | 1480 gtk_tree_model_get(store, &iter, 0, &text, 1, &itemdata, -1); |
1481 retval = treeselectfunc(work.window, (HTREEITEM)item, text, work.data, itemdata); | 1481 retval = treeselectfunc(work.window, (HTREEITEM)item, text, work.data, itemdata); |
1482 } | 1482 } |
1483 else | 1483 else |
1484 { | 1484 { |
1485 GtkTreePath *path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter); | 1485 GtkTreePath *path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter); |
1514 gtk_tree_model_get(store, &iter, 0, &text, 2, &itemdata, 3, &item, -1); | 1514 gtk_tree_model_get(store, &iter, 0, &text, 2, &itemdata, 3, &item, -1); |
1515 retval = treeselectfunc(work.window, (HTREEITEM)item, text, work.data, itemdata); | 1515 retval = treeselectfunc(work.window, (HTREEITEM)item, text, work.data, itemdata); |
1516 } | 1516 } |
1517 else if(g_object_get_data(G_OBJECT(widget), "_dw_tree_type") == GINT_TO_POINTER(_DW_TREE_TYPE_CONTAINER)) | 1517 else if(g_object_get_data(G_OBJECT(widget), "_dw_tree_type") == GINT_TO_POINTER(_DW_TREE_TYPE_CONTAINER)) |
1518 { | 1518 { |
1519 gtk_tree_model_get(store, &iter, 0, &text, -1); | 1519 gtk_tree_model_get(store, &iter, 0, &text, 1, &itemdata, -1); |
1520 retval = treeselectfunc(work.window, (HTREEITEM)item, text, work.data, itemdata); | 1520 retval = treeselectfunc(work.window, (HTREEITEM)item, text, work.data, itemdata); |
1521 } | 1521 } |
1522 else | 1522 else |
1523 { | 1523 { |
1524 gint *indices = gtk_tree_path_get_indices(path); | 1524 gint *indices = gtk_tree_path_get_indices(path); |
5480 free(item); | 5480 free(item); |
5481 } | 5481 } |
5482 DW_MUTEX_UNLOCK; | 5482 DW_MUTEX_UNLOCK; |
5483 } | 5483 } |
5484 | 5484 |
5485 #define _DW_CONTAINER_STORE_EXTRA 2 | |
5486 | |
5485 static int _dw_container_setup(HWND handle, unsigned long *flags, char **titles, int count, int separator, int extra) | 5487 static int _dw_container_setup(HWND handle, unsigned long *flags, char **titles, int count, int separator, int extra) |
5486 { | 5488 { |
5487 int z; | 5489 int z; |
5488 char numbuf[21]; | 5490 char numbuf[21]; |
5489 GtkWidget *tree; | 5491 GtkWidget *tree; |
5490 GtkListStore *store; | 5492 GtkListStore *store; |
5491 GtkTreeViewColumn *col; | 5493 GtkTreeViewColumn *col; |
5492 GtkCellRenderer *rend; | 5494 GtkCellRenderer *rend; |
5493 GtkTreeSelection *sel; | 5495 GtkTreeSelection *sel; |
5494 int _locked_by_me = FALSE; | 5496 int _locked_by_me = FALSE; |
5495 GType *array = calloc(count + 2, sizeof(GType)); | 5497 GType *array = calloc(count + _DW_CONTAINER_STORE_EXTRA + 1, sizeof(GType)); |
5496 | 5498 |
5497 DW_MUTEX_LOCK; | 5499 DW_MUTEX_LOCK; |
5498 /* Save some of the info so it is easily accessible */ | 5500 /* Save some of the info so it is easily accessible */ |
5499 g_object_set_data(G_OBJECT(handle), "_dw_cont_columns", GINT_TO_POINTER(count)); | 5501 g_object_set_data(G_OBJECT(handle), "_dw_cont_columns", GINT_TO_POINTER(count)); |
5500 g_object_set_data(G_OBJECT(handle), "_dw_cont_extra", GINT_TO_POINTER(extra)); | 5502 g_object_set_data(G_OBJECT(handle), "_dw_cont_extra", GINT_TO_POINTER(extra)); |
5501 | 5503 |
5502 /* First param is row title/data */ | 5504 /* First param is row title */ |
5503 array[0] = G_TYPE_POINTER; | 5505 array[0] = G_TYPE_STRING; |
5506 /* Second param is row data */ | |
5504 array[1] = G_TYPE_POINTER; | 5507 array[1] = G_TYPE_POINTER; |
5508 array[2] = G_TYPE_POINTER; | |
5505 /* First loop... create array to create the store */ | 5509 /* First loop... create array to create the store */ |
5506 for(z=0;z<count;z++) | 5510 for(z=0;z<count;z++) |
5507 { | 5511 { |
5508 if(z == 0 && flags[z] & DW_CFA_STRINGANDICON) | 5512 if(z == 0 && flags[z] & DW_CFA_STRINGANDICON) |
5509 { | 5513 { |
5510 array[1] = GDK_TYPE_PIXBUF; | 5514 array[_DW_CONTAINER_STORE_EXTRA] = GDK_TYPE_PIXBUF; |
5511 array[2] = G_TYPE_STRING; | 5515 array[_DW_CONTAINER_STORE_EXTRA+1] = G_TYPE_STRING; |
5512 } | 5516 } |
5513 else if(flags[z] & DW_CFA_BITMAPORICON) | 5517 else if(flags[z] & DW_CFA_BITMAPORICON) |
5514 { | 5518 { |
5515 array[z+2] = GDK_TYPE_PIXBUF; | 5519 array[z+_DW_CONTAINER_STORE_EXTRA+1] = GDK_TYPE_PIXBUF; |
5516 } | 5520 } |
5517 else if(flags[z] & DW_CFA_STRING) | 5521 else if(flags[z] & DW_CFA_STRING) |
5518 { | 5522 { |
5519 array[z+2] = G_TYPE_STRING; | 5523 array[z+_DW_CONTAINER_STORE_EXTRA+1] = G_TYPE_STRING; |
5520 } | 5524 } |
5521 else if(flags[z] & DW_CFA_ULONG) | 5525 else if(flags[z] & DW_CFA_ULONG) |
5522 { | 5526 { |
5523 array[z+2] = G_TYPE_ULONG; | 5527 array[z+_DW_CONTAINER_STORE_EXTRA+1] = G_TYPE_ULONG; |
5524 } | 5528 } |
5525 else if(flags[z] & DW_CFA_TIME) | 5529 else if(flags[z] & DW_CFA_TIME) |
5526 { | 5530 { |
5527 array[z+2] = G_TYPE_STRING; | 5531 array[z+_DW_CONTAINER_STORE_EXTRA+1] = G_TYPE_STRING; |
5528 } | 5532 } |
5529 else if(flags[z] & DW_CFA_DATE) | 5533 else if(flags[z] & DW_CFA_DATE) |
5530 { | 5534 { |
5531 array[z+2] = G_TYPE_STRING; | 5535 array[z+_DW_CONTAINER_STORE_EXTRA+1] = G_TYPE_STRING; |
5532 } | 5536 } |
5533 } | 5537 } |
5534 /* Create the store and then the tree */ | 5538 /* Create the store and then the tree */ |
5535 store = gtk_list_store_newv(count+2, array); | 5539 store = gtk_list_store_newv(count + _DW_CONTAINER_STORE_EXTRA + 1, array); |
5536 tree = _tree_setup(handle, GTK_TREE_MODEL(store)); | 5540 tree = _tree_setup(handle, GTK_TREE_MODEL(store)); |
5537 g_object_set_data(G_OBJECT(tree), "_dw_tree_type", GINT_TO_POINTER(_DW_TREE_TYPE_CONTAINER)); | 5541 g_object_set_data(G_OBJECT(tree), "_dw_tree_type", GINT_TO_POINTER(_DW_TREE_TYPE_CONTAINER)); |
5538 /* Second loop... create the columns */ | 5542 /* Second loop... create the columns */ |
5539 for(z=0;z<count;z++) | 5543 for(z=0;z<count;z++) |
5540 { | 5544 { |
5546 | 5550 |
5547 if(z == 0 && flags[z] & DW_CFA_STRINGANDICON) | 5551 if(z == 0 && flags[z] & DW_CFA_STRINGANDICON) |
5548 { | 5552 { |
5549 rend = gtk_cell_renderer_pixbuf_new(); | 5553 rend = gtk_cell_renderer_pixbuf_new(); |
5550 gtk_tree_view_column_pack_start(col, rend, FALSE); | 5554 gtk_tree_view_column_pack_start(col, rend, FALSE); |
5551 gtk_tree_view_column_add_attribute(col, rend, "pixbuf", 1); | 5555 gtk_tree_view_column_add_attribute(col, rend, "pixbuf", _DW_CONTAINER_STORE_EXTRA); |
5552 rend = gtk_cell_renderer_text_new(); | 5556 rend = gtk_cell_renderer_text_new(); |
5553 gtk_tree_view_column_pack_start(col, rend, TRUE); | 5557 gtk_tree_view_column_pack_start(col, rend, TRUE); |
5554 gtk_tree_view_column_add_attribute(col, rend, "text", 2); | 5558 gtk_tree_view_column_add_attribute(col, rend, "text", _DW_CONTAINER_STORE_EXTRA+1); |
5555 } | 5559 } |
5556 else if(flags[z] & DW_CFA_BITMAPORICON) | 5560 else if(flags[z] & DW_CFA_BITMAPORICON) |
5557 { | 5561 { |
5558 rend = gtk_cell_renderer_pixbuf_new(); | 5562 rend = gtk_cell_renderer_pixbuf_new(); |
5559 gtk_tree_view_column_pack_start(col, rend, FALSE); | 5563 gtk_tree_view_column_pack_start(col, rend, FALSE); |
5560 gtk_tree_view_column_add_attribute(col, rend, "pixbuf", z+2); | 5564 gtk_tree_view_column_add_attribute(col, rend, "pixbuf", z+_DW_CONTAINER_STORE_EXTRA+1); |
5561 } | 5565 } |
5562 else if(flags[z] & DW_CFA_STRING) | 5566 else if(flags[z] & DW_CFA_STRING) |
5563 { | 5567 { |
5564 rend = gtk_cell_renderer_text_new(); | 5568 rend = gtk_cell_renderer_text_new(); |
5565 gtk_tree_view_column_pack_start(col, rend, TRUE); | 5569 gtk_tree_view_column_pack_start(col, rend, TRUE); |
5566 gtk_tree_view_column_add_attribute(col, rend, "text", z+2); | 5570 gtk_tree_view_column_add_attribute(col, rend, "text", z+_DW_CONTAINER_STORE_EXTRA+1); |
5567 gtk_tree_view_column_set_resizable(col, TRUE); | 5571 gtk_tree_view_column_set_resizable(col, TRUE); |
5568 } | 5572 } |
5569 else if(flags[z] & DW_CFA_ULONG) | 5573 else if(flags[z] & DW_CFA_ULONG) |
5570 { | 5574 { |
5571 rend = gtk_cell_renderer_text_new(); | 5575 rend = gtk_cell_renderer_text_new(); |
5572 gtk_tree_view_column_pack_start(col, rend, TRUE); | 5576 gtk_tree_view_column_pack_start(col, rend, TRUE); |
5573 gtk_tree_view_column_add_attribute(col, rend, "text", z+2); | 5577 gtk_tree_view_column_add_attribute(col, rend, "text", z+_DW_CONTAINER_STORE_EXTRA+1); |
5574 gtk_tree_view_column_set_resizable(col, TRUE); | 5578 gtk_tree_view_column_set_resizable(col, TRUE); |
5575 } | 5579 } |
5576 else if(flags[z] & DW_CFA_TIME) | 5580 else if(flags[z] & DW_CFA_TIME) |
5577 { | 5581 { |
5578 rend = gtk_cell_renderer_text_new(); | 5582 rend = gtk_cell_renderer_text_new(); |
5579 gtk_tree_view_column_pack_start(col, rend, TRUE); | 5583 gtk_tree_view_column_pack_start(col, rend, TRUE); |
5580 gtk_tree_view_column_add_attribute(col, rend, "text", z+2); | 5584 gtk_tree_view_column_add_attribute(col, rend, "text", z+_DW_CONTAINER_STORE_EXTRA+1); |
5581 gtk_tree_view_column_set_resizable(col, TRUE); | 5585 gtk_tree_view_column_set_resizable(col, TRUE); |
5582 } | 5586 } |
5583 else if(flags[z] & DW_CFA_DATE) | 5587 else if(flags[z] & DW_CFA_DATE) |
5584 { | 5588 { |
5585 rend = gtk_cell_renderer_text_new(); | 5589 rend = gtk_cell_renderer_text_new(); |
5586 gtk_tree_view_column_pack_start(col, rend, TRUE); | 5590 gtk_tree_view_column_pack_start(col, rend, TRUE); |
5587 gtk_tree_view_column_add_attribute(col, rend, "text", z+2); | 5591 gtk_tree_view_column_add_attribute(col, rend, "text", z+_DW_CONTAINER_STORE_EXTRA+1); |
5588 gtk_tree_view_column_set_resizable(col, TRUE); | 5592 gtk_tree_view_column_set_resizable(col, TRUE); |
5589 } | 5593 } |
5590 g_object_set_data(G_OBJECT(col), "_dw_column", GINT_TO_POINTER(z)); | 5594 g_object_set_data(G_OBJECT(col), "_dw_column", GINT_TO_POINTER(z)); |
5591 params[2] = tree; | 5595 params[2] = tree; |
5592 g_signal_connect_data(G_OBJECT(col), "clicked", G_CALLBACK(_column_click_event), (gpointer)params, _dw_signal_disconnect, 0); | 5596 g_signal_connect_data(G_OBJECT(col), "clicked", G_CALLBACK(_column_click_event), (gpointer)params, _dw_signal_disconnect, 0); |
5885 void **thisdata = (void **)data; | 5889 void **thisdata = (void **)data; |
5886 HICN hicon = data ? *((HICN *)thisdata[0]) : 0; | 5890 HICN hicon = data ? *((HICN *)thisdata[0]) : 0; |
5887 char *tmp = data ? (char *)thisdata[1] : NULL; | 5891 char *tmp = data ? (char *)thisdata[1] : NULL; |
5888 GdkPixbuf *pixbuf = hicon ? _find_pixbuf(hicon, NULL, NULL) : NULL; | 5892 GdkPixbuf *pixbuf = hicon ? _find_pixbuf(hicon, NULL, NULL) : NULL; |
5889 | 5893 |
5890 gtk_list_store_set(store, &iter, 1, pixbuf, -1); | 5894 gtk_list_store_set(store, &iter, _DW_CONTAINER_STORE_EXTRA, pixbuf, -1); |
5891 gtk_list_store_set(store, &iter, 2, tmp, -1); | 5895 gtk_list_store_set(store, &iter, _DW_CONTAINER_STORE_EXTRA + 1, tmp, -1); |
5892 } | 5896 } |
5893 else if(flag & DW_CFA_BITMAPORICON) | 5897 else if(flag & DW_CFA_BITMAPORICON) |
5894 { | 5898 { |
5895 HICN hicon = data ? *((HICN *)data) : 0; | 5899 HICN hicon = data ? *((HICN *)data) : 0; |
5896 GdkPixbuf *pixbuf = hicon ? _find_pixbuf(hicon, NULL, NULL) : NULL; | 5900 GdkPixbuf *pixbuf = hicon ? _find_pixbuf(hicon, NULL, NULL) : NULL; |
5897 | 5901 |
5898 gtk_list_store_set(store, &iter, column + 2, pixbuf, -1); | 5902 gtk_list_store_set(store, &iter, column + _DW_CONTAINER_STORE_EXTRA + 1, pixbuf, -1); |
5899 } | 5903 } |
5900 else if(flag & DW_CFA_STRING) | 5904 else if(flag & DW_CFA_STRING) |
5901 { | 5905 { |
5902 char *tmp = data ? *((char **)data) : NULL; | 5906 char *tmp = data ? *((char **)data) : NULL; |
5903 gtk_list_store_set(store, &iter, column + 2, tmp, -1); | 5907 gtk_list_store_set(store, &iter, column + _DW_CONTAINER_STORE_EXTRA + 1, tmp, -1); |
5904 } | 5908 } |
5905 else if(flag & DW_CFA_ULONG) | 5909 else if(flag & DW_CFA_ULONG) |
5906 { | 5910 { |
5907 ULONG tmp = data ? *((ULONG *)data): 0; | 5911 ULONG tmp = data ? *((ULONG *)data): 0; |
5908 | 5912 |
5909 gtk_list_store_set(store, &iter, column + 2, tmp, -1); | 5913 gtk_list_store_set(store, &iter, column + _DW_CONTAINER_STORE_EXTRA + 1, tmp, -1); |
5910 } | 5914 } |
5911 else if(flag & DW_CFA_DATE) | 5915 else if(flag & DW_CFA_DATE) |
5912 { | 5916 { |
5913 if(data) | 5917 if(data) |
5914 { | 5918 { |
5920 curtm.tm_mon = cdate.month - 1; | 5924 curtm.tm_mon = cdate.month - 1; |
5921 curtm.tm_year = cdate.year - 1900; | 5925 curtm.tm_year = cdate.year - 1900; |
5922 | 5926 |
5923 strftime(textbuffer, 100, "%x", &curtm); | 5927 strftime(textbuffer, 100, "%x", &curtm); |
5924 } | 5928 } |
5925 gtk_list_store_set(store, &iter, column + 2, textbuffer, -1); | 5929 gtk_list_store_set(store, &iter, column + _DW_CONTAINER_STORE_EXTRA + 1, textbuffer, -1); |
5926 } | 5930 } |
5927 else if(flag & DW_CFA_TIME) | 5931 else if(flag & DW_CFA_TIME) |
5928 { | 5932 { |
5929 if(data) | 5933 if(data) |
5930 { | 5934 { |
5936 curtm.tm_min = ctime.minutes; | 5940 curtm.tm_min = ctime.minutes; |
5937 curtm.tm_sec = ctime.seconds; | 5941 curtm.tm_sec = ctime.seconds; |
5938 | 5942 |
5939 strftime(textbuffer, 100, "%X", &curtm); | 5943 strftime(textbuffer, 100, "%X", &curtm); |
5940 } | 5944 } |
5941 gtk_list_store_set(store, &iter, column + 2, textbuffer, -1); | 5945 gtk_list_store_set(store, &iter, column + _DW_CONTAINER_STORE_EXTRA + 1, textbuffer, -1); |
5942 } | 5946 } |
5943 } | 5947 } |
5944 } | 5948 } |
5945 DW_MUTEX_UNLOCK; | 5949 DW_MUTEX_UNLOCK; |
5946 } | 5950 } |
6134 } | 6138 } |
6135 DW_MUTEX_UNLOCK; | 6139 DW_MUTEX_UNLOCK; |
6136 } | 6140 } |
6137 | 6141 |
6138 /* Internal version for both */ | 6142 /* Internal version for both */ |
6139 void _dw_container_set_row_title(HWND handle, void *pointer, int row, char *title) | 6143 #define _DW_DATA_TYPE_STRING 0 |
6144 #define _DW_DATA_TYPE_POINTER 1 | |
6145 | |
6146 void _dw_container_set_row_data(HWND handle, void *pointer, int row, int type, void *data) | |
6140 { | 6147 { |
6141 GtkWidget *cont = handle; | 6148 GtkWidget *cont = handle; |
6142 GtkListStore *store = NULL; | 6149 GtkListStore *store = NULL; |
6143 int _locked_by_me = FALSE; | 6150 int _locked_by_me = FALSE; |
6144 | 6151 |
6156 row += GPOINTER_TO_INT(g_object_get_data(G_OBJECT(cont), "_dw_insertpos")); | 6163 row += GPOINTER_TO_INT(g_object_get_data(G_OBJECT(cont), "_dw_insertpos")); |
6157 } | 6164 } |
6158 | 6165 |
6159 if(gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(store), &iter, NULL, row)) | 6166 if(gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(store), &iter, NULL, row)) |
6160 { | 6167 { |
6161 gtk_list_store_set(store, &iter, 0, (gpointer)title, -1); | 6168 gtk_list_store_set(store, &iter, type, (gpointer)data, -1); |
6162 } | 6169 } |
6163 } | 6170 } |
6164 DW_MUTEX_UNLOCK; | 6171 DW_MUTEX_UNLOCK; |
6165 } | 6172 } |
6166 | 6173 |
6171 * row: Zero based row of data being set. | 6178 * row: Zero based row of data being set. |
6172 * title: String title of the item. | 6179 * title: String title of the item. |
6173 */ | 6180 */ |
6174 void dw_container_set_row_title(void *pointer, int row, char *title) | 6181 void dw_container_set_row_title(void *pointer, int row, char *title) |
6175 { | 6182 { |
6176 _dw_container_set_row_title(pointer, pointer, row, title); | 6183 _dw_container_set_row_data(pointer, pointer, row, _DW_DATA_TYPE_STRING, title); |
6177 } | 6184 } |
6178 | 6185 |
6179 /* | 6186 /* |
6180 * Changes the title of a row already inserted in the container. | 6187 * Changes the title of a row already inserted in the container. |
6181 * Parameters: | 6188 * Parameters: |
6183 * row: Zero based row of data being set. | 6190 * row: Zero based row of data being set. |
6184 * title: String title of the item. | 6191 * title: String title of the item. |
6185 */ | 6192 */ |
6186 void dw_container_change_row_title(HWND handle, int row, char *title) | 6193 void dw_container_change_row_title(HWND handle, int row, char *title) |
6187 { | 6194 { |
6188 _dw_container_set_row_title(handle, NULL, row, title); | 6195 _dw_container_set_row_data(handle, NULL, row, _DW_DATA_TYPE_STRING, title); |
6196 } | |
6197 | |
6198 /* | |
6199 * Sets the title of a row in the container. | |
6200 * Parameters: | |
6201 * pointer: Pointer to the allocated memory in dw_container_alloc(). | |
6202 * row: Zero based row of data being set. | |
6203 * title: String title of the item. | |
6204 */ | |
6205 void dw_container_set_row_data(void *pointer, int row, void *data) | |
6206 { | |
6207 _dw_container_set_row_data(pointer, pointer, row, _DW_DATA_TYPE_POINTER, data); | |
6208 } | |
6209 | |
6210 /* | |
6211 * Changes the title of a row already inserted in the container. | |
6212 * Parameters: | |
6213 * handle: Handle to window (widget) of container. | |
6214 * row: Zero based row of data being set. | |
6215 * title: String title of the item. | |
6216 */ | |
6217 void dw_container_change_row_data(HWND handle, int row, void *data) | |
6218 { | |
6219 _dw_container_set_row_data(handle, NULL, row, _DW_DATA_TYPE_POINTER, data); | |
6189 } | 6220 } |
6190 | 6221 |
6191 /* | 6222 /* |
6192 * Sets the title of a row in the container. | 6223 * Sets the title of a row in the container. |
6193 * Parameters: | 6224 * Parameters: |
6506 } | 6537 } |
6507 DW_MUTEX_UNLOCK; | 6538 DW_MUTEX_UNLOCK; |
6508 return retval; | 6539 return retval; |
6509 } | 6540 } |
6510 | 6541 |
6511 int _find_iter(GtkListStore *store, GtkTreeIter *iter, char *text, int textcomp) | 6542 int _find_iter(GtkListStore *store, GtkTreeIter *iter, void *data, int textcomp) |
6512 { | 6543 { |
6513 int z, rows = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(store), NULL); | 6544 int z, rows = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(store), NULL); |
6514 char *thistext; | 6545 void *thisdata; |
6515 | 6546 |
6516 for(z=0;z<rows;z++) | 6547 for(z=0;z<rows;z++) |
6517 { | 6548 { |
6518 if(gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(store), iter, NULL, z)) | 6549 if(gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(store), iter, NULL, z)) |
6519 { | 6550 { |
6520 gtk_tree_model_get(GTK_TREE_MODEL(store), iter, 0, &thistext, -1); | 6551 /* Get either string from position 0 or pointer from position 1 */ |
6521 if((textcomp && thistext && strcmp(thistext, text) == 0) || (!textcomp && thistext == text)) | 6552 gtk_tree_model_get(GTK_TREE_MODEL(store), iter, textcomp ? 0 : 1, &thisdata, -1); |
6553 if((textcomp && thisdata && strcmp((char *)thisdata, (char *)data) == 0) || (!textcomp && thisdata == data)) | |
6522 { | 6554 { |
6523 return TRUE; | 6555 return TRUE; |
6524 } | 6556 } |
6525 } | 6557 } |
6526 } | 6558 } |
6527 return FALSE; | 6559 return FALSE; |
6528 } | 6560 } |
6529 | 6561 |
6530 /* | 6562 void _dw_container_cursor(HWND handle, void *data, int textcomp) |
6531 * Cursors the item with the text speficied, and scrolls to that item. | |
6532 * Parameters: | |
6533 * handle: Handle to the window (widget) to be queried. | |
6534 * text: Text usually returned by dw_container_query(). | |
6535 */ | |
6536 void dw_container_cursor(HWND handle, char *text) | |
6537 { | 6563 { |
6538 GtkWidget *cont; | 6564 GtkWidget *cont; |
6539 GtkListStore *store = NULL; | 6565 GtkListStore *store = NULL; |
6540 int textcomp, _locked_by_me = FALSE; | 6566 int _locked_by_me = FALSE; |
6541 | 6567 |
6542 DW_MUTEX_LOCK; | 6568 DW_MUTEX_LOCK; |
6543 cont = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_user"); | 6569 cont = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_user"); |
6544 textcomp = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(handle), "_dw_textcomp")); | |
6545 | 6570 |
6546 /* Make sure it is the correct tree type */ | 6571 /* Make sure it is the correct tree type */ |
6547 if(cont && GTK_IS_TREE_VIEW(cont) && g_object_get_data(G_OBJECT(cont), "_dw_tree_type") == GINT_TO_POINTER(_DW_TREE_TYPE_CONTAINER)) | 6572 if(cont && GTK_IS_TREE_VIEW(cont) && g_object_get_data(G_OBJECT(cont), "_dw_tree_type") == GINT_TO_POINTER(_DW_TREE_TYPE_CONTAINER)) |
6548 store = (GtkListStore *)gtk_tree_view_get_model(GTK_TREE_VIEW(cont)); | 6573 store = (GtkListStore *)gtk_tree_view_get_model(GTK_TREE_VIEW(cont)); |
6549 | 6574 |
6550 if(store) | 6575 if(store) |
6551 { | 6576 { |
6552 GtkTreeIter iter; | 6577 GtkTreeIter iter; |
6553 | 6578 |
6554 if(_find_iter(store, &iter, text, textcomp)) | 6579 if(_find_iter(store, &iter, data, textcomp)) |
6555 { | 6580 { |
6556 GtkTreePath *path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter); | 6581 GtkTreePath *path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter); |
6557 | 6582 |
6558 if(path) | 6583 if(path) |
6559 { | 6584 { |
6564 } | 6589 } |
6565 DW_MUTEX_UNLOCK; | 6590 DW_MUTEX_UNLOCK; |
6566 } | 6591 } |
6567 | 6592 |
6568 /* | 6593 /* |
6569 * Deletes the item with the text speficied. | 6594 * Cursors the item with the text speficied, and scrolls to that item. |
6570 * Parameters: | 6595 * Parameters: |
6571 * handle: Handle to the window (widget). | 6596 * handle: Handle to the window (widget) to be queried. |
6572 * text: Text usually returned by dw_container_query(). | 6597 * text: Text usually returned by dw_container_query(). |
6573 */ | 6598 */ |
6574 void dw_container_delete_row(HWND handle, char *text) | 6599 void dw_container_cursor(HWND handle, char *text) |
6600 { | |
6601 _dw_container_cursor(handle, text, TRUE); | |
6602 } | |
6603 | |
6604 /* | |
6605 * Cursors the item with the text speficied, and scrolls to that item. | |
6606 * Parameters: | |
6607 * handle: Handle to the window (widget) to be queried. | |
6608 * text: Text usually returned by dw_container_query(). | |
6609 */ | |
6610 void dw_container_cursor_by_data(HWND handle, void *data) | |
6611 { | |
6612 _dw_container_cursor(handle, data, FALSE); | |
6613 } | |
6614 | |
6615 void _dw_container_delete_row(HWND handle, void *data, int textcomp) | |
6575 { | 6616 { |
6576 GtkWidget *cont; | 6617 GtkWidget *cont; |
6577 GtkListStore *store = NULL; | 6618 GtkListStore *store = NULL; |
6578 int textcomp, _locked_by_me = FALSE; | 6619 int _locked_by_me = FALSE; |
6579 | 6620 |
6580 DW_MUTEX_LOCK; | 6621 DW_MUTEX_LOCK; |
6581 cont = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_user"); | 6622 cont = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_user"); |
6582 textcomp = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(handle), "_dw_textcomp")); | |
6583 | 6623 |
6584 /* Make sure it is the correct tree type */ | 6624 /* Make sure it is the correct tree type */ |
6585 if(cont && GTK_IS_TREE_VIEW(cont) && g_object_get_data(G_OBJECT(cont), "_dw_tree_type") == GINT_TO_POINTER(_DW_TREE_TYPE_CONTAINER)) | 6625 if(cont && GTK_IS_TREE_VIEW(cont) && g_object_get_data(G_OBJECT(cont), "_dw_tree_type") == GINT_TO_POINTER(_DW_TREE_TYPE_CONTAINER)) |
6586 store = (GtkListStore *)gtk_tree_view_get_model(GTK_TREE_VIEW(cont)); | 6626 store = (GtkListStore *)gtk_tree_view_get_model(GTK_TREE_VIEW(cont)); |
6587 | 6627 |
6588 if(store) | 6628 if(store) |
6589 { | 6629 { |
6590 GtkTreeIter iter; | 6630 GtkTreeIter iter; |
6591 int rows = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(cont), "_dw_rowcount")); | 6631 int rows = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(cont), "_dw_rowcount")); |
6592 | 6632 |
6593 if(_find_iter(store, &iter, text, textcomp)) | 6633 if(_find_iter(store, &iter, data, textcomp)) |
6594 { | 6634 { |
6595 gtk_list_store_remove(store, &iter); | 6635 gtk_list_store_remove(store, &iter); |
6596 rows--; | 6636 rows--; |
6597 } | 6637 } |
6598 | 6638 |
6599 g_object_set_data(G_OBJECT(cont), "_dw_rowcount", GINT_TO_POINTER(rows)); | 6639 g_object_set_data(G_OBJECT(cont), "_dw_rowcount", GINT_TO_POINTER(rows)); |
6600 } | 6640 } |
6601 DW_MUTEX_UNLOCK; | 6641 DW_MUTEX_UNLOCK; |
6642 } | |
6643 | |
6644 /* | |
6645 * Deletes the item with the text speficied. | |
6646 * Parameters: | |
6647 * handle: Handle to the window (widget). | |
6648 * text: Text usually returned by dw_container_query(). | |
6649 */ | |
6650 void dw_container_delete_row(HWND handle, char *text) | |
6651 { | |
6652 _dw_container_delete_row(handle, text, TRUE); | |
6653 } | |
6654 | |
6655 /* | |
6656 * Deletes the item with the text speficied. | |
6657 * Parameters: | |
6658 * handle: Handle to the window (widget). | |
6659 * text: Text usually returned by dw_container_query(). | |
6660 */ | |
6661 void dw_container_delete_row_by_data(HWND handle, void *data) | |
6662 { | |
6663 _dw_container_delete_row(handle, data, FALSE); | |
6602 } | 6664 } |
6603 | 6665 |
6604 /* | 6666 /* |
6605 * Optimizes the column widths so that all data is visible. | 6667 * Optimizes the column widths so that all data is visible. |
6606 * Parameters: | 6668 * Parameters: |