LibreOffice Module sw (master)  1
DateFormFieldButton.cxx
Go to the documentation of this file.
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.
4  *
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  */
9 
10 #include <DateFormFieldButton.hxx>
11 #include <edtwin.hxx>
12 #include <bookmrk.hxx>
13 #include <tools/date.hxx>
14 #include <svl/zforlist.hxx>
15 #include <vcl/svapp.hxx>
16 
17 IMPL_LINK(DateFormFieldButton, ImplSelectHdl, weld::Calendar&, rCalendar, void)
18 {
19  if (m_pDateFieldmark)
20  {
21  const Date& rNullDate = m_pNumberFormatter->GetNullDate();
22  double dDate = rCalendar.get_date() - rNullDate;
23  m_pDateFieldmark->SetCurrentDate(dDate);
24  }
25  m_xFieldPopup->popdown();
26 }
27 
29  SvNumberFormatter* pNumberFormatter)
30  : FormFieldButton(pEditWin, rFieldmark)
31  , m_pNumberFormatter(pNumberFormatter)
32  , m_pDateFieldmark(dynamic_cast<sw::mark::DateFieldmark*>(&m_rFieldmark))
33 {
34 }
35 
37 
39 {
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)
45  {
46  std::pair<bool, double> aResult = m_pDateFieldmark->GetCurrentDate();
47  if (aResult.first)
48  {
49  const Date& rNullDate = m_pNumberFormatter->GetNullDate();
50  m_xCalendar->set_date(rNullDate + sal_Int32(aResult.second));
51  }
52  }
53  m_xCalendar->connect_activated(LINK(this, DateFormFieldButton, ImplSelectHdl));
55  m_xCalendar->grab_focus();
56 }
57 
59 {
60  m_xCalendar.reset();
62 }
63 
64 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
virtual std::pair< bool, double > GetCurrentDate() const override
Definition: bookmrk.cxx:864
Fieldmark representing a date form field.
Definition: bookmrk.hxx:305
DateFormFieldButton(SwEditWin *pEditWin, sw::mark::DateFieldmark &rFieldMark, SvNumberFormatter *pNumberFormatter)
This button is shown when the cursor is on a date form field.
static weld::Builder * CreateBuilder(weld::Widget *pParent, const OUString &rUIFile, bool bMobile=false)
std::unique_ptr< weld::Calendar > m_xCalendar
Dialog to specify the properties of date form field.
weld::Window * GetFrameWeld() const
sw::mark::DateFieldmark * m_pDateFieldmark
std::unique_ptr< weld::Builder > m_xFieldPopupBuilder
virtual void LaunchPopup() override
This button is shown when the cursor is on a form field with drop-down capability.
std::unique_ptr< weld::Popover > m_xFieldPopup
Window class for the Writer edit area, this is the one handling mouse and keyboard events and doing t...
Definition: edtwin.hxx:58
virtual void DestroyPopup() override
SvNumberFormatter * m_pNumberFormatter
IMPL_LINK(DateFormFieldButton, ImplSelectHdl, weld::Calendar &, rCalendar, void)
virtual void LaunchPopup()
virtual void DestroyPopup()
const Date & GetNullDate() const
virtual ~DateFormFieldButton() override