]> Pileus Git - ~andy/gtk/blob - gtk/gtkfontsel.h
Moved font lists from the klass structure to a static structure in
[~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 #ifndef __GTK_FONTSEL_H__
25 #define __GTK_FONTSEL_H__
26
27
28 #include <gdk/gdk.h>
29 #include <gtk/gtkwindow.h>
30 #include <gtk/gtknotebook.h>
31
32
33 #ifdef __cplusplus
34 extern "C" {
35 #pragma }
36 #endif /* __cplusplus */
37
38 #define GTK_FONT_SELECTION(obj)         GTK_CHECK_CAST(obj, gtk_font_selection_get_type(), GtkFontSelection)
39 #define GTK_FONT_SELECTION_CLASS(klass) GTK_CHECK_CLASS_CAST(klass, gtk_font_selection_get_type(), GtkFontSelectionClass)
40 #define GTK_IS_FONT_SELECTION(obj)      GTK_CHECK_TYPE(obj, gtk_font_selection_get_type())
41
42 #define GTK_FONT_SELECTION_DIALOG(obj)          GTK_CHECK_CAST (obj, gtk_font_selection_dialog_get_type (), GtkFontSelectionDialog)
43 #define GTK_FONT_SELECTION_DIALOG_CLASS(klass)  GTK_CHECK_CLASS_CAST (klass, gtk_font_selection_dialog_get_type (), GtkFontSelectionDialogClass)
44 #define GTK_IS_FONT_SELECTION_DIALOG(obj)       GTK_CHECK_TYPE (obj, gtk_font_selection_dialog_get_type ())
45
46 typedef struct _GtkFontSelection             GtkFontSelection;
47 typedef struct _GtkFontSelectionClass        GtkFontSelectionClass;
48
49 typedef struct _GtkFontSelectionDialog       GtkFontSelectionDialog;
50 typedef struct _GtkFontSelectionDialogClass  GtkFontSelectionDialogClass;
51
52
53
54
55 /* This is the number of properties which we keep in the properties array,
56    i.e. Foundry, Weight, Slant, Set Width & Spacing. */
57 #define GTK_NUM_FONT_PROPERTIES  6
58
59 /* This is the number of properties each style has i.e. Weight, Slant,
60    Set Width & Spacing. Note that Foundry is not included. */
61 #define GTK_NUM_STYLE_PROPERTIES 5
62
63
64 /* Used to determine whether we are using point or pixel sizes. */
65 typedef enum
66 {
67   PIXELS_METRIC,
68   POINTS_METRIC
69 } GtkFontMetricType;
70
71
72 struct _GtkFontSelection
73 {
74   GtkNotebook notebook;
75
76   /* These are on the font page. */
77   GtkWidget *main_vbox;
78   GtkWidget *font_label;
79   GtkWidget *font_entry;
80   GtkWidget *font_clist;
81   GtkWidget *font_style_entry;
82   GtkWidget *font_style_clist;
83   GtkWidget *size_entry;
84   GtkWidget *size_clist;
85   GtkWidget *pixels_button;
86   GtkWidget *points_button;
87   GtkWidget *filter_button;
88   GtkWidget *scaled_bitmaps_button;
89   GtkWidget *preview_entry;
90   GtkWidget *message_label;
91
92   /* These are on the font info page. */
93   GtkWidget *info_vbox;
94   GtkWidget *info_clist;
95   GtkWidget *requested_font_name;
96   GtkWidget *actual_font_name;
97
98   /* These are on the filter page. */
99   GtkWidget *filter_vbox;
100   GtkWidget *filter_clists[GTK_NUM_FONT_PROPERTIES];
101
102   GdkFont *font;
103   gint font_index;
104   gint style;
105   GtkFontMetricType metric;
106   /* The size is either in pixels or deci-points, depending on the metric. */
107   gint size;
108
109   /* This is the last size explicitly selected. When the user selects different
110      fonts we try to find the nearest size to this. */
111   gint selected_size;
112
113   /* This flag determines if scaled bitmapped fonts are acceptable. */
114   gboolean scale_bitmapped_fonts;
115
116   /* These are the current property settings. They are indexes into the
117      strings in the class' properties array. */
118   guint16 property_values[GTK_NUM_STYLE_PROPERTIES];
119
120   /* These hold the arrays of current filter settings for each property.
121      If nfilters is 0 then all values of the property are OK. If not the
122      filters array contains the indexes of the valid property values. */
123   guint16 *property_filters[GTK_NUM_FONT_PROPERTIES];
124   guint16 property_nfilters[GTK_NUM_FONT_PROPERTIES];
125
126   /* This flags is set to scroll the clist to the selected value as soon as
127      it appears. There might be a better way of doing this. */
128   gboolean scroll_on_expose;
129 };
130
131
132 struct _GtkFontSelectionClass
133 {
134   GtkWindowClass parent_class;
135 };
136
137
138 struct _GtkFontSelectionDialog
139 {
140   GtkWindow window;
141
142   GtkWidget *fontsel;
143
144   GtkWidget *main_vbox;
145   GtkWidget *action_area;
146   GtkWidget *ok_button;
147   /* The 'Apply' button is not shown by default but you can show/hide it. */
148   GtkWidget *apply_button;
149   GtkWidget *cancel_button;
150
151   /* If the user changes the width of the dialog, we turn auto-shrink off. */
152   gint dialog_width;
153   gboolean auto_resize;
154 };
155
156 struct _GtkFontSelectionDialogClass
157 {
158   GtkWindowClass parent_class;
159 };
160
161
162
163 /* FontSelection */
164
165 guint      gtk_font_selection_get_type          (void);
166 GtkWidget* gtk_font_selection_new               (void);
167
168 /* This returns the X Logical Font Description fontname, or NULL if no font
169    is selected. Note that there is a slight possibility that the font might not
170    have been loaded OK. You should call gtk_font_selection_get_font() to see
171    if it has been loaded OK.
172    You should g_free() the returned font name after you're done with it. */
173 gchar*     gtk_font_selection_get_font_name     (GtkFontSelection *fontsel);
174
175 /* This will return the current GdkFont, or NULL if none is selected or there
176    was a problem loading it. Remember to use gdk_font_ref/unref() if you want
177    to use the font (in a style, for example). */
178 GdkFont*   gtk_font_selection_get_font          (GtkFontSelection *fontsel);
179
180 /* This sets the currently displayed font. It should be a valid X Logical
181    Font Description font name (anything else will be ignored), e.g.
182    "-adobe-courier-bold-o-normal--25-*-*-*-*-*-*-*" 
183    It returns TRUE on success. */
184 gboolean   gtk_font_selection_set_font_name     (GtkFontSelection *fontsel,
185                                                  const gchar      *fontname);
186
187 /* This returns the text in the preview entry. You should copy the returned
188    text if you need it. */
189 gchar*     gtk_font_selection_get_preview_text  (GtkFontSelection *fontsel);
190
191 /* This sets the text in the preview entry. It will be copied by the entry,
192    so there's no need to g_strdup() it first. */
193 void       gtk_font_selection_set_preview_text  (GtkFontSelection *fontsel,
194                                                  const gchar      *text);
195
196
197
198 /* FontSelectionDialog */
199
200 guint      gtk_font_selection_dialog_get_type   (void);
201 GtkWidget* gtk_font_selection_dialog_new        (const gchar      *title);
202
203 /* These simply call the corresponding FontSelection function. */
204 gchar*     gtk_font_selection_dialog_get_font_name
205                                                 (GtkFontSelectionDialog *fsd);
206 GdkFont*   gtk_font_selection_dialog_get_font   (GtkFontSelectionDialog *fsd);
207 gboolean   gtk_font_selection_dialog_set_font_name
208                                                 (GtkFontSelectionDialog *fsd,
209                                                  const gchar      *fontname);
210 gchar*     gtk_font_selection_dialog_get_preview_text
211                                                 (GtkFontSelectionDialog *fsd);
212 void       gtk_font_selection_dialog_set_preview_text
213                                                 (GtkFontSelectionDialog *fsd,
214                                                  const gchar      *text);
215
216
217 #ifdef __cplusplus
218 }
219 #endif /* __cplusplus */
220
221
222 #endif /* __GTK_FONTSEL_H__ */