Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / core / crsr / DateFormFieldButton.cxx
blobb16845a63318895516820ef64101c19cb80dc217
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 <DateFormFieldButton.hxx>
11 #include <edtwin.hxx>
12 #include <bookmark.hxx>
13 #include <tools/date.hxx>
14 #include <svl/numformat.hxx>
15 #include <vcl/svapp.hxx>
17 IMPL_LINK(DateFormFieldButton, ImplSelectHdl, weld::Calendar&, rCalendar, void)
19 if (m_pDateFieldmark)
21 const Date& rNullDate = m_pNumberFormatter->GetNullDate();
22 double dDate = rCalendar.get_date() - rNullDate;
23 m_pDateFieldmark->SetCurrentDate(dDate);
25 m_xFieldPopup->popdown();
28 DateFormFieldButton::DateFormFieldButton(SwEditWin* pEditWin, sw::mark::DateFieldmark& rFieldmark,
29 SvNumberFormatter* pNumberFormatter)
30 : FormFieldButton(pEditWin, rFieldmark)
31 , m_pNumberFormatter(pNumberFormatter)
32 , m_pDateFieldmark(dynamic_cast<sw::mark::DateFieldmark*>(&m_rFieldmark))
36 DateFormFieldButton::~DateFormFieldButton() { disposeOnce(); }
38 void DateFormFieldButton::LaunchPopup()
40 m_xFieldPopupBuilder
41 = Application::CreateBuilder(GetFrameWeld(), "modules/swriter/ui/calendar.ui");
42 m_xFieldPopup = m_xFieldPopupBuilder->weld_popover("Calendar");
43 m_xCalendar = m_xFieldPopupBuilder->weld_calendar("date");
44 if (m_pDateFieldmark)
46 std::pair<bool, double> aResult = m_pDateFieldmark->GetCurrentDate();
47 if (aResult.first)
49 const Date& rNullDate = m_pNumberFormatter->GetNullDate();
50 m_xCalendar->set_date(rNullDate + sal_Int32(aResult.second));
53 m_xCalendar->connect_activated(LINK(this, DateFormFieldButton, ImplSelectHdl));
54 FormFieldButton::LaunchPopup();
55 m_xCalendar->grab_focus();
58 void DateFormFieldButton::DestroyPopup()
60 m_xCalendar.reset();
61 FormFieldButton::DestroyPopup();
64 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */