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 <osl/diagnose.h>
22#include <wrtsh.hxx>
23#include <view.hxx>
24#include <docsh.hxx>
25#include <docfnote.hxx>
26#include "impfnote.hxx"
27#include <ftninfo.hxx>
28#include <fmtcol.hxx>
29#include <pagedesc.hxx>
30#include <charfmt.hxx>
31#include <docstyle.hxx>
32#include <wdocsh.hxx>
33#include <uitool.hxx>
34#include <poolfmt.hxx>
35#include <SwStyleNameMapper.hxx>
36#include <memory>
37
39 : SfxTabDialogController(pParent, "modules/swriter/ui/footendnotedialog.ui", "FootEndnoteDialog")
40 , m_rSh( rS )
41{
43
45
46 AddTabPage("footnotes", SwFootNoteOptionPage::Create, nullptr);
47 AddTabPage("endnotes", SwEndNoteOptionPage::Create, nullptr);
48}
49
50void SwFootNoteOptionDlg::PageCreated(const OUString& /*rId*/, SfxTabPage &rPage)
51{
52 static_cast<SwEndNoteOptionPage&>(rPage).SetShell(m_rSh);
53}
54
56{
57 SfxItemSetFixed<1, 1> aDummySet(m_rSh.GetAttrPool());
58 SfxTabPage *pPage = GetTabPage(u"footnotes");
59 if ( pPage )
60 pPage->FillItemSet( &aDummySet );
61 pPage = GetTabPage(u"endnotes");
62 if ( pPage )
63 pPage->FillItemSet( &aDummySet );
64 SfxTabDialogController::OkHdl(rBtn);
65}
66
68 const SfxItemSet &rSet)
69 : SfxTabPage(pPage, pController,
70 bEN ? OUString("modules/swriter/ui/endnotepage.ui") : OUString("modules/swriter/ui/footnotepage.ui"),
71 bEN ? OUString("EndnotePage") : OUString("FootnotePage"),
72 &rSet)
73 , m_pSh(nullptr)
74 , m_bPosDoc(false)
75 , m_bEndNote(bEN)
76 , m_xNumViewBox(new SwNumberingTypeListBox(m_xBuilder->weld_combo_box("numberinglb")))
77 , m_xOffsetLbl(m_xBuilder->weld_label("offset"))
78 , m_xOffsetField(m_xBuilder->weld_spin_button("offsetnf"))
79 , m_xNumCountBox(m_xBuilder->weld_combo_box("countinglb"))
80 , m_xPrefixED(m_xBuilder->weld_entry("prefix"))
81 , m_xSuffixED(m_xBuilder->weld_entry("suffix"))
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 (!m_bEndNote)
95 {
96 m_xNumCountBox->connect_changed(LINK(this, SwEndNoteOptionPage, NumCountHdl));
100 m_xPosPageBox->connect_toggled(LINK(this, SwEndNoteOptionPage, ToggleHdl));
101 m_xPosChapterBox->connect_toggled(LINK(this, SwEndNoteOptionPage, ToggleHdl));
102 }
103 m_xParaTemplBox->make_sorted();
104}
105
107{
108}
109
111{
112 std::unique_ptr<SwEndNoteInfo> pInf(m_bEndNote ? new SwEndNoteInfo( m_pSh->GetEndNoteInfo() )
115
116 if (dynamic_cast<SwWebDocShell*>( pDocSh) )
117 m_xStylesContainer->hide();
118
119 if ( m_bEndNote )
120 {
121 m_bPosDoc = true;
122 }
123 else
124 {
125 const SwFootnoteInfo &rInf = m_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(m_aNumPage);
137 m_xNumCountBox->remove_text(m_aNumChapter);
138 m_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
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(
157 m_xFootnoteCharTextTemplBox->set_active_text(pCharFormat->GetName());
158 m_xFootnoteCharTextTemplBox->save_value();
159
160 pCharFormat = pInf->GetAnchorCharFormat( *m_pSh->GetDoc() );
161 m_xFootnoteCharAnchorTemplBox->set_active_text( pCharFormat->GetName() );
162 m_xFootnoteCharAnchorTemplBox->save_value();
163
164 // styles special regions
165 // paragraph
167 SfxStyleSheetBase *pStyle = pStyleSheetPool->First(SfxStyleFamily::Para, SfxStyleSearchBits::SwExtra);
168 while(pStyle)
169 {
170 m_xParaTemplBox->append_text(pStyle->GetName());
171 pStyle = pStyleSheetPool->Next();
172 }
173
174 OUString sStr;
176 : RES_POOLCOLL_FOOTNOTE), sStr );
177 if (m_xParaTemplBox->find_text(sStr) == -1)
178 m_xParaTemplBox->append_text(sStr);
179
180 SwTextFormatColl* pColl = pInf->GetFootnoteTextColl();
181 if( !pColl )
182 m_xParaTemplBox->set_active_text(sStr); // Default
183 else
184 {
185 OSL_ENSURE(!pColl->IsDefault(), "default style for footnotes is wrong");
186 const int nPos = m_xParaTemplBox->find_text(pColl->GetName());
187 if (nPos != -1)
188 m_xParaTemplBox->set_active( nPos );
189 else
190 {
191 m_xParaTemplBox->append_text(pColl->GetName());
192 m_xParaTemplBox->set_active_text(pColl->GetName());
193 }
194 }
195
196 // page
197 for (sal_uInt16 i = RES_POOLPAGE_BEGIN; i < RES_POOLPAGE_END; ++i)
198 m_xPageTemplBox->append_text(SwStyleNameMapper::GetUIName(i, OUString()));
199
200 const size_t nCount = m_pSh->GetPageDescCnt();
201 for(size_t i = 0; i < nCount; ++i)
202 {
203 const SwPageDesc &rPageDesc = m_pSh->GetPageDesc(i);
204 if (m_xPageTemplBox->find_text(rPageDesc.GetName()) == -1)
205 m_xPageTemplBox->append_text(rPageDesc.GetName());
206 }
207 m_xPageTemplBox->make_sorted();
208
209 m_xPageTemplBox->set_active_text(pInf->GetPageDesc(*m_pSh->GetDoc())->GetName());
210}
211
212std::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 = m_aNumDoc;
226 break;
227 case FTNNUM_PAGE:
228 sSelect = m_aNumPage;
229 break;
230 case FTNNUM_CHAPTER:
231 sSelect = m_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>(m_bPosDoc ? nPos + 2 : nPos);
244}
245
247{
248 m_pSh = &rShell;
249 // collect character templates
253 m_pSh->GetView().GetDocShell(), true);
254
256 m_pSh->GetView().GetDocShell(), true);
257}
258
260{
261 if (!rButton.get_active())
262 return;
263
264 if (m_xPosPageBox->get_active())
265 {
266 // Handler behind the button to collect the footnote at the page. In this case
267 // all kinds of numbering can be used.
268
269 const SwFootnoteNum eNum = GetNumbering();
270 m_bPosDoc = false;
271 if (m_xNumCountBox->find_text(m_aNumPage) == -1)
272 {
273 m_xNumCountBox->insert_text(FTNNUM_PAGE, m_aNumPage);
274 m_xNumCountBox->insert_text(FTNNUM_CHAPTER, m_aNumChapter);
275 SelectNumbering(eNum);
276 }
277 m_xPageTemplLbl->set_sensitive(false);
278 m_xPageTemplBox->set_sensitive(false);
279 }
280 else if (m_xPosChapterBox->get_active())
281 {
282 // Handler behind the button to collect the footnote at the chapter or end of
283 // the document. In this case no pagewise numbering can be used.
284
285 if ( !m_bPosDoc )
286 SelectNumbering(FTNNUM_DOC);
287
288 m_bPosDoc = true;
289 m_xNumCountBox->remove_text(m_aNumPage);
290 m_xNumCountBox->remove_text(m_aNumChapter);
291 m_xPageTemplLbl->set_sensitive(true);
292 m_xPageTemplBox->set_sensitive(true);
293 }
294}
295
297{
298 bool bEnable = true;
299 if (m_xNumCountBox->get_count() - 1 != m_xNumCountBox->get_active())
300 {
301 bEnable = false;
302 m_xOffsetField->set_value(1);
303 }
304 m_xOffsetLbl->set_sensitive(bEnable);
305 m_xOffsetField->set_sensitive(bEnable);
306}
307
308static SwCharFormat* lcl_GetCharFormat( SwWrtShell* pSh, const OUString& rCharFormatName )
309{
310 SwCharFormat* pFormat = nullptr;
311 const sal_uInt16 nChCount = pSh->GetCharFormatCount();
312 for(sal_uInt16 i = 0; i< nChCount; i++)
313 {
314 SwCharFormat& rChFormat = pSh->GetCharFormat(i);
315 if(rChFormat.GetName() == rCharFormatName )
316 {
317 pFormat = &rChFormat;
318 break;
319 }
320 }
321 if(!pFormat)
322 {
324 SfxStyleSheetBase* pBase;
325 pBase = pPool->Find(rCharFormatName, SfxStyleFamily::Char);
326 if(!pBase)
327 pBase = &pPool->Make(rCharFormatName, SfxStyleFamily::Char);
328 pFormat = static_cast<SwDocStyleSheet*>(pBase)->GetCharFormat();
329 }
330 return pFormat;
331}
332
334{
335 std::unique_ptr<SwEndNoteInfo> pInf(m_bEndNote ? new SwEndNoteInfo() : new SwFootnoteInfo());
336
337 pInf->m_nFootnoteOffset = m_xOffsetField->get_value() - 1;
338 pInf->m_aFormat.SetNumberingType(m_xNumViewBox->GetSelectedNumberingType() );
339 pInf->SetPrefix(m_xPrefixED->get_text().replaceAll("\\t", "\t"));
340 pInf->SetSuffix(m_xSuffixED->get_text().replaceAll("\\t", "\t"));
341
342 pInf->SetCharFormat( lcl_GetCharFormat( m_pSh,
343 m_xFootnoteCharTextTemplBox->get_active_text() ) );
344 pInf->SetAnchorCharFormat( lcl_GetCharFormat( m_pSh,
345 m_xFootnoteCharAnchorTemplBox->get_active_text() ) );
346
347 // paragraph template
348 int nPos = m_xParaTemplBox->get_active();
349 if (nPos != -1)
350 {
351 const OUString aFormatName( m_xParaTemplBox->get_active_text() );
353 OSL_ENSURE(pColl, "paragraph style not found");
354 pInf->SetFootnoteTextColl(*pColl);
355 }
356
357 // page template
358 pInf->ChgPageDesc( m_pSh->FindPageDescByName(
359 m_xPageTemplBox->get_active_text(), true ) );
360
361 if ( m_bEndNote )
362 {
363 if ( !(*pInf == m_pSh->GetEndNoteInfo()) )
364 m_pSh->SetEndNoteInfo( *pInf );
365 }
366 else
367 {
368 SwFootnoteInfo *pI = static_cast<SwFootnoteInfo*>(pInf.get());
369 pI->m_ePos = m_xPosPageBox->get_active() ? FTNPOS_PAGE : FTNPOS_CHAPTER;
370 pI->m_eNum = GetNumbering();
371 pI->m_aQuoVadis = m_xContEdit->get_text();
372 pI->m_aErgoSum = m_xContFromEdit->get_text();
373 if ( !(*pI == m_pSh->GetFootnoteInfo()) )
374 m_pSh->SetFootnoteInfo( *pI );
375 }
376 return true;
377}
378
380 : SwEndNoteOptionPage(pPage, pController, false, rSet)
381{
382}
383
385{
386}
387
388std::unique_ptr<SfxTabPage> SwFootNoteOptionPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet *rSet )
389{
390 return std::make_unique<SwFootNoteOptionPage>(pPage, pController, *rSet);
391}
392
393/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static SAL_WARN_UNUSED_RESULT SfxObjectShell * Current()
SfxStyleSheetBase * First(SfxStyleFamily eFamily, SfxStyleSearchBits eMask=SfxStyleSearchBits::All)
virtual SfxStyleSheetBase & Make(const OUString &, SfxStyleFamily eFam, SfxStyleSearchBits nMask=SfxStyleSearchBits::All)
SfxStyleSheetBase * Next()
virtual SfxStyleSheetBase * Find(const OUString &, SfxStyleFamily eFam, SfxStyleSearchBits n=SfxStyleSearchBits::All)
const OUString & GetName() const
void AddTabPage(const OUString &rName, CreateTabPage pCreateFunc, GetTabPageRanges pRangesFunc)
virtual weld::Button & GetOKButton() const override
virtual bool FillItemSet(SfxItemSet *)
Represents the style of a text portion.
Definition: charfmt.hxx:27
virtual SfxStyleSheetBasePool * GetStyleSheetPool() override
For Style PI.
Definition: docsh.cxx:1152
SwDoc * GetDoc()
returns Doc. But be careful!
Definition: docsh.hxx:204
const SwFootnoteInfo & GetFootnoteInfo() const
Footnote attributes global to document.
Definition: editsh.cxx:901
const SwEndNoteInfo & GetEndNoteInfo() const
Definition: editsh.cxx:915
void SetEndNoteInfo(const SwEndNoteInfo &rInfo)
Definition: editsh.cxx:920
sal_uInt16 GetCharFormatCount() const
CHAR.
Definition: edfmt.cxx:29
void SetFootnoteInfo(const SwFootnoteInfo &rInfo)
Definition: editsh.cxx:906
SwCharFormat & GetCharFormat(sal_uInt16 nFormat) const
Definition: edfmt.cxx:34
std::unique_ptr< weld::Label > m_xPageTemplLbl
Definition: impfnote.hxx:48
std::unique_ptr< weld::RadioButton > m_xPosPageBox
Definition: impfnote.hxx:44
std::unique_ptr< weld::Entry > m_xPrefixED
Definition: impfnote.hxx:42
OUString m_aNumPage
Definition: impfnote.hxx:32
std::unique_ptr< weld::SpinButton > m_xOffsetField
Definition: impfnote.hxx:40
std::unique_ptr< weld::ComboBox > m_xParaTemplBox
Definition: impfnote.hxx:47
std::unique_ptr< weld::Entry > m_xContEdit
Definition: impfnote.hxx:52
std::unique_ptr< weld::ComboBox > m_xFootnoteCharAnchorTemplBox
Definition: impfnote.hxx:50
std::unique_ptr< weld::ComboBox > m_xPageTemplBox
Definition: impfnote.hxx:49
OUString m_aNumDoc
Definition: impfnote.hxx:31
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: docfnote.cxx:212
std::unique_ptr< weld::Entry > m_xSuffixED
Definition: impfnote.hxx:43
virtual void Reset(const SfxItemSet *) override
Definition: docfnote.cxx:110
OUString m_aNumChapter
Definition: impfnote.hxx:33
virtual ~SwEndNoteOptionPage() override
Definition: docfnote.cxx:106
void SelectNumbering(SwFootnoteNum eNum)
Definition: docfnote.cxx:219
void SetShell(SwWrtShell &rShell)
Definition: docfnote.cxx:246
std::unique_ptr< weld::ComboBox > m_xFootnoteCharTextTemplBox
Definition: impfnote.hxx:51
std::unique_ptr< weld::Entry > m_xContFromEdit
Definition: impfnote.hxx:53
std::unique_ptr< weld::Widget > m_xStylesContainer
Definition: impfnote.hxx:46
SwFootnoteNum GetNumbering() const
Definition: docfnote.cxx:240
std::unique_ptr< weld::RadioButton > m_xPosChapterBox
Definition: impfnote.hxx:45
SwWrtShell * m_pSh
Definition: impfnote.hxx:34
std::unique_ptr< weld::ComboBox > m_xNumCountBox
Definition: impfnote.hxx:41
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: docfnote.cxx:333
SwEndNoteOptionPage(weld::Container *pPage, weld::DialogController *pController, bool bEndNote, const SfxItemSet &rSet)
Definition: docfnote.cxx:67
std::unique_ptr< SwNumberingTypeListBox > m_xNumViewBox
Definition: impfnote.hxx:38
SwPageDesc * FindPageDescByName(const OUString &rName, bool bGetFromPool=false, size_t *pPos=nullptr)
Definition: fedesc.cxx:131
size_t GetPageDescCnt() const
Definition: fedesc.cxx:38
const SwPageDesc & GetPageDesc(size_t i) const
Definition: fedesc.cxx:126
SwFootNoteOptionDlg(weld::Window *pParent, SwWrtShell &rSh)
Definition: docfnote.cxx:38
SwWrtShell & m_rSh
Definition: docfnote.hxx:28
virtual void PageCreated(const OUString &rId, SfxTabPage &rPage) override
Definition: docfnote.cxx:50
virtual ~SwFootNoteOptionPage() override
Definition: docfnote.cxx:384
SwFootNoteOptionPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: docfnote.cxx:379
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: docfnote.cxx:388
OUString m_aErgoSum
Definition: ftninfo.hxx:96
SwFootnoteNum m_eNum
Definition: ftninfo.hxx:98
SwFootnotePos m_ePos
Definition: ftninfo.hxx:97
OUString m_aQuoVadis
Definition: ftninfo.hxx:95
bool IsDefault() const
Definition: format.hxx:129
const OUString & GetName() const
Definition: format.hxx:131
const OUString & GetName() const
Definition: pagedesc.hxx:196
static const OUString & GetUIName(const OUString &rName, SwGetPoolIdFromName)
static void FillUIName(const OUString &rName, OUString &rFillName, SwGetPoolIdFromName)
Represents the style of a paragraph.
Definition: fmtcol.hxx:61
SwDoc * GetDoc() const
Definition: viewsh.hxx:308
SwDocShell * GetDocShell()
Definition: view.cxx:1193
Used by the UI to modify the document model.
Definition: wrtsh.hxx:97
@ GETSTYLE_CREATEANY
Definition: wrtsh.hxx:363
SwTextFormatColl * GetParaStyle(const OUString &rCollName, GetStyle eCreate=GETSTYLE_NOCREATE)
Definition: wrtsh1.cxx:1823
const SwView & GetView() const
Definition: wrtsh.hxx:443
void connect_clicked(const Link< Button &, void > &rLink)
int nCount
static SwCharFormat * lcl_GetCharFormat(SwWrtShell *pSh, const OUString &rCharFormatName)
Definition: docfnote.cxx:308
IMPL_LINK(SwFootNoteOptionDlg, OkHdl, weld::Button &, rBtn, void)
Definition: docfnote.cxx:55
IMPL_LINK_NOARG(SwEndNoteOptionPage, NumCountHdl, weld::ComboBox &, void)
Definition: docfnote.cxx:296
float u
SwFootnoteNum
Definition: ftninfo.hxx:86
@ FTNNUM_PAGE
Definition: ftninfo.hxx:87
@ FTNNUM_DOC
Definition: ftninfo.hxx:87
@ FTNNUM_CHAPTER
Definition: ftninfo.hxx:87
@ FTNPOS_CHAPTER
Definition: ftninfo.hxx:82
@ FTNPOS_PAGE
Definition: ftninfo.hxx:81
sal_uInt16 nPos
int i
void SetShell(SwViewShell *pSh)
Definition: newfrm.cxx:353
@ RES_POOLCOLL_FOOTNOTE
Footnotes.
Definition: poolfmt.hxx:353
@ RES_POOLCOLL_ENDNOTE
Endnotes.
Definition: poolfmt.hxx:356
@ RES_POOLPAGE_END
Definition: poolfmt.hxx:181
@ RES_POOLPAGE_BEGIN
Definition: poolfmt.hxx:168
static SfxItemSet & rSet
SW_DLLPUBLIC void FillCharStyleListBox(weld::ComboBox &rToFill, SwDocShell *pDocSh, bool bSorted=false, bool bWithDefault=false)
Definition: uitool.cxx:781