diff options
author | Søren Sandmann <sandmann@redhat.com> | 2008-06-05 22:50:27 -0400 |
---|---|---|
committer | Søren Sandmann <sandmann@redhat.com> | 2008-06-05 22:50:27 -0400 |
commit | 6b90e189d35af19e9cfdcdc54314bfbdaf633951 (patch) | |
tree | 316b4ba298c499a2e261b3f3e63d8ee1b956c70c | |
parent | e9eaa5b1ec9eb280589f7f692ca8191dddca9ee7 (diff) |
Introduce new viewport_size_changed signal
-rw-r--r-- | main.c | 84 | ||||
-rw-r--r-- | scrollarea.c | 68 | ||||
-rw-r--r-- | scrollarea.h | 7 |
3 files changed, 108 insertions, 51 deletions
@@ -76,47 +76,61 @@ on_main_paint (FooScrollArea *scroll_area, } static void -on_viewport_changed (FooScrollArea *scroll_area, - GdkRectangle *viewport, - GdkRectangle *old_viewport) +on_viewport_size_changed (FooScrollArea *scroll_area, + GdkRectangle *viewport, + GdkRectangle *old_viewport) { - int th; +#if 0 double ratio; - - if (old_viewport) - { - slide_width = viewport->width - 2 * MARGIN; - slide_height = slide_width / RATIO; - - th = N_SLIDES * slide_height + (N_SLIDES + 1) * MARGIN; - - g_print ("new slide height: %d, new y: %d\n", slide_height, viewport->y); - - /* FIXME: We can recurse infinitely here when the area gets - * narrow enough that the scrollbar disappears causing the area - * to widen a little causing the scrollbar to appear causing - * the arrow to narrow causing ... - * - * For now we work around by have POLICY_ALWAYS on the scrollbar, - * it needs to be thought through and fixed in the scroll area - */ - - ratio = (double)viewport->width / old_viewport->width; - - g_print ("ratio: %f (%d %d)\n", ratio, old_viewport->y, (int)(old_viewport->y * ratio)); - - foo_scroll_area_set_size_fixed_y (scroll_area, viewport->width, th, - old_viewport->y + 100, - (old_viewport->y + 100) * ratio + 0.5); - } + int th; + + g_print ("new slide height: %d, new y: %d\n", slide_height, viewport->y); + + /* FIXME: We can recurse infinitely here when the area gets + * narrow enough that the scrollbar disappears causing the area + * to widen a little causing the scrollbar to appear causing + * the arrow to narrow causing ... + * + * For now we work around by have POLICY_ALWAYS on the scrollbar, + * it needs to be thought through and fixed in the scroll area + */ + + ratio = (double)viewport->width / old_viewport->width; #if 0 - foo_scroll_area_set_size (scroll_area, viewport->width, th); + g_print ("ratio: %f (%d %d)\n", ratio, old_viewport->y, (int)(old_viewport->y * ratio)); + + g_print ("old, new: %f %f\n", slide_n, MARGIN + slide_n * (MARGIN + (double)slide_height)); #endif + + foo_scroll_area_set_size_fixed_y (scroll_area, viewport->width, th, + slide_n, + MARGIN + slide_n * (MARGIN + slide_height)); +#endif + + int th; + double slide_n; + + slide_width = viewport->width - 2 * MARGIN; + slide_height = slide_width / RATIO; + + th = N_SLIDES * slide_height + (N_SLIDES + 1) * MARGIN; + foo_scroll_area_set_size (scroll_area, viewport->width, th); + + g_print ("size changed - set size %d %d\n", viewport->width, th); + foo_scroll_area_invalidate (scroll_area); } static void +on_viewport_changed (FooScrollArea *scroll_area, + GdkRectangle *viewport, + GdkRectangle *old_viewport) +{ + g_print ("viewport changed\n"); +} + +static void set_size (GtkWindow *window) { GdkScreen *screen; @@ -146,8 +160,8 @@ main (int argc, char **argv) app = g_new0 (App, 1); app->xml = glade_xml_new (GLADE_FILE, NULL, NULL); - app->main_area = foo_scroll_area_new(); - app->thumbnails = foo_scroll_area_new(); + app->main_area = (FooScrollArea *)foo_scroll_area_new(); + app->thumbnails = (FooScrollArea *)foo_scroll_area_new(); gtk_container_add ( GTK_CONTAINER (get_widget (app, "main_area_scrolled_window")), @@ -163,6 +177,8 @@ main (int argc, char **argv) G_CALLBACK (on_main_paint), app); g_signal_connect (app->main_area, "viewport_changed", G_CALLBACK (on_viewport_changed), app); + g_signal_connect (app->main_area, "viewport_size_changed", + G_CALLBACK (on_viewport_size_changed), app); g_signal_connect (app->thumbnails, "paint", G_CALLBACK (on_thumbs_paint), app); diff --git a/scrollarea.c b/scrollarea.c index b5a85f6..1d88534 100644 --- a/scrollarea.c +++ b/scrollarea.c @@ -83,6 +83,7 @@ struct FooScrollAreaPrivate enum { + VIEWPORT_SIZE_CHANGED, VIEWPORT_CHANGED, PAINT, INPUT, @@ -178,7 +179,21 @@ foo_scroll_area_class_init (FooScrollAreaClass *class) class->set_scroll_adjustments = foo_scroll_area_set_scroll_adjustments; parent_class = g_type_class_peek_parent (class); - + + /* Emitted when the viewport changes size, but not when it only changes position */ + signals[VIEWPORT_SIZE_CHANGED] = + g_signal_new ("viewport_size_changed", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (FooScrollAreaClass, + viewport_size_changed), + NULL, NULL, + foo_marshal_VOID__BOXED_BOXED, + G_TYPE_NONE, 2, + GDK_TYPE_RECTANGLE, + GDK_TYPE_RECTANGLE); + + /* Emitted when the viewport changes position or size or both */ signals[VIEWPORT_CHANGED] = g_signal_new ("viewport_changed", G_OBJECT_CLASS_TYPE (object_class), @@ -617,24 +632,45 @@ process_event (FooScrollArea *scroll_area, int button); static void -emit_viewport_changed (FooScrollArea *scroll_area, +emit_viewport_signals (FooScrollArea *scroll_area, GdkRectangle *new_viewport, GdkRectangle *old_viewport) { int px, py; + gboolean position_changed; + gboolean size_changed; - g_signal_emit (scroll_area, signals[VIEWPORT_CHANGED], 0, - new_viewport, old_viewport); - - if (new_viewport->x != old_viewport->x || - new_viewport->y != old_viewport->y || - new_viewport->width != old_viewport->width || - new_viewport->height != old_viewport->height) + size_changed = (new_viewport->width != old_viewport->width || + new_viewport->height != old_viewport->height); + + position_changed = (new_viewport->x != old_viewport->x || + new_viewport->y != old_viewport->y); + + if (size_changed || position_changed) { + g_signal_emit (scroll_area, signals[VIEWPORT_CHANGED], 0, + new_viewport, old_viewport); + + if (size_changed) + { + g_signal_emit (scroll_area, signals[VIEWPORT_SIZE_CHANGED], 0, + new_viewport, old_viewport); + } + else + { + g_print ("old size: %d %d\n", old_viewport->width, old_viewport->height); + g_print ("new size: %d %d\n", new_viewport->width, new_viewport->height); + } + gdk_window_get_pointer (GTK_WIDGET (scroll_area)->window, &px, &py, NULL); - + process_event (scroll_area, FOO_MOTION, px, py, 0); } + else + { + g_print ("old pos: %d %d\n", old_viewport->x, old_viewport->y); + g_print ("new pos: %d %d\n", new_viewport->x, new_viewport->y); + } } static void @@ -660,7 +696,7 @@ set_adjustment_values (FooScrollArea *scroll_area) GtkAdjustment *hadj = scroll_area->priv->hadj; GtkAdjustment *vadj = scroll_area->priv->vadj; - + /* Horizontal */ hadj->page_size = allocation->width; hadj->step_increment = 0.1 * allocation->width; @@ -674,7 +710,7 @@ set_adjustment_values (FooScrollArea *scroll_area) vadj->page_increment = 0.9 * allocation->height; vadj->lower = 0.0; vadj->upper = scroll_area->priv->height; - + clamp_adjustment (hadj); clamp_adjustment (vadj); @@ -688,8 +724,6 @@ foo_scroll_area_realize (GtkWidget *widget) GdkWindowAttr attributes; gint attributes_mask; - g_print ("realizing\n"); - GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); attributes.window_type = GDK_WINDOW_CHILD; @@ -787,7 +821,7 @@ foo_scroll_area_size_allocate (GtkWidget *widget, get_viewport (scroll_area, &new_viewport); - emit_viewport_changed (scroll_area, &new_viewport, &old_viewport); + emit_viewport_signals (scroll_area, &new_viewport, &old_viewport); } static void @@ -1181,6 +1215,8 @@ foo_scrollbar_adjustment_changed (GtkAdjustment *adj, gint dy = 0; GdkRectangle old_viewport, new_viewport; + g_print ("adjustment changed\n"); + /* FIXME: When dragging diagonally, this function will be called * twice, causing two separate scrolls in the backing store. * @@ -1216,7 +1252,7 @@ foo_scrollbar_adjustment_changed (GtkAdjustment *adj, get_viewport (scroll_area, &new_viewport); - emit_viewport_changed (scroll_area, &new_viewport, &old_viewport); + emit_viewport_signals (scroll_area, &new_viewport, &old_viewport); } static void diff --git a/scrollarea.h b/scrollarea.h index 1c95c9a..5a5236f 100644 --- a/scrollarea.h +++ b/scrollarea.h @@ -48,7 +48,12 @@ struct FooScrollAreaClass GtkAdjustment *vadjustment); void (*viewport_changed) (FooScrollArea *scroll_area, - GdkRectangle *viewport); + GdkRectangle *viewport, + GdkRectangle *old_viewport); + + void (*viewport_size_changed) (FooScrollArea *scroll_area, + GdkRectangle *viewport, + GdkRectangle *old_viewport); void (*paint) (FooScrollArea *scroll_area, cairo_t *cr, |