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(