~ubuntu-branches/ubuntu/maverick/gimp/maverick-updates

« back to all changes in this revision

Viewing changes to app/widgets/gimpcontrollerwheel.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2005-12-09 19:44:52 UTC
  • Revision ID: james.westby@ubuntu.com-20051209194452-yggpemjlofpjqyf4
Tags: upstream-2.2.9
ImportĀ upstreamĀ versionĀ 2.2.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* LIBGIMP - The GIMP Library
 
2
 * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
 
3
 *
 
4
 * gimpcontrollerwheel.c
 
5
 * Copyright (C) 2004 Michael Natterer <mitch@gimp.org>
 
6
 *
 
7
 * This library is free software; you can redistribute it and/or
 
8
 * modify it under the terms of the GNU Lesser General Public
 
9
 * License as published by the Free Software Foundation; either
 
10
 * version 2 of the License, or (at your option) any later version.
 
11
 *
 
12
 * This library is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
 * Lesser General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU Lesser General Public
 
18
 * License along with this library; if not, write to the
 
19
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
20
 * Boston, MA 02111-1307, USA.
 
21
 */
 
22
 
 
23
#include "config.h"
 
24
 
 
25
#include <gtk/gtk.h>
 
26
 
 
27
#include "libgimpwidgets/gimpwidgets.h"
 
28
 
 
29
#include "widgets-types.h"
 
30
 
 
31
#include "gimpcontrollerwheel.h"
 
32
#include "gimphelp-ids.h"
 
33
 
 
34
#include "gimp-intl.h"
 
35
 
 
36
 
 
37
typedef struct _WheelEvent WheelEvent;
 
38
 
 
39
struct _WheelEvent
 
40
{
 
41
  GdkScrollDirection  direction;
 
42
  GdkModifierType     modifiers;
 
43
  const gchar        *name;
 
44
  const gchar        *blurb;
 
45
};
 
46
 
 
47
 
 
48
static void          gimp_controller_wheel_class_init      (GimpControllerWheelClass *klass);
 
49
static void          gimp_controller_wheel_init            (GimpControllerWheel      *wheel);
 
50
 
 
51
static GObject     * gimp_controller_wheel_constructor     (GType           type,
 
52
                                                            guint           n_params,
 
53
                                                            GObjectConstructParam *params);
 
54
 
 
55
static gint          gimp_controller_wheel_get_n_events    (GimpController *controller);
 
56
static const gchar * gimp_controller_wheel_get_event_name  (GimpController *controller,
 
57
                                                            gint            event_id);
 
58
static const gchar * gimp_controller_wheel_get_event_blurb (GimpController *controller,
 
59
                                                            gint            event_id);
 
60
 
 
61
 
 
62
static GimpControllerClass *parent_class = NULL;
 
63
 
 
64
static const WheelEvent wheel_events[] =
 
65
{
 
66
  { GDK_SCROLL_UP, GDK_MOD1_MASK | GDK_CONTROL_MASK | GDK_SHIFT_MASK,
 
67
    "scroll-up-shift-control-alt",
 
68
    N_("Scroll Up (Shift + Control + Alt)") },
 
69
  { GDK_SCROLL_UP, GDK_MOD1_MASK | GDK_CONTROL_MASK,
 
70
    "scroll-up-control-alt",
 
71
    N_("Scroll Up (Control + Alt)") },
 
72
  { GDK_SCROLL_UP, GDK_MOD1_MASK | GDK_SHIFT_MASK,
 
73
    "scroll-up-shift-alt",
 
74
    N_("Scroll Up (Shift + Alt)") },
 
75
  { GDK_SCROLL_UP, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
 
76
    "scroll-up-shift-control",
 
77
    N_("Scroll Up (Shift + Control)") },
 
78
  { GDK_SCROLL_UP, GDK_MOD1_MASK,
 
79
    "scroll-up-alt",
 
80
    N_("Scroll Up (Alt)") },
 
81
  { GDK_SCROLL_UP, GDK_CONTROL_MASK,
 
82
    "scroll-up-control",
 
83
    N_("Scroll Up (Control)") },
 
84
  { GDK_SCROLL_UP, GDK_SHIFT_MASK,
 
85
    "scroll-up-shift",
 
86
    N_("Scroll Up (Shift)") },
 
87
  { GDK_SCROLL_UP, 0,
 
88
    "scroll-up",
 
89
    N_("Scroll Up") },
 
90
 
 
91
  { GDK_SCROLL_DOWN, GDK_MOD1_MASK | GDK_CONTROL_MASK | GDK_SHIFT_MASK,
 
92
    "scroll-down-shift-control-alt",
 
93
    N_("Scroll Down (Shift + Control + Alt)") },
 
94
  { GDK_SCROLL_DOWN, GDK_MOD1_MASK | GDK_CONTROL_MASK,
 
95
    "scroll-down-control-alt",
 
96
    N_("Scroll Down (Control + Alt)") },
 
97
  { GDK_SCROLL_DOWN, GDK_MOD1_MASK | GDK_SHIFT_MASK,
 
98
    "scroll-down-shift-alt",
 
99
    N_("Scroll Down (Shift + Alt)") },
 
100
  { GDK_SCROLL_DOWN, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
 
101
    "scroll-down-shift-control",
 
102
    N_("Scroll Down (Shift + Control)") },
 
103
  { GDK_SCROLL_DOWN, GDK_MOD1_MASK,
 
104
    "scroll-down-alt",
 
105
    N_("Scroll Down (Alt)") },
 
106
  { GDK_SCROLL_DOWN, GDK_CONTROL_MASK,
 
107
    "scroll-down-control",
 
108
    N_("Scroll Down (Control)") },
 
109
  { GDK_SCROLL_DOWN, GDK_SHIFT_MASK,
 
110
    "scroll-down-shift",
 
111
    N_("Scroll Down (Shift)") },
 
112
  { GDK_SCROLL_DOWN, 0,
 
113
    "scroll-down",
 
114
    N_("Scroll Down") },
 
115
 
 
116
  { GDK_SCROLL_LEFT, GDK_MOD1_MASK | GDK_CONTROL_MASK | GDK_SHIFT_MASK,
 
117
    "scroll-left-shift-control-alt",
 
118
    N_("Scroll Left (Shift + Control + Alt)") },
 
119
  { GDK_SCROLL_LEFT, GDK_MOD1_MASK | GDK_CONTROL_MASK,
 
120
    "scroll-left-control-alt",
 
121
    N_("Scroll Left (Control + Alt)") },
 
122
  { GDK_SCROLL_LEFT, GDK_MOD1_MASK | GDK_SHIFT_MASK,
 
123
    "scroll-left-shift-alt",
 
124
    N_("Scroll Left (Shift + Alt)") },
 
125
  { GDK_SCROLL_LEFT, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
 
126
    "scroll-left-shift-control",
 
127
    N_("Scroll Left (Shift + Control)") },
 
128
  { GDK_SCROLL_LEFT, GDK_MOD1_MASK,
 
129
    "scroll-left-alt",
 
130
    N_("Scroll Left (Alt)") },
 
131
  { GDK_SCROLL_LEFT, GDK_CONTROL_MASK,
 
132
    "scroll-left-control",
 
133
    N_("Scroll Left (Control)") },
 
134
  { GDK_SCROLL_LEFT, GDK_SHIFT_MASK,
 
135
    "scroll-left-shift",
 
136
    N_("Scroll Left (Shift)") },
 
137
  { GDK_SCROLL_LEFT, 0,
 
138
    "scroll-left",
 
139
    N_("Scroll Left") },
 
140
 
 
141
  { GDK_SCROLL_RIGHT, GDK_MOD1_MASK | GDK_CONTROL_MASK | GDK_SHIFT_MASK,
 
142
    "scroll-right-shift-control-alt",
 
143
    N_("Scroll Right (Shift + Control + Alt)") },
 
144
  { GDK_SCROLL_RIGHT, GDK_MOD1_MASK | GDK_CONTROL_MASK,
 
145
    "scroll-right-control-alt",
 
146
    N_("Scroll Right (Control + Alt)") },
 
147
  { GDK_SCROLL_RIGHT, GDK_MOD1_MASK | GDK_SHIFT_MASK,
 
148
    "scroll-right-shift-alt",
 
149
    N_("Scroll Right (Shift + Alt)") },
 
150
  { GDK_SCROLL_RIGHT, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
 
151
    "scroll-right-shift-control",
 
152
    N_("Scroll Right (Shift + Control)") },
 
153
  { GDK_SCROLL_RIGHT, GDK_MOD1_MASK,
 
154
    "scroll-right-alt",
 
155
    N_("Scroll Right (Alt)") },
 
156
  { GDK_SCROLL_RIGHT, GDK_CONTROL_MASK,
 
157
    "scroll-right-control",
 
158
    N_("Scroll Right (Control)") },
 
159
  { GDK_SCROLL_RIGHT, GDK_SHIFT_MASK,
 
160
    "scroll-right-shift",
 
161
    N_("Scroll Right (Shift)") },
 
162
  { GDK_SCROLL_RIGHT, 0,
 
163
    "scroll-right",
 
164
    N_("Scroll Right") }
 
165
};
 
166
 
 
167
 
 
168
GType
 
169
gimp_controller_wheel_get_type (void)
 
170
{
 
171
  static GType controller_type = 0;
 
172
 
 
173
  if (! controller_type)
 
174
    {
 
175
      static const GTypeInfo controller_info =
 
176
      {
 
177
        sizeof (GimpControllerWheelClass),
 
178
        (GBaseInitFunc) NULL,
 
179
        (GBaseFinalizeFunc) NULL,
 
180
        (GClassInitFunc) gimp_controller_wheel_class_init,
 
181
        NULL,           /* class_finalize */
 
182
        NULL,           /* class_data     */
 
183
        sizeof (GimpControllerWheel),
 
184
        0,              /* n_preallocs    */
 
185
        (GInstanceInitFunc) gimp_controller_wheel_init,
 
186
      };
 
187
 
 
188
      controller_type = g_type_register_static (GIMP_TYPE_CONTROLLER,
 
189
                                                "GimpControllerWheel",
 
190
                                                &controller_info, 0);
 
191
    }
 
192
 
 
193
  return controller_type;
 
194
}
 
195
 
 
196
static void
 
197
gimp_controller_wheel_class_init (GimpControllerWheelClass *klass)
 
198
{
 
199
  GObjectClass        *object_class     = G_OBJECT_CLASS (klass);
 
200
  GimpControllerClass *controller_class = GIMP_CONTROLLER_CLASS (klass);
 
201
 
 
202
  parent_class = g_type_class_peek_parent (klass);
 
203
 
 
204
  object_class->constructor         = gimp_controller_wheel_constructor;
 
205
 
 
206
  controller_class->name            = _("Mouse Wheel");
 
207
  controller_class->help_id         = GIMP_HELP_CONTROLLER_WHEEL;
 
208
 
 
209
  controller_class->get_n_events    = gimp_controller_wheel_get_n_events;
 
210
  controller_class->get_event_name  = gimp_controller_wheel_get_event_name;
 
211
  controller_class->get_event_blurb = gimp_controller_wheel_get_event_blurb;
 
212
}
 
213
 
 
214
static void
 
215
gimp_controller_wheel_init (GimpControllerWheel *wheel)
 
216
{
 
217
}
 
218
 
 
219
static GObject *
 
220
gimp_controller_wheel_constructor (GType                  type,
 
221
                                   guint                  n_params,
 
222
                                   GObjectConstructParam *params)
 
223
{
 
224
  GObject *object;
 
225
 
 
226
  object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
 
227
 
 
228
  g_object_set (object,
 
229
                "name",  _("Mouse Wheel Events"),
 
230
                "state", _("Ready"),
 
231
                NULL);
 
232
 
 
233
  return object;
 
234
}
 
235
 
 
236
static gint
 
237
gimp_controller_wheel_get_n_events (GimpController *controller)
 
238
{
 
239
  return G_N_ELEMENTS (wheel_events);
 
240
}
 
241
 
 
242
static const gchar *
 
243
gimp_controller_wheel_get_event_name (GimpController *controller,
 
244
                                      gint            event_id)
 
245
{
 
246
  if (event_id < 0 || event_id >= G_N_ELEMENTS (wheel_events))
 
247
    return NULL;
 
248
 
 
249
  return wheel_events[event_id].name;
 
250
}
 
251
 
 
252
static const gchar *
 
253
gimp_controller_wheel_get_event_blurb (GimpController *controller,
 
254
                                       gint            event_id)
 
255
{
 
256
  if (event_id < 0 || event_id >= G_N_ELEMENTS (wheel_events))
 
257
    return NULL;
 
258
 
 
259
  return gettext (wheel_events[event_id].blurb);
 
260
}
 
261
 
 
262
gboolean
 
263
gimp_controller_wheel_scroll (GimpControllerWheel  *wheel,
 
264
                              const GdkEventScroll *sevent)
 
265
{
 
266
  gint i;
 
267
 
 
268
  g_return_val_if_fail (GIMP_IS_CONTROLLER_WHEEL (wheel), FALSE);
 
269
  g_return_val_if_fail (sevent != NULL, FALSE);
 
270
 
 
271
  for (i = 0; i < G_N_ELEMENTS (wheel_events); i++)
 
272
    {
 
273
      if (wheel_events[i].direction == sevent->direction)
 
274
        {
 
275
          if ((wheel_events[i].modifiers & sevent->state) ==
 
276
              wheel_events[i].modifiers)
 
277
            {
 
278
              GimpControllerEvent         controller_event;
 
279
              GimpControllerEventTrigger *trigger;
 
280
 
 
281
              trigger = (GimpControllerEventTrigger *) &controller_event;
 
282
 
 
283
              trigger->type     = GIMP_CONTROLLER_EVENT_TRIGGER;
 
284
              trigger->source   = GIMP_CONTROLLER (wheel);
 
285
              trigger->event_id = i;
 
286
 
 
287
              if (gimp_controller_event (GIMP_CONTROLLER (wheel),
 
288
                                         &controller_event))
 
289
                {
 
290
                  return TRUE;
 
291
                }
 
292
            }
 
293
        }
 
294
    }
 
295
 
 
296
  return FALSE;
 
297
}