Debian Codegraph @

mixgtk/mixgtk_fontsel.c

raw symbols SCIP
1 /* -*-c-*- -------------- mixgtk_fontsel.c :
2 * Implementation of the functions declared in mixgtk_fontsel.h
3 * ------------------------------------------------------------------
4 * Copyright (C) 2001, 2004, 2006, 2007, 2008, 2019, 2020 Free Software Foundation, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 *
20 */
21
22 #include <mixlib/mix.h>
23 #include "mixgtk_widgets.h"
24 #include "mixgtk_config.h"
25 #include "mixgtk_mixvm.h"
26 #include "mixgtk_mixal.h"
27 #include "mixgtk_cmd_dispatcher.h"
28 #include "mixgtk_device.h"
29 #include "mixgtk_fontsel.h"
30
31 static GtkFontChooserDialog *fontsel_dialog_ = NULL;
32 #define FONTSEL_ GTK_FONT_CHOOSER (fontsel_dialog_)
33
34 static const gchar *keys_[MIX_FONT_NO] = {
35 "MIX.font", "Prompt.font", "Log.font", "MIXAL.font", "Devices.font",
36 "Symbols.font", "Default.font"
37 };
38
39 static const gchar *default_font_ = "Monospace 10";
40
41 /* initialise the font selection dialog */
42 static void
43 init_fontsel_ (void)
44 {
45 fontsel_dialog_ =
46 GTK_FONT_CHOOSER_DIALOG
47 (mixgtk_widget_factory_get_dialog (MIXGTK_FONTSEL_DIALOG));
48 g_assert (fontsel_dialog_ != NULL);
49 }
50
51 void
52 mixgtk_fontsel_set_font (mixgtk_font_t f, GtkWidget *w)
53 {
54 const gchar *font;
55 PangoFontDescription *font_desc;
56
57 if (f >= MIX_FONT_NO || w == NULL) return;
58
59 font = mixgtk_config_get (keys_[f]);
60 if (!font)
61 {
62 mixgtk_config_update (keys_[f], default_font_);
63 font = mixgtk_config_get (keys_[f]);
64 g_assert (font);
65 }
66
67 font_desc = pango_font_description_from_string (font);
68
69 if (font_desc)
70 {
71 gtk_widget_override_font (w, font_desc);
72 pango_font_description_free (font_desc);
73 }
74 else
75 mixgtk_config_remove (keys_[f]);
76
77 }
78
79 gboolean
80 mixgtk_fontsel_query_font (mixgtk_font_t f, GtkWidget **w, size_t no)
81 {
82 gint result = GTK_RESPONSE_APPLY;
83 const gchar *current;
84 gboolean ret = FALSE;
85
86 if (f >= MIX_FONT_NO) return FALSE;
87 if (!fontsel_dialog_) init_fontsel_ ();
88
89 current = mixgtk_config_get (keys_[f]);
90 gtk_font_chooser_set_font (FONTSEL_, current? current : default_font_);
91
92 while (result == GTK_RESPONSE_APPLY)
93 {
94 result = gtk_dialog_run (GTK_DIALOG (fontsel_dialog_));
95 if (result != GTK_RESPONSE_CANCEL)
96 {
97 gint k;
98 mixgtk_config_update
99 (keys_[f],
100 gtk_font_chooser_get_font (FONTSEL_));
101 for (k = 0; k < no; ++k)
102 mixgtk_fontsel_set_font (f, w[k]);
103 ret = TRUE;
104 }
105 }
106 gtk_widget_hide (GTK_WIDGET (fontsel_dialog_));
107 return ret;
108 }
109
110 void
111 on_all_fonts_activate (void)
112 {
113 gint result = GTK_RESPONSE_APPLY;
114 const gchar *current;
115
116 if (!fontsel_dialog_) init_fontsel_ ();
117
118 current = mixgtk_config_get (keys_[MIX_FONT_DEFAULT]);
119 gtk_font_chooser_set_font (FONTSEL_, current? current : default_font_);
120
121 while (result == GTK_RESPONSE_APPLY)
122 {
123 result = gtk_dialog_run (GTK_DIALOG (fontsel_dialog_));
124 if (result != GTK_RESPONSE_CANCEL)
125 {
126 gint k;
127 current = gtk_font_chooser_get_font (FONTSEL_);
128
129 for (k = 0; k < MIX_FONT_NO; ++k)
130 mixgtk_config_update (keys_[k], current);
131
132 mixgtk_mixal_update_fonts ();
133 mixgtk_mixvm_update_fonts ();
134 mixgtk_device_update_fonts ();
135 mixgtk_cmd_dispatcher_update_fonts ();
136 }
137 }
138 gtk_widget_hide (GTK_WIDGET (fontsel_dialog_));
139 }