diff options
author | Caolán McNamara <caolanm@redhat.com> | 2020-07-15 11:54:52 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2020-07-15 15:02:27 +0200 |
commit | c8fed68b953e5c1b3101758413fac4809ff3380e (patch) | |
tree | c288041f51e02ed9f2d03255a2dc9e7c3a14c871 /vcl/source/control | |
parent | db9d871b2dc89ac1a09e17ec08a1570dae546025 (diff) |
move SVTXDateField to toolkit
and svtools CalendarField to vcl
Change-Id: I6f3e9a71f21ac7ca70f8172d4f8be4804f3b1c7f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98818
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl/source/control')
-rw-r--r-- | vcl/source/control/calendar.cxx | 208 |
1 files changed, 208 insertions, 0 deletions
diff --git a/vcl/source/control/calendar.cxx b/vcl/source/control/calendar.cxx index c306185f1907..083bfa6d34d6 100644 --- a/vcl/source/control/calendar.cxx +++ b/vcl/source/control/calendar.cxx @@ -22,7 +22,9 @@ #include <vcl/menu.hxx> #include <vcl/settings.hxx> #include <vcl/event.hxx> +#include <vcl/calendar.hxx> #include <vcl/commandevent.hxx> +#include <vcl/dockwin.hxx> #include <unotools/calendarwrapper.hxx> #include <unotools/localedatawrapper.hxx> #include <com/sun/star/i18n/Weekdays.hpp> @@ -1511,4 +1513,210 @@ Size Calendar::GetOptimalSize() const return CalcWindowSizePixel(); } +namespace +{ + class ImplCFieldFloat final + { + private: + std::unique_ptr<weld::Builder> mxBuilder; + std::unique_ptr<weld::Container> mxContainer; + std::unique_ptr<weld::Calendar> mxCalendar; + std::unique_ptr<weld::Button> mxTodayBtn; + std::unique_ptr<weld::Button> mxNoneBtn; + + public: + ImplCFieldFloat(vcl::Window* pContainer) + : mxBuilder(Application::CreateInterimBuilder(pContainer, "svt/ui/calendar.ui")) + , mxContainer(mxBuilder->weld_container("Calendar")) + , mxCalendar(mxBuilder->weld_calendar("date")) + , mxTodayBtn(mxBuilder->weld_button("today")) + , mxNoneBtn(mxBuilder->weld_button("none")) + { + } + + weld::Calendar* GetCalendar() { return mxCalendar.get(); } + weld::Button* EnableTodayBtn(bool bEnable); + weld::Button* EnableNoneBtn(bool bEnable); + + void GrabFocus() + { + mxCalendar->grab_focus(); + } + }; +} + +struct ImplCFieldFloatWin : public DockingWindow +{ + explicit ImplCFieldFloatWin(vcl::Window* pParent); + virtual void dispose() override; + virtual ~ImplCFieldFloatWin() override; + virtual void GetFocus() override; + + VclPtr<vcl::Window> mxBox; + std::unique_ptr<ImplCFieldFloat> mxWidget; +}; + +ImplCFieldFloatWin::ImplCFieldFloatWin(vcl::Window* pParent) + : DockingWindow(pParent, "InterimDockParent", "svx/ui/interimdockparent.ui") + , mxBox(get("box")) +{ + setDeferredProperties(); + mxWidget.reset(new ImplCFieldFloat(mxBox.get())); +} + +ImplCFieldFloatWin::~ImplCFieldFloatWin() +{ + disposeOnce(); +} + +void ImplCFieldFloatWin::dispose() +{ + mxWidget.reset(); + mxBox.disposeAndClear(); + DockingWindow::dispose(); +} + +void ImplCFieldFloatWin::GetFocus() +{ + DockingWindow::GetFocus(); + if (!mxWidget) + return; + mxWidget->GrabFocus(); +} + +weld::Button* ImplCFieldFloat::EnableTodayBtn(bool bEnable) +{ + mxTodayBtn->set_visible(bEnable); + return bEnable ? mxTodayBtn.get() : nullptr; +} + +weld::Button* ImplCFieldFloat::EnableNoneBtn(bool bEnable) +{ + mxNoneBtn->set_visible(bEnable); + return bEnable ? mxNoneBtn.get() : nullptr; +} + +CalendarField::CalendarField(vcl::Window* pParent, WinBits nWinStyle) + : DateField(pParent, nWinStyle) + , mpFloatWin(nullptr) + , mpTodayBtn(nullptr) + , mpNoneBtn(nullptr) + , mbToday(false) + , mbNone(false) +{ +} + +CalendarField::~CalendarField() +{ + disposeOnce(); +} + +void CalendarField::dispose() +{ + mpTodayBtn = nullptr; + mpNoneBtn = nullptr; + mpFloatWin.disposeAndClear(); + DateField::dispose(); +} + +IMPL_LINK(CalendarField, ImplSelectHdl, weld::Calendar&, rCalendar, void) +{ + Date aNewDate = rCalendar.get_date(); + + vcl::Window::GetDockingManager()->EndPopupMode(mpFloatWin); + mpFloatWin->EnableDocking(false); + EndDropDown(); + GrabFocus(); + if ( IsEmptyDate() || ( aNewDate != GetDate() ) ) + { + SetDate( aNewDate ); + SetModifyFlag(); + Modify(); + } +} + +IMPL_LINK(CalendarField, ImplClickHdl, weld::Button&, rBtn, void) +{ + vcl::Window::GetDockingManager()->EndPopupMode(mpFloatWin); + mpFloatWin->EnableDocking(false); + EndDropDown(); + GrabFocus(); + + if (&rBtn == mpTodayBtn) + { + Date aToday( Date::SYSTEM ); + if ( (aToday != GetDate()) || IsEmptyDate() ) + { + SetDate( aToday ); + SetModifyFlag(); + Modify(); + } + } + else if (&rBtn == mpNoneBtn) + { + if ( !IsEmptyDate() ) + { + SetEmptyDate(); + SetModifyFlag(); + Modify(); + } + } +} + +IMPL_LINK_NOARG(CalendarField, ImplPopupModeEndHdl, FloatingWindow*, void) +{ + EndDropDown(); + GrabFocus(); +} + +bool CalendarField::ShowDropDown( bool bShow ) +{ + if ( bShow ) + { + if ( !mpFloatWin ) + mpFloatWin = VclPtr<ImplCFieldFloatWin>::Create( this ); + + Date aDate = GetDate(); + if ( IsEmptyDate() || !aDate.IsValidAndGregorian() ) + { + aDate = Date( Date::SYSTEM ); + } + weld::Calendar* pCalendar = mpFloatWin->mxWidget->GetCalendar(); + pCalendar->set_date( aDate ); + pCalendar->connect_activated(LINK(this, CalendarField, ImplSelectHdl)); + mpTodayBtn = mpFloatWin->mxWidget->EnableTodayBtn(mbToday); + mpNoneBtn = mpFloatWin->mxWidget->EnableNoneBtn(mbNone); + if (mpTodayBtn) + mpTodayBtn->connect_clicked( LINK( this, CalendarField, ImplClickHdl ) ); + if (mpNoneBtn) + mpNoneBtn->connect_clicked( LINK( this, CalendarField, ImplClickHdl ) ); + Point aPos(GetParent()->OutputToScreenPixel(GetPosPixel())); + tools::Rectangle aRect(aPos, GetSizePixel()); + aRect.AdjustBottom( -1 ); + DockingManager* pDockingManager = vcl::Window::GetDockingManager(); + mpFloatWin->EnableDocking(true); + pDockingManager->SetPopupModeEndHdl(mpFloatWin, LINK(this, CalendarField, ImplPopupModeEndHdl)); + pDockingManager->StartPopupMode(mpFloatWin, aRect, FloatWinPopupFlags::Down | FloatWinPopupFlags::GrabFocus); + } + else + { + vcl::Window::GetDockingManager()->EndPopupMode(mpFloatWin); + mpFloatWin->EnableDocking(false); + EndDropDown(); + } + return true; +} + +void CalendarField::StateChanged( StateChangedType nStateChange ) +{ + DateField::StateChanged( nStateChange ); + + if ( ( nStateChange == StateChangedType::Style ) && GetSubEdit() ) + { + WinBits nAllAlignmentBits = ( WB_LEFT | WB_CENTER | WB_RIGHT | WB_TOP | WB_VCENTER | WB_BOTTOM ); + WinBits nMyAlignment = GetStyle() & nAllAlignmentBits; + GetSubEdit()->SetStyle( ( GetSubEdit()->GetStyle() & ~nAllAlignmentBits ) | nMyAlignment ); + } +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |