1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: insfnote.cxx,v $
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
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>
50 #include <insfnote.hxx>
51 #include <crsskip.hxx>
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()
68 if ( aNumberCharBtn
.IsChecked() )
69 aStr
= aNumberCharEdit
.GetText();
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
);
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
);
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 );
107 SvxFontItem &rFont = (SvxFontItem &) aSet.Get( RES_CHRATR_FONT );
108 SvxFontItem aFont( rFont.GetFamily(), aFontName,
109 rFont.GetStyleName(), rFont.GetPitch(),
112 rSh.SetAttr( aSet, SETATTR_DONTEXPAND );
113 // zur Bearbeitung des Fussnotentextes
114 rSh.ResetSelect(0, FALSE);
117 rSh.EndUndo( UNDO_UI_INSERT_FOOTNOTE );
121 bFootnote
= aFtnBtn
.IsChecked();
125 /*------------------------------------------------------------------------
127 ------------------------------------------------------------------------*/
129 IMPL_LINK_INLINE_START( SwInsFootNoteDlg
, NumberCharHdl
, Button
*, EMPTYARG
)
131 aNumberCharEdit
.GrabFocus();
132 aOkBtn
.Enable( aNumberCharEdit
.GetText().Len() || bExtCharAvailable
);
135 IMPL_LINK_INLINE_END( SwInsFootNoteDlg
, NumberCharHdl
, Button
*, EMPTYARG
)
137 /*------------------------------------------------------------------------
139 ------------------------------------------------------------------------*/
141 IMPL_LINK_INLINE_START( SwInsFootNoteDlg
, NumberEditHdl
, void *, EMPTYARG
)
143 aNumberCharBtn
.Check( TRUE
);
144 aOkBtn
.Enable( 0 != aNumberCharEdit
.GetText().Len() );
148 IMPL_LINK_INLINE_END( SwInsFootNoteDlg
, NumberEditHdl
, void *, EMPTYARG
)
150 /*------------------------------------------------------------------------
152 ------------------------------------------------------------------------*/
154 IMPL_LINK_INLINE_START( SwInsFootNoteDlg
, NumberAutoBtnHdl
, Button
*, EMPTYARG
)
156 aOkBtn
.Enable( TRUE
);
159 IMPL_LINK_INLINE_END( SwInsFootNoteDlg
, NumberAutoBtnHdl
, Button
*, EMPTYARG
)
161 /*------------------------------------------------------------------------
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
);
186 String
sExtChars(pItem
->GetValue());
187 aNumberCharEdit
.SetText( sExtChars
);
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());
208 /*------------------------------------------------------------------------
210 ------------------------------------------------------------------------*/
212 IMPL_LINK( SwInsFootNoteDlg
, NextPrevHdl
, Button
*, pBtn
)
216 // Hier zur naechsten Fuss/Endnote wandern
217 rSh
.ResetSelect(0, FALSE
);
218 if (pBtn
== &aNextBT
)
219 rSh
.GotoNextFtnAnchor();
221 rSh
.GotoPrevFtnAnchor();
228 /*------------------------------------------------------------------------
230 ------------------------------------------------------------------------*/
232 SwInsFootNoteDlg::SwInsFootNoteDlg(Window
*pParent
, SwWrtShell
&rShell
, BOOL bEd
) :
234 SvxStandardDialog(pParent
,SW_RES(DLG_INS_FOOTNOTE
)),
237 bExtCharAvailable(FALSE
),
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
));
266 rSh
.SetCareWin(this);
278 /*------------------------------------------------------------------------
280 ------------------------------------------------------------------------*/
282 SwInsFootNoteDlg::~SwInsFootNoteDlg()
287 rSh
.ResetSelect(0, FALSE
);
290 /*------------------------------------------------------------------------
292 ------------------------------------------------------------------------*/
294 void SwInsFootNoteDlg::Init()
299 bExtCharAvailable
= FALSE
;
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
);
332 aNumberCharEdit
.GrabFocus();
339 BOOL bNext
= rSh
.GotoNextFtnAnchor();
342 rSh
.GotoPrevFtnAnchor();
344 BOOL bPrev
= rSh
.GotoPrevFtnAnchor();
347 rSh
.GotoNextFtnAnchor();
349 aPrevBT
.Enable(bPrev
);
350 aNextBT
.Enable(bNext
);
352 rSh
.Right(CRSR_SKIP_CHARS
, TRUE
, 1, FALSE
);