Commit fefe2c36 authored by Daniel P. Berrange's avatar Daniel P. Berrange

Preserve scrollbar offsets when switching images

When cycling back & forth between images when auto-scale is
not set, preserve the scrollbar offsets.
Signed-off-by: default avatarDaniel P. Berrange <berrange@redhat.com>
parent fad10008
......@@ -73,6 +73,7 @@ struct _EntangleCameraManagerPrivate {
EntangleImageLoader *imageLoader;
EntangleThumbnailLoader *thumbLoader;
EntangleColourProfileTransform *colourTransform;
GtkScrolledWindow *imageScroll;
EntangleImageDisplay *imageDisplay;
EntangleImageStatusbar *imageStatusbar;
ViewAutoDrawer *imageDrawer;
......@@ -90,6 +91,10 @@ struct _EntangleCameraManagerPrivate {
gint presentationMonitor;
GHashTable *popups;
gdouble imageScrollVOffset;
gdouble imageScrollHOffset;
gboolean imageScrollRestored;
int zoomLevel;
gulong sigFileDownload;
......@@ -559,6 +564,29 @@ static void do_capture_widget_sensitivity(EntangleCameraManager *manager)
}
static void do_restore_scroll(GtkWidget *widget,
GdkRectangle *allocation G_GNUC_UNUSED,
EntangleCameraManager *manager)
{
g_return_if_fail(ENTANGLE_IS_CAMERA_MANAGER(manager));
GtkAdjustment *hadjust;
GtkAdjustment *vadjust;
EntangleCameraManagerPrivate *priv = manager->priv;
if (!entangle_image_display_get_loaded(ENTANGLE_IMAGE_DISPLAY(widget)))
return;
hadjust = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(priv->imageScroll));
vadjust = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(priv->imageScroll));
gtk_adjustment_set_value(hadjust,
priv->imageScrollHOffset);
gtk_adjustment_set_value(vadjust,
priv->imageScrollVOffset);
priv->imageScrollRestored = TRUE;
}
static void do_select_image(EntangleCameraManager *manager,
EntangleImage *image)
{
......@@ -567,6 +595,8 @@ static void do_select_image(EntangleCameraManager *manager,
GList *newimages = NULL;
GList *oldimages;
GList *tmp;
GtkAdjustment *hadjust;
GtkAdjustment *vadjust;
EntangleCameraManagerPrivate *priv = manager->priv;
EntanglePreferences *prefs = entangle_application_get_preferences(priv->application);
......@@ -612,6 +642,15 @@ static void do_select_image(EntangleCameraManager *manager,
tmp = tmp->next;
}
hadjust = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(priv->imageScroll));
vadjust = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(priv->imageScroll));
if (priv->imageScrollRestored) {
priv->imageScrollHOffset = gtk_adjustment_get_value(hadjust);
priv->imageScrollVOffset = gtk_adjustment_get_value(vadjust);
priv->imageScrollRestored = FALSE;
}
entangle_image_display_set_image_list(priv->imageDisplay, newimages);
if (image)
......@@ -2961,7 +3000,6 @@ static void entangle_camera_manager_init(EntangleCameraManager *manager)
{
EntangleCameraManagerPrivate *priv;
GtkWidget *display;
GtkWidget *imageScroll;
GtkWidget *iconScroll;
GtkWidget *settingsBox;
GtkWidget *settingsViewport;
......@@ -2984,6 +3022,9 @@ static void entangle_camera_manager_init(EntangleCameraManager *manager)
if (error)
g_error(_("Could not load user interface definition file: %s"), error->message);
priv->imageScrollHOffset = 0;
priv->imageScrollVOffset = 0;
gtk_builder_connect_signals(priv->builder, manager);
win = GTK_WIDGET(gtk_builder_get_object(priv->builder, "camera-manager"));
......@@ -2995,10 +3036,11 @@ static void entangle_camera_manager_init(EntangleCameraManager *manager)
gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu), monitorMenu);
imageViewport = gtk_viewport_new(NULL, NULL);
imageScroll = gtk_scrolled_window_new(gtk_scrollable_get_hadjustment(GTK_SCROLLABLE(imageViewport)),
gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(imageViewport)));
priv->imageScroll = GTK_SCROLLED_WINDOW
(gtk_scrolled_window_new(gtk_scrollable_get_hadjustment(GTK_SCROLLABLE(imageViewport)),
gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(imageViewport))));
gtk_container_add(GTK_CONTAINER(imageScroll), imageViewport);
gtk_container_add(GTK_CONTAINER(priv->imageScroll), imageViewport);
priv->imageLoader = entangle_image_loader_new();
priv->thumbLoader = entangle_thumbnail_loader_new(96, 96);
......@@ -3019,6 +3061,9 @@ static void entangle_camera_manager_init(EntangleCameraManager *manager)
g_object_set(priv->sessionBrowser, "thumbnail-loader", priv->thumbLoader, NULL);
g_signal_connect(priv->imageDisplay, "size-allocate",
G_CALLBACK(do_restore_scroll), manager);
g_signal_connect(priv->sessionBrowser, "selection-changed",
G_CALLBACK(do_session_image_selected), manager);
g_signal_connect(priv->sessionBrowser, "button-press-event",
......@@ -3047,7 +3092,7 @@ static void entangle_camera_manager_init(EntangleCameraManager *manager)
gtk_container_add(GTK_CONTAINER(imageViewport), GTK_WIDGET(priv->imageDisplay));
ViewOvBox_SetOver(VIEW_OV_BOX(priv->imageDrawer), GTK_WIDGET(priv->imageStatusbar));
ViewOvBox_SetUnder(VIEW_OV_BOX(priv->imageDrawer), imageScroll);
ViewOvBox_SetUnder(VIEW_OV_BOX(priv->imageDrawer), GTK_WIDGET(priv->imageScroll));
ViewAutoDrawer_SetOffset(VIEW_AUTODRAWER(priv->imageDrawer), -1);
ViewAutoDrawer_SetFill(VIEW_AUTODRAWER(priv->imageDrawer), TRUE);
ViewAutoDrawer_SetOverlapPixels(VIEW_AUTODRAWER(priv->imageDrawer), 1);
......
......@@ -1025,6 +1025,17 @@ EntangleImageDisplayGrid entangle_image_display_get_grid_display(EntangleImageDi
}
gboolean entangle_image_display_get_loaded(EntangleImageDisplay *display)
{
EntangleImage *image = entangle_image_display_get_image(display);
GdkPixbuf *pixbuf = NULL;
if (image)
pixbuf = entangle_image_get_pixbuf(image);
return pixbuf != NULL;
}
/*
* Local variables:
......
......@@ -91,6 +91,8 @@ void entangle_image_display_set_focus_point(EntangleImageDisplay *display,
gboolean enabled);
gboolean entangle_image_display_get_focus_point(EntangleImageDisplay *display);
gboolean entangle_image_display_get_loaded(EntangleImageDisplay *display);
typedef enum {
ENTANGLE_IMAGE_DISPLAY_GRID_NONE,
ENTANGLE_IMAGE_DISPLAY_GRID_CENTER_LINES,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment