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>
21 #include <osl/diagnose.h>
25 #include <docfnote.hxx>
26 #include "impfnote.hxx"
27 #include <ftninfo.hxx>
29 #include <pagedesc.hxx>
30 #include <charfmt.hxx>
31 #include <docstyle.hxx>
34 #include <poolfmt.hxx>
35 #include <SwStyleNameMapper.hxx>
38 SwFootNoteOptionDlg::SwFootNoteOptionDlg(weld::Window
*pParent
, SwWrtShell
&rS
)
39 : SfxTabDialogController(pParent
, u
"modules/swriter/ui/footendnotedialog.ui"_ustr
, u
"FootEndnoteDialog"_ustr
)
44 GetOKButton().connect_clicked(LINK(this, SwFootNoteOptionDlg
, OkHdl
));
46 AddTabPage(u
"footnotes"_ustr
, SwFootNoteOptionPage::Create
, nullptr);
47 AddTabPage(u
"endnotes"_ustr
, SwEndNoteOptionPage::Create
, nullptr);
50 void SwFootNoteOptionDlg::PageCreated(const OUString
& /*rId*/, SfxTabPage
&rPage
)
52 static_cast<SwEndNoteOptionPage
&>(rPage
).SetShell(m_rSh
);
55 IMPL_LINK(SwFootNoteOptionDlg
, OkHdl
, weld::Button
&, rBtn
, void)
57 SfxItemSetFixed
<1, 1> aDummySet(m_rSh
.GetAttrPool());
58 SfxTabPage
*pPage
= GetTabPage(u
"footnotes");
60 pPage
->FillItemSet( &aDummySet
);
61 pPage
= GetTabPage(u
"endnotes");
63 pPage
->FillItemSet( &aDummySet
);
64 SfxTabDialogController::OkHdl(rBtn
);
67 SwEndNoteOptionPage::SwEndNoteOptionPage(weld::Container
* pPage
, weld::DialogController
* pController
, bool bEN
,
68 const SfxItemSet
&rSet
)
69 : SfxTabPage(pPage
, pController
,
70 bEN
? u
"modules/swriter/ui/endnotepage.ui"_ustr
: u
"modules/swriter/ui/footnotepage.ui"_ustr
,
71 bEN
? u
"EndnotePage"_ustr
: u
"FootnotePage"_ustr
,
76 , m_xNumViewBox(new SwNumberingTypeListBox(m_xBuilder
->weld_combo_box(u
"numberinglb"_ustr
)))
77 , m_xOffsetLbl(m_xBuilder
->weld_label(u
"offset"_ustr
))
78 , m_xOffsetField(m_xBuilder
->weld_spin_button(u
"offsetnf"_ustr
))
79 , m_xNumCountBox(m_xBuilder
->weld_combo_box(u
"countinglb"_ustr
))
80 , m_xPrefixED(m_xBuilder
->weld_entry(u
"prefix"_ustr
))
81 , m_xSuffixED(m_xBuilder
->weld_entry(u
"suffix"_ustr
))
82 , m_xPosPageBox(m_xBuilder
->weld_radio_button(u
"pospagecb"_ustr
))
83 , m_xPosChapterBox(m_xBuilder
->weld_radio_button(u
"posdoccb"_ustr
))
84 , m_xStylesContainer(m_xBuilder
->weld_widget(u
"allstyles"_ustr
))
85 , m_xParaTemplBox(m_xBuilder
->weld_combo_box(u
"parastylelb"_ustr
))
86 , m_xPageTemplLbl(m_xBuilder
->weld_label(u
"pagestyleft"_ustr
))
87 , m_xPageTemplBox(m_xBuilder
->weld_combo_box(u
"pagestylelb"_ustr
))
88 , m_xFootnoteCharAnchorTemplBox(m_xBuilder
->weld_combo_box(u
"charanchorstylelb"_ustr
))
89 , m_xFootnoteCharTextTemplBox(m_xBuilder
->weld_combo_box(u
"charstylelb"_ustr
))
90 , m_xContEdit(m_xBuilder
->weld_entry(u
"conted"_ustr
))
91 , m_xContFromEdit(m_xBuilder
->weld_entry(u
"contfromed"_ustr
))
93 m_xNumViewBox
->Reload(SwInsertNumTypes::Extended
);
96 m_xNumCountBox
->connect_changed(LINK(this, SwEndNoteOptionPage
, NumCountHdl
));
97 m_aNumDoc
= m_xNumCountBox
->get_text(FTNNUM_DOC
);
98 m_aNumPage
= m_xNumCountBox
->get_text(FTNNUM_PAGE
);
99 m_aNumChapter
= m_xNumCountBox
->get_text(FTNNUM_CHAPTER
);
100 m_xPosPageBox
->connect_toggled(LINK(this, SwEndNoteOptionPage
, ToggleHdl
));
101 m_xPosChapterBox
->connect_toggled(LINK(this, SwEndNoteOptionPage
, ToggleHdl
));
103 m_xParaTemplBox
->make_sorted();
106 SwEndNoteOptionPage::~SwEndNoteOptionPage()
110 void SwEndNoteOptionPage::Reset( const SfxItemSet
* )
112 std::unique_ptr
<SwEndNoteInfo
> pInf(m_bEndNote
? new SwEndNoteInfo( m_pSh
->GetEndNoteInfo() )
113 : new SwFootnoteInfo( m_pSh
->GetFootnoteInfo() ));
114 SfxObjectShell
* pDocSh
= SfxObjectShell::Current();
116 if (dynamic_cast<SwWebDocShell
*>( pDocSh
) )
117 m_xStylesContainer
->hide();
125 const SwFootnoteInfo
&rInf
= m_pSh
->GetFootnoteInfo();
126 // set position (page, chapter)
127 if ( rInf
.m_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(m_aNumPage
);
137 m_xNumCountBox
->remove_text(m_aNumChapter
);
141 m_xContEdit
->set_text(rInf
.m_aQuoVadis
);
142 m_xContFromEdit
->set_text(rInf
.m_aErgoSum
);
145 SelectNumbering(rInf
.m_eNum
);
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"));
155 const SwCharFormat
* pCharFormat
= pInf
->GetCharFormat(
156 *m_pSh
->GetView().GetDocShell()->GetDoc());
157 m_xFootnoteCharTextTemplBox
->set_active_text(pCharFormat
->GetName());
158 m_xFootnoteCharTextTemplBox
->save_value();
160 pCharFormat
= pInf
->GetAnchorCharFormat( *m_pSh
->GetDoc() );
161 m_xFootnoteCharAnchorTemplBox
->set_active_text( pCharFormat
->GetName() );
162 m_xFootnoteCharAnchorTemplBox
->save_value();
164 // styles special regions
166 SfxStyleSheetBasePool
* pStyleSheetPool
= m_pSh
->GetView().GetDocShell()->GetStyleSheetPool();
167 SfxStyleSheetBase
*pStyle
= pStyleSheetPool
->First(SfxStyleFamily::Para
, SfxStyleSearchBits::SwExtra
);
170 m_xParaTemplBox
->append_text(pStyle
->GetName());
171 pStyle
= pStyleSheetPool
->Next();
175 SwStyleNameMapper::FillUIName( static_cast< sal_uInt16
>(m_bEndNote
? RES_POOLCOLL_ENDNOTE
176 : RES_POOLCOLL_FOOTNOTE
), sStr
);
177 if (m_xParaTemplBox
->find_text(sStr
) == -1)
178 m_xParaTemplBox
->append_text(sStr
);
180 SwTextFormatColl
* pColl
= pInf
->GetFootnoteTextColl();
182 m_xParaTemplBox
->set_active_text(sStr
); // Default
185 OSL_ENSURE(!pColl
->IsDefault(), "default style for footnotes is wrong");
186 const int nPos
= m_xParaTemplBox
->find_text(pColl
->GetName());
188 m_xParaTemplBox
->set_active( nPos
);
191 m_xParaTemplBox
->append_text(pColl
->GetName());
192 m_xParaTemplBox
->set_active_text(pColl
->GetName());
197 for (sal_uInt16 i
= RES_POOLPAGE_BEGIN
; i
< RES_POOLPAGE_END
; ++i
)
198 m_xPageTemplBox
->append_text(SwStyleNameMapper::GetUIName(i
, OUString()));
200 const size_t nCount
= m_pSh
->GetPageDescCnt();
201 for(size_t i
= 0; i
< nCount
; ++i
)
203 const SwPageDesc
&rPageDesc
= m_pSh
->GetPageDesc(i
);
204 if (m_xPageTemplBox
->find_text(rPageDesc
.GetName()) == -1)
205 m_xPageTemplBox
->append_text(rPageDesc
.GetName());
207 m_xPageTemplBox
->make_sorted();
209 m_xPageTemplBox
->set_active_text(pInf
->GetPageDesc(*m_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
)
228 sSelect
= m_aNumPage
;
231 sSelect
= m_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
>(m_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 m_pSh
->GetView().GetDocShell(), true);
255 ::FillCharStyleListBox(*m_xFootnoteCharAnchorTemplBox
,
256 m_pSh
->GetView().GetDocShell(), true);
259 IMPL_LINK(SwEndNoteOptionPage
, ToggleHdl
, weld::Toggleable
&, rButton
, void)
261 if (!rButton
.get_active())
264 if (m_xPosPageBox
->get_active())
266 // Handler behind the button to collect the footnote at the page. In this case
267 // all kinds of numbering can be used.
269 const SwFootnoteNum eNum
= GetNumbering();
271 if (m_xNumCountBox
->find_text(m_aNumPage
) == -1)
273 m_xNumCountBox
->insert_text(FTNNUM_PAGE
, m_aNumPage
);
274 m_xNumCountBox
->insert_text(FTNNUM_CHAPTER
, m_aNumChapter
);
275 SelectNumbering(eNum
);
277 m_xPageTemplLbl
->set_sensitive(false);
278 m_xPageTemplBox
->set_sensitive(false);
280 else if (m_xPosChapterBox
->get_active())
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.
286 SelectNumbering(FTNNUM_DOC
);
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);
296 IMPL_LINK_NOARG(SwEndNoteOptionPage
, NumCountHdl
, weld::ComboBox
&, void)
299 if (m_xNumCountBox
->get_count() - 1 != m_xNumCountBox
->get_active())
302 m_xOffsetField
->set_value(1);
304 m_xOffsetLbl
->set_sensitive(bEnable
);
305 m_xOffsetField
->set_sensitive(bEnable
);
308 static SwCharFormat
* lcl_GetCharFormat( SwWrtShell
* pSh
, const OUString
& rCharFormatName
)
310 SwCharFormat
* pFormat
= nullptr;
311 const sal_uInt16 nChCount
= pSh
->GetCharFormatCount();
312 for(sal_uInt16 i
= 0; i
< nChCount
; i
++)
314 SwCharFormat
& rChFormat
= pSh
->GetCharFormat(i
);
315 if(rChFormat
.GetName() == rCharFormatName
)
317 pFormat
= &rChFormat
;
323 SfxStyleSheetBasePool
* pPool
= pSh
->GetView().GetDocShell()->GetStyleSheetPool();
324 SfxStyleSheetBase
* pBase
;
325 pBase
= pPool
->Find(rCharFormatName
, SfxStyleFamily::Char
);
327 pBase
= &pPool
->Make(rCharFormatName
, SfxStyleFamily::Char
);
328 pFormat
= static_cast<SwDocStyleSheet
*>(pBase
)->GetCharFormat();
333 bool SwEndNoteOptionPage::FillItemSet( SfxItemSet
* )
335 std::unique_ptr
<SwEndNoteInfo
> pInf(m_bEndNote
? new SwEndNoteInfo() : new SwFootnoteInfo());
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"));
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() ) );
347 // paragraph template
348 int nPos
= m_xParaTemplBox
->get_active();
351 const OUString
aFormatName( m_xParaTemplBox
->get_active_text() );
352 SwTextFormatColl
*pColl
= m_pSh
->GetParaStyle(aFormatName
, SwWrtShell::GETSTYLE_CREATEANY
);
353 assert(pColl
&& "paragraph style not found");
354 pInf
->SetFootnoteTextColl(*pColl
);
358 pInf
->ChgPageDesc( m_pSh
->FindPageDescByName(
359 m_xPageTemplBox
->get_active_text(), true ) );
363 if ( !(*pInf
== m_pSh
->GetEndNoteInfo()) )
364 m_pSh
->SetEndNoteInfo( *pInf
);
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
);
379 SwFootNoteOptionPage::SwFootNoteOptionPage(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
&rSet
)
380 : SwEndNoteOptionPage(pPage
, pController
, false, rSet
)
384 SwFootNoteOptionPage::~SwFootNoteOptionPage()
388 std::unique_ptr
<SfxTabPage
> SwFootNoteOptionPage::Create(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
*rSet
)
390 return std::make_unique
<SwFootNoteOptionPage
>(pPage
, pController
, *rSet
);
393 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */