From 1648a193c23a5e42acab91e8918322047fdd7a14 Mon Sep 17 00:00:00 2001 From: gustav_b Date: Thu, 20 Sep 2007 08:17:58 +0000 Subject: [PATCH] Add scrolling of dock on DockItem::present. --- src/ui/widget/dock-item.cpp | 8 +++++--- src/ui/widget/dock.cpp | 18 ++++++++++++++++++ src/ui/widget/dock.h | 3 +++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/ui/widget/dock-item.cpp b/src/ui/widget/dock-item.cpp index 372fe5d9d..2187c33e9 100644 --- a/src/ui/widget/dock-item.cpp +++ b/src/ui/widget/dock-item.cpp @@ -269,7 +269,7 @@ DockItem::show_all() void DockItem::present() { - // iconified or unattached + if (isIconified() || !isAttached()) { show(); } @@ -280,11 +280,13 @@ DockItem::present() GTK_WIDGET (_gdl_dock_item)); if (i >= 0) gtk_notebook_set_current_page (GTK_NOTEBOOK (_gdl_dock_item->parent), i); - return; - } + } // always grab focus, even if we're already present grab_focus(); + + if (!isFloating() && getWidget().is_realized()) + _dock.scrollToItem(*this); } diff --git a/src/ui/widget/dock.cpp b/src/ui/widget/dock.cpp index 0f92f7217..f282449dd 100644 --- a/src/ui/widget/dock.cpp +++ b/src/ui/widget/dock.cpp @@ -15,6 +15,8 @@ #include "dock.h" +#include + namespace Inkscape { namespace UI { namespace Widget { @@ -196,6 +198,22 @@ Dock::toggleDockable(int width, int height) } +void +Dock::scrollToItem(DockItem& item) +{ + int item_x, item_y; + item.getWidget().translate_coordinates(getWidget(), 0, 0, item_x, item_y); + + int dock_height = getWidget().get_height(), item_height = item.getWidget().get_height(); + double vadjustment = _scrolled_window->get_vadjustment()->get_value(); + + if (item_y < 0) + _scrolled_window->get_vadjustment()->set_value(vadjustment + item_y); + else if (item_y + item_height > dock_height) + _scrolled_window->get_vadjustment()->set_value( + vadjustment + ((item_y + item_height) - dock_height)); +} + Glib::SignalProxy0 Dock::signal_layout_changed() { diff --git a/src/ui/widget/dock.h b/src/ui/widget/dock.h index 3b2cb8d77..3cd29c01f 100644 --- a/src/ui/widget/dock.h +++ b/src/ui/widget/dock.h @@ -51,6 +51,9 @@ public: /** Toggle size of dock between the previous dimensions and the ones sent as parameters */ void toggleDockable(int width=0, int height=0); + /** Scrolls the scrolled window container to make the provided dock item visible, if needed */ + void scrollToItem(DockItem& item); + protected: std::list _dock_items; //< added dock items -- 2.30.2