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