Kaydet (Commit) c0251bf6 authored tarafından Cédric Bosdonnat's avatar Cédric Bosdonnat

Header/Footer: shared code for the insertion/removal

Moved the ChangedHeaderOrFooter method from SwTextShell to SwWrtShell
for it to be accessible from the SwHeaderFooterWin objects... and that
method didn't really need to be in the root shell.

That fixed a few quirks from the copied code in SwHeaderFooterWin.
üst c900069d
......@@ -1448,7 +1448,7 @@ Menu MN_HEADERFOOTER_BUTTON
{
Identifier = FN_HEADERFOOTER_DELETE ;
HelpID = CMD_FN_HEADERFOOTER_DELETE ;
Text [ en-US ] = "Delete $1" ;
Text [ en-US ] = "Delete $1..." ;
};
};
};
......
......@@ -45,7 +45,6 @@
#include <basegfx/polygon/b2dpolygon.hxx>
#include <basegfx/color/bcolortools.hxx>
#include <editeng/ulspitem.hxx>
#include <svtools/svtdata.hxx>
#include <vcl/decoview.hxx>
#include <vcl/gradient.hxx>
......@@ -184,7 +183,7 @@ void SwHeaderFooterWin::SetOffset( Point aOffset )
aTextPxRect.GetHeight() + TEXT_PADDING * 2 );
long nYFooterOff = 0;
if ( !IsHeader() )
if ( !m_bIsHeader )
nYFooterOff = aBoxSize.Height();
Point aBoxPos( aOffset.X() - aBoxSize.Width() - BOX_DISTANCE,
......@@ -270,54 +269,29 @@ bool SwHeaderFooterWin::IsEmptyHeaderFooter( )
return bResult;
}
void SwHeaderFooterWin::ChangeHeaderOrFooter( bool bAdd )
{
SwWrtShell& rSh = m_pEditWin->GetView().GetWrtShell();
rSh.addCurrentPosition();
rSh.StartAllAction();
rSh.StartUndo( UNDO_HEADER_FOOTER );
const SwPageDesc* pPageDesc = GetPageFrame()->GetPageDesc();
SwFrmFmt& rMaster = const_cast< SwFrmFmt& > (pPageDesc->GetMaster() );
if ( m_bIsHeader )
rMaster.SetFmtAttr( SwFmtHeader( bAdd ) );
else
rMaster.SetFmtAttr( SwFmtFooter( bAdd ) );
if ( bAdd )
{
SvxULSpaceItem aUL( m_bIsHeader ? 0 : MM50, m_bIsHeader ? MM50 : 0, RES_UL_SPACE );
SwFrmFmt* pFmt = m_bIsHeader ?
( SwFrmFmt* )rMaster.GetHeader().GetHeaderFmt():
( SwFrmFmt* )rMaster.GetFooter().GetFooterFmt();
pFmt->SetFmtAttr( aUL );
}
rSh.EndUndo( UNDO_HEADER_FOOTER );
rSh.EndAllAction();
}
void SwHeaderFooterWin::ExecuteCommand( sal_uInt16 nSlot )
{
SwView& rView = m_pEditWin->GetView();
SwWrtShell& rSh = rView.GetWrtShell();
const String& rStyleName = GetPageFrame()->GetPageDesc()->GetName();
switch ( nSlot )
{
case FN_HEADERFOOTER_EDIT:
{
SwView& rView = m_pEditWin->GetView();
SwWrtShell& rSh = rView.GetWrtShell();
sal_uInt16 nPageId = TP_FOOTER_PAGE;
if ( IsHeader() )
if ( m_bIsHeader )
nPageId = TP_HEADER_PAGE;
rView.GetDocShell()->FormatPage(
GetPageFrame()->GetPageDesc()->GetName(),
rStyleName,
nPageId, &rSh );
}
break;
case FN_HEADERFOOTER_DELETE:
ChangeHeaderOrFooter( false );
{
rSh.ChangeHeaderOrFooter( rStyleName, m_bIsHeader, false, true );
}
break;
default:
break;
......@@ -334,8 +308,11 @@ void SwHeaderFooterWin::MouseButtonDown( const MouseEvent& rMEvt )
{
if ( IsEmptyHeaderFooter( ) )
{
// Add the header / footer
ChangeHeaderOrFooter( true );
SwView& rView = m_pEditWin->GetView();
SwWrtShell& rSh = rView.GetWrtShell();
const String& rStyleName = GetPageFrame()->GetPageDesc()->GetName();
rSh.ChangeHeaderOrFooter( rStyleName, m_bIsHeader, true, false );
}
else
MenuButton::MouseButtonDown( rMEvt );
......
......@@ -31,7 +31,6 @@
#include <pagedesc.hxx>
#include <vcl/menubtn.hxx>
#include <vcl/window.hxx>
/** Class for the header and footer separator control window.
......@@ -61,7 +60,6 @@ public:
bool IsEmptyHeaderFooter( );
const SwPageFrm* GetPageFrame( ) { return m_pPageFrm; };
void ChangeHeaderOrFooter( bool bAdd );
void ExecuteCommand(sal_uInt16 nSlot);
void SetReadonly( bool bReadonly );
......
......@@ -44,7 +44,6 @@ class SwTextShell: public SwBaseShell
void InsertSymbol( SfxRequest& );
void InsertHyperlink(const SvxHyperlinkItem& rHlnkItem);
bool InsertMediaDlg( SfxRequest& );
void ChangeHeaderOrFooter(const String& rStyleName, sal_Bool bHeader, sal_Bool bOn, sal_Bool bShowWarning);
public:
SFX_DECL_INTERFACE(SW_TEXTSHELL)
......
......@@ -485,6 +485,8 @@ typedef sal_Bool (SwWrtShell:: *FNSimpleMove)();
sal_Bool GotoFld( const SwFmtFld& rFld );
const SwRedline* GotoRedline( sal_uInt16 nArrPos, sal_Bool bSelect = sal_False);
void ChangeHeaderOrFooter(const String& rStyleName, sal_Bool bHeader, sal_Bool bOn, sal_Bool bShowWarning);
private:
SW_DLLPRIVATE void OpenMark();
......
......@@ -33,7 +33,6 @@
#include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
#include <comphelper/processfactory.hxx>
#include <svx/dialogs.hrc>
#include <hintids.hxx>
#include <cmdid.h>
#include <helpid.h>
......@@ -50,13 +49,11 @@
#include <sfx2/bindings.hxx>
#include <sfx2/dispatch.hxx>
#include <sfx2/objitem.hxx>
#include <vcl/msgbox.hxx>
#include <vcl/unohelp2.hxx>
#include <sfx2/request.hxx>
#include <svl/eitem.hxx>
#include <svl/macitem.hxx>
#include <editeng/lrspitem.hxx>
#include <editeng/ulspitem.hxx>
#include <editeng/colritem.hxx>
#include <editeng/tstpitem.hxx>
#include <editeng/brshitem.hxx>
......@@ -67,7 +64,6 @@
#include <charfmt.hxx>
#include <editeng/fontitem.hxx>
#include <svx/SmartTagItem.hxx>
#include <svx/dialmgr.hxx>
#include <fmtinfmt.hxx>
#include <swwait.hxx>
#include <wrtsh.hxx>
......@@ -76,7 +72,6 @@
#include <viewopt.hxx>
#include <uitool.hxx>
#include <swevent.hxx>
#include <fmthdft.hxx>
#include <pagedesc.hxx>
#include <textsh.hxx>
#include <IMark.hxx>
......@@ -1188,7 +1183,7 @@ void SwTextShell::Execute(SfxRequest &rReq)
sal_Bool bOn = sal_True;
if( SFX_ITEM_SET == pArgs->GetItemState(FN_PARAM_1, sal_False, &pItem))
bOn = ((const SfxBoolItem*)pItem)->GetValue();
ChangeHeaderOrFooter(sStyleName, FN_INSERT_PAGEHEADER == nSlot, bOn, !rReq.IsAPI());
rWrtSh.ChangeHeaderOrFooter(sStyleName, FN_INSERT_PAGEHEADER == nSlot, bOn, !rReq.IsAPI());
rReq.Done();
}
break;
......@@ -1675,75 +1670,4 @@ void SwTextShell::GetState( SfxItemSet &rSet )
}
}
/*
* Switch on/off header of footer of a page style - if an empty name is
* given all styles are changed
*/
void SwTextShell::ChangeHeaderOrFooter(
const String& rStyleName, sal_Bool bHeader, sal_Bool bOn, sal_Bool bShowWarning)
{
SwWrtShell& rSh = GetShell();
rSh.addCurrentPosition();
rSh.StartAllAction();
rSh.StartUndo( UNDO_HEADER_FOOTER ); // #i7983#
sal_Bool bExecute = sal_True;
sal_Bool bCrsrSet = sal_False;
for( sal_uInt16 nFrom = 0, nTo = rSh.GetPageDescCnt();
nFrom < nTo; ++nFrom )
{
int bChgd = sal_False;
SwPageDesc aDesc( rSh.GetPageDesc( nFrom ));
String sTmp(aDesc.GetName());
if( !rStyleName.Len() || rStyleName == sTmp )
{
if( (bShowWarning && !bOn && GetActiveView() && GetActiveView() == &GetView() &&
(bHeader && aDesc.GetMaster().GetHeader().IsActive())) ||
(!bHeader && aDesc.GetMaster().GetFooter().IsActive()) )
{
bShowWarning = sal_False;
//Actions have to be closed while the dialog is showing
rSh.EndAllAction();
Window* pParent = &GetView().GetViewFrame()->GetWindow();
sal_Bool bRet = RET_YES == QueryBox( pParent, ResId( RID_SVXQBX_DELETE_HEADFOOT,
DIALOG_MGR() ) ).Execute();
bExecute = bRet;
rSh.StartAllAction();
}
if( bExecute )
{
bChgd = sal_True;
SwFrmFmt &rMaster = aDesc.GetMaster();
if(bHeader)
rMaster.SetFmtAttr( SwFmtHeader( bOn ));
else
rMaster.SetFmtAttr( SwFmtFooter( bOn ));
if( bOn )
{
SvxULSpaceItem aUL(bHeader ? 0 : MM50, bHeader ? MM50 : 0, RES_UL_SPACE );
SwFrmFmt* pFmt = bHeader ?
(SwFrmFmt*)rMaster.GetHeader().GetHeaderFmt() :
(SwFrmFmt*)rMaster.GetFooter().GetFooterFmt();
pFmt->SetFmtAttr( aUL );
}
}
if( bChgd )
{
rSh.ChgPageDesc( nFrom, aDesc );
if( !bCrsrSet && bOn )
{
if ( !rSh.IsHeaderFooterEdit() )
rSh.ToggleHeaderFooterEdit();
bCrsrSet = rSh.SetCrsrInHdFt(
!rStyleName.Len() ? USHRT_MAX : nFrom,
bHeader );
}
}
}
}
rSh.EndUndo( UNDO_HEADER_FOOTER ); // #i7983#
rSh.EndAllAction();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -38,6 +38,8 @@
#include <com/sun/star/chart2/XChartDocument.hpp>
#include <com/sun/star/util/XModifiable.hpp>
#include <svx/dialogs.hrc>
#include <math.h>
#include <hintids.hxx>
#include <svx/svdview.hxx>
......@@ -56,7 +58,9 @@
#include <editeng/sizeitem.hxx>
#include <editeng/brkitem.hxx>
#include <editeng/svxacorr.hxx>
#include <editeng/ulspitem.hxx>
#include <vcl/graph.hxx>
#include <vcl/msgbox.hxx>
#include <sfx2/printer.hxx>
#include <unotools/charclass.hxx>
#include <comphelper/storagehelper.hxx>
......@@ -65,6 +69,7 @@
#include <svx/fontworkbar.hxx>
#include <frmfmt.hxx>
#include <fmtftn.hxx>
#include <fmthdft.hxx>
#include <fmtpdsc.hxx>
#include <wdocsh.hxx>
#include <basesh.hxx>
......@@ -98,6 +103,7 @@
#include <editeng/acorrcfg.hxx>
#include <IMark.hxx>
#include <sfx2/bindings.hxx>
#include <svx/dialmgr.hxx>
// -> #111827#
#include <SwRewriter.hxx>
......@@ -1814,4 +1820,74 @@ void SwWrtShell::SetReadonlyOption(sal_Bool bSet)
ViewShell::SetReadonlyOption( bSet );
}
/*
* Switch on/off header of footer of a page style - if an empty name is
* given all styles are changed
*/
void SwWrtShell::ChangeHeaderOrFooter(
const String& rStyleName, sal_Bool bHeader, sal_Bool bOn, sal_Bool bShowWarning)
{
addCurrentPosition();
StartAllAction();
StartUndo( UNDO_HEADER_FOOTER ); // #i7983#
sal_Bool bExecute = sal_True;
sal_Bool bCrsrSet = sal_False;
for( sal_uInt16 nFrom = 0, nTo = GetPageDescCnt();
nFrom < nTo; ++nFrom )
{
int bChgd = sal_False;
SwPageDesc aDesc( GetPageDesc( nFrom ));
String sTmp(aDesc.GetName());
if( !rStyleName.Len() || rStyleName == sTmp )
{
if( (bShowWarning && !bOn && GetActiveView() && GetActiveView() == &GetView() &&
(bHeader && aDesc.GetMaster().GetHeader().IsActive())) ||
(!bHeader && aDesc.GetMaster().GetFooter().IsActive()) )
{
bShowWarning = sal_False;
//Actions have to be closed while the dialog is showing
EndAllAction();
Window* pParent = &GetView().GetViewFrame()->GetWindow();
sal_Bool bRet = RET_YES == QueryBox( pParent, ResId( RID_SVXQBX_DELETE_HEADFOOT,
DIALOG_MGR() ) ).Execute();
bExecute = bRet;
StartAllAction();
}
if( bExecute )
{
bChgd = sal_True;
SwFrmFmt &rMaster = aDesc.GetMaster();
if(bHeader)
rMaster.SetFmtAttr( SwFmtHeader( bOn ));
else
rMaster.SetFmtAttr( SwFmtFooter( bOn ));
if( bOn )
{
SvxULSpaceItem aUL(bHeader ? 0 : MM50, bHeader ? MM50 : 0, RES_UL_SPACE );
SwFrmFmt* pFmt = bHeader ?
(SwFrmFmt*)rMaster.GetHeader().GetHeaderFmt() :
(SwFrmFmt*)rMaster.GetFooter().GetFooterFmt();
pFmt->SetFmtAttr( aUL );
}
}
if( bChgd )
{
ChgPageDesc( nFrom, aDesc );
if( !bCrsrSet && bOn )
{
if ( !IsHeaderFooterEdit() )
ToggleHeaderFooterEdit();
bCrsrSet = SetCrsrInHdFt(
!rStyleName.Len() ? USHRT_MAX : nFrom,
bHeader );
}
}
}
}
EndUndo( UNDO_HEADER_FOOTER ); // #i7983#
EndAllAction();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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