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 |
#include <sfx2/viewfrm.hxx> |
44 |
#include <vcl/msgbox.hxx> |
45 |
#include <view.hxx> |
46 |
#include <swmodule.hxx> |
47 |
#include <wrtsh.hxx> |
48 |
#include <poolfmt.hxx> |
49 |
#include <docsh.hxx> |
50 |
#include <charfmt.hxx> |
51 |
#include <docstyle.hxx> |
52 |
|
53 |
#include "fldbas.hxx" |
54 |
#include "lineinfo.hxx" |
55 |
#include "globals.hrc" |
56 |
#include "titlepage.hrc" |
57 |
#include "titlepage.hxx" |
58 |
#include "uitool.hxx" |
59 |
#include "fmtpdsc.hxx" |
60 |
#include "pagedesc.hxx" |
61 |
|
62 |
#include <IDocumentStylePoolAccess.hxx> |
63 |
|
64 |
namespace |
65 |
{ |
66 |
bool lcl_GetPageDesc(SwWrtShell *pSh, USHORT &rPageNo, const SwFmtPageDesc **ppPageFmtDesc) |
67 |
{ |
68 |
bool bRet = false; |
69 |
SfxItemSet aSet( pSh->GetAttrPool(), RES_PAGEDESC, RES_PAGEDESC ); |
70 |
if (pSh->GetCurAttr( aSet )) |
71 |
{ |
72 |
const SfxPoolItem* pItem(0); |
73 |
if (SFX_ITEM_SET == aSet.GetItemState( RES_PAGEDESC, TRUE, &pItem ) && pItem) |
74 |
{ |
75 |
rPageNo = ((const SwFmtPageDesc *)pItem)->GetNumOffset(); |
76 |
if (ppPageFmtDesc) |
77 |
(*ppPageFmtDesc) = (const SwFmtPageDesc *)(pItem->Clone()); |
78 |
bRet = true; |
79 |
} |
80 |
} |
81 |
return bRet; |
82 |
} |
83 |
|
84 |
bool lcl_SkipNPages(SwWrtShell *pSh, USHORT nNoPages) |
85 |
{ |
86 |
bool bAllOk = true; |
87 |
for (USHORT nI = 0; nI < nNoPages && bAllOk; ++nI) |
88 |
bAllOk = pSh->SttNxtPg(); |
89 |
return bAllOk; |
90 |
} |
91 |
|
92 |
void lcl_ChangePage(SwWrtShell *pSh, USHORT nNewNumber, |
93 |
const SwPageDesc *pNewDesc) |
94 |
{ |
95 |
const USHORT nCurIdx = pSh->GetCurPageDesc(); |
96 |
const SwPageDesc &rCurrentDesc = pSh->GetPageDesc( nCurIdx ); |
97 |
|
98 |
const SwFmtPageDesc *pPageFmtDesc(0); |
99 |
USHORT nDontCare; |
100 |
lcl_GetPageDesc(pSh, nDontCare, &pPageFmtDesc); |
101 |
|
102 |
//If we want a new number then set it, otherwise reuse the existing one |
103 |
USHORT nPgNo = nNewNumber ? |
104 |
nNewNumber : ( pPageFmtDesc ? pPageFmtDesc->GetNumOffset() : 0 ); |
105 |
|
106 |
//If we want a new descriptior then set it, otherwise reuse the existing one |
107 |
if (!pNewDesc) |
108 |
{ |
109 |
SwFmtPageDesc aPageFmtDesc(pPageFmtDesc ? *pPageFmtDesc : &rCurrentDesc); |
110 |
if (nPgNo) aPageFmtDesc.SetNumOffset(nPgNo); |
111 |
pSh->SetAttr(aPageFmtDesc); |
112 |
} |
113 |
else |
114 |
{ |
115 |
SwFmtPageDesc aPageFmtDesc(pNewDesc); |
116 |
if (nPgNo) aPageFmtDesc.SetNumOffset(nPgNo); |
117 |
pSh->SetAttr(aPageFmtDesc); |
118 |
} |
119 |
|
120 |
delete pPageFmtDesc; |
121 |
} |
122 |
|
123 |
void lcl_PushCursor(SwWrtShell *pSh) |
124 |
{ |
125 |
pSh->LockView( TRUE ); |
126 |
pSh->StartAllAction(); |
127 |
pSh->SwCrsrShell::Push(); |
128 |
} |
129 |
|
130 |
void lcl_PopCursor(SwWrtShell *pSh) |
131 |
{ |
132 |
pSh->SwCrsrShell::Pop( FALSE ); |
133 |
pSh->EndAllAction(); |
134 |
pSh->LockView( FALSE ); |
135 |
} |
136 |
|
137 |
USHORT lcl_GetCurrentPage(SwWrtShell *pSh) |
138 |
{ |
139 |
String sDummy; |
140 |
USHORT nPhyNum=1, nVirtNum=1; |
141 |
pSh->GetPageNumber(0, true, nPhyNum, nVirtNum, sDummy); |
142 |
return nPhyNum; |
143 |
} |
144 |
} |
145 |
|
146 |
/* |
147 |
* Only include the Index page in the list if the page count implies one |
148 |
* to reduce confusing things |
149 |
*/ |
150 |
void SwTitlePageDlg::FillList() |
151 |
{ |
152 |
USHORT nTitlePages = aPageCountNF.GetValue(); |
153 |
aPagePropertiesLB.Clear(); |
154 |
if (mpTitleDesc) |
155 |
aPagePropertiesLB.InsertEntry(mpTitleDesc->GetName()); |
156 |
if (nTitlePages > 1 && mpIndexDesc) |
157 |
aPagePropertiesLB.InsertEntry(mpIndexDesc->GetName()); |
158 |
if (mpNormalDesc) |
159 |
aPagePropertiesLB.InsertEntry(mpNormalDesc->GetName()); |
160 |
aPagePropertiesLB.SelectEntryPos(0); |
161 |
} |
162 |
|
163 |
/*-------------------------------------------------------------------- |
164 |
Beschreibung: |
165 |
--------------------------------------------------------------------*/ |
166 |
|
167 |
USHORT SwTitlePageDlg::GetInsertPosition() const |
168 |
{ |
169 |
USHORT nPage = 1; |
170 |
if (aPageStartNF.IsEnabled()) |
171 |
nPage = aPageStartNF.GetValue(); |
172 |
return nPage; |
173 |
} |
174 |
|
175 |
SwTitlePageDlg::SwTitlePageDlg( Window *pParent ) : |
176 |
SfxModalDialog( pParent, SW_RES(DLG_TITLEPAGE) ), |
177 |
#pragma warning (disable : 4355) |
178 |
aMakeInsertFL ( this, SW_RES( FL_MAKEINSERT )), |
179 |
aUseExistingPagesRB ( this, SW_RES( RB_USE_EXISTING_PAGES )), |
180 |
aInsertNewPagesRB ( this, SW_RES( RB_INSERT_NEW_PAGES )), |
181 |
aPageCountFT ( this, SW_RES( FT_PAGE_COUNT )), |
182 |
aPageCountNF ( this, SW_RES( NF_PAGE_COUNT )), |
183 |
aPagePagesFT ( this, SW_RES( FT_PAGE_PAGES )), |
184 |
aPageStartFT ( this, SW_RES( FT_PAGE_START )), |
185 |
aDocumentStartRB ( this, SW_RES( RB_DOCUMENT_START )), |
186 |
aPageStartRB ( this, SW_RES( RB_PAGE_START )), |
187 |
aPageStartNF ( this, SW_RES( NF_PAGE_START )), |
188 |
aNumberingFL ( this, SW_RES( FL_NUMBERING )), |
189 |
aRestartNumberingCB ( this, SW_RES( CB_RESTART_NUMBERING )), |
190 |
aRestartNumberingFT ( this, SW_RES( FT_RESTART_NUMBERING )), |
191 |
aRestartNumberingNF ( this, SW_RES( NF_RESTART_NUMBERING )), |
192 |
aSetPageNumberCB ( this, SW_RES( CB_SET_PAGE_NUMBER )), |
193 |
aSetPageNumberFT ( this, SW_RES( FT_SET_PAGE_NUMBER )), |
194 |
aSetPageNumberNF ( this, SW_RES( NF_SET_PAGE_NUMBER )), |
195 |
aPagePropertiesFL ( this, SW_RES( FL_PAGE_PROPERTIES )), |
196 |
aPagePropertiesLB ( this, SW_RES( LB_PAGE_PROPERTIES )), |
197 |
aPagePropertiesPB ( this, SW_RES( PB_PAGE_PROPERTIES )), |
198 |
aBottomFL ( this, SW_RES( FL_BOTTOM )), |
199 |
aOkPB ( this, SW_RES( PB_OK )), |
200 |
aCancelPB ( this, SW_RES( PB_CANCEL )), |
201 |
aHelpPB ( this, SW_RES( PB_HELP )), |
202 |
mpPageFmtDesc (0) |
203 |
#pragma warning (default : 4355) |
204 |
{ |
205 |
FreeResource(); |
206 |
|
207 |
aOkPB.SetClickHdl(LINK(this, SwTitlePageDlg, OKHdl)); |
208 |
aRestartNumberingCB.SetClickHdl(LINK(this, SwTitlePageDlg, RestartNumberingHdl)); |
209 |
aSetPageNumberCB.SetClickHdl(LINK(this, SwTitlePageDlg, SetPageNumberHdl)); |
210 |
|
211 |
USHORT nSetPage = 1; |
212 |
USHORT nResetPage = 1; |
213 |
USHORT nTitlePages = 1; |
214 |
mpSh = ::GetActiveView()->GetWrtShellPtr(); |
215 |
lcl_PushCursor(mpSh); |
216 |
|
217 |
SwView& rView = mpSh->GetView(); |
218 |
rView.InvalidateRulerPos(); |
219 |
|
220 |
bool bMaybeResetNumbering = false; |
221 |
|
222 |
mpTitleDesc = mpSh->GetPageDescFromPool(RES_POOLPAGE_FIRST); |
223 |
mpIndexDesc = mpSh->GetPageDescFromPool(RES_POOLPAGE_REGISTER); |
224 |
mpNormalDesc = mpSh->GetPageDescFromPool(RES_POOLPAGE_STANDARD); |
225 |
|
226 |
mpSh->SttDoc(); |
227 |
if (lcl_GetPageDesc( mpSh, nSetPage, &mpPageFmtDesc )) |
228 |
{ |
229 |
if (mpPageFmtDesc->GetPageDesc() == mpTitleDesc) |
230 |
{ |
231 |
while (mpSh->SttNxtPg()) |
232 |
{ |
233 |
const USHORT nCurIdx = mpSh->GetCurPageDesc(); |
234 |
const SwPageDesc &rPageDesc = mpSh->GetPageDesc( nCurIdx ); |
235 |
|
236 |
if (mpIndexDesc != &rPageDesc) |
237 |
{ |
238 |
mpNormalDesc = &rPageDesc; |
239 |
bMaybeResetNumbering = lcl_GetPageDesc(mpSh, nResetPage, NULL); |
240 |
break; |
241 |
} |
242 |
++nTitlePages; |
243 |
} |
244 |
} |
245 |
} |
246 |
lcl_PopCursor(mpSh); |
247 |
|
248 |
aUseExistingPagesRB.Check(); |
249 |
aPageCountNF.SetValue(nTitlePages); |
250 |
aPageCountNF.SetUpHdl(LINK(this, SwTitlePageDlg, UpHdl)); |
251 |
aPageCountNF.SetDownHdl(LINK(this, SwTitlePageDlg, DownHdl)); |
252 |
|
253 |
aDocumentStartRB.Check(); |
254 |
aPageStartNF.Enable(false); |
255 |
aPageStartNF.SetValue(lcl_GetCurrentPage(mpSh)); |
256 |
Link aStartPageHdl = LINK(this, SwTitlePageDlg, StartPageHdl); |
257 |
aDocumentStartRB.SetClickHdl(aStartPageHdl); |
258 |
aPageStartRB.SetClickHdl(aStartPageHdl); |
259 |
|
260 |
if (bMaybeResetNumbering && nResetPage > 0) |
261 |
{ |
262 |
aRestartNumberingCB.Check(); |
263 |
aRestartNumberingNF.SetValue(nResetPage); |
264 |
} |
265 |
aRestartNumberingNF.Enable(aRestartNumberingCB.IsChecked()); |
266 |
|
267 |
aSetPageNumberNF.SetValue(nSetPage); |
268 |
if (nSetPage > 1) |
269 |
aSetPageNumberCB.Check(); |
270 |
aSetPageNumberNF.Enable(aSetPageNumberCB.IsChecked()); |
271 |
|
272 |
FillList(); |
273 |
aPagePropertiesPB.SetClickHdl(LINK(this, SwTitlePageDlg, EditHdl)); |
274 |
} |
275 |
|
276 |
IMPL_LINK(SwTitlePageDlg, UpHdl, NumericField *, EMPTYARG) |
277 |
{ |
278 |
if (aPageCountNF.GetValue() == 2) |
279 |
FillList(); |
280 |
return 0; |
281 |
} |
282 |
|
283 |
IMPL_LINK(SwTitlePageDlg, DownHdl, NumericField *, EMPTYARG) |
284 |
{ |
285 |
if (aPageCountNF.GetValue() == 1) |
286 |
FillList(); |
287 |
return 0; |
288 |
} |
289 |
|
290 |
IMPL_LINK(SwTitlePageDlg, RestartNumberingHdl, CheckBox*, EMPTYARG) |
291 |
{ |
292 |
aRestartNumberingNF.Enable(aRestartNumberingCB.IsChecked()); |
293 |
return 0; |
294 |
} |
295 |
|
296 |
IMPL_LINK(SwTitlePageDlg, SetPageNumberHdl, CheckBox*, EMPTYARG) |
297 |
{ |
298 |
aSetPageNumberNF.Enable(aSetPageNumberCB.IsChecked()); |
299 |
return 0; |
300 |
} |
301 |
|
302 |
IMPL_LINK(SwTitlePageDlg, StartPageHdl, RadioButton*, EMPTYARG) |
303 |
{ |
304 |
aPageStartNF.Enable(aPageStartRB.IsChecked()); |
305 |
return 0; |
306 |
} |
307 |
|
308 |
__EXPORT SwTitlePageDlg::~SwTitlePageDlg() |
309 |
{ |
310 |
delete mpPageFmtDesc; |
311 |
} |
312 |
|
313 |
IMPL_LINK( SwTitlePageDlg, EditHdl, Button *, /*pBtn*/ ) |
314 |
{ |
315 |
SwView& rView = mpSh->GetView(); |
316 |
rView.GetDocShell()->FormatPage(aPagePropertiesLB.GetSelectEntry(), false, mpSh); |
317 |
rView.InvalidateRulerPos(); |
318 |
|
319 |
return 0; |
320 |
} |
321 |
|
322 |
IMPL_LINK( SwTitlePageDlg, OKHdl, Button *, /*pBtn*/ ) |
323 |
{ |
324 |
lcl_PushCursor(mpSh); |
325 |
|
326 |
mpSh->StartUndo(); |
327 |
|
328 |
SwFmtPageDesc aTitleDesc(mpTitleDesc); |
329 |
|
330 |
if (aSetPageNumberCB.IsChecked()) |
331 |
aTitleDesc.SetNumOffset(aSetPageNumberNF.GetValue()); |
332 |
else if (mpPageFmtDesc) |
333 |
aTitleDesc.SetNumOffset(mpPageFmtDesc->GetNumOffset()); |
334 |
|
335 |
USHORT nNoPages = aPageCountNF.GetValue(); |
336 |
if (!aUseExistingPagesRB.IsChecked()) |
337 |
{ |
338 |
mpSh->GotoPage(GetInsertPosition(), false); |
339 |
for (USHORT nI=0; nI < nNoPages; ++nI) |
340 |
mpSh->InsertPageBreak(); |
341 |
} |
342 |
|
343 |
mpSh->GotoPage(GetInsertPosition(), false); |
344 |
for (USHORT nI=1; nI < nNoPages; ++nI) |
345 |
{ |
346 |
if (mpSh->SttNxtPg()) |
347 |
lcl_ChangePage(mpSh, 0, mpIndexDesc); |
348 |
} |
349 |
|
350 |
mpSh->GotoPage(GetInsertPosition(), false); |
351 |
mpSh->SetAttr(aTitleDesc); |
352 |
|
353 |
if (nNoPages > 1 && mpSh->GotoPage(GetInsertPosition() + nNoPages, false)) |
354 |
{ |
355 |
SwFmtPageDesc aPageFmtDesc(mpNormalDesc); |
356 |
mpSh->SetAttr(aPageFmtDesc); |
357 |
} |
358 |
|
359 |
if (aRestartNumberingCB.IsChecked() || nNoPages > 1) |
360 |
{ |
361 |
USHORT nPgNo = aRestartNumberingCB.IsChecked() ? aRestartNumberingNF.GetValue() : 0; |
362 |
const SwPageDesc *pNewDesc = nNoPages > 1 ? mpNormalDesc : 0; |
363 |
mpSh->GotoPage(GetInsertPosition() + nNoPages, false); |
364 |
lcl_ChangePage(mpSh, nPgNo, pNewDesc); |
365 |
} |
366 |
|
367 |
mpSh->EndUndo(); |
368 |
lcl_PopCursor(mpSh); |
369 |
if (!aUseExistingPagesRB.IsChecked()) |
370 |
mpSh->GotoPage(GetInsertPosition(), false); |
371 |
EndDialog( RET_OK ); |
372 |
return 0; |
373 |
} |
374 |
|
375 |
/* vi:set tabstop=4 shiftwidth=4 expandtab: */ |