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 
18 namespace
19 {
20 class SwDatePickerDialog : public FloatingWindow
21 {
22 private:
23  VclPtr<Calendar> m_pCalendar;
25  SvNumberFormatter* m_pNumberFormatter;
26 
27  DECL_LINK(ImplSelectHdl, Calendar*, void);
28 
29 public:
30  SwDatePickerDialog(SwEditWin* parent, sw::mark::DateFieldmark* pFieldmark,
31  SvNumberFormatter* pNumberFormatter);
32  virtual ~SwDatePickerDialog() override;
33  virtual void dispose() override;
34 };
35 }
36 
37 SwDatePickerDialog::SwDatePickerDialog(SwEditWin* parent, sw::mark::DateFieldmark* pFieldmark,
38  SvNumberFormatter* pNumberFormatter)
40  , m_pCalendar(VclPtr<Calendar>::Create(this, WB_TABSTOP))
41  , m_pFieldmark(pFieldmark)
42  , m_pNumberFormatter(pNumberFormatter)
43 {
44  if (m_pFieldmark != nullptr)
45  {
46  std::pair<bool, double> aResult = m_pFieldmark->GetCurrentDate();
47  if (aResult.first)
48  {
49  const Date& rNullDate = m_pNumberFormatter->GetNullDate();
50  m_pCalendar->SetCurDate(rNullDate + sal_Int32(aResult.second));
51  }
52  }
53  m_pCalendar->SetSelectHdl(LINK(this, SwDatePickerDialog, ImplSelectHdl));
54  m_pCalendar->SetOutputSizePixel(m_pCalendar->CalcWindowSizePixel());
55  m_pCalendar->Show();
56  SetOutputSizePixel(m_pCalendar->GetSizePixel());
57 }
58 
59 SwDatePickerDialog::~SwDatePickerDialog() { disposeOnce(); }
60 
62 {
63  m_pCalendar.clear();
65 }
66 
67 IMPL_LINK(SwDatePickerDialog, ImplSelectHdl, Calendar*, pCalendar, void)
68 {
69  if (!pCalendar->IsTravelSelect())
70  {
71  if (m_pFieldmark != nullptr)
72  {
73  const Date& rNullDate = m_pNumberFormatter->GetNullDate();
74  double dDate = pCalendar->GetFirstSelectedDate() - rNullDate;
75  m_pFieldmark->SetCurrentDate(dDate);
76  }
77  EndPopupMode();
78  }
79 }
80 
82  SvNumberFormatter* pNumberFormatter)
83  : FormFieldButton(pEditWin, rFieldmark)
84  , m_pNumberFormatter(pNumberFormatter)
85 {
86 }
87 
89 
91 {
92  sw::mark::DateFieldmark* pDateFieldmark = dynamic_cast<sw::mark::DateFieldmark*>(&m_rFieldmark);
93  m_pFieldPopup = VclPtr<SwDatePickerDialog>::Create(static_cast<SwEditWin*>(GetParent()),
94  pDateFieldmark, m_pNumberFormatter);
95 }
96 
97 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
Fieldmark representing a date form field.
Definition: bookmrk.hxx:308
WinBits const WB_NOSHADOW
WinBits const WB_SYSTEMWINDOW
DateFormFieldButton(SwEditWin *pEditWin, sw::mark::DateFieldmark &rFieldMark, SvNumberFormatter *pNumberFormatter)
sw::mark::Fieldmark & m_rFieldmark
void Create(SwFormatVertOrient &rItem, SvStream &rStrm, sal_uInt16 nVersionAbusedAsSize)
Definition: legacyitem.cxx:32
VclPtr< FloatingWindow > m_pFieldPopup
virtual void SetOutputSizePixel(const Size &rNewSize)
This button is shown when the cursor is on a form field with drop-down capability.
Window class for the Writer edit area, this is the one handling mouse and keyboard events and doing t...
Definition: edtwin.hxx:58
std::unique_ptr< Fieldmark > m_pFieldmark
Definition: docbm.cxx:1189
vcl::Window * GetParent() const
IMPL_LINK(SwDatePickerDialog, ImplSelectHdl, Calendar *, pCalendar, void)
SvNumberFormatter * m_pNumberFormatter
WinBits const WB_BORDER
virtual void InitPopup() override
static VclPtr< reference_type > Create(Arg &&...arg)
WinBits const WB_TABSTOP
virtual ~DateFormFieldButton() override
virtual void dispose() override