summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/xmloff/odffields.hxx1
-rw-r--r--sw/Library_sw.mk1
-rw-r--r--sw/source/core/crsr/DateFormFieldButton.cxx97
-rw-r--r--sw/source/core/crsr/bookmrk.cxx77
-rw-r--r--sw/source/core/doc/docbm.cxx13
-rw-r--r--sw/source/core/inc/DateFormFieldButton.hxx42
-rw-r--r--sw/source/core/inc/MarkManager.hxx4
-rw-r--r--sw/source/core/inc/bookmrk.hxx40
8 files changed, 198 insertions, 77 deletions
diff --git a/include/xmloff/odffields.hxx b/include/xmloff/odffields.hxx
index 0b0ec4676f39..fc119fe0a295 100644
--- a/include/xmloff/odffields.hxx
+++ b/include/xmloff/odffields.hxx
@@ -35,6 +35,7 @@
#define ODF_FORMDATE "vnd.oasis.opendocument.field.FORMDATE"
#define ODF_FORMDATE_DATEFORMAT "DateField_DateFormat"
+#define ODF_FORMDATE_CURRENTDATE "DateField_CurrentDate"
#define ODF_TOC "vnd.oasis.opendocument.field.TOC"
diff --git a/sw/Library_sw.mk b/sw/Library_sw.mk
index 15b921947018..e3a2f1b1177b 100644
--- a/sw/Library_sw.mk
+++ b/sw/Library_sw.mk
@@ -150,6 +150,7 @@ $(eval $(call gb_Library_add_exception_objects,sw,\
sw/source/core/crsr/crsrsh \
sw/source/core/crsr/crstrvl \
sw/source/core/crsr/crstrvl1 \
+ sw/source/core/crsr/DateFormFieldButton \
sw/source/core/crsr/DropDownFormFieldButton \
sw/source/core/crsr/findattr \
sw/source/core/crsr/findcoll \
diff --git a/sw/source/core/crsr/DateFormFieldButton.cxx b/sw/source/core/crsr/DateFormFieldButton.cxx
new file mode 100644
index 000000000000..466f6961f589
--- /dev/null
+++ b/sw/source/core/crsr/DateFormFieldButton.cxx
@@ -0,0 +1,97 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <DateFormFieldButton.hxx>
+#include <edtwin.hxx>
+#include <basegfx/color/bcolortools.hxx>
+#include <viewopt.hxx>
+#include <bookmrk.hxx>
+#include <vcl/floatwin.hxx>
+#include <vcl/event.hxx>
+#include <vcl/lstbox.hxx>
+#include <xmloff/odffields.hxx>
+#include <IMark.hxx>
+#include <view.hxx>
+#include <docsh.hxx>
+#include <strings.hrc>
+#include <vcl/calendar.hxx>
+#include <tools/date.hxx>
+
+class SwDatePickerDialog : public FloatingWindow
+{
+private:
+ VclPtr<Calendar> m_pCalendar;
+ sw::mark::IFieldmark* m_pFieldmark;
+
+ DECL_LINK(ImplSelectHdl, Calendar*, void);
+
+public:
+ SwDatePickerDialog(SwEditWin* parent, sw::mark::IFieldmark* pFieldmark);
+ virtual ~SwDatePickerDialog() override;
+ virtual void dispose() override;
+};
+
+SwDatePickerDialog::SwDatePickerDialog(SwEditWin* parent, sw::mark::IFieldmark* pFieldmark)
+ : FloatingWindow(parent, WB_BORDER | WB_SYSTEMWINDOW | WB_NOSHADOW)
+ , m_pCalendar(VclPtr<Calendar>::Create(this, WB_TABSTOP))
+ , m_pFieldmark(pFieldmark)
+{
+ if (m_pFieldmark != nullptr)
+ {
+ sw::mark::IFieldmark::parameter_map_t* pParameters = m_pFieldmark->GetParameters();
+ auto pResult = pParameters->find(ODF_FORMDATE_CURRENTDATE);
+ if (pResult != pParameters->end())
+ {
+ sal_Int32 nCurrentDate = 0;
+ pResult->second >>= nCurrentDate;
+ m_pCalendar->SetCurDate(Date(nCurrentDate));
+ }
+ }
+ m_pCalendar->SetSelectHdl(LINK(this, SwDatePickerDialog, ImplSelectHdl));
+ m_pCalendar->SetOutputSizePixel(m_pCalendar->CalcWindowSizePixel());
+ m_pCalendar->Show();
+ SetOutputSizePixel(m_pCalendar->GetSizePixel());
+}
+
+SwDatePickerDialog::~SwDatePickerDialog() { disposeOnce(); }
+
+void SwDatePickerDialog::dispose()
+{
+ m_pCalendar.clear();
+ FloatingWindow::dispose();
+}
+
+IMPL_LINK(SwDatePickerDialog, ImplSelectHdl, Calendar*, pCalendar, void)
+{
+ if (!pCalendar->IsTravelSelect())
+ {
+ if (m_pFieldmark != nullptr)
+ {
+ sw::mark::IFieldmark::parameter_map_t* pParameters = m_pFieldmark->GetParameters();
+ (*pParameters)[ODF_FORMDATE_CURRENTDATE]
+ <<= pCalendar->GetFirstSelectedDate().GetDate();
+ }
+ EndPopupMode();
+ }
+}
+
+DateFormFieldButton::DateFormFieldButton(SwEditWin* pEditWin, sw::mark::DateFieldmark& rFieldmark)
+ : FormFieldButton(pEditWin, rFieldmark)
+{
+}
+
+DateFormFieldButton::~DateFormFieldButton() { disposeOnce(); }
+
+void DateFormFieldButton::InitPopup()
+{
+ m_pFieldPopup
+ = VclPtr<SwDatePickerDialog>::Create(static_cast<SwEditWin*>(GetParent()), &m_rFieldmark);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/sw/source/core/crsr/bookmrk.cxx b/sw/source/core/crsr/bookmrk.cxx
index 5d570b96bafe..cddf7f6efef7 100644
--- a/sw/source/core/crsr/bookmrk.cxx
+++ b/sw/source/core/crsr/bookmrk.cxx
@@ -38,6 +38,8 @@
#include <comphelper/anytostring.hxx>
#include <sal/log.hxx>
#include <edtwin.hxx>
+#include <DateFormFieldButton.hxx>
+#include <DropDownFormFieldButton.hxx>
using namespace ::sw::mark;
using namespace ::com::sun::star;
@@ -485,18 +487,18 @@ namespace sw { namespace mark
return bResult;
}
- DropDownFieldmark::DropDownFieldmark(const SwPaM& rPaM)
+ FieldmarkWithDropDownButton::FieldmarkWithDropDownButton(const SwPaM& rPaM)
: NonTextFieldmark(rPaM)
, m_pButton(nullptr)
{
}
- DropDownFieldmark::~DropDownFieldmark()
+ FieldmarkWithDropDownButton::~FieldmarkWithDropDownButton()
{
m_pButton.disposeAndClear();
}
- void DropDownFieldmark::SetPortionPaintArea(const SwRect& rPortionPaintArea)
+ void FieldmarkWithDropDownButton::SetPortionPaintArea(const SwRect& rPortionPaintArea)
{
if(m_aPortionPaintArea == rPortionPaintArea &&
m_pButton && m_pButton->IsVisible())
@@ -511,81 +513,56 @@ namespace sw { namespace mark
}
}
- void DropDownFieldmark::ShowButton(SwEditWin* pEditWin)
- {
- if(pEditWin)
- {
- if(!m_pButton)
- m_pButton = VclPtr<DropDownFormFieldButton>::Create(pEditWin, *this);
- m_pButton->CalcPosAndSize(m_aPortionPaintArea);
- m_pButton->Show();
- }
- }
-
- void DropDownFieldmark::HideButton()
+ void FieldmarkWithDropDownButton::HideButton()
{
if(m_pButton)
m_pButton->Show(false);
}
- void DropDownFieldmark::RemoveButton()
+ void FieldmarkWithDropDownButton::RemoveButton()
{
if(m_pButton)
m_pButton.disposeAndClear();
}
- DateFieldmark::DateFieldmark(const SwPaM& rPaM)
- : NonTextFieldmark(rPaM)
- //, m_pButton(nullptr)
+ DropDownFieldmark::DropDownFieldmark(const SwPaM& rPaM)
+ : FieldmarkWithDropDownButton(rPaM)
{
}
- DateFieldmark::~DateFieldmark()
+ DropDownFieldmark::~DropDownFieldmark()
{
- //m_pButton.disposeAndClear();
- (void)m_pButton;
}
- void DateFieldmark::SetPortionPaintArea(const SwRect& /*rPortionPaintArea*/)
+ void DropDownFieldmark::ShowButton(SwEditWin* pEditWin)
{
- /*if(m_aPortionPaintArea == rPortionPaintArea &&
- m_pButton && m_pButton->IsVisible())
- return;
-
- m_aPortionPaintArea = rPortionPaintArea;
- if(m_pButton)
+ if(pEditWin)
{
- m_pButton->Show();
+ if(!m_pButton)
+ m_pButton = VclPtr<DropDownFormFieldButton>::Create(pEditWin, *this);
m_pButton->CalcPosAndSize(m_aPortionPaintArea);
- m_pButton->Invalidate();
- }*/
- (void)m_pButton;
+ m_pButton->Show();
+ }
}
- void DateFieldmark::ShowButton(SwEditWin* pEditWin)
+ DateFieldmark::DateFieldmark(const SwPaM& rPaM)
+ : FieldmarkWithDropDownButton(rPaM)
{
- if(pEditWin)
- {
- //if(!m_pButton)
- // m_pButton = VclPtr<DropDownFormFieldButton>::Create(pEditWin, *this);
- //m_pButton->CalcPosAndSize(m_aPortionPaintArea);
- //m_pButton->Show();
- }
- (void)m_pButton;
}
- void DateFieldmark::HideButton()
+ DateFieldmark::~DateFieldmark()
{
- //if(m_pButton)
- //m_pButton->Show(false);
- (void)m_pButton;
}
- void DateFieldmark::RemoveButton()
+ void DateFieldmark::ShowButton(SwEditWin* pEditWin)
{
- //if(m_pButton)
- //m_pButton.disposeAndClear();
- (void)m_pButton;
+ if(pEditWin)
+ {
+ if(!m_pButton)
+ m_pButton = VclPtr<DateFormFieldButton>::Create(pEditWin, *this);
+ m_pButton->CalcPosAndSize(m_aPortionPaintArea);
+ m_pButton->Show();
+ }
}
}}
diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx
index 0f754c74d798..b02d8a68730f 100644
--- a/sw/source/core/doc/docbm.cxx
+++ b/sw/source/core/doc/docbm.cxx
@@ -1320,21 +1320,22 @@ namespace sw { namespace mark
SwEditWin& rEditWin = pSwView->GetEditWin();
SwPosition aPos(*rCursorShell.GetCursor()->GetPoint());
IFieldmark* pFieldBM = getFieldmarkFor(aPos);
- DropDownFieldmark* pNewActiveFieldmark = nullptr;
- if ((!pFieldBM || pFieldBM->GetFieldname() != ODF_FORMDROPDOWN)
+ FieldmarkWithDropDownButton* pNewActiveFieldmark = nullptr;
+ if ((!pFieldBM || (pFieldBM->GetFieldname() != ODF_FORMDROPDOWN && pFieldBM->GetFieldname() != ODF_FORMDATE))
&& aPos.nContent.GetIndex() > 0 )
{
--aPos.nContent;
pFieldBM = getFieldmarkFor(aPos);
}
- if ( pFieldBM && pFieldBM->GetFieldname() == ODF_FORMDROPDOWN )
+ if ( pFieldBM && (pFieldBM->GetFieldname() == ODF_FORMDROPDOWN ||
+ pFieldBM->GetFieldname() == ODF_FORMDATE))
{
if (m_pLastActiveFieldmark != pFieldBM)
{
- DropDownFieldmark* pDropDownFm = dynamic_cast<DropDownFieldmark*>(pFieldBM);
- pDropDownFm->ShowButton(&rEditWin);
- pNewActiveFieldmark = pDropDownFm;
+ auto pFormField = dynamic_cast<FieldmarkWithDropDownButton*>(pFieldBM);
+ pFormField->ShowButton(&rEditWin);
+ pNewActiveFieldmark = pFormField;
}
else
{
diff --git a/sw/source/core/inc/DateFormFieldButton.hxx b/sw/source/core/inc/DateFormFieldButton.hxx
new file mode 100644
index 000000000000..ff677b610b3d
--- /dev/null
+++ b/sw/source/core/inc/DateFormFieldButton.hxx
@@ -0,0 +1,42 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_SW_SOURCE_CORE_TEXT_DATEFORMEFIELDBUTTO_HXX
+#define INCLUDED_SW_SOURCE_CORE_TEXT_DATEFORMEFIELDBUTTO_HXX
+
+#include <vcl/menubtn.hxx>
+#include <swrect.hxx>
+#include "FormFieldButton.hxx"
+
+class SwEditWin;
+class FloatingWindow;
+namespace sw
+{
+namespace mark
+{
+class DateFieldmark;
+}
+} // namespace sw
+
+/**
+ * This button is shown when the cursor is on a date form field.
+ * The user can select a date from a date picker while filling in a form.
+ */
+class DateFormFieldButton : public FormFieldButton
+{
+public:
+ DateFormFieldButton(SwEditWin* pEditWin, sw::mark::DateFieldmark& rFieldMark);
+ virtual ~DateFormFieldButton() override;
+
+ virtual void InitPopup() override;
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/sw/source/core/inc/MarkManager.hxx b/sw/source/core/inc/MarkManager.hxx
index a3d2ff7e56b5..2c30f8e79f75 100644
--- a/sw/source/core/inc/MarkManager.hxx
+++ b/sw/source/core/inc/MarkManager.hxx
@@ -31,7 +31,7 @@ namespace sw {
namespace mark {
typedef std::unordered_map<OUString, sal_Int32> MarkBasenameMapUniqueOffset_t;
- class DropDownFieldmark;
+ class FieldmarkWithDropDownButton;
class MarkManager
: virtual public IDocumentMarkAccess
@@ -138,7 +138,7 @@ namespace sw {
SwDoc * const m_pDoc;
- sw::mark::DropDownFieldmark* m_pLastActiveFieldmark;
+ sw::mark::FieldmarkWithDropDownButton* m_pLastActiveFieldmark;
};
} // namespace mark
}
diff --git a/sw/source/core/inc/bookmrk.hxx b/sw/source/core/inc/bookmrk.hxx
index 30b75bcbe6b1..3af70ebc26ce 100644
--- a/sw/source/core/inc/bookmrk.hxx
+++ b/sw/source/core/inc/bookmrk.hxx
@@ -29,7 +29,7 @@
#include <tools/ref.hxx>
#include <IMark.hxx>
#include <swrect.hxx>
-#include "DropDownFormFieldButton.hxx"
+#include "FormFieldButton.hxx"
namespace com {
namespace sun {
@@ -268,44 +268,46 @@ namespace sw {
void SetChecked(bool checked) override;
};
- /// Fieldmark representing a drop-down form field.
- class DropDownFieldmark
+ /// Fieldmark with a drop down button (e.g. this button opens the date picker for a date field)
+ class FieldmarkWithDropDownButton
: public NonTextFieldmark
{
public:
- DropDownFieldmark(const SwPaM& rPaM);
- virtual ~DropDownFieldmark() override;
+ FieldmarkWithDropDownButton(const SwPaM& rPaM);
+ virtual ~FieldmarkWithDropDownButton() override;
// This method should be called only by the portion so we can now the portion's painting area
void SetPortionPaintArea(const SwRect& rPortionPaintArea);
- void ShowButton(SwEditWin* pEditWin);
+ virtual void ShowButton(SwEditWin* pEditWin) = 0;
void HideButton();
void RemoveButton();
- private:
+ protected:
SwRect m_aPortionPaintArea;
- VclPtr<DropDownFormFieldButton> m_pButton;
+ VclPtr<FormFieldButton> m_pButton;
+ };
+
+ /// Fieldmark representing a drop-down form field.
+ class DropDownFieldmark
+ : public FieldmarkWithDropDownButton
+ {
+ public:
+ DropDownFieldmark(const SwPaM& rPaM);
+ virtual ~DropDownFieldmark() override;
+
+ virtual void ShowButton(SwEditWin* pEditWin) override;
};
/// Fieldmark representing a date form field.
class DateFieldmark
- : public NonTextFieldmark
+ : public FieldmarkWithDropDownButton
{
public:
DateFieldmark(const SwPaM& rPaM);
virtual ~DateFieldmark() override;
- // This method should be called only by the portion so we can now the portion's painting area
- void SetPortionPaintArea(const SwRect& rPortionPaintArea);
-
- void ShowButton(SwEditWin* pEditWin);
- void HideButton();
- void RemoveButton();
-
- private:
- SwRect m_aPortionPaintArea;
- VclPtr<MenuButton> m_pButton;
+ virtual void ShowButton(SwEditWin* pEditWin) override;
};
}
}