[Libreoffice-commits] core.git: Branch 'libreoffice-5-0' - sw/source

Michael Meeks michael.meeks at collabora.com
Fri Jun 12 13:57:12 PDT 2015


 sw/source/ui/envelp/labprt.cxx                  |    2 
 sw/source/uibase/docvw/FrameControlsManager.cxx |   59 ++++++++++++++++---
 sw/source/uibase/docvw/HeaderFooterWin.cxx      |   13 +---
 sw/source/uibase/docvw/PageBreakWin.cxx         |   12 +---
 sw/source/uibase/inc/FrameControl.hxx           |   71 +++++++++++++++---------
 sw/source/uibase/inc/HeaderFooterWin.hxx        |    5 -
 sw/source/uibase/inc/PageBreakWin.hxx           |    8 +-
 7 files changed, 107 insertions(+), 63 deletions(-)

New commits:
commit c9be3ebba438d202906ddb9da05a27a7fb5c1ab6
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Mon Jun 8 15:34:12 2015 +0100

    Writer FrameControl lifecycle and management cleanup.
    
    We can't derive from a VclPtr base-class, and also another base,
    and then use boost::shared_ptr for that; re-factor to use a boost_ptr
    to hold a VclPtr<> for now. Also fix leaking envelope dialog.
    
    Change-Id: I2e1efbfaee3b6051e38ff7a14903a83ccd75136b
    Reviewed-on: https://gerrit.libreoffice.org/16160
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
    Tested-by: Michael Meeks <michael.meeks at collabora.com>

diff --git a/sw/source/ui/envelp/labprt.cxx b/sw/source/ui/envelp/labprt.cxx
index ae81bbe..59e3e06 100644
--- a/sw/source/ui/envelp/labprt.cxx
+++ b/sw/source/ui/envelp/labprt.cxx
@@ -91,7 +91,7 @@ IMPL_LINK( SwLabPrtPage, CountHdl, Button *, pButton )
         VclPtrInstance< PrinterSetupDialog > pDlg(this);
         pDlg->SetPrinter(pPrinter);
         pDlg->Execute();
-        pDlg.reset();
+        pDlg.disposeAndClear();
         GrabFocus();
         m_pPrinterInfo->SetText(pPrinter->GetName());
         return 0;
diff --git a/sw/source/uibase/docvw/FrameControlsManager.cxx b/sw/source/uibase/docvw/FrameControlsManager.cxx
index e168096..262388c 100644
--- a/sw/source/uibase/docvw/FrameControlsManager.cxx
+++ b/sw/source/uibase/docvw/FrameControlsManager.cxx
@@ -117,7 +117,9 @@ void SwFrameControlsManager::SetHeaderFooterControl( const SwPageFrm* pPageFrm,
         pControl = lb->second;
     else
     {
-        SwFrameControlPtr pNewControl( new SwHeaderFooterWin( m_pEditWin, pPageFrm, bHeader ) );
+        SwFrameControlPtr pNewControl(
+                new SwFrameControl( VclPtr<SwHeaderFooterWin>::Create(
+                                        m_pEditWin, pPageFrm, bHeader ).get() ) );
         const SwViewOption* pViewOpt = m_pEditWin->GetView().GetWrtShell().GetViewOptions();
         pNewControl->SetReadonly( pViewOpt->IsReadonly() );
         rControls.insert(lb, make_pair(pPageFrm, pNewControl));
@@ -126,11 +128,12 @@ void SwFrameControlsManager::SetHeaderFooterControl( const SwPageFrm* pPageFrm,
 
     Rectangle aPageRect = m_pEditWin->LogicToPixel( pPageFrm->Frm().SVRect() );
 
-    SwHeaderFooterWin& rHFWin = dynamic_cast<SwHeaderFooterWin&>(*pControl.get());
-    assert(rHFWin.IsHeader() == bHeader);
-    rHFWin.SetOffset( aOffset, aPageRect.Left(), aPageRect.Right() );
+    SwHeaderFooterWin* pWin = dynamic_cast<SwHeaderFooterWin *>(pControl->GetWindow());
+    assert( pWin != NULL) ;
+    assert( pWin->IsHeader() == bHeader );
+    pWin->SetOffset( aOffset, aPageRect.Left(), aPageRect.Right() );
 
-    if (!rHFWin.IsVisible())
+    if (!pWin->IsVisible())
         pControl->ShowAll( true );
 }
 
@@ -146,7 +149,8 @@ void SwFrameControlsManager::SetPageBreakControl( const SwPageFrm* pPageFrm )
         pControl = lb->second;
     else
     {
-        SwFrameControlPtr pNewControl( new SwPageBreakWin( m_pEditWin, pPageFrm ) );
+        SwFrameControlPtr pNewControl( new SwFrameControl(
+                VclPtr<SwPageBreakWin>::Create( m_pEditWin, pPageFrm ).get() ) );
         const SwViewOption* pViewOpt = m_pEditWin->GetView().GetWrtShell().GetViewOptions();
         pNewControl->SetReadonly( pViewOpt->IsReadonly() );
 
@@ -155,10 +159,47 @@ void SwFrameControlsManager::SetPageBreakControl( const SwPageFrm* pPageFrm )
         pControl.swap( pNewControl );
     }
 
-    SwPageBreakWin& rWin = dynamic_cast<SwPageBreakWin&>(*pControl.get());
-    rWin.UpdatePosition();
-    if (!rWin.IsVisible())
+    SwPageBreakWin* pWin = dynamic_cast<SwPageBreakWin *>(pControl->GetWindow());
+    assert (pWin != NULL);
+    pWin->UpdatePosition();
+    if (!pWin->IsVisible())
         pControl->ShowAll( true );
 }
 
+SwFrameMenuButtonBase::SwFrameMenuButtonBase( SwEditWin* pEditWin, const SwFrm* pFrm ) :
+    MenuButton( pEditWin, WB_DIALOGCONTROL ),
+    m_pEditWin( pEditWin ),
+    m_pFrm( pFrm )
+{
+}
+
+const SwPageFrm* SwFrameMenuButtonBase::GetPageFrame()
+{
+    return static_cast< const SwPageFrm * >( m_pFrm );
+}
+
+void SwFrameMenuButtonBase::dispose()
+{
+    m_pEditWin.clear();
+    m_pFrm = NULL;
+    MenuButton::dispose();
+}
+
+SwFrameControl::SwFrameControl( const VclPtr<vcl::Window> &pWindow )
+{
+    assert( pWindow != NULL );
+    mxWindow.reset( pWindow );
+    mpIFace = dynamic_cast<ISwFrameControl *>( pWindow.get() );
+}
+
+SwFrameControl::~SwFrameControl()
+{
+    mpIFace = NULL;
+    mxWindow.disposeAndClear();
+}
+
+ISwFrameControl::~ISwFrameControl()
+{
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/docvw/HeaderFooterWin.cxx b/sw/source/uibase/docvw/HeaderFooterWin.cxx
index 548ae88..22d0c48 100644
--- a/sw/source/uibase/docvw/HeaderFooterWin.cxx
+++ b/sw/source/uibase/docvw/HeaderFooterWin.cxx
@@ -124,10 +124,8 @@ namespace
     }
 }
 
-SwHeaderFooterWin::SwHeaderFooterWin( SwEditWin* pEditWin, const SwPageFrm* pPageFrm, bool bHeader ) :
-    MenuButton( pEditWin, WB_DIALOGCONTROL ),
-    SwFrameControl( pEditWin, pPageFrm ),
-    m_sLabel( ),
+SwHeaderFooterWin::SwHeaderFooterWin( SwEditWin* pEditWin, const SwFrm *pFrm, bool bHeader ) :
+    SwFrameMenuButtonBase( pEditWin, pFrm ),
     m_bIsHeader( bHeader ),
     m_pPopupMenu( NULL ),
     m_pLine( NULL ),
@@ -175,12 +173,7 @@ void SwHeaderFooterWin::dispose()
 {
     delete m_pPopupMenu;
     m_pLine.disposeAndClear();
-    MenuButton::dispose();
-}
-
-const SwPageFrm* SwHeaderFooterWin::GetPageFrame( )
-{
-    return static_cast< const SwPageFrm * >( GetFrame( ) );
+    SwFrameMenuButtonBase::dispose();
 }
 
 void SwHeaderFooterWin::SetOffset(Point aOffset, long nXLineStart, long nXLineEnd)
diff --git a/sw/source/uibase/docvw/PageBreakWin.cxx b/sw/source/uibase/docvw/PageBreakWin.cxx
index 879ebd4..db26491 100644
--- a/sw/source/uibase/docvw/PageBreakWin.cxx
+++ b/sw/source/uibase/docvw/PageBreakWin.cxx
@@ -90,9 +90,8 @@ namespace
     }
 }
 
-SwPageBreakWin::SwPageBreakWin( SwEditWin* pEditWin, const SwPageFrm* pPageFrm ) :
-    MenuButton( pEditWin, WB_DIALOGCONTROL ),
-    SwFrameControl( pEditWin, pPageFrm ),
+SwPageBreakWin::SwPageBreakWin( SwEditWin* pEditWin, const SwFrm *pFrm ) :
+    SwFrameMenuButtonBase( pEditWin, pFrm ),
     m_pPopupMenu( NULL ),
     m_pLine( NULL ),
     m_bIsAppearing( false ),
@@ -132,7 +131,7 @@ void SwPageBreakWin::dispose()
     delete m_pMousePt;
     m_pMousePt = NULL;
 
-    MenuButton::dispose();
+    SwFrameMenuButtonBase::dispose();
 }
 
 void SwPageBreakWin::Paint(vcl::RenderContext& rRenderContext, const Rectangle&)
@@ -412,11 +411,6 @@ bool SwPageBreakWin::Contains( const Point &rDocPt ) const
     return false;
 }
 
-const SwPageFrm* SwPageBreakWin::GetPageFrame( )
-{
-    return static_cast< const SwPageFrm * >( GetFrame( ) );
-}
-
 void SwPageBreakWin::SetReadonly( bool bReadonly )
 {
     ShowAll( !bReadonly );
diff --git a/sw/source/uibase/inc/FrameControl.hxx b/sw/source/uibase/inc/FrameControl.hxx
index 936be2a..5787b23 100644
--- a/sw/source/uibase/inc/FrameControl.hxx
+++ b/sw/source/uibase/inc/FrameControl.hxx
@@ -10,42 +10,61 @@
 #define INCLUDED_SW_SOURCE_UIBASE_INC_FRAMECONTROL_HXX
 
 class SwEditWin;
+class SwPageFrm;
 class SwFrm;
 class Point;
 
-/** Class representing a control linked to a SwFrm.
-  */
-class SwFrameControl
+/// Abstract interface to be implemented by writer FrameControls
+class ISwFrameControl
 {
-    VclPtr<SwEditWin>     m_pEditWin;
-    const SwFrm*          m_pFrm;
-
 public:
-    SwFrameControl( SwEditWin* pEditWin, const SwFrm* pFrm ) :
-        m_pEditWin( pEditWin ), m_pFrm( pFrm ) {};
-    virtual ~SwFrameControl( ) {};
-
-    SwFrameControl( const SwFrameControl& rCopy ) :
-        m_pEditWin( rCopy.m_pEditWin ),
-        m_pFrm( rCopy.m_pFrm )
-    {
-    }
-
-    const SwFrameControl& operator=( const SwFrameControl& rCopy )
-    {
-        m_pEditWin = rCopy.m_pEditWin;
-        m_pFrm = rCopy.m_pFrm;
-        return *this;
-    }
-
-    const SwFrm* GetFrame( ) { return m_pFrm; }
-    SwEditWin*   GetEditWin( ) { return m_pEditWin; }
-
+    virtual ~ISwFrameControl();
     virtual void SetReadonly( bool bReadonly ) = 0;
     virtual void ShowAll( bool bShow ) = 0;
 
     /// Returns true if the point is inside the control.
     virtual bool Contains( const Point &rDocPt ) const = 0;
+
+    virtual const SwFrm* GetFrame() = 0;
+    virtual SwEditWin*   GetEditWin() = 0;
+};
+
+class SwFrameControl
+{
+    VclPtr<vcl::Window> mxWindow;
+    ISwFrameControl    *mpIFace;
+public:
+    SwFrameControl( const VclPtr<vcl::Window> &pWindow );
+    virtual ~SwFrameControl();
+
+    const SwFrm* GetFrame()   { return mpIFace->GetFrame(); }
+    SwEditWin*   GetEditWin() { return mpIFace->GetEditWin(); }
+    vcl::Window* GetWindow()  { return mxWindow.get(); }
+
+    void SetReadonly( bool bReadonly ) { mpIFace->SetReadonly( bReadonly ); }
+    void ShowAll( bool bShow )         { mpIFace->ShowAll( bShow ); }
+    bool Contains( const Point &rDocPt ) const { return mpIFace->Contains( rDocPt ); }
+};
+
+#include <vcl/menubtn.hxx>
+
+/** Class sharing some MenuButton code
+  */
+class SwFrameMenuButtonBase : public MenuButton, public ISwFrameControl
+{
+    VclPtr<SwEditWin>     m_pEditWin;
+    const SwFrm*          m_pFrm;
+
+protected:
+    virtual ~SwFrameMenuButtonBase() {}
+    virtual void dispose() SAL_OVERRIDE;
+
+public:
+    SwFrameMenuButtonBase( SwEditWin* pEditWin, const SwFrm* pFrm );
+
+    virtual const SwFrm* GetFrame()   SAL_OVERRIDE { return m_pFrm; }
+    virtual SwEditWin*   GetEditWin() SAL_OVERRIDE { return m_pEditWin; }
+    const SwPageFrm*     GetPageFrame();
 };
 
 #endif
diff --git a/sw/source/uibase/inc/HeaderFooterWin.hxx b/sw/source/uibase/inc/HeaderFooterWin.hxx
index b9fa86e..a96423f 100644
--- a/sw/source/uibase/inc/HeaderFooterWin.hxx
+++ b/sw/source/uibase/inc/HeaderFooterWin.hxx
@@ -18,7 +18,7 @@
     This control is showing the header / footer style name and provides
     a few useful actions to the user.
   */
-class SwHeaderFooterWin : public MenuButton, public SwFrameControl
+class SwHeaderFooterWin : public SwFrameMenuButtonBase
 {
     OUString              m_sLabel;
     bool                  m_bIsHeader;
@@ -29,7 +29,7 @@ class SwHeaderFooterWin : public MenuButton, public SwFrameControl
     Timer                 m_aFadeTimer;
 
 public:
-    SwHeaderFooterWin( SwEditWin* pEditWin, const SwPageFrm* pPageFrm, bool bHeader );
+    SwHeaderFooterWin( SwEditWin *pEditWin, const SwFrm *pFrm, bool bHeader );
     virtual ~SwHeaderFooterWin( );
     virtual void dispose() SAL_OVERRIDE;
 
@@ -44,7 +44,6 @@ public:
 
     bool IsHeader() { return m_bIsHeader; };
     bool IsEmptyHeaderFooter( );
-    const SwPageFrm* GetPageFrame( );
 
     void ExecuteCommand(sal_uInt16 nSlot);
 
diff --git a/sw/source/uibase/inc/PageBreakWin.hxx b/sw/source/uibase/inc/PageBreakWin.hxx
index 6efb632..34d1b4c 100644
--- a/sw/source/uibase/inc/PageBreakWin.hxx
+++ b/sw/source/uibase/inc/PageBreakWin.hxx
@@ -20,7 +20,7 @@ class SwPageFrm;
     This control shows a line indicating a manual page break and a
     button providing a few actions on that page break.
   */
-class SwPageBreakWin : public MenuButton, public SwFrameControl
+class SwPageBreakWin : public SwFrameMenuButtonBase
 {
     PopupMenu*            m_pPopupMenu;
     VclPtr<vcl::Window>   m_pLine;
@@ -33,8 +33,8 @@ class SwPageBreakWin : public MenuButton, public SwFrameControl
     const Point*          m_pMousePt;
 
 public:
-    SwPageBreakWin( SwEditWin* pEditWin, const SwPageFrm* pPageFrm );
-    virtual ~SwPageBreakWin( );
+    SwPageBreakWin( SwEditWin* pEditWin, const SwFrm *pFrm );
+    virtual ~SwPageBreakWin();
     virtual void dispose() SAL_OVERRIDE;
 
     virtual void Paint( vcl::RenderContext& /*rRenderContext*/, const Rectangle& rRect ) SAL_OVERRIDE;
@@ -47,8 +47,6 @@ public:
     virtual void ShowAll( bool bShow ) SAL_OVERRIDE;
     virtual bool Contains( const Point &rDocPt ) const SAL_OVERRIDE;
 
-    const SwPageFrm* GetPageFrame( );
-
     void SetReadonly( bool bReadonly ) SAL_OVERRIDE;
 
     void Fade( bool bFadeIn );


More information about the Libreoffice-commits mailing list