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 <editeng/fontitem.hxx>
24 #include <fmtftn.hxx>
25 #include <swundo.hxx>
26 #include <cmdid.h>
27 #include <wrtsh.hxx>
28 #include <insfnote.hxx>
29 #include <svx/svxdlg.hxx>
30 
31 #include <memory>
32 
33 static bool bFootnote = true;
34 
35 // inserting a footnote with OK
37 {
38  OUString aStr;
39  if ( m_xNumberCharBtn->get_active() )
40  aStr = m_xNumberCharEdit->get_text();
41 
42  if (m_bEdit)
43  {
45  m_rSh.Left(CRSR_SKIP_CHARS, false, 1, false );
47  SwFormatFootnote aNote( m_xEndNoteBtn->get_active() );
48  aNote.SetNumStr( aStr );
49 
51  {
52  m_rSh.Right(CRSR_SKIP_CHARS, true, 1, false );
54  m_rSh.GetCurAttr(aSet);
55  const SvxFontItem &rFont = aSet.Get( RES_CHRATR_FONT );
56  SvxFontItem aFont( rFont.GetFamily(), m_aFontName,
57  rFont.GetStyleName(), rFont.GetPitch(),
59  aSet.Put( aFont );
61  m_rSh.ResetSelect(nullptr, false);
62  m_rSh.Left(CRSR_SKIP_CHARS, false, 1, false );
63  }
65  m_rSh.EndAction();
66  }
67 
68  bFootnote = m_xFootnoteBtn->get_active();
69 }
70 
72 {
73  m_xNumberCharEdit->grab_focus();
74  m_xOkBtn->set_sensitive( !m_xNumberCharEdit->get_text().isEmpty() || m_bExtCharAvailable );
75 }
76 
78 {
79  m_xNumberCharBtn->set_active(true);
80  m_xOkBtn->set_sensitive( !m_xNumberCharEdit->get_text().isEmpty() );
81 }
82 
83 IMPL_LINK_NOARG(SwInsFootNoteDlg, NumberAutoBtnHdl, weld::Button&, void)
84 {
85  m_xOkBtn->set_sensitive(true);
86 }
87 
88 IMPL_LINK_NOARG(SwInsFootNoteDlg, NumberExtCharHdl, weld::Button&, void)
89 {
90  m_xNumberCharBtn->set_active(true);
91 
92  SfxItemSet aSet(m_rSh.GetAttrPool(), svl::Items<RES_CHRATR_FONT, RES_CHRATR_FONT>{});
93  m_rSh.GetCurAttr( aSet );
94  const SvxFontItem &rFont = aSet.Get( RES_CHRATR_FONT );
95 
96  SfxAllItemSet aAllSet(m_rSh.GetAttrPool());
97  aAllSet.Put( SfxBoolItem( FN_PARAM_1, false ) );
98  aAllSet.Put( rFont );
99 
101  ScopedVclPtr<SfxAbstractDialog> pDlg(pFact->CreateCharMapDialog(m_xDialog.get(), aAllSet, nullptr));
102  if (RET_OK == pDlg->Execute())
103  {
104  const SfxStringItem* pItem = SfxItemSet::GetItem<SfxStringItem>(pDlg->GetOutputItemSet(), SID_CHARMAP, false);
105  const SvxFontItem* pFontItem = SfxItemSet::GetItem<SvxFontItem>(pDlg->GetOutputItemSet(), SID_ATTR_CHAR_FONT, false);
106  if ( pItem )
107  {
108  m_xNumberCharEdit->set_text(pItem->GetValue());
109 
110  if ( pFontItem )
111  {
112  m_aFontName = pFontItem->GetFamilyName();
113  m_eCharSet = pFontItem->GetCharSet();
114  vcl::Font aFont(m_aFontName, pFontItem->GetStyleName(), m_xNumberCharEdit->get_font().GetFontSize());
115  aFont.SetCharSet( pFontItem->GetCharSet() );
116  aFont.SetPitch( pFontItem->GetPitch() );
117  m_xNumberCharEdit->set_font(aFont);
118  }
119 
120  m_bExtCharAvailable = true;
121  m_xOkBtn->set_sensitive(!m_xNumberCharEdit->get_text().isEmpty());
122  }
123  }
124 }
125 
126 IMPL_LINK( SwInsFootNoteDlg, NextPrevHdl, weld::Button&, rBtn, void )
127 {
128  Apply();
129 
130  // go to the next foot/endnote here
131  m_rSh.ResetSelect(nullptr, false);
132  if (&rBtn == m_xNextBT.get())
133  m_rSh.GotoNextFootnoteAnchor();
134  else
135  m_rSh.GotoPrevFootnoteAnchor();
136 
137  Init();
138 }
139 
141  : GenericDialogController(pParent, "modules/swriter/ui/insertfootnote.ui", "InsertFootnoteDialog")
142  , m_rSh(rShell)
143  , m_eCharSet(RTL_TEXTENCODING_DONTKNOW)
144  , m_bExtCharAvailable(false)
145  , m_bEdit(bEd)
146  , m_xNumberFrame(m_xBuilder->weld_widget("numberingframe"))
147  , m_xNumberAutoBtn(m_xBuilder->weld_radio_button("automatic"))
148  , m_xNumberCharBtn(m_xBuilder->weld_radio_button("character"))
149  , m_xNumberCharEdit(m_xBuilder->weld_entry("characterentry"))
150  , m_xNumberExtChar(m_xBuilder->weld_button("choosecharacter"))
151  , m_xFootnoteBtn(m_xBuilder->weld_radio_button("footnote"))
152  , m_xEndNoteBtn(m_xBuilder->weld_radio_button("endnote"))
153  , m_xOkBtn(m_xBuilder->weld_button("ok"))
154  , m_xPrevBT(m_xBuilder->weld_button("prev"))
155  , m_xNextBT(m_xBuilder->weld_button("next"))
156 {
157  m_xNumberAutoBtn->connect_clicked(LINK(this,SwInsFootNoteDlg,NumberAutoBtnHdl));
158  m_xNumberExtChar->connect_clicked(LINK(this,SwInsFootNoteDlg,NumberExtCharHdl));
159  m_xNumberCharBtn->connect_clicked(LINK(this,SwInsFootNoteDlg,NumberCharHdl));
160  m_xNumberCharEdit->connect_changed(LINK(this,SwInsFootNoteDlg,NumberEditHdl));
161 
162  m_xPrevBT->connect_clicked(LINK(this, SwInsFootNoteDlg, NextPrevHdl));
163  m_xNextBT->connect_clicked(LINK(this, SwInsFootNoteDlg, NextPrevHdl));
164 
166 
167  if (m_bEdit)
168  {
169  Init();
170 
171  m_xPrevBT->show();
172  m_xNextBT->show();
173  }
174 }
175 
176 SwInsFootNoteDlg::~SwInsFootNoteDlg() COVERITY_NOEXCEPT_FALSE
177 {
179 
180  if (m_bEdit)
181  m_rSh.ResetSelect(nullptr, false);
182 }
183 
185 {
186  SwFormatFootnote aFootnoteNote;
187  OUString sNumStr;
188  vcl::Font aFont;
189  m_bExtCharAvailable = false;
190 
191  m_rSh.StartAction();
192 
193  if (m_rSh.GetCurFootnote(&aFootnoteNote))
194  {
195  if (!aFootnoteNote.GetNumStr().isEmpty())
196  {
197  sNumStr = aFootnoteNote.GetNumStr();
198 
199  m_rSh.Right(CRSR_SKIP_CHARS, true, 1, false );
201  m_rSh.GetCurAttr(aSet);
202  const SvxFontItem &rFont = aSet.Get( RES_CHRATR_FONT );
203  aFont = m_xNumberCharEdit->get_font();
204  m_aFontName = rFont.GetFamilyName();
205  m_eCharSet = rFont.GetCharSet();
206  aFont.SetFamilyName(m_aFontName);
207  aFont.SetCharSet(m_eCharSet);
208  m_bExtCharAvailable = true;
209  m_rSh.Left( CRSR_SKIP_CHARS, false, 1, false );
210  }
211  bFootnote = !aFootnoteNote.IsEndNote();
212  }
213  m_xNumberCharEdit->set_font(aFont);
214 
215  const bool bNumChar = !sNumStr.isEmpty();
216 
217  m_xNumberCharEdit->set_text(sNumStr);
218  m_xNumberCharBtn->set_active(bNumChar);
219  m_xNumberAutoBtn->set_active(!bNumChar);
220  if (bNumChar)
221  m_xNumberCharEdit->grab_focus();
222 
223  if (bFootnote)
224  m_xFootnoteBtn->set_active(true);
225  else
226  m_xEndNoteBtn->set_active(true);
227 
228  bool bNext = m_rSh.GotoNextFootnoteAnchor();
229 
230  if (bNext)
232 
233  bool bPrev = m_rSh.GotoPrevFootnoteAnchor();
234 
235  if (bPrev)
237 
238  m_xPrevBT->set_sensitive(bPrev);
239  m_xNextBT->set_sensitive(bNext);
240 
241  m_rSh.Right(CRSR_SKIP_CHARS, true, 1, false );
242 
243  m_rSh.EndAction();
244 }
245 
246 /* 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:71
bool GotoNextFootnoteAnchor()
Definition: trvlfnfl.cxx:333
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:234
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
constexpr TypedWhichId< SvxFontItem > RES_CHRATR_FONT(7)
std::unique_ptr< weld::RadioButton > m_xNumberCharBtn
Definition: insfnote.hxx:40
static bool bFootnote
Definition: insfnote.cxx:33
std::unique_ptr< weld::Button > m_xNumberExtChar
Definition: insfnote.hxx:42
FontFamily GetFamily() const
virtual ~SwInsFootNoteDlg() COVERITY_NOEXCEPT_FALSE override
Definition: insfnote.cxx:176
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:612
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:239
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:223
long ResetSelect(const Point *, bool)
Definition: select.cxx:332
virtual VclPtr< SfxAbstractDialog > CreateCharMapDialog(weld::Window *pParent, const SfxItemSet &rAttr, const css::uno::Reference< css::frame::XFrame > &rFrame)=0
bool GotoPrevFootnoteAnchor()
Definition: trvlfnfl.cxx:338
void StartAction()
Definition: crsrsh.cxx:222
const OUString & GetFamilyName() const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
bool SetCurFootnote(const SwFormatFootnote &rFillFootnote)
Definition: edattr.cxx:425
static void SetCareDialog(const std::shared_ptr< weld::Window > &rNew)
Definition: viewsh.cxx:2490
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:140
aStr
IMPL_LINK(SwInsFootNoteDlg, NextPrevHdl, weld::Button &, rBtn, void)
Definition: insfnote.cxx:126