fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / formula / source / ui / dlg / parawin.cxx
blobf990deae1472a36f6670f979e4ae991177190c62
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
32 #define VAR_ARGS 30
33 #define PAIRED_VAR_ARGS (VAR_ARGS + VAR_ARGS)
34 namespace formula
38 ParaWin::ParaWin(vcl::Window* pParent,IControlReferenceHandler* _pDlg):
39 TabPage (pParent, "ParameterPage", "formula/ui/parameter.ui"),
40 pFuncDesc ( NULL ),
41 pMyParent (_pDlg),
42 m_sOptional ( ModuleRes( STR_OPTIONAL ) ),
43 m_sRequired ( ModuleRes( STR_REQUIRED ) ),
44 bRefMode (false)
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();
91 nEdFocus=NOT_FOUND;
92 nActiveLine=0;
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);
101 ClearAll();
104 void ParaWin::UpdateArgDesc( sal_uInt16 nArg )
106 if (nArg==NOT_FOUND) return;
108 if ( nArgs > 4 )
109 nArg = sal::static_int_cast<sal_uInt16>( nArg + GetSliderPos() );
111 if ( (nArgs > 0) && (nArg<nArgs) )
113 OUString aArgDesc;
114 OUString aArgName;
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);
124 aArgName += " ";
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);
135 if ( nArg >= nFix )
136 aArgName += OUString::number( nArg-nFix+1 );
137 aArgName += " ";
139 aArgName += (nArg > nFix || pFuncDesc->isParameterOptional(nRealArg)) ? m_sOptional : m_sRequired ;
141 else
143 sal_uInt16 nFix = nArgs - PAIRED_VAR_ARGS;
144 sal_uInt16 nPos;
145 if ( nArg < nFix )
146 nPos = nArg;
147 else
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);
153 if ( nArg >= nFix )
154 aArgName += OUString::number( (nArg-nFix)/2 + 1 );
155 aArgName += " ";
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)
170 if(nArg<nArgs)
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());
184 SetArgNameFont( i,
185 (nArg > nFix || pFuncDesc->isParameterOptional(nRealArg)) ?
186 aFntLight : aFntBold );
187 if ( nArg >= nFix )
189 OUString aArgName( pFuncDesc->getParameterName(nRealArg) );
190 aArgName += OUString::number(nArg-nFix+1);
191 SetArgName( i, aArgName );
193 else
194 SetArgName( i, pFuncDesc->getParameterName(nRealArg) );
196 else
198 sal_uInt16 nFix = nArgs - PAIRED_VAR_ARGS;
199 sal_uInt16 nPos;
200 if ( nArg < nFix )
201 nPos = nArg;
202 else
203 nPos = nFix + ( (nArg-nFix) % 2);
204 sal_uInt16 nRealArg = (nPos < aVisibleArgMapping.size() ?
205 aVisibleArgMapping[nPos] : aVisibleArgMapping.back());
206 SetArgNameFont( i,
207 (nArg > (nFix+1) || pFuncDesc->isParameterOptional(nRealArg)) ?
208 aFntLight : aFntBold );
209 if ( nArg >= nFix )
211 OUString aArgName( pFuncDesc->getParameterName(nRealArg) );
212 aArgName += OUString::number( (nArg-nFix)/2 + 1 );
213 SetArgName( i, aArgName );
215 else
216 SetArgName( i, pFuncDesc->getParameterName(nRealArg) );
218 if(nArg<nArgs) SetArgVal(i,aParaArray[nArg]);
222 ParaWin::~ParaWin()
224 disposeOnce();
227 void ParaWin::dispose()
229 // #i66422# if the focus changes during destruction of the controls,
230 // don't call the focus handlers
231 Link<> aEmptyLink;
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();
239 m_pBtnFx1.clear();
240 m_pFtArg1.clear();
241 m_pEdArg1.clear();
242 m_pRefBtn1.clear();
243 m_pBtnFx2.clear();
244 m_pFtArg2.clear();
245 m_pEdArg2.clear();
246 m_pRefBtn2.clear();
247 m_pBtnFx3.clear();
248 m_pFtArg3.clear();
249 m_pEdArg3.clear();
250 m_pRefBtn3.clear();
251 m_pBtnFx4.clear();
252 m_pFtArg4.clear();
253 m_pEdArg4.clear();
254 m_pRefBtn4.clear();
255 m_pSlider.clear();
256 TabPage::dispose();
260 void ParaWin::SetActiveLine(sal_uInt16 no)
262 if(no<nArgs)
264 long nOffset = GetSliderPos();
265 nActiveLine=no;
266 long nNewEdPos=(long)nActiveLine-nOffset;
267 if(nNewEdPos<0 || nNewEdPos>3)
269 nOffset+=nNewEdPos;
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();
284 else
286 return NULL;
291 OUString ParaWin::GetArgument(sal_uInt16 no)
293 OUString aStr;
294 if(no<aParaArray.size())
296 aStr=aParaArray[no];
297 if(no==nActiveLine && aStr.isEmpty())
298 aStr += " ";
300 return aStr;
303 OUString ParaWin::GetActiveArgName()
305 OUString aStr;
306 if(nArgs>0 && nEdFocus!=NOT_FOUND)
308 aStr=aArgInput[nEdFocus].GetArgName();
310 return aStr;
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)
327 aFntBold=aBoldFont;
328 aFntLight=aLightFont;
331 void ParaWin::SetFunctionDesc(const IFunctionDescription* pFDesc)
333 pFuncDesc=pFDesc;
335 SetArgumentDesc( OUString() );
336 SetArgumentText( OUString() );
337 SetEditDesc( OUString() );
338 nArgs = 0;
339 if ( pFuncDesc!=NULL)
341 if ( !pFuncDesc->getDescription().isEmpty() )
343 SetEditDesc(pFuncDesc->getDescription());
345 else
347 SetEditDesc(aDefaultString);
349 nArgs = pFuncDesc->getSuppressedArgumentCount();
350 pFuncDesc->fillVisibleArgumentMapping(aVisibleArgMapping);
351 m_pSlider->Hide();
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 );
365 SetActiveLine(0);
367 else
369 nActiveLine=0;
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)
417 UpdateArgDesc(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)
449 DelParaArray();
450 m_pSlider->SetThumbPos(0);
452 aParaArray.resize(nArgs);
454 if ( nArgs > 0 )
456 for ( int i=0; i<4 && i<nArgs; i++ )
458 OUString aString;
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(),
463 *m_pSlider, nArgs );
467 if ( nArgs < 5 )
469 m_pSlider->Hide();
471 else
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 );
478 m_pSlider->Show();
481 UpdateParas();
484 void ParaWin::UpdateParas()
486 sal_uInt16 i;
487 sal_uInt16 nOffset = GetSliderPos();
489 if ( nArgs > 0 )
491 for ( i=0; (i<nArgs) && (i<4); i++ )
493 UpdateArgInput( nOffset, i );
494 ShowParaLine(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;
534 ArgumentModified();
535 aArgInput[nEdFocus].UpdateAccessibleNames();
537 aScrollLink.Call(this);
540 void ParaWin::ArgumentModified()
542 aArgModifiedLink.Call(this);
545 void ParaWin::FxClick()
547 aFxLink.Call(this);
551 IMPL_LINK( ParaWin, GetFxHdl, ArgInput*, pPtr )
553 sal_uInt16 nOffset = GetSliderPos();
554 nEdFocus=NOT_FOUND;
555 for (sal_uInt16 nPos=0; nPos < SAL_N_ELEMENTS(aArgInput); ++nPos)
557 if(pPtr == &aArgInput[nPos])
559 nEdFocus=nPos;
560 break;
564 if(nEdFocus!=NOT_FOUND)
566 aArgInput[nEdFocus].SetArgSelection(Selection(0,SELECTION_MAX ));
567 nActiveLine=nEdFocus+nOffset;
568 FxClick();
570 return 0;
573 IMPL_LINK( ParaWin, GetFxFocusHdl, ArgInput*, pPtr )
575 sal_uInt16 nOffset = GetSliderPos();
576 nEdFocus=NOT_FOUND;
577 for (sal_uInt16 nPos=0; nPos < SAL_N_ELEMENTS(aArgInput); ++nPos)
579 if(pPtr == &aArgInput[nPos])
581 nEdFocus=nPos;
582 break;
586 if(nEdFocus!=NOT_FOUND)
588 aArgInput[nEdFocus].SetArgSelection(Selection(0,SELECTION_MAX ));
589 UpdateArgDesc( nEdFocus );
590 nActiveLine=nEdFocus+nOffset;
592 return 0;
597 IMPL_LINK( ParaWin, GetEdFocusHdl, ArgInput*, pPtr )
599 sal_uInt16 nOffset = GetSliderPos();
600 nEdFocus=NOT_FOUND;
601 for (sal_uInt16 nPos=0; nPos < SAL_N_ELEMENTS(aArgInput); ++nPos)
603 if(pPtr == &aArgInput[nPos])
605 nEdFocus=nPos;
606 break;
610 if(nEdFocus!=NOT_FOUND)
612 aArgInput[nEdFocus].SetArgSelection(Selection(0,SELECTION_MAX ));
613 UpdateArgDesc( nEdFocus );
614 nActiveLine=nEdFocus+nOffset;
615 ArgumentModified();
616 aArgInput[nEdFocus].UpdateAccessibleNames();
619 return 0;
623 IMPL_LINK_NOARG(ParaWin, ScrollHdl)
625 SliderMoved();
627 return 0;
630 IMPL_LINK( ParaWin, ModifyHdl, ArgInput*, pPtr )
632 sal_uInt16 nOffset = GetSliderPos();
633 nEdFocus=NOT_FOUND;
634 for (sal_uInt16 nPos=0; nPos < SAL_N_ELEMENTS(aArgInput); ++nPos)
636 if(pPtr == &aArgInput[nPos])
638 nEdFocus=nPos;
639 break;
642 if(nEdFocus!=NOT_FOUND)
644 aParaArray[nEdFocus+nOffset] = aArgInput[nEdFocus].GetArgVal();
645 UpdateArgDesc( nEdFocus);
646 nActiveLine=nEdFocus+nOffset;
649 ArgumentModified();
650 return 0;
655 } // formula
657 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */