1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <sfx2/viewfrm.hxx>
11 #include <vcl/msgbox.hxx>
13 #include <swmodule.hxx>
15 #include <poolfmt.hxx>
17 #include <charfmt.hxx>
18 #include <docstyle.hxx>
21 #include "lineinfo.hxx"
22 #include "globals.hrc"
23 #include "titlepage.hxx"
25 #include "fmtpdsc.hxx"
26 #include "pagedesc.hxx"
28 #include <IDocumentStylePoolAccess.hxx>
32 bool lcl_GetPageDesc(SwWrtShell
*pSh
, sal_uInt16
&rPageNo
, const SwFmtPageDesc
**ppPageFmtDesc
)
35 SfxItemSet
aSet( pSh
->GetAttrPool(), RES_PAGEDESC
, RES_PAGEDESC
);
36 if (pSh
->GetCurAttr( aSet
))
38 const SfxPoolItem
* pItem(0);
39 if (SFX_ITEM_SET
== aSet
.GetItemState( RES_PAGEDESC
, sal_True
, &pItem
) && pItem
)
41 rPageNo
= ((const SwFmtPageDesc
*)pItem
)->GetNumOffset();
43 (*ppPageFmtDesc
) = (const SwFmtPageDesc
*)(pItem
->Clone());
50 void lcl_ChangePage(SwWrtShell
*pSh
, sal_uInt16 nNewNumber
,
51 const SwPageDesc
*pNewDesc
)
53 const sal_uInt16 nCurIdx
= pSh
->GetCurPageDesc();
54 const SwPageDesc
&rCurrentDesc
= pSh
->GetPageDesc( nCurIdx
);
56 const SwFmtPageDesc
*pPageFmtDesc(0);
58 lcl_GetPageDesc(pSh
, nDontCare
, &pPageFmtDesc
);
60 //If we want a new number then set it, otherwise reuse the existing one
61 sal_uInt16 nPgNo
= nNewNumber
?
62 nNewNumber
: ( pPageFmtDesc
? pPageFmtDesc
->GetNumOffset() : 0 );
64 //If we want a new descriptior then set it, otherwise reuse the existing one
67 SwFmtPageDesc
aPageFmtDesc(pPageFmtDesc
? *pPageFmtDesc
: &rCurrentDesc
);
68 if (nPgNo
) aPageFmtDesc
.SetNumOffset(nPgNo
);
69 pSh
->SetAttr(aPageFmtDesc
);
73 SwFmtPageDesc
aPageFmtDesc(pNewDesc
);
74 if (nPgNo
) aPageFmtDesc
.SetNumOffset(nPgNo
);
75 pSh
->SetAttr(aPageFmtDesc
);
81 void lcl_PushCursor(SwWrtShell
*pSh
)
83 pSh
->LockView( sal_True
);
84 pSh
->StartAllAction();
85 pSh
->SwCrsrShell::Push();
88 void lcl_PopCursor(SwWrtShell
*pSh
)
90 pSh
->SwCrsrShell::Pop( sal_False
);
92 pSh
->LockView( sal_False
);
95 sal_uInt16
lcl_GetCurrentPage(SwWrtShell
*pSh
)
98 sal_uInt16 nPhyNum
=1, nVirtNum
=1;
99 pSh
->GetPageNumber(0, true, nPhyNum
, nVirtNum
, sDummy
);
105 * Only include the Index page in the list if the page count implies one
106 * to reduce confusing things
108 void SwTitlePageDlg::FillList()
110 sal_uInt16 nTitlePages
= m_pPageCountNF
->GetValue();
111 m_pPagePropertiesLB
->Clear();
113 m_pPagePropertiesLB
->InsertEntry(mpTitleDesc
->GetName());
114 if (nTitlePages
> 1 && mpIndexDesc
)
115 m_pPagePropertiesLB
->InsertEntry(mpIndexDesc
->GetName());
117 m_pPagePropertiesLB
->InsertEntry(mpNormalDesc
->GetName());
118 m_pPagePropertiesLB
->SelectEntryPos(0);
121 sal_uInt16
SwTitlePageDlg::GetInsertPosition() const
123 sal_uInt16 nPage
= 1;
124 if (m_pPageStartNF
->IsEnabled())
125 nPage
= m_pPageStartNF
->GetValue();
129 SwTitlePageDlg::SwTitlePageDlg( Window
*pParent
) :
130 SfxModalDialog( pParent
, "DLG_TITLEPAGE", "modules/swriter/ui/titlepage.ui"),
133 get(m_pUseExistingPagesRB
, "RB_USE_EXISTING_PAGES");
134 get(m_pPageCountNF
, "NF_PAGE_COUNT");
135 get(m_pDocumentStartRB
, "RB_DOCUMENT_START");
136 get(m_pPageStartRB
, "RB_PAGE_START");
137 get(m_pPageStartNF
, "NF_PAGE_START");
138 get(m_pRestartNumberingCB
, "CB_RESTART_NUMBERING");
139 get(m_pRestartNumberingNF
, "NF_RESTART_NUMBERING");
140 get(m_pSetPageNumberCB
, "CB_SET_PAGE_NUMBER");
141 get(m_pSetPageNumberNF
, "NF_SET_PAGE_NUMBER");
142 get(m_pPagePropertiesLB
, "LB_PAGE_PROPERTIES");
143 get(m_pPagePropertiesPB
, "PB_PAGE_PROPERTIES");
144 get(m_pOkPB
, "PB_OK");
146 m_pOkPB
->SetClickHdl(LINK(this, SwTitlePageDlg
, OKHdl
));
147 m_pRestartNumberingCB
->SetClickHdl(LINK(this, SwTitlePageDlg
, RestartNumberingHdl
));
148 m_pSetPageNumberCB
->SetClickHdl(LINK(this, SwTitlePageDlg
, SetPageNumberHdl
));
150 sal_uInt16 nSetPage
= 1;
151 sal_uInt16 nResetPage
= 1;
152 sal_uInt16 nTitlePages
= 1;
153 mpSh
= ::GetActiveView()->GetWrtShellPtr();
154 lcl_PushCursor(mpSh
);
156 SwView
& rView
= mpSh
->GetView();
157 rView
.InvalidateRulerPos();
159 bool bMaybeResetNumbering
= false;
161 mpTitleDesc
= mpSh
->GetPageDescFromPool(RES_POOLPAGE_FIRST
);
162 mpIndexDesc
= mpSh
->GetPageDescFromPool(RES_POOLPAGE_REGISTER
);
163 mpNormalDesc
= mpSh
->GetPageDescFromPool(RES_POOLPAGE_STANDARD
);
166 if (lcl_GetPageDesc( mpSh
, nSetPage
, &mpPageFmtDesc
))
168 if (mpPageFmtDesc
->GetPageDesc() == mpTitleDesc
)
170 while (mpSh
->SttNxtPg())
172 const sal_uInt16 nCurIdx
= mpSh
->GetCurPageDesc();
173 const SwPageDesc
&rPageDesc
= mpSh
->GetPageDesc( nCurIdx
);
175 if (mpIndexDesc
!= &rPageDesc
)
177 mpNormalDesc
= &rPageDesc
;
178 bMaybeResetNumbering
= lcl_GetPageDesc(mpSh
, nResetPage
, NULL
);
187 m_pUseExistingPagesRB
->Check();
188 m_pPageCountNF
->SetValue(nTitlePages
);
189 m_pPageCountNF
->SetUpHdl(LINK(this, SwTitlePageDlg
, UpHdl
));
190 m_pPageCountNF
->SetDownHdl(LINK(this, SwTitlePageDlg
, DownHdl
));
192 m_pDocumentStartRB
->Check();
193 m_pPageStartNF
->Enable(false);
194 m_pPageStartNF
->SetValue(lcl_GetCurrentPage(mpSh
));
195 Link aStartPageHdl
= LINK(this, SwTitlePageDlg
, StartPageHdl
);
196 m_pDocumentStartRB
->SetClickHdl(aStartPageHdl
);
197 m_pPageStartRB
->SetClickHdl(aStartPageHdl
);
199 if (bMaybeResetNumbering
&& nResetPage
> 0)
201 m_pRestartNumberingCB
->Check();
202 m_pRestartNumberingNF
->SetValue(nResetPage
);
204 m_pRestartNumberingNF
->Enable(m_pRestartNumberingCB
->IsChecked());
206 m_pSetPageNumberNF
->SetValue(nSetPage
);
208 m_pSetPageNumberCB
->Check();
209 m_pSetPageNumberNF
->Enable(m_pSetPageNumberCB
->IsChecked());
212 m_pPagePropertiesPB
->SetClickHdl(LINK(this, SwTitlePageDlg
, EditHdl
));
215 IMPL_LINK_NOARG(SwTitlePageDlg
, UpHdl
)
217 if (m_pPageCountNF
->GetValue() == 2)
222 IMPL_LINK_NOARG(SwTitlePageDlg
, DownHdl
)
224 if (m_pPageCountNF
->GetValue() == 1)
229 IMPL_LINK_NOARG(SwTitlePageDlg
, RestartNumberingHdl
)
231 m_pRestartNumberingNF
->Enable(m_pRestartNumberingCB
->IsChecked());
235 IMPL_LINK_NOARG(SwTitlePageDlg
, SetPageNumberHdl
)
237 m_pSetPageNumberNF
->Enable(m_pSetPageNumberCB
->IsChecked());
241 IMPL_LINK_NOARG(SwTitlePageDlg
, StartPageHdl
)
243 m_pPageStartNF
->Enable(m_pPageStartRB
->IsChecked());
247 SwTitlePageDlg::~SwTitlePageDlg()
249 delete mpPageFmtDesc
;
252 IMPL_LINK_NOARG(SwTitlePageDlg
, EditHdl
)
254 SwView
& rView
= mpSh
->GetView();
255 rView
.GetDocShell()->FormatPage(m_pPagePropertiesLB
->GetSelectEntry(), false, *mpSh
);
256 rView
.InvalidateRulerPos();
261 IMPL_LINK_NOARG(SwTitlePageDlg
, OKHdl
)
263 lcl_PushCursor(mpSh
);
267 SwFmtPageDesc
aTitleDesc(mpTitleDesc
);
269 if (m_pSetPageNumberCB
->IsChecked())
270 aTitleDesc
.SetNumOffset(m_pSetPageNumberNF
->GetValue());
271 else if (mpPageFmtDesc
)
272 aTitleDesc
.SetNumOffset(mpPageFmtDesc
->GetNumOffset());
274 sal_uInt16 nNoPages
= m_pPageCountNF
->GetValue();
275 if (!m_pUseExistingPagesRB
->IsChecked())
277 mpSh
->GotoPage(GetInsertPosition(), false);
278 for (sal_uInt16 nI
=0; nI
< nNoPages
; ++nI
)
279 mpSh
->InsertPageBreak();
282 mpSh
->GotoPage(GetInsertPosition(), false);
283 for (sal_uInt16 nI
=1; nI
< nNoPages
; ++nI
)
285 if (mpSh
->SttNxtPg())
286 lcl_ChangePage(mpSh
, 0, mpIndexDesc
);
289 mpSh
->GotoPage(GetInsertPosition(), false);
290 mpSh
->SetAttr(aTitleDesc
);
292 if (nNoPages
> 1 && mpSh
->GotoPage(GetInsertPosition() + nNoPages
, false))
294 SwFmtPageDesc
aPageFmtDesc(mpNormalDesc
);
295 mpSh
->SetAttr(aPageFmtDesc
);
298 if (m_pRestartNumberingCB
->IsChecked() || nNoPages
> 1)
300 sal_uInt16 nPgNo
= m_pRestartNumberingCB
->IsChecked() ? m_pRestartNumberingNF
->GetValue() : 0;
301 const SwPageDesc
*pNewDesc
= nNoPages
> 1 ? mpNormalDesc
: 0;
302 mpSh
->GotoPage(GetInsertPosition() + nNoPages
, false);
303 lcl_ChangePage(mpSh
, nPgNo
, pNewDesc
);
308 if (!m_pUseExistingPagesRB
->IsChecked())
309 mpSh
->GotoPage(GetInsertPosition(), false);
314 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */