2010-10-18 14:01:21 +01:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
2013-04-19 21:10:42 +01:00
|
|
|
* This file is part of the LibreOffice project.
|
2010-10-18 14:01:21 +01:00
|
|
|
*
|
2013-04-19 21:10:42 +01:00
|
|
|
* 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/.
|
2010-10-18 14:01:21 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#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
|
|
|
|
{
|
2011-03-14 16:51:14 +00:00
|
|
|
bool lcl_GetPageDesc(SwWrtShell *pSh, sal_uInt16 &rPageNo, const SwFmtPageDesc **ppPageFmtDesc)
|
2010-10-18 14:01:21 +01:00
|
|
|
{
|
|
|
|
bool bRet = false;
|
|
|
|
SfxItemSet aSet( pSh->GetAttrPool(), RES_PAGEDESC, RES_PAGEDESC );
|
|
|
|
if (pSh->GetCurAttr( aSet ))
|
|
|
|
{
|
|
|
|
const SfxPoolItem* pItem(0);
|
2011-03-14 16:51:14 +00:00
|
|
|
if (SFX_ITEM_SET == aSet.GetItemState( RES_PAGEDESC, sal_True, &pItem ) && pItem)
|
2010-10-18 14:01:21 +01:00
|
|
|
{
|
2013-08-29 17:16:44 +03:00
|
|
|
::boost::optional<sal_uInt16> oNumOffset = ((const SwFmtPageDesc *)pItem)->GetNumOffset();
|
|
|
|
if (oNumOffset)
|
|
|
|
rPageNo = oNumOffset.get();
|
2010-10-18 14:01:21 +01:00
|
|
|
if (ppPageFmtDesc)
|
|
|
|
(*ppPageFmtDesc) = (const SwFmtPageDesc *)(pItem->Clone());
|
|
|
|
bRet = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
2011-03-14 16:51:14 +00:00
|
|
|
void lcl_ChangePage(SwWrtShell *pSh, sal_uInt16 nNewNumber,
|
2010-10-18 14:01:21 +01:00
|
|
|
const SwPageDesc *pNewDesc)
|
|
|
|
{
|
2011-03-14 16:51:14 +00:00
|
|
|
const sal_uInt16 nCurIdx = pSh->GetCurPageDesc();
|
2010-10-18 14:01:21 +01:00
|
|
|
const SwPageDesc &rCurrentDesc = pSh->GetPageDesc( nCurIdx );
|
|
|
|
|
|
|
|
const SwFmtPageDesc *pPageFmtDesc(0);
|
2011-03-14 16:51:14 +00:00
|
|
|
sal_uInt16 nDontCare;
|
2010-10-18 14:01:21 +01:00
|
|
|
lcl_GetPageDesc(pSh, nDontCare, &pPageFmtDesc);
|
|
|
|
|
|
|
|
//If we want a new number then set it, otherwise reuse the existing one
|
2013-08-29 17:16:44 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2010-10-18 14:01:21 +01:00
|
|
|
|
|
|
|
//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);
|
2013-11-18 11:29:24 +00:00
|
|
|
pSh->SetAttrItem(aPageFmtDesc);
|
2010-10-18 14:01:21 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SwFmtPageDesc aPageFmtDesc(pNewDesc);
|
|
|
|
if (nPgNo) aPageFmtDesc.SetNumOffset(nPgNo);
|
2013-11-18 11:29:24 +00:00
|
|
|
pSh->SetAttrItem(aPageFmtDesc);
|
2010-10-18 14:01:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
delete pPageFmtDesc;
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcl_PushCursor(SwWrtShell *pSh)
|
|
|
|
{
|
2011-03-14 16:51:14 +00:00
|
|
|
pSh->LockView( sal_True );
|
2010-10-18 14:01:21 +01:00
|
|
|
pSh->StartAllAction();
|
|
|
|
pSh->SwCrsrShell::Push();
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcl_PopCursor(SwWrtShell *pSh)
|
|
|
|
{
|
2011-03-14 16:51:14 +00:00
|
|
|
pSh->SwCrsrShell::Pop( sal_False );
|
2010-10-18 14:01:21 +01:00
|
|
|
pSh->EndAllAction();
|
2011-03-14 16:51:14 +00:00
|
|
|
pSh->LockView( sal_False );
|
2010-10-18 14:01:21 +01:00
|
|
|
}
|
|
|
|
|
2011-03-14 16:51:14 +00:00
|
|
|
sal_uInt16 lcl_GetCurrentPage(SwWrtShell *pSh)
|
2010-10-18 14:01:21 +01:00
|
|
|
{
|
2013-10-10 15:54:33 +02:00
|
|
|
OUString sDummy;
|
2011-03-14 16:51:14 +00:00
|
|
|
sal_uInt16 nPhyNum=1, nVirtNum=1;
|
2010-10-18 14:01:21 +01:00
|
|
|
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()
|
|
|
|
{
|
2012-04-25 11:15:33 +01:00
|
|
|
sal_uInt16 nTitlePages = m_pPageCountNF->GetValue();
|
|
|
|
m_pPagePropertiesLB->Clear();
|
2010-10-18 14:01:21 +01:00
|
|
|
if (mpTitleDesc)
|
2012-04-25 11:15:33 +01:00
|
|
|
m_pPagePropertiesLB->InsertEntry(mpTitleDesc->GetName());
|
2010-10-18 14:01:21 +01:00
|
|
|
if (nTitlePages > 1 && mpIndexDesc)
|
2012-04-25 11:15:33 +01:00
|
|
|
m_pPagePropertiesLB->InsertEntry(mpIndexDesc->GetName());
|
2010-10-18 14:01:21 +01:00
|
|
|
if (mpNormalDesc)
|
2012-04-25 11:15:33 +01:00
|
|
|
m_pPagePropertiesLB->InsertEntry(mpNormalDesc->GetName());
|
|
|
|
m_pPagePropertiesLB->SelectEntryPos(0);
|
2010-10-18 14:01:21 +01:00
|
|
|
}
|
|
|
|
|
2011-03-14 16:51:14 +00:00
|
|
|
sal_uInt16 SwTitlePageDlg::GetInsertPosition() const
|
2010-10-18 14:01:21 +01:00
|
|
|
{
|
2011-03-14 16:51:14 +00:00
|
|
|
sal_uInt16 nPage = 1;
|
2012-04-25 11:15:33 +01:00
|
|
|
if (m_pPageStartNF->IsEnabled())
|
|
|
|
nPage = m_pPageStartNF->GetValue();
|
2010-10-18 14:01:21 +01:00
|
|
|
return nPage;
|
|
|
|
}
|
|
|
|
|
|
|
|
SwTitlePageDlg::SwTitlePageDlg( Window *pParent ) :
|
2012-09-26 09:52:48 +01:00
|
|
|
SfxModalDialog( pParent, "DLG_TITLEPAGE", "modules/swriter/ui/titlepage.ui"),
|
2012-04-25 11:15:33 +01:00
|
|
|
mpPageFmtDesc(0)
|
2010-10-18 14:01:21 +01:00
|
|
|
{
|
2012-08-30 00:56:52 +01:00
|
|
|
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");
|
2012-04-25 11:15:33 +01:00
|
|
|
|
|
|
|
m_pOkPB->SetClickHdl(LINK(this, SwTitlePageDlg, OKHdl));
|
|
|
|
m_pRestartNumberingCB->SetClickHdl(LINK(this, SwTitlePageDlg, RestartNumberingHdl));
|
|
|
|
m_pSetPageNumberCB->SetClickHdl(LINK(this, SwTitlePageDlg, SetPageNumberHdl));
|
2010-10-18 14:01:21 +01:00
|
|
|
|
2011-03-14 16:51:14 +00:00
|
|
|
sal_uInt16 nSetPage = 1;
|
|
|
|
sal_uInt16 nResetPage = 1;
|
|
|
|
sal_uInt16 nTitlePages = 1;
|
2010-10-18 14:01:21 +01:00
|
|
|
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())
|
|
|
|
{
|
2011-03-14 16:51:14 +00:00
|
|
|
const sal_uInt16 nCurIdx = mpSh->GetCurPageDesc();
|
2010-10-18 14:01:21 +01:00
|
|
|
const SwPageDesc &rPageDesc = mpSh->GetPageDesc( nCurIdx );
|
|
|
|
|
|
|
|
if (mpIndexDesc != &rPageDesc)
|
|
|
|
{
|
|
|
|
mpNormalDesc = &rPageDesc;
|
|
|
|
bMaybeResetNumbering = lcl_GetPageDesc(mpSh, nResetPage, NULL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++nTitlePages;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lcl_PopCursor(mpSh);
|
|
|
|
|
2012-04-25 11:15:33 +01:00
|
|
|
m_pUseExistingPagesRB->Check();
|
|
|
|
m_pPageCountNF->SetValue(nTitlePages);
|
|
|
|
m_pPageCountNF->SetUpHdl(LINK(this, SwTitlePageDlg, UpHdl));
|
|
|
|
m_pPageCountNF->SetDownHdl(LINK(this, SwTitlePageDlg, DownHdl));
|
2010-10-18 14:01:21 +01:00
|
|
|
|
2012-04-25 11:15:33 +01:00
|
|
|
m_pDocumentStartRB->Check();
|
|
|
|
m_pPageStartNF->Enable(false);
|
|
|
|
m_pPageStartNF->SetValue(lcl_GetCurrentPage(mpSh));
|
2010-10-18 14:01:21 +01:00
|
|
|
Link aStartPageHdl = LINK(this, SwTitlePageDlg, StartPageHdl);
|
2012-04-25 11:15:33 +01:00
|
|
|
m_pDocumentStartRB->SetClickHdl(aStartPageHdl);
|
|
|
|
m_pPageStartRB->SetClickHdl(aStartPageHdl);
|
2010-10-18 14:01:21 +01:00
|
|
|
|
|
|
|
if (bMaybeResetNumbering && nResetPage > 0)
|
|
|
|
{
|
2012-04-25 11:15:33 +01:00
|
|
|
m_pRestartNumberingCB->Check();
|
|
|
|
m_pRestartNumberingNF->SetValue(nResetPage);
|
2010-10-18 14:01:21 +01:00
|
|
|
}
|
2012-04-25 11:15:33 +01:00
|
|
|
m_pRestartNumberingNF->Enable(m_pRestartNumberingCB->IsChecked());
|
2010-10-18 14:01:21 +01:00
|
|
|
|
2012-04-25 11:15:33 +01:00
|
|
|
m_pSetPageNumberNF->SetValue(nSetPage);
|
2010-10-18 14:01:21 +01:00
|
|
|
if (nSetPage > 1)
|
2012-04-25 11:15:33 +01:00
|
|
|
m_pSetPageNumberCB->Check();
|
|
|
|
m_pSetPageNumberNF->Enable(m_pSetPageNumberCB->IsChecked());
|
2010-10-18 14:01:21 +01:00
|
|
|
|
|
|
|
FillList();
|
2012-04-25 11:15:33 +01:00
|
|
|
m_pPagePropertiesPB->SetClickHdl(LINK(this, SwTitlePageDlg, EditHdl));
|
2010-10-18 14:01:21 +01:00
|
|
|
}
|
|
|
|
|
2012-03-01 18:00:32 +01:00
|
|
|
IMPL_LINK_NOARG(SwTitlePageDlg, UpHdl)
|
2010-10-18 14:01:21 +01:00
|
|
|
{
|
2012-04-25 11:15:33 +01:00
|
|
|
if (m_pPageCountNF->GetValue() == 2)
|
2010-10-18 14:01:21 +01:00
|
|
|
FillList();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-03-01 18:00:32 +01:00
|
|
|
IMPL_LINK_NOARG(SwTitlePageDlg, DownHdl)
|
2010-10-18 14:01:21 +01:00
|
|
|
{
|
2012-04-25 11:15:33 +01:00
|
|
|
if (m_pPageCountNF->GetValue() == 1)
|
2010-10-18 14:01:21 +01:00
|
|
|
FillList();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-03-01 18:00:32 +01:00
|
|
|
IMPL_LINK_NOARG(SwTitlePageDlg, RestartNumberingHdl)
|
2010-10-18 14:01:21 +01:00
|
|
|
{
|
2012-04-25 11:15:33 +01:00
|
|
|
m_pRestartNumberingNF->Enable(m_pRestartNumberingCB->IsChecked());
|
2010-10-18 14:01:21 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-03-01 18:00:32 +01:00
|
|
|
IMPL_LINK_NOARG(SwTitlePageDlg, SetPageNumberHdl)
|
2010-10-18 14:01:21 +01:00
|
|
|
{
|
2012-04-25 11:15:33 +01:00
|
|
|
m_pSetPageNumberNF->Enable(m_pSetPageNumberCB->IsChecked());
|
2010-10-18 14:01:21 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-03-01 18:00:32 +01:00
|
|
|
IMPL_LINK_NOARG(SwTitlePageDlg, StartPageHdl)
|
2010-10-18 14:01:21 +01:00
|
|
|
{
|
2012-04-25 11:15:33 +01:00
|
|
|
m_pPageStartNF->Enable(m_pPageStartRB->IsChecked());
|
2010-10-18 14:01:21 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-12-12 00:08:03 +01:00
|
|
|
SwTitlePageDlg::~SwTitlePageDlg()
|
2010-10-18 14:01:21 +01:00
|
|
|
{
|
|
|
|
delete mpPageFmtDesc;
|
|
|
|
}
|
|
|
|
|
2013-01-09 16:06:30 +00:00
|
|
|
IMPL_LINK_NOARG(SwTitlePageDlg, EditHdl)
|
2010-10-18 14:01:21 +01:00
|
|
|
{
|
|
|
|
SwView& rView = mpSh->GetView();
|
2013-08-09 14:20:59 +01:00
|
|
|
rView.GetDocShell()->FormatPage(m_pPagePropertiesLB->GetSelectEntry(), "page", *mpSh);
|
2010-10-18 14:01:21 +01:00
|
|
|
rView.InvalidateRulerPos();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-09 16:06:30 +00:00
|
|
|
IMPL_LINK_NOARG(SwTitlePageDlg, OKHdl)
|
2010-10-18 14:01:21 +01:00
|
|
|
{
|
|
|
|
lcl_PushCursor(mpSh);
|
|
|
|
|
|
|
|
mpSh->StartUndo();
|
|
|
|
|
|
|
|
SwFmtPageDesc aTitleDesc(mpTitleDesc);
|
|
|
|
|
2012-04-25 11:15:33 +01:00
|
|
|
if (m_pSetPageNumberCB->IsChecked())
|
|
|
|
aTitleDesc.SetNumOffset(m_pSetPageNumberNF->GetValue());
|
2010-10-18 14:01:21 +01:00
|
|
|
else if (mpPageFmtDesc)
|
|
|
|
aTitleDesc.SetNumOffset(mpPageFmtDesc->GetNumOffset());
|
|
|
|
|
2012-04-25 11:15:33 +01:00
|
|
|
sal_uInt16 nNoPages = m_pPageCountNF->GetValue();
|
|
|
|
if (!m_pUseExistingPagesRB->IsChecked())
|
2010-10-18 14:01:21 +01:00
|
|
|
{
|
|
|
|
mpSh->GotoPage(GetInsertPosition(), false);
|
2011-03-14 16:51:14 +00:00
|
|
|
for (sal_uInt16 nI=0; nI < nNoPages; ++nI)
|
2010-10-18 14:01:21 +01:00
|
|
|
mpSh->InsertPageBreak();
|
|
|
|
}
|
|
|
|
|
|
|
|
mpSh->GotoPage(GetInsertPosition(), false);
|
2011-03-14 16:51:14 +00:00
|
|
|
for (sal_uInt16 nI=1; nI < nNoPages; ++nI)
|
2010-10-18 14:01:21 +01:00
|
|
|
{
|
|
|
|
if (mpSh->SttNxtPg())
|
|
|
|
lcl_ChangePage(mpSh, 0, mpIndexDesc);
|
|
|
|
}
|
|
|
|
|
|
|
|
mpSh->GotoPage(GetInsertPosition(), false);
|
2013-11-18 11:29:24 +00:00
|
|
|
mpSh->SetAttrItem(aTitleDesc);
|
2010-10-18 14:01:21 +01:00
|
|
|
|
|
|
|
if (nNoPages > 1 && mpSh->GotoPage(GetInsertPosition() + nNoPages, false))
|
|
|
|
{
|
|
|
|
SwFmtPageDesc aPageFmtDesc(mpNormalDesc);
|
2013-11-18 11:29:24 +00:00
|
|
|
mpSh->SetAttrItem(aPageFmtDesc);
|
2010-10-18 14:01:21 +01:00
|
|
|
}
|
|
|
|
|
2012-04-25 11:15:33 +01:00
|
|
|
if (m_pRestartNumberingCB->IsChecked() || nNoPages > 1)
|
2010-10-18 14:01:21 +01:00
|
|
|
{
|
2012-04-25 11:15:33 +01:00
|
|
|
sal_uInt16 nPgNo = m_pRestartNumberingCB->IsChecked() ? m_pRestartNumberingNF->GetValue() : 0;
|
2010-10-18 14:01:21 +01:00
|
|
|
const SwPageDesc *pNewDesc = nNoPages > 1 ? mpNormalDesc : 0;
|
|
|
|
mpSh->GotoPage(GetInsertPosition() + nNoPages, false);
|
|
|
|
lcl_ChangePage(mpSh, nPgNo, pNewDesc);
|
|
|
|
}
|
|
|
|
|
|
|
|
mpSh->EndUndo();
|
|
|
|
lcl_PopCursor(mpSh);
|
2012-04-25 11:15:33 +01:00
|
|
|
if (!m_pUseExistingPagesRB->IsChecked())
|
2010-10-18 14:01:21 +01:00
|
|
|
mpSh->GotoPage(GetInsertPosition(), false);
|
|
|
|
EndDialog( RET_OK );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|