Mercurial > dwindows
comparison gtk3/dw.c @ 1240:3bc6244279c0
Attempt at converting DW style font names on GTK for dw_pixmap_set_font().
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Wed, 19 Oct 2011 02:41:55 +0000 |
parents | db21c0081387 |
children | 3a2ffe3a7eae |
comparison
equal
deleted
inserted
replaced
1239:7ec60b650e5b | 1240:3bc6244279c0 |
---|---|
2504 */ | 2504 */ |
2505 void API dw_font_set_default(char *fontname) | 2505 void API dw_font_set_default(char *fontname) |
2506 { | 2506 { |
2507 } | 2507 } |
2508 | 2508 |
2509 /* | 2509 /* Convert DW style font to pango style */ |
2510 * Sets the font used by a specified window (widget) handle. | 2510 void _convert_font(char *font) |
2511 * Parameters: | 2511 { |
2512 * handle: The window (widget) handle. | |
2513 * fontname: Name and size of the font in the form "size.fontname" | |
2514 */ | |
2515 int dw_window_set_font(HWND handle, char *fontname) | |
2516 { | |
2517 PangoFontDescription *pfont; | |
2518 GtkWidget *handle2 = handle; | |
2519 char *font = strdup(fontname); | |
2520 char *name = strchr(font, '.'); | 2512 char *name = strchr(font, '.'); |
2521 int _locked_by_me = FALSE; | |
2522 gpointer data; | |
2523 | |
2524 DW_MUTEX_LOCK; | |
2525 if(GTK_IS_SCROLLED_WINDOW(handle)) | |
2526 { | |
2527 GtkWidget *tmp = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_user"); | |
2528 if(tmp) | |
2529 handle2 = tmp; | |
2530 } | |
2531 /* If it is a groupox we want to operate on the frame label */ | |
2532 else if(GTK_IS_FRAME(handle)) | |
2533 { | |
2534 GtkWidget *tmp = gtk_frame_get_label_widget(GTK_FRAME(handle)); | |
2535 if(tmp) | |
2536 handle2 = tmp; | |
2537 } | |
2538 | 2513 |
2539 /* Detect Dynamic Windows style font name... | 2514 /* Detect Dynamic Windows style font name... |
2540 * Format: ##.Fontname | 2515 * Format: ##.Fontname |
2541 * and convert to a Pango name | 2516 * and convert to a Pango name |
2542 */ | 2517 */ |
2545 int size = atoi(font); | 2520 int size = atoi(font); |
2546 *name = 0; | 2521 *name = 0; |
2547 name++; | 2522 name++; |
2548 sprintf(font, "%s %d", name, size); | 2523 sprintf(font, "%s %d", name, size); |
2549 } | 2524 } |
2525 } | |
2526 | |
2527 /* | |
2528 * Sets the font used by a specified window (widget) handle. | |
2529 * Parameters: | |
2530 * handle: The window (widget) handle. | |
2531 * fontname: Name and size of the font in the form "size.fontname" | |
2532 */ | |
2533 int dw_window_set_font(HWND handle, char *fontname) | |
2534 { | |
2535 PangoFontDescription *pfont; | |
2536 GtkWidget *handle2 = handle; | |
2537 char *font = strdup(fontname); | |
2538 int _locked_by_me = FALSE; | |
2539 gpointer data; | |
2540 | |
2541 DW_MUTEX_LOCK; | |
2542 if(GTK_IS_SCROLLED_WINDOW(handle)) | |
2543 { | |
2544 GtkWidget *tmp = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_user"); | |
2545 if(tmp) | |
2546 handle2 = tmp; | |
2547 } | |
2548 /* If it is a groupox we want to operate on the frame label */ | |
2549 else if(GTK_IS_FRAME(handle)) | |
2550 { | |
2551 GtkWidget *tmp = gtk_frame_get_label_widget(GTK_FRAME(handle)); | |
2552 if(tmp) | |
2553 handle2 = tmp; | |
2554 } | |
2555 | |
2556 _convert_font(font); | |
2550 | 2557 |
2551 /* Free old font name if one is allocated */ | 2558 /* Free old font name if one is allocated */ |
2552 data = g_object_get_data(G_OBJECT(handle2), "_dw_fontname"); | 2559 data = g_object_get_data(G_OBJECT(handle2), "_dw_fontname"); |
2560 g_object_set_data(G_OBJECT(handle2), "_dw_fontname", (gpointer)font); | |
2553 if(data) | 2561 if(data) |
2554 free(data); | 2562 free(data); |
2555 | 2563 |
2556 g_object_set_data(G_OBJECT(handle2), "_dw_fontname", (gpointer)font); | |
2557 pfont = pango_font_description_from_string(fontname); | 2564 pfont = pango_font_description_from_string(fontname); |
2558 | 2565 |
2559 if(pfont) | 2566 if(pfont) |
2560 { | 2567 { |
2561 gtk_widget_modify_font(handle2, pfont); | 2568 gtk_widget_modify_font(handle2, pfont); |
7268 { | 7275 { |
7269 if(pixmap && fontname && *fontname) | 7276 if(pixmap && fontname && *fontname) |
7270 { | 7277 { |
7271 char *oldfont = pixmap->font; | 7278 char *oldfont = pixmap->font; |
7272 pixmap->font = strdup(fontname); | 7279 pixmap->font = strdup(fontname); |
7280 _convert_font(pixmap->font); | |
7273 if(oldfont) | 7281 if(oldfont) |
7274 free(oldfont); | 7282 free(oldfont); |
7275 return DW_ERROR_NONE; | 7283 return DW_ERROR_NONE; |
7276 } | 7284 } |
7277 return DW_ERROR_GENERAL; | 7285 return DW_ERROR_GENERAL; |