1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <vcl/builder.hxx>
21 #include <vcl/svapp.hxx>
22 #include <vcl/scrbar.hxx>
24 #include "formula/funcutl.hxx"
25 #include "formula/IControlReferenceHandler.hxx"
26 #include "ControlHelper.hxx"
27 #include "ModuleHelper.hxx"
28 #include "ForResId.hrc"
33 //============================================================================
35 //----------------------------------------------------------------------------
37 ValWnd::ValWnd( Window
* pParent
, const ResId
& rId
) : Window( pParent
, rId
)
39 Font
aFnt( GetFont() );
40 aFnt
.SetTransparent( sal_True
);
41 aFnt
.SetWeight( WEIGHT_LIGHT
);
42 if ( pParent
->IsBackground() )
44 Wallpaper aBack
= pParent
->GetBackground();
45 SetFillColor( aBack
.GetColor() );
46 SetBackground( aBack
);
47 aFnt
.SetFillColor( aBack
.GetColor() );
57 Size aSzWnd
= GetOutputSizePixel();
58 long nHeight
= GetTextHeight();
59 long nDiff
= aSzWnd
.Height()-nHeight
;
61 aRectOut
= Rectangle( Point( 1, ( nDiff
<2 ) ? 1 : nDiff
/2),
62 Size ( aSzWnd
.Width()-2, nHeight
) );
63 SetClipRegion( Region( aRectOut
) );
66 //----------------------------------------------------------------------------
68 void ValWnd::Paint( const Rectangle
& )
70 DrawText( aRectOut
.TopLeft(), aStrValue
);
73 //----------------------------------------------------------------------------
75 void ValWnd::SetValue( const String
& rStrVal
)
77 if ( aStrValue
!= rStrVal
)
80 DrawRect( aRectOut
); // alten Text loeschen
81 Paint( aRectOut
); // and neu malen
85 //============================================================================
87 //----------------------------------------------------------------------------
89 ArgEdit::ArgEdit( Window
* pParent
, const ResId
& rResId
)
90 : RefEdit( pParent
, NULL
, NULL
, rResId
),
98 //----------------------------------------------------------------------------
100 void ArgEdit::Init( ArgEdit
* pPrevEdit
, ArgEdit
* pNextEdit
,
101 ScrollBar
& rArgSlider
, sal_uInt16 nArgCount
)
105 pSlider
= &rArgSlider
;
109 //----------------------------------------------------------------------------
111 // Cursor control for Edit Fields in Argument Dialog
113 void ArgEdit::KeyInput( const KeyEvent
& rKEvt
)
115 KeyCode aCode
= rKEvt
.GetKeyCode();
116 sal_Bool bUp
= (aCode
.GetCode() == KEY_UP
);
117 sal_Bool bDown
= (aCode
.GetCode() == KEY_DOWN
);
120 && ( !aCode
.IsShift() && !aCode
.IsMod1() && !aCode
.IsMod2() )
121 && ( bUp
|| bDown
) )
126 long nThumb
= pSlider
->GetThumbPos();
127 sal_Bool bDoScroll
= sal_False
;
128 sal_Bool bChangeFocus
= sal_False
;
137 bDoScroll
= ( nThumb
+3 < (long)nArgs
);
142 bChangeFocus
= sal_True
;
148 bChangeFocus
= sal_True
;
158 bDoScroll
= ( nThumb
>= 0 );
163 bChangeFocus
= sal_True
;
169 bChangeFocus
= sal_True
;
175 pSlider
->SetThumbPos( nThumb
);
176 ((Link
&)pSlider
->GetEndScrollHdl()).Call( pSlider
);
178 else if ( bChangeFocus
)
185 RefEdit::KeyInput( rKEvt
);
191 /*************************************************************************
192 #* Member: ArgInput Date:13.01.97
193 #*------------------------------------------------------------------------
197 #* Function: ArgInput class constructor
203 #************************************************************************/
213 /*************************************************************************
214 #* Member: InitArgInput Date:13.01.97
215 #*------------------------------------------------------------------------
219 #* Function: Initializes the class' Pointer
225 #************************************************************************/
227 void ArgInput::InitArgInput(FixedText
* pftArg
,
239 pBtnFx
->SetClickHdl ( LINK( this, ArgInput
, FxBtnClickHdl
) );
240 pBtnFx
->SetGetFocusHdl( LINK( this, ArgInput
, FxBtnFocusHdl
) );
244 pRefBtn
->SetClickHdl ( LINK( this, ArgInput
, RefBtnClickHdl
) );
245 pRefBtn
->SetGetFocusHdl( LINK( this, ArgInput
, RefBtnFocusHdl
) );
249 pEdArg
->SetGetFocusHdl ( LINK( this, ArgInput
, EdFocusHdl
) );
250 pEdArg
->SetModifyHdl ( LINK( this, ArgInput
, EdModifyHdl
) );
255 /*************************************************************************
256 #* Member: SetArgName Date:13.01.97
257 #*------------------------------------------------------------------------
261 #* Function: Sets the Name for the Argument
267 #************************************************************************/
268 void ArgInput::SetArgName(const String
&aArg
)
270 if(pFtArg
!=NULL
) pFtArg
->SetText(aArg
);
273 /*************************************************************************
274 #* Member: GetArgName Date:06.02.97
275 #*------------------------------------------------------------------------
279 #* Function: Returns the Name for the Argument
285 #************************************************************************/
286 String
ArgInput::GetArgName()
290 aPrivArgName
=pFtArg
->GetText();
295 /*************************************************************************
296 #* Member: SetArgName Date:13.01.97
297 #*------------------------------------------------------------------------
301 #* Function: Sets the Name for the Argument
307 #************************************************************************/
308 void ArgInput::SetArgNameFont (const Font
&aFont
)
310 if(pFtArg
!=NULL
) pFtArg
->SetFont(aFont
);
313 /*************************************************************************
314 #* Member: SetArgSelection Date:13.01.97
315 #*------------------------------------------------------------------------
319 #* Function: Sets up the Selection for the EditBox.
325 #************************************************************************/
326 void ArgInput::SetArgSelection (const Selection
& rSel
)
328 if(pEdArg
!=NULL
) pEdArg
->SetSelection(rSel
);
332 /*************************************************************************
333 #* Member: SetArgVal Date:13.01.97
334 #*------------------------------------------------------------------------
338 #* Function: Sets the Value for the Argument
344 #************************************************************************/
345 void ArgInput::SetArgVal(const String
&aVal
)
349 pEdArg
->SetRefString(aVal
);
353 /*************************************************************************
354 #* Member: SetArgName Date:13.01.97
355 #*------------------------------------------------------------------------
359 #* Function: Returns the Value for the Argument
365 #************************************************************************/
366 String
ArgInput::GetArgVal()
371 aResult
=pEdArg
->GetText();
376 /*************************************************************************
377 #* Member: SetArgName Date:13.01.97
378 #*------------------------------------------------------------------------
382 #* Function: Hides the Controls
388 #************************************************************************/
389 void ArgInput::Hide()
391 if ( pFtArg
&& pBtnFx
&& pEdArg
&& pRefBtn
)
400 /*************************************************************************
401 #* Member: SetArgName Date:13.01.97
402 #*------------------------------------------------------------------------
406 #* Function: Casts the Controls again.
412 #************************************************************************/
413 void ArgInput::Show()
415 if ( pFtArg
&& pBtnFx
&& pEdArg
&& pRefBtn
)
424 /*************************************************************************
425 #* Member: FxClick Date:13.01.97
426 #*------------------------------------------------------------------------
430 #* Function: Forwards the Event.
436 #************************************************************************/
437 void ArgInput::FxClick()
439 aFxClickLink
.Call(this);
442 /*************************************************************************
443 #* Member: RefClick Date:13.01.97
444 #*------------------------------------------------------------------------
448 #* Function: Forwards the Event.
454 #************************************************************************/
455 void ArgInput::RefClick()
457 aRefClickLink
.Call(this);
460 /*************************************************************************
461 #* Member: FxFocus Date:13.01.97
462 #*------------------------------------------------------------------------
466 #* Function: Forwards the Event.
472 #************************************************************************/
473 void ArgInput::FxFocus()
475 aFxFocusLink
.Call(this);
478 /*************************************************************************
479 #* Member: RefFocus Date:13.01.97
480 #*------------------------------------------------------------------------
484 #* Function: Forwards the Event.
490 #************************************************************************/
491 void ArgInput::RefFocus()
493 aRefFocusLink
.Call(this);
496 /*************************************************************************
497 #* Member: EdFocus Date:13.01.97
498 #*------------------------------------------------------------------------
502 #* Function: Forwards the Event.
508 #************************************************************************/
509 void ArgInput::EdFocus()
511 aEdFocusLink
.Call(this);
514 /*************************************************************************
515 #* Member: EdModify Date:13.01.97
516 #*------------------------------------------------------------------------
520 #* Function: Forwards the Event.
526 #************************************************************************/
527 void ArgInput::EdModify()
529 aEdModifyLink
.Call(this);
532 /*************************************************************************
533 #* Handle: FxBtnHdl Date:13.01.97
534 #*------------------------------------------------------------------------
538 #* Function: Handle for Fx-Button Click-Event.
544 #************************************************************************/
545 IMPL_LINK( ArgInput
, FxBtnClickHdl
, ImageButton
*, pBtn
)
547 if(pBtn
==pBtnFx
) FxClick();
552 /*************************************************************************
553 #* Handle: RefBtnClickHdl Date:13.01.97
554 #*------------------------------------------------------------------------
558 #* Function: Handle for Fx-Button Click-Event.
564 #************************************************************************/
565 IMPL_LINK( ArgInput
, RefBtnClickHdl
,RefButton
*, pBtn
)
567 if(pRefBtn
==pBtn
) RefClick();
572 /*************************************************************************
573 #* Handle: FxBtnFocusHdl Date:13.01.97
574 #*------------------------------------------------------------------------
578 #* Function: Handle for Fx-Button Focus-Event.
584 #************************************************************************/
585 IMPL_LINK( ArgInput
, FxBtnFocusHdl
, ImageButton
*, pBtn
)
587 if(pBtn
==pBtnFx
) FxFocus();
592 /*************************************************************************
593 #* Handle: RefBtnFocusHdl Date:13.01.97
594 #*------------------------------------------------------------------------
598 #* Function: Handle for Fx-Button Focus-Event.
604 #************************************************************************/
605 IMPL_LINK( ArgInput
, RefBtnFocusHdl
,RefButton
*, pBtn
)
607 if(pRefBtn
==pBtn
) RefFocus();
612 /*************************************************************************
613 #* Handle: EdFocusHdl Date:13.01.97
614 #*------------------------------------------------------------------------
618 #* Function: Handle for Fx-Button Focus-Event.
624 #************************************************************************/
625 IMPL_LINK( ArgInput
, EdFocusHdl
, ArgEdit
*, pEd
)
627 if(pEd
==pEdArg
) EdFocus();
632 /*************************************************************************
633 #* Handle: RefBtnClickHdl Date:13.01.97
634 #*------------------------------------------------------------------------
638 #* Function: Handle for Fx-Button Focus-Event.
644 #************************************************************************/
645 IMPL_LINK( ArgInput
, EdModifyHdl
,ArgEdit
*, pEd
)
647 if(pEd
==pEdArg
) EdModify();
652 /*************************************************************************
653 #* Member: EditBox Date:20.01.97
654 #*------------------------------------------------------------------------
658 #* Function: Constructor from Class ArgInput
660 #* Input: Parent, Resource
664 #************************************************************************/
665 EditBox::EditBox( Window
* pParent
, const ResId
& rResId
)
666 :Control(pParent
,rResId
),
667 bMouseFlag(sal_False
)
669 WinBits nStyle
=GetStyle();
670 SetStyle( nStyle
| WB_DIALOGCONTROL
);
672 pMEdit
=new MultiLineEdit(this,WB_LEFT
| WB_VSCROLL
| (nStyle
& WB_TABSTOP
) |
673 WB_NOBORDER
| WB_NOHIDESELECTION
| WB_IGNORETAB
);
675 aOldSel
=pMEdit
->GetSelection();
677 WinBits nWinStyle
=GetStyle() | WB_DIALOGCONTROL
;
680 // #105582# the HelpId from the resource must be set for the MultiLineEdit,
681 // not for the control that contains it.
682 pMEdit
->SetHelpId( GetHelpId() );
688 MultiLineEdit
* pTheEdit
=pMEdit
;
693 /*************************************************************************
694 #* Member: EditBox Date:20.01.97
695 #*------------------------------------------------------------------------
699 #* Function: When the seleccion is changed this function will be called
705 #************************************************************************/
706 void EditBox::SelectionChanged()
708 aSelChangedLink
.Call(this);
711 /*************************************************************************
712 #* Member: EditBox Date:20.05.98
713 #*------------------------------------------------------------------------
717 #* Function: When the size is changed, MultiLineEdit must
724 #************************************************************************/
725 void EditBox::Resize()
727 Size aSize
=GetOutputSizePixel();
728 if(pMEdit
!=NULL
) pMEdit
->SetOutputSizePixel(aSize
);
731 /*************************************************************************
732 #* Member: GetFocus Date:26.05.98
733 #*------------------------------------------------------------------------
737 #* Function: When the Control is activated,
738 #* the Selection is repealed and the Cursor set
745 #************************************************************************/
746 void EditBox::GetFocus()
756 /*************************************************************************
757 #* Member: EditBox Date:20.01.97
758 #*------------------------------------------------------------------------
762 #* Function: When an Event is cleared, this Routine is
763 #* first called and a PostUserEvent is sent.
765 #* Input: Notify-Event
769 #************************************************************************/
770 long EditBox::PreNotify( NotifyEvent
& rNEvt
)
772 long nResult
=sal_True
;
774 if(pMEdit
==NULL
) return nResult
;
776 sal_uInt16 nSwitch
=rNEvt
.GetType();
777 if(nSwitch
==EVENT_KEYINPUT
)// || nSwitch==EVENT_KEYUP)
779 const KeyCode
& aKeyCode
=rNEvt
.GetKeyEvent()->GetKeyCode();
780 sal_uInt16 nKey
=aKeyCode
.GetCode();
781 if( (nKey
==KEY_RETURN
&& !aKeyCode
.IsShift()) || nKey
==KEY_TAB
)
783 nResult
=GetParent()->Notify(rNEvt
);
787 nResult
=Control::PreNotify(rNEvt
);
788 Application::PostUserEvent( LINK( this, EditBox
, ChangedHdl
) );
794 nResult
=Control::PreNotify(rNEvt
);
796 if(nSwitch
==EVENT_MOUSEBUTTONDOWN
|| nSwitch
==EVENT_MOUSEBUTTONUP
)
799 Application::PostUserEvent( LINK( this, EditBox
, ChangedHdl
) );
805 /*************************************************************************
806 #* Member: EditBox Date:21.01.97
807 #*------------------------------------------------------------------------
811 #* Function: When an Event cleared wurde, this routine is
818 #************************************************************************/
819 IMPL_LINK_NOARG(EditBox
, ChangedHdl
)
823 Selection aNewSel
=pMEdit
->GetSelection();
825 if(aNewSel
.Min()!=aOldSel
.Min() || aNewSel
.Max()!=aOldSel
.Max())
834 void EditBox::UpdateOldSel()
836 // if selection is set for editing a function, store it as aOldSel,
837 // so SelectionChanged isn't called in the next ChangedHdl call
840 aOldSel
= pMEdit
->GetSelection();
842 //----------------------------------------------------------------------------
844 //============================================================================
846 //----------------------------------------------------------------------------
848 #define SC_ENABLE_TIME 100
850 RefEdit::RefEdit( Window
* _pParent
,IControlReferenceHandler
* pParent
,
851 Window
* pShrinkModeLabel
, const ResId
& rResId
)
852 : Edit( _pParent
, rResId
)
853 , pAnyRefDlg( pParent
)
854 , pLabelWidget(pShrinkModeLabel
)
856 aTimer
.SetTimeoutHdl( LINK( this, RefEdit
, UpdateHdl
) );
857 aTimer
.SetTimeout( SC_ENABLE_TIME
);
860 RefEdit::RefEdit( Window
* _pParent
, Window
* pShrinkModeLabel
, WinBits nStyle
)
861 : Edit( _pParent
, nStyle
)
863 , pLabelWidget(pShrinkModeLabel
)
865 aTimer
.SetTimeoutHdl( LINK( this, RefEdit
, UpdateHdl
) );
866 aTimer
.SetTimeout( SC_ENABLE_TIME
);
869 extern "C" SAL_DLLPUBLIC_EXPORT Window
* SAL_CALL
makeRefEdit(Window
*pParent
, VclBuilder::stringmap
&)
871 return new RefEdit(pParent
, NULL
, WB_BORDER
);
876 aTimer
.SetTimeoutHdl( Link() );
880 void RefEdit::SetRefString( const XubString
& rStr
)
882 Edit::SetText( rStr
);
885 void RefEdit::SetRefValid(bool bValid
)
889 SetControlForeground();
890 SetControlBackground();
894 SetControlForeground(COL_WHITE
);
895 SetControlBackground(0xff6563);
899 void RefEdit::SetText( const XubString
& rStr
)
901 Edit::SetText( rStr
);
902 UpdateHdl( &aTimer
);
905 void RefEdit::StartUpdateData()
910 void RefEdit::SetReferences( IControlReferenceHandler
* pDlg
, Window
* pLabel
)
913 pLabelWidget
= pLabel
;
917 aTimer
.SetTimeoutHdl( LINK( this, RefEdit
, UpdateHdl
) );
918 aTimer
.SetTimeout( SC_ENABLE_TIME
);
922 aTimer
.SetTimeoutHdl( Link() );
927 void RefEdit::Modify()
931 pAnyRefDlg
->HideReference();
934 void RefEdit::KeyInput( const KeyEvent
& rKEvt
)
936 const KeyCode
& rKeyCode
= rKEvt
.GetKeyCode();
937 if( pAnyRefDlg
&& !rKeyCode
.GetModifier() && (rKeyCode
.GetCode() == KEY_F2
) )
938 pAnyRefDlg
->ReleaseFocus( this );
940 Edit::KeyInput( rKEvt
);
943 void RefEdit::GetFocus()
949 void RefEdit::LoseFocus()
953 pAnyRefDlg
->HideReference();
956 IMPL_LINK_NOARG(RefEdit
, UpdateHdl
)
959 pAnyRefDlg
->ShowReference( GetText() );
964 //============================================================================
966 //----------------------------------------------------------------------------
967 RefButton::RefButton( Window
* _pParent
, const ResId
& rResId
) :
968 ImageButton( _pParent
, rResId
),
969 aImgRefStart( ModuleRes( RID_BMP_REFBTN1
) ),
970 aImgRefDone( ModuleRes( RID_BMP_REFBTN2
) ),
971 aShrinkQuickHelp( ModuleRes( RID_STR_SHRINK
).toString() ),
972 aExpandQuickHelp( ModuleRes( RID_STR_EXPAND
).toString() ),
979 RefButton::RefButton( Window
* _pParent
, WinBits nStyle
) :
980 ImageButton( _pParent
, nStyle
),
981 aImgRefStart( ModuleRes( RID_BMP_REFBTN1
) ),
982 aImgRefDone( ModuleRes( RID_BMP_REFBTN2
) ),
983 aShrinkQuickHelp( ModuleRes( RID_STR_SHRINK
).toString() ),
984 aExpandQuickHelp( ModuleRes( RID_STR_EXPAND
).toString() ),
991 extern "C" SAL_DLLPUBLIC_EXPORT Window
* SAL_CALL
makeRefButton(Window
*pParent
, VclBuilder::stringmap
&)
993 return new RefButton(pParent
, 0);
996 RefButton::RefButton( Window
* _pParent
, const ResId
& rResId
, RefEdit
* pEdit
, IControlReferenceHandler
* _pDlg
) :
997 ImageButton( _pParent
, rResId
),
998 aImgRefStart( ModuleRes( RID_BMP_REFBTN1
) ),
999 aImgRefDone( ModuleRes( RID_BMP_REFBTN2
) ),
1000 aShrinkQuickHelp( ModuleRes( RID_STR_SHRINK
).toString() ),
1001 aExpandQuickHelp( ModuleRes( RID_STR_EXPAND
).toString() ),
1002 pAnyRefDlg( _pDlg
),
1008 void RefButton::SetStartImage()
1010 SetModeImage( aImgRefStart
);
1011 SetQuickHelpText( aShrinkQuickHelp
);
1014 void RefButton::SetEndImage()
1016 SetModeImage( aImgRefDone
);
1017 SetQuickHelpText( aExpandQuickHelp
);
1020 void RefButton::SetReferences( IControlReferenceHandler
* pDlg
, RefEdit
* pEdit
)
1026 //----------------------------------------------------------------------------
1028 void RefButton::Click()
1031 pAnyRefDlg
->ToggleCollapsed( pRefEdit
, this );
1034 void RefButton::KeyInput( const KeyEvent
& rKEvt
)
1036 const KeyCode
& rKeyCode
= rKEvt
.GetKeyCode();
1037 if( pAnyRefDlg
&& !rKeyCode
.GetModifier() && (rKeyCode
.GetCode() == KEY_F2
) )
1038 pAnyRefDlg
->ReleaseFocus( pRefEdit
);
1040 ImageButton::KeyInput( rKEvt
);
1043 void RefButton::GetFocus()
1045 ImageButton::GetFocus();
1047 pRefEdit
->StartUpdateData();
1050 void RefButton::LoseFocus()
1052 ImageButton::LoseFocus();
1060 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */