vcl: more double-dispose protection, and survival after dispose.

Change-Id: I271f9bcb85d07a28abef2d97ef3c31287878324d
diff --git a/svtools/source/control/ctrlbox.cxx b/svtools/source/control/ctrlbox.cxx
index 2bac5a8..80e22ae 100644
--- a/svtools/source/control/ctrlbox.cxx
+++ b/svtools/source/control/ctrlbox.cxx
@@ -123,8 +123,12 @@ ColorListBox::~ColorListBox()

void ColorListBox::dispose()
{
    ImplDestroyColorEntries();
    delete pColorList;
    if ( pColorList )
    {
        ImplDestroyColorEntries();
        delete pColorList;
        pColorList = NULL;
    }
    ListBox::dispose();
}

@@ -953,8 +957,11 @@ FontNameBox::~FontNameBox()

void FontNameBox::dispose()
{
    SaveMRUEntries (maFontMRUEntriesFile);
    ImplDestroyFontList();
    if (mpFontList)
    {
        SaveMRUEntries (maFontMRUEntriesFile);
        ImplDestroyFontList();
    }
    ComboBox::dispose();
}

@@ -1017,6 +1024,7 @@ void FontNameBox::InitFontMRUEntriesFile()
void FontNameBox::ImplDestroyFontList()
{
    delete mpFontList;
    mpFontList = NULL;
}

void FontNameBox::Fill( const FontList* pList )
diff --git a/svx/source/tbxctrls/tbcontrl.cxx b/svx/source/tbxctrls/tbcontrl.cxx
index 55746fc5..b2926fd 100644
--- a/svx/source/tbxctrls/tbcontrl.cxx
+++ b/svx/source/tbxctrls/tbcontrl.cxx
@@ -338,7 +338,10 @@ SvxStyleBox_Impl::~SvxStyleBox_Impl()
void SvxStyleBox_Impl::dispose()
{
    for(int i = 0; i < MAX_STYLES_ENTRIES; i++)
    {
        delete m_pButtons[i];
        m_pButtons[i] = NULL;
    }
    ComboBox::dispose();
}

@@ -2297,21 +2300,19 @@ void SvxStyleToolBoxControl::SetFamilyState( sal_uInt16 nIdx,

IMPL_LINK_NOARG(SvxStyleToolBoxControl, VisibilityNotification)
{

    sal_uInt16 i;

    // Call ReBind() && UnBind() according to visibility
    SvxStyleBox_Impl* pBox = static_cast<SvxStyleBox_Impl*>( GetToolBox().GetItemWindow( GetId() ));
    if ( pBox->IsVisible() && !isBound() )

    if ( pBox && pBox->IsVisible() && !isBound() )
    {
        for ( i=0; i<MAX_FAMILIES; i++ )
        for ( sal_uInt16 i=0; i<MAX_FAMILIES; i++ )
            pBoundItems [i]->ReBind();

        bindListener();
    }
    else if ( !pBox->IsVisible() && isBound() )
    else if ( (!pBox || !pBox->IsVisible()) && isBound() )
    {
        for ( i=0; i<MAX_FAMILIES; i++ )
        for ( sal_uInt16 i=0; i<MAX_FAMILIES; i++ )
            pBoundItems[i]->UnBind();
        unbindListener();
    }
diff --git a/vcl/qa/cppunit/lifecycle.cxx b/vcl/qa/cppunit/lifecycle.cxx
index 8a453d4..3492b52 100644
--- a/vcl/qa/cppunit/lifecycle.cxx
+++ b/vcl/qa/cppunit/lifecycle.cxx
@@ -73,11 +73,11 @@ void LifecycleTest::testWidgets(vcl::Window *pParent)
    // Some widgets really insist on adoption.
    if (pParent)
    {
        { VclPtr<CheckBox>     aPtr(new CheckBox(pParent));    }
//        { VclPtr<Edit>         aPtr(new Edit(pParent));        }
//        { VclPtr<ComboBox>     aPtr(new ComboBox(pParent)); }
        { VclPtr<CheckBox>     aPtr(new CheckBox(pParent));     }
        { VclPtr<Edit>         aPtr(new Edit(pParent));         }
        { VclPtr<ComboBox>     aPtr(new ComboBox(pParent));     }
        { VclPtr<RadioButton>  aPtr(new RadioButton(pParent));  }
    }
//    { VclPtr<RadioButton>  aPtr(new RadioButton(pParent));  }
}

void LifecycleTest::testIsolatedWidgets()
diff --git a/vcl/source/control/combobox.cxx b/vcl/source/control/combobox.cxx
index 6396465..c0e5d9b 100644
--- a/vcl/source/control/combobox.cxx
+++ b/vcl/source/control/combobox.cxx
@@ -1267,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 )
@@ -1277,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 )
diff --git a/vcl/source/window/window2.cxx b/vcl/source/window/window2.cxx
index a3398ea..1e60f08 100644
--- a/vcl/source/window/window2.cxx
+++ b/vcl/source/window/window2.cxx
@@ -1381,7 +1381,7 @@ const Pointer& Window::GetPointer() const

VCLXWindow* Window::GetWindowPeer() const
{
    return mpWindowImpl->mpVCLXWindow;
    return mpWindowImpl ? mpWindowImpl->mpVCLXWindow : NULL;
}

void Window::SetPosPixel( const Point& rNewPos )