xref: /trunk/main/sw/source/ui/misc/insfnote.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 #ifdef SW_DLLIMPLEMENTATION
32 #undef SW_DLLIMPLEMENTATION
33 #endif
34 
35 #include <hintids.hxx>
36 #include <svl/eitem.hxx>
37 #include <svl/stritem.hxx>
38 #include <sfx2/request.hxx>
39 #include <editeng/fontitem.hxx>
40 #include <vcl/msgbox.hxx>
41 #include <fmtftn.hxx>
42 #include <swundo.hxx>
43 #include <cmdid.h>
44 #include <wrtsh.hxx>
45 #include <view.hxx>
46 #include <basesh.hxx>
47 #include <insfnote.hxx>
48 #include <crsskip.hxx>
49 #include <misc.hrc>
50 #include <insfnote.hrc>
51 #include <svx/svxdlg.hxx>
52 #include <svx/dialogs.hrc>
53 #include <sfx2/viewfrm.hxx>
54 
55 static sal_Bool bFootnote = sal_True;
56 
57 /*------------------------------------------------------------------------
58  Beschreibung:  Einfuegen der Fussnote durch OK
59 ------------------------------------------------------------------------*/
60 
61 void __EXPORT SwInsFootNoteDlg::Apply()
62 {
63     String aStr;
64 
65     if ( aNumberCharBtn.IsChecked() )
66         aStr = aNumberCharEdit.GetText();
67 
68     if ( bEdit )
69     {
70         rSh.StartAction();
71         rSh.Left(CRSR_SKIP_CHARS, sal_False, 1, sal_False );
72         rSh.StartUndo( UNDO_START );
73         SwFmtFtn aNote( aEndNoteBtn.IsChecked() );
74         aNote.SetNumStr( aStr );
75 
76         if( rSh.SetCurFtn( aNote ) && bExtCharAvailable )
77         {
78             rSh.Right(CRSR_SKIP_CHARS, sal_True, 1, sal_False );
79             SfxItemSet aSet( rSh.GetAttrPool(), RES_CHRATR_FONT, RES_CHRATR_FONT );
80             rSh.GetCurAttr( aSet );
81             SvxFontItem &rFont = (SvxFontItem &) aSet.Get( RES_CHRATR_FONT );
82             SvxFontItem aFont( rFont.GetFamily(), aFontName,
83                                rFont.GetStyleName(), rFont.GetPitch(),
84                                eCharSet, RES_CHRATR_FONT );
85             aSet.Put( aFont );
86             rSh.SetAttr( aSet, nsSetAttrMode::SETATTR_DONTEXPAND );
87             rSh.ResetSelect(0, sal_False);
88             rSh.Left(CRSR_SKIP_CHARS, sal_False, 1, sal_False );
89         }
90         rSh.EndUndo( UNDO_END );
91         rSh.EndAction();
92     }
93     else
94     {
95 /*
96         rSh.StartUndo( UNDO_UI_INSERT_FOOTNOTE );
97         rSh.InsertFootnote( aStr, aEndNoteBtn.IsChecked(), !bExtCharAvailable );
98 
99         if ( bExtCharAvailable )
100         {
101             rSh.Left( CRSR_SKIP_CHARS, sal_True, 1, sal_False );
102             SfxItemSet aSet( rSh.GetAttrPool(), RES_CHRATR_FONT, RES_CHRATR_FONT );
103             rSh.GetAttr( aSet );
104             SvxFontItem &rFont = (SvxFontItem &) aSet.Get( RES_CHRATR_FONT );
105             SvxFontItem aFont( rFont.GetFamily(), aFontName,
106                                rFont.GetStyleName(), rFont.GetPitch(),
107                                eCharSet );
108             aSet.Put( aFont );
109             rSh.SetAttr( aSet, SETATTR_DONTEXPAND );
110             // zur Bearbeitung des Fussnotentextes
111             rSh.ResetSelect(0, sal_False);
112             rSh.GotoFtnTxt();
113         }
114         rSh.EndUndo( UNDO_UI_INSERT_FOOTNOTE );
115 */
116     }
117 
118     bFootnote = aFtnBtn.IsChecked();
119 }
120 
121 
122 /*------------------------------------------------------------------------
123     Beschreibung:
124 ------------------------------------------------------------------------*/
125 
126 IMPL_LINK_INLINE_START( SwInsFootNoteDlg, NumberCharHdl, Button *, EMPTYARG )
127 {
128     aNumberCharEdit.GrabFocus();
129     aOkBtn.Enable( aNumberCharEdit.GetText().Len() || bExtCharAvailable );
130     return 0;
131 }
132 IMPL_LINK_INLINE_END( SwInsFootNoteDlg, NumberCharHdl, Button *, EMPTYARG )
133 
134 /*------------------------------------------------------------------------
135     Beschreibung:
136 ------------------------------------------------------------------------*/
137 
138 IMPL_LINK_INLINE_START( SwInsFootNoteDlg, NumberEditHdl, void *, EMPTYARG )
139 {
140     aNumberCharBtn.Check( sal_True );
141     aOkBtn.Enable( 0 != aNumberCharEdit.GetText().Len() );
142 
143     return 0;
144 }
145 IMPL_LINK_INLINE_END( SwInsFootNoteDlg, NumberEditHdl, void *, EMPTYARG )
146 
147 /*------------------------------------------------------------------------
148     Beschreibung:
149 ------------------------------------------------------------------------*/
150 
151 IMPL_LINK_INLINE_START( SwInsFootNoteDlg, NumberAutoBtnHdl, Button *, EMPTYARG )
152 {
153     aOkBtn.Enable( sal_True );
154     return 0;
155 }
156 IMPL_LINK_INLINE_END( SwInsFootNoteDlg, NumberAutoBtnHdl, Button *, EMPTYARG )
157 
158 /*------------------------------------------------------------------------
159     Beschreibung:
160 ------------------------------------------------------------------------*/
161 
162 IMPL_LINK( SwInsFootNoteDlg, NumberExtCharHdl, Button *, EMPTYARG )
163 {
164     aNumberCharBtn.Check( sal_True );
165 
166     SfxItemSet aSet( rSh.GetAttrPool(), RES_CHRATR_FONT, RES_CHRATR_FONT );
167     rSh.GetCurAttr( aSet );
168     const SvxFontItem &rFont = (SvxFontItem &) aSet.Get( RES_CHRATR_FONT );
169 
170     SfxAllItemSet aAllSet( rSh.GetAttrPool() );
171     aAllSet.Put( SfxBoolItem( FN_PARAM_1, sal_False ) );
172     aAllSet.Put( rFont );
173 
174     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
175     SfxAbstractDialog* pDlg = pFact->CreateSfxDialog( this, aAllSet,
176         rSh.GetView().GetViewFrame()->GetFrame().GetFrameInterface(), RID_SVXDLG_CHARMAP );
177     if (RET_OK == pDlg->Execute())
178     {
179         SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pItem, SfxStringItem, SID_CHARMAP, sal_False );
180         SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pFontItem, SvxFontItem, SID_ATTR_CHAR_FONT, sal_False );
181         if ( pItem )
182         {
183             String sExtChars(pItem->GetValue());
184             aNumberCharEdit.SetText( sExtChars );
185 
186             if ( pFontItem )
187             {
188                 aFontName = pFontItem->GetFamilyName();
189                 eCharSet  = pFontItem->GetCharSet();
190                 Font aFont( aFontName, pFontItem->GetStyleName(), aNumberCharEdit.GetFont().GetSize() );
191                 aFont.SetCharSet( pFontItem->GetCharSet() );
192                 aFont.SetPitch( pFontItem->GetPitch() );
193                 aNumberCharEdit.SetFont( aFont  );
194             }
195 
196             bExtCharAvailable = sal_True;
197             aOkBtn.Enable(0 != aNumberCharEdit.GetText().Len());
198         }
199     }
200     delete pDlg;
201 
202     return 0;
203 }
204 
205 /*------------------------------------------------------------------------
206     Beschreibung:
207 ------------------------------------------------------------------------*/
208 
209 IMPL_LINK( SwInsFootNoteDlg, NextPrevHdl, Button *, pBtn )
210 {
211     Apply();
212 
213     // Hier zur naechsten Fuss/Endnote wandern
214     rSh.ResetSelect(0, sal_False);
215     if (pBtn == &aNextBT)
216         rSh.GotoNextFtnAnchor();
217     else
218         rSh.GotoPrevFtnAnchor();
219 
220     Init();
221 
222     return 0;
223 }
224 
225 /*------------------------------------------------------------------------
226     Beschreibung:
227 ------------------------------------------------------------------------*/
228 
229 SwInsFootNoteDlg::SwInsFootNoteDlg(Window *pParent, SwWrtShell &rShell, sal_Bool bEd) :
230 
231     SvxStandardDialog(pParent,SW_RES(DLG_INS_FOOTNOTE)),
232 
233     rSh(rShell),
234     bExtCharAvailable(sal_False),
235     bEdit(bEd),
236     aNumberFL      (this,SW_RES(FL_NUMBER)),
237     aNumberAutoBtn  (this,SW_RES(RB_NUMBER_AUTO)),
238     aNumberCharBtn  (this,SW_RES(RB_NUMBER_CHAR)),
239     aNumberCharEdit (this,SW_RES(ED_NUMBER_CHAR)),
240     aNumberExtChar  (this,SW_RES(BT_NUMBER_CHAR)),
241 
242     aTypeFL        (this,SW_RES(FL_TYPE)),
243     aFtnBtn         (this,SW_RES(RB_TYPE_FTN)),
244     aEndNoteBtn     (this,SW_RES(RB_TYPE_ENDNOTE)),
245 
246     aOkBtn          (this,SW_RES(BT_OK)),
247     aCancelBtn      (this,SW_RES(BT_CANCEL)),
248     aHelpBtn        (this,SW_RES(BT_HELP)),
249     aPrevBT         (this,SW_RES(BT_PREV)),
250     aNextBT         (this,SW_RES(BT_NEXT))
251 {
252     aNumberCharEdit.SetAccessibleName(String(SW_RES(STR_CHAR)));
253     aNumberExtChar.SetAccessibleRelationMemberOf(&aNumberFL);
254     aNumberCharEdit.SetAccessibleRelationLabeledBy(&aNumberCharBtn);
255 
256     aNumberAutoBtn.SetClickHdl(LINK(this,SwInsFootNoteDlg,NumberAutoBtnHdl));
257     aNumberExtChar.SetClickHdl(LINK(this,SwInsFootNoteDlg,NumberExtCharHdl));
258     aNumberCharBtn.SetClickHdl(LINK(this,SwInsFootNoteDlg,NumberCharHdl));
259     aNumberCharEdit.SetModifyHdl(LINK(this,SwInsFootNoteDlg,NumberEditHdl));
260     aNumberCharEdit.SetMaxTextLen(10);
261     aNumberCharEdit.Enable();
262 
263     aPrevBT.SetClickHdl(LINK(this, SwInsFootNoteDlg, NextPrevHdl));
264     aNextBT.SetClickHdl(LINK(this, SwInsFootNoteDlg, NextPrevHdl));
265 
266     FreeResource();
267     rSh.SetCareWin(this);
268 
269     if (bEdit)
270     {
271         Init();
272 
273         aPrevBT.Show();
274         aNextBT.Show();
275     }
276 }
277 
278 
279 /*------------------------------------------------------------------------
280     Beschreibung:
281 ------------------------------------------------------------------------*/
282 
283 SwInsFootNoteDlg::~SwInsFootNoteDlg()
284 {
285     rSh.SetCareWin(0);
286 
287     if (bEdit)
288         rSh.ResetSelect(0, sal_False);
289 }
290 
291 /*------------------------------------------------------------------------
292     Beschreibung:
293 ------------------------------------------------------------------------*/
294 
295 void SwInsFootNoteDlg::Init()
296 {
297     SwFmtFtn aFtnNote;
298     String sNumStr;
299     Font aFont;
300     bExtCharAvailable = sal_False;
301 
302     rSh.StartAction();
303 
304     if( rSh.GetCurFtn( &aFtnNote ))
305     {
306         if(aFtnNote.GetNumStr().Len())
307         {
308             sNumStr = aFtnNote.GetNumStr();
309 
310             rSh.Right(CRSR_SKIP_CHARS, sal_True, 1, sal_False );
311             SfxItemSet aSet( rSh.GetAttrPool(), RES_CHRATR_FONT, RES_CHRATR_FONT );
312             rSh.GetCurAttr( aSet );
313             const SvxFontItem &rFont = (SvxFontItem &) aSet.Get( RES_CHRATR_FONT );
314 
315             aFont = aNumberCharEdit.GetFont();
316             aFontName = rFont.GetFamilyName();
317             eCharSet = rFont.GetCharSet();
318             aFont.SetName(aFontName);
319             aFont.SetCharSet(eCharSet);
320             bExtCharAvailable = sal_True;
321             rSh.Left( CRSR_SKIP_CHARS, sal_False, 1, sal_False );
322         }
323         bFootnote = !aFtnNote.IsEndNote();
324     }
325     aNumberCharEdit.SetFont(aFont);
326 
327     sal_Bool bNumChar = sNumStr.Len() != 0;
328 
329     aNumberCharEdit.SetText(sNumStr);
330     aNumberCharBtn.Check(bNumChar);
331     aNumberAutoBtn.Check(!bNumChar);
332     if (bNumChar)
333         aNumberCharEdit.GrabFocus();
334 
335     if (bFootnote)
336         aFtnBtn.Check();
337     else
338         aEndNoteBtn.Check();
339 
340     sal_Bool bNext = rSh.GotoNextFtnAnchor();
341 
342     if (bNext)
343         rSh.GotoPrevFtnAnchor();
344 
345     sal_Bool bPrev = rSh.GotoPrevFtnAnchor();
346 
347     if (bPrev)
348         rSh.GotoNextFtnAnchor();
349 
350     aPrevBT.Enable(bPrev);
351     aNextBT.Enable(bNext);
352 
353     rSh.Right(CRSR_SKIP_CHARS, sal_True, 1, sal_False );
354 
355     rSh.EndAction();
356 }
357 
358