lok: Hide file linking in section
[LibreOffice.git] / sw / source / ui / misc / insfnote.cxx
blob29d4c6482b24b28f702dce2aa503ac2d17b68d20
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
26 #include <fmtftn.hxx>
27 #include <swundo.hxx>
28 #include <cmdid.h>
29 #include <wrtsh.hxx>
30 #include <view.hxx>
31 #include <basesh.hxx>
32 #include <insfnote.hxx>
33 #include <globals.hrc>
34 #include <svx/svxdlg.hxx>
35 #include <svx/dialogs.hrc>
36 #include <sfx2/viewfrm.hxx>
38 #include <memory>
40 static bool bFootnote = true;
42 // inserting a footnote with OK
43 void SwInsFootNoteDlg::Apply()
45 OUString aStr;
46 if ( m_xNumberCharBtn->get_active() )
47 aStr = m_xNumberCharEdit->get_text();
49 if (m_bEdit)
51 m_rSh.StartAction();
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 );
66 aSet.Put( aFont );
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 );
72 m_rSh.EndAction();
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);
113 if ( pItem )
115 m_xNumberCharEdit->set_text(pItem->GetValue());
117 if ( pFontItem )
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 )
135 Apply();
137 // go to the next foot/endnote here
138 m_rSh.ResetSelect(nullptr, false);
139 if (&rBtn == m_xNextBT.get())
140 m_rSh.GotoNextFootnoteAnchor();
141 else
142 m_rSh.GotoPrevFootnoteAnchor();
144 Init();
147 SwInsFootNoteDlg::SwInsFootNoteDlg(weld::Window *pParent, SwWrtShell &rShell, bool bEd)
148 : GenericDialogController(pParent, "modules/swriter/ui/insertfootnote.ui", "InsertFootnoteDialog")
149 , m_rSh(rShell)
150 , m_eCharSet(RTL_TEXTENCODING_DONTKNOW)
151 , m_bExtCharAvailable(false)
152 , m_bEdit(bEd)
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);
174 if (m_bEdit)
176 Init();
178 m_xPrevBT->show();
179 m_xNextBT->show();
183 SwInsFootNoteDlg::~SwInsFootNoteDlg() COVERITY_NOEXCEPT_FALSE
185 SwViewShell::SetCareDialog(nullptr);
187 if (m_bEdit)
188 m_rSh.ResetSelect(nullptr, false);
191 void SwInsFootNoteDlg::Init()
193 SwFormatFootnote aFootnoteNote;
194 OUString sNumStr;
195 vcl::Font aFont;
196 m_bExtCharAvailable = false;
198 m_rSh.StartAction();
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);
227 if (bNumChar)
228 m_xNumberCharEdit->grab_focus();
230 if (bFootnote)
231 m_xFootnoteBtn->set_active(true);
232 else
233 m_xEndNoteBtn->set_active(true);
235 bool bNext = m_rSh.GotoNextFootnoteAnchor();
237 if (bNext)
238 m_rSh.GotoPrevFootnoteAnchor();
240 bool bPrev = m_rSh.GotoPrevFootnoteAnchor();
242 if (bPrev)
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 );
250 m_rSh.EndAction();
253 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */