comparison gtk/dw.c @ 121:d8af32b1b1cd

Switch back to using pixmaps and bitmaps, only use pixbufs for doing XPM conversion.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sat, 19 Oct 2002 21:48:57 +0000
parents 7d2108cbcd3e
children a05b6fb9c545
comparison
equal deleted inserted replaced
120:7d2108cbcd3e 121:d8af32b1b1cd
536 } 536 }
537 } 537 }
538 return TRUE; 538 return TRUE;
539 } 539 }
540 540
541 GdkPixmap *_find_pixmap(GdkBitmap **bitmap, long id, HWND handle) 541 GdkPixmap *_find_pixmap(GdkBitmap **bitmap, long id, HWND handle, unsigned long *userwidth, unsigned long *userheight)
542 { 542 {
543 char *data = NULL; 543 char *data = NULL;
544 int z; 544 int z;
545 545
546 for(z=0;z<_resources.resource_max;z++) 546 for(z=0;z<_resources.resource_max;z++)
554 554
555 if(data) 555 if(data)
556 { 556 {
557 GdkPixmap *icon_pixmap = NULL; 557 GdkPixmap *icon_pixmap = NULL;
558 #if GTK_MAJOR_VERSION > 1 558 #if GTK_MAJOR_VERSION > 1
559 icon_pixmap = (GdkPixmap *)gdk_pixbuf_new_from_xpm_data((const char **)data); 559 GdkPixbuf *icon_pixbuf = gdk_pixbuf_new_from_xpm_data((const char **)data);
560
561 if(userwidth)
562 *userwidth = gdk_pixbuf_get_width(icon_pixbuf);
563 if(userheight)
564 *userheight = gdk_pixbuf_get_height(icon_pixbuf);
565
566 gdk_pixbuf_render_pixmap_and_mask(icon_pixbuf, &icon_pixmap, bitmap, 1);
567 g_object_unref(icon_pixbuf);
560 #elif defined(USE_IMLIB) 568 #elif defined(USE_IMLIB)
561 gdk_imlib_data_to_pixmap((char **)data, &icon_pixmap, bitmap); 569 gdk_imlib_data_to_pixmap((char **)data, &icon_pixmap, bitmap);
562 #else 570 #else
563 icon_pixmap = gdk_pixmap_create_from_xpm_d(handle->window, bitmap, &_colors[DW_CLR_PALEGRAY], &data); 571 icon_pixmap = gdk_pixmap_create_from_xpm_d(handle->window, bitmap, &_colors[DW_CLR_PALEGRAY], (char **)data);
564 #endif 572 #endif
565 return icon_pixmap; 573 return icon_pixmap;
566 } 574 }
567 return NULL; 575 return NULL;
568 } 576 }
1468 * Parameters: 1476 * Parameters:
1469 * id: An ID to be used with WinWindowFromID() or 0L. 1477 * id: An ID to be used with WinWindowFromID() or 0L.
1470 */ 1478 */
1471 HWND dw_bitmap_new(unsigned long id) 1479 HWND dw_bitmap_new(unsigned long id)
1472 { 1480 {
1481 #if GTK_MAJOR_VERSION < 2
1473 GdkPixmap *pixmap = NULL; 1482 GdkPixmap *pixmap = NULL;
1474 GdkBitmap *bitmap = NULL; 1483 GdkBitmap *bitmap = NULL;
1475 GtkWidget *tmp;
1476 static char * test_xpm[] = { 1484 static char * test_xpm[] = {
1477 "1 1 2 1", 1485 "1 1 2 1",
1478 " c None", 1486 " c None",
1479 ". c #FFFFFF", 1487 ". c #FFFFFF",
1480 "."}; 1488 "."};
1489 #endif
1490 GtkWidget *tmp;
1481 int _locked_by_me = FALSE; 1491 int _locked_by_me = FALSE;
1482 1492
1483 DW_MUTEX_LOCK; 1493 DW_MUTEX_LOCK;
1484 #if GTK_MAJOR_VERSION > 1 1494 #if GTK_MAJOR_VERSION > 1
1485 pixmap = (GdkPixmap *)gdk_pixbuf_new_from_xpm_data((const char **)test_xpm); 1495 tmp = gtk_image_new();
1486 tmp = gtk_image_new_from_pixbuf((GdkPixbuf *)pixmap);
1487 #elif defined(USE_IMLIB) 1496 #elif defined(USE_IMLIB)
1488 gdk_imlib_data_to_pixmap(test_xpm, &pixmap, &bitmap); 1497 gdk_imlib_data_to_pixmap(test_xpm, &pixmap, &bitmap);
1489 #else 1498 #else
1490 gtk_widget_realize(last_window); 1499 gtk_widget_realize(last_window);
1491 1500
2254 GdkBitmap *bitmap = NULL; 2263 GdkBitmap *bitmap = NULL;
2255 GdkPixmap *icon_pixmap; 2264 GdkPixmap *icon_pixmap;
2256 int _locked_by_me = FALSE; 2265 int _locked_by_me = FALSE;
2257 2266
2258 DW_MUTEX_LOCK; 2267 DW_MUTEX_LOCK;
2259 icon_pixmap = _find_pixmap(&bitmap, id, handle); 2268 icon_pixmap = _find_pixmap(&bitmap, id, handle, NULL, NULL);
2260 2269
2261 if(handle->window && icon_pixmap) 2270 if(handle->window && icon_pixmap)
2262 #if GTK_MAJOR_VERSION > 1
2263 gtk_window_set_icon(GTK_WINDOW(handle), (GdkPixbuf *)icon_pixmap);
2264 #else
2265 gdk_window_set_icon(handle->window, NULL, icon_pixmap, bitmap); 2271 gdk_window_set_icon(handle->window, NULL, icon_pixmap, bitmap);
2266 #endif
2267 2272
2268 DW_MUTEX_UNLOCK; 2273 DW_MUTEX_UNLOCK;
2269 } 2274 }
2270 2275
2271 /* 2276 /*
2279 GdkBitmap *bitmap = NULL; 2284 GdkBitmap *bitmap = NULL;
2280 GdkPixmap *tmp; 2285 GdkPixmap *tmp;
2281 int _locked_by_me = FALSE; 2286 int _locked_by_me = FALSE;
2282 2287
2283 DW_MUTEX_LOCK; 2288 DW_MUTEX_LOCK;
2284 tmp = _find_pixmap(&bitmap, id, handle); 2289 tmp = _find_pixmap(&bitmap, id, handle, NULL, NULL);
2285 if(tmp) 2290 if(tmp)
2286 #if GTK_MAJOR_VERSION > 1 2291 #if GTK_MAJOR_VERSION > 1
2287 gtk_image_set_from_pixbuf(GTK_IMAGE(handle), (GdkPixbuf *)tmp); 2292 gtk_image_set_from_pixmap(GTK_IMAGE(handle), tmp, bitmap);
2288 #else 2293 #else
2289 gtk_pixmap_set(GTK_PIXMAP(handle), tmp, bitmap); 2294 gtk_pixmap_set(GTK_PIXMAP(handle), tmp, bitmap);
2290 #endif 2295 #endif
2291 DW_MUTEX_UNLOCK; 2296 DW_MUTEX_UNLOCK;
2292 } 2297 }
3068 gtk_object_set_data(GTK_OBJECT(newitem), "text", (gpointer)strdup(title)); 3073 gtk_object_set_data(GTK_OBJECT(newitem), "text", (gpointer)strdup(title));
3069 gtk_object_set_data(GTK_OBJECT(newitem), "itemdata", (gpointer)itemdata); 3074 gtk_object_set_data(GTK_OBJECT(newitem), "itemdata", (gpointer)itemdata);
3070 gtk_object_set_data(GTK_OBJECT(newitem), "tree", (gpointer)tree); 3075 gtk_object_set_data(GTK_OBJECT(newitem), "tree", (gpointer)tree);
3071 hbox = gtk_hbox_new(FALSE, 2); 3076 hbox = gtk_hbox_new(FALSE, 2);
3072 gtk_object_set_data(GTK_OBJECT(newitem), "hbox", (gpointer)hbox); 3077 gtk_object_set_data(GTK_OBJECT(newitem), "hbox", (gpointer)hbox);
3073 gdkpix = _find_pixmap(&gdkbmp, icon, hbox); 3078 gdkpix = _find_pixmap(&gdkbmp, icon, hbox, NULL, NULL);
3074 #if GTK_MAJOR_VERSION > 1 3079 #if GTK_MAJOR_VERSION > 1
3075 pixmap = gtk_image_new_from_pixbuf((GdkPixbuf *)gdkbmp); 3080 pixmap = gtk_image_new_from_pixmap(gdkpix, gdkbmp);
3076 #else 3081 #else
3077 pixmap = gtk_pixmap_new(gdkpix, gdkbmp); 3082 pixmap = gtk_pixmap_new(gdkpix, gdkbmp);
3078 #endif 3083 #endif
3079 gtk_container_add(GTK_CONTAINER(newitem), hbox); 3084 gtk_container_add(GTK_CONTAINER(newitem), hbox);
3080 gtk_box_pack_start(GTK_BOX(hbox), pixmap, FALSE, TRUE, 0); 3085 gtk_box_pack_start(GTK_BOX(hbox), pixmap, FALSE, TRUE, 0);
3157 gtk_object_set_data(GTK_OBJECT(item), "text", (gpointer)strdup(title)); 3162 gtk_object_set_data(GTK_OBJECT(item), "text", (gpointer)strdup(title));
3158 gtk_object_set_data(GTK_OBJECT(item), "itemdata", (gpointer)itemdata); 3163 gtk_object_set_data(GTK_OBJECT(item), "itemdata", (gpointer)itemdata);
3159 gtk_object_set_data(GTK_OBJECT(item), "tree", (gpointer)tree); 3164 gtk_object_set_data(GTK_OBJECT(item), "tree", (gpointer)tree);
3160 hbox = gtk_hbox_new(FALSE, 2); 3165 hbox = gtk_hbox_new(FALSE, 2);
3161 gtk_object_set_data(GTK_OBJECT(item), "hbox", (gpointer)hbox); 3166 gtk_object_set_data(GTK_OBJECT(item), "hbox", (gpointer)hbox);
3162 gdkpix = _find_pixmap(&gdkbmp, icon, hbox); 3167 gdkpix = _find_pixmap(&gdkbmp, icon, hbox, NULL, NULL);
3163 #if GTK_MAJOR_VERSION > 1 3168 #if GTK_MAJOR_VERSION > 1
3164 pixmap = gtk_image_new_from_pixbuf((GdkPixbuf *)gdkbmp); 3169 pixmap = gtk_image_new_from_pixmap(gdkpix, gdkbmp);
3165 #else 3170 #else
3166 pixmap = gtk_pixmap_new(gdkpix, gdkbmp); 3171 pixmap = gtk_pixmap_new(gdkpix, gdkbmp);
3167 #endif 3172 #endif
3168 gtk_container_add(GTK_CONTAINER(item), hbox); 3173 gtk_container_add(GTK_CONTAINER(item), hbox);
3169 gtk_box_pack_start(GTK_BOX(hbox), pixmap, FALSE, TRUE, 0); 3174 gtk_box_pack_start(GTK_BOX(hbox), pixmap, FALSE, TRUE, 0);
3242 gtk_object_set_data(GTK_OBJECT(item), "text", (gpointer)strdup(title)); 3247 gtk_object_set_data(GTK_OBJECT(item), "text", (gpointer)strdup(title));
3243 hbox = (GtkWidget *)gtk_object_get_data(GTK_OBJECT(item), "hbox"); 3248 hbox = (GtkWidget *)gtk_object_get_data(GTK_OBJECT(item), "hbox");
3244 gtk_widget_destroy(hbox); 3249 gtk_widget_destroy(hbox);
3245 hbox = gtk_hbox_new(FALSE, 2); 3250 hbox = gtk_hbox_new(FALSE, 2);
3246 gtk_object_set_data(GTK_OBJECT(item), "hbox", (gpointer)hbox); 3251 gtk_object_set_data(GTK_OBJECT(item), "hbox", (gpointer)hbox);
3247 gdkpix = _find_pixmap(&gdkbmp, icon, hbox); 3252 gdkpix = _find_pixmap(&gdkbmp, icon, hbox, NULL, NULL);
3248 #if GTK_MAJOR_VERSION > 1 3253 #if GTK_MAJOR_VERSION > 1
3249 pixmap = gtk_image_new_from_pixbuf((GdkPixbuf *)gdkbmp); 3254 pixmap = gtk_image_new_from_pixmap(gdkpix, gdkbmp);
3250 #else 3255 #else
3251 pixmap = gtk_pixmap_new(gdkpix, gdkbmp); 3256 pixmap = gtk_pixmap_new(gdkpix, gdkbmp);
3252 #endif 3257 #endif
3253 gtk_container_add(GTK_CONTAINER(item), hbox); 3258 gtk_container_add(GTK_CONTAINER(item), hbox);
3254 gtk_box_pack_start(GTK_BOX(hbox), pixmap, FALSE, TRUE, 0); 3259 gtk_box_pack_start(GTK_BOX(hbox), pixmap, FALSE, TRUE, 0);
3603 3608
3604 if(flag & DW_CFA_BITMAPORICON) 3609 if(flag & DW_CFA_BITMAPORICON)
3605 { 3610 {
3606 long hicon = *((long *)data); 3611 long hicon = *((long *)data);
3607 GdkBitmap *bitmap = NULL; 3612 GdkBitmap *bitmap = NULL;
3608 GdkPixmap *pixmap = _find_pixmap(&bitmap, hicon, clist); 3613 GdkPixmap *pixmap = _find_pixmap(&bitmap, hicon, clist, NULL, NULL);
3609 3614
3610 #if GTK_MAJOR_VERSION < 2
3611 if(pixmap) 3615 if(pixmap)
3612 gtk_clist_set_pixmap(GTK_CLIST(clist), row, column, pixmap, bitmap); 3616 gtk_clist_set_pixmap(GTK_CLIST(clist), row, column, pixmap, bitmap);
3613 #endif
3614 } 3617 }
3615 else if(flag & DW_CFA_STRING) 3618 else if(flag & DW_CFA_STRING)
3616 { 3619 {
3617 char *tmp = *((char **)data); 3620 char *tmp = *((char **)data);
3618 gtk_clist_set_text(GTK_CLIST(clist), row, column, tmp); 3621 gtk_clist_set_text(GTK_CLIST(clist), row, column, tmp);
4313 if (!(pixmap = calloc(1,sizeof(struct _hpixmap)))) 4316 if (!(pixmap = calloc(1,sizeof(struct _hpixmap))))
4314 return NULL; 4317 return NULL;
4315 4318
4316 4319
4317 DW_MUTEX_LOCK; 4320 DW_MUTEX_LOCK;
4318 pixmap->pixmap = _find_pixmap(&bitmap, id, handle); 4321 pixmap->pixmap = _find_pixmap(&bitmap, id, handle, &pixmap->width, &pixmap->height);
4319 if(pixmap->pixmap) 4322 if(pixmap->pixmap)
4320 { 4323 {
4321 #if GTK_MAJOR_VERSION < 2 4324 #if GTK_MAJOR_VERSION < 2
4322 GdkPixmapPrivate *pvt = (GdkPixmapPrivate *)pixmap->pixmap; 4325 GdkPixmapPrivate *pvt = (GdkPixmapPrivate *)pixmap->pixmap;
4323 pixmap->width = pvt->width; pixmap->height = pvt->height; 4326 pixmap->width = pvt->width; pixmap->height = pvt->height;
4324 #else
4325 pixmap->width = gdk_pixbuf_get_width((GdkPixbuf *)pixmap->pixmap);
4326 pixmap->height = gdk_pixbuf_get_height((GdkPixbuf *)pixmap->pixmap);
4327 #endif 4327 #endif
4328 } 4328 }
4329 DW_MUTEX_UNLOCK; 4329 DW_MUTEX_UNLOCK;
4330 return pixmap; 4330 return pixmap;
4331 } 4331 }