Mercurial > dwindows
comparison gtk/dw.c @ 1054:818698b4a0df
Added dw_font_choose() on GTK2 for 2.1.
Also a fix on GTK3 to prevent multiple dialogs from being active.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 02 Jun 2011 10:12:08 +0000 |
parents | 80cd7fed4995 |
children | fadb18121c56 |
comparison
equal
deleted
inserted
replaced
1053:0725114533fe | 1054:818698b4a0df |
---|---|
2721 } | 2721 } |
2722 #endif | 2722 #endif |
2723 return retval; | 2723 return retval; |
2724 } | 2724 } |
2725 | 2725 |
2726 static int _dw_font_active = 0; | |
2727 | |
2728 /* Internal function to handle the font OK press */ | |
2729 static gint _gtk_font_ok(GtkWidget *widget, DWDialog *dwwait) | |
2730 { | |
2731 GtkFontSelectionDialog *fd; | |
2732 char *retfont = NULL; | |
2733 gchar *fontname; | |
2734 int len, x; | |
2735 | |
2736 if(!dwwait) | |
2737 return FALSE; | |
2738 | |
2739 fd = dwwait->data; | |
2740 fontname = gtk_font_selection_dialog_get_font_name(fd); | |
2741 if(fontname && (retfont = strdup(fontname))) | |
2742 { | |
2743 len = strlen(fontname); | |
2744 /* Convert to Dynamic Windows format if we can... */ | |
2745 if(len > 0 && isdigit(fontname[len-1])) | |
2746 { | |
2747 int size; | |
2748 | |
2749 x=len-1; | |
2750 while(x > 0 && fontname[x] != ' ') | |
2751 { | |
2752 x--; | |
2753 } | |
2754 size = atoi(&fontname[x]); | |
2755 /* If we were able to find a valid size... */ | |
2756 if(size > 0) | |
2757 { | |
2758 /* Null terminate after the name... | |
2759 * and create the Dynamic Windows style font. | |
2760 */ | |
2761 fontname[x] = 0; | |
2762 snprintf(retfont, len+1, "%d.%s", size, fontname); | |
2763 } | |
2764 } | |
2765 dw_free(fontname); | |
2766 } | |
2767 gtk_widget_destroy(GTK_WIDGET(fd)); | |
2768 _dw_font_active = 0; | |
2769 dw_dialog_dismiss(dwwait, (void *)retfont); | |
2770 return FALSE; | |
2771 } | |
2772 | |
2773 /* Internal function to handle the font Cancel press */ | |
2774 static gint _gtk_font_cancel(GtkWidget *widget, DWDialog *dwwait) | |
2775 { | |
2776 if(!dwwait) | |
2777 return FALSE; | |
2778 | |
2779 gtk_widget_destroy(GTK_WIDGET(dwwait->data)); | |
2780 _dw_font_active = 0; | |
2781 dw_dialog_dismiss(dwwait, NULL); | |
2782 return FALSE; | |
2783 } | |
2784 | |
2785 /* Allows the user to choose a font using the system's font chooser dialog. | |
2786 * Parameters: | |
2787 * currfont: current font | |
2788 * Returns: | |
2789 * A malloced buffer with the selected font or NULL on error. | |
2790 */ | |
2791 char * API dw_font_choose(char *currfont) | |
2792 { | |
2793 GtkFontSelectionDialog *fd; | |
2794 char *font = currfont ? strdup(currfont) : NULL; | |
2795 char *name = font ? strchr(font, '.') : NULL; | |
2796 int _locked_by_me = FALSE; | |
2797 char *retfont = NULL; | |
2798 DWDialog *dwwait; | |
2799 | |
2800 /* Detect Dynamic Windows style font name... | |
2801 * Format: ##.Fontname | |
2802 * and convert to a Pango name | |
2803 */ | |
2804 if(name && isdigit(*font)) | |
2805 { | |
2806 int size = atoi(font); | |
2807 *name = 0; | |
2808 name++; | |
2809 sprintf(font, "%s %d", name, size); | |
2810 } | |
2811 | |
2812 DW_MUTEX_LOCK; | |
2813 /* The DW mutex should be sufficient for | |
2814 * insuring no thread changes this unknowingly. | |
2815 */ | |
2816 if(_dw_font_active) | |
2817 { | |
2818 DW_MUTEX_UNLOCK; | |
2819 if(name) | |
2820 free(name); | |
2821 return NULL; | |
2822 } | |
2823 fd = (GtkFontSelectionDialog *)gtk_font_selection_dialog_new("Choose font"); | |
2824 if(name) | |
2825 { | |
2826 gtk_font_selection_dialog_set_font_name(fd, name); | |
2827 free(name); | |
2828 } | |
2829 | |
2830 _dw_font_active = 1; | |
2831 | |
2832 dwwait = dw_dialog_new((void *)fd); | |
2833 | |
2834 g_signal_connect(G_OBJECT(fd->ok_button), "clicked", G_CALLBACK(_gtk_font_ok), dwwait); | |
2835 g_signal_connect(G_OBJECT(fd->cancel_button), "clicked", G_CALLBACK(_gtk_font_cancel), dwwait); | |
2836 | |
2837 gtk_widget_show(GTK_WIDGET(fd)); | |
2838 | |
2839 retfont = (char *)dw_dialog_wait(dwwait); | |
2840 DW_MUTEX_UNLOCK; | |
2841 return retfont; | |
2842 } | |
2843 | |
2726 /* | 2844 /* |
2727 * Sets the font used by a specified window (widget) handle. | 2845 * Sets the font used by a specified window (widget) handle. |
2728 * Parameters: | 2846 * Parameters: |
2729 * handle: The window (widget) handle. | 2847 * handle: The window (widget) handle. |
2730 * fontname: Name and size of the font in the form "size.fontname" | 2848 * fontname: Name and size of the font in the form "size.fontname" |