Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <svl/style.hxx>
21 : #include <wrtsh.hxx>
22 : #include <view.hxx>
23 : #include <docsh.hxx>
24 : #include <docfnote.hxx>
25 : #include <impfnote.hxx>
26 : #include <ftninfo.hxx>
27 : #include <fmtcol.hxx>
28 : #include <pagedesc.hxx>
29 : #include <charfmt.hxx>
30 : #include <docstyle.hxx>
31 : #include <wdocsh.hxx>
32 : #include <uitool.hxx>
33 : #include <poolfmt.hxx>
34 : #include <swstyle.h>
35 : #include <helpid.h>
36 : #include <misc.hrc>
37 : #include <frmui.hrc>
38 : #include <SwStyleNameMapper.hxx>
39 :
40 0 : SwFootNoteOptionDlg::SwFootNoteOptionDlg(Window *pParent, SwWrtShell &rS)
41 : : SfxTabDialog(pParent, "FootEndnoteDialog", "modules/swriter/ui/footendnotedialog.ui")
42 0 : , rSh( rS )
43 : {
44 0 : RemoveResetButton();
45 :
46 0 : aOldOkHdl = GetOKButton().GetClickHdl();
47 0 : GetOKButton().SetClickHdl( LINK( this, SwFootNoteOptionDlg, OkHdl ) );
48 :
49 0 : m_nFootNoteId = AddTabPage( "footnotes", SwFootNoteOptionPage::Create, 0 );
50 0 : m_nEndNoteId = AddTabPage( "endnotes", SwEndNoteOptionPage::Create, 0 );
51 0 : }
52 :
53 0 : void SwFootNoteOptionDlg::PageCreated( sal_uInt16 /*nId*/, SfxTabPage &rPage )
54 : {
55 0 : ((SwEndNoteOptionPage&)rPage).SetShell( rSh );
56 0 : }
57 :
58 0 : IMPL_LINK( SwFootNoteOptionDlg, OkHdl, Button *, pBtn )
59 : {
60 0 : SfxItemSet aDummySet(rSh.GetAttrPool(), 1, 1 );
61 0 : SfxTabPage *pPage = GetTabPage( m_nFootNoteId );
62 0 : if ( pPage )
63 0 : pPage->FillItemSet( aDummySet );
64 0 : pPage = GetTabPage( m_nEndNoteId );
65 0 : if ( pPage )
66 0 : pPage->FillItemSet( aDummySet );
67 0 : aOldOkHdl.Call( pBtn );
68 0 : return 0;
69 : }
70 :
71 :
72 : //----------------------------------------------------------------------
73 :
74 :
75 0 : SwEndNoteOptionPage::SwEndNoteOptionPage(Window *pParent, bool bEN,
76 : const SfxItemSet &rSet)
77 : : SfxTabPage(pParent,
78 : bEN ? OString("EndnotePage") : OString("FootnotePage"),
79 : bEN ? OUString("modules/swriter/ui/endnotepage.ui") : OUString("modules/swriter/ui/footnotepage.ui"),
80 : rSet)
81 : , pSh(0)
82 : , bPosDoc(false)
83 0 : , bEndNote(bEN)
84 : {
85 0 : get(m_pNumViewBox, "numberinglb");
86 0 : get(m_pOffsetLbl, "offset");
87 0 : get(m_pOffsetFld, "offsetnf");
88 0 : get(m_pPrefixED, "prefix");
89 0 : get(m_pSuffixED, "suffix");
90 :
91 0 : if (!bEndNote)
92 : {
93 0 : get(m_pNumCountBox, "countinglb");
94 0 : m_pNumCountBox->SetSelectHdl(LINK(this, SwEndNoteOptionPage, NumCountHdl));
95 0 : aNumDoc = m_pNumCountBox->GetEntry(FTNNUM_DOC);
96 0 : aNumPage = m_pNumCountBox->GetEntry(FTNNUM_PAGE);
97 0 : aNumChapter = m_pNumCountBox->GetEntry(FTNNUM_CHAPTER);
98 0 : get(m_pPosPageBox, "pospagecb");
99 0 : m_pPosPageBox->SetClickHdl(LINK(this, SwEndNoteOptionPage, PosPageHdl));
100 0 : get(m_pPosChapterBox, "posdoccb");
101 0 : m_pPosChapterBox->SetClickHdl(LINK(this, SwEndNoteOptionPage, PosChapterHdl));
102 0 : get(m_pPosFT, "pos");
103 0 : m_pPosPageBox->SetAccessibleRelationMemberOf(m_pPosFT);
104 0 : m_pPosChapterBox->SetAccessibleRelationMemberOf(m_pPosFT);
105 0 : get(m_pContEdit, "conted");
106 0 : get(m_pContFromEdit, "contfromed");
107 : }
108 :
109 0 : get(m_pStylesContainer, "allstyles");
110 0 : get(m_pParaTemplBox, "parastylelb");
111 0 : get(m_pPageTemplLbl, "pagestyleft");
112 0 : get(m_pPageTemplBox, "pagestylelb");
113 0 : get(m_pFtnCharAnchorTemplBox, "charanchorstylelb");
114 0 : get(m_pFtnCharTextTemplBox, "charstylelb");
115 0 : }
116 :
117 0 : void SwEndNoteOptionPage::Reset( const SfxItemSet& )
118 : {
119 0 : SwEndNoteInfo *pInf = bEndNote ? new SwEndNoteInfo( pSh->GetEndNoteInfo() )
120 0 : : new SwFtnInfo( pSh->GetFtnInfo() );
121 0 : SfxObjectShell * pDocSh = SfxObjectShell::Current();
122 : sal_uInt16 i;
123 :
124 0 : if (PTR_CAST(SwWebDocShell, pDocSh))
125 0 : m_pStylesContainer->Hide();
126 :
127 0 : if ( bEndNote )
128 : {
129 0 : bPosDoc = true;
130 : }
131 : else
132 : {
133 0 : const SwFtnInfo &rInf = pSh->GetFtnInfo();
134 : // set position (page, chapter)
135 0 : if ( rInf.ePos == FTNPOS_PAGE )
136 : {
137 0 : m_pPosPageBox->Check();
138 0 : m_pPageTemplLbl->Enable(sal_False);
139 0 : m_pPageTemplBox->Enable(sal_False);
140 : }
141 : else
142 : {
143 0 : m_pPosChapterBox->Check();
144 0 : m_pNumCountBox->RemoveEntry(aNumPage);
145 0 : m_pNumCountBox->RemoveEntry(aNumChapter);
146 0 : bPosDoc = true;
147 : }
148 : // reference tests
149 0 : m_pContEdit->SetText(rInf.aQuoVadis);
150 0 : m_pContFromEdit->SetText(rInf.aErgoSum);
151 :
152 : // collected
153 0 : SelectNumbering(rInf.eNum);
154 : }
155 :
156 : // numbering
157 : // art
158 0 : m_pNumViewBox->SelectNumberingType( pInf->aFmt.GetNumberingType());
159 0 : m_pOffsetFld->SetValue(pInf->nFtnOffset + 1);
160 0 : m_pPrefixED->SetText(pInf->GetPrefix().replaceAll("\t", "\\t")); // fdo#65666
161 0 : m_pSuffixED->SetText(pInf->GetSuffix().replaceAll("\t", "\\t"));
162 :
163 : const SwCharFmt* pCharFmt = pInf->GetCharFmt(
164 0 : *pSh->GetView().GetDocShell()->GetDoc());
165 0 : m_pFtnCharTextTemplBox->SelectEntry(pCharFmt->GetName());
166 0 : m_pFtnCharTextTemplBox->SaveValue();
167 :
168 0 : pCharFmt = pInf->GetAnchorCharFmt( *pSh->GetDoc() );
169 0 : m_pFtnCharAnchorTemplBox->SelectEntry( pCharFmt->GetName() );
170 0 : m_pFtnCharAnchorTemplBox->SaveValue();
171 :
172 : // styles special regions
173 : // paragraph
174 0 : SfxStyleSheetBasePool* pStyleSheetPool = pSh->GetView().GetDocShell()->GetStyleSheetPool();
175 0 : pStyleSheetPool->SetSearchMask(SFX_STYLE_FAMILY_PARA, SWSTYLEBIT_EXTRA);
176 0 : SfxStyleSheetBase *pStyle = pStyleSheetPool->First();
177 0 : while(pStyle)
178 : {
179 0 : m_pParaTemplBox->InsertEntry(pStyle->GetName());
180 0 : pStyle = pStyleSheetPool->Next();
181 : }
182 :
183 0 : String sStr;
184 : SwStyleNameMapper::FillUIName( static_cast< sal_uInt16 >(bEndNote ? RES_POOLCOLL_ENDNOTE
185 0 : : RES_POOLCOLL_FOOTNOTE), sStr );
186 0 : if(LISTBOX_ENTRY_NOTFOUND == m_pParaTemplBox->GetEntryPos( sStr ) )
187 0 : m_pParaTemplBox->InsertEntry( sStr );
188 :
189 0 : SwTxtFmtColl* pColl = pInf->GetFtnTxtColl();
190 0 : if( !pColl )
191 0 : m_pParaTemplBox->SelectEntry( sStr ); // Default
192 : else
193 : {
194 : OSL_ENSURE(!pColl->IsDefault(), "default style for footnotes is wrong");
195 0 : const sal_uInt16 nPos = m_pParaTemplBox->GetEntryPos(pColl->GetName());
196 0 : if( LISTBOX_ENTRY_NOTFOUND != nPos )
197 0 : m_pParaTemplBox->SelectEntryPos( nPos );
198 : else
199 : {
200 0 : m_pParaTemplBox->InsertEntry(pColl->GetName());
201 0 : m_pParaTemplBox->SelectEntry(pColl->GetName());
202 : }
203 : }
204 :
205 : // page
206 0 : for( i = RES_POOLPAGE_BEGIN; i < RES_POOLPAGE_END; ++i )
207 0 : m_pPageTemplBox->InsertEntry(SwStyleNameMapper::GetUIName( i, aEmptyStr ));
208 :
209 0 : sal_uInt16 nCount = pSh->GetPageDescCnt();
210 0 : for(i = 0; i < nCount; ++i)
211 : {
212 0 : const SwPageDesc &rPageDesc = pSh->GetPageDesc(i);
213 0 : if(LISTBOX_ENTRY_NOTFOUND == m_pPageTemplBox->GetEntryPos(rPageDesc.GetName()))
214 0 : m_pPageTemplBox->InsertEntry(rPageDesc.GetName());
215 : }
216 :
217 0 : m_pPageTemplBox->SelectEntry( pInf->GetPageDesc( *pSh->GetDoc() )->GetName());
218 0 : delete pInf;
219 0 : }
220 :
221 0 : SwEndNoteOptionPage::~SwEndNoteOptionPage()
222 : {
223 0 : }
224 :
225 0 : SfxTabPage *SwEndNoteOptionPage::Create( Window *pParent, const SfxItemSet &rSet )
226 : {
227 0 : return new SwEndNoteOptionPage( pParent, true, rSet );
228 : }
229 :
230 : /*------------------------------------------------------------------------
231 : Description: Different kinds of numbering; because the Listbox has
232 : varying numbers of entries, here are functions to
233 : set and query the intended kind of numbering.
234 : ------------------------------------------------------------------------*/
235 0 : void SwEndNoteOptionPage::SelectNumbering(int eNum)
236 : {
237 0 : String sSelect;
238 0 : switch(eNum)
239 : {
240 : case FTNNUM_DOC:
241 0 : sSelect = aNumDoc;
242 0 : break;
243 : case FTNNUM_PAGE:
244 0 : sSelect = aNumPage;
245 0 : break;
246 : case FTNNUM_CHAPTER:
247 0 : sSelect = aNumChapter;
248 0 : break;
249 : #if OSL_DEBUG_LEVEL > 0
250 : default:
251 : OSL_FAIL("Which numbering type?");
252 : #endif
253 : }
254 0 : m_pNumCountBox->SelectEntry(sSelect);
255 0 : NumCountHdl(m_pNumCountBox);
256 0 : }
257 :
258 :
259 :
260 0 : int SwEndNoteOptionPage::GetNumbering() const
261 : {
262 0 : const sal_uInt16 nPos = m_pNumCountBox->GetSelectEntryPos();
263 0 : return (int) bPosDoc? nPos + 1: nPos;
264 : }
265 :
266 0 : void SwEndNoteOptionPage::SetShell( SwWrtShell &rShell )
267 : {
268 0 : pSh = &rShell;
269 : // collect character templates
270 0 : m_pFtnCharTextTemplBox->Clear();
271 0 : m_pFtnCharAnchorTemplBox->Clear();
272 : ::FillCharStyleListBox(*m_pFtnCharTextTemplBox,
273 0 : pSh->GetView().GetDocShell());
274 :
275 : ::FillCharStyleListBox(*m_pFtnCharAnchorTemplBox,
276 0 : pSh->GetView().GetDocShell());
277 0 : }
278 :
279 : /*------------------------------------------------------------------------
280 : Description: Handler behind the button to collect the footnote at the
281 : page. In this case all kinds of numbering can be used.
282 : ------------------------------------------------------------------------*/
283 :
284 :
285 0 : IMPL_LINK_NOARG(SwEndNoteOptionPage, PosPageHdl)
286 : {
287 0 : const SwFtnNum eNum = (const SwFtnNum)GetNumbering();
288 0 : bPosDoc = false;
289 0 : if(LISTBOX_ENTRY_NOTFOUND == m_pNumCountBox->GetEntryPos(aNumPage))
290 : {
291 0 : m_pNumCountBox->InsertEntry(aNumPage, FTNNUM_PAGE);
292 0 : m_pNumCountBox->InsertEntry(aNumChapter, FTNNUM_CHAPTER);
293 0 : SelectNumbering(eNum);
294 : }
295 0 : m_pPageTemplLbl->Enable(sal_False);
296 0 : m_pPageTemplBox->Enable(sal_False);
297 :
298 0 : return 0;
299 : }
300 :
301 0 : IMPL_LINK_NOARG(SwEndNoteOptionPage, NumCountHdl)
302 : {
303 0 : sal_Bool bEnable = sal_True;
304 0 : if( m_pNumCountBox->GetEntryCount() - 1 != m_pNumCountBox->GetSelectEntryPos() )
305 : {
306 0 : bEnable = sal_False;
307 0 : m_pOffsetFld->SetValue(1);
308 : }
309 0 : m_pOffsetLbl->Enable(bEnable);
310 0 : m_pOffsetFld->Enable(bEnable);
311 0 : return 0;
312 : }
313 :
314 : /*------------------------------------------------------------------------
315 : Description: Handler behind the button to collect the footnote at the
316 : chapter or end of the document. In this case no pagewise
317 : numbering can be used.
318 : ------------------------------------------------------------------------*/
319 :
320 :
321 0 : IMPL_LINK_NOARG_INLINE_START(SwEndNoteOptionPage, PosChapterHdl)
322 : {
323 0 : if ( !bPosDoc )
324 0 : SelectNumbering(FTNNUM_DOC);
325 :
326 0 : bPosDoc = true;
327 0 : m_pNumCountBox->RemoveEntry(aNumPage);
328 0 : m_pNumCountBox->RemoveEntry(aNumChapter);
329 0 : m_pPageTemplLbl->Enable();
330 0 : m_pPageTemplBox->Enable();
331 0 : return 0;
332 : }
333 0 : IMPL_LINK_NOARG_INLINE_END(SwEndNoteOptionPage, PosChapterHdl)
334 :
335 0 : static SwCharFmt* lcl_GetCharFormat( SwWrtShell* pSh, const String& rCharFmtName )
336 : {
337 0 : SwCharFmt* pFmt = 0;
338 0 : sal_uInt16 nChCount = pSh->GetCharFmtCount();
339 0 : for(sal_uInt16 i = 0; i< nChCount; i++)
340 : {
341 0 : SwCharFmt& rChFmt = pSh->GetCharFmt(i);
342 0 : if(rChFmt.GetName() == rCharFmtName )
343 : {
344 0 : pFmt = &rChFmt;
345 0 : break;
346 : }
347 : }
348 0 : if(!pFmt)
349 : {
350 0 : SfxStyleSheetBasePool* pPool = pSh->GetView().GetDocShell()->GetStyleSheetPool();
351 : SfxStyleSheetBase* pBase;
352 0 : pBase = pPool->Find(rCharFmtName, SFX_STYLE_FAMILY_CHAR);
353 0 : if(!pBase)
354 0 : pBase = &pPool->Make(rCharFmtName, SFX_STYLE_FAMILY_CHAR);
355 0 : pFmt = ((SwDocStyleSheet*)pBase)->GetCharFmt();
356 : }
357 0 : return pFmt;
358 : }
359 :
360 0 : sal_Bool SwEndNoteOptionPage::FillItemSet( SfxItemSet & )
361 : {
362 0 : SwEndNoteInfo *pInf = bEndNote ? new SwEndNoteInfo() : new SwFtnInfo();
363 :
364 0 : pInf->nFtnOffset = static_cast< sal_uInt16 >(m_pOffsetFld->GetValue() -1);
365 0 : pInf->aFmt.SetNumberingType(m_pNumViewBox->GetSelectedNumberingType() );
366 0 : pInf->SetPrefix(m_pPrefixED->GetText().replaceAll("\\t", "\t"));
367 0 : pInf->SetSuffix(m_pSuffixED->GetText().replaceAll("\\t", "\t"));
368 :
369 : pInf->SetCharFmt( lcl_GetCharFormat( pSh,
370 0 : m_pFtnCharTextTemplBox->GetSelectEntry() ) );
371 : pInf->SetAnchorCharFmt( lcl_GetCharFormat( pSh,
372 0 : m_pFtnCharAnchorTemplBox->GetSelectEntry() ) );
373 :
374 : // paragraph template
375 0 : sal_uInt16 nPos = m_pParaTemplBox->GetSelectEntryPos();
376 0 : if(LISTBOX_ENTRY_NOTFOUND != nPos)
377 : {
378 0 : const String aFmtName( m_pParaTemplBox->GetSelectEntry() );
379 0 : SwTxtFmtColl *pColl = pSh->GetParaStyle(aFmtName, SwWrtShell::GETSTYLE_CREATEANY);
380 : OSL_ENSURE(pColl, "paragraph style not found");
381 0 : pInf->SetFtnTxtColl(*pColl);
382 : }
383 :
384 : // page template
385 : pInf->ChgPageDesc( pSh->FindPageDescByName(
386 0 : m_pPageTemplBox->GetSelectEntry(), sal_True ) );
387 :
388 0 : if ( bEndNote )
389 : {
390 0 : if ( !(*pInf == pSh->GetEndNoteInfo()) )
391 0 : pSh->SetEndNoteInfo( *pInf );
392 : }
393 : else
394 : {
395 0 : SwFtnInfo *pI = (SwFtnInfo*)pInf;
396 0 : pI->ePos = m_pPosPageBox->IsChecked() ? FTNPOS_PAGE : FTNPOS_CHAPTER;
397 0 : pI->eNum = (SwFtnNum)GetNumbering();
398 0 : pI->aQuoVadis = m_pContEdit->GetText();
399 0 : pI->aErgoSum = m_pContFromEdit->GetText();
400 0 : if ( !(*pI == pSh->GetFtnInfo()) )
401 0 : pSh->SetFtnInfo( *pI );
402 : }
403 0 : delete pInf;
404 0 : return sal_True;
405 : }
406 :
407 0 : SwFootNoteOptionPage::SwFootNoteOptionPage( Window *pParent, const SfxItemSet &rSet ) :
408 0 : SwEndNoteOptionPage( pParent, false, rSet )
409 : {
410 0 : }
411 :
412 0 : SwFootNoteOptionPage::~SwFootNoteOptionPage()
413 : {
414 0 : }
415 :
416 0 : SfxTabPage *SwFootNoteOptionPage::Create(Window *pParent, const SfxItemSet &rSet )
417 : {
418 0 : return new SwFootNoteOptionPage( pParent, rSet );
419 0 : }
420 :
421 :
422 :
423 :
424 :
425 :
426 :
427 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|