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 <comphelper/string.hxx>
21 #include <svl/zforlist.hxx>
22 #include <svl/stritem.hxx>
24 #include "parawin.hxx"
25 #include "parawin.hrc"
26 #include "helpids.hrc"
27 #include "formula/formdata.hxx"
28 #include "formula/IFunctionDescription.hxx"
29 #include "ModuleHelper.hxx"
30 #include "ForResId.hrc"
33 #define PAIRED_VAR_ARGS (VAR_ARGS + VAR_ARGS)
36 //============================================================================
38 ParaWin::ParaWin(Window
* pParent
,IControlReferenceHandler
* _pDlg
,Point aPos
):
39 TabPage (pParent
,ModuleRes(RID_FORMULATAB_PARAMETER
)),
42 aFtEditDesc ( this, ModuleRes( FT_EDITDESC
) ),
43 aFtArgName ( this, ModuleRes( FT_PARNAME
) ),
44 aFtArgDesc ( this, ModuleRes( FT_PARDESC
) ),
46 aBtnFx1 ( this, ModuleRes( BTN_FX1
) ),
47 aFtArg1 ( this, ModuleRes( FT_ARG1
) ),
48 aEdArg1 ( this, ModuleRes( ED_ARG1
) ),
49 aRefBtn1 ( this, ModuleRes( RB_ARG1
) ),
51 aBtnFx2 ( this, ModuleRes( BTN_FX2
) ),
52 aFtArg2 ( this, ModuleRes( FT_ARG2
) ),
53 aEdArg2 ( this, ModuleRes( ED_ARG2
) ),
54 aRefBtn2 ( this, ModuleRes( RB_ARG2
) ),
56 aBtnFx3 ( this, ModuleRes( BTN_FX3
) ),
57 aFtArg3 ( this, ModuleRes( FT_ARG3
) ),
58 aEdArg3 ( this, ModuleRes( ED_ARG3
) ),
59 aRefBtn3 ( this, ModuleRes( RB_ARG3
) ),
61 aBtnFx4 ( this, ModuleRes( BTN_FX4
) ),
62 aFtArg4 ( this, ModuleRes( FT_ARG4
) ),
63 aEdArg4 ( this, ModuleRes( ED_ARG4
) ),
64 aRefBtn4 ( this, ModuleRes( RB_ARG4
) ),
66 aSlider ( this, ModuleRes( WND_SLIDER
) ),
67 m_sOptional ( ModuleRes( STR_OPTIONAL
) ),
68 m_sRequired ( ModuleRes( STR_REQUIRED
) ),
72 aDefaultString
=aFtEditDesc
.GetText();
77 Size aSize
= aSlider
.GetSizePixel();
78 aSize
.Width() = GetSettings().GetStyleSettings().GetScrollBarSize();
79 aSlider
.SetSizePixel( aSize
);
80 aSlider
.SetEndScrollHdl( LINK( this, ParaWin
, ScrollHdl
) );
81 aSlider
.SetScrollHdl( LINK( this, ParaWin
, ScrollHdl
) );
83 InitArgInput( 0, aFtArg1
, aBtnFx1
, aEdArg1
, aRefBtn1
);
84 InitArgInput( 1, aFtArg2
, aBtnFx2
, aEdArg2
, aRefBtn2
);
85 InitArgInput( 2, aFtArg3
, aBtnFx3
, aEdArg3
, aRefBtn3
);
86 InitArgInput( 3, aFtArg4
, aBtnFx4
, aEdArg4
, aRefBtn4
);
90 void ParaWin::UpdateArgDesc( sal_uInt16 nArg
)
92 if (nArg
==NOT_FOUND
) return;
95 nArg
= sal::static_int_cast
<sal_uInt16
>( nArg
+ GetSliderPos() );
97 if ( (nArgs
> 0) && (nArg
<nArgs
) )
102 SetArgumentDesc( String() );
103 SetArgumentText( String() );
105 if ( nArgs
< VAR_ARGS
)
107 sal_uInt16 nRealArg
= (aVisibleArgMapping
.size() < nArg
) ? aVisibleArgMapping
[nArg
] : nArg
;
108 aArgDesc
= pFuncDesc
->getParameterDescription(nRealArg
);
109 aArgName
= pFuncDesc
->getParameterName(nRealArg
);
111 aArgName
+= (pFuncDesc
->isParameterOptional(nRealArg
)) ? m_sOptional
: m_sRequired
;
113 else if ( nArgs
< PAIRED_VAR_ARGS
)
115 sal_uInt16 nFix
= nArgs
- VAR_ARGS
;
116 sal_uInt16 nPos
= ( nArg
< nFix
? nArg
: nFix
);
117 sal_uInt16 nRealArg
= (nPos
< aVisibleArgMapping
.size() ?
118 aVisibleArgMapping
[nPos
] : aVisibleArgMapping
.back());
119 aArgDesc
= pFuncDesc
->getParameterDescription(nRealArg
);
120 aArgName
= pFuncDesc
->getParameterName(nRealArg
);
122 aArgName
+= String::CreateFromInt32(nArg
-nFix
+1);
125 aArgName
+= (nArg
> nFix
|| pFuncDesc
->isParameterOptional(nRealArg
)) ? m_sOptional
: m_sRequired
;
129 sal_uInt16 nFix
= nArgs
- PAIRED_VAR_ARGS
;
134 nPos
= nFix
+ ( (nArg
-nFix
) % 2);
135 sal_uInt16 nRealArg
= (nPos
< aVisibleArgMapping
.size() ?
136 aVisibleArgMapping
[nPos
] : aVisibleArgMapping
.back());
137 aArgDesc
= pFuncDesc
->getParameterDescription(nRealArg
);
138 aArgName
= pFuncDesc
->getParameterName(nRealArg
);
140 aArgName
+= String::CreateFromInt32((nArg
-nFix
)/2 + 1);
143 aArgName
+= (nArg
> (nFix
+1) || pFuncDesc
->isParameterOptional(nRealArg
)) ? m_sOptional
: m_sRequired
;
146 SetArgumentDesc(aArgDesc
);
147 SetArgumentText(aArgName
);
151 void ParaWin::UpdateArgInput( sal_uInt16 nOffset
, sal_uInt16 i
)
153 sal_uInt16 nArg
= nOffset
+ i
;
154 if ( nArgs
< VAR_ARGS
)
158 sal_uInt16 nRealArg
= aVisibleArgMapping
[nArg
];
159 SetArgNameFont (i
,(pFuncDesc
->isParameterOptional(nRealArg
))
160 ? aFntLight
: aFntBold
);
161 SetArgName (i
,pFuncDesc
->getParameterName(nRealArg
));
164 else if ( nArgs
< PAIRED_VAR_ARGS
)
166 sal_uInt16 nFix
= nArgs
- VAR_ARGS
;
167 sal_uInt16 nPos
= ( nArg
< nFix
? nArg
: nFix
);
168 sal_uInt16 nRealArg
= (nPos
< aVisibleArgMapping
.size() ?
169 aVisibleArgMapping
[nPos
] : aVisibleArgMapping
.back());
171 (nArg
> nFix
|| pFuncDesc
->isParameterOptional(nRealArg
)) ?
172 aFntLight
: aFntBold
);
175 String
aArgName( pFuncDesc
->getParameterName(nRealArg
) );
176 aArgName
+= String::CreateFromInt32(nArg
-nFix
+1);
177 SetArgName( i
, aArgName
);
180 SetArgName( i
, pFuncDesc
->getParameterName(nRealArg
) );
184 sal_uInt16 nFix
= nArgs
- PAIRED_VAR_ARGS
;
189 nPos
= nFix
+ ( (nArg
-nFix
) % 2);
190 sal_uInt16 nRealArg
= (nPos
< aVisibleArgMapping
.size() ?
191 aVisibleArgMapping
[nPos
] : aVisibleArgMapping
.back());
193 (nArg
> (nFix
+1) || pFuncDesc
->isParameterOptional(nRealArg
)) ?
194 aFntLight
: aFntBold
);
197 String
aArgName( pFuncDesc
->getParameterName(nRealArg
) );
198 aArgName
+= String::CreateFromInt32((nArg
-nFix
)/2 + 1);
199 SetArgName( i
, aArgName
);
202 SetArgName( i
, pFuncDesc
->getParameterName(nRealArg
) );
204 if(nArg
<nArgs
) SetArgVal(i
,aParaArray
[nArg
]);
210 // #i66422# if the focus changes during destruction of the controls,
211 // don't call the focus handlers
213 aBtnFx1
.SetGetFocusHdl( aEmptyLink
);
214 aBtnFx2
.SetGetFocusHdl( aEmptyLink
);
215 aBtnFx3
.SetGetFocusHdl( aEmptyLink
);
216 aBtnFx4
.SetGetFocusHdl( aEmptyLink
);
219 sal_uInt16
ParaWin::GetActiveLine()
224 void ParaWin::SetActiveLine(sal_uInt16 no
)
228 long nOffset
= GetSliderPos();
230 long nNewEdPos
=(long)nActiveLine
-nOffset
;
231 if(nNewEdPos
<0 || nNewEdPos
>3)
234 SetSliderPos((sal_uInt16
) nOffset
);
235 nOffset
=GetSliderPos();
237 nEdFocus
=no
-(sal_uInt16
)nOffset
;
238 UpdateArgDesc( nEdFocus
);
242 RefEdit
* ParaWin::GetActiveEdit()
244 if(nArgs
>0 && nEdFocus
!=NOT_FOUND
)
246 return aArgInput
[nEdFocus
].GetArgEdPtr();
255 String
ParaWin::GetArgument(sal_uInt16 no
)
258 if(no
<aParaArray
.size())
261 if(no
==nActiveLine
&& aStr
.Len()==0)
267 String
ParaWin::GetActiveArgName()
270 if(nArgs
>0 && nEdFocus
!=NOT_FOUND
)
272 aStr
=aArgInput
[nEdFocus
].GetArgName();
278 void ParaWin::SetArgument(sal_uInt16 no
, const String
& aString
)
280 if (no
< aParaArray
.size())
281 aParaArray
[no
] = comphelper::string::stripStart(aString
, ' ');
284 void ParaWin::DelParaArray()
286 ::std::vector
<String
>().swap(aParaArray
);
289 void ParaWin::SetArgumentFonts(const Font
&aBoldFont
,const Font
&aLightFont
)
292 aFntLight
=aLightFont
;
295 void ParaWin::SetFunctionDesc(const IFunctionDescription
* pFDesc
)
299 SetArgumentDesc( String() );
300 SetArgumentText( String() );
301 SetEditDesc( String() );
303 if ( pFuncDesc
!=NULL
)
305 if ( !pFuncDesc
->getDescription().isEmpty() )
307 SetEditDesc(pFuncDesc
->getDescription());
311 SetEditDesc(aDefaultString
);
313 nArgs
= pFuncDesc
->getSuppressedArgumentCount();
314 pFuncDesc
->fillVisibleArgumentMapping(aVisibleArgMapping
);
316 rtl::OString sHelpId
= pFuncDesc
->getHelpId();
317 SetHelpId( sHelpId
);
318 aEdArg1
.SetHelpId( sHelpId
);
319 aEdArg2
.SetHelpId( sHelpId
);
320 aEdArg3
.SetHelpId( sHelpId
);
321 aEdArg4
.SetHelpId( sHelpId
);
323 // Unique-IDs muessen gleich bleiben fuer Automatisierung
324 SetUniqueId( HID_FORMULA_FAP_PAGE
);
325 aEdArg1
.SetUniqueId( HID_FORMULA_FAP_EDIT1
);
326 aEdArg2
.SetUniqueId( HID_FORMULA_FAP_EDIT2
);
327 aEdArg3
.SetUniqueId( HID_FORMULA_FAP_EDIT3
);
328 aEdArg4
.SetUniqueId( HID_FORMULA_FAP_EDIT4
);
338 void ParaWin::SetArgumentText(const String
& aText
)
340 aFtArgName
.SetText(aText
);
343 void ParaWin::SetArgumentDesc(const String
& aText
)
345 aFtArgDesc
.SetText(aText
);
348 void ParaWin::SetEditDesc(const String
& aText
)
350 aFtEditDesc
.SetText(aText
);
353 void ParaWin::SetArgName(sal_uInt16 no
,const String
& aText
)
355 aArgInput
[no
].SetArgName(aText
);
358 void ParaWin::SetArgNameFont(sal_uInt16 no
,const Font
& aFont
)
360 aArgInput
[no
].SetArgNameFont(aFont
);
363 void ParaWin::SetArgVal(sal_uInt16 no
,const String
& aText
)
365 aArgInput
[no
].SetArgVal(aText
);
368 void ParaWin::HideParaLine(sal_uInt16 no
)
370 aArgInput
[no
].Hide();
373 void ParaWin::ShowParaLine(sal_uInt16 no
)
375 aArgInput
[no
].Show();
378 void ParaWin::SetEdFocus(sal_uInt16 no
)
381 if(no
<4 && no
<aParaArray
.size())
382 aArgInput
[no
].GetArgEdPtr()->GrabFocus();
386 void ParaWin::InitArgInput( sal_uInt16 nPos
, FixedText
& rFtArg
, ImageButton
& rBtnFx
,
387 ArgEdit
& rEdArg
, RefButton
& rRefBtn
)
390 rRefBtn
.SetReferences(pMyParent
,&rEdArg
);
391 rEdArg
.SetRefDialog(pMyParent
);
393 aArgInput
[nPos
].InitArgInput (&rFtArg
,&rBtnFx
,&rEdArg
,&rRefBtn
);
395 aArgInput
[nPos
].Hide();
397 aArgInput
[nPos
].SetFxClickHdl ( LINK( this, ParaWin
, GetFxHdl
) );
398 aArgInput
[nPos
].SetFxFocusHdl ( LINK( this, ParaWin
, GetFxFocusHdl
) );
399 aArgInput
[nPos
].SetEdFocusHdl ( LINK( this, ParaWin
, GetEdFocusHdl
) );
400 aArgInput
[nPos
].SetEdModifyHdl ( LINK( this, ParaWin
, ModifyHdl
) );
403 void ParaWin::ClearAll()
405 SetFunctionDesc(NULL
);
406 SetArgumentOffset(0);
409 void ParaWin::SetArgumentOffset(sal_uInt16 nOffset
)
412 aSlider
.SetThumbPos(0);
414 aParaArray
.resize(nArgs
);
418 for ( int i
=0; i
<4 && i
<nArgs
; i
++ )
421 aArgInput
[i
].SetArgVal(aString
);
422 aArgInput
[i
].GetArgEdPtr()->Init(
423 (i
==0) ? (ArgEdit
*)NULL
: aArgInput
[i
-1].GetArgEdPtr(),
424 (i
==3 || i
==nArgs
-1) ? (ArgEdit
*)NULL
: aArgInput
[i
+1].GetArgEdPtr(),
435 aSlider
.SetPageSize( 4 );
436 aSlider
.SetVisibleSize( 4 );
437 aSlider
.SetLineSize( 1 );
438 aSlider
.SetRange( Range( 0, nArgs
) );
439 aSlider
.SetThumbPos( nOffset
);
446 void ParaWin::UpdateParas()
449 sal_uInt16 nOffset
= GetSliderPos();
453 for ( i
=0; (i
<nArgs
) && (i
<4); i
++ )
455 UpdateArgInput( nOffset
, i
);
460 for ( i
=nArgs
; i
<4; i
++ ) HideParaLine(i
);
464 sal_uInt16
ParaWin::GetSliderPos()
466 return (sal_uInt16
) aSlider
.GetThumbPos();
469 void ParaWin::SetSliderPos(sal_uInt16 nSliderPos
)
471 sal_uInt16 nOffset
= GetSliderPos();
473 if(aSlider
.IsVisible() && nOffset
!=nSliderPos
)
475 aSlider
.SetThumbPos(nSliderPos
);
476 for ( sal_uInt16 i
=0; i
<4; i
++ )
478 UpdateArgInput( nSliderPos
, i
);
483 void ParaWin::SliderMoved()
485 sal_uInt16 nOffset
= GetSliderPos();
487 for ( sal_uInt16 i
=0; i
<4; i
++ )
489 UpdateArgInput( nOffset
, i
);
491 if(nEdFocus
!=NOT_FOUND
)
493 UpdateArgDesc( nEdFocus
);
494 aArgInput
[nEdFocus
].SetArgSelection(Selection(0,SELECTION_MAX
));
495 nActiveLine
=nEdFocus
+nOffset
;
498 aScrollLink
.Call(this);
501 void ParaWin::ArgumentModified()
503 aArgModifiedLink
.Call(this);
506 void ParaWin::FxClick()
512 IMPL_LINK( ParaWin
, GetFxHdl
, ArgInput
*, pPtr
)
514 sal_uInt16 nOffset
= GetSliderPos();
516 for ( sal_uInt16 nPos
=0; nPos
<5;nPos
++)
518 if(pPtr
== &aArgInput
[nPos
])
525 if(nEdFocus
!=NOT_FOUND
)
527 aArgInput
[nEdFocus
].SetArgSelection(Selection(0,SELECTION_MAX
));
528 nActiveLine
=nEdFocus
+nOffset
;
534 IMPL_LINK( ParaWin
, GetFxFocusHdl
, ArgInput
*, pPtr
)
536 sal_uInt16 nOffset
= GetSliderPos();
538 for ( sal_uInt16 nPos
=0; nPos
<5;nPos
++)
540 if(pPtr
== &aArgInput
[nPos
])
547 if(nEdFocus
!=NOT_FOUND
)
549 aArgInput
[nEdFocus
].SetArgSelection(Selection(0,SELECTION_MAX
));
550 UpdateArgDesc( nEdFocus
);
551 nActiveLine
=nEdFocus
+nOffset
;
558 IMPL_LINK( ParaWin
, GetEdFocusHdl
, ArgInput
*, pPtr
)
560 sal_uInt16 nOffset
= GetSliderPos();
562 for ( sal_uInt16 nPos
=0; nPos
<5;nPos
++)
564 if(pPtr
== &aArgInput
[nPos
])
571 if(nEdFocus
!=NOT_FOUND
)
573 aArgInput
[nEdFocus
].SetArgSelection(Selection(0,SELECTION_MAX
));
574 UpdateArgDesc( nEdFocus
);
575 nActiveLine
=nEdFocus
+nOffset
;
583 IMPL_LINK_NOARG(ParaWin
, ScrollHdl
)
590 IMPL_LINK( ParaWin
, ModifyHdl
, ArgInput
*, pPtr
)
592 sal_uInt16 nOffset
= GetSliderPos();
594 for ( sal_uInt16 nPos
=0; nPos
<5;nPos
++)
596 if(pPtr
== &aArgInput
[nPos
])
602 if(nEdFocus
!=NOT_FOUND
)
604 aParaArray
[nEdFocus
+nOffset
] = aArgInput
[nEdFocus
].GetArgVal();
605 UpdateArgDesc( nEdFocus
);
606 nActiveLine
=nEdFocus
+nOffset
;
617 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */