diff options
author | Caolán McNamara <caolanm@redhat.com> | 2020-07-15 12:10:32 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2020-07-21 10:25:42 +0200 |
commit | 6e7e19d9c300dbdd279789b09f94781e946fad52 (patch) | |
tree | 09155fadd224d8907d0dff7378e5041d3fe6cb1e /include | |
parent | 299638cab15831d31e7906d557d4f95239be4df9 (diff) |
weld DateControl
replace SpinButton when WB_SPINBUTTON is set on a date field
to always use a popover with a calendar in it to make it
possible to integrate this with native widgets
Change-Id: I36a26599a154bddf9aec9b50b6570e13477a1f63
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98858
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/svtools/editbrowsebox.hxx | 21 | ||||
-rw-r--r-- | include/vcl/field.hxx | 107 | ||||
-rw-r--r-- | include/vcl/toolkit/calendar.hxx (renamed from include/vcl/calendar.hxx) | 6 | ||||
-rw-r--r-- | include/vcl/toolkit/field.hxx | 111 | ||||
-rw-r--r-- | include/vcl/weldutils.hxx | 32 |
5 files changed, 169 insertions, 108 deletions
diff --git a/include/svtools/editbrowsebox.hxx b/include/svtools/editbrowsebox.hxx index b5ffad460555..4dc3381d5aaa 100644 --- a/include/svtools/editbrowsebox.hxx +++ b/include/svtools/editbrowsebox.hxx @@ -750,6 +750,27 @@ namespace svt TimeControl(BrowserDataWin* pParent, bool bSpinVariant); }; + class SVT_DLLPUBLIC DateControl : public FormattedControlBase + { + public: + DateControl(BrowserDataWin* pParent, bool bDropDown); + + void SetDate(const Date& rDate); + + virtual void dispose() override; + private: + std::unique_ptr<weld::MenuButton> m_xMenuButton; + std::unique_ptr<weld::Builder> m_xCalendarBuilder; + std::unique_ptr<weld::Widget> m_xTopLevel; + std::unique_ptr<weld::Calendar> m_xCalendar; + std::unique_ptr<weld::Button> m_xTodayBtn; + std::unique_ptr<weld::Button> m_xNoneBtn; + + DECL_LINK(ToggleHdl, weld::ToggleButton&, void); + DECL_LINK(ActivateHdl, weld::Calendar&, void); + DECL_LINK(ImplClickHdl, weld::Button&, void); + }; + //= FormattedFieldCellController class SVT_DLLPUBLIC FormattedFieldCellController final : public EditCellController { diff --git a/include/vcl/field.hxx b/include/vcl/field.hxx index 1cb4974bfd08..36a786061bdb 100644 --- a/include/vcl/field.hxx +++ b/include/vcl/field.hxx @@ -186,83 +186,6 @@ private: }; -class UNLESS_MERGELIBS(VCL_DLLPUBLIC) DateFormatter : public FormatterBase -{ -private: - std::unique_ptr<CalendarWrapper> mxCalendarWrapper; - Date maFieldDate; - Date maLastDate; - Date maMin; - Date maMax; - bool mbLongFormat; - bool mbShowDateCentury; - ExtDateFieldFormat mnExtDateFormat; - bool mbEnforceValidValue; - -protected: - DateFormatter(Edit* pEdit); - - SAL_DLLPRIVATE const Date& ImplGetFieldDate() const { return maFieldDate; } - SAL_DLLPRIVATE void ImplDateReformat( const OUString& rStr, OUString& rOutStr ); - SAL_DLLPRIVATE void ImplSetUserDate( const Date& rNewDate, - Selection const * pNewSelection = nullptr ); - SAL_DLLPRIVATE OUString ImplGetDateAsText( const Date& rDate ) const; - SAL_DLLPRIVATE void ImplNewFieldValue( const Date& rDate ); - CalendarWrapper& GetCalendarWrapper() const; - - SAL_DLLPRIVATE bool ImplAllowMalformedInput() const; - -public: - virtual ~DateFormatter() override; - - virtual void Reformat() override; - virtual void ReformatAll() override; - - void SetExtDateFormat( ExtDateFieldFormat eFormat ); - ExtDateFieldFormat GetExtDateFormat( bool bResolveSystemFormat = false ) const; - - void SetMin( const Date& rNewMin ); - const Date& GetMin() const { return maMin; } - - void SetMax( const Date& rNewMax ); - const Date& GetMax() const { return maMax; } - - - // MT: Remove these methods too, ExtDateFormat should be enough! - // What should happen if using DDMMYYYY, but ShowCentury=false? - - void SetLongFormat( bool bLong ); - bool IsLongFormat() const { return mbLongFormat; } - void SetShowDateCentury( bool bShowCentury ); - bool IsShowDateCentury() const { return mbShowDateCentury; } - - - void SetDate( const Date& rNewDate ); - Date GetDate() const; - void SetEmptyDate(); - bool IsEmptyDate() const; - - void ResetLastDate() { maLastDate = Date( Date::EMPTY ); } - - static void ExpandCentury( Date& rDate ); - static void ExpandCentury( Date& rDate, sal_uInt16 nTwoDigitYearStart ); - - /** enables or disables the enforcement of valid values - - If this is set to true (which is the default), then GetDate will always return a valid - date, no matter whether the current text can really be interpreted as date. (Note: this - is the compatible behavior). - - If this is set to false, the GetDate will return GetInvalidDate, in case the current text - cannot be interpreted as date. - - In addition, if this is set to false, the text in the field will \em not be corrected - when the control loses the focus - instead, the invalid input will be preserved. - */ - void EnforceValidValue( bool _bEnforce ) { mbEnforceValidValue = _bEnforce; } - bool IsEnforceValidValue( ) const { return mbEnforceValidValue; } -}; - class UNLESS_MERGELIBS(VCL_DLLPUBLIC) PatternField final : public SpinField, public PatternFormatter { public: @@ -298,36 +221,6 @@ public: virtual void DumpAsPropertyTree(tools::JsonWriter&) override; }; -class UNLESS_MERGELIBS(VCL_DLLPUBLIC) DateField : public SpinField, public DateFormatter -{ -private: - Date maFirst; - Date maLast; - -protected: - SAL_DLLPRIVATE void ImplDateSpinArea( bool bUp ); - -public: - explicit DateField( vcl::Window* pParent, WinBits nWinStyle ); - - virtual bool PreNotify( NotifyEvent& rNEvt ) override; - virtual bool EventNotify( NotifyEvent& rNEvt ) override; - virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; - - virtual void Modify() override; - - virtual void Up() override; - virtual void Down() override; - virtual void First() override; - virtual void Last() override; - - void SetFirst( const Date& rNewFirst ) { maFirst = rNewFirst; } - const Date& GetFirst() const { return maFirst; } - void SetLast( const Date& rNewLast ) { maLast = rNewLast; } - const Date& GetLast() const { return maLast; } - virtual void dispose() override; -}; - #endif // INCLUDED_VCL_FIELD_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/calendar.hxx b/include/vcl/toolkit/calendar.hxx index a88105e29e59..a1a1cd90105a 100644 --- a/include/vcl/calendar.hxx +++ b/include/vcl/toolkit/calendar.hxx @@ -19,10 +19,14 @@ #pragma once +#if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS) +#error "don't use this in new code" +#endif + #include <config_options.h> #include <vcl/dllapi.h> -#include <vcl/field.hxx> +#include <vcl/toolkit/field.hxx> #include <vcl/weld.hxx> class FloatingWindow; diff --git a/include/vcl/toolkit/field.hxx b/include/vcl/toolkit/field.hxx index 6b994b02baea..6316c5698933 100644 --- a/include/vcl/toolkit/field.hxx +++ b/include/vcl/toolkit/field.hxx @@ -260,6 +260,117 @@ public: virtual void dispose() override; }; +class UNLESS_MERGELIBS(VCL_DLLPUBLIC) DateFormatter : public FormatterBase +{ +private: + std::unique_ptr<CalendarWrapper> mxCalendarWrapper; + Date maFieldDate; + Date maLastDate; + Date maMin; + Date maMax; + bool mbLongFormat; + bool mbShowDateCentury; + ExtDateFieldFormat mnExtDateFormat; + bool mbEnforceValidValue; + +protected: + DateFormatter(Edit* pEdit); + + SAL_DLLPRIVATE const Date& ImplGetFieldDate() const { return maFieldDate; } + SAL_DLLPRIVATE void ImplDateReformat( const OUString& rStr, OUString& rOutStr ); + SAL_DLLPRIVATE void ImplSetUserDate( const Date& rNewDate, + Selection const * pNewSelection = nullptr ); + SAL_DLLPRIVATE OUString ImplGetDateAsText( const Date& rDate ) const; + SAL_DLLPRIVATE void ImplNewFieldValue( const Date& rDate ); + CalendarWrapper& GetCalendarWrapper() const; + + SAL_DLLPRIVATE bool ImplAllowMalformedInput() const; + +public: + static OUString FormatDate(const Date& rNewDate, ExtDateFieldFormat eFormat, const LocaleDataWrapper& rLocaleData, CalendarWrapper& rCalendarWrapper); + static bool TextToDate(const OUString& rStr, Date& rTime, ExtDateFieldFormat eFormat, const LocaleDataWrapper& rLocaleDataWrapper, const CalendarWrapper& rCalendarWrapper); + static int GetDateArea(ExtDateFieldFormat eFormat, const OUString& rText, int nCursor, const LocaleDataWrapper& rLocaleDataWrapper); + + virtual ~DateFormatter() override; + + virtual void Reformat() override; + virtual void ReformatAll() override; + + void SetExtDateFormat( ExtDateFieldFormat eFormat ); + ExtDateFieldFormat GetExtDateFormat( bool bResolveSystemFormat = false ) const; + + void SetMin( const Date& rNewMin ); + const Date& GetMin() const { return maMin; } + + void SetMax( const Date& rNewMax ); + const Date& GetMax() const { return maMax; } + + + // MT: Remove these methods too, ExtDateFormat should be enough! + // What should happen if using DDMMYYYY, but ShowCentury=false? + + void SetLongFormat( bool bLong ); + bool IsLongFormat() const { return mbLongFormat; } + void SetShowDateCentury( bool bShowCentury ); + bool IsShowDateCentury() const { return mbShowDateCentury; } + + + void SetDate( const Date& rNewDate ); + Date GetDate() const; + void SetEmptyDate(); + bool IsEmptyDate() const; + + void ResetLastDate() { maLastDate = Date( Date::EMPTY ); } + + static void ExpandCentury( Date& rDate ); + static void ExpandCentury( Date& rDate, sal_uInt16 nTwoDigitYearStart ); + + /** enables or disables the enforcement of valid values + + If this is set to true (which is the default), then GetDate will always return a valid + date, no matter whether the current text can really be interpreted as date. (Note: this + is the compatible behavior). + + If this is set to false, the GetDate will return GetInvalidDate, in case the current text + cannot be interpreted as date. + + In addition, if this is set to false, the text in the field will \em not be corrected + when the control loses the focus - instead, the invalid input will be preserved. + */ + void EnforceValidValue( bool _bEnforce ) { mbEnforceValidValue = _bEnforce; } + bool IsEnforceValidValue( ) const { return mbEnforceValidValue; } +}; + +class UNLESS_MERGELIBS(VCL_DLLPUBLIC) DateField : public SpinField, public DateFormatter +{ +private: + Date maFirst; + Date maLast; + +protected: + SAL_DLLPRIVATE void ImplDateSpinArea( bool bUp ); + +public: + explicit DateField( vcl::Window* pParent, WinBits nWinStyle ); + + virtual bool PreNotify( NotifyEvent& rNEvt ) override; + virtual bool EventNotify( NotifyEvent& rNEvt ) override; + virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; + + virtual void Modify() override; + + virtual void Up() override; + virtual void Down() override; + virtual void First() override; + virtual void Last() override; + + void SetFirst( const Date& rNewFirst ) { maFirst = rNewFirst; } + const Date& GetFirst() const { return maFirst; } + void SetLast( const Date& rNewLast ) { maLast = rNewLast; } + const Date& GetLast() const { return maLast; } + virtual void dispose() override; +}; + class UNLESS_MERGELIBS(VCL_DLLPUBLIC) NumericBox : public ComboBox, public NumericFormatter { SAL_DLLPRIVATE void ImplNumericReformat( const OUString& rStr, sal_Int64& rValue, OUString& rOutStr ); diff --git a/include/vcl/weldutils.hxx b/include/vcl/weldutils.hxx index e1944cc41ee8..cc2a49d4d881 100644 --- a/include/vcl/weldutils.hxx +++ b/include/vcl/weldutils.hxx @@ -19,6 +19,8 @@ #include <vcl/formatter.hxx> #include <vcl/weld.hxx> +class CalendarWrapper; + namespace weld { typedef cppu::WeakComponentImplHelper<css::awt::XWindow> TransportAsXWindow_Base; @@ -280,6 +282,36 @@ private: bool m_bDuration; }; +class VCL_DLLPUBLIC DateFormatter final : public EntryFormatter +{ +public: + DateFormatter(weld::Entry& rEntry); + + void SetMin(const Date& rNewMin); + void SetMax(const Date& rNewMax); + + void SetDate(const Date& rNewDate); + Date GetDate(); + + void SetExtDateFormat(ExtDateFieldFormat eFormat); + void SetShowDateCentury(bool bShowCentury); + + virtual ~DateFormatter() override; + +private: + DECL_LINK(FormatOutputHdl, LinkParamNone*, bool); + DECL_LINK(ParseInputHdl, sal_Int64*, TriState); + DECL_LINK(CursorChangedHdl, weld::Entry&, void); + + void Init(); + CalendarWrapper& GetCalendarWrapper() const; + + OUString FormatNumber(int nValue) const; + + ExtDateFieldFormat m_eFormat; + mutable std::unique_ptr<CalendarWrapper> m_xCalendarWrapper; +}; + // get the row the iterator is on VCL_DLLPUBLIC size_t GetAbsPos(const weld::TreeView& rTreeView, const weld::TreeIter& rIter); |