[Libreoffice-commits] core.git: Branch 'feature/vclptr' - 5 commits - include/rtl include/vcl vcl/qa vcl/README.lifecycle vcl/source vcl/unx vcl/workben
Michael Meeks
michael.meeks at collabora.com
Fri Apr 10 05:08:17 PDT 2015
include/rtl/ref.hxx | 8 +++++
include/vcl/vclptr.hxx | 50 ++++++++++++++++++++++++++++++++++--
vcl/README.lifecycle | 36 +++++++++++++++++++------
vcl/qa/cppunit/lifecycle.cxx | 20 ++++++++------
vcl/source/app/dbggui.cxx | 4 +-
vcl/source/gdi/print2.cxx | 4 +-
vcl/source/gdi/print3.cxx | 10 ++++---
vcl/source/outdev/map.cxx | 3 --
vcl/source/outdev/outdev.cxx | 2 -
vcl/source/window/builder.cxx | 3 +-
vcl/source/window/dialog.cxx | 2 -
vcl/source/window/menubarwindow.cxx | 2 -
vcl/source/window/paint.cxx | 2 -
vcl/source/window/printdlg.cxx | 6 ++--
vcl/source/window/syswin.cxx | 1
vcl/source/window/toolbox.cxx | 2 -
vcl/source/window/toolbox2.cxx | 14 +++++-----
vcl/unx/generic/printer/cupsmgr.cxx | 2 -
vcl/unx/x11/x11sys.cxx | 2 -
vcl/workben/outdevgrind.cxx | 2 -
20 files changed, 126 insertions(+), 49 deletions(-)
New commits:
commit f59c489e642059fc060054222505b544893a3873
Author: Michael Meeks <michael.meeks at collabora.com>
Date: Mon Mar 30 21:49:04 2015 +0100
Convert more sites to VclPtrInstance.
Change-Id: I364c5eb176d5003deb1938810cccf4f2aaedbd59
diff --git a/vcl/qa/cppunit/lifecycle.cxx b/vcl/qa/cppunit/lifecycle.cxx
index 7c1b1c2..cbe0ef6 100644
--- a/vcl/qa/cppunit/lifecycle.cxx
+++ b/vcl/qa/cppunit/lifecycle.cxx
@@ -68,8 +68,8 @@ void LifecycleTest::testVirtualDevice()
void LifecycleTest::testMultiDispose()
{
- VclPtr<WorkWindow> xWin(new WorkWindow((vcl::Window *)NULL,
- WB_APP|WB_STDWORK));
+ VclPtrInstance<WorkWindow> xWin((vcl::Window *)NULL,
+ WB_APP|WB_STDWORK);
CPPUNIT_ASSERT(xWin.get() != NULL);
xWin->disposeOnce();
xWin->disposeOnce();
@@ -122,8 +122,8 @@ public:
void LifecycleTest::testChildDispose()
{
- VclPtr<WorkWindow> xWin(new WorkWindow((vcl::Window *)NULL,
- WB_APP|WB_STDWORK));
+ VclPtrInstance<WorkWindow> xWin((vcl::Window *)NULL,
+ WB_APP|WB_STDWORK);
CPPUNIT_ASSERT(xWin.get() != NULL);
VclPtr<DisposableChild> xChild(new DisposableChild(xWin.get()));
xWin->Show();
diff --git a/vcl/source/app/dbggui.cxx b/vcl/source/app/dbggui.cxx
index f3ebc74..7d099d6 100644
--- a/vcl/source/app/dbggui.cxx
+++ b/vcl/source/app/dbggui.cxx
@@ -354,9 +354,9 @@ IMPL_LINK( DbgDialog, ClickHdl, Button*, pButton )
}
if( (aData.nTestFlags & ~IMMEDIATE_FLAGS) != (pData->nTestFlags & ~IMMEDIATE_FLAGS) )
{
- ScopedVclPtr<MessageDialog> aBox(new MessageDialog(this, OUString(
+ ScopedVclPtrInstance<MessageDialog> aBox(this, OUString(
"Some of the changed settings will only be active after "
- "restarting the process"), VCL_MESSAGE_INFO));
+ "restarting the process"), VCL_MESSAGE_INFO);
aBox->Execute();
}
EndDialog( RET_OK );
diff --git a/vcl/source/gdi/print2.cxx b/vcl/source/gdi/print2.cxx
index 2ea36cc..f66c139 100644
--- a/vcl/source/gdi/print2.cxx
+++ b/vcl/source/gdi/print2.cxx
@@ -1155,10 +1155,10 @@ bool OutputDevice::RemoveTransparenciesFromMetaFile( const GDIMetaFile& rInMtf,
Point aDstPtPix( aBoundRect.TopLeft() );
Size aDstSzPix;
- ScopedVclPtr<VirtualDevice> aMapVDev( new VirtualDevice() ); // here, we record only mapmode information
+ ScopedVclPtrInstance<VirtualDevice> aMapVDev; // here, we record only mapmode information
aMapVDev->EnableOutput(false);
- ScopedVclPtr<VirtualDevice> aPaintVDev( new VirtualDevice() ); // into this one, we render.
+ ScopedVclPtrInstance<VirtualDevice> aPaintVDev; // into this one, we render.
aPaintVDev->SetBackground( aBackgroundComponent.aBgColor );
rOutMtf.AddAction( new MetaPushAction( PushFlags::MAPMODE ) );
diff --git a/vcl/source/gdi/print3.cxx b/vcl/source/gdi/print3.cxx
index b5e7845..d3f5211 100644
--- a/vcl/source/gdi/print3.cxx
+++ b/vcl/source/gdi/print3.cxx
@@ -305,8 +305,9 @@ void Printer::PreparePrintJob(std::shared_ptr<PrinterController> xController,
{
if (xController->isShowDialogs())
{
- ScopedVclPtr<MessageDialog> aBox(new MessageDialog(NULL, "ErrorNoPrinterDialog",
- "vcl/ui/errornoprinterdialog.ui"));
+ ScopedVclPtrInstance<MessageDialog> aBox(
+ nullptr, "ErrorNoPrinterDialog",
+ "vcl/ui/errornoprinterdialog.ui");
aBox->Execute();
}
xController->setValue( OUString( "IsDirect" ),
@@ -454,8 +455,9 @@ void Printer::PreparePrintJob(std::shared_ptr<PrinterController> xController,
{
if( xController->getFilteredPageCount() == 0 )
{
- ScopedVclPtr<MessageDialog> aBox(new MessageDialog(NULL, "ErrorNoContentDialog",
- "vcl/ui/errornocontentdialog.ui"));
+ ScopedVclPtrInstance<MessageDialog> aBox(
+ nullptr, "ErrorNoContentDialog",
+ "vcl/ui/errornocontentdialog.ui");
aBox->Execute();
return;
}
diff --git a/vcl/source/outdev/map.cxx b/vcl/source/outdev/map.cxx
index 753e297..e7eed88 100644
--- a/vcl/source/outdev/map.cxx
+++ b/vcl/source/outdev/map.cxx
@@ -232,9 +232,8 @@ static void ImplCalcMapResolution( const MapMode& rMapMode,
vcl::Window::ImplInitAppFontData( pSVData->maWinData.mpFirstFrame );
else
{
- VclPtr<WorkWindow> pWin = new WorkWindow( NULL, 0 );
+ ScopedVclPtrInstance<WorkWindow> pWin( nullptr, 0 );
vcl::Window::ImplInitAppFontData( pWin );
- pWin.disposeAndClear();
}
}
rMapRes.mnMapScNumX = pSVData->maGDIData.mnAppFontX;
diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx
index 7a4bd3d..e6cb65a 100644
--- a/vcl/source/window/builder.cxx
+++ b/vcl/source/window/builder.cxx
@@ -1770,6 +1770,7 @@ 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< Window > xWindow( pWindow, SAL_NO_ACQUIRE );
pWindow->SetHelpId(m_sHelpRoot + id);
SAL_INFO("vcl.layout", "for " << name.getStr() <<
", created " << pWindow << " child of " <<
@@ -1777,7 +1778,7 @@ vcl::Window *VclBuilder::makeObject(vcl::Window *pParent, const OString &name, c
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;
}
commit c7f3e599da3f4adf0c8cfe6e087948dc8f61bcce
Author: Michael Meeks <michael.meeks at collabora.com>
Date: Mon Mar 30 17:52:43 2015 +0100
Revert part of "Unwind mpDialogParent oddness."
Now its ok to reference / un-reference ourself during construction.
Change-Id: Ib3b302719c7d40d7a42272f93db5e4c437859cad
diff --git a/include/vcl/dockwin.hxx b/include/vcl/dockwin.hxx
index bd334ea..71c8181 100644
--- a/include/vcl/dockwin.hxx
+++ b/include/vcl/dockwin.hxx
@@ -261,7 +261,7 @@ private:
mbIsCalculatingInitialLayoutSize:1,
mbInitialLayoutDone:1;
- vcl::Window *mpDialogParent; // deliberately not a VclPtr
+ VclPtr<vcl::Window> mpDialogParent;
SAL_DLLPRIVATE void ImplInitDockingWindowData();
SAL_DLLPRIVATE void setPosSizeOnContainee(Size aSize, Window &rBox);
diff --git a/include/vcl/syswin.hxx b/include/vcl/syswin.hxx
index 5609d57..f90fb16 100644
--- a/include/vcl/syswin.hxx
+++ b/include/vcl/syswin.hxx
@@ -149,7 +149,7 @@ private:
Idle maLayoutIdle;
protected:
bool mbIsDefferedInit;
- vcl::Window *mpDialogParent; // deliberately not a VclPtr
+ VclPtr<vcl::Window> mpDialogParent;
public:
using Window::ImplIsInTaskPaneList;
SAL_DLLPRIVATE bool ImplIsInTaskPaneList( vcl::Window* pWin );
diff --git a/vcl/source/window/dialog.cxx b/vcl/source/window/dialog.cxx
index e59ba30..0e29d4a 100644
--- a/vcl/source/window/dialog.cxx
+++ b/vcl/source/window/dialog.cxx
@@ -488,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;
commit 582e89610b366c0d887baa6b8de7fa5f065900fa
Author: Michael Meeks <michael.meeks at collabora.com>
Date: Mon Mar 30 17:49:20 2015 +0100
vclptr: create Instance helpers, and set initial ref-count to 1.
Document that in README.lifecycle; the problem is that our constructors
currently take and release references left/right on the object being
created, which ... means we need an initial reference.
Change-Id: I5de952b73ac67888c3fbb150d4a7cde2a7bc9abf
diff --git a/include/rtl/ref.hxx b/include/rtl/ref.hxx
index 942923a..097584b 100644
--- a/include/rtl/ref.hxx
+++ b/include/rtl/ref.hxx
@@ -49,6 +49,13 @@ public:
/** Constructor...
*/
+ inline Reference (reference_type * pBody, __sal_NoAcquire)
+ : m_pBody (pBody)
+ {
+ }
+
+ /** Constructor...
+ */
inline Reference (reference_type * pBody)
: m_pBody (pBody)
{
@@ -56,7 +63,6 @@ public:
m_pBody->acquire();
}
-
/** Copy constructor...
*/
inline Reference (const Reference<reference_type> & handle)
diff --git a/include/vcl/vclptr.hxx b/include/vcl/vclptr.hxx
index 6ab6373..0c29f11 100644
--- a/include/vcl/vclptr.hxx
+++ b/include/vcl/vclptr.hxx
@@ -22,6 +22,7 @@
#include <rtl/ref.hxx>
#include <cstddef>
+#include <utility>
/// @cond INTERNAL
namespace vcl { namespace detail {
@@ -90,14 +91,12 @@ public:
: m_rInnerRef()
{}
-
/** Constructor...
*/
inline VclPtr (reference_type * pBody)
: m_rInnerRef(pBody)
{}
-
/** Copy constructor...
*/
inline VclPtr (const VclPtr<reference_type> & handle)
@@ -216,8 +215,31 @@ public:
{
return (m_rInnerRef > handle.m_rInnerRef);
}
+
+protected:
+ inline VclPtr (reference_type * pBody, __sal_NoAcquire)
+ : m_rInnerRef(pBody, SAL_NO_ACQUIRE)
+ {}
}; // class VclPtr
+/**
+ * A construction helper for VclPtr. Since VclPtr types are created
+ * with a reference-count of one - to help fit into the existing
+ * code-flow; this helps us to construct them easily.
+ *
+ * For more details on the design please see vcl/README.lifecycle
+ *
+ * @param reference_type must be a subclass of vcl::Window
+ */
+template <class reference_type>
+class VclPtrInstance : public VclPtr<reference_type>
+{
+public:
+ template<typename... Arg> VclPtrInstance(Arg &&... arg)
+ : VclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE )
+ {
+ }
+};
template <class reference_type>
class ScopedVclPtr : public VclPtr<reference_type>
@@ -277,6 +299,30 @@ private:
ScopedVclPtr (const ScopedVclPtr<reference_type> &) SAL_DELETED_FUNCTION;
// And certainly we don't want a default assignment operator.
ScopedVclPtr<reference_type>& SAL_CALL operator= (const ScopedVclPtr<reference_type> &) SAL_DELETED_FUNCTION;
+
+protected:
+ inline ScopedVclPtr (reference_type * pBody, __sal_NoAcquire)
+ : VclPtr<reference_type>(pBody, SAL_NO_ACQUIRE)
+ {}
+};
+
+/**
+ * A construction helper for ScopedVclPtr. Since VclPtr types are created
+ * with a reference-count of one - to help fit into the existing
+ * code-flow; this helps us to construct them easily.
+ *
+ * For more details on the design please see vcl/README.lifecycle
+ *
+ * @param reference_type must be a subclass of vcl::Window
+ */
+template <class reference_type>
+class ScopedVclPtrInstance : public ScopedVclPtr<reference_type>
+{
+public:
+ template<typename... Arg> ScopedVclPtrInstance(Arg &&... arg)
+ : ScopedVclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE )
+ {
+ }
};
#endif // INCLUDED_VCL_PTR_HXX
diff --git a/vcl/README.lifecycle b/vcl/README.lifecycle
index 26e7a34..6a9e080 100644
--- a/vcl/README.lifecycle
+++ b/vcl/README.lifecycle
@@ -45,8 +45,9 @@ to lingering pointers to freed objects.
to reduce code-thrash. VclPtr is used to wrap all OutputDevice
derived classes thus:
- VclPtr<Dialog> pDialog( new Dialog( ... ) );
- // gotcha - this is not a good idea ...
+ VclPtr<Dialog> pDialog( new Dialog( ... ), SAL_NO_ACQUIRE );
+ ...
+ pDialog.disposeAndClear();
However - while the VclPtr reference count controls the
lifecycle of the Dialog object, it is necessary to be able to
@@ -84,30 +85,47 @@ to lingering pointers to freed objects.
Luckily it is easy to avoid that with a ScopedVclPtr which
does this for you when it goes out of scope.
+** One extra gotcha - an initial reference-count of 1
+
+ In the normal world of love and sanity, eg. creating UNO
+ objects, the objects start with a ref-count of zero. Thus
+ the first reference is always taken after construction by
+ the surrounding smart pointer.
+
+ Unfortunately, the existing VCL code is somewhat tortured,
+ and does a lot of reference and de-reference action on the
+ class -during- construction. This forces us to construct with
+ a reference of 1 - and to hand that into the initial smart
+ pointer with a SAL_NO_ACQUIRE.
+
+ To make this easier, we have 'Instance' template wrappers
+ that make this apparently easier, by constructing the
+ pointer for you.
+
** How does my familiar code change ?
Lets tweak the exemplary code above to fit the new model:
-- Dialog aDialog(...);
+- Dialog aDialog(... dialog params ... );
- aDialog.Execute(...);
-+ ScopedVclPtr<Dialog> pDialog(new Dialog(...));
++ ScopedVclPtrInstance<Dialog> pDialog(... dialog params ... );
+ pDialog->Execute(...); // VclPtr behaves much like a pointer
or:
-- Dialog *pDialog = new Dialog(...);
-+ VclPtr<Dialog> pDialog(newDialog(...));
+- Dialog *pDialog = new Dialog(... dialog params ...);
++ VclPtrInstance<Dialog> pDialog(... dialog params ...);
pDialog->Execute(...);
- delete pDialog;
+ pDialog.disposeAndClear(); // done manually - replaces a delete
or:
-- boost::shared_ptr<Dialog> xDialog(new pDialog());
-+ ScopedVclPtr<Dialog> xDialog(new Dialog(...));
+- boost::shared_ptr<Dialog> xDialog(new Dialog(...));
++ ScopedVclPtrInstance<Dialog> xDialog(...);
xDialog->Execute(...);
+ // depending how shared_ptr was shared perhaps
+ // someone else gets a VclPtr to xDialog
or:
- VirtualDevice aDev;
-+ ScopedVclPtr<VirtualDevice> pDev(new VirtualDevice());
++ ScopedVclPtrInstance<VirtualDevice> pDev();
** Why are these 'disposeOnce' calls in destructors ?
diff --git a/vcl/qa/cppunit/lifecycle.cxx b/vcl/qa/cppunit/lifecycle.cxx
index 12b0a51..7c1b1c2 100644
--- a/vcl/qa/cppunit/lifecycle.cxx
+++ b/vcl/qa/cppunit/lifecycle.cxx
@@ -59,7 +59,11 @@ void LifecycleTest::testCast()
void LifecycleTest::testVirtualDevice()
{
- VclPtr<VirtualDevice> pVDev = new VirtualDevice();
+ VclPtr<VirtualDevice> pVDev( new VirtualDevice() );
+ ScopedVclPtr<VirtualDevice> pVDev2( new VirtualDevice() );
+ VclPtrInstance<VirtualDevice> pVDev3;
+ VclPtrInstance<VirtualDevice> pVDev4( 1 );
+ CPPUNIT_ASSERT(!!pVDev && !!pVDev2 && !!pVDev3 && !!pVDev4);
}
void LifecycleTest::testMultiDispose()
@@ -99,8 +103,8 @@ void LifecycleTest::testIsolatedWidgets()
void LifecycleTest::testParentedWidgets()
{
- VclPtr<WorkWindow> xWin(new WorkWindow((vcl::Window *)NULL,
- WB_APP|WB_STDWORK));
+ ScopedVclPtrInstance<WorkWindow> xWin(new WorkWindow((vcl::Window *)NULL,
+ WB_APP|WB_STDWORK));
CPPUNIT_ASSERT(xWin.get() != NULL);
xWin->Show();
testWidgets(xWin);
@@ -129,7 +133,7 @@ void LifecycleTest::testChildDispose()
void LifecycleTest::testPostDispose()
{
- VclPtr<WorkWindow> xWin(new WorkWindow((vcl::Window *)NULL, WB_STDWORK));
+ VclPtrInstance<WorkWindow> xWin((vcl::Window *)NULL, WB_STDWORK);
xWin->disposeOnce();
// check selected methods continue to work post-dispose
diff --git a/vcl/source/outdev/outdev.cxx b/vcl/source/outdev/outdev.cxx
index beee1b7..e42c8c5 100644
--- a/vcl/source/outdev/outdev.cxx
+++ b/vcl/source/outdev/outdev.cxx
@@ -82,7 +82,7 @@ namespace {
// Begin initializer and accessor public functions
OutputDevice::OutputDevice() :
- mnRefCnt(0),
+ mnRefCnt(1), // cf. VclPtrInstance and README.lifecycle
maRegion(true),
maFillColor( COL_WHITE ),
maTextLineColor( COL_TRANSPARENT ),
diff --git a/vcl/source/window/dialog.cxx b/vcl/source/window/dialog.cxx
index 9ca9c30..e59ba30 100644
--- a/vcl/source/window/dialog.cxx
+++ b/vcl/source/window/dialog.cxx
@@ -1065,7 +1065,7 @@ void Dialog::GrabFocusToFirstControl()
void Dialog::GetDrawWindowBorder( sal_Int32& rLeftBorder, sal_Int32& rTopBorder, sal_Int32& rRightBorder, sal_Int32& rBottomBorder ) const
{
- ScopedVclPtr<ImplBorderWindow> aImplWin( new ImplBorderWindow( (vcl::Window*)this, WB_BORDER|WB_STDWORK, BORDERWINDOW_STYLE_OVERLAP ) );
+ ScopedVclPtrInstance<ImplBorderWindow> aImplWin( (vcl::Window*)this, WB_BORDER|WB_STDWORK, BORDERWINDOW_STYLE_OVERLAP );
aImplWin->GetBorder( rLeftBorder, rTopBorder, rRightBorder, rBottomBorder );
}
diff --git a/vcl/source/window/menubarwindow.cxx b/vcl/source/window/menubarwindow.cxx
index 0f49c51..7c0bca7 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()
{
- ScopedVclPtr<ToolBox> aTbx( new ToolBox(GetParent()) );
+ ScopedVclPtrInstance<ToolBox> aTbx( GetParent() );
if( GetItemCount() == 0 )
{
ResMgr* pResMgr = ImplGetResMgr();
diff --git a/vcl/source/window/paint.cxx b/vcl/source/window/paint.cxx
index 0f05ded..1dd9b3a 100644
--- a/vcl/source/window/paint.cxx
+++ b/vcl/source/window/paint.cxx
@@ -1094,7 +1094,7 @@ void Window::ImplPaintToDevice( OutputDevice* i_pTargetOutDev, const Point& i_rP
mpWindowImpl->mbReallyVisible = bRVisible;
// paint metafile to VDev
- VclPtr<VirtualDevice> pMaskedDevice = new VirtualDevice( *i_pTargetOutDev, 0, 0 );
+ VclPtrInstance<VirtualDevice> pMaskedDevice( *i_pTargetOutDev, 0, 0 );
pMaskedDevice->SetOutputSizePixel( GetOutputSizePixel() );
pMaskedDevice->EnableRTL( IsRTLEnabled() );
aMtf.WindStart();
diff --git a/vcl/source/window/printdlg.cxx b/vcl/source/window/printdlg.cxx
index 4ab06b6..f173ad3 100644
--- a/vcl/source/window/printdlg.cxx
+++ b/vcl/source/window/printdlg.cxx
@@ -624,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( VclPtr<Printer>( new Printer( aValue ) ) );
+ maPController->setPrinter( VclPtrInstance<Printer>( aValue ) );
}
else
{
// fall back to default printer
maJobPage.mpPrinters->SelectEntry( Printer::GetDefaultPrinterName() );
- maPController->setPrinter( VclPtr<Printer>( new Printer( Printer::GetDefaultPrinterName() ) ) );
+ maPController->setPrinter( VclPtrInstance<Printer>( Printer::GetDefaultPrinterName() ) );
}
}
// not printing to file
@@ -1521,7 +1521,7 @@ IMPL_LINK( PrintDialog, SelectHdl, ListBox*, pBox )
{
OUString aNewPrinter( pBox->GetSelectEntry() );
// set new printer
- maPController->setPrinter( VclPtr<Printer>( new Printer( aNewPrinter ) ) );
+ maPController->setPrinter( VclPtrInstance<Printer>( aNewPrinter ) );
maPController->resetPrinterOptions( maOptionsPage.mpToFileBox->IsChecked() );
// update text fields
updatePrinterText();
diff --git a/vcl/source/window/toolbox.cxx b/vcl/source/window/toolbox.cxx
index 58ec924..b434061 100644
--- a/vcl/source/window/toolbox.cxx
+++ b/vcl/source/window/toolbox.cxx
@@ -4833,7 +4833,7 @@ Size ToolBox::CalcMinimumWindowSizePixel() const
else
{
// create dummy toolbox for measurements
- VclPtr< 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();
diff --git a/vcl/unx/generic/printer/cupsmgr.cxx b/vcl/unx/generic/printer/cupsmgr.cxx
index daddd1a..d51f752 100644
--- a/vcl/unx/generic/printer/cupsmgr.cxx
+++ b/vcl/unx/generic/printer/cupsmgr.cxx
@@ -966,7 +966,7 @@ namespace
{
bool bRet = false;
- ScopedVclPtr<RTSPWDialog> aDialog(new RTSPWDialog(rServer, rUserName, NULL));
+ ScopedVclPtrInstance<RTSPWDialog> aDialog(rServer, rUserName, nullptr);
if (aDialog->Execute())
{
rUserName = aDialog->getUserName();
diff --git a/vcl/unx/x11/x11sys.cxx b/vcl/unx/x11/x11sys.cxx
index 8cad695..6723c63 100644
--- a/vcl/unx/x11/x11sys.cxx
+++ b/vcl/unx/x11/x11sys.cxx
@@ -134,7 +134,7 @@ int X11SalSystem::ShowNativeDialog( const OUString& rTitle, const OUString& rMes
if( pSVData->mpIntroWindow )
pSVData->mpIntroWindow->Hide();
- ScopedVclPtr<WarningBox> aWarn(new WarningBox(NULL, WB_STDWORK, rMessage) );
+ ScopedVclPtrInstance<WarningBox> aWarn(nullptr, WB_STDWORK, rMessage);
aWarn->SetText( rTitle );
aWarn->Clear();
diff --git a/vcl/workben/outdevgrind.cxx b/vcl/workben/outdevgrind.cxx
index d530748..da14e1a 100644
--- a/vcl/workben/outdevgrind.cxx
+++ b/vcl/workben/outdevgrind.cxx
@@ -898,7 +898,7 @@ sal_uInt16 GrindApp::Exception( sal_uInt16 nError )
int GrindApp::Main()
{
- ScopedVclPtr<TestWindow> aWindow(new TestWindow);
+ ScopedVclPtrInstance<TestWindow> aWindow;
aWindow->Execute();
return 0;
}
commit 49dadad0b55f879ebe5daf539a97043d283ad0a8
Author: Michael Meeks <michael.meeks at collabora.com>
Date: Fri Mar 27 14:51:14 2015 +0000
Encourage disposed toolbox items to play nicely.
Change-Id: I4a28ba4740e9c84666cd85c046598862f20a7a96
diff --git a/vcl/source/window/toolbox2.cxx b/vcl/source/window/toolbox2.cxx
index 574705a..3b1ad8f 100644
--- a/vcl/source/window/toolbox2.cxx
+++ b/vcl/source/window/toolbox2.cxx
@@ -867,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
@@ -877,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;
}
commit 7df35a2e92fa9fb548bbca0d0935f055e56e6d10
Author: Michael Meeks <michael.meeks at collabora.com>
Date: Fri Mar 27 14:36:47 2015 +0000
Unwind mpDialogParent oddness.
This pointer is used to pass extra information through dialog
constructors, and (as such) if implemented with a VclPtr it causes
us to take and then release a reference on our in-construction
object, before it can return it's 'this' into the safety of its
calling VclPtr<> constructor; not good. cf.
Dialog::doDeferredInit vs. SystemWindow::loadUI.
Change-Id: Idcab40cedcdebed560077cfaa1a14395e6e01cd6
diff --git a/include/vcl/dockwin.hxx b/include/vcl/dockwin.hxx
index 71c8181..bd334ea 100644
--- a/include/vcl/dockwin.hxx
+++ b/include/vcl/dockwin.hxx
@@ -261,7 +261,7 @@ private:
mbIsCalculatingInitialLayoutSize:1,
mbInitialLayoutDone:1;
- VclPtr<vcl::Window> mpDialogParent;
+ vcl::Window *mpDialogParent; // deliberately not a VclPtr
SAL_DLLPRIVATE void ImplInitDockingWindowData();
SAL_DLLPRIVATE void setPosSizeOnContainee(Size aSize, Window &rBox);
diff --git a/include/vcl/syswin.hxx b/include/vcl/syswin.hxx
index f90fb16..5609d57 100644
--- a/include/vcl/syswin.hxx
+++ b/include/vcl/syswin.hxx
@@ -149,7 +149,7 @@ private:
Idle maLayoutIdle;
protected:
bool mbIsDefferedInit;
- VclPtr<vcl::Window> mpDialogParent;
+ vcl::Window *mpDialogParent; // deliberately not a VclPtr
public:
using Window::ImplIsInTaskPaneList;
SAL_DLLPRIVATE bool ImplIsInTaskPaneList( vcl::Window* pWin );
diff --git a/vcl/source/window/dialog.cxx b/vcl/source/window/dialog.cxx
index 56c5dd4..9ca9c30 100644
--- a/vcl/source/window/dialog.cxx
+++ b/vcl/source/window/dialog.cxx
@@ -488,7 +488,7 @@ OUString VclBuilderContainer::getUIRootDir()
//do the init. Find the real parent stashed in mpDialogParent.
void Dialog::doDeferredInit(WinBits nBits)
{
- VclPtr<vcl::Window> pParent = mpDialogParent;
+ vcl::Window *pParent = mpDialogParent;
mpDialogParent = NULL;
ImplInit(pParent, nBits);
mbIsDefferedInit = false;
diff --git a/vcl/source/window/syswin.cxx b/vcl/source/window/syswin.cxx
index 9cb57f3..99ac9bc 100644
--- a/vcl/source/window/syswin.cxx
+++ b/vcl/source/window/syswin.cxx
@@ -119,7 +119,6 @@ void SystemWindow::dispose()
// as a SystemWindow (which it no longer is by then):
mpWindowImpl->mbSysWin = false;
disposeBuilder();
-
mpDialogParent.clear();
Window::dispose();
}
More information about the Libreoffice-commits
mailing list