Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / core / crsr / datecontentcontrolbutton.cxx
blob9de971b6f9f6e9c5d3c1e0c4c8b0c0fc43aff616
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2 /*
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/.
8 */
10 #include <datecontentcontrolbutton.hxx>
12 #include <svl/numformat.hxx>
13 #include <tools/date.hxx>
14 #include <vcl/svapp.hxx>
16 #include <edtwin.hxx>
17 #include <formatcontentcontrol.hxx>
18 #include <view.hxx>
19 #include <wrtsh.hxx>
21 IMPL_LINK(SwDateContentControlButton, SelectHandler, weld::Calendar&, rCalendar, void)
23 const Date& rNullDate = m_pNumberFormatter->GetNullDate();
24 double fDate = rCalendar.get_date() - rNullDate;
25 m_xPopup->popdown();
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()
67 m_xCalendar.reset();
68 SwContentControlButton::DestroyPopup();
71 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */