diff options
Diffstat (limited to 'vcl/source/window')
47 files changed, 955 insertions, 576 deletions
diff --git a/vcl/source/window/accel.cxx b/vcl/source/window/accel.cxx index a3b7c0f8d061..99fea0983520 100644 --- a/vcl/source/window/accel.cxx +++ b/vcl/source/window/accel.cxx @@ -20,6 +20,7 @@ #include <tools/debug.hxx> #include <tools/rc.h> +#include <vcl/window.hxx> #include <vcl/svapp.hxx> #include <accel.h> #include <vcl/accel.hxx> diff --git a/vcl/source/window/accessibility.cxx b/vcl/source/window/accessibility.cxx index fc3dc74d009d..07abf759c92d 100644 --- a/vcl/source/window/accessibility.cxx +++ b/vcl/source/window/accessibility.cxx @@ -136,6 +136,8 @@ namespace vcl { return pChild->GetAccessible(); } */ + if ( !mpWindowImpl ) + return css::uno::Reference< css::accessibility::XAccessible >(); if ( !mpWindowImpl->mxAccessible.is() && bCreate ) mpWindowImpl->mxAccessible = CreateAccessible(); @@ -647,12 +649,11 @@ vcl::Window* Window::GetAccessibleRelationLabeledBy() const if (mpWindowImpl->mpAccessibleInfos && mpWindowImpl->mpAccessibleInfos->pLabeledByWindow) return mpWindowImpl->mpAccessibleInfos->pLabeledByWindow; - std::vector<FixedText*> aMnemonicLabels(list_mnemonic_labels()); + std::vector<VclPtr<FixedText> > aMnemonicLabels(list_mnemonic_labels()); if (!aMnemonicLabels.empty()) { //if we have multiple labels, then prefer the first that is visible - for (std::vector<FixedText*>::iterator - aI = aMnemonicLabels.begin(), aEnd = aMnemonicLabels.end(); aI != aEnd; ++aI) + for (auto aI = aMnemonicLabels.begin(), aEnd = aMnemonicLabels.end(); aI != aEnd; ++aI) { vcl::Window *pCandidate = *aI; if (pCandidate->IsVisible()) diff --git a/vcl/source/window/brdwin.cxx b/vcl/source/window/brdwin.cxx index c472777cf101..88ef65a07391 100644 --- a/vcl/source/window/brdwin.cxx +++ b/vcl/source/window/brdwin.cxx @@ -1013,7 +1013,7 @@ void ImplSmallBorderWindowView::Init( OutputDevice* pDev, long nWidth, long nHei vcl::Window *pWin = NULL, *pCtrl = NULL; if (mpOutDev->GetOutDevType() == OUTDEV_WINDOW) - pWin = static_cast<vcl::Window*>(mpOutDev); + pWin = static_cast<vcl::Window*>(mpOutDev.get()); if (pWin) pCtrl = mpBorderWindow->GetWindow(WINDOW_CLIENT); @@ -1193,7 +1193,7 @@ void ImplSmallBorderWindowView::DrawWindow( sal_uInt16 nDrawFlags, OutputDevice* // control this border belongs to vcl::Window *pWin = NULL, *pCtrl = NULL; if( mpOutDev->GetOutDevType() == OUTDEV_WINDOW ) - pWin = static_cast<vcl::Window*>(mpOutDev); + pWin = static_cast<vcl::Window*>(mpOutDev.get()); ControlType aCtrlType = 0; ControlPart aCtrlPart = PART_ENTIRE_CONTROL; @@ -1364,8 +1364,8 @@ ImplStdBorderWindowView::ImplStdBorderWindowView( ImplBorderWindow* pBorderWindo ImplStdBorderWindowView::~ImplStdBorderWindowView() { - delete mpATitleVirDev; - delete mpDTitleVirDev; + mpATitleVirDev.disposeAndClear(); + mpDTitleVirDev.disposeAndClear(); } bool ImplStdBorderWindowView::MouseMove( const MouseEvent& rMEvt ) @@ -1556,7 +1556,7 @@ long ImplStdBorderWindowView::CalcTitleWidth() const void ImplStdBorderWindowView::DrawWindow( sal_uInt16 nDrawFlags, OutputDevice* pOutDev, const Point* pOffset ) { ImplBorderFrameData* pData = &maFrameData; - OutputDevice* pDev = pOutDev ? pOutDev : pData->mpOutDev; + OutputDevice* pDev = pOutDev ? pOutDev : pData->mpOutDev.get(); ImplBorderWindow* pBorderWindow = pData->mpBorderWindow; Point aTmpPoint = pOffset ? Point(*pOffset) : Point(); Rectangle aInRect( aTmpPoint, Size( pData->mnWidth, pData->mnHeight ) ); @@ -1851,7 +1851,15 @@ ImplBorderWindow::ImplBorderWindow( vcl::Window* pParent, WinBits nStyle , ImplBorderWindow::~ImplBorderWindow() { + disposeOnce(); +} + +void ImplBorderWindow::dispose() +{ delete mpBorderView; + mpBorderView = NULL; + mpMenuBarWindow.clear(); + vcl::Window::dispose(); } void ImplBorderWindow::MouseMove( const MouseEvent& rMEvt ) diff --git a/vcl/source/window/btndlg.cxx b/vcl/source/window/btndlg.cxx index 515d17a20cc6..2e8532cecba7 100644 --- a/vcl/source/window/btndlg.cxx +++ b/vcl/source/window/btndlg.cxx @@ -30,10 +30,10 @@ typedef boost::ptr_vector<ImplBtnDlgItem>::const_iterator btn_const_iterator; struct ImplBtnDlgItem { sal_uInt16 mnId; - bool mbOwnButton; - bool mbDummyAlign; - long mnSepSize; - PushButton* mpPushButton; + bool mbOwnButton; + bool mbDummyAlign; + long mnSepSize; + VclPtr<PushButton> mpPushButton; }; void ButtonDialog::ImplInitButtonDialogData() @@ -59,11 +59,18 @@ ButtonDialog::ButtonDialog( vcl::Window* pParent, WinBits nStyle ) : ButtonDialog::~ButtonDialog() { + disposeOnce(); +} + +void ButtonDialog::dispose() +{ for ( btn_iterator it = maItemList.begin(); it != maItemList.end(); ++it) { - if ( it->mpPushButton && it->mbOwnButton ) - delete it->mpPushButton; + if ( it->mbOwnButton ) + it->mpPushButton.disposeAndClear(); } + maItemList.clear(); + Dialog::dispose(); } PushButton* ButtonDialog::ImplCreatePushButton( sal_uInt16 nBtnFlags ) @@ -74,13 +81,13 @@ PushButton* ButtonDialog::ImplCreatePushButton( sal_uInt16 nBtnFlags ) if ( nBtnFlags & BUTTONDIALOG_DEFBUTTON ) nStyle |= WB_DEFBUTTON; if ( nBtnFlags & BUTTONDIALOG_CANCELBUTTON ) - pBtn = new CancelButton( this, nStyle ); + pBtn = VclPtr<CancelButton>::Create( this, nStyle ); else if ( nBtnFlags & BUTTONDIALOG_OKBUTTON ) - pBtn = new OKButton( this, nStyle ); + pBtn = VclPtr<OKButton>::Create( this, nStyle ); else if ( nBtnFlags & BUTTONDIALOG_HELPBUTTON ) - pBtn = new HelpButton( this, nStyle ); + pBtn = VclPtr<HelpButton>::Create( this, nStyle ); else - pBtn = new PushButton( this, nStyle ); + pBtn = VclPtr<PushButton>::Create( this, nStyle ); if ( !(nBtnFlags & BUTTONDIALOG_HELPBUTTON) ) pBtn->SetClickHdl( LINK( this, ButtonDialog, ImplClickHdl ) ); @@ -327,10 +334,10 @@ void ButtonDialog::RemoveButton( sal_uInt16 nId ) if (it->mnId == nId) { it->mpPushButton->Hide(); - - if (it->mbOwnButton ) - delete it->mpPushButton; - + if (it->mbOwnButton) + it->mpPushButton.disposeAndClear(); + else + it->mpPushButton.clear(); maItemList.erase(it); return; } @@ -344,9 +351,8 @@ void ButtonDialog::Clear() for (btn_iterator it = maItemList.begin(); it != maItemList.end(); ++it) { it->mpPushButton->Hide(); - - if (it->mbOwnButton ) - delete it->mpPushButton; + if (it->mbOwnButton) + it->mpPushButton.disposeAndClear(); } maItemList.clear(); diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx index f7de2d12130a..dc06f34a003f 100644 --- a/vcl/source/window/builder.cxx +++ b/vcl/source/window/builder.cxx @@ -471,14 +471,14 @@ VclBuilder::VclBuilder(vcl::Window *pParent, const OUString& sUIDir, const OUStr //Remove ScrollWindow parent widgets whose children in vcl implement scrolling //internally. - for (std::map<vcl::Window*, vcl::Window*>::iterator aI = m_pParserState->m_aRedundantParentWidgets.begin(), + for (auto aI = m_pParserState->m_aRedundantParentWidgets.begin(), aEnd = m_pParserState->m_aRedundantParentWidgets.end(); aI != aEnd; ++aI) { delete_by_window(aI->first); } //fdo#67378 merge the label into the disclosure button - for (std::vector<VclExpander*>::iterator aI = m_pParserState->m_aExpanderWidgets.begin(), + for (auto aI = m_pParserState->m_aExpanderWidgets.begin(), aEnd = m_pParserState->m_aExpanderWidgets.end(); aI != aEnd; ++aI) { VclExpander *pOne = *aI; @@ -525,17 +525,24 @@ VclBuilder::VclBuilder(vcl::Window *pParent, const OUString& sUIDir, const OUStr VclBuilder::~VclBuilder() { + disposeBuilder(); +} + +void VclBuilder::disposeBuilder() +{ for (std::vector<WinAndId>::reverse_iterator aI = m_aChildren.rbegin(), aEnd = m_aChildren.rend(); aI != aEnd; ++aI) { - delete aI->m_pWindow; + aI->m_pWindow.disposeAndClear(); } + m_aChildren.clear(); for (std::vector<MenuAndId>::reverse_iterator aI = m_aMenus.rbegin(), aEnd = m_aMenus.rend(); aI != aEnd; ++aI) { delete aI->m_pMenu; } + m_aMenus.clear(); } void VclBuilder::handleTranslations(xmlreader::XmlReader &reader) @@ -1259,7 +1266,7 @@ void VclBuilder::cleanupWidgetOwnScrolling(vcl::Window *pScrollParent, vcl::Wind extern "C" { static void SAL_CALL thisModule() {} } #endif -vcl::Window *VclBuilder::makeObject(vcl::Window *pParent, const OString &name, const OString &id, +VclPtr<vcl::Window> VclBuilder::makeObject(vcl::Window *pParent, const OString &name, const OString &id, stringmap &rMap) { bool bIsPlaceHolder = name.isEmpty(); @@ -1301,7 +1308,7 @@ vcl::Window *VclBuilder::makeObject(vcl::Window *pParent, const OString &name, c } if (bIsPlaceHolder || name == "GtkTreeSelection") - return NULL; + return nullptr; extractButtonImage(id, rMap, name == "GtkRadioButton"); @@ -1696,7 +1703,7 @@ vcl::Window *VclBuilder::makeObject(vcl::Window *pParent, const OString &name, c m_pParserState->m_nLastToolbarId = nItemId; - return NULL; // no widget to be created + return nullptr; // no widget to be created } } else if (name == "GtkSeparatorToolItem") @@ -1705,7 +1712,7 @@ vcl::Window *VclBuilder::makeObject(vcl::Window *pParent, const OString &name, c if (pToolBox) { pToolBox->InsertSeparator(); - return NULL; // no widget to be created + return nullptr; // no widget to be created } } else if (name == "GtkWindow") @@ -1763,16 +1770,17 @@ vcl::Window *VclBuilder::makeObject(vcl::Window *pParent, const OString &name, c SAL_WARN_IF(!pWindow, "vcl.layout", "probably need to implement " << name.getStr() << " or add a make" << name.getStr() << " function"); if (pWindow) { + VclPtr< vcl::Window > xWindow( pWindow ); pWindow->SetHelpId(m_sHelpRoot + id); SAL_INFO("vcl.layout", "for " << name.getStr() << ", created " << pWindow << " child of " << - pParent << "(" << pWindow->mpWindowImpl->mpParent << "/" << - pWindow->mpWindowImpl->mpRealParent << "/" << - pWindow->mpWindowImpl->mpBorderWindow << ") with helpid " << + pParent << "(" << pWindow->mpWindowImpl->mpParent.get() << "/" << + pWindow->mpWindowImpl->mpRealParent.get() << "/" << + pWindow->mpWindowImpl->mpBorderWindow.get() << ") with helpid " << pWindow->GetHelpId().getStr()); - m_aChildren.push_back(WinAndId(id, pWindow, bVertical)); + m_aChildren.push_back(WinAndId(id, xWindow, bVertical)); } - return pWindow; + return VclPtr<vcl::Window>(pWindow, SAL_NO_ACQUIRE); } namespace @@ -1807,10 +1815,10 @@ void VclBuilder::set_properties(vcl::Window *pWindow, const stringmap &rProps) } } -vcl::Window *VclBuilder::insertObject(vcl::Window *pParent, const OString &rClass, +VclPtr<vcl::Window> VclBuilder::insertObject(vcl::Window *pParent, const OString &rClass, const OString &rID, stringmap &rProps, stringmap &rPango, stringmap &rAtk) { - vcl::Window *pCurrentChild = NULL; + VclPtr<vcl::Window> pCurrentChild; if (m_pParent && !isConsideredGtkPseudo(m_pParent) && !m_sID.isEmpty() && rID.equals(m_sID)) { @@ -1821,13 +1829,13 @@ vcl::Window *VclBuilder::insertObject(vcl::Window *pParent, const OString &rClas //initialize the dialog. if (pParent && pParent->IsSystemWindow()) { - SystemWindow *pSysWin = static_cast<SystemWindow*>(pCurrentChild); + SystemWindow *pSysWin = static_cast<SystemWindow*>(pCurrentChild.get()); pSysWin->doDeferredInit(extractDeferredBits(rProps)); m_bToplevelHasDeferredInit = false; } else if (pParent && pParent->IsDockingWindow()) { - DockingWindow *pDockWin = static_cast<DockingWindow*>(pCurrentChild); + DockingWindow *pDockWin = static_cast<DockingWindow*>(pCurrentChild.get()); pDockWin->doDeferredInit(extractDeferredBits(rProps)); m_bToplevelHasDeferredInit = false; } @@ -1846,14 +1854,14 @@ vcl::Window *VclBuilder::insertObject(vcl::Window *pParent, const OString &rClas //if we're being inserting under a toplevel dialog whose init is //deferred due to waiting to encounter it in this .ui, and it hasn't //been seen yet, then make unattached widgets parent-less toplevels - if (pParent == m_pParent && m_bToplevelHasDeferredInit) + if (pParent == m_pParent.get() && m_bToplevelHasDeferredInit) pParent = NULL; pCurrentChild = makeObject(pParent, rClass, rID, rProps); } if (pCurrentChild) { - if (pCurrentChild == m_pParent && m_bToplevelHasDeferredProperties) + if (pCurrentChild == m_pParent.get() && m_bToplevelHasDeferredProperties) m_aDeferredProperties = rProps; else set_properties(pCurrentChild, rProps); @@ -1865,7 +1873,7 @@ vcl::Window *VclBuilder::insertObject(vcl::Window *pParent, const OString &rClas pCurrentChild->set_font_attribute(rKey, rValue); } - m_pParserState->m_aAtkInfo[pCurrentChild] = rAtk; + m_pParserState->m_aAtkInfo[VclPtr<vcl::Window>(pCurrentChild)] = rAtk; } rProps.clear(); @@ -1873,7 +1881,7 @@ vcl::Window *VclBuilder::insertObject(vcl::Window *pParent, const OString &rClas rAtk.clear(); if (!pCurrentChild) - pCurrentChild = m_aChildren.empty() ? pParent : m_aChildren.back().m_pWindow; + pCurrentChild = m_aChildren.empty() ? pParent : m_aChildren.back().m_pWindow.get(); return pCurrentChild; } @@ -2093,14 +2101,14 @@ void VclBuilder::handleChild(vcl::Window *pParent, xmlreader::XmlReader &reader) if (sInternalChild.startsWith("vbox") || sInternalChild.startsWith("messagedialog-vbox")) { if (Dialog *pBoxParent = dynamic_cast<Dialog*>(pParent)) - pBoxParent->set_content_area(static_cast<VclBox*>(pCurrentChild)); + pBoxParent->set_content_area(static_cast<VclBox*>(pCurrentChild)); // FIXME-VCLPTR } else if (sInternalChild.startsWith("action_area") || sInternalChild.startsWith("messagedialog-action_area")) { vcl::Window *pContentArea = pCurrentChild->GetParent(); if (Dialog *pBoxParent = dynamic_cast<Dialog*>(pContentArea ? pContentArea->GetParent() : NULL)) { - pBoxParent->set_action_area(static_cast<VclButtonBox*>(pCurrentChild)); + pBoxParent->set_action_area(static_cast<VclButtonBox*>(pCurrentChild)); // FIXME-VCLPTR } } @@ -2835,7 +2843,7 @@ template<typename T> bool insertItems(vcl::Window *pWindow, VclBuilder::stringma return true; } -vcl::Window* VclBuilder::handleObject(vcl::Window *pParent, xmlreader::XmlReader &reader) +VclPtr<vcl::Window> VclBuilder::handleObject(vcl::Window *pParent, xmlreader::XmlReader &reader) { OString sClass; OString sID; @@ -2867,22 +2875,22 @@ vcl::Window* VclBuilder::handleObject(vcl::Window *pParent, xmlreader::XmlReader if (sClass == "GtkListStore") { handleListStore(reader, sID); - return NULL; + return nullptr; } else if (sClass == "GtkMenu") { handleMenu(reader, sID); - return NULL; + return nullptr; } else if (sClass == "GtkSizeGroup") { handleSizeGroup(reader, sID); - return NULL; + return nullptr; } else if (sClass == "AtkObject") { handleAtkObject(reader, sID, pParent); - return NULL; + return nullptr; } int nLevel = 1; @@ -2893,7 +2901,7 @@ vcl::Window* VclBuilder::handleObject(vcl::Window *pParent, xmlreader::XmlReader if (!sCustomProperty.isEmpty()) aProperties[OString("customproperty")] = sCustomProperty; - vcl::Window *pCurrentChild = NULL; + VclPtr<vcl::Window> pCurrentChild; while(true) { xmlreader::XmlReader::Result res = reader.nextItem( @@ -3015,7 +3023,7 @@ void VclBuilder::applyPackingProperty(vcl::Window *pCurrent, if (pCurrent->GetType() == WINDOW_SCROLLWINDOW) { - std::map<vcl::Window*, vcl::Window*>::iterator aFind = m_pParserState->m_aRedundantParentWidgets.find(pCurrent); + auto aFind = m_pParserState->m_aRedundantParentWidgets.find(VclPtr<vcl::Window>(pCurrent)); if (aFind != m_pParserState->m_aRedundantParentWidgets.end()) { pCurrent = aFind->second; @@ -3213,7 +3221,7 @@ void VclBuilder::collectAccelerator(xmlreader::XmlReader &reader, stringmap &rMa vcl::Window *VclBuilder::get_widget_root() { - return m_aChildren.empty() ? NULL : m_aChildren[0].m_pWindow; + return m_aChildren.empty() ? NULL : m_aChildren[0].m_pWindow.get(); } vcl::Window *VclBuilder::get_by_name(const OString& sID) @@ -3279,17 +3287,17 @@ void VclBuilder::delete_by_name(const OString& sID) { if (aI->m_sID.equals(sID)) { - delete aI->m_pWindow; + aI->m_pWindow.disposeAndClear(); m_aChildren.erase(aI); break; } } } -void VclBuilder::delete_by_window(const vcl::Window *pWindow) +void VclBuilder::delete_by_window(vcl::Window *pWindow) { drop_ownership(pWindow); - delete pWindow; + pWindow->disposeOnce(); } void VclBuilder::drop_ownership(const vcl::Window *pWindow) @@ -3551,4 +3559,8 @@ void VclBuilder::mungeTextBuffer(VclMultiLineEdit &rTarget, const TextBuffer &rT } } +VclBuilder::ParserState::ParserState() + : m_nLastToolbarId(0) +{} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/window/clipping.cxx b/vcl/source/window/clipping.cxx index 0c24e3051832..38efc376c7ef 100644 --- a/vcl/source/window/clipping.cxx +++ b/vcl/source/window/clipping.cxx @@ -842,7 +842,7 @@ void Window::ImplSaveOverlapBackground() if ( nSaveBackSize+mpWindowImpl->mpFrameData->mnAllSaveBackSize <= IMPL_MAXALLSAVEBACKSIZE ) { Size aOutSize( mnOutWidth, mnOutHeight ); - mpWindowImpl->mpOverlapData->mpSaveBackDev = new VirtualDevice( *mpWindowImpl->mpFrameWindow ); + mpWindowImpl->mpOverlapData->mpSaveBackDev = VclPtr<VirtualDevice>::Create( *mpWindowImpl->mpFrameWindow ); if ( mpWindowImpl->mpOverlapData->mpSaveBackDev->SetOutputSizePixel( aOutSize ) ) { mpWindowImpl->mpFrameWindow->ImplUpdateAll(); @@ -863,8 +863,7 @@ void Window::ImplSaveOverlapBackground() } else { - delete mpWindowImpl->mpOverlapData->mpSaveBackDev; - mpWindowImpl->mpOverlapData->mpSaveBackDev = NULL; + mpWindowImpl->mpOverlapData->mpSaveBackDev.disposeAndClear(); } } } @@ -915,8 +914,7 @@ void Window::ImplDeleteOverlapBackground() if ( mpWindowImpl->mpOverlapData->mpSaveBackDev ) { mpWindowImpl->mpFrameData->mnAllSaveBackSize -= mpWindowImpl->mpOverlapData->mnSaveBackSize; - delete mpWindowImpl->mpOverlapData->mpSaveBackDev; - mpWindowImpl->mpOverlapData->mpSaveBackDev = NULL; + mpWindowImpl->mpOverlapData->mpSaveBackDev.disposeAndClear(); if ( mpWindowImpl->mpOverlapData->mpSaveBackRgn ) { delete mpWindowImpl->mpOverlapData->mpSaveBackRgn; @@ -929,7 +927,7 @@ void Window::ImplDeleteOverlapBackground() else { vcl::Window* pTemp = mpWindowImpl->mpFrameData->mpFirstBackWin; - while ( pTemp->mpWindowImpl->mpOverlapData->mpNextBackWin != this ) + while ( pTemp->mpWindowImpl->mpOverlapData->mpNextBackWin.get() != this ) pTemp = pTemp->mpWindowImpl->mpOverlapData->mpNextBackWin; pTemp->mpWindowImpl->mpOverlapData->mpNextBackWin = mpWindowImpl->mpOverlapData->mpNextBackWin; } diff --git a/vcl/source/window/cursor.cxx b/vcl/source/window/cursor.cxx index d0c9a7327e5d..e61d82b1b5d6 100644 --- a/vcl/source/window/cursor.cxx +++ b/vcl/source/window/cursor.cxx @@ -38,7 +38,7 @@ struct ImplCursorData unsigned char mnDirection; // indicates writing direction sal_uInt16 mnStyle; // Cursor-Style bool mbCurVisible; // Ist Cursor aktuell sichtbar - vcl::Window* mpWindow; // Zugeordnetes Windows + VclPtr<vcl::Window> mpWindow; // Zugeordnetes Windows }; static void ImplCursorInvert( ImplCursorData* pData ) @@ -319,7 +319,7 @@ void vcl::Cursor::Hide() void vcl::Cursor::SetWindow( vcl::Window* pWindow ) { - if ( mpWindow != pWindow ) + if ( mpWindow.get() != pWindow ) { mpWindow = pWindow; ImplNew(); diff --git a/vcl/source/window/decoview.cxx b/vcl/source/window/decoview.cxx index c04c430ceac3..5bb7b79cbb0e 100644 --- a/vcl/source/window/decoview.cxx +++ b/vcl/source/window/decoview.cxx @@ -1050,7 +1050,7 @@ void DecorationView::DrawSeparator( const Point& rStart, const Point& rStop, boo { Point aStart( rStart ), aStop( rStop ); const StyleSettings& rStyleSettings = mpOutDev->GetSettings().GetStyleSettings(); - vcl::Window *const pWin = (mpOutDev->GetOutDevType()==OUTDEV_WINDOW) ? static_cast<vcl::Window*>(mpOutDev) : NULL; + vcl::Window *const pWin = (mpOutDev->GetOutDevType()==OUTDEV_WINDOW) ? static_cast<vcl::Window*>(mpOutDev.get()) : NULL; if(pWin) { ControlPart nPart = ( bVertical ? PART_SEPARATOR_VERT : PART_SEPARATOR_HORZ ); diff --git a/vcl/source/window/dialog.cxx b/vcl/source/window/dialog.cxx index 1e9f53a86df3..9e6d4bf12dae 100644 --- a/vcl/source/window/dialog.cxx +++ b/vcl/source/window/dialog.cxx @@ -347,8 +347,8 @@ void Dialog::ImplInitDialogData() mbOldSaveBack = false; mbInClose = false; mbModalMode = false; - mpContentArea = NULL; - mpActionArea = NULL; + mpContentArea.clear(); + mpActionArea.clear(); mnMousePositioned = 0; mpDialogImpl = new DialogImpl; } @@ -403,7 +403,7 @@ void Dialog::ImplInit( vcl::Window* pParent, WinBits nStyle ) // create window with a small border ? if ( (nStyle & (WB_BORDER | WB_NOBORDER | WB_MOVEABLE | WB_SIZEABLE | WB_CLOSEABLE)) == WB_BORDER ) { - ImplBorderWindow* pBorderWin = new ImplBorderWindow( pParent, nStyle, BORDERWINDOW_STYLE_FRAME ); + VclPtrInstance<ImplBorderWindow> pBorderWin( pParent, nStyle, BORDERWINDOW_STYLE_FRAME ); SystemWindow::ImplInit( pBorderWin, nStyle & ~WB_BORDER, NULL ); pBorderWin->mpWindowImpl->mpClientWindow = this; pBorderWin->GetBorder( mpWindowImpl->mnLeftBorder, mpWindowImpl->mnTopBorder, mpWindowImpl->mnRightBorder, mpWindowImpl->mnBottomBorder ); @@ -421,7 +421,7 @@ void Dialog::ImplInit( vcl::Window* pParent, WinBits nStyle ) } else { - ImplBorderWindow* pBorderWin = new ImplBorderWindow( pParent, nStyle, BORDERWINDOW_STYLE_OVERLAP | BORDERWINDOW_STYLE_BORDER ); + VclPtrInstance<ImplBorderWindow> pBorderWin( pParent, nStyle, BORDERWINDOW_STYLE_OVERLAP | BORDERWINDOW_STYLE_BORDER ); SystemWindow::ImplInit( pBorderWin, nStyle & ~WB_BORDER, NULL ); pBorderWin->mpWindowImpl->mpClientWindow = this; pBorderWin->GetBorder( mpWindowImpl->mnLeftBorder, mpWindowImpl->mnTopBorder, mpWindowImpl->mnRightBorder, mpWindowImpl->mnBottomBorder ); @@ -456,6 +456,12 @@ Dialog::Dialog( WindowType nType ) ImplInitDialogData(); } +void VclBuilderContainer::disposeBuilder() +{ + if (m_pUIBuilder) + m_pUIBuilder->disposeBuilder(); +} + OUString VclBuilderContainer::getUIRootDir() { /*to-do, check if user config has an override before using shared one, etc*/ @@ -482,7 +488,7 @@ OUString VclBuilderContainer::getUIRootDir() //do the init. Find the real parent stashed in mpDialogParent. void Dialog::doDeferredInit(WinBits nBits) { - vcl::Window *pParent = mpDialogParent; + VclPtr<vcl::Window> pParent = mpDialogParent; mpDialogParent = NULL; ImplInit(pParent, nBits); mbIsDefferedInit = false; @@ -509,14 +515,14 @@ Dialog::Dialog(vcl::Window* pParent, WinBits nStyle) ImplInit( pParent, nStyle ); } -void Dialog::set_action_area(VclButtonBox* pActionArea) +void Dialog::set_action_area(VclButtonBox* pBox) { - mpActionArea = pActionArea; + mpActionArea.set(pBox); } -void Dialog::set_content_area(VclBox* pContentArea) +void Dialog::set_content_area(VclBox* pBox) { - mpContentArea = pContentArea; + mpContentArea.set(pBox); } void Dialog::settingOptimalLayoutSize(Window *pBox) @@ -538,8 +544,17 @@ void Dialog::settingOptimalLayoutSize(Window *pBox) Dialog::~Dialog() { + disposeOnce(); +} + +void Dialog::dispose() +{ delete mpDialogImpl; mpDialogImpl = NULL; + mpPrevExecuteDlg.clear(); + mpActionArea.clear(); + mpContentArea.clear(); + SystemWindow::dispose(); } IMPL_LINK_NOARG(Dialog, ImplAsyncCloseHdl) @@ -991,7 +1006,7 @@ void Dialog::SetModalInputMode( bool bModal ) pPrevModalDlg = pPrevModalDlg->mpPrevExecuteDlg; if( pPrevModalDlg && - ( pPrevModalDlg == mpPrevExecuteDlg + ( pPrevModalDlg == mpPrevExecuteDlg.get() || !pPrevModalDlg->IsWindowOrChild( this, true ) ) ) { mpPrevExecuteDlg->SetModalInputMode( false ); @@ -1050,8 +1065,8 @@ void Dialog::GrabFocusToFirstControl() void Dialog::GetDrawWindowBorder( sal_Int32& rLeftBorder, sal_Int32& rTopBorder, sal_Int32& rRightBorder, sal_Int32& rBottomBorder ) const { - ImplBorderWindow aImplWin( (vcl::Window*)this, WB_BORDER|WB_STDWORK, BORDERWINDOW_STYLE_OVERLAP ); - aImplWin.GetBorder( rLeftBorder, rTopBorder, rRightBorder, rBottomBorder ); + ScopedVclPtrInstance<ImplBorderWindow> aImplWin( (vcl::Window*)this, WB_BORDER|WB_STDWORK, BORDERWINDOW_STYLE_OVERLAP ); + aImplWin->GetBorder( rLeftBorder, rTopBorder, rRightBorder, rBottomBorder ); } void Dialog::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, sal_uLong ) @@ -1077,13 +1092,13 @@ void Dialog::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, sal if (!( GetStyle() & WB_NOBORDER )) { - ImplBorderWindow aImplWin( this, WB_BORDER|WB_STDWORK, BORDERWINDOW_STYLE_OVERLAP ); - aImplWin.SetText( GetText() ); - aImplWin.setPosSizePixel( aPos.X(), aPos.Y(), aSize.Width(), aSize.Height() ); - aImplWin.SetDisplayActive( true ); - aImplWin.InitView(); + ScopedVclPtrInstance< ImplBorderWindow > aImplWin( this, WB_BORDER|WB_STDWORK, BORDERWINDOW_STYLE_OVERLAP ); + aImplWin->SetText( GetText() ); + aImplWin->setPosSizePixel( aPos.X(), aPos.Y(), aSize.Width(), aSize.Height() ); + aImplWin->SetDisplayActive( true ); + aImplWin->InitView(); - aImplWin.Draw( Rectangle( aPos, aSize ), pDev, aPos ); + aImplWin->Draw( Rectangle( aPos, aSize ), pDev, aPos ); } pDev->Pop(); diff --git a/vcl/source/window/dlgctrl.cxx b/vcl/source/window/dlgctrl.cxx index 2b63b3f3920d..eb899fdb2831 100644 --- a/vcl/source/window/dlgctrl.cxx +++ b/vcl/source/window/dlgctrl.cxx @@ -530,9 +530,9 @@ namespace ); } - bool focusNextInGroup(std::vector<RadioButton*>::iterator aStart, std::vector<RadioButton*> &rGroup) + bool focusNextInGroup(const std::vector<VclPtr<RadioButton> >::iterator& aStart, std::vector<VclPtr<RadioButton> > &rGroup) { - std::vector<RadioButton*>::iterator aI(aStart); + std::vector<VclPtr<RadioButton> >::iterator aI(aStart); if (aStart != rGroup.end()) ++aI; @@ -564,7 +564,7 @@ namespace bool nextInGroup(RadioButton *pSourceWindow, bool bBackward) { - std::vector<RadioButton*> aGroup(pSourceWindow->GetRadioButtonGroup(true)); + std::vector<VclPtr<RadioButton> > aGroup(pSourceWindow->GetRadioButtonGroup(true)); if (aGroup.size() == 1) //only one button in group return false; @@ -572,7 +572,7 @@ namespace if (bBackward) std::reverse(aGroup.begin(), aGroup.end()); - std::vector<RadioButton*>::iterator aStart(std::find(aGroup.begin(), aGroup.end(), pSourceWindow)); + auto aStart(std::find(aGroup.begin(), aGroup.end(), VclPtr<RadioButton>(pSourceWindow))); assert(aStart != aGroup.end()); @@ -716,9 +716,9 @@ bool Window::ImplDlgCtrl( const KeyEvent& rKEvt, bool bKeyInput ) if ( bKeyInput && mpWindowImpl->mpDlgCtrlDownWindow ) { - if ( mpWindowImpl->mpDlgCtrlDownWindow != pButtonWindow ) + if ( mpWindowImpl->mpDlgCtrlDownWindow.get() != pButtonWindow ) { - static_cast<PushButton*>(mpWindowImpl->mpDlgCtrlDownWindow)->SetPressed( false ); + static_cast<PushButton*>(mpWindowImpl->mpDlgCtrlDownWindow.get())->SetPressed( false ); mpWindowImpl->mpDlgCtrlDownWindow = NULL; return true; } @@ -928,16 +928,16 @@ bool Window::ImplDlgCtrl( const KeyEvent& rKEvt, bool bKeyInput ) { if ( bKeyInput ) { - if ( mpWindowImpl->mpDlgCtrlDownWindow && (mpWindowImpl->mpDlgCtrlDownWindow != pButtonWindow) ) + if ( mpWindowImpl->mpDlgCtrlDownWindow && (mpWindowImpl->mpDlgCtrlDownWindow.get() != pButtonWindow) ) { - static_cast<PushButton*>(mpWindowImpl->mpDlgCtrlDownWindow)->SetPressed( false ); + static_cast<PushButton*>(mpWindowImpl->mpDlgCtrlDownWindow.get())->SetPressed( false ); mpWindowImpl->mpDlgCtrlDownWindow = NULL; } static_cast<PushButton*>(pButtonWindow)->SetPressed( true ); mpWindowImpl->mpDlgCtrlDownWindow = pButtonWindow; } - else if ( mpWindowImpl->mpDlgCtrlDownWindow == pButtonWindow ) + else if ( mpWindowImpl->mpDlgCtrlDownWindow.get() == pButtonWindow ) { mpWindowImpl->mpDlgCtrlDownWindow = NULL; static_cast<PushButton*>(pButtonWindow)->SetPressed( false ); @@ -1060,7 +1060,7 @@ void Window::ImplDlgCtrlFocusChanged( vcl::Window* pWindow, bool bGetFocus ) { if ( mpWindowImpl->mpDlgCtrlDownWindow && !bGetFocus ) { - static_cast<PushButton*>(mpWindowImpl->mpDlgCtrlDownWindow)->SetPressed( false ); + static_cast<PushButton*>(mpWindowImpl->mpDlgCtrlDownWindow.get())->SetPressed( false ); mpWindowImpl->mpDlgCtrlDownWindow = NULL; } diff --git a/vcl/source/window/dndevdis.cxx b/vcl/source/window/dndevdis.cxx index dabfef79569e..94d6ae75b1dd 100644 --- a/vcl/source/window/dndevdis.cxx +++ b/vcl/source/window/dndevdis.cxx @@ -99,7 +99,7 @@ void SAL_CALL DNDEventDispatcher::drop( const DropTargetDropEvent& dtde ) vcl::Window* pChildWindow = findTopLevelWindow(location); // handle the case that drop is in an other vcl window than the last dragOver - if( pChildWindow != m_pCurrentWindow ) + if( pChildWindow != m_pCurrentWindow.get() ) { // fire dragExit on listeners of previous window fireDragExitEvent( m_pCurrentWindow ); @@ -177,7 +177,7 @@ void SAL_CALL DNDEventDispatcher::dragOver( const DropTargetDragEvent& dtde ) vcl::Window * pChildWindow = findTopLevelWindow(location); - if( pChildWindow != m_pCurrentWindow ) + if( pChildWindow != m_pCurrentWindow.get() ) { // fire dragExit on listeners of previous window fireDragExitEvent( m_pCurrentWindow ); @@ -215,7 +215,7 @@ void SAL_CALL DNDEventDispatcher::dropActionChanged( const DropTargetDragEvent& vcl::Window* pChildWindow = findTopLevelWindow(location); - if( pChildWindow != m_pCurrentWindow ) + if( pChildWindow != m_pCurrentWindow.get() ) { // fire dragExit on listeners of previous window fireDragExitEvent( m_pCurrentWindow ); diff --git a/vcl/source/window/dockingarea.cxx b/vcl/source/window/dockingarea.cxx index 623ea9635b37..43ce7bdb3c4d 100644 --- a/vcl/source/window/dockingarea.cxx +++ b/vcl/source/window/dockingarea.cxx @@ -92,7 +92,13 @@ DockingAreaWindow::DockingAreaWindow( vcl::Window* pParent ) : DockingAreaWindow::~DockingAreaWindow() { + disposeOnce(); +} + +void DockingAreaWindow::dispose() +{ delete mpImplData; + Window::dispose(); } void DockingAreaWindow::DataChanged( const DataChangedEvent& rDCEvt ) diff --git a/vcl/source/window/dockmgr.cxx b/vcl/source/window/dockmgr.cxx index 66b01f9e1283..160e21074029 100644 --- a/vcl/source/window/dockmgr.cxx +++ b/vcl/source/window/dockmgr.cxx @@ -57,6 +57,7 @@ public: ImplDockFloatWin2( vcl::Window* pParent, WinBits nWinBits, ImplDockingWindowWrapper* pDockingWin ); virtual ~ImplDockFloatWin2(); + virtual void dispose() SAL_OVERRIDE; virtual void Move() SAL_OVERRIDE; virtual void Resize() SAL_OVERRIDE; @@ -97,8 +98,14 @@ ImplDockFloatWin2::ImplDockFloatWin2( vcl::Window* pParent, WinBits nWinBits, ImplDockFloatWin2::~ImplDockFloatWin2() { + disposeOnce(); +} + +void ImplDockFloatWin2::dispose() +{ if( mnLastUserEvent ) Application::RemoveUserEvent( mnLastUserEvent ); + FloatingWindow::dispose(); } IMPL_LINK_NOARG(ImplDockFloatWin2, DockTimerHdl) @@ -477,6 +484,7 @@ private: public: ImplPopupFloatWin( vcl::Window* pParent, ImplDockingWindowWrapper* pDockingWin, bool bHasGrip ); virtual ~ImplPopupFloatWin(); + virtual void dispose() SAL_OVERRIDE; virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > CreateAccessible() SAL_OVERRIDE; virtual void Paint( const Rectangle& rRect ) SAL_OVERRIDE; @@ -513,7 +521,13 @@ ImplPopupFloatWin::ImplPopupFloatWin( vcl::Window* pParent, ImplDockingWindowWra ImplPopupFloatWin::~ImplPopupFloatWin() { + disposeOnce(); +} + +void ImplPopupFloatWin::dispose() +{ mpDockingWin = NULL; + FloatingWindow::dispose(); } ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > ImplPopupFloatWin::CreateAccessible() @@ -813,7 +827,7 @@ ImplDockingWindowWrapper::ImplDockingWindowWrapper( const vcl::Window *pWindow ) , mbStartDockingEnabled(false) , mbLocked(false) { - DockingWindow *pDockWin = dynamic_cast< DockingWindow* > ( mpDockingWindow ); + DockingWindow *pDockWin = dynamic_cast< DockingWindow* > ( mpDockingWindow.get() ); if( pDockWin ) mnFloatBits = pDockWin->GetFloatStyle(); } @@ -842,14 +856,14 @@ bool ImplDockingWindowWrapper::ImplStartDocking( const Point& rPos ) mbStartFloat = mbLastFloatMode; // calculate FloatingBorder - FloatingWindow* pWin; + VclPtr<FloatingWindow> pWin; if ( mpFloatWin ) pWin = mpFloatWin; else - pWin = new ImplDockFloatWin2( mpParent, mnFloatBits, NULL ); + pWin = VclPtr<ImplDockFloatWin2>::Create( mpParent, mnFloatBits, nullptr ); pWin->GetBorder( mnDockLeft, mnDockTop, mnDockRight, mnDockBottom ); if ( !mpFloatWin ) - delete pWin; + pWin.disposeAndClear(); Point aPos = GetWindow()->ImplOutputToFrame( Point() ); Size aSize = GetWindow()->GetOutputSizePixel(); @@ -1098,11 +1112,11 @@ void ImplDockingWindowWrapper::StartPopupMode( ToolBox *pParentToolBox, sal_uLon // prepare reparenting vcl::Window* pRealParent = GetWindow()->GetWindow( WINDOW_PARENT ); mpOldBorderWin = GetWindow()->GetWindow( WINDOW_BORDER ); - if( mpOldBorderWin == GetWindow() ) + if( mpOldBorderWin.get() == GetWindow() ) mpOldBorderWin = NULL; // no border window found // the new parent for popup mode - ImplPopupFloatWin* pWin = new ImplPopupFloatWin( mpParent, this, (nFlags & FLOATWIN_POPUPMODE_ALLOWTEAROFF) != 0 ); + VclPtrInstance<ImplPopupFloatWin> pWin( mpParent, this, (nFlags & FLOATWIN_POPUPMODE_ALLOWTEAROFF) != 0 ); pWin->SetPopupModeEndHdl( LINK( this, ImplDockingWindowWrapper, PopupModeEnd ) ); pWin->SetText( GetWindow()->GetText() ); @@ -1153,7 +1167,7 @@ IMPL_LINK_NOARG(ImplDockingWindowWrapper, PopupModeEnd) GetWindow()->Show( false, SHOW_NOFOCUSCHANGE ); // set parameter for handler before destroying floating window - ImplPopupFloatWin *pPopupFloatWin = static_cast<ImplPopupFloatWin*>(mpFloatWin); + ImplPopupFloatWin *pPopupFloatWin = static_cast<ImplPopupFloatWin*>(mpFloatWin.get()); EndPopupModeData aData( pPopupFloatWin->GetTearOffPosition(), mpFloatWin->IsPopupModeTearOff() ); // before deleting change parent back, so we can delete the floating window alone @@ -1162,7 +1176,7 @@ IMPL_LINK_NOARG(ImplDockingWindowWrapper, PopupModeEnd) if ( mpOldBorderWin ) { GetWindow()->SetParent( mpOldBorderWin ); - static_cast<ImplBorderWindow*>(mpOldBorderWin)->GetBorder( + static_cast<ImplBorderWindow*>(mpOldBorderWin.get())->GetBorder( GetWindow()->mpWindowImpl->mnLeftBorder, GetWindow()->mpWindowImpl->mnTopBorder, GetWindow()->mpWindowImpl->mnRightBorder, GetWindow()->mpWindowImpl->mnBottomBorder ); mpOldBorderWin->Resize(); @@ -1171,8 +1185,7 @@ IMPL_LINK_NOARG(ImplDockingWindowWrapper, PopupModeEnd) GetWindow()->SetParent( pRealParent ); GetWindow()->mpWindowImpl->mpRealParent = pRealParent; - delete mpFloatWin; - mpFloatWin = NULL; + mpFloatWin.disposeAndClear(); // call handler - which will destroy the window and thus the wrapper as well ! GetWindow()->CallEventListeners( VCLEVENT_WINDOW_ENDPOPUPMODE, &aData ); @@ -1212,7 +1225,8 @@ void ImplDockingWindowWrapper::SetFloatingMode( bool bFloatMode ) mpOldBorderWin = NULL; // no border window found ImplDockFloatWin2* pWin = - new ImplDockFloatWin2( + VclPtr<ImplDockFloatWin2>::Create( + mpParent, mnFloatBits & ( WB_MOVEABLE | WB_SIZEABLE | WB_CLOSEABLE ) ? mnFloatBits | WB_SYSTEMWINDOW @@ -1277,7 +1291,7 @@ void ImplDockingWindowWrapper::SetFloatingMode( bool bFloatMode ) if ( mpOldBorderWin ) { GetWindow()->SetParent( mpOldBorderWin ); - static_cast<ImplBorderWindow*>(mpOldBorderWin)->GetBorder( + static_cast<ImplBorderWindow*>(mpOldBorderWin.get())->GetBorder( GetWindow()->mpWindowImpl->mnLeftBorder, GetWindow()->mpWindowImpl->mnTopBorder, GetWindow()->mpWindowImpl->mnRightBorder, GetWindow()->mpWindowImpl->mnBottomBorder ); mpOldBorderWin->Resize(); @@ -1286,8 +1300,7 @@ void ImplDockingWindowWrapper::SetFloatingMode( bool bFloatMode ) GetWindow()->SetParent( pRealParent ); GetWindow()->mpWindowImpl->mpRealParent = pRealParent; - delete static_cast<ImplDockFloatWin2*>(mpFloatWin); - mpFloatWin = NULL; + mpFloatWin.disposeAndClear(); GetWindow()->SetPosPixel( maDockPos ); if ( bVisible ) @@ -1350,7 +1363,7 @@ void ImplDockingWindowWrapper::SetMaxOutputSizePixel( const Size& rSize ) bool ImplDockingWindowWrapper::IsFloatingMode() const { - return (mpFloatWin != NULL); + return (mpFloatWin != nullptr); } void ImplDockingWindowWrapper::SetDragArea( const Rectangle& rRect ) diff --git a/vcl/source/window/dockwin.cxx b/vcl/source/window/dockwin.cxx index a170e3f3d5ca..408cb328a132 100644 --- a/vcl/source/window/dockwin.cxx +++ b/vcl/source/window/dockwin.cxx @@ -42,8 +42,8 @@ public: ImplData(); ~ImplData(); - vcl::Window* mpParent; - Size maMaxOutSize; + VclPtr<vcl::Window> mpParent; + Size maMaxOutSize; }; DockingWindow::ImplData::ImplData() @@ -59,7 +59,7 @@ DockingWindow::ImplData::~ImplData() class ImplDockFloatWin : public FloatingWindow { private: - DockingWindow* mpDockWin; + VclPtr<DockingWindow> mpDockWin; sal_uInt64 mnLastTicks; Idle maDockIdle; Point maDockPos; @@ -73,6 +73,7 @@ public: ImplDockFloatWin( vcl::Window* pParent, WinBits nWinBits, DockingWindow* pDockingWin ); virtual ~ImplDockFloatWin(); + virtual void dispose() SAL_OVERRIDE; virtual void Move() SAL_OVERRIDE; virtual void Resize() SAL_OVERRIDE; @@ -111,8 +112,18 @@ ImplDockFloatWin::ImplDockFloatWin( vcl::Window* pParent, WinBits nWinBits, ImplDockFloatWin::~ImplDockFloatWin() { + disposeOnce(); +} + +void ImplDockFloatWin::dispose() +{ if( mnLastUserEvent ) Application::RemoveUserEvent( mnLastUserEvent ); + + disposeBuilder(); + + mpDockWin.clear(); + FloatingWindow::dispose(); } IMPL_LINK_NOARG(ImplDockFloatWin, DockTimerHdl) @@ -253,14 +264,14 @@ bool DockingWindow::ImplStartDocking( const Point& rPos ) mbStartFloat = mbLastFloatMode; // calculate FloatingBorder - FloatingWindow* pWin; + VclPtr<FloatingWindow> pWin; if ( mpFloatWin ) pWin = mpFloatWin; else - pWin = new ImplDockFloatWin( mpImplData->mpParent, mnFloatBits, NULL ); + pWin = VclPtr<ImplDockFloatWin>::Create( mpImplData->mpParent, mnFloatBits, nullptr ); pWin->GetBorder( mnDockLeft, mnDockTop, mnDockRight, mnDockBottom ); if ( !mpFloatWin ) - delete pWin; + pWin.disposeAndClear(); Point aPos = ImplOutputToFrame( Point() ); Size aSize = Window::GetOutputSizePixel(); @@ -460,6 +471,11 @@ DockingWindow::DockingWindow(vcl::Window* pParent, const OString& rID, DockingWindow::~DockingWindow() { + disposeOnce(); +} + +void DockingWindow::dispose() +{ if ( IsFloatingMode() ) { Show( false, SHOW_NOFOCUSCHANGE ); @@ -467,6 +483,11 @@ DockingWindow::~DockingWindow() } delete mpImplData; mpImplData = NULL; + mpFloatWin.clear(); + mpOldBorderWin.clear(); + mpDialogParent.clear(); + disposeBuilder(); + Window::dispose(); } void DockingWindow::Tracking( const TrackingEvent& rTEvt ) @@ -781,7 +802,8 @@ void DockingWindow::SetFloatingMode( bool bFloatMode ) mpOldBorderWin = mpWindowImpl->mpBorderWindow; ImplDockFloatWin* pWin = - new ImplDockFloatWin( + VclPtr<ImplDockFloatWin>::Create( + mpImplData->mpParent, mnFloatBits & ( WB_MOVEABLE | WB_SIZEABLE | WB_CLOSEABLE ) ? mnFloatBits | WB_SYSTEMWINDOW : mnFloatBits, this ); @@ -851,14 +873,13 @@ void DockingWindow::SetFloatingMode( bool bFloatMode ) if ( mpOldBorderWin ) { SetParent( mpOldBorderWin ); - static_cast<ImplBorderWindow*>(mpOldBorderWin)->GetBorder( mpWindowImpl->mnLeftBorder, mpWindowImpl->mnTopBorder, mpWindowImpl->mnRightBorder, mpWindowImpl->mnBottomBorder ); + static_cast<ImplBorderWindow*>(mpOldBorderWin.get())->GetBorder( mpWindowImpl->mnLeftBorder, mpWindowImpl->mnTopBorder, mpWindowImpl->mnRightBorder, mpWindowImpl->mnBottomBorder ); mpOldBorderWin->Resize(); } mpWindowImpl->mpBorderWindow = mpOldBorderWin; SetParent( pRealParent ); mpWindowImpl->mpRealParent = pRealParent; - delete static_cast<ImplDockFloatWin*>(mpFloatWin); - mpFloatWin = NULL; + mpFloatWin.disposeAndClear(); SetPosPixel( maDockPos ); ToggleFloatingMode(); @@ -1033,7 +1054,7 @@ bool DockingWindow::IsFloatingMode() const if( pWrapper ) return pWrapper->IsFloatingMode(); else - return (mpFloatWin != NULL); + return (mpFloatWin != nullptr); } void DockingWindow::SetMaxOutputSizePixel( const Size& rSize ) diff --git a/vcl/source/window/event.cxx b/vcl/source/window/event.cxx index da38fde26b36..9c954125779d 100644 --- a/vcl/source/window/event.cxx +++ b/vcl/source/window/event.cxx @@ -94,6 +94,9 @@ bool Window::Notify( NotifyEvent& rNEvt ) { bool nRet = false; + if (IsDisposed()) + return false; + // check for docking window // but do nothing if window is docked and locked ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this ); @@ -221,6 +224,9 @@ void Window::CallEventListeners( sal_uLong nEvent, void* pData ) { pWindow->ImplAddDel( &aDelData ); + if ( aDelData.IsDead() ) + return; + pWindow->mpWindowImpl->maChildEventListeners.Call( &aEvent ); if ( aDelData.IsDead() ) @@ -277,7 +283,7 @@ ImplSVEvent * Window::PostUserEvent( const Link& rLink, void* pCaller ) void Window::RemoveUserEvent( ImplSVEvent * nUserEvent ) { - DBG_ASSERT( nUserEvent->mpWindow == this, + DBG_ASSERT( nUserEvent->mpWindow.get() == this, "Window::RemoveUserEvent(): Event doesn't send to this window or is already removed" ); DBG_ASSERT( nUserEvent->mbCall, "Window::RemoveUserEvent(): Event is already removed" ); @@ -515,14 +521,14 @@ void Window::ImplCallFocusChangeActivate( vcl::Window* pNewOverlapWindow, { if ( pSVData->maWinData.mpLastDeacWin ) { - if ( pSVData->maWinData.mpLastDeacWin == pNewOverlapWindow ) + if ( pSVData->maWinData.mpLastDeacWin.get() == pNewOverlapWindow ) bCallActivate = false; else { vcl::Window* pLastRealWindow = pSVData->maWinData.mpLastDeacWin->ImplGetWindow(); pSVData->maWinData.mpLastDeacWin->mpWindowImpl->mbActive = false; pSVData->maWinData.mpLastDeacWin->Deactivate(); - if ( pLastRealWindow != pSVData->maWinData.mpLastDeacWin ) + if ( pLastRealWindow != pSVData->maWinData.mpLastDeacWin.get() ) { pLastRealWindow->mpWindowImpl->mbActive = true; pLastRealWindow->Activate(); @@ -568,5 +574,21 @@ void Window::ImplCallFocusChangeActivate( vcl::Window* pNewOverlapWindow, } /* namespace vcl */ +NotifyEvent::NotifyEvent() +{ + mpWindow = NULL; + mpData = NULL; + mnEventType = MouseNotifyEvent::NONE; + mnRetValue = 0; +} + +NotifyEvent::NotifyEvent( MouseNotifyEvent nEventType, vcl::Window* pWindow, + const void* pEvent, long nRet ) +{ + mpWindow = pWindow; + mpData = const_cast<void*>(pEvent); + mnEventType = nEventType; + mnRetValue = nRet; +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/window/floatwin.cxx b/vcl/source/window/floatwin.cxx index 8ad024e1511f..65a5ef452458 100644 --- a/vcl/source/window/floatwin.cxx +++ b/vcl/source/window/floatwin.cxx @@ -39,7 +39,7 @@ public: ImplData(); ~ImplData(); - ToolBox* mpBox; + VclPtr<ToolBox> mpBox; Rectangle maItemEdgeClipRect; // used to clip the common edge between a toolbar item and the border of this window }; @@ -107,7 +107,7 @@ void FloatingWindow::ImplInit( vcl::Window* pParent, WinBits nStyle ) nBorderStyle |= BORDERWINDOW_STYLE_FRAME; nStyle |= WB_CLOSEABLE; // make undecorated floaters closeable } - pBorderWin = new ImplBorderWindow( pParent, nStyle, nBorderStyle ); + pBorderWin = VclPtr<ImplBorderWindow>::Create( pParent, nStyle, nBorderStyle ); SystemWindow::ImplInit( pBorderWin, nStyle & ~WB_BORDER, NULL ); pBorderWin->mpWindowImpl->mpClientWindow = this; pBorderWin->GetBorder( mpWindowImpl->mnLeftBorder, mpWindowImpl->mnTopBorder, mpWindowImpl->mnRightBorder, mpWindowImpl->mnBottomBorder ); @@ -185,18 +185,32 @@ void FloatingWindow::doDeferredInit(WinBits nBits) FloatingWindow::~FloatingWindow() { - if( mbPopupModeCanceled ) - // indicates that ESC key was pressed - // will be handled in Window::ImplGrabFocus() - SetDialogControlFlags( GetDialogControlFlags() | WINDOW_DLGCTRL_FLOATWIN_POPUPMODEEND_CANCEL ); + disposeOnce(); +} + +void FloatingWindow::dispose() +{ + if (mpImplData) + { + if( mbPopupModeCanceled ) + // indicates that ESC key was pressed + // will be handled in Window::ImplGrabFocus() + SetDialogControlFlags( GetDialogControlFlags() | WINDOW_DLGCTRL_FLOATWIN_POPUPMODEEND_CANCEL ); - if ( IsInPopupMode() ) - EndPopupMode( FLOATWIN_POPUPMODEEND_CANCEL | FLOATWIN_POPUPMODEEND_CLOSEALL | FLOATWIN_POPUPMODEEND_DONTCALLHDL ); + if ( IsInPopupMode() ) + EndPopupMode( FLOATWIN_POPUPMODEEND_CANCEL | FLOATWIN_POPUPMODEEND_CLOSEALL | FLOATWIN_POPUPMODEEND_DONTCALLHDL ); - if ( mnPostId ) - Application::RemoveUserEvent( mnPostId ); + if ( mnPostId ) + Application::RemoveUserEvent( mnPostId ); + mnPostId = 0; + } delete mpImplData; + mpImplData = NULL; + + mpNextFloat.clear(); + mpFirstPopupModeWin.clear(); + SystemWindow::dispose(); } Point FloatingWindow::CalcFloatingPosition( vcl::Window* pWindow, const Rectangle& rRect, sal_uLong nFlags, sal_uInt16& rArrangeIndex ) @@ -593,8 +607,8 @@ void FloatingWindow::SetTitleType( sal_uInt16 nTitle ) nTitleStyle = BORDERWINDOW_TITLE_POPUP; else // nTitle == FLOATWIN_TITLE_NONE nTitleStyle = BORDERWINDOW_TITLE_NONE; - static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow)->SetTitleType( nTitleStyle, aOutSize ); - static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow)->GetBorder( mpWindowImpl->mnLeftBorder, mpWindowImpl->mnTopBorder, mpWindowImpl->mnRightBorder, mpWindowImpl->mnBottomBorder ); + static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->SetTitleType( nTitleStyle, aOutSize ); + static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->GetBorder( mpWindowImpl->mnLeftBorder, mpWindowImpl->mnTopBorder, mpWindowImpl->mnRightBorder, mpWindowImpl->mnBottomBorder ); } } @@ -734,7 +748,7 @@ void FloatingWindow::ImplEndPopupMode( sal_uInt16 nFlags, sal_uLong nFocusId ) mbInCleanUp = true; // prevent killing this window due to focus change while working with it // stop the PopupMode also for all following PopupMode windows - while ( pSVData->maWinData.mpFirstFloat && pSVData->maWinData.mpFirstFloat != this ) + while ( pSVData->maWinData.mpFirstFloat && pSVData->maWinData.mpFirstFloat.get() != this ) pSVData->maWinData.mpFirstFloat->EndPopupMode( FLOATWIN_POPUPMODEEND_CANCEL ); // delete window from the list diff --git a/vcl/source/window/introwin.cxx b/vcl/source/window/introwin.cxx index fa311d3129b5..d8b400135477 100644 --- a/vcl/source/window/introwin.cxx +++ b/vcl/source/window/introwin.cxx @@ -40,9 +40,16 @@ IntroWindow::IntroWindow( ) : IntroWindow::~IntroWindow() { + disposeOnce(); +} + +void IntroWindow::dispose() +{ ImplSVData* pSVData = ImplGetSVData(); - if ( pSVData->mpIntroWindow == this ) - pSVData->mpIntroWindow = NULL; + if ( pSVData->mpIntroWindow.get() == this ) + pSVData->mpIntroWindow = nullptr; + + WorkWindow::dispose(); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/window/layout.cxx b/vcl/source/window/layout.cxx index 2cc0a675b5dc..c9a43087cdf7 100644 --- a/vcl/source/window/layout.cxx +++ b/vcl/source/window/layout.cxx @@ -1286,6 +1286,17 @@ void VclBin::setAllocation(const Size &rAllocation) setLayoutAllocation(*pChild, Point(0, 0), rAllocation); } +VclFrame::~VclFrame() +{ + disposeOnce(); +} + +void VclFrame::dispose() +{ + m_pLabel.clear(); + VclBin::dispose(); +} + //To-Do, hook a DecorationView into VclFrame ? Size VclFrame::calculateRequisition() const @@ -1467,11 +1478,17 @@ bool VclAlignment::set_property(const OString &rKey, const OString &rValue) return true; } +void VclExpander::dispose() +{ + m_pDisclosureButton.disposeAndClear(); + VclBin::dispose(); +} + const vcl::Window *VclExpander::get_child() const { const WindowImpl* pWindowImpl = ImplGetWindowImpl(); - assert(pWindowImpl->mpFirstChild == m_pDisclosureButton.get()); + assert(pWindowImpl->mpFirstChild == m_pDisclosureButton); return pWindowImpl->mpFirstChild->GetWindow(WINDOW_NEXT); } @@ -1488,12 +1505,12 @@ Size VclExpander::calculateRequisition() const WindowImpl* pWindowImpl = ImplGetWindowImpl(); const vcl::Window *pChild = get_child(); - const vcl::Window *pLabel = pChild != pWindowImpl->mpLastChild ? pWindowImpl->mpLastChild : NULL; + const vcl::Window *pLabel = pChild != pWindowImpl->mpLastChild ? pWindowImpl->mpLastChild.get() : NULL; if (pChild && pChild->IsVisible() && m_pDisclosureButton->IsChecked()) aRet = getLayoutRequisition(*pChild); - Size aExpanderSize = getLayoutRequisition(*m_pDisclosureButton.get()); + Size aExpanderSize = getLayoutRequisition(*m_pDisclosureButton); if (pLabel && pLabel->IsVisible()) { @@ -1525,9 +1542,9 @@ void VclExpander::setAllocation(const Size &rAllocation) //The label widget is the last (of two) children vcl::Window *pChild = get_child(); - vcl::Window *pLabel = pChild != pWindowImpl->mpLastChild ? pWindowImpl->mpLastChild : NULL; + vcl::Window *pLabel = pChild != pWindowImpl->mpLastChild.get() ? pWindowImpl->mpLastChild.get() : NULL; - Size aButtonSize = getLayoutRequisition(*m_pDisclosureButton.get()); + Size aButtonSize = getLayoutRequisition(*m_pDisclosureButton); Size aLabelSize; Size aExpanderSize = aButtonSize; if (pLabel && pLabel->IsVisible()) @@ -1545,7 +1562,7 @@ void VclExpander::setAllocation(const Size &rAllocation) long nExtraExpanderHeight = aExpanderSize.Height() - aButtonSize.Height(); Point aButtonPos(aChildPos.X(), aChildPos.Y() + nExtraExpanderHeight/2); - setLayoutAllocation(*m_pDisclosureButton.get(), aButtonPos, aButtonSize); + setLayoutAllocation(*m_pDisclosureButton, aButtonPos, aButtonSize); if (pLabel && pLabel->IsVisible()) { @@ -1610,9 +1627,9 @@ IMPL_LINK( VclExpander, ClickHdl, DisclosureButton*, pBtn ) VclScrolledWindow::VclScrolledWindow(vcl::Window *pParent, WinBits nStyle) : VclBin(pParent, nStyle) , m_bUserManagedScrolling(false) - , m_pVScroll(new ScrollBar(this, WB_HIDE | WB_VERT)) - , m_pHScroll(new ScrollBar(this, WB_HIDE | WB_HORZ)) - , m_aScrollBarBox(this, WB_HIDE) + , m_pVScroll(VclPtr<ScrollBar>::Create(this, WB_HIDE | WB_VERT)) + , m_pHScroll(VclPtr<ScrollBar>::Create(this, WB_HIDE | WB_HORZ)) + , m_aScrollBarBox(VclPtr<ScrollBarBox>::Create(this, WB_HIDE)) { SetType(WINDOW_SCROLLWINDOW); @@ -1621,6 +1638,14 @@ VclScrolledWindow::VclScrolledWindow(vcl::Window *pParent, WinBits nStyle) m_pHScroll->SetScrollHdl(aLink); } +void VclScrolledWindow::dispose() +{ + m_pVScroll.disposeAndClear(); + m_pHScroll.disposeAndClear(); + m_aScrollBarBox.disposeAndClear(); + VclBin::dispose(); +} + IMPL_LINK_NOARG(VclScrolledWindow, ScrollBarHdl) { vcl::Window *pChild = get_child(); @@ -1672,10 +1697,10 @@ Size VclScrolledWindow::calculateRequisition() const aRet = getLayoutRequisition(*pChild); if (GetStyle() & WB_VSCROLL) - aRet.Width() += getLayoutRequisition(*m_pVScroll.get()).Width(); + aRet.Width() += getLayoutRequisition(*m_pVScroll).Width(); if (GetStyle() & WB_HSCROLL) - aRet.Height() += getLayoutRequisition(*m_pHScroll.get()).Height(); + aRet.Height() += getLayoutRequisition(*m_pHScroll).Height(); return aRet; } @@ -1721,7 +1746,7 @@ void VclScrolledWindow::setAllocation(const Size &rAllocation) } if (m_pVScroll->IsVisible()) - nAvailWidth -= getLayoutRequisition(*m_pVScroll.get()).Width(); + nAvailWidth -= getLayoutRequisition(*m_pVScroll).Width(); // horz. ScrollBar if (GetStyle() & WB_AUTOHSCROLL) @@ -1730,7 +1755,7 @@ void VclScrolledWindow::setAllocation(const Size &rAllocation) m_pHScroll->Show(bShowHScroll); if (bShowHScroll) - nAvailHeight -= getLayoutRequisition(*m_pHScroll.get()).Height(); + nAvailHeight -= getLayoutRequisition(*m_pHScroll).Height(); if (GetStyle() & WB_AUTOVSCROLL) m_pVScroll->Show(nAvailHeight < aChildReq.Height()); @@ -1741,10 +1766,10 @@ void VclScrolledWindow::setAllocation(const Size &rAllocation) if (m_pVScroll->IsVisible()) { - nScrollBarWidth = getLayoutRequisition(*m_pVScroll.get()).Width(); + nScrollBarWidth = getLayoutRequisition(*m_pVScroll).Width(); Point aScrollPos(rAllocation.Width() - nScrollBarWidth, 0); Size aScrollSize(nScrollBarWidth, rAllocation.Height()); - setLayoutAllocation(*m_pVScroll.get(), aScrollPos, aScrollSize); + setLayoutAllocation(*m_pVScroll, aScrollPos, aScrollSize); aChildAllocation.Width() -= nScrollBarWidth; aInnerSize.Width() -= nScrollBarWidth; aChildAllocation.Height() = aChildReq.Height(); @@ -1752,10 +1777,10 @@ void VclScrolledWindow::setAllocation(const Size &rAllocation) if (m_pHScroll->IsVisible()) { - nScrollBarHeight = getLayoutRequisition(*m_pHScroll.get()).Height(); + nScrollBarHeight = getLayoutRequisition(*m_pHScroll).Height(); Point aScrollPos(0, rAllocation.Height() - nScrollBarHeight); Size aScrollSize(rAllocation.Width(), nScrollBarHeight); - setLayoutAllocation(*m_pHScroll.get(), aScrollPos, aScrollSize); + setLayoutAllocation(*m_pHScroll, aScrollPos, aScrollSize); aChildAllocation.Height() -= nScrollBarHeight; aInnerSize.Height() -= nScrollBarHeight; aChildAllocation.Width() = aChildReq.Width(); @@ -1764,12 +1789,12 @@ void VclScrolledWindow::setAllocation(const Size &rAllocation) if (m_pVScroll->IsVisible() && m_pHScroll->IsVisible()) { Point aBoxPos(aInnerSize.Width(), aInnerSize.Height()); - m_aScrollBarBox.SetPosSizePixel(aBoxPos, Size(nScrollBarWidth, nScrollBarHeight)); - m_aScrollBarBox.Show(); + m_aScrollBarBox->SetPosSizePixel(aBoxPos, Size(nScrollBarWidth, nScrollBarHeight)); + m_aScrollBarBox->Show(); } else { - m_aScrollBarBox.Hide(); + m_aScrollBarBox->Hide(); } if (pChild && pChild->IsVisible()) @@ -1811,7 +1836,7 @@ bool VclScrolledWindow::Notify(NotifyEvent& rNEvt) const CommandWheelData* pData = rCEvt.GetWheelData(); if( !pData->GetModifier() && ( pData->GetMode() == CommandWheelMode::SCROLL ) ) { - nDone = HandleScrollCommand(rCEvt, m_pHScroll.get(), m_pVScroll.get()); + nDone = HandleScrollCommand(rCEvt, m_pHScroll, m_pVScroll); } } } @@ -1835,7 +1860,7 @@ const vcl::Window *VclEventBox::get_child() const { const WindowImpl* pWindowImpl = ImplGetWindowImpl(); - assert(pWindowImpl->mpFirstChild == &m_aEventBoxHelper); + assert(pWindowImpl->mpFirstChild.get() == m_aEventBoxHelper.get()); return pWindowImpl->mpFirstChild->GetWindow(WINDOW_NEXT); } @@ -1878,6 +1903,17 @@ void VclEventBox::Command(const CommandEvent&) //discard events by default to block them reaching children } +VclEventBox::~VclEventBox() +{ + disposeOnce(); +} + +void VclEventBox::dispose() +{ + m_aEventBoxHelper.disposeAndClear(); + VclBin::dispose(); +} + void VclSizeGroup::trigger_queue_resize() { //sufficient to trigger one widget to trigger all of them @@ -1939,10 +1975,10 @@ bool VclSizeGroup::set_property(const OString &rKey, const OString &rValue) void MessageDialog::create_owned_areas() { set_border_width(12); - m_pOwnedContentArea = new VclVBox(this, false, 24); + m_pOwnedContentArea.set(VclPtr<VclVBox>::Create(this, false, 24)); set_content_area(m_pOwnedContentArea); m_pOwnedContentArea->Show(); - m_pOwnedActionArea = new VclHButtonBox(m_pOwnedContentArea); + m_pOwnedActionArea.set( VclPtr<VclHButtonBox>::Create(m_pOwnedContentArea) ); set_action_area(m_pOwnedActionArea); m_pOwnedActionArea->Show(); } @@ -1992,16 +2028,24 @@ MessageDialog::MessageDialog(vcl::Window* pParent, const OString& rID, const OUS { } -MessageDialog::~MessageDialog() +void MessageDialog::dispose() { for (size_t i = 0; i < m_aOwnedButtons.size(); ++i) - delete m_aOwnedButtons[i]; - delete m_pSecondaryMessage; - delete m_pPrimaryMessage; - delete m_pImage; - delete m_pGrid; - delete m_pOwnedActionArea; - delete m_pOwnedContentArea; + m_aOwnedButtons[i].disposeAndClear(); + m_aOwnedButtons.clear(); + + m_pPrimaryMessage.disposeAndClear(); + m_pSecondaryMessage.disposeAndClear(); + m_pImage.disposeAndClear(); + m_pGrid.disposeAndClear(); + m_pOwnedActionArea.disposeAndClear(); + m_pOwnedContentArea.disposeAndClear(); + Dialog::dispose(); +} + +MessageDialog::~MessageDialog() +{ + disposeOnce(); } void MessageDialog::response(short nResponseId) @@ -2017,7 +2061,7 @@ IMPL_LINK(MessageDialog, ButtonHdl, Button *, pButton) short MessageDialog::get_response(const vcl::Window *pWindow) const { - std::map<const vcl::Window*, short>::const_iterator aFind = m_aResponses.find(pWindow); + auto aFind = m_aResponses.find(pWindow); if (aFind != m_aResponses.end()) return aFind->second; if (!m_pUIBuilder) @@ -2090,12 +2134,12 @@ short MessageDialog::Execute() VclContainer *pContainer = get_content_area(); assert(pContainer); - m_pGrid = new VclGrid(pContainer); + m_pGrid.set( VclPtr<VclGrid>::Create(pContainer) ); m_pGrid->reorderWithinParent(0); m_pGrid->set_column_spacing(12); m_pGrid->set_row_spacing(GetTextHeight()); - m_pImage = new FixedImage(m_pGrid, WB_CENTER | WB_VCENTER | WB_3DLOOK); + m_pImage = VclPtr<FixedImage>::Create(m_pGrid, WB_CENTER | WB_VCENTER | WB_3DLOOK); switch (m_eMessageType) { case VCL_MESSAGE_INFO: @@ -2120,7 +2164,7 @@ short MessageDialog::Execute() bool bHasSecondaryText = !m_sSecondaryString.isEmpty(); - m_pPrimaryMessage = new VclMultiLineEdit(m_pGrid, nWinStyle); + m_pPrimaryMessage = VclPtr<VclMultiLineEdit>::Create(m_pGrid, nWinStyle); m_pPrimaryMessage->SetPaintTransparent(true); m_pPrimaryMessage->EnableCursor(false); @@ -2130,7 +2174,7 @@ short MessageDialog::Execute() m_pPrimaryMessage->SetText(m_sPrimaryString); m_pPrimaryMessage->Show(!m_sPrimaryString.isEmpty()); - m_pSecondaryMessage = new VclMultiLineEdit(m_pGrid, nWinStyle); + m_pSecondaryMessage = VclPtr<VclMultiLineEdit>::Create(m_pGrid, nWinStyle); m_pSecondaryMessage->SetPaintTransparent(true); m_pSecondaryMessage->EnableCursor(false); m_pSecondaryMessage->set_grid_left_attach(1); @@ -2139,44 +2183,44 @@ short MessageDialog::Execute() m_pSecondaryMessage->SetText(m_sSecondaryString); m_pSecondaryMessage->Show(bHasSecondaryText); - MessageDialog::SetMessagesWidths(this, m_pPrimaryMessage, bHasSecondaryText ? m_pSecondaryMessage : NULL); + MessageDialog::SetMessagesWidths(this, m_pPrimaryMessage, bHasSecondaryText ? m_pSecondaryMessage.get() : NULL); VclButtonBox *pButtonBox = get_action_area(); assert(pButtonBox); - PushButton *pBtn; + VclPtr<PushButton> pBtn; switch (m_eButtonsType) { case VCL_BUTTONS_NONE: break; case VCL_BUTTONS_OK: - pBtn = new OKButton(pButtonBox); + pBtn.set( VclPtr<OKButton>::Create(pButtonBox) ); pBtn->SetStyle(pBtn->GetStyle() & WB_DEFBUTTON); pBtn->Show(); m_aOwnedButtons.push_back(pBtn); m_aResponses[pBtn] = RET_OK; break; case VCL_BUTTONS_CLOSE: - pBtn = new CloseButton(pButtonBox); + pBtn.set( VclPtr<CloseButton>::Create(pButtonBox) ); pBtn->SetStyle(pBtn->GetStyle() & WB_DEFBUTTON); pBtn->Show(); m_aOwnedButtons.push_back(pBtn); m_aResponses[pBtn] = RET_CLOSE; break; case VCL_BUTTONS_CANCEL: - pBtn = new CancelButton(pButtonBox); + pBtn.set( VclPtr<CancelButton>::Create(pButtonBox) ); pBtn->SetStyle(pBtn->GetStyle() & WB_DEFBUTTON); m_aOwnedButtons.push_back(pBtn); m_aResponses[pBtn] = RET_CANCEL; break; case VCL_BUTTONS_YES_NO: - pBtn = new PushButton(pButtonBox); + pBtn = VclPtr<PushButton>::Create(pButtonBox); pBtn->SetText(Button::GetStandardText(StandardButtonType::Yes)); pBtn->Show(); m_aOwnedButtons.push_back(pBtn); m_aResponses[pBtn] = RET_YES; - pBtn = new PushButton(pButtonBox); + pBtn.set( VclPtr<PushButton>::Create(pButtonBox) ); pBtn->SetStyle(pBtn->GetStyle() & WB_DEFBUTTON); pBtn->SetText(Button::GetStandardText(StandardButtonType::No)); pBtn->Show(); @@ -2184,12 +2228,12 @@ short MessageDialog::Execute() m_aResponses[pBtn] = RET_NO; break; case VCL_BUTTONS_OK_CANCEL: - pBtn = new OKButton(pButtonBox); + pBtn.set( VclPtr<OKButton>::Create(pButtonBox) ); pBtn->Show(); m_aOwnedButtons.push_back(pBtn); m_aResponses[pBtn] = RET_OK; - pBtn = new CancelButton(pButtonBox); + pBtn.set( VclPtr<CancelButton>::Create(pButtonBox) ); pBtn->SetStyle(pBtn->GetStyle() & WB_DEFBUTTON); pBtn->Show(); m_aOwnedButtons.push_back(pBtn); diff --git a/vcl/source/window/menu.cxx b/vcl/source/window/menu.cxx index 597e6627d1fb..e972321a7f53 100644 --- a/vcl/source/window/menu.cxx +++ b/vcl/source/window/menu.cxx @@ -133,16 +133,13 @@ Menu::Menu() Menu::~Menu() { - - vcl::LazyDeletor<Menu>::Undelete( this ); - ImplCallEventListeners( VCLEVENT_OBJECT_DYING, ITEMPOS_INVALID ); // at the window free the reference to the accessible component // and make sure the MenuFloatingWindow knows about our destruction if ( pWindow ) { - MenuFloatingWindow* pFloat = static_cast<MenuFloatingWindow*>(pWindow); + MenuFloatingWindow* pFloat = static_cast<MenuFloatingWindow*>(pWindow.get()); if( pFloat->pMenu == this ) pFloat->pMenu = NULL; pWindow->SetAccessible( ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >() ); @@ -1704,7 +1701,7 @@ Size Menu::ImplCalcSize( const vcl::Window* pWin ) // account for the size of the close button, which actually is a toolbox // due to NWF this is variable - long nCloseButtonHeight = static_cast<MenuBarWindow*>(pWindow)->MinCloseButtonSize().Height(); + long nCloseButtonHeight = static_cast<MenuBarWindow*>(pWindow.get())->MinCloseButtonSize().Height(); if (aSz.Height() < nCloseButtonHeight) aSz.Height() = nCloseButtonHeight; } @@ -2269,7 +2266,7 @@ void Menu::ImplFillLayoutData() const } else { - MenuFloatingWindow* pFloat = static_cast<MenuFloatingWindow*>(pWindow); + MenuFloatingWindow* pFloat = static_cast<MenuFloatingWindow*>(pWindow.get()); ImplPaint( pWindow, pFloat->nScrollerHeight, pFloat->ImplGetStartY(), 0, false, true ); } } @@ -2381,9 +2378,9 @@ bool Menu::IsHighlighted( sal_uInt16 nItemPos ) const if( pWindow ) { if (IsMenuBar()) - bRet = ( nItemPos == static_cast< MenuBarWindow * > (pWindow)->GetHighlightedItem() ); + bRet = ( nItemPos == static_cast< MenuBarWindow * > (pWindow.get())->GetHighlightedItem() ); else - bRet = ( nItemPos == static_cast< MenuFloatingWindow * > (pWindow)->GetHighlightedItem() ); + bRet = ( nItemPos == static_cast< MenuFloatingWindow * > (pWindow.get())->GetHighlightedItem() ); } return bRet; @@ -2395,13 +2392,13 @@ void Menu::HighlightItem( sal_uInt16 nItemPos ) { if (IsMenuBar()) { - MenuBarWindow* pMenuWin = static_cast< MenuBarWindow* >( pWindow ); + MenuBarWindow* pMenuWin = static_cast< MenuBarWindow* >( pWindow.get() ); pMenuWin->SetAutoPopup( false ); pMenuWin->ChangeHighlightItem( nItemPos, false ); } else { - static_cast< MenuFloatingWindow* >( pWindow )->ChangeHighlightItem( nItemPos, false ); + static_cast< MenuFloatingWindow* >( pWindow.get() )->ChangeHighlightItem( nItemPos, false ); } } } @@ -2411,7 +2408,7 @@ IMenuBarWindow* MenuBar::getMenuBarWindow() { // so far just a dynamic_cast, hopefully to be turned into something saner // at some stage - IMenuBarWindow *pWin = dynamic_cast<IMenuBarWindow*>(pWindow); + IMenuBarWindow *pWin = dynamic_cast<IMenuBarWindow*>(pWindow.get()); //either there is no window (fdo#87663) or it is an IMenuBarWindow assert(!pWindow || pWin); return pWin; @@ -2505,7 +2502,7 @@ vcl::Window* MenuBar::ImplCreate(vcl::Window* pParent, vcl::Window* pWindow, Men MenuBarWindow *pMenuBarWindow = dynamic_cast<MenuBarWindow*>(pWindow); if (!pMenuBarWindow) { - pWindow = pMenuBarWindow = new MenuBarWindow( pParent ); + pWindow = pMenuBarWindow = VclPtr<MenuBarWindow>::Create( pParent ); } pMenu->pStartedFrom = 0; @@ -2532,7 +2529,7 @@ void MenuBar::ImplDestroy( MenuBar* pMenu, bool bDelete ) IMenuBarWindow* pMenuWin = pMenu->getMenuBarWindow(); if (pMenuWin) pMenuWin->KillActivePopup(); - delete pWindow; + pWindow->disposeOnce(); } pMenu->pWindow = NULL; } @@ -2929,7 +2926,7 @@ sal_uInt16 PopupMenu::ImplExecute( vcl::Window* pW, const Rectangle& rRect, sal_ CreateAutoMnemonics(); } - MenuFloatingWindow* pWin = new MenuFloatingWindow( this, pW, nStyle | WB_SYSTEMWINDOW ); + VclPtrInstance<MenuFloatingWindow> pWin( this, pW, nStyle | WB_SYSTEMWINDOW ); if( pSVData->maNWFData.mbFlatMenu ) pWin->SetBorderStyle( WindowBorderStyle::NOBORDER ); else @@ -3009,9 +3006,9 @@ sal_uInt16 PopupMenu::ImplExecute( vcl::Window* pW, const Rectangle& rRect, sal_ { sal_uInt16 aPos; if (pSFrom->IsMenuBar()) - aPos = static_cast<MenuBarWindow *>(pSFrom->pWindow)->GetHighlightedItem(); + aPos = static_cast<MenuBarWindow *>(pSFrom->pWindow.get())->GetHighlightedItem(); else - aPos = static_cast<MenuFloatingWindow *>(pSFrom->pWindow)->GetHighlightedItem(); + aPos = static_cast<MenuFloatingWindow *>(pSFrom->pWindow.get())->GetHighlightedItem(); pWin->SetPosInParent( aPos ); // store position to be sent in SUBMENUDEACTIVATE pSFrom->ImplCallEventListeners( VCLEVENT_MENU_SUBMENUACTIVATE, aPos ); diff --git a/vcl/source/window/menubarwindow.cxx b/vcl/source/window/menubarwindow.cxx index 553baa472ecb..47f61ad6829d 100644 --- a/vcl/source/window/menubarwindow.cxx +++ b/vcl/source/window/menubarwindow.cxx @@ -60,7 +60,7 @@ void DecoToolBox::DataChanged( const DataChangedEvent& rDCEvt ) void DecoToolBox::calcMinSize() { - ToolBox aTbx( GetParent() ); + ScopedVclPtrInstance<ToolBox> aTbx( GetParent() ); if( GetItemCount() == 0 ) { ResMgr* pResMgr = ImplGetResMgr(); @@ -68,7 +68,7 @@ void DecoToolBox::calcMinSize() Bitmap aBitmap; if( pResMgr ) aBitmap = Bitmap( ResId( SV_RESID_BITMAP_CLOSEDOC, *pResMgr ) ); - aTbx.InsertItem( IID_DOCUMENTCLOSE, Image( aBitmap ) ); + aTbx->InsertItem( IID_DOCUMENTCLOSE, Image( aBitmap ) ); } else { @@ -76,11 +76,13 @@ void DecoToolBox::calcMinSize() for( sal_uInt16 i = 0; i < nItems; i++ ) { sal_uInt16 nId = GetItemId( i ); - aTbx.InsertItem( nId, GetItemImage( nId ) ); + aTbx->InsertItem( nId, GetItemImage( nId ) ); } } - aTbx.SetOutStyle( TOOLBOX_STYLE_FLAT ); - maMinSize = aTbx.CalcWindowSizePixel(); + aTbx->SetOutStyle( TOOLBOX_STYLE_FLAT ); + maMinSize = aTbx->CalcWindowSizePixel(); + + aTbx.disposeAndClear(); } void DecoToolBox::SetImages( long nMaxHeight, bool bForce ) @@ -117,9 +119,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(VclPtr<DecoToolBox>::Create(this)), + aFloatBtn(VclPtr<PushButton>::Create( this, WB_NOPOINTERFOCUS | WB_SMALLSTYLE | WB_RECTSTYLE )), + aHideBtn(VclPtr<PushButton>::Create(this, WB_NOPOINTERFOCUS | WB_SMALLSTYLE | WB_RECTSTYLE )) { SetType( WINDOW_MENUBARWINDOW ); pMenu = NULL; @@ -137,25 +139,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,8 +167,19 @@ MenuBarWindow::MenuBarWindow( vcl::Window* pParent ) : MenuBarWindow::~MenuBarWindow() { - aCloseBtn.RemoveEventListener(LINK(this, MenuBarWindow, ToolboxEventHdl)); + disposeOnce(); +} + +void MenuBarWindow::dispose() +{ + aCloseBtn->RemoveEventListener(LINK(this, MenuBarWindow, ToolboxEventHdl)); RemoveEventListener(LINK(this, MenuBarWindow, ShowHideListener)); + + aHideBtn.disposeAndClear(); + aFloatBtn.disposeAndClear(); + aCloseBtn.disposeAndClear(); + + Window::dispose(); } void MenuBarWindow::SetMenu( MenuBar* pMen ) @@ -177,10 +190,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 +214,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 +231,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 +240,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 +263,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() ) @@ -338,8 +351,8 @@ void MenuBarWindow::KillActivePopup() { if ( pActivePopup ) { - if( pActivePopup->pWindow != NULL ) - if( static_cast<FloatingWindow *>(pActivePopup->pWindow)->IsInCleanUp() ) + if( pActivePopup->pWindow ) + if( static_cast<FloatingWindow *>(pActivePopup->pWindow.get())->IsInCleanUp() ) return; // kill it later if ( pActivePopup->bInCallback ) @@ -446,7 +459,7 @@ void MenuBarWindow::ChangeHighlightItem( sal_uInt16 n, bool bSelectEntry, bool b if( !bStayActive ) { // #105406# avoid saving the focus when we already have the focus - bool bNoSaveFocus = (this == ImplGetSVData()->maWinData.mpFocusWin ); + bool bNoSaveFocus = (this == ImplGetSVData()->maWinData.mpFocusWin.get() ); if( nSaveFocusId ) { @@ -913,30 +926,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(); } @@ -1083,9 +1096,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 +1131,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 +1141,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..bb3c8be22073 100644 --- a/vcl/source/window/menubarwindow.hxx +++ b/vcl/source/window/menubarwindow.hxx @@ -39,7 +39,9 @@ class DecoToolBox : public ToolBox using Window::ImplInit; public: - DecoToolBox( vcl::Window* pParent, WinBits nStyle = 0 ); + DecoToolBox( vcl::Window* pParent, WinBits nStyle = 0 ); + virtual ~DecoToolBox() {} + void ImplInit(); void DataChanged( const DataChangedEvent& rDCEvt ) SAL_OVERRIDE; @@ -52,6 +54,7 @@ public: Image maImage; }; + /** 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; + VclPtr<DecoToolBox> aCloseBtn; + VclPtr<PushButton> aFloatBtn; + VclPtr<PushButton> 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 ); @@ -107,7 +110,8 @@ private: public: MenuBarWindow( vcl::Window* pParent ); - virtual ~MenuBarWindow(); + virtual ~MenuBarWindow(); + virtual void dispose() SAL_OVERRIDE; virtual void ShowButtons(bool bClose, bool bFloat, bool bHide) SAL_OVERRIDE; diff --git a/vcl/source/window/menufloatingwindow.cxx b/vcl/source/window/menufloatingwindow.cxx index 19e709d43423..227cc8bb5932 100644 --- a/vcl/source/window/menufloatingwindow.cxx +++ b/vcl/source/window/menufloatingwindow.cxx @@ -104,7 +104,14 @@ void MenuFloatingWindow::doShutdown() MenuFloatingWindow::~MenuFloatingWindow() { + disposeOnce(); +} + +void MenuFloatingWindow::dispose() +{ doShutdown(); + + FloatingWindow::dispose(); } void MenuFloatingWindow::Resize() @@ -406,8 +413,8 @@ void MenuFloatingWindow::KillActivePopup( PopupMenu* pThisOnly ) { if ( pActivePopup && ( !pThisOnly || ( pThisOnly == pActivePopup ) ) ) { - if( pActivePopup->pWindow != NULL ) - if( static_cast<FloatingWindow *>(pActivePopup->pWindow)->IsInCleanUp() ) + if( pActivePopup->pWindow ) + if( static_cast<FloatingWindow *>(pActivePopup->pWindow.get())->IsInCleanUp() ) return; // kill it later if ( pActivePopup->bInCallback ) pActivePopup->bCanceled = true; diff --git a/vcl/source/window/menufloatingwindow.hxx b/vcl/source/window/menufloatingwindow.hxx index 5e1b3437584d..3157be8d493f 100644 --- a/vcl/source/window/menufloatingwindow.hxx +++ b/vcl/source/window/menufloatingwindow.hxx @@ -80,7 +80,8 @@ protected: public: MenuFloatingWindow( Menu* pMenu, vcl::Window* pParent, WinBits nStyle ); - virtual ~MenuFloatingWindow(); + virtual ~MenuFloatingWindow(); + virtual void dispose() SAL_OVERRIDE; void doShutdown(); diff --git a/vcl/source/window/mouse.cxx b/vcl/source/window/mouse.cxx index bb7698a8428e..c4623a61fb72 100644 --- a/vcl/source/window/mouse.cxx +++ b/vcl/source/window/mouse.cxx @@ -198,7 +198,7 @@ static bool IsWindowFocused(const WindowImpl& rWinImpl) void Window::ImplGrabFocus( sal_uInt16 nFlags ) { // #143570# no focus for destructing windows - if( mpWindowImpl->mbInDtor ) + if( !mpWindowImpl || mpWindowImpl->mbInDispose ) return; // some event listeners do really bad stuff @@ -215,7 +215,7 @@ void Window::ImplGrabFocus( sal_uInt16 nFlags ) // For a lack of design we need a little hack here to // ensure that dialogs on close pass the focus back to // the correct window - if ( mpWindowImpl->mpLastFocusWindow && (mpWindowImpl->mpLastFocusWindow != this) && + if ( mpWindowImpl->mpLastFocusWindow && (mpWindowImpl->mpLastFocusWindow.get() != this) && !(mpWindowImpl->mnDlgCtrlFlags & WINDOW_DLGCTRL_WANTFOCUS) && mpWindowImpl->mpLastFocusWindow->IsEnabled() && mpWindowImpl->mpLastFocusWindow->IsInputEnabled() && @@ -231,7 +231,7 @@ void Window::ImplGrabFocus( sal_uInt16 nFlags ) // For a lack of design we need a little hack here to // ensure that dialogs on close pass the focus back to // the correct window - if ( mpWindowImpl->mpLastFocusWindow && (mpWindowImpl->mpLastFocusWindow != this) && + if ( mpWindowImpl->mpLastFocusWindow && (mpWindowImpl->mpLastFocusWindow.get() != this) && !(mpWindowImpl->mnDlgCtrlFlags & WINDOW_DLGCTRL_WANTFOCUS) && mpWindowImpl->mpLastFocusWindow->IsEnabled() && mpWindowImpl->mpLastFocusWindow->IsInputEnabled() && @@ -257,7 +257,7 @@ void Window::ImplGrabFocus( sal_uInt16 nFlags ) vcl::Window *pFrame = pSVData->maWinData.mpFirstFrame; while( pFrame ) { - if( pFrame != mpWindowImpl->mpFrameWindow && pFrame->mpWindowImpl->mpFrameData->mnFocusId ) + if( pFrame != mpWindowImpl->mpFrameWindow.get() && pFrame->mpWindowImpl->mpFrameData->mnFocusId ) { bAsyncFocusWaiting = true; break; @@ -283,11 +283,13 @@ void Window::ImplGrabFocus( sal_uInt16 nFlags ) pParent = pParent->mpWindowImpl->mpParent; } - if ( ( pSVData->maWinData.mpFocusWin != this && ! mpWindowImpl->mbInDtor ) || ( bAsyncFocusWaiting && !bHasFocus && !bMustNotGrabFocus ) ) + if ( ( pSVData->maWinData.mpFocusWin.get() != this && + mpWindowImpl && !mpWindowImpl->mbInDispose ) || + ( bAsyncFocusWaiting && !bHasFocus && !bMustNotGrabFocus ) ) { // EndExtTextInput if it is not the same window if ( pSVData->maWinData.mpExtTextInputWin && - (pSVData->maWinData.mpExtTextInputWin != this) ) + (pSVData->maWinData.mpExtTextInputWin.get() != this) ) pSVData->maWinData.mpExtTextInputWin->EndExtTextInput( EXTTEXTINPUT_END_COMPLETE ); // mark this windows as the last FocusWindow @@ -358,7 +360,7 @@ void Window::ImplGrabFocus( sal_uInt16 nFlags ) pOldFocusWindow->ImplCallDeactivateListeners( this ); } - if ( pSVData->maWinData.mpFocusWin == this ) + if ( pSVData->maWinData.mpFocusWin.get() == this ) { if ( mpWindowImpl->mpSysObj ) { @@ -367,7 +369,7 @@ void Window::ImplGrabFocus( sal_uInt16 nFlags ) mpWindowImpl->mpSysObj->GrabFocus(); } - if ( pSVData->maWinData.mpFocusWin == this ) + if ( pSVData->maWinData.mpFocusWin.get() == this ) { if ( mpWindowImpl->mpCursor ) mpWindowImpl->mpCursor->ImplShow(); @@ -450,13 +452,13 @@ void Window::CaptureMouse() ImplSVData* pSVData = ImplGetSVData(); // possibly stop tracking - if ( pSVData->maWinData.mpTrackWin != this ) + if ( pSVData->maWinData.mpTrackWin.get() != this ) { if ( pSVData->maWinData.mpTrackWin ) pSVData->maWinData.mpTrackWin->EndTracking( ENDTRACK_CANCEL ); } - if ( pSVData->maWinData.mpCaptureWin != this ) + if ( pSVData->maWinData.mpCaptureWin.get() != this ) { pSVData->maWinData.mpCaptureWin = this; mpWindowImpl->mpFrame->CaptureMouse( true ); @@ -468,10 +470,10 @@ void Window::ReleaseMouse() ImplSVData* pSVData = ImplGetSVData(); - DBG_ASSERTWARNING( pSVData->maWinData.mpCaptureWin == this, + DBG_ASSERTWARNING( pSVData->maWinData.mpCaptureWin.get() == this, "Window::ReleaseMouse(): window doesn't have the mouse capture" ); - if ( pSVData->maWinData.mpCaptureWin == this ) + if ( pSVData->maWinData.mpCaptureWin.get() == this ) { pSVData->maWinData.mpCaptureWin = NULL; mpWindowImpl->mpFrame->CaptureMouse( false ); @@ -657,6 +659,8 @@ void Window::ImplStartDnd() Reference< css::datatransfer::dnd::XDropTarget > Window::GetDropTarget() { + if( !mpWindowImpl ) + return Reference< css::datatransfer::dnd::XDropTarget >(); if( ! mpWindowImpl->mxDNDListenerContainer.is() ) { diff --git a/vcl/source/window/msgbox.cxx b/vcl/source/window/msgbox.cxx index 2c68157e759c..9f2fd75973c7 100644 --- a/vcl/source/window/msgbox.cxx +++ b/vcl/source/window/msgbox.cxx @@ -151,9 +151,15 @@ MessBox::MessBox( vcl::Window* pParent, WinBits nStyle, MessBox::~MessBox() { - delete mpVCLMultiLineEdit; - delete mpFixedImage; - delete mpCheckBox; + disposeOnce(); +} + +void MessBox::dispose() +{ + mpVCLMultiLineEdit.disposeAndClear(); + mpFixedImage.disposeAndClear(); + mpCheckBox.disposeAndClear(); + ButtonDialog::dispose(); } void MessBox::ImplPosControls() @@ -190,17 +196,12 @@ void MessBox::ImplPosControls() WinBits nWinStyle = WB_LEFT | WB_NOLABEL; sal_uInt16 nTextStyle = TEXT_DRAW_MULTILINE | TEXT_DRAW_TOP | TEXT_DRAW_LEFT; - delete mpVCLMultiLineEdit; - if ( mpFixedImage ) - { - delete mpFixedImage; - mpFixedImage = NULL; - } + mpVCLMultiLineEdit.disposeAndClear(); + mpFixedImage.disposeAndClear(); if ( mpCheckBox ) { mbCheck = mpCheckBox->IsChecked(); - delete mpCheckBox; - mpCheckBox = NULL; + mpCheckBox.disposeAndClear(); } // Clean up message text with tabs @@ -230,7 +231,7 @@ void MessBox::ImplPosControls() aImageSize.Width() += 4; aImageSize.Height() += 4; aTextPos.X() += aImageSize.Width()+IMPL_SEP_MSGBOX_IMAGE; - mpFixedImage = new FixedImage( this ); + mpFixedImage = VclPtr<FixedImage>::Create( this ); mpFixedImage->SetPosSizePixel( Point( IMPL_DIALOG_OFFSET-2+IMPL_MSGBOX_OFFSET_EXTRA_X, IMPL_DIALOG_OFFSET-2+IMPL_MSGBOX_OFFSET_EXTRA_Y ), aImageSize ); @@ -320,7 +321,7 @@ void MessBox::ImplPosControls() } } - mpCheckBox = new CheckBox( this ); + mpCheckBox = VclPtr<CheckBox>::Create( this ); mpCheckBox->Check( mbCheck ); mpCheckBox->SetText( aMnemonicString ); mpCheckBox->SetStyle( mpCheckBox->GetStyle() | WB_WORDBREAK ); @@ -342,7 +343,7 @@ void MessBox::ImplPosControls() mpCheckBox->Show(); } - mpVCLMultiLineEdit = new VclMultiLineEdit( this, nWinStyle ); + mpVCLMultiLineEdit = VclPtr<VclMultiLineEdit>::Create( this, nWinStyle ); mpVCLMultiLineEdit->SetText( aMessText ); mpVCLMultiLineEdit->SetPosSizePixel( aTextPos, aMEditSize ); mpVCLMultiLineEdit->Show(); diff --git a/vcl/source/window/openglwin.cxx b/vcl/source/window/openglwin.cxx index 741940f45e2d..21af6cc53598 100644 --- a/vcl/source/window/openglwin.cxx +++ b/vcl/source/window/openglwin.cxx @@ -16,22 +16,22 @@ class OpenGLWindowImpl { public: OpenGLWindowImpl(vcl::Window* pWindow); + ~OpenGLWindowImpl() { mxChildWindow.disposeAndClear(); } OpenGLContext& getContext() { return maContext;} private: OpenGLContext maContext; - std::unique_ptr<SystemChildWindow> mxChildWindow; + VclPtr<SystemChildWindow> mxChildWindow; }; OpenGLWindowImpl::OpenGLWindowImpl(vcl::Window* pWindow) { SystemWindowData aData = OpenGLContext::generateWinData(pWindow, false); - mxChildWindow.reset(new SystemChildWindow(pWindow, 0, &aData)); + mxChildWindow.reset(VclPtr<SystemChildWindow>::Create(pWindow, 0, &aData)); mxChildWindow->Show(); maContext.init(mxChildWindow.get()); pWindow->SetMouseTransparent(false); } - OpenGLWindow::OpenGLWindow(vcl::Window* pParent): Window(pParent, 0), mxImpl(new OpenGLWindowImpl(this)), @@ -41,8 +41,16 @@ OpenGLWindow::OpenGLWindow(vcl::Window* pParent): OpenGLWindow::~OpenGLWindow() { + disposeOnce(); +} + +void OpenGLWindow::dispose() +{ if(mpRenderer) mpRenderer->contextDestroyed(); + mpRenderer = NULL; + mxImpl.reset(); + Window::dispose(); } OpenGLContext& OpenGLWindow::getContext() diff --git a/vcl/source/window/paint.cxx b/vcl/source/window/paint.cxx index 1384dfe3d8f2..1dd9b3a50e98 100644 --- a/vcl/source/window/paint.cxx +++ b/vcl/source/window/paint.cxx @@ -43,7 +43,7 @@ class PaintHelper { private: - vcl::Window* m_pWindow; + VclPtr<vcl::Window> m_pWindow; vcl::Region* m_pChildRegion; Rectangle m_aSelectionRect; Rectangle m_aPaintRect; @@ -1094,7 +1094,7 @@ void Window::ImplPaintToDevice( OutputDevice* i_pTargetOutDev, const Point& i_rP mpWindowImpl->mbReallyVisible = bRVisible; // paint metafile to VDev - VirtualDevice* pMaskedDevice = new VirtualDevice( *i_pTargetOutDev, 0, 0 ); + VclPtrInstance<VirtualDevice> pMaskedDevice( *i_pTargetOutDev, 0, 0 ); pMaskedDevice->SetOutputSizePixel( GetOutputSizePixel() ); pMaskedDevice->EnableRTL( IsRTLEnabled() ); aMtf.WindStart(); @@ -1102,7 +1102,7 @@ void Window::ImplPaintToDevice( OutputDevice* i_pTargetOutDev, const Point& i_rP BitmapEx aBmpEx( pMaskedDevice->GetBitmapEx( Point( 0, 0 ), pMaskedDevice->GetOutputSizePixel() ) ); i_pTargetOutDev->DrawBitmapEx( i_rPos, aBmpEx ); // get rid of virtual device now so they don't pile up during recursive calls - delete pMaskedDevice, pMaskedDevice = NULL; + pMaskedDevice.disposeAndClear(); for( vcl::Window* pChild = mpWindowImpl->mpFirstChild; pChild; pChild = pChild->mpWindowImpl->mpNext ) { diff --git a/vcl/source/window/popupmenuwindow.cxx b/vcl/source/window/popupmenuwindow.cxx index 1a33ff9037ca..2d9c52699054 100644 --- a/vcl/source/window/popupmenuwindow.cxx +++ b/vcl/source/window/popupmenuwindow.cxx @@ -46,7 +46,13 @@ PopupMenuFloatingWindow::PopupMenuFloatingWindow( vcl::Window* pParent, WinBits PopupMenuFloatingWindow::~PopupMenuFloatingWindow() { + disposeOnce(); +} + +void PopupMenuFloatingWindow::dispose() +{ delete mpImplData; + FloatingWindow::dispose(); } sal_uInt16 PopupMenuFloatingWindow::GetMenuStackLevel() const diff --git a/vcl/source/window/printdlg.cxx b/vcl/source/window/printdlg.cxx index c4ea5c7aac3c..f24755d92904 100644 --- a/vcl/source/window/printdlg.cxx +++ b/vcl/source/window/printdlg.cxx @@ -64,24 +64,33 @@ extern "C" SAL_DLLPUBLIC_EXPORT vcl::Window* SAL_CALL makeShowNupOrderWindow(vcl PrintDialog::PrintPreviewWindow::PrintPreviewWindow( vcl::Window* i_pParent ) : Window( i_pParent, 0 ) , maOrigSize( 10, 10 ) - , maPageVDev( *this ) + , maPageVDev( VclPtr<VirtualDevice>::Create(*this) ) , maToolTipString(VclResId( SV_PRINT_PRINTPREVIEW_TXT).toString()) , mbGreyscale( false ) - , maHorzDim( this, WB_HORZ | WB_CENTER ) - , maVertDim( this, WB_VERT | WB_VCENTER ) + , maHorzDim(VclPtr<FixedLine>::Create(this, WB_HORZ | WB_CENTER)) + , maVertDim(VclPtr<FixedLine>::Create(this, WB_VERT | WB_VCENTER)) { SetPaintTransparent( true ); SetBackground(); - maPageVDev.SetBackground( Color( COL_WHITE ) ); - maHorzDim.Show(); - maVertDim.Show(); + maPageVDev->SetBackground( Color( COL_WHITE ) ); + 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() { + disposeOnce(); +} + +void PrintDialog::PrintPreviewWindow::dispose() +{ + maHorzDim.disposeAndClear(); + maVertDim.disposeAndClear(); + maPageVDev.disposeAndClear(); + Window::dispose(); } const sal_Int32 PrintDialog::PrintPreviewWindow::PREVIEW_BITMAP_WIDTH = 1600; @@ -91,7 +100,7 @@ void PrintDialog::PrintPreviewWindow::DataChanged( const DataChangedEvent& i_rDC // react on settings changed if( i_rDCEvt.GetType() == DataChangedEventType::SETTINGS ) { - maPageVDev.SetBackground( Color( COL_WHITE ) ); + maPageVDev->SetBackground( Color( COL_WHITE ) ); } Window::DataChanged( i_rDCEvt ); } @@ -99,7 +108,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; @@ -140,21 +149,21 @@ void PrintDialog::PrintPreviewWindow::Resize() aScaledSize.Width() = PREVIEW_BITMAP_WIDTH; aScaledSize.Height() = PREVIEW_BITMAP_WIDTH * aAspectRatio; - maPageVDev.SetOutputSizePixel( aScaledSize, false ); + maPageVDev->SetOutputSizePixel( aScaledSize, false ); // 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 ); @@ -218,8 +227,8 @@ void PrintDialog::PrintPreviewWindow::setPreview( const GDIMetaFile& i_rNewPrevi maOrigSize = i_rOrigSize; maReplacementString = i_rReplacement; mbGreyscale = i_bGreyscale; - maPageVDev.SetReferenceDevice( i_nDPIX, i_nDPIY ); - maPageVDev.EnableOutput( true ); + maPageVDev->SetReferenceDevice( i_nDPIX, i_nDPIY ); + maPageVDev->EnableOutput( true ); // use correct measurements const LocaleDataWrapper& rLocWrap( GetSettings().GetLocaleDataWrapper() ); @@ -241,13 +250,13 @@ 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(); @@ -258,8 +267,8 @@ void PrintDialog::PrintPreviewWindow::preparePreviewBitmap() { GDIMetaFile aMtf( maMtf ); - Size aVDevSize( maPageVDev.GetOutputSizePixel() ); - const Size aLogicSize( maPageVDev.PixelToLogic( aVDevSize, MapMode( MAP_100TH_MM ) ) ); + Size aVDevSize( maPageVDev->GetOutputSizePixel() ); + const Size aLogicSize( maPageVDev->PixelToLogic( aVDevSize, MapMode( MAP_100TH_MM ) ) ); Size aOrigSize( maOrigSize ); if( aOrigSize.Width() < 1 ) aOrigSize.Width() = aLogicSize.Width(); @@ -267,31 +276,31 @@ void PrintDialog::PrintPreviewWindow::preparePreviewBitmap() aOrigSize.Height() = aLogicSize.Height(); double fScale = double(aLogicSize.Width())/double(aOrigSize.Width()); - maPageVDev.Erase(); - maPageVDev.Push(); - maPageVDev.SetMapMode( MAP_100TH_MM ); - sal_uLong nOldDrawMode = maPageVDev.GetDrawMode(); + maPageVDev->Erase(); + maPageVDev->Push(); + maPageVDev->SetMapMode( MAP_100TH_MM ); + sal_uLong nOldDrawMode = maPageVDev->GetDrawMode(); if( mbGreyscale ) - maPageVDev.SetDrawMode( maPageVDev.GetDrawMode() | + maPageVDev->SetDrawMode( maPageVDev->GetDrawMode() | ( DRAWMODE_GRAYLINE | DRAWMODE_GRAYFILL | DRAWMODE_GRAYTEXT | DRAWMODE_GRAYBITMAP | DRAWMODE_GRAYGRADIENT ) ); aMtf.WindStart(); aMtf.Scale( fScale, fScale ); aMtf.WindStart(); - const sal_uInt16 nOriginalAA(maPageVDev.GetAntialiasing()); - maPageVDev.SetAntialiasing(nOriginalAA | ANTIALIASING_ENABLE_B2DDRAW); - aMtf.Play( &maPageVDev, Point( 0, 0 ), aLogicSize ); - maPageVDev.SetAntialiasing(nOriginalAA); + const sal_uInt16 nOriginalAA(maPageVDev->GetAntialiasing()); + maPageVDev->SetAntialiasing(nOriginalAA | ANTIALIASING_ENABLE_B2DDRAW); + aMtf.Play( maPageVDev.get(), Point( 0, 0 ), aLogicSize ); + maPageVDev->SetAntialiasing(nOriginalAA); - maPageVDev.Pop(); + maPageVDev->Pop(); SetMapMode( MAP_PIXEL ); - maPageVDev.SetMapMode( MAP_PIXEL ); + maPageVDev->SetMapMode( MAP_PIXEL ); - maPreviewBitmap = Bitmap(maPageVDev.GetBitmap(Point(0, 0), aVDevSize)); + maPreviewBitmap = Bitmap(maPageVDev->GetBitmap(Point(0, 0), aVDevSize)); - maPageVDev.SetDrawMode( nOldDrawMode ); + maPageVDev->SetDrawMode( nOldDrawMode ); } PrintDialog::ShowNupOrderWindow::ShowNupOrderWindow( vcl::Window* i_pParent ) @@ -303,10 +312,6 @@ PrintDialog::ShowNupOrderWindow::ShowNupOrderWindow( vcl::Window* i_pParent ) ImplInitSettings(); } -PrintDialog::ShowNupOrderWindow::~ShowNupOrderWindow() -{ -} - void PrintDialog::ShowNupOrderWindow::ImplInitSettings() { SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetFieldColor() ) ); @@ -619,13 +624,13 @@ PrintDialog::PrintDialog( vcl::Window* i_pParent, const std::shared_ptr<PrinterC if( maJobPage.mpPrinters->GetEntryPos( aValue ) != LISTBOX_ENTRY_NOTFOUND ) { maJobPage.mpPrinters->SelectEntry( aValue ); - maPController->setPrinter(std::make_shared<Printer>(aValue)); + maPController->setPrinter( VclPtrInstance<Printer>( aValue ) ); } else { // fall back to default printer maJobPage.mpPrinters->SelectEntry( Printer::GetDefaultPrinterName() ); - maPController->setPrinter(std::make_shared<Printer>(Printer::GetDefaultPrinterName())); + maPController->setPrinter( VclPtrInstance<Printer>( Printer::GetDefaultPrinterName() ) ); } } // not printing to file @@ -712,7 +717,22 @@ PrintDialog::PrintDialog( vcl::Window* i_pParent, const std::shared_ptr<PrinterC PrintDialog::~PrintDialog() { + disposeOnce(); +} + +void PrintDialog::dispose() +{ delete mpCustomOptionsUIBuilder; + mpTabCtrl.clear(); + mpPreviewWindow.clear(); + mpPageEdit.clear(); + mpNumPagesText.clear(); + mpBackwardBtn.clear(); + mpForwardBtn.clear(); + mpOKButton.clear(); + mpCancelButton.clear(); + mpHelpButton.clear(); + ModalDialog::dispose(); } void PrintDialog::readFromSettings() @@ -1207,7 +1227,7 @@ void PrintDialog::checkControlDependencies() void PrintDialog::checkOptionalControlDependencies() { - for( std::map< vcl::Window*, OUString >::iterator it = maControlToPropertyMap.begin(); + for( auto it = maControlToPropertyMap.begin(); it != maControlToPropertyMap.end(); ++it ) { bool bShouldbeEnabled = maPController->isUIOptionEnabled( it->second ); @@ -1229,9 +1249,9 @@ void PrintDialog::checkOptionalControlDependencies() } } - if( bShouldbeEnabled && dynamic_cast<RadioButton*>(it->first) ) + if( bShouldbeEnabled && dynamic_cast<RadioButton*>(it->first.get()) ) { - std::map< vcl::Window*, sal_Int32 >::const_iterator r_it = maControlToNumValMap.find( it->first ); + auto r_it = maControlToNumValMap.find( it->first ); if( r_it != maControlToNumValMap.end() ) { bShouldbeEnabled = maPController->isUIChoiceEnabled( it->second, r_it->second ); @@ -1308,7 +1328,7 @@ void PrintDialog::preparePreview( bool i_bNewPage, bool i_bMayUseCache ) { const MapMode aMapMode( MAP_100TH_MM ); GDIMetaFile aMtf; - std::shared_ptr<Printer> aPrt(maPController->getPrinter()); + VclPtr<Printer> aPrt( maPController->getPrinter() ); if( nPages > 0 ) { PrinterController::PageSize aPageSize = @@ -1501,7 +1521,7 @@ IMPL_LINK( PrintDialog, SelectHdl, ListBox*, pBox ) { OUString aNewPrinter( pBox->GetSelectEntry() ); // set new printer - maPController->setPrinter(std::make_shared<Printer>(aNewPrinter)); + maPController->setPrinter( VclPtrInstance<Printer>( aNewPrinter ) ); maPController->resetPrinterOptions( maOptionsPage.mpToFileBox->IsChecked() ); // update text fields updatePrinterText(); @@ -1650,7 +1670,7 @@ IMPL_LINK_NOARG(PrintDialog, UIOptionsChanged) PropertyValue* PrintDialog::getValueForWindow( vcl::Window* i_pWindow ) const { PropertyValue* pVal = NULL; - std::map< vcl::Window*, OUString >::const_iterator it = maControlToPropertyMap.find( i_pWindow ); + auto it = maControlToPropertyMap.find( i_pWindow ); if( it != maControlToPropertyMap.end() ) { pVal = maPController->getValue( it->second ); @@ -1666,10 +1686,10 @@ PropertyValue* PrintDialog::getValueForWindow( vcl::Window* i_pWindow ) const void PrintDialog::updateWindowFromProperty( const OUString& i_rProperty ) { beans::PropertyValue* pValue = maPController->getValue( i_rProperty ); - std::map< OUString, std::vector< vcl::Window* > >::const_iterator it = maPropertyToWindowMap.find( i_rProperty ); + auto it = maPropertyToWindowMap.find( i_rProperty ); if( pValue && it != maPropertyToWindowMap.end() ) { - const std::vector< vcl::Window* >& rWindows( it->second ); + const std::vector< VclPtr<vcl::Window> >& rWindows( it->second ); if( ! rWindows.empty() ) { bool bVal = false; @@ -1677,7 +1697,7 @@ void PrintDialog::updateWindowFromProperty( const OUString& i_rProperty ) if( pValue->Value >>= bVal ) { // we should have a CheckBox for this one - CheckBox* pBox = dynamic_cast< CheckBox* >( rWindows.front() ); + CheckBox* pBox = dynamic_cast< CheckBox* >( rWindows.front().get() ); if( pBox ) { pBox->Check( bVal ); @@ -1698,14 +1718,14 @@ void PrintDialog::updateWindowFromProperty( const OUString& i_rProperty ) else if( pValue->Value >>= nVal ) { // this could be a ListBox or a RadioButtonGroup - ListBox* pList = dynamic_cast< ListBox* >( rWindows.front() ); + ListBox* pList = dynamic_cast< ListBox* >( rWindows.front().get() ); if( pList ) { pList->SelectEntryPos( static_cast< sal_uInt16 >(nVal) ); } else if( nVal >= 0 && nVal < sal_Int32(rWindows.size() ) ) { - RadioButton* pBtn = dynamic_cast< RadioButton* >( rWindows[nVal] ); + RadioButton* pBtn = dynamic_cast< RadioButton* >( rWindows[nVal].get() ); DBG_ASSERT( pBtn, "unexpected control for property" ); if( pBtn ) pBtn->Check(); @@ -1717,7 +1737,7 @@ void PrintDialog::updateWindowFromProperty( const OUString& i_rProperty ) void PrintDialog::makeEnabled( vcl::Window* i_pWindow ) { - std::map< vcl::Window*, OUString >::const_iterator it = maControlToPropertyMap.find( i_pWindow ); + auto it = maControlToPropertyMap.find( i_pWindow ); if( it != maControlToPropertyMap.end() ) { OUString aDependency( maPController->makeEnabled( it->second ) ); @@ -1752,7 +1772,7 @@ IMPL_LINK( PrintDialog, UIOption_RadioHdl, RadioButton*, i_pBtn ) if( i_pBtn->IsChecked() ) { PropertyValue* pVal = getValueForWindow( i_pBtn ); - std::map< vcl::Window*, sal_Int32 >::const_iterator it = maControlToNumValMap.find( i_pBtn ); + auto it = maControlToNumValMap.find( i_pBtn ); if( pVal && it != maControlToNumValMap.end() ) { makeEnabled( i_pBtn ); @@ -1895,6 +1915,19 @@ PrintProgressDialog::PrintProgressDialog(vcl::Window* i_pParent, int i_nMax) } +PrintProgressDialog::~PrintProgressDialog() +{ + disposeOnce(); +} + +void PrintProgressDialog::dispose() +{ + mpText.clear(); + mpProgress.clear(); + mpButton.clear(); + ModelessDialog::dispose(); +} + IMPL_LINK( PrintProgressDialog, ClickHdl, Button*, pButton ) { if( pButton == mpButton ) diff --git a/vcl/source/window/scrwnd.cxx b/vcl/source/window/scrwnd.cxx index 7532ccf9cdc4..a40ef10dc592 100644 --- a/vcl/source/window/scrwnd.cxx +++ b/vcl/source/window/scrwnd.cxx @@ -84,8 +84,16 @@ ImplWheelWindow::ImplWheelWindow( vcl::Window* pParent ) : ImplWheelWindow::~ImplWheelWindow() { + disposeOnce(); +} + +void ImplWheelWindow::dispose() +{ ImplStop(); delete mpTimer; + mpTimer = NULL; + + FloatingWindow::dispose(); } void ImplWheelWindow::ImplStop() diff --git a/vcl/source/window/scrwnd.hxx b/vcl/source/window/scrwnd.hxx index ddd08f940cc9..6ec18c4e2b73 100644 --- a/vcl/source/window/scrwnd.hxx +++ b/vcl/source/window/scrwnd.hxx @@ -70,7 +70,8 @@ protected: public: ImplWheelWindow( vcl::Window* pParent ); - virtual ~ImplWheelWindow(); + virtual ~ImplWheelWindow(); + virtual void dispose() SAL_OVERRIDE; void ImplStop(); void ImplSetWheelMode( sal_uLong nWheelMode ); diff --git a/vcl/source/window/settings.cxx b/vcl/source/window/settings.cxx index 3e60bbd9bab0..63586e3ee70e 100644 --- a/vcl/source/window/settings.cxx +++ b/vcl/source/window/settings.cxx @@ -51,8 +51,8 @@ void Window::SetSettings( const AllSettings& rSettings, bool bChild ) { mpWindowImpl->mpBorderWindow->SetSettings( rSettings, false ); if ( (mpWindowImpl->mpBorderWindow->GetType() == WINDOW_BORDERWINDOW) && - static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow)->mpMenuBarWindow ) - static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow)->mpMenuBarWindow->SetSettings( rSettings, true ); + static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->mpMenuBarWindow ) + static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->mpMenuBarWindow->SetSettings( rSettings, true ); } AllSettings aOldSettings(*mxSettings); @@ -86,8 +86,8 @@ void Window::UpdateSettings( const AllSettings& rSettings, bool bChild ) { mpWindowImpl->mpBorderWindow->UpdateSettings( rSettings, false ); if ( (mpWindowImpl->mpBorderWindow->GetType() == WINDOW_BORDERWINDOW) && - static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow)->mpMenuBarWindow ) - static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow)->mpMenuBarWindow->UpdateSettings( rSettings, true ); + static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->mpMenuBarWindow ) + static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->mpMenuBarWindow->UpdateSettings( rSettings, true ); } AllSettings aOldSettings(*mxSettings); diff --git a/vcl/source/window/split.cxx b/vcl/source/window/split.cxx index 947dc986cf20..70482c02a039 100644 --- a/vcl/source/window/split.cxx +++ b/vcl/source/window/split.cxx @@ -151,8 +151,19 @@ Splitter::Splitter( vcl::Window* pParent, WinBits nStyle ) : Splitter::~Splitter() { - TaskPaneList *pTList = GetSystemWindow()->GetTaskPaneList(); - pTList->RemoveWindow( this ); + disposeOnce(); +} + +void Splitter::dispose() +{ + SystemWindow *pSysWin = GetSystemWindow(); + if(pSysWin) + { + TaskPaneList *pTList = pSysWin->GetTaskPaneList(); + pTList->RemoveWindow(this); + } + mpRefWin.clear(); + Window::dispose(); } void Splitter::SetHorizontal(bool bNew) diff --git a/vcl/source/window/splitwin.cxx b/vcl/source/window/splitwin.cxx index c18e1d06adca..293479151943 100644 --- a/vcl/source/window/splitwin.cxx +++ b/vcl/source/window/splitwin.cxx @@ -53,9 +53,9 @@ struct ImplSplitItem long mnOldWidth; long mnOldHeight; ImplSplitSet* mpSet; - vcl::Window* mpWindow; - vcl::Window* mpOrgParent; - sal_uInt16 mnId; + VclPtr<vcl::Window> mpWindow; + VclPtr<vcl::Window> mpOrgParent; + sal_uInt16 mnId; SplitWindowItemBits mnBits; bool mbFixed; bool mbSubSize; @@ -1347,9 +1347,16 @@ SplitWindow::SplitWindow( vcl::Window* pParent, WinBits nStyle ) : SplitWindow::~SplitWindow() { + disposeOnce(); +} + +void SplitWindow::dispose() +{ // delete Sets - ImplDeleteSet( mpMainSet ); + if (mpMainSet) + ImplDeleteSet( mpMainSet ); mpMainSet = NULL; //NULL for base-class callbacks during dtoring + DockingWindow::dispose(); } void SplitWindow::ImplSetWindowSize( long nDelta ) diff --git a/vcl/source/window/stacking.cxx b/vcl/source/window/stacking.cxx index f20c0ece86dd..ccf60ca60f5f 100644 --- a/vcl/source/window/stacking.cxx +++ b/vcl/source/window/stacking.cxx @@ -46,8 +46,8 @@ using ::com::sun::star::awt::XTopWindow; struct ImplCalcToTopData { - ImplCalcToTopData* mpNext; - vcl::Window* mpWindow; + ImplCalcToTopData* mpNext; + VclPtr<vcl::Window> mpWindow; vcl::Region* mpInvalidateRegion; }; @@ -117,12 +117,12 @@ void Window::ImplRemoveWindow( bool bRemoveFrameData ) { if ( ImplIsOverlapWindow() ) { - if ( mpWindowImpl->mpFrameData->mpFirstOverlap == this ) + if ( mpWindowImpl->mpFrameData->mpFirstOverlap.get() == this ) mpWindowImpl->mpFrameData->mpFirstOverlap = mpWindowImpl->mpNextOverlap; else { vcl::Window* pTempWin = mpWindowImpl->mpFrameData->mpFirstOverlap; - while ( pTempWin->mpWindowImpl->mpNextOverlap != this ) + while ( pTempWin->mpWindowImpl->mpNextOverlap.get() != this ) pTempWin = pTempWin->mpWindowImpl->mpNextOverlap; pTempWin->mpWindowImpl->mpNextOverlap = mpWindowImpl->mpNextOverlap; } @@ -194,7 +194,7 @@ void Window::reorderWithinParent(sal_uInt16 nNewPosition) void Window::ImplToBottomChild() { - if ( !ImplIsOverlapWindow() && !mpWindowImpl->mbReallyVisible && (mpWindowImpl->mpParent->mpWindowImpl->mpLastChild != this) ) + if ( !ImplIsOverlapWindow() && !mpWindowImpl->mbReallyVisible && (mpWindowImpl->mpParent->mpWindowImpl->mpLastChild.get() != this) ) { // put the window to the end of the list if ( mpWindowImpl->mpPrev ) @@ -265,7 +265,7 @@ void Window::ImplToTop( sal_uInt16 nFlags ) } else { - if ( mpWindowImpl->mpOverlapWindow->mpWindowImpl->mpFirstOverlap != this ) + if ( mpWindowImpl->mpOverlapWindow->mpWindowImpl->mpFirstOverlap.get() != this ) { // remove window from the list mpWindowImpl->mpPrev->mpWindowImpl->mpNext = mpWindowImpl->mpNext; @@ -477,7 +477,7 @@ void Window::SetZOrder( vcl::Window* pRefWindow, sal_uInt16 nFlags ) DBG_ASSERT( pRefWindow->mpWindowImpl->mpParent == mpWindowImpl->mpParent, "Window::SetZOrder() - pRefWindow has other parent" ); if ( nFlags & WINDOW_ZORDER_BEFOR ) { - if ( pRefWindow->mpWindowImpl->mpPrev == this ) + if ( pRefWindow->mpWindowImpl->mpPrev.get() == this ) return; if ( ImplIsOverlapWindow() ) @@ -515,7 +515,7 @@ void Window::SetZOrder( vcl::Window* pRefWindow, sal_uInt16 nFlags ) } else if ( nFlags & WINDOW_ZORDER_BEHIND ) { - if ( pRefWindow->mpWindowImpl->mpNext == this ) + if ( pRefWindow->mpWindowImpl->mpNext.get() == this ) return; if ( ImplIsOverlapWindow() ) @@ -632,7 +632,7 @@ void Window::EnableAlwaysOnTop( bool bEnable ) bool Window::IsTopWindow() const { - if ( mpWindowImpl->mbInDtor ) + if ( !mpWindowImpl || mpWindowImpl->mbInDispose ) return false; // topwindows must be frames or they must have a borderwindow which is a frame @@ -879,9 +879,8 @@ void Window::SetParent( vcl::Window* pNewParent ) // remove ownerdraw decorated windows from list in the top-most frame window if( (GetStyle() & WB_OWNERDRAWDECORATION) && mpWindowImpl->mbFrame ) { - ::std::vector< vcl::Window* >& rList = ImplGetOwnerDrawList(); - ::std::vector< vcl::Window* >::iterator p; - p = ::std::find( rList.begin(), rList.end(), this ); + ::std::vector< VclPtr<vcl::Window> >& rList = ImplGetOwnerDrawList(); + auto p = ::std::find( rList.begin(), rList.end(), VclPtr<vcl::Window>(this) ); if( p != rList.end() ) rList.erase( p ); } @@ -895,7 +894,7 @@ void Window::SetParent( vcl::Window* pNewParent ) return; } - if ( mpWindowImpl->mpParent == pNewParent ) + if ( mpWindowImpl->mpParent.get() == pNewParent ) return; if ( mpWindowImpl->mbFrame ) @@ -912,7 +911,7 @@ void Window::SetParent( vcl::Window* pNewParent ) else { pNewOverlapWindow = pNewParent->ImplGetFirstOverlapWindow(); - if ( mpWindowImpl->mpOverlapWindow != pNewOverlapWindow ) + if ( mpWindowImpl->mpOverlapWindow.get() != pNewOverlapWindow ) pOldOverlapWindow = mpWindowImpl->mpOverlapWindow; else pOldOverlapWindow = NULL; @@ -1023,6 +1022,8 @@ void Window::SetParent( vcl::Window* pNewParent ) sal_uInt16 Window::GetChildCount() const { + if (!mpWindowImpl) + return 0; sal_uInt16 nChildCount = 0; vcl::Window* pChild = mpWindowImpl->mpFirstChild; @@ -1037,6 +1038,8 @@ sal_uInt16 Window::GetChildCount() const vcl::Window* Window::GetChild( sal_uInt16 nChild ) const { + if (!mpWindowImpl) + return NULL; sal_uInt16 nChildCount = 0; vcl::Window* pChild = mpWindowImpl->mpFirstChild; @@ -1053,6 +1056,8 @@ vcl::Window* Window::GetChild( sal_uInt16 nChild ) const vcl::Window* Window::GetWindow( sal_uInt16 nType ) const { + if (!mpWindowImpl) + return 0; switch ( nType ) { @@ -1104,17 +1109,17 @@ vcl::Window* Window::GetWindow( sal_uInt16 nType ) const return const_cast<vcl::Window*>(this); case WINDOW_FIRSTTOPWINDOWCHILD: - return ImplGetWinData()->maTopWindowChildren.empty() ? NULL : *ImplGetWinData()->maTopWindowChildren.begin(); + return ImplGetWinData()->maTopWindowChildren.empty() ? NULL : (*ImplGetWinData()->maTopWindowChildren.begin()).get(); case WINDOW_LASTTOPWINDOWCHILD: - return ImplGetWinData()->maTopWindowChildren.empty() ? NULL : *ImplGetWinData()->maTopWindowChildren.rbegin(); + return ImplGetWinData()->maTopWindowChildren.empty() ? NULL : (*ImplGetWinData()->maTopWindowChildren.rbegin()).get(); case WINDOW_PREVTOPWINDOWSIBLING: { if ( !mpWindowImpl->mpRealParent ) return NULL; - const ::std::list< vcl::Window* >& rTopWindows( mpWindowImpl->mpRealParent->ImplGetWinData()->maTopWindowChildren ); - ::std::list< vcl::Window* >::const_iterator myPos = + const ::std::list< VclPtr<vcl::Window> >& rTopWindows( mpWindowImpl->mpRealParent->ImplGetWinData()->maTopWindowChildren ); + ::std::list< VclPtr<vcl::Window> >::const_iterator myPos = ::std::find( rTopWindows.begin(), rTopWindows.end(), this ); if ( myPos == rTopWindows.end() ) return NULL; @@ -1127,8 +1132,8 @@ vcl::Window* Window::GetWindow( sal_uInt16 nType ) const { if ( !mpWindowImpl->mpRealParent ) return NULL; - const ::std::list< vcl::Window* >& rTopWindows( mpWindowImpl->mpRealParent->ImplGetWinData()->maTopWindowChildren ); - ::std::list< vcl::Window* >::const_iterator myPos = + const ::std::list< VclPtr<vcl::Window> >& rTopWindows( mpWindowImpl->mpRealParent->ImplGetWinData()->maTopWindowChildren ); + ::std::list< VclPtr<vcl::Window> >::const_iterator myPos = ::std::find( rTopWindows.begin(), rTopWindows.end(), this ); if ( ( myPos == rTopWindows.end() ) || ( ++myPos == rTopWindows.end() ) ) return NULL; diff --git a/vcl/source/window/status.cxx b/vcl/source/window/status.cxx index bca642e23612..7f43c18e2b1a 100644 --- a/vcl/source/window/status.cxx +++ b/vcl/source/window/status.cxx @@ -45,7 +45,7 @@ public: ImplData(); ~ImplData(); - VirtualDevice* mpVirDev; + VclPtr<VirtualDevice> mpVirDev; long mnItemBorderWidth; bool mbDrawItemFrames:1; }; @@ -123,7 +123,7 @@ void StatusBar::ImplInit( vcl::Window* pParent, WinBits nStyle ) // remember WinBits mpItemList = new ImplStatusItemList; - mpImplData->mpVirDev = new VirtualDevice( *this ); + mpImplData->mpVirDev = VclPtr<VirtualDevice>::Create( *this ); mnCurItemId = 0; mbFormat = true; mbVisibleItems = true; @@ -151,6 +151,11 @@ StatusBar::StatusBar( vcl::Window* pParent, WinBits nStyle ) : StatusBar::~StatusBar() { + disposeOnce(); +} + +void StatusBar::dispose() +{ // delete all items for ( size_t i = 0, n = mpItemList->size(); i < n; ++i ) { delete (*mpItemList)[ i ]; @@ -158,8 +163,9 @@ StatusBar::~StatusBar() delete mpItemList; // delete VirtualDevice - delete mpImplData->mpVirDev; + mpImplData->mpVirDev.disposeAndClear(); delete mpImplData; + Window::dispose(); } void StatusBar::AdjustItemWidthsForHiDPI(bool bAdjustHiDPI) diff --git a/vcl/source/window/syschild.cxx b/vcl/source/window/syschild.cxx index f82e274d3c12..618170994105 100644 --- a/vcl/source/window/syschild.cxx +++ b/vcl/source/window/syschild.cxx @@ -133,12 +133,18 @@ SystemChildWindow::SystemChildWindow( vcl::Window* pParent, WinBits nStyle, Syst SystemChildWindow::~SystemChildWindow() { + disposeOnce(); +} + +void SystemChildWindow::dispose() +{ Hide(); - if ( mpWindowImpl->mpSysObj ) + if ( mpWindowImpl && mpWindowImpl->mpSysObj ) { ImplGetSVData()->mpDefInst->DestroyObject( mpWindowImpl->mpSysObj ); mpWindowImpl->mpSysObj = NULL; } + Window::dispose(); } const SystemEnvData* SystemChildWindow::GetSystemData() const diff --git a/vcl/source/window/syswin.cxx b/vcl/source/window/syswin.cxx index c5d0522dc0e1..99ac9bcb4fa4 100644 --- a/vcl/source/window/syswin.cxx +++ b/vcl/source/window/syswin.cxx @@ -106,12 +106,21 @@ void SystemWindow::loadUI(vcl::Window* pParent, const OString& rID, const OUStri SystemWindow::~SystemWindow() { + disposeOnce(); +} + +void SystemWindow::dispose() +{ maLayoutIdle.Stop(); delete mpImplData; mpImplData = NULL; + // Hack to make sure code called from base ~Window does not interpret this // as a SystemWindow (which it no longer is by then): mpWindowImpl->mbSysWin = false; + disposeBuilder(); + mpDialogParent.clear(); + Window::dispose(); } bool SystemWindow::Notify( NotifyEvent& rNEvt ) @@ -177,6 +186,8 @@ bool SystemWindow::PreNotify( NotifyEvent& rNEvt ) TaskPaneList* SystemWindow::GetTaskPaneList() { + if( !mpImplData ) + return NULL; if( mpImplData->mpTaskPaneList ) return mpImplData->mpTaskPaneList ; else @@ -306,7 +317,7 @@ void SystemWindow::ShowTitleButton( sal_uInt16 nButton, bool bVisible ) { mbDockBtn = bVisible; if ( mpWindowImpl->mpBorderWindow ) - static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow)->SetDockButton( bVisible ); + static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->SetDockButton( bVisible ); } } else if ( nButton == TITLE_BUTTON_HIDE ) @@ -315,13 +326,13 @@ void SystemWindow::ShowTitleButton( sal_uInt16 nButton, bool bVisible ) { mbHideBtn = bVisible; if ( mpWindowImpl->mpBorderWindow ) - static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow)->SetHideButton( bVisible ); + static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->SetHideButton( bVisible ); } } else if ( nButton == TITLE_BUTTON_MENU ) { if ( mpWindowImpl->mpBorderWindow ) - static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow)->SetMenuButton( bVisible ); + static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->SetMenuButton( bVisible ); } else return; @@ -341,7 +352,7 @@ void SystemWindow::SetPin( bool bPin ) { mbPinned = bPin; if ( mpWindowImpl->mpBorderWindow ) - static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow)->SetPin( bPin ); + static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->SetPin( bPin ); } } @@ -356,7 +367,7 @@ void SystemWindow::RollUp() aSize.Width() = GetOutputSizePixel().Width(); mbRollUp = true; if ( mpWindowImpl->mpBorderWindow ) - static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow)->SetRollUp( true, aSize ); + static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->SetRollUp( true, aSize ); else SetOutputSizePixel( aSize ); mbRollFunc = false; @@ -369,7 +380,7 @@ void SystemWindow::RollDown() { mbRollUp = false; if ( mpWindowImpl->mpBorderWindow ) - static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow)->SetRollUp( false, maOrgSize ); + static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->SetRollUp( false, maOrgSize ); else SetOutputSizePixel( maOrgSize ); } @@ -380,7 +391,7 @@ void SystemWindow::SetMinOutputSizePixel( const Size& rSize ) maMinOutSize = rSize; if ( mpWindowImpl->mpBorderWindow ) { - static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow)->SetMinOutputSize( rSize.Width(), rSize.Height() ); + static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->SetMinOutputSize( rSize.Width(), rSize.Height() ); if ( mpWindowImpl->mpBorderWindow->mpWindowImpl->mbFrame ) mpWindowImpl->mpBorderWindow->mpWindowImpl->mpFrame->SetMinClientSize( rSize.Width(), rSize.Height() ); } @@ -399,7 +410,7 @@ void SystemWindow::SetMaxOutputSizePixel( const Size& rSize ) mpImplData->maMaxOutSize = aSize; if ( mpWindowImpl->mpBorderWindow ) { - static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow)->SetMaxOutputSize( aSize.Width(), aSize.Height() ); + static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->SetMaxOutputSize( aSize.Width(), aSize.Height() ); if ( mpWindowImpl->mpBorderWindow->mpWindowImpl->mbFrame ) mpWindowImpl->mpBorderWindow->mpWindowImpl->mpFrame->SetMaxClientSize( aSize.Width(), aSize.Height() ); } @@ -905,11 +916,11 @@ void SystemWindow::SetMenuBar(MenuBar* pMenuBar, const css::uno::Reference<css:: if ( pMenuBar ) { DBG_ASSERT( !pMenuBar->pWindow, "SystemWindow::SetMenuBar() - MenuBars can only set in one SystemWindow at time" ); - static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow)->SetMenuBarWindow( pNewWindow = MenuBar::ImplCreate( mpWindowImpl->mpBorderWindow, pOldWindow, pMenuBar, rFrame)); + static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->SetMenuBarWindow( pNewWindow = MenuBar::ImplCreate( mpWindowImpl->mpBorderWindow, pOldWindow, pMenuBar, rFrame)); CallEventListeners( VCLEVENT_WINDOW_MENUBARADDED, (void*) pMenuBar ); } else - static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow)->SetMenuBarWindow( NULL ); + static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->SetMenuBarWindow( NULL ); ImplToBottomChild(); if ( pOldMenuBar ) { @@ -952,9 +963,9 @@ void SystemWindow::SetMenuBarMode( sal_uInt16 nMode ) if ( mpWindowImpl->mpBorderWindow && (mpWindowImpl->mpBorderWindow->GetType() == WINDOW_BORDERWINDOW) ) { if ( nMode == MENUBAR_MODE_HIDE ) - static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow)->SetMenuBarMode( true ); + static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->SetMenuBarMode( true ); else - static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow)->SetMenuBarMode( false ); + static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->SetMenuBarMode( false ); } } } diff --git a/vcl/source/window/tabdlg.cxx b/vcl/source/window/tabdlg.cxx index f15a2a03be49..e5c9061389e3 100644 --- a/vcl/source/window/tabdlg.cxx +++ b/vcl/source/window/tabdlg.cxx @@ -197,7 +197,7 @@ void TabDialog::ImplPosControls() { Size aDlgSize = GetOutputSizePixel(); if ( !mpFixedLine ) - mpFixedLine = new FixedLine( this ); + mpFixedLine = VclPtr<FixedLine>::Create( this ); mpFixedLine->SetPosSizePixel( Point( 0, nOffY ), Size( aDlgSize.Width(), 2 ) ); mpFixedLine->Show(); @@ -221,7 +221,14 @@ TabDialog::TabDialog( vcl::Window* pParent, const OUString& rID, const OUString& TabDialog::~TabDialog() { - delete mpFixedLine; + disposeOnce(); +} + +void TabDialog::dispose() +{ + mpFixedLine.disposeAndClear(); + mpViewWindow.clear(); + Dialog::dispose(); } void TabDialog::StateChanged( StateChangedType nType ) diff --git a/vcl/source/window/tabpage.cxx b/vcl/source/window/tabpage.cxx index d55496412e2b..964f96043d78 100644 --- a/vcl/source/window/tabpage.cxx +++ b/vcl/source/window/tabpage.cxx @@ -85,6 +85,17 @@ TabPage::TabPage(vcl::Window *pParent, const OString& rID, const OUString& rUIXM set_expand(true); } +TabPage::~TabPage() +{ + disposeOnce(); +} + +void TabPage::dispose() +{ + disposeBuilder(); + vcl::Window::dispose(); +} + void TabPage::StateChanged( StateChangedType nType ) { Window::StateChanged( nType ); diff --git a/vcl/source/window/taskpanelist.cxx b/vcl/source/window/taskpanelist.cxx index 2089172df14d..af4f617205ae 100644 --- a/vcl/source/window/taskpanelist.cxx +++ b/vcl/source/window/taskpanelist.cxx @@ -95,11 +95,8 @@ void TaskPaneList::AddWindow( vcl::Window *pWindow ) { if( pWindow ) { - ::std::vector< vcl::Window* >::iterator insertionPos = mTaskPanes.end(); - for ( ::std::vector< vcl::Window* >::iterator p = mTaskPanes.begin(); - p != mTaskPanes.end(); - ++p - ) + auto insertionPos = mTaskPanes.end(); + for ( auto p = mTaskPanes.begin(); p != mTaskPanes.end(); ++p ) { if ( *p == pWindow ) // avoid duplicates @@ -131,8 +128,7 @@ void TaskPaneList::AddWindow( vcl::Window *pWindow ) void TaskPaneList::RemoveWindow( vcl::Window *pWindow ) { - ::std::vector< vcl::Window* >::iterator p; - p = ::std::find( mTaskPanes.begin(), mTaskPanes.end(), pWindow ); + auto p = ::std::find( mTaskPanes.begin(), mTaskPanes.end(), VclPtr<vcl::Window>(pWindow) ); if( p != mTaskPanes.end() ) { mTaskPanes.erase( p ); @@ -142,8 +138,7 @@ void TaskPaneList::RemoveWindow( vcl::Window *pWindow ) bool TaskPaneList::IsInList( vcl::Window *pWindow ) { - ::std::vector< vcl::Window* >::iterator p; - p = ::std::find( mTaskPanes.begin(), mTaskPanes.end(), pWindow ); + auto p = ::std::find( mTaskPanes.begin(), mTaskPanes.end(), VclPtr<vcl::Window>(pWindow) ); if( p != mTaskPanes.end() ) return true; else @@ -172,7 +167,7 @@ bool TaskPaneList::HandleKeyEvent(const KeyEvent& rKeyEvent) bSplitterOnly = aKeyCode.IsMod1() && aKeyCode.IsShift(); // is the focus in the list ? - ::std::vector< vcl::Window* >::iterator p = mTaskPanes.begin(); + auto p = mTaskPanes.begin(); while( p != mTaskPanes.end() ) { vcl::Window *pWin = *p; @@ -245,7 +240,7 @@ vcl::Window* TaskPaneList::FindNextSplitter( vcl::Window *pWindow, bool bForward else ::std::stable_sort( mTaskPanes.begin(), mTaskPanes.end(), LTRSortBackward() ); - ::std::vector< vcl::Window* >::iterator p = mTaskPanes.begin(); + auto p = mTaskPanes.begin(); while( p != mTaskPanes.end() ) { if( !pWindow || *p == pWindow ) @@ -282,7 +277,7 @@ vcl::Window* TaskPaneList::FindNextFloat( vcl::Window *pWindow, bool bForward ) else ::std::stable_sort( mTaskPanes.begin(), mTaskPanes.end(), LTRSortBackward() ); - ::std::vector< vcl::Window* >::iterator p = mTaskPanes.begin(); + auto p = mTaskPanes.begin(); while( p != mTaskPanes.end() ) { if( !pWindow || *p == pWindow ) diff --git a/vcl/source/window/toolbox.cxx b/vcl/source/window/toolbox.cxx index 5b627939ef76..2369a7d25da5 100644 --- a/vcl/source/window/toolbox.cxx +++ b/vcl/source/window/toolbox.cxx @@ -84,13 +84,13 @@ static void ImplDrawButton( ToolBox* pThis, const Rectangle &rRect, sal_uInt16 highlight, bool bChecked, bool bEnabled, bool bIsWindow ); -typedef ::std::vector< ToolBox* > ImplTBList; +typedef ::std::vector< VclPtr<ToolBox> > ImplTBList; class ImplTBDragMgr { private: ImplTBList* mpBoxList; - ToolBox* mpDragBox; + VclPtr<ToolBox> mpDragBox; Point maMouseOff; Rectangle maRect; Rectangle maStartRect; @@ -1570,8 +1570,13 @@ ToolBox::ToolBox( vcl::Window* pParent, const ResId& rResId ) : ToolBox::~ToolBox() { + disposeOnce(); +} + +void ToolBox::dispose() +{ // custom menu event still running? - if( mpData->mnEventId ) + if( mpData && mpData->mnEventId ) Application::RemoveUserEvent( mpData->mnEventId ); // #103005# make sure our activate/deactivate balance is right @@ -1582,9 +1587,12 @@ ToolBox::~ToolBox() // still connected if ( mpFloatWin ) mpFloatWin->EndPopupMode( FLOATWIN_POPUPMODEEND_CANCEL ); + mpFloatWin = NULL; // delete private data - delete mpData; + if (mpData) + delete mpData; + mpData = NULL; // remove the lists when there are no more toolbox references to // the lists @@ -1601,10 +1609,15 @@ ToolBox::~ToolBox() pSVData->maCtrlData.mpTBDragMgr = NULL; } } + mpFloatWin.clear(); + DockingWindow::dispose(); } ImplToolItem* ToolBox::ImplGetItem( sal_uInt16 nItemId ) const { + if (!mpData) + return NULL; + std::vector< ImplToolItem >::iterator it = mpData->m_aItems.begin(); while ( it != mpData->m_aItems.end() ) { @@ -2630,7 +2643,7 @@ IMPL_LINK_NOARG(ToolBox, ImplDropdownLongClickHdl) // do not reset data if the dropdown handler opened a floating window // see ImplFloatControl() - if( mpFloatWin == NULL ) + if( !mpFloatWin ) { // no floater was opened Deactivate(); @@ -2651,7 +2664,7 @@ IMPL_LINK_NOARG(ToolBox, ImplDropdownLongClickHdl) IMPL_LINK_NOARG(ToolBox, ImplUpdateHdl) { - if( mbFormat ) + if( mbFormat && mpData ) ImplFormat(); return 0; @@ -2952,7 +2965,7 @@ void ToolBox::ImplDrawItem( sal_uInt16 nPos, sal_uInt16 nHighlight, bool bPaint, const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings(); // no gradient background for items that have a popup open - bool bHasOpenPopup = (mpFloatWin != NULL) && (mnDownItemId==pItem->mnId); + bool bHasOpenPopup = mpFloatWin && (mnDownItemId==pItem->mnId); bool bHighContrastWhite = false; // check the face color as highcontrast indicator @@ -3864,7 +3877,7 @@ void ToolBox::MouseButtonDown( const MouseEvent& rMEvt ) // do not reset data if the dropdown handler opened a floating window // see ImplFloatControl() - if( mpFloatWin == NULL ) + if( !mpFloatWin ) { // no floater was opened Deactivate(); @@ -4823,7 +4836,7 @@ Size ToolBox::CalcMinimumWindowSizePixel() const else { // create dummy toolbox for measurements - ToolBox *pToolBox = new ToolBox( GetParent(), GetStyle() ); + VclPtrInstance< ToolBox > pToolBox( GetParent(), GetStyle() ); // copy until first useful item std::vector< ImplToolItem >::iterator it = mpData->m_aItems.begin(); @@ -4851,7 +4864,8 @@ Size ToolBox::CalcMinimumWindowSizePixel() const ImplGetDockingManager()->RemoveWindow( pToolBox ); pToolBox->Clear(); - delete pToolBox; + + pToolBox.disposeAndClear(); return aSize; } diff --git a/vcl/source/window/toolbox2.cxx b/vcl/source/window/toolbox2.cxx index 80b2bf920075..481122834fc5 100644 --- a/vcl/source/window/toolbox2.cxx +++ b/vcl/source/window/toolbox2.cxx @@ -165,6 +165,7 @@ ImplToolItem::ImplToolItem( const ImplToolItem& rItem ) : ImplToolItem::~ImplToolItem() { + // don't dispose mpWindow - we get copied around. } ImplToolItem& ImplToolItem::operator=( const ImplToolItem& rItem ) @@ -866,7 +867,7 @@ void ToolBox::SetPageScroll( bool b ) sal_uInt16 ToolBox::GetItemCount() const { - return (sal_uInt16)mpData->m_aItems.size(); + return mpData ? (sal_uInt16)mpData->m_aItems.size() : 0; } ToolBoxItemType ToolBox::GetItemType( sal_uInt16 nPos ) const @@ -876,11 +877,13 @@ ToolBoxItemType ToolBox::GetItemType( sal_uInt16 nPos ) const sal_uInt16 ToolBox::GetItemPos( sal_uInt16 nItemId ) const { - int nCount = mpData->m_aItems.size(); - for( int nPos = 0; nPos < nCount; nPos++ ) - if( mpData->m_aItems[nPos].mnId == nItemId ) - return (sal_uInt16)nPos; - + if (mpData) + { + int nCount = mpData->m_aItems.size(); + for( int nPos = 0; nPos < nCount; nPos++ ) + if( mpData->m_aItems[nPos].mnId == nItemId ) + return (sal_uInt16)nPos; + } return TOOLBOX_ITEM_NOTFOUND; } @@ -934,6 +937,9 @@ sal_uInt16 ToolBox::GetItemId( const Point& rPos ) const sal_uInt16 ToolBox::GetItemId(const OUString &rCommand) const { + if (!mpData) + return TOOLBOX_ITEM_NOTFOUND; + for (std::vector<ImplToolItem>::const_iterator it = mpData->m_aItems.begin(); it != mpData->m_aItems.end(); ++it) { if (it->maCommandStr == rCommand) diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx index 4a898eeac6b9..f991b98b6fe5 100644 --- a/vcl/source/window/window.cxx +++ b/vcl/source/window/window.cxx @@ -33,6 +33,7 @@ #include <vcl/syschild.hxx> #include <vcl/dockwin.hxx> #include <vcl/wall.hxx> +#include <vcl/fixed.hxx> #include <vcl/gradient.hxx> #include <vcl/button.hxx> #include <vcl/taskpanelist.hxx> @@ -131,13 +132,18 @@ namespace } #endif -Window::~Window() +bool Window::IsDisposed() const { - vcl::LazyDeletor<vcl::Window>::Undelete( this ); - - DBG_ASSERT( !mpWindowImpl->mbInDtor, "~Window - already in DTOR!" ); + return !mpWindowImpl; +} - dispose(); +void Window::dispose() +{ + assert( mpWindowImpl ); + assert( !mpWindowImpl->mbInDispose ); // should only be called from disposeOnce() + assert( !mpWindowImpl->mpParent || + !mpWindowImpl->mpParent->IsDisposed() || + "vcl::Window child should have its parent disposed first" ); // remove Key and Mouse events issued by Application::PostKey/MouseEvent Application::RemoveMouseAndKeyEvents( this ); @@ -152,7 +158,7 @@ Window::~Window() xCanvasComponent->dispose(); } - mpWindowImpl->mbInDtor = true; + mpWindowImpl->mbInDispose = true; CallEventListeners( VCLEVENT_OBJECT_DYING ); @@ -167,9 +173,8 @@ Window::~Window() // remove ownerdraw decorated windows from list in the top-most frame window if( (GetStyle() & WB_OWNERDRAWDECORATION) && mpWindowImpl->mbFrame ) { - ::std::vector< vcl::Window* >& rList = ImplGetOwnerDrawList(); - ::std::vector< vcl::Window* >::iterator p; - p = ::std::find( rList.begin(), rList.end(), this ); + ::std::vector< VclPtr<vcl::Window> >& rList = ImplGetOwnerDrawList(); + auto p = ::std::find( rList.begin(), rList.end(), VclPtr<vcl::Window>(this) ); if( p != rList.end() ) rList.erase( p ); } @@ -232,9 +237,9 @@ Window::~Window() if ( pSVData->maHelpData.mpHelpWin && (pSVData->maHelpData.mpHelpWin->GetParent() == this) ) ImplDestroyHelpWindow( true ); - DBG_ASSERT( pSVData->maWinData.mpTrackWin != this, + DBG_ASSERT( pSVData->maWinData.mpTrackWin.get() != this, "Window::~Window(): Window is in TrackingMode" ); - DBG_ASSERT( pSVData->maWinData.mpCaptureWin != this, + DBG_ASSERT( pSVData->maWinData.mpCaptureWin.get() != this, "Window::~Window(): Window has the mouse captured" ); // due to old compatibility @@ -251,6 +256,22 @@ Window::~Window() OStringBuffer aErrorStr; bool bError = false; vcl::Window* pTempWin; + + if ( mpWindowImpl->mpFirstChild ) + { + OStringBuffer aTempStr("Window ("); + aTempStr.append(lcl_createWindowInfo(*this)); + aTempStr.append(") with live children destroyed: "); + pTempWin = mpWindowImpl->mpFirstChild; + while ( pTempWin ) + { + aTempStr.append(lcl_createWindowInfo(*pTempWin)); + pTempWin = pTempWin->mpWindowImpl->mpNext; + } + OSL_FAIL( aTempStr.getStr() ); + Application::Abort(OStringToOUString(aTempStr.makeStringAndClear(), RTL_TEXTENCODING_UTF8)); // abort in debug builds, this must be fixed! + } + if (mpWindowImpl->mpFrameData != 0) { pTempWin = mpWindowImpl->mpFrameData->mpFirstOverlap; @@ -267,8 +288,7 @@ Window::~Window() { OStringBuffer aTempStr; aTempStr.append("Window ("); - aTempStr.append(OUStringToOString(GetText(), - RTL_TEXTENCODING_UTF8)); + aTempStr.append(lcl_createWindowInfo(*this)); aTempStr.append(") with live SystemWindows destroyed: "); aTempStr.append(aErrorStr.toString()); OSL_FAIL(aTempStr.getStr()); @@ -292,32 +312,17 @@ Window::~Window() if ( bError ) { OStringBuffer aTempStr( "Window (" ); - aTempStr.append(OUStringToOString(GetText(), RTL_TEXTENCODING_UTF8)); + aTempStr.append(lcl_createWindowInfo(*this)); aTempStr.append(") with live SystemWindows destroyed: "); aTempStr.append(aErrorStr.toString()); OSL_FAIL( aTempStr.getStr() ); Application::Abort(OStringToOUString(aTempStr.makeStringAndClear(), RTL_TEXTENCODING_UTF8)); // abort in debug builds, this must be fixed! } - if ( mpWindowImpl->mpFirstChild ) - { - OStringBuffer aTempStr("Window ("); - aTempStr.append(OUStringToOString(GetText(), RTL_TEXTENCODING_UTF8)); - aTempStr.append(") with live children destroyed: "); - pTempWin = mpWindowImpl->mpFirstChild; - while ( pTempWin ) - { - aTempStr.append(lcl_createWindowInfo(*pTempWin)); - pTempWin = pTempWin->mpWindowImpl->mpNext; - } - OSL_FAIL( aTempStr.getStr() ); - Application::Abort(OStringToOUString(aTempStr.makeStringAndClear(), RTL_TEXTENCODING_UTF8)); // abort in debug builds, this must be fixed! - } - if ( mpWindowImpl->mpFirstOverlap ) { OStringBuffer aTempStr("Window ("); - aTempStr.append(OUStringToOString(GetText(), RTL_TEXTENCODING_UTF8)); + aTempStr.append(lcl_createWindowInfo(*this)); aTempStr.append(") with live SystemWindows destroyed: "); pTempWin = mpWindowImpl->mpFirstOverlap; while ( pTempWin ) @@ -343,7 +348,7 @@ Window::~Window() if ( pMySysWin && pMySysWin->ImplIsInTaskPaneList( this ) ) { OStringBuffer aTempStr("Window ("); - aTempStr.append(OUStringToOString(GetText(), RTL_TEXTENCODING_UTF8)); + aTempStr.append(lcl_createWindowInfo(*this)); aTempStr.append(") still in TaskPanelList!"); OSL_FAIL( aTempStr.getStr() ); Application::Abort(OStringToOUString(aTempStr.makeStringAndClear(), RTL_TEXTENCODING_UTF8)); // abort in debug builds, this must be fixed! @@ -381,9 +386,8 @@ Window::~Window() remove_from_all_size_groups(); // clear mnemonic labels - std::vector<FixedText*> aMnemonicLabels(list_mnemonic_labels()); - for (std::vector<FixedText*>::iterator aI = aMnemonicLabels.begin(); - aI != aMnemonicLabels.end(); ++aI) + std::vector<VclPtr<FixedText> > aMnemonicLabels(list_mnemonic_labels()); + for (auto aI = aMnemonicLabels.begin(); aI != aMnemonicLabels.end(); ++aI) { remove_mnemonic_label(*aI); } @@ -499,7 +503,7 @@ Window::~Window() while ( pDelData ) { pDelData->mbDel = true; - pDelData->mpWindow = NULL; // #112873# pDel is not associated with a Window anymore + pDelData->mpWindow.clear(); // #112873# pDel is not associated with a Window anymore pDelData = pDelData->mpNext; } @@ -514,8 +518,8 @@ Window::~Window() { ImplWinData* pParentWinData = mpWindowImpl->mpRealParent->ImplGetWinData(); - ::std::list< vcl::Window* >::iterator myPos = ::std::find( pParentWinData->maTopWindowChildren.begin(), - pParentWinData->maTopWindowChildren.end(), this ); + auto myPos = ::std::find( pParentWinData->maTopWindowChildren.begin(), + pParentWinData->maTopWindowChildren.end(), VclPtr<vcl::Window>(this) ); DBG_ASSERT( myPos != pParentWinData->maTopWindowChildren.end(), "Window::~Window: inconsistency in top window chain!" ); if ( myPos != pParentWinData->maTopWindowChildren.end() ) pParentWinData->maTopWindowChildren.erase( myPos ); @@ -546,17 +550,18 @@ Window::~Window() delete mpWindowImpl->mpOverlapData; // remove BorderWindow or Frame window data - if ( mpWindowImpl->mpBorderWindow ) - delete mpWindowImpl->mpBorderWindow; - else if ( mpWindowImpl->mbFrame ) + mpWindowImpl->mpBorderWindow.disposeAndClear(); + if ( mpWindowImpl->mbFrame ) { if ( pSVData->maWinData.mpFirstFrame == this ) pSVData->maWinData.mpFirstFrame = mpWindowImpl->mpFrameData->mpNextFrame; else { vcl::Window* pSysWin = pSVData->maWinData.mpFirstFrame; - while ( pSysWin->mpWindowImpl->mpFrameData->mpNextFrame != this ) + while ( pSysWin->mpWindowImpl->mpFrameData->mpNextFrame.get() != this ) pSysWin = pSysWin->mpWindowImpl->mpFrameData->mpNextFrame; + + assert (mpWindowImpl->mpFrameData->mpNextFrame.get() != pSysWin); pSysWin->mpWindowImpl->mpFrameData->mpNextFrame = mpWindowImpl->mpFrameData->mpNextFrame; } mpWindowImpl->mpFrame->SetCallback( NULL, NULL ); @@ -566,6 +571,31 @@ Window::~Window() // should be the last statements delete mpWindowImpl; mpWindowImpl = NULL; + + OutputDevice::dispose(); +} + +Window::~Window() +{ + // FIXME: we should kill all LazyDeletor usage. + vcl::LazyDeletor<vcl::Window>::Undelete( this ); + disposeOnce(); +} + +// We will eventually being removing the inheritance of OutputDevice +// from Window. It will be replaced with a transient relationship such +// that the OutputDevice is only live for the scope of the Paint method. +// In the meantime this can help move us towards a Window use an +// OutputDevice, not being one. + +::OutputDevice const* Window::GetOutDev() const +{ + return this; +} + +::OutputDevice* Window::GetOutDev() +{ + return this; } } /* namespace vcl */ @@ -584,8 +614,8 @@ WindowImpl::WindowImpl( WindowType nType ) mpOverlapWindow = NULL; // first overlap parent mpBorderWindow = NULL; // Border-Window mpClientWindow = NULL; // Client-Window of a FrameWindow - mpParent = NULL; // parent (inkl. BorderWindow) - mpRealParent = NULL; // real parent (exkl. BorderWindow) + mpParent = NULL; // parent (incl. BorderWindow) + mpRealParent = NULL; // real parent (excl. BorderWindow) mpFirstChild = NULL; // first child window mpLastChild = NULL; // last child window mpFirstOverlap = NULL; // first overlap window (only set in overlap windows) @@ -704,7 +734,7 @@ WindowImpl::WindowImpl( WindowType nType ) mbCompoundControlHasFocus = false; // true: Composite Control has focus somewhere mbPaintDisabled = false; // true: Paint should not be executed mbAllResize = false; // true: Also sent ResizeEvents with 0,0 - mbInDtor = false; // true: We're still in Window-Dtor + mbInDispose = false; // true: We're still in Window::dispose() mbExtTextInput = false; // true: ExtTextInput-Mode is active mbInFocusHdl = false; // true: Within GetFocus-Handler mbCreatedWithToolkit = false; @@ -876,7 +906,7 @@ void Window::ImplInit( vcl::Window* pParent, WinBits nStyle, SystemParentData* p nBorderTypeStyle |= BORDERWINDOW_STYLE_FRAME; nStyle |= WB_BORDER; } - ImplBorderWindow* pBorderWin = new ImplBorderWindow( pParent, nStyle & (WB_BORDER | WB_DIALOGCONTROL | WB_NODIALOGCONTROL | WB_NEEDSFOCUS), nBorderTypeStyle ); + VclPtrInstance<ImplBorderWindow> pBorderWin( pParent, nStyle & (WB_BORDER | WB_DIALOGCONTROL | WB_NODIALOGCONTROL | WB_NEEDSFOCUS), nBorderTypeStyle ); ((vcl::Window*)pBorderWin)->mpWindowImpl->mpClientWindow = this; pBorderWin->GetBorder( mpWindowImpl->mnLeftBorder, mpWindowImpl->mnTopBorder, mpWindowImpl->mnRightBorder, mpWindowImpl->mnBottomBorder ); mpWindowImpl->mpBorderWindow = pBorderWin; @@ -989,6 +1019,7 @@ void Window::ImplInit( vcl::Window* pParent, WinBits nStyle, SystemParentData* p mpWindowImpl->mpOverlapWindow = this; // set frame data + assert (pSVData->maWinData.mpFirstFrame.get() != this); mpWindowImpl->mpFrameData->mpNextFrame = pSVData->maWinData.mpFirstFrame; pSVData->maWinData.mpFirstFrame = this; mpWindowImpl->mpFrameData->mpFirstOverlap = NULL; @@ -1181,13 +1212,6 @@ void Window::ImplInitAppFontData( vcl::Window* pWindow ) void Window::ImplInitWindowData( WindowType nType ) { - // We will eventually being removing the inheritance of OutputDevice from Window. - // It will be replaced with a composition relationship. A Window will use an OutputDevice, - // it will not *be* an OutputDevice - mpOutputDevice = (OutputDevice*)this; - - mnRefCnt = 0; - mpWindowImpl = new WindowImpl( nType ); meOutDevType = OUTDEV_WINDOW; @@ -1352,6 +1376,12 @@ void Window::ImplSetReallyVisible() void Window::ImplAddDel( ImplDelData* pDel ) // TODO: make "const" when incompatibility ok { + if ( IsDisposed() ) + { + pDel->mbDel = true; + return; + } + DBG_ASSERT( !pDel->mpWindow, "Window::ImplAddDel(): cannot add ImplDelData twice !" ); if( !pDel->mpWindow ) { @@ -1364,6 +1394,10 @@ void Window::ImplAddDel( ImplDelData* pDel ) // TODO: make "const" when incompat void Window::ImplRemoveDel( ImplDelData* pDel ) // TODO: make "const" when incompatibility ok { pDel->mpWindow = NULL; // #112873# pDel is not associated with a Window anymore + + if ( IsDisposed() ) + return; + if ( mpWindowImpl->mpFirstDel == pDel ) mpWindowImpl->mpFirstDel = pDel->mpNext; else @@ -2074,7 +2108,7 @@ void Window::SetBorderStyle( WindowBorderStyle nBorderStyle ) // this is a little awkward: some controls (e.g. svtools ProgressBar) // cannot avoid getting constructed with WB_BORDER but want to disable // borders in case of NWF drawing. So they need a method to remove their border window - vcl::Window* pBorderWin = mpWindowImpl->mpBorderWindow; + VclPtr<vcl::Window> pBorderWin = mpWindowImpl->mpBorderWindow; // remove us as border window's client pBorderWin->mpWindowImpl->mpClientWindow = NULL; mpWindowImpl->mpBorderWindow = NULL; @@ -2086,7 +2120,7 @@ void Window::SetBorderStyle( WindowBorderStyle nBorderStyle ) Size aBorderSize( pBorderWin->GetSizePixel() ); setPosSizePixel( aBorderPos.X(), aBorderPos.Y(), aBorderSize.Width(), aBorderSize.Height() ); // release border window - delete pBorderWin; + pBorderWin.disposeAndClear(); // set new style bits SetStyle( GetStyle() & (~WB_BORDER) ); @@ -2094,7 +2128,7 @@ void Window::SetBorderStyle( WindowBorderStyle nBorderStyle ) else { if ( mpWindowImpl->mpBorderWindow->GetType() == WINDOW_BORDERWINDOW ) - static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow)->SetBorderStyle( nBorderStyle ); + static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->SetBorderStyle( nBorderStyle ); else mpWindowImpl->mpBorderWindow->SetBorderStyle( nBorderStyle ); } @@ -2107,7 +2141,7 @@ WindowBorderStyle Window::GetBorderStyle() const if ( mpWindowImpl->mpBorderWindow ) { if ( mpWindowImpl->mpBorderWindow->GetType() == WINDOW_BORDERWINDOW ) - return static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow)->GetBorderStyle(); + return static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->GetBorderStyle(); else return mpWindowImpl->mpBorderWindow->GetBorderStyle(); } @@ -2121,7 +2155,7 @@ long Window::CalcTitleWidth() const if ( mpWindowImpl->mpBorderWindow ) { if ( mpWindowImpl->mpBorderWindow->GetType() == WINDOW_BORDERWINDOW ) - return static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow)->CalcTitleWidth(); + return static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->CalcTitleWidth(); else return mpWindowImpl->mpBorderWindow->CalcTitleWidth(); } @@ -2241,8 +2275,7 @@ vcl::Font Window::GetPointFont() const void Window::Show( bool bVisible, sal_uInt16 nFlags ) { - - if ( mpWindowImpl->mbVisible == bVisible ) + if ( IsDisposed() || mpWindowImpl->mbVisible == bVisible ) return; ImplDelData aDogTag( this ); @@ -2482,7 +2515,7 @@ Size Window::GetSizePixel() const // #i43257# trigger pending resize handler to assure correct window sizes if( mpWindowImpl->mpFrameData->maResizeIdle.IsActive() ) { - ImplDelData aDogtag( this ); + ImplDelData aDogtag( const_cast<Window*>(this) ); mpWindowImpl->mpFrameData->maResizeIdle.Stop(); mpWindowImpl->mpFrameData->maResizeIdle.GetIdleHdl().Call( NULL ); if( aDogtag.IsDead() ) @@ -2504,6 +2537,8 @@ void Window::GetBorder( sal_Int32& rLeftBorder, sal_Int32& rTopBorder, void Window::Enable( bool bEnable, bool bChild ) { + if ( IsDisposed() ) + return; if ( !bEnable ) { @@ -2525,15 +2560,15 @@ void Window::Enable( bool bEnable, bool bChild ) { mpWindowImpl->mpBorderWindow->Enable( bEnable, false ); if ( (mpWindowImpl->mpBorderWindow->GetType() == WINDOW_BORDERWINDOW) && - static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow)->mpMenuBarWindow ) - static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow)->mpMenuBarWindow->Enable( bEnable, true ); + static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->mpMenuBarWindow ) + static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->mpMenuBarWindow->Enable( bEnable, true ); } // #i56102# restore app focus win in case the // window was disabled when the frame focus changed ImplSVData* pSVData = ImplGetSVData(); if( bEnable && - pSVData->maWinData.mpFocusWin == NULL && + pSVData->maWinData.mpFocusWin == nullptr && mpWindowImpl->mpFrameData->mbHasFocus && mpWindowImpl->mpFrameData->mpFocusWin == this ) pSVData->maWinData.mpFocusWin = this; @@ -2587,8 +2622,8 @@ void Window::EnableInput( bool bEnable, bool bChild ) { mpWindowImpl->mpBorderWindow->EnableInput( bEnable, false ); if ( (mpWindowImpl->mpBorderWindow->GetType() == WINDOW_BORDERWINDOW) && - static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow)->mpMenuBarWindow ) - static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow)->mpMenuBarWindow->EnableInput( bEnable, true ); + static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->mpMenuBarWindow ) + static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->mpMenuBarWindow->EnableInput( bEnable, true ); } if ( (! bEnable && mpWindowImpl->meAlwaysInputMode != AlwaysInputEnabled) || @@ -2616,7 +2651,7 @@ void Window::EnableInput( bool bEnable, bool bChild ) // window was disabled when the frame focus changed ImplSVData* pSVData = ImplGetSVData(); if( bEnable && - pSVData->maWinData.mpFocusWin == NULL && + pSVData->maWinData.mpFocusWin == nullptr && mpWindowImpl->mpFrameData->mbHasFocus && mpWindowImpl->mpFrameData->mpFocusWin == this ) pSVData->maWinData.mpFocusWin = this; @@ -2688,8 +2723,8 @@ void Window::EnableInput( bool bEnable, bool bChild, bool bSysWin, // the same for ownerdraw floating windows if( mpWindowImpl->mbFrame ) { - ::std::vector< vcl::Window* >& rList = mpWindowImpl->mpFrameData->maOwnerDrawList; - ::std::vector< vcl::Window* >::iterator p = rList.begin(); + ::std::vector< VclPtr<vcl::Window> >& rList = mpWindowImpl->mpFrameData->maOwnerDrawList; + auto p = rList.begin(); while( p != rList.end() ) { // Is Window in the path from this window @@ -3055,7 +3090,7 @@ Rectangle Window::ImplGetWindowExtentsRelative( vcl::Window *pRelativeWindow, bo if( pRelativeWindow ) { // #106399# express coordinates relative to borderwindow - vcl::Window *pRelWin = (!bClientOnly && pRelativeWindow->mpWindowImpl->mpBorderWindow) ? pRelativeWindow->mpWindowImpl->mpBorderWindow : pRelativeWindow; + vcl::Window *pRelWin = (!bClientOnly && pRelativeWindow->mpWindowImpl->mpBorderWindow) ? pRelativeWindow->mpWindowImpl->mpBorderWindow.get() : pRelativeWindow; aPos = pRelWin->AbsoluteScreenToOutputPixel( aPos ); } return Rectangle( aPos, aSize ); @@ -3102,7 +3137,6 @@ void Window::SetUpdateMode( bool bUpdate ) void Window::GrabFocus() { - ImplGrabFocus( 0 ); } @@ -3608,7 +3642,7 @@ void Window::ImplIncModalCount() { pParent = pParent->GetParent(); } - pFrameWindow = pParent ? pParent->mpWindowImpl->mpFrameWindow : NULL; + pFrameWindow = pParent ? pParent->mpWindowImpl->mpFrameWindow.get() : NULL; } } void Window::ImplDecModalCount() @@ -3622,7 +3656,7 @@ void Window::ImplDecModalCount() { pParent = pParent->GetParent(); } - pFrameWindow = pParent ? pParent->mpWindowImpl->mpFrameWindow : NULL; + pFrameWindow = pParent ? pParent->mpWindowImpl->mpFrameWindow.get() : NULL; } } diff --git a/vcl/source/window/window2.cxx b/vcl/source/window/window2.cxx index 68129c08561b..c43563e7db74 100644 --- a/vcl/source/window/window2.cxx +++ b/vcl/source/window/window2.cxx @@ -375,7 +375,7 @@ void Window::StartTracking( sal_uInt16 nFlags ) { ImplSVData* pSVData = ImplGetSVData(); - if ( pSVData->maWinData.mpTrackWin != this ) + if ( pSVData->maWinData.mpTrackWin.get() != this ) { if ( pSVData->maWinData.mpTrackWin ) pSVData->maWinData.mpTrackWin->EndTracking( ENDTRACK_CANCEL ); @@ -402,7 +402,7 @@ void Window::EndTracking( sal_uInt16 nFlags ) { ImplSVData* pSVData = ImplGetSVData(); - if ( pSVData->maWinData.mpTrackWin == this ) + if ( pSVData->maWinData.mpTrackWin.get() == this ) { // due to DbgChkThis in brackets, as the window could be destroyed // in the handler @@ -449,7 +449,7 @@ void Window::StartAutoScroll( sal_uInt16 nFlags ) { ImplSVData* pSVData = ImplGetSVData(); - if ( pSVData->maWinData.mpAutoScrollWin != this ) + if ( pSVData->maWinData.mpAutoScrollWin.get() != this ) { if ( pSVData->maWinData.mpAutoScrollWin ) pSVData->maWinData.mpAutoScrollWin->EndAutoScroll(); @@ -457,14 +457,14 @@ void Window::StartAutoScroll( sal_uInt16 nFlags ) pSVData->maWinData.mpAutoScrollWin = this; pSVData->maWinData.mnAutoScrollFlags = nFlags; - pSVData->maAppData.mpWheelWindow = new ImplWheelWindow( this ); + pSVData->maAppData.mpWheelWindow = VclPtr<ImplWheelWindow>::Create( this ); } void Window::EndAutoScroll() { ImplSVData* pSVData = ImplGetSVData(); - if ( pSVData->maWinData.mpAutoScrollWin == this ) + if ( pSVData->maWinData.mpAutoScrollWin.get() == this ) { pSVData->maWinData.mpAutoScrollWin = NULL; pSVData->maWinData.mnAutoScrollFlags = 0; @@ -938,7 +938,7 @@ void Window::EnableDocking( bool bEnable ) } // retrieves the list of owner draw decorated windows for this window hiearchy -::std::vector<vcl::Window *>& Window::ImplGetOwnerDrawList() +::std::vector<VclPtr<vcl::Window> >& Window::ImplGetOwnerDrawList() { return ImplGetTopmostFrameWindow()->mpWindowImpl->mpFrameData->maOwnerDrawList; } @@ -975,27 +975,27 @@ vcl::Window* Window::ImplGetWindow() ImplFrameData* Window::ImplGetFrameData() { - return mpWindowImpl->mpFrameData; + return mpWindowImpl ? mpWindowImpl->mpFrameData : NULL; } SalFrame* Window::ImplGetFrame() const { - return mpWindowImpl->mpFrame; + return mpWindowImpl ? mpWindowImpl->mpFrame : NULL; } vcl::Window* Window::ImplGetParent() const { - return mpWindowImpl->mpParent; + return mpWindowImpl ? mpWindowImpl->mpParent.get() : NULL; } vcl::Window* Window::ImplGetClientWindow() const { - return mpWindowImpl->mpClientWindow; + return mpWindowImpl ? mpWindowImpl->mpClientWindow.get() : NULL; } vcl::Window* Window::ImplGetBorderWindow() const { - return mpWindowImpl->mpBorderWindow; + return mpWindowImpl ? mpWindowImpl->mpBorderWindow.get() : NULL; } vcl::Window* Window::ImplGetFirstOverlapWindow() @@ -1016,37 +1016,38 @@ const vcl::Window* Window::ImplGetFirstOverlapWindow() const vcl::Window* Window::ImplGetFrameWindow() const { - return mpWindowImpl->mpFrameWindow; + return mpWindowImpl ? mpWindowImpl->mpFrameWindow.get() : NULL; } bool Window::IsDockingWindow() const { - return mpWindowImpl->mbDockWin; + return mpWindowImpl ? mpWindowImpl->mbDockWin : false; } bool Window::ImplIsFloatingWindow() const { - return mpWindowImpl->mbFloatWin; + return mpWindowImpl ? mpWindowImpl->mbFloatWin : false; } bool Window::ImplIsSplitter() const { - return mpWindowImpl->mbSplitter; + return mpWindowImpl ? mpWindowImpl->mbSplitter : false; } bool Window::ImplIsPushButton() const { - return mpWindowImpl->mbPushButton; + return mpWindowImpl ? mpWindowImpl->mbPushButton : false; } bool Window::ImplIsOverlapWindow() const { - return mpWindowImpl->mbOverlapWin; + return mpWindowImpl ? mpWindowImpl->mbOverlapWin : false; } void Window::ImplSetMouseTransparent( bool bTransparent ) { - mpWindowImpl->mbMouseTransparent = bTransparent; + if (mpWindowImpl) + mpWindowImpl->mbMouseTransparent = bTransparent; } Point Window::ImplOutputToFrame( const Point& rPos ) @@ -1061,7 +1062,8 @@ Point Window::ImplFrameToOutput( const Point& rPos ) void Window::SetCompoundControl( bool bCompound ) { - mpWindowImpl->mbCompoundControl = bCompound; + if (mpWindowImpl) + mpWindowImpl->mbCompoundControl = bCompound; } void Window::IncrementLockCount() @@ -1076,27 +1078,31 @@ void Window::DecrementLockCount() WinBits Window::GetStyle() const { - return mpWindowImpl->mnStyle; + return mpWindowImpl ? mpWindowImpl->mnStyle : 0; } WinBits Window::GetPrevStyle() const { - return mpWindowImpl->mnPrevStyle; + return mpWindowImpl ? mpWindowImpl->mnPrevStyle : 0; } WinBits Window::GetExtendedStyle() const { - return mpWindowImpl->mnExtendedStyle; + return mpWindowImpl ? mpWindowImpl->mnExtendedStyle : 0; } void Window::SetType( WindowType nType ) { - mpWindowImpl->mnType = nType; + if (mpWindowImpl) + mpWindowImpl->mnType = nType; } WindowType Window::GetType() const { - return mpWindowImpl->mnType; + if (mpWindowImpl) + return mpWindowImpl->mnType; + else + return WINDOW_PARENT; } Dialog* Window::GetParentDialog() const @@ -1116,22 +1122,22 @@ Dialog* Window::GetParentDialog() const bool Window::IsSystemWindow() const { - return mpWindowImpl->mbSysWin; + return mpWindowImpl ? mpWindowImpl->mbSysWin : false; } bool Window::IsDialog() const { - return mpWindowImpl->mbDialog; + return mpWindowImpl ? mpWindowImpl->mbDialog : false; } bool Window::IsMenuFloatingWindow() const { - return mpWindowImpl->mbMenuFloatingWindow; + return mpWindowImpl ? mpWindowImpl->mbMenuFloatingWindow : false; } bool Window::IsToolbarFloatingWindow() const { - return mpWindowImpl->mbToolbarFloatingWindow; + return mpWindowImpl ? mpWindowImpl->mbToolbarFloatingWindow : false; } void Window::EnableAllResize( bool bEnable ) @@ -1146,17 +1152,17 @@ void Window::EnableChildTransparentMode( bool bEnable ) bool Window::IsChildTransparentModeEnabled() const { - return mpWindowImpl->mbChildTransparent; + return mpWindowImpl ? mpWindowImpl->mbChildTransparent : false; } bool Window::IsMouseTransparent() const { - return mpWindowImpl->mbMouseTransparent; + return mpWindowImpl ? mpWindowImpl->mbMouseTransparent : false; } bool Window::IsPaintTransparent() const { - return mpWindowImpl->mbPaintTransparent; + return mpWindowImpl ? mpWindowImpl->mbPaintTransparent : false; } void Window::SetDialogControlStart( bool bStart ) @@ -1166,7 +1172,7 @@ void Window::SetDialogControlStart( bool bStart ) bool Window::IsDialogControlStart() const { - return mpWindowImpl->mbDlgCtrlStart; + return mpWindowImpl ? mpWindowImpl->mbDlgCtrlStart : false; } void Window::SetDialogControlFlags( sal_uInt16 nFlags ) @@ -1211,27 +1217,27 @@ bool Window::IsControlBackground() const bool Window::IsInPaint() const { - return mpWindowImpl->mbInPaint; + return mpWindowImpl ? mpWindowImpl->mbInPaint : false; } vcl::Window* Window::GetParent() const { - return mpWindowImpl->mpRealParent; + return mpWindowImpl ? mpWindowImpl->mpRealParent.get() : NULL; } bool Window::IsVisible() const { - return mpWindowImpl->mbVisible; + return mpWindowImpl ? mpWindowImpl->mbVisible : false; } bool Window::IsReallyVisible() const { - return mpWindowImpl->mbReallyVisible; + return mpWindowImpl ? mpWindowImpl->mbReallyVisible : false; } bool Window::IsReallyShown() const { - return mpWindowImpl->mbReallyShown; + return mpWindowImpl ? mpWindowImpl->mbReallyShown : false; } bool Window::IsInInitShow() const @@ -1241,12 +1247,12 @@ bool Window::IsInInitShow() const bool Window::IsEnabled() const { - return !mpWindowImpl->mbDisabled; + return mpWindowImpl ? !mpWindowImpl->mbDisabled : false; } bool Window::IsInputEnabled() const { - return !mpWindowImpl->mbInputDisabled; + return mpWindowImpl ? !mpWindowImpl->mbInputDisabled : false; } bool Window::IsAlwaysEnableInput() const @@ -1317,6 +1323,8 @@ bool Window::IsWait() const vcl::Cursor* Window::GetCursor() const { + if (!mpWindowImpl) + return NULL; return mpWindowImpl->mpCursor; } @@ -1338,7 +1346,8 @@ void Window::SetHelpText( const OUString& rHelpText ) void Window::SetQuickHelpText( const OUString& rHelpText ) { - mpWindowImpl->maQuickHelpText = rHelpText; + if (mpWindowImpl) + mpWindowImpl->maQuickHelpText = rHelpText; } const OUString& Window::GetQuickHelpText() const @@ -1364,8 +1373,8 @@ bool Window::IsCreatedWithToolkit() const void Window::SetCreatedWithToolkit( bool b ) { mpWindowImpl->mbCreatedWithToolkit = b; - } + const Pointer& Window::GetPointer() const { return mpWindowImpl->maPointer; @@ -1373,7 +1382,7 @@ const Pointer& Window::GetPointer() const VCLXWindow* Window::GetWindowPeer() const { - return mpWindowImpl->mpVCLXWindow; + return mpWindowImpl ? mpWindowImpl->mpVCLXWindow : NULL; } void Window::SetPosPixel( const Point& rNewPos ) @@ -1436,6 +1445,9 @@ void Window::InvalidateSizeCache() void Window::queue_resize(StateChangedType eReason) { + if (IsDisposed()) + return; + bool bSomeoneCares = queue_ungrouped_resize(this); if (eReason != StateChangedType::VISIBLE) @@ -1446,9 +1458,8 @@ void Window::queue_resize(StateChangedType eReason) WindowImpl *pWindowImpl = mpWindowImpl->mpBorderWindow ? mpWindowImpl->mpBorderWindow->mpWindowImpl : mpWindowImpl; if (pWindowImpl->m_xSizeGroup && pWindowImpl->m_xSizeGroup->get_mode() != VCL_SIZE_GROUP_NONE) { - std::set<vcl::Window*> &rWindows = pWindowImpl->m_xSizeGroup->get_widgets(); - for (std::set<vcl::Window*>::iterator aI = rWindows.begin(), - aEnd = rWindows.end(); aI != aEnd; ++aI) + std::set<VclPtr<vcl::Window> > &rWindows = pWindowImpl->m_xSizeGroup->get_widgets(); + for (auto aI = rWindows.begin(), aEnd = rWindows.end(); aI != aEnd; ++aI) { vcl::Window *pOther = *aI; if (pOther == this) @@ -1743,9 +1754,8 @@ Size Window::get_preferred_size() const if (eMode != VCL_SIZE_GROUP_NONE) { const bool bIgnoreInHidden = pWindowImpl->m_xSizeGroup->get_ignore_hidden(); - const std::set<vcl::Window*> &rWindows = pWindowImpl->m_xSizeGroup->get_widgets(); - for (std::set<vcl::Window*>::const_iterator aI = rWindows.begin(), - aEnd = rWindows.end(); aI != aEnd; ++aI) + const std::set<VclPtr<vcl::Window> > &rWindows = pWindowImpl->m_xSizeGroup->get_widgets(); + for (auto aI = rWindows.begin(), aEnd = rWindows.end(); aI != aEnd; ++aI) { const vcl::Window *pOther = *aI; if (pOther == this) @@ -2029,8 +2039,8 @@ void Window::remove_from_all_size_groups() void Window::add_mnemonic_label(FixedText *pLabel) { - std::vector<FixedText*>& v = mpWindowImpl->m_aMnemonicLabels; - if (std::find(v.begin(), v.end(), pLabel) != v.end()) + std::vector<VclPtr<FixedText> >& v = mpWindowImpl->m_aMnemonicLabels; + if (std::find(v.begin(), v.end(), VclPtr<FixedText>(pLabel)) != v.end()) return; v.push_back(pLabel); pLabel->set_mnemonic_widget(this); @@ -2038,15 +2048,15 @@ void Window::add_mnemonic_label(FixedText *pLabel) void Window::remove_mnemonic_label(FixedText *pLabel) { - std::vector<FixedText*>& v = mpWindowImpl->m_aMnemonicLabels; - std::vector<FixedText*>::iterator aFind = std::find(v.begin(), v.end(), pLabel); + std::vector<VclPtr<FixedText> >& v = mpWindowImpl->m_aMnemonicLabels; + auto aFind = std::find(v.begin(), v.end(), VclPtr<FixedText>(pLabel)); if (aFind == v.end()) return; v.erase(aFind); pLabel->set_mnemonic_widget(NULL); } -std::vector<FixedText*> Window::list_mnemonic_labels() const +std::vector<VclPtr<FixedText> > Window::list_mnemonic_labels() const { return mpWindowImpl->m_aMnemonicLabels; } diff --git a/vcl/source/window/winproc.cxx b/vcl/source/window/winproc.cxx index 139d77149e1e..ce4edf81670b 100644 --- a/vcl/source/window/winproc.cxx +++ b/vcl/source/window/winproc.cxx @@ -243,7 +243,7 @@ static bool ImplCallCommand( vcl::Window* pChild, sal_uInt16 nEvt, void* pData = struct ContextMenuEvent { - vcl::Window* pWindow; + VclPtr<vcl::Window> pWindow; ImplDelData aDelData; Point aChildPos; }; @@ -377,13 +377,13 @@ bool ImplHandleMouseEvent( vcl::Window* pWindow, MouseNotifyEvent nSVEvent, bool // no mouse messages to disabled windows // #106845# if the window was disabed during capturing we have to pass the mouse events to release capturing - if ( pSVData->maWinData.mpCaptureWin != pChild && (!pChild->IsEnabled() || !pChild->IsInputEnabled() || pChild->IsInModalNonRefMode() ) ) + if ( pSVData->maWinData.mpCaptureWin.get() != pChild && (!pChild->IsEnabled() || !pChild->IsInputEnabled() || pChild->IsInModalNonRefMode() ) ) { ImplHandleMouseFloatMode( pChild, aMousePos, nCode, nSVEvent, bMouseLeave ); if ( nSVEvent == MouseNotifyEvent::MOUSEMOVE ) { ImplHandleMouseHelpRequest( pChild, aMousePos ); - if( pWinFrameData->mpMouseMoveWin != pChild ) + if( pWinFrameData->mpMouseMoveWin.get() != pChild ) nMode |= MouseEventModifiers::ENTERWINDOW; } @@ -1371,11 +1371,10 @@ class HandleGestureEventBase { protected: ImplSVData* m_pSVData; - vcl::Window *m_pWindow; + VclPtr<vcl::Window> m_pWindow; Point m_aMousePos; public: - HandleGestureEventBase(vcl::Window *pWindow, const Point &rMousePos) : m_pSVData(ImplGetSVData()) , m_pWindow(pWindow) @@ -1692,7 +1691,7 @@ void ImplHandleResize( vcl::Window* pWindow, long nNewWidth, long nNewHeight ) { // #i42750# presentation wants to be informed about resize // as early as possible - WorkWindow* pWorkWindow = dynamic_cast<WorkWindow*>(pWindow->ImplGetWindowImpl()->mpClientWindow); + WorkWindow* pWorkWindow = dynamic_cast<WorkWindow*>(pWindow->ImplGetWindowImpl()->mpClientWindow.get()); if( ! pWorkWindow || pWorkWindow->IsPresentationMode() ) bStartTimer = false; } @@ -1938,7 +1937,7 @@ static void ImplHandleLoseFocus( vcl::Window* pWindow ) struct DelayedCloseEvent { - vcl::Window* pWindow; + VclPtr<vcl::Window> pWindow; ImplDelData aDelData; }; @@ -1951,9 +1950,9 @@ static sal_IntPtr DelayedCloseEventLink( void* pCEvent, void* ) pEv->pWindow->ImplRemoveDel( &pEv->aDelData ); // dispatch to correct window type if( pEv->pWindow->IsSystemWindow() ) - static_cast<SystemWindow*>(pEv->pWindow)->Close(); + static_cast<SystemWindow*>(pEv->pWindow.get())->Close(); else if( pEv->pWindow->IsDockingWindow() ) - static_cast<DockingWindow*>(pEv->pWindow)->Close(); + static_cast<DockingWindow*>(pEv->pWindow.get())->Close(); } delete pEv; diff --git a/vcl/source/window/wrkwin.cxx b/vcl/source/window/wrkwin.cxx index 1f75bd63a5ec..136adc859d84 100644 --- a/vcl/source/window/wrkwin.cxx +++ b/vcl/source/window/wrkwin.cxx @@ -49,7 +49,7 @@ void WorkWindow::ImplInit( vcl::Window* pParent, WinBits nStyle, SystemParentDat if ( nStyle & WB_APP ) nFrameStyle |= BORDERWINDOW_STYLE_APP; - ImplBorderWindow* pBorderWin = new ImplBorderWindow( pParent, pSystemParentData, nStyle, nFrameStyle ); + VclPtrInstance<ImplBorderWindow> pBorderWin( pParent, pSystemParentData, nStyle, nFrameStyle ); Window::ImplInit( pBorderWin, nStyle & (WB_3DLOOK | WB_CLIPCHILDREN | WB_DIALOGCONTROL | WB_SYSTEMFLOATWIN), NULL ); pBorderWin->mpWindowImpl->mpClientWindow = this; pBorderWin->GetBorder( mpWindowImpl->mnLeftBorder, mpWindowImpl->mnTopBorder, mpWindowImpl->mnRightBorder, mpWindowImpl->mnBottomBorder ); @@ -113,12 +113,18 @@ WorkWindow::WorkWindow( SystemParentData* pParent ) : WorkWindow::~WorkWindow() { + disposeOnce(); +} + +void WorkWindow::dispose() +{ ImplSVData* pSVData = ImplGetSVData(); if ( pSVData->maWinData.mpAppWin == this ) { pSVData->maWinData.mpAppWin = NULL; Application::Quit(); } + SystemWindow::dispose(); } void WorkWindow::ShowFullScreenMode( bool bFullScreenMode ) |