diff options
-rw-r--r-- | include/sfx2/infobar.hxx | 20 | ||||
-rw-r--r-- | include/sfx2/viewfrm.hxx | 5 | ||||
-rw-r--r-- | sfx2/source/dialog/infobar.cxx | 28 | ||||
-rw-r--r-- | sfx2/source/view/sfxbasecontroller.cxx | 5 | ||||
-rw-r--r-- | sfx2/source/view/viewfrm.cxx | 52 |
5 files changed, 54 insertions, 56 deletions
diff --git a/include/sfx2/infobar.hxx b/include/sfx2/infobar.hxx index ee92d398e674..14c680f37885 100644 --- a/include/sfx2/infobar.hxx +++ b/include/sfx2/infobar.hxx @@ -51,15 +51,19 @@ class SfxInfoBarWindow : public vcl::Window boost::ptr_vector<PushButton> m_aActionBtns; public: - SfxInfoBarWindow( vcl::Window* parent, const OUString& sId, - const OUString& sMessage, - std::vector< PushButton* > aButtons ); + SfxInfoBarWindow(vcl::Window* parent, const OUString& sId, const OUString& sMessage); virtual ~SfxInfoBarWindow( ); virtual const OUString& getId() const { return m_sId; } virtual void Paint( const Rectangle& ) SAL_OVERRIDE; virtual void Resize( ) SAL_OVERRIDE; + /** Add button to Infobar. + * Infobar takes ownership of the button so the button is + * destroyed when the infobar gets destroyed. + */ + void addButton(PushButton* pButton); + private: DECL_LINK( CloseHandler, void* ); }; @@ -71,14 +75,14 @@ class SfxInfoBarContainerWindow : public vcl::Window boost::ptr_vector<SfxInfoBarWindow> m_pInfoBars; public: - SfxInfoBarContainerWindow( SfxInfoBarContainerChild* pChildWin ); + SfxInfoBarContainerWindow(SfxInfoBarContainerChild* pChildWin); virtual ~SfxInfoBarContainerWindow( ); - void appendInfoBar( const OUString& sId, const OUString& sMessage, std::vector< PushButton* > aButtons ); - SfxInfoBarWindow* getInfoBar( const OUString& sId ); - void removeInfoBar( SfxInfoBarWindow* pInfoBar ); + SfxInfoBarWindow* appendInfoBar(const OUString& sId, const OUString& sMessage); + SfxInfoBarWindow* getInfoBar(const OUString& sId); + void removeInfoBar(SfxInfoBarWindow* pInfoBar); - virtual void Resize( ) SAL_OVERRIDE; + virtual void Resize() SAL_OVERRIDE; }; diff --git a/include/sfx2/viewfrm.hxx b/include/sfx2/viewfrm.hxx index 1d043fcd2ded..ec5ef1374c8d 100644 --- a/include/sfx2/viewfrm.hxx +++ b/include/sfx2/viewfrm.hxx @@ -47,6 +47,7 @@ class Fraction; class Point; class Size; class SfxChildWindow; +class SfxInfoBarWindow; namespace sfx2 { @@ -191,8 +192,8 @@ public: The buttons will be added from Right to Left at the right of the info bar. The parent, size and position of each button will be changed: only the width will remain unchanged. */ - void AppendInfoBar( const OUString& sId, const OUString& sMessage, std::vector< PushButton* > aButtons = std::vector< PushButton* >() ); - void RemoveInfoBar( const OUString& sId ); + SfxInfoBarWindow* AppendInfoBar(const OUString& sId, const OUString& sMessage); + void RemoveInfoBar(const OUString& sId); SAL_DLLPRIVATE void SetDowning_Impl(); SAL_DLLPRIVATE void GetDocNumber_Impl(); diff --git a/sfx2/source/dialog/infobar.cxx b/sfx2/source/dialog/infobar.cxx index 7cd0ebee684d..f530456b679f 100644 --- a/sfx2/source/dialog/infobar.cxx +++ b/sfx2/source/dialog/infobar.cxx @@ -115,7 +115,7 @@ void SfxCloseButton::Paint(const Rectangle&) } // anonymous namespace SfxInfoBarWindow::SfxInfoBarWindow(vcl::Window* pParent, const OUString& sId, - const OUString& sMessage, vector<PushButton*> aButtons) : + const OUString& sMessage) : Window(pParent, 0), m_sId(sId), m_pMessage(new FixedText(this, 0)), @@ -133,22 +133,19 @@ SfxInfoBarWindow::SfxInfoBarWindow(vcl::Window* pParent, const OUString& sId, m_pCloseBtn->SetClickHdl(LINK(this, SfxInfoBarWindow, CloseHandler)); m_pCloseBtn->Show(); - // Reparent the buttons and place them on the right of the bar - vector<PushButton*>::iterator it; - for (it = aButtons.begin(); it != aButtons.end(); ++it) - { - PushButton* pButton = *it; - pButton->SetParent(this); - pButton->Show(); - m_aActionBtns.push_back(pButton); - } - Resize(); } SfxInfoBarWindow::~SfxInfoBarWindow() {} +void SfxInfoBarWindow::addButton(PushButton* pButton) { + pButton->SetParent(this); + pButton->Show(); + m_aActionBtns.push_back(pButton); + Resize(); +} + void SfxInfoBarWindow::Paint(const Rectangle& rPaintRect) { const ViewInformation2D aNewViewInfos; @@ -238,18 +235,19 @@ SfxInfoBarContainerWindow::~SfxInfoBarContainerWindow() { } -void SfxInfoBarContainerWindow::appendInfoBar(const OUString& sId, const OUString& sMessage, vector<PushButton*> aButtons) +SfxInfoBarWindow* SfxInfoBarContainerWindow::appendInfoBar(const OUString& sId, const OUString& sMessage) { - Size aSize = GetSizePixel( ); + Size aSize = GetSizePixel(); - SfxInfoBarWindow* pInfoBar = new SfxInfoBarWindow(this, sId, sMessage, aButtons); - pInfoBar->SetPosPixel(Point( 0, aSize.getHeight())); + SfxInfoBarWindow* pInfoBar = new SfxInfoBarWindow(this, sId, sMessage); + pInfoBar->SetPosPixel(Point(0, aSize.getHeight())); pInfoBar->Show(); m_pInfoBars.push_back(pInfoBar); long nHeight = pInfoBar->GetSizePixel().getHeight(); aSize.setHeight(aSize.getHeight() + nHeight); SetSizePixel(aSize); + return pInfoBar; } SfxInfoBarWindow* SfxInfoBarContainerWindow::getInfoBar(const OUString& sId) diff --git a/sfx2/source/view/sfxbasecontroller.cxx b/sfx2/source/view/sfxbasecontroller.cxx index 943f60da08c1..5ea8ebe08565 100644 --- a/sfx2/source/view/sfxbasecontroller.cxx +++ b/sfx2/source/view/sfxbasecontroller.cxx @@ -1448,11 +1448,10 @@ void SfxBaseController::ShowInfoBars( ) { // Get the Frame and show the InfoBar if not checked out SfxViewFrame* pViewFrame = m_pData->m_pViewShell->GetFrame(); - std::vector< PushButton* > aButtons; PushButton* pBtn = new PushButton( &pViewFrame->GetWindow(), SfxResId( BT_CHECKOUT ) ); pBtn->SetClickHdl( LINK( this, SfxBaseController, CheckOutHandler ) ); - aButtons.push_back( pBtn ); - pViewFrame->AppendInfoBar( "checkout", SfxResId( STR_NONCHECKEDOUT_DOCUMENT ), aButtons ); + SfxInfoBarWindow* pInfoBar = pViewFrame->AppendInfoBar( "checkout", SfxResId( STR_NONCHECKEDOUT_DOCUMENT ) ); + pInfoBar->addButton(pBtn); } } } diff --git a/sfx2/source/view/viewfrm.cxx b/sfx2/source/view/viewfrm.cxx index 3c9a9df554b4..5ba7ef13a3e2 100644 --- a/sfx2/source/view/viewfrm.cxx +++ b/sfx2/source/view/viewfrm.cxx @@ -1379,11 +1379,11 @@ void SfxViewFrame::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) } else { - std::vector< PushButton* > aButtons; + SfxInfoBarWindow* pInfoBar = AppendInfoBar("readonly", SfxResId(STR_READONLY_DOCUMENT)); + PushButton* pBtn = new PushButton( &GetWindow(), SfxResId(BT_READONLY_EDIT)); pBtn->SetClickHdl(LINK(this, SfxViewFrame, SwitchReadOnlyHandler)); - aButtons.push_back( pBtn ); - AppendInfoBar("readonly", SfxResId(STR_READONLY_DOCUMENT), aButtons); + pInfoBar->addButton(pBtn); } break; @@ -3357,28 +3357,23 @@ void SfxViewFrame::ActivateToolPanel_Impl( const OUString& i_rPanelURL ) pPanelAccess->ActivateToolPanel( i_rPanelURL ); } -void SfxViewFrame::AppendInfoBar( const OUString& sId, const OUString& sMessage, std::vector< PushButton* > aButtons ) +SfxInfoBarWindow* SfxViewFrame::AppendInfoBar( const OUString& sId, const OUString& sMessage ) { const sal_uInt16 nId = SfxInfoBarContainerChild::GetChildWindowId(); // Make sure the InfoBar container is visible - if ( !HasChildWindow( nId ) ) - ToggleChildWindow( nId ); - SfxChildWindow* pChild = GetChildWindow( nId ); - if ( pChild ) - { - SfxInfoBarContainerWindow* pInfoBars = static_cast<SfxInfoBarContainerWindow*>( pChild->GetWindow() ); - pInfoBars->appendInfoBar( sId, sMessage, aButtons ); - ShowChildWindow( nId ); - } - else + if (!HasChildWindow(nId)) + ToggleChildWindow(nId); + + SfxChildWindow* pChild = GetChildWindow(nId); + if (pChild) { - SAL_WARN( "sfx.view", "No consumer for InfoBar buttons, so deleting them instead" ); - for (std::vector< PushButton* >::iterator it = aButtons.begin(); it != aButtons.end(); ++it) - { - delete *it; - } + SfxInfoBarContainerWindow* pInfoBarContainer = static_cast<SfxInfoBarContainerWindow*>(pChild->GetWindow()); + SfxInfoBarWindow* pInfoBar = pInfoBarContainer->appendInfoBar(sId, sMessage); + ShowChildWindow(nId); + return pInfoBar; } + return NULL; } void SfxViewFrame::RemoveInfoBar( const OUString& sId ) @@ -3386,15 +3381,16 @@ void SfxViewFrame::RemoveInfoBar( const OUString& sId ) const sal_uInt16 nId = SfxInfoBarContainerChild::GetChildWindowId(); // Make sure the InfoBar container is visible - if ( !HasChildWindow( nId ) ) - ToggleChildWindow( nId ); - SfxChildWindow* pChild = GetChildWindow( nId ); - if ( pChild ) - { - SfxInfoBarContainerWindow* pInfoBars = static_cast<SfxInfoBarContainerWindow*>( pChild->GetWindow() ); - SfxInfoBarWindow* pInfoBar = pInfoBars->getInfoBar( sId ); - pInfoBars->removeInfoBar( pInfoBar ); - ShowChildWindow( nId ); + if (!HasChildWindow(nId)) + ToggleChildWindow(nId); + + SfxChildWindow* pChild = GetChildWindow(nId); + if (pChild) + { + SfxInfoBarContainerWindow* pInfoBarContainer = static_cast<SfxInfoBarContainerWindow*>(pChild->GetWindow()); + SfxInfoBarWindow* pInfoBar = pInfoBarContainer->getInfoBar(sId); + pInfoBarContainer->removeInfoBar(pInfoBar); + ShowChildWindow(nId); } } |