]> Pileus Git - ~andy/gtk/blob - gtk/gtkfontsel.h
Fix typo: Italian uses ISO-8859-1, not -2. Add en_GB.
[~andy/gtk] / gtk / gtkfontsel.h
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 #define GTK_FONT_SELECTION_GET_CLASS(obj)    (GTK_CHECK_GET_CLASS ((obj), GTK_TYPE_FONT_SELECTION, GtkFontSelectionClass))
50
51
52 #define GTK_TYPE_FONT_SELECTION_DIALOG              (gtk_font_selection_dialog_get_type ())
53 #define GTK_FONT_SELECTION_DIALOG(obj)              (GTK_CHECK_CAST ((obj), GTK_TYPE_FONT_SELECTION_DIALOG, GtkFontSelectionDialog))
54 #define GTK_FONT_SELECTION_DIALOG_CLASS(klass)      (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_FONT_SELECTION_DIALOG, GtkFontSelectionDialogClass))
55 #define GTK_IS_FONT_SELECTION_DIALOG(obj)           (GTK_CHECK_TYPE ((obj), GTK_TYPE_FONT_SELECTION_DIALOG))
56 #define GTK_IS_FONT_SELECTION_DIALOG_CLASS(klass)   (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_FONT_SELECTION_DIALOG))
57 #define GTK_FONT_SELECTION_DIALOG_GET_CLASS(obj)    (GTK_CHECK_GET_CLASS ((obj), GTK_TYPE_FONT_SELECTION_DIALOG, GtkFontSelectionDialogClass))
58
59
60 typedef struct _GtkFontSelection             GtkFontSelection;
61 typedef struct _GtkFontSelectionClass        GtkFontSelectionClass;
62
63 typedef struct _GtkFontSelectionDialog       GtkFontSelectionDialog;
64 typedef struct _GtkFontSelectionDialogClass  GtkFontSelectionDialogClass;
65
66
67
68
69 /* This is the number of properties which we keep in the properties array,
70    i.e. Weight, Slant, Set Width, Spacing, Charset & Foundry. */
71 #define GTK_NUM_FONT_PROPERTIES  6
72
73 /* This is the number of properties each style has i.e. Weight, Slant,
74    Set Width, Spacing & Charset. Note that Foundry is not included,
75    since it is the same for all styles of the same FontInfo. */
76 #define GTK_NUM_STYLE_PROPERTIES 5
77
78
79 /* Used to determine whether we are using point or pixel sizes. */
80 typedef enum
81 {
82   GTK_FONT_METRIC_PIXELS,
83   GTK_FONT_METRIC_POINTS
84 } GtkFontMetricType;
85
86 /* Used for determining the type of a font style, and also for setting filters.
87    These can be combined if a style has bitmaps and scalable fonts available.*/
88 typedef enum
89 {
90   GTK_FONT_BITMAP               = 1 << 0,
91   GTK_FONT_SCALABLE             = 1 << 1,
92   GTK_FONT_SCALABLE_BITMAP      = 1 << 2,
93
94   GTK_FONT_ALL                  = 0x07
95 } GtkFontType;
96
97 /* These are the two types of filter available - base and user. The base
98    filter is set by the application and can't be changed by the user. */
99 #define GTK_NUM_FONT_FILTERS    2
100 typedef enum
101 {
102   GTK_FONT_FILTER_BASE,
103   GTK_FONT_FILTER_USER
104 } GtkFontFilterType;
105
106 /* These hold the arrays of current filter settings for each property.
107    If nfilters is 0 then all values of the property are OK. If not the
108    filters array contains the indexes of the valid property values. */
109 typedef struct _GtkFontFilter   GtkFontFilter;
110 struct _GtkFontFilter
111 {
112   gint font_type;
113   guint16 *property_filters[GTK_NUM_FONT_PROPERTIES];
114   guint16 property_nfilters[GTK_NUM_FONT_PROPERTIES];
115 };
116
117
118 struct _GtkFontSelection
119 {
120   GtkNotebook notebook;
121   
122   /* These are on the font page. */
123   GtkWidget *main_vbox;
124   GtkWidget *font_label;
125   GtkWidget *font_entry;
126   GtkWidget *font_clist;
127   GtkWidget *font_style_entry;
128   GtkWidget *font_style_clist;
129   GtkWidget *size_entry;
130   GtkWidget *size_clist;
131   GtkWidget *pixels_button;
132   GtkWidget *points_button;
133   GtkWidget *filter_button;
134   GtkWidget *preview_entry;
135   GtkWidget *message_label;
136   
137   /* These are on the font info page. */
138   GtkWidget *info_vbox;
139   GtkWidget *info_clist;
140   GtkWidget *requested_font_name;
141   GtkWidget *actual_font_name;
142   
143   /* These are on the filter page. */
144   GtkWidget *filter_vbox;
145   GtkWidget *type_bitmaps_button;
146   GtkWidget *type_scalable_button;
147   GtkWidget *type_scaled_bitmaps_button;
148   GtkWidget *filter_clists[GTK_NUM_FONT_PROPERTIES];
149   
150   GdkFont *font;
151   gint font_index;
152   gint style;
153   GtkFontMetricType metric;
154   /* The size is either in pixels or deci-points, depending on the metric. */
155   gint size;
156   
157   /* This is the last size explicitly selected. When the user selects different
158      fonts we try to find the nearest size to this. */
159   gint selected_size;
160   
161   /* These are the current property settings. They are indexes into the
162      strings in the GtkFontSelInfo properties array. */
163   guint16 property_values[GTK_NUM_STYLE_PROPERTIES];
164   
165   /* These are the base and user font filters. */
166   GtkFontFilter filters[GTK_NUM_FONT_FILTERS];
167 };
168
169
170 struct _GtkFontSelectionClass
171 {
172   GtkNotebookClass parent_class;
173 };
174
175
176 struct _GtkFontSelectionDialog
177 {
178   GtkWindow window;
179   
180   GtkWidget *fontsel;
181   
182   GtkWidget *main_vbox;
183   GtkWidget *action_area;
184   GtkWidget *ok_button;
185   /* The 'Apply' button is not shown by default but you can show/hide it. */
186   GtkWidget *apply_button;
187   GtkWidget *cancel_button;
188   
189   /* If the user changes the width of the dialog, we turn auto-shrink off. */
190   gint dialog_width;
191   gboolean auto_resize;
192 };
193
194 struct _GtkFontSelectionDialogClass
195 {
196   GtkWindowClass parent_class;
197 };
198
199
200
201 /*****************************************************************************
202  * GtkFontSelection functions.
203  *   see the comments in the GtkFontSelectionDialog functions.
204  *****************************************************************************/
205
206 GtkType    gtk_font_selection_get_type          (void);
207 GtkWidget* gtk_font_selection_new               (void);
208 gchar*     gtk_font_selection_get_font_name     (GtkFontSelection *fontsel);
209 GdkFont*   gtk_font_selection_get_font          (GtkFontSelection *fontsel);
210 gboolean   gtk_font_selection_set_font_name     (GtkFontSelection *fontsel,
211                                                  const gchar      *fontname);
212 void       gtk_font_selection_set_filter        (GtkFontSelection *fontsel,
213                                                  GtkFontFilterType filter_type,
214                                                  GtkFontType       font_type,
215                                                  gchar           **foundries,
216                                                  gchar           **weights,
217                                                  gchar           **slants,
218                                                  gchar           **setwidths,
219                                                  gchar           **spacings,
220                                                  gchar           **charsets);
221 gchar*     gtk_font_selection_get_preview_text  (GtkFontSelection *fontsel);
222 void       gtk_font_selection_set_preview_text  (GtkFontSelection *fontsel,
223                                                  const gchar      *text);
224
225
226
227 /*****************************************************************************
228  * GtkFontSelectionDialog functions.
229  *   most of these functions simply call the corresponding function in the
230  *   GtkFontSelection.
231  *****************************************************************************/
232
233 GtkType    gtk_font_selection_dialog_get_type   (void);
234 GtkWidget* gtk_font_selection_dialog_new        (const gchar      *title);
235
236 /* This returns the X Logical Font Description fontname, or NULL if no font
237    is selected. Note that there is a slight possibility that the font might not
238    have been loaded OK. You should call gtk_font_selection_dialog_get_font()
239    to see if it has been loaded OK.
240    You should g_free() the returned font name after you're done with it. */
241 gchar*   gtk_font_selection_dialog_get_font_name    (GtkFontSelectionDialog *fsd);
242
243 /* This will return the current GdkFont, or NULL if none is selected or there
244    was a problem loading it. Remember to use gdk_font_ref/unref() if you want
245    to use the font (in a style, for example). */
246 GdkFont* gtk_font_selection_dialog_get_font         (GtkFontSelectionDialog *fsd);
247
248 /* This sets the currently displayed font. It should be a valid X Logical
249    Font Description font name (anything else will be ignored), e.g.
250    "-adobe-courier-bold-o-normal--25-*-*-*-*-*-*-*" 
251    It returns TRUE on success. */
252 gboolean gtk_font_selection_dialog_set_font_name    (GtkFontSelectionDialog *fsd,
253                                                      const gchar        *fontname);
254
255 /* This sets one of the font filters, to limit the fonts shown. The filter_type
256    is GTK_FONT_FILTER_BASE or GTK_FONT_FILTER_USER. The font type is a
257    combination of the bit flags GTK_FONT_BITMAP, GTK_FONT_SCALABLE and
258    GTK_FONT_SCALABLE_BITMAP (or GTK_FONT_ALL for all font types).
259    The foundries, weights etc. are arrays of strings containing property
260    values, e.g. 'bold', 'demibold', and *MUST* finish with a NULL.
261    Standard long names are also accepted, e.g. 'italic' instead of 'i'.
262
263    e.g. to allow only fixed-width fonts ('char cell' or 'monospaced') to be
264    selected use:
265
266   gchar *spacings[] = { "c", "m", NULL };
267   gtk_font_selection_dialog_set_filter (GTK_FONT_SELECTION_DIALOG (fontsel),
268                                        GTK_FONT_FILTER_BASE, GTK_FONT_ALL,
269                                        NULL, NULL, NULL, NULL, spacings, NULL);
270
271   to allow only true scalable fonts to be selected use:
272
273   gtk_font_selection_dialog_set_filter (GTK_FONT_SELECTION_DIALOG (fontsel),
274                                        GTK_FONT_FILTER_BASE, GTK_FONT_SCALABLE,
275                                        NULL, NULL, NULL, NULL, NULL, NULL);
276 */
277 void       gtk_font_selection_dialog_set_filter (GtkFontSelectionDialog *fsd,
278                                                  GtkFontFilterType filter_type,
279                                                  GtkFontType       font_type,
280                                                  gchar           **foundries,
281                                                  gchar           **weights,
282                                                  gchar           **slants,
283                                                  gchar           **setwidths,
284                                                  gchar           **spacings,
285                                                  gchar           **charsets);
286
287 /* This returns the text in the preview entry. You should copy the returned
288    text if you need it. */
289 gchar*   gtk_font_selection_dialog_get_preview_text (GtkFontSelectionDialog *fsd);
290
291 /* This sets the text in the preview entry. It will be copied by the entry,
292    so there's no need to g_strdup() it first. */
293 void     gtk_font_selection_dialog_set_preview_text (GtkFontSelectionDialog *fsd,
294                                                      const gchar            *text);
295
296
297 #ifdef __cplusplus
298 }
299 #endif /* __cplusplus */
300
301
302 #endif /* __GTK_FONTSEL_H__ */