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