1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: funcutl.cxx,v $
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"
48 //============================================================================
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() );
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
)
95 DrawRect( aRectOut
); // alten Text loeschen
96 Paint( aRectOut
); // und neu malen
100 //============================================================================
102 //----------------------------------------------------------------------------
104 ArgEdit::ArgEdit( Window
* pParent
, const ResId
& rResId
)
105 : RefEdit( pParent
, rResId
),
113 //----------------------------------------------------------------------------
115 void ArgEdit::Init( ArgEdit
* pPrevEdit
, ArgEdit
* pNextEdit
,
116 ScrollBar
& rArgSlider
, USHORT nArgCount
)
120 pSlider
= &rArgSlider
;
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
);
136 && ( !aCode
.IsShift() && !aCode
.IsMod1() && !aCode
.IsMod2() )
137 && ( bUp
|| bDown
) )
141 long nThumb
= pSlider
->GetThumbPos();
142 BOOL bDoScroll
= FALSE
;
143 BOOL bChangeFocus
= FALSE
;
152 bDoScroll
= ( nThumb
+3 < (long)nArgs
);
173 bDoScroll
= ( nThumb
>= 0 );
190 pSlider
->SetThumbPos( nThumb
);
191 ((Link
&)pSlider
->GetEndScrollHdl()).Call( pSlider
);
193 else if ( bChangeFocus
)
204 RefEdit::KeyInput( rKEvt
);
210 /*************************************************************************
211 #* Member: ArgInput Datum:13.01.97
212 #*------------------------------------------------------------------------
216 #* Funktion: Konstruktor der Klasse ArgInput
222 #************************************************************************/
232 /*************************************************************************
233 #* Member: InitArgInput Datum:13.01.97
234 #*------------------------------------------------------------------------
238 #* Funktion: Initialisiert die Pointer der Klasse
244 #************************************************************************/
246 void ArgInput::InitArgInput(FixedText
* pftArg
,
258 pBtnFx
->SetClickHdl ( LINK( this, ArgInput
, FxBtnClickHdl
) );
259 pBtnFx
->SetGetFocusHdl( LINK( this, ArgInput
, FxBtnFocusHdl
) );
263 pRefBtn
->SetClickHdl ( LINK( this, ArgInput
, RefBtnClickHdl
) );
264 pRefBtn
->SetGetFocusHdl( LINK( this, ArgInput
, RefBtnFocusHdl
) );
268 pEdArg
->SetGetFocusHdl ( LINK( this, ArgInput
, EdFocusHdl
) );
269 pEdArg
->SetModifyHdl ( LINK( this, ArgInput
, EdModifyHdl
) );
274 /*************************************************************************
275 #* Member: SetArgName Datum:13.01.97
276 #*------------------------------------------------------------------------
280 #* Funktion: Setzt den Namen fuer das Argument
286 #************************************************************************/
287 void ArgInput::SetArgName(const String
&aArg
)
289 if(pFtArg
!=NULL
) pFtArg
->SetText(aArg
);
292 /*************************************************************************
293 #* Member: GetArgName Datum:06.02.97
294 #*------------------------------------------------------------------------
298 #* Funktion: Liefert den Namen fuer das Argument zurueck
304 #************************************************************************/
305 String
ArgInput::GetArgName()
309 aPrivArgName
=pFtArg
->GetText();
315 /*************************************************************************
316 #* Member: SetArgName Datum:13.01.97
317 #*------------------------------------------------------------------------
321 #* Funktion: Setzt den Namen fuer das Argument
327 #************************************************************************/
328 void ArgInput::SetArgNameFont (const Font
&aFont
)
330 if(pFtArg
!=NULL
) pFtArg
->SetFont(aFont
);
333 /*************************************************************************
334 #* Member: SetArgSelection Datum:13.01.97
335 #*------------------------------------------------------------------------
339 #* Funktion: Stellt die Selection fuer die EditBox ein.
345 #************************************************************************/
346 void ArgInput::SetArgSelection (const Selection
& rSel
)
348 if(pEdArg
!=NULL
) pEdArg
->SetSelection(rSel
);
351 /*************************************************************************
352 #* Member: SetArgSelection Datum:13.01.97
353 #*------------------------------------------------------------------------
357 #* Funktion: Liefert die Selection fuer die EditBox zurueck.
363 #************************************************************************/
364 Selection
ArgInput::GetArgSelection ()
367 if(pEdArg
!=NULL
) aSel
=pEdArg
->GetSelection();
371 /*************************************************************************
372 #* Member: SetArgSelection Datum:13.01.97
373 #*------------------------------------------------------------------------
377 #* Funktion: Ersetzt die Selection in der EditBox.
383 #************************************************************************/
384 void ArgInput::ReplaceSelOfArg(const String
& rStr
)
386 if(pEdArg
!=NULL
) pEdArg
->ReplaceSelected(rStr
);
391 /*************************************************************************
392 #* Member: SetArgVal Datum:13.01.97
393 #*------------------------------------------------------------------------
397 #* Funktion: Setzt den Wert fuer das Argument
403 #************************************************************************/
404 void ArgInput::SetArgVal(const String
&aVal
)
408 pEdArg
->SetRefString(aVal
);
412 /*************************************************************************
413 #* Member: SetArgName Datum:13.01.97
414 #*------------------------------------------------------------------------
418 #* Funktion: Liefert den Wert fuer das Argument
424 #************************************************************************/
425 String
ArgInput::GetArgVal()
430 aResult
=pEdArg
->GetText();
435 /*************************************************************************
436 #* Member: SetArgName Datum:13.01.97
437 #*------------------------------------------------------------------------
441 #* Funktion: Versteckt die Controls
447 #************************************************************************/
448 void ArgInput::Hide()
450 if ( pFtArg
&& pBtnFx
&& pEdArg
&& pRefBtn
)
459 /*************************************************************************
460 #* Member: SetArgName Datum:13.01.97
461 #*------------------------------------------------------------------------
465 #* Funktion: Zaubert die Controls wieder hervor.
471 #************************************************************************/
472 void ArgInput::Show()
474 if ( pFtArg
&& pBtnFx
&& pEdArg
&& pRefBtn
)
483 /*************************************************************************
484 #* Member: FxClick Datum:13.01.97
485 #*------------------------------------------------------------------------
489 #* Funktion: Gibt den Event weiter.
495 #************************************************************************/
496 void ArgInput::FxClick()
498 aFxClickLink
.Call(this);
501 /*************************************************************************
502 #* Member: RefClick Datum:13.01.97
503 #*------------------------------------------------------------------------
507 #* Funktion: Gibt den Event weiter.
513 #************************************************************************/
514 void ArgInput::RefClick()
516 aRefClickLink
.Call(this);
519 /*************************************************************************
520 #* Member: FxFocus Datum:13.01.97
521 #*------------------------------------------------------------------------
525 #* Funktion: Gibt den Event weiter.
531 #************************************************************************/
532 void ArgInput::FxFocus()
534 aFxFocusLink
.Call(this);
537 /*************************************************************************
538 #* Member: RefFocus Datum:13.01.97
539 #*------------------------------------------------------------------------
543 #* Funktion: Gibt den Event weiter.
549 #************************************************************************/
550 void ArgInput::RefFocus()
552 aRefFocusLink
.Call(this);
555 /*************************************************************************
556 #* Member: EdFocus Datum:13.01.97
557 #*------------------------------------------------------------------------
561 #* Funktion: Gibt den Event weiter.
567 #************************************************************************/
568 void ArgInput::EdFocus()
570 aEdFocusLink
.Call(this);
573 /*************************************************************************
574 #* Member: EdModify Datum:13.01.97
575 #*------------------------------------------------------------------------
579 #* Funktion: Gibt den Event weiter.
585 #************************************************************************/
586 void ArgInput::EdModify()
588 aEdModifyLink
.Call(this);
591 /*************************************************************************
592 #* Handle: FxBtnHdl Datum:13.01.97
593 #*------------------------------------------------------------------------
597 #* Funktion: Handle fuer Fx-Button Click-Event.
603 #************************************************************************/
604 IMPL_LINK( ArgInput
, FxBtnClickHdl
, ImageButton
*, pBtn
)
606 if(pBtn
==pBtnFx
) FxClick();
611 /*************************************************************************
612 #* Handle: RefBtnClickHdl Datum:13.01.97
613 #*------------------------------------------------------------------------
617 #* Funktion: Handle fuer Fx-Button Click-Event.
623 #************************************************************************/
624 IMPL_LINK( ArgInput
, RefBtnClickHdl
,RefButton
*, pBtn
)
626 if(pRefBtn
==pBtn
) RefClick();
631 /*************************************************************************
632 #* Handle: FxBtnFocusHdl Datum:13.01.97
633 #*------------------------------------------------------------------------
637 #* Funktion: Handle fuer Fx-Button Focus-Event.
643 #************************************************************************/
644 IMPL_LINK( ArgInput
, FxBtnFocusHdl
, ImageButton
*, pBtn
)
646 if(pBtn
==pBtnFx
) FxFocus();
651 /*************************************************************************
652 #* Handle: RefBtnFocusHdl Datum:13.01.97
653 #*------------------------------------------------------------------------
657 #* Funktion: Handle fuer Fx-Button Focus-Event.
663 #************************************************************************/
664 IMPL_LINK( ArgInput
, RefBtnFocusHdl
,RefButton
*, pBtn
)
666 if(pRefBtn
==pBtn
) RefFocus();
671 /*************************************************************************
672 #* Handle: EdFocusHdl Datum:13.01.97
673 #*------------------------------------------------------------------------
677 #* Funktion: Handle fuer Fx-Button Focus-Event.
683 #************************************************************************/
684 IMPL_LINK( ArgInput
, EdFocusHdl
, ArgEdit
*, pEd
)
686 if(pEd
==pEdArg
) EdFocus();
691 /*************************************************************************
692 #* Handle: RefBtnClickHdl Datum:13.01.97
693 #*------------------------------------------------------------------------
697 #* Funktion: Handle fuer Fx-Button Focus-Event.
703 #************************************************************************/
704 IMPL_LINK( ArgInput
, EdModifyHdl
,ArgEdit
*, pEd
)
706 if(pEd
==pEdArg
) EdModify();
711 /*************************************************************************
712 #* Member: EditBox Datum:20.01.97
713 #*------------------------------------------------------------------------
717 #* Funktion: Konstruktor der Klasse ArgInput
719 #* Input: Parent, Window-Style
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
);
731 aOldSel
=pMEdit
->GetSelection();
734 /*************************************************************************
735 #* Member: EditBox Datum:20.01.97
736 #*------------------------------------------------------------------------
740 #* Funktion: Konstruktor der Klasse ArgInput
742 #* Input: Parent, Resource
746 #************************************************************************/
747 EditBox::EditBox( Window
* pParent
, const ResId
& rResId
)
748 :Control(pParent
,rResId
),
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
);
757 aOldSel
=pMEdit
->GetSelection();
759 WinBits nWinStyle
=GetStyle() | WB_DIALOGCONTROL
;
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() );
770 MultiLineEdit
* pTheEdit
=pMEdit
;
775 /*************************************************************************
776 #* Member: EditBox Datum:20.01.97
777 #*------------------------------------------------------------------------
781 #* Funktion: Wenn sich die Selektion geaendert hat, so wird
782 #* diese Funktion aufgerufen.
788 #************************************************************************/
789 void EditBox::SelectionChanged()
791 aSelChangedLink
.Call(this);
794 /*************************************************************************
795 #* Member: EditBox Datum:20.05.98
796 #*------------------------------------------------------------------------
800 #* Funktion: Wenn sich die Groesse geaendert hat, so muss
801 #* auch der MultiLineEdit angepasst werden..
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 #*------------------------------------------------------------------------
820 #* Funktion: Wenn der Control aktiviert wird, so wird
821 #* die Selection aufgehoben und der Cursor ans
828 #************************************************************************/
829 void EditBox::GetFocus()
839 /*************************************************************************
840 #* Member: EditBox Datum:20.01.97
841 #*------------------------------------------------------------------------
845 #* Funktion: Wenn ein Event ausgeloest wird, so wird diese Routine
846 #* zuerst aufgerufen und ein PostUserEvent verschickt.
848 #* Input: Notify-Event
852 #************************************************************************/
853 long EditBox::PreNotify( NotifyEvent
& rNEvt
)
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
);
870 nResult
=Control::PreNotify(rNEvt
);
871 Application::PostUserEvent( LINK( this, EditBox
, ChangedHdl
) );
877 nResult
=Control::PreNotify(rNEvt
);
879 if(nSwitch
==EVENT_MOUSEBUTTONDOWN
|| nSwitch
==EVENT_MOUSEBUTTONUP
)
882 Application::PostUserEvent( LINK( this, EditBox
, ChangedHdl
) );
888 /*************************************************************************
889 #* Member: EditBox Datum:21.01.97
890 #*------------------------------------------------------------------------
894 #* Funktion: Wenn ein Event ausgeloest wurde, so wird diese Routine
895 #* zuerst aufgerufen.
901 #************************************************************************/
902 IMPL_LINK( EditBox
, ChangedHdl
, EditBox
*, EMPTYARG
)
906 Selection aNewSel
=pMEdit
->GetSelection();
908 if(aNewSel
.Min()!=aOldSel
.Min() || aNewSel
.Max()!=aOldSel
.Max())
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
923 aOldSel
= pMEdit
->GetSelection();
925 //----------------------------------------------------------------------------
927 //============================================================================
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
),
945 bSilentFocus( FALSE
)
951 aTimer
.SetTimeoutHdl( Link() );
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()
971 void RefEdit::SilentGrabFocus()
975 bSilentFocus
= FALSE
;
978 void RefEdit::SetRefDialog( IControlReferenceHandler
* pDlg
)
984 aTimer
.SetTimeoutHdl( LINK( this, RefEdit
, UpdateHdl
) );
985 aTimer
.SetTimeout( SC_ENABLE_TIME
);
989 aTimer
.SetTimeoutHdl( Link() );
994 void RefEdit::Modify()
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 );
1007 Edit::KeyInput( rKEvt
);
1010 void RefEdit::GetFocus()
1017 void RefEdit::LoseFocus()
1021 pAnyRefDlg
->HideReference();
1024 IMPL_LINK( RefEdit
, UpdateHdl
, Timer
*, EMPTYARG
)
1027 pAnyRefDlg
->ShowReference( GetText() );
1032 //============================================================================
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
) ),
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
),
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
)
1077 //----------------------------------------------------------------------------
1079 void RefButton::Click()
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
);
1091 ImageButton::KeyInput( rKEvt
);
1094 void RefButton::GetFocus()
1096 ImageButton::GetFocus();
1098 pRefEdit
->StartUpdateData();
1101 void RefButton::LoseFocus()
1103 ImageButton::LoseFocus();