1 | /* GTK - The GIMP Toolkit |
---|
2 | * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald |
---|
3 | * |
---|
4 | * GtkFontSelection widget for Gtk+, by Damon Chaplin, May 1998. |
---|
5 | * Based on the GnomeFontSelector widget, by Elliot Lee, but major changes. |
---|
6 | * The GnomeFontSelector was derived from app/text_tool.c in the GIMP. |
---|
7 | * |
---|
8 | * This library is free software; you can redistribute it and/or |
---|
9 | * modify it under the terms of the GNU Library General Public |
---|
10 | * License as published by the Free Software Foundation; either |
---|
11 | * version 2 of the License, or (at your option) any later version. |
---|
12 | * |
---|
13 | * This library is distributed in the hope that it will be useful, |
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
16 | * Library General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU Library General Public |
---|
19 | * License along with this library; if not, write to the |
---|
20 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
---|
21 | * Boston, MA 02111-1307, USA. |
---|
22 | */ |
---|
23 | |
---|
24 | /* |
---|
25 | * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS |
---|
26 | * file for a list of people on the GTK+ Team. See the ChangeLog |
---|
27 | * files for a list of changes. These files are distributed with |
---|
28 | * GTK+ at ftp://ftp.gtk.org/pub/gtk/. |
---|
29 | */ |
---|
30 | |
---|
31 | #ifndef __GTK_FONTSEL_H__ |
---|
32 | #define __GTK_FONTSEL_H__ |
---|
33 | |
---|
34 | |
---|
35 | #include <gdk/gdk.h> |
---|
36 | #include <gtk/gtkwindow.h> |
---|
37 | #include <gtk/gtknotebook.h> |
---|
38 | |
---|
39 | |
---|
40 | #ifdef __cplusplus |
---|
41 | extern "C" { |
---|
42 | #endif /* __cplusplus */ |
---|
43 | |
---|
44 | #define GTK_TYPE_FONT_SELECTION (gtk_font_selection_get_type ()) |
---|
45 | #define GTK_FONT_SELECTION(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_FONT_SELECTION, GtkFontSelection)) |
---|
46 | #define GTK_FONT_SELECTION_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_FONT_SELECTION, GtkFontSelectionClass)) |
---|
47 | #define GTK_IS_FONT_SELECTION(obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_FONT_SELECTION)) |
---|
48 | #define GTK_IS_FONT_SELECTION_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_FONT_SELECTION)) |
---|
49 | |
---|
50 | #define GTK_TYPE_FONT_SELECTION_DIALOG (gtk_font_selection_dialog_get_type ()) |
---|
51 | #define GTK_FONT_SELECTION_DIALOG(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_FONT_SELECTION_DIALOG, GtkFontSelectionDialog)) |
---|
52 | #define GTK_FONT_SELECTION_DIALOG_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_FONT_SELECTION_DIALOG, GtkFontSelectionDialogClass)) |
---|
53 | #define GTK_IS_FONT_SELECTION_DIALOG(obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_FONT_SELECTION_DIALOG)) |
---|
54 | #define GTK_IS_FONT_SELECTION_DIALOG_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_FONT_SELECTION_DIALOG)) |
---|
55 | |
---|
56 | typedef struct _GtkFontSelection GtkFontSelection; |
---|
57 | typedef struct _GtkFontSelectionClass GtkFontSelectionClass; |
---|
58 | |
---|
59 | typedef struct _GtkFontSelectionDialog GtkFontSelectionDialog; |
---|
60 | typedef struct _GtkFontSelectionDialogClass GtkFontSelectionDialogClass; |
---|
61 | |
---|
62 | |
---|
63 | |
---|
64 | |
---|
65 | /* This is the number of properties which we keep in the properties array, |
---|
66 | i.e. Weight, Slant, Set Width, Spacing, Charset & Foundry. */ |
---|
67 | #define GTK_NUM_FONT_PROPERTIES 6 |
---|
68 | |
---|
69 | /* This is the number of properties each style has i.e. Weight, Slant, |
---|
70 | Set Width, Spacing & Charset. Note that Foundry is not included, |
---|
71 | since it is the same for all styles of the same FontInfo. */ |
---|
72 | #define GTK_NUM_STYLE_PROPERTIES 5 |
---|
73 | |
---|
74 | |
---|
75 | /* Used to determine whether we are using point or pixel sizes. */ |
---|
76 | typedef enum |
---|
77 | { |
---|
78 | GTK_FONT_METRIC_PIXELS, |
---|
79 | GTK_FONT_METRIC_POINTS |
---|
80 | } GtkFontMetricType; |
---|
81 | |
---|
82 | /* Used for determining the type of a font style, and also for setting filters. |
---|
83 | These can be combined if a style has bitmaps and scalable fonts available.*/ |
---|
84 | typedef enum |
---|
85 | { |
---|
86 | GTK_FONT_BITMAP = 1 << 0, |
---|
87 | GTK_FONT_SCALABLE = 1 << 1, |
---|
88 | GTK_FONT_SCALABLE_BITMAP = 1 << 2, |
---|
89 | |
---|
90 | GTK_FONT_ALL = 0x07 |
---|
91 | } GtkFontType; |
---|
92 | |
---|
93 | /* These are the two types of filter available - base and user. The base |
---|
94 | filter is set by the application and can't be changed by the user. */ |
---|
95 | #define GTK_NUM_FONT_FILTERS 2 |
---|
96 | typedef enum |
---|
97 | { |
---|
98 | GTK_FONT_FILTER_BASE, |
---|
99 | GTK_FONT_FILTER_USER |
---|
100 | } GtkFontFilterType; |
---|
101 | |
---|
102 | /* These hold the arrays of current filter settings for each property. |
---|
103 | If nfilters is 0 then all values of the property are OK. If not the |
---|
104 | filters array contains the indexes of the valid property values. */ |
---|
105 | typedef struct _GtkFontFilter GtkFontFilter; |
---|
106 | struct _GtkFontFilter |
---|
107 | { |
---|
108 | gint font_type; |
---|
109 | guint16 *property_filters[GTK_NUM_FONT_PROPERTIES]; |
---|
110 | guint16 property_nfilters[GTK_NUM_FONT_PROPERTIES]; |
---|
111 | }; |
---|
112 | |
---|
113 | |
---|
114 | struct _GtkFontSelection |
---|
115 | { |
---|
116 | GtkNotebook notebook; |
---|
117 | |
---|
118 | /* These are on the font page. */ |
---|
119 | GtkWidget *main_vbox; |
---|
120 | GtkWidget *font_label; |
---|
121 | GtkWidget *font_entry; |
---|
122 | GtkWidget *font_clist; |
---|
123 | GtkWidget *font_style_entry; |
---|
124 | GtkWidget *font_style_clist; |
---|
125 | GtkWidget *size_entry; |
---|
126 | GtkWidget *size_clist; |
---|
127 | GtkWidget *pixels_button; |
---|
128 | GtkWidget *points_button; |
---|
129 | GtkWidget *filter_button; |
---|
130 | GtkWidget *preview_entry; |
---|
131 | GtkWidget *message_label; |
---|
132 | |
---|
133 | /* These are on the font info page. */ |
---|
134 | GtkWidget *info_vbox; |
---|
135 | GtkWidget *info_clist; |
---|
136 | GtkWidget *requested_font_name; |
---|
137 | GtkWidget *actual_font_name; |
---|
138 | |
---|
139 | /* These are on the filter page. */ |
---|
140 | GtkWidget *filter_vbox; |
---|
141 | GtkWidget *type_bitmaps_button; |
---|
142 | GtkWidget *type_scalable_button; |
---|
143 | GtkWidget *type_scaled_bitmaps_button; |
---|
144 | GtkWidget *filter_clists[GTK_NUM_FONT_PROPERTIES]; |
---|
145 | |
---|
146 | GdkFont *font; |
---|
147 | gint font_index; |
---|
148 | gint style; |
---|
149 | GtkFontMetricType metric; |
---|
150 | /* The size is either in pixels or deci-points, depending on the metric. */ |
---|
151 | gint size; |
---|
152 | |
---|
153 | /* This is the last size explicitly selected. When the user selects different |
---|
154 | fonts we try to find the nearest size to this. */ |
---|
155 | gint selected_size; |
---|
156 | |
---|
157 | /* These are the current property settings. They are indexes into the |
---|
158 | strings in the GtkFontSelInfo properties array. */ |
---|
159 | guint16 property_values[GTK_NUM_STYLE_PROPERTIES]; |
---|
160 | |
---|
161 | /* These are the base and user font filters. */ |
---|
162 | GtkFontFilter filters[GTK_NUM_FONT_FILTERS]; |
---|
163 | }; |
---|
164 | |
---|
165 | |
---|
166 | struct _GtkFontSelectionClass |
---|
167 | { |
---|
168 | GtkNotebookClass parent_class; |
---|
169 | }; |
---|
170 | |
---|
171 | |
---|
172 | struct _GtkFontSelectionDialog |
---|
173 | { |
---|
174 | GtkWindow window; |
---|
175 | |
---|
176 | GtkWidget *fontsel; |
---|
177 | |
---|
178 | GtkWidget *main_vbox; |
---|
179 | GtkWidget *action_area; |
---|
180 | GtkWidget *ok_button; |
---|
181 | /* The 'Apply' button is not shown by default but you can show/hide it. */ |
---|
182 | GtkWidget *apply_button; |
---|
183 | GtkWidget *cancel_button; |
---|
184 | |
---|
185 | /* If the user changes the width of the dialog, we turn auto-shrink off. */ |
---|
186 | gint dialog_width; |
---|
187 | gboolean auto_resize; |
---|
188 | }; |
---|
189 | |
---|
190 | struct _GtkFontSelectionDialogClass |
---|
191 | { |
---|
192 | GtkWindowClass parent_class; |
---|
193 | }; |
---|
194 | |
---|
195 | |
---|
196 | |
---|
197 | /***************************************************************************** |
---|
198 | * GtkFontSelection functions. |
---|
199 | * see the comments in the GtkFontSelectionDialog functions. |
---|
200 | *****************************************************************************/ |
---|
201 | |
---|
202 | GtkType gtk_font_selection_get_type (void); |
---|
203 | GtkWidget* gtk_font_selection_new (void); |
---|
204 | gchar* gtk_font_selection_get_font_name (GtkFontSelection *fontsel); |
---|
205 | GdkFont* gtk_font_selection_get_font (GtkFontSelection *fontsel); |
---|
206 | gboolean gtk_font_selection_set_font_name (GtkFontSelection *fontsel, |
---|
207 | const gchar *fontname); |
---|
208 | void gtk_font_selection_set_filter (GtkFontSelection *fontsel, |
---|
209 | GtkFontFilterType filter_type, |
---|
210 | GtkFontType font_type, |
---|
211 | gchar **foundries, |
---|
212 | gchar **weights, |
---|
213 | gchar **slants, |
---|
214 | gchar **setwidths, |
---|
215 | gchar **spacings, |
---|
216 | gchar **charsets); |
---|
217 | gchar* gtk_font_selection_get_preview_text (GtkFontSelection *fontsel); |
---|
218 | void gtk_font_selection_set_preview_text (GtkFontSelection *fontsel, |
---|
219 | const gchar *text); |
---|
220 | |
---|
221 | |
---|
222 | |
---|
223 | /***************************************************************************** |
---|
224 | * GtkFontSelectionDialog functions. |
---|
225 | * most of these functions simply call the corresponding function in the |
---|
226 | * GtkFontSelection. |
---|
227 | *****************************************************************************/ |
---|
228 | |
---|
229 | GtkType gtk_font_selection_dialog_get_type (void); |
---|
230 | GtkWidget* gtk_font_selection_dialog_new (const gchar *title); |
---|
231 | |
---|
232 | /* This returns the X Logical Font Description fontname, or NULL if no font |
---|
233 | is selected. Note that there is a slight possibility that the font might not |
---|
234 | have been loaded OK. You should call gtk_font_selection_dialog_get_font() |
---|
235 | to see if it has been loaded OK. |
---|
236 | You should g_free() the returned font name after you're done with it. */ |
---|
237 | gchar* gtk_font_selection_dialog_get_font_name (GtkFontSelectionDialog *fsd); |
---|
238 | |
---|
239 | /* This will return the current GdkFont, or NULL if none is selected or there |
---|
240 | was a problem loading it. Remember to use gdk_font_ref/unref() if you want |
---|
241 | to use the font (in a style, for example). */ |
---|
242 | GdkFont* gtk_font_selection_dialog_get_font (GtkFontSelectionDialog *fsd); |
---|
243 | |
---|
244 | /* This sets the currently displayed font. It should be a valid X Logical |
---|
245 | Font Description font name (anything else will be ignored), e.g. |
---|
246 | "-adobe-courier-bold-o-normal--25-*-*-*-*-*-*-*" |
---|
247 | It returns TRUE on success. */ |
---|
248 | gboolean gtk_font_selection_dialog_set_font_name (GtkFontSelectionDialog *fsd, |
---|
249 | const gchar *fontname); |
---|
250 | |
---|
251 | /* This sets one of the font filters, to limit the fonts shown. The filter_type |
---|
252 | is GTK_FONT_FILTER_BASE or GTK_FONT_FILTER_USER. The font type is a |
---|
253 | combination of the bit flags GTK_FONT_BITMAP, GTK_FONT_SCALABLE and |
---|
254 | GTK_FONT_SCALABLE_BITMAP (or GTK_FONT_ALL for all font types). |
---|
255 | The foundries, weights etc. are arrays of strings containing property |
---|
256 | values, e.g. 'bold', 'demibold', and *MUST* finish with a NULL. |
---|
257 | Standard long names are also accepted, e.g. 'italic' instead of 'i'. |
---|
258 | |
---|
259 | e.g. to allow only fixed-width fonts ('char cell' or 'monospaced') to be |
---|
260 | selected use: |
---|
261 | |
---|
262 | gchar *spacings[] = { "c", "m", NULL }; |
---|
263 | gtk_font_selection_dialog_set_filter (GTK_FONT_SELECTION_DIALOG (fontsel), |
---|
264 | GTK_FONT_FILTER_BASE, GTK_FONT_ALL, |
---|
265 | NULL, NULL, NULL, NULL, spacings, NULL); |
---|
266 | |
---|
267 | to allow only true scalable fonts to be selected use: |
---|
268 | |
---|
269 | gtk_font_selection_dialog_set_filter (GTK_FONT_SELECTION_DIALOG (fontsel), |
---|
270 | GTK_FONT_FILTER_BASE, GTK_FONT_SCALABLE, |
---|
271 | NULL, NULL, NULL, NULL, NULL, NULL); |
---|
272 | */ |
---|
273 | void gtk_font_selection_dialog_set_filter (GtkFontSelectionDialog *fsd, |
---|
274 | GtkFontFilterType filter_type, |
---|
275 | GtkFontType font_type, |
---|
276 | gchar **foundries, |
---|
277 | gchar **weights, |
---|
278 | gchar **slants, |
---|
279 | gchar **setwidths, |
---|
280 | gchar **spacings, |
---|
281 | gchar **charsets); |
---|
282 | |
---|
283 | /* This returns the text in the preview entry. You should copy the returned |
---|
284 | text if you need it. */ |
---|
285 | gchar* gtk_font_selection_dialog_get_preview_text (GtkFontSelectionDialog *fsd); |
---|
286 | |
---|
287 | /* This sets the text in the preview entry. It will be copied by the entry, |
---|
288 | so there's no need to g_strdup() it first. */ |
---|
289 | void gtk_font_selection_dialog_set_preview_text (GtkFontSelectionDialog *fsd, |
---|
290 | const gchar *text); |
---|
291 | |
---|
292 | |
---|
293 | #ifdef __cplusplus |
---|
294 | } |
---|
295 | #endif /* __cplusplus */ |
---|
296 | |
---|
297 | |
---|
298 | #endif /* __GTK_FONTSEL_H__ */ |
---|