diff options
Diffstat (limited to 'vcl/source/control')
-rw-r--r-- | vcl/source/control/button.cxx | 64 | ||||
-rw-r--r-- | vcl/source/control/combobox.cxx | 84 | ||||
-rw-r--r-- | vcl/source/control/ctrl.cxx | 18 | ||||
-rw-r--r-- | vcl/source/control/edit.cxx | 26 | ||||
-rw-r--r-- | vcl/source/control/field.cxx | 24 | ||||
-rw-r--r-- | vcl/source/control/field2.cxx | 24 | ||||
-rw-r--r-- | vcl/source/control/fixed.cxx | 15 | ||||
-rw-r--r-- | vcl/source/control/fixedhyper.cxx | 4 | ||||
-rw-r--r-- | vcl/source/control/ilstbox.cxx | 113 | ||||
-rw-r--r-- | vcl/source/control/longcurr.cxx | 8 | ||||
-rw-r--r-- | vcl/source/control/lstbox.cxx | 96 | ||||
-rw-r--r-- | vcl/source/control/menubtn.cxx | 6 | ||||
-rw-r--r-- | vcl/source/control/morebtn.cxx | 8 | ||||
-rw-r--r-- | vcl/source/control/prgsbar.cxx | 4 | ||||
-rw-r--r-- | vcl/source/control/scrbar.cxx | 8 | ||||
-rw-r--r-- | vcl/source/control/spinbtn.cxx | 4 | ||||
-rw-r--r-- | vcl/source/control/spinfld.cxx | 15 | ||||
-rw-r--r-- | vcl/source/control/tabctrl.cxx | 38 | ||||
-rw-r--r-- | vcl/source/control/throbber.cxx | 6 |
19 files changed, 298 insertions, 267 deletions
diff --git a/vcl/source/control/button.cxx b/vcl/source/control/button.cxx index 09abe44f5f80..bf23b10fb9d4 100644 --- a/vcl/source/control/button.cxx +++ b/vcl/source/control/button.cxx @@ -88,14 +88,19 @@ ImplCommonButtonData::~ImplCommonButtonData() } Button::Button( WindowType nType ) : - Control( nType ) + Control( nType ), + mpButtonData( new ImplCommonButtonData ) { - mpButtonData = new ImplCommonButtonData; } Button::~Button() { - delete mpButtonData; + disposeOnce(); +} + +void Button::dispose() +{ + Control::dispose(); } void Button::SetCommandHandler(const OUString& aCommand) @@ -1173,10 +1178,6 @@ PushButton::PushButton( vcl::Window* pParent, const ResId& rResId ) : Show(); } -PushButton::~PushButton() -{ -} - void PushButton::MouseButtonDown( const MouseEvent& rMEvt ) { if ( rMEvt.IsLeft() && @@ -1583,7 +1584,8 @@ void PushButton::SetPressed( bool bPressed ) void PushButton::EndSelection() { EndTracking( ENDTRACK_CANCEL ); - if ( ImplGetButtonState() & BUTTON_DRAW_PRESSED ) + if ( !IsDisposed() && + ImplGetButtonState() & BUTTON_DRAW_PRESSED ) { ImplGetButtonState() &= ~BUTTON_DRAW_PRESSED; if ( !mbPressed ) @@ -2143,20 +2145,20 @@ void RadioButton::group(RadioButton &rOther) if (!m_xGroup) { - m_xGroup.reset(new std::vector<RadioButton*>); + m_xGroup.reset(new std::vector<VclPtr<RadioButton> >); m_xGroup->push_back(this); } - std::vector<RadioButton*>::iterator aFind = std::find(m_xGroup->begin(), m_xGroup->end(), &rOther); + auto aFind = std::find(m_xGroup->begin(), m_xGroup->end(), VclPtr<RadioButton>(&rOther)); if (aFind == m_xGroup->end()) { m_xGroup->push_back(&rOther); if (rOther.m_xGroup) { - std::vector< RadioButton* > aOthers(rOther.GetRadioButtonGroup(false)); + std::vector< VclPtr<RadioButton> > aOthers(rOther.GetRadioButtonGroup(false)); //make all members of the group share the same button group - for (std::vector<RadioButton*>::iterator aI = aOthers.begin(), aEnd = aOthers.end(); aI != aEnd; ++aI) + for (auto aI = aOthers.begin(), aEnd = aOthers.end(); aI != aEnd; ++aI) { aFind = std::find(m_xGroup->begin(), m_xGroup->end(), *aI); if (aFind == m_xGroup->end()) @@ -2165,8 +2167,7 @@ void RadioButton::group(RadioButton &rOther) } //make all members of the group share the same button group - for (std::vector<RadioButton*>::iterator aI = m_xGroup->begin(), aEnd = m_xGroup->end(); - aI != aEnd; ++aI) + for (auto aI = m_xGroup->begin(), aEnd = m_xGroup->end(); aI != aEnd; ++aI) { RadioButton* pButton = *aI; pButton->m_xGroup = m_xGroup; @@ -2178,14 +2179,14 @@ void RadioButton::group(RadioButton &rOther) ImplUncheckAllOther(); } -std::vector< RadioButton* > RadioButton::GetRadioButtonGroup(bool bIncludeThis) const +std::vector< VclPtr<RadioButton> > RadioButton::GetRadioButtonGroup(bool bIncludeThis) const { if (m_xGroup) { if (bIncludeThis) return *m_xGroup; - std::vector< RadioButton* > aGroup; - for (std::vector<RadioButton*>::iterator aI = m_xGroup->begin(), aEnd = m_xGroup->end(); aI != aEnd; ++aI) + std::vector< VclPtr<RadioButton> > aGroup; + for (auto aI = m_xGroup->begin(), aEnd = m_xGroup->end(); aI != aEnd; ++aI) { RadioButton *pRadioButton = *aI; if (pRadioButton == this) @@ -2207,7 +2208,7 @@ std::vector< RadioButton* > RadioButton::GetRadioButtonGroup(bool bIncludeThis) else break; } - std::vector< RadioButton* > aGroup; + std::vector< VclPtr<RadioButton> > aGroup; // insert radiobuttons up to next group do { @@ -2226,9 +2227,9 @@ void RadioButton::ImplUncheckAllOther() { mpWindowImpl->mnStyle |= WB_TABSTOP; - std::vector<RadioButton*> aGroup(GetRadioButtonGroup(false)); + std::vector<VclPtr<RadioButton> > aGroup(GetRadioButtonGroup(false)); // iterate over radio button group and checked buttons - for (std::vector<RadioButton*>::iterator aI = aGroup.begin(), aEnd = aGroup.end(); aI != aEnd; ++aI) + for (auto aI = aGroup.begin(), aEnd = aGroup.end(); aI != aEnd; ++aI) { RadioButton *pWindow = *aI; if ( pWindow->IsChecked() ) @@ -2305,11 +2306,18 @@ void RadioButton::ImplLoadRes( const ResId& rResId ) RadioButton::~RadioButton() { + disposeOnce(); +} + +void RadioButton::dispose() +{ if (m_xGroup) { - m_xGroup->erase(std::remove(m_xGroup->begin(), m_xGroup->end(), this), - m_xGroup->end()); + m_xGroup->erase(std::remove(m_xGroup->begin(), m_xGroup->end(), VclPtr<RadioButton>(this)), + m_xGroup->end()); + m_xGroup.reset(); } + Button::dispose(); } void RadioButton::MouseButtonDown( const MouseEvent& rMEvt ) @@ -3753,10 +3761,6 @@ ImageButton::ImageButton( vcl::Window* pParent, const ResId& rResId ) : ImplInitStyle(); } -ImageButton::~ImageButton() -{ -} - void ImageButton::ImplInitStyle() { WinBits nStyle = GetStyle(); @@ -3775,20 +3779,12 @@ ImageRadioButton::ImageRadioButton( vcl::Window* pParent, WinBits nStyle ) : { } -ImageRadioButton::~ImageRadioButton() -{ -} - TriStateBox::TriStateBox( vcl::Window* pParent, WinBits nStyle ) : CheckBox( pParent, nStyle ) { EnableTriState( true ); } -TriStateBox::~TriStateBox() -{ -} - DisclosureButton::DisclosureButton( vcl::Window* pParent, WinBits nStyle ) : CheckBox( pParent, nStyle ) { diff --git a/vcl/source/control/combobox.cxx b/vcl/source/control/combobox.cxx index be0e048991c6..e9e24ee3cabc 100644 --- a/vcl/source/control/combobox.cxx +++ b/vcl/source/control/combobox.cxx @@ -68,20 +68,25 @@ ComboBox::ComboBox( vcl::Window* pParent, const ResId& rResId ) : ComboBox::~ComboBox() { - SetSubEdit( NULL ); - delete mpSubEdit; + disposeOnce(); +} + +void ComboBox::dispose() +{ + mpSubEdit.disposeAndClear(); - ImplListBox *pImplLB = mpImplLB; - mpImplLB = NULL; - delete pImplLB; + VclPtr< ImplListBox > pImplLB = mpImplLB; + mpImplLB.clear(); + pImplLB.disposeAndClear(); - delete mpFloatWin; - delete mpBtn; + mpFloatWin.disposeAndClear(); + mpBtn.disposeAndClear(); + Edit::dispose(); } void ComboBox::ImplInitComboBoxData() { - mpSubEdit = NULL; + mpSubEdit.disposeAndClear(); mpBtn = NULL; mpImplLB = NULL; mpFloatWin = NULL; @@ -142,11 +147,11 @@ void ComboBox::ImplInit( vcl::Window* pParent, WinBits nStyle ) WinBits nListStyle = nStyle; if( nStyle & WB_DROPDOWN ) { - mpFloatWin = new ImplListBoxFloatingWindow( this ); + mpFloatWin = VclPtr<ImplListBoxFloatingWindow>::Create( this ); mpFloatWin->SetAutoWidth( true ); mpFloatWin->SetPopupModeEndHdl( LINK( this, ComboBox, ImplPopupModeEndHdl ) ); - mpBtn = new ImplBtn( this, WB_NOLIGHTBORDER | WB_RECTSTYLE ); + mpBtn = VclPtr<ImplBtn>::Create( this, WB_NOLIGHTBORDER | WB_RECTSTYLE ); ImplInitDropDownButton( mpBtn ); mpBtn->buttonDownSignal.connect( boost::bind( &ComboBox::ImplClickButtonHandler, this, _1 )); mpBtn->Show(); @@ -165,7 +170,7 @@ void ComboBox::ImplInit( vcl::Window* pParent, WinBits nStyle ) } } - mpSubEdit = new Edit( this, nEditStyle ); + mpSubEdit.set( VclPtr<Edit>::Create( this, nEditStyle ) ); mpSubEdit->EnableRTL( false ); SetSubEdit( mpSubEdit ); mpSubEdit->SetPosPixel( Point() ); @@ -175,7 +180,7 @@ void ComboBox::ImplInit( vcl::Window* pParent, WinBits nStyle ) vcl::Window* pLBParent = this; if ( mpFloatWin ) pLBParent = mpFloatWin; - mpImplLB = new ImplListBox( pLBParent, nListStyle|WB_SIMPLEMODE|WB_AUTOHSCROLL ); + mpImplLB = VclPtr<ImplListBox>::Create( pLBParent, nListStyle|WB_SIMPLEMODE|WB_AUTOHSCROLL ); mpImplLB->SetPosPixel( Point() ); mpImplLB->SetSelectHdl( LINK( this, ComboBox, ImplSelectHdl ) ); mpImplLB->SetCancelHdl( LINK( this, ComboBox, ImplCancelHdl ) ); @@ -188,7 +193,7 @@ void ComboBox::ImplInit( vcl::Window* pParent, WinBits nStyle ) if ( mpFloatWin ) mpFloatWin->SetImplListBox( mpImplLB ); else - mpImplLB->GetMainWindow().AllowGrabFocus( true ); + mpImplLB->GetMainWindow()->AllowGrabFocus( true ); ImplCalcEditHeight(); @@ -253,7 +258,7 @@ void ComboBox::ImplClickButtonHandler( ImplBtn* ) ImplClearLayoutData(); if( mpImplLB ) - mpImplLB->GetMainWindow().ImplClearLayoutData(); + mpImplLB->GetMainWindow()->ImplClearLayoutData(); } IMPL_LINK_NOARG(ComboBox, ImplPopupModeEndHdl) @@ -272,7 +277,7 @@ IMPL_LINK_NOARG(ComboBox, ImplPopupModeEndHdl) ImplClearLayoutData(); if( mpImplLB ) - mpImplLB->GetMainWindow().ImplClearLayoutData(); + mpImplLB->GetMainWindow()->ImplClearLayoutData(); mpBtn->SetPressed( false ); CallEventListeners( VCLEVENT_DROPDOWN_CLOSE ); @@ -581,20 +586,20 @@ void ComboBox::FillLayoutData() const mpControlData->mpLayoutData = new vcl::ControlLayoutData(); AppendLayoutData( *mpSubEdit ); mpSubEdit->SetLayoutDataParent( this ); - Control& rMainWindow = mpImplLB->GetMainWindow(); + ImplListBoxWindow* rMainWindow = mpImplLB->GetMainWindow(); if( mpFloatWin ) { // dropdown mode if( mpFloatWin->IsReallyVisible() ) { - AppendLayoutData( rMainWindow ); - rMainWindow.SetLayoutDataParent( this ); + AppendLayoutData( *rMainWindow ); + rMainWindow->SetLayoutDataParent( this ); } } else { - AppendLayoutData( rMainWindow ); - rMainWindow.SetLayoutDataParent( this ); + AppendLayoutData( *rMainWindow ); + rMainWindow->SetLayoutDataParent( this ); } } @@ -647,7 +652,7 @@ void ComboBox::StateChanged( StateChangedType nType ) else if ( nType == StateChangedType::STYLE ) { SetStyle( ImplInitStyle( GetStyle() ) ); - mpImplLB->GetMainWindow().EnableSort( ( GetStyle() & WB_SORT ) != 0 ); + mpImplLB->GetMainWindow()->EnableSort( ( GetStyle() & WB_SORT ) != 0 ); } else if( nType == StateChangedType::MIRRORING ) { @@ -765,7 +770,7 @@ bool ComboBox::Notify( NotifyEvent& rNEvt ) nDone = false; // don't eat this event, let the default handling happen (i.e. scroll the context) } } - else if( ( rNEvt.GetType() == MouseNotifyEvent::MOUSEBUTTONDOWN ) && ( rNEvt.GetWindow() == &mpImplLB->GetMainWindow() ) ) + else if( ( rNEvt.GetType() == MouseNotifyEvent::MOUSEBUTTONDOWN ) && ( rNEvt.GetWindow() == mpImplLB->GetMainWindow() ) ) { mpSubEdit->GrabFocus(); } @@ -799,6 +804,9 @@ void ComboBox::Modify() void ComboBox::ImplUpdateFloatSelection() { + if (!mpImplLB) + return; + // move text in the ListBox into the visible region mpImplLB->SetCallSelectionChangedHdl( false ); if ( !IsMultiSelectionEnabled() ) @@ -1106,7 +1114,7 @@ void ComboBox::GetMaxVisColumnsAndLines( sal_uInt16& rnCols, sal_uInt16& rnLines long nCharWidth = GetTextWidth(OUString(static_cast<sal_Unicode>('x'))); if ( !IsDropDownBox() ) { - Size aOutSz = mpImplLB->GetMainWindow().GetOutputSizePixel(); + Size aOutSz = mpImplLB->GetMainWindow()->GetOutputSizePixel(); rnCols = (nCharWidth > 0) ? (sal_uInt16)(aOutSz.Width()/nCharWidth) : 1; rnLines = (sal_uInt16)(aOutSz.Height()/mpImplLB->GetEntryHeight()); } @@ -1120,11 +1128,11 @@ void ComboBox::GetMaxVisColumnsAndLines( sal_uInt16& rnCols, sal_uInt16& rnLines void ComboBox::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, sal_uLong nFlags ) { - mpImplLB->GetMainWindow().ImplInitSettings( true, true, true ); + mpImplLB->GetMainWindow()->ImplInitSettings( true, true, true ); Point aPos = pDev->LogicToPixel( rPos ); Size aSize = pDev->LogicToPixel( rSize ); - vcl::Font aFont = mpImplLB->GetMainWindow().GetDrawPixelFont( pDev ); + vcl::Font aFont = mpImplLB->GetMainWindow()->GetDrawPixelFont( pDev ); OutDevType eOutDevType = pDev->GetOutDevType(); pDev->Push(); @@ -1233,18 +1241,18 @@ void ComboBox::UserDraw( const UserDrawEvent& ) void ComboBox::SetUserItemSize( const Size& rSz ) { - mpImplLB->GetMainWindow().SetUserItemSize( rSz ); + mpImplLB->GetMainWindow()->SetUserItemSize( rSz ); } void ComboBox::EnableUserDraw( bool bUserDraw ) { - mpImplLB->GetMainWindow().EnableUserDraw( bUserDraw ); + mpImplLB->GetMainWindow()->EnableUserDraw( bUserDraw ); } void ComboBox::DrawEntry( const UserDrawEvent& rEvt, bool bDrawImage, bool bDrawText, bool bDrawTextAtImagePos ) { - DBG_ASSERT( rEvt.GetDevice() == &mpImplLB->GetMainWindow(), "DrawEntry?!" ); - mpImplLB->GetMainWindow().DrawEntry( rEvt.GetItemId(), bDrawImage, bDrawText, bDrawTextAtImagePos ); + DBG_ASSERT( rEvt.GetDevice() == mpImplLB->GetMainWindow(), "DrawEntry?!" ); + mpImplLB->GetMainWindow()->DrawEntry( rEvt.GetItemId(), bDrawImage, bDrawText, bDrawTextAtImagePos ); } void ComboBox::SetSeparatorPos( sal_Int32 n ) @@ -1259,7 +1267,7 @@ void ComboBox::SetMRUEntries( const OUString& rEntries, sal_Unicode cSep ) OUString ComboBox::GetMRUEntries( sal_Unicode cSep ) const { - return mpImplLB->GetMRUEntries( cSep ); + return mpImplLB ? mpImplLB->GetMRUEntries( cSep ) : OUString(); } void ComboBox::SetMaxMRUCount( sal_Int32 n ) @@ -1269,12 +1277,12 @@ void ComboBox::SetMaxMRUCount( sal_Int32 n ) sal_Int32 ComboBox::GetMaxMRUCount() const { - return mpImplLB->GetMaxMRUCount(); + return mpImplLB ? mpImplLB->GetMaxMRUCount() : 0; } sal_uInt16 ComboBox::GetDisplayLineCount() const { - return mpImplLB->GetDisplayLineCount(); + return mpImplLB ? mpImplLB->GetDisplayLineCount() : 0; } void ComboBox::SetEntryData( sal_Int32 nPos, void* pNewData ) @@ -1355,8 +1363,8 @@ void ComboBox::SetNoSelection() Rectangle ComboBox::GetBoundingRectangle( sal_Int32 nItem ) const { - Rectangle aRect = mpImplLB->GetMainWindow().GetBoundingRectangle( nItem ); - Rectangle aOffset = mpImplLB->GetMainWindow().GetWindowExtentsRelative( (vcl::Window*)this ); + Rectangle aRect = mpImplLB->GetMainWindow()->GetBoundingRectangle( nItem ); + Rectangle aOffset = mpImplLB->GetMainWindow()->GetWindowExtentsRelative( (vcl::Window*)this ); aRect.Move( aOffset.TopLeft().X(), aOffset.TopLeft().Y() ); return aRect; } @@ -1382,16 +1390,16 @@ long ComboBox::GetIndexForPoint( const Point& rPoint, sal_Int32& rPos ) const { // point must be either in main list window // or in impl window (dropdown case) - ImplListBoxWindow& rMain = mpImplLB->GetMainWindow(); + ImplListBoxWindow* rMain = mpImplLB->GetMainWindow(); // convert coordinates to ImplListBoxWindow pixel coordinate space Point aConvPoint = LogicToPixel( rPoint ); aConvPoint = OutputToAbsoluteScreenPixel( aConvPoint ); - aConvPoint = rMain.AbsoluteScreenToOutputPixel( aConvPoint ); - aConvPoint = rMain.PixelToLogic( aConvPoint ); + aConvPoint = rMain->AbsoluteScreenToOutputPixel( aConvPoint ); + aConvPoint = rMain->PixelToLogic( aConvPoint ); // try to find entry - sal_Int32 nEntry = rMain.GetEntryPosForPoint( aConvPoint ); + sal_Int32 nEntry = rMain->GetEntryPosForPoint( aConvPoint ); if( nEntry == LISTBOX_ENTRY_NOTFOUND ) nIndex = -1; else diff --git a/vcl/source/control/ctrl.cxx b/vcl/source/control/ctrl.cxx index 411243cccaeb..85ca49501f24 100644 --- a/vcl/source/control/ctrl.cxx +++ b/vcl/source/control/ctrl.cxx @@ -67,7 +67,13 @@ Control::Control( vcl::Window* pParent, const ResId& rResId ) : Control::~Control() { + disposeOnce(); +} + +void Control::dispose() +{ delete mpControlData, mpControlData = NULL; + Window::dispose(); } void Control::EnableRTL( bool bEnable ) @@ -107,7 +113,7 @@ void Control::CreateLayoutData() const bool Control::HasLayoutData() const { - return mpControlData->mpLayoutData != NULL; + return mpControlData ? mpControlData->mpLayoutData != NULL : false; } ::vcl::ControlLayoutData* Control::GetLayoutData() const @@ -121,6 +127,10 @@ void Control::SetText( const OUString& rStr ) Window::SetText( rStr ); } +ControlLayoutData::ControlLayoutData() : m_pParent( NULL ) +{ +} + Rectangle ControlLayoutData::GetCharacterBounds( long nIndex ) const { return (nIndex >= 0 && nIndex < (long) m_aUnicodeBoundRects.size()) ? m_aUnicodeBoundRects[ nIndex ] : Rectangle(); @@ -338,7 +348,11 @@ void Control::SetLayoutDataParent( const Control* pParent ) const void Control::ImplClearLayoutData() const { - delete mpControlData->mpLayoutData, mpControlData->mpLayoutData = NULL; + if (mpControlData) + { + delete mpControlData->mpLayoutData; + mpControlData->mpLayoutData = NULL; + } } void Control::ImplDrawFrame( OutputDevice* pDev, Rectangle& rRect ) diff --git a/vcl/source/control/edit.cxx b/vcl/source/control/edit.cxx index 809e9445fe1a..6efac8a766b7 100644 --- a/vcl/source/control/edit.cxx +++ b/vcl/source/control/edit.cxx @@ -239,7 +239,14 @@ bool Edit::set_property(const OString &rKey, const OString &rValue) Edit::~Edit() { + disposeOnce(); +} + +void Edit::dispose() +{ delete mpDDInfo; + mpDDInfo = NULL; + vcl::Cursor* pCursor = GetCursor(); if ( pCursor ) { @@ -248,8 +255,10 @@ Edit::~Edit() } delete mpIMEInfos; + mpIMEInfos = NULL; delete mpUpdateDataTimer; + mpUpdateDataTimer = NULL; if ( mxDnDListener.is() ) { @@ -266,14 +275,18 @@ Edit::~Edit() uno::Reference< lang::XEventListener> xEL( mxDnDListener, uno::UNO_QUERY ); xEL->disposing( lang::EventObject() ); // #95154# #96585# Empty Source means it's the Client + mxDnDListener.clear(); } SetType(WINDOW_WINDOW); + + mpSubEdit.disposeAndClear(); + Control::dispose(); } void Edit::ImplInitEditData() { - mpSubEdit = NULL; + mpSubEdit = VclPtr<Edit>(); mpUpdateDataTimer = NULL; mpFilterText = NULL; mnXOffset = 0; @@ -792,8 +805,8 @@ void Edit::ShowTruncationWarning( vcl::Window* pParent ) ResMgr* pResMgr = ImplGetResMgr(); if( pResMgr ) { - MessageDialog aBox(pParent, ResId(SV_EDIT_WARNING_STR, *pResMgr), VCL_MESSAGE_WARNING); - aBox.Execute(); + ScopedVclPtrInstance< MessageDialog > aBox( pParent, ResId(SV_EDIT_WARNING_STR, *pResMgr), VCL_MESSAGE_WARNING ); + aBox->Execute(); } } @@ -2696,7 +2709,8 @@ void Edit::ClearModifyFlag() void Edit::SetSubEdit( Edit* pEdit ) { - mpSubEdit = pEdit; + mpSubEdit.disposeAndClear(); + mpSubEdit.set( pEdit ); if ( mpSubEdit ) { SetPointer( POINTER_ARROW ); // Nur das SubEdit hat den BEAM... @@ -2771,8 +2785,8 @@ Size Edit::CalcMinimumSize() const Size Edit::GetMinimumEditSize() { vcl::Window* pDefWin = ImplGetDefaultWindow(); - Edit aEdit( pDefWin, WB_BORDER ); - Size aSize( aEdit.CalcMinimumSize() ); + ScopedVclPtrInstance< Edit > aEdit( pDefWin, WB_BORDER ); + Size aSize( aEdit->CalcMinimumSize() ); return aSize; } diff --git a/vcl/source/control/field.cxx b/vcl/source/control/field.cxx index c71b7265c32e..cb6b46b8cb7a 100644 --- a/vcl/source/control/field.cxx +++ b/vcl/source/control/field.cxx @@ -842,10 +842,6 @@ void NumericField::ImplLoadRes( const ResId& rResId ) mnSpinSize = ReadLongRes(); } -NumericField::~NumericField() -{ -} - bool NumericField::PreNotify( NotifyEvent& rNEvt ) { if ( (rNEvt.GetType() == MouseNotifyEvent::KEYINPUT) && !rNEvt.GetKeyEvent()->GetKeyCode().IsMod2() ) @@ -979,10 +975,6 @@ Size NumericBox::CalcMinimumSize() const return aRet; } -NumericBox::~NumericBox() -{ -} - bool NumericBox::PreNotify( NotifyEvent& rNEvt ) { if ( (rNEvt.GetType() == MouseNotifyEvent::KEYINPUT) && !rNEvt.GetKeyEvent()->GetKeyCode().IsMod2() ) @@ -1679,10 +1671,6 @@ void MetricField::ImplLoadRes( const ResId& rResId ) Reformat(); } -MetricField::~MetricField() -{ -} - void MetricField::SetUnit( FieldUnit nNewUnit ) { sal_Int64 nRawMax = GetMax( nNewUnit ); @@ -1826,10 +1814,6 @@ Size MetricBox::CalcMinimumSize() const return aRet; } -MetricBox::~MetricBox() -{ -} - bool MetricBox::PreNotify( NotifyEvent& rNEvt ) { if ( (rNEvt.GetType() == MouseNotifyEvent::KEYINPUT) && !rNEvt.GetKeyEvent()->GetKeyCode().IsMod2() ) @@ -2056,10 +2040,6 @@ CurrencyField::CurrencyField( vcl::Window* pParent, WinBits nWinStyle ) : Reformat(); } -CurrencyField::~CurrencyField() -{ -} - bool CurrencyField::PreNotify( NotifyEvent& rNEvt ) { if ( (rNEvt.GetType() == MouseNotifyEvent::KEYINPUT) && !rNEvt.GetKeyEvent()->GetKeyCode().IsMod2() ) @@ -2138,10 +2118,6 @@ CurrencyBox::CurrencyBox( vcl::Window* pParent, WinBits nWinStyle ) : Reformat(); } -CurrencyBox::~CurrencyBox() -{ -} - bool CurrencyBox::PreNotify( NotifyEvent& rNEvt ) { if ( (rNEvt.GetType() == MouseNotifyEvent::KEYINPUT) && !rNEvt.GetKeyEvent()->GetKeyCode().IsMod2() ) diff --git a/vcl/source/control/field2.cxx b/vcl/source/control/field2.cxx index 4bf320f61f48..3f343b215760 100644 --- a/vcl/source/control/field2.cxx +++ b/vcl/source/control/field2.cxx @@ -820,10 +820,6 @@ PatternField::PatternField( vcl::Window* pParent, WinBits nWinStyle ) : Reformat(); } -PatternField::~PatternField() -{ -} - bool PatternField::PreNotify( NotifyEvent& rNEvt ) { if ( (rNEvt.GetType() == MouseNotifyEvent::KEYINPUT) && !rNEvt.GetKeyEvent()->GetKeyCode().IsMod2() ) @@ -870,10 +866,6 @@ PatternBox::PatternBox( vcl::Window* pParent, WinBits nWinStyle ) : Reformat(); } -PatternBox::~PatternBox() -{ -} - bool PatternBox::PreNotify( NotifyEvent& rNEvt ) { if ( (rNEvt.GetType() == MouseNotifyEvent::KEYINPUT) && !rNEvt.GetKeyEvent()->GetKeyCode().IsMod2() ) @@ -1738,10 +1730,6 @@ DateField::DateField( vcl::Window* pParent, WinBits nWinStyle ) : ResetLastDate(); } -DateField::~DateField() -{ -} - bool DateField::PreNotify( NotifyEvent& rNEvt ) { if ( (rNEvt.GetType() == MouseNotifyEvent::KEYINPUT) && IsStrictFormat() && @@ -1841,10 +1829,6 @@ DateBox::DateBox( vcl::Window* pParent, WinBits nWinStyle ) : Reformat(); } -DateBox::~DateBox() -{ -} - bool DateBox::PreNotify( NotifyEvent& rNEvt ) { if ( (rNEvt.GetType() == MouseNotifyEvent::KEYINPUT) && IsStrictFormat() && @@ -2532,10 +2516,6 @@ TimeField::TimeField( vcl::Window* pParent, WinBits nWinStyle ) : Reformat(); } -TimeField::~TimeField() -{ -} - bool TimeField::PreNotify( NotifyEvent& rNEvt ) { if ( (rNEvt.GetType() == MouseNotifyEvent::KEYINPUT) && !rNEvt.GetKeyEvent()->GetKeyCode().IsMod2() ) @@ -2673,10 +2653,6 @@ TimeBox::TimeBox( vcl::Window* pParent, WinBits nWinStyle ) : Reformat(); } -TimeBox::~TimeBox() -{ -} - bool TimeBox::PreNotify( NotifyEvent& rNEvt ) { if ( (rNEvt.GetType() == MouseNotifyEvent::KEYINPUT) && !rNEvt.GetKeyEvent()->GetKeyCode().IsMod2() ) diff --git a/vcl/source/control/fixed.cxx b/vcl/source/control/fixed.cxx index 62c6135438b6..69922de6df07 100644 --- a/vcl/source/control/fixed.cxx +++ b/vcl/source/control/fixed.cxx @@ -460,7 +460,14 @@ void FixedText::set_mnemonic_widget(vcl::Window *pWindow) FixedText::~FixedText() { + disposeOnce(); +} + +void FixedText::dispose() +{ set_mnemonic_widget(NULL); + m_pMnemonicWindow.clear(); + Control::dispose(); } SelectableFixedText::SelectableFixedText(vcl::Window* pParent, WinBits nStyle) @@ -748,10 +755,6 @@ FixedBitmap::FixedBitmap( vcl::Window* pParent, WinBits nStyle ) : ImplInit( pParent, nStyle ); } -FixedBitmap::~FixedBitmap() -{ -} - void FixedBitmap::ImplDraw( OutputDevice* pDev, sal_uLong /* nDrawFlags */, const Point& rPos, const Size& rSize ) { @@ -915,10 +918,6 @@ FixedImage::FixedImage( vcl::Window* pParent, const ResId& rResId ) : Show(); } -FixedImage::~FixedImage() -{ -} - void FixedImage::ImplDraw( OutputDevice* pDev, sal_uLong nDrawFlags, const Point& rPos, const Size& rSize ) { diff --git a/vcl/source/control/fixedhyper.cxx b/vcl/source/control/fixedhyper.cxx index 6926a0c843c6..db36f90c2572 100644 --- a/vcl/source/control/fixedhyper.cxx +++ b/vcl/source/control/fixedhyper.cxx @@ -26,10 +26,6 @@ FixedHyperlink::FixedHyperlink(vcl::Window* pParent, WinBits nWinStyle) Initialize(); } -FixedHyperlink::~FixedHyperlink() -{ -} - void FixedHyperlink::Initialize() { // saves the old pointer diff --git a/vcl/source/control/ilstbox.cxx b/vcl/source/control/ilstbox.cxx index 64d009ab9e34..083faf072e96 100644 --- a/vcl/source/control/ilstbox.cxx +++ b/vcl/source/control/ilstbox.cxx @@ -536,7 +536,13 @@ ImplListBoxWindow::ImplListBoxWindow( vcl::Window* pParent, WinBits nWinStyle ) ImplListBoxWindow::~ImplListBoxWindow() { + disposeOnce(); +} + +void ImplListBoxWindow::dispose() +{ delete mpEntryList; + Control::dispose(); } void ImplListBoxWindow::ImplInitSettings( bool bFont, bool bForeground, bool bBackground ) @@ -2135,16 +2141,16 @@ sal_uInt16 ImplListBoxWindow::ImplGetTextStyle() const ImplListBox::ImplListBox( vcl::Window* pParent, WinBits nWinStyle ) : Control( pParent, nWinStyle ), - maLBWindow( this, nWinStyle&(~WB_BORDER) ) + maLBWindow(VclPtr<ImplListBoxWindow>::Create( this, nWinStyle&(~WB_BORDER) )) { - maLBWindow.userDrawSignal.connect( userDrawSignal ); + maLBWindow->userDrawSignal.connect( userDrawSignal ); // for native widget rendering we must be able to detect this window type SetType( WINDOW_LISTBOXWINDOW ); - mpVScrollBar = new ScrollBar( this, WB_VSCROLL | WB_DRAG ); - mpHScrollBar = new ScrollBar( this, WB_HSCROLL | WB_DRAG ); - mpScrollBarBox = new ScrollBarBox( this ); + mpVScrollBar = VclPtr<ScrollBar>::Create( this, WB_VSCROLL | WB_DRAG ); + mpHScrollBar = VclPtr<ScrollBar>::Create( this, WB_HSCROLL | WB_DRAG ); + mpScrollBarBox = VclPtr<ScrollBarBox>::Create( this ); Link aLink( LINK( this, ImplListBox, ScrollBarHdl ) ); mpVScrollBar->SetScrollHdl( aLink ); @@ -2155,26 +2161,33 @@ ImplListBox::ImplListBox( vcl::Window* pParent, WinBits nWinStyle ) : mbAutoHScroll = ( nWinStyle & WB_AUTOHSCROLL ); mbEdgeBlending = false; - maLBWindow.SetScrollHdl( LINK( this, ImplListBox, LBWindowScrolled ) ); - maLBWindow.SetMRUChangedHdl( LINK( this, ImplListBox, MRUChanged ) ); - maLBWindow.SetEdgeBlending(GetEdgeBlending()); - maLBWindow.Show(); + maLBWindow->SetScrollHdl( LINK( this, ImplListBox, LBWindowScrolled ) ); + maLBWindow->SetMRUChangedHdl( LINK( this, ImplListBox, MRUChanged ) ); + maLBWindow->SetEdgeBlending(GetEdgeBlending()); + maLBWindow->Show(); } ImplListBox::~ImplListBox() { - delete mpHScrollBar; - delete mpVScrollBar; - delete mpScrollBarBox; + disposeOnce(); +} + +void ImplListBox::dispose() +{ + mpHScrollBar.disposeAndClear(); + mpVScrollBar.disposeAndClear(); + mpScrollBarBox.disposeAndClear(); + maLBWindow.disposeAndClear(); + Control::dispose(); } void ImplListBox::Clear() { - maLBWindow.Clear(); + maLBWindow->Clear(); if ( GetEntryList()->GetMRUCount() ) { - maLBWindow.GetEntryList()->SetMRUCount( 0 ); - maLBWindow.SetSeparatorPos( LISTBOX_ENTRY_NOTFOUND ); + maLBWindow->GetEntryList()->SetMRUCount( 0 ); + maLBWindow->SetSeparatorPos( LISTBOX_ENTRY_NOTFOUND ); } mpVScrollBar->SetThumbPos( 0 ); mpHScrollBar->SetThumbPos( 0 ); @@ -2184,7 +2197,7 @@ void ImplListBox::Clear() sal_Int32 ImplListBox::InsertEntry( sal_Int32 nPos, const OUString& rStr ) { ImplEntryType* pNewEntry = new ImplEntryType( rStr ); - sal_Int32 nNewPos = maLBWindow.InsertEntry( nPos, pNewEntry ); + sal_Int32 nNewPos = maLBWindow->InsertEntry( nPos, pNewEntry ); if (nNewPos == LISTBOX_ERROR) { delete pNewEntry; @@ -2197,7 +2210,7 @@ sal_Int32 ImplListBox::InsertEntry( sal_Int32 nPos, const OUString& rStr ) sal_Int32 ImplListBox::InsertEntry( sal_Int32 nPos, const OUString& rStr, const Image& rImage ) { ImplEntryType* pNewEntry = new ImplEntryType( rStr, rImage ); - sal_Int32 nNewPos = maLBWindow.InsertEntry( nPos, pNewEntry ); + sal_Int32 nNewPos = maLBWindow->InsertEntry( nPos, pNewEntry ); if (nNewPos == LISTBOX_ERROR) { delete pNewEntry; @@ -2209,33 +2222,33 @@ sal_Int32 ImplListBox::InsertEntry( sal_Int32 nPos, const OUString& rStr, const void ImplListBox::RemoveEntry( sal_Int32 nPos ) { - maLBWindow.RemoveEntry( nPos ); + maLBWindow->RemoveEntry( nPos ); StateChanged( StateChangedType::DATA ); } void ImplListBox::SetEntryFlags( sal_Int32 nPos, long nFlags ) { - maLBWindow.SetEntryFlags( nPos, nFlags ); + maLBWindow->SetEntryFlags( nPos, nFlags ); } void ImplListBox::SelectEntry( sal_Int32 nPos, bool bSelect ) { - maLBWindow.SelectEntry( nPos, bSelect ); + maLBWindow->SelectEntry( nPos, bSelect ); } void ImplListBox::SetNoSelection() { - maLBWindow.DeselectAll(); + maLBWindow->DeselectAll(); } void ImplListBox::GetFocus() { - maLBWindow.GrabFocus(); + maLBWindow->GrabFocus(); } vcl::Window* ImplListBox::GetPreferredKeyInputWindow() { - return &maLBWindow; + return maLBWindow.get(); } void ImplListBox::Resize() @@ -2359,7 +2372,7 @@ void ImplListBox::ImplCheckScrollBars() void ImplListBox::ImplInitScrollBars() { - Size aOutSz = maLBWindow.GetOutputSizePixel(); + Size aOutSz = maLBWindow->GetOutputSizePixel(); if ( mbVScroll ) { @@ -2396,9 +2409,9 @@ void ImplListBox::ImplResizeControls() // pb: #106948# explicit mirroring for calc // Scrollbar on left or right side? - bool bMirroring = maLBWindow.IsMirroring(); + bool bMirroring = maLBWindow->IsMirroring(); Point aWinPos( bMirroring && mbVScroll ? nSBWidth : 0, 0 ); - maLBWindow.SetPosSizePixel( aWinPos, aInnerSz ); + maLBWindow->SetPosSizePixel( aWinPos, aInnerSz ); // ScrollBarBox if( mbVScroll && mbHScroll ) @@ -2450,7 +2463,7 @@ void ImplListBox::StateChanged( StateChangedType nType ) else if ( ( nType == StateChangedType::UPDATEMODE ) || ( nType == StateChangedType::DATA ) ) { bool bUpdate = IsUpdateMode(); - maLBWindow.SetUpdateMode( bUpdate ); + maLBWindow->SetUpdateMode( bUpdate ); if ( bUpdate && IsReallyVisible() ) ImplCheckScrollBars(); } @@ -2459,30 +2472,30 @@ void ImplListBox::StateChanged( StateChangedType nType ) mpHScrollBar->Enable( IsEnabled() ); mpVScrollBar->Enable( IsEnabled() ); mpScrollBarBox->Enable( IsEnabled() ); - maLBWindow.Enable( IsEnabled() ); + maLBWindow->Enable( IsEnabled() ); Invalidate(); } else if ( nType == StateChangedType::ZOOM ) { - maLBWindow.SetZoom( GetZoom() ); + maLBWindow->SetZoom( GetZoom() ); Resize(); } else if ( nType == StateChangedType::CONTROLFONT ) { - maLBWindow.SetControlFont( GetControlFont() ); + maLBWindow->SetControlFont( GetControlFont() ); } else if ( nType == StateChangedType::CONTROLFOREGROUND ) { - maLBWindow.SetControlForeground( GetControlForeground() ); + maLBWindow->SetControlForeground( GetControlForeground() ); } else if ( nType == StateChangedType::CONTROLBACKGROUND ) { - maLBWindow.SetControlBackground( GetControlBackground() ); + maLBWindow->SetControlBackground( GetControlBackground() ); } else if( nType == StateChangedType::MIRRORING ) { - maLBWindow.EnableRTL( IsRTLEnabled() ); + maLBWindow->EnableRTL( IsRTLEnabled() ); mpHScrollBar->EnableRTL( IsRTLEnabled() ); mpVScrollBar->EnableRTL( IsRTLEnabled() ); ImplResizeControls(); @@ -2517,7 +2530,7 @@ bool ImplListBox::Notify( NotifyEvent& rNEvt ) const Wallpaper& ImplListBox::GetDisplayBackground() const { - return maLBWindow.GetDisplayBackground(); + return maLBWindow->GetDisplayBackground(); } bool ImplListBox::HandleWheelAsCursorTravel( const CommandEvent& rCEvt ) @@ -2542,7 +2555,7 @@ void ImplListBox::SetMRUEntries( const OUString& rEntries, sal_Unicode cSep ) // Remove old MRU entries for ( sal_Int32 n = GetEntryList()->GetMRUCount();n; ) - maLBWindow.RemoveEntry( --n ); + maLBWindow->RemoveEntry( --n ); sal_Int32 nMRUCount = 0; sal_Int32 nIndex = 0; @@ -2553,7 +2566,7 @@ void ImplListBox::SetMRUEntries( const OUString& rEntries, sal_Unicode cSep ) if ( GetEntryList()->FindEntry( aEntry ) != LISTBOX_ENTRY_NOTFOUND ) { ImplEntryType* pNewEntry = new ImplEntryType( aEntry ); - maLBWindow.GetEntryList()->InsertEntry( nMRUCount++, pNewEntry, false ); + maLBWindow->GetEntryList()->InsertEntry( nMRUCount++, pNewEntry, false ); bChanges = true; } } @@ -2561,7 +2574,7 @@ void ImplListBox::SetMRUEntries( const OUString& rEntries, sal_Unicode cSep ) if ( bChanges ) { - maLBWindow.GetEntryList()->SetMRUCount( nMRUCount ); + maLBWindow->GetEntryList()->SetMRUCount( nMRUCount ); SetSeparatorPos( nMRUCount ? nMRUCount-1 : 0 ); StateChanged( StateChangedType::DATA ); } @@ -2584,7 +2597,7 @@ void ImplListBox::SetEdgeBlending(bool bNew) if(mbEdgeBlending != bNew) { mbEdgeBlending = bNew; - maLBWindow.SetEdgeBlending(GetEdgeBlending()); + maLBWindow->SetEdgeBlending(GetEdgeBlending()); } } @@ -2918,6 +2931,18 @@ ImplListBoxFloatingWindow::ImplListBoxFloatingWindow( vcl::Window* pParent ) : } +ImplListBoxFloatingWindow::~ImplListBoxFloatingWindow() +{ + disposeOnce(); +} + +void ImplListBoxFloatingWindow::dispose() +{ + mpImplLB.clear(); + FloatingWindow::dispose(); +} + + bool ImplListBoxFloatingWindow::PreNotify( NotifyEvent& rNEvt ) { if( rNEvt.GetType() == MouseNotifyEvent::LOSEFOCUS ) @@ -2959,13 +2984,13 @@ void ImplListBoxFloatingWindow::setPosSizePixel( long nX, long nY, long nWidth, // this the presence of the vertical Scrollbar has to be known. mpImplLB->SetSizePixel( GetOutputSizePixel() ); ((vcl::Window*)mpImplLB)->Resize(); - ((vcl::Window&)mpImplLB->GetMainWindow()).Resize(); + ((vcl::Window*)mpImplLB->GetMainWindow())->Resize(); } } void ImplListBoxFloatingWindow::Resize() { - mpImplLB->GetMainWindow().ImplClearLayoutData(); + mpImplLB->GetMainWindow()->ImplClearLayoutData(); FloatingWindow::Resize(); } @@ -3085,12 +3110,12 @@ void ImplListBoxFloatingWindow::StartFloat( bool bStartTracking ) mpImplLB->ShowProminentEntry( nPos ); if( bStartTracking ) - mpImplLB->GetMainWindow().EnableMouseMoveSelect( true ); + mpImplLB->GetMainWindow()->EnableMouseMoveSelect( true ); - if ( mpImplLB->GetMainWindow().IsGrabFocusAllowed() ) - mpImplLB->GetMainWindow().GrabFocus(); + if ( mpImplLB->GetMainWindow()->IsGrabFocusAllowed() ) + mpImplLB->GetMainWindow()->GrabFocus(); - mpImplLB->GetMainWindow().ImplClearLayoutData(); + mpImplLB->GetMainWindow()->ImplClearLayoutData(); } } diff --git a/vcl/source/control/longcurr.cxx b/vcl/source/control/longcurr.cxx index 5f081bed20de..77724b0b02d3 100644 --- a/vcl/source/control/longcurr.cxx +++ b/vcl/source/control/longcurr.cxx @@ -468,10 +468,6 @@ LongCurrencyField::LongCurrencyField( vcl::Window* pParent, WinBits nWinStyle ) Reformat(); } -LongCurrencyField::~LongCurrencyField() -{ -} - bool LongCurrencyField::PreNotify( NotifyEvent& rNEvt ) { if( rNEvt.GetType() == MouseNotifyEvent::KEYINPUT ) @@ -546,10 +542,6 @@ LongCurrencyBox::LongCurrencyBox( vcl::Window* pParent, WinBits nWinStyle ) : Reformat(); } -LongCurrencyBox::~LongCurrencyBox() -{ -} - bool LongCurrencyBox::PreNotify( NotifyEvent& rNEvt ) { if( rNEvt.GetType() == MouseNotifyEvent::KEYINPUT ) diff --git a/vcl/source/control/lstbox.cxx b/vcl/source/control/lstbox.cxx index a35c502851fd..06da9a114911 100644 --- a/vcl/source/control/lstbox.cxx +++ b/vcl/source/control/lstbox.cxx @@ -39,7 +39,7 @@ void ListBox::EnableQuickSelection( const bool& b ) { - mpImplLB->GetMainWindow().EnableQuickSelection(b); + mpImplLB->GetMainWindow()->EnableQuickSelection(b); } ListBox::ListBox(WindowType nType) @@ -70,17 +70,19 @@ ListBox::ListBox( vcl::Window* pParent, const ResId& rResId ) : ListBox::~ListBox() { + disposeOnce(); +} + +void ListBox::dispose() +{ CallEventListeners( VCLEVENT_OBJECT_DYING ); - // When destroying the FloatWin TH does a GrabFocus to the Parent: - // that means this "ListBox => PreNotify() ..." - ImplListBox *pImplLB = mpImplLB; - mpImplLB = NULL; - delete pImplLB; + mpImplLB.disposeAndClear(); + mpFloatWin.disposeAndClear(); + mpImplWin.disposeAndClear(); + mpBtn.disposeAndClear(); - delete mpFloatWin; - delete mpImplWin; - delete mpBtn; + Control::dispose(); } void ListBox::ImplInitListBoxData() @@ -130,19 +132,19 @@ void ListBox::ImplInit( vcl::Window* pParent, WinBits nStyle ) } } - mpFloatWin = new ImplListBoxFloatingWindow( this ); + mpFloatWin = VclPtr<ImplListBoxFloatingWindow>::Create( this ); mpFloatWin->SetAutoWidth( true ); mpFloatWin->SetPopupModeEndHdl( LINK( this, ListBox, ImplPopupModeEndHdl ) ); mpFloatWin->GetDropTarget()->addDropTargetListener(xDrop); - mpImplWin = new ImplWin( this, (nStyle & (WB_LEFT|WB_RIGHT|WB_CENTER))|WB_NOBORDER ); + mpImplWin = VclPtr<ImplWin>::Create( this, (nStyle & (WB_LEFT|WB_RIGHT|WB_CENTER))|WB_NOBORDER ); mpImplWin->buttonDownSignal.connect( boost::bind( &ListBox::ImplClickButtonHandler, this, _1 )); mpImplWin->userDrawSignal.connect( boost::bind( &ListBox::ImplUserDrawHandler, this, _1 ) ); mpImplWin->Show(); mpImplWin->GetDropTarget()->addDropTargetListener(xDrop); mpImplWin->SetEdgeBlending(GetEdgeBlending()); - mpBtn = new ImplBtn( this, WB_NOLIGHTBORDER | WB_RECTSTYLE ); + mpBtn = VclPtr<ImplBtn>::Create( this, WB_NOLIGHTBORDER | WB_RECTSTYLE ); ImplInitDropDownButton( mpBtn ); mpBtn->buttonDownSignal.connect( boost::bind( &ListBox::ImplClickButtonHandler, this, _1 )); mpBtn->Show(); @@ -152,7 +154,7 @@ void ListBox::ImplInit( vcl::Window* pParent, WinBits nStyle ) vcl::Window* pLBParent = this; if ( mpFloatWin ) pLBParent = mpFloatWin; - mpImplLB = new ImplListBox( pLBParent, nStyle&(~WB_BORDER) ); + mpImplLB = VclPtr<ImplListBox>::Create( pLBParent, nStyle&(~WB_BORDER) ); mpImplLB->SetSelectHdl( LINK( this, ListBox, ImplSelectHdl ) ); mpImplLB->SetScrollHdl( LINK( this, ListBox, ImplScrollHdl ) ); mpImplLB->SetCancelHdl( LINK( this, ListBox, ImplCancelHdl ) ); @@ -173,7 +175,7 @@ void ListBox::ImplInit( vcl::Window* pParent, WinBits nStyle ) mpImplLB->SetSelectionChangedHdl( LINK( this, ListBox, ImplSelectionChangedHdl ) ); } else - mpImplLB->GetMainWindow().AllowGrabFocus( true ); + mpImplLB->GetMainWindow()->AllowGrabFocus( true ); SetCompoundControl( true ); } @@ -311,7 +313,7 @@ void ListBox::ImplClickButtonHandler( Control* ) ImplClearLayoutData(); if( mpImplLB ) - mpImplLB->GetMainWindow().ImplClearLayoutData(); + mpImplLB->GetMainWindow()->ImplClearLayoutData(); if( mpImplWin ) mpImplWin->ImplClearLayoutData(); } @@ -341,7 +343,7 @@ IMPL_LINK_NOARG(ListBox, ImplPopupModeEndHdl) ImplClearLayoutData(); if( mpImplLB ) - mpImplLB->GetMainWindow().ImplClearLayoutData(); + mpImplLB->GetMainWindow()->ImplClearLayoutData(); if( mpImplWin ) mpImplWin->ImplClearLayoutData(); @@ -369,11 +371,11 @@ void ListBox::ToggleDropDown() void ListBox::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, sal_uLong nFlags ) { - mpImplLB->GetMainWindow().ImplInitSettings( true, true, true ); + mpImplLB->GetMainWindow()->ImplInitSettings( true, true, true ); Point aPos = pDev->LogicToPixel( rPos ); Size aSize = pDev->LogicToPixel( rSize ); - vcl::Font aFont = mpImplLB->GetMainWindow().GetDrawPixelFont( pDev ); + vcl::Font aFont = mpImplLB->GetMainWindow()->GetDrawPixelFont( pDev ); OutDevType eOutDevType = pDev->GetOutDevType(); pDev->Push(); @@ -519,9 +521,15 @@ vcl::Window* ListBox::GetPreferredKeyInputWindow() void ListBox::LoseFocus() { if( IsDropDownBox() ) - mpImplWin->HideFocus(); + { + if (mpImplWin) + mpImplWin->HideFocus(); + } else - mpImplLB->HideFocus(); + { + if (mpImplLB) + mpImplLB->HideFocus(); + } Control::LoseFocus(); } @@ -691,7 +699,7 @@ void ListBox::Resize() void ListBox::FillLayoutData() const { mpControlData->mpLayoutData = new vcl::ControlLayoutData(); - const Control& rMainWin = mpImplLB->GetMainWindow(); + const ImplListBoxWindow* rMainWin = mpImplLB->GetMainWindow(); if( mpFloatWin ) { // Dropdown mode @@ -699,14 +707,14 @@ void ListBox::FillLayoutData() const mpImplWin->SetLayoutDataParent( this ); if( mpFloatWin->IsReallyVisible() ) { - AppendLayoutData( rMainWin ); - rMainWin.SetLayoutDataParent( this ); + AppendLayoutData( *rMainWin ); + rMainWin->SetLayoutDataParent( this ); } } else { - AppendLayoutData( rMainWin ); - rMainWin.SetLayoutDataParent( this ); + AppendLayoutData( *rMainWin ); + rMainWin->SetLayoutDataParent( this ); } } @@ -721,16 +729,16 @@ long ListBox::GetIndexForPoint( const Point& rPoint, sal_Int32& rPos ) const { // Point must be either in main list window // or in impl window (dropdown case) - ImplListBoxWindow& rMain = mpImplLB->GetMainWindow(); + ImplListBoxWindow* rMain = mpImplLB->GetMainWindow(); // Convert coordinates to ImplListBoxWindow pixel coordinate space Point aConvPoint = LogicToPixel( rPoint ); aConvPoint = OutputToAbsoluteScreenPixel( aConvPoint ); - aConvPoint = rMain.AbsoluteScreenToOutputPixel( aConvPoint ); - aConvPoint = rMain.PixelToLogic( aConvPoint ); + aConvPoint = rMain->AbsoluteScreenToOutputPixel( aConvPoint ); + aConvPoint = rMain->PixelToLogic( aConvPoint ); // Try to find entry - sal_Int32 nEntry = rMain.GetEntryPosForPoint( aConvPoint ); + sal_Int32 nEntry = rMain->GetEntryPosForPoint( aConvPoint ); if( nEntry == LISTBOX_ENTRY_NOTFOUND ) { // Not found, maybe dropdown case @@ -803,7 +811,7 @@ void ListBox::StateChanged( StateChangedType nType ) if ( mpImplWin ) { mpImplWin->SetZoom( GetZoom() ); - mpImplWin->SetFont( mpImplLB->GetMainWindow().GetFont() ); + mpImplWin->SetFont( mpImplLB->GetMainWindow()->GetFont() ); mpImplWin->Invalidate(); } Resize(); @@ -814,7 +822,7 @@ void ListBox::StateChanged( StateChangedType nType ) if ( mpImplWin ) { mpImplWin->SetControlFont( GetControlFont() ); - mpImplWin->SetFont( mpImplLB->GetMainWindow().GetFont() ); + mpImplWin->SetFont( mpImplLB->GetMainWindow()->GetFont() ); mpImplWin->Invalidate(); } Resize(); @@ -826,7 +834,7 @@ void ListBox::StateChanged( StateChangedType nType ) { mpImplWin->SetControlForeground( GetControlForeground() ); mpImplWin->SetTextColor( GetControlForeground() ); - mpImplWin->SetFont( mpImplLB->GetMainWindow().GetFont() ); + mpImplWin->SetFont( mpImplLB->GetMainWindow()->GetFont() ); mpImplWin->Invalidate(); } } @@ -843,17 +851,17 @@ void ListBox::StateChanged( StateChangedType nType ) } else { - mpImplWin->SetBackground( mpImplLB->GetMainWindow().GetControlBackground() ); - mpImplWin->SetControlBackground( mpImplLB->GetMainWindow().GetControlBackground() ); + mpImplWin->SetBackground( mpImplLB->GetMainWindow()->GetControlBackground() ); + mpImplWin->SetControlBackground( mpImplLB->GetMainWindow()->GetControlBackground() ); } - mpImplWin->SetFont( mpImplLB->GetMainWindow().GetFont() ); + mpImplWin->SetFont( mpImplLB->GetMainWindow()->GetFont() ); mpImplWin->Invalidate(); } } else if ( nType == StateChangedType::STYLE ) { SetStyle( ImplInitStyle( GetStyle() ) ); - mpImplLB->GetMainWindow().EnableSort( ( GetStyle() & WB_SORT ) != 0 ); + mpImplLB->GetMainWindow()->EnableSort( ( GetStyle() & WB_SORT ) != 0 ); bool bSimpleMode = ( GetStyle() & WB_SIMPLEMODE ) != 0; mpImplLB->SetMultiSelectionSimpleMode( bSimpleMode ); } @@ -1157,8 +1165,8 @@ bool ListBox::IsInDropDown() const Rectangle ListBox::GetBoundingRectangle( sal_Int32 nItem ) const { - Rectangle aRect = mpImplLB->GetMainWindow().GetBoundingRectangle( nItem ); - Rectangle aOffset = mpImplLB->GetMainWindow().GetWindowExtentsRelative( (vcl::Window*)this ); + Rectangle aRect = mpImplLB->GetMainWindow()->GetBoundingRectangle( nItem ); + Rectangle aOffset = mpImplLB->GetMainWindow()->GetWindowExtentsRelative( (vcl::Window*)this ); aRect.Move( aOffset.TopLeft().X(), aOffset.TopLeft().Y() ); return aRect; } @@ -1180,7 +1188,7 @@ void ListBox::EnableMultiSelection( bool bMulti, bool bStackSelection ) // In a MultiSelection, we can't see us travelling without focus if ( mpFloatWin ) - mpImplLB->GetMainWindow().AllowGrabFocus( bMulti ); + mpImplLB->GetMainWindow()->AllowGrabFocus( bMulti ); } bool ListBox::IsMultiSelectionEnabled() const @@ -1348,7 +1356,7 @@ void ListBox::GetMaxVisColumnsAndLines( sal_uInt16& rnCols, sal_uInt16& rnLines float nCharWidth = approximate_char_width(); if ( !IsDropDownBox() ) { - Size aOutSz = mpImplLB->GetMainWindow().GetOutputSizePixel(); + Size aOutSz = mpImplLB->GetMainWindow()->GetOutputSizePixel(); rnCols = (sal_uInt16) (aOutSz.Width()/nCharWidth); rnLines = (sal_uInt16) (aOutSz.Height()/mpImplLB->GetEntryHeight()); } @@ -1371,22 +1379,22 @@ void ListBox::UserDraw( const UserDrawEvent& ) void ListBox::DrawEntry( const UserDrawEvent& rEvt, bool bDrawImage, bool bDrawText, bool bDrawTextAtImagePos ) { - if ( rEvt.GetDevice() == &mpImplLB->GetMainWindow() ) - mpImplLB->GetMainWindow().DrawEntry( rEvt.GetItemId(), bDrawImage, bDrawText, bDrawTextAtImagePos ); + if ( rEvt.GetDevice() == mpImplLB->GetMainWindow() ) + mpImplLB->GetMainWindow()->DrawEntry( rEvt.GetItemId(), bDrawImage, bDrawText, bDrawTextAtImagePos ); else if ( rEvt.GetDevice() == mpImplWin ) mpImplWin->DrawEntry( bDrawImage, bDrawText, bDrawTextAtImagePos ); } void ListBox::SetUserItemSize( const Size& rSz ) { - mpImplLB->GetMainWindow().SetUserItemSize( rSz ); + mpImplLB->GetMainWindow()->SetUserItemSize( rSz ); if ( mpImplWin ) mpImplWin->SetUserItemSize( rSz ); } void ListBox::EnableUserDraw( bool bUserDraw ) { - mpImplLB->GetMainWindow().EnableUserDraw( bUserDraw ); + mpImplLB->GetMainWindow()->EnableUserDraw( bUserDraw ); if ( mpImplWin ) mpImplWin->EnableUserDraw( bUserDraw ); } diff --git a/vcl/source/control/menubtn.cxx b/vcl/source/control/menubtn.cxx index a78c5612ec86..314c41ab7f9f 100644 --- a/vcl/source/control/menubtn.cxx +++ b/vcl/source/control/menubtn.cxx @@ -82,8 +82,14 @@ MenuButton::MenuButton( vcl::Window* pParent, WinBits nWinBits ) MenuButton::~MenuButton() { + disposeOnce(); +} + +void MenuButton::dispose() +{ delete mpMenuTimer; delete mpOwnMenu; + PushButton::dispose(); } IMPL_LINK_NOARG(MenuButton, ImplMenuTimeoutHdl) diff --git a/vcl/source/control/morebtn.cxx b/vcl/source/control/morebtn.cxx index 95cd171afd81..999c3c308d73 100644 --- a/vcl/source/control/morebtn.cxx +++ b/vcl/source/control/morebtn.cxx @@ -22,7 +22,7 @@ #include <tools/rc.h> #include <vector> -typedef ::std::vector< vcl::Window* > ImplMoreWindowList; +typedef ::std::vector< VclPtr<vcl::Window> > ImplMoreWindowList; struct ImplMoreButtonData { @@ -80,8 +80,14 @@ MoreButton::MoreButton( vcl::Window* pParent, WinBits nStyle ) : MoreButton::~MoreButton() { + disposeOnce(); +} + +void MoreButton::dispose() +{ delete mpMBData->mpItemList; delete mpMBData; + PushButton::dispose(); } void MoreButton::Click() diff --git a/vcl/source/control/prgsbar.cxx b/vcl/source/control/prgsbar.cxx index d6443cd16515..a89afac723bb 100644 --- a/vcl/source/control/prgsbar.cxx +++ b/vcl/source/control/prgsbar.cxx @@ -56,10 +56,6 @@ ProgressBar::ProgressBar( vcl::Window* pParent, WinBits nWinStyle ) : ImplInit(); } -ProgressBar::~ProgressBar() -{ -} - void ProgressBar::ImplInitSettings( bool bFont, bool bForeground, bool bBackground ) { diff --git a/vcl/source/control/scrbar.cxx b/vcl/source/control/scrbar.cxx index e31391d27ab3..b239c623e3ff 100644 --- a/vcl/source/control/scrbar.cxx +++ b/vcl/source/control/scrbar.cxx @@ -125,7 +125,13 @@ ScrollBar::ScrollBar( vcl::Window* pParent, WinBits nStyle ) : ScrollBar::~ScrollBar() { - delete mpData; + disposeOnce(); +} + +void ScrollBar::dispose() +{ + delete mpData; mpData = NULL; + Control::dispose(); } void ScrollBar::ImplUpdateRects( bool bUpdate ) diff --git a/vcl/source/control/spinbtn.cxx b/vcl/source/control/spinbtn.cxx index 9b16b4753751..c9feafa07663 100644 --- a/vcl/source/control/spinbtn.cxx +++ b/vcl/source/control/spinbtn.cxx @@ -55,10 +55,6 @@ SpinButton::SpinButton( vcl::Window* pParent, WinBits nStyle ) ImplInit( pParent, nStyle ); } -SpinButton::~SpinButton() -{ -} - IMPL_LINK( SpinButton, ImplTimeout, Timer*, pTimer ) { if ( pTimer->GetTimeout() == GetSettings().GetMouseSettings().GetButtonStartRepeat() ) diff --git a/vcl/source/control/spinfld.cxx b/vcl/source/control/spinfld.cxx index 972bded96429..fe1feea8ef05 100644 --- a/vcl/source/control/spinfld.cxx +++ b/vcl/source/control/spinfld.cxx @@ -286,7 +286,7 @@ void ImplDrawSpinButton( OutputDevice* pOutDev, void SpinField::ImplInitSpinFieldData() { - mpEdit = NULL; + mpEdit.disposeAndClear(); mbSpin = false; mbRepeat = false; mbUpperIn = false; @@ -311,11 +311,11 @@ void SpinField::ImplInit( vcl::Window* pParent, WinBits nWinStyle ) if ( (nWinStyle & WB_SPIN) && ImplUseNativeBorder( nWinStyle ) ) { SetBackground(); - mpEdit = new Edit( this, WB_NOBORDER ); + mpEdit.set( VclPtr<Edit>::Create( this, WB_NOBORDER ) ); mpEdit->SetBackground(); } else - mpEdit = new Edit( this, WB_NOBORDER ); + mpEdit.set( VclPtr<Edit>::Create( this, WB_NOBORDER ) ); mpEdit->EnableRTL( false ); mpEdit->SetPosPixel( Point() ); @@ -359,7 +359,14 @@ SpinField::SpinField( vcl::Window* pParent, const ResId& rResId ) : SpinField::~SpinField() { - delete mpEdit; + disposeOnce(); +} + +void SpinField::dispose() +{ + mpEdit.disposeAndClear(); + + Edit::dispose(); } void SpinField::Up() diff --git a/vcl/source/control/tabctrl.cxx b/vcl/source/control/tabctrl.cxx index ca63e5485d68..3bf2d59598d6 100644 --- a/vcl/source/control/tabctrl.cxx +++ b/vcl/source/control/tabctrl.cxx @@ -42,7 +42,7 @@ struct ImplTabItem { sal_uInt16 mnId; - TabPage* mpTabPage; + VclPtr<TabPage> mpTabPage; OUString maText; OUString maFormatText; OUString maHelpText; @@ -67,7 +67,7 @@ struct ImplTabCtrlData std::vector< Rectangle > maTabRectangles; Point maItemsOffset; // offset of the tabitems std::vector< ImplTabItem > maItemList; - ListBox* mpListBox; + VclPtr<ListBox> mpListBox; }; #define TAB_OFFSET 3 @@ -112,7 +112,7 @@ void TabControl::ImplInit( vcl::Window* pParent, WinBits nStyle ) if( (nStyle & WB_DROPDOWN) ) { - mpTabCtrlData->mpListBox = new ListBox( this, WB_DROPDOWN ); + mpTabCtrlData->mpListBox = VclPtr<ListBox>::Create( this, WB_DROPDOWN ); mpTabCtrlData->mpListBox->SetPosSizePixel( Point( 0, 0 ), Size( 200, 20 ) ); mpTabCtrlData->mpListBox->SetSelectHdl( LINK( this, TabControl, ImplListBoxSelectHdl ) ); mpTabCtrlData->mpListBox->Show(); @@ -192,6 +192,11 @@ TabControl::TabControl( vcl::Window* pParent, WinBits nStyle ) : TabControl::~TabControl() { + disposeOnce(); +} + +void TabControl::dispose() +{ Window *pParent = GetParent(); if (pParent && pParent->IsDialog()) GetParent()->RemoveChildEventListener( LINK( this, TabControl, ImplWindowEventListener ) ); @@ -199,12 +204,11 @@ TabControl::~TabControl() ImplFreeLayoutData(); // delete TabCtrl data - if ( mpTabCtrlData ) - { - if( mpTabCtrlData->mpListBox ) - delete mpTabCtrlData->mpListBox; - delete mpTabCtrlData; - } + if (mpTabCtrlData) + mpTabCtrlData->mpListBox.disposeAndClear(); + delete mpTabCtrlData; + mpTabCtrlData = NULL; + Control::dispose(); } ImplTabItem* TabControl::ImplGetItem( sal_uInt16 nId ) const @@ -574,9 +578,9 @@ void TabControl::ImplChangeTabPage( sal_uInt16 nId, sal_uInt16 nOldId ) ImplTabItem* pOldItem = ImplGetItem( nOldId ); ImplTabItem* pItem = ImplGetItem( nId ); - TabPage* pOldPage = (pOldItem) ? pOldItem->mpTabPage : NULL; - TabPage* pPage = (pItem) ? pItem->mpTabPage : NULL; - vcl::Window* pCtrlParent = GetParent(); + TabPage* pOldPage = (pOldItem) ? pOldItem->mpTabPage.get() : NULL; + TabPage* pPage = (pItem) ? pItem->mpTabPage.get() : NULL; + vcl::Window* pCtrlParent = GetParent(); if ( IsReallyVisible() && IsUpdateMode() ) { @@ -1013,7 +1017,7 @@ IMPL_LINK( TabControl, ImplWindowEventListener, VclSimpleEvent*, pEvent ) void TabControl::MouseButtonDown( const MouseEvent& rMEvt ) { - if( mpTabCtrlData->mpListBox == NULL ) + if( mpTabCtrlData->mpListBox.get() == NULL ) { if( rMEvt.IsLeft() ) { @@ -1083,7 +1087,7 @@ void TabControl::ImplPaint( const Rectangle& rRect, bool bLayout ) // in this case we're only interested in the top border of the tabpage because the tabitems are used // standalone (eg impress) bool bNoTabPage = false; - TabPage* pCurPage = pCurItem ? pCurItem->mpTabPage : NULL; + TabPage* pCurPage = pCurItem ? pCurItem->mpTabPage.get() : NULL; if( !pCurPage || !pCurPage->IsVisible() ) { bNoTabPage = true; @@ -1169,7 +1173,7 @@ void TabControl::ImplPaint( const Rectangle& rRect, bool bLayout ) } } - if ( !mpTabCtrlData->maItemList.empty() && mpTabCtrlData->mpListBox == NULL ) + if ( !mpTabCtrlData->maItemList.empty() && mpTabCtrlData->mpListBox == nullptr ) { // Some native toolkits (GTK+) draw tabs right-to-left, with an // overlap between adjacent tabs @@ -1427,7 +1431,7 @@ void TabControl::RequestHelp( const HelpEvent& rHEvt ) void TabControl::Command( const CommandEvent& rCEvt ) { - if( (mpTabCtrlData->mpListBox == NULL) && (rCEvt.GetCommand() == COMMAND_CONTEXTMENU) && (GetPageCount() > 1) ) + if( (mpTabCtrlData->mpListBox == nullptr) && (rCEvt.GetCommand() == COMMAND_CONTEXTMENU) && (GetPageCount() > 1) ) { Point aMenuPos; bool bMenu; @@ -1879,7 +1883,7 @@ void TabControl::SetTabPage( sal_uInt16 nPageId, TabPage* pTabPage ) { ImplTabItem* pItem = ImplGetItem( nPageId ); - if ( pItem && (pItem->mpTabPage != pTabPage) ) + if ( pItem && (pItem->mpTabPage.get() != pTabPage) ) { if ( pTabPage ) { diff --git a/vcl/source/control/throbber.cxx b/vcl/source/control/throbber.cxx index 347f24a32e31..eedadc4e5637 100644 --- a/vcl/source/control/throbber.cxx +++ b/vcl/source/control/throbber.cxx @@ -59,7 +59,13 @@ Throbber::Throbber( vcl::Window* i_parentWindow, WinBits i_style, const ImageSet Throbber::~Throbber() { + disposeOnce(); +} + +void Throbber::dispose() +{ maWaitTimer.Stop(); + ImageControl::dispose(); } namespace |