diff options
author | Michael Stahl <mstahl@redhat.com> | 2015-11-12 23:37:12 +0100 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2015-11-13 12:25:25 +0100 |
commit | 5fe66069010e9afc3a16d238592c3b672850514c (patch) | |
tree | 30ef1669092bbb7df50740a80a1c275d57859347 /sc/source | |
parent | 613ef01748bd155653954f1effe00e395ba38a3b (diff) |
sc: loplugin:badstatics: remove pActiveEdWnd global variable
Just use a Link, or rather std::function to set a member in the tab
page. Unfortunately loplugin:vclwidgets complains about the new member.
Change-Id: Ie2f9cb73c38292d02057d43b12694c6609fa0db8
Diffstat (limited to 'sc/source')
-rw-r--r-- | sc/source/ui/inc/scuitphfedit.hxx | 4 | ||||
-rw-r--r-- | sc/source/ui/inc/tphfedit.hxx | 4 | ||||
-rw-r--r-- | sc/source/ui/pagedlg/scuitphfedit.cxx | 36 | ||||
-rw-r--r-- | sc/source/ui/pagedlg/tphfedit.cxx | 11 |
4 files changed, 30 insertions, 25 deletions
diff --git a/sc/source/ui/inc/scuitphfedit.hxx b/sc/source/ui/inc/scuitphfedit.hxx index fbdf7cd4183f..326f6b356661 100644 --- a/sc/source/ui/inc/scuitphfedit.hxx +++ b/sc/source/ui/inc/scuitphfedit.hxx @@ -82,6 +82,8 @@ private: VclPtr<FixedText> m_pFtCreatedBy; VclPtr<FixedText> m_pFtCustomized; + ScEditWindow * m_pEditFocus; ///one of m_pWndLeft, m_pWndCenter, m_pWndRight + sal_uInt16 nWhich; OUString aCmdArr[6]; @@ -99,7 +101,7 @@ private: static bool IsExtFileNameEntry(EditTextObject* pTextObj); DECL_LINK_TYPED( ListHdl_Impl, ListBox&, void); DECL_LINK_TYPED( ClickHdl, Button*, void ); - DECL_STATIC_LINK_TYPED( ScHFEditPage, MenuHdl, ScExtIButton&, void ); + DECL_LINK_TYPED( MenuHdl, ScExtIButton&, void ); }; class ScRightHeaderEditPage : public ScHFEditPage diff --git a/sc/source/ui/inc/tphfedit.hxx b/sc/source/ui/inc/tphfedit.hxx index b362a02d255a..52024fda3998 100644 --- a/sc/source/ui/inc/tphfedit.hxx +++ b/sc/source/ui/inc/tphfedit.hxx @@ -33,6 +33,8 @@ #include <com/sun/star/accessibility/XAccessible.hpp> #include <cppuhelper/weakref.hxx> +#include <functional> + class ScHeaderEditEngine; class ScPatternAttr; class EditView; @@ -72,6 +74,7 @@ public: ScHeaderEditEngine* GetEditEngine() const { return pEdEngine; } void SetObjectSelectHdl( const Link<ScEditWindow&,void>& aLink) { aObjectSelectLink = aLink; } + void SetGetFocusHdl(const std::function<void (ScEditWindow&)>& rLink) { m_GetFocusLink = rLink; } void SetLocation(ScEditWindowLocation eLoc) { eLocation = eLoc; } protected: @@ -95,6 +98,7 @@ private: ScAccessibleEditObject* pAcc; Link<ScEditWindow&,void> aObjectSelectLink; + std::function<void (ScEditWindow&)> m_GetFocusLink; }; class SC_DLLPUBLIC ScExtIButton : public ImageButton diff --git a/sc/source/ui/pagedlg/scuitphfedit.cxx b/sc/source/ui/pagedlg/scuitphfedit.cxx index 9f6f843f66ce..be28c1199bda 100644 --- a/sc/source/ui/pagedlg/scuitphfedit.cxx +++ b/sc/source/ui/pagedlg/scuitphfedit.cxx @@ -58,6 +58,7 @@ ScHFEditPage::ScHFEditPage( vcl::Window* pParent, sal_uInt16 nWhichId, bool bHeader ) : SfxTabPage( pParent, "HeaderFooterContent", "modules/scalc/ui/headerfootercontent.ui", &rCoreAttrs ) + , m_pEditFocus(nullptr) , nWhich( nWhichId ) { get(m_pWndLeft,"textviewWND_LEFT"); @@ -139,9 +140,14 @@ ScHFEditPage::ScHFEditPage( vcl::Window* pParent, m_pWndLeft->SetObjectSelectHdl( LINK(this,ScHFEditPage,ObjectSelectHdl) ); m_pWndCenter->SetObjectSelectHdl( LINK(this,ScHFEditPage,ObjectSelectHdl) ); m_pWndRight->SetObjectSelectHdl( LINK(this,ScHFEditPage,ObjectSelectHdl) ); + auto setEditFocus = [this](ScEditWindow & rEdit) { this->m_pEditFocus = &rEdit; }; + m_pWndLeft->SetGetFocusHdl(setEditFocus); + m_pWndCenter->SetGetFocusHdl(setEditFocus); + m_pWndRight->SetGetFocusHdl(setEditFocus); FillCmdArr(); m_pWndLeft->GrabFocus(); + m_pEditFocus = m_pWndLeft; // there's no event from GrabFocus() InitPreDefinedList(); @@ -791,39 +797,37 @@ IMPL_LINK_TYPED( ScHFEditPage, ListHdl_Impl, ListBox&, rList, void ) IMPL_LINK_TYPED( ScHFEditPage, ClickHdl, Button*, pBtn, void ) { - VclPtr<ScEditWindow> pActiveEdWnd = ::GetScEditWindow(); - if ( !pActiveEdWnd ) + if (!m_pEditFocus) return; if ( pBtn == m_pBtnText ) { - pActiveEdWnd->SetCharAttributes(); + m_pEditFocus->SetCharAttributes(); } else { if ( pBtn == m_pBtnPage ) - pActiveEdWnd->InsertField( SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD) ); + m_pEditFocus->InsertField(SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD)); else if ( pBtn == m_pBtnLastPage ) - pActiveEdWnd->InsertField( SvxFieldItem(SvxPagesField(), EE_FEATURE_FIELD) ); + m_pEditFocus->InsertField(SvxFieldItem(SvxPagesField(), EE_FEATURE_FIELD)); else if ( pBtn == m_pBtnDate ) - pActiveEdWnd->InsertField( SvxFieldItem(SvxDateField(Date( Date::SYSTEM ),SVXDATETYPE_VAR), EE_FEATURE_FIELD) ); + m_pEditFocus->InsertField(SvxFieldItem(SvxDateField(Date(Date::SYSTEM),SVXDATETYPE_VAR), EE_FEATURE_FIELD)); else if ( pBtn == m_pBtnTime ) - pActiveEdWnd->InsertField( SvxFieldItem(SvxTimeField(), EE_FEATURE_FIELD) ); + m_pEditFocus->InsertField(SvxFieldItem(SvxTimeField(), EE_FEATURE_FIELD)); else if ( pBtn == m_pBtnFile ) { - pActiveEdWnd->InsertField( SvxFieldItem( SvxFileField(), EE_FEATURE_FIELD ) ); + m_pEditFocus->InsertField(SvxFieldItem(SvxFileField(), EE_FEATURE_FIELD)); } else if ( pBtn == m_pBtnTable ) - pActiveEdWnd->InsertField( SvxFieldItem(SvxTableField(), EE_FEATURE_FIELD) ); + m_pEditFocus->InsertField(SvxFieldItem(SvxTableField(), EE_FEATURE_FIELD)); } InsertToDefinedList(); - pActiveEdWnd->GrabFocus(); + m_pEditFocus->GrabFocus(); } -IMPL_STATIC_LINK_TYPED( ScHFEditPage, MenuHdl, ScExtIButton&, rBtn, void ) +IMPL_LINK_TYPED( ScHFEditPage, MenuHdl, ScExtIButton&, rBtn, void ) { - VclPtr<ScEditWindow> pActiveEdWnd = ::GetScEditWindow(); - if ( !pActiveEdWnd ) + if (!m_pEditFocus) return; SAL_WARN_IF(rBtn.GetSelected() == 0, "sc.ui", "nothing selected"); @@ -831,16 +835,16 @@ IMPL_STATIC_LINK_TYPED( ScHFEditPage, MenuHdl, ScExtIButton&, rBtn, void ) if (sSelectedId == "title") { - pActiveEdWnd->InsertField( SvxFieldItem( SvxFileField(), EE_FEATURE_FIELD ) ); + m_pEditFocus->InsertField(SvxFieldItem(SvxFileField(), EE_FEATURE_FIELD)); } else if (sSelectedId == "filename") { - pActiveEdWnd->InsertField( SvxFieldItem( SvxExtFileField( + m_pEditFocus->InsertField( SvxFieldItem( SvxExtFileField( OUString(), SVXFILETYPE_VAR, SVXFILEFORMAT_NAME_EXT ), EE_FEATURE_FIELD ) ); } else if (sSelectedId == "pathname") { - pActiveEdWnd->InsertField( SvxFieldItem( SvxExtFileField( + m_pEditFocus->InsertField( SvxFieldItem( SvxExtFileField( OUString(), SVXFILETYPE_VAR, SVXFILEFORMAT_FULLPATH ), EE_FEATURE_FIELD ) ); } } diff --git a/sc/source/ui/pagedlg/tphfedit.cxx b/sc/source/ui/pagedlg/tphfedit.cxx index eab598cc2231..9a094d34d2d7 100644 --- a/sc/source/ui/pagedlg/tphfedit.cxx +++ b/sc/source/ui/pagedlg/tphfedit.cxx @@ -47,13 +47,6 @@ #include "scabstdlg.hxx" #include <memory> -// STATIC DATA ----------------------------------------------------------- -static VclPtr<ScEditWindow> g_pActiveEdWnd = nullptr; - -ScEditWindow* GetScEditWindow () -{ - return g_pActiveEdWnd; -} static void lcl_GetFieldData( ScHeaderFieldData& rData ) { @@ -283,7 +276,9 @@ void ScEditWindow::Command( const CommandEvent& rCEvt ) void ScEditWindow::GetFocus() { pEdView->ShowCursor(); - g_pActiveEdWnd = this; + + assert(m_GetFocusLink); + m_GetFocusLink(*this); css::uno::Reference< css::accessibility::XAccessible > xTemp = xAcc; if (xTemp.is() && pAcc) |