comparison gtk/dw.c @ 1289:5fb54aeba5e0

Allow removing icons from containers on GTK2. Also a small performance helper in both GTK versions.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Mon, 31 Oct 2011 11:04:03 +0000
parents 8cb3650eb242
children b99b0b2c2826
comparison
equal deleted inserted replaced
1288:d10969835d2d 1289:5fb54aeba5e0
129 pthread_key_t _dw_fg_color_key; 129 pthread_key_t _dw_fg_color_key;
130 pthread_key_t _dw_bg_color_key; 130 pthread_key_t _dw_bg_color_key;
131 pthread_key_t _dw_mutex_key; 131 pthread_key_t _dw_mutex_key;
132 132
133 GtkWidget *last_window = NULL, *popup = NULL; 133 GtkWidget *last_window = NULL, *popup = NULL;
134 GdkPixmap *_dw_tmppixmap = NULL;
135 GdkBitmap *_dw_tmpbitmap = NULL;
134 136
135 #if GTK_MAJOR_VERSION < 2 137 #if GTK_MAJOR_VERSION < 2
136 static int _dw_file_active = 0; 138 static int _dw_file_active = 0;
137 #endif 139 #endif
138 static int _dw_ignore_click = 0, _dw_ignore_expand = 0, _dw_color_active = 0; 140 static int _dw_ignore_click = 0, _dw_ignore_expand = 0, _dw_color_active = 0;
1866 static GdkPixmap *_find_pixmap(GdkBitmap **bitmap, HICN icon, HWND handle, unsigned long *userwidth, unsigned long *userheight) 1868 static GdkPixmap *_find_pixmap(GdkBitmap **bitmap, HICN icon, HWND handle, unsigned long *userwidth, unsigned long *userheight)
1867 { 1869 {
1868 char *data = NULL; 1870 char *data = NULL;
1869 int z, id = GPOINTER_TO_INT(icon); 1871 int z, id = GPOINTER_TO_INT(icon);
1870 1872
1873 /* Quick dropout for non-handle */
1874 if(!icon)
1875 return NULL;
1876
1871 if(id & (1 << 31)) 1877 if(id & (1 << 31))
1872 return _find_private_pixmap(bitmap, GINT_TO_POINTER((id & 0xFFFFFF)), userwidth, userheight); 1878 return _find_private_pixmap(bitmap, GINT_TO_POINTER((id & 0xFFFFFF)), userwidth, userheight);
1873 1879
1874 for(z=0;z<_resources.resource_max;z++) 1880 for(z=0;z<_resources.resource_max;z++)
1875 { 1881 {
1915 1921
1916 static GdkPixbuf *_find_pixbuf(HICN icon) 1922 static GdkPixbuf *_find_pixbuf(HICN icon)
1917 { 1923 {
1918 char *data = NULL; 1924 char *data = NULL;
1919 int z, id = GPOINTER_TO_INT(icon); 1925 int z, id = GPOINTER_TO_INT(icon);
1926
1927 /* Quick dropout for non-handle */
1928 if(!icon)
1929 return NULL;
1920 1930
1921 if(id & (1 << 31)) 1931 if(id & (1 << 31))
1922 return _find_private_pixbuf(GINT_TO_POINTER((id & 0xFFFFFF))); 1932 return _find_private_pixbuf(GINT_TO_POINTER((id & 0xFFFFFF)));
1923 1933
1924 for(z=0;z<_resources.resource_max;z++) 1934 for(z=0;z<_resources.resource_max;z++)
2065 int dw_int_init(DWResources *res, int newthread, int *argc, char **argv[]) 2075 int dw_int_init(DWResources *res, int newthread, int *argc, char **argv[])
2066 { 2076 {
2067 int z; 2077 int z;
2068 char *tmp; 2078 char *tmp;
2069 char *fname; 2079 char *fname;
2080 static char * test_xpm[] = {
2081 "1 1 1 1",
2082 " c None",
2083 " "};
2070 2084
2071 if(res) 2085 if(res)
2072 { 2086 {
2073 _resources.resource_max = res->resource_max; 2087 _resources.resource_max = res->resource_max;
2074 _resources.resource_id = res->resource_id; 2088 _resources.resource_id = res->resource_id;
2113 #endif 2127 #endif
2114 2128
2115 #ifdef USE_WEBKIT 2129 #ifdef USE_WEBKIT
2116 init_webkit(); 2130 init_webkit();
2117 #endif 2131 #endif
2132
2133 /* Create place holder pixmap/bitmap when one is needed by the API...
2134 * but we don't really want to display anything.
2135 */
2136 #if GTK_MAJOR_VERSION > 1
2137 {
2138 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_xpm_data((const char **)test_xpm);
2139
2140 gdk_pixbuf_render_pixmap_and_mask(pixbuf, &_dw_tmppixmap, &_dw_tmpbitmap, 1);
2141 g_object_unref(pixbuf);
2142 }
2143 #elif defined(USE_IMLIB)
2144 gdk_imlib_data_to_pixmap((char **)test_xpm, &_dw_tmppixmap, &_dw_tmpbitmap);
2145 #else
2146 {
2147 GtkWidget *handle = gtk_label_new("");
2148 gtk_widget_realize(handle);
2149 _dw_tmppixmap = gdk_pixmap_create_from_xpm_d(handle->window, &_dw_tmpbitmap, &_colors[DW_CLR_PALEGRAY], (char **)test_xpm);
2150 gtk_widget_destroy(handle);
2151 }
2152 #endif
2153
2118 /* 2154 /*
2119 * Setup logging/debugging 2155 * Setup logging/debugging
2120 */ 2156 */
2121 if ( (fname = getenv( "DWINDOWS_DEBUGFILE" ) ) != NULL ) 2157 if ( (fname = getenv( "DWINDOWS_DEBUGFILE" ) ) != NULL )
2122 { 2158 {
3502 * Parameters: 3538 * Parameters:
3503 * id: An ID to be used with dw_window_from_id() or 0L. 3539 * id: An ID to be used with dw_window_from_id() or 0L.
3504 */ 3540 */
3505 HWND dw_bitmap_new(unsigned long id) 3541 HWND dw_bitmap_new(unsigned long id)
3506 { 3542 {
3507 #if GTK_MAJOR_VERSION < 2
3508 GdkPixmap *pixmap = NULL;
3509 GdkBitmap *bitmap = NULL;
3510 static char * test_xpm[] = {
3511 "1 1 2 1",
3512 " c None",
3513 ". c #FFFFFF",
3514 "."};
3515 #endif
3516 GtkWidget *tmp; 3543 GtkWidget *tmp;
3517 int _locked_by_me = FALSE; 3544 int _locked_by_me = FALSE;
3518 3545
3519 DW_MUTEX_LOCK; 3546 DW_MUTEX_LOCK;
3520 #if GTK_MAJOR_VERSION > 1 3547 #if GTK_MAJOR_VERSION > 1
3521 tmp = gtk_image_new(); 3548 tmp = gtk_image_new();
3522 #elif defined(USE_IMLIB)
3523 gdk_imlib_data_to_pixmap(test_xpm, &pixmap, &bitmap);
3524 #else 3549 #else
3525 gtk_widget_realize(last_window); 3550 tmp = gtk_pixmap_new(_dw_tmppixmap, _dw_tmpbitmap);
3526
3527 if(last_window)
3528 pixmap = gdk_pixmap_create_from_xpm_d(last_window->window, &bitmap, &_colors[DW_CLR_PALEGRAY], test_xpm);
3529 #endif
3530 #if GTK_MAJOR_VERSION < 2
3531 tmp = gtk_pixmap_new(pixmap, bitmap);
3532 #endif 3551 #endif
3533 gtk_widget_show(tmp); 3552 gtk_widget_show(tmp);
3534 gtk_object_set_data(GTK_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id)); 3553 gtk_object_set_data(GTK_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id));
3535 DW_MUTEX_UNLOCK; 3554 DW_MUTEX_UNLOCK;
3536 return tmp; 3555 return tmp;
6948 { 6967 {
6949 HICN hicon = *((HICN *)data); 6968 HICN hicon = *((HICN *)data);
6950 GdkBitmap *bitmap = NULL; 6969 GdkBitmap *bitmap = NULL;
6951 GdkPixmap *pixmap = _find_pixmap(&bitmap, hicon, clist, NULL, NULL); 6970 GdkPixmap *pixmap = _find_pixmap(&bitmap, hicon, clist, NULL, NULL);
6952 6971
6953 if(pixmap) 6972 gtk_clist_set_pixmap(GTK_CLIST(clist), row, column, pixmap ? pixmap : _dw_tmppixmap, pixmap ? bitmap : _dw_tmpbitmap);
6954 gtk_clist_set_pixmap(GTK_CLIST(clist), row, column, pixmap, bitmap);
6955 } 6973 }
6956 else if(flag & DW_CFA_STRINGANDICON) 6974 else if(flag & DW_CFA_STRINGANDICON)
6957 { 6975 {
6958 HICN hicon = *((HICN *)data); 6976 HICN hicon = *((HICN *)data);
6959 GdkBitmap *bitmap = NULL; 6977 GdkBitmap *bitmap = NULL;
6960 GdkPixmap *pixmap = _find_pixmap(&bitmap, hicon, clist, NULL, NULL); 6978 GdkPixmap *pixmap = _find_pixmap(&bitmap, hicon, clist, NULL, NULL);
6961 6979
6962 if(pixmap) 6980 gtk_clist_set_pixtext(GTK_CLIST(clist), row, column, text, 2, pixmap ? pixmap : _dw_tmppixmap, pixmap ? bitmap : _dw_tmpbitmap);
6963 gtk_clist_set_pixtext(GTK_CLIST(clist), row, column, text, 2, pixmap, bitmap);
6964 } 6981 }
6965 else if(flag & DW_CFA_STRING) 6982 else if(flag & DW_CFA_STRING)
6966 { 6983 {
6967 char *tmp = *((char **)data); 6984 char *tmp = *((char **)data);
6968 gtk_clist_set_text(GTK_CLIST(clist), row, column, tmp); 6985 gtk_clist_set_text(GTK_CLIST(clist), row, column, tmp);