diff options
author | Caolán McNamara <caolanm@redhat.com> | 2020-06-26 20:57:29 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2020-07-01 18:04:46 +0200 |
commit | d2f1cd004310b9ea6654d17fddc11cb08e884c90 (patch) | |
tree | 2d2ad2d4afa5e2eb1c62a8e7ee1ac7bd0bf4f791 /include/svtools | |
parent | 96dc14a041ea803f0d194a47a8f3d62f6cfa37be (diff) |
weld EditControl for browsebox
Change-Id: I8f21c12f7ee10e1b9ba883a8ff01bb5252429f09
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97353
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'include/svtools')
-rw-r--r-- | include/svtools/editbrowsebox.hxx | 173 | ||||
-rw-r--r-- | include/svtools/editimplementation.hxx | 21 |
2 files changed, 153 insertions, 41 deletions
diff --git a/include/svtools/editbrowsebox.hxx b/include/svtools/editbrowsebox.hxx index ac84f078b6b1..73f12c5c50d7 100644 --- a/include/svtools/editbrowsebox.hxx +++ b/include/svtools/editbrowsebox.hxx @@ -29,6 +29,7 @@ #include <svtools/brwbox.hxx> #include <svtools/brwhead.hxx> +#include <tools/lineend.hxx> #include <vcl/InterimItemWindow.hxx> #include <vcl/vclmedit.hxx> #include <o3tl/typed_flags_set.hxx> @@ -93,9 +94,8 @@ namespace svt Control& GetWindow() const { return *const_cast< CellController* >( this )->pWindow; } - virtual void SetModified(); - virtual void ClearModified() = 0; - virtual bool IsModified() const = 0; + virtual void SaveValue() = 0; + virtual bool IsValueChangedFromSaved() const = 0; // commit any current changes. Especially, do any reformatting you need (from input formatting // to output formatting) here @@ -140,9 +140,8 @@ namespace svt virtual void ReplaceSelected( const OUString& _rStr ) = 0; virtual OUString GetSelected( LineEnd aSeparator ) const = 0; - virtual void SetModified() = 0; - virtual bool IsModified() const = 0; - virtual void ClearModified() = 0; + virtual bool IsValueChangedFromSaved() const = 0; + virtual void SaveValue() = 0; virtual void SetModifyHdl( const Link<LinkParamNone*,void>& _rLink ) = 0; }; @@ -177,12 +176,127 @@ namespace svt virtual void ReplaceSelected( const OUString& _rStr ) override; virtual OUString GetSelected( LineEnd aSeparator ) const override; - virtual void SetModified() override; - virtual bool IsModified() const override; - virtual void ClearModified() override; + virtual bool IsValueChangedFromSaved() const override; + virtual void SaveValue() override; virtual void SetModifyHdl( const Link<LinkParamNone*,void>& _rLink ) override; }; + class SVT_DLLPUBLIC EditControl final : public InterimItemWindow + { + public: + EditControl(vcl::Window* pParent); + + virtual void dispose() override; + + virtual void GetFocus() override + { + if (m_xWidget) + m_xWidget->grab_focus(); + InterimItemWindow::GetFocus(); + } + + weld::Entry& get_widget() { return *m_xWidget; } + + private: + std::unique_ptr<weld::Entry> m_xWidget; + + DECL_LINK(KeyInputHdl, const KeyEvent&, bool); + }; + + class SVT_DLLPUBLIC EntryImplementation : public IEditImplementation + { + EditControl& m_rEdit; + int m_nMaxTextLen; + Link<LinkParamNone*,void> m_aModifyHdl; + + DECL_LINK(ModifyHdl, weld::Entry&, void); + public: + EntryImplementation(EditControl& rEdit) + : m_rEdit(rEdit) + , m_nMaxTextLen(EDIT_NOLIMIT) + { + m_rEdit.get_widget().connect_changed(LINK(this, EntryImplementation, ModifyHdl)); + } + + virtual Control& GetControl() override + { + return m_rEdit; + } + + virtual OUString GetText( LineEnd /*aSeparator*/ ) const override + { + // ignore the line end - this base implementation does not support it + return m_rEdit.get_widget().get_text(); + } + + virtual void SetText( const OUString& _rStr ) override + { + return m_rEdit.get_widget().set_text(_rStr); + } + + virtual bool IsReadOnly() const override + { + return !m_rEdit.get_widget().get_editable(); + } + + virtual void SetReadOnly( bool bReadOnly ) override + { + m_rEdit.get_widget().set_editable(!bReadOnly); + } + + virtual sal_Int32 GetMaxTextLen() const override + { + return m_nMaxTextLen; + } + + virtual void SetMaxTextLen( sal_Int32 nMaxLen ) override + { + m_nMaxTextLen = nMaxLen; + m_rEdit.get_widget().set_max_length(nMaxLen == EDIT_NOLIMIT ? 0 : nMaxLen); + } + + virtual Selection GetSelection() const override + { + int nStartPos, nEndPos; + m_rEdit.get_widget().get_selection_bounds(nStartPos, nEndPos); + return Selection(nStartPos, nEndPos); + } + + virtual void SetSelection( const Selection& rSelection ) override + { + m_rEdit.get_widget().select_region(rSelection.Min(), rSelection.Max()); + } + + virtual void ReplaceSelected( const OUString& rStr ) override + { + m_rEdit.get_widget().replace_selection(rStr); + } + + virtual OUString GetSelected( LineEnd /*aSeparator*/ ) const override + // ignore the line end - this base implementation does not support it + { + int nStartPos, nEndPos; + weld::Entry& rEntry = m_rEdit.get_widget(); + rEntry.get_selection_bounds(nStartPos, nEndPos); + return rEntry.get_text().copy(nStartPos, nEndPos - nStartPos); + } + + virtual bool IsValueChangedFromSaved() const override + { + return m_rEdit.get_widget().get_value_changed_from_saved(); + } + + virtual void SaveValue() override + { + m_rEdit.get_widget().save_value(); + } + + virtual void SetModifyHdl( const Link<LinkParamNone*,void>& rLink ) override + { + m_aModifyHdl = rLink; + } + }; + #include <svtools/editimplementation.hxx> @@ -244,15 +358,15 @@ namespace svt public: EditCellController( Edit* _pEdit ); + EditCellController( EditControl* _pEdit ); EditCellController( IEditImplementation* _pImplementation ); virtual ~EditCellController( ) override; const IEditImplementation* GetEditImplementation( ) const { return m_pEditImplementation; } IEditImplementation* GetEditImplementation( ) { return m_pEditImplementation; } - virtual void SetModified() override; - virtual bool IsModified() const override; - virtual void ClearModified() override; + virtual bool IsValueChangedFromSaved() const override; + virtual void SaveValue() override; protected: virtual bool MoveAllowed(const KeyEvent& rEvt) const override; @@ -270,9 +384,8 @@ namespace svt const SpinField& GetSpinWindow() const; SpinField& GetSpinWindow(); - virtual void SetModified() override; - virtual bool IsModified() const override; - virtual void ClearModified() override; + virtual bool IsValueChangedFromSaved() const override; + virtual void SaveValue() override; private: virtual bool MoveAllowed(const KeyEvent& rEvt) const override; @@ -319,8 +432,8 @@ namespace svt CheckBoxCellController(CheckBoxControl* pWin); CheckBox& GetCheckBox() const; - virtual bool IsModified() const override; - virtual void ClearModified() override; + virtual bool IsValueChangedFromSaved() const override; + virtual void SaveValue() override; private: virtual bool WantMouseEvent() const override; @@ -335,6 +448,13 @@ namespace svt public: ComboBoxControl(vcl::Window* pParent); + virtual void GetFocus() override + { + if (m_xWidget) + m_xWidget->grab_focus(); + InterimItemWindow::GetFocus(); + } + weld::ComboBox& get_widget() { return *m_xWidget; } virtual void dispose() override; @@ -351,8 +471,8 @@ namespace svt ComboBoxCellController(ComboBoxControl* pParent); weld::ComboBox& GetComboBox() const { return static_cast<ComboBoxControl&>(GetWindow()).get_widget(); } - virtual bool IsModified() const override; - virtual void ClearModified() override; + virtual bool IsValueChangedFromSaved() const override; + virtual void SaveValue() override; protected: virtual bool MoveAllowed(const KeyEvent& rEvt) const override; @@ -368,6 +488,13 @@ namespace svt public: ListBoxControl(vcl::Window* pParent); + virtual void GetFocus() override + { + if (m_xWidget) + m_xWidget->grab_focus(); + InterimItemWindow::GetFocus(); + } + weld::ComboBox& get_widget() { return *m_xWidget; } virtual void dispose() override; @@ -383,8 +510,8 @@ namespace svt ListBoxCellController(ListBoxControl* pParent); weld::ComboBox& GetListBox() const { return static_cast<ListBoxControl&>(GetWindow()).get_widget(); } - virtual bool IsModified() const override; - virtual void ClearModified() override; + virtual bool IsValueChangedFromSaved() const override; + virtual void SaveValue() override; protected: virtual bool MoveAllowed(const KeyEvent& rEvt) const override; @@ -403,7 +530,6 @@ namespace svt //= EditBrowserHeader - class SVT_DLLPUBLIC EditBrowserHeader : public BrowserHeader { public: @@ -416,7 +542,6 @@ namespace svt //= EditBrowseBox - class EditBrowseBoxImpl; class SVT_DLLPUBLIC EditBrowseBox: public BrowseBox { @@ -552,7 +677,7 @@ namespace svt // return sal_False prevents leaving the cell virtual bool SaveRow(); // commit the current row - virtual bool IsModified() const {return aController.is() && aController->IsModified();} + virtual bool IsModified() const {return aController.is() && aController->IsValueChangedFromSaved();} virtual CellController* GetController(long nRow, sal_uInt16 nCol); virtual void InitController(CellControllerRef& rController, long nRow, sal_uInt16 nCol); diff --git a/include/svtools/editimplementation.hxx b/include/svtools/editimplementation.hxx index ceddf0a81fbc..9797009b2369 100644 --- a/include/svtools/editimplementation.hxx +++ b/include/svtools/editimplementation.hxx @@ -84,49 +84,36 @@ void GenericEditImplementation< EDIT >::ReplaceSelected( const OUString& _rStr ) m_rEdit.ReplaceSelected( _rStr ); } - template <class EDIT> OUString GenericEditImplementation< EDIT >::GetSelected( LineEnd ) const { return m_rEdit.GetSelected( ); } - template <class EDIT> void GenericEditImplementation< EDIT >::SetMaxTextLen( sal_Int32 _nMaxLen ) { m_rEdit.SetMaxTextLen( _nMaxLen ); } - template <class EDIT> sal_Int32 GenericEditImplementation< EDIT >::GetMaxTextLen() const { return m_rEdit.GetMaxTextLen( ); } - template <class EDIT> -void GenericEditImplementation< EDIT >::SetModified() +bool GenericEditImplementation< EDIT >::IsValueChangedFromSaved() const { - m_rEdit.SetModifyFlag(); + return m_rEdit.IsValueChangedFromSaved(); } - template <class EDIT> -bool GenericEditImplementation< EDIT >::IsModified() const +void GenericEditImplementation< EDIT >::SaveValue() { - return m_rEdit.IsModified(); + m_rEdit.SaveValue(); } - -template <class EDIT> -void GenericEditImplementation< EDIT >::ClearModified() -{ - m_rEdit.ClearModifyFlag(); -} - - template <class EDIT> void GenericEditImplementation< EDIT >::SetModifyHdl( const Link<LinkParamNone*,void>& _rLink ) { |