diff options
author | Caolán McNamara <caolanm@redhat.com> | 2020-06-21 17:44:08 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2020-06-21 21:14:55 +0200 |
commit | 1b96a96d4a3236fe4b2dcef08b85330a328060ec (patch) | |
tree | 78435ce7cfadc5cffbf09ff98b2892ded5aa76f1 | |
parent | bafd50ee06d982e19d54fae0f9d8f968a2dedbd4 (diff) |
weld date selection widget
Change-Id: If7ea24d85c20f1bda972688e97c7f74b26e533e1
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96817
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r-- | sw/UIConfig_swriter.mk | 1 | ||||
-rw-r--r-- | sw/source/core/crsr/DateFormFieldButton.cxx | 63 | ||||
-rw-r--r-- | sw/uiconfig/swriter/ui/calendar.ui | 25 |
3 files changed, 70 insertions, 19 deletions
diff --git a/sw/UIConfig_swriter.mk b/sw/UIConfig_swriter.mk index f8727a015b82..366c1ed19854 100644 --- a/sw/UIConfig_swriter.mk +++ b/sw/UIConfig_swriter.mk @@ -104,6 +104,7 @@ $(eval $(call gb_UIConfig_add_uifiles,modules/swriter,\ sw/uiconfig/swriter/ui/bibliofragment \ sw/uiconfig/swriter/ui/bulletsandnumbering \ sw/uiconfig/swriter/ui/businessdatapage \ + sw/uiconfig/swriter/ui/calendar \ sw/uiconfig/swriter/ui/cannotsavelabeldialog \ sw/uiconfig/swriter/ui/captiondialog \ sw/uiconfig/swriter/ui/captionoptions \ diff --git a/sw/source/core/crsr/DateFormFieldButton.cxx b/sw/source/core/crsr/DateFormFieldButton.cxx index d5c44f121f42..2d4b66815daf 100644 --- a/sw/source/core/crsr/DateFormFieldButton.cxx +++ b/sw/source/core/crsr/DateFormFieldButton.cxx @@ -11,20 +11,40 @@ #include <edtwin.hxx> #include <bookmrk.hxx> #include <vcl/floatwin.hxx> -#include <vcl/calendar.hxx> +#include <vcl/InterimItemWindow.hxx> #include <tools/date.hxx> #include <svl/zforlist.hxx> namespace { +class SwCalendarBox final : public InterimItemWindow +{ +private: + std::unique_ptr<weld::Calendar> m_xCalendar; + +public: + SwCalendarBox(vcl::Window* pParent) + : InterimItemWindow(pParent, "modules/swriter/ui/calendar.ui", "Calendar") + , m_xCalendar(m_xBuilder->weld_calendar("date")) + { + } + weld::Calendar& get_widget() { return *m_xCalendar; } + virtual ~SwCalendarBox() override { disposeOnce(); } + virtual void dispose() override + { + m_xCalendar.reset(); + InterimItemWindow::dispose(); + } +}; + class SwDatePickerDialog : public FloatingWindow { private: - VclPtr<Calendar> m_pCalendar; + VclPtr<SwCalendarBox> m_xCalendar; sw::mark::DateFieldmark* m_pFieldmark; SvNumberFormatter* m_pNumberFormatter; - DECL_LINK(ImplSelectHdl, Calendar*, void); + DECL_LINK(ImplSelectHdl, weld::Calendar&, void); public: SwDatePickerDialog(SwEditWin* parent, sw::mark::DateFieldmark* pFieldmark, @@ -37,45 +57,50 @@ public: SwDatePickerDialog::SwDatePickerDialog(SwEditWin* parent, sw::mark::DateFieldmark* pFieldmark, SvNumberFormatter* pNumberFormatter) : FloatingWindow(parent, WB_BORDER | WB_SYSTEMWINDOW | WB_NOSHADOW) - , m_pCalendar(VclPtr<Calendar>::Create(this, WB_TABSTOP)) + , m_xCalendar(VclPtr<SwCalendarBox>::Create(this)) , m_pFieldmark(pFieldmark) , m_pNumberFormatter(pNumberFormatter) { + weld::Calendar& rCalendar = m_xCalendar->get_widget(); + if (m_pFieldmark != nullptr) { std::pair<bool, double> aResult = m_pFieldmark->GetCurrentDate(); if (aResult.first) { const Date& rNullDate = m_pNumberFormatter->GetNullDate(); - m_pCalendar->SetCurDate(rNullDate + sal_Int32(aResult.second)); + rCalendar.set_date(rNullDate + sal_Int32(aResult.second)); } } - m_pCalendar->SetSelectHdl(LINK(this, SwDatePickerDialog, ImplSelectHdl)); - m_pCalendar->SetOutputSizePixel(m_pCalendar->CalcWindowSizePixel()); - m_pCalendar->Show(); - SetOutputSizePixel(m_pCalendar->GetSizePixel()); + + Size lbSize(rCalendar.get_preferred_size()); + + m_xCalendar->SetSizePixel(lbSize); + rCalendar.connect_activated(LINK(this, SwDatePickerDialog, ImplSelectHdl)); + m_xCalendar->Show(); + + rCalendar.grab_focus(); + + SetSizePixel(lbSize); } SwDatePickerDialog::~SwDatePickerDialog() { disposeOnce(); } void SwDatePickerDialog::dispose() { - m_pCalendar.clear(); + m_xCalendar.disposeAndClear(); FloatingWindow::dispose(); } -IMPL_LINK(SwDatePickerDialog, ImplSelectHdl, Calendar*, pCalendar, void) +IMPL_LINK(SwDatePickerDialog, ImplSelectHdl, weld::Calendar&, rCalendar, void) { - if (!pCalendar->IsTravelSelect()) + if (m_pFieldmark != nullptr) { - if (m_pFieldmark != nullptr) - { - const Date& rNullDate = m_pNumberFormatter->GetNullDate(); - double dDate = pCalendar->GetFirstSelectedDate() - rNullDate; - m_pFieldmark->SetCurrentDate(dDate); - } - EndPopupMode(); + const Date& rNullDate = m_pNumberFormatter->GetNullDate(); + double dDate = rCalendar.get_date() - rNullDate; + m_pFieldmark->SetCurrentDate(dDate); } + EndPopupMode(); } DateFormFieldButton::DateFormFieldButton(SwEditWin* pEditWin, sw::mark::DateFieldmark& rFieldmark, diff --git a/sw/uiconfig/swriter/ui/calendar.ui b/sw/uiconfig/swriter/ui/calendar.ui new file mode 100644 index 000000000000..9939873527e2 --- /dev/null +++ b/sw/uiconfig/swriter/ui/calendar.ui @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Generated with glade 3.22.2 --> +<interface domain="sw"> + <requires lib="gtk+" version="3.18"/> + <object class="GtkBox" id="Calendar"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="orientation">vertical</property> + <property name="spacing">6</property> + <child> + <object class="GtkCalendar" id="date"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="year">2019</property> + <property name="month">1</property> + <property name="day">14</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + </object> +</interface> |