2003-12-05 23:55:15 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
2001-05-07 04:31:46 +08:00
|
|
|
*
|
|
|
|
* gimpbutton.c
|
2008-09-04 03:03:36 +08:00
|
|
|
* Copyright (C) 2000-2008 Michael Natterer <mitch@gimp.org>
|
2001-05-07 04:31:46 +08:00
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This library is free software: you can redistribute it and/or
|
2001-05-07 04:31:46 +08:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2009-01-18 06:28:01 +08:00
|
|
|
* version 3 of the License, or (at your option) any later version.
|
2003-12-05 23:55:15 +08:00
|
|
|
*
|
2001-05-07 04:31:46 +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
|
|
|
|
* Lesser 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/>.
|
2001-05-07 04:31:46 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "gimpwidgetstypes.h"
|
|
|
|
|
|
|
|
#include "gimpbutton.h"
|
|
|
|
|
|
|
|
|
2010-07-06 00:01:28 +08:00
|
|
|
/**
|
|
|
|
* SECTION: gimpbutton
|
|
|
|
* @title: GimpButton
|
|
|
|
* @short_description: A #GtkButton with a little extra functionality.
|
|
|
|
*
|
|
|
|
* #GimpButton adds an extra signal to the #GtkButton widget that
|
2012-11-11 22:50:25 +08:00
|
|
|
* allows the callback to distinguish a normal click from a click that
|
|
|
|
* was performed with modifier keys pressed.
|
2010-07-06 00:01:28 +08:00
|
|
|
**/
|
|
|
|
|
|
|
|
|
2001-05-07 04:31:46 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
EXTENDED_CLICKED,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2024-07-31 03:04:53 +08:00
|
|
|
typedef struct _GimpButtonPrivate
|
2011-01-01 00:24:54 +08:00
|
|
|
{
|
|
|
|
GdkModifierType press_state;
|
2024-07-31 03:04:53 +08:00
|
|
|
} GimpButtonPrivate;
|
2011-01-01 00:24:54 +08:00
|
|
|
|
|
|
|
|
2008-09-04 03:03:36 +08:00
|
|
|
static gboolean gimp_button_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *event);
|
|
|
|
static void gimp_button_clicked (GtkButton *button);
|
2001-05-07 04:31:46 +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 (GimpButton, gimp_button, GTK_TYPE_BUTTON)
|
2001-05-07 04:31:46 +08:00
|
|
|
|
2005-12-21 04:35:23 +08:00
|
|
|
#define parent_class gimp_button_parent_class
|
2001-05-07 04:31:46 +08:00
|
|
|
|
2005-12-21 04:35:23 +08:00
|
|
|
static guint button_signals[LAST_SIGNAL] = { 0 };
|
2001-05-07 04:31:46 +08:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_button_class_init (GimpButtonClass *klass)
|
|
|
|
{
|
2005-02-24 07:03:00 +08:00
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
2008-09-04 03:03:36 +08:00
|
|
|
GtkButtonClass *button_class = GTK_BUTTON_CLASS (klass);
|
2001-05-07 04:31:46 +08:00
|
|
|
|
2010-07-06 00:01:28 +08:00
|
|
|
/**
|
|
|
|
* GimpButton::extended-clicked:
|
|
|
|
* @gimpbutton: the object that received the signal.
|
|
|
|
* @arg1: the state of modifier keys when the button was clicked
|
|
|
|
*
|
|
|
|
* This signal is emitted when the button is clicked with a modifier
|
|
|
|
* key pressed.
|
|
|
|
**/
|
2003-12-05 23:55:15 +08:00
|
|
|
button_signals[EXTENDED_CLICKED] =
|
2005-05-27 21:05:26 +08:00
|
|
|
g_signal_new ("extended-clicked",
|
2005-02-24 07:03:00 +08:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpButtonClass, extended_clicked),
|
2020-01-12 18:06:05 +08:00
|
|
|
NULL, NULL, NULL,
|
2005-02-24 07:03:00 +08:00
|
|
|
G_TYPE_NONE, 1,
|
|
|
|
GDK_TYPE_MODIFIER_TYPE);
|
2001-05-07 04:31:46 +08:00
|
|
|
|
2008-09-04 03:03:36 +08:00
|
|
|
widget_class->button_press_event = gimp_button_button_press;
|
|
|
|
|
|
|
|
button_class->clicked = gimp_button_clicked;
|
2001-05-07 04:31:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_button_init (GimpButton *button)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_button_new:
|
|
|
|
*
|
|
|
|
* Creates a new #GimpButton widget.
|
|
|
|
*
|
|
|
|
* Returns: A pointer to the new #GimpButton widget.
|
|
|
|
**/
|
|
|
|
GtkWidget *
|
|
|
|
gimp_button_new (void)
|
|
|
|
{
|
2005-02-24 07:03:00 +08:00
|
|
|
return g_object_new (GIMP_TYPE_BUTTON, NULL);
|
2001-05-07 04:31:46 +08:00
|
|
|
}
|
|
|
|
|
2001-10-24 19:23:50 +08:00
|
|
|
/**
|
|
|
|
* gimp_button_extended_clicked:
|
2019-08-08 04:05:12 +08:00
|
|
|
* @button: a #GimpButton.
|
|
|
|
* @modifier_state: a state as found in #GdkEventButton->state,
|
|
|
|
* e.g. #GDK_SHIFT_MASK.
|
2003-12-05 23:55:15 +08:00
|
|
|
*
|
2001-10-24 19:23:50 +08:00
|
|
|
* Emits the button's "extended_clicked" signal.
|
|
|
|
**/
|
|
|
|
void
|
2003-03-20 21:22:22 +08:00
|
|
|
gimp_button_extended_clicked (GimpButton *button,
|
2019-08-08 04:05:12 +08:00
|
|
|
GdkModifierType modifier_state)
|
2001-10-24 19:23:50 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_BUTTON (button));
|
|
|
|
|
2019-08-08 04:05:12 +08:00
|
|
|
g_signal_emit (button, button_signals[EXTENDED_CLICKED], 0, modifier_state);
|
2001-10-24 19:23:50 +08:00
|
|
|
}
|
|
|
|
|
2001-05-07 04:31:46 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_button_button_press (GtkWidget *widget,
|
2005-02-24 07:03:00 +08:00
|
|
|
GdkEventButton *bevent)
|
2001-05-07 04:31:46 +08:00
|
|
|
{
|
2024-07-31 03:04:53 +08:00
|
|
|
GimpButton *button = GIMP_BUTTON (widget);
|
|
|
|
GimpButtonPrivate *private = gimp_button_get_instance_private (button);
|
2001-08-07 08:06:06 +08:00
|
|
|
|
2005-02-24 07:03:00 +08:00
|
|
|
if (bevent->button == 1)
|
2001-05-07 04:31:46 +08:00
|
|
|
{
|
2011-01-01 00:24:54 +08:00
|
|
|
private->press_state = bevent->state;
|
2001-05-07 04:31:46 +08:00
|
|
|
}
|
2001-08-07 08:06:06 +08:00
|
|
|
else
|
|
|
|
{
|
2011-01-01 00:24:54 +08:00
|
|
|
private->press_state = 0;
|
2001-08-07 08:06:06 +08:00
|
|
|
}
|
2001-05-07 04:31:46 +08:00
|
|
|
|
2008-09-04 03:03:36 +08:00
|
|
|
return GTK_WIDGET_CLASS (parent_class)->button_press_event (widget, bevent);
|
2001-05-07 04:31:46 +08:00
|
|
|
}
|
|
|
|
|
2008-09-04 03:03:36 +08:00
|
|
|
static void
|
|
|
|
gimp_button_clicked (GtkButton *button)
|
2001-05-07 04:31:46 +08:00
|
|
|
{
|
2024-07-31 03:04:53 +08:00
|
|
|
GimpButton *gimp_button = GIMP_BUTTON (button);
|
|
|
|
GimpButtonPrivate *private = gimp_button_get_instance_private (gimp_button);
|
2011-01-01 00:24:54 +08:00
|
|
|
|
|
|
|
if (private->press_state &
|
2011-10-10 05:59:40 +08:00
|
|
|
(GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK |
|
|
|
|
gtk_widget_get_modifier_mask (GTK_WIDGET (button),
|
|
|
|
GDK_MODIFIER_INTENT_PRIMARY_ACCELERATOR) |
|
|
|
|
gtk_widget_get_modifier_mask (GTK_WIDGET (button),
|
|
|
|
GDK_MODIFIER_INTENT_EXTEND_SELECTION) |
|
|
|
|
gtk_widget_get_modifier_mask (GTK_WIDGET (button),
|
|
|
|
GDK_MODIFIER_INTENT_MODIFY_SELECTION)))
|
2001-05-07 04:31:46 +08:00
|
|
|
{
|
2008-09-04 03:03:36 +08:00
|
|
|
g_signal_stop_emission_by_name (button, "clicked");
|
2001-05-07 04:31:46 +08:00
|
|
|
|
2011-01-01 00:24:54 +08:00
|
|
|
gimp_button_extended_clicked (GIMP_BUTTON (button), private->press_state);
|
2008-09-04 03:03:36 +08:00
|
|
|
}
|
2009-01-27 04:23:01 +08:00
|
|
|
else if (GTK_BUTTON_CLASS (parent_class)->clicked)
|
|
|
|
{
|
|
|
|
GTK_BUTTON_CLASS (parent_class)->clicked (button);
|
|
|
|
}
|
2001-05-07 04:31:46 +08:00
|
|
|
}
|