dbaccess/source/ui/control/sqledit.cxx | 68 ++++++++++++++++++++++- dbaccess/source/ui/dlg/directsql.cxx | 2 dbaccess/source/ui/inc/sqledit.hxx | 11 +++ dbaccess/source/ui/querydesign/QueryTextView.cxx | 2 dbaccess/uiconfig/ui/directsqldialog.ui | 4 + dbaccess/uiconfig/ui/queryview.ui | 4 + 6 files changed, 84 insertions(+), 7 deletions(-)
New commits: commit 4df823c52b02b7cb81e97c9b999a7e7a2296a602 Author: Caolán McNamara <caol...@redhat.com> AuthorDate: Mon Nov 1 11:48:13 2021 +0000 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Tue Nov 2 11:39:33 2021 +0100 Resolves: tdf#144793 add scrollbar to sql editview Change-Id: I23126a89c136a134590900c38ccd589fb4ea29a2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124550 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> diff --git a/dbaccess/source/ui/control/sqledit.cxx b/dbaccess/source/ui/control/sqledit.cxx index cae055b20558..c379ad5fcc32 100644 --- a/dbaccess/source/ui/control/sqledit.cxx +++ b/dbaccess/source/ui/control/sqledit.cxx @@ -67,11 +67,14 @@ private: SQLEditView& editor_; }; -SQLEditView::SQLEditView() - : m_aHighlighter(HighlighterLanguage::SQL) +SQLEditView::SQLEditView(std::unique_ptr<weld::ScrolledWindow> xScrolledWindow) + : m_xScrolledWindow(std::move(xScrolledWindow)) + , m_aUpdateDataTimer("dbaccess SQLEditView m_aUpdateDataTimer") + , m_aHighlighter(HighlighterLanguage::SQL) , m_bInUpdate(false) , m_bDisableInternalUndo(false) { + m_xScrolledWindow->connect_vadjustment_changed(LINK(this, SQLEditView, ScrollHdl)); } void SQLEditView::DisableInternalUndo() @@ -127,6 +130,7 @@ void SQLEditView::SetDrawingArea(weld::DrawingArea* pDrawingArea) rEditEngine.SetDefaultHorizontalTextDirection(EEHorizontalTextDirection::L2R); rEditEngine.SetModifyHdl(LINK(this, SQLEditView, ModifyHdl)); + rEditEngine.SetStatusEventHdl(LINK(this, SQLEditView, EditStatusHdl)); m_aUpdateDataTimer.SetTimeout(150); m_aUpdateDataTimer.SetInvokeHandler(LINK(this, SQLEditView, ImplUpdateDataHdl)); @@ -430,6 +434,66 @@ bool SQLEditView::Command(const CommandEvent& rCEvt) return WeldEditView::Command(rCEvt); } +void SQLEditView::EditViewScrollStateChange() +{ + // editengine height has changed or editview scroll pos has changed + SetScrollBarRange(); +} + +void SQLEditView::SetScrollBarRange() +{ + EditEngine *pEditEngine = GetEditEngine(); + if (!pEditEngine) + return; + if (!m_xScrolledWindow) + return; + EditView* pEditView = GetEditView(); + if (!pEditView) + return; + + int nVUpper = pEditEngine->GetTextHeight(); + int nVCurrentDocPos = pEditView->GetVisArea().Top(); + const Size aOut(pEditView->GetOutputArea().GetSize()); + int nVStepIncrement = aOut.Height() * 2 / 10; + int nVPageIncrement = aOut.Height() * 8 / 10; + int nVPageSize = aOut.Height(); + + /* limit the page size to below nUpper because gtk's gtk_scrolled_window_start_deceleration has + effectively... + + lower = gtk_adjustment_get_lower + upper = gtk_adjustment_get_upper - gtk_adjustment_get_page_size + + and requires that upper > lower or the deceleration animation never ends + */ + nVPageSize = std::min(nVPageSize, nVUpper); + + m_xScrolledWindow->vadjustment_configure(nVCurrentDocPos, 0, nVUpper, + nVStepIncrement, nVPageIncrement, nVPageSize); +} + +IMPL_LINK_NOARG(SQLEditView, ScrollHdl, weld::ScrolledWindow&, void) +{ + DoScroll(); +} + +IMPL_LINK_NOARG(SQLEditView, EditStatusHdl, EditStatus&, void) +{ + Resize(); +} + +void SQLEditView::DoScroll() +{ + if (m_xEditView) + { + auto currentDocPos = m_xEditView->GetVisArea().Top(); + auto nDiff = currentDocPos - m_xScrolledWindow->vadjustment_get_value(); + // we expect SetScrollBarRange callback to be triggered by Scroll + // to set where we ended up + m_xEditView->Scroll(0, nDiff); + } +} + void SQLEditView::ConfigurationChanged(utl::ConfigurationBroadcaster*, ConfigurationHints) { UpdateData(); diff --git a/dbaccess/source/ui/dlg/directsql.cxx b/dbaccess/source/ui/dlg/directsql.cxx index 03d7b2115dc8..93c24612a6f3 100644 --- a/dbaccess/source/ui/dlg/directsql.cxx +++ b/dbaccess/source/ui/dlg/directsql.cxx @@ -48,7 +48,7 @@ namespace dbaui , m_xShowOutput(m_xBuilder->weld_check_button("showoutput")) , m_xOutput(m_xBuilder->weld_text_view("output")) , m_xClose(m_xBuilder->weld_button("close")) - , m_xSQL(new SQLEditView) + , m_xSQL(new SQLEditView(m_xBuilder->weld_scrolled_window("scrolledwindow", true))) , m_xSQLEd(new weld::CustomWeld(*m_xBuilder, "sql", *m_xSQL)) , m_nStatusCount(1) , m_xConnection(_rxConn) diff --git a/dbaccess/source/ui/inc/sqledit.hxx b/dbaccess/source/ui/inc/sqledit.hxx index 99d5e636c24e..0f2ecc8b60eb 100644 --- a/dbaccess/source/ui/inc/sqledit.hxx +++ b/dbaccess/source/ui/inc/sqledit.hxx @@ -36,6 +36,7 @@ namespace dbaui class ChangesListener; friend class ChangesListener; + std::unique_ptr<weld::ScrolledWindow> m_xScrolledWindow; Link<LinkParamNone*,void> m_aModifyLink; const svtools::ColorConfig m_aColorConfig; Timer m_aUpdateDataTimer; @@ -52,6 +53,8 @@ namespace dbaui DECL_LINK(ModifyHdl, LinkParamNone*, void); DECL_LINK(ImplUpdateDataHdl, Timer*, void); + DECL_LINK(ScrollHdl, weld::ScrolledWindow&, void); + DECL_LINK(EditStatusHdl, EditStatus&, void); Color GetColorValue(TokenType aToken); @@ -62,8 +65,14 @@ namespace dbaui static void SetItemPoolFont(SfxItemPool* pItemPool); void UpdateData(); + + void SetScrollBarRange(); + void DoScroll(); + + virtual void EditViewScrollStateChange() override; + public: - SQLEditView(); + SQLEditView(std::unique_ptr<weld::ScrolledWindow> xScrolledWindow); virtual void makeEditEngine() override; virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override; virtual ~SQLEditView() override; diff --git a/dbaccess/source/ui/querydesign/QueryTextView.cxx b/dbaccess/source/ui/querydesign/QueryTextView.cxx index 4af5a1c591a8..600f18c20300 100644 --- a/dbaccess/source/ui/querydesign/QueryTextView.cxx +++ b/dbaccess/source/ui/querydesign/QueryTextView.cxx @@ -33,7 +33,7 @@ using namespace ::com::sun::star::lang; OQueryTextView::OQueryTextView(OQueryContainerWindow* pParent, OQueryController& rController) : InterimItemWindow(pParent, "dbaccess/ui/queryview.ui", "QueryView") , m_rController(rController) - , m_xSQL(new SQLEditView) + , m_xSQL(new SQLEditView(m_xBuilder->weld_scrolled_window("scrolledwindow", true))) , m_xSQLEd(new weld::CustomWeld(*m_xBuilder, "sql", *m_xSQL)) , m_bStopTimer(false) { diff --git a/dbaccess/uiconfig/ui/directsqldialog.ui b/dbaccess/uiconfig/ui/directsqldialog.ui index 7546c9c7472d..60245375fa76 100644 --- a/dbaccess/uiconfig/ui/directsqldialog.ui +++ b/dbaccess/uiconfig/ui/directsqldialog.ui @@ -79,12 +79,14 @@ <property name="margin-start">12</property> <property name="margin-top">6</property> <child> - <object class="GtkScrolledWindow"> + <object class="GtkScrolledWindow" id="scrolledwindow"> <property name="visible">True</property> <property name="can_focus">True</property> <property name="hexpand">True</property> <property name="vexpand">True</property> <property name="border_width">0</property> + <property name="hscrollbar-policy">never</property> + <property name="vscrollbar-policy">always</property> <property name="shadow_type">in</property> <child> <object class="GtkViewport"> diff --git a/dbaccess/uiconfig/ui/queryview.ui b/dbaccess/uiconfig/ui/queryview.ui index 3688fd855ece..ed31cfc345cd 100644 --- a/dbaccess/uiconfig/ui/queryview.ui +++ b/dbaccess/uiconfig/ui/queryview.ui @@ -8,12 +8,14 @@ <property name="hexpand">True</property> <property name="vexpand">True</property> <child> - <object class="GtkScrolledWindow"> + <object class="GtkScrolledWindow" id="scrolledwindow"> <property name="visible">True</property> <property name="can_focus">True</property> <property name="hexpand">True</property> <property name="vexpand">True</property> <property name="border_width">0</property> + <property name="hscrollbar-policy">never</property> + <property name="vscrollbar-policy">always</property> <property name="shadow_type">in</property> <child> <object class="GtkViewport">