1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <svl/style.hxx>
24 #include <docfnote.hxx>
25 #include "impfnote.hxx"
26 #include <ftninfo.hxx>
28 #include <pagedesc.hxx>
29 #include <charfmt.hxx>
30 #include <docstyle.hxx>
33 #include <poolfmt.hxx>
34 #include <SwStyleNameMapper.hxx>
37 SwFootNoteOptionDlg::SwFootNoteOptionDlg(weld::Window
*pParent
, SwWrtShell
&rS
)
38 : SfxTabDialogController(pParent
, "modules/swriter/ui/footendnotedialog.ui", "FootEndnoteDialog")
43 GetOKButton().connect_clicked(LINK(this, SwFootNoteOptionDlg
, OkHdl
));
45 AddTabPage("footnotes", SwFootNoteOptionPage::Create
, nullptr);
46 AddTabPage("endnotes", SwEndNoteOptionPage::Create
, nullptr);
49 void SwFootNoteOptionDlg::PageCreated(const OString
& /*rId*/, SfxTabPage
&rPage
)
51 static_cast<SwEndNoteOptionPage
&>(rPage
).SetShell(rSh
);
54 IMPL_LINK(SwFootNoteOptionDlg
, OkHdl
, weld::Button
&, rBtn
, void)
56 SfxItemSet
aDummySet(rSh
.GetAttrPool(), svl::Items
<1, 1>{} );
57 SfxTabPage
*pPage
= GetTabPage("footnotes");
59 pPage
->FillItemSet( &aDummySet
);
60 pPage
= GetTabPage("endnotes");
62 pPage
->FillItemSet( &aDummySet
);
63 SfxTabDialogController::OkHdl(rBtn
);
66 SwEndNoteOptionPage::SwEndNoteOptionPage(weld::Container
* pPage
, weld::DialogController
* pController
, bool bEN
,
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"),
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"))
93 m_xNumViewBox
->Reload(SwInsertNumTypes::Extended
);
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
);
99 aNumChapter
= m_xNumCountBox
->get_text(FTNNUM_CHAPTER
);
100 m_xPosPageBox
->connect_clicked(LINK(this, SwEndNoteOptionPage
, PosPageHdl
));
101 m_xPosChapterBox
->connect_clicked(LINK(this, SwEndNoteOptionPage
, PosChapterHdl
));
106 SwEndNoteOptionPage::~SwEndNoteOptionPage()
110 void SwEndNoteOptionPage::Reset( const SfxItemSet
* )
112 std::unique_ptr
<SwEndNoteInfo
> pInf(bEndNote
? new SwEndNoteInfo( pSh
->GetEndNoteInfo() )
113 : new SwFootnoteInfo( pSh
->GetFootnoteInfo() ));
114 SfxObjectShell
* pDocSh
= SfxObjectShell::Current();
116 if (dynamic_cast<SwWebDocShell
*>( pDocSh
) )
117 m_xStylesContainer
->hide();
125 const SwFootnoteInfo
&rInf
= pSh
->GetFootnoteInfo();
126 // set position (page, chapter)
127 if ( rInf
.ePos
== FTNPOS_PAGE
)
129 m_xPosPageBox
->set_active(true);
130 m_xPageTemplLbl
->set_sensitive(false);
131 m_xPageTemplBox
->set_sensitive(false);
135 m_xPosChapterBox
->set_active(true);
136 m_xNumCountBox
->remove_text(aNumPage
);
137 m_xNumCountBox
->remove_text(aNumChapter
);
141 m_xContEdit
->set_text(rInf
.aQuoVadis
);
142 m_xContFromEdit
->set_text(rInf
.aErgoSum
);
145 SelectNumbering(rInf
.eNum
);
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"));
155 const SwCharFormat
* pCharFormat
= pInf
->GetCharFormat(
156 *pSh
->GetView().GetDocShell()->GetDoc());
157 m_xFootnoteCharTextTemplBox
->set_active_text(pCharFormat
->GetName());
158 m_xFootnoteCharTextTemplBox
->save_value();
160 pCharFormat
= pInf
->GetAnchorCharFormat( *pSh
->GetDoc() );
161 m_xFootnoteCharAnchorTemplBox
->set_active_text( pCharFormat
->GetName() );
162 m_xFootnoteCharAnchorTemplBox
->save_value();
164 // styles special regions
166 SfxStyleSheetBasePool
* pStyleSheetPool
= pSh
->GetView().GetDocShell()->GetStyleSheetPool();
167 pStyleSheetPool
->SetSearchMask(SfxStyleFamily::Para
, SfxStyleSearchBits::SwExtra
);
168 SfxStyleSheetBase
*pStyle
= pStyleSheetPool
->First();
171 m_xParaTemplBox
->append_text(pStyle
->GetName());
172 pStyle
= pStyleSheetPool
->Next();
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
);
181 SwTextFormatColl
* pColl
= pInf
->GetFootnoteTextColl();
183 m_xParaTemplBox
->set_active_text(sStr
); // Default
186 OSL_ENSURE(!pColl
->IsDefault(), "default style for footnotes is wrong");
187 const int nPos
= m_xParaTemplBox
->find_text(pColl
->GetName());
189 m_xParaTemplBox
->set_active( nPos
);
192 m_xParaTemplBox
->append_text(pColl
->GetName());
193 m_xParaTemplBox
->set_active_text(pColl
->GetName());
198 for (sal_uInt16 i
= RES_POOLPAGE_BEGIN
; i
< RES_POOLPAGE_END
; ++i
)
199 m_xPageTemplBox
->append_text(SwStyleNameMapper::GetUIName(i
, OUString()));
201 const size_t nCount
= pSh
->GetPageDescCnt();
202 for(size_t i
= 0; i
< nCount
; ++i
)
204 const SwPageDesc
&rPageDesc
= pSh
->GetPageDesc(i
);
205 if (m_xPageTemplBox
->find_text(rPageDesc
.GetName()) == -1)
206 m_xPageTemplBox
->append_text(rPageDesc
.GetName());
209 m_xPageTemplBox
->set_active_text(pInf
->GetPageDesc(*pSh
->GetDoc())->GetName());
212 std::unique_ptr
<SfxTabPage
> SwEndNoteOptionPage::Create( weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
*rSet
)
214 return std::make_unique
<SwEndNoteOptionPage
>(pPage
, pController
, true, *rSet
);
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.
219 void SwEndNoteOptionPage::SelectNumbering(SwFootnoteNum
const eNum
)
231 sSelect
= aNumChapter
;
236 m_xNumCountBox
->set_active_text(sSelect
);
237 NumCountHdl(*m_xNumCountBox
);
240 SwFootnoteNum
SwEndNoteOptionPage::GetNumbering() const
242 const int nPos
= m_xNumCountBox
->get_active();
243 return static_cast<SwFootnoteNum
>(bPosDoc
? nPos
+ 2 : nPos
);
246 void SwEndNoteOptionPage::SetShell( SwWrtShell
&rShell
)
249 // collect character templates
250 m_xFootnoteCharTextTemplBox
->clear();
251 m_xFootnoteCharAnchorTemplBox
->clear();
252 ::FillCharStyleListBox(*m_xFootnoteCharTextTemplBox
,
253 pSh
->GetView().GetDocShell());
255 ::FillCharStyleListBox(*m_xFootnoteCharAnchorTemplBox
,
256 pSh
->GetView().GetDocShell());
259 // Handler behind the button to collect the footnote at the page. In this case
260 // all kinds of numbering can be used.
261 IMPL_LINK_NOARG(SwEndNoteOptionPage
, PosPageHdl
, weld::Button
&, void)
263 const SwFootnoteNum eNum
= GetNumbering();
265 if (m_xNumCountBox
->find_text(aNumPage
) == -1)
267 m_xNumCountBox
->insert_text(FTNNUM_PAGE
, aNumPage
);
268 m_xNumCountBox
->insert_text(FTNNUM_CHAPTER
, aNumChapter
);
269 SelectNumbering(eNum
);
271 m_xPageTemplLbl
->set_sensitive(false);
272 m_xPageTemplBox
->set_sensitive(false);
275 IMPL_LINK_NOARG(SwEndNoteOptionPage
, NumCountHdl
, weld::ComboBox
&, void)
278 if (m_xNumCountBox
->get_count() - 1 != m_xNumCountBox
->get_active())
281 m_xOffsetField
->set_value(1);
283 m_xOffsetLbl
->set_sensitive(bEnable
);
284 m_xOffsetField
->set_sensitive(bEnable
);
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.
289 IMPL_LINK_NOARG(SwEndNoteOptionPage
, PosChapterHdl
, weld::Button
&, void)
292 SelectNumbering(FTNNUM_DOC
);
295 m_xNumCountBox
->remove_text(aNumPage
);
296 m_xNumCountBox
->remove_text(aNumChapter
);
297 m_xPageTemplLbl
->set_sensitive(true);
298 m_xPageTemplBox
->set_sensitive(true);
301 static SwCharFormat
* lcl_GetCharFormat( SwWrtShell
* pSh
, const OUString
& rCharFormatName
)
303 SwCharFormat
* pFormat
= nullptr;
304 const sal_uInt16 nChCount
= pSh
->GetCharFormatCount();
305 for(sal_uInt16 i
= 0; i
< nChCount
; i
++)
307 SwCharFormat
& rChFormat
= pSh
->GetCharFormat(i
);
308 if(rChFormat
.GetName() == rCharFormatName
)
310 pFormat
= &rChFormat
;
316 SfxStyleSheetBasePool
* pPool
= pSh
->GetView().GetDocShell()->GetStyleSheetPool();
317 SfxStyleSheetBase
* pBase
;
318 pBase
= pPool
->Find(rCharFormatName
, SfxStyleFamily::Char
);
320 pBase
= &pPool
->Make(rCharFormatName
, SfxStyleFamily::Char
);
321 pFormat
= static_cast<SwDocStyleSheet
*>(pBase
)->GetCharFormat();
326 bool SwEndNoteOptionPage::FillItemSet( SfxItemSet
* )
328 std::unique_ptr
<SwEndNoteInfo
> pInf(bEndNote
? new SwEndNoteInfo() : new SwFootnoteInfo());
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"));
335 pInf
->SetCharFormat( lcl_GetCharFormat( pSh
,
336 m_xFootnoteCharTextTemplBox
->get_active_text() ) );
337 pInf
->SetAnchorCharFormat( lcl_GetCharFormat( pSh
,
338 m_xFootnoteCharAnchorTemplBox
->get_active_text() ) );
340 // paragraph template
341 int nPos
= m_xParaTemplBox
->get_active();
344 const OUString
aFormatName( m_xParaTemplBox
->get_active_text() );
345 SwTextFormatColl
*pColl
= pSh
->GetParaStyle(aFormatName
, SwWrtShell::GETSTYLE_CREATEANY
);
346 OSL_ENSURE(pColl
, "paragraph style not found");
347 pInf
->SetFootnoteTextColl(*pColl
);
351 pInf
->ChgPageDesc( pSh
->FindPageDescByName(
352 m_xPageTemplBox
->get_active_text(), true ) );
356 if ( !(*pInf
== pSh
->GetEndNoteInfo()) )
357 pSh
->SetEndNoteInfo( *pInf
);
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
);
372 SwFootNoteOptionPage::SwFootNoteOptionPage(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
&rSet
)
373 : SwEndNoteOptionPage(pPage
, pController
, false, rSet
)
377 SwFootNoteOptionPage::~SwFootNoteOptionPage()
381 std::unique_ptr
<SfxTabPage
> SwFootNoteOptionPage::Create(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
*rSet
)
383 return std::make_unique
<SwFootNoteOptionPage
>(pPage
, pController
, *rSet
);
386 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */