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/svapp.hxx>
21 #include <vcl/scrbar.hxx>
23 #include "formula/funcutl.hxx"
24 #include "formula/IControlReferenceHandler.hxx"
25 #include "ControlHelper.hxx"
26 #include "ModuleHelper.hxx"
27 #include "ForResId.hrc"
32 //============================================================================
34 //----------------------------------------------------------------------------
36 ValWnd::ValWnd( Window
* pParent
, const ResId
& rId
) : Window( pParent
, rId
)
38 Font
aFnt( GetFont() );
39 aFnt
.SetTransparent( sal_True
);
40 aFnt
.SetWeight( WEIGHT_LIGHT
);
41 if ( pParent
->IsBackground() )
43 Wallpaper aBack
= pParent
->GetBackground();
44 SetFillColor( aBack
.GetColor() );
45 SetBackground( aBack
);
46 aFnt
.SetFillColor( aBack
.GetColor() );
56 Size aSzWnd
= GetOutputSizePixel();
57 long nHeight
= GetTextHeight();
58 long nDiff
= aSzWnd
.Height()-nHeight
;
60 aRectOut
= Rectangle( Point( 1, ( nDiff
<2 ) ? 1 : nDiff
/2),
61 Size ( aSzWnd
.Width()-2, nHeight
) );
62 SetClipRegion( Region( aRectOut
) );
65 //----------------------------------------------------------------------------
67 void ValWnd::Paint( const Rectangle
& )
69 DrawText( aRectOut
.TopLeft(), aStrValue
);
72 //----------------------------------------------------------------------------
74 void ValWnd::SetValue( const String
& rStrVal
)
76 if ( aStrValue
!= rStrVal
)
79 DrawRect( aRectOut
); // alten Text loeschen
80 Paint( aRectOut
); // and neu malen
84 //============================================================================
86 //----------------------------------------------------------------------------
88 ArgEdit::ArgEdit( Window
* pParent
, const ResId
& rResId
)
89 : RefEdit( pParent
, NULL
, rResId
),
97 //----------------------------------------------------------------------------
99 void ArgEdit::Init( ArgEdit
* pPrevEdit
, ArgEdit
* pNextEdit
,
100 ScrollBar
& rArgSlider
, sal_uInt16 nArgCount
)
104 pSlider
= &rArgSlider
;
108 //----------------------------------------------------------------------------
110 // Cursor control for Edit Fields in Argument Dialog
112 void ArgEdit::KeyInput( const KeyEvent
& rKEvt
)
114 KeyCode aCode
= rKEvt
.GetKeyCode();
115 sal_Bool bUp
= (aCode
.GetCode() == KEY_UP
);
116 sal_Bool bDown
= (aCode
.GetCode() == KEY_DOWN
);
120 && ( !aCode
.IsShift() && !aCode
.IsMod1() && !aCode
.IsMod2() )
121 && ( bUp
|| bDown
) )
125 long nThumb
= pSlider
->GetThumbPos();
126 sal_Bool bDoScroll
= sal_False
;
127 sal_Bool bChangeFocus
= sal_False
;
136 bDoScroll
= ( nThumb
+3 < (long)nArgs
);
141 bChangeFocus
= sal_True
;
147 bChangeFocus
= sal_True
;
157 bDoScroll
= ( nThumb
>= 0 );
162 bChangeFocus
= sal_True
;
168 bChangeFocus
= sal_True
;
174 pSlider
->SetThumbPos( nThumb
);
175 ((Link
&)pSlider
->GetEndScrollHdl()).Call( pSlider
);
177 else if ( bChangeFocus
)
184 RefEdit::KeyInput( rKEvt
);
190 /*************************************************************************
191 #* Member: ArgInput Date:13.01.97
192 #*------------------------------------------------------------------------
196 #* Function: ArgInput class constructor
202 #************************************************************************/
212 /*************************************************************************
213 #* Member: InitArgInput Date:13.01.97
214 #*------------------------------------------------------------------------
218 #* Function: Initializes the class' Pointer
224 #************************************************************************/
226 void ArgInput::InitArgInput(FixedText
* pftArg
,
238 pBtnFx
->SetClickHdl ( LINK( this, ArgInput
, FxBtnClickHdl
) );
239 pBtnFx
->SetGetFocusHdl( LINK( this, ArgInput
, FxBtnFocusHdl
) );
243 pRefBtn
->SetClickHdl ( LINK( this, ArgInput
, RefBtnClickHdl
) );
244 pRefBtn
->SetGetFocusHdl( LINK( this, ArgInput
, RefBtnFocusHdl
) );
248 pEdArg
->SetGetFocusHdl ( LINK( this, ArgInput
, EdFocusHdl
) );
249 pEdArg
->SetModifyHdl ( LINK( this, ArgInput
, EdModifyHdl
) );
254 /*************************************************************************
255 #* Member: SetArgName Date:13.01.97
256 #*------------------------------------------------------------------------
260 #* Function: Sets the Name for the Argument
266 #************************************************************************/
267 void ArgInput::SetArgName(const String
&aArg
)
269 if(pFtArg
!=NULL
) pFtArg
->SetText(aArg
);
272 /*************************************************************************
273 #* Member: GetArgName Date:06.02.97
274 #*------------------------------------------------------------------------
278 #* Function: Returns the Name for the Argument
284 #************************************************************************/
285 String
ArgInput::GetArgName()
289 aPrivArgName
=pFtArg
->GetText();
294 /*************************************************************************
295 #* Member: SetArgName Date:13.01.97
296 #*------------------------------------------------------------------------
300 #* Function: Sets the Name for the Argument
306 #************************************************************************/
307 void ArgInput::SetArgNameFont (const Font
&aFont
)
309 if(pFtArg
!=NULL
) pFtArg
->SetFont(aFont
);
312 /*************************************************************************
313 #* Member: SetArgSelection Date:13.01.97
314 #*------------------------------------------------------------------------
318 #* Function: Sets up the Selection for the EditBox.
324 #************************************************************************/
325 void ArgInput::SetArgSelection (const Selection
& rSel
)
327 if(pEdArg
!=NULL
) pEdArg
->SetSelection(rSel
);
331 /*************************************************************************
332 #* Member: SetArgVal Date:13.01.97
333 #*------------------------------------------------------------------------
337 #* Function: Sets the Value for the Argument
343 #************************************************************************/
344 void ArgInput::SetArgVal(const String
&aVal
)
348 pEdArg
->SetRefString(aVal
);
352 /*************************************************************************
353 #* Member: SetArgName Date:13.01.97
354 #*------------------------------------------------------------------------
358 #* Function: Returns the Value for the Argument
364 #************************************************************************/
365 String
ArgInput::GetArgVal()
370 aResult
=pEdArg
->GetText();
375 /*************************************************************************
376 #* Member: SetArgName Date:13.01.97
377 #*------------------------------------------------------------------------
381 #* Function: Hides the Controls
387 #************************************************************************/
388 void ArgInput::Hide()
390 if ( pFtArg
&& pBtnFx
&& pEdArg
&& pRefBtn
)
399 /*************************************************************************
400 #* Member: SetArgName Date:13.01.97
401 #*------------------------------------------------------------------------
405 #* Function: Casts the Controls again.
411 #************************************************************************/
412 void ArgInput::Show()
414 if ( pFtArg
&& pBtnFx
&& pEdArg
&& pRefBtn
)
423 /*************************************************************************
424 #* Member: FxClick Date:13.01.97
425 #*------------------------------------------------------------------------
429 #* Function: Forwards the Event.
435 #************************************************************************/
436 void ArgInput::FxClick()
438 aFxClickLink
.Call(this);
441 /*************************************************************************
442 #* Member: RefClick Date:13.01.97
443 #*------------------------------------------------------------------------
447 #* Function: Forwards the Event.
453 #************************************************************************/
454 void ArgInput::RefClick()
456 aRefClickLink
.Call(this);
459 /*************************************************************************
460 #* Member: FxFocus Date:13.01.97
461 #*------------------------------------------------------------------------
465 #* Function: Forwards the Event.
471 #************************************************************************/
472 void ArgInput::FxFocus()
474 aFxFocusLink
.Call(this);
477 /*************************************************************************
478 #* Member: RefFocus Date:13.01.97
479 #*------------------------------------------------------------------------
483 #* Function: Forwards the Event.
489 #************************************************************************/
490 void ArgInput::RefFocus()
492 aRefFocusLink
.Call(this);
495 /*************************************************************************
496 #* Member: EdFocus Date:13.01.97
497 #*------------------------------------------------------------------------
501 #* Function: Forwards the Event.
507 #************************************************************************/
508 void ArgInput::EdFocus()
510 aEdFocusLink
.Call(this);
513 /*************************************************************************
514 #* Member: EdModify Date:13.01.97
515 #*------------------------------------------------------------------------
519 #* Function: Forwards the Event.
525 #************************************************************************/
526 void ArgInput::EdModify()
528 aEdModifyLink
.Call(this);
531 /*************************************************************************
532 #* Handle: FxBtnHdl Date:13.01.97
533 #*------------------------------------------------------------------------
537 #* Function: Handle for Fx-Button Click-Event.
543 #************************************************************************/
544 IMPL_LINK( ArgInput
, FxBtnClickHdl
, ImageButton
*, pBtn
)
546 if(pBtn
==pBtnFx
) FxClick();
551 /*************************************************************************
552 #* Handle: RefBtnClickHdl Date:13.01.97
553 #*------------------------------------------------------------------------
557 #* Function: Handle for Fx-Button Click-Event.
563 #************************************************************************/
564 IMPL_LINK( ArgInput
, RefBtnClickHdl
,RefButton
*, pBtn
)
566 if(pRefBtn
==pBtn
) RefClick();
571 /*************************************************************************
572 #* Handle: FxBtnFocusHdl Date:13.01.97
573 #*------------------------------------------------------------------------
577 #* Function: Handle for Fx-Button Focus-Event.
583 #************************************************************************/
584 IMPL_LINK( ArgInput
, FxBtnFocusHdl
, ImageButton
*, pBtn
)
586 if(pBtn
==pBtnFx
) FxFocus();
591 /*************************************************************************
592 #* Handle: RefBtnFocusHdl Date:13.01.97
593 #*------------------------------------------------------------------------
597 #* Function: Handle for Fx-Button Focus-Event.
603 #************************************************************************/
604 IMPL_LINK( ArgInput
, RefBtnFocusHdl
,RefButton
*, pBtn
)
606 if(pRefBtn
==pBtn
) RefFocus();
611 /*************************************************************************
612 #* Handle: EdFocusHdl Date:13.01.97
613 #*------------------------------------------------------------------------
617 #* Function: Handle for Fx-Button Focus-Event.
623 #************************************************************************/
624 IMPL_LINK( ArgInput
, EdFocusHdl
, ArgEdit
*, pEd
)
626 if(pEd
==pEdArg
) EdFocus();
631 /*************************************************************************
632 #* Handle: RefBtnClickHdl Date:13.01.97
633 #*------------------------------------------------------------------------
637 #* Function: Handle for Fx-Button Focus-Event.
643 #************************************************************************/
644 IMPL_LINK( ArgInput
, EdModifyHdl
,ArgEdit
*, pEd
)
646 if(pEd
==pEdArg
) EdModify();
651 /*************************************************************************
652 #* Member: EditBox Date:20.01.97
653 #*------------------------------------------------------------------------
657 #* Function: Constructor from Class ArgInput
659 #* Input: Parent, Resource
663 #************************************************************************/
664 EditBox::EditBox( Window
* pParent
, const ResId
& rResId
)
665 :Control(pParent
,rResId
),
666 bMouseFlag(sal_False
)
668 WinBits nStyle
=GetStyle();
669 SetStyle( nStyle
| WB_DIALOGCONTROL
);
671 pMEdit
=new MultiLineEdit(this,WB_LEFT
| WB_VSCROLL
| (nStyle
& WB_TABSTOP
) |
672 WB_NOBORDER
| WB_NOHIDESELECTION
| WB_IGNORETAB
);
674 aOldSel
=pMEdit
->GetSelection();
676 WinBits nWinStyle
=GetStyle() | WB_DIALOGCONTROL
;
679 // #105582# the HelpId from the resource must be set for the MultiLineEdit,
680 // not for the control that contains it.
681 pMEdit
->SetHelpId( GetHelpId() );
687 MultiLineEdit
* pTheEdit
=pMEdit
;
692 /*************************************************************************
693 #* Member: EditBox Date:20.01.97
694 #*------------------------------------------------------------------------
698 #* Function: When the seleccion is changed this function will be called
704 #************************************************************************/
705 void EditBox::SelectionChanged()
707 aSelChangedLink
.Call(this);
710 /*************************************************************************
711 #* Member: EditBox Date:20.05.98
712 #*------------------------------------------------------------------------
716 #* Function: When the size is changed, MultiLineEdit must
723 #************************************************************************/
724 void EditBox::Resize()
726 Size aSize
=GetOutputSizePixel();
727 if(pMEdit
!=NULL
) pMEdit
->SetOutputSizePixel(aSize
);
730 /*************************************************************************
731 #* Member: GetFocus Date:26.05.98
732 #*------------------------------------------------------------------------
736 #* Function: When the Control is activated,
737 #* the Selection is repealed and the Cursor set
744 #************************************************************************/
745 void EditBox::GetFocus()
755 /*************************************************************************
756 #* Member: EditBox Date:20.01.97
757 #*------------------------------------------------------------------------
761 #* Function: When an Event is cleared, this Routine is
762 #* first called and a PostUserEvent is sent.
764 #* Input: Notify-Event
768 #************************************************************************/
769 long EditBox::PreNotify( NotifyEvent
& rNEvt
)
771 long nResult
=sal_True
;
773 if(pMEdit
==NULL
) return nResult
;
775 sal_uInt16 nSwitch
=rNEvt
.GetType();
776 if(nSwitch
==EVENT_KEYINPUT
)// || nSwitch==EVENT_KEYUP)
778 const KeyCode
& aKeyCode
=rNEvt
.GetKeyEvent()->GetKeyCode();
779 sal_uInt16 nKey
=aKeyCode
.GetCode();
780 if( (nKey
==KEY_RETURN
&& !aKeyCode
.IsShift()) || nKey
==KEY_TAB
)
782 nResult
=GetParent()->Notify(rNEvt
);
786 nResult
=Control::PreNotify(rNEvt
);
787 Application::PostUserEvent( LINK( this, EditBox
, ChangedHdl
) );
793 nResult
=Control::PreNotify(rNEvt
);
795 if(nSwitch
==EVENT_MOUSEBUTTONDOWN
|| nSwitch
==EVENT_MOUSEBUTTONUP
)
798 Application::PostUserEvent( LINK( this, EditBox
, ChangedHdl
) );
804 /*************************************************************************
805 #* Member: EditBox Date:21.01.97
806 #*------------------------------------------------------------------------
810 #* Function: When an Event cleared wurde, this routine is
817 #************************************************************************/
818 IMPL_LINK_NOARG(EditBox
, ChangedHdl
)
822 Selection aNewSel
=pMEdit
->GetSelection();
824 if(aNewSel
.Min()!=aOldSel
.Min() || aNewSel
.Max()!=aOldSel
.Max())
833 void EditBox::UpdateOldSel()
835 // if selection is set for editing a function, store it as aOldSel,
836 // so SelectionChanged isn't called in the next ChangedHdl call
839 aOldSel
= pMEdit
->GetSelection();
841 //----------------------------------------------------------------------------
843 //============================================================================
845 //----------------------------------------------------------------------------
847 #define SC_ENABLE_TIME 100
849 RefEdit::RefEdit( Window
* _pParent
,IControlReferenceHandler
* pParent
, const ResId
& rResId
) :
850 Edit( _pParent
, rResId
),
851 pAnyRefDlg( pParent
)
853 aTimer
.SetTimeoutHdl( LINK( this, RefEdit
, UpdateHdl
) );
854 aTimer
.SetTimeout( SC_ENABLE_TIME
);
859 aTimer
.SetTimeoutHdl( Link() );
863 void RefEdit::SetRefString( const XubString
& rStr
)
865 Edit::SetText( rStr
);
868 void RefEdit::SetRefValid(bool bValid
)
872 SetControlForeground();
873 SetControlBackground();
877 SetControlForeground(COL_WHITE
);
878 SetControlBackground(0xff6563);
882 void RefEdit::SetText( const XubString
& rStr
)
884 Edit::SetText( rStr
);
885 UpdateHdl( &aTimer
);
888 void RefEdit::StartUpdateData()
893 void RefEdit::SetRefDialog( IControlReferenceHandler
* pDlg
)
899 aTimer
.SetTimeoutHdl( LINK( this, RefEdit
, UpdateHdl
) );
900 aTimer
.SetTimeout( SC_ENABLE_TIME
);
904 aTimer
.SetTimeoutHdl( Link() );
909 void RefEdit::Modify()
913 pAnyRefDlg
->HideReference();
916 void RefEdit::KeyInput( const KeyEvent
& rKEvt
)
918 const KeyCode
& rKeyCode
= rKEvt
.GetKeyCode();
919 if( pAnyRefDlg
&& !rKeyCode
.GetModifier() && (rKeyCode
.GetCode() == KEY_F2
) )
920 pAnyRefDlg
->ReleaseFocus( this );
922 Edit::KeyInput( rKEvt
);
925 void RefEdit::GetFocus()
931 void RefEdit::LoseFocus()
935 pAnyRefDlg
->HideReference();
938 IMPL_LINK_NOARG(RefEdit
, UpdateHdl
)
941 pAnyRefDlg
->ShowReference( GetText() );
946 //============================================================================
948 //----------------------------------------------------------------------------
949 RefButton::RefButton( Window
* _pParent
, const ResId
& rResId
) :
950 ImageButton( _pParent
, rResId
),
951 aImgRefStart( ModuleRes( RID_BMP_REFBTN1
) ),
952 aImgRefDone( ModuleRes( RID_BMP_REFBTN2
) ),
959 RefButton::RefButton( Window
* _pParent
, const ResId
& rResId
, RefEdit
* pEdit
, IControlReferenceHandler
* _pDlg
) :
960 ImageButton( _pParent
, rResId
),
961 aImgRefStart( ModuleRes( RID_BMP_REFBTN1
) ),
962 aImgRefDone( ModuleRes( RID_BMP_REFBTN2
) ),
969 void RefButton::SetStartImage()
971 SetModeImage( aImgRefStart
);
974 void RefButton::SetEndImage()
976 SetModeImage( aImgRefDone
);
979 void RefButton::SetReferences( IControlReferenceHandler
* pDlg
, RefEdit
* pEdit
)
985 //----------------------------------------------------------------------------
987 void RefButton::Click()
990 pAnyRefDlg
->ToggleCollapsed( pRefEdit
, this );
993 void RefButton::KeyInput( const KeyEvent
& rKEvt
)
995 const KeyCode
& rKeyCode
= rKEvt
.GetKeyCode();
996 if( pAnyRefDlg
&& !rKeyCode
.GetModifier() && (rKeyCode
.GetCode() == KEY_F2
) )
997 pAnyRefDlg
->ReleaseFocus( pRefEdit
);
999 ImageButton::KeyInput( rKEvt
);
1002 void RefButton::GetFocus()
1004 ImageButton::GetFocus();
1006 pRefEdit
->StartUpdateData();
1009 void RefButton::LoseFocus()
1011 ImageButton::LoseFocus();
1019 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */