diff options
author | Noel Grandin <noel@peralex.com> | 2014-12-04 13:50:21 +0200 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2015-04-09 19:48:04 +0100 |
commit | b72c6feba87bd8707f39902a3066ba476188cb1d (patch) | |
tree | 94791632f79f14214ec7518d18a35ab822676178 /vcl/source/window | |
parent | d6398719abecfca60db37637490e602222992dc2 (diff) |
manage VCL widgets using rtl::Reference
Change-Id: Ie95790cbaa5d459c8e849d7333098d857d31ed0a
Diffstat (limited to 'vcl/source/window')
-rw-r--r-- | vcl/source/window/menubarwindow.cxx | 115 | ||||
-rw-r--r-- | vcl/source/window/menubarwindow.hxx | 24 | ||||
-rw-r--r-- | vcl/source/window/printdlg.cxx | 31 | ||||
-rw-r--r-- | vcl/source/window/window.cxx | 15 |
4 files changed, 103 insertions, 82 deletions
diff --git a/vcl/source/window/menubarwindow.cxx b/vcl/source/window/menubarwindow.cxx index 553baa472ecb..126e8b9be0b9 100644 --- a/vcl/source/window/menubarwindow.cxx +++ b/vcl/source/window/menubarwindow.cxx @@ -117,9 +117,9 @@ void DecoToolBox::SetImages( long nMaxHeight, bool bForce ) MenuBarWindow::MenuBarWindow( vcl::Window* pParent ) : Window( pParent, 0 ), - aCloseBtn(this), - aFloatBtn( this, WB_NOPOINTERFOCUS | WB_SMALLSTYLE | WB_RECTSTYLE ), - aHideBtn( this, WB_NOPOINTERFOCUS | WB_SMALLSTYLE | WB_RECTSTYLE ) + aCloseBtn(new DecoToolBox(this)), + aFloatBtn(new PushButton( this, WB_NOPOINTERFOCUS | WB_SMALLSTYLE | WB_RECTSTYLE )), + aHideBtn(new PushButton(this, WB_NOPOINTERFOCUS | WB_SMALLSTYLE | WB_RECTSTYLE )) { SetType( WINDOW_MENUBARWINDOW ); pMenu = NULL; @@ -137,25 +137,25 @@ MenuBarWindow::MenuBarWindow( vcl::Window* pParent ) : if( pResMgr ) { BitmapEx aBitmap( ResId( SV_RESID_BITMAP_CLOSEDOC, *pResMgr ) ); - aCloseBtn.maImage = Image(aBitmap); + aCloseBtn->maImage = Image(aBitmap); - aCloseBtn.SetOutStyle(TOOLBOX_STYLE_FLAT); - aCloseBtn.SetBackground(); - aCloseBtn.SetPaintTransparent(true); - aCloseBtn.SetParentClipMode(PARENTCLIPMODE_NOCLIP); + aCloseBtn->SetOutStyle(TOOLBOX_STYLE_FLAT); + aCloseBtn->SetBackground(); + aCloseBtn->SetPaintTransparent(true); + aCloseBtn->SetParentClipMode(PARENTCLIPMODE_NOCLIP); - aCloseBtn.InsertItem(IID_DOCUMENTCLOSE, aCloseBtn.maImage, ToolBoxItemBits::NONE); - aCloseBtn.SetSelectHdl(LINK(this, MenuBarWindow, CloseHdl)); - aCloseBtn.AddEventListener(LINK(this, MenuBarWindow, ToolboxEventHdl)); - aCloseBtn.SetQuickHelpText(IID_DOCUMENTCLOSE, ResId(SV_HELPTEXT_CLOSEDOCUMENT, *pResMgr).toString()); + aCloseBtn->InsertItem(IID_DOCUMENTCLOSE, aCloseBtn->maImage, ToolBoxItemBits::NONE); + aCloseBtn->SetSelectHdl(LINK(this, MenuBarWindow, CloseHdl)); + aCloseBtn->AddEventListener(LINK(this, MenuBarWindow, ToolboxEventHdl)); + aCloseBtn->SetQuickHelpText(IID_DOCUMENTCLOSE, ResId(SV_HELPTEXT_CLOSEDOCUMENT, *pResMgr).toString()); - aFloatBtn.SetClickHdl( LINK( this, MenuBarWindow, FloatHdl ) ); - aFloatBtn.SetSymbol( SymbolType::FLOAT ); - aFloatBtn.SetQuickHelpText( ResId(SV_HELPTEXT_RESTORE, *pResMgr).toString() ); + aFloatBtn->SetClickHdl( LINK( this, MenuBarWindow, FloatHdl ) ); + aFloatBtn->SetSymbol( SymbolType::FLOAT ); + aFloatBtn->SetQuickHelpText( ResId(SV_HELPTEXT_RESTORE, *pResMgr).toString() ); - aHideBtn.SetClickHdl( LINK( this, MenuBarWindow, HideHdl ) ); - aHideBtn.SetSymbol( SymbolType::HIDE ); - aHideBtn.SetQuickHelpText( ResId(SV_HELPTEXT_MINIMIZE, *pResMgr).toString() ); + aHideBtn->SetClickHdl( LINK( this, MenuBarWindow, HideHdl ) ); + aHideBtn->SetSymbol( SymbolType::HIDE ); + aHideBtn->SetQuickHelpText( ResId(SV_HELPTEXT_MINIMIZE, *pResMgr).toString() ); } ImplInitStyleSettings(); @@ -165,7 +165,7 @@ MenuBarWindow::MenuBarWindow( vcl::Window* pParent ) : MenuBarWindow::~MenuBarWindow() { - aCloseBtn.RemoveEventListener(LINK(this, MenuBarWindow, ToolboxEventHdl)); + aCloseBtn->RemoveEventListener(LINK(this, MenuBarWindow, ToolboxEventHdl)); RemoveEventListener(LINK(this, MenuBarWindow, ShowHideListener)); } @@ -177,10 +177,10 @@ void MenuBarWindow::SetMenu( MenuBar* pMen ) ImplInitMenuWindow( this, true, true ); if ( pMen ) { - aCloseBtn.ShowItem(IID_DOCUMENTCLOSE, pMen->HasCloseButton()); - aCloseBtn.Show(pMen->HasCloseButton() || !m_aAddButtons.empty()); - aFloatBtn.Show(pMen->HasFloatButton()); - aHideBtn.Show(pMen->HasHideButton()); + aCloseBtn->ShowItem(IID_DOCUMENTCLOSE, pMen->HasCloseButton()); + aCloseBtn->Show(pMen->HasCloseButton() || !m_aAddButtons.empty()); + aFloatBtn->Show(pMen->HasFloatButton()); + aHideBtn->Show(pMen->HasHideButton()); } Invalidate(); @@ -201,16 +201,16 @@ void MenuBarWindow::SetHeight(long nHeight) void MenuBarWindow::ShowButtons( bool bClose, bool bFloat, bool bHide ) { - aCloseBtn.ShowItem(IID_DOCUMENTCLOSE, bClose); - aCloseBtn.Show(bClose || !m_aAddButtons.empty()); - aFloatBtn.Show( bFloat ); - aHideBtn.Show( bHide ); + aCloseBtn->ShowItem(IID_DOCUMENTCLOSE, bClose); + aCloseBtn->Show(bClose || !m_aAddButtons.empty()); + aFloatBtn->Show( bFloat ); + aHideBtn->Show( bHide ); Resize(); } Size MenuBarWindow::MinCloseButtonSize() { - return aCloseBtn.getMinSize(); + return aCloseBtn->getMinSize(); } IMPL_LINK_NOARG(MenuBarWindow, CloseHdl) @@ -218,7 +218,7 @@ IMPL_LINK_NOARG(MenuBarWindow, CloseHdl) if( ! pMenu ) return 0; - if( aCloseBtn.GetCurItemId() == IID_DOCUMENTCLOSE ) + if( aCloseBtn->GetCurItemId() == IID_DOCUMENTCLOSE ) { // #i106052# call close hdl asynchronously to ease handler implementation // this avoids still being in the handler while the DecoToolBox already @@ -227,12 +227,12 @@ IMPL_LINK_NOARG(MenuBarWindow, CloseHdl) } else { - std::map<sal_uInt16,AddButtonEntry>::iterator it = m_aAddButtons.find(aCloseBtn.GetCurItemId()); + std::map<sal_uInt16,AddButtonEntry>::iterator it = m_aAddButtons.find(aCloseBtn->GetCurItemId()); if( it != m_aAddButtons.end() ) { MenuBar::MenuBarButtonCallbackArg aArg; aArg.nId = it->first; - aArg.bHighlight = (aCloseBtn.GetHighlightItemId() == it->first); + aArg.bHighlight = (aCloseBtn->GetHighlightItemId() == it->first); aArg.pMenuBar = dynamic_cast<MenuBar*>(pMenu); return it->second.m_aSelectLink.Call( &aArg ); } @@ -250,11 +250,11 @@ IMPL_LINK( MenuBarWindow, ToolboxEventHdl, VclWindowEvent*, pEvent ) aArg.bHighlight = (pEvent->GetId() == VCLEVENT_TOOLBOX_HIGHLIGHT); aArg.pMenuBar = dynamic_cast<MenuBar*>(pMenu); if( pEvent->GetId() == VCLEVENT_TOOLBOX_HIGHLIGHT ) - aArg.nId = aCloseBtn.GetHighlightItemId(); + aArg.nId = aCloseBtn->GetHighlightItemId(); else if( pEvent->GetId() == VCLEVENT_TOOLBOX_HIGHLIGHTOFF ) { sal_uInt16 nPos = static_cast< sal_uInt16 >(reinterpret_cast<sal_IntPtr>(pEvent->GetData())); - aArg.nId = aCloseBtn.GetItemId(nPos); + aArg.nId = aCloseBtn->GetItemId(nPos); } std::map< sal_uInt16, AddButtonEntry >::iterator it = m_aAddButtons.find( aArg.nId ); if( it != m_aAddButtons.end() ) @@ -913,30 +913,30 @@ void MenuBarWindow::Resize() long nX = aOutSz.Width()-3; long nY = 2; - if ( aCloseBtn.IsVisible() ) + if ( aCloseBtn->IsVisible() ) { - aCloseBtn.Hide(); - aCloseBtn.SetImages(n); - Size aTbxSize( aCloseBtn.CalcWindowSizePixel() ); + aCloseBtn->Hide(); + aCloseBtn->SetImages(n); + Size aTbxSize( aCloseBtn->CalcWindowSizePixel() ); nX -= aTbxSize.Width(); long nTbxY = (aOutSz.Height() - aTbxSize.Height())/2; - aCloseBtn.setPosSizePixel(nX, nTbxY, aTbxSize.Width(), aTbxSize.Height()); + aCloseBtn->setPosSizePixel(nX, nTbxY, aTbxSize.Width(), aTbxSize.Height()); nX -= 3; - aCloseBtn.Show(); + aCloseBtn->Show(); } - if ( aFloatBtn.IsVisible() ) + if ( aFloatBtn->IsVisible() ) { nX -= n; - aFloatBtn.setPosSizePixel( nX, nY, n, n ); + aFloatBtn->setPosSizePixel( nX, nY, n, n ); } - if ( aHideBtn.IsVisible() ) + if ( aHideBtn->IsVisible() ) { nX -= n; - aHideBtn.setPosSizePixel( nX, nY, n, n ); + aHideBtn->setPosSizePixel( nX, nY, n, n ); } - aFloatBtn.SetSymbol( SymbolType::FLOAT ); - aHideBtn.SetSymbol( SymbolType::HIDE ); + aFloatBtn->SetSymbol( SymbolType::FLOAT ); + aHideBtn->SetSymbol( SymbolType::HIDE ); Invalidate(); } @@ -1057,6 +1057,15 @@ void MenuBarWindow::GetFocus() } } +void MenuBarWindow::dispose() +{ + aCloseBtn.disposeAndClear(); + aFloatBtn.disposeAndClear(); + aHideBtn.disposeAndClear(); + Window::dispose(); +} + + ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > MenuBarWindow::CreateAccessible() { ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > xAcc; @@ -1083,9 +1092,9 @@ sal_uInt16 MenuBarWindow::AddMenuBarButton( const Image& i_rImage, const Link& i AddButtonEntry& rNewEntry = m_aAddButtons[nId]; rNewEntry.m_nId = nId; rNewEntry.m_aSelectLink = i_rLink; - aCloseBtn.InsertItem(nId, i_rImage, ToolBoxItemBits::NONE, 0); - aCloseBtn.calcMinSize(); - ShowButtons(aCloseBtn.IsItemVisible(IID_DOCUMENTCLOSE), aFloatBtn.IsVisible(), aHideBtn.IsVisible()); + aCloseBtn->InsertItem(nId, i_rImage, ToolBoxItemBits::NONE, 0); + aCloseBtn->calcMinSize(); + ShowButtons(aCloseBtn->IsItemVisible(IID_DOCUMENTCLOSE), aFloatBtn->IsVisible(), aHideBtn->IsVisible()); LayoutChanged(); if( pMenu->mpSalMenu ) @@ -1118,8 +1127,8 @@ Rectangle MenuBarWindow::GetMenuBarButtonRectPixel( sal_uInt16 nId ) if( aRect.IsEmpty() ) { - aRect = aCloseBtn.GetItemRect(nId); - Point aOffset = aCloseBtn.OutputToScreenPixel(Point()); + aRect = aCloseBtn->GetItemRect(nId); + Point aOffset = aCloseBtn->OutputToScreenPixel(Point()); aRect.Move( aOffset.X(), aOffset.Y() ); } } @@ -1128,10 +1137,10 @@ Rectangle MenuBarWindow::GetMenuBarButtonRectPixel( sal_uInt16 nId ) void MenuBarWindow::RemoveMenuBarButton( sal_uInt16 nId ) { - sal_uInt16 nPos = aCloseBtn.GetItemPos(nId); - aCloseBtn.RemoveItem(nPos); + sal_uInt16 nPos = aCloseBtn->GetItemPos(nId); + aCloseBtn->RemoveItem(nPos); m_aAddButtons.erase( nId ); - aCloseBtn.calcMinSize(); + aCloseBtn->calcMinSize(); LayoutChanged(); if( pMenu->mpSalMenu ) diff --git a/vcl/source/window/menubarwindow.hxx b/vcl/source/window/menubarwindow.hxx index 46c79accc0f5..b34784780ebc 100644 --- a/vcl/source/window/menubarwindow.hxx +++ b/vcl/source/window/menubarwindow.hxx @@ -52,6 +52,9 @@ public: Image maImage; }; +typedef VclReference<DecoToolBox> DecoToolBoxPtr; + + /** Class that implements the actual window of the menu bar. */ class MenuBarWindow : public vcl::Window, public IMenuBarWindow @@ -62,32 +65,32 @@ class MenuBarWindow : public vcl::Window, public IMenuBarWindow private: struct AddButtonEntry { - sal_uInt16 m_nId; - Link m_aSelectLink; - Link m_aHighlightLink; + sal_uInt16 m_nId; + Link m_aSelectLink; + Link m_aHighlightLink; AddButtonEntry() : m_nId( 0 ) {} }; Menu* pMenu; PopupMenu* pActivePopup; - sal_uInt16 nHighlightedItem; - sal_uInt16 nRolloveredItem; - sal_uLong nSaveFocusId; + sal_uInt16 nHighlightedItem; + sal_uInt16 nRolloveredItem; + sal_uLong nSaveFocusId; bool mbAutoPopup; bool bIgnoreFirstMove; bool bStayActive; - DecoToolBox aCloseBtn; - PushButton aFloatBtn; - PushButton aHideBtn; + DecoToolBoxPtr aCloseBtn; + PushButtonPtr aFloatBtn; + PushButtonPtr aHideBtn; std::map< sal_uInt16, AddButtonEntry > m_aAddButtons; void HighlightItem( sal_uInt16 nPos, bool bHighlight ); virtual void ChangeHighlightItem(sal_uInt16 n, bool bSelectPopupEntry, bool bAllowRestoreFocus = true, bool bDefaultToDocument = true) SAL_OVERRIDE; - sal_uInt16 ImplFindEntry( const Point& rMousePos ) const; + sal_uInt16 ImplFindEntry( const Point& rMousePos ) const; void ImplCreatePopup( bool bPreSelectFirst ); virtual bool HandleKeyEvent(const KeyEvent& rKEvent, bool bFromMenu = true) SAL_OVERRIDE; Rectangle ImplGetItemRect( sal_uInt16 nPos ); @@ -104,6 +107,7 @@ private: void DataChanged( const DataChangedEvent& rDCEvt ) SAL_OVERRIDE; void LoseFocus() SAL_OVERRIDE; void GetFocus() SAL_OVERRIDE; + virtual void dispose() SAL_OVERRIDE; public: MenuBarWindow( vcl::Window* pParent ); diff --git a/vcl/source/window/printdlg.cxx b/vcl/source/window/printdlg.cxx index c4ea5c7aac3c..0015caf7d886 100644 --- a/vcl/source/window/printdlg.cxx +++ b/vcl/source/window/printdlg.cxx @@ -67,17 +67,17 @@ PrintDialog::PrintPreviewWindow::PrintPreviewWindow( vcl::Window* i_pParent ) , maPageVDev( *this ) , maToolTipString(VclResId( SV_PRINT_PRINTPREVIEW_TXT).toString()) , mbGreyscale( false ) - , maHorzDim( this, WB_HORZ | WB_CENTER ) - , maVertDim( this, WB_VERT | WB_VCENTER ) + , maHorzDim(new FixedLine(this, WB_HORZ | WB_CENTER)) + , maVertDim(new FixedLine(this, WB_VERT | WB_VCENTER)) { SetPaintTransparent( true ); SetBackground(); maPageVDev.SetBackground( Color( COL_WHITE ) ); - maHorzDim.Show(); - maVertDim.Show(); + maHorzDim->Show(); + maVertDim->Show(); - maHorzDim.SetText( OUString( "2.0in" ) ); - maVertDim.SetText( OUString( "2.0in" ) ); + maHorzDim->SetText( OUString( "2.0in" ) ); + maVertDim->SetText( OUString( "2.0in" ) ); } PrintDialog::PrintPreviewWindow::~PrintPreviewWindow() @@ -99,7 +99,7 @@ void PrintDialog::PrintPreviewWindow::DataChanged( const DataChangedEvent& i_rDC void PrintDialog::PrintPreviewWindow::Resize() { Size aNewSize( GetSizePixel() ); - long nTextHeight = maHorzDim.GetTextHeight(); + long nTextHeight = maHorzDim->GetTextHeight(); // leave small space for decoration aNewSize.Width() -= nTextHeight + 2; aNewSize.Height() -= nTextHeight + 2; @@ -145,16 +145,16 @@ void PrintDialog::PrintPreviewWindow::Resize() // position dimension lines Point aRef( nTextHeight + (aNewSize.Width() - maPreviewSize.Width())/2, nTextHeight + (aNewSize.Height() - maPreviewSize.Height())/2 ); - maHorzDim.SetPosSizePixel( Point( aRef.X(), aRef.Y() - nTextHeight ), + maHorzDim->SetPosSizePixel( Point( aRef.X(), aRef.Y() - nTextHeight ), Size( maPreviewSize.Width(), nTextHeight ) ); - maVertDim.SetPosSizePixel( Point( aRef.X() - nTextHeight, aRef.Y() ), + maVertDim->SetPosSizePixel( Point( aRef.X() - nTextHeight, aRef.Y() ), Size( nTextHeight, maPreviewSize.Height() ) ); } void PrintDialog::PrintPreviewWindow::Paint( const Rectangle& ) { - long nTextHeight = maHorzDim.GetTextHeight(); + long nTextHeight = maHorzDim->GetTextHeight(); Size aSize( GetSizePixel() ); Point aOffset( (aSize.Width() - maPreviewSize.Width() + nTextHeight) / 2 , (aSize.Height() - maPreviewSize.Height() + nTextHeight) / 2 ); @@ -241,19 +241,26 @@ void PrintDialog::PrintPreviewWindow::setPreview( const GDIMetaFile& i_rNewPrevi aBuf.append( i_rPaperName ); aBuf.append( ')' ); } - maHorzDim.SetText( aBuf.makeStringAndClear() ); + maHorzDim->SetText( aBuf.makeStringAndClear() ); aNumText = rLocWrap.getNum( aLogicPaperSize.Height(), nDigits ); aBuf.append( aNumText ) .append( sal_Unicode( ' ' ) ); aBuf.appendAscii( eUnit == MAP_MM ? "mm" : "in" ); - maVertDim.SetText( aBuf.makeStringAndClear() ); + maVertDim->SetText( aBuf.makeStringAndClear() ); Resize(); preparePreviewBitmap(); Invalidate(); } +void PrintDialog::PrintPreviewWindow::dispose() +{ + maHorzDim.disposeAndClear(); + maVertDim.disposeAndClear(); + Window::dispose(); +} + void PrintDialog::PrintPreviewWindow::preparePreviewBitmap() { GDIMetaFile aMtf( maMtf ); diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx index 6fdb764bf2b5..156cc66ac8fa 100644 --- a/vcl/source/window/window.cxx +++ b/vcl/source/window/window.cxx @@ -131,14 +131,8 @@ namespace } #endif -Window::~Window() +void Window::dispose() { - vcl::LazyDeletor<vcl::Window>::Undelete( this ); - - DBG_ASSERT( !mpWindowImpl->mbInDtor, "~Window - already in DTOR!" ); - - dispose(); - // remove Key and Mouse events issued by Application::PostKey/MouseEvent Application::RemoveMouseAndKeyEvents( this ); @@ -568,6 +562,13 @@ Window::~Window() delete mpWindowImpl; mpWindowImpl = NULL; } +Window::~Window() +{ + vcl::LazyDeletor<vcl::Window>::Undelete( this ); + + DBG_ASSERT( !mpWindowImpl->mbInDtor, "~Window - already in DTOR!" ); +} + } /* namespace vcl */ WindowImpl::WindowImpl( WindowType nType ) |