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
1=== modified file 'src/Makefile.am'
2--- src/Makefile.am 2011-09-13 16:21:24 +0000
3+++ src/Makefile.am 2012-03-12 16:37:21 +0000
4@@ -28,13 +28,6 @@
5 idotypebuiltins.c.template
6
7
8-if USE_GTK3
9-sources_h += idooffscreenproxy.h
10-else
11-EXTRA_DIST += idooffscreenproxy.h \
12- idooffscreenproxy.c
13-endif
14-
15 idotypebuiltins.h: stamp-idotypebuiltins.h
16
17 stamp-idotypebuiltins.h: $(sources_h)
18@@ -73,10 +66,6 @@
19 idoscalemenuitem.c \
20 idotimeline.c
21
22-if USE_GTK3
23-libido_0_1_la_SOURCES += idooffscreenproxy.c
24-endif
25-
26 libido3_0_1_la_SOURCES = $(libido_0_1_la_SOURCES)
27
28 libidoincludedir=$(includedir)/libido$(VER)-0.1/libido
29@@ -90,10 +79,6 @@
30 idotimeline.h \
31 libido.h
32
33-if USE_GTK3
34-libidoinclude_HEADERS += idooffscreenproxy.h
35-endif
36-
37 libido_0_1_la_LIBADD = $(GTK_LIBS)
38 libido_0_1_la_LDFLAGS = $(GTK_LT_LDFLAGS)
39 libido3_0_1_la_LIBADD = $(libido_0_1_la_LIBADD)
40
41=== removed file 'src/idooffscreenproxy.c'
42--- src/idooffscreenproxy.c 2012-02-09 04:18:09 +0000
43+++ src/idooffscreenproxy.c 1970-01-01 00:00:00 +0000
44@@ -1,515 +0,0 @@
45-/*
46- * Copyright 2011 Canonical, Ltd.
47- *
48- * This program is free software: you can redistribute it and/or modify it
49- * under the terms of either or both of the following licenses:
50- *
51- * 1) the GNU Lesser General Public License version 3, as published by the
52- * Free Software Foundation; and/or
53- * 2) the GNU Lesser General Public License version 2.1, as published by
54- * the Free Software Foundation.
55- *
56- * This program is distributed in the hope that it will be useful, but
57- * WITHOUT ANY WARRANTY; without even the implied warranties of
58- * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
59- * PURPOSE. See the applicable version of the GNU Lesser General Public
60- * License for more details.
61- *
62- * You should have received a copy of both the GNU Lesser General Public
63- * License version 3 and version 2.1 along with this program. If not, see
64- * <http://www.gnu.org/licenses/>
65- *
66- * Authors:
67- * Robert Carr <racarr@canonical.com>
68- */
69-
70-#include <gtk/gtk.h>
71-#include "idooffscreenproxy.h"
72-
73-struct _IdoOffscreenProxyPrivate
74-{
75- GtkWidget *child;
76-
77- GdkWindow *offscreen_window;
78-};
79-
80-static void ido_offscreen_proxy_realize (GtkWidget *widget);
81-static void ido_offscreen_proxy_unrealize (GtkWidget *widget);
82-static void ido_offscreen_proxy_get_preferred_width (GtkWidget *widget,
83- gint *minimum,
84- gint *natural);
85-static void ido_offscreen_proxy_get_preferred_height (GtkWidget *widget,
86- gint *minimum,
87- gint *natural);
88-
89-static void ido_offscreen_proxy_size_allocate (GtkWidget *widget,
90- GtkAllocation *allocation);
91-static gboolean ido_offscreen_proxy_damage (GtkWidget *widget,
92- GdkEventExpose *event);
93-static gboolean ido_offscreen_proxy_draw (GtkWidget *widget,
94- cairo_t *cr);
95-static void ido_offscreen_proxy_add (GtkContainer *container,
96- GtkWidget *child);
97-static void ido_offscreen_proxy_remove (GtkContainer *container,
98- GtkWidget *widget);
99-static void ido_offscreen_proxy_forall (GtkContainer *container,
100- gboolean include_internals,
101- GtkCallback callback,
102- gpointer callback_data);
103-static GType ido_offscreen_proxy_child_type (GtkContainer *container);
104-
105-static cairo_surface_t * ido_offscreen_proxy_create_alpha_image_surface (GdkWindow *offscreen, gint width, gint height);
106-
107-
108-
109-G_DEFINE_TYPE (IdoOffscreenProxy, ido_offscreen_proxy, GTK_TYPE_CONTAINER);
110-
111-#define IDO_OFFSCREEN_PROXY_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), IDO_TYPE_OFFSCREEN_PROXY, IdoOffscreenProxyPrivate))
112-
113-static void
114-ido_offscreen_proxy_class_init (IdoOffscreenProxyClass *klass)
115-{
116- GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
117- GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
118-
119- g_type_class_add_private (klass, sizeof (IdoOffscreenProxyPrivate));
120-
121- widget_class->realize = ido_offscreen_proxy_realize;
122- widget_class->unrealize = ido_offscreen_proxy_unrealize;
123- widget_class->get_preferred_width = ido_offscreen_proxy_get_preferred_width;
124- widget_class->get_preferred_height = ido_offscreen_proxy_get_preferred_height;
125- widget_class->size_allocate = ido_offscreen_proxy_size_allocate;
126- widget_class->draw = ido_offscreen_proxy_draw;
127-
128- g_signal_override_class_closure (g_signal_lookup ("damage-event", GTK_TYPE_WIDGET),
129- IDO_TYPE_OFFSCREEN_PROXY,
130- g_cclosure_new (G_CALLBACK (ido_offscreen_proxy_damage),
131- NULL, NULL));
132-
133- container_class->add = ido_offscreen_proxy_add;
134- container_class->remove = ido_offscreen_proxy_remove;
135- container_class->forall = ido_offscreen_proxy_forall;
136- container_class->child_type = ido_offscreen_proxy_child_type;
137-
138-}
139-
140-static void
141-ido_offscreen_proxy_init (IdoOffscreenProxy *proxy)
142-{
143- proxy->priv = IDO_OFFSCREEN_PROXY_GET_PRIVATE (proxy);
144-
145- gtk_widget_set_has_window (GTK_WIDGET (proxy), TRUE);
146-
147- gtk_widget_set_events (GTK_WIDGET(proxy), gtk_widget_get_events (GTK_WIDGET(proxy))
148- | GDK_EXPOSURE_MASK
149- | GDK_POINTER_MOTION_MASK
150- | GDK_BUTTON_PRESS_MASK
151- | GDK_BUTTON_RELEASE_MASK
152- | GDK_SCROLL_MASK
153- | GDK_ENTER_NOTIFY_MASK
154- | GDK_LEAVE_NOTIFY_MASK);
155-
156- gtk_container_set_border_width (GTK_CONTAINER (proxy), 0);
157-}
158-
159-GtkWidget *
160-ido_offscreen_proxy_new (void)
161-{
162- return g_object_new (IDO_TYPE_OFFSCREEN_PROXY, NULL);
163-}
164-
165-static GdkWindow *
166-pick_offscreen_child (GdkWindow *offscreen_window,
167- double widget_x, double widget_y,
168- IdoOffscreenProxy *proxy)
169-{
170- GtkAllocation child_area;
171-
172- if (proxy->priv->child && gtk_widget_get_visible (proxy->priv->child))
173- {
174- gtk_widget_get_allocation (proxy->priv->child, &child_area);
175-
176- // if (widget_x >= 0 && widget_x < child_area.width &&
177- // widget_y >= 0 && widget_y < child_area.height)
178- //return proxy->priv->offscreen_window;
179- return proxy->priv->offscreen_window;
180- }
181-
182- return NULL;
183-}
184-
185-static void
186-offscreen_to_parent (GdkWindow *offscreen_window,
187- double offscreen_x,
188- double offscreen_y,
189- double *parent_x,
190- double *parent_y,
191- gpointer user_data)
192-{
193- *parent_x = offscreen_x;
194- *parent_y = offscreen_y;
195-}
196-
197-static void
198-offscreen_from_parent (GdkWindow *window,
199- double parent_x,
200- double parent_y,
201- double *offscreen_x,
202- double *offscreen_y,
203- gpointer user_data)
204-{
205- *offscreen_x = parent_x;
206- *offscreen_y = parent_y;
207-}
208-
209-static cairo_surface_t *
210-ido_offscreen_proxy_create_alpha_image_surface (GdkWindow *offscreen, gint width, gint height)
211-{
212- return cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
213-}
214-
215-static void
216-proxy_add_css (GtkStyleContext *sc)
217-{
218- GtkCssProvider *provider = gtk_css_provider_new();
219- const gchar *proxy_css = ".menu.ido-offscreen { \nborder-width: 0;\nborder-radius:0; \n}\n";
220-
221- gtk_css_provider_load_from_data (provider, proxy_css, -1, NULL);
222-
223- gtk_style_context_add_provider (sc, GTK_STYLE_PROVIDER (provider),
224- GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
225-
226-}
227-
228-static void
229-ido_offscreen_proxy_realize (GtkWidget *widget)
230-{
231- IdoOffscreenProxy *proxy = IDO_OFFSCREEN_PROXY (widget);
232- GtkAllocation allocation, child_area;
233- GtkStyleContext *context;
234- GdkWindow *window;
235- GdkWindowAttr attributes;
236- gint attributes_mask;
237- // GtkRequisition child_requisition;
238-
239- gtk_widget_set_realized (widget, TRUE);
240-
241- gtk_widget_get_allocation (widget, &allocation);
242-
243- attributes.x = allocation.x;
244- attributes.y = allocation.y;
245- attributes.width = allocation.width;
246- attributes.height = allocation.height;
247-
248- attributes.window_type = GDK_WINDOW_CHILD;
249- attributes.event_mask = gtk_widget_get_events (widget)
250- | GDK_EXPOSURE_MASK
251- | GDK_POINTER_MOTION_MASK
252- | GDK_BUTTON_PRESS_MASK
253- | GDK_BUTTON_RELEASE_MASK
254- | GDK_SCROLL_MASK
255- | GDK_ENTER_NOTIFY_MASK
256- | GDK_LEAVE_NOTIFY_MASK;
257- attributes.visual = gdk_screen_get_rgba_visual (gdk_screen_get_default ());//gtk_widget_get_visual (widget);
258- if (!attributes.visual)
259- {
260- attributes.visual = gdk_screen_get_system_visual (gdk_screen_get_default ());
261- }
262- attributes.wclass = GDK_INPUT_OUTPUT;
263-
264- attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
265-
266- window = gdk_window_new (gtk_widget_get_parent_window (widget),
267- &attributes, attributes_mask);
268-
269- gtk_widget_set_window (widget, window);
270- gdk_window_set_user_data (window, widget);
271-
272- g_signal_connect (window, "pick-embedded-child",
273- G_CALLBACK (pick_offscreen_child), proxy);
274-
275- attributes.window_type = GDK_WINDOW_OFFSCREEN;
276- attributes.x = attributes.y = 0;
277-
278- if (proxy->priv->child && gtk_widget_get_visible (proxy->priv->child))
279- {
280- gtk_widget_get_allocation (proxy->priv->child, &child_area);
281- attributes.width = child_area.width;
282- attributes.height = child_area.height;
283- }
284-
285- proxy->priv->offscreen_window = gdk_window_new (gtk_widget_get_root_window (widget),
286- &attributes, attributes_mask);
287- gdk_window_set_user_data (proxy->priv->offscreen_window, widget);
288-
289- if (proxy->priv->child)
290- gtk_widget_set_parent_window (proxy->priv->child, proxy->priv->offscreen_window);
291-
292- gdk_offscreen_window_set_embedder (proxy->priv->offscreen_window,
293- window);
294-
295- g_signal_connect(proxy->priv->offscreen_window, "create-surface",
296- G_CALLBACK (ido_offscreen_proxy_create_alpha_image_surface),
297- proxy);
298- g_signal_connect (proxy->priv->offscreen_window, "to-embedder",
299- G_CALLBACK (offscreen_to_parent), NULL);
300- g_signal_connect (proxy->priv->offscreen_window, "from-embedder",
301- G_CALLBACK (offscreen_from_parent), NULL);
302-
303- context = gtk_widget_get_style_context (widget);
304- gtk_style_context_add_class (context, GTK_STYLE_CLASS_MENUITEM);
305- gtk_style_context_set_background (context, window);
306- gtk_style_context_set_background (context, proxy->priv->offscreen_window);
307- gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP | GTK_JUNCTION_BOTTOM | GTK_JUNCTION_LEFT | GTK_JUNCTION_RIGHT);
308-
309- gtk_widget_set_name (widget, "IdoOffscreenProxy");
310- gtk_widget_path_iter_set_name (gtk_widget_get_path (widget), -1, "IdoOffscreenProxy");
311-
312- gdk_window_show (proxy->priv->offscreen_window);
313-}
314-
315-static void
316-ido_offscreen_proxy_unrealize (GtkWidget *widget)
317-{
318- IdoOffscreenProxy *proxy = IDO_OFFSCREEN_PROXY (widget);
319-
320- gdk_window_set_user_data (proxy->priv->offscreen_window, NULL);
321- gdk_window_destroy (proxy->priv->offscreen_window);
322- proxy->priv->offscreen_window = NULL;
323-
324- GTK_WIDGET_CLASS (ido_offscreen_proxy_parent_class)->unrealize (widget);
325-}
326-
327-static GType
328-ido_offscreen_proxy_child_type (GtkContainer *container)
329-{
330- IdoOffscreenProxy *proxy = IDO_OFFSCREEN_PROXY (container);
331-
332- if (proxy->priv->child)
333- return G_TYPE_NONE;
334-
335- return GTK_TYPE_WIDGET;
336-}
337-
338-static void
339-ido_offscreen_proxy_add (GtkContainer *container,
340- GtkWidget *child)
341-{
342- IdoOffscreenProxy *proxy = IDO_OFFSCREEN_PROXY (container);
343-
344- if (!proxy->priv->child)
345- {
346- gtk_widget_set_parent_window (child, proxy->priv->offscreen_window);
347- gtk_widget_set_parent (child, GTK_WIDGET (proxy));
348- proxy->priv->child = child;
349- }
350- else
351- {
352- g_warning ("IdoOffscreenProxy can only have a single child\n");
353- }
354-}
355-
356-static void
357-ido_offscreen_proxy_remove (GtkContainer *container,
358- GtkWidget *widget)
359-{
360- IdoOffscreenProxy *proxy = IDO_OFFSCREEN_PROXY (container);
361- gboolean was_visible;
362-
363- was_visible = gtk_widget_get_visible (widget);
364-
365- if (proxy->priv->child == widget)
366- {
367- gtk_widget_unparent (widget);
368- proxy->priv->child = NULL;
369-
370- if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
371- gtk_widget_queue_resize (GTK_WIDGET (container));
372- }
373-}
374-
375-static void
376-ido_offscreen_proxy_forall (GtkContainer *container,
377- gboolean include_internals,
378- GtkCallback callback,
379- gpointer callback_data)
380-{
381- IdoOffscreenProxy *proxy = IDO_OFFSCREEN_PROXY (container);
382-
383- g_return_if_fail (callback != NULL);
384-
385- if (proxy->priv->child)
386- (*callback) (proxy->priv->child, callback_data);
387-}
388-
389-static void
390-ido_offscreen_proxy_size_request (GtkWidget *widget,
391- GtkRequisition *requisition)
392-{
393- IdoOffscreenProxy *proxy = IDO_OFFSCREEN_PROXY (widget);
394- int w, h;
395-
396- w = 0;
397- h = 0;
398-
399- if (proxy->priv->child && gtk_widget_get_visible (proxy->priv->child))
400- {
401- GtkRequisition child_requisition;
402-
403- gtk_widget_get_preferred_size (proxy->priv->child,
404- &child_requisition, NULL);
405- w = child_requisition.width;
406- h = child_requisition.height;
407- }
408-
409- requisition->width = w;
410- requisition->height = h;
411-
412-}
413-
414-static void
415-ido_offscreen_proxy_get_preferred_width (GtkWidget *widget,
416- gint *minimum,
417- gint *natural)
418-{
419- GtkRequisition requisition;
420-
421- ido_offscreen_proxy_size_request (widget, &requisition);
422-
423- *minimum = *natural = requisition.width;
424-}
425-
426-static void
427-ido_offscreen_proxy_get_preferred_height (GtkWidget *widget,
428- gint *minimum,
429- gint *natural)
430-{
431- GtkRequisition requisition;
432-
433- ido_offscreen_proxy_size_request (widget, &requisition);
434-
435- *minimum = *natural = requisition.height;
436-
437-}
438-
439-static void
440-ido_offscreen_proxy_size_allocate (GtkWidget *widget,
441- GtkAllocation *allocation)
442-{
443- IdoOffscreenProxy *proxy;
444-
445- proxy = IDO_OFFSCREEN_PROXY (widget);
446-
447- gtk_widget_set_allocation (widget, allocation);
448-
449- if (gtk_widget_get_realized (widget))
450- {
451- gdk_window_move_resize (gtk_widget_get_window (widget),
452- allocation->x,
453- allocation->y,
454- allocation->width,
455- allocation->height);
456- }
457-
458- if (proxy->priv->child && gtk_widget_get_visible (proxy->priv->child))
459- {
460- GtkRequisition child_requisition;
461- GtkAllocation child_allocation;
462-
463- gtk_widget_get_preferred_size (proxy->priv->child,
464- &child_requisition, NULL);
465-
466- child_allocation.x = child_requisition.width;
467- child_allocation.y = child_requisition.height;
468- child_allocation.width = allocation->width;
469- child_allocation.height = allocation->height;
470-
471- if (gtk_widget_get_realized (widget))
472- gdk_window_move_resize (proxy->priv->offscreen_window,
473- child_allocation.x,
474- child_allocation.y,
475- child_allocation.width+4,
476- child_allocation.height);
477-
478- child_allocation.x = child_allocation.y = 0;
479- gtk_widget_size_allocate (proxy->priv->child, &child_allocation);
480- }
481-}
482-
483-
484-static gboolean
485-ido_offscreen_proxy_damage (GtkWidget *widget,
486- GdkEventExpose *event)
487-{
488- gdk_window_invalidate_rect (gtk_widget_get_window (widget),
489- NULL, FALSE);
490- return TRUE;
491-}
492-
493-static GtkStyleContext *
494-get_menu_style_context ()
495-{
496- GtkStyleContext *sc;
497- GtkWidgetPath *path;
498-
499- path = gtk_widget_path_new ();
500- gtk_widget_path_append_type (path, GTK_TYPE_MENU);
501-
502- sc = gtk_style_context_new();
503-
504- proxy_add_css (sc);
505-
506- gtk_style_context_set_path (sc, path);
507- gtk_style_context_add_class (sc, GTK_STYLE_CLASS_MENU);
508- gtk_style_context_add_class (sc, "ido-offscreen");
509-
510-
511-
512- gtk_widget_path_free (path);
513-
514- return sc;
515-}
516-
517-static gboolean
518-ido_offscreen_proxy_draw (GtkWidget *widget,
519- cairo_t *cr)
520-{
521- IdoOffscreenProxy *proxy = IDO_OFFSCREEN_PROXY (widget);
522- GdkWindow *window;
523- GtkStyleContext *sc;
524-
525- window = gtk_widget_get_window (widget);
526-
527- sc = get_menu_style_context();
528-
529- gtk_style_context_add_class (sc, "menubar");
530-
531- gtk_render_background (sc, cr,
532- 0, 0,
533- gdk_window_get_width (window),
534- gdk_window_get_height (window));
535-
536- g_object_unref (sc);
537-
538- if (gtk_cairo_should_draw_window (cr, window))
539- {
540- cairo_surface_t *surface;
541-
542- if (proxy->priv->child && gtk_widget_get_visible (proxy->priv->child))
543- {
544- surface = gdk_offscreen_window_get_surface (proxy->priv->offscreen_window);
545-
546- cairo_set_source_surface (cr, surface, 0, 0);
547- cairo_paint (cr);
548- }
549- }
550- else if (gtk_cairo_should_draw_window (cr, proxy->priv->offscreen_window))
551- {
552- if (proxy->priv->child)
553- gtk_container_propagate_draw (GTK_CONTAINER (widget),
554- proxy->priv->child,
555- cr);
556- }
557-
558- return TRUE;
559-}
560
561=== removed file 'src/idooffscreenproxy.h'
562--- src/idooffscreenproxy.h 2011-09-02 18:55:39 +0000
563+++ src/idooffscreenproxy.h 1970-01-01 00:00:00 +0000
564@@ -1,62 +0,0 @@
565-/*
566- * Copyright 2011 Canonical, Ltd.
567- *
568- * This program is free software: you can redistribute it and/or modify it
569- * under the terms of either or both of the following licenses:
570- *
571- * 1) the GNU Lesser General Public License version 3, as published by the
572- * Free Software Foundation; and/or
573- * 2) the GNU Lesser General Public License version 2.1, as published by
574- * the Free Software Foundation.
575- *
576- * This program is distributed in the hope that it will be useful, but
577- * WITHOUT ANY WARRANTY; without even the implied warranties of
578- * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
579- * PURPOSE. See the applicable version of the GNU Lesser General Public
580- * License for more details.
581- *
582- * You should have received a copy of both the GNU Lesser General Public
583- * License version 3 and version 2.1 along with this program. If not, see
584- * <http://www.gnu.org/licenses/>
585- *
586- * Authors:
587- * Robert Carr <racarr@canonical.com>
588- */
589-
590-#ifndef __IDO_OFFSCREEN_PROXY_H__
591-#define __IDO_OFFSCREEN_PROXy_H__
592-
593-#include <gdk/gdk.h>
594-#include <gtk/gtk.h>
595-
596-G_BEGIN_DECLS
597-
598-#define IDO_TYPE_OFFSCREEN_PROXY (ido_offscreen_proxy_get_type ())
599-#define IDO_OFFSCREEN_PROXY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IDO_TYPE_OFFSCREEN_PROXY, IdoOffscreenProxy))
600-#define IDO_OFFSCREEN_PROXY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), IDO_TYPE_OFFSCREEN_PROXY, IdoOffscreenProxyClass))
601-#define IDO_IS_OFFSCREEN_PROXY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IDO_TYPE_OFFSCREEN_PROXY))
602-#define IDO_IS_OFFSCREEN_PROXY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), IDO_TYPE_OFFSCREEN_PROXY))
603-#define IDO_OFFSCREEN_PROXY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), IDO_TYPE_OFFSCREEN_PROXY, IdoOffscreenProxyClass))
604-
605-typedef struct _IdoOffscreenProxy IdoOffscreenProxy;
606-typedef struct _IdoOffscreenProxyClass IdoOffscreenProxyClass;
607-typedef struct _IdoOffscreenProxyPrivate IdoOffscreenProxyPrivate;
608-
609-struct _IdoOffscreenProxyClass
610-{
611- GtkBinClass parent_class;
612-};
613-
614-struct _IdoOffscreenProxy
615-{
616- GtkContainer container;
617-
618- IdoOffscreenProxyPrivate *priv;
619-};
620-
621-GType ido_offscreen_proxy_get_type (void) G_GNUC_CONST;
622-GtkWidget *ido_offscreen_proxy_new (void);
623-
624-G_END_DECLS
625-
626-#endif
627
628=== modified file 'src/idoscalemenuitem.c'
629--- src/idoscalemenuitem.c 2011-12-14 17:19:26 +0000
630+++ src/idoscalemenuitem.c 2012-03-12 16:37:21 +0000
631@@ -31,10 +31,6 @@
632 #include "idoscalemenuitem.h"
633 #include "idotypebuiltins.h"
634
635-#ifdef USE_GTK3
636-#include "idooffscreenproxy.h"
637-#endif
638-
639 static void ido_scale_menu_item_set_property (GObject *object,
640 guint prop_id,
641 const GValue *value,
642@@ -59,16 +55,12 @@
643 GParamSpec *pspec,
644 gpointer user_data);
645 static void update_packing (IdoScaleMenuItem *self,
646- IdoScaleMenuItemStyle style,
647- IdoScaleMenuItemStyle old_style);
648+ IdoScaleMenuItemStyle style);
649+static void default_primary_clicked_handler (IdoScaleMenuItem *self);
650+static void default_secondary_clicked_handler (IdoScaleMenuItem *self);
651
652 struct _IdoScaleMenuItemPrivate {
653 GtkWidget *scale;
654-
655-#ifdef USE_GTK3
656- GtkWidget *proxy;
657-#endif
658-
659 GtkAdjustment *adjustment;
660 GtkWidget *primary_image;
661 GtkWidget *secondary_image;
662@@ -88,6 +80,8 @@
663 enum {
664 SLIDER_GRABBED,
665 SLIDER_RELEASED,
666+ PRIMARY_CLICKED,
667+ SECONDARY_CLICKED,
668 LAST_SIGNAL
669 };
670
671@@ -105,13 +99,6 @@
672
673 #define GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), IDO_TYPE_SCALE_MENU_ITEM, IdoScaleMenuItemPrivate))
674
675-static void
676-ido_scale_menu_item_state_changed (GtkWidget *widget,
677- GtkStateType previous_state)
678-{
679- gtk_widget_set_state (widget, GTK_STATE_NORMAL);
680-}
681-
682 static gboolean
683 ido_scale_menu_item_scroll_event (GtkWidget *menuitem,
684 GdkEventScroll *event)
685@@ -250,14 +237,6 @@
686 gtk_scale_set_draw_value (GTK_SCALE (priv->scale), FALSE);
687
688 #ifdef USE_GTK3
689- gtk_widget_set_can_focus (priv->scale, FALSE);
690-
691- priv->proxy = ido_offscreen_proxy_new ();
692- g_object_ref (priv->proxy);
693- gtk_container_add (GTK_CONTAINER (priv->proxy), priv->scale);
694-#endif
695-
696-#ifdef USE_GTK3
697 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
698 #else
699 hbox = gtk_hbox_new (FALSE, 0);
700@@ -278,7 +257,7 @@
701
702 priv->hbox = hbox;
703
704- update_packing (self, priv->style, priv->style);
705+ update_packing (self, priv->style);
706
707 g_signal_connect (self, "toggle-size-allocate",
708 G_CALLBACK (ido_scale_menu_item_toggle_size_allocate),
709@@ -297,11 +276,13 @@
710 GObjectClass *gobject_class = G_OBJECT_CLASS (item_class);
711 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (item_class);
712
713+ item_class->primary_clicked = default_primary_clicked_handler;
714+ item_class->secondary_clicked = default_secondary_clicked_handler;
715+
716 widget_class->button_press_event = ido_scale_menu_item_button_press_event;
717 widget_class->button_release_event = ido_scale_menu_item_button_release_event;
718 widget_class->motion_notify_event = ido_scale_menu_item_motion_notify_event;
719 widget_class->scroll_event = ido_scale_menu_item_scroll_event;
720- widget_class->state_changed = ido_scale_menu_item_state_changed;
721 widget_class->size_allocate = ido_scale_menu_item_size_allocate;
722
723 gobject_class->constructed = ido_scale_menu_item_constructed;
724@@ -358,95 +339,58 @@
725 g_cclosure_marshal_VOID__VOID,
726 G_TYPE_NONE, 0);
727
728+ signals[PRIMARY_CLICKED] = g_signal_new ("primary-clicked",
729+ G_TYPE_FROM_CLASS (item_class),
730+ G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
731+ G_STRUCT_OFFSET (IdoScaleMenuItemClass, primary_clicked),
732+ NULL, NULL,
733+ g_cclosure_marshal_VOID__VOID,
734+ G_TYPE_NONE, /* return type */
735+ 0 /* n_params */);
736+
737+ signals[SECONDARY_CLICKED] = g_signal_new ("secondary-clicked",
738+ G_TYPE_FROM_CLASS (item_class),
739+ G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
740+ G_STRUCT_OFFSET (IdoScaleMenuItemClass, secondary_clicked),
741+ NULL, NULL,
742+ g_cclosure_marshal_VOID__VOID,
743+ G_TYPE_NONE, /* return type */
744+ 0 /* n_params */);
745+
746 g_type_class_add_private (item_class, sizeof (IdoScaleMenuItemPrivate));
747 }
748
749 static void
750-update_packing (IdoScaleMenuItem *self, IdoScaleMenuItemStyle style, IdoScaleMenuItemStyle old_style)
751+update_packing (IdoScaleMenuItem *self, IdoScaleMenuItemStyle style)
752 {
753 IdoScaleMenuItemPrivate *priv = GET_PRIVATE (self);
754+ GtkBox * box = GTK_BOX (priv->hbox);
755 GtkContainer *container = GTK_CONTAINER (priv->hbox);
756
757- if (style != old_style)
758- {
759- switch (old_style)
760- {
761- case IDO_SCALE_MENU_ITEM_STYLE_NONE:
762-#ifdef USE_GTK3
763- gtk_container_remove (container, priv->proxy);
764-#else
765- gtk_container_remove (container, priv->scale);
766-#endif
767- break;
768-
769- case IDO_SCALE_MENU_ITEM_STYLE_IMAGE:
770- gtk_container_remove (container, priv->primary_image);
771- gtk_container_remove (container, priv->secondary_image);
772-#ifdef USE_GTK3
773- gtk_container_remove (container, priv->proxy);
774-#else
775- gtk_container_remove (container, priv->scale);
776-#endif
777- break;
778-
779- case IDO_SCALE_MENU_ITEM_STYLE_LABEL:
780- gtk_container_remove (container, priv->primary_label);
781- gtk_container_remove (container, priv->secondary_label);
782-#ifdef USE_GTK3
783- gtk_container_remove (container, priv->proxy);
784-#else
785- gtk_container_remove (container, priv->scale);
786-#endif
787- break;
788-
789- default:
790-#ifdef USE_GTK3
791- gtk_container_remove (container, priv->proxy);
792-#else
793- gtk_container_remove (container, priv->scale);
794-#endif
795- break;
796- }
797- }
798-
799+ /* remove the old layout */
800+ GList * children = gtk_container_get_children (container);
801+ GList * l;
802+ for (l=children; l!=NULL; l=l->next)
803+ gtk_container_remove (container, l->data);
804+ g_list_free (children);
805+
806+ /* add the new layout */
807 switch (style)
808 {
809- case IDO_SCALE_MENU_ITEM_STYLE_NONE:
810-#ifdef USE_GTK3
811- gtk_box_pack_start (GTK_BOX (priv->hbox), priv->proxy, FALSE, FALSE, 0);
812-#else
813- gtk_box_pack_start (GTK_BOX (priv->hbox), priv->scale, FALSE, FALSE, 0);
814-#endif
815- break;
816-
817 case IDO_SCALE_MENU_ITEM_STYLE_IMAGE:
818- gtk_box_pack_start (GTK_BOX (priv->hbox), priv->primary_image, FALSE, FALSE, 0);
819-
820-#ifdef USE_GTK3
821- gtk_box_pack_start (GTK_BOX (priv->hbox), priv->proxy, FALSE, FALSE, 0);
822-#else
823- gtk_box_pack_start (GTK_BOX (priv->hbox), priv->scale, FALSE, FALSE, 0);
824-#endif
825-
826- gtk_box_pack_start (GTK_BOX (priv->hbox), priv->secondary_image, FALSE, FALSE, 0);
827+ gtk_box_pack_start (box, priv->primary_image, FALSE, FALSE, 0);
828+ gtk_box_pack_start (box, priv->scale, FALSE, FALSE, 0);
829+ gtk_box_pack_start (box, priv->secondary_image, FALSE, FALSE, 0);
830 break;
831
832 case IDO_SCALE_MENU_ITEM_STYLE_LABEL:
833- gtk_box_pack_start (GTK_BOX (priv->hbox), priv->primary_label, FALSE, FALSE, 0);
834-#ifdef USE_GTK3
835- gtk_box_pack_start (GTK_BOX (priv->hbox), priv->proxy, FALSE, FALSE, 0);
836-#else
837- gtk_box_pack_start (GTK_BOX (priv->hbox), priv->scale, FALSE, FALSE, 0);
838-#endif
839- gtk_box_pack_start (GTK_BOX (priv->hbox), priv->secondary_label, FALSE, FALSE, 0);
840+ gtk_box_pack_start (box, priv->primary_label, FALSE, FALSE, 0);
841+ gtk_box_pack_start (box, priv->scale, FALSE, FALSE, 0);
842+ gtk_box_pack_start (box, priv->secondary_label, FALSE, FALSE, 0);
843 break;
844
845 default:
846-#ifdef USE_GTK3
847- gtk_box_pack_start (GTK_BOX (priv->hbox), priv->proxy, FALSE, FALSE, 0);
848-#else
849- gtk_box_pack_start (GTK_BOX (priv->hbox), priv->scale, FALSE, FALSE, 0);
850-#endif
851+ gtk_box_pack_start (box, priv->scale, FALSE, FALSE, 0);
852 break;
853 }
854
855@@ -579,64 +523,50 @@
856 ido_scale_menu_item_button_release_event (GtkWidget *menuitem,
857 GdkEventButton *event)
858 {
859+ IdoScaleMenuItem *item = IDO_SCALE_MENU_ITEM (menuitem);
860 IdoScaleMenuItemPrivate *priv = GET_PRIVATE (menuitem);
861 GtkWidget *scale = priv->scale;
862 gdouble x;
863
864+ /* if user clicked to the left of the scale... */
865 if (event->x > priv->child_allocation.x &&
866 event->x < priv->child_allocation.x + priv->left_padding)
867 {
868- GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (priv->scale));
869-
870 if (gtk_widget_get_direction (menuitem) == GTK_TEXT_DIR_LTR)
871 {
872- gtk_adjustment_set_value (adj, gtk_adjustment_get_lower (adj));
873+ ido_scale_menu_item_primary_clicked (item);
874 }
875 else
876 {
877- gtk_adjustment_set_value (adj, gtk_adjustment_get_upper (adj));
878- }
879-
880- if (priv->grabbed)
881- {
882- priv->grabbed = FALSE;
883- g_signal_emit (menuitem, signals[SLIDER_RELEASED], 0);
884- }
885-
886- return TRUE;
887+ ido_scale_menu_item_secondary_clicked (item);
888+ }
889 }
890
891- if (event->x < priv->child_allocation.x + priv->child_allocation.width + priv->right_padding + priv->left_padding &&
892+ /* if user clicked to the right of the scale... */
893+ else if (event->x < priv->child_allocation.x + priv->child_allocation.width + priv->right_padding + priv->left_padding &&
894 event->x > priv->child_allocation.x + priv->child_allocation.width + priv->left_padding)
895 {
896- GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (priv->scale));
897-
898 if (gtk_widget_get_direction (menuitem) == GTK_TEXT_DIR_LTR)
899 {
900- gtk_adjustment_set_value (adj, gtk_adjustment_get_upper (adj));
901+ ido_scale_menu_item_secondary_clicked (item);
902 }
903 else
904 {
905- gtk_adjustment_set_value (adj, gtk_adjustment_get_lower (adj));
906- }
907-
908- if (priv->grabbed)
909- {
910- priv->grabbed = FALSE;
911- g_signal_emit (menuitem, signals[SLIDER_RELEASED], 0);
912- }
913-
914- return TRUE;
915- }
916-
917- translate_event_coordinates (menuitem, event->x, &x);
918- event->x = x;
919-
920- translate_event_coordinates (menuitem, event->x_root, &x);
921- event->x_root= x;
922-
923- gtk_widget_event (scale,
924- ((GdkEvent *)(void*)(event)));
925+ ido_scale_menu_item_primary_clicked (item);
926+ }
927+ }
928+
929+ /* user clicked on the scale... */
930+ else
931+ {
932+ translate_event_coordinates (menuitem, event->x, &x);
933+ event->x = x;
934+
935+ translate_event_coordinates (menuitem, event->x_root, &x);
936+ event->x_root= x;
937+
938+ gtk_widget_event (scale, (GdkEvent*)event);
939+ }
940
941 if (priv->grabbed)
942 {
943@@ -812,16 +742,14 @@
944 IdoScaleMenuItemStyle style)
945 {
946 IdoScaleMenuItemPrivate *priv;
947- IdoScaleMenuItemStyle old_style;
948
949 g_return_if_fail (IDO_IS_SCALE_MENU_ITEM (menuitem));
950
951 priv = GET_PRIVATE (menuitem);
952
953- old_style = priv->style;
954 priv->style = style;
955
956- update_packing (menuitem, style, old_style);
957+ update_packing (menuitem, style);
958 }
959
960 /**
961@@ -958,5 +886,50 @@
962 }
963 }
964
965+/**
966+ * ido_scale_menu_item_primary_clicked:
967+ * @menuitem: the #IdoScaleMenuItem
968+ *
969+ * Emits the "primary-clicked" signal.
970+ *
971+ * The default handler for this signal lowers the scale's
972+ * adjustment to its lower bound.
973+ */
974+void
975+ido_scale_menu_item_primary_clicked (IdoScaleMenuItem * item)
976+{
977+ g_signal_emit (item, signals[PRIMARY_CLICKED], 0);
978+}
979+static void
980+default_primary_clicked_handler (IdoScaleMenuItem * item)
981+{
982+ g_debug ("%s: setting scale to lower bound", G_STRFUNC);
983+ IdoScaleMenuItemPrivate * priv = GET_PRIVATE (item);
984+ GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (priv->scale));
985+ gtk_adjustment_set_value (adj, gtk_adjustment_get_lower (adj));
986+}
987+
988+/**
989+ * ido_scale_menu_item_primary_clicked:
990+ * @menuitem: the #IdoScaleMenuItem
991+ *
992+ * Emits the "primary-clicked" signal.
993+ *
994+ * The default handler for this signal raises the scale's
995+ * adjustment to its upper bound.
996+ */
997+void
998+ido_scale_menu_item_secondary_clicked (IdoScaleMenuItem * item)
999+{
1000+ g_signal_emit (item, signals[SECONDARY_CLICKED], 0);
1001+}
1002+static void
1003+default_secondary_clicked_handler (IdoScaleMenuItem * item)
1004+{
1005+ g_debug ("%s: setting scale to upper bound", G_STRFUNC);
1006+ IdoScaleMenuItemPrivate * priv = GET_PRIVATE (item);
1007+ GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (priv->scale));
1008+ gtk_adjustment_set_value (adj, gtk_adjustment_get_upper (adj));
1009+}
1010
1011 #define __IDO_SCALE_MENU_ITEM_C__
1012
1013=== modified file 'src/idoscalemenuitem.h'
1014--- src/idoscalemenuitem.h 2011-06-20 13:34:43 +0000
1015+++ src/idoscalemenuitem.h 2012-03-12 16:37:21 +0000
1016@@ -59,6 +59,10 @@
1017 struct _IdoScaleMenuItemClass
1018 {
1019 GtkMenuItemClass parent_class;
1020+
1021+ /* signal default handlers */
1022+ void (*primary_clicked)(IdoScaleMenuItem * self);
1023+ void (*secondary_clicked)(IdoScaleMenuItem * self);
1024 };
1025
1026
1027@@ -79,12 +83,14 @@
1028 IdoScaleMenuItemStyle style);
1029 GtkWidget *ido_scale_menu_item_get_primary_image (IdoScaleMenuItem *menuitem);
1030 GtkWidget *ido_scale_menu_item_get_secondary_image (IdoScaleMenuItem *menuitem);
1031-const gchar *ido_scale_menu_item_get_primary_label (IdoScaleMenuItem *menuitem);
1032-const gchar *ido_scale_menu_item_get_secondary_label (IdoScaleMenuItem *menuitem);
1033+const gchar *ido_scale_menu_item_get_primary_label (IdoScaleMenuItem *menuitem);
1034 void ido_scale_menu_item_set_primary_label (IdoScaleMenuItem *menuitem,
1035 const gchar *label);
1036+const gchar *ido_scale_menu_item_get_secondary_label (IdoScaleMenuItem *menuitem);
1037 void ido_scale_menu_item_set_secondary_label (IdoScaleMenuItem *menuitem,
1038 const gchar *label);
1039+void ido_scale_menu_item_primary_clicked (IdoScaleMenuItem *menuitem);
1040+void ido_scale_menu_item_secondary_clicked (IdoScaleMenuItem *menuitem);
1041
1042 G_END_DECLS
1043

Subscribers

People subscribed via source and target branches