Kaydet (Commit) c9be3ebb authored tarafından Michael Meeks's avatar Michael Meeks

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/16160Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMichael Meeks <michael.meeks@collabora.com>
Tested-by: 's avatarMichael Meeks <michael.meeks@collabora.com>
üst 1930fe19
......@@ -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;
......
......@@ -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: */
......@@ -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)
......
......@@ -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 );
......
......@@ -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
......
......@@ -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);
......
......@@ -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 );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment