Resolves: tdf#144793 add scrollbar to sql editview
Change-Id: I23126a89c136a134590900c38ccd589fb4ea29a2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124546
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/dbaccess/source/ui/control/sqledit.cxx b/dbaccess/source/ui/control/sqledit.cxx
index a61f9d8..a556645 100644
--- a/dbaccess/source/ui/control/sqledit.cxx
+++ b/dbaccess/source/ui/control/sqledit.cxx
@@ -68,12 +68,14 @@ private:
SQLEditView& editor_;
};
SQLEditView::SQLEditView()
: m_aUpdateDataTimer("dbaccess SQLEditView m_aUpdateDataTimer")
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()
@@ -129,6 +131,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));
@@ -432,6 +435,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 604cb17..709ac41 100644
--- a/dbaccess/source/ui/dlg/directsql.cxx
+++ b/dbaccess/source/ui/dlg/directsql.cxx
@@ -51,7 +51,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 99d5e63..0f2ecc8 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 f67ebbe..9805c2a 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_timerUndoActionCreation("dbaccess OQueryTextView m_timerUndoActionCreation")
, m_timerInvalidate("dbaccess OQueryTextView m_timerInvalidate")
diff --git a/dbaccess/uiconfig/ui/directsqldialog.ui b/dbaccess/uiconfig/ui/directsqldialog.ui
index 8d8b57d..ede0bd8 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 3688fd85..ed31cfc 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">