update dev300-m58
[ooovba.git] / sw / source / ui / misc / insfnote.cxx
blobe0f21b11cfac58b3b4d96a1c587f382365c6434b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: insfnote.cxx,v $
10 * $Revision: 1.14 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
34 #ifdef SW_DLLIMPLEMENTATION
35 #undef SW_DLLIMPLEMENTATION
36 #endif
38 #include <hintids.hxx>
39 #include <svtools/eitem.hxx>
40 #include <svtools/stritem.hxx>
41 #include <sfx2/request.hxx>
42 #include <svx/fontitem.hxx>
43 #include <vcl/msgbox.hxx>
44 #include <fmtftn.hxx>
45 #include <swundo.hxx>
46 #include <cmdid.h>
47 #include <wrtsh.hxx>
48 #include <view.hxx>
49 #include <basesh.hxx>
50 #include <insfnote.hxx>
51 #include <crsskip.hxx>
52 #include <misc.hrc>
53 #include <insfnote.hrc>
54 #include <svx/svxdlg.hxx>
55 #include <svx/dialogs.hrc>
56 #include <sfx2/viewfrm.hxx>
58 static BOOL bFootnote = TRUE;
60 /*------------------------------------------------------------------------
61 Beschreibung: Einfuegen der Fussnote durch OK
62 ------------------------------------------------------------------------*/
64 void __EXPORT SwInsFootNoteDlg::Apply()
66 String aStr;
68 if ( aNumberCharBtn.IsChecked() )
69 aStr = aNumberCharEdit.GetText();
71 if ( bEdit )
73 rSh.StartAction();
74 rSh.Left(CRSR_SKIP_CHARS, FALSE, 1, FALSE );
75 rSh.StartUndo( UNDO_START );
76 SwFmtFtn aNote( aEndNoteBtn.IsChecked() );
77 aNote.SetNumStr( aStr );
79 if( rSh.SetCurFtn( aNote ) && bExtCharAvailable )
81 rSh.Right(CRSR_SKIP_CHARS, TRUE, 1, FALSE );
82 SfxItemSet aSet( rSh.GetAttrPool(), RES_CHRATR_FONT, RES_CHRATR_FONT );
83 rSh.GetCurAttr( aSet );
84 SvxFontItem &rFont = (SvxFontItem &) aSet.Get( RES_CHRATR_FONT );
85 SvxFontItem aFont( rFont.GetFamily(), aFontName,
86 rFont.GetStyleName(), rFont.GetPitch(),
87 eCharSet, RES_CHRATR_FONT );
88 aSet.Put( aFont );
89 rSh.SetAttr( aSet, nsSetAttrMode::SETATTR_DONTEXPAND );
90 rSh.ResetSelect(0, FALSE);
91 rSh.Left(CRSR_SKIP_CHARS, FALSE, 1, FALSE );
93 rSh.EndUndo( UNDO_END );
94 rSh.EndAction();
96 else
99 rSh.StartUndo( UNDO_UI_INSERT_FOOTNOTE );
100 rSh.InsertFootnote( aStr, aEndNoteBtn.IsChecked(), !bExtCharAvailable );
102 if ( bExtCharAvailable )
104 rSh.Left( CRSR_SKIP_CHARS, TRUE, 1, FALSE );
105 SfxItemSet aSet( rSh.GetAttrPool(), RES_CHRATR_FONT, RES_CHRATR_FONT );
106 rSh.GetAttr( aSet );
107 SvxFontItem &rFont = (SvxFontItem &) aSet.Get( RES_CHRATR_FONT );
108 SvxFontItem aFont( rFont.GetFamily(), aFontName,
109 rFont.GetStyleName(), rFont.GetPitch(),
110 eCharSet );
111 aSet.Put( aFont );
112 rSh.SetAttr( aSet, SETATTR_DONTEXPAND );
113 // zur Bearbeitung des Fussnotentextes
114 rSh.ResetSelect(0, FALSE);
115 rSh.GotoFtnTxt();
117 rSh.EndUndo( UNDO_UI_INSERT_FOOTNOTE );
121 bFootnote = aFtnBtn.IsChecked();
125 /*------------------------------------------------------------------------
126 Beschreibung:
127 ------------------------------------------------------------------------*/
129 IMPL_LINK_INLINE_START( SwInsFootNoteDlg, NumberCharHdl, Button *, EMPTYARG )
131 aNumberCharEdit.GrabFocus();
132 aOkBtn.Enable( aNumberCharEdit.GetText().Len() || bExtCharAvailable );
133 return 0;
135 IMPL_LINK_INLINE_END( SwInsFootNoteDlg, NumberCharHdl, Button *, EMPTYARG )
137 /*------------------------------------------------------------------------
138 Beschreibung:
139 ------------------------------------------------------------------------*/
141 IMPL_LINK_INLINE_START( SwInsFootNoteDlg, NumberEditHdl, void *, EMPTYARG )
143 aNumberCharBtn.Check( TRUE );
144 aOkBtn.Enable( 0 != aNumberCharEdit.GetText().Len() );
146 return 0;
148 IMPL_LINK_INLINE_END( SwInsFootNoteDlg, NumberEditHdl, void *, EMPTYARG )
150 /*------------------------------------------------------------------------
151 Beschreibung:
152 ------------------------------------------------------------------------*/
154 IMPL_LINK_INLINE_START( SwInsFootNoteDlg, NumberAutoBtnHdl, Button *, EMPTYARG )
156 aOkBtn.Enable( TRUE );
157 return 0;
159 IMPL_LINK_INLINE_END( SwInsFootNoteDlg, NumberAutoBtnHdl, Button *, EMPTYARG )
161 /*------------------------------------------------------------------------
162 Beschreibung:
163 ------------------------------------------------------------------------*/
165 IMPL_LINK( SwInsFootNoteDlg, NumberExtCharHdl, Button *, EMPTYARG )
167 aNumberCharBtn.Check( TRUE );
169 SfxItemSet aSet( rSh.GetAttrPool(), RES_CHRATR_FONT, RES_CHRATR_FONT );
170 rSh.GetCurAttr( aSet );
171 const SvxFontItem &rFont = (SvxFontItem &) aSet.Get( RES_CHRATR_FONT );
173 SfxAllItemSet aAllSet( rSh.GetAttrPool() );
174 aAllSet.Put( SfxBoolItem( FN_PARAM_1, FALSE ) );
175 aAllSet.Put( rFont );
177 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
178 SfxAbstractDialog* pDlg = pFact->CreateSfxDialog( this, aAllSet,
179 rSh.GetView().GetViewFrame()->GetFrame()->GetFrameInterface(), RID_SVXDLG_CHARMAP );
180 if (RET_OK == pDlg->Execute())
182 SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pItem, SfxStringItem, SID_CHARMAP, FALSE );
183 SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pFontItem, SvxFontItem, SID_ATTR_CHAR_FONT, FALSE );
184 if ( pItem )
186 String sExtChars(pItem->GetValue());
187 aNumberCharEdit.SetText( sExtChars );
189 if ( pFontItem )
191 aFontName = pFontItem->GetFamilyName();
192 eCharSet = pFontItem->GetCharSet();
193 Font aFont( aFontName, pFontItem->GetStyleName(), aNumberCharEdit.GetFont().GetSize() );
194 aFont.SetCharSet( pFontItem->GetCharSet() );
195 aFont.SetPitch( pFontItem->GetPitch() );
196 aNumberCharEdit.SetFont( aFont );
199 bExtCharAvailable = TRUE;
200 aOkBtn.Enable(0 != aNumberCharEdit.GetText().Len());
203 delete pDlg;
205 return 0;
208 /*------------------------------------------------------------------------
209 Beschreibung:
210 ------------------------------------------------------------------------*/
212 IMPL_LINK( SwInsFootNoteDlg, NextPrevHdl, Button *, pBtn )
214 Apply();
216 // Hier zur naechsten Fuss/Endnote wandern
217 rSh.ResetSelect(0, FALSE);
218 if (pBtn == &aNextBT)
219 rSh.GotoNextFtnAnchor();
220 else
221 rSh.GotoPrevFtnAnchor();
223 Init();
225 return 0;
228 /*------------------------------------------------------------------------
229 Beschreibung:
230 ------------------------------------------------------------------------*/
232 SwInsFootNoteDlg::SwInsFootNoteDlg(Window *pParent, SwWrtShell &rShell, BOOL bEd) :
234 SvxStandardDialog(pParent,SW_RES(DLG_INS_FOOTNOTE)),
236 rSh(rShell),
237 bExtCharAvailable(FALSE),
238 bEdit(bEd),
239 aNumberAutoBtn (this,SW_RES(RB_NUMBER_AUTO)),
240 aNumberCharBtn (this,SW_RES(RB_NUMBER_CHAR)),
241 aNumberCharEdit (this,SW_RES(ED_NUMBER_CHAR)),
242 aNumberExtChar (this,SW_RES(BT_NUMBER_CHAR)),
243 aNumberFL (this,SW_RES(FL_NUMBER)),
245 aFtnBtn (this,SW_RES(RB_TYPE_FTN)),
246 aEndNoteBtn (this,SW_RES(RB_TYPE_ENDNOTE)),
247 aTypeFL (this,SW_RES(FL_TYPE)),
249 aOkBtn (this,SW_RES(BT_OK)),
250 aCancelBtn (this,SW_RES(BT_CANCEL)),
251 aHelpBtn (this,SW_RES(BT_HELP)),
252 aPrevBT (this,SW_RES(BT_PREV)),
253 aNextBT (this,SW_RES(BT_NEXT))
255 aNumberAutoBtn.SetClickHdl(LINK(this,SwInsFootNoteDlg,NumberAutoBtnHdl));
256 aNumberExtChar.SetClickHdl(LINK(this,SwInsFootNoteDlg,NumberExtCharHdl));
257 aNumberCharBtn.SetClickHdl(LINK(this,SwInsFootNoteDlg,NumberCharHdl));
258 aNumberCharEdit.SetModifyHdl(LINK(this,SwInsFootNoteDlg,NumberEditHdl));
259 aNumberCharEdit.SetMaxTextLen(10);
260 aNumberCharEdit.Enable();
262 aPrevBT.SetClickHdl(LINK(this, SwInsFootNoteDlg, NextPrevHdl));
263 aNextBT.SetClickHdl(LINK(this, SwInsFootNoteDlg, NextPrevHdl));
265 FreeResource();
266 rSh.SetCareWin(this);
268 if (bEdit)
270 Init();
272 aPrevBT.Show();
273 aNextBT.Show();
278 /*------------------------------------------------------------------------
279 Beschreibung:
280 ------------------------------------------------------------------------*/
282 SwInsFootNoteDlg::~SwInsFootNoteDlg()
284 rSh.SetCareWin(0);
286 if (bEdit)
287 rSh.ResetSelect(0, FALSE);
290 /*------------------------------------------------------------------------
291 Beschreibung:
292 ------------------------------------------------------------------------*/
294 void SwInsFootNoteDlg::Init()
296 SwFmtFtn aFtnNote;
297 String sNumStr;
298 Font aFont;
299 bExtCharAvailable = FALSE;
301 rSh.StartAction();
303 if( rSh.GetCurFtn( &aFtnNote ))
305 if(aFtnNote.GetNumStr().Len())
307 sNumStr = aFtnNote.GetNumStr();
309 rSh.Right(CRSR_SKIP_CHARS, TRUE, 1, FALSE );
310 SfxItemSet aSet( rSh.GetAttrPool(), RES_CHRATR_FONT, RES_CHRATR_FONT );
311 rSh.GetCurAttr( aSet );
312 const SvxFontItem &rFont = (SvxFontItem &) aSet.Get( RES_CHRATR_FONT );
314 aFont = aNumberCharEdit.GetFont();
315 aFontName = rFont.GetFamilyName();
316 eCharSet = rFont.GetCharSet();
317 aFont.SetName(aFontName);
318 aFont.SetCharSet(eCharSet);
319 bExtCharAvailable = TRUE;
320 rSh.Left( CRSR_SKIP_CHARS, FALSE, 1, FALSE );
322 bFootnote = !aFtnNote.IsEndNote();
324 aNumberCharEdit.SetFont(aFont);
326 BOOL bNumChar = sNumStr.Len() != 0;
328 aNumberCharEdit.SetText(sNumStr);
329 aNumberCharBtn.Check(bNumChar);
330 aNumberAutoBtn.Check(!bNumChar);
331 if (bNumChar)
332 aNumberCharEdit.GrabFocus();
334 if (bFootnote)
335 aFtnBtn.Check();
336 else
337 aEndNoteBtn.Check();
339 BOOL bNext = rSh.GotoNextFtnAnchor();
341 if (bNext)
342 rSh.GotoPrevFtnAnchor();
344 BOOL bPrev = rSh.GotoPrevFtnAnchor();
346 if (bPrev)
347 rSh.GotoNextFtnAnchor();
349 aPrevBT.Enable(bPrev);
350 aNextBT.Enable(bNext);
352 rSh.Right(CRSR_SKIP_CHARS, TRUE, 1, FALSE );
354 rSh.EndAction();