Files
libreoffice/sw/source/ui/misc/titlepage.cxx
Oliver-Rainer Wittmann c2b5521921 Resolves: #i33737# enable in-place editing of Input Fields
(cherry picked from commit c2afeb1c3f11e8f420b59f3786eb8626c99ff595)

Conflicts:
	sw/inc/IDocumentContentOperations.hxx
	sw/inc/crsrsh.hxx
	sw/inc/doc.hxx
	sw/inc/editsh.hxx
	sw/inc/expfld.hxx
	sw/inc/fldbas.hxx
	sw/inc/fmtfld.hxx
	sw/inc/hintids.hxx
	sw/inc/ndtxt.hxx
	sw/inc/txatbase.hxx
	sw/inc/txtfld.hxx
	sw/inc/txtrfmrk.hxx
	sw/inc/txttxmrk.hxx
	sw/inc/viscrs.hxx
	sw/source/core/bastyp/init.cxx
	sw/source/core/crsr/crsrsh.cxx
	sw/source/core/crsr/crstrvl.cxx
	sw/source/core/crsr/findattr.cxx
	sw/source/core/crsr/findtxt.cxx
	sw/source/core/crsr/swcrsr.cxx
	sw/source/core/crsr/viscrs.cxx
	sw/source/core/doc/dbgoutsw.cxx
	sw/source/core/doc/doc.cxx
	sw/source/core/doc/docfld.cxx
	sw/source/core/doc/docfmt.cxx
	sw/source/core/doc/docnum.cxx
	sw/source/core/doc/docredln.cxx
	sw/source/core/doc/docruby.cxx
	sw/source/core/doc/doctxm.cxx
	sw/source/core/doc/visiturl.cxx
	sw/source/core/docnode/nodes.cxx
	sw/source/core/edit/edatmisc.cxx
	sw/source/core/edit/edattr.cxx
	sw/source/core/edit/edfld.cxx
	sw/source/core/edit/edfldexp.cxx
	sw/source/core/edit/editsh.cxx
	sw/source/core/edit/edlingu.cxx
	sw/source/core/edit/ednumber.cxx
	sw/source/core/fields/expfld.cxx
	sw/source/core/fields/fldbas.cxx
	sw/source/core/fields/reffld.cxx
	sw/source/core/frmedt/fefly1.cxx
	sw/source/core/inc/docfld.hxx
	sw/source/core/inc/rolbck.hxx
	sw/source/core/inc/swfont.hxx
	sw/source/core/layout/flycnt.cxx
	sw/source/core/layout/laycache.cxx
	sw/source/core/layout/trvlfrm.cxx
	sw/source/core/text/atrhndl.hxx
	sw/source/core/text/atrstck.cxx
	sw/source/core/text/inftxt.cxx
	sw/source/core/text/porfld.cxx
	sw/source/core/text/porfld.hxx
	sw/source/core/text/txtfld.cxx
	sw/source/core/tox/tox.cxx
	sw/source/core/tox/txmsrt.cxx
	sw/source/core/txtnode/atrfld.cxx
	sw/source/core/txtnode/ndhints.cxx
	sw/source/core/txtnode/ndtxt.cxx
	sw/source/core/txtnode/thints.cxx
	sw/source/core/txtnode/txatbase.cxx
	sw/source/core/txtnode/txatritr.cxx
	sw/source/core/txtnode/txtedt.cxx
	sw/source/core/undo/SwUndoField.cxx
	sw/source/core/undo/rolbck.cxx
	sw/source/core/undo/unsect.cxx
	sw/source/core/undo/untbl.cxx
	sw/source/core/unocore/unocrsrhelper.cxx
	sw/source/core/unocore/unofield.cxx
	sw/source/core/unocore/unoframe.cxx
	sw/source/core/unocore/unorefmk.cxx
	sw/source/core/view/vprint.cxx
	sw/source/filter/ascii/ascatr.cxx
	sw/source/filter/html/htmlatr.cxx
	sw/source/filter/rtf/rtffly.cxx
	sw/source/filter/ww1/fltshell.cxx
	sw/source/filter/ww1/w1filter.cxx
	sw/source/filter/ww8/wrtw8esh.cxx
	sw/source/filter/ww8/wrtw8nds.cxx
	sw/source/filter/ww8/ww8atr.cxx
	sw/source/filter/ww8/ww8par.cxx
	sw/source/filter/ww8/ww8par3.cxx
	sw/source/filter/ww8/ww8par5.cxx
	sw/source/ui/app/applab.cxx
	sw/source/ui/docvw/edtwin.cxx
	sw/source/ui/docvw/edtwin2.cxx
	sw/source/ui/envelp/envfmt.cxx
	sw/source/ui/fldui/fldedt.cxx
	sw/source/ui/fldui/fldmgr.cxx
	sw/source/ui/inc/wrtsh.hxx
	sw/source/ui/lingu/hhcwrp.cxx
	sw/source/ui/shells/basesh.cxx
	sw/source/ui/shells/drwtxtex.cxx
	sw/source/ui/shells/grfsh.cxx
	sw/source/ui/shells/tabsh.cxx
	sw/source/ui/shells/textfld.cxx
	sw/source/ui/shells/textidx.cxx
	sw/source/ui/shells/textsh.cxx
	sw/source/ui/shells/textsh1.cxx
	sw/source/ui/shells/txtattr.cxx
	sw/source/ui/uiview/formatclipboard.cxx
	sw/source/ui/uiview/view.cxx
	sw/source/ui/uiview/view2.cxx
	sw/source/ui/uiview/viewsrch.cxx
	sw/source/ui/uiview/viewstat.cxx
	sw/source/ui/uiview/viewtab.cxx
	sw/source/ui/wrtsh/wrtsh1.cxx
	sw/source/ui/wrtsh/wrtsh2.cxx

Change-Id: I6758d6719e1fd523797cc6ee2648ffcb47d52595
2013-11-19 15:51:27 +00:00

339 lines
9.8 KiB
C++

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <sfx2/viewfrm.hxx>
#include <vcl/msgbox.hxx>
#include <view.hxx>
#include <swmodule.hxx>
#include <wrtsh.hxx>
#include <poolfmt.hxx>
#include <docsh.hxx>
#include <charfmt.hxx>
#include <docstyle.hxx>
#include "fldbas.hxx"
#include "lineinfo.hxx"
#include "globals.hrc"
#include "titlepage.hxx"
#include "uitool.hxx"
#include "fmtpdsc.hxx"
#include "pagedesc.hxx"
#include <IDocumentStylePoolAccess.hxx>
namespace
{
bool lcl_GetPageDesc(SwWrtShell *pSh, sal_uInt16 &rPageNo, const SwFmtPageDesc **ppPageFmtDesc)
{
bool bRet = false;
SfxItemSet aSet( pSh->GetAttrPool(), RES_PAGEDESC, RES_PAGEDESC );
if (pSh->GetCurAttr( aSet ))
{
const SfxPoolItem* pItem(0);
if (SFX_ITEM_SET == aSet.GetItemState( RES_PAGEDESC, sal_True, &pItem ) && pItem)
{
::boost::optional<sal_uInt16> oNumOffset = ((const SwFmtPageDesc *)pItem)->GetNumOffset();
if (oNumOffset)
rPageNo = oNumOffset.get();
if (ppPageFmtDesc)
(*ppPageFmtDesc) = (const SwFmtPageDesc *)(pItem->Clone());
bRet = true;
}
}
return bRet;
}
void lcl_ChangePage(SwWrtShell *pSh, sal_uInt16 nNewNumber,
const SwPageDesc *pNewDesc)
{
const sal_uInt16 nCurIdx = pSh->GetCurPageDesc();
const SwPageDesc &rCurrentDesc = pSh->GetPageDesc( nCurIdx );
const SwFmtPageDesc *pPageFmtDesc(0);
sal_uInt16 nDontCare;
lcl_GetPageDesc(pSh, nDontCare, &pPageFmtDesc);
//If we want a new number then set it, otherwise reuse the existing one
sal_uInt16 nPgNo;
if (nNewNumber)
{
nPgNo = nNewNumber;
}
else
{
if (pPageFmtDesc)
{
::boost::optional<sal_uInt16> oNumOffset = pPageFmtDesc->GetNumOffset();
if (oNumOffset)
{
nPgNo = oNumOffset.get();
}
else
{
nPgNo = 0;
}
}
else
{
nPgNo = 0;
}
}
//If we want a new descriptior then set it, otherwise reuse the existing one
if (!pNewDesc)
{
SwFmtPageDesc aPageFmtDesc(pPageFmtDesc ? *pPageFmtDesc : &rCurrentDesc);
if (nPgNo) aPageFmtDesc.SetNumOffset(nPgNo);
pSh->SetAttrItem(aPageFmtDesc);
}
else
{
SwFmtPageDesc aPageFmtDesc(pNewDesc);
if (nPgNo) aPageFmtDesc.SetNumOffset(nPgNo);
pSh->SetAttrItem(aPageFmtDesc);
}
delete pPageFmtDesc;
}
void lcl_PushCursor(SwWrtShell *pSh)
{
pSh->LockView( sal_True );
pSh->StartAllAction();
pSh->SwCrsrShell::Push();
}
void lcl_PopCursor(SwWrtShell *pSh)
{
pSh->SwCrsrShell::Pop( sal_False );
pSh->EndAllAction();
pSh->LockView( sal_False );
}
sal_uInt16 lcl_GetCurrentPage(SwWrtShell *pSh)
{
OUString sDummy;
sal_uInt16 nPhyNum=1, nVirtNum=1;
pSh->GetPageNumber(0, true, nPhyNum, nVirtNum, sDummy);
return nPhyNum;
}
}
/*
* Only include the Index page in the list if the page count implies one
* to reduce confusing things
*/
void SwTitlePageDlg::FillList()
{
sal_uInt16 nTitlePages = m_pPageCountNF->GetValue();
m_pPagePropertiesLB->Clear();
if (mpTitleDesc)
m_pPagePropertiesLB->InsertEntry(mpTitleDesc->GetName());
if (nTitlePages > 1 && mpIndexDesc)
m_pPagePropertiesLB->InsertEntry(mpIndexDesc->GetName());
if (mpNormalDesc)
m_pPagePropertiesLB->InsertEntry(mpNormalDesc->GetName());
m_pPagePropertiesLB->SelectEntryPos(0);
}
sal_uInt16 SwTitlePageDlg::GetInsertPosition() const
{
sal_uInt16 nPage = 1;
if (m_pPageStartNF->IsEnabled())
nPage = m_pPageStartNF->GetValue();
return nPage;
}
SwTitlePageDlg::SwTitlePageDlg( Window *pParent ) :
SfxModalDialog( pParent, "DLG_TITLEPAGE", "modules/swriter/ui/titlepage.ui"),
mpPageFmtDesc(0)
{
get(m_pUseExistingPagesRB, "RB_USE_EXISTING_PAGES");
get(m_pPageCountNF, "NF_PAGE_COUNT");
get(m_pDocumentStartRB, "RB_DOCUMENT_START");
get(m_pPageStartRB, "RB_PAGE_START");
get(m_pPageStartNF, "NF_PAGE_START");
get(m_pRestartNumberingCB, "CB_RESTART_NUMBERING");
get(m_pRestartNumberingNF, "NF_RESTART_NUMBERING");
get(m_pSetPageNumberCB, "CB_SET_PAGE_NUMBER");
get(m_pSetPageNumberNF, "NF_SET_PAGE_NUMBER");
get(m_pPagePropertiesLB, "LB_PAGE_PROPERTIES");
get(m_pPagePropertiesPB, "PB_PAGE_PROPERTIES");
get(m_pOkPB, "PB_OK");
m_pOkPB->SetClickHdl(LINK(this, SwTitlePageDlg, OKHdl));
m_pRestartNumberingCB->SetClickHdl(LINK(this, SwTitlePageDlg, RestartNumberingHdl));
m_pSetPageNumberCB->SetClickHdl(LINK(this, SwTitlePageDlg, SetPageNumberHdl));
sal_uInt16 nSetPage = 1;
sal_uInt16 nResetPage = 1;
sal_uInt16 nTitlePages = 1;
mpSh = ::GetActiveView()->GetWrtShellPtr();
lcl_PushCursor(mpSh);
SwView& rView = mpSh->GetView();
rView.InvalidateRulerPos();
bool bMaybeResetNumbering = false;
mpTitleDesc = mpSh->GetPageDescFromPool(RES_POOLPAGE_FIRST);
mpIndexDesc = mpSh->GetPageDescFromPool(RES_POOLPAGE_REGISTER);
mpNormalDesc = mpSh->GetPageDescFromPool(RES_POOLPAGE_STANDARD);
mpSh->SttDoc();
if (lcl_GetPageDesc( mpSh, nSetPage, &mpPageFmtDesc ))
{
if (mpPageFmtDesc->GetPageDesc() == mpTitleDesc)
{
while (mpSh->SttNxtPg())
{
const sal_uInt16 nCurIdx = mpSh->GetCurPageDesc();
const SwPageDesc &rPageDesc = mpSh->GetPageDesc( nCurIdx );
if (mpIndexDesc != &rPageDesc)
{
mpNormalDesc = &rPageDesc;
bMaybeResetNumbering = lcl_GetPageDesc(mpSh, nResetPage, NULL);
break;
}
++nTitlePages;
}
}
}
lcl_PopCursor(mpSh);
m_pUseExistingPagesRB->Check();
m_pPageCountNF->SetValue(nTitlePages);
m_pPageCountNF->SetUpHdl(LINK(this, SwTitlePageDlg, UpHdl));
m_pPageCountNF->SetDownHdl(LINK(this, SwTitlePageDlg, DownHdl));
m_pDocumentStartRB->Check();
m_pPageStartNF->Enable(false);
m_pPageStartNF->SetValue(lcl_GetCurrentPage(mpSh));
Link aStartPageHdl = LINK(this, SwTitlePageDlg, StartPageHdl);
m_pDocumentStartRB->SetClickHdl(aStartPageHdl);
m_pPageStartRB->SetClickHdl(aStartPageHdl);
if (bMaybeResetNumbering && nResetPage > 0)
{
m_pRestartNumberingCB->Check();
m_pRestartNumberingNF->SetValue(nResetPage);
}
m_pRestartNumberingNF->Enable(m_pRestartNumberingCB->IsChecked());
m_pSetPageNumberNF->SetValue(nSetPage);
if (nSetPage > 1)
m_pSetPageNumberCB->Check();
m_pSetPageNumberNF->Enable(m_pSetPageNumberCB->IsChecked());
FillList();
m_pPagePropertiesPB->SetClickHdl(LINK(this, SwTitlePageDlg, EditHdl));
}
IMPL_LINK_NOARG(SwTitlePageDlg, UpHdl)
{
if (m_pPageCountNF->GetValue() == 2)
FillList();
return 0;
}
IMPL_LINK_NOARG(SwTitlePageDlg, DownHdl)
{
if (m_pPageCountNF->GetValue() == 1)
FillList();
return 0;
}
IMPL_LINK_NOARG(SwTitlePageDlg, RestartNumberingHdl)
{
m_pRestartNumberingNF->Enable(m_pRestartNumberingCB->IsChecked());
return 0;
}
IMPL_LINK_NOARG(SwTitlePageDlg, SetPageNumberHdl)
{
m_pSetPageNumberNF->Enable(m_pSetPageNumberCB->IsChecked());
return 0;
}
IMPL_LINK_NOARG(SwTitlePageDlg, StartPageHdl)
{
m_pPageStartNF->Enable(m_pPageStartRB->IsChecked());
return 0;
}
SwTitlePageDlg::~SwTitlePageDlg()
{
delete mpPageFmtDesc;
}
IMPL_LINK_NOARG(SwTitlePageDlg, EditHdl)
{
SwView& rView = mpSh->GetView();
rView.GetDocShell()->FormatPage(m_pPagePropertiesLB->GetSelectEntry(), "page", *mpSh);
rView.InvalidateRulerPos();
return 0;
}
IMPL_LINK_NOARG(SwTitlePageDlg, OKHdl)
{
lcl_PushCursor(mpSh);
mpSh->StartUndo();
SwFmtPageDesc aTitleDesc(mpTitleDesc);
if (m_pSetPageNumberCB->IsChecked())
aTitleDesc.SetNumOffset(m_pSetPageNumberNF->GetValue());
else if (mpPageFmtDesc)
aTitleDesc.SetNumOffset(mpPageFmtDesc->GetNumOffset());
sal_uInt16 nNoPages = m_pPageCountNF->GetValue();
if (!m_pUseExistingPagesRB->IsChecked())
{
mpSh->GotoPage(GetInsertPosition(), false);
for (sal_uInt16 nI=0; nI < nNoPages; ++nI)
mpSh->InsertPageBreak();
}
mpSh->GotoPage(GetInsertPosition(), false);
for (sal_uInt16 nI=1; nI < nNoPages; ++nI)
{
if (mpSh->SttNxtPg())
lcl_ChangePage(mpSh, 0, mpIndexDesc);
}
mpSh->GotoPage(GetInsertPosition(), false);
mpSh->SetAttrItem(aTitleDesc);
if (nNoPages > 1 && mpSh->GotoPage(GetInsertPosition() + nNoPages, false))
{
SwFmtPageDesc aPageFmtDesc(mpNormalDesc);
mpSh->SetAttrItem(aPageFmtDesc);
}
if (m_pRestartNumberingCB->IsChecked() || nNoPages > 1)
{
sal_uInt16 nPgNo = m_pRestartNumberingCB->IsChecked() ? m_pRestartNumberingNF->GetValue() : 0;
const SwPageDesc *pNewDesc = nNoPages > 1 ? mpNormalDesc : 0;
mpSh->GotoPage(GetInsertPosition() + nNoPages, false);
lcl_ChangePage(mpSh, nPgNo, pNewDesc);
}
mpSh->EndUndo();
lcl_PopCursor(mpSh);
if (!m_pUseExistingPagesRB->IsChecked())
mpSh->GotoPage(GetInsertPosition(), false);
EndDialog( RET_OK );
return 0;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */