[Libreoffice-commits] core.git: Branch 'feature/vclptr' - 2 commits - include/vcl vcl/source

Michael Meeks michael.meeks at collabora.com
Tue Apr 14 02:02:38 PDT 2015


 include/vcl/builder.hxx       |    7 ++++---
 vcl/source/control/lstbox.cxx |    8 ++++----
 vcl/source/window/builder.cxx |   30 +++++++++++++++---------------
 vcl/source/window/window.cxx  |   31 ++++++++++++++++---------------
 4 files changed, 39 insertions(+), 37 deletions(-)

New commits:
commit ca7fa9bdad7b07955cd1783d2e58f06cb0533703
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Tue Apr 14 10:07:27 2015 +0100

    Use VclPtr in VclBuilder to get construction referencing right.
    
    Change-Id: I2100de7c599c3d2c241e336d369fc5998e23af16

diff --git a/include/vcl/builder.hxx b/include/vcl/builder.hxx
index 17410c2b..3479124 100644
--- a/include/vcl/builder.hxx
+++ b/include/vcl/builder.hxx
@@ -45,6 +45,7 @@ class VCL_DLLPUBLIC VclBuilder
 {
 public:
     typedef std::map<OString, OString> stringmap;
+    /// These functions return a vcl::Window with a reference count of one.
     typedef vcl::Window* (*customMakeWidget)(vcl::Window *pParent, stringmap &rVec);
 
 public:
@@ -340,12 +341,12 @@ private:
     css::uno::Reference<css::frame::XFrame> m_xFrame;
 
 private:
-    vcl::Window *insertObject(vcl::Window *pParent,
+    VclPtr<vcl::Window> insertObject(vcl::Window *pParent,
                     const OString &rClass, const OString &rID,
                     stringmap &rProps, stringmap &rPangoAttributes,
                     stringmap &rAtkProps);
 
-    vcl::Window *makeObject(vcl::Window *pParent,
+    VclPtr<vcl::Window> makeObject(vcl::Window *pParent,
                     const OString &rClass, const OString &rID,
                     stringmap &rVec);
 
@@ -364,7 +365,7 @@ private:
     void        handleTranslations(xmlreader::XmlReader &reader);
 
     void        handleChild(vcl::Window *pParent, xmlreader::XmlReader &reader);
-    vcl::Window* handleObject(vcl::Window *pParent, xmlreader::XmlReader &reader);
+    VclPtr<vcl::Window> handleObject(vcl::Window *pParent, xmlreader::XmlReader &reader);
     void        handlePacking(vcl::Window *pCurrent, vcl::Window *pParent, xmlreader::XmlReader &reader);
     void        applyPackingProperty(vcl::Window *pCurrent, vcl::Window *pParent, xmlreader::XmlReader &reader);
     void        collectProperty(xmlreader::XmlReader &reader, const OString &rID, stringmap &rVec);
diff --git a/vcl/source/control/lstbox.cxx b/vcl/source/control/lstbox.cxx
index 01ac564..966ddbb 100644
--- a/vcl/source/control/lstbox.cxx
+++ b/vcl/source/control/lstbox.cxx
@@ -132,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();
@@ -154,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 ) );
diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx
index e4097ed..5574b03 100644
--- a/vcl/source/window/builder.cxx
+++ b/vcl/source/window/builder.cxx
@@ -1266,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();
@@ -1308,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");
 
@@ -1703,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")
@@ -1712,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")
@@ -1780,7 +1780,7 @@ vcl::Window *VclBuilder::makeObject(vcl::Window *pParent, const OString &name, c
             pWindow->GetHelpId().getStr());
         m_aChildren.push_back(WinAndId(id, xWindow, bVertical));
     }
-    return pWindow;
+    return VclPtr<vcl::Window>(pWindow, SAL_NO_ACQUIRE);
 }
 
 namespace
@@ -1815,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))
     {
@@ -1829,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;
         }
@@ -2843,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;
@@ -2875,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;
@@ -2901,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(
commit df103589be3a1aaff026db76566ef77eb71d8405
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Tue Apr 14 10:06:05 2015 +0100

    Make leaked child debugging more helpful wrt. the hierarchy.
    
    Change-Id: Iadd2b5214661e00209f789c9ada83d5d9dce12b7

diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx
index cd26b3d..1ec060b 100644
--- a/vcl/source/window/window.cxx
+++ b/vcl/source/window/window.cxx
@@ -255,6 +255,22 @@ void Window::dispose()
         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;
@@ -302,21 +318,6 @@ void Window::dispose()
             Application::Abort(OStringToOUString(aTempStr.makeStringAndClear(), RTL_TEXTENCODING_UTF8));   // abort in debug builds, this must be fixed!
         }
 
-        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->mpFirstOverlap )
         {
             OStringBuffer aTempStr("Window (");


More information about the Libreoffice-commits mailing list