Merge lp:~cimi/overlay-scrollbar/fixes-pager-creation-and-show into lp:overlay-scrollbar
- fixes-pager-creation-and-show
- Merge into trunk
Proposed by
Andrea Cimitan
Status: | Merged | ||||||||
---|---|---|---|---|---|---|---|---|---|
Merged at revision: | 148 | ||||||||
Proposed branch: | lp:~cimi/overlay-scrollbar/fixes-pager-creation-and-show | ||||||||
Merge into: | lp:overlay-scrollbar | ||||||||
Diff against target: |
484 lines (+128/-132) 3 files modified
os/os-pager.c (+91/-105) os/os-private.h (+11/-8) os/os-scrollbar.c (+26/-19) |
||||||||
To merge this branch: | bzr merge lp:~cimi/overlay-scrollbar/fixes-pager-creation-and-show | ||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Loïc Molinari (community) | Approve | ||
Review via email: mp+52541@code.launchpad.net |
Commit message
Description of the change
first create the pager, then show it properly setting its parent
To post a comment you must log in.
Revision history for this message
Andrea Cimitan (cimi) wrote : | # |
- 148. By Andrea Cimitan
-
don't show the pager on realize
Revision history for this message
Loïc Molinari (loic.molinari) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'os/os-pager.c' |
2 | --- os/os-pager.c 2011-03-03 17:59:02 +0000 |
3 | +++ os/os-pager.c 2011-03-08 11:38:09 +0000 |
4 | @@ -39,21 +39,13 @@ |
5 | GdkRectangle mask; |
6 | GdkRectangle allocation; |
7 | gboolean active; |
8 | + gboolean visible; |
9 | gint width; |
10 | gint height; |
11 | }; |
12 | |
13 | -enum { |
14 | - PROP_0, |
15 | - PROP_PARENT, |
16 | - LAST_ARG |
17 | -}; |
18 | - |
19 | -static void os_pager_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); |
20 | -static void os_pager_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); |
21 | static void os_pager_dispose (GObject *object); |
22 | static void os_pager_finalize (GObject *object); |
23 | -static void os_pager_check_properties (OsPager *pager); |
24 | static void os_pager_create (OsPager *pager); |
25 | static void os_pager_draw (OsPager *pager); |
26 | static void os_pager_draw_bitmap (GdkPixmap *pixmap, GdkRectangle mask); |
27 | @@ -62,38 +54,36 @@ |
28 | |
29 | /* Private functions */ |
30 | |
31 | -/* Check if all properties are set. */ |
32 | -static void |
33 | -os_pager_check_properties (OsPager *pager) |
34 | -{ |
35 | - OsPagerPrivate *priv; |
36 | - |
37 | - priv = OS_PAGER_GET_PRIVATE (pager); |
38 | - |
39 | - g_return_if_fail (GTK_WIDGET (priv->parent)); |
40 | - |
41 | - os_pager_create (pager); |
42 | -} |
43 | - |
44 | /* Create a pager. */ |
45 | static void |
46 | os_pager_create (OsPager *pager) |
47 | { |
48 | - GdkWindowAttr attributes; |
49 | OsPagerPrivate *priv; |
50 | |
51 | priv = OS_PAGER_GET_PRIVATE (pager); |
52 | |
53 | - attributes.width = priv->allocation.width; |
54 | - attributes.height = priv->allocation.height; |
55 | - attributes.wclass = GDK_INPUT_OUTPUT; |
56 | - attributes.window_type = GDK_WINDOW_CHILD; |
57 | - |
58 | - priv->pager_window = gdk_window_new (gtk_widget_get_window (priv->parent), |
59 | - &attributes, 0); |
60 | - |
61 | - gdk_window_set_transient_for (priv->pager_window, |
62 | - gtk_widget_get_window (priv->parent)); |
63 | + if (priv->pager_window != NULL) |
64 | + { |
65 | + gdk_window_reparent (priv->pager_window, |
66 | + gtk_widget_get_window (priv->parent), |
67 | + priv->allocation.x, |
68 | + priv->allocation.y); |
69 | + } |
70 | + else |
71 | + { |
72 | + GdkWindowAttr attributes; |
73 | + |
74 | + attributes.width = priv->allocation.width; |
75 | + attributes.height = priv->allocation.height; |
76 | + attributes.wclass = GDK_INPUT_OUTPUT; |
77 | + attributes.window_type = GDK_WINDOW_CHILD; |
78 | + |
79 | + priv->pager_window = gdk_window_new (gtk_widget_get_window (priv->parent), |
80 | + &attributes, 0); |
81 | + |
82 | + gdk_window_set_transient_for (priv->pager_window, |
83 | + gtk_widget_get_window (priv->parent)); |
84 | + } |
85 | } |
86 | |
87 | /* Draw on the pager. */ |
88 | @@ -109,9 +99,6 @@ |
89 | priv->allocation.height, 24); |
90 | os_pager_draw_pixmap (pixmap, priv->active); |
91 | |
92 | - if (priv->pager_window == NULL) |
93 | - os_pager_check_properties (pager); |
94 | - |
95 | gdk_window_set_back_pixmap (priv->pager_window, pixmap, FALSE); |
96 | gdk_window_clear (priv->pager_window); |
97 | } |
98 | @@ -196,19 +183,9 @@ |
99 | { |
100 | GObjectClass *gobject_class = G_OBJECT_CLASS (class); |
101 | |
102 | - gobject_class->get_property = os_pager_get_property; |
103 | - gobject_class->set_property = os_pager_set_property; |
104 | - gobject_class->dispose = os_pager_dispose; |
105 | + gobject_class->dispose = os_pager_dispose; |
106 | gobject_class->finalize = os_pager_finalize; |
107 | |
108 | - g_object_class_install_property |
109 | - (gobject_class, PROP_PARENT, |
110 | - g_param_spec_object ("parent", "Parent", |
111 | - "Reference to the parent GtkWidget", |
112 | - GTK_TYPE_WIDGET, |
113 | - G_PARAM_READWRITE | G_PARAM_STATIC_NAME | |
114 | - G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); |
115 | - |
116 | g_type_class_add_private (gobject_class, sizeof (OsPagerPrivate)); |
117 | } |
118 | |
119 | @@ -227,7 +204,8 @@ |
120 | |
121 | priv->allocation = allocation; |
122 | |
123 | - priv->active = FALSE; |
124 | + priv->active = TRUE; |
125 | + priv->visible = FALSE; |
126 | } |
127 | |
128 | static void |
129 | @@ -242,62 +220,19 @@ |
130 | G_OBJECT_CLASS (os_pager_parent_class)->finalize (object); |
131 | } |
132 | |
133 | -static void |
134 | -os_pager_get_property (GObject *object, |
135 | - guint prop_id, |
136 | - GValue *value, |
137 | - GParamSpec *pspec) |
138 | -{ |
139 | - OsPagerPrivate *priv; |
140 | - |
141 | - priv = OS_PAGER_GET_PRIVATE (OS_PAGER (object)); |
142 | - |
143 | - switch (prop_id) |
144 | - { |
145 | - case PROP_PARENT: |
146 | - g_value_set_object (value, priv->parent); |
147 | - break; |
148 | - |
149 | - default: |
150 | - break; |
151 | - } |
152 | -} |
153 | - |
154 | -static void |
155 | -os_pager_set_property (GObject *object, |
156 | - guint prop_id, |
157 | - const GValue *value, |
158 | - GParamSpec *pspec) |
159 | -{ |
160 | - OsPagerPrivate *priv; |
161 | - |
162 | - priv = OS_PAGER_GET_PRIVATE (OS_PAGER (object)); |
163 | - |
164 | - switch (prop_id) |
165 | - { |
166 | - case PROP_PARENT: |
167 | - priv->parent = g_value_get_object (value); |
168 | - break; |
169 | - |
170 | - default: |
171 | - break; |
172 | - } |
173 | -} |
174 | - |
175 | /* Public functions. */ |
176 | |
177 | /** |
178 | * os_pager_new: |
179 | - * @widget: the parent window |
180 | * |
181 | * Creates a new #OsPager instance. |
182 | * |
183 | * Returns: the new #OsPager instance. |
184 | */ |
185 | GObject* |
186 | -os_pager_new (GtkWidget *widget) |
187 | +os_pager_new (void) |
188 | { |
189 | - return g_object_new (OS_TYPE_PAGER, "parent", widget, NULL); |
190 | + return g_object_new (OS_TYPE_PAGER, NULL); |
191 | } |
192 | |
193 | /** |
194 | @@ -315,7 +250,9 @@ |
195 | |
196 | priv = OS_PAGER_GET_PRIVATE (pager); |
197 | |
198 | - if (priv->pager_window == NULL) |
199 | + priv->visible = FALSE; |
200 | + |
201 | + if (priv->parent == NULL) |
202 | return; |
203 | |
204 | gdk_window_hide (priv->pager_window); |
205 | @@ -338,16 +275,16 @@ |
206 | |
207 | priv = OS_PAGER_GET_PRIVATE (pager); |
208 | |
209 | - if (priv->pager_window == NULL) |
210 | - os_pager_check_properties (pager); |
211 | - |
212 | priv->mask = mask; |
213 | |
214 | + if (priv->parent == NULL) |
215 | + return; |
216 | + |
217 | os_pager_mask (pager); |
218 | } |
219 | |
220 | /** |
221 | - * os_pager_show: |
222 | + * os_pager_set_active: |
223 | * @pager: a #OsPager |
224 | * @active: whether is active or not |
225 | * |
226 | @@ -366,7 +303,54 @@ |
227 | if (priv->active != active) |
228 | { |
229 | priv->active = active; |
230 | - os_pager_draw (pager); |
231 | + |
232 | + if (priv->parent == NULL) |
233 | + return; |
234 | + |
235 | + os_pager_draw (pager); |
236 | + } |
237 | +} |
238 | + |
239 | +/** |
240 | + * os_pager_set_parent: |
241 | + * @pager: a #OsPager |
242 | + * @parent: a #GtkWidget |
243 | + * |
244 | + * Sets the parent widget |
245 | + **/ |
246 | +void |
247 | +os_pager_set_parent (OsPager *pager, |
248 | + GtkWidget *parent) |
249 | +{ |
250 | + OsPagerPrivate *priv; |
251 | + |
252 | + g_return_if_fail (OS_PAGER (pager)); |
253 | + |
254 | + priv = OS_PAGER_GET_PRIVATE (pager); |
255 | + |
256 | + if (priv->parent != NULL) |
257 | + { |
258 | + g_object_unref (priv->parent); |
259 | + } |
260 | + |
261 | + priv->parent = parent; |
262 | + |
263 | + if (priv->parent != NULL) |
264 | + { |
265 | + g_object_ref_sink (priv->parent); |
266 | + |
267 | + os_pager_create (pager); |
268 | + os_pager_draw (pager); |
269 | + os_pager_mask (pager); |
270 | + |
271 | + gdk_window_move_resize (priv->pager_window, |
272 | + priv->allocation.x, |
273 | + priv->allocation.y, |
274 | + priv->allocation.width, |
275 | + priv->allocation.height); |
276 | + |
277 | + if (priv->visible) |
278 | + gdk_window_show (priv->pager_window); |
279 | } |
280 | } |
281 | |
282 | @@ -385,8 +369,10 @@ |
283 | |
284 | priv = OS_PAGER_GET_PRIVATE (pager); |
285 | |
286 | - if (priv->pager_window == NULL) |
287 | - os_pager_draw (pager); |
288 | + priv->visible = TRUE; |
289 | + |
290 | + if (priv->parent == NULL) |
291 | + return; |
292 | |
293 | gdk_window_show (priv->pager_window); |
294 | } |
295 | @@ -399,8 +385,8 @@ |
296 | * Sets the position and dimension of the whole area. |
297 | **/ |
298 | void |
299 | -os_pager_size_allocate (OsPager *pager, |
300 | - GdkRectangle rectangle) |
301 | +os_pager_size_allocate (OsPager *pager, |
302 | + GdkRectangle rectangle) |
303 | { |
304 | OsPagerPrivate *priv; |
305 | |
306 | @@ -410,8 +396,8 @@ |
307 | |
308 | priv->allocation = rectangle; |
309 | |
310 | - if (priv->pager_window == NULL) |
311 | - os_pager_draw (pager); |
312 | + if (priv->parent == NULL) |
313 | + return; |
314 | |
315 | gdk_window_move_resize (priv->pager_window, |
316 | rectangle.x, |
317 | |
318 | === modified file 'os/os-private.h' |
319 | --- os/os-private.h 2011-03-03 15:58:07 +0000 |
320 | +++ os/os-private.h 2011-03-08 11:38:09 +0000 |
321 | @@ -145,21 +145,24 @@ |
322 | |
323 | GType os_pager_get_type (void) G_GNUC_CONST; |
324 | |
325 | -GObject *os_pager_new (GtkWidget *widget); |
326 | +GObject* os_pager_new (void); |
327 | |
328 | void os_pager_hide (OsPager *overlay); |
329 | |
330 | -void os_pager_move_resize (OsPager *overlay, |
331 | - GdkRectangle mask); |
332 | - |
333 | -void os_pager_size_allocate (OsPager *overlay, |
334 | - GdkRectangle rectangle); |
335 | - |
336 | -void os_pager_show (OsPager *overlay); |
337 | +void os_pager_move_resize (OsPager *overlay, |
338 | + GdkRectangle mask); |
339 | |
340 | void os_pager_set_active (OsPager *overlay, |
341 | gboolean active); |
342 | |
343 | +void os_pager_set_parent (OsPager *pager, |
344 | + GtkWidget *parent); |
345 | + |
346 | +void os_pager_show (OsPager *overlay); |
347 | + |
348 | +void os_pager_size_allocate (OsPager *overlay, |
349 | + GdkRectangle rectangle); |
350 | + |
351 | G_END_DECLS |
352 | |
353 | #ifdef __GNUC__ |
354 | |
355 | === modified file 'os/os-scrollbar.c' |
356 | --- os/os-scrollbar.c 2011-03-08 01:22:04 +0000 |
357 | +++ os/os-scrollbar.c 2011-03-08 11:38:09 +0000 |
358 | @@ -111,6 +111,7 @@ |
359 | static void adjustment_changed_cb (GtkAdjustment *adjustment, gpointer user_data); |
360 | static void adjustment_value_changed_cb (GtkAdjustment *adjustment, gpointer user_data); |
361 | static gboolean parent_expose_event_cb (GtkWidget *widget, GdkEventExpose *event, gpointer user_data); |
362 | +static void parent_realize_cb (GtkWidget *widget, gpointer user_data); |
363 | static void parent_size_allocate_cb (GtkWidget *widget, GtkAllocation *allocation, gpointer user_data); |
364 | static gboolean toplevel_configure_event_cb (GtkWidget *widget, GdkEventConfigure *event, gpointer user_data); |
365 | static GdkFilterReturn toplevel_filter_func (GdkXEvent *gdkxevent, GdkEvent *event, gpointer user_data); |
366 | @@ -215,8 +216,7 @@ |
367 | priv->overlay.height = height; |
368 | |
369 | if (tmp_height != height) |
370 | - if (priv->pager != NULL) |
371 | - pager_move (scrollbar); |
372 | + pager_move (scrollbar); |
373 | } |
374 | else |
375 | { |
376 | @@ -254,8 +254,7 @@ |
377 | priv->overlay.width = width; |
378 | |
379 | if (tmp_width != width) |
380 | - if (priv->pager != NULL) |
381 | - pager_move (scrollbar); |
382 | + pager_move (scrollbar); |
383 | } |
384 | } |
385 | |
386 | @@ -554,6 +553,8 @@ |
387 | g_signal_handlers_disconnect_by_func (G_OBJECT (priv->parent), |
388 | G_CALLBACK (parent_expose_event_cb), scrollbar); |
389 | g_signal_handlers_disconnect_by_func (G_OBJECT (priv->parent), |
390 | + G_CALLBACK (parent_realize_cb), scrollbar); |
391 | + g_signal_handlers_disconnect_by_func (G_OBJECT (priv->parent), |
392 | G_CALLBACK (parent_size_allocate_cb), scrollbar); |
393 | |
394 | g_object_unref (priv->parent); |
395 | @@ -567,6 +568,8 @@ |
396 | |
397 | g_signal_connect (G_OBJECT (priv->parent), "expose-event", |
398 | G_CALLBACK (parent_expose_event_cb), scrollbar); |
399 | + g_signal_connect (G_OBJECT (priv->parent), "realize", |
400 | + G_CALLBACK (parent_realize_cb), scrollbar); |
401 | g_signal_connect (G_OBJECT (priv->parent), "size-allocate", |
402 | G_CALLBACK (parent_size_allocate_cb), scrollbar); |
403 | } |
404 | @@ -640,15 +643,6 @@ |
405 | |
406 | os_scrollbar_move_thumb (scrollbar, x_pos + priv->thumb_all.x, y_pos + priv->thumb_all.y); |
407 | |
408 | - if (priv->pager != NULL) |
409 | - { |
410 | - g_object_unref (priv->pager); |
411 | - priv->pager = NULL; |
412 | - } |
413 | - |
414 | - priv->pager = os_pager_new (priv->parent); |
415 | - os_pager_show (OS_PAGER (priv->pager)); |
416 | - |
417 | os_scrollbar_store_window_position (scrollbar); |
418 | } |
419 | |
420 | @@ -952,13 +946,13 @@ |
421 | if ((adjustment->upper - adjustment->lower) > adjustment->page_size) |
422 | { |
423 | priv->fullsize = FALSE; |
424 | - if (priv->pager != NULL && priv->proximity != FALSE) |
425 | + if (priv->proximity != FALSE) |
426 | os_pager_show (OS_PAGER (priv->pager)); |
427 | } |
428 | else |
429 | { |
430 | priv->fullsize = TRUE; |
431 | - if (priv->pager != NULL && priv->proximity != FALSE) |
432 | + if (priv->proximity != FALSE) |
433 | os_pager_hide (OS_PAGER (priv->pager)); |
434 | } |
435 | } |
436 | @@ -1002,6 +996,19 @@ |
437 | } |
438 | |
439 | static void |
440 | +parent_realize_cb (GtkWidget *widget, |
441 | + gpointer user_data) |
442 | +{ |
443 | + OsScrollbar *scrollbar; |
444 | + OsScrollbarPrivate *priv; |
445 | + |
446 | + scrollbar = OS_SCROLLBAR (user_data); |
447 | + priv = OS_SCROLLBAR_GET_PRIVATE (scrollbar); |
448 | + |
449 | + os_pager_set_parent (OS_PAGER (priv->pager), priv->parent); |
450 | +} |
451 | + |
452 | +static void |
453 | parent_size_allocate_cb (GtkWidget *widget, |
454 | GtkAllocation *allocation, |
455 | gpointer user_data) |
456 | @@ -1261,6 +1268,8 @@ |
457 | priv->fullsize = FALSE; |
458 | priv->proximity = FALSE; |
459 | |
460 | + priv->pager = os_pager_new (); |
461 | + |
462 | g_signal_connect (G_OBJECT (scrollbar), "notify::adjustment", |
463 | G_CALLBACK (os_scrollbar_notify_adjustment_cb), NULL); |
464 | |
465 | @@ -1316,8 +1325,7 @@ |
466 | |
467 | priv->proximity = TRUE; |
468 | |
469 | - if (priv->pager != NULL) |
470 | - os_pager_show (OS_PAGER (priv->pager)); |
471 | + os_pager_show (OS_PAGER (priv->pager)); |
472 | |
473 | #if 0 |
474 | Display *display; |
475 | @@ -1399,8 +1407,7 @@ |
476 | |
477 | priv->proximity = FALSE; |
478 | |
479 | - if (priv->pager != NULL) |
480 | - os_pager_hide (OS_PAGER (priv->pager)); |
481 | + os_pager_hide (OS_PAGER (priv->pager)); |
482 | } |
483 | |
484 | static void |
Not ready for the review, will update the branch maybe or confirm it's ready