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