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 <vcl/floatwin.hxx>
14 #include <vcl/calendar.hxx>
15 #include <tools/date.hxx>
16 #include <svl/zforlist.hxx>
17 
19 {
20 private:
24 
25  DECL_LINK(ImplSelectHdl, Calendar*, void);
26 
27 public:
29  SvNumberFormatter* pNumberFormatter);
30  virtual ~SwDatePickerDialog() override;
31  virtual void dispose() override;
32 };
33 
35  SvNumberFormatter* pNumberFormatter)
37  , m_pCalendar(VclPtr<Calendar>::Create(this, WB_TABSTOP))
38  , m_pFieldmark(pFieldmark)
39  , m_pNumberFormatter(pNumberFormatter)
40 {
41  if (m_pFieldmark != nullptr)
42  {
43  std::pair<bool, double> aResult = m_pFieldmark->GetCurrentDate();
44  if (aResult.first)
45  {
46  const Date& rNullDate = m_pNumberFormatter->GetNullDate();
47  m_pCalendar->SetCurDate(rNullDate + sal_Int32(aResult.second));
48  }
49  }
50  m_pCalendar->SetSelectHdl(LINK(this, SwDatePickerDialog, ImplSelectHdl));
52  m_pCalendar->Show();
54 }
55 
57 
59 {
62 }
63 
64 IMPL_LINK(SwDatePickerDialog, ImplSelectHdl, Calendar*, pCalendar, void)
65 {
66  if (!pCalendar->IsTravelSelect())
67  {
68  if (m_pFieldmark != nullptr)
69  {
70  const Date& rNullDate = m_pNumberFormatter->GetNullDate();
71  double dDate = pCalendar->GetFirstSelectedDate() - rNullDate;
72  m_pFieldmark->SetCurrentDate(dDate);
73  }
74  EndPopupMode();
75  }
76 }
77 
79  SvNumberFormatter* pNumberFormatter)
80  : FormFieldButton(pEditWin, rFieldmark)
81  , m_pNumberFormatter(pNumberFormatter)
82 {
83 }
84 
86 
88 {
89  sw::mark::DateFieldmark* pDateFieldmark = dynamic_cast<sw::mark::DateFieldmark*>(&m_rFieldmark);
90  m_pFieldPopup = VclPtr<SwDatePickerDialog>::Create(static_cast<SwEditWin*>(GetParent()),
91  pDateFieldmark, m_pNumberFormatter);
92 }
93 
94 /* 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:761
Fieldmark representing a date form field.
Definition: bookmrk.hxx:306
virtual void dispose() override
WinBits const WB_NOSHADOW
WinBits const WB_SYSTEMWINDOW
DateFormFieldButton(SwEditWin *pEditWin, sw::mark::DateFieldmark &rFieldMark, SvNumberFormatter *pNumberFormatter)
SwDatePickerDialog(SwEditWin *parent, sw::mark::DateFieldmark *pFieldmark, SvNumberFormatter *pNumberFormatter)
sw::mark::DateFieldmark * m_pFieldmark
sw::mark::Fieldmark & m_rFieldmark
virtual ~SwDatePickerDialog() override
VclPtr< Calendar > m_pCalendar
virtual Size GetSizePixel() const
SvNumberFormatter * m_pNumberFormatter
Size CalcWindowSizePixel() const
VclPtr< FloatingWindow > m_pFieldPopup
DECL_LINK(ImplSelectHdl, Calendar *, void)
virtual void SetOutputSizePixel(const Size &rNewSize)
This button is shown when the cursor is on a form field with drop-down capability.
void clear()
Window class for the Writer edit area, this is the one handling mouse and keyboard events and doing t...
Definition: edtwin.hxx:58
void SetSelectHdl(const Link< Calendar *, void > &rLink)
vcl::Window * GetParent() const
void SetCurDate(const Date &rNewDate)
IMPL_LINK(SwDatePickerDialog, ImplSelectHdl, Calendar *, pCalendar, void)
SvNumberFormatter * m_pNumberFormatter
WinBits const WB_BORDER
virtual void InitPopup() override
void Create(SwFormatVertOrient &rItem, SvStream &rStrm, sal_uInt16 nVersionAbusedAsSize)
Definition: legacyitem.cxx:34
static VclPtr< reference_type > Create(Arg &&...arg)
WinBits const WB_TABSTOP
const Date & GetNullDate() const
virtual ~DateFormFieldButton() override
virtual void dispose() override
void Show(bool bVisible=true, ShowFlags nFlags=ShowFlags::NONE)