comparison gtk3/dw.c @ 883:63a8e77191c7

Experimental changes to the containers so filsystem icon and name are same column for GTK3. Also fixed warnings when querying a combobox that does not have a selected item.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 07 Apr 2011 07:18:45 +0000
parents d3693ceec9b1
children 0f99520041c4
comparison
equal deleted inserted replaced
882:1e7b7f870d88 883:63a8e77191c7
5329 g_object_set_data(G_OBJECT(handle), "_dw_cont_columns", GINT_TO_POINTER(count)); 5329 g_object_set_data(G_OBJECT(handle), "_dw_cont_columns", GINT_TO_POINTER(count));
5330 g_object_set_data(G_OBJECT(handle), "_dw_cont_extra", GINT_TO_POINTER(extra)); 5330 g_object_set_data(G_OBJECT(handle), "_dw_cont_extra", GINT_TO_POINTER(extra));
5331 5331
5332 /* First param is row title/data */ 5332 /* First param is row title/data */
5333 array[0] = G_TYPE_POINTER; 5333 array[0] = G_TYPE_POINTER;
5334 array[1] = G_TYPE_POINTER;
5334 /* First loop... create array to create the store */ 5335 /* First loop... create array to create the store */
5335 for(z=0;z<count;z++) 5336 for(z=0;z<count;z++)
5336 { 5337 {
5337 if(flags[z] & DW_CFA_BITMAPORICON) 5338 if(z == 0 && flags[z] & DW_CFA_STRINGANDICON)
5338 { 5339 {
5339 array[z+1] = GDK_TYPE_PIXBUF; 5340 array[1] = GDK_TYPE_PIXBUF;
5341 array[2] = G_TYPE_STRING;
5342 }
5343 else if(flags[z] & DW_CFA_BITMAPORICON)
5344 {
5345 array[z+2] = GDK_TYPE_PIXBUF;
5340 } 5346 }
5341 else if(flags[z] & DW_CFA_STRING) 5347 else if(flags[z] & DW_CFA_STRING)
5342 { 5348 {
5343 array[z+1] = G_TYPE_STRING; 5349 array[z+2] = G_TYPE_STRING;
5344 } 5350 }
5345 else if(flags[z] & DW_CFA_ULONG) 5351 else if(flags[z] & DW_CFA_ULONG)
5346 { 5352 {
5347 array[z+1] = G_TYPE_ULONG; 5353 array[z+2] = G_TYPE_ULONG;
5348 } 5354 }
5349 else if(flags[z] & DW_CFA_TIME) 5355 else if(flags[z] & DW_CFA_TIME)
5350 { 5356 {
5351 array[z+1] = G_TYPE_STRING; 5357 array[z+2] = G_TYPE_STRING;
5352 } 5358 }
5353 else if(flags[z] & DW_CFA_DATE) 5359 else if(flags[z] & DW_CFA_DATE)
5354 { 5360 {
5355 array[z+1] = G_TYPE_STRING; 5361 array[z+2] = G_TYPE_STRING;
5356 } 5362 }
5357 } 5363 }
5358 /* Create the store and then the tree */ 5364 /* Create the store and then the tree */
5359 store = gtk_list_store_newv(count+1, array); 5365 store = gtk_list_store_newv(count+2, array);
5360 tree = _tree_setup(handle, GTK_TREE_MODEL(store)); 5366 tree = _tree_setup(handle, GTK_TREE_MODEL(store));
5361 g_object_set_data(G_OBJECT(tree), "_dw_tree_type", (gpointer)_DW_TREE_TYPE_CONTAINER); 5367 g_object_set_data(G_OBJECT(tree), "_dw_tree_type", (gpointer)_DW_TREE_TYPE_CONTAINER);
5362 /* Second loop... create the columns */ 5368 /* Second loop... create the columns */
5363 for(z=0;z<count;z++) 5369 for(z=0;z<count;z++)
5364 { 5370 {
5365 sprintf(numbuf, "_dw_cont_col%d", z); 5371 sprintf(numbuf, "_dw_cont_col%d", z);
5366 g_object_set_data(G_OBJECT(tree), numbuf, GINT_TO_POINTER(flags[z])); 5372 g_object_set_data(G_OBJECT(tree), numbuf, GINT_TO_POINTER(flags[z]));
5367 col = gtk_tree_view_column_new(); 5373 col = gtk_tree_view_column_new();
5368 if(flags[z] & DW_CFA_BITMAPORICON) 5374 if(z == 0 && flags[z] & DW_CFA_STRINGANDICON)
5369 { 5375 {
5370 rend = gtk_cell_renderer_pixbuf_new(); 5376 rend = gtk_cell_renderer_pixbuf_new();
5371 gtk_tree_view_column_pack_start(col, rend, FALSE); 5377 gtk_tree_view_column_pack_start(col, rend, FALSE);
5372 gtk_tree_view_column_add_attribute(col, rend, "pixbuf", z+1); 5378 gtk_tree_view_column_add_attribute(col, rend, "pixbuf", 1);
5373 }
5374 else if(flags[z] & DW_CFA_STRING)
5375 {
5376 rend = gtk_cell_renderer_text_new(); 5379 rend = gtk_cell_renderer_text_new();
5377 gtk_tree_view_column_pack_start(col, rend, TRUE); 5380 gtk_tree_view_column_pack_start(col, rend, TRUE);
5378 gtk_tree_view_column_add_attribute(col, rend, "text", z+1); 5381 gtk_tree_view_column_add_attribute(col, rend, "text", 2);
5379 gtk_tree_view_column_set_resizable(col, TRUE); 5382 }
5380 } 5383 else if(flags[z] & DW_CFA_BITMAPORICON)
5381 else if(flags[z] & DW_CFA_ULONG) 5384 {
5385 rend = gtk_cell_renderer_pixbuf_new();
5386 gtk_tree_view_column_pack_start(col, rend, FALSE);
5387 gtk_tree_view_column_add_attribute(col, rend, "pixbuf", z+2);
5388 }
5389 else if(flags[z] & DW_CFA_STRING)
5382 { 5390 {
5383 rend = gtk_cell_renderer_text_new(); 5391 rend = gtk_cell_renderer_text_new();
5384 gtk_tree_view_column_pack_start(col, rend, TRUE); 5392 gtk_tree_view_column_pack_start(col, rend, TRUE);
5385 gtk_tree_view_column_add_attribute(col, rend, "text", z+1); 5393 gtk_tree_view_column_add_attribute(col, rend, "text", z+2);
5386 gtk_tree_view_column_set_resizable(col, TRUE); 5394 gtk_tree_view_column_set_resizable(col, TRUE);
5387 } 5395 }
5388 else if(flags[z] & DW_CFA_TIME) 5396 else if(flags[z] & DW_CFA_ULONG)
5389 { 5397 {
5390 rend = gtk_cell_renderer_text_new(); 5398 rend = gtk_cell_renderer_text_new();
5391 gtk_tree_view_column_pack_start(col, rend, TRUE); 5399 gtk_tree_view_column_pack_start(col, rend, TRUE);
5392 gtk_tree_view_column_add_attribute(col, rend, "text", z+1); 5400 gtk_tree_view_column_add_attribute(col, rend, "text", z+2);
5393 gtk_tree_view_column_set_resizable(col, TRUE); 5401 gtk_tree_view_column_set_resizable(col, TRUE);
5394 } 5402 }
5395 else if(flags[z] & DW_CFA_DATE) 5403 else if(flags[z] & DW_CFA_TIME)
5396 { 5404 {
5397 rend = gtk_cell_renderer_text_new(); 5405 rend = gtk_cell_renderer_text_new();
5398 gtk_tree_view_column_pack_start(col, rend, TRUE); 5406 gtk_tree_view_column_pack_start(col, rend, TRUE);
5399 gtk_tree_view_column_add_attribute(col, rend, "text", z+1); 5407 gtk_tree_view_column_add_attribute(col, rend, "text", z+2);
5400 gtk_tree_view_column_set_resizable(col, TRUE); 5408 gtk_tree_view_column_set_resizable(col, TRUE);
5401 } 5409 }
5402 if(extra) 5410 else if(flags[z] & DW_CFA_DATE)
5403 { 5411 {
5404 if(extra > 1 && z > 1) 5412 rend = gtk_cell_renderer_text_new();
5405 { 5413 gtk_tree_view_column_pack_start(col, rend, TRUE);
5406 g_object_set_data(G_OBJECT(col), "_dw_column", GINT_TO_POINTER(z-1)); 5414 gtk_tree_view_column_add_attribute(col, rend, "text", z+2);
5407 } 5415 gtk_tree_view_column_set_resizable(col, TRUE);
5408 } 5416 }
5409 else 5417 g_object_set_data(G_OBJECT(col), "_dw_column", GINT_TO_POINTER(z));
5410 {
5411 g_object_set_data(G_OBJECT(col), "_dw_column", GINT_TO_POINTER(z));
5412 }
5413 g_signal_connect(G_OBJECT(col), "clicked", G_CALLBACK(_column_click_event), (gpointer)tree); 5418 g_signal_connect(G_OBJECT(col), "clicked", G_CALLBACK(_column_click_event), (gpointer)tree);
5414 gtk_tree_view_column_set_title(col, titles[z]); 5419 gtk_tree_view_column_set_title(col, titles[z]);
5415 gtk_tree_view_append_column(GTK_TREE_VIEW (tree), col); 5420 gtk_tree_view_append_column(GTK_TREE_VIEW (tree), col);
5416 } 5421 }
5417 /* Finish up */ 5422 /* Finish up */
5456 * titles: An array of strings with column text titles. 5461 * titles: An array of strings with column text titles.
5457 * count: The number of columns (this should match the arrays). 5462 * count: The number of columns (this should match the arrays).
5458 */ 5463 */
5459 int dw_filesystem_setup(HWND handle, unsigned long *flags, char **titles, int count) 5464 int dw_filesystem_setup(HWND handle, unsigned long *flags, char **titles, int count)
5460 { 5465 {
5461 char **newtitles = malloc(sizeof(char *) * (count + 2)); 5466 char **newtitles = malloc(sizeof(char *) * (count + 1));
5462 unsigned long *newflags = malloc(sizeof(unsigned long) * (count + 2)); 5467 unsigned long *newflags = malloc(sizeof(unsigned long) * (count + 1));
5463 5468
5464 newtitles[0] = "Icon"; 5469 newtitles[0] = "Filename";
5465 newflags[0] = DW_CFA_BITMAPORICON | DW_CFA_LEFT | DW_CFA_HORZSEPARATOR; 5470 newflags[0] = DW_CFA_STRINGANDICON | DW_CFA_LEFT | DW_CFA_HORZSEPARATOR;
5466 newtitles[1] = "Filename"; 5471
5467 newflags[1] = DW_CFA_STRING | DW_CFA_LEFT | DW_CFA_HORZSEPARATOR; 5472 memcpy(&newtitles[1], titles, sizeof(char *) * count);
5468 5473 memcpy(&newflags[1], flags, sizeof(unsigned long) * count);
5469 memcpy(&newtitles[2], titles, sizeof(char *) * count); 5474
5470 memcpy(&newflags[2], flags, sizeof(unsigned long) * count); 5475 _dw_container_setup(handle, newflags, newtitles, count + 1, 1, 1);
5471
5472 _dw_container_setup(handle, newflags, newtitles, count + 2, 1, 2);
5473 5476
5474 if ( newtitles) free(newtitles); 5477 if ( newtitles) free(newtitles);
5475 if ( newflags ) free(newflags); 5478 if ( newflags ) free(newflags);
5476 return TRUE; 5479 return TRUE;
5477 } 5480 }
5720 row += (int)g_object_get_data(G_OBJECT(cont), "_dw_insertpos"); 5723 row += (int)g_object_get_data(G_OBJECT(cont), "_dw_insertpos");
5721 } 5724 }
5722 5725
5723 if(gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(store), &iter, NULL, row)) 5726 if(gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(store), &iter, NULL, row))
5724 { 5727 {
5725 if(flag & DW_CFA_BITMAPORICON) 5728 if(flag & DW_CFA_STRINGANDICON)
5729 {
5730 void **thisdata = (void **)data;
5731 long hicon = *((long *)thisdata[0]);
5732 char *tmp = (char *)thisdata[1];
5733 GdkPixbuf *pixbuf = _find_pixbuf(hicon, NULL, NULL);
5734
5735 if(pixbuf)
5736 gtk_list_store_set(store, &iter, 1, pixbuf, -1);
5737
5738 gtk_list_store_set(store, &iter, 2, tmp, -1);
5739 }
5740 else if(flag & DW_CFA_BITMAPORICON)
5726 { 5741 {
5727 long hicon = *((long *)data); 5742 long hicon = *((long *)data);
5728 GdkPixbuf *pixbuf = _find_pixbuf(hicon, NULL, NULL); 5743 GdkPixbuf *pixbuf = _find_pixbuf(hicon, NULL, NULL);
5729 5744
5730 if(pixbuf) 5745 if(pixbuf)
5731 gtk_list_store_set(store, &iter, column + 1, pixbuf, -1); 5746 gtk_list_store_set(store, &iter, column + 2, pixbuf, -1);
5732 } 5747 }
5733 else if(flag & DW_CFA_STRING) 5748 else if(flag & DW_CFA_STRING)
5734 { 5749 {
5735 char *tmp = *((char **)data); 5750 char *tmp = *((char **)data);
5736 gtk_list_store_set(store, &iter, column + 1, tmp, -1); 5751 gtk_list_store_set(store, &iter, column + 2, tmp, -1);
5737 } 5752 }
5738 else if(flag & DW_CFA_ULONG) 5753 else if(flag & DW_CFA_ULONG)
5739 { 5754 {
5740 ULONG tmp = *((ULONG *)data); 5755 ULONG tmp = *((ULONG *)data);
5741 5756
5742 gtk_list_store_set(store, &iter, column + 1, tmp, -1); 5757 gtk_list_store_set(store, &iter, column + 2, tmp, -1);
5743 } 5758 }
5744 else if(flag & DW_CFA_DATE) 5759 else if(flag & DW_CFA_DATE)
5745 { 5760 {
5746 struct tm curtm; 5761 struct tm curtm;
5747 CDATE cdate = *((CDATE *)data); 5762 CDATE cdate = *((CDATE *)data);
5751 curtm.tm_mon = cdate.month - 1; 5766 curtm.tm_mon = cdate.month - 1;
5752 curtm.tm_year = cdate.year - 1900; 5767 curtm.tm_year = cdate.year - 1900;
5753 5768
5754 strftime(textbuffer, 100, "%x", &curtm); 5769 strftime(textbuffer, 100, "%x", &curtm);
5755 5770
5756 gtk_list_store_set(store, &iter, column + 1, textbuffer, -1); 5771 gtk_list_store_set(store, &iter, column + 2, textbuffer, -1);
5757 } 5772 }
5758 else if(flag & DW_CFA_TIME) 5773 else if(flag & DW_CFA_TIME)
5759 { 5774 {
5760 struct tm curtm; 5775 struct tm curtm;
5761 CTIME ctime = *((CTIME *)data); 5776 CTIME ctime = *((CTIME *)data);
5765 curtm.tm_min = ctime.minutes; 5780 curtm.tm_min = ctime.minutes;
5766 curtm.tm_sec = ctime.seconds; 5781 curtm.tm_sec = ctime.seconds;
5767 5782
5768 strftime(textbuffer, 100, "%X", &curtm); 5783 strftime(textbuffer, 100, "%X", &curtm);
5769 5784
5770 gtk_list_store_set(store, &iter, column + 1, textbuffer, -1); 5785 gtk_list_store_set(store, &iter, column + 2, textbuffer, -1);
5771 } 5786 }
5772 } 5787 }
5773 } 5788 }
5774 DW_MUTEX_UNLOCK; 5789 DW_MUTEX_UNLOCK;
5775 } 5790 }
5837 * row: Zero based row of data being set. 5852 * row: Zero based row of data being set.
5838 * data: Pointer to the data to be added. 5853 * data: Pointer to the data to be added.
5839 */ 5854 */
5840 void dw_filesystem_set_file(HWND handle, void *pointer, int row, char *filename, HICN icon) 5855 void dw_filesystem_set_file(HWND handle, void *pointer, int row, char *filename, HICN icon)
5841 { 5856 {
5842 _dw_container_set_item(handle, pointer, 0, row, (void *)&icon); 5857 void *data[2] = { (void *)&icon, (void *)filename };
5843 _dw_container_set_item(handle, pointer, 1, row, (void *)&filename); 5858
5859 _dw_container_set_item(handle, pointer, 0, row, (void *)data);
5844 } 5860 }
5845 5861
5846 /* 5862 /*
5847 * Sets an item in specified row and column to the given data. 5863 * Sets an item in specified row and column to the given data.
5848 * Parameters: 5864 * Parameters:
5852 * row: Zero based row of data being set. 5868 * row: Zero based row of data being set.
5853 * data: Pointer to the data to be added. 5869 * data: Pointer to the data to be added.
5854 */ 5870 */
5855 void dw_filesystem_set_item(HWND handle, void *pointer, int column, int row, void *data) 5871 void dw_filesystem_set_item(HWND handle, void *pointer, int column, int row, void *data)
5856 { 5872 {
5857 _dw_container_set_item(handle, pointer, column + 2, row, data); 5873 _dw_container_set_item(handle, pointer, column + 1, row, data);
5858 } 5874 }
5859 5875
5860 /* 5876 /*
5861 * Gets column type for a container column 5877 * Gets column type for a container column
5862 * Parameters: 5878 * Parameters:
5903 * handle: Handle to the container window (widget). 5919 * handle: Handle to the container window (widget).
5904 * column: Zero based column. 5920 * column: Zero based column.
5905 */ 5921 */
5906 int API dw_filesystem_get_column_type(HWND handle, int column) 5922 int API dw_filesystem_get_column_type(HWND handle, int column)
5907 { 5923 {
5908 return dw_container_get_column_type( handle, column + 2 ); 5924 return dw_container_get_column_type( handle, column + 1 );
5909 } 5925 }
5910 5926
5911 /* 5927 /*
5912 * Sets the width of a column in the container. 5928 * Sets the width of a column in the container.
5913 * Parameters: 5929 * Parameters:
5920 GtkWidget *cont; 5936 GtkWidget *cont;
5921 int _locked_by_me = FALSE; 5937 int _locked_by_me = FALSE;
5922 5938
5923 DW_MUTEX_LOCK; 5939 DW_MUTEX_LOCK;
5924 cont = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_user"); 5940 cont = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_user");
5925
5926 /* Handle filesystem */
5927 if(g_object_get_data(G_OBJECT(handle), "_dw_cont_extra"))
5928 {
5929 column++;
5930 }
5931 5941
5932 /* Make sure it is the correct tree type */ 5942 /* Make sure it is the correct tree type */
5933 if(cont && GTK_IS_TREE_VIEW(cont) && g_object_get_data(G_OBJECT(cont), "_dw_tree_type") == GINT_TO_POINTER(_DW_TREE_TYPE_CONTAINER)) 5943 if(cont && GTK_IS_TREE_VIEW(cont) && g_object_get_data(G_OBJECT(cont), "_dw_tree_type") == GINT_TO_POINTER(_DW_TREE_TYPE_CONTAINER))
5934 { 5944 {
5935 GtkTreeViewColumn *col = gtk_tree_view_get_column(GTK_TREE_VIEW(cont), column); 5945 GtkTreeViewColumn *col = gtk_tree_view_get_column(GTK_TREE_VIEW(cont), column);
9027 } 9037 }
9028 else 9038 else
9029 { 9039 {
9030 GtkTreeIter iter; 9040 GtkTreeIter iter;
9031 GtkTreePath *path; 9041 GtkTreePath *path;
9032 gint *indices;
9033 9042
9034 gtk_combo_box_get_active_iter(GTK_COMBO_BOX(handle2), &iter); 9043 if(gtk_combo_box_get_active_iter(GTK_COMBO_BOX(handle2), &iter))
9035 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter);
9036 indices = gtk_tree_path_get_indices(path);
9037
9038 if(indices)
9039 { 9044 {
9040 retval = indices[0]; 9045 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter);
9046 if(path)
9047 {
9048 gint *indices = gtk_tree_path_get_indices(path);
9049
9050 if(indices)
9051 {
9052 retval = indices[0];
9053 }
9054 gtk_tree_path_free(path);
9055 }
9041 } 9056 }
9042 gtk_tree_path_free(path);
9043 } 9057 }
9044 } 9058 }
9045 } 9059 }
9046 DW_MUTEX_UNLOCK; 9060 DW_MUTEX_UNLOCK;
9047 return retval; 9061 return retval;