diff options
author | Caolán McNamara <caolanm@redhat.com> | 2021-08-04 12:44:37 +0100 |
---|---|---|
committer | Michael Stahl <michael.stahl@allotropia.de> | 2021-08-10 19:52:56 +0200 |
commit | e77d6b92c51a8adf517fd283cf8984345bc3f8ce (patch) | |
tree | d36db90c2d7348781c85deb4c15bdd4f8ad2eb0a /svx | |
parent | 99420dc0b80df22d12519efca05803898fbfcfbd (diff) |
Resolves: tdf#143023 explicitly connect to ControlBase focus-[in/out]
instead of listening to the generic vcl::Window/Control focus events.
The thing which really gets/loses focus is now a Widget hosted inside
the ControlBase.
also contains...
fix comment
Change-Id: Ia1783aff3fded7fd73de2b04b9aced647771a92c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119998
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
establish that DbCellControl Window member is always a ControlBase
and remove resulting known redundant dynamic_casting
Change-Id: I5f098ef1adee3ad5d2a2bc5fcd30523f980df2f9
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119999
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
EventWindow is always a svt::ControlBase
Change-Id: I012d0bea687aa6d5965a4e2f6ce3899bfc629f1b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120004
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
Diffstat (limited to 'svx')
-rw-r--r-- | svx/source/fmcomp/gridcell.cxx | 103 | ||||
-rw-r--r-- | svx/source/inc/gridcell.hxx | 23 |
2 files changed, 52 insertions, 74 deletions
diff --git a/svx/source/fmcomp/gridcell.cxx b/svx/source/fmcomp/gridcell.cxx index cb5129e89326..f768d4cb134b 100644 --- a/svx/source/fmcomp/gridcell.cxx +++ b/svx/source/fmcomp/gridcell.cxx @@ -801,16 +801,12 @@ void DbCellControl::implAdjustReadOnly( const Reference< XPropertySet >& _rxMode if ( !(m_pWindow && _rxModel.is()) ) return; - ControlBase* pEditWindow = dynamic_cast<ControlBase*>(m_pWindow.get()); - if ( pEditWindow ) + bool bReadOnly = m_rColumn.IsReadOnly(); + if ( !bReadOnly ) { - bool bReadOnly = m_rColumn.IsReadOnly(); - if ( !bReadOnly ) - { - _rxModel->getPropertyValue( i_bReadOnly ? OUString(FM_PROP_READONLY) : OUString(FM_PROP_ISREADONLY)) >>= bReadOnly; - } - pEditWindow->SetEditableReadOnly(bReadOnly); + _rxModel->getPropertyValue( i_bReadOnly ? OUString(FM_PROP_READONLY) : OUString(FM_PROP_ISREADONLY)) >>= bReadOnly; } + m_pWindow->SetEditableReadOnly(bReadOnly); } void DbCellControl::implAdjustEnabled( const Reference< XPropertySet >& _rxModel ) @@ -1920,7 +1916,7 @@ void DbNumericField::implAdjustGenericFieldSetting( const Reference< XPropertySe rPaintFormatter.SetFormat( sFormatString, aAppLanguage ); } -VclPtr<Control> DbNumericField::createField(BrowserDataWin* pParent, bool bSpinButton, const Reference<XPropertySet>& /*rxModel*/) +VclPtr<svt::ControlBase> DbNumericField::createField(BrowserDataWin* pParent, bool bSpinButton, const Reference<XPropertySet>& /*rxModel*/) { return VclPtr<DoubleNumericControl>::Create(pParent, bSpinButton); } @@ -2040,7 +2036,7 @@ void DbCurrencyField::implAdjustGenericFieldSetting( const Reference< XPropertyS rPaintCurrencyFormatter.SetCurrencySymbol(aStr); } -VclPtr<Control> DbCurrencyField::createField(BrowserDataWin* pParent, bool bSpinButton, const Reference< XPropertySet >& /*rxModel*/) +VclPtr<svt::ControlBase> DbCurrencyField::createField(BrowserDataWin* pParent, bool bSpinButton, const Reference< XPropertySet >& /*rxModel*/) { return VclPtr<LongCurrencyControl>::Create(pParent, bSpinButton); } @@ -2123,7 +2119,7 @@ DbDateField::DbDateField( DbGridColumn& _rColumn ) doPropertyListening( FM_PROP_DATE_SHOW_CENTURY ); } -VclPtr<Control> DbDateField::createField(BrowserDataWin* pParent, bool bSpinButton, const Reference< XPropertySet >& rxModel) +VclPtr<svt::ControlBase> DbDateField::createField(BrowserDataWin* pParent, bool bSpinButton, const Reference< XPropertySet >& rxModel) { // check if there is a DropDown property set to TRUE bool bDropDown = !hasProperty( FM_PROP_DROPDOWN, rxModel ) @@ -2249,7 +2245,7 @@ DbTimeField::DbTimeField( DbGridColumn& _rColumn ) doPropertyListening( FM_PROP_STRICTFORMAT ); } -VclPtr<Control> DbTimeField::createField(BrowserDataWin* pParent, bool bSpinButton, const Reference< XPropertySet >& /*rxModel*/ ) +VclPtr<svt::ControlBase> DbTimeField::createField(BrowserDataWin* pParent, bool bSpinButton, const Reference< XPropertySet >& /*rxModel*/ ) { return VclPtr<TimeControl>::Create(pParent, bSpinButton); } @@ -2762,9 +2758,8 @@ void DbFilterField::Init(BrowserDataWin& rParent, const Reference< XRowSet >& xC DbCellControl::Init( rParent, xCursor ); // filter cells are never readonly - ControlBase* pAsEdit = dynamic_cast<ControlBase*>(m_pWindow.get()); - if (pAsEdit) - pAsEdit->SetEditableReadOnly(false); + if (m_pWindow) + m_pWindow->SetEditableReadOnly(false); } CellControllerRef DbFilterField::CreateController() const @@ -3088,7 +3083,6 @@ IMPL_LINK_NOARG(DbFilterField, OnToggle, weld::CheckButton&, void) } } - FmXGridCell::FmXGridCell( DbGridColumn* pColumn, std::unique_ptr<DbCellControl> _pControl ) :OComponentHelper(m_aMutex) ,m_pColumn(pColumn) @@ -3101,23 +3095,24 @@ FmXGridCell::FmXGridCell( DbGridColumn* pColumn, std::unique_ptr<DbCellControl> { } - void FmXGridCell::init() { - vcl::Window* pEventWindow( getEventWindow() ); + svt::ControlBase* pEventWindow( getEventWindow() ); if ( pEventWindow ) + { pEventWindow->AddEventListener( LINK( this, FmXGridCell, OnWindowEvent ) ); + pEventWindow->SetFocusInHdl(LINK( this, FmXGridCell, OnFocusGained)); + pEventWindow->SetFocusOutHdl(LINK( this, FmXGridCell, OnFocusLost)); + } } - -vcl::Window* FmXGridCell::getEventWindow() const +svt::ControlBase* FmXGridCell::getEventWindow() const { if ( m_pCellControl ) return &m_pCellControl->GetWindow(); return nullptr; } - FmXGridCell::~FmXGridCell() { if (!OComponentHelper::rBHelper.bDisposed) @@ -3128,14 +3123,12 @@ FmXGridCell::~FmXGridCell() } - void FmXGridCell::SetTextLineColor() { if (m_pCellControl) m_pCellControl->SetTextLineColor(); } - void FmXGridCell::SetTextLineColor(const Color& _rColor) { if (m_pCellControl) @@ -3331,78 +3324,62 @@ void SAL_CALL FmXGridCell::removeMouseMotionListener( const Reference< awt::XMou m_aMouseMotionListeners.removeInterface( _rxListener ); } - void SAL_CALL FmXGridCell::addPaintListener( const Reference< awt::XPaintListener >& ) { OSL_FAIL( "FmXGridCell::addPaintListener: not implemented" ); } - void SAL_CALL FmXGridCell::removePaintListener( const Reference< awt::XPaintListener >& ) { OSL_FAIL( "FmXGridCell::removePaintListener: not implemented" ); } - IMPL_LINK( FmXGridCell, OnWindowEvent, VclWindowEvent&, _rEvent, void ) { ENSURE_OR_THROW( _rEvent.GetWindow(), "illegal window" ); - onWindowEvent( _rEvent.GetId(), *_rEvent.GetWindow(), _rEvent.GetData() ); + onWindowEvent(_rEvent.GetId(), _rEvent.GetData()); } - void FmXGridCell::onFocusGained( const awt::FocusEvent& _rEvent ) { checkDisposed(OComponentHelper::rBHelper.bDisposed); m_aFocusListeners.notifyEach( &awt::XFocusListener::focusGained, _rEvent ); } - void FmXGridCell::onFocusLost( const awt::FocusEvent& _rEvent ) { checkDisposed(OComponentHelper::rBHelper.bDisposed); m_aFocusListeners.notifyEach( &awt::XFocusListener::focusLost, _rEvent ); } +IMPL_LINK_NOARG(FmXGridCell, OnFocusGained, LinkParamNone*, void) +{ + if (!m_aFocusListeners.getLength()) + return; + + awt::FocusEvent aEvent; + aEvent.Source = *this; + aEvent.Temporary = false; -void FmXGridCell::onWindowEvent( const VclEventId _nEventId, const vcl::Window& _rWindow, const void* _pEventData ) + onFocusGained(aEvent); +} + +IMPL_LINK_NOARG(FmXGridCell, OnFocusLost, LinkParamNone*, void) { - switch ( _nEventId ) - { - case VclEventId::ControlGetFocus: - case VclEventId::WindowGetFocus: - case VclEventId::ControlLoseFocus: - case VclEventId::WindowLoseFocus: - { - if ( ( _rWindow.IsCompoundControl() - && ( _nEventId == VclEventId::ControlGetFocus - || _nEventId == VclEventId::ControlLoseFocus - ) - ) - || ( !_rWindow.IsCompoundControl() - && ( _nEventId == VclEventId::WindowGetFocus - || _nEventId == VclEventId::WindowLoseFocus - ) - ) - ) - { - if ( !m_aFocusListeners.getLength() ) - break; + if (!m_aFocusListeners.getLength()) + return; - bool bFocusGained = ( _nEventId == VclEventId::ControlGetFocus ) || ( _nEventId == VclEventId::WindowGetFocus ); + awt::FocusEvent aEvent; + aEvent.Source = *this; + aEvent.Temporary = false; - awt::FocusEvent aEvent; - aEvent.Source = *this; - aEvent.FocusFlags = static_cast<sal_Int16>(_rWindow.GetGetFocusFlags()); - aEvent.Temporary = false; + onFocusLost(aEvent); +} - if ( bFocusGained ) - onFocusGained( aEvent ); - else - onFocusLost( aEvent ); - } - } - break; +void FmXGridCell::onWindowEvent(const VclEventId _nEventId, const void* _pEventData) +{ + switch ( _nEventId ) + { case VclEventId::WindowMouseButtonDown: case VclEventId::WindowMouseButtonUp: { diff --git a/svx/source/inc/gridcell.hxx b/svx/source/inc/gridcell.hxx index 0ffeebcf84b2..45a92c0011c3 100644 --- a/svx/source/inc/gridcell.hxx +++ b/svx/source/inc/gridcell.hxx @@ -211,8 +211,8 @@ private: protected: DbGridColumn& m_rColumn; - VclPtr<vcl::Window> m_pPainter; - VclPtr<vcl::Window> m_pWindow; + VclPtr<svt::ControlBase> m_pPainter; + VclPtr<svt::ControlBase> m_pWindow; protected: // attribute access @@ -262,8 +262,7 @@ public: DbCellControl(DbGridColumn& _rColumn); virtual ~DbCellControl() override; - - vcl::Window& GetWindow() const + svt::ControlBase& GetWindow() const { ENSURE_OR_THROW( m_pWindow, "no window" ); return *m_pWindow; @@ -545,7 +544,7 @@ public: virtual ::svt::CellControllerRef CreateController() const override; protected: - virtual VclPtr<Control> createField( + virtual VclPtr<svt::ControlBase> createField( BrowserDataWin* _pParent, bool bSpinButton, const css::uno::Reference< css::beans::XPropertySet >& _rxModel @@ -565,7 +564,7 @@ protected: virtual void updateFromModel( css::uno::Reference< css::beans::XPropertySet > _rxModel ) override; // DbSpinField - virtual VclPtr<Control> createField( + virtual VclPtr<svt::ControlBase> createField( BrowserDataWin* _pParent, bool bSpinButton, const css::uno::Reference< css::beans::XPropertySet >& _rxModel @@ -588,7 +587,7 @@ protected: virtual void updateFromModel( css::uno::Reference< css::beans::XPropertySet > _rxModel ) override; // DbSpinField - virtual VclPtr<Control> createField( + virtual VclPtr<svt::ControlBase> createField( BrowserDataWin* _pParent, bool bSpinButton, const css::uno::Reference< css::beans::XPropertySet >& _rxModel @@ -611,7 +610,7 @@ protected: virtual void updateFromModel( css::uno::Reference< css::beans::XPropertySet > _rxModel ) override; // DbSpinField - virtual VclPtr<Control> createField( + virtual VclPtr<svt::ControlBase> createField( BrowserDataWin* _pParent, bool bSpinButton, const css::uno::Reference< css::beans::XPropertySet >& _rxModel @@ -635,7 +634,7 @@ protected: virtual void updateFromModel( css::uno::Reference< css::beans::XPropertySet > _rxModel ) override; // DbSpinField - virtual VclPtr<Control> createField( + virtual VclPtr<svt::ControlBase> createField( BrowserDataWin* _pParent, bool bSpinButton, const css::uno::Reference< css::beans::XPropertySet >& _rxModel @@ -776,14 +775,16 @@ public: { m_pCellControl->AlignControl(nAlignment);} protected: - void onWindowEvent( const VclEventId _nEventId, const vcl::Window& _rWindow, const void* _pEventData ); + void onWindowEvent(const VclEventId _nEventId, const void* _pEventData); // default implementations call our focus listeners, don't forget to call them if you override this virtual void onFocusGained( const css::awt::FocusEvent& _rEvent ); virtual void onFocusLost( const css::awt::FocusEvent& _rEvent ); private: - vcl::Window* getEventWindow() const; + svt::ControlBase* getEventWindow() const; + DECL_LINK(OnFocusGained, LinkParamNone*, void); + DECL_LINK(OnFocusLost, LinkParamNone*, void); DECL_LINK( OnWindowEvent, VclWindowEvent&, void ); }; |