1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <datecontentcontrolbutton.hxx>
12 #include <svl/numformat.hxx>
13 #include <tools/date.hxx>
14 #include <vcl/svapp.hxx>
17 #include <formatcontentcontrol.hxx>
21 IMPL_LINK(SwDateContentControlButton
, SelectHandler
, weld::Calendar
&, rCalendar
, void)
23 const Date
& rNullDate
= m_pNumberFormatter
->GetNullDate();
24 double fDate
= rCalendar
.get_date() - rNullDate
;
26 m_pContentControl
->SetSelectedDate(fDate
);
27 SwView
& rView
= static_cast<SwEditWin
*>(GetParent())->GetView();
28 SwWrtShell
& rWrtShell
= rView
.GetWrtShell();
29 rWrtShell
.GotoContentControl(*m_pContentControl
->GetFormatContentControl());
32 SwDateContentControlButton::SwDateContentControlButton(
33 SwEditWin
* pEditWin
, const std::shared_ptr
<SwContentControl
>& pContentControl
,
34 SvNumberFormatter
* pNumberFormatter
)
35 : SwContentControlButton(pEditWin
, pContentControl
)
36 , m_pNumberFormatter(pNumberFormatter
)
40 SwDateContentControlButton::~SwDateContentControlButton() { disposeOnce(); }
42 void SwDateContentControlButton::LaunchPopup()
44 m_xPopupBuilder
= Application::CreateBuilder(GetFrameWeld(),
45 "modules/swriter/ui/contentcontrolcalendar.ui");
46 m_xPopup
= m_xPopupBuilder
->weld_popover("Calendar");
47 m_xCalendar
= m_xPopupBuilder
->weld_calendar("date");
49 // Read the doc model.
50 if (m_pContentControl
)
52 const Date
& rNullDate
= m_pNumberFormatter
->GetNullDate();
53 double fCurrentDate
= m_pContentControl
->GetCurrentDateValue();
54 if (fCurrentDate
!= 0)
56 m_xCalendar
->set_date(rNullDate
+ sal_Int32(fCurrentDate
));
60 m_xCalendar
->connect_activated(LINK(this, SwDateContentControlButton
, SelectHandler
));
61 SwContentControlButton::LaunchPopup();
62 m_xCalendar
->grab_focus();
65 void SwDateContentControlButton::DestroyPopup()
68 SwContentControlButton::DestroyPopup();
71 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */