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 |
void lcl_ChangePage(SwWrtShell *pSh, USHORT nNoPages, USHORT nNewNumber, const SwPageDesc *pNewDesc) |
111 |
{ |
112 |
pSh->SttDoc(); |
113 |
FASTBOOL bAllOk = true; |
114 |
|
115 |
for (USHORT nI = 0; nI < nNoPages; ++nI) |
116 |
bAllOk = pSh->SttNxtPg(); |
117 |
|
118 |
if (bAllOk); |
119 |
{ |
120 |
const USHORT nCurIdx = pSh->GetCurPageDesc(); |
121 |
const SwPageDesc &rCurrentDesc = pSh->GetPageDesc( nCurIdx ); |
122 |
|
123 |
const SwFmtPageDesc *pPageFmtDesc(0); |
124 |
USHORT nDontCare; |
125 |
lcl_GetPageDesc(pSh, nDontCare, &pPageFmtDesc); |
126 |
|
127 |
//If we want a new number then set it, otherwise reuse the existing one |
128 |
USHORT nPgNo = nNewNumber ? nNewNumber : ( pPageFmtDesc ? pPageFmtDesc->GetNumOffset() : 0 ); |
129 |
|
130 |
//If we want a new descriptior then set it, otherwise reuse the existing one |
131 |
if (!pNewDesc) |
132 |
{ |
133 |
SwFmtPageDesc aPageFmtDesc(pPageFmtDesc ? *pPageFmtDesc : &rCurrentDesc); |
134 |
if (nPgNo) aPageFmtDesc.SetNumOffset(nPgNo); |
135 |
pSh->SetAttr(aPageFmtDesc); |
136 |
} |
137 |
else |
138 |
{ |
139 |
SwFmtPageDesc aPageFmtDesc(pNewDesc); |
140 |
if (nPgNo) aPageFmtDesc.SetNumOffset(nPgNo); |
141 |
pSh->SetAttr(aPageFmtDesc); |
142 |
} |
143 |
|
144 |
delete pPageFmtDesc; |
145 |
} |
146 |
} |
147 |
|
148 |
void lcl_PushCursor(SwWrtShell *pSh) |
149 |
{ |
150 |
pSh->LockView( TRUE ); |
151 |
pSh->StartAllAction(); |
152 |
pSh->SwCrsrShell::Push(); |
153 |
pSh->SttDoc(); |
154 |
} |
155 |
|
156 |
void lcl_PopCursor(SwWrtShell *pSh) |
157 |
{ |
158 |
pSh->SwCrsrShell::Pop( FALSE ); |
159 |
pSh->EndAllAction(); |
160 |
pSh->LockView( FALSE ); |
161 |
} |
162 |
} |
163 |
|
164 |
/* |
165 |
* Only include the Index page in the list if the page count implies one |
166 |
* to reduce confusing things |
167 |
*/ |
168 |
void SwTitlePageDlg::FillList() |
169 |
{ |
170 |
USHORT nTitlePages = aPageCountNF.GetValue(); |
171 |
aPagePropertiesLB.Clear(); |
172 |
if (mpTitleDesc) |
173 |
aPagePropertiesLB.InsertEntry(mpTitleDesc->GetName()); |
174 |
if (nTitlePages > 1 && mpIndexDesc) |
175 |
aPagePropertiesLB.InsertEntry(mpIndexDesc->GetName()); |
176 |
if (mpNormalDesc) |
177 |
aPagePropertiesLB.InsertEntry(mpNormalDesc->GetName()); |
178 |
aPagePropertiesLB.SelectEntryPos(0); |
179 |
} |
180 |
|
181 |
/*-------------------------------------------------------------------- |
182 |
Beschreibung: |
183 |
--------------------------------------------------------------------*/ |
184 |
|
185 |
SwTitlePageDlg::SwTitlePageDlg( Window *pParent ) : |
186 |
SfxModalDialog( pParent, SW_RES(DLG_TITLEPAGE) ), |
187 |
#pragma warning (disable : 4355) |
188 |
aMakeInsertFL ( this, SW_RES( FL_MAKEINSERT )), |
189 |
aUseExistingPagesRB ( this, SW_RES( RB_USE_EXISTING_PAGES )), |
190 |
aInsertNewPagesRB ( this, SW_RES( RB_INSERT_NEW_PAGES )), |
191 |
aPageCountFT ( this, SW_RES( FT_PAGE_COUNT )), |
192 |
aPageCountNF ( this, SW_RES( NF_PAGE_COUNT )), |
193 |
aPagePagesFT ( this, SW_RES( FT_PAGE_PAGES )), |
194 |
aNumberingFL ( this, SW_RES( FL_NUMBERING )), |
195 |
aRestartNumberingCB ( this, SW_RES( CB_RESTART_NUMBERING )), |
196 |
aRestartNumberingFT ( this, SW_RES( FT_RESTART_NUMBERING )), |
197 |
aRestartNumberingNF ( this, SW_RES( NF_RESTART_NUMBERING )), |
198 |
aSetPageNumberCB ( this, SW_RES( CB_SET_PAGE_NUMBER )), |
199 |
aSetPageNumberFT ( this, SW_RES( FT_SET_PAGE_NUMBER )), |
200 |
aSetPageNumberNF ( this, SW_RES( NF_SET_PAGE_NUMBER )), |
201 |
aPagePropertiesFL ( this, SW_RES( FL_PAGE_PROPERTIES )), |
202 |
aPagePropertiesLB ( this, SW_RES( LB_PAGE_PROPERTIES )), |
203 |
aPagePropertiesPB ( this, SW_RES( PB_PAGE_PROPERTIES )), |
204 |
aBottomFL ( this, SW_RES( FL_BOTTOM )), |
205 |
aOkPB ( this, SW_RES( PB_OK )), |
206 |
aCancelPB ( this, SW_RES( PB_CANCEL )), |
207 |
aHelpPB ( this, SW_RES( PB_HELP )), |
208 |
mpPageFmtDesc (0) |
209 |
#pragma warning (default : 4355) |
210 |
{ |
211 |
FreeResource(); |
212 |
|
213 |
aOkPB.SetClickHdl(LINK(this, SwTitlePageDlg, OKHdl)); |
214 |
aRestartNumberingCB.SetClickHdl(LINK(this, SwTitlePageDlg, RestartNumberingHdl)); |
215 |
aSetPageNumberCB.SetClickHdl(LINK(this, SwTitlePageDlg, SetPageNumberHdl)); |
216 |
|
217 |
USHORT nSetPage = 1; |
218 |
USHORT nResetPage = 1; |
219 |
USHORT nTitlePages = 1; |
220 |
SwWrtShell* pSh = ::GetActiveView()->GetWrtShellPtr(); |
221 |
lcl_PushCursor(pSh); |
222 |
|
223 |
SwView& rView = pSh->GetView(); |
224 |
rView.InvalidateRulerPos(); |
225 |
|
226 |
bool bMaybeResetNumbering = false; |
227 |
|
228 |
mpTitleDesc = pSh->GetPageDescFromPool(RES_POOLPAGE_FIRST); |
229 |
mpIndexDesc = pSh->GetPageDescFromPool(RES_POOLPAGE_REGISTER); |
230 |
mpNormalDesc = pSh->GetPageDescFromPool(RES_POOLPAGE_STANDARD); |
231 |
|
232 |
if (lcl_GetPageDesc( pSh, nSetPage, &mpPageFmtDesc )) |
233 |
{ |
234 |
if (mpPageFmtDesc->GetPageDesc() == mpTitleDesc) |
235 |
{ |
236 |
while (pSh->SttNxtPg()) |
237 |
{ |
238 |
const USHORT nCurIdx = pSh->GetCurPageDesc(); |
239 |
const SwPageDesc &rPageDesc = pSh->GetPageDesc( nCurIdx ); |
240 |
|
241 |
if (mpIndexDesc != &rPageDesc) |
242 |
{ |
243 |
mpNormalDesc = &rPageDesc; |
244 |
bMaybeResetNumbering = lcl_GetPageDesc(pSh, nResetPage, NULL); |
245 |
break; |
246 |
} |
247 |
++nTitlePages; |
248 |
} |
249 |
pSh->SttDoc(); |
250 |
} |
251 |
} |
252 |
lcl_PopCursor(pSh); |
253 |
|
254 |
aUseExistingPagesRB.Check(); |
255 |
aPageCountNF.SetValue(nTitlePages); |
256 |
aPageCountNF.SetUpHdl(LINK(this, SwTitlePageDlg, UpHdl)); |
257 |
aPageCountNF.SetDownHdl(LINK(this, SwTitlePageDlg, DownHdl)); |
258 |
|
259 |
if (bMaybeResetNumbering && nResetPage > 0) |
260 |
{ |
261 |
aRestartNumberingCB.Check(); |
262 |
aRestartNumberingNF.SetValue(nResetPage); |
263 |
} |
264 |
aRestartNumberingNF.Enable(aRestartNumberingCB.IsChecked()); |
265 |
|
266 |
aSetPageNumberNF.SetValue(nSetPage); |
267 |
if (nSetPage > 1) |
268 |
aSetPageNumberCB.Check(); |
269 |
aSetPageNumberNF.Enable(aSetPageNumberCB.IsChecked()); |
270 |
|
271 |
FillList(); |
272 |
aPagePropertiesPB.SetClickHdl(LINK(this, SwTitlePageDlg, EditHdl)); |
273 |
} |
274 |
|
275 |
IMPL_LINK(SwTitlePageDlg, UpHdl, NumericField *, EMPTYARG) |
276 |
{ |
277 |
if (aPageCountNF.GetValue() == 2) |
278 |
FillList(); |
279 |
return 0; |
280 |
} |
281 |
|
282 |
IMPL_LINK(SwTitlePageDlg, DownHdl, NumericField *, EMPTYARG) |
283 |
{ |
284 |
if (aPageCountNF.GetValue() == 1) |
285 |
FillList(); |
286 |
return 0; |
287 |
} |
288 |
|
289 |
IMPL_LINK(SwTitlePageDlg, RestartNumberingHdl, CheckBox*, EMPTYARG) |
290 |
{ |
291 |
aRestartNumberingNF.Enable(aRestartNumberingCB.IsChecked()); |
292 |
return 0; |
293 |
} |
294 |
|
295 |
IMPL_LINK(SwTitlePageDlg, SetPageNumberHdl, CheckBox*, EMPTYARG) |
296 |
{ |
297 |
aSetPageNumberNF.Enable(aSetPageNumberCB.IsChecked()); |
298 |
return 0; |
299 |
} |
300 |
|
301 |
/*-------------------------------------------------------------------- |
302 |
Beschreibung: |
303 |
--------------------------------------------------------------------*/ |
304 |
|
305 |
__EXPORT SwTitlePageDlg::~SwTitlePageDlg() |
306 |
{ |
307 |
delete mpPageFmtDesc; |
308 |
} |
309 |
|
310 |
/*-------------------------------------------------------------------- |
311 |
Beschreibung: |
312 |
--------------------------------------------------------------------*/ |
313 |
|
314 |
IMPL_LINK( SwTitlePageDlg, EditHdl, Button *, pBtn ) |
315 |
{ |
316 |
SwWrtShell* pSh = ::GetActiveView()->GetWrtShellPtr(); |
317 |
SwView& rView = pSh->GetView(); |
318 |
rView.GetDocShell()->FormatPage(aPagePropertiesLB.GetSelectEntry(), false, pSh); |
319 |
rView.InvalidateRulerPos(); |
320 |
|
321 |
return 0; |
322 |
} |
323 |
|
324 |
IMPL_LINK( SwTitlePageDlg, OKHdl, Button *, pBtn ) |
325 |
{ |
326 |
SwWrtShell* pSh = ::GetActiveView()->GetWrtShellPtr(); |
327 |
lcl_PushCursor(pSh); |
328 |
pSh->StartUndo(); |
329 |
|
330 |
SwFmtPageDesc aTitleDesc(mpTitleDesc); |
331 |
|
332 |
if (aSetPageNumberCB.IsChecked()) |
333 |
aTitleDesc.SetNumOffset(aSetPageNumberNF.GetValue()); |
334 |
else if (mpPageFmtDesc) |
335 |
aTitleDesc.SetNumOffset(mpPageFmtDesc->GetNumOffset()); |
336 |
|
337 |
USHORT nNoPages = aPageCountNF.GetValue(); |
338 |
if (!aUseExistingPagesRB.IsChecked()) |
339 |
{ |
340 |
for (USHORT nI=0; nI < nNoPages; ++nI) |
341 |
pSh->InsertPageBreak(); |
342 |
} |
343 |
for (USHORT nI=1; nI < nNoPages; ++nI) |
344 |
lcl_ChangePage(pSh, nI, 0, mpIndexDesc); |
345 |
|
346 |
pSh->SttDoc(); |
347 |
pSh->SetAttr(aTitleDesc); |
348 |
|
349 |
if (nNoPages > 1 && pSh->GotoPage(nNoPages, false)) |
350 |
{ |
351 |
SwFmtPageDesc aPageFmtDesc(mpNormalDesc); |
352 |
pSh->SetAttr(aPageFmtDesc); |
353 |
} |
354 |
|
355 |
if (aRestartNumberingCB.IsChecked() || nNoPages > 1) |
356 |
{ |
357 |
USHORT nPgNo = aRestartNumberingCB.IsChecked() ? aRestartNumberingNF.GetValue() : 0; |
358 |
const SwPageDesc *pNewDesc = nNoPages > 1 ? mpNormalDesc : 0; |
359 |
lcl_ChangePage(pSh, nNoPages, nPgNo, pNewDesc); |
360 |
} |
361 |
|
362 |
pSh->EndUndo(); |
363 |
lcl_PopCursor(pSh); |
364 |
if (!aUseExistingPagesRB.IsChecked()) |
365 |
pSh->SttDoc(); |
366 |
EndDialog( RET_OK ); |
367 |
return 0; |
368 |
} |