merge the formfield patch from ooo-build
[ooovba.git] / formula / source / ui / dlg / parawin.cxx
bloba0c26562a57ad695a125e6a340f75f607dc4f952
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: parawin.cxx,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_formula.hxx"
36 //----------------------------------------------------------------------------
38 #include <svtools/zforlist.hxx>
39 #include <svtools/stritem.hxx>
41 #include "parawin.hxx"
42 #include "parawin.hrc"
43 #include "helpids.hrc"
44 #include "formula/formdata.hxx"
45 #include "formula/IFunctionDescription.hxx"
46 #include "ModuleHelper.hxx"
47 #include "ForResId.hrc"
49 #define VAR_ARGS 30
50 namespace formula
52 //============================================================================
54 ParaWin::ParaWin(Window* pParent,IControlReferenceHandler* _pDlg,Point aPos):
55 TabPage (pParent,ModuleRes(RID_FORMULATAB_PARAMETER)),
56 pFuncDesc ( NULL ),
57 pMyParent (_pDlg),
58 aFtEditDesc ( this, ModuleRes( FT_EDITDESC ) ),
59 aFtArgName ( this, ModuleRes( FT_PARNAME ) ),
60 aFtArgDesc ( this, ModuleRes( FT_PARDESC ) ),
62 aFtArg1 ( this, ModuleRes( FT_ARG1 ) ),
63 aFtArg2 ( this, ModuleRes( FT_ARG2 ) ),
64 aFtArg3 ( this, ModuleRes( FT_ARG3 ) ),
65 aFtArg4 ( this, ModuleRes( FT_ARG4 ) ),
67 aBtnFx1 ( this, ModuleRes( BTN_FX1 ) ),
68 aBtnFx2 ( this, ModuleRes( BTN_FX2 ) ),
69 aBtnFx3 ( this, ModuleRes( BTN_FX3 ) ),
70 aBtnFx4 ( this, ModuleRes( BTN_FX4 ) ),
72 aEdArg1 ( this, ModuleRes( ED_ARG1 ) ),
73 aEdArg2 ( this, ModuleRes( ED_ARG2 ) ),
74 aEdArg3 ( this, ModuleRes( ED_ARG3 ) ),
75 aEdArg4 ( this, ModuleRes( ED_ARG4 ) ),
77 aRefBtn1 ( this, ModuleRes( RB_ARG1 ) ),
78 aRefBtn2 ( this, ModuleRes( RB_ARG2 ) ),
79 aRefBtn3 ( this, ModuleRes( RB_ARG3 ) ),
80 aRefBtn4 ( this, ModuleRes( RB_ARG4 ) ),
82 aSlider ( this, ModuleRes( WND_SLIDER ) ),
83 m_sOptional ( ModuleRes( STR_OPTIONAL ) ),
84 m_sRequired ( ModuleRes( STR_REQUIRED ) ),
85 bRefMode (FALSE)
87 Image aFxHC( ModuleRes( IMG_FX_H ) );
88 FreeResource();
89 aDefaultString=aFtEditDesc.GetText();
91 SetPosPixel(aPos);
92 nEdFocus=NOT_FOUND;
93 nActiveLine=0;
94 Size aSize = aSlider.GetSizePixel();
95 aSize.Width() = GetSettings().GetStyleSettings().GetScrollBarSize();
96 aSlider.SetSizePixel( aSize );
97 aSlider.SetEndScrollHdl( LINK( this, ParaWin, ScrollHdl ) );
98 aSlider.SetScrollHdl( LINK( this, ParaWin, ScrollHdl ) );
100 aBtnFx1.SetModeImage( aFxHC, BMP_COLOR_HIGHCONTRAST );
101 aBtnFx2.SetModeImage( aFxHC, BMP_COLOR_HIGHCONTRAST );
102 aBtnFx3.SetModeImage( aFxHC, BMP_COLOR_HIGHCONTRAST );
103 aBtnFx4.SetModeImage( aFxHC, BMP_COLOR_HIGHCONTRAST );
105 InitArgInput( 0, aFtArg1, aBtnFx1, aEdArg1, aRefBtn1);
106 InitArgInput( 1, aFtArg2, aBtnFx2, aEdArg2, aRefBtn2);
107 InitArgInput( 2, aFtArg3, aBtnFx3, aEdArg3, aRefBtn3);
108 InitArgInput( 3, aFtArg4, aBtnFx4, aEdArg4, aRefBtn4);
109 ClearAll();
112 void ParaWin::UpdateArgDesc( USHORT nArg )
114 if (nArg==NOT_FOUND) return;
116 if ( nArgs > 4 )
117 nArg = sal::static_int_cast<USHORT>( nArg + GetSliderPos() );
118 //@ nArg += (USHORT)aSlider.GetThumbPos();
120 if ( (nArgs > 0) && (nArg<nArgs) )
122 String aArgDesc;
123 String aArgName;
125 SetArgumentDesc( String() );
126 SetArgumentText( String() );
128 if ( nArgs < VAR_ARGS )
130 USHORT nRealArg = (aVisibleArgMapping.size() < nArg) ? aVisibleArgMapping[nArg] : nArg;
131 aArgDesc = pFuncDesc->getParameterDescription(nRealArg);
132 aArgName = pFuncDesc->getParameterName(nRealArg);
133 aArgName += ' ';
134 aArgName += (pFuncDesc->isParameterOptional(nRealArg)) ? m_sOptional : m_sRequired ;
136 else
138 USHORT nFix = nArgs - VAR_ARGS;
139 USHORT nPos = ( nArg < nFix ? nArg : nFix );
140 USHORT nRealArg = (nPos < aVisibleArgMapping.size() ?
141 aVisibleArgMapping[nPos] : aVisibleArgMapping.back());
142 aArgDesc = pFuncDesc->getParameterDescription(nRealArg);
143 aArgName = pFuncDesc->getParameterName(nRealArg);
144 if ( nArg >= nFix )
145 aArgName += String::CreateFromInt32(nArg-nFix+1);
146 aArgName += ' ';
148 aArgName += (nArg > nFix || pFuncDesc->isParameterOptional(nRealArg)) ? m_sOptional : m_sRequired ;
151 SetArgumentDesc(aArgDesc);
152 SetArgumentText(aArgName);
156 void ParaWin::UpdateArgInput( USHORT nOffset, USHORT i )
158 USHORT nArg = nOffset + i;
159 if ( nArgs < VAR_ARGS)
161 if(nArg<nArgs)
163 USHORT nRealArg = aVisibleArgMapping[nArg];
164 SetArgNameFont (i,(pFuncDesc->isParameterOptional(nRealArg))
165 ? aFntLight : aFntBold );
166 SetArgName (i,pFuncDesc->getParameterName(nRealArg));
169 else
171 USHORT nFix = nArgs - VAR_ARGS;
172 USHORT nPos = ( nArg < nFix ? nArg : nFix );
173 USHORT nRealArg = (nPos < aVisibleArgMapping.size() ?
174 aVisibleArgMapping[nPos] : aVisibleArgMapping.back());
175 SetArgNameFont( i,
176 (nArg > nFix || pFuncDesc->isParameterOptional(nRealArg)) ?
177 aFntLight : aFntBold );
178 if ( nArg >= nFix )
180 String aArgName( pFuncDesc->getParameterName(nRealArg) );
181 aArgName += String::CreateFromInt32(nArg-nFix+1);
182 SetArgName( i, aArgName );
184 else
185 SetArgName( i, pFuncDesc->getParameterName(nRealArg) );
187 if(nArg<nArgs) SetArgVal(i,aParaArray[nArg]);
188 //@ aArgInput[i].SetArgVal( *(pArgArr[nOffset+i]) );
192 ParaWin::~ParaWin()
194 // #i66422# if the focus changes during destruction of the controls,
195 // don't call the focus handlers
196 Link aEmptyLink;
197 aBtnFx1.SetGetFocusHdl( aEmptyLink );
198 aBtnFx2.SetGetFocusHdl( aEmptyLink );
199 aBtnFx3.SetGetFocusHdl( aEmptyLink );
200 aBtnFx4.SetGetFocusHdl( aEmptyLink );
203 USHORT ParaWin::GetActiveLine()
205 return nActiveLine;
208 void ParaWin::SetActiveLine(USHORT no)
210 if(no<nArgs)
212 long nOffset = GetSliderPos();
213 nActiveLine=no;
214 long nNewEdPos=(long)nActiveLine-nOffset;
215 if(nNewEdPos<0 || nNewEdPos>3)
217 nOffset+=nNewEdPos;
218 SetSliderPos((USHORT) nOffset);
219 nOffset=GetSliderPos();
221 nEdFocus=no-(USHORT)nOffset;
222 UpdateArgDesc( nEdFocus );
226 RefEdit* ParaWin::GetActiveEdit()
228 if(nArgs>0 && nEdFocus!=NOT_FOUND)
230 return aArgInput[nEdFocus].GetArgEdPtr();
232 else
234 return NULL;
239 String ParaWin::GetArgument(USHORT no)
241 String aStr;
242 if(no<aParaArray.size())
244 aStr=aParaArray[no];
245 if(no==nActiveLine && aStr.Len()==0)
246 aStr+=' ';
248 return aStr;
251 String ParaWin::GetActiveArgName()
253 String aStr;
254 if(nArgs>0 && nEdFocus!=NOT_FOUND)
256 aStr=aArgInput[nEdFocus].GetArgName();
258 return aStr;
262 void ParaWin::SetArgument(USHORT no, const String& aString)
264 if(no<aParaArray.size())
266 aParaArray[no] = aString;
267 aParaArray[no].EraseLeadingChars();
271 void ParaWin::DelParaArray()
273 ::std::vector<String>().swap(aParaArray);
276 void ParaWin::SetArgumentFonts(const Font&aBoldFont,const Font&aLightFont)
278 aFntBold=aBoldFont;
279 aFntLight=aLightFont;
282 void ParaWin::SetFunctionDesc(const IFunctionDescription* pFDesc)
284 pFuncDesc=pFDesc;
286 SetArgumentDesc( String() );
287 SetArgumentText( String() );
288 SetEditDesc( String() );
289 nArgs = 0;
290 if ( pFuncDesc!=NULL)
292 if ( pFuncDesc->getDescription().getLength() )
294 SetEditDesc(pFuncDesc->getDescription());
296 else
298 SetEditDesc(aDefaultString);
300 long nHelpId = pFuncDesc->getHelpId();
301 nArgs = pFuncDesc->getSuppressedArgumentCount();
302 pFuncDesc->fillVisibleArgumentMapping(aVisibleArgMapping);
303 aSlider.Hide();
304 SetHelpId( nHelpId );
305 aEdArg1.SetHelpId( nHelpId );
306 aEdArg2.SetHelpId( nHelpId );
307 aEdArg3.SetHelpId( nHelpId );
308 aEdArg4.SetHelpId( nHelpId );
310 // Unique-IDs muessen gleich bleiben fuer Automatisierung
311 SetUniqueId( HID_FORMULA_FAP_PAGE );
312 aEdArg1.SetUniqueId( HID_FORMULA_FAP_EDIT1 );
313 aEdArg2.SetUniqueId( HID_FORMULA_FAP_EDIT2 );
314 aEdArg3.SetUniqueId( HID_FORMULA_FAP_EDIT3 );
315 aEdArg4.SetUniqueId( HID_FORMULA_FAP_EDIT4 );
316 SetActiveLine(0);
318 else
320 nActiveLine=0;
325 void ParaWin::SetArgumentText(const String& aText)
327 aFtArgName.SetText(aText);
330 void ParaWin::SetArgumentDesc(const String& aText)
332 aFtArgDesc.SetText(aText);
335 void ParaWin::SetEditDesc(const String& aText)
337 aFtEditDesc.SetText(aText);
340 void ParaWin::SetArgName(USHORT no,const String& aText)
342 aArgInput[no].SetArgName(aText);
345 void ParaWin::SetArgNameFont(USHORT no,const Font& aFont)
347 aArgInput[no].SetArgNameFont(aFont);
350 void ParaWin::SetArgVal(USHORT no,const String& aText)
352 aArgInput[no].SetArgVal(aText);
355 void ParaWin::HideParaLine(USHORT no)
357 aArgInput[no].Hide();
360 void ParaWin::ShowParaLine(USHORT no)
362 aArgInput[no].Show();
365 void ParaWin::SetEdFocus(USHORT no)
367 UpdateArgDesc(no);
368 if(no<4 && no<aParaArray.size())
369 aArgInput[no].GetArgEdPtr()->GrabFocus();
373 void ParaWin::InitArgInput( USHORT nPos, FixedText& rFtArg, ImageButton& rBtnFx,
374 ArgEdit& rEdArg, RefButton& rRefBtn)
377 rRefBtn.SetReferences(pMyParent,&rEdArg);
378 rEdArg.SetRefDialog(pMyParent);
380 aArgInput[nPos].InitArgInput (&rFtArg,&rBtnFx,&rEdArg,&rRefBtn);
382 aArgInput[nPos].Hide();
384 aArgInput[nPos].SetFxClickHdl ( LINK( this, ParaWin, GetFxHdl ) );
385 aArgInput[nPos].SetFxFocusHdl ( LINK( this, ParaWin, GetFxFocusHdl ) );
386 aArgInput[nPos].SetEdFocusHdl ( LINK( this, ParaWin, GetEdFocusHdl ) );
387 aArgInput[nPos].SetEdModifyHdl ( LINK( this, ParaWin, ModifyHdl ) );
390 void ParaWin::ClearAll()
392 SetFunctionDesc(NULL);
393 SetArgumentOffset(0);
396 void ParaWin::SetArgumentOffset(USHORT nOffset)
398 DelParaArray();
399 aSlider.SetThumbPos(0);
401 aParaArray.resize(nArgs);
403 if ( nArgs > 0 )
405 for ( int i=0; i<4 && i<nArgs; i++ )
407 String aString;
408 aArgInput[i].SetArgVal(aString);
409 aArgInput[i].GetArgEdPtr()->Init(
410 (i==0) ? (ArgEdit *)NULL : aArgInput[i-1].GetArgEdPtr(),
411 (i==3 || i==nArgs-1) ? (ArgEdit *)NULL : aArgInput[i+1].GetArgEdPtr(),
412 aSlider, nArgs );
416 if ( nArgs < 5 )
418 aSlider.Hide();
420 else
422 //aSlider.SetEndScrollHdl( LINK( this, ScFormulaDlg, ScrollHdl ) );
423 aSlider.SetPageSize( 4 );
424 aSlider.SetVisibleSize( 4 );
425 aSlider.SetLineSize( 1 );
426 aSlider.SetRange( Range( 0, nArgs ) );
427 aSlider.SetThumbPos( nOffset );
428 aSlider.Show();
431 UpdateParas();
434 void ParaWin::UpdateParas()
436 USHORT i;
437 USHORT nOffset = GetSliderPos();
439 if ( nArgs > 0 )
441 for ( i=0; (i<nArgs) && (i<4); i++ )
443 UpdateArgInput( nOffset, i );
444 ShowParaLine(i);
448 for ( i=nArgs; i<4; i++ ) HideParaLine(i);
452 USHORT ParaWin::GetSliderPos()
454 return (USHORT) aSlider.GetThumbPos();
457 void ParaWin::SetSliderPos(USHORT nSliderPos)
459 USHORT nOffset = GetSliderPos();
461 if(aSlider.IsVisible() && nOffset!=nSliderPos)
463 aSlider.SetThumbPos(nSliderPos);
464 for ( USHORT i=0; i<4; i++ )
466 UpdateArgInput( nSliderPos, i );
471 void ParaWin::SliderMoved()
473 USHORT nOffset = GetSliderPos();
475 for ( USHORT i=0; i<4; i++ )
477 UpdateArgInput( nOffset, i );
479 if(nEdFocus!=NOT_FOUND)
481 UpdateArgDesc( nEdFocus );
482 aArgInput[nEdFocus].SetArgSelection(Selection(0,SELECTION_MAX ));
483 nActiveLine=nEdFocus+nOffset;
484 ArgumentModified();
486 aScrollLink.Call(this);
489 void ParaWin::ArgumentModified()
491 aArgModifiedLink.Call(this);
494 void ParaWin::FxClick()
496 aFxLink.Call(this);
500 IMPL_LINK( ParaWin, GetFxHdl, ArgInput*, pPtr )
502 USHORT nOffset = GetSliderPos();
503 nEdFocus=NOT_FOUND;
504 for ( USHORT nPos=0; nPos<5;nPos++)
506 if(pPtr == &aArgInput[nPos])
508 nEdFocus=nPos;
509 break;
513 if(nEdFocus!=NOT_FOUND)
515 aArgInput[nEdFocus].SetArgSelection(Selection(0,SELECTION_MAX ));
516 nActiveLine=nEdFocus+nOffset;
517 FxClick();
519 return 0;
522 IMPL_LINK( ParaWin, GetFxFocusHdl, ArgInput*, pPtr )
524 USHORT nOffset = GetSliderPos();
525 nEdFocus=NOT_FOUND;
526 for ( USHORT nPos=0; nPos<5;nPos++)
528 if(pPtr == &aArgInput[nPos])
530 nEdFocus=nPos;
531 break;
535 if(nEdFocus!=NOT_FOUND)
537 aArgInput[nEdFocus].SetArgSelection(Selection(0,SELECTION_MAX ));
538 UpdateArgDesc( nEdFocus );
539 nActiveLine=nEdFocus+nOffset;
541 return 0;
546 IMPL_LINK( ParaWin, GetEdFocusHdl, ArgInput*, pPtr )
548 USHORT nOffset = GetSliderPos();
549 nEdFocus=NOT_FOUND;
550 for ( USHORT nPos=0; nPos<5;nPos++)
552 if(pPtr == &aArgInput[nPos])
554 nEdFocus=nPos;
555 break;
559 if(nEdFocus!=NOT_FOUND)
561 aArgInput[nEdFocus].SetArgSelection(Selection(0,SELECTION_MAX ));
562 UpdateArgDesc( nEdFocus );
563 nActiveLine=nEdFocus+nOffset;
564 ArgumentModified();
567 return 0;
571 IMPL_LINK( ParaWin, ScrollHdl, ScrollBar*, EMPTYARG )
573 SliderMoved();
575 return 0;
578 IMPL_LINK( ParaWin, ModifyHdl, ArgInput*, pPtr )
580 USHORT nOffset = GetSliderPos();
581 nEdFocus=NOT_FOUND;
582 for ( USHORT nPos=0; nPos<5;nPos++)
584 if(pPtr == &aArgInput[nPos])
586 nEdFocus=nPos;
587 break;
590 if(nEdFocus!=NOT_FOUND)
592 aParaArray[nEdFocus+nOffset] = aArgInput[nEdFocus].GetArgVal();
593 UpdateArgDesc( nEdFocus);
594 nActiveLine=nEdFocus+nOffset;
597 ArgumentModified();
598 return 0;
603 } // formula