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 <hintids.hxx>
21 #include <svl/eitem.hxx>
22 #include <svl/stritem.hxx>
23 #include <svx/svxids.hrc>
24 #include <sfx2/request.hxx>
25 #include <editeng/fontitem.hxx>
32 #include <insfnote.hxx>
33 #include <globals.hrc>
34 #include <svx/svxdlg.hxx>
35 #include <svx/dialogs.hrc>
36 #include <sfx2/viewfrm.hxx>
40 static bool bFootnote
= true;
42 // inserting a footnote with OK
43 void SwInsFootNoteDlg::Apply()
46 if ( m_xNumberCharBtn
->get_active() )
47 aStr
= m_xNumberCharEdit
->get_text();
52 m_rSh
.Left(CRSR_SKIP_CHARS
, false, 1, false );
53 m_rSh
.StartUndo( SwUndoId::START
);
54 SwFormatFootnote
aNote( m_xEndNoteBtn
->get_active() );
55 aNote
.SetNumStr( aStr
);
57 if (m_rSh
.SetCurFootnote( aNote
) && m_bExtCharAvailable
)
59 m_rSh
.Right(CRSR_SKIP_CHARS
, true, 1, false );
60 SfxItemSet
aSet(m_rSh
.GetAttrPool(), svl::Items
<RES_CHRATR_FONT
, RES_CHRATR_FONT
>{});
61 m_rSh
.GetCurAttr(aSet
);
62 const SvxFontItem
&rFont
= aSet
.Get( RES_CHRATR_FONT
);
63 SvxFontItem
aFont( rFont
.GetFamily(), m_aFontName
,
64 rFont
.GetStyleName(), rFont
.GetPitch(),
65 m_eCharSet
, RES_CHRATR_FONT
);
67 m_rSh
.SetAttrSet( aSet
, SetAttrMode::DONTEXPAND
);
68 m_rSh
.ResetSelect(nullptr, false);
69 m_rSh
.Left(CRSR_SKIP_CHARS
, false, 1, false );
71 m_rSh
.EndUndo( SwUndoId::END
);
75 bFootnote
= m_xFootnoteBtn
->get_active();
78 IMPL_LINK_NOARG(SwInsFootNoteDlg
, NumberCharHdl
, weld::Button
&, void)
80 m_xNumberCharEdit
->grab_focus();
81 m_xOkBtn
->set_sensitive( !m_xNumberCharEdit
->get_text().isEmpty() || m_bExtCharAvailable
);
84 IMPL_LINK_NOARG(SwInsFootNoteDlg
, NumberEditHdl
, weld::Entry
&, void)
86 m_xNumberCharBtn
->set_active(true);
87 m_xOkBtn
->set_sensitive( !m_xNumberCharEdit
->get_text().isEmpty() );
90 IMPL_LINK_NOARG(SwInsFootNoteDlg
, NumberAutoBtnHdl
, weld::Button
&, void)
92 m_xOkBtn
->set_sensitive(true);
95 IMPL_LINK_NOARG(SwInsFootNoteDlg
, NumberExtCharHdl
, weld::Button
&, void)
97 m_xNumberCharBtn
->set_active(true);
99 SfxItemSet
aSet(m_rSh
.GetAttrPool(), svl::Items
<RES_CHRATR_FONT
, RES_CHRATR_FONT
>{});
100 m_rSh
.GetCurAttr( aSet
);
101 const SvxFontItem
&rFont
= aSet
.Get( RES_CHRATR_FONT
);
103 SfxAllItemSet
aAllSet(m_rSh
.GetAttrPool());
104 aAllSet
.Put( SfxBoolItem( FN_PARAM_1
, false ) );
105 aAllSet
.Put( rFont
);
107 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
108 ScopedVclPtr
<SfxAbstractDialog
> pDlg(pFact
->CreateCharMapDialog(m_xDialog
.get(), aAllSet
, nullptr));
109 if (RET_OK
== pDlg
->Execute())
111 const SfxStringItem
* pItem
= SfxItemSet::GetItem
<SfxStringItem
>(pDlg
->GetOutputItemSet(), SID_CHARMAP
, false);
112 const SvxFontItem
* pFontItem
= SfxItemSet::GetItem
<SvxFontItem
>(pDlg
->GetOutputItemSet(), SID_ATTR_CHAR_FONT
, false);
115 m_xNumberCharEdit
->set_text(pItem
->GetValue());
119 m_aFontName
= pFontItem
->GetFamilyName();
120 m_eCharSet
= pFontItem
->GetCharSet();
121 vcl::Font
aFont(m_aFontName
, pFontItem
->GetStyleName(), m_xNumberCharEdit
->get_font().GetFontSize());
122 aFont
.SetCharSet( pFontItem
->GetCharSet() );
123 aFont
.SetPitch( pFontItem
->GetPitch() );
124 m_xNumberCharEdit
->set_font(aFont
);
127 m_bExtCharAvailable
= true;
128 m_xOkBtn
->set_sensitive(!m_xNumberCharEdit
->get_text().isEmpty());
133 IMPL_LINK( SwInsFootNoteDlg
, NextPrevHdl
, weld::Button
&, rBtn
, void )
137 // go to the next foot/endnote here
138 m_rSh
.ResetSelect(nullptr, false);
139 if (&rBtn
== m_xNextBT
.get())
140 m_rSh
.GotoNextFootnoteAnchor();
142 m_rSh
.GotoPrevFootnoteAnchor();
147 SwInsFootNoteDlg::SwInsFootNoteDlg(weld::Window
*pParent
, SwWrtShell
&rShell
, bool bEd
)
148 : GenericDialogController(pParent
, "modules/swriter/ui/insertfootnote.ui", "InsertFootnoteDialog")
150 , m_eCharSet(RTL_TEXTENCODING_DONTKNOW
)
151 , m_bExtCharAvailable(false)
153 , m_xNumberFrame(m_xBuilder
->weld_widget("numberingframe"))
154 , m_xNumberAutoBtn(m_xBuilder
->weld_radio_button("automatic"))
155 , m_xNumberCharBtn(m_xBuilder
->weld_radio_button("character"))
156 , m_xNumberCharEdit(m_xBuilder
->weld_entry("characterentry"))
157 , m_xNumberExtChar(m_xBuilder
->weld_button("choosecharacter"))
158 , m_xFootnoteBtn(m_xBuilder
->weld_radio_button("footnote"))
159 , m_xEndNoteBtn(m_xBuilder
->weld_radio_button("endnote"))
160 , m_xOkBtn(m_xBuilder
->weld_button("ok"))
161 , m_xPrevBT(m_xBuilder
->weld_button("prev"))
162 , m_xNextBT(m_xBuilder
->weld_button("next"))
164 m_xNumberAutoBtn
->connect_clicked(LINK(this,SwInsFootNoteDlg
,NumberAutoBtnHdl
));
165 m_xNumberExtChar
->connect_clicked(LINK(this,SwInsFootNoteDlg
,NumberExtCharHdl
));
166 m_xNumberCharBtn
->connect_clicked(LINK(this,SwInsFootNoteDlg
,NumberCharHdl
));
167 m_xNumberCharEdit
->connect_changed(LINK(this,SwInsFootNoteDlg
,NumberEditHdl
));
169 m_xPrevBT
->connect_clicked(LINK(this, SwInsFootNoteDlg
, NextPrevHdl
));
170 m_xNextBT
->connect_clicked(LINK(this, SwInsFootNoteDlg
, NextPrevHdl
));
172 SwViewShell::SetCareDialog(m_xDialog
);
183 SwInsFootNoteDlg::~SwInsFootNoteDlg() COVERITY_NOEXCEPT_FALSE
185 SwViewShell::SetCareDialog(nullptr);
188 m_rSh
.ResetSelect(nullptr, false);
191 void SwInsFootNoteDlg::Init()
193 SwFormatFootnote aFootnoteNote
;
196 m_bExtCharAvailable
= false;
200 if (m_rSh
.GetCurFootnote(&aFootnoteNote
))
202 if (!aFootnoteNote
.GetNumStr().isEmpty())
204 sNumStr
= aFootnoteNote
.GetNumStr();
206 m_rSh
.Right(CRSR_SKIP_CHARS
, true, 1, false );
207 SfxItemSet
aSet(m_rSh
.GetAttrPool(), svl::Items
<RES_CHRATR_FONT
, RES_CHRATR_FONT
>{});
208 m_rSh
.GetCurAttr(aSet
);
209 const SvxFontItem
&rFont
= aSet
.Get( RES_CHRATR_FONT
);
210 aFont
= m_xNumberCharEdit
->get_font();
211 m_aFontName
= rFont
.GetFamilyName();
212 m_eCharSet
= rFont
.GetCharSet();
213 aFont
.SetFamilyName(m_aFontName
);
214 aFont
.SetCharSet(m_eCharSet
);
215 m_bExtCharAvailable
= true;
216 m_rSh
.Left( CRSR_SKIP_CHARS
, false, 1, false );
218 bFootnote
= !aFootnoteNote
.IsEndNote();
220 m_xNumberCharEdit
->set_font(aFont
);
222 const bool bNumChar
= !sNumStr
.isEmpty();
224 m_xNumberCharEdit
->set_text(sNumStr
);
225 m_xNumberCharBtn
->set_active(bNumChar
);
226 m_xNumberAutoBtn
->set_active(!bNumChar
);
228 m_xNumberCharEdit
->grab_focus();
231 m_xFootnoteBtn
->set_active(true);
233 m_xEndNoteBtn
->set_active(true);
235 bool bNext
= m_rSh
.GotoNextFootnoteAnchor();
238 m_rSh
.GotoPrevFootnoteAnchor();
240 bool bPrev
= m_rSh
.GotoPrevFootnoteAnchor();
243 m_rSh
.GotoNextFootnoteAnchor();
245 m_xPrevBT
->set_sensitive(bPrev
);
246 m_xNextBT
->set_sensitive(bNext
);
248 m_rSh
.Right(CRSR_SKIP_CHARS
, true, 1, false );
253 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */