Added
Link Here
|
1 |
/************************************************************************* |
2 |
* |
3 |
* OpenOffice.org - a multi-platform office productivity suite |
4 |
* |
5 |
* $RCSfile$ |
6 |
* |
7 |
* $Revision$ |
8 |
* |
9 |
* last change: $Author$ $Date$ |
10 |
* |
11 |
* The Contents of this file are made available subject to |
12 |
* the terms of GNU Lesser General Public License Version 2.1. |
13 |
* |
14 |
* |
15 |
* GNU Lesser General Public License Version 2.1 |
16 |
* ============================================= |
17 |
* Copyright 2005 by Sun Microsystems, Inc. |
18 |
* 901 San Antonio Road, Palo Alto, CA 94303, USA |
19 |
* |
20 |
* This library is free software; you can redistribute it and/or |
21 |
* modify it under the terms of the GNU Lesser General Public |
22 |
* License version 2.1, as published by the Free Software Foundation. |
23 |
* |
24 |
* This library is distributed in the hope that it will be useful, |
25 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
26 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
27 |
* Lesser General Public License for more details. |
28 |
* |
29 |
* You should have received a copy of the GNU Lesser General Public |
30 |
* License along with this library; if not, write to the Free Software |
31 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
32 |
* MA 02111-1307 USA |
33 |
* |
34 |
************************************************************************/ |
35 |
|
36 |
// MARKER(update_precomp.py): autogen include statement, do not remove |
37 |
#include "precompiled_sw.hxx" |
38 |
|
39 |
#ifdef SW_DLLIMPLEMENTATION |
40 |
#undef SW_DLLIMPLEMENTATION |
41 |
#endif |
42 |
|
43 |
#ifndef _SFXVIEWFRM_HXX //autogen |
44 |
#include <sfx2/viewfrm.hxx> |
45 |
#endif |
46 |
|
47 |
#ifndef _SFXSTYLE_HXX //autogen |
48 |
#include <svtools/style.hxx> |
49 |
#endif |
50 |
|
51 |
#ifndef _SV_MSGBOX_HXX //autogen |
52 |
#include <vcl/msgbox.hxx> |
53 |
#endif |
54 |
|
55 |
#ifndef _SWVIEW_HXX //autogen |
56 |
#include <view.hxx> |
57 |
#endif |
58 |
#ifndef _SWMODULE_HXX |
59 |
#include <swmodule.hxx> |
60 |
#endif |
61 |
#ifndef _WRTSH_HXX //autogen |
62 |
#include <wrtsh.hxx> |
63 |
#endif |
64 |
#ifndef _POOLFMT_HXX |
65 |
#include <poolfmt.hxx> |
66 |
#endif |
67 |
#ifndef _SWDOCSH_HXX //autogen |
68 |
#include <docsh.hxx> |
69 |
#endif |
70 |
|
71 |
#ifndef _CHARFMT_HXX //autogen |
72 |
#include <charfmt.hxx> |
73 |
#endif |
74 |
|
75 |
#ifndef _DOCSTYLE_HXX //autogen |
76 |
#include <docstyle.hxx> |
77 |
#endif |
78 |
|
79 |
#include "fldbas.hxx" |
80 |
#include "lineinfo.hxx" |
81 |
#include "globals.hrc" |
82 |
#include "titlepage.hrc" |
83 |
#include "titlepage.hxx" |
84 |
#include "uitool.hxx" |
85 |
#include "fmtpdsc.hxx" |
86 |
#include "pagedesc.hxx" |
87 |
|
88 |
#include <IDocumentStylePoolAccess.hxx> |
89 |
|
90 |
namespace |
91 |
{ |
92 |
bool lcl_GetPageDesc(SwWrtShell *pSh, USHORT &rPageNo, const SwFmtPageDesc **ppPageFmtDesc) |
93 |
{ |
94 |
bool bRet = false; |
95 |
SfxItemSet aSet( pSh->GetAttrPool(), RES_PAGEDESC, RES_PAGEDESC ); |
96 |
if (pSh->GetCurAttr( aSet )) |
97 |
{ |
98 |
const SfxPoolItem* pItem(0); |
99 |
if (SFX_ITEM_SET == aSet.GetItemState( RES_PAGEDESC, TRUE, &pItem ) && pItem) |
100 |
{ |
101 |
rPageNo = ((const SwFmtPageDesc *)pItem)->GetNumOffset(); |
102 |
if (ppPageFmtDesc) |
103 |
(*ppPageFmtDesc) = (const SwFmtPageDesc *)(pItem->Clone()); |
104 |
bRet = true; |
105 |
} |
106 |
} |
107 |
return bRet; |
108 |
} |
109 |
|
110 |
bool lcl_SkipNPages(SwWrtShell *pSh, USHORT nNoPages) |
111 |
{ |
112 |
bool bAllOk = true; |
113 |
for (USHORT nI = 0; nI < nNoPages && bAllOk; ++nI) |
114 |
bAllOk = pSh->SttNxtPg(); |
115 |
return bAllOk; |
116 |
} |
117 |
|
118 |
void lcl_ChangePage(SwWrtShell *pSh, USHORT nNewNumber, |
119 |
const SwPageDesc *pNewDesc) |
120 |
{ |
121 |
const USHORT nCurIdx = pSh->GetCurPageDesc(); |
122 |
const SwPageDesc &rCurrentDesc = pSh->GetPageDesc( nCurIdx ); |
123 |
|
124 |
const SwFmtPageDesc *pPageFmtDesc(0); |
125 |
USHORT nDontCare; |
126 |
lcl_GetPageDesc(pSh, nDontCare, &pPageFmtDesc); |
127 |
|
128 |
//If we want a new number then set it, otherwise reuse the existing one |
129 |
USHORT nPgNo = nNewNumber ? |
130 |
nNewNumber : ( pPageFmtDesc ? pPageFmtDesc->GetNumOffset() : 0 ); |
131 |
|
132 |
//If we want a new descriptior then set it, otherwise reuse the existing one |
133 |
if (!pNewDesc) |
134 |
{ |
135 |
SwFmtPageDesc aPageFmtDesc(pPageFmtDesc ? *pPageFmtDesc : &rCurrentDesc); |
136 |
if (nPgNo) aPageFmtDesc.SetNumOffset(nPgNo); |
137 |
pSh->SetAttr(aPageFmtDesc); |
138 |
} |
139 |
else |
140 |
{ |
141 |
SwFmtPageDesc aPageFmtDesc(pNewDesc); |
142 |
if (nPgNo) aPageFmtDesc.SetNumOffset(nPgNo); |
143 |
pSh->SetAttr(aPageFmtDesc); |
144 |
} |
145 |
|
146 |
delete pPageFmtDesc; |
147 |
} |
148 |
|
149 |
void lcl_PushCursor(SwWrtShell *pSh) |
150 |
{ |
151 |
pSh->LockView( TRUE ); |
152 |
pSh->StartAllAction(); |
153 |
pSh->SwCrsrShell::Push(); |
154 |
} |
155 |
|
156 |
void lcl_PopCursor(SwWrtShell *pSh) |
157 |
{ |
158 |
pSh->SwCrsrShell::Pop( FALSE ); |
159 |
pSh->EndAllAction(); |
160 |
pSh->LockView( FALSE ); |
161 |
} |
162 |
|
163 |
USHORT lcl_GetCurrentPage(SwWrtShell *pSh) |
164 |
{ |
165 |
String sDummy; |
166 |
USHORT nPhyNum=1, nVirtNum=1; |
167 |
pSh->GetPageNumber(0, true, nPhyNum, nVirtNum, sDummy); |
168 |
return nPhyNum; |
169 |
} |
170 |
} |
171 |
|
172 |
/* |
173 |
* Only include the Index page in the list if the page count implies one |
174 |
* to reduce confusing things |
175 |
*/ |
176 |
void SwTitlePageDlg::FillList() |
177 |
{ |
178 |
USHORT nTitlePages = aPageCountNF.GetValue(); |
179 |
aPagePropertiesLB.Clear(); |
180 |
if (mpTitleDesc) |
181 |
aPagePropertiesLB.InsertEntry(mpTitleDesc->GetName()); |
182 |
if (nTitlePages > 1 && mpIndexDesc) |
183 |
aPagePropertiesLB.InsertEntry(mpIndexDesc->GetName()); |
184 |
if (mpNormalDesc) |
185 |
aPagePropertiesLB.InsertEntry(mpNormalDesc->GetName()); |
186 |
aPagePropertiesLB.SelectEntryPos(0); |
187 |
} |
188 |
|
189 |
/*-------------------------------------------------------------------- |
190 |
Beschreibung: |
191 |
--------------------------------------------------------------------*/ |
192 |
|
193 |
USHORT SwTitlePageDlg::GetInsertPosition() const |
194 |
{ |
195 |
USHORT nPage = 1; |
196 |
if (aPageStartNF.IsEnabled()) |
197 |
nPage = aPageStartNF.GetValue(); |
198 |
return nPage; |
199 |
} |
200 |
|
201 |
SwTitlePageDlg::SwTitlePageDlg( Window *pParent ) : |
202 |
SfxModalDialog( pParent, SW_RES(DLG_TITLEPAGE) ), |
203 |
#pragma warning (disable : 4355) |
204 |
aMakeInsertFL ( this, SW_RES( FL_MAKEINSERT )), |
205 |
aUseExistingPagesRB ( this, SW_RES( RB_USE_EXISTING_PAGES )), |
206 |
aInsertNewPagesRB ( this, SW_RES( RB_INSERT_NEW_PAGES )), |
207 |
aPageCountFT ( this, SW_RES( FT_PAGE_COUNT )), |
208 |
aPageCountNF ( this, SW_RES( NF_PAGE_COUNT )), |
209 |
aPagePagesFT ( this, SW_RES( FT_PAGE_PAGES )), |
210 |
aPageStartFT ( this, SW_RES( FT_PAGE_START )), |
211 |
aDocumentStartRB ( this, SW_RES( RB_DOCUMENT_START )), |
212 |
aPageStartRB ( this, SW_RES( RB_PAGE_START )), |
213 |
aPageStartNF ( this, SW_RES( NF_PAGE_START )), |
214 |
aNumberingFL ( this, SW_RES( FL_NUMBERING )), |
215 |
aRestartNumberingCB ( this, SW_RES( CB_RESTART_NUMBERING )), |
216 |
aRestartNumberingFT ( this, SW_RES( FT_RESTART_NUMBERING )), |
217 |
aRestartNumberingNF ( this, SW_RES( NF_RESTART_NUMBERING )), |
218 |
aSetPageNumberCB ( this, SW_RES( CB_SET_PAGE_NUMBER )), |
219 |
aSetPageNumberFT ( this, SW_RES( FT_SET_PAGE_NUMBER )), |
220 |
aSetPageNumberNF ( this, SW_RES( NF_SET_PAGE_NUMBER )), |
221 |
aPagePropertiesFL ( this, SW_RES( FL_PAGE_PROPERTIES )), |
222 |
aPagePropertiesLB ( this, SW_RES( LB_PAGE_PROPERTIES )), |
223 |
aPagePropertiesPB ( this, SW_RES( PB_PAGE_PROPERTIES )), |
224 |
aBottomFL ( this, SW_RES( FL_BOTTOM )), |
225 |
aOkPB ( this, SW_RES( PB_OK )), |
226 |
aCancelPB ( this, SW_RES( PB_CANCEL )), |
227 |
aHelpPB ( this, SW_RES( PB_HELP )), |
228 |
mpPageFmtDesc (0) |
229 |
#pragma warning (default : 4355) |
230 |
{ |
231 |
FreeResource(); |
232 |
|
233 |
aOkPB.SetClickHdl(LINK(this, SwTitlePageDlg, OKHdl)); |
234 |
aRestartNumberingCB.SetClickHdl(LINK(this, SwTitlePageDlg, RestartNumberingHdl)); |
235 |
aSetPageNumberCB.SetClickHdl(LINK(this, SwTitlePageDlg, SetPageNumberHdl)); |
236 |
|
237 |
USHORT nSetPage = 1; |
238 |
USHORT nResetPage = 1; |
239 |
USHORT nTitlePages = 1; |
240 |
mpSh = ::GetActiveView()->GetWrtShellPtr(); |
241 |
lcl_PushCursor(mpSh); |
242 |
|
243 |
SwView& rView = mpSh->GetView(); |
244 |
rView.InvalidateRulerPos(); |
245 |
|
246 |
bool bMaybeResetNumbering = false; |
247 |
|
248 |
mpTitleDesc = mpSh->GetPageDescFromPool(RES_POOLPAGE_FIRST); |
249 |
mpIndexDesc = mpSh->GetPageDescFromPool(RES_POOLPAGE_REGISTER); |
250 |
mpNormalDesc = mpSh->GetPageDescFromPool(RES_POOLPAGE_STANDARD); |
251 |
|
252 |
mpSh->SttDoc(); |
253 |
if (lcl_GetPageDesc( mpSh, nSetPage, &mpPageFmtDesc )) |
254 |
{ |
255 |
if (mpPageFmtDesc->GetPageDesc() == mpTitleDesc) |
256 |
{ |
257 |
while (mpSh->SttNxtPg()) |
258 |
{ |
259 |
const USHORT nCurIdx = mpSh->GetCurPageDesc(); |
260 |
const SwPageDesc &rPageDesc = mpSh->GetPageDesc( nCurIdx ); |
261 |
|
262 |
if (mpIndexDesc != &rPageDesc) |
263 |
{ |
264 |
mpNormalDesc = &rPageDesc; |
265 |
bMaybeResetNumbering = lcl_GetPageDesc(mpSh, nResetPage, NULL); |
266 |
break; |
267 |
} |
268 |
++nTitlePages; |
269 |
} |
270 |
} |
271 |
} |
272 |
lcl_PopCursor(mpSh); |
273 |
|
274 |
aUseExistingPagesRB.Check(); |
275 |
aPageCountNF.SetValue(nTitlePages); |
276 |
aPageCountNF.SetUpHdl(LINK(this, SwTitlePageDlg, UpHdl)); |
277 |
aPageCountNF.SetDownHdl(LINK(this, SwTitlePageDlg, DownHdl)); |
278 |
|
279 |
aDocumentStartRB.Check(); |
280 |
aPageStartNF.Enable(false); |
281 |
aPageStartNF.SetValue(lcl_GetCurrentPage(mpSh)); |
282 |
Link aStartPageHdl = LINK(this, SwTitlePageDlg, StartPageHdl); |
283 |
aDocumentStartRB.SetClickHdl(aStartPageHdl); |
284 |
aPageStartRB.SetClickHdl(aStartPageHdl); |
285 |
|
286 |
if (bMaybeResetNumbering && nResetPage > 0) |
287 |
{ |
288 |
aRestartNumberingCB.Check(); |
289 |
aRestartNumberingNF.SetValue(nResetPage); |
290 |
} |
291 |
aRestartNumberingNF.Enable(aRestartNumberingCB.IsChecked()); |
292 |
|
293 |
aSetPageNumberNF.SetValue(nSetPage); |
294 |
if (nSetPage > 1) |
295 |
aSetPageNumberCB.Check(); |
296 |
aSetPageNumberNF.Enable(aSetPageNumberCB.IsChecked()); |
297 |
|
298 |
FillList(); |
299 |
aPagePropertiesPB.SetClickHdl(LINK(this, SwTitlePageDlg, EditHdl)); |
300 |
} |
301 |
|
302 |
IMPL_LINK(SwTitlePageDlg, UpHdl, NumericField *, EMPTYARG) |
303 |
{ |
304 |
if (aPageCountNF.GetValue() == 2) |
305 |
FillList(); |
306 |
return 0; |
307 |
} |
308 |
|
309 |
IMPL_LINK(SwTitlePageDlg, DownHdl, NumericField *, EMPTYARG) |
310 |
{ |
311 |
if (aPageCountNF.GetValue() == 1) |
312 |
FillList(); |
313 |
return 0; |
314 |
} |
315 |
|
316 |
IMPL_LINK(SwTitlePageDlg, RestartNumberingHdl, CheckBox*, EMPTYARG) |
317 |
{ |
318 |
aRestartNumberingNF.Enable(aRestartNumberingCB.IsChecked()); |
319 |
return 0; |
320 |
} |
321 |
|
322 |
IMPL_LINK(SwTitlePageDlg, SetPageNumberHdl, CheckBox*, EMPTYARG) |
323 |
{ |
324 |
aSetPageNumberNF.Enable(aSetPageNumberCB.IsChecked()); |
325 |
return 0; |
326 |
} |
327 |
|
328 |
IMPL_LINK(SwTitlePageDlg, StartPageHdl, RadioButton*, EMPTYARG) |
329 |
{ |
330 |
aPageStartNF.Enable(aPageStartRB.IsChecked()); |
331 |
return 0; |
332 |
} |
333 |
|
334 |
__EXPORT SwTitlePageDlg::~SwTitlePageDlg() |
335 |
{ |
336 |
delete mpPageFmtDesc; |
337 |
} |
338 |
|
339 |
IMPL_LINK( SwTitlePageDlg, EditHdl, Button *, /*pBtn*/ ) |
340 |
{ |
341 |
SwView& rView = mpSh->GetView(); |
342 |
rView.GetDocShell()->FormatPage(aPagePropertiesLB.GetSelectEntry(), false, mpSh); |
343 |
rView.InvalidateRulerPos(); |
344 |
|
345 |
return 0; |
346 |
} |
347 |
|
348 |
IMPL_LINK( SwTitlePageDlg, OKHdl, Button *, /*pBtn*/ ) |
349 |
{ |
350 |
lcl_PushCursor(mpSh); |
351 |
|
352 |
mpSh->StartUndo(); |
353 |
|
354 |
SwFmtPageDesc aTitleDesc(mpTitleDesc); |
355 |
|
356 |
if (aSetPageNumberCB.IsChecked()) |
357 |
aTitleDesc.SetNumOffset(aSetPageNumberNF.GetValue()); |
358 |
else if (mpPageFmtDesc) |
359 |
aTitleDesc.SetNumOffset(mpPageFmtDesc->GetNumOffset()); |
360 |
|
361 |
USHORT nNoPages = aPageCountNF.GetValue(); |
362 |
if (!aUseExistingPagesRB.IsChecked()) |
363 |
{ |
364 |
mpSh->GotoPage(GetInsertPosition(), false); |
365 |
for (USHORT nI=0; nI < nNoPages; ++nI) |
366 |
mpSh->InsertPageBreak(); |
367 |
} |
368 |
|
369 |
mpSh->GotoPage(GetInsertPosition(), false); |
370 |
for (USHORT nI=1; nI < nNoPages; ++nI) |
371 |
{ |
372 |
if (mpSh->SttNxtPg()) |
373 |
lcl_ChangePage(mpSh, 0, mpIndexDesc); |
374 |
} |
375 |
|
376 |
mpSh->GotoPage(GetInsertPosition(), false); |
377 |
mpSh->SetAttr(aTitleDesc); |
378 |
|
379 |
if (nNoPages > 1 && mpSh->GotoPage(GetInsertPosition() + nNoPages, false)) |
380 |
{ |
381 |
SwFmtPageDesc aPageFmtDesc(mpNormalDesc); |
382 |
mpSh->SetAttr(aPageFmtDesc); |
383 |
} |
384 |
|
385 |
if (aRestartNumberingCB.IsChecked() || nNoPages > 1) |
386 |
{ |
387 |
USHORT nPgNo = aRestartNumberingCB.IsChecked() ? aRestartNumberingNF.GetValue() : 0; |
388 |
const SwPageDesc *pNewDesc = nNoPages > 1 ? mpNormalDesc : 0; |
389 |
mpSh->GotoPage(GetInsertPosition() + nNoPages, false); |
390 |
lcl_ChangePage(mpSh, nPgNo, pNewDesc); |
391 |
} |
392 |
|
393 |
mpSh->EndUndo(); |
394 |
lcl_PopCursor(mpSh); |
395 |
if (!aUseExistingPagesRB.IsChecked()) |
396 |
mpSh->GotoPage(GetInsertPosition(), false); |
397 |
EndDialog( RET_OK ); |
398 |
return 0; |
399 |
} |
400 |
|
401 |
/* vi:set tabstop=4 shiftwidth=4 expandtab: */ |