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 <bookmark.hxx>
13 #include <tools/date.hxx>
14 #include <svl/numformat.hxx>
15 #include <svl/zforlist.hxx>
16 #include <vcl/svapp.hxx>
17 
18 IMPL_LINK(DateFormFieldButton, ImplSelectHdl, weld::Calendar&, rCalendar, void)
19 {
20  if (m_pDateFieldmark)
21  {
22  const Date& rNullDate = m_pNumberFormatter->GetNullDate();
23  double dDate = rCalendar.get_date() - rNullDate;
24  m_pDateFieldmark->SetCurrentDate(dDate);
25  }
26  m_xFieldPopup->popdown();
27 }
28 
30  SvNumberFormatter* pNumberFormatter)
31  : FormFieldButton(pEditWin, rFieldmark)
32  , m_pNumberFormatter(pNumberFormatter)
33  , m_pDateFieldmark(dynamic_cast<sw::mark::DateFieldmark*>(&m_rFieldmark))
34 {
35 }
36 
38 
40 {
42  Application::CreateBuilder(GetFrameWeld(), "modules/swriter/ui/calendar.ui"));
43  m_xFieldPopup = m_xFieldPopupBuilder->weld_popover("Calendar");
44  m_xCalendar = m_xFieldPopupBuilder->weld_calendar("date");
45  if (m_pDateFieldmark)
46  {
47  std::pair<bool, double> aResult = m_pDateFieldmark->GetCurrentDate();
48  if (aResult.first)
49  {
50  const Date& rNullDate = m_pNumberFormatter->GetNullDate();
51  m_xCalendar->set_date(rNullDate + sal_Int32(aResult.second));
52  }
53  }
54  m_xCalendar->connect_activated(LINK(this, DateFormFieldButton, ImplSelectHdl));
56  m_xCalendar->grab_focus();
57 }
58 
60 {
61  m_xCalendar.reset();
63 }
64 
65 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
virtual std::pair< bool, double > GetCurrentDate() const override
Fieldmark representing a date form field.
static weld::Builder * CreateBuilder(weld::Widget *pParent, const OUString &rUIFile, bool bMobile=false, sal_uInt64 nLOKWindowId=0)
DateFormFieldButton(SwEditWin *pEditWin, sw::mark::DateFieldmark &rFieldMark, SvNumberFormatter *pNumberFormatter)
This button is shown when the cursor is on a date form field.
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