~ubuntu-branches/ubuntu/maverick/gimp/maverick-updates

« back to all changes in this revision

Viewing changes to libgimp/gimpfontselect.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2005-12-09 19:44:52 UTC
  • Revision ID: james.westby@ubuntu.com-20051209194452-yggpemjlofpjqyf4
Tags: upstream-2.2.9
ImportĀ upstreamĀ versionĀ 2.2.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* LIBGIMP - The GIMP Library
 
2
 * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
 
3
 *
 
4
 * gimpfontselect.c
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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.
 
20
 */
 
21
 
 
22
#include "config.h"
 
23
 
 
24
#include "gimp.h"
 
25
 
 
26
 
 
27
typedef struct _GimpFontData GimpFontData;
 
28
 
 
29
struct _GimpFontData
 
30
{
 
31
  gchar               *font_callback;
 
32
  guint                idle_id;
 
33
  gchar               *font_name;
 
34
  GimpRunFontCallback  callback;
 
35
  gboolean             closing;
 
36
  gpointer             data;
 
37
};
 
38
 
 
39
 
 
40
/*  local function prototypes  */
 
41
 
 
42
static void      gimp_temp_font_run      (const gchar      *name,
 
43
                                          gint              nparams,
 
44
                                          const GimpParam  *param,
 
45
                                          gint             *nreturn_vals,
 
46
                                          GimpParam       **return_vals);
 
47
static gboolean  gimp_temp_font_run_idle (GimpFontData     *font_data);
 
48
 
 
49
 
 
50
/*  private variables  */
 
51
 
 
52
static GHashTable *gimp_font_select_ht = NULL;
 
53
 
 
54
 
 
55
/*  public functions  */
 
56
 
 
57
const gchar *
 
58
gimp_font_select_new (const gchar         *title,
 
59
                      const gchar         *font_name,
 
60
                      GimpRunFontCallback  callback,
 
61
                      gpointer             data)
 
62
{
 
63
  static GimpParamDef args[] =
 
64
  {
 
65
    { GIMP_PDB_STRING, "str",           "String" },
 
66
    { GIMP_PDB_INT32,  "dialog status", "If the dialog was closing "
 
67
                                        "[0 = No, 1 = Yes]" },
 
68
  };
 
69
 
 
70
  gchar *font_callback = gimp_procedural_db_temp_name ();
 
71
 
 
72
  gimp_install_temp_proc (font_callback,
 
73
                          "Temporary font popup callback procedure",
 
74
                          "",
 
75
                          "Andy Thomas",
 
76
                          "Andy Thomas",
 
77
                          "1997",
 
78
                          NULL,
 
79
                          "RGB*, GRAY*",
 
80
                          GIMP_TEMPORARY,
 
81
                          G_N_ELEMENTS (args), 0,
 
82
                          args, NULL,
 
83
                          gimp_temp_font_run);
 
84
 
 
85
  if (gimp_fonts_popup (font_callback, title, font_name))
 
86
    {
 
87
      GimpFontData *font_data;
 
88
 
 
89
      gimp_extension_enable (); /* Allow callbacks to be watched */
 
90
 
 
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,
 
94
                                                     g_free, g_free);
 
95
 
 
96
      font_data = g_new0 (GimpFontData, 1);
 
97
 
 
98
      font_data->font_callback = font_callback;
 
99
      font_data->callback      = callback;
 
100
      font_data->data          = data;
 
101
 
 
102
      g_hash_table_insert (gimp_font_select_ht, font_callback, font_data);
 
103
 
 
104
      return font_callback;
 
105
    }
 
106
 
 
107
  gimp_uninstall_temp_proc (font_callback);
 
108
  g_free (font_callback);
 
109
 
 
110
  return NULL;
 
111
}
 
112
 
 
113
void
 
114
gimp_font_select_destroy (const gchar *font_callback)
 
115
{
 
116
  GimpFontData *font_data;
 
117
 
 
118
  g_return_if_fail (font_callback != NULL);
 
119
  g_return_if_fail (gimp_font_select_ht != NULL);
 
120
 
 
121
  font_data = g_hash_table_lookup (gimp_font_select_ht, font_callback);
 
122
 
 
123
  if (! font_data)
 
124
    {
 
125
      g_warning ("Can't find internal font data");
 
126
      return;
 
127
    }
 
128
 
 
129
  if (font_data->idle_id)
 
130
    g_source_remove (font_data->idle_id);
 
131
 
 
132
  g_free (font_data->font_name);
 
133
 
 
134
  if (font_data->font_callback)
 
135
    gimp_fonts_close_popup (font_data->font_callback);
 
136
 
 
137
  gimp_uninstall_temp_proc (font_callback);
 
138
 
 
139
  g_hash_table_remove (gimp_font_select_ht, font_callback);
 
140
}
 
141
 
 
142
 
 
143
/*  private functions  */
 
144
 
 
145
static void
 
146
gimp_temp_font_run (const gchar      *name,
 
147
                    gint              nparams,
 
148
                    const GimpParam  *param,
 
149
                    gint             *nreturn_vals,
 
150
                    GimpParam       **return_vals)
 
151
{
 
152
  static GimpParam  values[1];
 
153
  GimpFontData     *font_data;
 
154
 
 
155
  font_data = g_hash_table_lookup (gimp_font_select_ht, name);
 
156
 
 
157
  if (! font_data)
 
158
    {
 
159
      g_warning ("Can't find internal font data");
 
160
    }
 
161
  else
 
162
    {
 
163
      g_free (font_data->font_name);
 
164
 
 
165
      font_data->font_name = g_strdup (param[0].data.d_string);
 
166
      font_data->closing   = param[1].data.d_int32;
 
167
 
 
168
      if (! font_data->idle_id)
 
169
        font_data->idle_id = g_idle_add ((GSourceFunc) gimp_temp_font_run_idle,
 
170
                                         font_data);
 
171
    }
 
172
 
 
173
  *nreturn_vals = 1;
 
174
  *return_vals  = values;
 
175
 
 
176
  values[0].type          = GIMP_PDB_STATUS;
 
177
  values[0].data.d_status = GIMP_PDB_SUCCESS;
 
178
}
 
179
 
 
180
static gboolean
 
181
gimp_temp_font_run_idle (GimpFontData *font_data)
 
182
{
 
183
  font_data->idle_id = 0;
 
184
 
 
185
  if (font_data->callback)
 
186
    font_data->callback (font_data->font_name,
 
187
                         font_data->closing,
 
188
                         font_data->data);
 
189
 
 
190
  if (font_data->closing)
 
191
    {
 
192
      gchar *font_callback = font_data->font_callback;
 
193
 
 
194
      font_data->font_callback = NULL;
 
195
      gimp_font_select_destroy (font_callback);
 
196
    }
 
197
 
 
198
  return FALSE;
 
199
}