summaryrefslogtreecommitdiff
path: root/include/vcl/toolkit
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2020-07-15 12:10:32 +0100
committerCaolán McNamara <caolanm@redhat.com>2020-07-21 10:25:42 +0200
commit6e7e19d9c300dbdd279789b09f94781e946fad52 (patch)
tree09155fadd224d8907d0dff7378e5041d3fe6cb1e /include/vcl/toolkit
parent299638cab15831d31e7906d557d4f95239be4df9 (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/vcl/toolkit')
-rw-r--r--include/vcl/toolkit/calendar.hxx98
-rw-r--r--include/vcl/toolkit/field.hxx111
2 files changed, 209 insertions, 0 deletions
diff --git a/include/vcl/toolkit/calendar.hxx b/include/vcl/toolkit/calendar.hxx
new file mode 100644
index 000000000000..a1a1cd90105a
--- /dev/null
+++ b/include/vcl/toolkit/calendar.hxx
@@ -0,0 +1,98 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * 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/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#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/toolkit/field.hxx>
+#include <vcl/weld.hxx>
+
+class FloatingWindow;
+struct ImplCFieldFloatWin;
+
+/*************************************************************************
+
+Description
+============
+
+class CalendarField
+
+This class is a DateField with which one can select a date via a DropDownButton
+and the CalendarControl.
+
+--------------------------------------------------------------------------
+
+WinBits
+
+See DateField
+
+The preferences for the CalendarControl can be set via SetCalendarStyle().
+
+--------------------------------------------------------------------------
+
+With EnableToday()/EnableNone() we can enable a TodayButton and a NoneButton.
+
+--------------------------------------------------------------------------
+
+Because we only take over the start date into the field, we should query
+with GetCalendar() in the SelectHandler and with GetSelectDateCount()/GetSelectDate()
+the selected range. We then can e.g. take over that value to another field.
+
+--------------------------------------------------------------------------
+
+If a derived Calendar should be used, we can override the CreateCalendar()
+method in CalendarField and create an own calendar there ourselves.
+
+*************************************************************************/
+
+
+class VCL_DLLPUBLIC CalendarField final : public DateField
+{
+private:
+ VclPtr<ImplCFieldFloatWin> mpFloatWin;
+ weld::Button* mpTodayBtn;
+ weld::Button* mpNoneBtn;
+ bool mbToday;
+ bool mbNone;
+
+ DECL_DLLPRIVATE_LINK( ImplSelectHdl, weld::Calendar&, void );
+ DECL_DLLPRIVATE_LINK( ImplClickHdl, weld::Button&, void );
+ DECL_DLLPRIVATE_LINK( ImplPopupModeEndHdl, FloatingWindow*, void );
+
+public:
+ CalendarField( vcl::Window* pParent, WinBits nWinStyle );
+ virtual ~CalendarField() override;
+ virtual void dispose() override;
+
+ virtual bool ShowDropDown( bool bShow ) override;
+
+ void EnableToday() { mbToday = true; }
+ void EnableNone() { mbNone = true; }
+
+private:
+ virtual void StateChanged( StateChangedType nStateChange ) override;
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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 );