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
|
|
|
*
|
|
|
|
* 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.
|
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
|
|
|
|
* 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"
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "gimpwidgetstypes.h"
|
|
|
|
|
|
|
|
#include "gimpbutton.h"
|
|
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
EXTENDED_CLICKED,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
2006-05-15 17:46:31 +08:00
|
|
|
G_DEFINE_TYPE (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
|
|
|
|
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),
|
|
|
|
NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__FLAGS,
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
button->press_state = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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:
|
|
|
|
* @button: a #GimpButton.
|
|
|
|
* @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,
|
|
|
|
GdkModifierType state)
|
2001-10-24 19:23:50 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_BUTTON (button));
|
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_emit (button, button_signals[EXTENDED_CLICKED], 0, 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
|
|
|
{
|
2005-02-24 07:03:00 +08:00
|
|
|
GimpButton *button = GIMP_BUTTON (widget);
|
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
|
|
|
{
|
|
|
|
button->press_state = bevent->state;
|
|
|
|
}
|
2001-08-07 08:06:06 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
button->press_state = 0;
|
|
|
|
}
|
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
|
|
|
{
|
2008-09-04 03:03:36 +08:00
|
|
|
if (GIMP_BUTTON (button)->press_state &
|
|
|
|
(GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK))
|
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
|
|
|
|
2008-09-04 03:03:36 +08:00
|
|
|
gimp_button_extended_clicked (GIMP_BUTTON (button),
|
|
|
|
GIMP_BUTTON (button)->press_state);
|
|
|
|
}
|
2001-05-07 04:31:46 +08:00
|
|
|
}
|