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>
13 #include <viewopt.hxx>
14 #include <bookmrk.hxx>
15 #include <vcl/floatwin.hxx>
16 #include <vcl/event.hxx>
17 #include <vcl/lstbox.hxx>
18 #include <xmloff/odffields.hxx>
19 #include <IMark.hxx>
20 #include <view.hxx>
21 #include <docsh.hxx>
22 #include <strings.hrc>
23 #include <vcl/calendar.hxx>
24 #include <tools/date.hxx>
25 #include <svx/numfmtsh.hxx>
26 
28 {
29 private:
33 
34  DECL_LINK(ImplSelectHdl, Calendar*, void);
35 
36 public:
38  SvNumberFormatter* pNumberFormatter);
39  virtual ~SwDatePickerDialog() override;
40  virtual void dispose() override;
41 };
42 
44  SvNumberFormatter* pNumberFormatter)
46  , m_pCalendar(VclPtr<Calendar>::Create(this, WB_TABSTOP))
47  , m_pFieldmark(pFieldmark)
48  , m_pNumberFormatter(pNumberFormatter)
49 {
50  if (m_pFieldmark != nullptr)
51  {
52  std::pair<bool, double> aResult = m_pFieldmark->GetCurrentDate();
53  if (aResult.first)
54  {
55  const Date& rNullDate = m_pNumberFormatter->GetNullDate();
56  m_pCalendar->SetCurDate(rNullDate + sal_Int32(aResult.second));
57  }
58  }
59  m_pCalendar->SetSelectHdl(LINK(this, SwDatePickerDialog, ImplSelectHdl));
61  m_pCalendar->Show();
63 }
64 
66 
68 {
71 }
72 
73 IMPL_LINK(SwDatePickerDialog, ImplSelectHdl, Calendar*, pCalendar, void)
74 {
75  if (!pCalendar->IsTravelSelect())
76  {
77  if (m_pFieldmark != nullptr)
78  {
79  const Date& rNullDate = m_pNumberFormatter->GetNullDate();
80  double dDate = pCalendar->GetFirstSelectedDate() - rNullDate;
81  m_pFieldmark->SetCurrentDate(dDate);
82  }
83  EndPopupMode();
84  }
85 }
86 
88  SvNumberFormatter* pNumberFormatter)
89  : FormFieldButton(pEditWin, rFieldmark)
90  , m_pNumberFormatter(pNumberFormatter)
91 {
92 }
93 
95 
97 {
98  sw::mark::DateFieldmark* pDateFieldmark = dynamic_cast<sw::mark::DateFieldmark*>(&m_rFieldmark);
99  m_pFieldPopup = VclPtr<SwDatePickerDialog>::Create(static_cast<SwEditWin*>(GetParent()),
100  pDateFieldmark, m_pNumberFormatter);
101 }
102 
103 /* 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:658
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)