diff options
author | Caolán McNamara <caolanm@redhat.com> | 2020-11-25 12:13:14 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2020-11-26 15:06:35 +0100 |
commit | 952242a20cdc4a0248a95c1e1d61b1c213ae270a (patch) | |
tree | 7599ba314f80cfb188ae8e42fbe0b1c8f3dd4d70 | |
parent | 59fec754a1523eede0f19a59e4eeeff593a4d688 (diff) |
factor out as a standalone "ButtonPressRepeater" class
Change-Id: Id89d5655c2428cecdaf9faa224133302c6448a87
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106600
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r-- | include/svx/gridctrl.hxx | 11 | ||||
-rw-r--r-- | include/vcl/weldutils.hxx | 19 | ||||
-rw-r--r-- | svx/source/fmcomp/gridctrl.cxx | 62 | ||||
-rw-r--r-- | vcl/source/app/weldutils.cxx | 40 |
4 files changed, 65 insertions, 67 deletions
diff --git a/include/svx/gridctrl.hxx b/include/svx/gridctrl.hxx index 1fb6c19951b6..d5d15d0054e4 100644 --- a/include/svx/gridctrl.hxx +++ b/include/svx/gridctrl.hxx @@ -190,8 +190,8 @@ class NavigationBar final : public InterimItemWindow std::unique_ptr<weld::Button> m_xLastBtn; // Button for 'go to the last record' std::unique_ptr<weld::Button> m_xNewBtn; // Button for 'go to a new record' - AutoTimer m_aNextRepeat; - AutoTimer m_aPrevRepeat; + weld::ButtonPressRepeater m_aPrevRepeater; + weld::ButtonPressRepeater m_aNextRepeater; sal_Int32 m_nCurrentPos; @@ -213,13 +213,6 @@ private: DECL_LINK(OnClick, weld::Button&, void); - DECL_LINK(PrevMousePressHdl, const MouseEvent&, bool); - DECL_LINK(PrevMouseReleaseHdl, const MouseEvent&, bool); - DECL_LINK(NextMousePressHdl, const MouseEvent&, bool); - DECL_LINK(NextMouseReleaseHdl, const MouseEvent&, bool); - DECL_LINK(PrevRepeatTimerHdl, Timer*, void); - DECL_LINK(NextRepeatTimerHdl, Timer*, void); - void PositionDataSource(sal_Int32 nRecord); }; diff --git a/include/vcl/weldutils.hxx b/include/vcl/weldutils.hxx index 9a29e89d7b5f..d956849a3292 100644 --- a/include/vcl/weldutils.hxx +++ b/include/vcl/weldutils.hxx @@ -20,6 +20,7 @@ #include <tools/time.hxx> #include <vcl/dllapi.h> #include <vcl/formatter.hxx> +#include <vcl/timer.hxx> #include <vcl/weld.hxx> class CalendarWrapper; @@ -390,6 +391,24 @@ private: DECL_DLLPRIVATE_LINK(KeyInputHdl, const KeyEvent&, bool); }; +class VCL_DLLPUBLIC ButtonPressRepeater final +{ +private: + weld::Button& m_rButton; + AutoTimer m_aRepeat; + const Link<Button&, void> m_aLink; + bool m_bModKey; + + DECL_LINK(MousePressHdl, const MouseEvent&, bool); + DECL_LINK(MouseReleaseHdl, const MouseEvent&, bool); + DECL_LINK(RepeatTimerHdl, Timer*, void); + +public: + ButtonPressRepeater(weld::Button& rButton, const Link<Button&, void>& rLink); + void Stop() { m_aRepeat.Stop(); } + bool IsModKeyPressed() const { return m_bModKey; } +}; + // get the row the iterator is on VCL_DLLPUBLIC size_t GetAbsPos(const weld::TreeView& rTreeView, const weld::TreeIter& rIter); diff --git a/svx/source/fmcomp/gridctrl.cxx b/svx/source/fmcomp/gridctrl.cxx index c5eb6ba50ac6..b004aed7d7d9 100644 --- a/svx/source/fmcomp/gridctrl.cxx +++ b/svx/source/fmcomp/gridctrl.cxx @@ -317,6 +317,8 @@ NavigationBar::NavigationBar(vcl::Window* pParent) , m_xNextBtn(m_xBuilder->weld_button("next")) , m_xLastBtn(m_xBuilder->weld_button("last")) , m_xNewBtn(m_xBuilder->weld_button("new")) + , m_aPrevRepeater(*m_xPrevBtn, LINK(this,NavigationBar,OnClick)) + , m_aNextRepeater(*m_xNextBtn, LINK(this,NavigationBar,OnClick)) , m_nCurrentPos(-1) , m_bPositioning(false) { @@ -340,19 +342,6 @@ NavigationBar::NavigationBar(vcl::Window* pParent) m_xLastBtn->connect_clicked(LINK(this,NavigationBar,OnClick)); m_xNewBtn->connect_clicked(LINK(this,NavigationBar,OnClick)); - // instead of connect_clicked because we want a button held down to - // repeat the next/prev - m_xPrevBtn->connect_mouse_press(LINK(this, NavigationBar, PrevMousePressHdl)); - m_xNextBtn->connect_mouse_press(LINK(this, NavigationBar, NextMousePressHdl)); - m_xPrevBtn->connect_mouse_release(LINK(this, NavigationBar, PrevMouseReleaseHdl)); - m_xNextBtn->connect_mouse_release(LINK(this, NavigationBar, NextMouseReleaseHdl)); - - auto nRepeatTime = Application::GetSettings().GetMouseSettings().GetButtonRepeat(); - m_aNextRepeat.SetTimeout(nRepeatTime); - m_aNextRepeat.SetInvokeHandler(LINK(this, NavigationBar, NextRepeatTimerHdl)); - m_aPrevRepeat.SetTimeout(nRepeatTime); - m_aPrevRepeat.SetInvokeHandler(LINK(this, NavigationBar, PrevRepeatTimerHdl)); - m_xRecordText->set_label(SvxResId(RID_STR_REC_TEXT)); m_xRecordOf->set_label(SvxResId(RID_STR_REC_FROM_TEXT)); m_xRecordCount->set_label(OUString('?')); @@ -386,49 +375,6 @@ sal_uInt16 NavigationBar::ArrangeControls() return m_xContainer->get_preferred_size().Width(); } -IMPL_LINK_NOARG(NavigationBar, PrevRepeatTimerHdl, Timer*, void) -{ - OnClick(*m_xPrevBtn); -} - -IMPL_LINK_NOARG(NavigationBar, NextRepeatTimerHdl, Timer*, void) -{ - OnClick(*m_xNextBtn); -} - -IMPL_LINK_NOARG(NavigationBar, PrevMousePressHdl, const MouseEvent&, bool) -{ - if (!m_xPrevBtn->get_sensitive()) - return false; - PrevRepeatTimerHdl(nullptr); - if (!m_xPrevBtn->get_sensitive()) - return false; - m_aPrevRepeat.Start(); - return false; -} - -IMPL_LINK_NOARG(NavigationBar, PrevMouseReleaseHdl, const MouseEvent&, bool) -{ - m_aPrevRepeat.Stop(); - return false; -} - -IMPL_LINK_NOARG(NavigationBar, NextMousePressHdl, const MouseEvent&, bool) -{ - if (m_xNextBtn->get_sensitive()) - { - NextRepeatTimerHdl(nullptr); - m_aNextRepeat.Start(); - } - return false; -} - -IMPL_LINK_NOARG(NavigationBar, NextMouseReleaseHdl, const MouseEvent&, bool) -{ - m_aNextRepeat.Stop(); - return false; -} - IMPL_LINK(NavigationBar, OnClick, weld::Button&, rButton, void) { DbGridControl* pParent = static_cast<DbGridControl*>(GetParent()); @@ -631,9 +577,9 @@ void NavigationBar::SetState(DbGridControlNavigationBarState nWhich) if (!bAvailable) { if (pWnd == m_xNextBtn.get()) - m_aNextRepeat.Stop(); + m_aNextRepeater.Stop(); else if (pWnd == m_xPrevBtn.get()) - m_aPrevRepeat.Stop(); + m_aPrevRepeater.Stop(); } } diff --git a/vcl/source/app/weldutils.cxx b/vcl/source/app/weldutils.cxx index 237645076330..76e887c67644 100644 --- a/vcl/source/app/weldutils.cxx +++ b/vcl/source/app/weldutils.cxx @@ -14,6 +14,7 @@ #include <svl/zformat.hxx> #include <vcl/builderpage.hxx> #include <vcl/commandinfoprovider.hxx> +#include <vcl/event.hxx> #include <vcl/settings.hxx> #include <vcl/svapp.hxx> #include <vcl/weldutils.hxx> @@ -546,6 +547,45 @@ void WidgetStatusListener::dispose() mxFrame.clear(); mWidget = nullptr; } + +ButtonPressRepeater::ButtonPressRepeater(weld::Button& rButton, const Link<Button&, void>& rLink) + : m_rButton(rButton) + , m_aLink(rLink) + , m_bModKey(false) +{ + // instead of connect_clicked because we want a button held down to + // repeat the next/prev + m_rButton.connect_mouse_press(LINK(this, ButtonPressRepeater, MousePressHdl)); + m_rButton.connect_mouse_release(LINK(this, ButtonPressRepeater, MouseReleaseHdl)); + + m_aRepeat.SetInvokeHandler(LINK(this, ButtonPressRepeater, RepeatTimerHdl)); +} + +IMPL_LINK(ButtonPressRepeater, MousePressHdl, const MouseEvent&, rMouseEvent, bool) +{ + m_bModKey = rMouseEvent.IsMod1(); + if (!m_rButton.get_sensitive()) + return false; + RepeatTimerHdl(nullptr); + if (!m_rButton.get_sensitive()) + return false; + m_aRepeat.SetTimeout(MouseSettings::GetButtonStartRepeat()); + m_aRepeat.Start(); + return false; +} + +IMPL_LINK_NOARG(ButtonPressRepeater, MouseReleaseHdl, const MouseEvent&, bool) +{ + m_bModKey = false; + m_aRepeat.Stop(); + return false; +} + +IMPL_LINK_NOARG(ButtonPressRepeater, RepeatTimerHdl, Timer*, void) +{ + m_aRepeat.SetTimeout(Application::GetSettings().GetMouseSettings().GetButtonRepeat()); + m_aLink.Call(m_rButton); +} } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |