1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
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.
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.
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.
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.
24 #ifndef __GTK_FONTSEL_H__
25 #define __GTK_FONTSEL_H__
29 #include <gtk/gtkwindow.h>
30 #include <gtk/gtknotebook.h>
36 #endif /* __cplusplus */
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())
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 ())
46 typedef struct _GtkFontSelection GtkFontSelection;
47 typedef struct _GtkFontSelectionClass GtkFontSelectionClass;
49 typedef struct _GtkFontSelectionDialog GtkFontSelectionDialog;
50 typedef struct _GtkFontSelectionDialogClass GtkFontSelectionDialogClass;
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
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
64 /* Used to determine whether we are using point or pixel sizes. */
72 struct _GtkFontSelection
76 /* These are on the font page. */
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;
92 /* These are on the font info page. */
94 GtkWidget *info_clist;
95 GtkWidget *requested_font_name;
96 GtkWidget *actual_font_name;
98 /* These are on the filter page. */
99 GtkWidget *filter_vbox;
100 GtkWidget *filter_clists[GTK_NUM_FONT_PROPERTIES];
105 GtkFontMetricType metric;
106 /* The size is either in pixels or deci-points, depending on the metric. */
109 /* This is the last size explicitly selected. When the user selects different
110 fonts we try to find the nearest size to this. */
113 /* This flag determines if scaled bitmapped fonts are acceptable. */
114 gboolean scale_bitmapped_fonts;
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];
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];
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;
132 struct _GtkFontSelectionClass
134 GtkWindowClass parent_class;
138 struct _GtkFontSelectionDialog
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;
151 /* If the user changes the width of the dialog, we turn auto-shrink off. */
153 gboolean auto_resize;
156 struct _GtkFontSelectionDialogClass
158 GtkWindowClass parent_class;
165 guint gtk_font_selection_get_type (void);
166 GtkWidget* gtk_font_selection_new (void);
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);
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);
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);
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);
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,
198 /* FontSelectionDialog */
200 guint gtk_font_selection_dialog_get_type (void);
201 GtkWidget* gtk_font_selection_dialog_new (const gchar *title);
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,
219 #endif /* __cplusplus */
222 #endif /* __GTK_FONTSEL_H__ */