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