comparison gtk/dw.c @ 279:984db8aefd7f

Build fixes for GTK.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 14 Mar 2003 18:09:56 +0000
parents df0665ba147f
children 916045924784
comparison
equal deleted inserted replaced
278:df0665ba147f 279:984db8aefd7f
2364 * id: An ID to be used with dw_window_from_id() or 0L. 2364 * id: An ID to be used with dw_window_from_id() or 0L.
2365 * filename: Name of the file, omit extention to have 2365 * filename: Name of the file, omit extention to have
2366 * DW pick the appropriate file extension. 2366 * DW pick the appropriate file extension.
2367 * (BMP on OS/2 or Windows, XPM on Unix) 2367 * (BMP on OS/2 or Windows, XPM on Unix)
2368 */ 2368 */
2369 HWND dw_bitmapbutton_new_from_file(char *text, unsigned long id, char filename) 2369 HWND dw_bitmapbutton_new_from_file(char *text, unsigned long id, char *filename)
2370 { 2370 {
2371 GtkWidget *tmp; 2371 GtkWidget *tmp;
2372 GtkWidget *bitmap; 2372 GtkWidget *bitmap;
2373 GtkTooltips *tooltips; 2373 GtkTooltips *tooltips;
2374 int _locked_by_me = FALSE; 2374 int _locked_by_me = FALSE;
2581 gdk_window_set_icon(handle->window, NULL, icon_pixmap, bitmap); 2581 gdk_window_set_icon(handle->window, NULL, icon_pixmap, bitmap);
2582 2582
2583 DW_MUTEX_UNLOCK; 2583 DW_MUTEX_UNLOCK;
2584 } 2584 }
2585 2585
2586 HPIXMAP dw_pixmap_new_from_file(HWND handle, char *filename)
2587 {
2588 int _locked_by_me = FALSE;
2589 HPIXMAP pixmap;
2590 #ifndef USE_IMLIB
2591 GdkBitmap *bitmap = NULL;
2592 #endif
2593 #if GTK_MAJOR_VERSION > 1
2594 GdkPixbuf *pixbuf;
2595 #elif defined(USE_IMLIB)
2596 GdkImlibImage *image;
2597 #endif
2598 char *file = alloca(strlen(filename) + 5);
2599
2600 if (!file || !(pixmap = calloc(1,sizeof(struct _hpixmap))))
2601 return NULL;
2602
2603 strcpy(file, filename);
2604
2605 /* check if we can read from this file (it exists and read permission) */
2606 if(access(file, 04) != 0)
2607 {
2608 /* Try with .xpm extention */
2609 strcat(file, ".xpm");
2610 if(access(file, 04) != 0)
2611 {
2612 free(pixmap);
2613 return NULL;
2614 }
2615 }
2616
2617 DW_MUTEX_LOCK;
2618 #if GTK_MAJOR_VERSION > 1
2619 pixbuf = gdk_pixbuf_new_from_file(file, NULL);
2620
2621 pixmap->width = gdk_pixbuf_get_width(pixbuf);
2622 pixmap->height = gdk_pixbuf_get_height(pixbuf);
2623
2624 gdk_pixbuf_render_pixmap_and_mask(pixbuf, &pixmap->pixmap, &bitmap, 1);
2625 g_object_unref(pixbuf);
2626 #elif defined(USE_IMLIB)
2627 image = gdk_imlib_load_image(file);
2628
2629 pixmap->width = image->rgb_width;
2630 pixmap->height = image->rgb_height;
2631
2632 gdk_imlib_render(image, pixmap->width, pixmap->height);
2633 pixmap->pixmap = gdk_imlib_copy_image(image);
2634 gdk_imlib_destroy_image(image);
2635 #else
2636 pixmap->pixmap = gdk_pixmap_create_from_xpm(handle->window, &bitmap, &_colors[DW_CLR_PALEGRAY], file);
2637 #endif
2638 pixmap->handle = handle;
2639 DW_MUTEX_UNLOCK;
2640 return pixmap;
2641 }
2642 /* 2586 /*
2643 * Sets the bitmap used for a given static window. 2587 * Sets the bitmap used for a given static window.
2644 * Parameters: 2588 * Parameters:
2645 * handle: Handle to the window. 2589 * handle: Handle to the window.
2646 * id: An ID to be used to specify the icon, 2590 * id: An ID to be used to specify the icon,
2684 /* Try with .xpm extention */ 2628 /* Try with .xpm extention */
2685 strcat(file, ".xpm"); 2629 strcat(file, ".xpm");
2686 if(access(file, 04) != 0) 2630 if(access(file, 04) != 0)
2687 { 2631 {
2688 DW_MUTEX_UNLOCK; 2632 DW_MUTEX_UNLOCK;
2689 return NULL; 2633 return;
2690 } 2634 }
2691 } 2635 }
2692 #if GTK_MAJOR_VERSION > 1 2636 #if GTK_MAJOR_VERSION > 1
2693 pixbuf = gdk_pixbuf_new_from_file(file, NULL); 2637 pixbuf = gdk_pixbuf_new_from_file(file, NULL);
2694 2638