2006-12-11 00:38:48 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2004-06-16 06:59:26 +08:00
|
|
|
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
|
|
|
*
|
|
|
|
* gimpcontrollerwheel.c
|
|
|
|
* Copyright (C) 2004 Michael Natterer <mitch@gimp.org>
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2006-12-10 05:51:48 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2006-12-10 05:51:48 +08:00
|
|
|
* (at your option) any later version.
|
2004-06-16 06:59:26 +08:00
|
|
|
*
|
2006-12-10 05:51:48 +08:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2004-06-16 06:59:26 +08:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2006-12-10 05:51:48 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2004-06-16 06:59:26 +08:00
|
|
|
*
|
2006-12-10 05:51:48 +08:00
|
|
|
* You should have received a copy of the GNU General Public License
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2004-06-16 06:59:26 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
|
|
|
#include "widgets-types.h"
|
|
|
|
|
|
|
|
#include "gimpcontrollerwheel.h"
|
2004-11-24 10:17:12 +08:00
|
|
|
#include "gimphelp-ids.h"
|
2005-09-18 04:44:06 +08:00
|
|
|
#include "gimpwidgets-utils.h"
|
2004-06-16 06:59:26 +08:00
|
|
|
|
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
|
|
|
|
2007-09-26 17:55:09 +08:00
|
|
|
#define MODIFIER_MASK (GDK_MOD1_MASK | GDK_CONTROL_MASK | GDK_SHIFT_MASK)
|
|
|
|
|
|
|
|
|
2004-06-16 06:59:26 +08:00
|
|
|
typedef struct _WheelEvent WheelEvent;
|
|
|
|
|
|
|
|
struct _WheelEvent
|
|
|
|
{
|
2006-04-06 20:43:58 +08:00
|
|
|
const GdkScrollDirection direction;
|
|
|
|
const GdkModifierType modifiers;
|
|
|
|
const gchar *name;
|
2008-09-04 04:17:57 +08:00
|
|
|
const gchar *blurb;
|
2004-06-16 06:59:26 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2004-06-17 22:07:05 +08:00
|
|
|
static GObject * gimp_controller_wheel_constructor (GType type,
|
|
|
|
guint n_params,
|
|
|
|
GObjectConstructParam *params);
|
2004-06-16 06:59:26 +08:00
|
|
|
|
2004-06-16 19:53:37 +08:00
|
|
|
static gint gimp_controller_wheel_get_n_events (GimpController *controller);
|
|
|
|
static const gchar * gimp_controller_wheel_get_event_name (GimpController *controller,
|
|
|
|
gint event_id);
|
|
|
|
static const gchar * gimp_controller_wheel_get_event_blurb (GimpController *controller,
|
|
|
|
gint event_id);
|
2004-06-16 06:59:26 +08:00
|
|
|
|
|
|
|
|
2005-12-20 06:37:49 +08:00
|
|
|
G_DEFINE_TYPE (GimpControllerWheel, gimp_controller_wheel,
|
2006-05-15 17:46:31 +08:00
|
|
|
GIMP_TYPE_CONTROLLER)
|
2005-12-20 06:37:49 +08:00
|
|
|
|
|
|
|
#define parent_class gimp_controller_wheel_parent_class
|
|
|
|
|
2004-06-16 06:59:26 +08:00
|
|
|
|
2005-09-18 04:44:06 +08:00
|
|
|
static WheelEvent wheel_events[] =
|
2004-06-16 06:59:26 +08:00
|
|
|
{
|
2007-09-26 17:55:09 +08:00
|
|
|
{ GDK_SCROLL_UP, 0,
|
|
|
|
"scroll-up",
|
2005-09-18 04:44:06 +08:00
|
|
|
N_("Scroll Up") },
|
2007-09-26 17:55:09 +08:00
|
|
|
{ GDK_SCROLL_UP, GDK_SHIFT_MASK,
|
|
|
|
"scroll-up-shift",
|
2005-09-18 04:44:06 +08:00
|
|
|
N_("Scroll Up") },
|
2007-09-26 17:55:09 +08:00
|
|
|
{ GDK_SCROLL_UP, GDK_CONTROL_MASK,
|
|
|
|
"scroll-up-control",
|
2005-09-18 04:44:06 +08:00
|
|
|
N_("Scroll Up") },
|
2004-06-16 08:52:28 +08:00
|
|
|
{ GDK_SCROLL_UP, GDK_MOD1_MASK,
|
2004-06-16 19:53:37 +08:00
|
|
|
"scroll-up-alt",
|
2005-09-18 04:44:06 +08:00
|
|
|
N_("Scroll Up") },
|
2007-09-26 17:55:09 +08:00
|
|
|
{ GDK_SCROLL_UP, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
|
|
|
|
"scroll-up-shift-control",
|
2005-09-18 04:44:06 +08:00
|
|
|
N_("Scroll Up") },
|
2007-09-26 17:55:09 +08:00
|
|
|
{ GDK_SCROLL_UP, GDK_MOD1_MASK | GDK_SHIFT_MASK,
|
|
|
|
"scroll-up-shift-alt",
|
2005-09-18 04:44:06 +08:00
|
|
|
N_("Scroll Up") },
|
2007-09-26 17:55:09 +08:00
|
|
|
{ GDK_SCROLL_UP, GDK_MOD1_MASK | GDK_CONTROL_MASK,
|
|
|
|
"scroll-up-control-alt",
|
|
|
|
N_("Scroll Up") },
|
|
|
|
{ GDK_SCROLL_UP, GDK_MOD1_MASK | GDK_CONTROL_MASK | GDK_SHIFT_MASK,
|
|
|
|
"scroll-up-shift-control-alt",
|
2004-06-16 08:52:28 +08:00
|
|
|
N_("Scroll Up") },
|
|
|
|
|
2007-09-26 17:55:09 +08:00
|
|
|
{ GDK_SCROLL_DOWN, 0,
|
|
|
|
"scroll-down",
|
2005-09-18 04:44:06 +08:00
|
|
|
N_("Scroll Down") },
|
2007-09-26 17:55:09 +08:00
|
|
|
{ GDK_SCROLL_DOWN, GDK_SHIFT_MASK,
|
|
|
|
"scroll-down-shift",
|
2005-09-18 04:44:06 +08:00
|
|
|
N_("Scroll Down") },
|
2007-09-26 17:55:09 +08:00
|
|
|
{ GDK_SCROLL_DOWN, GDK_CONTROL_MASK,
|
|
|
|
"scroll-down-control",
|
2005-09-18 04:44:06 +08:00
|
|
|
N_("Scroll Down") },
|
2004-06-16 08:52:28 +08:00
|
|
|
{ GDK_SCROLL_DOWN, GDK_MOD1_MASK,
|
2004-06-16 19:53:37 +08:00
|
|
|
"scroll-down-alt",
|
2005-09-18 04:44:06 +08:00
|
|
|
N_("Scroll Down") },
|
2007-09-26 17:55:09 +08:00
|
|
|
{ GDK_SCROLL_DOWN, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
|
|
|
|
"scroll-down-shift-control",
|
2005-09-18 04:44:06 +08:00
|
|
|
N_("Scroll Down") },
|
2007-09-26 17:55:09 +08:00
|
|
|
{ GDK_SCROLL_DOWN, GDK_MOD1_MASK | GDK_SHIFT_MASK,
|
|
|
|
"scroll-down-shift-alt",
|
2005-09-18 04:44:06 +08:00
|
|
|
N_("Scroll Down") },
|
2007-09-26 17:55:09 +08:00
|
|
|
{ GDK_SCROLL_DOWN, GDK_MOD1_MASK | GDK_CONTROL_MASK,
|
|
|
|
"scroll-down-control-alt",
|
|
|
|
N_("Scroll Down") },
|
|
|
|
{ GDK_SCROLL_DOWN, GDK_MOD1_MASK | GDK_CONTROL_MASK | GDK_SHIFT_MASK,
|
|
|
|
"scroll-down-shift-control-alt",
|
2004-06-16 08:52:28 +08:00
|
|
|
N_("Scroll Down") },
|
|
|
|
|
2007-09-26 17:55:09 +08:00
|
|
|
{ GDK_SCROLL_LEFT, 0,
|
|
|
|
"scroll-left",
|
2005-09-18 04:44:06 +08:00
|
|
|
N_("Scroll Left") },
|
2007-09-26 17:55:09 +08:00
|
|
|
{ GDK_SCROLL_LEFT, GDK_SHIFT_MASK,
|
|
|
|
"scroll-left-shift",
|
2005-09-18 04:44:06 +08:00
|
|
|
N_("Scroll Left") },
|
2007-09-26 17:55:09 +08:00
|
|
|
{ GDK_SCROLL_LEFT, GDK_CONTROL_MASK,
|
|
|
|
"scroll-left-control",
|
2005-09-18 04:44:06 +08:00
|
|
|
N_("Scroll Left") },
|
2004-06-16 08:52:28 +08:00
|
|
|
{ GDK_SCROLL_LEFT, GDK_MOD1_MASK,
|
2004-06-16 19:53:37 +08:00
|
|
|
"scroll-left-alt",
|
2005-09-18 04:44:06 +08:00
|
|
|
N_("Scroll Left") },
|
2007-09-26 17:55:09 +08:00
|
|
|
{ GDK_SCROLL_LEFT, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
|
|
|
|
"scroll-left-shift-control",
|
2005-09-18 04:44:06 +08:00
|
|
|
N_("Scroll Left") },
|
2007-09-26 17:55:09 +08:00
|
|
|
{ GDK_SCROLL_LEFT, GDK_MOD1_MASK | GDK_SHIFT_MASK,
|
|
|
|
"scroll-left-shift-alt",
|
2005-09-18 04:44:06 +08:00
|
|
|
N_("Scroll Left") },
|
2007-09-26 17:55:09 +08:00
|
|
|
{ GDK_SCROLL_LEFT, GDK_MOD1_MASK | GDK_CONTROL_MASK,
|
|
|
|
"scroll-left-control-alt",
|
|
|
|
N_("Scroll Left") },
|
|
|
|
{ GDK_SCROLL_LEFT, GDK_MOD1_MASK | GDK_CONTROL_MASK | GDK_SHIFT_MASK,
|
|
|
|
"scroll-left-shift-control-alt",
|
2004-06-16 08:52:28 +08:00
|
|
|
N_("Scroll Left") },
|
|
|
|
|
2007-09-26 17:55:09 +08:00
|
|
|
{ GDK_SCROLL_RIGHT, 0,
|
|
|
|
"scroll-right",
|
2005-09-18 04:44:06 +08:00
|
|
|
N_("Scroll Right") },
|
2007-09-26 17:55:09 +08:00
|
|
|
{ GDK_SCROLL_RIGHT, GDK_SHIFT_MASK,
|
|
|
|
"scroll-right-shift",
|
2005-09-18 04:44:06 +08:00
|
|
|
N_("Scroll Right") },
|
2007-09-26 17:55:09 +08:00
|
|
|
{ GDK_SCROLL_RIGHT, GDK_CONTROL_MASK,
|
|
|
|
"scroll-right-control",
|
2005-09-18 04:44:06 +08:00
|
|
|
N_("Scroll Right") },
|
2004-06-16 08:52:28 +08:00
|
|
|
{ GDK_SCROLL_RIGHT, GDK_MOD1_MASK,
|
2004-06-16 19:53:37 +08:00
|
|
|
"scroll-right-alt",
|
2005-09-18 04:44:06 +08:00
|
|
|
N_("Scroll Right") },
|
2007-09-26 17:55:09 +08:00
|
|
|
{ GDK_SCROLL_RIGHT, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
|
|
|
|
"scroll-right-shift-control",
|
2005-09-18 04:44:06 +08:00
|
|
|
N_("Scroll Right") },
|
2007-09-26 17:55:09 +08:00
|
|
|
{ GDK_SCROLL_RIGHT, GDK_MOD1_MASK | GDK_SHIFT_MASK,
|
|
|
|
"scroll-right-shift-alt",
|
2005-09-18 04:44:06 +08:00
|
|
|
N_("Scroll Right") },
|
2007-09-26 17:55:09 +08:00
|
|
|
{ GDK_SCROLL_RIGHT, GDK_MOD1_MASK | GDK_CONTROL_MASK,
|
|
|
|
"scroll-right-control-alt",
|
|
|
|
N_("Scroll Right") },
|
|
|
|
{ GDK_SCROLL_RIGHT, GDK_MOD1_MASK | GDK_CONTROL_MASK | GDK_SHIFT_MASK,
|
|
|
|
"scroll-right-shift-control-alt",
|
2004-06-16 08:52:28 +08:00
|
|
|
N_("Scroll Right") }
|
2004-06-16 06:59:26 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_controller_wheel_class_init (GimpControllerWheelClass *klass)
|
|
|
|
{
|
2004-06-17 22:07:05 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2004-06-16 06:59:26 +08:00
|
|
|
GimpControllerClass *controller_class = GIMP_CONTROLLER_CLASS (klass);
|
|
|
|
|
2004-06-17 22:07:05 +08:00
|
|
|
object_class->constructor = gimp_controller_wheel_constructor;
|
|
|
|
|
2004-06-16 19:53:37 +08:00
|
|
|
controller_class->name = _("Mouse Wheel");
|
2004-11-24 10:17:12 +08:00
|
|
|
controller_class->help_id = GIMP_HELP_CONTROLLER_WHEEL;
|
2006-10-02 01:31:42 +08:00
|
|
|
controller_class->stock_id = GIMP_STOCK_CONTROLLER_WHEEL;
|
2004-06-16 06:59:26 +08:00
|
|
|
|
2004-06-16 19:53:37 +08:00
|
|
|
controller_class->get_n_events = gimp_controller_wheel_get_n_events;
|
|
|
|
controller_class->get_event_name = gimp_controller_wheel_get_event_name;
|
|
|
|
controller_class->get_event_blurb = gimp_controller_wheel_get_event_blurb;
|
2004-06-16 06:59:26 +08:00
|
|
|
}
|
|
|
|
|
2004-06-17 22:07:05 +08:00
|
|
|
static void
|
|
|
|
gimp_controller_wheel_init (GimpControllerWheel *wheel)
|
|
|
|
{
|
2005-09-18 04:44:06 +08:00
|
|
|
static gboolean event_names_initialized = FALSE;
|
|
|
|
|
|
|
|
if (! event_names_initialized)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (wheel_events); i++)
|
|
|
|
{
|
|
|
|
WheelEvent *wevent = &wheel_events[i];
|
|
|
|
|
|
|
|
if (wevent->modifiers != 0)
|
|
|
|
{
|
|
|
|
wevent->blurb =
|
|
|
|
g_strdup_printf ("%s (%s)", gettext (wevent->blurb),
|
|
|
|
gimp_get_mod_string (wevent->modifiers));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
event_names_initialized = TRUE;
|
|
|
|
}
|
2004-06-17 22:07:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static GObject *
|
|
|
|
gimp_controller_wheel_constructor (GType type,
|
|
|
|
guint n_params,
|
|
|
|
GObjectConstructParam *params)
|
|
|
|
{
|
|
|
|
GObject *object;
|
|
|
|
|
|
|
|
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
|
|
|
|
|
2004-11-24 10:17:12 +08:00
|
|
|
g_object_set (object,
|
|
|
|
"name", _("Mouse Wheel Events"),
|
|
|
|
"state", _("Ready"),
|
|
|
|
NULL);
|
2004-06-17 22:07:05 +08:00
|
|
|
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
2004-06-16 06:59:26 +08:00
|
|
|
static gint
|
|
|
|
gimp_controller_wheel_get_n_events (GimpController *controller)
|
|
|
|
{
|
|
|
|
return G_N_ELEMENTS (wheel_events);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const gchar *
|
|
|
|
gimp_controller_wheel_get_event_name (GimpController *controller,
|
|
|
|
gint event_id)
|
|
|
|
{
|
|
|
|
if (event_id < 0 || event_id >= G_N_ELEMENTS (wheel_events))
|
|
|
|
return NULL;
|
|
|
|
|
2004-06-17 01:22:19 +08:00
|
|
|
return wheel_events[event_id].name;
|
2004-06-16 06:59:26 +08:00
|
|
|
}
|
|
|
|
|
2004-06-16 19:53:37 +08:00
|
|
|
static const gchar *
|
|
|
|
gimp_controller_wheel_get_event_blurb (GimpController *controller,
|
|
|
|
gint event_id)
|
|
|
|
{
|
|
|
|
if (event_id < 0 || event_id >= G_N_ELEMENTS (wheel_events))
|
|
|
|
return NULL;
|
|
|
|
|
2005-09-18 04:44:06 +08:00
|
|
|
return wheel_events[event_id].blurb;
|
2004-06-16 19:53:37 +08:00
|
|
|
}
|
|
|
|
|
2004-06-16 06:59:26 +08:00
|
|
|
gboolean
|
2004-06-24 23:29:19 +08:00
|
|
|
gimp_controller_wheel_scroll (GimpControllerWheel *wheel,
|
|
|
|
const GdkEventScroll *sevent)
|
2004-06-16 06:59:26 +08:00
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_CONTROLLER_WHEEL (wheel), FALSE);
|
|
|
|
g_return_val_if_fail (sevent != NULL, FALSE);
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (wheel_events); i++)
|
|
|
|
{
|
|
|
|
if (wheel_events[i].direction == sevent->direction)
|
|
|
|
{
|
2007-09-26 17:55:09 +08:00
|
|
|
if ((sevent->state & MODIFIER_MASK) == wheel_events[i].modifiers)
|
2004-06-16 06:59:26 +08:00
|
|
|
{
|
|
|
|
GimpControllerEvent controller_event;
|
|
|
|
GimpControllerEventTrigger *trigger;
|
|
|
|
|
|
|
|
trigger = (GimpControllerEventTrigger *) &controller_event;
|
|
|
|
|
|
|
|
trigger->type = GIMP_CONTROLLER_EVENT_TRIGGER;
|
|
|
|
trigger->source = GIMP_CONTROLLER (wheel);
|
|
|
|
trigger->event_id = i;
|
|
|
|
|
2007-09-26 17:55:09 +08:00
|
|
|
return gimp_controller_event (GIMP_CONTROLLER (wheel),
|
|
|
|
&controller_event);
|
2004-06-16 06:59:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|