Started to fix bug #106920 in a more genreral way:

2004-06-16  Michael Natterer  <mitch@gimp.org>

	Started to fix bug #106920 in a more genreral way:

	* libgimpwidgets/Makefile.am
	* libgimpwidgets/gimpwidgetstypes.h
	* libgimpwidgets/gimpwidgetsmarshal.list
	* libgimpwidgets/gimpcontroller.[ch]: new abstract base class
	which provides an API for pluggable input controller modules
	(mouse wheel, usb/midi stuff etc.).

	* app/widgets/Makefile.am
	* app/widgets/widgets-types.h
	* app/widgets/gimpcontrollerwheel.[ch]: subclass of the above
	which maps wheel mouse scroll events to controller events.

	* app/widgets/gimpcontrollers.[ch]: manager for controllers.
	reads $(gimpdir)/controllerrc and keeps a mapping of controller
	events to GtkActions.

	* app/gui/gui.c: initialize and shut down the controller stuff.

	* app/display/gimpdisplayshell-callbacks.c
	(gimp_display_shell_canvas_tool_events): if a wheel controller
	exists, dispatch GdkEventScroll to it first and return if it was
	handled.
This commit is contained in:
Michael Natterer 2004-06-15 22:59:26 +00:00 committed by Michael Natterer
parent 7070931e6a
commit d0117ef5b9
14 changed files with 1128 additions and 3 deletions

View File

@ -1,3 +1,30 @@
2004-06-16 Michael Natterer <mitch@gimp.org>
Started to fix bug #106920 in a more genreral way:
* libgimpwidgets/Makefile.am
* libgimpwidgets/gimpwidgetstypes.h
* libgimpwidgets/gimpwidgetsmarshal.list
* libgimpwidgets/gimpcontroller.[ch]: new abstract base class
which provides an API for pluggable input controller modules
(mouse wheel, usb/midi stuff etc.).
* app/widgets/Makefile.am
* app/widgets/widgets-types.h
* app/widgets/gimpcontrollerwheel.[ch]: subclass of the above
which maps wheel mouse scroll events to controller events.
* app/widgets/gimpcontrollers.[ch]: manager for controllers.
reads $(gimpdir)/controllerrc and keeps a mapping of controller
events to GtkActions.
* app/gui/gui.c: initialize and shut down the controller stuff.
* app/display/gimpdisplayshell-callbacks.c
(gimp_display_shell_canvas_tool_events): if a wheel controller
exists, dispatch GdkEventScroll to it first and return if it was
handled.
2004-06-15 Sven Neumann <sven@gimp.org>
* tools/pdbgen/pdb/text_tool.pdb: deprecate the XLFD-based API

View File

@ -45,6 +45,8 @@
#include "tools/tool_manager.h"
#include "widgets/gimpactiongroup.h"
#include "widgets/gimpcontrollers.h"
#include "widgets/gimpcontrollerwheel.h"
#include "widgets/gimpcursor.h"
#include "widgets/gimpdevices.h"
#include "widgets/gimpitemfactory.h"
@ -397,7 +399,7 @@ gimp_display_shell_canvas_expose (GtkWidget *widget,
/* draw the transform tool preview */
gimp_display_shell_preview_transform (shell);
/* draw the guides */
gimp_display_shell_draw_guides (shell);
@ -459,7 +461,7 @@ gimp_display_shell_canvas_tool_events (GtkWidget *canvas,
gboolean return_val = FALSE;
gboolean update_cursor = FALSE;
static GimpToolInfo *space_shaded_tool = NULL;
static GimpToolInfo *space_shaded_tool = NULL;
if (! canvas->window)
{
@ -847,10 +849,18 @@ gimp_display_shell_canvas_tool_events (GtkWidget *canvas,
{
GdkEventScroll *sevent = (GdkEventScroll *) event;
GdkScrollDirection direction;
GimpController *wheel;
wheel = gimp_controllers_get_wheel (gimp);
if (wheel &&
gimp_controller_wheel_scrolled (GIMP_CONTROLLER_WHEEL (wheel),
sevent))
return TRUE;
direction = sevent->direction;
if (state & GDK_SHIFT_MASK)
if (state & GDK_SHIFT_MASK)
{
switch (direction)
{

View File

@ -44,6 +44,7 @@
#include "tools/gimp-tools.h"
#include "widgets/gimpactiongroup.h"
#include "widgets/gimpcontrollers.h"
#include "widgets/gimpdevices.h"
#include "widgets/gimpdevicestatus.h"
#include "widgets/gimpdialogfactory.h"
@ -324,6 +325,7 @@ gui_restore_callback (Gimp *gimp,
dialogs_init (gimp);
gimp_devices_init (gimp, gui_device_change_notify);
gimp_controllers_init (gimp);
session_init (gimp);
(* status_callback) (NULL, _("Tool Options"), 1.0);
@ -354,6 +356,7 @@ gui_restore_after_callback (Gimp *gimp,
image_ui_manager, 0);
gimp_devices_restore (gimp);
gimp_controllers_restore (gimp, image_ui_manager);
if (status_callback == splash_update)
splash_destroy ();
@ -418,6 +421,9 @@ gui_exit_callback (Gimp *gimp,
if (gui_config->save_device_status)
gimp_devices_save (gimp);
if (TRUE /* gui_config->save_controllers */)
gimp_controllers_save (gimp);
gimp_displays_delete (gimp);
gimp_tools_save (gimp);
@ -448,6 +454,7 @@ gui_exit_after_callback (Gimp *gimp,
render_exit (gimp);
dialogs_exit (gimp);
gimp_controllers_exit (gimp);
gimp_devices_exit (gimp);
themes_exit (gimp);

View File

@ -71,6 +71,10 @@ libappwidgets_a_sources = \
gimpcontainerview.h \
gimpcontainerview-utils.c \
gimpcontainerview-utils.h \
gimpcontrollers.c \
gimpcontrollers.h \
gimpcontrollerwheel.c \
gimpcontrollerwheel.h \
gimpcursor.c \
gimpcursor.h \
gimpdasheditor.c \

View File

@ -0,0 +1,420 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "config.h"
#include <gtk/gtk.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "widgets-types.h"
#include "config/gimpconfig-utils.h"
#include "config/gimpconfigwriter.h"
#include "config/gimpscanner.h"
#include "core/gimp.h"
#include "gimpcontrollers.h"
#include "gimpcontrollerwheel.h"
#include "gimpuimanager.h"
#include "gimp-intl.h"
#define GIMP_CONTROLLER_MANAGER_DATA_KEY "gimp-controller-manager"
typedef struct _GimpControllerManager GimpControllerManager;
typedef struct _GimpControllerInfo GimpControllerInfo;
struct _GimpControllerManager
{
GList *controllers;
GimpController *wheel;
GimpUIManager *ui_manager;
};
struct _GimpControllerInfo
{
GimpController *controller;
GHashTable *mapping;
};
/* local function prototypes */
static GimpControllerManager * gimp_controller_manager_get (Gimp *gimp);
static void gimp_controller_manager_free (GimpControllerManager *manager);
static void gimp_controller_info_free (GimpControllerInfo *info);
static gboolean gimp_controller_info_event (GimpController *controller,
const GimpControllerEvent *event,
GimpControllerInfo *info);
static GTokenType gimp_controller_deserialize (GimpControllerManager *manager,
GScanner *scanner);
/* public functions */
void
gimp_controllers_init (Gimp *gimp)
{
GimpControllerManager *manager;
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (gimp_controller_manager_get (gimp) == NULL);
manager = g_new0 (GimpControllerManager, 1);
g_object_set_data_full (G_OBJECT (gimp),
GIMP_CONTROLLER_MANAGER_DATA_KEY, manager,
(GDestroyNotify) gimp_controller_manager_free);
g_type_class_ref (GIMP_TYPE_CONTROLLER_WHEEL);
}
void
gimp_controllers_exit (Gimp *gimp)
{
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (gimp_controller_manager_get (gimp) != NULL);
g_object_set_data (G_OBJECT (gimp), GIMP_CONTROLLER_MANAGER_DATA_KEY, NULL);
g_type_class_unref (g_type_class_peek (GIMP_TYPE_CONTROLLER_WHEEL));
}
enum
{
CONTROLLER,
CONTROLLER_MAPPING
};
void
gimp_controllers_restore (Gimp *gimp,
GimpUIManager *ui_manager)
{
GimpControllerManager *manager;
gchar *filename;
GScanner *scanner;
GTokenType token;
GError *error = NULL;
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (GIMP_IS_UI_MANAGER (ui_manager));
manager = gimp_controller_manager_get (gimp);
g_return_if_fail (manager != NULL);
g_return_if_fail (manager->ui_manager == NULL);
manager->ui_manager = g_object_ref (ui_manager);
filename = gimp_personal_rc_file ("controllerrc");
scanner = gimp_scanner_new_file (filename, &error);
if (! scanner)
{
g_clear_error (&error);
g_free (filename);
return;
}
g_scanner_scope_add_symbol (scanner, 0, "controller",
GINT_TO_POINTER (CONTROLLER));
g_scanner_scope_add_symbol (scanner, CONTROLLER, "mapping",
GINT_TO_POINTER (CONTROLLER_MAPPING));
token = G_TOKEN_LEFT_PAREN;
while (g_scanner_peek_next_token (scanner) == token)
{
token = g_scanner_get_next_token (scanner);
switch (token)
{
case G_TOKEN_LEFT_PAREN:
token = G_TOKEN_SYMBOL;
break;
case G_TOKEN_SYMBOL:
if (scanner->value.v_symbol == GINT_TO_POINTER (CONTROLLER))
{
g_scanner_set_scope (scanner, CONTROLLER);
token = gimp_controller_deserialize (manager, scanner);
if (token == G_TOKEN_RIGHT_PAREN)
g_scanner_set_scope (scanner, 0);
else
break;
}
token = G_TOKEN_RIGHT_PAREN;
break;
case G_TOKEN_RIGHT_PAREN:
token = G_TOKEN_LEFT_PAREN;
break;
default: /* do nothing */
break;
}
}
if (token != G_TOKEN_LEFT_PAREN)
{
g_scanner_get_next_token (scanner);
g_scanner_unexp_token (scanner, token, NULL, NULL, NULL,
_("fatal parse error"), TRUE);
}
if (error)
{
g_message (error->message);
g_clear_error (&error);
gimp_config_file_backup_on_error (filename, "sessionrc", NULL);
}
gimp_scanner_destroy (scanner);
g_free (filename);
manager->controllers = g_list_reverse (manager->controllers);
}
void
gimp_controllers_save (Gimp *gimp)
{
GimpControllerManager *manager;
gchar *filename;
GError *error = NULL;
g_return_if_fail (GIMP_IS_GIMP (gimp));
manager = gimp_controller_manager_get (gimp);
g_return_if_fail (manager != NULL);
filename = gimp_personal_rc_file ("controllerrc");
g_free (filename);
}
GimpController *
gimp_controllers_get_wheel (Gimp *gimp)
{
GimpControllerManager *manager;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
manager = gimp_controller_manager_get (gimp);
g_return_val_if_fail (manager != NULL, NULL);
return manager->wheel;
}
/* private functions */
static GimpControllerManager *
gimp_controller_manager_get (Gimp *gimp)
{
return g_object_get_data (G_OBJECT (gimp), GIMP_CONTROLLER_MANAGER_DATA_KEY);
}
static void
gimp_controller_manager_free (GimpControllerManager *manager)
{
g_list_foreach (manager->controllers, (GFunc) gimp_controller_info_free, NULL);
g_list_free (manager->controllers);
g_object_unref (manager->ui_manager);
g_free (manager);
}
static void
gimp_controller_info_free (GimpControllerInfo *info)
{
if (info->controller)
g_object_unref (info->controller);
if (info->mapping)
g_hash_table_destroy (info->mapping);
g_free (info);
}
static GTokenType
gimp_controller_deserialize (GimpControllerManager *manager,
GScanner *scanner)
{
GimpControllerInfo *info = NULL;
GTokenType token;
gchar *controller_name;
GType controller_type;
token = G_TOKEN_STRING;
if (! gimp_scanner_parse_string (scanner, &controller_name))
goto error;
controller_type = g_type_from_name (controller_name);
g_free (controller_name);
if (! g_type_is_a (controller_type, GIMP_TYPE_CONTROLLER))
goto error;
info = g_new0 (GimpControllerInfo, 1);
info->controller = gimp_controller_new (controller_type);
info->mapping = g_hash_table_new_full (g_int_hash,
g_int_equal,
(GDestroyNotify) g_free,
(GDestroyNotify) g_object_unref);
token = G_TOKEN_LEFT_PAREN;
while (g_scanner_peek_next_token (scanner) == token)
{
token = g_scanner_get_next_token (scanner);
switch (token)
{
case G_TOKEN_LEFT_PAREN:
token = G_TOKEN_SYMBOL;
break;
case G_TOKEN_SYMBOL:
switch (GPOINTER_TO_INT (scanner->value.v_symbol))
{
case CONTROLLER_MAPPING:
{
GtkAction *action = NULL;
GList *list;
gint event_id;
gchar *action_name;
token = G_TOKEN_INT;
if (! gimp_scanner_parse_int (scanner, &event_id))
goto error;
token = G_TOKEN_STRING;
if (! gimp_scanner_parse_string (scanner, &action_name))
goto error;
for (list = gtk_ui_manager_get_action_groups (GTK_UI_MANAGER (manager->ui_manager));
list;
list = g_list_next (list))
{
GtkActionGroup *group = list->data;
action = gtk_action_group_get_action (group, action_name);
if (action)
break;
}
if (action)
{
gint *key = g_new (gint, 1);
*key = event_id;
g_hash_table_insert (info->mapping, key, action);
}
else
{
g_printerr ("%s: action '%s' not found\n",
G_STRFUNC, action_name);
}
g_free (action_name);
}
break;
default:
break;
}
token = G_TOKEN_RIGHT_PAREN;
break;
case G_TOKEN_RIGHT_PAREN:
token = G_TOKEN_LEFT_PAREN;
break;
default:
break;
}
}
if (token == G_TOKEN_LEFT_PAREN)
{
token = G_TOKEN_RIGHT_PAREN;
if (g_scanner_peek_next_token (scanner) == token)
{
g_signal_connect (info->controller, "event",
G_CALLBACK (gimp_controller_info_event),
info);
if (GIMP_IS_CONTROLLER_WHEEL (info->controller))
manager->wheel = info->controller;
manager->controllers = g_list_prepend (manager->controllers, info);
}
else
{
goto error;
}
}
else
{
error:
gimp_controller_info_free (info);
}
return token;
}
static gboolean
gimp_controller_info_event (GimpController *controller,
const GimpControllerEvent *event,
GimpControllerInfo *info)
{
GtkAction *action;
const gchar *controller_name;
controller_name = GIMP_CONTROLLER_GET_CLASS (controller)->name;
g_print ("Received '%s' controller event '%s'\n",
controller_name,
gimp_controller_get_event_name (controller, event->any.event_id));
action = g_hash_table_lookup (info->mapping, &event->any.event_id);
if (action)
{
gtk_action_activate (action);
return TRUE;
}
return FALSE;
}

View File

@ -0,0 +1,36 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpcontrollers.h
* Copyright (C) 2004 Michael Natterer <mitch@gimp.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __GIMP_CONTROLLERS_H__
#define __GIMP_CONTROLLERS_H__
void gimp_controllers_init (Gimp *gimp);
void gimp_controllers_exit (Gimp *gimp);
void gimp_controllers_restore (Gimp *gimp,
GimpUIManager *ui_manager);
void gimp_controllers_save (Gimp *gimp);
GimpController * gimp_controllers_get_wheel (Gimp *gimp);
#endif /* __GIMP_CONTROLLERS_H__ */

View File

@ -0,0 +1,171 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpcontrollerwheel.c
* Copyright (C) 2004 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.
*
* 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 "libgimpwidgets/gimpwidgets.h"
#include "widgets-types.h"
#include "gimpcontrollerwheel.h"
#include "gimp-intl.h"
typedef struct _WheelEvent WheelEvent;
struct _WheelEvent
{
GdkScrollDirection direction;
GdkModifierType modifiers;
const gchar *name;
};
static void gimp_controller_wheel_class_init (GimpControllerWheelClass *klass);
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 GimpControllerClass *parent_class = NULL;
static const WheelEvent wheel_events[] =
{
{ GDK_SCROLL_UP, GDK_MOD1_MASK, N_("Alt + Scroll Up") },
{ GDK_SCROLL_UP, GDK_CONTROL_MASK, N_("Control + Scroll Up") },
{ GDK_SCROLL_UP, GDK_SHIFT_MASK, N_("Shift + Scroll Up") },
{ GDK_SCROLL_UP, 0, N_("Scroll Up") },
{ GDK_SCROLL_DOWN, GDK_MOD1_MASK, N_("Alt + Scroll Down") },
{ GDK_SCROLL_DOWN, GDK_CONTROL_MASK, N_("Control + Scroll Down") },
{ GDK_SCROLL_DOWN, GDK_SHIFT_MASK, N_("Shift + Scroll Down") },
{ GDK_SCROLL_DOWN, 0, N_("Scroll Down") },
{ GDK_SCROLL_LEFT, GDK_MOD1_MASK, N_("Alt + Scroll Left") },
{ GDK_SCROLL_LEFT, GDK_CONTROL_MASK, N_("Control + Scroll Left") },
{ GDK_SCROLL_LEFT, GDK_SHIFT_MASK, N_("Shift + Scroll Left") },
{ GDK_SCROLL_LEFT, 0, N_("Scroll Left") },
{ GDK_SCROLL_RIGHT, GDK_MOD1_MASK, N_("Alt + Scroll Right") },
{ GDK_SCROLL_RIGHT, GDK_CONTROL_MASK, N_("Control + Scroll Right") },
{ GDK_SCROLL_RIGHT, GDK_SHIFT_MASK, N_("Shift + Scroll Right") },
{ GDK_SCROLL_RIGHT, 0, N_("Scroll Right") }
};
GType
gimp_controller_wheel_get_type (void)
{
static GType controller_type = 0;
if (! controller_type)
{
static const GTypeInfo controller_info =
{
sizeof (GimpControllerWheelClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_controller_wheel_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpControllerWheel),
0, /* n_preallocs */
NULL /* instance_init */
};
controller_type = g_type_register_static (GIMP_TYPE_CONTROLLER,
"GimpControllerWheel",
&controller_info, 0);
}
return controller_type;
}
static void
gimp_controller_wheel_class_init (GimpControllerWheelClass *klass)
{
GimpControllerClass *controller_class = GIMP_CONTROLLER_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
controller_class->name = _("Mouse Wheel");
controller_class->get_n_events = gimp_controller_wheel_get_n_events;
controller_class->get_event_name = gimp_controller_wheel_get_event_name;
}
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;
return gettext (wheel_events[event_id].name);
}
gboolean
gimp_controller_wheel_scrolled (GimpControllerWheel *wheel,
const GdkEventScroll *sevent)
{
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)
{
if ((wheel_events[i].modifiers & sevent->state) ==
wheel_events[i].modifiers)
{
GimpControllerEvent controller_event;
GimpControllerEventTrigger *trigger;
trigger = (GimpControllerEventTrigger *) &controller_event;
trigger->type = GIMP_CONTROLLER_EVENT_TRIGGER;
trigger->source = GIMP_CONTROLLER (wheel);
trigger->event_id = i;
if (gimp_controller_event (GIMP_CONTROLLER (wheel),
&controller_event))
{
return TRUE;
}
}
}
}
return FALSE;
}

View File

@ -0,0 +1,57 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpcontrollerwheel.h
* Copyright (C) 2004 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.
*
* 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.
*/
#ifndef __GIMP_CONTROLLER_WHELL_H__
#define __GIMP_CONTROLLER_WHEEL_H__
#include "libgimpwidgets/gimpcontroller.h"
#define GIMP_TYPE_CONTROLLER_WHEEL (gimp_controller_wheel_get_type ())
#define GIMP_CONTROLLER_WHEEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_CONTROLLER_WHEEL, GimpControllerWheel))
#define GIMP_CONTROLLER_WHEEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_CONTROLLER_WHEEL, GimpControllerWheelClass))
#define GIMP_IS_CONTROLLER_WHEEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_CONTROLLER_WHEEL))
#define GIMP_IS_CONTROLLER_WHEEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_CONTROLLER_WHEEL))
#define GIMP_CONTROLLER_WHEEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_CONTROLLER_WHEEL, GimpControllerWheelClass))
typedef struct _GimpControllerWheelClass GimpControllerWheelClass;
struct _GimpControllerWheel
{
GimpController parent_instance;
};
struct _GimpControllerWheelClass
{
GimpControllerClass parent_class;
};
GType gimp_controller_wheel_get_type (void) G_GNUC_CONST;
gboolean gimp_controller_wheel_scrolled (GimpControllerWheel *wheel,
const GdkEventScroll *sevent);
#endif /* __GIMP_CONTROLLER_WHEEL_H__ */

View File

@ -56,6 +56,8 @@ typedef struct _GimpPreviewRendererImage GimpPreviewRendererImage;
typedef struct _GimpPreviewRendererImagefile GimpPreviewRendererImagefile;
typedef struct _GimpPreviewRendererVectors GimpPreviewRendererVectors;
typedef struct _GimpControllerWheel GimpControllerWheel;
/* widgets */

View File

@ -86,6 +86,8 @@ libgimpwidgets_2_0_la_sources = \
gimpcolorselect.h \
gimpcolorselection.c \
gimpcolorselection.h \
gimpcontroller.c \
gimpcontroller.h \
gimpdialog.c \
gimpdialog.h \
gimpfileentry.c \
@ -151,6 +153,7 @@ libgimpwidgetsinclude_HEADERS = \
gimpcolorselector.h \
gimpcolorselect.h \
gimpcolorselection.h \
gimpcontroller.h \
gimpdialog.h \
gimpfileentry.h \
gimpframe.h \

View File

@ -0,0 +1,252 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpcontroller.c
* Copyright (C) 2004 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.
*
* 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 "libgimpcolor/gimpcolor.h"
#include "gimpwidgetstypes.h"
#include "gimpcontroller.h"
#include "gimpwidgetsmarshal.h"
enum
{
PROP_0,
PROP_ENABLED
};
enum
{
EVENT,
LAST_SIGNAL
};
static void gimp_controller_class_init (GimpControllerClass *klass);
static void gimp_controller_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_controller_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static GObjectClass *parent_class = NULL;
static guint controller_signals[LAST_SIGNAL] = { 0 };
GType
gimp_controller_get_type (void)
{
static GType controller_type = 0;
if (! controller_type)
{
static const GTypeInfo controller_info =
{
sizeof (GimpControllerClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_controller_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpController),
0, /* n_preallocs */
NULL /* instance_init */
};
controller_type = g_type_register_static (G_TYPE_OBJECT,
"GimpController",
&controller_info, 0);
}
return controller_type;
}
gboolean
gimp_controller_boolean_handled_accumulator (GSignalInvocationHint *ihint,
GValue *return_accu,
const GValue *handler_return,
gpointer dummy)
{
gboolean continue_emission;
gboolean signal_handled;
signal_handled = g_value_get_boolean (handler_return);
g_value_set_boolean (return_accu, signal_handled);
continue_emission = ! signal_handled;
return continue_emission;
}
static void
gimp_controller_class_init (GimpControllerClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
object_class->set_property = gimp_controller_set_property;
object_class->get_property = gimp_controller_get_property;
g_object_class_install_property (object_class, PROP_ENABLED,
g_param_spec_boolean ("enabled", NULL, NULL,
TRUE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
controller_signals[EVENT] =
g_signal_new ("event",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GimpControllerClass, event),
gimp_controller_boolean_handled_accumulator, NULL,
_gimp_widgets_marshal_BOOLEAN__POINTER,
G_TYPE_BOOLEAN, 1,
G_TYPE_POINTER);
klass->name = "Unnamed";
klass->help_id = NULL;
klass->get_n_events = NULL;
klass->get_event_name = NULL;
klass->event = NULL;
}
static void
gimp_controller_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpController *controller = GIMP_CONTROLLER (object);
switch (property_id)
{
case PROP_ENABLED:
controller->enabled = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_controller_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GimpController *controller = GIMP_CONTROLLER (object);
switch (property_id)
{
case PROP_ENABLED:
g_value_set_boolean (value, controller->enabled);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
GimpController *
gimp_controller_new (GType controller_type)
{
GimpController *controller;
g_return_val_if_fail (g_type_is_a (controller_type, GIMP_TYPE_CONTROLLER),
NULL);
controller = g_object_new (controller_type, NULL);
return controller;
}
gint
gimp_controller_get_n_events (GimpController *controller)
{
g_return_val_if_fail (GIMP_IS_CONTROLLER (controller), 0);
if (GIMP_CONTROLLER_GET_CLASS (controller)->get_n_events)
return GIMP_CONTROLLER_GET_CLASS (controller)->get_n_events (controller);
return 0;
}
const gchar *
gimp_controller_get_event_name (GimpController *controller,
gint event_id)
{
g_return_val_if_fail (GIMP_IS_CONTROLLER (controller), NULL);
if (GIMP_CONTROLLER_GET_CLASS (controller)->get_event_name)
return GIMP_CONTROLLER_GET_CLASS (controller)->get_event_name (controller,
event_id);
return NULL;
}
void
gimp_controller_set_enabled (GimpController *controller,
gboolean enabled)
{
g_return_if_fail (GIMP_IS_CONTROLLER (controller));
if (enabled != controller->enabled)
{
g_object_set (controller,
"enabled", enabled,
NULL);
}
}
gboolean
gimp_controller_get_enabled (GimpController *controller)
{
g_return_val_if_fail (GIMP_IS_CONTROLLER (controller), FALSE);
return controller->enabled;
}
gboolean
gimp_controller_event (GimpController *controller,
const GimpControllerEvent *event)
{
gboolean retval = FALSE;
g_return_val_if_fail (GIMP_IS_CONTROLLER (controller), FALSE);
g_return_val_if_fail (event != NULL, FALSE);
g_signal_emit (controller, controller_signals[EVENT], 0,
event, &retval);
return retval;
}

View File

@ -0,0 +1,133 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpcontroller.h
* Copyright (C) 2004 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.
*
* 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.
*/
#ifndef __GIMP_CONTROLLER_H__
#define __GIMP_CONTROLLER_H__
G_BEGIN_DECLS
/* For information look at the html documentation */
typedef enum
{
GIMP_CONTROLLER_EVENT_TRIGGER,
GIMP_CONTROLLER_EVENT_VALUE
} GimpControllerEventType;
typedef struct _GimpControllerEventAny GimpControllerEventAny;
typedef struct _GimpControllerEventTrigger GimpControllerEventTrigger;
typedef struct _GimpControllerEventValue GimpControllerEventValue;
typedef union _GimpControllerEvent GimpControllerEvent;
struct _GimpControllerEventAny
{
GimpControllerEventType type;
GimpController *source;
gint event_id;
};
struct _GimpControllerEventTrigger
{
GimpControllerEventType type;
GimpController *source;
gint event_id;
};
struct _GimpControllerEventValue
{
GimpControllerEventType type;
GimpController *source;
gint event_id;
GValue value;
};
union _GimpControllerEvent
{
GimpControllerEventType type;
GimpControllerEventAny any;
GimpControllerEventTrigger trigger;
GimpControllerEventValue value;
};
#define GIMP_TYPE_CONTROLLER (gimp_controller_get_type ())
#define GIMP_CONTROLLER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_CONTROLLER, GimpController))
#define GIMP_CONTROLLER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_CONTROLLER, GimpControllerClass))
#define GIMP_IS_CONTROLLER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_CONTROLLER))
#define GIMP_IS_CONTROLLER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_CONTROLLER))
#define GIMP_CONTROLLER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_CONTROLLER, GimpControllerClass))
typedef struct _GimpControllerClass GimpControllerClass;
struct _GimpController
{
GObject parent_instance;
gboolean enabled;
};
struct _GimpControllerClass
{
GObjectClass parent_class;
const gchar *name;
const gchar *help_id;
/* virtual functions */
gint (* get_n_events) (GimpController *controller);
const gchar * (* get_event_name) (GimpController *controller,
gint event_id);
/* signals */
gboolean (* event) (GimpController *controller,
const GimpControllerEvent *event);
/* Padding for future expansion */
void (* _gimp_reserved1) (void);
void (* _gimp_reserved2) (void);
void (* _gimp_reserved3) (void);
void (* _gimp_reserved4) (void);
};
GType gimp_controller_get_type (void) G_GNUC_CONST;
GimpController * gimp_controller_new (GType controller_type);
gint gimp_controller_get_n_events (GimpController *controller);
const gchar * gimp_controller_get_event_name (GimpController *controller,
gint event_id);
void gimp_controller_set_enabled (GimpController *controller,
gboolean enabled);
gboolean gimp_controller_get_enabled (GimpController *controller);
/* protected */
gboolean gimp_controller_event (GimpController *controller,
const GimpControllerEvent *event);
G_END_DECLS
#endif /* __GIMP_CONTROLLER_H__ */

View File

@ -27,3 +27,5 @@ VOID: INT, INT
VOID: OBJECT
VOID: OBJECT, INT
VOID: POINTER, POINTER
BOOLEAN: POINTER

View File

@ -67,6 +67,7 @@ typedef struct _GimpColorScales GimpColorScales;
typedef struct _GimpColorSelector GimpColorSelector;
typedef struct _GimpColorSelect GimpColorSelect;
typedef struct _GimpColorSelection GimpColorSelection;
typedef struct _GimpController GimpController;
typedef struct _GimpDialog GimpDialog;
typedef struct _GimpFileEntry GimpFileEntry;
typedef struct _GimpFrame GimpFrame;