Mercurial > dwindows
comparison gtk/dw.c @ 1149:cf934fd39d03
Implemented dw_pixmap_set_font() on GTK2 and incorporated the
same GTK3 fontname fixes to avoid clobbering the default font.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 11 Sep 2011 22:19:01 +0000 |
parents | e24e5a13ff2c |
children | 58b5374355ab |
comparison
equal
deleted
inserted
replaced
1148:439f276042cc | 1149:cf934fd39d03 |
---|---|
7859 #if GTK_MAJOR_VERSION > 1 | 7859 #if GTK_MAJOR_VERSION > 1 |
7860 PangoFontDescription *font; | 7860 PangoFontDescription *font; |
7861 #else | 7861 #else |
7862 GdkFont *font; | 7862 GdkFont *font; |
7863 #endif | 7863 #endif |
7864 char *fontname = "fixed"; | 7864 char *tmpname, *fontname = "fixed"; |
7865 | 7865 |
7866 if(!text) | 7866 if(!text) |
7867 return; | 7867 return; |
7868 | 7868 |
7869 DW_MUTEX_LOCK; | 7869 DW_MUTEX_LOCK; |
7870 if(handle) | 7870 if(handle) |
7871 { | 7871 { |
7872 fontname = (char *)gtk_object_get_data(GTK_OBJECT(handle), "_dw_fontname"); | 7872 if((tmpname = (char *)gtk_object_get_data(GTK_OBJECT(handle), "_dw_fontname"))) |
7873 fontname = tmpname; | |
7873 gc = _set_colors(handle->window); | 7874 gc = _set_colors(handle->window); |
7874 } | 7875 } |
7875 else if(pixmap) | 7876 else if(pixmap) |
7876 { | 7877 { |
7877 fontname = (char *)gtk_object_get_data(GTK_OBJECT(pixmap->handle), "_dw_fontname"); | 7878 if(pixmap->font) |
7879 fontname = pixmap->font; | |
7880 else if((tmpname = (char *)gtk_object_get_data(GTK_OBJECT(pixmap->handle), "_dw_fontname"))) | |
7881 fontname = tmpname; | |
7878 gc = _set_colors(pixmap->pixmap); | 7882 gc = _set_colors(pixmap->pixmap); |
7879 } | 7883 } |
7880 if(gc) | 7884 if(gc) |
7881 { | 7885 { |
7882 #if GTK_MAJOR_VERSION > 1 | 7886 #if GTK_MAJOR_VERSION > 1 |
8269 DW_MUTEX_UNLOCK; | 8273 DW_MUTEX_UNLOCK; |
8270 #endif | 8274 #endif |
8271 } | 8275 } |
8272 | 8276 |
8273 /* | 8277 /* |
8278 * Sets the font used by a specified pixmap. | |
8279 * Normally the pixmap font is obtained from the associated window handle. | |
8280 * However this can be used to override that, or for pixmaps with no window. | |
8281 * Parameters: | |
8282 * pixmap: Handle to a pixmap returned by dw_pixmap_new() or | |
8283 * passed to the application via a callback. | |
8284 * fontname: Name and size of the font in the form "size.fontname" | |
8285 * Returns: | |
8286 * DW_ERROR_NONE on success and DW_ERROR_GENERAL on failure. | |
8287 */ | |
8288 int API dw_pixmap_set_font(HPIXMAP pixmap, char *fontname) | |
8289 { | |
8290 if(pixmap && fontname && *fontname) | |
8291 { | |
8292 char *oldfont = pixmap->font; | |
8293 pixmap->font = strdup(fontname); | |
8294 if(oldfont) | |
8295 free(oldfont); | |
8296 return DW_ERROR_NONE; | |
8297 } | |
8298 return DW_ERROR_GENERAL; | |
8299 } | |
8300 | |
8301 /* | |
8274 * Destroys an allocated pixmap. | 8302 * Destroys an allocated pixmap. |
8275 * Parameters: | 8303 * Parameters: |
8276 * pixmap: Handle to a pixmap returned by | 8304 * pixmap: Handle to a pixmap returned by |
8277 * dw_pixmap_new.. | 8305 * dw_pixmap_new.. |
8278 */ | 8306 */ |
8280 { | 8308 { |
8281 int _locked_by_me = FALSE; | 8309 int _locked_by_me = FALSE; |
8282 | 8310 |
8283 DW_MUTEX_LOCK; | 8311 DW_MUTEX_LOCK; |
8284 gdk_pixmap_unref(pixmap->pixmap); | 8312 gdk_pixmap_unref(pixmap->pixmap); |
8313 if(pixmap->font) | |
8314 free(pixmap->font); | |
8285 free(pixmap); | 8315 free(pixmap); |
8286 DW_MUTEX_UNLOCK; | 8316 DW_MUTEX_UNLOCK; |
8287 } | 8317 } |
8288 | 8318 |
8289 /* | 8319 /* |