gimpfontmenu.c 4.01 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/* LIBGIMP - The GIMP Library
 * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
 *
 * gimpfontmenu.c
 * Copyright (C) 2003  Sven Neumann  <sven@gimp.org>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include "config.h"

25 26
#include <gtk/gtk.h>

27
#include "gimp.h"
28 29 30 31 32 33

#include "gimpuitypes.h"
#include "gimpfontselectbutton.h"

#undef GIMP_DISABLE_DEPRECATED
#include "gimpfontmenu.h"
34

35

36
typedef struct
37
{
38 39
  GimpRunFontCallback callback;
  gpointer            data;
40
} CompatCallbackData;
41 42


43 44 45 46 47
static void compat_callback           (GimpFontSelectButton *font_button,
                                       const gchar          *font_name,
                                       gboolean              dialog_closing,
                                       CompatCallbackData   *data);
static void compat_callback_data_free (CompatCallbackData   *data);
48

49 50

/**
51
 * gimp_font_select_widget_new:
52
 * @title:     Title of the dialog to use or %NULL to use the default title.
53
 * @font_name: Initial font name.
54 55
 * @callback:  A function to call when the selected font changes.
 * @data:      A pointer to arbitary data to be used in the call to @callback.
56
 *
57 58
 * Creates a new #GtkWidget that completely controls the selection of
 * a font.  This widget is suitable for placement in a table in a
59 60
 * plug-in dialog.
 *
61
 * Returns: A #GtkWidget that you can use in your UI.
62
 */
63
GtkWidget *
64
gimp_font_select_widget_new (const gchar         *title,
65
                             const gchar         *font_name,
66 67
                             GimpRunFontCallback  callback,
                             gpointer             data)
68
{
69 70
  GtkWidget          *font_button;
  CompatCallbackData *compat_data;
71

72
  g_return_val_if_fail (callback != NULL, NULL);
73

74
  font_button = gimp_font_select_button_new (title, font_name);
75

76 77
  compat_data = g_slice_new (CompatCallbackData);

78
  compat_data->callback = callback;
79
  compat_data->data     = data;
80

81 82
  g_signal_connect_data (font_button, "font-set",
                         G_CALLBACK (compat_callback),
83 84
                         compat_data,
                         (GClosureNotify) compat_callback_data_free, 0);
85

86
  return font_button;
87 88 89
}

/**
90
 * gimp_font_select_widget_close:
91 92 93 94 95
 * @widget: A font select widget.
 *
 * Closes the popup window associated with @widget.
 */
void
96
gimp_font_select_widget_close (GtkWidget *widget)
97
{
98
  g_return_if_fail (widget != NULL);
99

100
  gimp_select_button_close_popup (GIMP_SELECT_BUTTON (widget));
101 102 103
}

/**
104 105
 * gimp_font_select_widget_set;
 * @widget:    A font select widget.
106
 * @font_name: Font name to set; %NULL means no change.
107
 *
108 109 110
 * Sets the current font for the font select widget.  Calls the
 * callback function if one was supplied in the call to
 * gimp_font_select_widget_new().
111 112
 */
void
113 114
gimp_font_select_widget_set (GtkWidget   *widget,
                             const gchar *font_name)
115
{
116
  g_return_if_fail (widget != NULL);
117

118 119
  gimp_font_select_button_set_font (GIMP_FONT_SELECT_BUTTON (widget),
                                    font_name);
120 121
}

122

123
static void
124 125 126
compat_callback (GimpFontSelectButton *font_button,
                 const gchar          *font_name,
                 gboolean              dialog_closing,
127
                 CompatCallbackData   *data)
128
{
129 130
  data->callback (font_name, dialog_closing, data->data);
}
131

132 133 134 135
static void
compat_callback_data_free (CompatCallbackData *data)
{
  g_slice_free (CompatCallbackData, data);
136
}