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. Weight, Slant, Set Width, Spacing, Charset & Foundry. */
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 & 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
65 /* Used to determine whether we are using point or pixel sizes. */
73 struct _GtkFontSelection
77 /* These are on the font page. */
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;
93 /* These are on the font info page. */
95 GtkWidget *info_clist;
96 GtkWidget *requested_font_name;
97 GtkWidget *actual_font_name;
99 /* These are on the filter page. */
100 GtkWidget *filter_vbox;
101 GtkWidget *filter_clists[GTK_NUM_FONT_PROPERTIES];
106 GtkFontMetricType metric;
107 /* The size is either in pixels or deci-points, depending on the metric. */
110 /* This is the last size explicitly selected. When the user selects different
111 fonts we try to find the nearest size to this. */
114 /* This flag determines if scaled bitmapped fonts are acceptable. */
115 gboolean scale_bitmapped_fonts;
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];
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];
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;
133 struct _GtkFontSelectionClass
135 GtkNotebookClass parent_class;
139 struct _GtkFontSelectionDialog
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;
152 /* If the user changes the width of the dialog, we turn auto-shrink off. */
154 gboolean auto_resize;
157 struct _GtkFontSelectionDialogClass
159 GtkWindowClass parent_class;
166 guint gtk_font_selection_get_type (void);
167 GtkWidget* gtk_font_selection_new (void);
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);
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);
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);
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);
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,
199 /* FontSelectionDialog */
201 guint gtk_font_selection_dialog_get_type (void);
202 GtkWidget* gtk_font_selection_dialog_new (const gchar *title);
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,
220 #endif /* __cplusplus */
223 #endif /* __GTK_FONTSEL_H__ */