comparison gtk/dw.c @ 241:00d2b1bcf036

Added dw_pixmap_new_from_file().
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Wed, 19 Feb 2003 06:00:54 +0000
parents 403b07f873e1
children 68158098a092
comparison
equal deleted inserted replaced
240:afc0d5f5d74f 241:00d2b1bcf036
5047 DW_MUTEX_UNLOCK; 5047 DW_MUTEX_UNLOCK;
5048 return pixmap; 5048 return pixmap;
5049 } 5049 }
5050 5050
5051 /* 5051 /*
5052 * Creates a pixmap from a file.
5053 * Parameters:
5054 * handle: Window handle the pixmap is associated with.
5055 * filename: Name of the file, omit extention to have
5056 * DW pick the appropriate file extension.
5057 * (BMP on OS/2 or Windows, XPM on Unix)
5058 * Returns:
5059 * A handle to a pixmap or NULL on failure.
5060 */
5061 HPIXMAP dw_pixmap_new_from_file(HWND handle, char *filename)
5062 {
5063 int _locked_by_me = FALSE;
5064 HPIXMAP pixmap;
5065 GdkBitmap *bitmap = NULL;
5066 #if GTK_MAJOR_VERSION > 1
5067 GdkPixbuf *pixbuf;
5068 #endif
5069 char *file = alloca(strlen(filename) + 5);
5070
5071 if (!file || !(pixmap = calloc(1,sizeof(struct _hpixmap))))
5072 return NULL;
5073
5074 strcpy(file, filename);
5075
5076 /* check if we can read from this file (it exists and read permission) */
5077 if(access(file, 04) != 0)
5078 {
5079 /* Try with .xpm extention */
5080 strcat(file, ".xpm");
5081 if(access(file, 04) != 0)
5082 {
5083 free(pixmap);
5084 return NULL;
5085 }
5086 }
5087
5088 DW_MUTEX_LOCK;
5089 #if GTK_MAJOR_VERSION > 1
5090 pixbuf = gdk_pixbuf_new_from_file(file);
5091
5092 pixmap->width = gdk_pixbuf_get_width(pixbuf);
5093 pixmap->height = gdk_pixbuf_get_height(pixbuf);
5094
5095 gdk_pixbuf_render_pixmap_and_mask(pixbuf, &pixmap->pixmap, &bitmap, 1);
5096 g_object_unref(pixbuf);
5097 #endif
5098 pixmap->handle = handle;
5099 DW_MUTEX_UNLOCK;
5100 return pixmap;
5101 }
5102
5103 /*
5052 * Creates a pixmap from internal resource graphic specified by id. 5104 * Creates a pixmap from internal resource graphic specified by id.
5053 * Parameters: 5105 * Parameters:
5054 * handle: Window handle the pixmap is associated with. 5106 * handle: Window handle the pixmap is associated with.
5055 * id: Resource ID associated with requested pixmap. 5107 * id: Resource ID associated with requested pixmap.
5056 * Returns: 5108 * Returns: