comparison gtk3/dw.c @ 1052:c008a186b735

Added dw_font_choose() on GTK3 for 2.1.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 02 Jun 2011 07:20:53 +0000
parents 80cd7fed4995
children 0725114533fe
comparison
equal deleted inserted replaced
1051:6919854298fd 1052:c008a186b735
2557 } 2557 }
2558 DW_MUTEX_UNLOCK; 2558 DW_MUTEX_UNLOCK;
2559 return TRUE; 2559 return TRUE;
2560 } 2560 }
2561 2561
2562 /* Allows the user to choose a font using the system's font chooser dialog.
2563 * Parameters:
2564 * currfont: current font
2565 * Returns:
2566 * A malloced buffer with the selected font or NULL on error.
2567 */
2568 char * API dw_font_choose(char *currfont)
2569 {
2570 GtkFontSelectionDialog *fd;
2571 char *font = currfont ? strdup(currfont) : NULL;
2572 char *name = font ? strchr(font, '.') : NULL;
2573 int _locked_by_me = FALSE;
2574 GtkResponseType result;
2575 char *retfont = NULL;
2576
2577 /* Detect Dynamic Windows style font name...
2578 * Format: ##.Fontname
2579 * and convert to a Pango name
2580 */
2581 if(name && isdigit(*font))
2582 {
2583 int size = atoi(font);
2584 *name = 0;
2585 name++;
2586 sprintf(font, "%s %d", name, size);
2587 }
2588
2589 DW_MUTEX_LOCK;
2590 fd = (GtkFontSelectionDialog *)gtk_font_selection_dialog_new("Choose font");
2591 if(name)
2592 {
2593 gtk_font_selection_dialog_set_font_name(fd, name);
2594 free(name);
2595 }
2596
2597 result = gtk_dialog_run(GTK_DIALOG(fd));
2598
2599 if(result == GTK_RESPONSE_OK || result == GTK_RESPONSE_APPLY)
2600 {
2601 gchar *fontname = gtk_font_selection_dialog_get_font_name(fd);
2602 int len, x;
2603
2604 retfont = strdup(fontname);
2605 len = strlen(fontname);
2606 /* Convert to Dynamic Windows format if we can... */
2607 if(len > 0 && isdigit(fontname[len-1]))
2608 {
2609 int size;
2610
2611 x=len-1;
2612 while(x > 0 && fontname[x] != ' ')
2613 {
2614 x--;
2615 }
2616 size = atoi(&fontname[x]);
2617 /* If we were able to find a valid size... */
2618 if(size > 0)
2619 {
2620 /* Null terminate after the name...
2621 * and create the Dynamic Windows style font.
2622 */
2623 fontname[x] = 0;
2624 snprintf(retfont, len+1, "%d.%s", size, fontname);
2625 }
2626 }
2627 dw_free(fontname);
2628 }
2629 gtk_widget_destroy(GTK_WIDGET(fd));
2630 DW_MUTEX_UNLOCK;
2631 return retfont;
2632 }
2633
2562 /* 2634 /*
2563 * Gets the font used by a specified window (widget) handle. 2635 * Gets the font used by a specified window (widget) handle.
2564 * Parameters: 2636 * Parameters:
2565 * handle: The window (widget) handle. 2637 * handle: The window (widget) handle.
2566 */ 2638 */