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
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void gimp_button_class_init (GimpButtonClass *klass);
|
|
|
|
static void gimp_button_init (GimpButton *button);
|
|
|
|
|
|
|
|
static gboolean gimp_button_button_press (GtkWidget *widget,
|
2005-02-24 07:03:00 +08:00
|
|
|
GdkEventButton *event);
|
2001-05-07 04:31:46 +08:00
|
|
|
static gboolean gimp_button_button_release (GtkWidget *widget,
|
2005-02-24 07:03:00 +08:00
|
|
|
GdkEventButton *event);
|
2001-05-07 04:31:46 +08:00
|
|
|
|
|
|
|
|
|
|
|
static guint button_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
|
|
|
static GtkButtonClass *parent_class = NULL;
|
|
|
|
|
|
|
|
|
2001-08-07 08:06:06 +08:00
|
|
|
GType
|
2001-05-07 04:31:46 +08:00
|
|
|
gimp_button_get_type (void)
|
|
|
|
{
|
2001-08-07 08:06:06 +08:00
|
|
|
static GType button_type = 0;
|
2001-05-07 04:31:46 +08:00
|
|
|
|
2001-08-07 08:06:06 +08:00
|
|
|
if (! button_type)
|
2001-05-07 04:31:46 +08:00
|
|
|
{
|
2001-09-21 18:47:19 +08:00
|
|
|
static const GTypeInfo button_info =
|
2001-05-07 04:31:46 +08:00
|
|
|
{
|
2001-09-21 18:47:19 +08:00
|
|
|
sizeof (GimpButtonClass),
|
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) gimp_button_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GimpButton),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_button_init,
|
2001-05-07 04:31:46 +08:00
|
|
|
};
|
|
|
|
|
2001-09-21 18:47:19 +08:00
|
|
|
button_type = g_type_register_static (GTK_TYPE_BUTTON,
|
2005-02-24 07:03:00 +08:00
|
|
|
"GimpButton",
|
|
|
|
&button_info, 0);
|
2001-05-07 04:31:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return button_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
2001-07-24 Michael Natterer <mitch@gimp.org>
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
* configure.in: require glib/gtk+ >= 1.3.7, commented out the
gtkxmhtml stuff.
From now on, you will need glib, pango, atk and gtk+ HEAD from CVS
to hack or use GIMP HEAD.
Beware, it crashes randomly :)
* app/core/Makefile.am
* app/core/gimpmarshal.list: new file plus rules to generate
gimpmarshal.[ch] from it.
* app/core/*
* app/tools/*
* app/widgets/*
* libgimpwidgets/*: started to use the glib object system. All
core/ objects are still gtk objects however. All signals are
created using g_signal_new(). There are many gtk+ artefacts left.
Finally, we will _not_ use the gtk_signal_foo() wrappers and
friends any more.
* app/colormaps.c
* app/devices.[ch]
* app/disp_callbacks.c
* app/errorconsole.c
* app/file-save.[ch]
* app/interface.c
* app/module_db.c
* app/nav_window.c
* app/ops_buttons.c
* app/scroll.c
* app/user_install.c
* app/gui/about-dialog.c
* app/gui/brush-editor.c
* app/gui/brushes-commands.c
* app/gui/color-notebook.c
* app/gui/colormap-dialog.c
* app/gui/dialogs-commands.c
* app/gui/dialogs-constructors.c
* app/gui/file-commands.c
* app/gui/file-dialog-utils.c
* app/gui/file-new-dialog.c
* app/gui/file-open-dialog.[ch]
* app/gui/file-save-dialog.c
* app/gui/gradient-editor.c
* app/gui/gradients-commands.c
* app/gui/image-commands.c
* app/gui/info-dialog.[ch]
* app/gui/layer-select.c
* app/gui/layers-commands.c
* app/gui/menus.c
* app/gui/offset-dialog.c
* app/gui/palette-editor.c
* app/gui/palettes-commands.c
* app/gui/patterns-commands.c
* app/gui/preferences-dialog.c
* app/gui/resize-dialog.[ch]
* app/gui/splash.c
* app/gui/tips-dialog.c
* app/gui/tool-options-dialog.c
* app/gui/toolbox.c
* app/gui/tools-commands.c
* libgimp/gimpbrushmenu.c
* libgimp/gimpmenu.c
* libgimp/gimppatternmenu.c
* libgimp/gimpui.c
* libgimpbase/gimpenv.c: tons and tons of changes like "const
gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete
and currently disables), lots of s/gtk_signal/g_signal/,
removal/replacement of deprecated stuff,
s/GtkSignalFunc/GCallback/ and lots of small changes and fixes
while I was on it, zillions of warnings left...
* modules/Makefile.am: disabled the water color selector
temporarily (XInput issues).
* plug-ins/Makefile.am
* plug-ins/common/.cvsignore
* plug-ins/common/Makefile.am
* plug-ins/common/plugin-defs.pl: simply excluded all plug-ins
which did not build (including Script-Fu). They are trivial to
fix.
2001-07-25 05:27:11 +08:00
|
|
|
parent_class = g_type_class_peek_parent (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
|
|
|
}
|