gimppatternmenu.c 4.79 KB
Newer Older
1 2
/* LIBGIMP - The GIMP Library
 * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
3 4
 *
 * gimppatternmenu.c
5
 * Copyright (C) 1998 Andy Thomas
6
 *
7
 * This library is free software: you can redistribute it and/or
Marc Lehmann's avatar
Marc Lehmann committed
8
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation; either
10
 * version 3 of the License, or (at your option) any later version.
11 12 13 14
 *
 * 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
15 16
 * Library General Public License for more details.
 *
Marc Lehmann's avatar
Marc Lehmann committed
17
 * You should have received a copy of the GNU Lesser General Public
18 19
 * License along with this library.  If not, see
 * <http://www.gnu.org/licenses/>.
20 21
 */

Sven Neumann's avatar
Sven Neumann committed
22 23
#include "config.h"

24 25
#include <gtk/gtk.h>

26
#include "gimp.h"
27

28 29
#include "gimpuitypes.h"
#include "gimppatternmenu.h"
30
#include "gimppatternselectbutton.h"
31 32


33 34 35 36 37 38 39 40 41
/**
 * SECTION: gimppatternmenu
 * @title: gimppatternmenu
 * @short_description: A widget for selecting patterns.
 *
 * A widget for selecting patterns.
 **/


42
typedef struct
43
{
44 45
  GimpRunPatternCallback callback;
  gpointer               data;
46
} CompatCallbackData;
47

48 49 50 51 52 53 54 55 56 57

static void compat_callback           (GimpPatternSelectButton *pattern_button,
                                       const gchar             *pattern_name,
                                       gint                     width,
                                       gint                     height,
                                       gint                     bytes,
                                       const guchar            *mask_data,
                                       gboolean                 dialog_closing,
                                       CompatCallbackData      *data);
static void compat_callback_data_free (CompatCallbackData      *data);
58

59

60 61 62
/**
 * gimp_pattern_select_widget_new:
 * @title:        Title of the dialog to use or %NULL to use the default title.
63
 * @pattern_name: Initial pattern name or %NULL to use current selection.
64
 * @callback:     A function to call when the selected pattern changes.
65
 * @data:         A pointer to arbitrary data to be used in the call to @callback.
66 67 68 69 70 71 72
 *
 * Creates a new #GtkWidget that completely controls the selection of
 * a pattern. This widget is suitable for placement in a table in a
 * plug-in dialog.
 *
 * Returns: A #GtkWidget that you can use in your UI.
 */
73
GtkWidget *
74
gimp_pattern_select_widget_new (const gchar            *title,
75
                                const gchar            *pattern_name,
76 77
                                GimpRunPatternCallback  callback,
                                gpointer                data)
78
{
79 80
  GtkWidget          *pattern_button;
  CompatCallbackData *compat_data;
81

82
  g_return_val_if_fail (callback != NULL, NULL);
83

84
  pattern_button = gimp_pattern_select_button_new (title, pattern_name);
85

86 87
  compat_data = g_slice_new (CompatCallbackData);

88
  compat_data->callback = callback;
89
  compat_data->data     = data;
90

91 92
  g_signal_connect_data (pattern_button, "pattern-set",
                         G_CALLBACK (compat_callback),
93 94
                         compat_data,
                         (GClosureNotify) compat_callback_data_free, 0);
95

96
  return pattern_button;
97 98 99 100 101 102 103 104 105 106 107
}

/**
 * gimp_pattern_select_widget_close:
 * @widget: A pattern select widget.
 *
 * Closes the popup window associated with @widget.
 */
void
gimp_pattern_select_widget_close (GtkWidget *widget)
{
108
  g_return_if_fail (widget != NULL);
109

110
  gimp_select_button_close_popup (GIMP_SELECT_BUTTON (widget));
111 112 113 114 115
}

/**
 * gimp_pattern_select_widget_set:
 * @widget:       A pattern select widget.
116
 * @pattern_name: Pattern name to set. NULL means no change.
117 118 119 120 121 122 123 124 125
 *
 * Sets the current pattern for the pattern select widget.  Calls the
 * callback function if one was supplied in the call to
 * gimp_pattern_select_widget_new().
 */
void
gimp_pattern_select_widget_set (GtkWidget   *widget,
                                const gchar *pattern_name)
{
126
  g_return_if_fail (widget != NULL);
127

128 129
  gimp_pattern_select_button_set_pattern (GIMP_PATTERN_SELECT_BUTTON (widget),
                                          pattern_name);
130 131
}

132

133
static void
134 135 136 137 138 139 140
compat_callback (GimpPatternSelectButton *pattern_button,
                 const gchar             *pattern_name,
                 gint                     width,
                 gint                     height,
                 gint                     bpp,
                 const guchar            *mask_data,
                 gboolean                 dialog_closing,
141
                 CompatCallbackData      *data)
142
{
143 144 145
  data->callback (pattern_name, width, height, bpp, mask_data,
                  dialog_closing, data->data);
}
146

147 148 149 150
static void
compat_callback_data_free (CompatCallbackData *data)
{
  g_slice_free (CompatCallbackData, data);
151
}