1
/* LIBGIMP - The GIMP Library
2
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
6
* This library is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU Lesser General Public
8
* License as published by the Free Software Foundation; either
9
* version 2 of the License, or (at your option) any later version.
11
* This library is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* Library General Public License for more details.
16
* You should have received a copy of the GNU Lesser General Public
17
* License along with this library; if not, write to the
18
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19
* Boston, MA 02111-1307, USA.
27
typedef struct _GimpFontData GimpFontData;
34
GimpRunFontCallback callback;
40
/* local function prototypes */
42
static void gimp_temp_font_run (const gchar *name,
44
const GimpParam *param,
46
GimpParam **return_vals);
47
static gboolean gimp_temp_font_run_idle (GimpFontData *font_data);
50
/* private variables */
52
static GHashTable *gimp_font_select_ht = NULL;
55
/* public functions */
58
gimp_font_select_new (const gchar *title,
59
const gchar *font_name,
60
GimpRunFontCallback callback,
63
static GimpParamDef args[] =
65
{ GIMP_PDB_STRING, "str", "String" },
66
{ GIMP_PDB_INT32, "dialog status", "If the dialog was closing "
67
"[0 = No, 1 = Yes]" },
70
gchar *font_callback = gimp_procedural_db_temp_name ();
72
gimp_install_temp_proc (font_callback,
73
"Temporary font popup callback procedure",
81
G_N_ELEMENTS (args), 0,
85
if (gimp_fonts_popup (font_callback, title, font_name))
87
GimpFontData *font_data;
89
gimp_extension_enable (); /* Allow callbacks to be watched */
91
/* Now add to hash table so we can find it again */
92
if (! gimp_font_select_ht)
93
gimp_font_select_ht = g_hash_table_new_full (g_str_hash, g_str_equal,
96
font_data = g_new0 (GimpFontData, 1);
98
font_data->font_callback = font_callback;
99
font_data->callback = callback;
100
font_data->data = data;
102
g_hash_table_insert (gimp_font_select_ht, font_callback, font_data);
104
return font_callback;
107
gimp_uninstall_temp_proc (font_callback);
108
g_free (font_callback);
114
gimp_font_select_destroy (const gchar *font_callback)
116
GimpFontData *font_data;
118
g_return_if_fail (font_callback != NULL);
119
g_return_if_fail (gimp_font_select_ht != NULL);
121
font_data = g_hash_table_lookup (gimp_font_select_ht, font_callback);
125
g_warning ("Can't find internal font data");
129
if (font_data->idle_id)
130
g_source_remove (font_data->idle_id);
132
g_free (font_data->font_name);
134
if (font_data->font_callback)
135
gimp_fonts_close_popup (font_data->font_callback);
137
gimp_uninstall_temp_proc (font_callback);
139
g_hash_table_remove (gimp_font_select_ht, font_callback);
143
/* private functions */
146
gimp_temp_font_run (const gchar *name,
148
const GimpParam *param,
150
GimpParam **return_vals)
152
static GimpParam values[1];
153
GimpFontData *font_data;
155
font_data = g_hash_table_lookup (gimp_font_select_ht, name);
159
g_warning ("Can't find internal font data");
163
g_free (font_data->font_name);
165
font_data->font_name = g_strdup (param[0].data.d_string);
166
font_data->closing = param[1].data.d_int32;
168
if (! font_data->idle_id)
169
font_data->idle_id = g_idle_add ((GSourceFunc) gimp_temp_font_run_idle,
174
*return_vals = values;
176
values[0].type = GIMP_PDB_STATUS;
177
values[0].data.d_status = GIMP_PDB_SUCCESS;
181
gimp_temp_font_run_idle (GimpFontData *font_data)
183
font_data->idle_id = 0;
185
if (font_data->callback)
186
font_data->callback (font_data->font_name,
190
if (font_data->closing)
192
gchar *font_callback = font_data->font_callback;
194
font_data->font_callback = NULL;
195
gimp_font_select_destroy (font_callback);