xref: /aoo42x/main/formula/source/ui/dlg/funcutl.cxx (revision c25918c1)
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_formula.hxx"
26 
27 //----------------------------------------------------------------------------
28 #include <vcl/sound.hxx>
29 #include <vcl/svapp.hxx>
30 #include <vcl/scrbar.hxx>
31 
32 #include "formula/funcutl.hxx"
33 #include "formula/IControlReferenceHandler.hxx"
34 #include "ControlHelper.hxx"
35 #include "ModuleHelper.hxx"
36 #include "ForResId.hrc"
37 
38 
39 namespace formula
40 {
41 //============================================================================
42 // class ValWnd
43 //----------------------------------------------------------------------------
44 
45 ValWnd::ValWnd( Window* pParent, const ResId& rId ) : Window( pParent, rId )
46 {
47 	Font aFnt( GetFont() );
48 	aFnt.SetTransparent( sal_True );
49 	aFnt.SetWeight( WEIGHT_LIGHT );
50 	if ( pParent->IsBackground() )
51 	{
52 		Wallpaper aBack = pParent->GetBackground();
53 		SetFillColor( aBack.GetColor() );
54 		SetBackground( aBack );
55 		aFnt.SetFillColor( aBack.GetColor() );
56 	}
57 	else
58 	{
59 		SetFillColor();
60 		SetBackground();
61 	}
62 	SetFont( aFnt );
63 	SetLineColor();
64 
65 	Size aSzWnd  = GetOutputSizePixel();
66 	long nHeight = GetTextHeight();
67 	long nDiff   = aSzWnd.Height()-nHeight;
68 
69 	aRectOut = Rectangle( Point( 1, ( nDiff<2 ) ? 1 : nDiff/2),
70 						  Size ( aSzWnd.Width()-2, nHeight ) );
71 	SetClipRegion( Region( aRectOut ) );
72 }
73 
74 //----------------------------------------------------------------------------
75 
76 void __EXPORT ValWnd::Paint( const Rectangle& )
77 {
78 	DrawText( aRectOut.TopLeft(), aStrValue );
79 }
80 
81 //----------------------------------------------------------------------------
82 
83 void ValWnd::SetValue( const String& rStrVal )
84 {
85 	if ( aStrValue != rStrVal )
86 	{
87 		aStrValue = rStrVal;
88 		DrawRect( aRectOut );	// alten Text loeschen
89 		Paint( aRectOut );		// und neu malen
90 	}
91 }
92 
93 //============================================================================
94 // class ArgEdit
95 //----------------------------------------------------------------------------
96 
97 ArgEdit::ArgEdit( Window* pParent, const ResId& rResId )
98 	:	RefEdit( pParent, rResId ),
99 		pEdPrev	( NULL ),
100 		pEdNext	( NULL ),
101 		pSlider	( NULL ),
102 		nArgs	( 0 )
103 {
104 }
105 
106 //----------------------------------------------------------------------------
107 
108 void ArgEdit::Init( ArgEdit* pPrevEdit, ArgEdit* pNextEdit,
109 					ScrollBar& rArgSlider, sal_uInt16 nArgCount )
110 {
111 	pEdPrev	= pPrevEdit;
112 	pEdNext	= pNextEdit;
113 	pSlider = &rArgSlider;
114 	nArgs	= nArgCount;
115 }
116 
117 //----------------------------------------------------------------------------
118 
119 // Cursorsteuerung fuer EditFelder im Argument-Dialog
120 
121 void __EXPORT ArgEdit::KeyInput( const KeyEvent& rKEvt )
122 {
123 	KeyCode		aCode	= rKEvt.GetKeyCode();
124 	sal_Bool		bUp		= (aCode.GetCode() == KEY_UP);
125 	sal_Bool		bDown	= (aCode.GetCode() == KEY_DOWN);
126 	ArgEdit*	pEd		= NULL;
127 
128 	if (   pSlider
129 		&& ( !aCode.IsShift() && !aCode.IsMod1() && !aCode.IsMod2() )
130 		&& ( bUp || bDown ) )
131 	{
132 		if ( nArgs > 1 )
133 		{
134 			long	nThumb		 = pSlider->GetThumbPos();
135 			sal_Bool	bDoScroll	 = sal_False;
136 			sal_Bool	bChangeFocus = sal_False;
137 
138 			if ( bDown )
139 			{
140 				if ( nArgs > 4 )
141 				{
142 					if ( !pEdNext )
143 					{
144 						nThumb++;
145 						bDoScroll = ( nThumb+3 < (long)nArgs );
146 					}
147 					else
148 					{
149 						pEd = pEdNext;
150 						bChangeFocus = sal_True;
151 					}
152 				}
153 				else if ( pEdNext )
154 				{
155 					pEd = pEdNext;
156 					bChangeFocus = sal_True;
157 				}
158 			}
159 			else // if ( bUp )
160 			{
161 				if ( nArgs > 4 )
162 				{
163 					if ( !pEdPrev )
164 					{
165 						nThumb--;
166 						bDoScroll = ( nThumb >= 0 );
167 					}
168 					else
169 					{
170 						pEd = pEdPrev;
171 						bChangeFocus = sal_True;
172 					}
173 				}
174 				else if ( pEdPrev )
175 				{
176 					pEd = pEdPrev;
177 					bChangeFocus = sal_True;
178 				}
179 			}
180 
181 			if ( bDoScroll )
182 			{
183 				pSlider->SetThumbPos( nThumb );
184 				((Link&)pSlider->GetEndScrollHdl()).Call( pSlider );
185 			}
186 			else if ( bChangeFocus )
187 			{
188 				pEd->GrabFocus();
189 			}
190 			else
191 				Sound::Beep();
192 		}
193 		else
194 			Sound::Beep();
195 	}
196 	else
197         RefEdit::KeyInput( rKEvt );
198 }
199 
200 
201 
202 
203 /*************************************************************************
204 #*	Member:		ArgInput									Datum:13.01.97
205 #*------------------------------------------------------------------------
206 #*
207 #*  Klasse:		ArgInput
208 #*
209 #*  Funktion:	Konstruktor der Klasse ArgInput
210 #*
211 #*  Input:		---
212 #*
213 #*	Output:		---
214 #*
215 #************************************************************************/
216 
217 ArgInput::ArgInput()
218 {
219 	pFtArg=NULL;
220 	pBtnFx=NULL;
221 	pEdArg=NULL;
222 	pRefBtn=NULL;
223 }
224 
225 /*************************************************************************
226 #*	Member:		InitArgInput								Datum:13.01.97
227 #*------------------------------------------------------------------------
228 #*
229 #*  Klasse:		ArgInput
230 #*
231 #*  Funktion:	Initialisiert die Pointer der Klasse
232 #*
233 #*  Input:		---
234 #*
235 #*	Output:		---
236 #*
237 #************************************************************************/
238 
239 void ArgInput::InitArgInput(FixedText*		pftArg,
240 							ImageButton*	pbtnFx,
241 							ArgEdit*		pedArg,
242 							RefButton*	prefBtn)
243 {
244 	pFtArg =pftArg;
245 	pBtnFx =pbtnFx;
246 	pEdArg =pedArg;
247 	pRefBtn=prefBtn;
248 
249 	if(pBtnFx!=NULL)
250 	{
251 		pBtnFx->SetClickHdl   ( LINK( this, ArgInput, FxBtnClickHdl ) );
252 		pBtnFx->SetGetFocusHdl( LINK( this, ArgInput, FxBtnFocusHdl ) );
253 	}
254 	if(pRefBtn!=NULL)
255 	{
256 		pRefBtn->SetClickHdl   ( LINK( this, ArgInput, RefBtnClickHdl ) );
257 		pRefBtn->SetGetFocusHdl( LINK( this, ArgInput, RefBtnFocusHdl ) );
258 	}
259 	if(pEdArg!=NULL)
260 	{
261 		pEdArg->SetGetFocusHdl ( LINK( this, ArgInput, EdFocusHdl ) );
262 		pEdArg->SetModifyHdl   ( LINK( this, ArgInput, EdModifyHdl ) );
263 	}
264 
265 }
266 
267 /*************************************************************************
268 #*	Member:		SetArgName									Datum:13.01.97
269 #*------------------------------------------------------------------------
270 #*
271 #*  Klasse:		ArgInput
272 #*
273 #*  Funktion:	Setzt den Namen fuer das Argument
274 #*
275 #*  Input:		String
276 #*
277 #*	Output:		---
278 #*
279 #************************************************************************/
280 void ArgInput::SetArgName(const String &aArg)
281 {
282 	if(pFtArg !=NULL) pFtArg->SetText(aArg );
283 }
284 
285 /*************************************************************************
286 #*	Member:		GetArgName									Datum:06.02.97
287 #*------------------------------------------------------------------------
288 #*
289 #*  Klasse:		ArgInput
290 #*
291 #*  Funktion:	Liefert den Namen fuer das Argument zurueck
292 #*
293 #*  Input:		String
294 #*
295 #*	Output:		---
296 #*
297 #************************************************************************/
298 String ArgInput::GetArgName()
299 {
300 	String aPrivArgName;
301 	if(pFtArg !=NULL)
302 		aPrivArgName=pFtArg->GetText();
303 
304 	return aPrivArgName;
305 }
306 
307 
308 /*************************************************************************
309 #*	Member:		SetArgName									Datum:13.01.97
310 #*------------------------------------------------------------------------
311 #*
312 #*  Klasse:		ArgInput
313 #*
314 #*  Funktion:	Setzt den Namen fuer das Argument
315 #*
316 #*  Input:		String
317 #*
318 #*	Output:		---
319 #*
320 #************************************************************************/
321 void ArgInput::SetArgNameFont	(const Font &aFont)
322 {
323 	if(pFtArg !=NULL) pFtArg->SetFont(aFont);
324 }
325 
326 /*************************************************************************
327 #*	Member:		SetArgSelection								Datum:13.01.97
328 #*------------------------------------------------------------------------
329 #*
330 #*  Klasse:		ArgInput
331 #*
332 #*  Funktion:	Stellt die Selection fuer die EditBox ein.
333 #*
334 #*  Input:		String
335 #*
336 #*	Output:		---
337 #*
338 #************************************************************************/
339 void ArgInput::SetArgSelection	(const Selection& rSel )
340 {
341 	if(pEdArg !=NULL) pEdArg ->SetSelection(rSel );
342 }
343 
344 /*************************************************************************
345 #*	Member:		SetArgSelection								Datum:13.01.97
346 #*------------------------------------------------------------------------
347 #*
348 #*  Klasse:		ArgInput
349 #*
350 #*  Funktion:	Liefert die Selection fuer die EditBox zurueck.
351 #*
352 #*  Input:		String
353 #*
354 #*	Output:		---
355 #*
356 #************************************************************************/
357 Selection ArgInput::GetArgSelection	()
358 {
359 	Selection	aSel;
360 	if(pEdArg !=NULL) aSel=pEdArg ->GetSelection();
361 	return aSel;
362 }
363 
364 /*************************************************************************
365 #*	Member:		SetArgSelection								Datum:13.01.97
366 #*------------------------------------------------------------------------
367 #*
368 #*  Klasse:		ArgInput
369 #*
370 #*  Funktion:	Ersetzt die Selection in der EditBox.
371 #*
372 #*  Input:		String
373 #*
374 #*	Output:		---
375 #*
376 #************************************************************************/
377 void ArgInput::ReplaceSelOfArg(const String& rStr )
378 {
379 	if(pEdArg !=NULL) pEdArg ->ReplaceSelected(rStr );
380 }
381 
382 
383 
384 /*************************************************************************
385 #*	Member:		SetArgVal									Datum:13.01.97
386 #*------------------------------------------------------------------------
387 #*
388 #*  Klasse:		ArgInput
389 #*
390 #*  Funktion:	Setzt den Wert fuer das Argument
391 #*
392 #*  Input:		String
393 #*
394 #*	Output:		---
395 #*
396 #************************************************************************/
397 void ArgInput::SetArgVal(const String &aVal)
398 {
399 	if(pEdArg !=NULL)
400 	{
401 		pEdArg ->SetRefString(aVal );
402 	}
403 }
404 
405 /*************************************************************************
406 #*	Member:		SetArgName									Datum:13.01.97
407 #*------------------------------------------------------------------------
408 #*
409 #*  Klasse:		ArgInput
410 #*
411 #*  Funktion:	Liefert den Wert fuer das Argument
412 #*
413 #*  Input:		---
414 #*
415 #*	Output:		String
416 #*
417 #************************************************************************/
418 String ArgInput::GetArgVal()
419 {
420 	String aResult;
421 	if(pEdArg!=NULL)
422 	{
423 		aResult=pEdArg->GetText();
424 	}
425 	return aResult;
426 }
427 
428 /*************************************************************************
429 #*	Member:		SetArgName									Datum:13.01.97
430 #*------------------------------------------------------------------------
431 #*
432 #*  Klasse:		ArgInput
433 #*
434 #*  Funktion:	Versteckt die Controls
435 #*
436 #*  Input:		---
437 #*
438 #*	Output:		---
439 #*
440 #************************************************************************/
441 void ArgInput::Hide()
442 {
443 	if ( pFtArg && pBtnFx && pEdArg && pRefBtn)
444 	{
445 		pFtArg->Hide();
446 		pBtnFx->Hide();
447 		pEdArg->Hide();
448 		pRefBtn->Hide();
449 	}
450 }
451 
452 /*************************************************************************
453 #*	Member:		SetArgName									Datum:13.01.97
454 #*------------------------------------------------------------------------
455 #*
456 #*  Klasse:		ArgInput
457 #*
458 #*  Funktion:	Zaubert die Controls wieder hervor.
459 #*
460 #*  Input:		---
461 #*
462 #*	Output:		---
463 #*
464 #************************************************************************/
465 void ArgInput::Show()
466 {
467 	if ( pFtArg && pBtnFx && pEdArg && pRefBtn)
468 	{
469 		pFtArg->Show();
470 		pBtnFx->Show();
471 		pEdArg->Show();
472 		pRefBtn->Show();
473 	}
474 }
475 
476 /*************************************************************************
477 #*	Member:		FxClick										Datum:13.01.97
478 #*------------------------------------------------------------------------
479 #*
480 #*  Klasse:		ArgInput
481 #*
482 #*  Funktion:	Gibt den Event weiter.
483 #*
484 #*  Input:		---
485 #*
486 #*	Output:		---
487 #*
488 #************************************************************************/
489 void ArgInput::FxClick()
490 {
491 	aFxClickLink.Call(this);
492 }
493 
494 /*************************************************************************
495 #*	Member:		RefClick									Datum:13.01.97
496 #*------------------------------------------------------------------------
497 #*
498 #*  Klasse:		ArgInput
499 #*
500 #*  Funktion:	Gibt den Event weiter.
501 #*
502 #*  Input:		---
503 #*
504 #*	Output:		---
505 #*
506 #************************************************************************/
507 void ArgInput::RefClick()
508 {
509 	aRefClickLink.Call(this);
510 }
511 
512 /*************************************************************************
513 #*	Member:		FxFocus										Datum:13.01.97
514 #*------------------------------------------------------------------------
515 #*
516 #*  Klasse:		ArgInput
517 #*
518 #*  Funktion:	Gibt den Event weiter.
519 #*
520 #*  Input:		---
521 #*
522 #*	Output:		---
523 #*
524 #************************************************************************/
525 void ArgInput::FxFocus()
526 {
527 	aFxFocusLink.Call(this);
528 }
529 
530 /*************************************************************************
531 #*	Member:		RefFocus									Datum:13.01.97
532 #*------------------------------------------------------------------------
533 #*
534 #*  Klasse:		ArgInput
535 #*
536 #*  Funktion:	Gibt den Event weiter.
537 #*
538 #*  Input:		---
539 #*
540 #*	Output:		---
541 #*
542 #************************************************************************/
543 void ArgInput::RefFocus()
544 {
545 	aRefFocusLink.Call(this);
546 }
547 
548 /*************************************************************************
549 #*	Member:		EdFocus										Datum:13.01.97
550 #*------------------------------------------------------------------------
551 #*
552 #*  Klasse:		ArgInput
553 #*
554 #*  Funktion:	Gibt den Event weiter.
555 #*
556 #*  Input:		---
557 #*
558 #*	Output:		---
559 #*
560 #************************************************************************/
561 void ArgInput::EdFocus()
562 {
563 	aEdFocusLink.Call(this);
564 }
565 
566 /*************************************************************************
567 #*	Member:		EdModify									Datum:13.01.97
568 #*------------------------------------------------------------------------
569 #*
570 #*  Klasse:		ArgInput
571 #*
572 #*  Funktion:	Gibt den Event weiter.
573 #*
574 #*  Input:		---
575 #*
576 #*	Output:		---
577 #*
578 #************************************************************************/
579 void ArgInput::EdModify()
580 {
581 	aEdModifyLink.Call(this);
582 }
583 
584 /*************************************************************************
585 #*	Handle:		FxBtnHdl									Datum:13.01.97
586 #*------------------------------------------------------------------------
587 #*
588 #*  Klasse:		ArgInput
589 #*
590 #*  Funktion:	Handle fuer Fx-Button Click-Event.
591 #*
592 #*  Input:		---
593 #*
594 #*	Output:		---
595 #*
596 #************************************************************************/
597 IMPL_LINK( ArgInput, FxBtnClickHdl, ImageButton*, pBtn )
598 {
599 	if(pBtn==pBtnFx) FxClick();
600 
601 	return 0;
602 }
603 
604 /*************************************************************************
605 #*	Handle:		RefBtnClickHdl								Datum:13.01.97
606 #*------------------------------------------------------------------------
607 #*
608 #*  Klasse:		ArgInput
609 #*
610 #*  Funktion:	Handle fuer Fx-Button Click-Event.
611 #*
612 #*  Input:		---
613 #*
614 #*	Output:		---
615 #*
616 #************************************************************************/
617 IMPL_LINK( ArgInput, RefBtnClickHdl,RefButton*, pBtn )
618 {
619 	if(pRefBtn==pBtn) RefClick();
620 
621 	return 0;
622 }
623 
624 /*************************************************************************
625 #*	Handle:		FxBtnFocusHdl								Datum:13.01.97
626 #*------------------------------------------------------------------------
627 #*
628 #*  Klasse:		ArgInput
629 #*
630 #*  Funktion:	Handle fuer Fx-Button Focus-Event.
631 #*
632 #*  Input:		---
633 #*
634 #*	Output:		---
635 #*
636 #************************************************************************/
637 IMPL_LINK( ArgInput, FxBtnFocusHdl, ImageButton*, pBtn )
638 {
639 	if(pBtn==pBtnFx) FxFocus();
640 
641 	return 0;
642 }
643 
644 /*************************************************************************
645 #*	Handle:		RefBtnFocusHdl								Datum:13.01.97
646 #*------------------------------------------------------------------------
647 #*
648 #*  Klasse:		ArgInput
649 #*
650 #*  Funktion:	Handle fuer Fx-Button Focus-Event.
651 #*
652 #*  Input:		---
653 #*
654 #*	Output:		---
655 #*
656 #************************************************************************/
657 IMPL_LINK( ArgInput, RefBtnFocusHdl,RefButton*, pBtn )
658 {
659 	if(pRefBtn==pBtn) RefFocus();
660 
661 	return 0;
662 }
663 
664 /*************************************************************************
665 #*	Handle:		EdFocusHdl									Datum:13.01.97
666 #*------------------------------------------------------------------------
667 #*
668 #*  Klasse:		ArgInput
669 #*
670 #*  Funktion:	Handle fuer Fx-Button Focus-Event.
671 #*
672 #*  Input:		---
673 #*
674 #*	Output:		---
675 #*
676 #************************************************************************/
677 IMPL_LINK( ArgInput, EdFocusHdl, ArgEdit*, pEd )
678 {
679 	if(pEd==pEdArg) EdFocus();
680 
681 	return 0;
682 }
683 
684 /*************************************************************************
685 #*	Handle:		RefBtnClickHdl								Datum:13.01.97
686 #*------------------------------------------------------------------------
687 #*
688 #*  Klasse:		ArgInput
689 #*
690 #*  Funktion:	Handle fuer Fx-Button Focus-Event.
691 #*
692 #*  Input:		---
693 #*
694 #*	Output:		---
695 #*
696 #************************************************************************/
697 IMPL_LINK( ArgInput, EdModifyHdl,ArgEdit*, pEd )
698 {
699 	if(pEd==pEdArg) EdModify();
700 
701 	return 0;
702 }
703 
704 /*************************************************************************
705 #*	Member:		EditBox									Datum:20.01.97
706 #*------------------------------------------------------------------------
707 #*
708 #*  Klasse:		EditBox
709 #*
710 #*  Funktion:	Konstruktor der Klasse ArgInput
711 #*
712 #*  Input:		Parent, Window-Style
713 #*
714 #*	Output:		---
715 #*
716 #************************************************************************/
717 EditBox::EditBox(	Window* pParent,WinBits nWinStyle)
718 		:Control(pParent,nWinStyle|WB_DIALOGCONTROL)
719 {
720 	pMEdit=new MultiLineEdit(this,WB_LEFT | WB_VSCROLL | (nWinStyle & WB_TABSTOP) |
721 					WB_NOBORDER | WB_NOHIDESELECTION | WB_IGNORETAB);
722 
723 	pMEdit->Show();
724 	aOldSel=pMEdit->GetSelection();
725 }
726 
727 /*************************************************************************
728 #*	Member:		EditBox									Datum:20.01.97
729 #*------------------------------------------------------------------------
730 #*
731 #*  Klasse:		EditBox
732 #*
733 #*  Funktion:	Konstruktor der Klasse ArgInput
734 #*
735 #*  Input:		Parent, Resource
736 #*
737 #*	Output:		---
738 #*
739 #************************************************************************/
740 EditBox::EditBox( Window* pParent, const ResId& rResId )
741 		:Control(pParent,rResId),
742 		bMouseFlag(sal_False)
743 {
744 	WinBits nStyle=GetStyle();
745 	SetStyle( nStyle| WB_DIALOGCONTROL);
746 
747 	pMEdit=new MultiLineEdit(this,WB_LEFT | WB_VSCROLL | (nStyle & WB_TABSTOP) |
748 					WB_NOBORDER | WB_NOHIDESELECTION | WB_IGNORETAB);
749 	pMEdit->Show();
750 	aOldSel=pMEdit->GetSelection();
751 	Resize();
752 	WinBits nWinStyle=GetStyle() | WB_DIALOGCONTROL;
753 	SetStyle(nWinStyle);
754 
755 	//	#105582# the HelpId from the resource must be set for the MultiLineEdit,
756 	//	not for the control that contains it.
757 	pMEdit->SetHelpId( GetHelpId() );
758 	SetHelpId( "" );
759 }
760 
761 EditBox::~EditBox()
762 {
763 	MultiLineEdit* pTheEdit=pMEdit;
764 	pMEdit->Disable();
765 	pMEdit=NULL;
766 	delete pTheEdit;
767 }
768 /*************************************************************************
769 #*	Member:		EditBox									Datum:20.01.97
770 #*------------------------------------------------------------------------
771 #*
772 #*  Klasse:		EditBox
773 #*
774 #*  Funktion:	Wenn sich die Selektion geaendert hat, so wird
775 #*				diese Funktion aufgerufen.
776 #*
777 #*  Input:		---
778 #*
779 #*	Output:		---
780 #*
781 #************************************************************************/
782 void EditBox::SelectionChanged()
783 {
784 	aSelChangedLink.Call(this);
785 }
786 
787 /*************************************************************************
788 #*	Member:		EditBox									Datum:20.05.98
789 #*------------------------------------------------------------------------
790 #*
791 #*  Klasse:		EditBox
792 #*
793 #*  Funktion:	Wenn sich die Groesse geaendert hat, so muss
794 #*				auch der MultiLineEdit angepasst werden..
795 #*
796 #*  Input:		---
797 #*
798 #*	Output:		---
799 #*
800 #************************************************************************/
801 void EditBox::Resize()
802 {
803 	Size aSize=GetOutputSizePixel();
804 	if(pMEdit!=NULL) pMEdit->SetOutputSizePixel(aSize);
805 }
806 
807 /*************************************************************************
808 #*	Member:		GetFocus									Datum:26.05.98
809 #*------------------------------------------------------------------------
810 #*
811 #*  Klasse:		EditBox
812 #*
813 #*  Funktion:	Wenn der Control aktiviert wird, so wird
814 #*				die Selection aufgehoben und der Cursor ans
815 #*				Ende gesetzt.
816 #*
817 #*  Input:		---
818 #*
819 #*	Output:		---
820 #*
821 #************************************************************************/
822 void EditBox::GetFocus()
823 {
824 	if(pMEdit!=NULL)
825 	{
826 		pMEdit->GrabFocus();
827 	}
828 }
829 
830 
831 
832 /*************************************************************************
833 #*	Member:		EditBox									Datum:20.01.97
834 #*------------------------------------------------------------------------
835 #*
836 #*  Klasse:		EditBox
837 #*
838 #*  Funktion:	Wenn ein Event ausgeloest wird, so wird diese Routine
839 #*				zuerst aufgerufen und ein PostUserEvent verschickt.
840 #*
841 #*  Input:		Notify-Event
842 #*
843 #*	Output:		---
844 #*
845 #************************************************************************/
846 long EditBox::PreNotify( NotifyEvent& rNEvt )
847 {
848 	long nResult=sal_True;
849 
850 	if(pMEdit==NULL) return nResult;
851 
852 	sal_uInt16 nSwitch=rNEvt.GetType();
853 	if(nSwitch==EVENT_KEYINPUT)// || nSwitch==EVENT_KEYUP)
854 	{
855 		const KeyCode& aKeyCode=rNEvt.GetKeyEvent()->GetKeyCode();
856 		sal_uInt16 nKey=aKeyCode.GetCode();
857 		if( (nKey==KEY_RETURN && !aKeyCode.IsShift()) || nKey==KEY_TAB )
858 		{
859 			nResult=GetParent()->Notify(rNEvt);
860 		}
861 		else
862 		{
863 			nResult=Control::PreNotify(rNEvt);
864 			Application::PostUserEvent( LINK( this, EditBox, ChangedHdl ) );
865 		}
866 
867 	}
868 	else
869 	{
870 		nResult=Control::PreNotify(rNEvt);
871 
872 		if(nSwitch==EVENT_MOUSEBUTTONDOWN || nSwitch==EVENT_MOUSEBUTTONUP)
873 		{
874 			bMouseFlag=sal_True;
875 			Application::PostUserEvent( LINK( this, EditBox, ChangedHdl ) );
876 		}
877 	}
878 	return nResult;
879 }
880 
881 /*************************************************************************
882 #*	Member:		EditBox									Datum:21.01.97
883 #*------------------------------------------------------------------------
884 #*
885 #*  Klasse:		EditBox
886 #*
887 #*  Funktion:	Wenn ein Event ausgeloest wurde, so wird diese Routine
888 #*				zuerst aufgerufen.
889 #*
890 #*  Input:		Key-Event
891 #*
892 #*	Output:		---
893 #*
894 #************************************************************************/
895 IMPL_LINK( EditBox, ChangedHdl, EditBox*, EMPTYARG )
896 {
897 	if(pMEdit!=NULL)
898 	{
899 		Selection aNewSel=pMEdit->GetSelection();
900 
901 		if(aNewSel.Min()!=aOldSel.Min() || aNewSel.Max()!=aOldSel.Max())
902 		{
903 			SelectionChanged();
904 			aOldSel=aNewSel;
905 		}
906 	}
907 	return 0;
908 }
909 
910 void EditBox::UpdateOldSel()
911 {
912 	//	if selection is set for editing a function, store it as aOldSel,
913 	//	so SelectionChanged isn't called in the next ChangedHdl call
914 
915 	if (pMEdit)
916 		aOldSel = pMEdit->GetSelection();
917 }
918 //----------------------------------------------------------------------------
919 
920 //============================================================================
921 //	class RefEdit
922 //----------------------------------------------------------------------------
923 
924 #define SC_ENABLE_TIME 100
925 
926 RefEdit::RefEdit( Window* _pParent,IControlReferenceHandler* pParent, const ResId& rResId ) :
927     Edit( _pParent, rResId ),
928     pAnyRefDlg( pParent ),
929     bSilentFocus( sal_False )
930 {
931     aTimer.SetTimeoutHdl( LINK( this, RefEdit, UpdateHdl ) );
932     aTimer.SetTimeout( SC_ENABLE_TIME );
933 }
934 
935 RefEdit::RefEdit( Window* pParent, const ResId& rResId ) :
936     Edit( pParent, rResId ),
937     pAnyRefDlg( NULL ),
938     bSilentFocus( sal_False )
939 {
940 }
941 
942 RefEdit::~RefEdit()
943 {
944     aTimer.SetTimeoutHdl( Link() );
945 	aTimer.Stop();
946 }
947 
948 void RefEdit::SetRefString( const XubString& rStr )
949 {
950     Edit::SetText( rStr );
951 }
952 
953 void RefEdit::SetText( const XubString& rStr )
954 {
955     Edit::SetText( rStr );
956     UpdateHdl( &aTimer );
957 }
958 
959 void RefEdit::StartUpdateData()
960 {
961 	aTimer.Start();
962 }
963 
964 void RefEdit::SilentGrabFocus()
965 {
966     bSilentFocus = sal_True;
967     GrabFocus();
968     bSilentFocus = sal_False;
969 }
970 
971 void RefEdit::SetRefDialog( IControlReferenceHandler* pDlg )
972 {
973     pAnyRefDlg = pDlg;
974 
975     if( pDlg )
976 	{
977         aTimer.SetTimeoutHdl( LINK( this, RefEdit, UpdateHdl ) );
978         aTimer.SetTimeout( SC_ENABLE_TIME );
979 	}
980 	else
981 	{
982         aTimer.SetTimeoutHdl( Link() );
983 		aTimer.Stop();
984 	}
985 }
986 
987 void RefEdit::Modify()
988 {
989 	Edit::Modify();
990     if( pAnyRefDlg )
991 		pAnyRefDlg->HideReference();
992 }
993 
994 void RefEdit::KeyInput( const KeyEvent& rKEvt )
995 {
996     const KeyCode& rKeyCode = rKEvt.GetKeyCode();
997     if( pAnyRefDlg && !rKeyCode.GetModifier() && (rKeyCode.GetCode() == KEY_F2) )
998         pAnyRefDlg->ReleaseFocus( this );
999     else
1000         Edit::KeyInput( rKEvt );
1001 }
1002 
1003 void RefEdit::GetFocus()
1004 {
1005     Edit::GetFocus();
1006     if( !bSilentFocus )
1007         StartUpdateData();
1008 }
1009 
1010 void RefEdit::LoseFocus()
1011 {
1012 	Edit::LoseFocus();
1013     if( pAnyRefDlg )
1014 		pAnyRefDlg->HideReference();
1015 }
1016 
1017 IMPL_LINK( RefEdit, UpdateHdl, Timer*, EMPTYARG )
1018 {
1019     if( pAnyRefDlg )
1020         pAnyRefDlg->ShowReference( GetText() );
1021 	return 0;
1022 }
1023 
1024 
1025 //============================================================================
1026 //	class RefButton
1027 //----------------------------------------------------------------------------
1028 RefButton::RefButton( Window* _pParent, const ResId& rResId) :
1029     ImageButton( _pParent, rResId ),
1030     aImgRefStart( ModuleRes( RID_BMP_REFBTN1 ) ),
1031     aImgRefStartHC( ModuleRes( RID_BMP_REFBTN1_H ) ),
1032     aImgRefDone( ModuleRes( RID_BMP_REFBTN2 ) ),
1033     aImgRefDoneHC( ModuleRes( RID_BMP_REFBTN2_H ) ),
1034     pAnyRefDlg( NULL ),
1035     pRefEdit( NULL )
1036 {
1037     SetStartImage();
1038 }
1039 
1040 RefButton::RefButton( Window* _pParent, const ResId& rResId, RefEdit* pEdit, IControlReferenceHandler* _pDlg ) :
1041     ImageButton( _pParent, rResId ),
1042     aImgRefStart( ModuleRes( RID_BMP_REFBTN1 ) ),
1043     aImgRefStartHC( ModuleRes( RID_BMP_REFBTN1_H ) ),
1044     aImgRefDone( ModuleRes( RID_BMP_REFBTN2 ) ),
1045     aImgRefDoneHC( ModuleRes( RID_BMP_REFBTN2_H ) ),
1046     pAnyRefDlg( _pDlg ),
1047     pRefEdit( pEdit )
1048 {
1049     SetStartImage();
1050 }
1051 
1052 void RefButton::SetStartImage()
1053 {
1054     SetModeImage( aImgRefStart );
1055     SetModeImage( aImgRefStartHC, BMP_COLOR_HIGHCONTRAST );
1056 }
1057 
1058 void RefButton::SetEndImage()
1059 {
1060     SetModeImage( aImgRefDone );
1061     SetModeImage( aImgRefDoneHC, BMP_COLOR_HIGHCONTRAST );
1062 }
1063 
1064 void RefButton::SetReferences( IControlReferenceHandler* pDlg, RefEdit* pEdit )
1065 {
1066     pAnyRefDlg = pDlg;
1067     pRefEdit = pEdit;
1068 }
1069 
1070 //----------------------------------------------------------------------------
1071 
1072 void RefButton::Click()
1073 {
1074     if( pAnyRefDlg )
1075         pAnyRefDlg->ToggleCollapsed( pRefEdit, this );
1076 }
1077 
1078 void RefButton::KeyInput( const KeyEvent& rKEvt )
1079 {
1080     const KeyCode& rKeyCode = rKEvt.GetKeyCode();
1081     if( pAnyRefDlg && !rKeyCode.GetModifier() && (rKeyCode.GetCode() == KEY_F2) )
1082         pAnyRefDlg->ReleaseFocus( pRefEdit );
1083     else
1084         ImageButton::KeyInput( rKEvt );
1085 }
1086 
1087 void RefButton::GetFocus()
1088 {
1089 	ImageButton::GetFocus();
1090     if( pRefEdit )
1091         pRefEdit->StartUpdateData();
1092 }
1093 
1094 void RefButton::LoseFocus()
1095 {
1096 	ImageButton::LoseFocus();
1097     if( pRefEdit )
1098         pRefEdit->Modify();
1099 }
1100 
1101 
1102 } // formula
1103