diff options
author | Caolán McNamara <caolanm@redhat.com> | 2018-05-06 15:21:33 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2018-05-10 14:37:06 +0200 |
commit | 476ed0aed1c09055fa05209485919a026e5f014e (patch) | |
tree | 68c2cc8ca587dd7b47f97d800d32560339f546fc /include | |
parent | 7cee480efe22d48af9e9d96b49ad4358a4010690 (diff) |
weld SdStartPresentationDlg
to get duration spinbutton working need to know where the cursor
is in the spinbutton and to change the adjustment factor depending
on that, and need to additionally disable the vcl round to nearest base unit on
up/down
Change-Id: I6dd09e1639454cb4820d3aeb0c0c698fcebd417e
Reviewed-on: https://gerrit.libreoffice.org/54065
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/vcl/field.hxx | 26 | ||||
-rw-r--r-- | include/vcl/vclenum.hxx | 5 | ||||
-rw-r--r-- | include/vcl/weld.hxx | 83 |
3 files changed, 102 insertions, 12 deletions
diff --git a/include/vcl/field.hxx b/include/vcl/field.hxx index 3af20ff93558..8f4bf5b07219 100644 --- a/include/vcl/field.hxx +++ b/include/vcl/field.hxx @@ -40,7 +40,6 @@ class VCL_DLLPUBLIC FormatterBase { private: VclPtr<Edit> mpField; - Link<Edit&, bool> maOutputHdl; std::unique_ptr<LocaleDataWrapper> mpLocaleDataWrapper; bool mbReformat; @@ -85,8 +84,6 @@ public: void EnableEmptyFieldValue( bool bEnable ) { mbEmptyFieldValueEnabled = bEnable; } bool IsEmptyFieldValueEnabled() const { return mbEmptyFieldValueEnabled; } - - void SetOutputHdl(const Link<Edit&, bool>& rLink) { maOutputHdl = rLink; } }; #define PATTERN_FORMAT_EMPTYLITERALS (sal_uInt16(0x0001)) @@ -152,6 +149,7 @@ public: void SetShowTrailingZeros( bool bShowTrailingZeros ); bool IsShowTrailingZeros() const { return mbShowTrailingZeros; } + void DisableRemainderFactor(); void SetUserValue( sal_Int64 nNewValue ); virtual void SetValue( sal_Int64 nNewValue ); @@ -163,12 +161,16 @@ public: sal_Int64 Normalize( sal_Int64 nValue ) const; sal_Int64 Denormalize( sal_Int64 nValue ) const; + void SetInputHdl(const Link<sal_Int64*,TriState>& rLink) { m_aInputHdl = rLink; } + void SetOutputHdl(const Link<Edit&, bool>& rLink) { m_aOutputHdl = rLink; } protected: sal_Int64 mnFieldValue; sal_Int64 mnLastValue; sal_Int64 mnMin; sal_Int64 mnMax; bool mbWrapOnLimits; + bool mbFormatting; + bool mbDisableRemainderFactor; // the members below are used in all derivatives of NumericFormatter // not in NumericFormatter itself. @@ -182,8 +184,9 @@ protected: void FieldDown(); void FieldFirst(); void FieldLast(); + void FormatValue(Selection const * pNewSelection = nullptr); - SAL_DLLPRIVATE void ImplNumericReformat( sal_Int64& rValue, OUString& rOutStr ); + SAL_DLLPRIVATE void ImplNumericReformat(); SAL_DLLPRIVATE void ImplNewFieldValue( sal_Int64 nNewValue ); SAL_DLLPRIVATE void ImplSetUserValue( sal_Int64 nNewValue, Selection const * pNewSelection = nullptr ); @@ -192,6 +195,8 @@ protected: private: SAL_DLLPRIVATE void ImplInit(); + Link<sal_Int64*, TriState> m_aInputHdl; + Link<Edit&, bool> m_aOutputHdl; sal_uInt16 mnDecimalDigits; bool mbThousandSep; bool mbShowTrailingZeros; @@ -358,12 +363,6 @@ public: class VCL_DLLPUBLIC TimeFormatter : public FormatterBase { -public: - enum class TimeFormat { - Hour12, - Hour24 - }; - private: tools::Time maLastTime; tools::Time maMin; @@ -386,6 +385,13 @@ protected: SAL_DLLPRIVATE bool ImplAllowMalformedInput() const; public: + static OUString FormatTime(const tools::Time& rNewTime, TimeFieldFormat eFormat, TimeFormat eHourFormat, bool bDuration, const LocaleDataWrapper& rLocaleData); + static bool TextToTime(const OUString& rStr, tools::Time& rTime, TimeFieldFormat eFormat, bool bDuration, const LocaleDataWrapper& rLocaleDataWrapper, bool _bSkipInvalidCharacters = true); + static int GetTimeArea(TimeFieldFormat eFormat, const OUString& rText, int nCursor, + const LocaleDataWrapper& rLocaleDataWrapper); + static tools::Time SpinTime(bool bUp, const tools::Time& rTime, TimeFieldFormat eFormat, + bool bDuration, const OUString& rText, int nCursor, + const LocaleDataWrapper& rLocaleDataWrapper); virtual ~TimeFormatter() override; diff --git a/include/vcl/vclenum.hxx b/include/vcl/vclenum.hxx index e31c7cc70e50..8697465af32d 100644 --- a/include/vcl/vclenum.hxx +++ b/include/vcl/vclenum.hxx @@ -118,6 +118,11 @@ namespace o3tl template<> struct typed_flags<WindowBorderStyle> : is_typed_flags<WindowBorderStyle, 0x3033> {}; } +enum class TimeFormat +{ + Hour12, Hour24 +}; + enum class ExtTimeFieldFormat { Short24H, Long24H diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx index 448a592fb15c..b7f53ab0e057 100644 --- a/include/vcl/weld.hxx +++ b/include/vcl/weld.hxx @@ -15,6 +15,7 @@ #include <tools/link.hxx> #include <vcl/dllapi.h> #include <vcl/field.hxx> +#include <vcl/vclenum.hxx> #include <vcl/virdev.hxx> #include <com/sun/star/accessibility/XAccessibleRelationSet.hpp> @@ -451,9 +452,10 @@ private: protected: Link<Entry&, void> m_aChangeHdl; Link<OUString&, bool> m_aInsertTextHdl; + Link<Entry&, void> m_aCursorPositionHdl; void signal_changed() { m_aChangeHdl.Call(*this); } - + void signal_cursor_position() { m_aCursorPositionHdl.Call(*this); } void signal_insert_text(OUString& rString); public: @@ -470,8 +472,11 @@ public: virtual void set_font(const vcl::Font& rFont) = 0; void connect_changed(const Link<Entry&, void>& rLink) { m_aChangeHdl = rLink; } - void connect_insert_text(const Link<OUString&, bool>& rLink) { m_aInsertTextHdl = rLink; } + virtual void connect_cursor_position(const Link<Entry&, void>& rLink) + { + m_aCursorPositionHdl = rLink; + } void save_value() { m_sSavedValue = get_text(); } @@ -483,6 +488,7 @@ class VCL_DLLPUBLIC SpinButton : virtual public Entry protected: Link<SpinButton&, void> m_aValueChangedHdl; Link<SpinButton&, void> m_aOutputHdl; + Link<int*, bool> m_aInputHdl; void signal_value_changed() { m_aValueChangedHdl.Call(*this); } @@ -494,6 +500,13 @@ protected: return true; } + TriState signal_input(int* result) + { + if (!m_aInputHdl.IsSet()) + return TRISTATE_INDET; + return m_aInputHdl.Call(result) ? TRISTATE_TRUE : TRISTATE_FALSE; + } + public: virtual void set_value(int value) = 0; virtual int get_value() const = 0; @@ -519,6 +532,7 @@ public: void connect_value_changed(const Link<SpinButton&, void>& rLink) { m_aValueChangedHdl = rLink; } void connect_output(const Link<SpinButton&, void>& rLink) { m_aOutputHdl = rLink; } + void connect_input(const Link<int*, bool>& rLink) { m_aInputHdl = rLink; } int normalize(int nValue) const { return (nValue * Power10(get_digits())); } @@ -621,6 +635,8 @@ public: m_aValueChangedHdl = rLink; } + void connect_changed(const Link<Entry&, void>& rLink) { m_xSpinButton->connect_changed(rLink); } + int normalize(int nValue) const { return m_xSpinButton->normalize(nValue); } int denormalize(int nValue) const { return m_xSpinButton->denormalize(nValue); } void set_sensitive(bool sensitive) { m_xSpinButton->set_sensitive(sensitive); } @@ -653,9 +669,69 @@ public: m_xSpinButton->connect_focus_out(rLink); } void set_help_id(const OString& rName) { m_xSpinButton->set_help_id(rName); } + void set_position(int nCursorPos) { m_xSpinButton->set_position(nCursorPos); } const weld::SpinButton* get_widget() const { return m_xSpinButton.get(); } }; +class VCL_DLLPUBLIC TimeSpinButton +{ +protected: + TimeFieldFormat m_eFormat; + std::unique_ptr<weld::SpinButton> m_xSpinButton; + Link<TimeSpinButton&, void> m_aValueChangedHdl; + + DECL_LINK(spin_button_value_changed, weld::SpinButton&, void); + DECL_LINK(spin_button_output, weld::SpinButton&, void); + DECL_LINK(spin_button_input, int* result, bool); + DECL_LINK(spin_button_cursor_position, weld::Entry&, void); + + void signal_value_changed() { m_aValueChangedHdl.Call(*this); } + + tools::Time ConvertValue(int nValue) const; + int ConvertValue(const tools::Time& rTime) const; + OUString format_number(int nValue) const; + void update_width_chars(); + +public: + TimeSpinButton(SpinButton* pSpinButton, TimeFieldFormat eFormat) + : m_eFormat(eFormat) + , m_xSpinButton(pSpinButton) + { + update_width_chars(); + m_xSpinButton->connect_output(LINK(this, TimeSpinButton, spin_button_output)); + m_xSpinButton->connect_input(LINK(this, TimeSpinButton, spin_button_input)); + m_xSpinButton->connect_value_changed(LINK(this, TimeSpinButton, spin_button_value_changed)); + m_xSpinButton->connect_cursor_position( + LINK(this, TimeSpinButton, spin_button_cursor_position)); + } + + void set_value(const tools::Time& rTime) { m_xSpinButton->set_value(ConvertValue(rTime)); } + + tools::Time get_value() const { return ConvertValue(m_xSpinButton->get_value()); } + + void connect_value_changed(const Link<TimeSpinButton&, void>& rLink) + { + m_aValueChangedHdl = rLink; + } + + void connect_changed(const Link<Entry&, void>& rLink) { m_xSpinButton->connect_changed(rLink); } + + void set_sensitive(bool sensitive) { m_xSpinButton->set_sensitive(sensitive); } + bool get_sensitive() const { return m_xSpinButton->get_sensitive(); } + bool get_visible() const { return m_xSpinButton->get_visible(); } + void grab_focus() { m_xSpinButton->grab_focus(); } + bool has_focus() const { return m_xSpinButton->has_focus(); } + void show(bool bShow = true) { m_xSpinButton->show(bShow); } + void hide() { m_xSpinButton->hide(); } + void save_value() { m_xSpinButton->save_value(); } + bool get_value_changed_from_saved() const + { + return m_xSpinButton->get_value_changed_from_saved(); + } + void set_position(int nCursorPos) { m_xSpinButton->set_position(nCursorPos); } + weld::SpinButton* get_widget() { return m_xSpinButton.get(); } +}; + class VCL_DLLPUBLIC Label : virtual public Widget { public: @@ -782,6 +858,9 @@ public: { return new MetricSpinButton(weld_spin_button(id, bTakeOwnership), eUnit); } + virtual TimeSpinButton* weld_time_spin_button(const OString& id, TimeFieldFormat eFormat, + bool bTakeOwnership = false) + = 0; virtual ComboBoxText* weld_combo_box_text(const OString& id, bool bTakeOwnership = false) = 0; virtual TreeView* weld_tree_view(const OString& id, bool bTakeOwnership = false) = 0; virtual Label* weld_label(const OString& id, bool bTakeOwnership = false) = 0; |