diff options
author | Szymon Kłos <szymon.klos@collabora.com> | 2020-02-21 14:35:13 +0100 |
---|---|---|
committer | Szymon Kłos <szymon.klos@collabora.com> | 2020-02-25 08:15:46 +0100 |
commit | 9dba074405b3db3a0bd2b09a15c98abf4a2cd646 (patch) | |
tree | 3903122400f76936b004ecd9d2c62a3eeb623ed5 /vcl | |
parent | 619e757283037e2ba91cfe2038fa3778e5249dfd (diff) |
Move SalInstanceEdit declaration to the header file
Change-Id: I660de317b88c4e83ccc310743dc4ef5b4c955a21
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/89370
Tested-by: Jenkins
Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/salvtables.hxx | 120 | ||||
-rw-r--r-- | vcl/source/app/salvtables.cxx | 430 |
2 files changed, 346 insertions, 204 deletions
diff --git a/vcl/inc/salvtables.hxx b/vcl/inc/salvtables.hxx index 3d41d3589871..519e2ddf7ef9 100644 --- a/vcl/inc/salvtables.hxx +++ b/vcl/inc/salvtables.hxx @@ -7,6 +7,8 @@ #include <vcl/settings.hxx> #include <vcl/virdev.hxx> #include <vcl/ctrl.hxx> +#include <vcl/edit.hxx> +#include <vcl/spinfld.hxx> class SalInstanceBuilder : public weld::Builder { @@ -495,4 +497,122 @@ public: virtual weld::Container* weld_content_area() override; }; +class WeldTextFilter : public TextFilter +{ +private: + Link<OUString&, bool>& m_rInsertTextHdl; + +public: + WeldTextFilter(Link<OUString&, bool>& rInsertTextHdl); + + virtual OUString filter(const OUString& rText) override; +}; + +class SalInstanceEntry : public SalInstanceWidget, public virtual weld::Entry +{ +private: + VclPtr<::Edit> m_xEntry; + + DECL_LINK(ChangeHdl, Edit&, void); + DECL_LINK(CursorListener, VclWindowEvent&, void); + DECL_LINK(ActivateHdl, Edit&, bool); + + WeldTextFilter m_aTextFilter; + +public: + SalInstanceEntry(::Edit* pEntry, SalInstanceBuilder* pBuilder, bool bTakeOwnership); + + virtual void set_text(const OUString& rText) override; + + virtual OUString get_text() const override; + + virtual void set_width_chars(int nChars) override; + + virtual int get_width_chars() const override; + + virtual void set_max_length(int nChars) override; + + virtual void select_region(int nStartPos, int nEndPos) override; + + bool get_selection_bounds(int& rStartPos, int& rEndPos) override; + + virtual void replace_selection(const OUString& rText) override; + + virtual void set_position(int nCursorPos) override; + + virtual int get_position() const override; + + virtual void set_editable(bool bEditable) override; + + virtual bool get_editable() const override; + + virtual void set_message_type(weld::EntryMessageType eType) override; + + virtual void set_font(const vcl::Font& rFont) override; + + virtual void connect_cursor_position(const Link<Entry&, void>& rLink) override; + + virtual void set_placeholder_text(const OUString& rText) override; + + Edit& getEntry(); + + void fire_signal_changed(); + + virtual void cut_clipboard() override; + + virtual void copy_clipboard() override; + + virtual void paste_clipboard() override; + + virtual ~SalInstanceEntry() override; +}; + +class SalInstanceSpinButton : public SalInstanceEntry, public virtual weld::SpinButton +{ +private: + VclPtr<FormattedField> m_xButton; + + DECL_LINK(UpDownHdl, SpinField&, void); + DECL_LINK(LoseFocusHdl, Control&, void); + DECL_LINK(OutputHdl, Edit&, bool); + DECL_LINK(InputHdl, sal_Int64*, TriState); + DECL_LINK(ActivateHdl, Edit&, bool); + + double toField(int nValue) const; + + int fromField(double fValue) const; + +public: + SalInstanceSpinButton(FormattedField* pButton, SalInstanceBuilder* pBuilder, + bool bTakeOwnership); + + virtual int get_value() const override; + + virtual void set_value(int value) override; + + virtual void set_range(int min, int max) override; + + virtual void get_range(int& min, int& max) const override; + + virtual void set_increments(int step, int /*page*/) override; + + virtual void get_increments(int& step, int& page) const override; + + virtual void set_digits(unsigned int digits) override; + + // SpinButton may be comprised of multiple subwidgets, consider the lot as + // one thing for focus + virtual bool has_focus() const override; + + //so with hh::mm::ss, incrementing mm will not reset ss + void DisableRemainderFactor(); + + //off by default for direct SpinButtons, MetricSpinButton enables it + void SetUseThousandSep(); + + virtual unsigned int get_digits() const override; + + virtual ~SalInstanceSpinButton() override; +}; + #endif
\ No newline at end of file diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx index 4d4e1c6372ef..49acab55dcb7 100644 --- a/vcl/source/app/salvtables.cxx +++ b/vcl/source/app/salvtables.cxx @@ -2989,169 +2989,181 @@ IMPL_LINK_NOARG(SalInstanceCalendar, ActivateHdl, ::Calendar*, void) signal_activated(); } -namespace +WeldTextFilter::WeldTextFilter(Link<OUString&, bool>& rInsertTextHdl) + : TextFilter(OUString()) + , m_rInsertTextHdl(rInsertTextHdl) { -class WeldTextFilter : public TextFilter +} + +OUString WeldTextFilter::filter(const OUString& rText) { -private: - Link<OUString&, bool>& m_rInsertTextHdl; + if (!m_rInsertTextHdl.IsSet()) + return rText; + OUString sText(rText); + const bool bContinue = m_rInsertTextHdl.Call(sText); + if (!bContinue) + return OUString(); + return sText; +} -public: - WeldTextFilter(Link<OUString&, bool>& rInsertTextHdl) - : TextFilter(OUString()) - , m_rInsertTextHdl(rInsertTextHdl) - { - } +SalInstanceEntry::SalInstanceEntry(Edit* pEntry, SalInstanceBuilder* pBuilder, bool bTakeOwnership) + : SalInstanceWidget(pEntry, pBuilder, bTakeOwnership) + , m_xEntry(pEntry) + , m_aTextFilter(m_aInsertTextHdl) +{ + m_xEntry->SetModifyHdl(LINK(this, SalInstanceEntry, ChangeHdl)); + m_xEntry->SetActivateHdl(LINK(this, SalInstanceEntry, ActivateHdl)); + m_xEntry->SetTextFilter(&m_aTextFilter); +} - virtual OUString filter(const OUString& rText) override - { - if (!m_rInsertTextHdl.IsSet()) - return rText; - OUString sText(rText); - const bool bContinue = m_rInsertTextHdl.Call(sText); - if (!bContinue) - return OUString(); - return sText; - } -}; +void SalInstanceEntry::set_text(const OUString& rText) +{ + disable_notify_events(); + m_xEntry->SetText(rText); + enable_notify_events(); +} -class SalInstanceEntry : public SalInstanceWidget, public virtual weld::Entry +OUString SalInstanceEntry::get_text() const { -private: - VclPtr<Edit> m_xEntry; + return m_xEntry->GetText(); +} - DECL_LINK(ChangeHdl, Edit&, void); - DECL_LINK(CursorListener, VclWindowEvent&, void); - DECL_LINK(ActivateHdl, Edit&, bool); +void SalInstanceEntry::set_width_chars(int nChars) +{ + m_xEntry->SetWidthInChars(nChars); +} - WeldTextFilter m_aTextFilter; +int SalInstanceEntry::get_width_chars() const +{ + return m_xEntry->GetWidthInChars(); +} -public: - SalInstanceEntry(Edit* pEntry, SalInstanceBuilder* pBuilder, bool bTakeOwnership) - : SalInstanceWidget(pEntry, pBuilder, bTakeOwnership) - , m_xEntry(pEntry) - , m_aTextFilter(m_aInsertTextHdl) - { - m_xEntry->SetModifyHdl(LINK(this, SalInstanceEntry, ChangeHdl)); - m_xEntry->SetActivateHdl(LINK(this, SalInstanceEntry, ActivateHdl)); - m_xEntry->SetTextFilter(&m_aTextFilter); - } +void SalInstanceEntry::set_max_length(int nChars) +{ + m_xEntry->SetMaxTextLen(nChars); +} - virtual void set_text(const OUString& rText) override - { - disable_notify_events(); - m_xEntry->SetText(rText); - enable_notify_events(); - } +void SalInstanceEntry::select_region(int nStartPos, int nEndPos) +{ + disable_notify_events(); + m_xEntry->SetSelection(Selection(nStartPos, nEndPos < 0 ? SELECTION_MAX : nEndPos)); + enable_notify_events(); +} - virtual OUString get_text() const override { return m_xEntry->GetText(); } +bool SalInstanceEntry::get_selection_bounds(int& rStartPos, int& rEndPos) +{ + const Selection& rSelection = m_xEntry->GetSelection(); + rStartPos = rSelection.Min(); + rEndPos = rSelection.Max(); + return rSelection.Len(); +} - virtual void set_width_chars(int nChars) override { m_xEntry->SetWidthInChars(nChars); } +void SalInstanceEntry::replace_selection(const OUString& rText) +{ + m_xEntry->ReplaceSelected(rText); +} - virtual int get_width_chars() const override { return m_xEntry->GetWidthInChars(); } +void SalInstanceEntry::set_position(int nCursorPos) +{ + disable_notify_events(); + if (nCursorPos < 0) + m_xEntry->SetCursorAtLast(); + else + m_xEntry->SetSelection(Selection(nCursorPos, nCursorPos)); + enable_notify_events(); +} - virtual void set_max_length(int nChars) override { m_xEntry->SetMaxTextLen(nChars); } +int SalInstanceEntry::get_position() const +{ + return m_xEntry->GetSelection().Max(); +} - virtual void select_region(int nStartPos, int nEndPos) override - { - disable_notify_events(); - m_xEntry->SetSelection(Selection(nStartPos, nEndPos < 0 ? SELECTION_MAX : nEndPos)); - enable_notify_events(); - } +void SalInstanceEntry::set_editable(bool bEditable) +{ + m_xEntry->SetReadOnly(!bEditable); +} - bool get_selection_bounds(int& rStartPos, int& rEndPos) override - { - const Selection& rSelection = m_xEntry->GetSelection(); - rStartPos = rSelection.Min(); - rEndPos = rSelection.Max(); - return rSelection.Len(); - } +bool SalInstanceEntry::get_editable() const +{ + return !m_xEntry->IsReadOnly(); +} - virtual void replace_selection(const OUString& rText) override +void SalInstanceEntry::set_message_type(weld::EntryMessageType eType) +{ + if (eType == weld::EntryMessageType::Error) { - m_xEntry->ReplaceSelected(rText); + // tdf#114603: enable setting the background to a different color; + // relevant for GTK; see also #i75179# + m_xEntry->SetForceControlBackground(true); + m_xEntry->SetControlForeground(COL_WHITE); + m_xEntry->SetControlBackground(0xff6563); } - - virtual void set_position(int nCursorPos) override + else if (eType == weld::EntryMessageType::Warning) { - disable_notify_events(); - if (nCursorPos < 0) - m_xEntry->SetCursorAtLast(); - else - m_xEntry->SetSelection(Selection(nCursorPos, nCursorPos)); - enable_notify_events(); + // tdf#114603: enable setting the background to a different color; + // relevant for GTK; see also #i75179# + m_xEntry->SetForceControlBackground(true); + m_xEntry->SetControlForeground(); + m_xEntry->SetControlBackground(COL_YELLOW); } - - virtual int get_position() const override { return m_xEntry->GetSelection().Max(); } - - virtual void set_editable(bool bEditable) override { m_xEntry->SetReadOnly(!bEditable); } - - virtual bool get_editable() const override { return !m_xEntry->IsReadOnly(); } - - virtual void set_message_type(weld::EntryMessageType eType) override - { - if (eType == weld::EntryMessageType::Error) - { - // tdf#114603: enable setting the background to a different color; - // relevant for GTK; see also #i75179# - m_xEntry->SetForceControlBackground(true); - m_xEntry->SetControlForeground(COL_WHITE); - m_xEntry->SetControlBackground(0xff6563); - } - else if (eType == weld::EntryMessageType::Warning) - { - // tdf#114603: enable setting the background to a different color; - // relevant for GTK; see also #i75179# - m_xEntry->SetForceControlBackground(true); - m_xEntry->SetControlForeground(); - m_xEntry->SetControlBackground(COL_YELLOW); - } - else - { - m_xEntry->SetForceControlBackground(false); - m_xEntry->SetControlForeground(); - m_xEntry->SetControlBackground(); - } - } - - virtual void set_font(const vcl::Font& rFont) override + else { - m_xEntry->SetPointFont(*m_xEntry, rFont); - m_xEntry->Invalidate(); + m_xEntry->SetForceControlBackground(false); + m_xEntry->SetControlForeground(); + m_xEntry->SetControlBackground(); } +} - virtual void connect_cursor_position(const Link<Entry&, void>& rLink) override - { - assert(!m_aCursorPositionHdl.IsSet()); - m_xEntry->AddEventListener(LINK(this, SalInstanceEntry, CursorListener)); - weld::Entry::connect_cursor_position(rLink); - } +void SalInstanceEntry::set_font(const vcl::Font& rFont) +{ + m_xEntry->SetPointFont(*m_xEntry, rFont); + m_xEntry->Invalidate(); +} - virtual void set_placeholder_text(const OUString& rText) override - { - m_xEntry->SetPlaceholderText(rText); - } +void SalInstanceEntry::connect_cursor_position(const Link<Entry&, void>& rLink) +{ + assert(!m_aCursorPositionHdl.IsSet()); + m_xEntry->AddEventListener(LINK(this, SalInstanceEntry, CursorListener)); + weld::Entry::connect_cursor_position(rLink); +} - Edit& getEntry() { return *m_xEntry; } +void SalInstanceEntry::set_placeholder_text(const OUString& rText) +{ + m_xEntry->SetPlaceholderText(rText); +} - void fire_signal_changed() { signal_changed(); } +Edit& SalInstanceEntry::getEntry() +{ + return *m_xEntry; +} - virtual void cut_clipboard() override { m_xEntry->Cut(); } +void SalInstanceEntry::fire_signal_changed() +{ + signal_changed(); +} - virtual void copy_clipboard() override { m_xEntry->Copy(); } +void SalInstanceEntry::cut_clipboard() +{ + m_xEntry->Cut(); +} - virtual void paste_clipboard() override { m_xEntry->Paste(); } +void SalInstanceEntry::copy_clipboard() +{ + m_xEntry->Copy(); +} - virtual ~SalInstanceEntry() override - { - if (m_aCursorPositionHdl.IsSet()) - m_xEntry->RemoveEventListener(LINK(this, SalInstanceEntry, CursorListener)); - m_xEntry->SetTextFilter(nullptr); - m_xEntry->SetActivateHdl(Link<Edit&, bool>()); - m_xEntry->SetModifyHdl(Link<Edit&, void>()); - } -}; +void SalInstanceEntry::paste_clipboard() +{ + m_xEntry->Paste(); +} +SalInstanceEntry::~SalInstanceEntry() +{ + if (m_aCursorPositionHdl.IsSet()) + m_xEntry->RemoveEventListener(LINK(this, SalInstanceEntry, CursorListener)); + m_xEntry->SetTextFilter(nullptr); + m_xEntry->SetActivateHdl(Link<Edit&, bool>()); + m_xEntry->SetModifyHdl(Link<Edit&, void>()); } IMPL_LINK_NOARG(SalInstanceEntry, ChangeHdl, Edit&, void) { signal_changed(); } @@ -4912,96 +4924,106 @@ IMPL_LINK_NOARG(SalInstanceIconView, DoubleClickHdl, SvTreeListBox*, bool) return !signal_item_activated(); } -namespace -{ -class SalInstanceSpinButton : public SalInstanceEntry, public virtual weld::SpinButton +double SalInstanceSpinButton::toField(int nValue) const { -private: - VclPtr<FormattedField> m_xButton; - - DECL_LINK(UpDownHdl, SpinField&, void); - DECL_LINK(LoseFocusHdl, Control&, void); - DECL_LINK(OutputHdl, Edit&, bool); - DECL_LINK(InputHdl, sal_Int64*, TriState); - DECL_LINK(ActivateHdl, Edit&, bool); - - double toField(int nValue) const { return static_cast<double>(nValue) / Power10(get_digits()); } - - int fromField(double fValue) const { return FRound(fValue * Power10(get_digits())); } - -public: - SalInstanceSpinButton(FormattedField* pButton, SalInstanceBuilder* pBuilder, - bool bTakeOwnership) - : SalInstanceEntry(pButton, pBuilder, bTakeOwnership) - , m_xButton(pButton) - { - m_xButton->SetThousandsSep(false); //off by default, MetricSpinButton enables it - m_xButton->SetUpHdl(LINK(this, SalInstanceSpinButton, UpDownHdl)); - m_xButton->SetDownHdl(LINK(this, SalInstanceSpinButton, UpDownHdl)); - m_xButton->SetLoseFocusHdl(LINK(this, SalInstanceSpinButton, LoseFocusHdl)); - m_xButton->SetOutputHdl(LINK(this, SalInstanceSpinButton, OutputHdl)); - m_xButton->SetInputHdl(LINK(this, SalInstanceSpinButton, InputHdl)); - if (Edit* pEdit = m_xButton->GetSubEdit()) - pEdit->SetActivateHdl(LINK(this, SalInstanceSpinButton, ActivateHdl)); - else - m_xButton->SetActivateHdl(LINK(this, SalInstanceSpinButton, ActivateHdl)); + return static_cast<double>(nValue) / Power10(get_digits()); } - virtual int get_value() const override { return fromField(m_xButton->GetValue()); } +int SalInstanceSpinButton::fromField(double fValue) const +{ + return FRound(fValue * Power10(get_digits())); +} - virtual void set_value(int value) override { m_xButton->SetValue(toField(value)); } +SalInstanceSpinButton::SalInstanceSpinButton(FormattedField* pButton, SalInstanceBuilder* pBuilder, + bool bTakeOwnership) + : SalInstanceEntry(pButton, pBuilder, bTakeOwnership) + , m_xButton(pButton) +{ + m_xButton->SetThousandsSep(false); //off by default, MetricSpinButton enables it + m_xButton->SetUpHdl(LINK(this, SalInstanceSpinButton, UpDownHdl)); + m_xButton->SetDownHdl(LINK(this, SalInstanceSpinButton, UpDownHdl)); + m_xButton->SetLoseFocusHdl(LINK(this, SalInstanceSpinButton, LoseFocusHdl)); + m_xButton->SetOutputHdl(LINK(this, SalInstanceSpinButton, OutputHdl)); + m_xButton->SetInputHdl(LINK(this, SalInstanceSpinButton, InputHdl)); + if (Edit* pEdit = m_xButton->GetSubEdit()) + pEdit->SetActivateHdl(LINK(this, SalInstanceSpinButton, ActivateHdl)); + else + m_xButton->SetActivateHdl(LINK(this, SalInstanceSpinButton, ActivateHdl)); +} - virtual void set_range(int min, int max) override - { - m_xButton->SetMinValue(toField(min)); - m_xButton->SetMaxValue(toField(max)); +int SalInstanceSpinButton::get_value() const +{ + return fromField(m_xButton->GetValue()); } - virtual void get_range(int& min, int& max) const override - { - min = fromField(m_xButton->GetMinValue()); - max = fromField(m_xButton->GetMaxValue()); +void SalInstanceSpinButton::set_value(int value) +{ + m_xButton->SetValue(toField(value)); } - virtual void set_increments(int step, int /*page*/) override - { - m_xButton->SetSpinSize(toField(step)); - } +void SalInstanceSpinButton::set_range(int min, int max) +{ + m_xButton->SetMinValue(toField(min)); + m_xButton->SetMaxValue(toField(max)); +} - virtual void get_increments(int& step, int& page) const override - { - step = fromField(m_xButton->GetSpinSize()); - page = fromField(m_xButton->GetSpinSize()); - } +void SalInstanceSpinButton::get_range(int& min, int& max) const +{ + min = fromField(m_xButton->GetMinValue()); + max = fromField(m_xButton->GetMaxValue()); +} - virtual void set_digits(unsigned int digits) override { m_xButton->SetDecimalDigits(digits); } +void SalInstanceSpinButton::set_increments(int step, int /*page*/) +{ + m_xButton->SetSpinSize(toField(step)); +} - // SpinButton may be comprised of multiple subwidgets, consider the lot as - // one thing for focus - virtual bool has_focus() const override { return m_xWidget->HasChildPathFocus(); } +void SalInstanceSpinButton::get_increments(int& step, int& page) const +{ + step = fromField(m_xButton->GetSpinSize()); + page = fromField(m_xButton->GetSpinSize()); +} - //so with hh::mm::ss, incrementing mm will not reset ss - void DisableRemainderFactor() { m_xButton->DisableRemainderFactor(); } +void SalInstanceSpinButton::set_digits(unsigned int digits) +{ + m_xButton->SetDecimalDigits(digits); +} - //off by default for direct SpinButtons, MetricSpinButton enables it - void SetUseThousandSep() { m_xButton->SetThousandsSep(true); } +// SpinButton may be comprised of multiple subwidgets, consider the lot as +// one thing for focus +bool SalInstanceSpinButton::has_focus() const +{ + return m_xWidget->HasChildPathFocus(); +} + +//so with hh::mm::ss, incrementing mm will not reset ss +void SalInstanceSpinButton::DisableRemainderFactor() +{ + m_xButton->DisableRemainderFactor(); +} - virtual unsigned int get_digits() const override { return m_xButton->GetDecimalDigits(); } +//off by default for direct SpinButtons, MetricSpinButton enables it +void SalInstanceSpinButton::SetUseThousandSep() +{ + m_xButton->SetThousandsSep(true); +} - virtual ~SalInstanceSpinButton() override - { - if (Edit* pEdit = m_xButton->GetSubEdit()) - pEdit->SetActivateHdl(Link<Edit&, bool>()); - else - m_xButton->SetActivateHdl(Link<Edit&, bool>()); - m_xButton->SetInputHdl(Link<sal_Int64*, TriState>()); - m_xButton->SetOutputHdl(Link<Edit&, bool>()); - m_xButton->SetLoseFocusHdl(Link<Control&, void>()); - m_xButton->SetDownHdl(Link<SpinField&, void>()); - m_xButton->SetUpHdl(Link<SpinField&, void>()); - } -}; +unsigned int SalInstanceSpinButton::get_digits() const +{ + return m_xButton->GetDecimalDigits(); +} +SalInstanceSpinButton::~SalInstanceSpinButton() +{ + if (Edit* pEdit = m_xButton->GetSubEdit()) + pEdit->SetActivateHdl(Link<Edit&, bool>()); + else + m_xButton->SetActivateHdl(Link<Edit&, bool>()); + m_xButton->SetInputHdl(Link<sal_Int64*, TriState>()); + m_xButton->SetOutputHdl(Link<Edit&, bool>()); + m_xButton->SetLoseFocusHdl(Link<Control&, void>()); + m_xButton->SetDownHdl(Link<SpinField&, void>()); + m_xButton->SetUpHdl(Link<SpinField&, void>()); } IMPL_LINK_NOARG(SalInstanceSpinButton, ActivateHdl, Edit&, bool) |