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.m_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.m_aQuoVadis);
142  m_xContFromEdit->set_text(rInf.m_aErgoSum);
143 
144  // collected
145  SelectNumbering(rInf.m_eNum);
146  }
147 
148  // numbering
149  // art
150  m_xNumViewBox->SelectNumberingType( pInf->m_aFormat.GetNumberingType());
151  m_xOffsetField->set_value(pInf->m_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  m_xParaTemplBox->make_sorted();
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  m_xPageTemplBox->make_sorted();
210 
211  m_xPageTemplBox->set_active_text(pInf->GetPageDesc(*pSh->GetDoc())->GetName());
212 }
213 
214 std::unique_ptr<SfxTabPage> SwEndNoteOptionPage::Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet *rSet )
215 {
216  return std::make_unique<SwEndNoteOptionPage>(pPage, pController, true, *rSet);
217 }
218 
219 // Different kinds of numbering; because the Listbox has varying numbers of
220 // entries, here are functions to set and query the intended kind of numbering.
222 {
223  OUString sSelect;
224  switch(eNum)
225  {
226  case FTNNUM_DOC:
227  sSelect = aNumDoc;
228  break;
229  case FTNNUM_PAGE:
230  sSelect = aNumPage;
231  break;
232  case FTNNUM_CHAPTER:
233  sSelect = aNumChapter;
234  break;
235  default:
236  assert(false);
237  }
238  m_xNumCountBox->set_active_text(sSelect);
239  NumCountHdl(*m_xNumCountBox);
240 }
241 
243 {
244  const int nPos = m_xNumCountBox->get_active();
245  return static_cast<SwFootnoteNum>(bPosDoc ? nPos + 2 : nPos);
246 }
247 
249 {
250  pSh = &rShell;
251  // collect character templates
255  pSh->GetView().GetDocShell(), true);
256 
258  pSh->GetView().GetDocShell(), true);
259 }
260 
261 // Handler behind the button to collect the footnote at the page. In this case
262 // all kinds of numbering can be used.
264 {
265  const SwFootnoteNum eNum = GetNumbering();
266  bPosDoc = false;
267  if (m_xNumCountBox->find_text(aNumPage) == -1)
268  {
269  m_xNumCountBox->insert_text(FTNNUM_PAGE, aNumPage);
270  m_xNumCountBox->insert_text(FTNNUM_CHAPTER, aNumChapter);
271  SelectNumbering(eNum);
272  }
273  m_xPageTemplLbl->set_sensitive(false);
274  m_xPageTemplBox->set_sensitive(false);
275 }
276 
278 {
279  bool bEnable = true;
280  if (m_xNumCountBox->get_count() - 1 != m_xNumCountBox->get_active())
281  {
282  bEnable = false;
283  m_xOffsetField->set_value(1);
284  }
285  m_xOffsetLbl->set_sensitive(bEnable);
286  m_xOffsetField->set_sensitive(bEnable);
287 }
288 
289 // Handler behind the button to collect the footnote at the chapter or end of
290 // the document. In this case no pagewise numbering can be used.
292 {
293  if ( !bPosDoc )
294  SelectNumbering(FTNNUM_DOC);
295 
296  bPosDoc = true;
297  m_xNumCountBox->remove_text(aNumPage);
298  m_xNumCountBox->remove_text(aNumChapter);
299  m_xPageTemplLbl->set_sensitive(true);
300  m_xPageTemplBox->set_sensitive(true);
301 }
302 
303 static SwCharFormat* lcl_GetCharFormat( SwWrtShell* pSh, const OUString& rCharFormatName )
304 {
305  SwCharFormat* pFormat = nullptr;
306  const sal_uInt16 nChCount = pSh->GetCharFormatCount();
307  for(sal_uInt16 i = 0; i< nChCount; i++)
308  {
309  SwCharFormat& rChFormat = pSh->GetCharFormat(i);
310  if(rChFormat.GetName() == rCharFormatName )
311  {
312  pFormat = &rChFormat;
313  break;
314  }
315  }
316  if(!pFormat)
317  {
319  SfxStyleSheetBase* pBase;
320  pBase = pPool->Find(rCharFormatName, SfxStyleFamily::Char);
321  if(!pBase)
322  pBase = &pPool->Make(rCharFormatName, SfxStyleFamily::Char);
323  pFormat = static_cast<SwDocStyleSheet*>(pBase)->GetCharFormat();
324  }
325  return pFormat;
326 }
327 
329 {
330  std::unique_ptr<SwEndNoteInfo> pInf(bEndNote ? new SwEndNoteInfo() : new SwFootnoteInfo());
331 
332  pInf->m_nFootnoteOffset = m_xOffsetField->get_value() - 1;
333  pInf->m_aFormat.SetNumberingType(m_xNumViewBox->GetSelectedNumberingType() );
334  pInf->SetPrefix(m_xPrefixED->get_text().replaceAll("\\t", "\t"));
335  pInf->SetSuffix(m_xSuffixED->get_text().replaceAll("\\t", "\t"));
336 
337  pInf->SetCharFormat( lcl_GetCharFormat( pSh,
338  m_xFootnoteCharTextTemplBox->get_active_text() ) );
339  pInf->SetAnchorCharFormat( lcl_GetCharFormat( pSh,
340  m_xFootnoteCharAnchorTemplBox->get_active_text() ) );
341 
342  // paragraph template
343  int nPos = m_xParaTemplBox->get_active();
344  if (nPos != -1)
345  {
346  const OUString aFormatName( m_xParaTemplBox->get_active_text() );
348  OSL_ENSURE(pColl, "paragraph style not found");
349  pInf->SetFootnoteTextColl(*pColl);
350  }
351 
352  // page template
353  pInf->ChgPageDesc( pSh->FindPageDescByName(
354  m_xPageTemplBox->get_active_text(), true ) );
355 
356  if ( bEndNote )
357  {
358  if ( !(*pInf == pSh->GetEndNoteInfo()) )
359  pSh->SetEndNoteInfo( *pInf );
360  }
361  else
362  {
363  SwFootnoteInfo *pI = static_cast<SwFootnoteInfo*>(pInf.get());
364  pI->m_ePos = m_xPosPageBox->get_active() ? FTNPOS_PAGE : FTNPOS_CHAPTER;
365  pI->m_eNum = GetNumbering();
366  pI->m_aQuoVadis = m_xContEdit->get_text();
367  pI->m_aErgoSum = m_xContFromEdit->get_text();
368  if ( !(*pI == pSh->GetFootnoteInfo()) )
369  pSh->SetFootnoteInfo( *pI );
370  }
371  return true;
372 }
373 
375  : SwEndNoteOptionPage(pPage, pController, false, rSet)
376 {
377 }
378 
380 {
381 }
382 
383 std::unique_ptr<SfxTabPage> SwFootNoteOptionPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet *rSet )
384 {
385  return std::make_unique<SwFootNoteOptionPage>(pPage, pController, *rSet);
386 }
387 
388 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const SwEndNoteInfo & GetEndNoteInfo() const
Definition: editsh.cxx:903
IMPL_LINK_NOARG(SwEndNoteOptionPage, PosPageHdl, weld::Button &, void)
Definition: docfnote.cxx:263
void SetFootnoteInfo(const SwFootnoteInfo &rInfo)
Definition: editsh.cxx:894
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:37
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:723
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:242
void SetShell(SwViewShell *pSh)
Definition: newfrm.cxx:352
void SetEndNoteInfo(const SwEndNoteInfo &rInfo)
Definition: editsh.cxx:908
SwFootNoteOptionPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: docfnote.cxx:374
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:328
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:214
virtual ~SwFootNoteOptionPage() override
Definition: docfnote.cxx:379
const OUString & GetName() const
Definition: format.hxx:111
int nCount
SwDoc * GetDoc() const
Definition: viewsh.hxx:284
sal_uInt16 GetCharFormatCount() const
CHAR.
Definition: edfmt.cxx:30
std::unique_ptr< weld::ComboBox > m_xFootnoteCharTextTemplBox
Definition: impfnote.hxx:52
SwDoc * GetDoc()
returns Doc. But be careful!
Definition: docsh.hxx:203
SwFootnoteNum m_eNum
Definition: ftninfo.hxx:97
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:125
virtual SfxStyleSheetBasePool * GetStyleSheetPool() override
For Style PI.
Definition: docsh.cxx:1136
SwDocShell * GetDocShell()
Definition: view.cxx:1107
static SwCharFormat * lcl_GetCharFormat(SwWrtShell *pSh, const OUString &rCharFormatName)
Definition: docfnote.cxx:303
std::unique_ptr< weld::Label > m_xPageTemplLbl
Definition: impfnote.hxx:49
const SwFootnoteInfo & GetFootnoteInfo() const
Footnote attributes global to document.
Definition: editsh.cxx:889
virtual ~SwEndNoteOptionPage() override
Definition: docfnote.cxx:106
std::unique_ptr< weld::SpinButton > m_xOffsetField
Definition: impfnote.hxx:40
SfxStyleSheetBase * Next()
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:248
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: docfnote.cxx:383
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:130
OUString m_aQuoVadis
Definition: ftninfo.hxx:94
SwFootnotePos m_ePos
Definition: ftninfo.hxx:96
void SelectNumbering(SwFootnoteNum eNum)
Definition: docfnote.cxx:221
virtual SfxStyleSheetBase * Find(const OUString &, SfxStyleFamily eFam, SfxStyleSearchBits n=SfxStyleSearchBits::All)
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
OUString m_aErgoSum
Definition: ftninfo.hxx:95
sal_uInt16 nPos
SwTextFormatColl * GetParaStyle(const OUString &rCollName, GetStyle eCreate=GETSTYLE_NOCREATE)
Definition: wrtsh1.cxx:1488
SwCharFormat & GetCharFormat(sal_uInt16 nFormat) const
Definition: edfmt.cxx:35