1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimppickbutton.c
* Copyright (C) 2002 Michael Natterer <mitch@gimp.org>
*
* based on gtk+/gtk/gtkcolorsel.c
*
* 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, see
* <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gegl.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include "libgimpcolor/gimpcolor.h"
#include "gimpwidgetstypes.h"
#include "gimpcairo-utils.h"
#include "gimphelpui.h"
#include "gimpicons.h"
#include "gimppickbutton.h"
#include "gimppickbutton-default.h"
#include "gimppickbutton-kwin.h"
#ifdef GDK_WINDOWING_QUARTZ
#include "gimppickbutton-quartz.h"
#endif
#include "libgimp/libgimp-intl.h"
/**
* SECTION: gimppickbutton
* @title: GimpPickButton
* @short_description: Widget to pick a color from screen.
*
* #GimpPickButton is a specialized button. When clicked, it changes
* the cursor to a color-picker pipette and allows the user to pick a
* color from any point on the screen.
**/
enum
{
COLOR_PICKED,
LAST_SIGNAL
};
static void gimp_pick_button_dispose (GObject *object);
static void gimp_pick_button_clicked (GtkButton *button);
G_DEFINE_TYPE (GimpPickButton, gimp_pick_button, GTK_TYPE_BUTTON)
#define parent_class gimp_pick_button_parent_class
static guint pick_button_signals[LAST_SIGNAL] = { 0 };
static void
gimp_pick_button_class_init (GimpPickButtonClass* klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkButtonClass *button_class = GTK_BUTTON_CLASS (klass);
/**
* GimpPickButton::color-picked:
* @gimppickbutton: the object which received the signal.
* @arg1: pointer to a #GimpRGB structure that holds the picked color
*
* This signal is emitted when the user has picked a color.
**/
pick_button_signals[COLOR_PICKED] =
g_signal_new ("color-picked",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpPickButtonClass, color_picked),
NULL, NULL,
g_cclosure_marshal_VOID__POINTER,
G_TYPE_NONE, 1,
G_TYPE_POINTER);
object_class->dispose = gimp_pick_button_dispose;
button_class->clicked = gimp_pick_button_clicked;
klass->color_picked = NULL;
}
static void
gimp_pick_button_init (GimpPickButton *button)
{
GtkWidget *image;
image = gtk_image_new_from_icon_name (GIMP_ICON_COLOR_PICK_FROM_SCREEN,
GTK_ICON_SIZE_BUTTON);
gtk_container_add (GTK_CONTAINER (button), image);
gtk_widget_show (image);
gimp_help_set_help_data (GTK_WIDGET (button),
_("Click the eyedropper, then click a color "
"anywhere on your screen to select that color."),
NULL);
}
static void
gimp_pick_button_dispose (GObject *object)
{
GimpPickButton *button = GIMP_PICK_BUTTON (object);
if (button->cursor)
{
gdk_cursor_unref (button->cursor);
button->cursor = NULL;
}
if (button->grab_widget)
{
gtk_widget_destroy (button->grab_widget);
button->grab_widget = NULL;
}
G_OBJECT_CLASS (parent_class)->dispose (object);
}
static void
gimp_pick_button_clicked (GtkButton *button)
{
#ifdef GDK_WINDOWING_QUARTZ
_gimp_pick_button_quartz_pick (GIMP_PICK_BUTTON (button));
#else
if (_gimp_pick_button_kwin_available ())
_gimp_pick_button_kwin_pick (GIMP_PICK_BUTTON (button));
else
_gimp_pick_button_default_pick (GIMP_PICK_BUTTON (button));
#endif
}
/* public functions */
/**
* gimp_pick_button_new:
*
* Creates a new #GimpPickButton widget.
*
* Returns: A new #GimpPickButton widget.
**/
GtkWidget *
gimp_pick_button_new (void)
{
return g_object_new (GIMP_TYPE_PICK_BUTTON, NULL);
}
|