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>
23 #include <vcl/settings.hxx>
25 #include "parawin.hxx"
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)
38 ParaWin::ParaWin(vcl::Window
* pParent
,IControlReferenceHandler
* _pDlg
):
39 TabPage (pParent
, "ParameterPage", "formula/ui/parameter.ui"),
42 m_sOptional ( ModuleRes( STR_OPTIONAL
) ),
43 m_sRequired ( ModuleRes( STR_REQUIRED
) ),
46 get(m_pFtEditDesc
, "editdesc");
47 get(m_pFtArgName
, "parname");
48 get(m_pFtArgDesc
, "pardesc");
50 //Space for two lines of text
51 m_pFtArgDesc
->SetText("X\nX\n");
52 long nHeight
= m_pFtArgDesc
->GetOptimalSize().Height();
53 m_pFtEditDesc
->set_height_request(nHeight
);
54 m_pFtArgDesc
->set_height_request(nHeight
);
55 m_pFtArgDesc
->SetText("");
57 get(m_pBtnFx1
, "FX1");
58 m_pBtnFx1
->SetModeImage(Image(ModuleRes( BMP_FX
)));
59 get(m_pBtnFx2
, "FX2");
60 m_pBtnFx2
->SetModeImage(Image(ModuleRes( BMP_FX
)));
61 get(m_pBtnFx3
, "FX3");
62 m_pBtnFx3
->SetModeImage(Image(ModuleRes( BMP_FX
)));
63 get(m_pBtnFx4
, "FX4");
64 m_pBtnFx4
->SetModeImage(Image(ModuleRes( BMP_FX
)));
66 get(m_pFtArg1
, "FT_ARG1");
67 get(m_pFtArg2
, "FT_ARG2");
68 get(m_pFtArg3
, "FT_ARG3");
69 get(m_pFtArg4
, "FT_ARG4");
71 get(m_pEdArg1
, "ED_ARG1");
72 get(m_pEdArg2
, "ED_ARG2");
73 get(m_pEdArg3
, "ED_ARG3");
74 get(m_pEdArg4
, "ED_ARG4");
76 get(m_pRefBtn1
, "RB_ARG1");
77 get(m_pRefBtn2
, "RB_ARG2");
78 get(m_pRefBtn3
, "RB_ARG3");
79 get(m_pRefBtn4
, "RB_ARG4");
81 get(m_pSlider
, "scrollbar");
83 //lock down initial preferences
84 vcl::Window
*pGrid
= get
<vcl::Window
>("paramgrid");
85 pGrid
->set_height_request(pGrid
->get_preferred_size().Height());
86 Size
aSize(get_preferred_size());
87 set_width_request(aSize
.Width());
88 set_height_request(aSize
.Height());
90 aDefaultString
=m_pFtEditDesc
->GetText();
94 m_pSlider
->SetEndScrollHdl( LINK( this, ParaWin
, ScrollHdl
) );
95 m_pSlider
->SetScrollHdl( LINK( this, ParaWin
, ScrollHdl
) );
97 InitArgInput( 0, *m_pFtArg1
, *m_pBtnFx1
, *m_pEdArg1
, *m_pRefBtn1
);
98 InitArgInput( 1, *m_pFtArg2
, *m_pBtnFx2
, *m_pEdArg2
, *m_pRefBtn2
);
99 InitArgInput( 2, *m_pFtArg3
, *m_pBtnFx3
, *m_pEdArg3
, *m_pRefBtn3
);
100 InitArgInput( 3, *m_pFtArg4
, *m_pBtnFx4
, *m_pEdArg4
, *m_pRefBtn4
);
104 void ParaWin::UpdateArgDesc( sal_uInt16 nArg
)
106 if (nArg
==NOT_FOUND
) return;
109 nArg
= sal::static_int_cast
<sal_uInt16
>( nArg
+ GetSliderPos() );
111 if ( (nArgs
> 0) && (nArg
<nArgs
) )
116 SetArgumentDesc( OUString() );
117 SetArgumentText( OUString() );
119 if ( nArgs
< VAR_ARGS
)
121 sal_uInt16 nRealArg
= (aVisibleArgMapping
.size() < nArg
) ? aVisibleArgMapping
[nArg
] : nArg
;
122 aArgDesc
= pFuncDesc
->getParameterDescription(nRealArg
);
123 aArgName
= pFuncDesc
->getParameterName(nRealArg
);
125 aArgName
+= (pFuncDesc
->isParameterOptional(nRealArg
)) ? m_sOptional
: m_sRequired
;
127 else if ( nArgs
< PAIRED_VAR_ARGS
)
129 sal_uInt16 nFix
= nArgs
- VAR_ARGS
;
130 sal_uInt16 nPos
= ( nArg
< nFix
? nArg
: nFix
);
131 sal_uInt16 nRealArg
= (nPos
< aVisibleArgMapping
.size() ?
132 aVisibleArgMapping
[nPos
] : aVisibleArgMapping
.back());
133 aArgDesc
= pFuncDesc
->getParameterDescription(nRealArg
);
134 aArgName
= pFuncDesc
->getParameterName(nRealArg
);
136 aArgName
+= OUString::number( nArg
-nFix
+1 );
139 aArgName
+= (nArg
> nFix
|| pFuncDesc
->isParameterOptional(nRealArg
)) ? m_sOptional
: m_sRequired
;
143 sal_uInt16 nFix
= nArgs
- PAIRED_VAR_ARGS
;
148 nPos
= nFix
+ ( (nArg
-nFix
) % 2);
149 sal_uInt16 nRealArg
= (nPos
< aVisibleArgMapping
.size() ?
150 aVisibleArgMapping
[nPos
] : aVisibleArgMapping
.back());
151 aArgDesc
= pFuncDesc
->getParameterDescription(nRealArg
);
152 aArgName
= pFuncDesc
->getParameterName(nRealArg
);
154 aArgName
+= OUString::number( (nArg
-nFix
)/2 + 1 );
157 aArgName
+= (nArg
> (nFix
+1) || pFuncDesc
->isParameterOptional(nRealArg
)) ? m_sOptional
: m_sRequired
;
160 SetArgumentDesc(aArgDesc
);
161 SetArgumentText(aArgName
);
165 void ParaWin::UpdateArgInput( sal_uInt16 nOffset
, sal_uInt16 i
)
167 sal_uInt16 nArg
= nOffset
+ i
;
168 if ( nArgs
< VAR_ARGS
)
172 sal_uInt16 nRealArg
= aVisibleArgMapping
[nArg
];
173 SetArgNameFont (i
,(pFuncDesc
->isParameterOptional(nRealArg
))
174 ? aFntLight
: aFntBold
);
175 SetArgName (i
,pFuncDesc
->getParameterName(nRealArg
));
178 else if ( nArgs
< PAIRED_VAR_ARGS
)
180 sal_uInt16 nFix
= nArgs
- VAR_ARGS
;
181 sal_uInt16 nPos
= ( nArg
< nFix
? nArg
: nFix
);
182 sal_uInt16 nRealArg
= (nPos
< aVisibleArgMapping
.size() ?
183 aVisibleArgMapping
[nPos
] : aVisibleArgMapping
.back());
185 (nArg
> nFix
|| pFuncDesc
->isParameterOptional(nRealArg
)) ?
186 aFntLight
: aFntBold
);
189 OUString
aArgName( pFuncDesc
->getParameterName(nRealArg
) );
190 aArgName
+= OUString::number(nArg
-nFix
+1);
191 SetArgName( i
, aArgName
);
194 SetArgName( i
, pFuncDesc
->getParameterName(nRealArg
) );
198 sal_uInt16 nFix
= nArgs
- PAIRED_VAR_ARGS
;
203 nPos
= nFix
+ ( (nArg
-nFix
) % 2);
204 sal_uInt16 nRealArg
= (nPos
< aVisibleArgMapping
.size() ?
205 aVisibleArgMapping
[nPos
] : aVisibleArgMapping
.back());
207 (nArg
> (nFix
+1) || pFuncDesc
->isParameterOptional(nRealArg
)) ?
208 aFntLight
: aFntBold
);
211 OUString
aArgName( pFuncDesc
->getParameterName(nRealArg
) );
212 aArgName
+= OUString::number( (nArg
-nFix
)/2 + 1 );
213 SetArgName( i
, aArgName
);
216 SetArgName( i
, pFuncDesc
->getParameterName(nRealArg
) );
218 if(nArg
<nArgs
) SetArgVal(i
,aParaArray
[nArg
]);
227 void ParaWin::dispose()
229 // #i66422# if the focus changes during destruction of the controls,
230 // don't call the focus handlers
232 m_pBtnFx1
->SetGetFocusHdl( aEmptyLink
);
233 m_pBtnFx2
->SetGetFocusHdl( aEmptyLink
);
234 m_pBtnFx3
->SetGetFocusHdl( aEmptyLink
);
235 m_pBtnFx4
->SetGetFocusHdl( aEmptyLink
);
236 m_pFtEditDesc
.clear();
237 m_pFtArgName
.clear();
238 m_pFtArgDesc
.clear();
260 void ParaWin::SetActiveLine(sal_uInt16 no
)
264 long nOffset
= GetSliderPos();
266 long nNewEdPos
=(long)nActiveLine
-nOffset
;
267 if(nNewEdPos
<0 || nNewEdPos
>3)
270 SetSliderPos((sal_uInt16
) nOffset
);
271 nOffset
=GetSliderPos();
273 nEdFocus
=no
-(sal_uInt16
)nOffset
;
274 UpdateArgDesc( nEdFocus
);
278 RefEdit
* ParaWin::GetActiveEdit()
280 if(nArgs
>0 && nEdFocus
!=NOT_FOUND
)
282 return aArgInput
[nEdFocus
].GetArgEdPtr();
291 OUString
ParaWin::GetArgument(sal_uInt16 no
)
294 if(no
<aParaArray
.size())
297 if(no
==nActiveLine
&& aStr
.isEmpty())
303 OUString
ParaWin::GetActiveArgName()
306 if(nArgs
>0 && nEdFocus
!=NOT_FOUND
)
308 aStr
=aArgInput
[nEdFocus
].GetArgName();
314 void ParaWin::SetArgument(sal_uInt16 no
, const OUString
& aString
)
316 if (no
< aParaArray
.size())
317 aParaArray
[no
] = comphelper::string::stripStart(aString
, ' ');
320 void ParaWin::DelParaArray()
322 ::std::vector
<OUString
>().swap(aParaArray
);
325 void ParaWin::SetArgumentFonts(const vcl::Font
&aBoldFont
,const vcl::Font
&aLightFont
)
328 aFntLight
=aLightFont
;
331 void ParaWin::SetFunctionDesc(const IFunctionDescription
* pFDesc
)
335 SetArgumentDesc( OUString() );
336 SetArgumentText( OUString() );
337 SetEditDesc( OUString() );
339 if ( pFuncDesc
!=NULL
)
341 if ( !pFuncDesc
->getDescription().isEmpty() )
343 SetEditDesc(pFuncDesc
->getDescription());
347 SetEditDesc(aDefaultString
);
349 nArgs
= pFuncDesc
->getSuppressedArgumentCount();
350 pFuncDesc
->fillVisibleArgumentMapping(aVisibleArgMapping
);
352 OString sHelpId
= pFuncDesc
->getHelpId();
353 SetHelpId( sHelpId
);
354 m_pEdArg1
->SetHelpId( sHelpId
);
355 m_pEdArg2
->SetHelpId( sHelpId
);
356 m_pEdArg3
->SetHelpId( sHelpId
);
357 m_pEdArg4
->SetHelpId( sHelpId
);
359 // Unique-IDs muessen gleich bleiben fuer Automatisierung
360 SetUniqueId( HID_FORMULA_FAP_PAGE
);
361 m_pEdArg1
->SetUniqueId( HID_FORMULA_FAP_EDIT1
);
362 m_pEdArg2
->SetUniqueId( HID_FORMULA_FAP_EDIT2
);
363 m_pEdArg3
->SetUniqueId( HID_FORMULA_FAP_EDIT3
);
364 m_pEdArg4
->SetUniqueId( HID_FORMULA_FAP_EDIT4
);
374 void ParaWin::SetArgumentText(const OUString
& aText
)
376 m_pFtArgName
->SetText(aText
);
379 void ParaWin::SetArgumentDesc(const OUString
& aText
)
381 m_pFtArgDesc
->SetText(aText
);
384 void ParaWin::SetEditDesc(const OUString
& aText
)
386 m_pFtEditDesc
->SetText(aText
);
389 void ParaWin::SetArgName(sal_uInt16 no
,const OUString
& aText
)
391 aArgInput
[no
].SetArgName(aText
);
392 aArgInput
[no
].UpdateAccessibleNames();
395 void ParaWin::SetArgNameFont(sal_uInt16 no
,const vcl::Font
& aFont
)
397 aArgInput
[no
].SetArgNameFont(aFont
);
400 void ParaWin::SetArgVal(sal_uInt16 no
,const OUString
& aText
)
402 aArgInput
[no
].SetArgVal(aText
);
405 void ParaWin::HideParaLine(sal_uInt16 no
)
407 aArgInput
[no
].Hide();
410 void ParaWin::ShowParaLine(sal_uInt16 no
)
412 aArgInput
[no
].Show();
415 void ParaWin::SetEdFocus(sal_uInt16 no
)
418 if(no
<4 && no
<aParaArray
.size())
419 aArgInput
[no
].GetArgEdPtr()->GrabFocus();
423 void ParaWin::InitArgInput( sal_uInt16 nPos
, FixedText
& rFtArg
, PushButton
& rBtnFx
,
424 ArgEdit
& rEdArg
, RefButton
& rRefBtn
)
427 rRefBtn
.SetReferences(pMyParent
, &rEdArg
);
428 rEdArg
.SetReferences(pMyParent
, &rFtArg
);
430 aArgInput
[nPos
].InitArgInput (&rFtArg
,&rBtnFx
,&rEdArg
,&rRefBtn
);
432 aArgInput
[nPos
].Hide();
434 aArgInput
[nPos
].SetFxClickHdl ( LINK( this, ParaWin
, GetFxHdl
) );
435 aArgInput
[nPos
].SetFxFocusHdl ( LINK( this, ParaWin
, GetFxFocusHdl
) );
436 aArgInput
[nPos
].SetEdFocusHdl ( LINK( this, ParaWin
, GetEdFocusHdl
) );
437 aArgInput
[nPos
].SetEdModifyHdl ( LINK( this, ParaWin
, ModifyHdl
) );
438 aArgInput
[nPos
].UpdateAccessibleNames();
441 void ParaWin::ClearAll()
443 SetFunctionDesc(NULL
);
444 SetArgumentOffset(0);
447 void ParaWin::SetArgumentOffset(sal_uInt16 nOffset
)
450 m_pSlider
->SetThumbPos(0);
452 aParaArray
.resize(nArgs
);
456 for ( int i
=0; i
<4 && i
<nArgs
; i
++ )
459 aArgInput
[i
].SetArgVal(aString
);
460 aArgInput
[i
].GetArgEdPtr()->Init(
461 (i
==0) ? (ArgEdit
*)NULL
: aArgInput
[i
-1].GetArgEdPtr(),
462 (i
==3 || i
==nArgs
-1) ? (ArgEdit
*)NULL
: aArgInput
[i
+1].GetArgEdPtr(),
473 m_pSlider
->SetPageSize( 4 );
474 m_pSlider
->SetVisibleSize( 4 );
475 m_pSlider
->SetLineSize( 1 );
476 m_pSlider
->SetRange( Range( 0, nArgs
) );
477 m_pSlider
->SetThumbPos( nOffset
);
484 void ParaWin::UpdateParas()
487 sal_uInt16 nOffset
= GetSliderPos();
491 for ( i
=0; (i
<nArgs
) && (i
<4); i
++ )
493 UpdateArgInput( nOffset
, i
);
498 for ( i
=nArgs
; i
<4; i
++ ) HideParaLine(i
);
502 sal_uInt16
ParaWin::GetSliderPos()
504 return (sal_uInt16
) m_pSlider
->GetThumbPos();
507 void ParaWin::SetSliderPos(sal_uInt16 nSliderPos
)
509 sal_uInt16 nOffset
= GetSliderPos();
511 if(m_pSlider
->IsVisible() && nOffset
!=nSliderPos
)
513 m_pSlider
->SetThumbPos(nSliderPos
);
514 for ( sal_uInt16 i
=0; i
<4; i
++ )
516 UpdateArgInput( nSliderPos
, i
);
521 void ParaWin::SliderMoved()
523 sal_uInt16 nOffset
= GetSliderPos();
525 for ( sal_uInt16 i
=0; i
<4; i
++ )
527 UpdateArgInput( nOffset
, i
);
529 if(nEdFocus
!=NOT_FOUND
)
531 UpdateArgDesc( nEdFocus
);
532 aArgInput
[nEdFocus
].SetArgSelection(Selection(0,SELECTION_MAX
));
533 nActiveLine
=nEdFocus
+nOffset
;
535 aArgInput
[nEdFocus
].UpdateAccessibleNames();
537 aScrollLink
.Call(this);
540 void ParaWin::ArgumentModified()
542 aArgModifiedLink
.Call(this);
545 void ParaWin::FxClick()
551 IMPL_LINK( ParaWin
, GetFxHdl
, ArgInput
*, pPtr
)
553 sal_uInt16 nOffset
= GetSliderPos();
555 for (sal_uInt16 nPos
=0; nPos
< SAL_N_ELEMENTS(aArgInput
); ++nPos
)
557 if(pPtr
== &aArgInput
[nPos
])
564 if(nEdFocus
!=NOT_FOUND
)
566 aArgInput
[nEdFocus
].SetArgSelection(Selection(0,SELECTION_MAX
));
567 nActiveLine
=nEdFocus
+nOffset
;
573 IMPL_LINK( ParaWin
, GetFxFocusHdl
, ArgInput
*, pPtr
)
575 sal_uInt16 nOffset
= GetSliderPos();
577 for (sal_uInt16 nPos
=0; nPos
< SAL_N_ELEMENTS(aArgInput
); ++nPos
)
579 if(pPtr
== &aArgInput
[nPos
])
586 if(nEdFocus
!=NOT_FOUND
)
588 aArgInput
[nEdFocus
].SetArgSelection(Selection(0,SELECTION_MAX
));
589 UpdateArgDesc( nEdFocus
);
590 nActiveLine
=nEdFocus
+nOffset
;
597 IMPL_LINK( ParaWin
, GetEdFocusHdl
, ArgInput
*, pPtr
)
599 sal_uInt16 nOffset
= GetSliderPos();
601 for (sal_uInt16 nPos
=0; nPos
< SAL_N_ELEMENTS(aArgInput
); ++nPos
)
603 if(pPtr
== &aArgInput
[nPos
])
610 if(nEdFocus
!=NOT_FOUND
)
612 aArgInput
[nEdFocus
].SetArgSelection(Selection(0,SELECTION_MAX
));
613 UpdateArgDesc( nEdFocus
);
614 nActiveLine
=nEdFocus
+nOffset
;
616 aArgInput
[nEdFocus
].UpdateAccessibleNames();
623 IMPL_LINK_NOARG(ParaWin
, ScrollHdl
)
630 IMPL_LINK( ParaWin
, ModifyHdl
, ArgInput
*, pPtr
)
632 sal_uInt16 nOffset
= GetSliderPos();
634 for (sal_uInt16 nPos
=0; nPos
< SAL_N_ELEMENTS(aArgInput
); ++nPos
)
636 if(pPtr
== &aArgInput
[nPos
])
642 if(nEdFocus
!=NOT_FOUND
)
644 aParaArray
[nEdFocus
+nOffset
] = aArgInput
[nEdFocus
].GetArgVal();
645 UpdateArgDesc( nEdFocus
);
646 nActiveLine
=nEdFocus
+nOffset
;
657 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */