Update ooo320-m1
[ooovba.git] / formula / source / ui / dlg / funcutl.cxx
blob4d12751105463eea562c69ba66a5328e80211547
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: funcutl.cxx,v $
10 * $Revision: 1.9 $
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_formula.hxx"
34 //----------------------------------------------------------------------------
35 #include <vcl/sound.hxx>
36 #include <vcl/svapp.hxx>
37 #include <vcl/scrbar.hxx>
39 #include "formula/funcutl.hxx"
40 #include "formula/IControlReferenceHandler.hxx"
41 #include "ControlHelper.hxx"
42 #include "ModuleHelper.hxx"
43 #include "ForResId.hrc"
46 namespace formula
48 //============================================================================
49 // class ValWnd
50 //----------------------------------------------------------------------------
52 ValWnd::ValWnd( Window* pParent, const ResId& rId ) : Window( pParent, rId )
54 Font aFnt( GetFont() );
55 aFnt.SetTransparent( TRUE );
56 aFnt.SetWeight( WEIGHT_LIGHT );
57 if ( pParent->IsBackground() )
59 Wallpaper aBack = pParent->GetBackground();
60 SetFillColor( aBack.GetColor() );
61 SetBackground( aBack );
62 aFnt.SetFillColor( aBack.GetColor() );
64 else
66 SetFillColor();
67 SetBackground();
69 SetFont( aFnt );
70 SetLineColor();
72 Size aSzWnd = GetOutputSizePixel();
73 long nHeight = GetTextHeight();
74 long nDiff = aSzWnd.Height()-nHeight;
76 aRectOut = Rectangle( Point( 1, ( nDiff<2 ) ? 1 : nDiff/2),
77 Size ( aSzWnd.Width()-2, nHeight ) );
78 SetClipRegion( Region( aRectOut ) );
81 //----------------------------------------------------------------------------
83 void __EXPORT ValWnd::Paint( const Rectangle& )
85 DrawText( aRectOut.TopLeft(), aStrValue );
88 //----------------------------------------------------------------------------
90 void ValWnd::SetValue( const String& rStrVal )
92 if ( aStrValue != rStrVal )
94 aStrValue = rStrVal;
95 DrawRect( aRectOut ); // alten Text loeschen
96 Paint( aRectOut ); // und neu malen
100 //============================================================================
101 // class ArgEdit
102 //----------------------------------------------------------------------------
104 ArgEdit::ArgEdit( Window* pParent, const ResId& rResId )
105 : RefEdit( pParent, rResId ),
106 pEdPrev ( NULL ),
107 pEdNext ( NULL ),
108 pSlider ( NULL ),
109 nArgs ( 0 )
113 //----------------------------------------------------------------------------
115 void ArgEdit::Init( ArgEdit* pPrevEdit, ArgEdit* pNextEdit,
116 ScrollBar& rArgSlider, USHORT nArgCount )
118 pEdPrev = pPrevEdit;
119 pEdNext = pNextEdit;
120 pSlider = &rArgSlider;
121 nArgs = nArgCount;
124 //----------------------------------------------------------------------------
126 // Cursorsteuerung fuer EditFelder im Argument-Dialog
128 void __EXPORT ArgEdit::KeyInput( const KeyEvent& rKEvt )
130 KeyCode aCode = rKEvt.GetKeyCode();
131 BOOL bUp = (aCode.GetCode() == KEY_UP);
132 BOOL bDown = (aCode.GetCode() == KEY_DOWN);
133 ArgEdit* pEd = NULL;
135 if ( pSlider
136 && ( !aCode.IsShift() && !aCode.IsMod1() && !aCode.IsMod2() )
137 && ( bUp || bDown ) )
139 if ( nArgs > 1 )
141 long nThumb = pSlider->GetThumbPos();
142 BOOL bDoScroll = FALSE;
143 BOOL bChangeFocus = FALSE;
145 if ( bDown )
147 if ( nArgs > 4 )
149 if ( !pEdNext )
151 nThumb++;
152 bDoScroll = ( nThumb+3 < (long)nArgs );
154 else
156 pEd = pEdNext;
157 bChangeFocus = TRUE;
160 else if ( pEdNext )
162 pEd = pEdNext;
163 bChangeFocus = TRUE;
166 else // if ( bUp )
168 if ( nArgs > 4 )
170 if ( !pEdPrev )
172 nThumb--;
173 bDoScroll = ( nThumb >= 0 );
175 else
177 pEd = pEdPrev;
178 bChangeFocus = TRUE;
181 else if ( pEdPrev )
183 pEd = pEdPrev;
184 bChangeFocus = TRUE;
188 if ( bDoScroll )
190 pSlider->SetThumbPos( nThumb );
191 ((Link&)pSlider->GetEndScrollHdl()).Call( pSlider );
193 else if ( bChangeFocus )
195 pEd->GrabFocus();
197 else
198 Sound::Beep();
200 else
201 Sound::Beep();
203 else
204 RefEdit::KeyInput( rKEvt );
210 /*************************************************************************
211 #* Member: ArgInput Datum:13.01.97
212 #*------------------------------------------------------------------------
214 #* Klasse: ArgInput
216 #* Funktion: Konstruktor der Klasse ArgInput
218 #* Input: ---
220 #* Output: ---
222 #************************************************************************/
224 ArgInput::ArgInput()
226 pFtArg=NULL;
227 pBtnFx=NULL;
228 pEdArg=NULL;
229 pRefBtn=NULL;
232 /*************************************************************************
233 #* Member: InitArgInput Datum:13.01.97
234 #*------------------------------------------------------------------------
236 #* Klasse: ArgInput
238 #* Funktion: Initialisiert die Pointer der Klasse
240 #* Input: ---
242 #* Output: ---
244 #************************************************************************/
246 void ArgInput::InitArgInput(FixedText* pftArg,
247 ImageButton* pbtnFx,
248 ArgEdit* pedArg,
249 RefButton* prefBtn)
251 pFtArg =pftArg;
252 pBtnFx =pbtnFx;
253 pEdArg =pedArg;
254 pRefBtn=prefBtn;
256 if(pBtnFx!=NULL)
258 pBtnFx->SetClickHdl ( LINK( this, ArgInput, FxBtnClickHdl ) );
259 pBtnFx->SetGetFocusHdl( LINK( this, ArgInput, FxBtnFocusHdl ) );
261 if(pRefBtn!=NULL)
263 pRefBtn->SetClickHdl ( LINK( this, ArgInput, RefBtnClickHdl ) );
264 pRefBtn->SetGetFocusHdl( LINK( this, ArgInput, RefBtnFocusHdl ) );
266 if(pEdArg!=NULL)
268 pEdArg->SetGetFocusHdl ( LINK( this, ArgInput, EdFocusHdl ) );
269 pEdArg->SetModifyHdl ( LINK( this, ArgInput, EdModifyHdl ) );
274 /*************************************************************************
275 #* Member: SetArgName Datum:13.01.97
276 #*------------------------------------------------------------------------
278 #* Klasse: ArgInput
280 #* Funktion: Setzt den Namen fuer das Argument
282 #* Input: String
284 #* Output: ---
286 #************************************************************************/
287 void ArgInput::SetArgName(const String &aArg)
289 if(pFtArg !=NULL) pFtArg->SetText(aArg );
292 /*************************************************************************
293 #* Member: GetArgName Datum:06.02.97
294 #*------------------------------------------------------------------------
296 #* Klasse: ArgInput
298 #* Funktion: Liefert den Namen fuer das Argument zurueck
300 #* Input: String
302 #* Output: ---
304 #************************************************************************/
305 String ArgInput::GetArgName()
307 String aPrivArgName;
308 if(pFtArg !=NULL)
309 aPrivArgName=pFtArg->GetText();
311 return aPrivArgName;
315 /*************************************************************************
316 #* Member: SetArgName Datum:13.01.97
317 #*------------------------------------------------------------------------
319 #* Klasse: ArgInput
321 #* Funktion: Setzt den Namen fuer das Argument
323 #* Input: String
325 #* Output: ---
327 #************************************************************************/
328 void ArgInput::SetArgNameFont (const Font &aFont)
330 if(pFtArg !=NULL) pFtArg->SetFont(aFont);
333 /*************************************************************************
334 #* Member: SetArgSelection Datum:13.01.97
335 #*------------------------------------------------------------------------
337 #* Klasse: ArgInput
339 #* Funktion: Stellt die Selection fuer die EditBox ein.
341 #* Input: String
343 #* Output: ---
345 #************************************************************************/
346 void ArgInput::SetArgSelection (const Selection& rSel )
348 if(pEdArg !=NULL) pEdArg ->SetSelection(rSel );
351 /*************************************************************************
352 #* Member: SetArgSelection Datum:13.01.97
353 #*------------------------------------------------------------------------
355 #* Klasse: ArgInput
357 #* Funktion: Liefert die Selection fuer die EditBox zurueck.
359 #* Input: String
361 #* Output: ---
363 #************************************************************************/
364 Selection ArgInput::GetArgSelection ()
366 Selection aSel;
367 if(pEdArg !=NULL) aSel=pEdArg ->GetSelection();
368 return aSel;
371 /*************************************************************************
372 #* Member: SetArgSelection Datum:13.01.97
373 #*------------------------------------------------------------------------
375 #* Klasse: ArgInput
377 #* Funktion: Ersetzt die Selection in der EditBox.
379 #* Input: String
381 #* Output: ---
383 #************************************************************************/
384 void ArgInput::ReplaceSelOfArg(const String& rStr )
386 if(pEdArg !=NULL) pEdArg ->ReplaceSelected(rStr );
391 /*************************************************************************
392 #* Member: SetArgVal Datum:13.01.97
393 #*------------------------------------------------------------------------
395 #* Klasse: ArgInput
397 #* Funktion: Setzt den Wert fuer das Argument
399 #* Input: String
401 #* Output: ---
403 #************************************************************************/
404 void ArgInput::SetArgVal(const String &aVal)
406 if(pEdArg !=NULL)
408 pEdArg ->SetRefString(aVal );
412 /*************************************************************************
413 #* Member: SetArgName Datum:13.01.97
414 #*------------------------------------------------------------------------
416 #* Klasse: ArgInput
418 #* Funktion: Liefert den Wert fuer das Argument
420 #* Input: ---
422 #* Output: String
424 #************************************************************************/
425 String ArgInput::GetArgVal()
427 String aResult;
428 if(pEdArg!=NULL)
430 aResult=pEdArg->GetText();
432 return aResult;
435 /*************************************************************************
436 #* Member: SetArgName Datum:13.01.97
437 #*------------------------------------------------------------------------
439 #* Klasse: ArgInput
441 #* Funktion: Versteckt die Controls
443 #* Input: ---
445 #* Output: ---
447 #************************************************************************/
448 void ArgInput::Hide()
450 if ( pFtArg && pBtnFx && pEdArg && pRefBtn)
452 pFtArg->Hide();
453 pBtnFx->Hide();
454 pEdArg->Hide();
455 pRefBtn->Hide();
459 /*************************************************************************
460 #* Member: SetArgName Datum:13.01.97
461 #*------------------------------------------------------------------------
463 #* Klasse: ArgInput
465 #* Funktion: Zaubert die Controls wieder hervor.
467 #* Input: ---
469 #* Output: ---
471 #************************************************************************/
472 void ArgInput::Show()
474 if ( pFtArg && pBtnFx && pEdArg && pRefBtn)
476 pFtArg->Show();
477 pBtnFx->Show();
478 pEdArg->Show();
479 pRefBtn->Show();
483 /*************************************************************************
484 #* Member: FxClick Datum:13.01.97
485 #*------------------------------------------------------------------------
487 #* Klasse: ArgInput
489 #* Funktion: Gibt den Event weiter.
491 #* Input: ---
493 #* Output: ---
495 #************************************************************************/
496 void ArgInput::FxClick()
498 aFxClickLink.Call(this);
501 /*************************************************************************
502 #* Member: RefClick Datum:13.01.97
503 #*------------------------------------------------------------------------
505 #* Klasse: ArgInput
507 #* Funktion: Gibt den Event weiter.
509 #* Input: ---
511 #* Output: ---
513 #************************************************************************/
514 void ArgInput::RefClick()
516 aRefClickLink.Call(this);
519 /*************************************************************************
520 #* Member: FxFocus Datum:13.01.97
521 #*------------------------------------------------------------------------
523 #* Klasse: ArgInput
525 #* Funktion: Gibt den Event weiter.
527 #* Input: ---
529 #* Output: ---
531 #************************************************************************/
532 void ArgInput::FxFocus()
534 aFxFocusLink.Call(this);
537 /*************************************************************************
538 #* Member: RefFocus Datum:13.01.97
539 #*------------------------------------------------------------------------
541 #* Klasse: ArgInput
543 #* Funktion: Gibt den Event weiter.
545 #* Input: ---
547 #* Output: ---
549 #************************************************************************/
550 void ArgInput::RefFocus()
552 aRefFocusLink.Call(this);
555 /*************************************************************************
556 #* Member: EdFocus Datum:13.01.97
557 #*------------------------------------------------------------------------
559 #* Klasse: ArgInput
561 #* Funktion: Gibt den Event weiter.
563 #* Input: ---
565 #* Output: ---
567 #************************************************************************/
568 void ArgInput::EdFocus()
570 aEdFocusLink.Call(this);
573 /*************************************************************************
574 #* Member: EdModify Datum:13.01.97
575 #*------------------------------------------------------------------------
577 #* Klasse: ArgInput
579 #* Funktion: Gibt den Event weiter.
581 #* Input: ---
583 #* Output: ---
585 #************************************************************************/
586 void ArgInput::EdModify()
588 aEdModifyLink.Call(this);
591 /*************************************************************************
592 #* Handle: FxBtnHdl Datum:13.01.97
593 #*------------------------------------------------------------------------
595 #* Klasse: ArgInput
597 #* Funktion: Handle fuer Fx-Button Click-Event.
599 #* Input: ---
601 #* Output: ---
603 #************************************************************************/
604 IMPL_LINK( ArgInput, FxBtnClickHdl, ImageButton*, pBtn )
606 if(pBtn==pBtnFx) FxClick();
608 return 0;
611 /*************************************************************************
612 #* Handle: RefBtnClickHdl Datum:13.01.97
613 #*------------------------------------------------------------------------
615 #* Klasse: ArgInput
617 #* Funktion: Handle fuer Fx-Button Click-Event.
619 #* Input: ---
621 #* Output: ---
623 #************************************************************************/
624 IMPL_LINK( ArgInput, RefBtnClickHdl,RefButton*, pBtn )
626 if(pRefBtn==pBtn) RefClick();
628 return 0;
631 /*************************************************************************
632 #* Handle: FxBtnFocusHdl Datum:13.01.97
633 #*------------------------------------------------------------------------
635 #* Klasse: ArgInput
637 #* Funktion: Handle fuer Fx-Button Focus-Event.
639 #* Input: ---
641 #* Output: ---
643 #************************************************************************/
644 IMPL_LINK( ArgInput, FxBtnFocusHdl, ImageButton*, pBtn )
646 if(pBtn==pBtnFx) FxFocus();
648 return 0;
651 /*************************************************************************
652 #* Handle: RefBtnFocusHdl Datum:13.01.97
653 #*------------------------------------------------------------------------
655 #* Klasse: ArgInput
657 #* Funktion: Handle fuer Fx-Button Focus-Event.
659 #* Input: ---
661 #* Output: ---
663 #************************************************************************/
664 IMPL_LINK( ArgInput, RefBtnFocusHdl,RefButton*, pBtn )
666 if(pRefBtn==pBtn) RefFocus();
668 return 0;
671 /*************************************************************************
672 #* Handle: EdFocusHdl Datum:13.01.97
673 #*------------------------------------------------------------------------
675 #* Klasse: ArgInput
677 #* Funktion: Handle fuer Fx-Button Focus-Event.
679 #* Input: ---
681 #* Output: ---
683 #************************************************************************/
684 IMPL_LINK( ArgInput, EdFocusHdl, ArgEdit*, pEd )
686 if(pEd==pEdArg) EdFocus();
688 return 0;
691 /*************************************************************************
692 #* Handle: RefBtnClickHdl Datum:13.01.97
693 #*------------------------------------------------------------------------
695 #* Klasse: ArgInput
697 #* Funktion: Handle fuer Fx-Button Focus-Event.
699 #* Input: ---
701 #* Output: ---
703 #************************************************************************/
704 IMPL_LINK( ArgInput, EdModifyHdl,ArgEdit*, pEd )
706 if(pEd==pEdArg) EdModify();
708 return 0;
711 /*************************************************************************
712 #* Member: EditBox Datum:20.01.97
713 #*------------------------------------------------------------------------
715 #* Klasse: EditBox
717 #* Funktion: Konstruktor der Klasse ArgInput
719 #* Input: Parent, Window-Style
721 #* Output: ---
723 #************************************************************************/
724 EditBox::EditBox( Window* pParent,WinBits nWinStyle)
725 :Control(pParent,nWinStyle|WB_DIALOGCONTROL)
727 pMEdit=new MultiLineEdit(this,WB_LEFT | WB_VSCROLL | (nWinStyle & WB_TABSTOP) |
728 WB_NOBORDER | WB_NOHIDESELECTION | WB_IGNORETAB);
730 pMEdit->Show();
731 aOldSel=pMEdit->GetSelection();
734 /*************************************************************************
735 #* Member: EditBox Datum:20.01.97
736 #*------------------------------------------------------------------------
738 #* Klasse: EditBox
740 #* Funktion: Konstruktor der Klasse ArgInput
742 #* Input: Parent, Resource
744 #* Output: ---
746 #************************************************************************/
747 EditBox::EditBox( Window* pParent, const ResId& rResId )
748 :Control(pParent,rResId),
749 bMouseFlag(FALSE)
751 WinBits nStyle=GetStyle();
752 SetStyle( nStyle| WB_DIALOGCONTROL);
754 pMEdit=new MultiLineEdit(this,WB_LEFT | WB_VSCROLL | (nStyle & WB_TABSTOP) |
755 WB_NOBORDER | WB_NOHIDESELECTION | WB_IGNORETAB);
756 pMEdit->Show();
757 aOldSel=pMEdit->GetSelection();
758 Resize();
759 WinBits nWinStyle=GetStyle() | WB_DIALOGCONTROL;
760 SetStyle(nWinStyle);
762 // #105582# the HelpId from the resource must be set for the MultiLineEdit,
763 // not for the control that contains it.
764 pMEdit->SetSmartHelpId( GetSmartHelpId() );
765 SetSmartHelpId( SmartId() );
768 EditBox::~EditBox()
770 MultiLineEdit* pTheEdit=pMEdit;
771 pMEdit->Disable();
772 pMEdit=NULL;
773 delete pTheEdit;
775 /*************************************************************************
776 #* Member: EditBox Datum:20.01.97
777 #*------------------------------------------------------------------------
779 #* Klasse: EditBox
781 #* Funktion: Wenn sich die Selektion geaendert hat, so wird
782 #* diese Funktion aufgerufen.
784 #* Input: ---
786 #* Output: ---
788 #************************************************************************/
789 void EditBox::SelectionChanged()
791 aSelChangedLink.Call(this);
794 /*************************************************************************
795 #* Member: EditBox Datum:20.05.98
796 #*------------------------------------------------------------------------
798 #* Klasse: EditBox
800 #* Funktion: Wenn sich die Groesse geaendert hat, so muss
801 #* auch der MultiLineEdit angepasst werden..
803 #* Input: ---
805 #* Output: ---
807 #************************************************************************/
808 void EditBox::Resize()
810 Size aSize=GetOutputSizePixel();
811 if(pMEdit!=NULL) pMEdit->SetOutputSizePixel(aSize);
814 /*************************************************************************
815 #* Member: GetFocus Datum:26.05.98
816 #*------------------------------------------------------------------------
818 #* Klasse: EditBox
820 #* Funktion: Wenn der Control aktiviert wird, so wird
821 #* die Selection aufgehoben und der Cursor ans
822 #* Ende gesetzt.
824 #* Input: ---
826 #* Output: ---
828 #************************************************************************/
829 void EditBox::GetFocus()
831 if(pMEdit!=NULL)
833 pMEdit->GrabFocus();
839 /*************************************************************************
840 #* Member: EditBox Datum:20.01.97
841 #*------------------------------------------------------------------------
843 #* Klasse: EditBox
845 #* Funktion: Wenn ein Event ausgeloest wird, so wird diese Routine
846 #* zuerst aufgerufen und ein PostUserEvent verschickt.
848 #* Input: Notify-Event
850 #* Output: ---
852 #************************************************************************/
853 long EditBox::PreNotify( NotifyEvent& rNEvt )
855 long nResult=TRUE;
857 if(pMEdit==NULL) return nResult;
859 USHORT nSwitch=rNEvt.GetType();
860 if(nSwitch==EVENT_KEYINPUT)// || nSwitch==EVENT_KEYUP)
862 const KeyCode& aKeyCode=rNEvt.GetKeyEvent()->GetKeyCode();
863 USHORT nKey=aKeyCode.GetCode();
864 if( (nKey==KEY_RETURN && !aKeyCode.IsShift()) || nKey==KEY_TAB )
866 nResult=GetParent()->Notify(rNEvt);
868 else
870 nResult=Control::PreNotify(rNEvt);
871 Application::PostUserEvent( LINK( this, EditBox, ChangedHdl ) );
875 else
877 nResult=Control::PreNotify(rNEvt);
879 if(nSwitch==EVENT_MOUSEBUTTONDOWN || nSwitch==EVENT_MOUSEBUTTONUP)
881 bMouseFlag=TRUE;
882 Application::PostUserEvent( LINK( this, EditBox, ChangedHdl ) );
885 return nResult;
888 /*************************************************************************
889 #* Member: EditBox Datum:21.01.97
890 #*------------------------------------------------------------------------
892 #* Klasse: EditBox
894 #* Funktion: Wenn ein Event ausgeloest wurde, so wird diese Routine
895 #* zuerst aufgerufen.
897 #* Input: Key-Event
899 #* Output: ---
901 #************************************************************************/
902 IMPL_LINK( EditBox, ChangedHdl, EditBox*, EMPTYARG )
904 if(pMEdit!=NULL)
906 Selection aNewSel=pMEdit->GetSelection();
908 if(aNewSel.Min()!=aOldSel.Min() || aNewSel.Max()!=aOldSel.Max())
910 SelectionChanged();
911 aOldSel=aNewSel;
914 return 0;
917 void EditBox::UpdateOldSel()
919 // if selection is set for editing a function, store it as aOldSel,
920 // so SelectionChanged isn't called in the next ChangedHdl call
922 if (pMEdit)
923 aOldSel = pMEdit->GetSelection();
925 //----------------------------------------------------------------------------
927 //============================================================================
928 // class RefEdit
929 //----------------------------------------------------------------------------
931 #define SC_ENABLE_TIME 100
933 RefEdit::RefEdit( Window* _pParent,IControlReferenceHandler* pParent, const ResId& rResId ) :
934 Edit( _pParent, rResId ),
935 pAnyRefDlg( pParent ),
936 bSilentFocus( FALSE )
938 aTimer.SetTimeoutHdl( LINK( this, RefEdit, UpdateHdl ) );
939 aTimer.SetTimeout( SC_ENABLE_TIME );
942 RefEdit::RefEdit( Window* pParent, const ResId& rResId ) :
943 Edit( pParent, rResId ),
944 pAnyRefDlg( NULL ),
945 bSilentFocus( FALSE )
949 RefEdit::~RefEdit()
951 aTimer.SetTimeoutHdl( Link() );
952 aTimer.Stop();
955 void RefEdit::SetRefString( const XubString& rStr )
957 Edit::SetText( rStr );
960 void RefEdit::SetText( const XubString& rStr )
962 Edit::SetText( rStr );
963 UpdateHdl( &aTimer );
966 void RefEdit::StartUpdateData()
968 aTimer.Start();
971 void RefEdit::SilentGrabFocus()
973 bSilentFocus = TRUE;
974 GrabFocus();
975 bSilentFocus = FALSE;
978 void RefEdit::SetRefDialog( IControlReferenceHandler* pDlg )
980 pAnyRefDlg = pDlg;
982 if( pDlg )
984 aTimer.SetTimeoutHdl( LINK( this, RefEdit, UpdateHdl ) );
985 aTimer.SetTimeout( SC_ENABLE_TIME );
987 else
989 aTimer.SetTimeoutHdl( Link() );
990 aTimer.Stop();
994 void RefEdit::Modify()
996 Edit::Modify();
997 if( pAnyRefDlg )
998 pAnyRefDlg->HideReference();
1001 void RefEdit::KeyInput( const KeyEvent& rKEvt )
1003 const KeyCode& rKeyCode = rKEvt.GetKeyCode();
1004 if( pAnyRefDlg && !rKeyCode.GetModifier() && (rKeyCode.GetCode() == KEY_F2) )
1005 pAnyRefDlg->ReleaseFocus( this );
1006 else
1007 Edit::KeyInput( rKEvt );
1010 void RefEdit::GetFocus()
1012 Edit::GetFocus();
1013 if( !bSilentFocus )
1014 StartUpdateData();
1017 void RefEdit::LoseFocus()
1019 Edit::LoseFocus();
1020 if( pAnyRefDlg )
1021 pAnyRefDlg->HideReference();
1024 IMPL_LINK( RefEdit, UpdateHdl, Timer*, EMPTYARG )
1026 if( pAnyRefDlg )
1027 pAnyRefDlg->ShowReference( GetText() );
1028 return 0;
1032 //============================================================================
1033 // class RefButton
1034 //----------------------------------------------------------------------------
1035 RefButton::RefButton( Window* _pParent, const ResId& rResId) :
1036 ImageButton( _pParent, rResId ),
1037 aImgRefStart( ModuleRes( RID_BMP_REFBTN1 ) ),
1038 aImgRefStartHC( ModuleRes( RID_BMP_REFBTN1_H ) ),
1039 aImgRefDone( ModuleRes( RID_BMP_REFBTN2 ) ),
1040 aImgRefDoneHC( ModuleRes( RID_BMP_REFBTN2_H ) ),
1041 pAnyRefDlg( NULL ),
1042 pRefEdit( NULL )
1044 SetStartImage();
1047 RefButton::RefButton( Window* _pParent, const ResId& rResId, RefEdit* pEdit, IControlReferenceHandler* _pDlg ) :
1048 ImageButton( _pParent, rResId ),
1049 aImgRefStart( ModuleRes( RID_BMP_REFBTN1 ) ),
1050 aImgRefStartHC( ModuleRes( RID_BMP_REFBTN1_H ) ),
1051 aImgRefDone( ModuleRes( RID_BMP_REFBTN2 ) ),
1052 aImgRefDoneHC( ModuleRes( RID_BMP_REFBTN2_H ) ),
1053 pAnyRefDlg( _pDlg ),
1054 pRefEdit( pEdit )
1056 SetStartImage();
1059 void RefButton::SetStartImage()
1061 SetModeImage( aImgRefStart );
1062 SetModeImage( aImgRefStartHC, BMP_COLOR_HIGHCONTRAST );
1065 void RefButton::SetEndImage()
1067 SetModeImage( aImgRefDone );
1068 SetModeImage( aImgRefDoneHC, BMP_COLOR_HIGHCONTRAST );
1071 void RefButton::SetReferences( IControlReferenceHandler* pDlg, RefEdit* pEdit )
1073 pAnyRefDlg = pDlg;
1074 pRefEdit = pEdit;
1077 //----------------------------------------------------------------------------
1079 void RefButton::Click()
1081 if( pAnyRefDlg )
1082 pAnyRefDlg->ToggleCollapsed( pRefEdit, this );
1085 void RefButton::KeyInput( const KeyEvent& rKEvt )
1087 const KeyCode& rKeyCode = rKEvt.GetKeyCode();
1088 if( pAnyRefDlg && !rKeyCode.GetModifier() && (rKeyCode.GetCode() == KEY_F2) )
1089 pAnyRefDlg->ReleaseFocus( pRefEdit );
1090 else
1091 ImageButton::KeyInput( rKEvt );
1094 void RefButton::GetFocus()
1096 ImageButton::GetFocus();
1097 if( pRefEdit )
1098 pRefEdit->StartUpdateData();
1101 void RefButton::LoseFocus()
1103 ImageButton::LoseFocus();
1104 if( pRefEdit )
1105 pRefEdit->Modify();
1109 } // formula