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

Michael Meeks michael.meeks at collabora.com
Tue Apr 14 05:13:43 PDT 2015


 include/sfx2/sidebar/ControlFactory.hxx    |    5 +++--
 sfx2/source/sidebar/ControlFactory.cxx     |    8 ++++----
 sfx2/source/sidebar/Deck.cxx               |   13 ++++++-------
 sfx2/source/sidebar/Panel.cxx              |    2 +-
 sfx2/source/sidebar/SidebarChildWindow.cxx |    4 ++--
 sfx2/source/sidebar/SidebarController.cxx  |   15 +++++++++------
 sfx2/source/sidebar/SidebarController.hxx  |    2 +-
 sfx2/source/sidebar/TabBar.cxx             |   10 +++++++---
 sfx2/source/sidebar/TabBar.hxx             |    2 +-
 sw/inc/AnnotationWin.hxx                   |    2 +-
 sw/inc/SidebarWin.hxx                      |    2 +-
 sw/source/uibase/docvw/AnnotationWin.cxx   |    4 ++--
 vcl/source/window/builder.cxx              |    2 +-
 13 files changed, 39 insertions(+), 32 deletions(-)

New commits:
commit dc2ec59cb3ca6825510ad9c5953330eba3dc8cb2
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Tue Apr 14 13:19:03 2015 +0100

    Unwind lifecycle mistake in VclBuilder.
    
    Change-Id: I46e1b2fac3e49e1ef1a0aa7de7fc8e8cb90ddcf8

diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx
index 5574b03..dc06f34 100644
--- a/vcl/source/window/builder.cxx
+++ b/vcl/source/window/builder.cxx
@@ -1770,7 +1770,7 @@ VclPtr<vcl::Window> VclBuilder::makeObject(vcl::Window *pParent, const OString &
     SAL_WARN_IF(!pWindow, "vcl.layout", "probably need to implement " << name.getStr() << " or add a make" << name.getStr() << " function");
     if (pWindow)
     {
-        VclPtr< vcl::Window > xWindow( pWindow, SAL_NO_ACQUIRE );
+        VclPtr< vcl::Window > xWindow( pWindow );
         pWindow->SetHelpId(m_sHelpRoot + id);
         SAL_INFO("vcl.layout", "for " << name.getStr() <<
             ", created " << pWindow << " child of " <<
commit 6f9c00dfe02cdc62ad1b9798a0d007e1303a96e6
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Tue Apr 14 11:52:19 2015 +0100

    Sidebar lifecycle - dispose panel if we fail to construct it properly.
    
    Change-Id: I5e46e72227ac8532aed10758e1ccbb2b452ba8d4

diff --git a/include/sfx2/sidebar/ControlFactory.hxx b/include/sfx2/sidebar/ControlFactory.hxx
index a078e00..142f249 100644
--- a/include/sfx2/sidebar/ControlFactory.hxx
+++ b/include/sfx2/sidebar/ControlFactory.hxx
@@ -22,6 +22,7 @@
 #include <sfx2/dllapi.h>
 #include <sfx2/sidebar/SidebarToolBox.hxx>
 #include <vcl/button.hxx>
+#include <vcl/vclptr.hxx>
 #include <com/sun/star/frame/XFrame.hpp>
 class ToolBox;
 
@@ -39,9 +40,9 @@ class SFX2_DLLPUBLIC ControlFactory
 public:
     /** Create the menu button for the task bar.
     */
-    static CheckBox* CreateMenuButton (vcl::Window* pParentWindow);
+    static VclPtr<CheckBox> CreateMenuButton (vcl::Window* pParentWindow);
 
-    static ImageRadioButton* CreateTabItem (vcl::Window* pParentWindow);
+    static VclPtr<ImageRadioButton> CreateTabItem (vcl::Window* pParentWindow);
 };
 
 
diff --git a/sfx2/source/sidebar/ControlFactory.cxx b/sfx2/source/sidebar/ControlFactory.cxx
index 23e17a6..d8a49b3 100644
--- a/sfx2/source/sidebar/ControlFactory.cxx
+++ b/sfx2/source/sidebar/ControlFactory.cxx
@@ -25,14 +25,14 @@
 
 namespace sfx2 { namespace sidebar {
 
-CheckBox* ControlFactory::CreateMenuButton (vcl::Window* pParentWindow)
+VclPtr<CheckBox> ControlFactory::CreateMenuButton (vcl::Window* pParentWindow)
 {
-    return new MenuButton(pParentWindow);
+    return VclPtr<CheckBox>(new MenuButton(pParentWindow), SAL_NO_ACQUIRE);
 }
 
-ImageRadioButton* ControlFactory::CreateTabItem (vcl::Window* pParentWindow)
+VclPtr<ImageRadioButton> ControlFactory::CreateTabItem (vcl::Window* pParentWindow)
 {
-    return new TabItem(pParentWindow);
+    return VclPtr<ImageRadioButton>(new TabItem(pParentWindow), SAL_NO_ACQUIRE);
 }
 
 } } // end of namespace sfx2::sidebar
diff --git a/sfx2/source/sidebar/Deck.cxx b/sfx2/source/sidebar/Deck.cxx
index a44217c..bbdac3e 100644
--- a/sfx2/source/sidebar/Deck.cxx
+++ b/sfx2/source/sidebar/Deck.cxx
@@ -48,11 +48,11 @@ Deck::Deck (
       maIcon(),
       mnMinimalWidth(0),
       maPanels(),
-      mpTitleBar(new DeckTitleBar(rDeckDescriptor.msTitle, this, rCloserAction)),
-      mpScrollClipWindow(new vcl::Window(this)),
-      mpScrollContainer(new ScrollContainerWindow(mpScrollClipWindow.get())),
-      mpFiller(new vcl::Window(this)),
-      mpVerticalScrollBar(new ScrollBar(this))
+      mpTitleBar(VclPtr<DeckTitleBar>::Create(rDeckDescriptor.msTitle, this, rCloserAction)),
+      mpScrollClipWindow(VclPtr<vcl::Window>::Create(this)),
+      mpScrollContainer(VclPtr<ScrollContainerWindow>::Create(mpScrollClipWindow.get())),
+      mpFiller(VclPtr<vcl::Window>::Create(this)),
+      mpVerticalScrollBar(VclPtr<ScrollBar>::Create(this))
 {
     SetBackground(Wallpaper());
 
@@ -88,13 +88,12 @@ void Deck::dispose()
     // without updating maPanels.
     for (size_t i = 0; i < aPanels.size(); i++)
         aPanels[i].disposeAndClear();
-    maPanels.clear();
 
+    mpTitleBar.disposeAndClear();
     mpFiller.disposeAndClear();
     mpVerticalScrollBar.disposeAndClear();
     mpScrollContainer.disposeAndClear();
     mpScrollClipWindow.disposeAndClear();
-    mpTitleBar.disposeAndClear();
 
     vcl::Window::dispose();
 }
diff --git a/sfx2/source/sidebar/Panel.cxx b/sfx2/source/sidebar/Panel.cxx
index 8be4f28..c0246e5 100644
--- a/sfx2/source/sidebar/Panel.cxx
+++ b/sfx2/source/sidebar/Panel.cxx
@@ -51,7 +51,7 @@ Panel::Panel (
     const ::boost::function<Context(void)>& rContextAccess)
     : Window(pParentWindow),
       msPanelId(rPanelDescriptor.msId),
-      mpTitleBar(new PanelTitleBar(
+      mpTitleBar(VclPtr<PanelTitleBar>::Create(
               rPanelDescriptor.msTitle,
               pParentWindow,
               this)),
diff --git a/sfx2/source/sidebar/SidebarChildWindow.cxx b/sfx2/source/sidebar/SidebarChildWindow.cxx
index 05fad1c..c1b50bc 100644
--- a/sfx2/source/sidebar/SidebarChildWindow.cxx
+++ b/sfx2/source/sidebar/SidebarChildWindow.cxx
@@ -37,11 +37,11 @@ SidebarChildWindow::SidebarChildWindow (
     SfxChildWinInfo* pInfo)
     : SfxChildWindow(pParentWindow, nId)
 {
-    pWindow = new SidebarDockingWindow(
+    pWindow.reset(VclPtr<SidebarDockingWindow>::Create(
         pBindings,
         *this,
         pParentWindow,
-        WB_STDDOCKWIN | WB_OWNERDRAWDECORATION | WB_CLIPCHILDREN | WB_SIZEABLE | WB_3DLOOK | WB_ROLLABLE);
+        WB_STDDOCKWIN | WB_OWNERDRAWDECORATION | WB_CLIPCHILDREN | WB_SIZEABLE | WB_3DLOOK | WB_ROLLABLE));
     eChildAlignment = SfxChildAlignment::RIGHT;
 
     pWindow->SetHelpId(HID_SIDEBAR_WINDOW);
diff --git a/sfx2/source/sidebar/SidebarController.cxx b/sfx2/source/sidebar/SidebarController.cxx
index ee99a28..d1acaaa 100644
--- a/sfx2/source/sidebar/SidebarController.cxx
+++ b/sfx2/source/sidebar/SidebarController.cxx
@@ -95,7 +95,7 @@ SidebarController::SidebarController (
     : SidebarControllerInterfaceBase(m_aMutex),
       mpCurrentDeck(),
       mpParentWindow(pParentWindow),
-      mpTabBar(new TabBar(
+      mpTabBar(VclPtr<TabBar>::Create(
               mpParentWindow,
               rxFrame,
               ::boost::bind(&SidebarController::OpenThenSwitchToDeck, this, _1),
@@ -572,7 +572,7 @@ void SidebarController::SwitchToDeck (
     if ( ! mpCurrentDeck)
     {
         mpCurrentDeck.reset(
-            new Deck(
+            VclPtr<Deck>::Create(
                 rDeckDescriptor,
                 mpParentWindow,
                 ::boost::bind(&SidebarController::RequestCloseDeck, this)));
@@ -593,6 +593,7 @@ void SidebarController::SwitchToDeck (
     const sal_Int32 nNewPanelCount (aPanelContextDescriptors.size());
     SharedPanelContainer aNewPanels;
     const SharedPanelContainer& rCurrentPanels (mpCurrentDeck->GetPanels());
+    // FIXME: concerns wrt. dispose / lifecycle when we re-use panels here...
     aNewPanels.resize(nNewPanelCount);
     sal_Int32 nWriteIndex (0);
     bool bHasPanelSetChanged (false);
@@ -640,6 +641,7 @@ void SidebarController::SwitchToDeck (
                 mpCurrentDeck->GetPanelParentWindow(),
                 rPanelContexDescriptor.mbIsInitiallyVisible,
                 rContext);
+            aNewPanels[nWriteIndex].disposeAndClear();
             bHasPanelSetChanged = true;
         }
         if (aNewPanels[nWriteIndex] != nullptr)
@@ -658,6 +660,7 @@ void SidebarController::SwitchToDeck (
         }
 
     }
+    // mpCurrentPanels - may miss stuff (?)
     aNewPanels.resize(nWriteIndex);
 
     // Activate the deck and the new set of panels.
@@ -683,7 +686,7 @@ void SidebarController::SwitchToDeck (
     UpdateTitleBarIcons();
 }
 
-Panel* SidebarController::CreatePanel (
+VclPtr<Panel> SidebarController::CreatePanel (
     const OUString& rsPanelId,
     vcl::Window* pParentWindow,
     const bool bIsInitiallyExpanded,
@@ -694,7 +697,7 @@ Panel* SidebarController::CreatePanel (
         return NULL;
 
     // Create the panel which is the parent window of the UIElement.
-    Panel *pPanel = new Panel(
+    VclPtr<Panel> pPanel = VclPtr<Panel>::Create(
         *pPanelDescriptor,
         pParentWindow,
         bIsInitiallyExpanded,
@@ -714,7 +717,7 @@ Panel* SidebarController::CreatePanel (
     }
     else
     {
-        pPanel = NULL;
+        pPanel.disposeAndClear();
     }
 
     return pPanel;
@@ -1099,7 +1102,7 @@ void SidebarController::UpdateCloseIndicator (const bool bCloseAfterDrag)
         // Make sure that the indicator exists.
         if ( ! mpCloseIndicator)
         {
-            mpCloseIndicator.reset(new FixedImage(mpParentWindow));
+            mpCloseIndicator.reset(VclPtr<FixedImage>::Create(mpParentWindow));
             FixedImage* pFixedImage = static_cast<FixedImage*>(mpCloseIndicator.get());
             const Image aImage (Theme::GetImage(Theme::Image_CloseIndicator));
             pFixedImage->SetImage(aImage);
diff --git a/sfx2/source/sidebar/SidebarController.hxx b/sfx2/source/sidebar/SidebarController.hxx
index 68f634d..99941c3 100644
--- a/sfx2/source/sidebar/SidebarController.hxx
+++ b/sfx2/source/sidebar/SidebarController.hxx
@@ -198,7 +198,7 @@ private:
         const ::rtl::OUString& rsImplementationURL,
         const bool bWantsCanvas,
         const Context& rContext);
-    Panel* CreatePanel (
+    VclPtr<Panel> CreatePanel (
         const ::rtl::OUString& rsPanelId,
         vcl::Window* pParentWindow,
         const bool bIsInitiallyExpanded,
diff --git a/sfx2/source/sidebar/TabBar.cxx b/sfx2/source/sidebar/TabBar.cxx
index b055ec3..20c1da2 100644
--- a/sfx2/source/sidebar/TabBar.cxx
+++ b/sfx2/source/sidebar/TabBar.cxx
@@ -69,6 +69,11 @@ TabBar::~TabBar()
 
 void TabBar::dispose()
 {
+    for(ItemContainer::iterator
+            iItem(maItems.begin()), iEnd(maItems.end());
+        iItem!=iEnd;
+        ++iItem)
+        iItem->mpButton.disposeAndClear();
     maItems.clear();
     mpMenuButton.disposeAndClear();
     vcl::Window::dispose();
@@ -254,12 +259,11 @@ bool TabBar::Notify (NotifyEvent&)
     return false;
 }
 
-RadioButton* TabBar::CreateTabItem (const DeckDescriptor& rDeckDescriptor)
+VclPtr<RadioButton> TabBar::CreateTabItem (const DeckDescriptor& rDeckDescriptor)
 {
-    RadioButton* pItem = ControlFactory::CreateTabItem(this);
+    VclPtr<RadioButton> pItem = ControlFactory::CreateTabItem(this);
     pItem->SetHelpText(rDeckDescriptor.msHelpText);
     pItem->SetQuickHelpText(rDeckDescriptor.msHelpText);
-
     return pItem;
 }
 
diff --git a/sfx2/source/sidebar/TabBar.hxx b/sfx2/source/sidebar/TabBar.hxx
index 31778a5..a1061c3 100644
--- a/sfx2/source/sidebar/TabBar.hxx
+++ b/sfx2/source/sidebar/TabBar.hxx
@@ -111,7 +111,7 @@ private:
     sal_Int32 mnMenuSeparatorY;
     PopupMenuProvider maPopupMenuProvider;
 
-    RadioButton* CreateTabItem (const DeckDescriptor& rDeckDescriptor);
+    VclPtr<RadioButton> CreateTabItem (const DeckDescriptor& rDeckDescriptor);
     Image GetItemImage (const DeckDescriptor& rDeskDescriptor) const;
     void Layout (void);
     void UpdateButtonIcons (void);
diff --git a/sw/inc/AnnotationWin.hxx b/sw/inc/AnnotationWin.hxx
index 8533cfe..3f63b27 100644
--- a/sw/inc/AnnotationWin.hxx
+++ b/sw/inc/AnnotationWin.hxx
@@ -56,7 +56,7 @@ class SwAnnotationWin : public sw::sidebarwindows::SwSidebarWin
         virtual bool    IsProtected() SAL_OVERRIDE;
 
     protected:
-        virtual MenuButton* CreateMenuButton() SAL_OVERRIDE;
+        virtual VclPtr<MenuButton> CreateMenuButton() SAL_OVERRIDE;
 
     private:
         virtual SvxLanguageItem GetLanguage(void) SAL_OVERRIDE;
diff --git a/sw/inc/SidebarWin.hxx b/sw/inc/SidebarWin.hxx
index 3495713..6d5c90d 100644
--- a/sw/inc/SidebarWin.hxx
+++ b/sw/inc/SidebarWin.hxx
@@ -184,7 +184,7 @@ class SwSidebarWin : public vcl::Window
         virtual void    LoseFocus() SAL_OVERRIDE;
         virtual void    Paint( const Rectangle& rRect) SAL_OVERRIDE;
         virtual void    GetFocus() SAL_OVERRIDE;
-        virtual MenuButton* CreateMenuButton() = 0;
+        virtual VclPtr<MenuButton> CreateMenuButton() = 0;
 
         void        SetSizePixel( const Size& rNewSize ) SAL_OVERRIDE;
         SfxItemSet  DefaultItem();
diff --git a/sw/source/uibase/docvw/AnnotationWin.cxx b/sw/source/uibase/docvw/AnnotationWin.cxx
index 2d253ba..c061708 100644
--- a/sw/source/uibase/docvw/AnnotationWin.cxx
+++ b/sw/source/uibase/docvw/AnnotationWin.cxx
@@ -213,7 +213,7 @@ sal_uInt32 SwAnnotationWin::CountFollowing()
     return aCount - 1;
 }
 
-MenuButton* SwAnnotationWin::CreateMenuButton()
+VclPtr<MenuButton> SwAnnotationWin::CreateMenuButton()
 {
     mpButtonPopup = new PopupMenu(SW_RES(MN_ANNOTATION_BUTTON));
     OUString aText = mpButtonPopup->GetItemText( FN_DELETE_NOTE_AUTHOR );
@@ -221,7 +221,7 @@ MenuButton* SwAnnotationWin::CreateMenuButton()
     aRewriter.AddRule(UndoArg1,GetAuthor());
     aText = aRewriter.Apply(aText);
     mpButtonPopup->SetItemText(FN_DELETE_NOTE_AUTHOR,aText);
-    MenuButton* pMenuButton = new AnnotationMenuButton( *this );
+    VclPtr<MenuButton> pMenuButton( new AnnotationMenuButton( *this ), SAL_NO_ACQUIRE );
     pMenuButton->SetPopupMenu( mpButtonPopup );
     pMenuButton->Show();
     return pMenuButton;


More information about the Libreoffice-commits mailing list