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
|
|
|
|
* Copyright (C) 2000 Michael Natterer <mitch@gimp.org>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-12-21 04:35:23 +08:00
|
|
|
static gboolean gimp_button_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *event);
|
|
|
|
static gboolean gimp_button_button_release (GtkWidget *widget,
|
|
|
|
GdkEventButton *event);
|
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);
|
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
|
|
|
|
|
|
|
widget_class->button_press_event = gimp_button_button_press;
|
|
|
|
widget_class->button_release_event = gimp_button_button_release;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
if (GTK_WIDGET_CLASS (parent_class)->button_press_event)
|
2001-05-25 01:09:57 +08:00
|
|
|
return GTK_WIDGET_CLASS (parent_class)->button_press_event (widget, bevent);
|
2001-05-07 04:31:46 +08:00
|
|
|
|
2005-02-24 07:03:00 +08:00
|
|
|
return TRUE;
|
2001-05-07 04:31:46 +08:00
|
|
|
}
|
|
|
|
|
2001-08-07 08:06:06 +08:00
|
|
|
static gboolean
|
2001-05-07 04:31:46 +08:00
|
|
|
gimp_button_button_release (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
|
|
|
GtkButton *button = GTK_BUTTON (widget);
|
2001-05-25 01:09:57 +08:00
|
|
|
gboolean extended_clicked = FALSE;
|
2001-05-07 04:31:46 +08:00
|
|
|
|
|
|
|
if (bevent->button == 1)
|
|
|
|
{
|
2001-05-25 01:09:57 +08:00
|
|
|
if (button->in_button &&
|
2005-02-24 07:03:00 +08:00
|
|
|
(GIMP_BUTTON (button)->press_state &
|
|
|
|
(GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK)))
|
|
|
|
{
|
|
|
|
gimp_button_extended_clicked (GIMP_BUTTON (button),
|
2001-10-24 19:23:50 +08:00
|
|
|
GIMP_BUTTON (button)->press_state);
|
2001-05-07 04:31:46 +08:00
|
|
|
|
2005-02-24 07:03:00 +08:00
|
|
|
extended_clicked = TRUE;
|
2001-05-25 01:09:57 +08:00
|
|
|
|
2005-02-24 07:03:00 +08:00
|
|
|
/* HACK: don't let GtkButton emit "clicked" by telling it that
|
|
|
|
* the mouse pointer is outside the widget
|
|
|
|
*/
|
|
|
|
button->in_button = FALSE;
|
|
|
|
}
|
2001-05-07 04:31:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (GTK_WIDGET_CLASS (parent_class)->button_release_event)
|
2001-08-07 08:06:06 +08:00
|
|
|
GTK_WIDGET_CLASS (parent_class)->button_release_event (widget, bevent);
|
2001-05-07 04:31:46 +08:00
|
|
|
|
2001-05-25 01:09:57 +08:00
|
|
|
if (extended_clicked)
|
2001-05-07 04:31:46 +08:00
|
|
|
{
|
2001-05-25 01:09:57 +08:00
|
|
|
/* revert the above HACK and let the button draw itself in the
|
|
|
|
* correct state, because upchaining with "in_button" == FALSE
|
|
|
|
* messed it up
|
|
|
|
*/
|
2001-05-07 06:29:48 +08:00
|
|
|
button->in_button = TRUE;
|
|
|
|
|
2001-05-07 04:31:46 +08:00
|
|
|
gtk_widget_set_state (widget, GTK_STATE_PRELIGHT);
|
2001-12-29 21:26:29 +08:00
|
|
|
gtk_widget_queue_draw (widget);
|
2001-12-31 09:59:46 +08:00
|
|
|
gdk_window_process_updates (widget->window, TRUE);
|
2001-05-07 04:31:46 +08:00
|
|
|
}
|
|
|
|
|
2001-08-07 08:06:06 +08:00
|
|
|
return TRUE;
|
2001-05-07 04:31:46 +08:00
|
|
|
}
|