bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / ui / misc / docfnote.cxx
blob63f1dc9da5731a88dea35425a191421aea641448
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
40 SwFootNoteOptionDlg::SwFootNoteOptionDlg( Window *pParent, SwWrtShell &rS ) :
41 SfxTabDialog( pParent, SW_RES(DLG_DOC_FOOTNOTE) ),
42 rSh( rS )
44 FreeResource();
45 RemoveResetButton();
47 aOldOkHdl = GetOKButton().GetClickHdl();
48 GetOKButton().SetClickHdl( LINK( this, SwFootNoteOptionDlg, OkHdl ) );
50 AddTabPage( TP_FOOTNOTEOPTION, SwFootNoteOptionPage::Create, 0 );
51 AddTabPage( TP_ENDNOTEOPTION, SwEndNoteOptionPage::Create, 0 );
54 void SwFootNoteOptionDlg::PageCreated( sal_uInt16 /*nId*/, SfxTabPage &rPage )
56 ((SwEndNoteOptionPage&)rPage).SetShell( rSh );
59 SwFootNoteOptionDlg::~SwFootNoteOptionDlg()
63 IMPL_LINK( SwFootNoteOptionDlg, OkHdl, Button *, pBtn )
65 SfxItemSet aDummySet(rSh.GetAttrPool(), 1, 1 );
66 SfxTabPage *pPage = GetTabPage( TP_FOOTNOTEOPTION );
67 if ( pPage )
68 pPage->FillItemSet( aDummySet );
69 pPage = GetTabPage( TP_ENDNOTEOPTION );
70 if ( pPage )
71 pPage->FillItemSet( aDummySet );
72 aOldOkHdl.Call( pBtn );
73 return 0;
77 //----------------------------------------------------------------------
80 SwEndNoteOptionPage::SwEndNoteOptionPage(Window *pParent, bool bEN,
81 const SfxItemSet &rSet)
82 : SfxTabPage(pParent,
83 bEN ? OString("EndnotePage") : OString("FootnotePage"),
84 bEN ? OUString("modules/swriter/ui/endnotepage.ui") : OUString("modules/swriter/ui/footnotepage.ui"),
85 rSet)
86 , pSh(0)
87 , bPosDoc(false)
88 , bEndNote(bEN)
90 get(m_pNumViewBox, "numberinglb");
91 get(m_pOffsetLbl, "offset");
92 get(m_pOffsetFld, "offsetnf");
93 get(m_pPrefixED, "prefix");
94 get(m_pSuffixED, "suffix");
96 if (!bEndNote)
98 get(m_pNumCountBox, "countinglb");
99 m_pNumCountBox->SetSelectHdl(LINK(this, SwEndNoteOptionPage, NumCountHdl));
100 aNumDoc = m_pNumCountBox->GetEntry(FTNNUM_DOC);
101 aNumPage = m_pNumCountBox->GetEntry(FTNNUM_PAGE);
102 aNumChapter = m_pNumCountBox->GetEntry(FTNNUM_CHAPTER);
103 get(m_pPosPageBox, "pospagecb");
104 m_pPosPageBox->SetClickHdl(LINK(this, SwEndNoteOptionPage, PosPageHdl));
105 get(m_pPosChapterBox, "posdoccb");
106 m_pPosChapterBox->SetClickHdl(LINK(this, SwEndNoteOptionPage, PosChapterHdl));
107 get(m_pPosFT, "pos");
108 m_pPosPageBox->SetAccessibleRelationMemberOf(m_pPosFT);
109 m_pPosChapterBox->SetAccessibleRelationMemberOf(m_pPosFT);
110 get(m_pContEdit, "conted");
111 get(m_pContFromEdit, "contfromed");
114 get(m_pStylesContainer, "allstyles");
115 get(m_pParaTemplBox, "parastylelb");
116 get(m_pPageTemplLbl, "pagestyleft");
117 get(m_pPageTemplBox, "pagestylelb");
118 get(m_pFtnCharAnchorTemplBox, "charanchorstylelb");
119 get(m_pFtnCharTextTemplBox, "charstylelb");
122 void SwEndNoteOptionPage::Reset( const SfxItemSet& )
124 SwEndNoteInfo *pInf = bEndNote ? new SwEndNoteInfo( pSh->GetEndNoteInfo() )
125 : new SwFtnInfo( pSh->GetFtnInfo() );
126 SfxObjectShell * pDocSh = SfxObjectShell::Current();
127 sal_uInt16 i;
129 if (PTR_CAST(SwWebDocShell, pDocSh))
130 m_pStylesContainer->Hide();
132 if ( bEndNote )
134 bPosDoc = true;
136 else
138 const SwFtnInfo &rInf = pSh->GetFtnInfo();
139 // set position (page, chapter)
140 if ( rInf.ePos == FTNPOS_PAGE )
142 m_pPosPageBox->Check();
143 m_pPageTemplLbl->Enable(sal_False);
144 m_pPageTemplBox->Enable(sal_False);
146 else
148 m_pPosChapterBox->Check();
149 m_pNumCountBox->RemoveEntry(aNumPage);
150 m_pNumCountBox->RemoveEntry(aNumChapter);
151 bPosDoc = true;
153 // reference tests
154 m_pContEdit->SetText(rInf.aQuoVadis);
155 m_pContFromEdit->SetText(rInf.aErgoSum);
157 // collected
158 SelectNumbering(rInf.eNum);
161 // numbering
162 // art
163 m_pNumViewBox->SelectNumberingType( pInf->aFmt.GetNumberingType());
164 m_pOffsetFld->SetValue(pInf->nFtnOffset + 1);
165 m_pPrefixED->SetText(pInf->GetPrefix().replaceAll("\t", "\\t")); // fdo#65666
166 m_pSuffixED->SetText(pInf->GetSuffix().replaceAll("\t", "\\t"));
168 const SwCharFmt* pCharFmt = pInf->GetCharFmt(
169 *pSh->GetView().GetDocShell()->GetDoc());
170 m_pFtnCharTextTemplBox->SelectEntry(pCharFmt->GetName());
171 m_pFtnCharTextTemplBox->SaveValue();
173 pCharFmt = pInf->GetAnchorCharFmt( *pSh->GetDoc() );
174 m_pFtnCharAnchorTemplBox->SelectEntry( pCharFmt->GetName() );
175 m_pFtnCharAnchorTemplBox->SaveValue();
177 // styles special regions
178 // paragraph
179 SfxStyleSheetBasePool* pStyleSheetPool = pSh->GetView().GetDocShell()->GetStyleSheetPool();
180 pStyleSheetPool->SetSearchMask(SFX_STYLE_FAMILY_PARA, SWSTYLEBIT_EXTRA);
181 SfxStyleSheetBase *pStyle = pStyleSheetPool->First();
182 while(pStyle)
184 m_pParaTemplBox->InsertEntry(pStyle->GetName());
185 pStyle = pStyleSheetPool->Next();
188 String sStr;
189 SwStyleNameMapper::FillUIName( static_cast< sal_uInt16 >(bEndNote ? RES_POOLCOLL_ENDNOTE
190 : RES_POOLCOLL_FOOTNOTE), sStr );
191 if(LISTBOX_ENTRY_NOTFOUND == m_pParaTemplBox->GetEntryPos( sStr ) )
192 m_pParaTemplBox->InsertEntry( sStr );
194 SwTxtFmtColl* pColl = pInf->GetFtnTxtColl();
195 if( !pColl )
196 m_pParaTemplBox->SelectEntry( sStr ); // Default
197 else
199 OSL_ENSURE(!pColl->IsDefault(), "default style for footnotes is wrong");
200 const sal_uInt16 nPos = m_pParaTemplBox->GetEntryPos(pColl->GetName());
201 if( LISTBOX_ENTRY_NOTFOUND != nPos )
202 m_pParaTemplBox->SelectEntryPos( nPos );
203 else
205 m_pParaTemplBox->InsertEntry(pColl->GetName());
206 m_pParaTemplBox->SelectEntry(pColl->GetName());
210 // page
211 for( i = RES_POOLPAGE_BEGIN; i < RES_POOLPAGE_END; ++i )
212 m_pPageTemplBox->InsertEntry(SwStyleNameMapper::GetUIName( i, aEmptyStr ));
214 sal_uInt16 nCount = pSh->GetPageDescCnt();
215 for(i = 0; i < nCount; ++i)
217 const SwPageDesc &rPageDesc = pSh->GetPageDesc(i);
218 if(LISTBOX_ENTRY_NOTFOUND == m_pPageTemplBox->GetEntryPos(rPageDesc.GetName()))
219 m_pPageTemplBox->InsertEntry(rPageDesc.GetName());
222 m_pPageTemplBox->SelectEntry( pInf->GetPageDesc( *pSh->GetDoc() )->GetName());
223 delete pInf;
226 SwEndNoteOptionPage::~SwEndNoteOptionPage()
230 SfxTabPage *SwEndNoteOptionPage::Create( Window *pParent, const SfxItemSet &rSet )
232 return new SwEndNoteOptionPage( pParent, true, rSet );
235 /*------------------------------------------------------------------------
236 Description: Different kinds of numbering; because the Listbox has
237 varying numbers of entries, here are functions to
238 set and query the intended kind of numbering.
239 ------------------------------------------------------------------------*/
240 void SwEndNoteOptionPage::SelectNumbering(int eNum)
242 String sSelect;
243 switch(eNum)
245 case FTNNUM_DOC:
246 sSelect = aNumDoc;
247 break;
248 case FTNNUM_PAGE:
249 sSelect = aNumPage;
250 break;
251 case FTNNUM_CHAPTER:
252 sSelect = aNumChapter;
253 break;
254 #if OSL_DEBUG_LEVEL > 0
255 default:
256 OSL_FAIL("Which numbering type?");
257 #endif
259 m_pNumCountBox->SelectEntry(sSelect);
260 NumCountHdl(m_pNumCountBox);
265 int SwEndNoteOptionPage::GetNumbering() const
267 const sal_uInt16 nPos = m_pNumCountBox->GetSelectEntryPos();
268 return (int) bPosDoc? nPos + 1: nPos;
271 void SwEndNoteOptionPage::SetShell( SwWrtShell &rShell )
273 pSh = &rShell;
274 // collect character templates
275 m_pFtnCharTextTemplBox->Clear();
276 m_pFtnCharAnchorTemplBox->Clear();
277 ::FillCharStyleListBox(*m_pFtnCharTextTemplBox,
278 pSh->GetView().GetDocShell());
280 ::FillCharStyleListBox(*m_pFtnCharAnchorTemplBox,
281 pSh->GetView().GetDocShell());
284 /*------------------------------------------------------------------------
285 Description: Handler behind the button to collect the footnote at the
286 page. In this case all kinds of numbering can be used.
287 ------------------------------------------------------------------------*/
290 IMPL_LINK_NOARG(SwEndNoteOptionPage, PosPageHdl)
292 const SwFtnNum eNum = (const SwFtnNum)GetNumbering();
293 bPosDoc = false;
294 if(LISTBOX_ENTRY_NOTFOUND == m_pNumCountBox->GetEntryPos(aNumPage))
296 m_pNumCountBox->InsertEntry(aNumPage, FTNNUM_PAGE);
297 m_pNumCountBox->InsertEntry(aNumChapter, FTNNUM_CHAPTER);
298 SelectNumbering(eNum);
300 m_pPageTemplLbl->Enable(sal_False);
301 m_pPageTemplBox->Enable(sal_False);
303 return 0;
306 IMPL_LINK_NOARG(SwEndNoteOptionPage, NumCountHdl)
308 sal_Bool bEnable = sal_True;
309 if( m_pNumCountBox->GetEntryCount() - 1 != m_pNumCountBox->GetSelectEntryPos() )
311 bEnable = sal_False;
312 m_pOffsetFld->SetValue(1);
314 m_pOffsetLbl->Enable(bEnable);
315 m_pOffsetFld->Enable(bEnable);
316 return 0;
319 /*------------------------------------------------------------------------
320 Description: Handler behind the button to collect the footnote at the
321 chapter or end of the document. In this case no pagewise
322 numbering can be used.
323 ------------------------------------------------------------------------*/
326 IMPL_LINK_NOARG_INLINE_START(SwEndNoteOptionPage, PosChapterHdl)
328 if ( !bPosDoc )
329 SelectNumbering(FTNNUM_DOC);
331 bPosDoc = true;
332 m_pNumCountBox->RemoveEntry(aNumPage);
333 m_pNumCountBox->RemoveEntry(aNumChapter);
334 m_pPageTemplLbl->Enable();
335 m_pPageTemplBox->Enable();
336 return 0;
338 IMPL_LINK_NOARG_INLINE_END(SwEndNoteOptionPage, PosChapterHdl)
340 static SwCharFmt* lcl_GetCharFormat( SwWrtShell* pSh, const String& rCharFmtName )
342 SwCharFmt* pFmt = 0;
343 sal_uInt16 nChCount = pSh->GetCharFmtCount();
344 for(sal_uInt16 i = 0; i< nChCount; i++)
346 SwCharFmt& rChFmt = pSh->GetCharFmt(i);
347 if(rChFmt.GetName() == rCharFmtName )
349 pFmt = &rChFmt;
350 break;
353 if(!pFmt)
355 SfxStyleSheetBasePool* pPool = pSh->GetView().GetDocShell()->GetStyleSheetPool();
356 SfxStyleSheetBase* pBase;
357 pBase = pPool->Find(rCharFmtName, SFX_STYLE_FAMILY_CHAR);
358 if(!pBase)
359 pBase = &pPool->Make(rCharFmtName, SFX_STYLE_FAMILY_CHAR);
360 pFmt = ((SwDocStyleSheet*)pBase)->GetCharFmt();
362 return pFmt;
365 sal_Bool SwEndNoteOptionPage::FillItemSet( SfxItemSet & )
367 SwEndNoteInfo *pInf = bEndNote ? new SwEndNoteInfo() : new SwFtnInfo();
369 pInf->nFtnOffset = static_cast< sal_uInt16 >(m_pOffsetFld->GetValue() -1);
370 pInf->aFmt.SetNumberingType(m_pNumViewBox->GetSelectedNumberingType() );
371 pInf->SetPrefix(m_pPrefixED->GetText().replaceAll("\\t", "\t"));
372 pInf->SetSuffix(m_pSuffixED->GetText().replaceAll("\\t", "\t"));
374 pInf->SetCharFmt( lcl_GetCharFormat( pSh,
375 m_pFtnCharTextTemplBox->GetSelectEntry() ) );
376 pInf->SetAnchorCharFmt( lcl_GetCharFormat( pSh,
377 m_pFtnCharAnchorTemplBox->GetSelectEntry() ) );
379 // paragraph template
380 sal_uInt16 nPos = m_pParaTemplBox->GetSelectEntryPos();
381 if(LISTBOX_ENTRY_NOTFOUND != nPos)
383 const String aFmtName( m_pParaTemplBox->GetSelectEntry() );
384 SwTxtFmtColl *pColl = pSh->GetParaStyle(aFmtName, SwWrtShell::GETSTYLE_CREATEANY);
385 OSL_ENSURE(pColl, "paragraph style not found");
386 pInf->SetFtnTxtColl(*pColl);
389 // page template
390 pInf->ChgPageDesc( pSh->FindPageDescByName(
391 m_pPageTemplBox->GetSelectEntry(), sal_True ) );
393 if ( bEndNote )
395 if ( !(*pInf == pSh->GetEndNoteInfo()) )
396 pSh->SetEndNoteInfo( *pInf );
398 else
400 SwFtnInfo *pI = (SwFtnInfo*)pInf;
401 pI->ePos = m_pPosPageBox->IsChecked() ? FTNPOS_PAGE : FTNPOS_CHAPTER;
402 pI->eNum = (SwFtnNum)GetNumbering();
403 pI->aQuoVadis = m_pContEdit->GetText();
404 pI->aErgoSum = m_pContFromEdit->GetText();
405 if ( !(*pI == pSh->GetFtnInfo()) )
406 pSh->SetFtnInfo( *pI );
408 delete pInf;
409 return sal_True;
412 SwFootNoteOptionPage::SwFootNoteOptionPage( Window *pParent, const SfxItemSet &rSet ) :
413 SwEndNoteOptionPage( pParent, false, rSet )
417 SwFootNoteOptionPage::~SwFootNoteOptionPage()
421 SfxTabPage *SwFootNoteOptionPage::Create(Window *pParent, const SfxItemSet &rSet )
423 return new SwFootNoteOptionPage( pParent, rSet );
432 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */