LibreOffice Module sw (master)  1
docfnote.cxx
Go to the documentation of this file.
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 <SwStyleNameMapper.hxx>
35 #include <memory>
36 
38  : SfxTabDialogController(pParent, "modules/swriter/ui/footendnotedialog.ui", "FootEndnoteDialog")
39  , rSh( rS )
40 {
42 
44 
45  AddTabPage("footnotes", SwFootNoteOptionPage::Create, nullptr);
46  AddTabPage("endnotes", SwEndNoteOptionPage::Create, nullptr);
47 }
48 
49 void SwFootNoteOptionDlg::PageCreated(const OString& /*rId*/, SfxTabPage &rPage)
50 {
51  static_cast<SwEndNoteOptionPage&>(rPage).SetShell(rSh);
52 }
53 
55 {
56  SfxItemSet aDummySet(rSh.GetAttrPool(), svl::Items<1, 1>{} );
57  SfxTabPage *pPage = GetTabPage("footnotes");
58  if ( pPage )
59  pPage->FillItemSet( &aDummySet );
60  pPage = GetTabPage("endnotes");
61  if ( pPage )
62  pPage->FillItemSet( &aDummySet );
63  SfxTabDialogController::OkHdl(rBtn);
64 }
65 
67  const SfxItemSet &rSet)
68  : SfxTabPage(pParent,
69  bEN ? OUString("modules/swriter/ui/endnotepage.ui") : OUString("modules/swriter/ui/footnotepage.ui"),
70  bEN ? OString("EndnotePage") : OString("FootnotePage"),
71  &rSet)
72  , pSh(nullptr)
73  , bPosDoc(false)
74  , bEndNote(bEN)
75  , m_xNumViewBox(new SwNumberingTypeListBox(m_xBuilder->weld_combo_box("numberinglb")))
76  , m_xOffsetLbl(m_xBuilder->weld_label("offset"))
77  , m_xOffsetField(m_xBuilder->weld_spin_button("offsetnf"))
78  , m_xNumCountBox(m_xBuilder->weld_combo_box("countinglb"))
79  , m_xPrefixED(m_xBuilder->weld_entry("prefix"))
80  , m_xSuffixED(m_xBuilder->weld_entry("suffix"))
81  , m_xPosFT(m_xBuilder->weld_label("pos"))
82  , m_xPosPageBox(m_xBuilder->weld_radio_button("pospagecb"))
83  , m_xPosChapterBox(m_xBuilder->weld_radio_button("posdoccb"))
84  , m_xStylesContainer(m_xBuilder->weld_widget("allstyles"))
85  , m_xParaTemplBox(m_xBuilder->weld_combo_box("parastylelb"))
86  , m_xPageTemplLbl(m_xBuilder->weld_label("pagestyleft"))
87  , m_xPageTemplBox(m_xBuilder->weld_combo_box("pagestylelb"))
88  , m_xFootnoteCharAnchorTemplBox(m_xBuilder->weld_combo_box("charanchorstylelb"))
89  , m_xFootnoteCharTextTemplBox(m_xBuilder->weld_combo_box("charstylelb"))
90  , m_xContEdit(m_xBuilder->weld_entry("conted"))
91  , m_xContFromEdit(m_xBuilder->weld_entry("contfromed"))
92 {
94  if (!bEndNote)
95  {
96  m_xNumCountBox->connect_changed(LINK(this, SwEndNoteOptionPage, NumCountHdl));
97  aNumDoc = m_xNumCountBox->get_text(FTNNUM_DOC);
98  aNumPage = m_xNumCountBox->get_text(FTNNUM_PAGE);
100  m_xPosPageBox->connect_clicked(LINK(this, SwEndNoteOptionPage, PosPageHdl));
101  m_xPosChapterBox->connect_clicked(LINK(this, SwEndNoteOptionPage, PosChapterHdl));
102  }
103 
104 }
105 
107 {
108  disposeOnce();
109 }
110 
112 {
113  std::unique_ptr<SwEndNoteInfo> pInf(bEndNote ? new SwEndNoteInfo( pSh->GetEndNoteInfo() )
114  : new SwFootnoteInfo( pSh->GetFootnoteInfo() ));
116 
117  if (dynamic_cast<SwWebDocShell*>( pDocSh) )
118  m_xStylesContainer->hide();
119 
120  if ( bEndNote )
121  {
122  bPosDoc = true;
123  }
124  else
125  {
126  const SwFootnoteInfo &rInf = pSh->GetFootnoteInfo();
127  // set position (page, chapter)
128  if ( rInf.ePos == FTNPOS_PAGE )
129  {
130  m_xPosPageBox->set_active(true);
131  m_xPageTemplLbl->set_sensitive(false);
132  m_xPageTemplBox->set_sensitive(false);
133  }
134  else
135  {
136  m_xPosChapterBox->set_active(true);
137  m_xNumCountBox->remove_text(aNumPage);
138  m_xNumCountBox->remove_text(aNumChapter);
139  bPosDoc = true;
140  }
141  // reference tests
142  m_xContEdit->set_text(rInf.aQuoVadis);
143  m_xContFromEdit->set_text(rInf.aErgoSum);
144 
145  // collected
146  SelectNumbering(rInf.eNum);
147  }
148 
149  // numbering
150  // art
151  m_xNumViewBox->SelectNumberingType( pInf->aFormat.GetNumberingType());
152  m_xOffsetField->set_value(pInf->nFootnoteOffset + 1);
153  m_xPrefixED->set_text(pInf->GetPrefix().replaceAll("\t", "\\t")); // fdo#65666
154  m_xSuffixED->set_text(pInf->GetSuffix().replaceAll("\t", "\\t"));
155 
156  const SwCharFormat* pCharFormat = pInf->GetCharFormat(
157  *pSh->GetView().GetDocShell()->GetDoc());
158  m_xFootnoteCharTextTemplBox->set_active_text(pCharFormat->GetName());
159  m_xFootnoteCharTextTemplBox->save_value();
160 
161  pCharFormat = pInf->GetAnchorCharFormat( *pSh->GetDoc() );
162  m_xFootnoteCharAnchorTemplBox->set_active_text( pCharFormat->GetName() );
163  m_xFootnoteCharAnchorTemplBox->save_value();
164 
165  // styles special regions
166  // paragraph
168  pStyleSheetPool->SetSearchMask(SfxStyleFamily::Para, SfxStyleSearchBits::SwExtra);
169  SfxStyleSheetBase *pStyle = pStyleSheetPool->First();
170  while(pStyle)
171  {
172  m_xParaTemplBox->append_text(pStyle->GetName());
173  pStyle = pStyleSheetPool->Next();
174  }
175 
176  OUString sStr;
177  SwStyleNameMapper::FillUIName( static_cast< sal_uInt16 >(bEndNote ? RES_POOLCOLL_ENDNOTE
178  : RES_POOLCOLL_FOOTNOTE), sStr );
179  if (m_xParaTemplBox->find_text(sStr) == -1)
180  m_xParaTemplBox->append_text(sStr);
181 
182  SwTextFormatColl* pColl = pInf->GetFootnoteTextColl();
183  if( !pColl )
184  m_xParaTemplBox->set_active_text(sStr); // Default
185  else
186  {
187  OSL_ENSURE(!pColl->IsDefault(), "default style for footnotes is wrong");
188  const int nPos = m_xParaTemplBox->find_text(pColl->GetName());
189  if (nPos != -1)
190  m_xParaTemplBox->set_active( nPos );
191  else
192  {
193  m_xParaTemplBox->append_text(pColl->GetName());
194  m_xParaTemplBox->set_active_text(pColl->GetName());
195  }
196  }
197 
198  // page
199  for (sal_uInt16 i = RES_POOLPAGE_BEGIN; i < RES_POOLPAGE_END; ++i)
200  m_xPageTemplBox->append_text(SwStyleNameMapper::GetUIName(i, OUString()));
201 
202  const size_t nCount = pSh->GetPageDescCnt();
203  for(size_t i = 0; i < nCount; ++i)
204  {
205  const SwPageDesc &rPageDesc = pSh->GetPageDesc(i);
206  if (m_xPageTemplBox->find_text(rPageDesc.GetName()) == -1)
207  m_xPageTemplBox->append_text(rPageDesc.GetName());
208  }
209 
210  m_xPageTemplBox->set_active_text(pInf->GetPageDesc(*pSh->GetDoc())->GetName());
211 }
212 
214 {
215  return VclPtr<SwEndNoteOptionPage>::Create(pParent, true, *rSet);
216 }
217 
218 // Different kinds of numbering; because the Listbox has varying numbers of
219 // entries, here are functions to set and query the intended kind of numbering.
221 {
222  OUString sSelect;
223  switch(eNum)
224  {
225  case FTNNUM_DOC:
226  sSelect = aNumDoc;
227  break;
228  case FTNNUM_PAGE:
229  sSelect = aNumPage;
230  break;
231  case FTNNUM_CHAPTER:
232  sSelect = aNumChapter;
233  break;
234  default:
235  assert(false);
236  }
237  m_xNumCountBox->set_active_text(sSelect);
238  NumCountHdl(*m_xNumCountBox);
239 }
240 
242 {
243  const int nPos = m_xNumCountBox->get_active();
244  return static_cast<SwFootnoteNum>(bPosDoc ? nPos + 2 : nPos);
245 }
246 
248 {
249  pSh = &rShell;
250  // collect character templates
254  pSh->GetView().GetDocShell());
255 
257  pSh->GetView().GetDocShell());
258 }
259 
260 // Handler behind the button to collect the footnote at the page. In this case
261 // all kinds of numbering can be used.
263 {
264  const SwFootnoteNum eNum = GetNumbering();
265  bPosDoc = false;
266  if (m_xNumCountBox->find_text(aNumPage) == -1)
267  {
268  m_xNumCountBox->insert_text(FTNNUM_PAGE, aNumPage);
269  m_xNumCountBox->insert_text(FTNNUM_CHAPTER, aNumChapter);
270  SelectNumbering(eNum);
271  }
272  m_xPageTemplLbl->set_sensitive(false);
273  m_xPageTemplBox->set_sensitive(false);
274 }
275 
277 {
278  bool bEnable = true;
279  if (m_xNumCountBox->get_count() - 1 != m_xNumCountBox->get_active())
280  {
281  bEnable = false;
282  m_xOffsetField->set_value(1);
283  }
284  m_xOffsetLbl->set_sensitive(bEnable);
285  m_xOffsetField->set_sensitive(bEnable);
286 }
287 
288 // Handler behind the button to collect the footnote at the chapter or end of
289 // the document. In this case no pagewise numbering can be used.
291 {
292  if ( !bPosDoc )
293  SelectNumbering(FTNNUM_DOC);
294 
295  bPosDoc = true;
296  m_xNumCountBox->remove_text(aNumPage);
297  m_xNumCountBox->remove_text(aNumChapter);
298  m_xPageTemplLbl->set_sensitive(true);
299  m_xPageTemplBox->set_sensitive(true);
300 }
301 
302 static SwCharFormat* lcl_GetCharFormat( SwWrtShell* pSh, const OUString& rCharFormatName )
303 {
304  SwCharFormat* pFormat = nullptr;
305  const sal_uInt16 nChCount = pSh->GetCharFormatCount();
306  for(sal_uInt16 i = 0; i< nChCount; i++)
307  {
308  SwCharFormat& rChFormat = pSh->GetCharFormat(i);
309  if(rChFormat.GetName() == rCharFormatName )
310  {
311  pFormat = &rChFormat;
312  break;
313  }
314  }
315  if(!pFormat)
316  {
318  SfxStyleSheetBase* pBase;
319  pBase = pPool->Find(rCharFormatName, SfxStyleFamily::Char);
320  if(!pBase)
321  pBase = &pPool->Make(rCharFormatName, SfxStyleFamily::Char);
322  pFormat = static_cast<SwDocStyleSheet*>(pBase)->GetCharFormat();
323  }
324  return pFormat;
325 }
326 
328 {
329  std::unique_ptr<SwEndNoteInfo> pInf(bEndNote ? new SwEndNoteInfo() : new SwFootnoteInfo());
330 
331  pInf->nFootnoteOffset = m_xOffsetField->get_value() - 1;
332  pInf->aFormat.SetNumberingType(m_xNumViewBox->GetSelectedNumberingType() );
333  pInf->SetPrefix(m_xPrefixED->get_text().replaceAll("\\t", "\t"));
334  pInf->SetSuffix(m_xSuffixED->get_text().replaceAll("\\t", "\t"));
335 
336  pInf->SetCharFormat( lcl_GetCharFormat( pSh,
337  m_xFootnoteCharTextTemplBox->get_active_text() ) );
338  pInf->SetAnchorCharFormat( lcl_GetCharFormat( pSh,
339  m_xFootnoteCharAnchorTemplBox->get_active_text() ) );
340 
341  // paragraph template
342  int nPos = m_xParaTemplBox->get_active();
343  if (nPos != -1)
344  {
345  const OUString aFormatName( m_xParaTemplBox->get_active_text() );
347  OSL_ENSURE(pColl, "paragraph style not found");
348  pInf->SetFootnoteTextColl(*pColl);
349  }
350 
351  // page template
352  pInf->ChgPageDesc( pSh->FindPageDescByName(
353  m_xPageTemplBox->get_active_text(), true ) );
354 
355  if ( bEndNote )
356  {
357  if ( !(*pInf == pSh->GetEndNoteInfo()) )
358  pSh->SetEndNoteInfo( *pInf );
359  }
360  else
361  {
362  SwFootnoteInfo *pI = static_cast<SwFootnoteInfo*>(pInf.get());
363  pI->ePos = m_xPosPageBox->get_active() ? FTNPOS_PAGE : FTNPOS_CHAPTER;
364  pI->eNum = GetNumbering();
365  pI->aQuoVadis = m_xContEdit->get_text();
366  pI->aErgoSum = m_xContFromEdit->get_text();
367  if ( !(*pI == pSh->GetFootnoteInfo()) )
368  pSh->SetFootnoteInfo( *pI );
369  }
370  return true;
371 }
372 
374  : SwEndNoteOptionPage(pParent, false, rSet)
375 {
376 }
377 
379 {
380 }
381 
383 {
384  return VclPtr<SwFootNoteOptionPage>::Create(pParent, *rSet);
385 }
386 
387 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const SwEndNoteInfo & GetEndNoteInfo() const
Definition: editsh.cxx:909
IMPL_LINK_NOARG(SwEndNoteOptionPage, PosPageHdl, weld::Button &, void)
Definition: docfnote.cxx:262
void SetFootnoteInfo(const SwFootnoteInfo &rInfo)
Definition: editsh.cxx:900
SwFootNoteOptionDlg(weld::Window *pParent, SwWrtShell &rSh)
Definition: docfnote.cxx:37
std::unique_ptr< weld::Entry > m_xPrefixED
Definition: impfnote.hxx:42
Represents the style of a paragraph.
Definition: fmtcol.hxx:55
SwWrtShell & rSh
Definition: docfnote.hxx:28
size_t GetPageDescCnt() const
Definition: fedesc.cxx:39
bool IsDefault() const
Definition: format.hxx:109
SfxStyleSheetBase * First()
std::unique_ptr< weld::RadioButton > m_xPosChapterBox
Definition: impfnote.hxx:46
virtual void PageCreated(const OString &rId, SfxTabPage &rPage) override
Definition: docfnote.cxx:49
std::unique_ptr< weld::ComboBox > m_xFootnoteCharAnchorTemplBox
Definition: impfnote.hxx:51
SW_DLLPUBLIC void FillCharStyleListBox(weld::ComboBox &rToFill, SwDocShell *pDocSh, bool bSorted=false, bool bWithDefault=false)
Definition: uitool.cxx:735
SwFootnoteNum
Definition: ftninfo.hxx:84
std::unique_ptr< weld::Entry > m_xContFromEdit
Definition: impfnote.hxx:54
static void FillUIName(const OUString &rName, OUString &rFillName, SwGetPoolIdFromName)
SwFootnoteNum GetNumbering() const
Definition: docfnote.cxx:241
void SetShell(SwViewShell *pSh)
Definition: newfrm.cxx:354
void SetEndNoteInfo(const SwEndNoteInfo &rInfo)
Definition: editsh.cxx:914
SwEndNoteOptionPage(TabPageParent pParent, bool bEndNote, const SfxItemSet &rSet)
Definition: docfnote.cxx:66
OUString aNumChapter
Definition: impfnote.hxx:33
static SfxObjectShell * Current()
std::unique_ptr< weld::Entry > m_xContEdit
Definition: impfnote.hxx:53
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: docfnote.cxx:327
std::unique_ptr< weld::Entry > m_xSuffixED
Definition: impfnote.hxx:43
std::unique_ptr< SwNumberingTypeListBox > m_xNumViewBox
Definition: impfnote.hxx:38
const OUString & GetName() const
Definition: pagedesc.hxx:186
IMPL_LINK(SwFootNoteOptionDlg, OkHdl, weld::Button &, rBtn, void)
Definition: docfnote.cxx:54
Used by the UI to modify the document model.
Definition: wrtsh.hxx:88
std::unique_ptr< weld::ComboBox > m_xNumCountBox
Definition: impfnote.hxx:41
const SwView & GetView() const
Definition: wrtsh.hxx:426
const OUString & GetName() const
virtual ~SwFootNoteOptionPage() override
Definition: docfnote.cxx:378
const OUString & GetName() const
Definition: format.hxx:111
SwDoc * GetDoc() const
Definition: viewsh.hxx:284
static VclPtr< SfxTabPage > Create(TabPageParent pParent, const SfxItemSet *rSet)
Definition: docfnote.cxx:213
sal_uInt16 GetCharFormatCount() const
CHAR.
Definition: edfmt.cxx:32
std::unique_ptr< weld::ComboBox > m_xFootnoteCharTextTemplBox
Definition: impfnote.hxx:52
SwDoc * GetDoc()
returns Doc. But be careful!
Definition: docsh.hxx:203
void connect_clicked(const Link< Button &, void > &rLink)
std::unique_ptr< weld::ComboBox > m_xParaTemplBox
Definition: impfnote.hxx:48
virtual SfxStyleSheetBase & Make(const OUString &, SfxStyleFamily eFam, SfxStyleSearchBits nMask=SfxStyleSearchBits::All)
int i
SwFootNoteOptionPage(TabPageParent pParent, const SfxItemSet &rSet)
Definition: docfnote.cxx:373
static VclPtr< SfxTabPage > Create(TabPageParent pParent, const SfxItemSet *rSet)
Definition: docfnote.cxx:382
const SwPageDesc & GetPageDesc(size_t i) const
Definition: fedesc.cxx:127
virtual SfxStyleSheetBasePool * GetStyleSheetPool() override
For Style PI.
Definition: docsh.cxx:1159
OUString aErgoSum
Definition: ftninfo.hxx:95
SwDocShell * GetDocShell()
Definition: view.cxx:1127
static SwCharFormat * lcl_GetCharFormat(SwWrtShell *pSh, const OUString &rCharFormatName)
Definition: docfnote.cxx:302
std::unique_ptr< weld::Label > m_xPageTemplLbl
Definition: impfnote.hxx:49
const SwFootnoteInfo & GetFootnoteInfo() const
Footnote attributes global to document.
Definition: editsh.cxx:895
virtual ~SwEndNoteOptionPage() override
Definition: docfnote.cxx:106
std::unique_ptr< weld::SpinButton > m_xOffsetField
Definition: impfnote.hxx:40
SfxStyleSheetBase * Next()
SwFootnoteNum eNum
Definition: ftninfo.hxx:97
static VclPtr< reference_type > Create(Arg &&...arg)
void AddTabPage(const OString &rName, CreateTabPage pCreateFunc, GetTabPageRanges pRangesFunc)
bool const bEndNote
Definition: impfnote.hxx:36
static const OUString & GetUIName(const OUString &rName, SwGetPoolIdFromName)
virtual void Reset(const SfxItemSet *) override
Definition: docfnote.cxx:111
void SetShell(SwWrtShell &rShell)
Definition: docfnote.cxx:247
void SetSearchMask(SfxStyleFamily eFam, SfxStyleSearchBits n=SfxStyleSearchBits::All)
virtual weld::Button & GetOKButton() const override
std::unique_ptr< weld::ComboBox > m_xPageTemplBox
Definition: impfnote.hxx:50
SwPageDesc * FindPageDescByName(const OUString &rName, bool bGetFromPool=false, size_t *pPos=nullptr)
Definition: fedesc.cxx:132
SwFootnotePos ePos
Definition: ftninfo.hxx:96
void SelectNumbering(SwFootnoteNum eNum)
Definition: docfnote.cxx:220
virtual SfxStyleSheetBase * Find(const OUString &, SfxStyleFamily eFam, SfxStyleSearchBits n=SfxStyleSearchBits::All)
sal_Int32 nPos
std::unique_ptr< weld::Widget > m_xStylesContainer
Definition: impfnote.hxx:47
SwWrtShell * pSh
Definition: impfnote.hxx:34
std::unique_ptr< weld::RadioButton > m_xPosPageBox
Definition: impfnote.hxx:45
SwTextFormatColl * GetParaStyle(const OUString &rCollName, GetStyle eCreate=GETSTYLE_NOCREATE)
Definition: wrtsh1.cxx:1480
SwCharFormat & GetCharFormat(sal_uInt16 nFormat) const
Definition: edfmt.cxx:37
OUString aQuoVadis
Definition: ftninfo.hxx:94