bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / ui / misc / insfnote.cxx
blobad8327e06c15ff5cbedba86ddadcf92058815f7a
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 <sfx2/request.hxx>
24 #include <editeng/fontitem.hxx>
25 #include <vcl/msgbox.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 <crsskip.hxx>
34 #include <misc.hrc>
35 #include <globals.hrc>
36 #include <svx/svxdlg.hxx>
37 #include <svx/dialogs.hrc>
38 #include <sfx2/viewfrm.hxx>
39 #include <vcl/layout.hxx>
41 static sal_Bool bFootnote = sal_True;
43 /*------------------------------------------------------------------------
44 Description: inserting a footnote with OK
45 ------------------------------------------------------------------------*/
47 void SwInsFootNoteDlg::Apply()
49 String aStr;
51 if ( m_pNumberCharBtn->IsChecked() )
52 aStr = m_pNumberCharEdit->GetText();
54 if ( bEdit )
56 rSh.StartAction();
57 rSh.Left(CRSR_SKIP_CHARS, sal_False, 1, sal_False );
58 rSh.StartUndo( UNDO_START );
59 SwFmtFtn aNote( m_pEndNoteBtn->IsChecked() );
60 aNote.SetNumStr( aStr );
62 if( rSh.SetCurFtn( aNote ) && bExtCharAvailable )
64 rSh.Right(CRSR_SKIP_CHARS, sal_True, 1, sal_False );
65 SfxItemSet aSet( rSh.GetAttrPool(), RES_CHRATR_FONT, RES_CHRATR_FONT );
66 rSh.GetCurAttr( aSet );
67 SvxFontItem &rFont = (SvxFontItem &) aSet.Get( RES_CHRATR_FONT );
68 SvxFontItem aFont( rFont.GetFamily(), aFontName,
69 rFont.GetStyleName(), rFont.GetPitch(),
70 eCharSet, RES_CHRATR_FONT );
71 aSet.Put( aFont );
72 rSh.SetAttr( aSet, nsSetAttrMode::SETATTR_DONTEXPAND );
73 rSh.ResetSelect(0, sal_False);
74 rSh.Left(CRSR_SKIP_CHARS, sal_False, 1, sal_False );
76 rSh.EndUndo( UNDO_END );
77 rSh.EndAction();
79 else
84 bFootnote = m_pFtnBtn->IsChecked();
87 IMPL_LINK_NOARG_INLINE_START(SwInsFootNoteDlg, NumberCharHdl)
89 m_pNumberCharEdit->GrabFocus();
90 m_pOkBtn->Enable( !m_pNumberCharEdit->GetText().isEmpty() || bExtCharAvailable );
91 return 0;
93 IMPL_LINK_NOARG_INLINE_END(SwInsFootNoteDlg, NumberCharHdl)
95 IMPL_LINK_NOARG_INLINE_START(SwInsFootNoteDlg, NumberEditHdl)
97 m_pNumberCharBtn->Check( sal_True );
98 m_pOkBtn->Enable( !m_pNumberCharEdit->GetText().isEmpty() );
100 return 0;
102 IMPL_LINK_NOARG_INLINE_END(SwInsFootNoteDlg, NumberEditHdl)
104 IMPL_LINK_NOARG_INLINE_START(SwInsFootNoteDlg, NumberAutoBtnHdl)
106 m_pOkBtn->Enable( sal_True );
107 return 0;
109 IMPL_LINK_NOARG_INLINE_END(SwInsFootNoteDlg, NumberAutoBtnHdl)
111 IMPL_LINK_NOARG(SwInsFootNoteDlg, NumberExtCharHdl)
113 m_pNumberCharBtn->Check( sal_True );
115 SfxItemSet aSet( rSh.GetAttrPool(), RES_CHRATR_FONT, RES_CHRATR_FONT );
116 rSh.GetCurAttr( aSet );
117 const SvxFontItem &rFont = (SvxFontItem &) aSet.Get( RES_CHRATR_FONT );
119 SfxAllItemSet aAllSet( rSh.GetAttrPool() );
120 aAllSet.Put( SfxBoolItem( FN_PARAM_1, sal_False ) );
121 aAllSet.Put( rFont );
123 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
124 SfxAbstractDialog* pDlg = pFact->CreateSfxDialog( this, aAllSet,
125 rSh.GetView().GetViewFrame()->GetFrame().GetFrameInterface(), RID_SVXDLG_CHARMAP );
126 if (RET_OK == pDlg->Execute())
128 SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pItem, SfxStringItem, SID_CHARMAP, sal_False );
129 SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pFontItem, SvxFontItem, SID_ATTR_CHAR_FONT, sal_False );
130 if ( pItem )
132 String sExtChars(pItem->GetValue());
133 m_pNumberCharEdit->SetText( sExtChars );
135 if ( pFontItem )
137 aFontName = pFontItem->GetFamilyName();
138 eCharSet = pFontItem->GetCharSet();
139 Font aFont( aFontName, pFontItem->GetStyleName(), m_pNumberCharEdit->GetFont().GetSize() );
140 aFont.SetCharSet( pFontItem->GetCharSet() );
141 aFont.SetPitch( pFontItem->GetPitch() );
142 m_pNumberCharEdit->SetFont( aFont );
145 bExtCharAvailable = sal_True;
146 m_pOkBtn->Enable(!m_pNumberCharEdit->GetText().isEmpty());
149 delete pDlg;
151 return 0;
154 IMPL_LINK( SwInsFootNoteDlg, NextPrevHdl, Button *, pBtn )
156 Apply();
158 // go to the next foot/endnote here
159 rSh.ResetSelect(0, sal_False);
160 if (pBtn == m_pNextBT)
161 rSh.GotoNextFtnAnchor();
162 else
163 rSh.GotoPrevFtnAnchor();
165 Init();
167 return 0;
170 SwInsFootNoteDlg::SwInsFootNoteDlg(Window *pParent, SwWrtShell &rShell, sal_Bool bEd) :
171 SvxStandardDialog(pParent, "InsertFootnoteDialog", "modules/swriter/ui/insertfootnote.ui"),
172 rSh(rShell),
173 bExtCharAvailable(sal_False),
174 bEdit(bEd)
176 get(m_pNumberFrame, "numberingframe");
177 get(m_pNumberAutoBtn, "automatic");
178 get(m_pNumberCharBtn, "character");
179 get(m_pNumberCharEdit, "characterentry");
180 get(m_pNumberExtChar, "choosecharacter");
181 get(m_pFtnBtn, "footnote");
182 get(m_pEndNoteBtn, "endnote");
183 get(m_pOkBtn, "ok");
184 get(m_pPrevBT, "prev");
185 get(m_pNextBT, "next");
187 m_pNumberAutoBtn->SetClickHdl(LINK(this,SwInsFootNoteDlg,NumberAutoBtnHdl));
188 m_pNumberExtChar->SetClickHdl(LINK(this,SwInsFootNoteDlg,NumberExtCharHdl));
189 m_pNumberCharBtn->SetClickHdl(LINK(this,SwInsFootNoteDlg,NumberCharHdl));
190 m_pNumberCharEdit->SetModifyHdl(LINK(this,SwInsFootNoteDlg,NumberEditHdl));
191 m_pNumberCharEdit->SetMaxTextLen(10);
192 m_pNumberCharEdit->Enable();
194 m_pPrevBT->SetClickHdl(LINK(this, SwInsFootNoteDlg, NextPrevHdl));
195 m_pNextBT->SetClickHdl(LINK(this, SwInsFootNoteDlg, NextPrevHdl));
197 rSh.SetCareWin(this);
199 if (bEdit)
201 Init();
203 m_pPrevBT->Show();
204 m_pNextBT->Show();
208 SwInsFootNoteDlg::~SwInsFootNoteDlg()
210 rSh.SetCareWin(0);
212 if (bEdit)
213 rSh.ResetSelect(0, sal_False);
216 void SwInsFootNoteDlg::Init()
218 SwFmtFtn aFtnNote;
219 String sNumStr;
220 Font aFont;
221 bExtCharAvailable = sal_False;
223 rSh.StartAction();
225 if( rSh.GetCurFtn( &aFtnNote ))
227 if(aFtnNote.GetNumStr().Len())
229 sNumStr = aFtnNote.GetNumStr();
231 rSh.Right(CRSR_SKIP_CHARS, sal_True, 1, sal_False );
232 SfxItemSet aSet( rSh.GetAttrPool(), RES_CHRATR_FONT, RES_CHRATR_FONT );
233 rSh.GetCurAttr( aSet );
234 const SvxFontItem &rFont = (SvxFontItem &) aSet.Get( RES_CHRATR_FONT );
236 aFont = m_pNumberCharEdit->GetFont();
237 aFontName = rFont.GetFamilyName();
238 eCharSet = rFont.GetCharSet();
239 aFont.SetName(aFontName);
240 aFont.SetCharSet(eCharSet);
241 bExtCharAvailable = sal_True;
242 rSh.Left( CRSR_SKIP_CHARS, sal_False, 1, sal_False );
244 bFootnote = !aFtnNote.IsEndNote();
246 m_pNumberCharEdit->SetFont(aFont);
248 bool bNumChar = sNumStr.Len() != 0;
250 m_pNumberCharEdit->SetText(sNumStr);
251 m_pNumberCharBtn->Check(bNumChar);
252 m_pNumberAutoBtn->Check(!bNumChar);
253 if (bNumChar)
254 m_pNumberCharEdit->GrabFocus();
256 if (bFootnote)
257 m_pFtnBtn->Check();
258 else
259 m_pEndNoteBtn->Check();
261 sal_Bool bNext = rSh.GotoNextFtnAnchor();
263 if (bNext)
264 rSh.GotoPrevFtnAnchor();
266 sal_Bool bPrev = rSh.GotoPrevFtnAnchor();
268 if (bPrev)
269 rSh.GotoNextFtnAnchor();
271 m_pPrevBT->Enable(bPrev);
272 m_pNextBT->Enable(bNext);
274 rSh.Right(CRSR_SKIP_CHARS, sal_True, 1, sal_False );
276 rSh.EndAction();
279 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */