LibreOffice Module sw (master)  1
insfnote.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 <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>
37 
38 #include <memory>
39 
40 static bool bFootnote = true;
41 
42 // inserting a footnote with OK
44 {
45  OUString aStr;
46  if ( m_xNumberCharBtn->get_active() )
47  aStr = m_xNumberCharEdit->get_text();
48 
49  if (m_bEdit)
50  {
52  m_rSh.Left(CRSR_SKIP_CHARS, false, 1, false );
54  SwFormatFootnote aNote( m_xEndNoteBtn->get_active() );
55  aNote.SetNumStr( aStr );
56 
58  {
59  m_rSh.Right(CRSR_SKIP_CHARS, true, 1, false );
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(),
66  aSet.Put( aFont );
68  m_rSh.ResetSelect(nullptr, false);
69  m_rSh.Left(CRSR_SKIP_CHARS, false, 1, false );
70  }
72  m_rSh.EndAction();
73  }
74 
75  bFootnote = m_xFootnoteBtn->get_active();
76 }
77 
79 {
80  m_xNumberCharEdit->grab_focus();
81  m_xOkBtn->set_sensitive( !m_xNumberCharEdit->get_text().isEmpty() || m_bExtCharAvailable );
82 }
83 
85 {
86  m_xNumberCharBtn->set_active(true);
87  m_xOkBtn->set_sensitive( !m_xNumberCharEdit->get_text().isEmpty() );
88 }
89 
90 IMPL_LINK_NOARG(SwInsFootNoteDlg, NumberAutoBtnHdl, weld::Button&, void)
91 {
92  m_xOkBtn->set_sensitive(true);
93 }
94 
95 IMPL_LINK_NOARG(SwInsFootNoteDlg, NumberExtCharHdl, weld::Button&, void)
96 {
97  m_xNumberCharBtn->set_active(true);
98 
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 );
102 
103  SfxAllItemSet aAllSet(m_rSh.GetAttrPool());
104  aAllSet.Put( SfxBoolItem( FN_PARAM_1, false ) );
105  aAllSet.Put( rFont );
106 
108  ScopedVclPtr<SfxAbstractDialog> pDlg(pFact->CreateCharMapDialog(m_xDialog.get(), aAllSet, nullptr));
109  if (RET_OK == pDlg->Execute())
110  {
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 )
114  {
115  m_xNumberCharEdit->set_text(pItem->GetValue());
116 
117  if ( pFontItem )
118  {
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);
125  }
126 
127  m_bExtCharAvailable = true;
128  m_xOkBtn->set_sensitive(!m_xNumberCharEdit->get_text().isEmpty());
129  }
130  }
131 }
132 
133 IMPL_LINK( SwInsFootNoteDlg, NextPrevHdl, weld::Button&, rBtn, void )
134 {
135  Apply();
136 
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();
143 
144  Init();
145 }
146 
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"))
163 {
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));
168 
169  m_xPrevBT->connect_clicked(LINK(this, SwInsFootNoteDlg, NextPrevHdl));
170  m_xNextBT->connect_clicked(LINK(this, SwInsFootNoteDlg, NextPrevHdl));
171 
173 
174  if (m_bEdit)
175  {
176  Init();
177 
178  m_xPrevBT->show();
179  m_xNextBT->show();
180  }
181 }
182 
183 SwInsFootNoteDlg::~SwInsFootNoteDlg() COVERITY_NOEXCEPT_FALSE
184 {
186 
187  if (m_bEdit)
188  m_rSh.ResetSelect(nullptr, false);
189 }
190 
192 {
193  SwFormatFootnote aFootnoteNote;
194  OUString sNumStr;
195  vcl::Font aFont;
196  m_bExtCharAvailable = false;
197 
198  m_rSh.StartAction();
199 
200  if (m_rSh.GetCurFootnote(&aFootnoteNote))
201  {
202  if (!aFootnoteNote.GetNumStr().isEmpty())
203  {
204  sNumStr = aFootnoteNote.GetNumStr();
205 
206  m_rSh.Right(CRSR_SKIP_CHARS, true, 1, false );
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 );
217  }
218  bFootnote = !aFootnoteNote.IsEndNote();
219  }
220  m_xNumberCharEdit->set_font(aFont);
221 
222  const bool bNumChar = !sNumStr.isEmpty();
223 
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();
229 
230  if (bFootnote)
231  m_xFootnoteBtn->set_active(true);
232  else
233  m_xEndNoteBtn->set_active(true);
234 
235  bool bNext = m_rSh.GotoNextFootnoteAnchor();
236 
237  if (bNext)
239 
240  bool bPrev = m_rSh.GotoPrevFootnoteAnchor();
241 
242  if (bPrev)
244 
245  m_xPrevBT->set_sensitive(bPrev);
246  m_xNextBT->set_sensitive(bNext);
247 
248  m_rSh.Right(CRSR_SKIP_CHARS, true, 1, false );
249 
250  m_rSh.EndAction();
251 }
252 
253 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::shared_ptr< weld::Dialog > m_xDialog
std::unique_ptr< weld::Entry > m_xNumberCharEdit
Definition: insfnote.hxx:41
bool Right(sal_uInt16 nMode, bool bSelect, sal_uInt16 nCount, bool bBasicCall, bool bVisual=false)
Definition: move.cxx:123
OUString m_aFontName
Definition: insfnote.hxx:33
void Init()
IMPL_LINK_NOARG(SwInsFootNoteDlg, NumberCharHdl, weld::Button &, void)
Definition: insfnote.cxx:78
bool GotoNextFootnoteAnchor()
Definition: trvlfnfl.cxx:327
virtual const SfxItemSet * GetOutputItemSet() const =0
static SvxAbstractDialogFactory * Create()
void SetAttrSet(const SfxItemSet &, SetAttrMode nFlags=SetAttrMode::DEFAULT, SwPaM *pCursor=nullptr, const bool bParagraphSetting=false)
Definition: edatmisc.cxx:151
void SetNumStr(const OUString &rStr)
Definition: fmtftn.hxx:76
SwUndoId EndUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Closes parenthesis of nUndoId, not used by UI.
Definition: edws.cxx:233
#define RES_CHRATR_FONT
Definition: hintids.hxx:76
std::unique_ptr< weld::RadioButton > m_xFootnoteBtn
Definition: insfnote.hxx:45
void SetCharSet(rtl_TextEncoding)
bool IsEndNote() const
Definition: fmtftn.hxx:74
std::unique_ptr< weld::Button > m_xPrevBT
Definition: insfnote.hxx:49
FontPitch GetPitch() const
std::unique_ptr< weld::RadioButton > m_xNumberCharBtn
Definition: insfnote.hxx:40
static bool bFootnote
Definition: insfnote.cxx:40
std::unique_ptr< weld::Button > m_xNumberExtChar
Definition: insfnote.hxx:42
FontFamily GetFamily() const
virtual ~SwInsFootNoteDlg() COVERITY_NOEXCEPT_FALSE override
Definition: insfnote.cxx:183
SwWrtShell & m_rSh
Definition: insfnote.hxx:30
Used by the UI to modify the document model.
Definition: wrtsh.hxx:90
std::unique_ptr< weld::Button > m_xNextBT
Definition: insfnote.hxx:50
rtl_TextEncoding GetCharSet() const
const OUString & GetNumStr() const
Definition: fmtftn.hxx:71
std::unique_ptr< weld::RadioButton > m_xNumberAutoBtn
Definition: insfnote.hxx:39
const OUString & GetStyleName() const
std::unique_ptr< weld::RadioButton > m_xEndNoteBtn
Definition: insfnote.hxx:46
const SfxItemPool & GetAttrPool() const
Definition: viewsh.hxx:614
bool m_bExtCharAvailable
Definition: insfnote.hxx:35
void SetFamilyName(const OUString &rFamilyName)
void EndAction(const bool bIdleEnd=false, const bool DoSetPosX=false)
Definition: crsrsh.cxx:228
rtl_TextEncoding m_eCharSet
Definition: insfnote.hxx:34
const OUString & GetValue() const
SwUndoId StartUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Undo: set up Undo parenthesis, return nUndoId of this parenthesis.
Definition: edws.cxx:222
long ResetSelect(const Point *, bool)
Definition: select.cxx:337
virtual VclPtr< SfxAbstractDialog > CreateCharMapDialog(weld::Window *pParent, const SfxItemSet &rAttr, const css::uno::Reference< css::frame::XFrame > &rFrame)=0
bool GotoPrevFootnoteAnchor()
Definition: trvlfnfl.cxx:332
void StartAction()
Definition: crsrsh.cxx:211
const OUString & GetFamilyName() const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
bool SetCurFootnote(const SwFormatFootnote &rFillFootnote)
Definition: edattr.cxx:425
bool const m_bEdit
Definition: insfnote.hxx:36
static void SetCareDialog(const std::shared_ptr< weld::Window > &rNew)
Definition: viewsh.cxx:2498
bool Left(sal_uInt16 nMode, bool bSelect, sal_uInt16 nCount, bool bBasicCall, bool bVisual=false)
Definition: move.cxx:106
RET_OK
Reference< XExecutableDialog > m_xDialog
bool GetCurFootnote(SwFormatFootnote *pToFillFootnote=nullptr)
Query and set footnote-text/number. Set... to current SSelection!
Definition: edattr.cxx:405
bool GetCurAttr(SfxItemSet &, const bool bMergeIndentValuesOfNumRule=false) const
Definition: edattr.cxx:176
const sal_uInt16 CRSR_SKIP_CHARS
Definition: swcrsr.hxx:63
SwInsFootNoteDlg(weld::Window *pParent, SwWrtShell &rSh, bool bEd)
Definition: insfnote.cxx:147
aStr
IMPL_LINK(SwInsFootNoteDlg, NextPrevHdl, weld::Button &, rBtn, void)
Definition: insfnote.cxx:133