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(pPage, pController,
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 }
109 
111 {
112  std::unique_ptr<SwEndNoteInfo> pInf(bEndNote ? new SwEndNoteInfo( pSh->GetEndNoteInfo() )
113  : new SwFootnoteInfo( pSh->GetFootnoteInfo() ));
115 
116  if (dynamic_cast<SwWebDocShell*>( pDocSh) )
117  m_xStylesContainer->hide();
118 
119  if ( bEndNote )
120  {
121  bPosDoc = true;
122  }
123  else
124  {
125  const SwFootnoteInfo &rInf = pSh->GetFootnoteInfo();
126  // set position (page, chapter)
127  if ( rInf.ePos == FTNPOS_PAGE )
128  {
129  m_xPosPageBox->set_active(true);
130  m_xPageTemplLbl->set_sensitive(false);
131  m_xPageTemplBox->set_sensitive(false);
132  }
133  else
134  {
135  m_xPosChapterBox->set_active(true);
136  m_xNumCountBox->remove_text(aNumPage);
137  m_xNumCountBox->remove_text(aNumChapter);
138  bPosDoc = true;
139  }
140  // reference tests
141  m_xContEdit->set_text(rInf.aQuoVadis);
142  m_xContFromEdit->set_text(rInf.aErgoSum);
143 
144  // collected
145  SelectNumbering(rInf.eNum);
146  }
147 
148  // numbering
149  // art
150  m_xNumViewBox->SelectNumberingType( pInf->aFormat.GetNumberingType());
151  m_xOffsetField->set_value(pInf->nFootnoteOffset + 1);
152  m_xPrefixED->set_text(pInf->GetPrefix().replaceAll("\t", "\\t")); // fdo#65666
153  m_xSuffixED->set_text(pInf->GetSuffix().replaceAll("\t", "\\t"));
154 
155  const SwCharFormat* pCharFormat = pInf->GetCharFormat(
156  *pSh->GetView().GetDocShell()->GetDoc());
157  m_xFootnoteCharTextTemplBox->set_active_text(pCharFormat->GetName());
158  m_xFootnoteCharTextTemplBox->save_value();
159 
160  pCharFormat = pInf->GetAnchorCharFormat( *pSh->GetDoc() );
161  m_xFootnoteCharAnchorTemplBox->set_active_text( pCharFormat->GetName() );
162  m_xFootnoteCharAnchorTemplBox->save_value();
163 
164  // styles special regions
165  // paragraph
167  pStyleSheetPool->SetSearchMask(SfxStyleFamily::Para, SfxStyleSearchBits::SwExtra);
168  SfxStyleSheetBase *pStyle = pStyleSheetPool->First();
169  while(pStyle)
170  {
171  m_xParaTemplBox->append_text(pStyle->GetName());
172  pStyle = pStyleSheetPool->Next();
173  }
174 
175  OUString sStr;
176  SwStyleNameMapper::FillUIName( static_cast< sal_uInt16 >(bEndNote ? RES_POOLCOLL_ENDNOTE
177  : RES_POOLCOLL_FOOTNOTE), sStr );
178  if (m_xParaTemplBox->find_text(sStr) == -1)
179  m_xParaTemplBox->append_text(sStr);
180 
181  SwTextFormatColl* pColl = pInf->GetFootnoteTextColl();
182  if( !pColl )
183  m_xParaTemplBox->set_active_text(sStr); // Default
184  else
185  {
186  OSL_ENSURE(!pColl->IsDefault(), "default style for footnotes is wrong");
187  const int nPos = m_xParaTemplBox->find_text(pColl->GetName());
188  if (nPos != -1)
189  m_xParaTemplBox->set_active( nPos );
190  else
191  {
192  m_xParaTemplBox->append_text(pColl->GetName());
193  m_xParaTemplBox->set_active_text(pColl->GetName());
194  }
195  }
196 
197  // page
198  for (sal_uInt16 i = RES_POOLPAGE_BEGIN; i < RES_POOLPAGE_END; ++i)
199  m_xPageTemplBox->append_text(SwStyleNameMapper::GetUIName(i, OUString()));
200 
201  const size_t nCount = pSh->GetPageDescCnt();
202  for(size_t i = 0; i < nCount; ++i)
203  {
204  const SwPageDesc &rPageDesc = pSh->GetPageDesc(i);
205  if (m_xPageTemplBox->find_text(rPageDesc.GetName()) == -1)
206  m_xPageTemplBox->append_text(rPageDesc.GetName());
207  }
208 
209  m_xPageTemplBox->set_active_text(pInf->GetPageDesc(*pSh->GetDoc())->GetName());
210 }
211 
212 std::unique_ptr<SfxTabPage> SwEndNoteOptionPage::Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet *rSet )
213 {
214  return std::make_unique<SwEndNoteOptionPage>(pPage, pController, true, *rSet);
215 }
216 
217 // Different kinds of numbering; because the Listbox has varying numbers of
218 // entries, here are functions to set and query the intended kind of numbering.
220 {
221  OUString sSelect;
222  switch(eNum)
223  {
224  case FTNNUM_DOC:
225  sSelect = aNumDoc;
226  break;
227  case FTNNUM_PAGE:
228  sSelect = aNumPage;
229  break;
230  case FTNNUM_CHAPTER:
231  sSelect = aNumChapter;
232  break;
233  default:
234  assert(false);
235  }
236  m_xNumCountBox->set_active_text(sSelect);
237  NumCountHdl(*m_xNumCountBox);
238 }
239 
241 {
242  const int nPos = m_xNumCountBox->get_active();
243  return static_cast<SwFootnoteNum>(bPosDoc ? nPos + 2 : nPos);
244 }
245 
247 {
248  pSh = &rShell;
249  // collect character templates
253  pSh->GetView().GetDocShell());
254 
256  pSh->GetView().GetDocShell());
257 }
258 
259 // Handler behind the button to collect the footnote at the page. In this case
260 // all kinds of numbering can be used.
262 {
263  const SwFootnoteNum eNum = GetNumbering();
264  bPosDoc = false;
265  if (m_xNumCountBox->find_text(aNumPage) == -1)
266  {
267  m_xNumCountBox->insert_text(FTNNUM_PAGE, aNumPage);
268  m_xNumCountBox->insert_text(FTNNUM_CHAPTER, aNumChapter);
269  SelectNumbering(eNum);
270  }
271  m_xPageTemplLbl->set_sensitive(false);
272  m_xPageTemplBox->set_sensitive(false);
273 }
274 
276 {
277  bool bEnable = true;
278  if (m_xNumCountBox->get_count() - 1 != m_xNumCountBox->get_active())
279  {
280  bEnable = false;
281  m_xOffsetField->set_value(1);
282  }
283  m_xOffsetLbl->set_sensitive(bEnable);
284  m_xOffsetField->set_sensitive(bEnable);
285 }
286 
287 // Handler behind the button to collect the footnote at the chapter or end of
288 // the document. In this case no pagewise numbering can be used.
290 {
291  if ( !bPosDoc )
292  SelectNumbering(FTNNUM_DOC);
293 
294  bPosDoc = true;
295  m_xNumCountBox->remove_text(aNumPage);
296  m_xNumCountBox->remove_text(aNumChapter);
297  m_xPageTemplLbl->set_sensitive(true);
298  m_xPageTemplBox->set_sensitive(true);
299 }
300 
301 static SwCharFormat* lcl_GetCharFormat( SwWrtShell* pSh, const OUString& rCharFormatName )
302 {
303  SwCharFormat* pFormat = nullptr;
304  const sal_uInt16 nChCount = pSh->GetCharFormatCount();
305  for(sal_uInt16 i = 0; i< nChCount; i++)
306  {
307  SwCharFormat& rChFormat = pSh->GetCharFormat(i);
308  if(rChFormat.GetName() == rCharFormatName )
309  {
310  pFormat = &rChFormat;
311  break;
312  }
313  }
314  if(!pFormat)
315  {
317  SfxStyleSheetBase* pBase;
318  pBase = pPool->Find(rCharFormatName, SfxStyleFamily::Char);
319  if(!pBase)
320  pBase = &pPool->Make(rCharFormatName, SfxStyleFamily::Char);
321  pFormat = static_cast<SwDocStyleSheet*>(pBase)->GetCharFormat();
322  }
323  return pFormat;
324 }
325 
327 {
328  std::unique_ptr<SwEndNoteInfo> pInf(bEndNote ? new SwEndNoteInfo() : new SwFootnoteInfo());
329 
330  pInf->nFootnoteOffset = m_xOffsetField->get_value() - 1;
331  pInf->aFormat.SetNumberingType(m_xNumViewBox->GetSelectedNumberingType() );
332  pInf->SetPrefix(m_xPrefixED->get_text().replaceAll("\\t", "\t"));
333  pInf->SetSuffix(m_xSuffixED->get_text().replaceAll("\\t", "\t"));
334 
335  pInf->SetCharFormat( lcl_GetCharFormat( pSh,
336  m_xFootnoteCharTextTemplBox->get_active_text() ) );
337  pInf->SetAnchorCharFormat( lcl_GetCharFormat( pSh,
338  m_xFootnoteCharAnchorTemplBox->get_active_text() ) );
339 
340  // paragraph template
341  int nPos = m_xParaTemplBox->get_active();
342  if (nPos != -1)
343  {
344  const OUString aFormatName( m_xParaTemplBox->get_active_text() );
346  OSL_ENSURE(pColl, "paragraph style not found");
347  pInf->SetFootnoteTextColl(*pColl);
348  }
349 
350  // page template
351  pInf->ChgPageDesc( pSh->FindPageDescByName(
352  m_xPageTemplBox->get_active_text(), true ) );
353 
354  if ( bEndNote )
355  {
356  if ( !(*pInf == pSh->GetEndNoteInfo()) )
357  pSh->SetEndNoteInfo( *pInf );
358  }
359  else
360  {
361  SwFootnoteInfo *pI = static_cast<SwFootnoteInfo*>(pInf.get());
362  pI->ePos = m_xPosPageBox->get_active() ? FTNPOS_PAGE : FTNPOS_CHAPTER;
363  pI->eNum = GetNumbering();
364  pI->aQuoVadis = m_xContEdit->get_text();
365  pI->aErgoSum = m_xContFromEdit->get_text();
366  if ( !(*pI == pSh->GetFootnoteInfo()) )
367  pSh->SetFootnoteInfo( *pI );
368  }
369  return true;
370 }
371 
373  : SwEndNoteOptionPage(pPage, pController, false, rSet)
374 {
375 }
376 
378 {
379 }
380 
381 std::unique_ptr<SfxTabPage> SwFootNoteOptionPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet *rSet )
382 {
383  return std::make_unique<SwFootNoteOptionPage>(pPage, pController, *rSet);
384 }
385 
386 /* 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:261
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:734
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:240
void SetShell(SwViewShell *pSh)
Definition: newfrm.cxx:354
void SetEndNoteInfo(const SwEndNoteInfo &rInfo)
Definition: editsh.cxx:914
SwFootNoteOptionPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: docfnote.cxx:372
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:326
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:187
IMPL_LINK(SwFootNoteOptionDlg, OkHdl, weld::Button &, rBtn, void)
Definition: docfnote.cxx:54
Used by the UI to modify the document model.
Definition: wrtsh.hxx:90
std::unique_ptr< weld::ComboBox > m_xNumCountBox
Definition: impfnote.hxx:41
const SwView & GetView() const
Definition: wrtsh.hxx:428
SwEndNoteOptionPage(weld::Container *pPage, weld::DialogController *pController, bool bEndNote, const SfxItemSet &rSet)
Definition: docfnote.cxx:66
const OUString & GetName() const
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: docfnote.cxx:212
virtual ~SwFootNoteOptionPage() override
Definition: docfnote.cxx:377
const OUString & GetName() const
Definition: format.hxx:111
SwDoc * GetDoc() const
Definition: viewsh.hxx:284
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
const SwPageDesc & GetPageDesc(size_t i) const
Definition: fedesc.cxx:127
virtual SfxStyleSheetBasePool * GetStyleSheetPool() override
For Style PI.
Definition: docsh.cxx:1165
OUString aErgoSum
Definition: ftninfo.hxx:95
SwDocShell * GetDocShell()
Definition: view.cxx:1127
static SwCharFormat * lcl_GetCharFormat(SwWrtShell *pSh, const OUString &rCharFormatName)
Definition: docfnote.cxx:301
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
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:110
void SetShell(SwWrtShell &rShell)
Definition: docfnote.cxx:246
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: docfnote.cxx:381
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:219
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:1506
SwCharFormat & GetCharFormat(sal_uInt16 nFormat) const
Definition: edfmt.cxx:37
OUString aQuoVadis
Definition: ftninfo.hxx:94