diff options
author | Caolán McNamara <caolanm@redhat.com> | 2019-02-14 21:26:27 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2019-02-15 15:11:58 +0100 |
commit | 03b4d8f486d9ecdfe21a05d6bf65c396a35772f6 (patch) | |
tree | e12a35585430f1cfcac56a202382a30d3d1917f9 /vcl/source | |
parent | 8fdbda18b593e7014e44a0fd590bbf98d83258b7 (diff) |
weld ScDPDateGroupDlg
adding a weld::Calendar and a pretty menubutton to access it, sidestepping the
difficulty of abusing a spinbutton to select a date. The prettiness is wasted
on this hard to find obscure dialog
Change-Id: I51d461fe0220f947c106d96965e6422b4b26575b
Reviewed-on: https://gerrit.libreoffice.org/67863
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl/source')
-rw-r--r-- | vcl/source/app/salvtables.cxx | 55 | ||||
-rw-r--r-- | vcl/source/control/calendar.cxx | 18 |
2 files changed, 73 insertions, 0 deletions
diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx index d783794ca8d2..c24d6f5ab745 100644 --- a/vcl/source/app/salvtables.cxx +++ b/vcl/source/app/salvtables.cxx @@ -36,6 +36,7 @@ #include <utility> #include <tools/helpers.hxx> #include <vcl/builder.hxx> +#include <vcl/calendar.hxx> #include <vcl/combobox.hxx> #include <vcl/lstbox.hxx> #include <vcl/dialog.hxx> @@ -1788,6 +1789,54 @@ public: } }; +class SalInstanceCalendar : public SalInstanceWidget, public virtual weld::Calendar +{ +private: + VclPtr<::Calendar> m_xCalendar; + + DECL_LINK(SelectHdl, ::Calendar*, void); + DECL_LINK(ActivateHdl, ::Calendar*, void); + +public: + SalInstanceCalendar(::Calendar* pCalendar, bool bTakeOwnership) + : SalInstanceWidget(pCalendar, bTakeOwnership) + , m_xCalendar(pCalendar) + { + m_xCalendar->SetSelectHdl(LINK(this, SalInstanceCalendar, SelectHdl)); + m_xCalendar->SetActivateHdl(LINK(this, SalInstanceCalendar, ActivateHdl)); + } + + virtual void set_date(const Date& rDate) override + { + m_xCalendar->SetCurDate(rDate); + } + + virtual Date get_date() const override + { + return m_xCalendar->GetFirstSelectedDate(); + } + + virtual ~SalInstanceCalendar() override + { + m_xCalendar->SetSelectHdl(Link<::Calendar*, void>()); + m_xCalendar->SetActivateHdl(Link<::Calendar*, void>()); + } +}; + +IMPL_LINK_NOARG(SalInstanceCalendar, SelectHdl, ::Calendar*, void) +{ + if (notify_events_disabled()) + return; + signal_selected(); +} + +IMPL_LINK_NOARG(SalInstanceCalendar, ActivateHdl, ::Calendar*, void) +{ + if (notify_events_disabled()) + return; + signal_activated(); +} + namespace { class WeldTextFilter : public TextFilter @@ -3854,6 +3903,12 @@ public: return pImage ? std::make_unique<SalInstanceImage>(pImage, bTakeOwnership) : nullptr; } + virtual std::unique_ptr<weld::Calendar> weld_calendar(const OString &id, bool bTakeOwnership) override + { + Calendar* pCalendar = m_xBuilder->get<Calendar>(id); + return pCalendar ? std::make_unique<SalInstanceCalendar>(pCalendar, bTakeOwnership) : nullptr; + } + virtual std::unique_ptr<weld::Entry> weld_entry(const OString &id, bool bTakeOwnership) override { Edit* pEntry = m_xBuilder->get<Edit>(id); diff --git a/vcl/source/control/calendar.cxx b/vcl/source/control/calendar.cxx index d9656d3e60ff..9bd1c17b31e1 100644 --- a/vcl/source/control/calendar.cxx +++ b/vcl/source/control/calendar.cxx @@ -1057,6 +1057,8 @@ void Calendar::MouseButtonDown( const MouseEvent& rMEvt ) ImplMouseSelect( aTempDate, nHitTest, false ); } + if (rMEvt.GetClicks() == 2) + maActivateHdl.Call(this); } } } @@ -1135,6 +1137,9 @@ void Calendar::KeyInput( const KeyEvent& rKEvt ) aNewDate.AddDays( aNewDate.GetDaysInMonth() ); break; + case KEY_RETURN: + break; + default: Control::KeyInput( rKEvt ); break; @@ -1147,6 +1152,14 @@ void Calendar::KeyInput( const KeyEvent& rKEvt ) Select(); mbTravelSelect = false; } + + if (rKEvt.GetKeyCode().GetCode() == KEY_RETURN) + { + if (maActivateHdl.IsSet()) + maActivateHdl.Call(this); + else + Control::KeyInput(rKEvt); + } } void Calendar::Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& ) @@ -1547,4 +1560,9 @@ Size Calendar::CalcWindowSizePixel() const return aSize; } +Size Calendar::GetOptimalSize() const +{ + return CalcWindowSizePixel(); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |