2002-11-05 06:56:41 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
|
|
|
*
|
|
|
|
* gimppickbutton.c
|
|
|
|
* Copyright (C) 2002 Michael Natterer <mitch@gimp.org>
|
|
|
|
*
|
2004-02-08 23:47:20 +08:00
|
|
|
* based on gtk+/gtk/gtkcolorsel.c
|
2002-11-05 06:56:41 +08:00
|
|
|
*
|
|
|
|
* 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
|
2009-01-18 06:28:01 +08:00
|
|
|
* License along with this library. If not, see
|
2018-07-12 05:27:07 +08:00
|
|
|
* <https://www.gnu.org/licenses/>.
|
2002-11-05 06:56:41 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2012-05-03 09:36:22 +08:00
|
|
|
#include <gegl.h>
|
2002-11-05 06:56:41 +08:00
|
|
|
#include <gtk/gtk.h>
|
2012-03-30 21:08:54 +08:00
|
|
|
#include <gdk/gdkkeysyms.h>
|
2002-11-05 06:56:41 +08:00
|
|
|
|
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
|
|
|
|
|
|
|
#include "gimpwidgetstypes.h"
|
|
|
|
|
2010-08-08 22:10:14 +08:00
|
|
|
#include "gimpcairo-utils.h"
|
2002-11-05 06:56:41 +08:00
|
|
|
#include "gimphelpui.h"
|
2015-12-13 03:44:46 +08:00
|
|
|
#include "gimpicons.h"
|
2002-11-05 06:56:41 +08:00
|
|
|
#include "gimppickbutton.h"
|
2017-12-09 06:57:09 +08:00
|
|
|
#include "gimppickbutton-default.h"
|
|
|
|
#include "gimppickbutton-kwin.h"
|
2010-12-29 23:20:00 +08:00
|
|
|
#include "gimppickbutton-private.h"
|
2017-12-09 06:57:09 +08:00
|
|
|
|
|
|
|
#ifdef GDK_WINDOWING_QUARTZ
|
|
|
|
#include "gimppickbutton-quartz.h"
|
|
|
|
#endif
|
2002-11-05 06:56:41 +08:00
|
|
|
|
|
|
|
#include "libgimp/libgimp-intl.h"
|
|
|
|
|
2010-07-06 00:01:28 +08:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
2002-11-05 06:56:41 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
COLOR_PICKED,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2010-12-29 23:20:00 +08:00
|
|
|
|
2017-12-09 06:32:45 +08:00
|
|
|
static void gimp_pick_button_dispose (GObject *object);
|
2002-11-05 06:56:41 +08:00
|
|
|
|
2017-12-09 06:32:45 +08:00
|
|
|
static void gimp_pick_button_clicked (GtkButton *button);
|
2015-10-07 05:44:36 +08:00
|
|
|
|
|
|
|
|
app, libgimp*, modules: don't use g_type_class_add_private() ...
... and G_TYPE_INSTANCE_GET_PRIVATE()
g_type_class_add_private() and G_TYPE_INSTANCE_GET_PRIVATE() were
deprecated in GLib 2.58. Instead, use
G_DEFINE_[ABSTRACT_]TYPE_WITH_PRIVATE(), and
G_ADD_PRIVATE[_DYNAMIC](), and the implictly-defined
foo_get_instance_private() functions, all of which are available in
the GLib versions we depend on.
This commit only covers types registered using one of the
G_DEFINE_FOO() macros (i.e., most types), but not types with a
custom registration function, of which we still have a few -- GLib
currently only provides a (non-deprecated) public API for adding a
private struct using the G_DEFINE_FOO() macros.
Note that this commit was 99% auto-generated (because I'm not
*that* crazy :), so if there are any style mismatches... we'll have
to live with them for now.
2018-09-19 00:09:39 +08:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GimpPickButton, gimp_pick_button, GTK_TYPE_BUTTON)
|
2002-11-05 06:56:41 +08:00
|
|
|
|
2005-12-21 04:35:23 +08:00
|
|
|
#define parent_class gimp_pick_button_parent_class
|
2002-11-05 06:56:41 +08:00
|
|
|
|
2005-12-21 04:35:23 +08:00
|
|
|
static guint pick_button_signals[LAST_SIGNAL] = { 0 };
|
2002-11-05 06:56:41 +08:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_pick_button_class_init (GimpPickButtonClass* klass)
|
|
|
|
{
|
2010-10-15 08:34:29 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2004-07-13 22:55:16 +08:00
|
|
|
GtkButtonClass *button_class = GTK_BUTTON_CLASS (klass);
|
2002-11-05 06:56:41 +08:00
|
|
|
|
2010-07-06 00:01:28 +08:00
|
|
|
/**
|
|
|
|
* GimpPickButton::color-picked:
|
|
|
|
* @gimppickbutton: the object which received the signal.
|
2020-05-05 03:33:37 +08:00
|
|
|
* @color: pointer to a #GimpRGB structure that holds the picked color
|
2010-07-06 00:01:28 +08:00
|
|
|
*
|
|
|
|
* This signal is emitted when the user has picked a color.
|
|
|
|
**/
|
2003-10-30 04:57:21 +08:00
|
|
|
pick_button_signals[COLOR_PICKED] =
|
2005-05-27 21:05:26 +08:00
|
|
|
g_signal_new ("color-picked",
|
2006-04-12 18:53:28 +08:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpPickButtonClass, color_picked),
|
2020-01-12 18:06:05 +08:00
|
|
|
NULL, NULL, NULL,
|
2006-04-12 18:53:28 +08:00
|
|
|
G_TYPE_NONE, 1,
|
2020-05-05 03:33:37 +08:00
|
|
|
GIMP_TYPE_RGB);
|
2002-11-05 06:56:41 +08:00
|
|
|
|
2010-10-15 08:34:29 +08:00
|
|
|
object_class->dispose = gimp_pick_button_dispose;
|
2002-11-05 06:56:41 +08:00
|
|
|
|
2015-10-07 05:44:36 +08:00
|
|
|
button_class->clicked = gimp_pick_button_clicked;
|
2002-11-05 06:56:41 +08:00
|
|
|
|
|
|
|
klass->color_picked = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_pick_button_init (GimpPickButton *button)
|
|
|
|
{
|
|
|
|
GtkWidget *image;
|
|
|
|
|
app, libgimp*, modules: don't use g_type_class_add_private() ...
... and G_TYPE_INSTANCE_GET_PRIVATE()
g_type_class_add_private() and G_TYPE_INSTANCE_GET_PRIVATE() were
deprecated in GLib 2.58. Instead, use
G_DEFINE_[ABSTRACT_]TYPE_WITH_PRIVATE(), and
G_ADD_PRIVATE[_DYNAMIC](), and the implictly-defined
foo_get_instance_private() functions, all of which are available in
the GLib versions we depend on.
This commit only covers types registered using one of the
G_DEFINE_FOO() macros (i.e., most types), but not types with a
custom registration function, of which we still have a few -- GLib
currently only provides a (non-deprecated) public API for adding a
private struct using the G_DEFINE_FOO() macros.
Note that this commit was 99% auto-generated (because I'm not
*that* crazy :), so if there are any style mismatches... we'll have
to live with them for now.
2018-09-19 00:09:39 +08:00
|
|
|
button->priv = gimp_pick_button_get_instance_private (button);
|
2010-12-29 23:20:00 +08:00
|
|
|
|
2017-03-05 23:01:59 +08:00
|
|
|
image = gtk_image_new_from_icon_name (GIMP_ICON_COLOR_PICK_FROM_SCREEN,
|
2014-05-08 03:27:57 +08:00
|
|
|
GTK_ICON_SIZE_BUTTON);
|
2002-11-05 06:56:41 +08:00
|
|
|
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
|
2010-10-15 08:34:29 +08:00
|
|
|
gimp_pick_button_dispose (GObject *object)
|
2002-11-05 06:56:41 +08:00
|
|
|
{
|
2004-02-08 23:47:20 +08:00
|
|
|
GimpPickButton *button = GIMP_PICK_BUTTON (object);
|
2002-11-05 06:56:41 +08:00
|
|
|
|
2010-12-29 23:20:00 +08:00
|
|
|
if (button->priv->cursor)
|
2002-11-05 06:56:41 +08:00
|
|
|
{
|
2010-12-29 23:20:00 +08:00
|
|
|
g_object_unref (button->priv->cursor);
|
|
|
|
button->priv->cursor = NULL;
|
2002-11-05 06:56:41 +08:00
|
|
|
}
|
|
|
|
|
2010-12-29 23:20:00 +08:00
|
|
|
if (button->priv->grab_widget)
|
2002-11-05 06:56:41 +08:00
|
|
|
{
|
2010-12-29 23:20:00 +08:00
|
|
|
gtk_widget_destroy (button->priv->grab_widget);
|
|
|
|
button->priv->grab_widget = NULL;
|
2002-11-05 06:56:41 +08:00
|
|
|
}
|
|
|
|
|
2010-10-15 08:34:29 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
2002-11-05 06:56:41 +08:00
|
|
|
}
|
|
|
|
|
2015-10-07 05:44:36 +08:00
|
|
|
static void
|
|
|
|
gimp_pick_button_clicked (GtkButton *button)
|
|
|
|
{
|
|
|
|
#ifdef GDK_WINDOWING_QUARTZ
|
|
|
|
_gimp_pick_button_quartz_pick (GIMP_PICK_BUTTON (button));
|
|
|
|
#else
|
2017-12-09 06:32:45 +08:00
|
|
|
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));
|
2015-10-07 05:44:36 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2002-11-05 06:56:41 +08:00
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
2003-01-05 23:41:23 +08:00
|
|
|
/**
|
|
|
|
* gimp_pick_button_new:
|
|
|
|
*
|
|
|
|
* Creates a new #GimpPickButton widget.
|
2003-10-30 04:57:21 +08:00
|
|
|
*
|
2003-01-05 23:41:23 +08:00
|
|
|
* Returns: A new #GimpPickButton widget.
|
|
|
|
**/
|
2002-11-05 06:56:41 +08:00
|
|
|
GtkWidget *
|
|
|
|
gimp_pick_button_new (void)
|
|
|
|
{
|
2004-02-08 23:47:20 +08:00
|
|
|
return g_object_new (GIMP_TYPE_PICK_BUTTON, NULL);
|
2002-11-05 06:56:41 +08:00
|
|
|
}
|