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 , rSh( rS )
41{
43
45
46 AddTabPage("footnotes", SwFootNoteOptionPage::Create, nullptr);
47 AddTabPage("endnotes", SwEndNoteOptionPage::Create, nullptr);
48}
49
50void SwFootNoteOptionDlg::PageCreated(const OString& /*rId*/, SfxTabPage &rPage)
51{
52 static_cast<SwEndNoteOptionPage&>(rPage).SetShell(rSh);
53}
54
56{
57 SfxItemSetFixed<1, 1> aDummySet(rSh.GetAttrPool());
58 SfxTabPage *pPage = GetTabPage("footnotes");
59 if ( pPage )
60 pPage->FillItemSet( &aDummySet );
61 pPage = GetTabPage("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 ? OString("EndnotePage") : OString("FootnotePage"),
72 &rSet)
73 , pSh(nullptr)
74 , bPosDoc(false)
75 , 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_xPosFT(m_xBuilder->weld_label("pos"))
83 , m_xPosPageBox(m_xBuilder->weld_radio_button("pospagecb"))
84 , m_xPosChapterBox(m_xBuilder->weld_radio_button("posdoccb"))
85 , m_xStylesContainer(m_xBuilder->weld_widget("allstyles"))
86 , m_xParaTemplBox(m_xBuilder->weld_combo_box("parastylelb"))
87 , m_xPageTemplLbl(m_xBuilder->weld_label("pagestyleft"))
88 , m_xPageTemplBox(m_xBuilder->weld_combo_box("pagestylelb"))
89 , m_xFootnoteCharAnchorTemplBox(m_xBuilder->weld_combo_box("charanchorstylelb"))
90 , m_xFootnoteCharTextTemplBox(m_xBuilder->weld_combo_box("charstylelb"))
91 , m_xContEdit(m_xBuilder->weld_entry("conted"))
92 , m_xContFromEdit(m_xBuilder->weld_entry("contfromed"))
93{
95 if (!bEndNote)
96 {
97 m_xNumCountBox->connect_changed(LINK(this, SwEndNoteOptionPage, NumCountHdl));
101 m_xPosPageBox->connect_toggled(LINK(this, SwEndNoteOptionPage, ToggleHdl));
102 m_xPosChapterBox->connect_toggled(LINK(this, SwEndNoteOptionPage, ToggleHdl));
103 }
104 m_xParaTemplBox->make_sorted();
105}
106
108{
109}
110
112{
113 std::unique_ptr<SwEndNoteInfo> pInf(bEndNote ? new SwEndNoteInfo( pSh->GetEndNoteInfo() )
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.m_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.m_aQuoVadis);
143 m_xContFromEdit->set_text(rInf.m_aErgoSum);
144
145 // collected
147 }
148
149 // numbering
150 // art
151 m_xNumViewBox->SelectNumberingType( pInf->m_aFormat.GetNumberingType());
152 m_xOffsetField->set_value(pInf->m_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 SfxStyleSheetBase *pStyle = pStyleSheetPool->First(SfxStyleFamily::Para, SfxStyleSearchBits::SwExtra);
169 while(pStyle)
170 {
171 m_xParaTemplBox->append_text(pStyle->GetName());
172 pStyle = pStyleSheetPool->Next();
173 }
174
175 OUString sStr;
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 m_xPageTemplBox->make_sorted();
209
210 m_xPageTemplBox->set_active_text(pInf->GetPageDesc(*pSh->GetDoc())->GetName());
211}
212
213std::unique_ptr<SfxTabPage> SwEndNoteOptionPage::Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet *rSet )
214{
215 return std::make_unique<SwEndNoteOptionPage>(pPage, pController, 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(), true);
255
257 pSh->GetView().GetDocShell(), true);
258}
259
261{
262 if (!rButton.get_active())
263 return;
264
265 if (m_xPosPageBox->get_active())
266 {
267 // Handler behind the button to collect the footnote at the page. In this case
268 // all kinds of numbering can be used.
269
270 const SwFootnoteNum eNum = GetNumbering();
271 bPosDoc = false;
272 if (m_xNumCountBox->find_text(aNumPage) == -1)
273 {
274 m_xNumCountBox->insert_text(FTNNUM_PAGE, aNumPage);
275 m_xNumCountBox->insert_text(FTNNUM_CHAPTER, aNumChapter);
276 SelectNumbering(eNum);
277 }
278 m_xPageTemplLbl->set_sensitive(false);
279 m_xPageTemplBox->set_sensitive(false);
280 }
281 else if (m_xPosChapterBox->get_active())
282 {
283 // Handler behind the button to collect the footnote at the chapter or end of
284 // the document. In this case no pagewise numbering can be used.
285
286 if ( !bPosDoc )
287 SelectNumbering(FTNNUM_DOC);
288
289 bPosDoc = true;
290 m_xNumCountBox->remove_text(aNumPage);
291 m_xNumCountBox->remove_text(aNumChapter);
292 m_xPageTemplLbl->set_sensitive(true);
293 m_xPageTemplBox->set_sensitive(true);
294 }
295}
296
298{
299 bool bEnable = true;
300 if (m_xNumCountBox->get_count() - 1 != m_xNumCountBox->get_active())
301 {
302 bEnable = false;
303 m_xOffsetField->set_value(1);
304 }
305 m_xOffsetLbl->set_sensitive(bEnable);
306 m_xOffsetField->set_sensitive(bEnable);
307}
308
309static SwCharFormat* lcl_GetCharFormat( SwWrtShell* pSh, const OUString& rCharFormatName )
310{
311 SwCharFormat* pFormat = nullptr;
312 const sal_uInt16 nChCount = pSh->GetCharFormatCount();
313 for(sal_uInt16 i = 0; i< nChCount; i++)
314 {
315 SwCharFormat& rChFormat = pSh->GetCharFormat(i);
316 if(rChFormat.GetName() == rCharFormatName )
317 {
318 pFormat = &rChFormat;
319 break;
320 }
321 }
322 if(!pFormat)
323 {
325 SfxStyleSheetBase* pBase;
326 pBase = pPool->Find(rCharFormatName, SfxStyleFamily::Char);
327 if(!pBase)
328 pBase = &pPool->Make(rCharFormatName, SfxStyleFamily::Char);
329 pFormat = static_cast<SwDocStyleSheet*>(pBase)->GetCharFormat();
330 }
331 return pFormat;
332}
333
335{
336 std::unique_ptr<SwEndNoteInfo> pInf(bEndNote ? new SwEndNoteInfo() : new SwFootnoteInfo());
337
338 pInf->m_nFootnoteOffset = m_xOffsetField->get_value() - 1;
339 pInf->m_aFormat.SetNumberingType(m_xNumViewBox->GetSelectedNumberingType() );
340 pInf->SetPrefix(m_xPrefixED->get_text().replaceAll("\\t", "\t"));
341 pInf->SetSuffix(m_xSuffixED->get_text().replaceAll("\\t", "\t"));
342
343 pInf->SetCharFormat( lcl_GetCharFormat( pSh,
344 m_xFootnoteCharTextTemplBox->get_active_text() ) );
345 pInf->SetAnchorCharFormat( lcl_GetCharFormat( pSh,
346 m_xFootnoteCharAnchorTemplBox->get_active_text() ) );
347
348 // paragraph template
349 int nPos = m_xParaTemplBox->get_active();
350 if (nPos != -1)
351 {
352 const OUString aFormatName( m_xParaTemplBox->get_active_text() );
354 OSL_ENSURE(pColl, "paragraph style not found");
355 pInf->SetFootnoteTextColl(*pColl);
356 }
357
358 // page template
359 pInf->ChgPageDesc( pSh->FindPageDescByName(
360 m_xPageTemplBox->get_active_text(), true ) );
361
362 if ( bEndNote )
363 {
364 if ( !(*pInf == pSh->GetEndNoteInfo()) )
365 pSh->SetEndNoteInfo( *pInf );
366 }
367 else
368 {
369 SwFootnoteInfo *pI = static_cast<SwFootnoteInfo*>(pInf.get());
370 pI->m_ePos = m_xPosPageBox->get_active() ? FTNPOS_PAGE : FTNPOS_CHAPTER;
371 pI->m_eNum = GetNumbering();
372 pI->m_aQuoVadis = m_xContEdit->get_text();
373 pI->m_aErgoSum = m_xContFromEdit->get_text();
374 if ( !(*pI == pSh->GetFootnoteInfo()) )
375 pSh->SetFootnoteInfo( *pI );
376 }
377 return true;
378}
379
381 : SwEndNoteOptionPage(pPage, pController, false, rSet)
382{
383}
384
386{
387}
388
389std::unique_ptr<SfxTabPage> SwFootNoteOptionPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet *rSet )
390{
391 return std::make_unique<SwFootNoteOptionPage>(pPage, pController, *rSet);
392}
393
394/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static SfxObjectShell * Current()
SfxStyleSheetBase * First(SfxStyleFamily eFamily, SfxStyleSearchBits eMask=SfxStyleSearchBits::All)
virtual SfxStyleSheetBase * Find(const OUString &, SfxStyleFamily eFam, SfxStyleSearchBits n=SfxStyleSearchBits::All) const
virtual SfxStyleSheetBase & Make(const OUString &, SfxStyleFamily eFam, SfxStyleSearchBits nMask=SfxStyleSearchBits::All)
SfxStyleSheetBase * Next()
const OUString & GetName() const
void AddTabPage(const OString &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:1154
SwDoc * GetDoc()
returns Doc. But be careful!
Definition: docsh.hxx:204
const SwFootnoteInfo & GetFootnoteInfo() const
Footnote attributes global to document.
Definition: editsh.cxx:903
const SwEndNoteInfo & GetEndNoteInfo() const
Definition: editsh.cxx:917
void SetEndNoteInfo(const SwEndNoteInfo &rInfo)
Definition: editsh.cxx:922
sal_uInt16 GetCharFormatCount() const
CHAR.
Definition: edfmt.cxx:29
void SetFootnoteInfo(const SwFootnoteInfo &rInfo)
Definition: editsh.cxx:908
SwCharFormat & GetCharFormat(sal_uInt16 nFormat) const
Definition: edfmt.cxx:34
std::unique_ptr< weld::Label > m_xPageTemplLbl
Definition: impfnote.hxx:49
std::unique_ptr< weld::RadioButton > m_xPosPageBox
Definition: impfnote.hxx:45
std::unique_ptr< weld::Entry > m_xPrefixED
Definition: impfnote.hxx:42
std::unique_ptr< weld::SpinButton > m_xOffsetField
Definition: impfnote.hxx:40
std::unique_ptr< weld::ComboBox > m_xParaTemplBox
Definition: impfnote.hxx:48
std::unique_ptr< weld::Entry > m_xContEdit
Definition: impfnote.hxx:53
std::unique_ptr< weld::ComboBox > m_xFootnoteCharAnchorTemplBox
Definition: impfnote.hxx:51
SwWrtShell * pSh
Definition: impfnote.hxx:34
std::unique_ptr< weld::ComboBox > m_xPageTemplBox
Definition: impfnote.hxx:50
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: docfnote.cxx:213
std::unique_ptr< weld::Entry > m_xSuffixED
Definition: impfnote.hxx:43
virtual void Reset(const SfxItemSet *) override
Definition: docfnote.cxx:111
virtual ~SwEndNoteOptionPage() override
Definition: docfnote.cxx:107
void SelectNumbering(SwFootnoteNum eNum)
Definition: docfnote.cxx:220
void SetShell(SwWrtShell &rShell)
Definition: docfnote.cxx:247
OUString aNumChapter
Definition: impfnote.hxx:33
std::unique_ptr< weld::ComboBox > m_xFootnoteCharTextTemplBox
Definition: impfnote.hxx:52
std::unique_ptr< weld::Entry > m_xContFromEdit
Definition: impfnote.hxx:54
std::unique_ptr< weld::Widget > m_xStylesContainer
Definition: impfnote.hxx:47
SwFootnoteNum GetNumbering() const
Definition: docfnote.cxx:241
std::unique_ptr< weld::RadioButton > m_xPosChapterBox
Definition: impfnote.hxx:46
std::unique_ptr< weld::ComboBox > m_xNumCountBox
Definition: impfnote.hxx:41
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: docfnote.cxx:334
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
virtual void PageCreated(const OString &rId, SfxTabPage &rPage) override
Definition: docfnote.cxx:50
SwWrtShell & rSh
Definition: docfnote.hxx:28
virtual ~SwFootNoteOptionPage() override
Definition: docfnote.cxx:385
SwFootNoteOptionPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: docfnote.cxx:380
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: docfnote.cxx:389
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:59
SwDoc * GetDoc() const
Definition: viewsh.hxx:282
SwDocShell * GetDocShell()
Definition: view.cxx:1133
Used by the UI to modify the document model.
Definition: wrtsh.hxx:97
@ GETSTYLE_CREATEANY
Definition: wrtsh.hxx:362
SwTextFormatColl * GetParaStyle(const OUString &rCollName, GetStyle eCreate=GETSTYLE_NOCREATE)
Definition: wrtsh1.cxx:1793
const SwView & GetView() const
Definition: wrtsh.hxx:437
void connect_clicked(const Link< Button &, void > &rLink)
int nCount
static SwCharFormat * lcl_GetCharFormat(SwWrtShell *pSh, const OUString &rCharFormatName)
Definition: docfnote.cxx:309
IMPL_LINK(SwFootNoteOptionDlg, OkHdl, weld::Button &, rBtn, void)
Definition: docfnote.cxx:55
IMPL_LINK_NOARG(SwEndNoteOptionPage, NumCountHdl, weld::ComboBox &, void)
Definition: docfnote.cxx:297
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:352
@ 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:780