Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * Version: MPL 1.1 / GPLv3+ / LGPLv3+
4 : : *
5 : : * The contents of this file are subject to the Mozilla Public License Version
6 : : * 1.1 (the "License"); you may not use this file except in compliance with
7 : : * the License or as specified alternatively below. You may obtain a copy of
8 : : * the License at http://www.mozilla.org/MPL/
9 : : *
10 : : * Software distributed under the License is distributed on an "AS IS" basis,
11 : : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : : * for the specific language governing rights and limitations under the
13 : : * License.
14 : : *
15 : : * Major Contributor(s):
16 : : * Copyright (C) 2010 Red Hat, Inc., Caolán McNamara <caolanm@redhat.com>
17 : : * (initial developer)
18 : : *
19 : : * All Rights Reserved.
20 : : *
21 : : * For minor contributions see the git repository.
22 : : *
23 : : * Alternatively, the contents of this file may be used under the terms of
24 : : * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
25 : : * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
26 : : * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
27 : : * instead of those above.
28 : : */
29 : :
30 : : #include <sfx2/viewfrm.hxx>
31 : : #include <vcl/msgbox.hxx>
32 : : #include <view.hxx>
33 : : #include <swmodule.hxx>
34 : : #include <wrtsh.hxx>
35 : : #include <poolfmt.hxx>
36 : : #include <docsh.hxx>
37 : : #include <charfmt.hxx>
38 : : #include <docstyle.hxx>
39 : :
40 : : #include "fldbas.hxx"
41 : : #include "lineinfo.hxx"
42 : : #include "globals.hrc"
43 : : #include "titlepage.hrc"
44 : : #include "titlepage.hxx"
45 : : #include "uitool.hxx"
46 : : #include "fmtpdsc.hxx"
47 : : #include "pagedesc.hxx"
48 : :
49 : : #include <IDocumentStylePoolAccess.hxx>
50 : :
51 : : namespace
52 : : {
53 : 0 : bool lcl_GetPageDesc(SwWrtShell *pSh, sal_uInt16 &rPageNo, const SwFmtPageDesc **ppPageFmtDesc)
54 : : {
55 : 0 : bool bRet = false;
56 : 0 : SfxItemSet aSet( pSh->GetAttrPool(), RES_PAGEDESC, RES_PAGEDESC );
57 : 0 : if (pSh->GetCurAttr( aSet ))
58 : : {
59 : 0 : const SfxPoolItem* pItem(0);
60 : 0 : if (SFX_ITEM_SET == aSet.GetItemState( RES_PAGEDESC, sal_True, &pItem ) && pItem)
61 : : {
62 : 0 : rPageNo = ((const SwFmtPageDesc *)pItem)->GetNumOffset();
63 : 0 : if (ppPageFmtDesc)
64 : 0 : (*ppPageFmtDesc) = (const SwFmtPageDesc *)(pItem->Clone());
65 : 0 : bRet = true;
66 : : }
67 : : }
68 : 0 : return bRet;
69 : : }
70 : :
71 : 0 : void lcl_ChangePage(SwWrtShell *pSh, sal_uInt16 nNewNumber,
72 : : const SwPageDesc *pNewDesc)
73 : : {
74 : 0 : const sal_uInt16 nCurIdx = pSh->GetCurPageDesc();
75 : 0 : const SwPageDesc &rCurrentDesc = pSh->GetPageDesc( nCurIdx );
76 : :
77 : 0 : const SwFmtPageDesc *pPageFmtDesc(0);
78 : : sal_uInt16 nDontCare;
79 : 0 : lcl_GetPageDesc(pSh, nDontCare, &pPageFmtDesc);
80 : :
81 : : //If we want a new number then set it, otherwise reuse the existing one
82 : : sal_uInt16 nPgNo = nNewNumber ?
83 : 0 : nNewNumber : ( pPageFmtDesc ? pPageFmtDesc->GetNumOffset() : 0 );
84 : :
85 : : //If we want a new descriptior then set it, otherwise reuse the existing one
86 : 0 : if (!pNewDesc)
87 : : {
88 : 0 : SwFmtPageDesc aPageFmtDesc(pPageFmtDesc ? *pPageFmtDesc : &rCurrentDesc);
89 : 0 : if (nPgNo) aPageFmtDesc.SetNumOffset(nPgNo);
90 : 0 : pSh->SetAttr(aPageFmtDesc);
91 : : }
92 : : else
93 : : {
94 : 0 : SwFmtPageDesc aPageFmtDesc(pNewDesc);
95 : 0 : if (nPgNo) aPageFmtDesc.SetNumOffset(nPgNo);
96 : 0 : pSh->SetAttr(aPageFmtDesc);
97 : : }
98 : :
99 : 0 : delete pPageFmtDesc;
100 : 0 : }
101 : :
102 : 0 : void lcl_PushCursor(SwWrtShell *pSh)
103 : : {
104 : 0 : pSh->LockView( sal_True );
105 : 0 : pSh->StartAllAction();
106 : 0 : pSh->SwCrsrShell::Push();
107 : 0 : }
108 : :
109 : 0 : void lcl_PopCursor(SwWrtShell *pSh)
110 : : {
111 : 0 : pSh->SwCrsrShell::Pop( sal_False );
112 : 0 : pSh->EndAllAction();
113 : 0 : pSh->LockView( sal_False );
114 : 0 : }
115 : :
116 : 0 : sal_uInt16 lcl_GetCurrentPage(SwWrtShell *pSh)
117 : : {
118 : 0 : String sDummy;
119 : 0 : sal_uInt16 nPhyNum=1, nVirtNum=1;
120 : 0 : pSh->GetPageNumber(0, true, nPhyNum, nVirtNum, sDummy);
121 : 0 : return nPhyNum;
122 : : }
123 : : }
124 : :
125 : : /*
126 : : * Only include the Index page in the list if the page count implies one
127 : : * to reduce confusing things
128 : : */
129 : 0 : void SwTitlePageDlg::FillList()
130 : : {
131 : 0 : sal_uInt16 nTitlePages = aPageCountNF.GetValue();
132 : 0 : aPagePropertiesLB.Clear();
133 : 0 : if (mpTitleDesc)
134 : 0 : aPagePropertiesLB.InsertEntry(mpTitleDesc->GetName());
135 : 0 : if (nTitlePages > 1 && mpIndexDesc)
136 : 0 : aPagePropertiesLB.InsertEntry(mpIndexDesc->GetName());
137 : 0 : if (mpNormalDesc)
138 : 0 : aPagePropertiesLB.InsertEntry(mpNormalDesc->GetName());
139 : 0 : aPagePropertiesLB.SelectEntryPos(0);
140 : 0 : }
141 : :
142 : 0 : sal_uInt16 SwTitlePageDlg::GetInsertPosition() const
143 : : {
144 : 0 : sal_uInt16 nPage = 1;
145 : 0 : if (aPageStartNF.IsEnabled())
146 : 0 : nPage = aPageStartNF.GetValue();
147 : 0 : return nPage;
148 : : }
149 : :
150 : 0 : SwTitlePageDlg::SwTitlePageDlg( Window *pParent ) :
151 : : SfxModalDialog( pParent, SW_RES(DLG_TITLEPAGE) ),
152 : : #ifdef MSC
153 : : #pragma warning (disable : 4355)
154 : : #endif
155 : : aMakeInsertFL ( this, SW_RES( FL_MAKEINSERT )),
156 : : aUseExistingPagesRB ( this, SW_RES( RB_USE_EXISTING_PAGES )),
157 : : aInsertNewPagesRB ( this, SW_RES( RB_INSERT_NEW_PAGES )),
158 : : aPageCountFT ( this, SW_RES( FT_PAGE_COUNT )),
159 : : aPageCountNF ( this, SW_RES( NF_PAGE_COUNT )),
160 : : aPagePagesFT ( this, SW_RES( FT_PAGE_PAGES )),
161 : : aPageStartFT ( this, SW_RES( FT_PAGE_START )),
162 : : aDocumentStartRB ( this, SW_RES( RB_DOCUMENT_START )),
163 : : aPageStartRB ( this, SW_RES( RB_PAGE_START )),
164 : : aPageStartNF ( this, SW_RES( NF_PAGE_START )),
165 : : aNumberingFL ( this, SW_RES( FL_NUMBERING )),
166 : : aRestartNumberingCB ( this, SW_RES( CB_RESTART_NUMBERING )),
167 : : aRestartNumberingFT ( this, SW_RES( FT_RESTART_NUMBERING )),
168 : : aRestartNumberingNF ( this, SW_RES( NF_RESTART_NUMBERING )),
169 : : aSetPageNumberCB ( this, SW_RES( CB_SET_PAGE_NUMBER )),
170 : : aSetPageNumberFT ( this, SW_RES( FT_SET_PAGE_NUMBER )),
171 : : aSetPageNumberNF ( this, SW_RES( NF_SET_PAGE_NUMBER )),
172 : : aPagePropertiesFL ( this, SW_RES( FL_PAGE_PROPERTIES )),
173 : : aPagePropertiesLB ( this, SW_RES( LB_PAGE_PROPERTIES )),
174 : : aPagePropertiesPB ( this, SW_RES( PB_PAGE_PROPERTIES )),
175 : : aBottomFL ( this, SW_RES( FL_BOTTOM )),
176 : : aOkPB ( this, SW_RES( PB_OK )),
177 : : aCancelPB ( this, SW_RES( PB_CANCEL )),
178 : : aHelpPB ( this, SW_RES( PB_HELP )),
179 : 0 : mpPageFmtDesc (0)
180 : : #ifdef MSC
181 : : #pragma warning (default : 4355)
182 : : #endif
183 : : {
184 : 0 : FreeResource();
185 : :
186 : 0 : aOkPB.SetClickHdl(LINK(this, SwTitlePageDlg, OKHdl));
187 : 0 : aRestartNumberingCB.SetClickHdl(LINK(this, SwTitlePageDlg, RestartNumberingHdl));
188 : 0 : aSetPageNumberCB.SetClickHdl(LINK(this, SwTitlePageDlg, SetPageNumberHdl));
189 : :
190 : 0 : sal_uInt16 nSetPage = 1;
191 : 0 : sal_uInt16 nResetPage = 1;
192 : 0 : sal_uInt16 nTitlePages = 1;
193 : 0 : mpSh = ::GetActiveView()->GetWrtShellPtr();
194 : 0 : lcl_PushCursor(mpSh);
195 : :
196 : 0 : SwView& rView = mpSh->GetView();
197 : 0 : rView.InvalidateRulerPos();
198 : :
199 : 0 : bool bMaybeResetNumbering = false;
200 : :
201 : 0 : mpTitleDesc = mpSh->GetPageDescFromPool(RES_POOLPAGE_FIRST);
202 : 0 : mpIndexDesc = mpSh->GetPageDescFromPool(RES_POOLPAGE_REGISTER);
203 : 0 : mpNormalDesc = mpSh->GetPageDescFromPool(RES_POOLPAGE_STANDARD);
204 : :
205 : 0 : mpSh->SttDoc();
206 : 0 : if (lcl_GetPageDesc( mpSh, nSetPage, &mpPageFmtDesc ))
207 : : {
208 : 0 : if (mpPageFmtDesc->GetPageDesc() == mpTitleDesc)
209 : : {
210 : 0 : while (mpSh->SttNxtPg())
211 : : {
212 : 0 : const sal_uInt16 nCurIdx = mpSh->GetCurPageDesc();
213 : 0 : const SwPageDesc &rPageDesc = mpSh->GetPageDesc( nCurIdx );
214 : :
215 : 0 : if (mpIndexDesc != &rPageDesc)
216 : : {
217 : 0 : mpNormalDesc = &rPageDesc;
218 : 0 : bMaybeResetNumbering = lcl_GetPageDesc(mpSh, nResetPage, NULL);
219 : 0 : break;
220 : : }
221 : 0 : ++nTitlePages;
222 : : }
223 : : }
224 : : }
225 : 0 : lcl_PopCursor(mpSh);
226 : :
227 : 0 : aUseExistingPagesRB.Check();
228 : 0 : aPageCountNF.SetValue(nTitlePages);
229 : 0 : aPageCountNF.SetUpHdl(LINK(this, SwTitlePageDlg, UpHdl));
230 : 0 : aPageCountNF.SetDownHdl(LINK(this, SwTitlePageDlg, DownHdl));
231 : :
232 : 0 : aDocumentStartRB.Check();
233 : 0 : aPageStartNF.Enable(false);
234 : 0 : aPageStartNF.SetValue(lcl_GetCurrentPage(mpSh));
235 : 0 : Link aStartPageHdl = LINK(this, SwTitlePageDlg, StartPageHdl);
236 : 0 : aDocumentStartRB.SetClickHdl(aStartPageHdl);
237 : 0 : aPageStartRB.SetClickHdl(aStartPageHdl);
238 : :
239 : 0 : if (bMaybeResetNumbering && nResetPage > 0)
240 : : {
241 : 0 : aRestartNumberingCB.Check();
242 : 0 : aRestartNumberingNF.SetValue(nResetPage);
243 : : }
244 : 0 : aRestartNumberingNF.Enable(aRestartNumberingCB.IsChecked());
245 : :
246 : 0 : aSetPageNumberNF.SetValue(nSetPage);
247 : 0 : if (nSetPage > 1)
248 : 0 : aSetPageNumberCB.Check();
249 : 0 : aSetPageNumberNF.Enable(aSetPageNumberCB.IsChecked());
250 : :
251 : 0 : FillList();
252 : 0 : aPagePropertiesPB.SetClickHdl(LINK(this, SwTitlePageDlg, EditHdl));
253 : 0 : }
254 : :
255 : 0 : IMPL_LINK_NOARG(SwTitlePageDlg, UpHdl)
256 : : {
257 : 0 : if (aPageCountNF.GetValue() == 2)
258 : 0 : FillList();
259 : 0 : return 0;
260 : : }
261 : :
262 : 0 : IMPL_LINK_NOARG(SwTitlePageDlg, DownHdl)
263 : : {
264 : 0 : if (aPageCountNF.GetValue() == 1)
265 : 0 : FillList();
266 : 0 : return 0;
267 : : }
268 : :
269 : 0 : IMPL_LINK_NOARG(SwTitlePageDlg, RestartNumberingHdl)
270 : : {
271 : 0 : aRestartNumberingNF.Enable(aRestartNumberingCB.IsChecked());
272 : 0 : return 0;
273 : : }
274 : :
275 : 0 : IMPL_LINK_NOARG(SwTitlePageDlg, SetPageNumberHdl)
276 : : {
277 : 0 : aSetPageNumberNF.Enable(aSetPageNumberCB.IsChecked());
278 : 0 : return 0;
279 : : }
280 : :
281 : 0 : IMPL_LINK_NOARG(SwTitlePageDlg, StartPageHdl)
282 : : {
283 : 0 : aPageStartNF.Enable(aPageStartRB.IsChecked());
284 : 0 : return 0;
285 : : }
286 : :
287 : 0 : SwTitlePageDlg::~SwTitlePageDlg()
288 : : {
289 : 0 : delete mpPageFmtDesc;
290 : 0 : }
291 : :
292 : 0 : IMPL_LINK( SwTitlePageDlg, EditHdl, Button *, /*pBtn*/ )
293 : : {
294 : 0 : SwView& rView = mpSh->GetView();
295 : 0 : rView.GetDocShell()->FormatPage(aPagePropertiesLB.GetSelectEntry(), false, mpSh);
296 : 0 : rView.InvalidateRulerPos();
297 : :
298 : 0 : return 0;
299 : : }
300 : :
301 : 0 : IMPL_LINK( SwTitlePageDlg, OKHdl, Button *, /*pBtn*/ )
302 : : {
303 : 0 : lcl_PushCursor(mpSh);
304 : :
305 : 0 : mpSh->StartUndo();
306 : :
307 : 0 : SwFmtPageDesc aTitleDesc(mpTitleDesc);
308 : :
309 : 0 : if (aSetPageNumberCB.IsChecked())
310 : 0 : aTitleDesc.SetNumOffset(aSetPageNumberNF.GetValue());
311 : 0 : else if (mpPageFmtDesc)
312 : 0 : aTitleDesc.SetNumOffset(mpPageFmtDesc->GetNumOffset());
313 : :
314 : 0 : sal_uInt16 nNoPages = aPageCountNF.GetValue();
315 : 0 : if (!aUseExistingPagesRB.IsChecked())
316 : : {
317 : 0 : mpSh->GotoPage(GetInsertPosition(), false);
318 : 0 : for (sal_uInt16 nI=0; nI < nNoPages; ++nI)
319 : 0 : mpSh->InsertPageBreak();
320 : : }
321 : :
322 : 0 : mpSh->GotoPage(GetInsertPosition(), false);
323 : 0 : for (sal_uInt16 nI=1; nI < nNoPages; ++nI)
324 : : {
325 : 0 : if (mpSh->SttNxtPg())
326 : 0 : lcl_ChangePage(mpSh, 0, mpIndexDesc);
327 : : }
328 : :
329 : 0 : mpSh->GotoPage(GetInsertPosition(), false);
330 : 0 : mpSh->SetAttr(aTitleDesc);
331 : :
332 : 0 : if (nNoPages > 1 && mpSh->GotoPage(GetInsertPosition() + nNoPages, false))
333 : : {
334 : 0 : SwFmtPageDesc aPageFmtDesc(mpNormalDesc);
335 : 0 : mpSh->SetAttr(aPageFmtDesc);
336 : : }
337 : :
338 : 0 : if (aRestartNumberingCB.IsChecked() || nNoPages > 1)
339 : : {
340 : 0 : sal_uInt16 nPgNo = aRestartNumberingCB.IsChecked() ? aRestartNumberingNF.GetValue() : 0;
341 : 0 : const SwPageDesc *pNewDesc = nNoPages > 1 ? mpNormalDesc : 0;
342 : 0 : mpSh->GotoPage(GetInsertPosition() + nNoPages, false);
343 : 0 : lcl_ChangePage(mpSh, nPgNo, pNewDesc);
344 : : }
345 : :
346 : 0 : mpSh->EndUndo();
347 : 0 : lcl_PopCursor(mpSh);
348 : 0 : if (!aUseExistingPagesRB.IsChecked())
349 : 0 : mpSh->GotoPage(GetInsertPosition(), false);
350 : 0 : EndDialog( RET_OK );
351 : 0 : return 0;
352 : : }
353 : :
354 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|