Merge lp:~charlesk/ido/lp-921065 into lp:ido/0.3

Proposed by Conor Curran
Status: Merged
Approved by: Charles Kerr
Approved revision: 106
Merge reported by: Charles Kerr
Merged at revision: not available
Proposed branch: lp:~charlesk/ido/lp-921065
Merge into: lp:ido/0.3
Diff against target: 1042 lines (+121/-734)
5 files modified
src/Makefile.am (+0/-15)
src/idooffscreenproxy.c (+0/-515)
src/idooffscreenproxy.h (+0/-62)
src/idoscalemenuitem.c (+113/-140)
src/idoscalemenuitem.h (+8/-2)
To merge this branch: bzr merge lp:~charlesk/ido/lp-921065
Reviewer Review Type Date Requested Status
Conor Curran (community) Approve
Review via email: mp+97055@code.launchpad.net

Description of the change

Provides the needed signals inorder to determine ido icon clicking. (helps the i-sound)

To post a comment you must log in.
Revision history for this message
Conor Curran (cjcurran) wrote :

looks good !

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/Makefile.am'
--- src/Makefile.am 2011-09-13 16:21:24 +0000
+++ src/Makefile.am 2012-03-12 16:37:21 +0000
@@ -28,13 +28,6 @@
28 idotypebuiltins.c.template28 idotypebuiltins.c.template
2929
3030
31if USE_GTK3
32sources_h += idooffscreenproxy.h
33else
34EXTRA_DIST += idooffscreenproxy.h \
35 idooffscreenproxy.c
36endif
37
38idotypebuiltins.h: stamp-idotypebuiltins.h31idotypebuiltins.h: stamp-idotypebuiltins.h
3932
40stamp-idotypebuiltins.h: $(sources_h)33stamp-idotypebuiltins.h: $(sources_h)
@@ -73,10 +66,6 @@
73 idoscalemenuitem.c \66 idoscalemenuitem.c \
74 idotimeline.c 67 idotimeline.c
7568
76if USE_GTK3
77libido_0_1_la_SOURCES += idooffscreenproxy.c
78endif
79
80libido3_0_1_la_SOURCES = $(libido_0_1_la_SOURCES)69libido3_0_1_la_SOURCES = $(libido_0_1_la_SOURCES)
8170
82libidoincludedir=$(includedir)/libido$(VER)-0.1/libido71libidoincludedir=$(includedir)/libido$(VER)-0.1/libido
@@ -90,10 +79,6 @@
90 idotimeline.h \79 idotimeline.h \
91 libido.h80 libido.h
9281
93if USE_GTK3
94libidoinclude_HEADERS += idooffscreenproxy.h
95endif
96
97libido_0_1_la_LIBADD = $(GTK_LIBS)82libido_0_1_la_LIBADD = $(GTK_LIBS)
98libido_0_1_la_LDFLAGS = $(GTK_LT_LDFLAGS)83libido_0_1_la_LDFLAGS = $(GTK_LT_LDFLAGS)
99libido3_0_1_la_LIBADD = $(libido_0_1_la_LIBADD)84libido3_0_1_la_LIBADD = $(libido_0_1_la_LIBADD)
10085
=== removed file 'src/idooffscreenproxy.c'
--- src/idooffscreenproxy.c 2012-02-09 04:18:09 +0000
+++ src/idooffscreenproxy.c 1970-01-01 00:00:00 +0000
@@ -1,515 +0,0 @@
1/*
2 * Copyright 2011 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of either or both of the following licenses:
6 *
7 * 1) the GNU Lesser General Public License version 3, as published by the
8 * Free Software Foundation; and/or
9 * 2) the GNU Lesser General Public License version 2.1, as published by
10 * the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranties of
14 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the applicable version of the GNU Lesser General Public
16 * License for more details.
17 *
18 * You should have received a copy of both the GNU Lesser General Public
19 * License version 3 and version 2.1 along with this program. If not, see
20 * <http://www.gnu.org/licenses/>
21 *
22 * Authors:
23 * Robert Carr <racarr@canonical.com>
24 */
25
26#include <gtk/gtk.h>
27#include "idooffscreenproxy.h"
28
29struct _IdoOffscreenProxyPrivate
30{
31 GtkWidget *child;
32
33 GdkWindow *offscreen_window;
34};
35
36static void ido_offscreen_proxy_realize (GtkWidget *widget);
37static void ido_offscreen_proxy_unrealize (GtkWidget *widget);
38static void ido_offscreen_proxy_get_preferred_width (GtkWidget *widget,
39 gint *minimum,
40 gint *natural);
41static void ido_offscreen_proxy_get_preferred_height (GtkWidget *widget,
42 gint *minimum,
43 gint *natural);
44
45static void ido_offscreen_proxy_size_allocate (GtkWidget *widget,
46 GtkAllocation *allocation);
47static gboolean ido_offscreen_proxy_damage (GtkWidget *widget,
48 GdkEventExpose *event);
49static gboolean ido_offscreen_proxy_draw (GtkWidget *widget,
50 cairo_t *cr);
51static void ido_offscreen_proxy_add (GtkContainer *container,
52 GtkWidget *child);
53static void ido_offscreen_proxy_remove (GtkContainer *container,
54 GtkWidget *widget);
55static void ido_offscreen_proxy_forall (GtkContainer *container,
56 gboolean include_internals,
57 GtkCallback callback,
58 gpointer callback_data);
59static GType ido_offscreen_proxy_child_type (GtkContainer *container);
60
61static cairo_surface_t * ido_offscreen_proxy_create_alpha_image_surface (GdkWindow *offscreen, gint width, gint height);
62
63
64
65G_DEFINE_TYPE (IdoOffscreenProxy, ido_offscreen_proxy, GTK_TYPE_CONTAINER);
66
67#define IDO_OFFSCREEN_PROXY_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), IDO_TYPE_OFFSCREEN_PROXY, IdoOffscreenProxyPrivate))
68
69static void
70ido_offscreen_proxy_class_init (IdoOffscreenProxyClass *klass)
71{
72 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
73 GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
74
75 g_type_class_add_private (klass, sizeof (IdoOffscreenProxyPrivate));
76
77 widget_class->realize = ido_offscreen_proxy_realize;
78 widget_class->unrealize = ido_offscreen_proxy_unrealize;
79 widget_class->get_preferred_width = ido_offscreen_proxy_get_preferred_width;
80 widget_class->get_preferred_height = ido_offscreen_proxy_get_preferred_height;
81 widget_class->size_allocate = ido_offscreen_proxy_size_allocate;
82 widget_class->draw = ido_offscreen_proxy_draw;
83
84 g_signal_override_class_closure (g_signal_lookup ("damage-event", GTK_TYPE_WIDGET),
85 IDO_TYPE_OFFSCREEN_PROXY,
86 g_cclosure_new (G_CALLBACK (ido_offscreen_proxy_damage),
87 NULL, NULL));
88
89 container_class->add = ido_offscreen_proxy_add;
90 container_class->remove = ido_offscreen_proxy_remove;
91 container_class->forall = ido_offscreen_proxy_forall;
92 container_class->child_type = ido_offscreen_proxy_child_type;
93
94}
95
96static void
97ido_offscreen_proxy_init (IdoOffscreenProxy *proxy)
98{
99 proxy->priv = IDO_OFFSCREEN_PROXY_GET_PRIVATE (proxy);
100
101 gtk_widget_set_has_window (GTK_WIDGET (proxy), TRUE);
102
103 gtk_widget_set_events (GTK_WIDGET(proxy), gtk_widget_get_events (GTK_WIDGET(proxy))
104 | GDK_EXPOSURE_MASK
105 | GDK_POINTER_MOTION_MASK
106 | GDK_BUTTON_PRESS_MASK
107 | GDK_BUTTON_RELEASE_MASK
108 | GDK_SCROLL_MASK
109 | GDK_ENTER_NOTIFY_MASK
110 | GDK_LEAVE_NOTIFY_MASK);
111
112 gtk_container_set_border_width (GTK_CONTAINER (proxy), 0);
113}
114
115GtkWidget *
116ido_offscreen_proxy_new (void)
117{
118 return g_object_new (IDO_TYPE_OFFSCREEN_PROXY, NULL);
119}
120
121static GdkWindow *
122pick_offscreen_child (GdkWindow *offscreen_window,
123 double widget_x, double widget_y,
124 IdoOffscreenProxy *proxy)
125{
126 GtkAllocation child_area;
127
128 if (proxy->priv->child && gtk_widget_get_visible (proxy->priv->child))
129 {
130 gtk_widget_get_allocation (proxy->priv->child, &child_area);
131
132 // if (widget_x >= 0 && widget_x < child_area.width &&
133 // widget_y >= 0 && widget_y < child_area.height)
134 //return proxy->priv->offscreen_window;
135 return proxy->priv->offscreen_window;
136 }
137
138 return NULL;
139}
140
141static void
142offscreen_to_parent (GdkWindow *offscreen_window,
143 double offscreen_x,
144 double offscreen_y,
145 double *parent_x,
146 double *parent_y,
147 gpointer user_data)
148{
149 *parent_x = offscreen_x;
150 *parent_y = offscreen_y;
151}
152
153static void
154offscreen_from_parent (GdkWindow *window,
155 double parent_x,
156 double parent_y,
157 double *offscreen_x,
158 double *offscreen_y,
159 gpointer user_data)
160{
161 *offscreen_x = parent_x;
162 *offscreen_y = parent_y;
163}
164
165static cairo_surface_t *
166ido_offscreen_proxy_create_alpha_image_surface (GdkWindow *offscreen, gint width, gint height)
167{
168 return cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
169}
170
171static void
172proxy_add_css (GtkStyleContext *sc)
173{
174 GtkCssProvider *provider = gtk_css_provider_new();
175 const gchar *proxy_css = ".menu.ido-offscreen { \nborder-width: 0;\nborder-radius:0; \n}\n";
176
177 gtk_css_provider_load_from_data (provider, proxy_css, -1, NULL);
178
179 gtk_style_context_add_provider (sc, GTK_STYLE_PROVIDER (provider),
180 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
181
182}
183
184static void
185ido_offscreen_proxy_realize (GtkWidget *widget)
186{
187 IdoOffscreenProxy *proxy = IDO_OFFSCREEN_PROXY (widget);
188 GtkAllocation allocation, child_area;
189 GtkStyleContext *context;
190 GdkWindow *window;
191 GdkWindowAttr attributes;
192 gint attributes_mask;
193 // GtkRequisition child_requisition;
194
195 gtk_widget_set_realized (widget, TRUE);
196
197 gtk_widget_get_allocation (widget, &allocation);
198
199 attributes.x = allocation.x;
200 attributes.y = allocation.y;
201 attributes.width = allocation.width;
202 attributes.height = allocation.height;
203
204 attributes.window_type = GDK_WINDOW_CHILD;
205 attributes.event_mask = gtk_widget_get_events (widget)
206 | GDK_EXPOSURE_MASK
207 | GDK_POINTER_MOTION_MASK
208 | GDK_BUTTON_PRESS_MASK
209 | GDK_BUTTON_RELEASE_MASK
210 | GDK_SCROLL_MASK
211 | GDK_ENTER_NOTIFY_MASK
212 | GDK_LEAVE_NOTIFY_MASK;
213 attributes.visual = gdk_screen_get_rgba_visual (gdk_screen_get_default ());//gtk_widget_get_visual (widget);
214 if (!attributes.visual)
215 {
216 attributes.visual = gdk_screen_get_system_visual (gdk_screen_get_default ());
217 }
218 attributes.wclass = GDK_INPUT_OUTPUT;
219
220 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
221
222 window = gdk_window_new (gtk_widget_get_parent_window (widget),
223 &attributes, attributes_mask);
224
225 gtk_widget_set_window (widget, window);
226 gdk_window_set_user_data (window, widget);
227
228 g_signal_connect (window, "pick-embedded-child",
229 G_CALLBACK (pick_offscreen_child), proxy);
230
231 attributes.window_type = GDK_WINDOW_OFFSCREEN;
232 attributes.x = attributes.y = 0;
233
234 if (proxy->priv->child && gtk_widget_get_visible (proxy->priv->child))
235 {
236 gtk_widget_get_allocation (proxy->priv->child, &child_area);
237 attributes.width = child_area.width;
238 attributes.height = child_area.height;
239 }
240
241 proxy->priv->offscreen_window = gdk_window_new (gtk_widget_get_root_window (widget),
242 &attributes, attributes_mask);
243 gdk_window_set_user_data (proxy->priv->offscreen_window, widget);
244
245 if (proxy->priv->child)
246 gtk_widget_set_parent_window (proxy->priv->child, proxy->priv->offscreen_window);
247
248 gdk_offscreen_window_set_embedder (proxy->priv->offscreen_window,
249 window);
250
251 g_signal_connect(proxy->priv->offscreen_window, "create-surface",
252 G_CALLBACK (ido_offscreen_proxy_create_alpha_image_surface),
253 proxy);
254 g_signal_connect (proxy->priv->offscreen_window, "to-embedder",
255 G_CALLBACK (offscreen_to_parent), NULL);
256 g_signal_connect (proxy->priv->offscreen_window, "from-embedder",
257 G_CALLBACK (offscreen_from_parent), NULL);
258
259 context = gtk_widget_get_style_context (widget);
260 gtk_style_context_add_class (context, GTK_STYLE_CLASS_MENUITEM);
261 gtk_style_context_set_background (context, window);
262 gtk_style_context_set_background (context, proxy->priv->offscreen_window);
263 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP | GTK_JUNCTION_BOTTOM | GTK_JUNCTION_LEFT | GTK_JUNCTION_RIGHT);
264
265 gtk_widget_set_name (widget, "IdoOffscreenProxy");
266 gtk_widget_path_iter_set_name (gtk_widget_get_path (widget), -1, "IdoOffscreenProxy");
267
268 gdk_window_show (proxy->priv->offscreen_window);
269}
270
271static void
272ido_offscreen_proxy_unrealize (GtkWidget *widget)
273{
274 IdoOffscreenProxy *proxy = IDO_OFFSCREEN_PROXY (widget);
275
276 gdk_window_set_user_data (proxy->priv->offscreen_window, NULL);
277 gdk_window_destroy (proxy->priv->offscreen_window);
278 proxy->priv->offscreen_window = NULL;
279
280 GTK_WIDGET_CLASS (ido_offscreen_proxy_parent_class)->unrealize (widget);
281}
282
283static GType
284ido_offscreen_proxy_child_type (GtkContainer *container)
285{
286 IdoOffscreenProxy *proxy = IDO_OFFSCREEN_PROXY (container);
287
288 if (proxy->priv->child)
289 return G_TYPE_NONE;
290
291 return GTK_TYPE_WIDGET;
292}
293
294static void
295ido_offscreen_proxy_add (GtkContainer *container,
296 GtkWidget *child)
297{
298 IdoOffscreenProxy *proxy = IDO_OFFSCREEN_PROXY (container);
299
300 if (!proxy->priv->child)
301 {
302 gtk_widget_set_parent_window (child, proxy->priv->offscreen_window);
303 gtk_widget_set_parent (child, GTK_WIDGET (proxy));
304 proxy->priv->child = child;
305 }
306 else
307 {
308 g_warning ("IdoOffscreenProxy can only have a single child\n");
309 }
310}
311
312static void
313ido_offscreen_proxy_remove (GtkContainer *container,
314 GtkWidget *widget)
315{
316 IdoOffscreenProxy *proxy = IDO_OFFSCREEN_PROXY (container);
317 gboolean was_visible;
318
319 was_visible = gtk_widget_get_visible (widget);
320
321 if (proxy->priv->child == widget)
322 {
323 gtk_widget_unparent (widget);
324 proxy->priv->child = NULL;
325
326 if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
327 gtk_widget_queue_resize (GTK_WIDGET (container));
328 }
329}
330
331static void
332ido_offscreen_proxy_forall (GtkContainer *container,
333 gboolean include_internals,
334 GtkCallback callback,
335 gpointer callback_data)
336{
337 IdoOffscreenProxy *proxy = IDO_OFFSCREEN_PROXY (container);
338
339 g_return_if_fail (callback != NULL);
340
341 if (proxy->priv->child)
342 (*callback) (proxy->priv->child, callback_data);
343}
344
345static void
346ido_offscreen_proxy_size_request (GtkWidget *widget,
347 GtkRequisition *requisition)
348{
349 IdoOffscreenProxy *proxy = IDO_OFFSCREEN_PROXY (widget);
350 int w, h;
351
352 w = 0;
353 h = 0;
354
355 if (proxy->priv->child && gtk_widget_get_visible (proxy->priv->child))
356 {
357 GtkRequisition child_requisition;
358
359 gtk_widget_get_preferred_size (proxy->priv->child,
360 &child_requisition, NULL);
361 w = child_requisition.width;
362 h = child_requisition.height;
363 }
364
365 requisition->width = w;
366 requisition->height = h;
367
368}
369
370static void
371ido_offscreen_proxy_get_preferred_width (GtkWidget *widget,
372 gint *minimum,
373 gint *natural)
374{
375 GtkRequisition requisition;
376
377 ido_offscreen_proxy_size_request (widget, &requisition);
378
379 *minimum = *natural = requisition.width;
380}
381
382static void
383ido_offscreen_proxy_get_preferred_height (GtkWidget *widget,
384 gint *minimum,
385 gint *natural)
386{
387 GtkRequisition requisition;
388
389 ido_offscreen_proxy_size_request (widget, &requisition);
390
391 *minimum = *natural = requisition.height;
392
393}
394
395static void
396ido_offscreen_proxy_size_allocate (GtkWidget *widget,
397 GtkAllocation *allocation)
398{
399 IdoOffscreenProxy *proxy;
400
401 proxy = IDO_OFFSCREEN_PROXY (widget);
402
403 gtk_widget_set_allocation (widget, allocation);
404
405 if (gtk_widget_get_realized (widget))
406 {
407 gdk_window_move_resize (gtk_widget_get_window (widget),
408 allocation->x,
409 allocation->y,
410 allocation->width,
411 allocation->height);
412 }
413
414 if (proxy->priv->child && gtk_widget_get_visible (proxy->priv->child))
415 {
416 GtkRequisition child_requisition;
417 GtkAllocation child_allocation;
418
419 gtk_widget_get_preferred_size (proxy->priv->child,
420 &child_requisition, NULL);
421
422 child_allocation.x = child_requisition.width;
423 child_allocation.y = child_requisition.height;
424 child_allocation.width = allocation->width;
425 child_allocation.height = allocation->height;
426
427 if (gtk_widget_get_realized (widget))
428 gdk_window_move_resize (proxy->priv->offscreen_window,
429 child_allocation.x,
430 child_allocation.y,
431 child_allocation.width+4,
432 child_allocation.height);
433
434 child_allocation.x = child_allocation.y = 0;
435 gtk_widget_size_allocate (proxy->priv->child, &child_allocation);
436 }
437}
438
439
440static gboolean
441ido_offscreen_proxy_damage (GtkWidget *widget,
442 GdkEventExpose *event)
443{
444 gdk_window_invalidate_rect (gtk_widget_get_window (widget),
445 NULL, FALSE);
446 return TRUE;
447}
448
449static GtkStyleContext *
450get_menu_style_context ()
451{
452 GtkStyleContext *sc;
453 GtkWidgetPath *path;
454
455 path = gtk_widget_path_new ();
456 gtk_widget_path_append_type (path, GTK_TYPE_MENU);
457
458 sc = gtk_style_context_new();
459
460 proxy_add_css (sc);
461
462 gtk_style_context_set_path (sc, path);
463 gtk_style_context_add_class (sc, GTK_STYLE_CLASS_MENU);
464 gtk_style_context_add_class (sc, "ido-offscreen");
465
466
467
468 gtk_widget_path_free (path);
469
470 return sc;
471}
472
473static gboolean
474ido_offscreen_proxy_draw (GtkWidget *widget,
475 cairo_t *cr)
476{
477 IdoOffscreenProxy *proxy = IDO_OFFSCREEN_PROXY (widget);
478 GdkWindow *window;
479 GtkStyleContext *sc;
480
481 window = gtk_widget_get_window (widget);
482
483 sc = get_menu_style_context();
484
485 gtk_style_context_add_class (sc, "menubar");
486
487 gtk_render_background (sc, cr,
488 0, 0,
489 gdk_window_get_width (window),
490 gdk_window_get_height (window));
491
492 g_object_unref (sc);
493
494 if (gtk_cairo_should_draw_window (cr, window))
495 {
496 cairo_surface_t *surface;
497
498 if (proxy->priv->child && gtk_widget_get_visible (proxy->priv->child))
499 {
500 surface = gdk_offscreen_window_get_surface (proxy->priv->offscreen_window);
501
502 cairo_set_source_surface (cr, surface, 0, 0);
503 cairo_paint (cr);
504 }
505 }
506 else if (gtk_cairo_should_draw_window (cr, proxy->priv->offscreen_window))
507 {
508 if (proxy->priv->child)
509 gtk_container_propagate_draw (GTK_CONTAINER (widget),
510 proxy->priv->child,
511 cr);
512 }
513
514 return TRUE;
515}
5160
=== removed file 'src/idooffscreenproxy.h'
--- src/idooffscreenproxy.h 2011-09-02 18:55:39 +0000
+++ src/idooffscreenproxy.h 1970-01-01 00:00:00 +0000
@@ -1,62 +0,0 @@
1/*
2 * Copyright 2011 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of either or both of the following licenses:
6 *
7 * 1) the GNU Lesser General Public License version 3, as published by the
8 * Free Software Foundation; and/or
9 * 2) the GNU Lesser General Public License version 2.1, as published by
10 * the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranties of
14 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the applicable version of the GNU Lesser General Public
16 * License for more details.
17 *
18 * You should have received a copy of both the GNU Lesser General Public
19 * License version 3 and version 2.1 along with this program. If not, see
20 * <http://www.gnu.org/licenses/>
21 *
22 * Authors:
23 * Robert Carr <racarr@canonical.com>
24 */
25
26#ifndef __IDO_OFFSCREEN_PROXY_H__
27#define __IDO_OFFSCREEN_PROXy_H__
28
29#include <gdk/gdk.h>
30#include <gtk/gtk.h>
31
32G_BEGIN_DECLS
33
34#define IDO_TYPE_OFFSCREEN_PROXY (ido_offscreen_proxy_get_type ())
35#define IDO_OFFSCREEN_PROXY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IDO_TYPE_OFFSCREEN_PROXY, IdoOffscreenProxy))
36#define IDO_OFFSCREEN_PROXY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), IDO_TYPE_OFFSCREEN_PROXY, IdoOffscreenProxyClass))
37#define IDO_IS_OFFSCREEN_PROXY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IDO_TYPE_OFFSCREEN_PROXY))
38#define IDO_IS_OFFSCREEN_PROXY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), IDO_TYPE_OFFSCREEN_PROXY))
39#define IDO_OFFSCREEN_PROXY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), IDO_TYPE_OFFSCREEN_PROXY, IdoOffscreenProxyClass))
40
41typedef struct _IdoOffscreenProxy IdoOffscreenProxy;
42typedef struct _IdoOffscreenProxyClass IdoOffscreenProxyClass;
43typedef struct _IdoOffscreenProxyPrivate IdoOffscreenProxyPrivate;
44
45struct _IdoOffscreenProxyClass
46{
47 GtkBinClass parent_class;
48};
49
50struct _IdoOffscreenProxy
51{
52 GtkContainer container;
53
54 IdoOffscreenProxyPrivate *priv;
55};
56
57GType ido_offscreen_proxy_get_type (void) G_GNUC_CONST;
58GtkWidget *ido_offscreen_proxy_new (void);
59
60G_END_DECLS
61
62#endif
630
=== modified file 'src/idoscalemenuitem.c'
--- src/idoscalemenuitem.c 2011-12-14 17:19:26 +0000
+++ src/idoscalemenuitem.c 2012-03-12 16:37:21 +0000
@@ -31,10 +31,6 @@
31#include "idoscalemenuitem.h"31#include "idoscalemenuitem.h"
32#include "idotypebuiltins.h"32#include "idotypebuiltins.h"
3333
34#ifdef USE_GTK3
35#include "idooffscreenproxy.h"
36#endif
37
38static void ido_scale_menu_item_set_property (GObject *object,34static void ido_scale_menu_item_set_property (GObject *object,
39 guint prop_id,35 guint prop_id,
40 const GValue *value,36 const GValue *value,
@@ -59,16 +55,12 @@
59 GParamSpec *pspec,55 GParamSpec *pspec,
60 gpointer user_data);56 gpointer user_data);
61static void update_packing (IdoScaleMenuItem *self,57static void update_packing (IdoScaleMenuItem *self,
62 IdoScaleMenuItemStyle style,58 IdoScaleMenuItemStyle style);
63 IdoScaleMenuItemStyle old_style);59static void default_primary_clicked_handler (IdoScaleMenuItem *self);
60static void default_secondary_clicked_handler (IdoScaleMenuItem *self);
6461
65struct _IdoScaleMenuItemPrivate {62struct _IdoScaleMenuItemPrivate {
66 GtkWidget *scale;63 GtkWidget *scale;
67
68#ifdef USE_GTK3
69 GtkWidget *proxy;
70#endif
71
72 GtkAdjustment *adjustment;64 GtkAdjustment *adjustment;
73 GtkWidget *primary_image;65 GtkWidget *primary_image;
74 GtkWidget *secondary_image;66 GtkWidget *secondary_image;
@@ -88,6 +80,8 @@
88enum {80enum {
89 SLIDER_GRABBED,81 SLIDER_GRABBED,
90 SLIDER_RELEASED,82 SLIDER_RELEASED,
83 PRIMARY_CLICKED,
84 SECONDARY_CLICKED,
91 LAST_SIGNAL85 LAST_SIGNAL
92};86};
9387
@@ -105,13 +99,6 @@
10599
106#define GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), IDO_TYPE_SCALE_MENU_ITEM, IdoScaleMenuItemPrivate))100#define GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), IDO_TYPE_SCALE_MENU_ITEM, IdoScaleMenuItemPrivate))
107101
108static void
109ido_scale_menu_item_state_changed (GtkWidget *widget,
110 GtkStateType previous_state)
111{
112 gtk_widget_set_state (widget, GTK_STATE_NORMAL);
113}
114
115static gboolean102static gboolean
116ido_scale_menu_item_scroll_event (GtkWidget *menuitem,103ido_scale_menu_item_scroll_event (GtkWidget *menuitem,
117 GdkEventScroll *event)104 GdkEventScroll *event)
@@ -250,14 +237,6 @@
250 gtk_scale_set_draw_value (GTK_SCALE (priv->scale), FALSE);237 gtk_scale_set_draw_value (GTK_SCALE (priv->scale), FALSE);
251 238
252#ifdef USE_GTK3239#ifdef USE_GTK3
253 gtk_widget_set_can_focus (priv->scale, FALSE);
254
255 priv->proxy = ido_offscreen_proxy_new ();
256 g_object_ref (priv->proxy);
257 gtk_container_add (GTK_CONTAINER (priv->proxy), priv->scale);
258#endif
259
260#ifdef USE_GTK3
261 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);240 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
262#else241#else
263 hbox = gtk_hbox_new (FALSE, 0);242 hbox = gtk_hbox_new (FALSE, 0);
@@ -278,7 +257,7 @@
278257
279 priv->hbox = hbox;258 priv->hbox = hbox;
280259
281 update_packing (self, priv->style, priv->style);260 update_packing (self, priv->style);
282261
283 g_signal_connect (self, "toggle-size-allocate",262 g_signal_connect (self, "toggle-size-allocate",
284 G_CALLBACK (ido_scale_menu_item_toggle_size_allocate),263 G_CALLBACK (ido_scale_menu_item_toggle_size_allocate),
@@ -297,11 +276,13 @@
297 GObjectClass *gobject_class = G_OBJECT_CLASS (item_class);276 GObjectClass *gobject_class = G_OBJECT_CLASS (item_class);
298 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (item_class);277 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (item_class);
299278
279 item_class->primary_clicked = default_primary_clicked_handler;
280 item_class->secondary_clicked = default_secondary_clicked_handler;
281
300 widget_class->button_press_event = ido_scale_menu_item_button_press_event;282 widget_class->button_press_event = ido_scale_menu_item_button_press_event;
301 widget_class->button_release_event = ido_scale_menu_item_button_release_event;283 widget_class->button_release_event = ido_scale_menu_item_button_release_event;
302 widget_class->motion_notify_event = ido_scale_menu_item_motion_notify_event;284 widget_class->motion_notify_event = ido_scale_menu_item_motion_notify_event;
303 widget_class->scroll_event = ido_scale_menu_item_scroll_event;285 widget_class->scroll_event = ido_scale_menu_item_scroll_event;
304 widget_class->state_changed = ido_scale_menu_item_state_changed;
305 widget_class->size_allocate = ido_scale_menu_item_size_allocate;286 widget_class->size_allocate = ido_scale_menu_item_size_allocate;
306287
307 gobject_class->constructed = ido_scale_menu_item_constructed;288 gobject_class->constructed = ido_scale_menu_item_constructed;
@@ -358,95 +339,58 @@
358 g_cclosure_marshal_VOID__VOID,339 g_cclosure_marshal_VOID__VOID,
359 G_TYPE_NONE, 0);340 G_TYPE_NONE, 0);
360341
342 signals[PRIMARY_CLICKED] = g_signal_new ("primary-clicked",
343 G_TYPE_FROM_CLASS (item_class),
344 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
345 G_STRUCT_OFFSET (IdoScaleMenuItemClass, primary_clicked),
346 NULL, NULL,
347 g_cclosure_marshal_VOID__VOID,
348 G_TYPE_NONE, /* return type */
349 0 /* n_params */);
350
351 signals[SECONDARY_CLICKED] = g_signal_new ("secondary-clicked",
352 G_TYPE_FROM_CLASS (item_class),
353 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
354 G_STRUCT_OFFSET (IdoScaleMenuItemClass, secondary_clicked),
355 NULL, NULL,
356 g_cclosure_marshal_VOID__VOID,
357 G_TYPE_NONE, /* return type */
358 0 /* n_params */);
359
361 g_type_class_add_private (item_class, sizeof (IdoScaleMenuItemPrivate));360 g_type_class_add_private (item_class, sizeof (IdoScaleMenuItemPrivate));
362}361}
363362
364static void363static void
365update_packing (IdoScaleMenuItem *self, IdoScaleMenuItemStyle style, IdoScaleMenuItemStyle old_style)364update_packing (IdoScaleMenuItem *self, IdoScaleMenuItemStyle style)
366{365{
367 IdoScaleMenuItemPrivate *priv = GET_PRIVATE (self);366 IdoScaleMenuItemPrivate *priv = GET_PRIVATE (self);
367 GtkBox * box = GTK_BOX (priv->hbox);
368 GtkContainer *container = GTK_CONTAINER (priv->hbox);368 GtkContainer *container = GTK_CONTAINER (priv->hbox);
369369
370 if (style != old_style)370 /* remove the old layout */
371 {371 GList * children = gtk_container_get_children (container);
372 switch (old_style)372 GList * l;
373 {373 for (l=children; l!=NULL; l=l->next)
374 case IDO_SCALE_MENU_ITEM_STYLE_NONE:374 gtk_container_remove (container, l->data);
375#ifdef USE_GTK3375 g_list_free (children);
376 gtk_container_remove (container, priv->proxy);376
377#else 377 /* add the new layout */
378 gtk_container_remove (container, priv->scale);
379#endif
380 break;
381
382 case IDO_SCALE_MENU_ITEM_STYLE_IMAGE:
383 gtk_container_remove (container, priv->primary_image);
384 gtk_container_remove (container, priv->secondary_image);
385#ifdef USE_GTK3
386 gtk_container_remove (container, priv->proxy);
387#else
388 gtk_container_remove (container, priv->scale);
389#endif
390 break;
391
392 case IDO_SCALE_MENU_ITEM_STYLE_LABEL:
393 gtk_container_remove (container, priv->primary_label);
394 gtk_container_remove (container, priv->secondary_label);
395#ifdef USE_GTK3
396 gtk_container_remove (container, priv->proxy);
397#else
398 gtk_container_remove (container, priv->scale);
399#endif
400 break;
401
402 default:
403#ifdef USE_GTK3
404 gtk_container_remove (container, priv->proxy);
405#else
406 gtk_container_remove (container, priv->scale);
407#endif
408 break;
409 }
410 }
411
412 switch (style)378 switch (style)
413 {379 {
414 case IDO_SCALE_MENU_ITEM_STYLE_NONE:
415#ifdef USE_GTK3
416 gtk_box_pack_start (GTK_BOX (priv->hbox), priv->proxy, FALSE, FALSE, 0);
417#else
418 gtk_box_pack_start (GTK_BOX (priv->hbox), priv->scale, FALSE, FALSE, 0);
419#endif
420 break;
421
422 case IDO_SCALE_MENU_ITEM_STYLE_IMAGE:380 case IDO_SCALE_MENU_ITEM_STYLE_IMAGE:
423 gtk_box_pack_start (GTK_BOX (priv->hbox), priv->primary_image, FALSE, FALSE, 0);381 gtk_box_pack_start (box, priv->primary_image, FALSE, FALSE, 0);
424382 gtk_box_pack_start (box, priv->scale, FALSE, FALSE, 0);
425#ifdef USE_GTK3383 gtk_box_pack_start (box, priv->secondary_image, FALSE, FALSE, 0);
426 gtk_box_pack_start (GTK_BOX (priv->hbox), priv->proxy, FALSE, FALSE, 0);
427#else
428 gtk_box_pack_start (GTK_BOX (priv->hbox), priv->scale, FALSE, FALSE, 0);
429#endif
430
431 gtk_box_pack_start (GTK_BOX (priv->hbox), priv->secondary_image, FALSE, FALSE, 0);
432 break;384 break;
433385
434 case IDO_SCALE_MENU_ITEM_STYLE_LABEL:386 case IDO_SCALE_MENU_ITEM_STYLE_LABEL:
435 gtk_box_pack_start (GTK_BOX (priv->hbox), priv->primary_label, FALSE, FALSE, 0);387 gtk_box_pack_start (box, priv->primary_label, FALSE, FALSE, 0);
436#ifdef USE_GTK3388 gtk_box_pack_start (box, priv->scale, FALSE, FALSE, 0);
437 gtk_box_pack_start (GTK_BOX (priv->hbox), priv->proxy, FALSE, FALSE, 0);389 gtk_box_pack_start (box, priv->secondary_label, FALSE, FALSE, 0);
438#else
439 gtk_box_pack_start (GTK_BOX (priv->hbox), priv->scale, FALSE, FALSE, 0);
440#endif
441 gtk_box_pack_start (GTK_BOX (priv->hbox), priv->secondary_label, FALSE, FALSE, 0);
442 break;390 break;
443391
444 default:392 default:
445#ifdef USE_GTK3393 gtk_box_pack_start (box, priv->scale, FALSE, FALSE, 0);
446 gtk_box_pack_start (GTK_BOX (priv->hbox), priv->proxy, FALSE, FALSE, 0);
447#else
448 gtk_box_pack_start (GTK_BOX (priv->hbox), priv->scale, FALSE, FALSE, 0);
449#endif
450 break;394 break;
451 }395 }
452396
@@ -579,64 +523,50 @@
579ido_scale_menu_item_button_release_event (GtkWidget *menuitem,523ido_scale_menu_item_button_release_event (GtkWidget *menuitem,
580 GdkEventButton *event)524 GdkEventButton *event)
581{525{
526 IdoScaleMenuItem *item = IDO_SCALE_MENU_ITEM (menuitem);
582 IdoScaleMenuItemPrivate *priv = GET_PRIVATE (menuitem);527 IdoScaleMenuItemPrivate *priv = GET_PRIVATE (menuitem);
583 GtkWidget *scale = priv->scale;528 GtkWidget *scale = priv->scale;
584 gdouble x;529 gdouble x;
585530
531 /* if user clicked to the left of the scale... */
586 if (event->x > priv->child_allocation.x &&532 if (event->x > priv->child_allocation.x &&
587 event->x < priv->child_allocation.x + priv->left_padding)533 event->x < priv->child_allocation.x + priv->left_padding)
588 {534 {
589 GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (priv->scale));
590
591 if (gtk_widget_get_direction (menuitem) == GTK_TEXT_DIR_LTR)535 if (gtk_widget_get_direction (menuitem) == GTK_TEXT_DIR_LTR)
592 {536 {
593 gtk_adjustment_set_value (adj, gtk_adjustment_get_lower (adj));537 ido_scale_menu_item_primary_clicked (item);
594 }538 }
595 else539 else
596 {540 {
597 gtk_adjustment_set_value (adj, gtk_adjustment_get_upper (adj));541 ido_scale_menu_item_secondary_clicked (item);
598 }542 }
599
600 if (priv->grabbed)
601 {
602 priv->grabbed = FALSE;
603 g_signal_emit (menuitem, signals[SLIDER_RELEASED], 0);
604 }
605
606 return TRUE;
607 }543 }
608544
609 if (event->x < priv->child_allocation.x + priv->child_allocation.width + priv->right_padding + priv->left_padding &&545 /* if user clicked to the right of the scale... */
546 else if (event->x < priv->child_allocation.x + priv->child_allocation.width + priv->right_padding + priv->left_padding &&
610 event->x > priv->child_allocation.x + priv->child_allocation.width + priv->left_padding)547 event->x > priv->child_allocation.x + priv->child_allocation.width + priv->left_padding)
611 {548 {
612 GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (priv->scale));
613
614 if (gtk_widget_get_direction (menuitem) == GTK_TEXT_DIR_LTR)549 if (gtk_widget_get_direction (menuitem) == GTK_TEXT_DIR_LTR)
615 {550 {
616 gtk_adjustment_set_value (adj, gtk_adjustment_get_upper (adj));551 ido_scale_menu_item_secondary_clicked (item);
617 }552 }
618 else553 else
619 {554 {
620 gtk_adjustment_set_value (adj, gtk_adjustment_get_lower (adj));555 ido_scale_menu_item_primary_clicked (item);
621 }556 }
622557 }
623 if (priv->grabbed)558
624 {559 /* user clicked on the scale... */
625 priv->grabbed = FALSE;560 else
626 g_signal_emit (menuitem, signals[SLIDER_RELEASED], 0);561 {
627 }562 translate_event_coordinates (menuitem, event->x, &x);
628563 event->x = x;
629 return TRUE;564
630 }565 translate_event_coordinates (menuitem, event->x_root, &x);
631566 event->x_root= x;
632 translate_event_coordinates (menuitem, event->x, &x);567
633 event->x = x;568 gtk_widget_event (scale, (GdkEvent*)event);
634569 }
635 translate_event_coordinates (menuitem, event->x_root, &x);
636 event->x_root= x;
637
638 gtk_widget_event (scale,
639 ((GdkEvent *)(void*)(event)));
640570
641 if (priv->grabbed)571 if (priv->grabbed)
642 {572 {
@@ -812,16 +742,14 @@
812 IdoScaleMenuItemStyle style)742 IdoScaleMenuItemStyle style)
813{743{
814 IdoScaleMenuItemPrivate *priv;744 IdoScaleMenuItemPrivate *priv;
815 IdoScaleMenuItemStyle old_style;
816745
817 g_return_if_fail (IDO_IS_SCALE_MENU_ITEM (menuitem));746 g_return_if_fail (IDO_IS_SCALE_MENU_ITEM (menuitem));
818747
819 priv = GET_PRIVATE (menuitem);748 priv = GET_PRIVATE (menuitem);
820749
821 old_style = priv->style;
822 priv->style = style;750 priv->style = style;
823751
824 update_packing (menuitem, style, old_style);752 update_packing (menuitem, style);
825}753}
826754
827/**755/**
@@ -958,5 +886,50 @@
958 }886 }
959}887}
960888
889/**
890 * ido_scale_menu_item_primary_clicked:
891 * @menuitem: the #IdoScaleMenuItem
892 *
893 * Emits the "primary-clicked" signal.
894 *
895 * The default handler for this signal lowers the scale's
896 * adjustment to its lower bound.
897 */
898void
899ido_scale_menu_item_primary_clicked (IdoScaleMenuItem * item)
900{
901 g_signal_emit (item, signals[PRIMARY_CLICKED], 0);
902}
903static void
904default_primary_clicked_handler (IdoScaleMenuItem * item)
905{
906 g_debug ("%s: setting scale to lower bound", G_STRFUNC);
907 IdoScaleMenuItemPrivate * priv = GET_PRIVATE (item);
908 GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (priv->scale));
909 gtk_adjustment_set_value (adj, gtk_adjustment_get_lower (adj));
910}
911
912/**
913 * ido_scale_menu_item_primary_clicked:
914 * @menuitem: the #IdoScaleMenuItem
915 *
916 * Emits the "primary-clicked" signal.
917 *
918 * The default handler for this signal raises the scale's
919 * adjustment to its upper bound.
920 */
921void
922ido_scale_menu_item_secondary_clicked (IdoScaleMenuItem * item)
923{
924 g_signal_emit (item, signals[SECONDARY_CLICKED], 0);
925}
926static void
927default_secondary_clicked_handler (IdoScaleMenuItem * item)
928{
929 g_debug ("%s: setting scale to upper bound", G_STRFUNC);
930 IdoScaleMenuItemPrivate * priv = GET_PRIVATE (item);
931 GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (priv->scale));
932 gtk_adjustment_set_value (adj, gtk_adjustment_get_upper (adj));
933}
961934
962#define __IDO_SCALE_MENU_ITEM_C__935#define __IDO_SCALE_MENU_ITEM_C__
963936
=== modified file 'src/idoscalemenuitem.h'
--- src/idoscalemenuitem.h 2011-06-20 13:34:43 +0000
+++ src/idoscalemenuitem.h 2012-03-12 16:37:21 +0000
@@ -59,6 +59,10 @@
59struct _IdoScaleMenuItemClass59struct _IdoScaleMenuItemClass
60{60{
61 GtkMenuItemClass parent_class;61 GtkMenuItemClass parent_class;
62
63 /* signal default handlers */
64 void (*primary_clicked)(IdoScaleMenuItem * self);
65 void (*secondary_clicked)(IdoScaleMenuItem * self);
62};66};
6367
6468
@@ -79,12 +83,14 @@
79 IdoScaleMenuItemStyle style);83 IdoScaleMenuItemStyle style);
80GtkWidget *ido_scale_menu_item_get_primary_image (IdoScaleMenuItem *menuitem);84GtkWidget *ido_scale_menu_item_get_primary_image (IdoScaleMenuItem *menuitem);
81GtkWidget *ido_scale_menu_item_get_secondary_image (IdoScaleMenuItem *menuitem);85GtkWidget *ido_scale_menu_item_get_secondary_image (IdoScaleMenuItem *menuitem);
82const gchar *ido_scale_menu_item_get_primary_label (IdoScaleMenuItem *menuitem);86const gchar *ido_scale_menu_item_get_primary_label (IdoScaleMenuItem *menuitem);
83const gchar *ido_scale_menu_item_get_secondary_label (IdoScaleMenuItem *menuitem);
84void ido_scale_menu_item_set_primary_label (IdoScaleMenuItem *menuitem,87void ido_scale_menu_item_set_primary_label (IdoScaleMenuItem *menuitem,
85 const gchar *label);88 const gchar *label);
89const gchar *ido_scale_menu_item_get_secondary_label (IdoScaleMenuItem *menuitem);
86void ido_scale_menu_item_set_secondary_label (IdoScaleMenuItem *menuitem,90void ido_scale_menu_item_set_secondary_label (IdoScaleMenuItem *menuitem,
87 const gchar *label);91 const gchar *label);
92void ido_scale_menu_item_primary_clicked (IdoScaleMenuItem *menuitem);
93void ido_scale_menu_item_secondary_clicked (IdoScaleMenuItem *menuitem);
8894
89G_END_DECLS95G_END_DECLS
9096

Subscribers

People subscribed via source and target branches