xref: /trunk/main/sc/source/ui/formdlg/dwfunctr.cxx (revision 4847afeb)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26 
27 
28 
29 // INCLUDE ---------------------------------------------------------------
30 
31 #include <editeng/editview.hxx>
32 #include <sfx2/bindings.hxx>
33 #include <sfx2/dispatch.hxx>
34 #include <sfx2/objsh.hxx>
35 #include <sfx2/viewsh.hxx>
36 
37 #include "sc.hrc"
38 #include "global.hxx"		// ScAddress
39 #include "scresid.hxx"
40 #include "reffact.hxx"
41 #include "document.hxx"
42 #include "cell.hxx"
43 #include "scmod.hxx"
44 #include "inputhdl.hxx"
45 #include "tabvwsh.hxx"
46 #include "appoptio.hxx"
47 #include "compiler.hxx"
48 
49 #include "dwfunctr.hrc"
50 #include "dwfunctr.hxx"
51 
52 // -----------------------------------------------------------------------
53 
54 #define ARG_SEPERATOR String("; ")
SFX_IMPL_DOCKINGWINDOW(ScFunctionChildWindow,FID_FUNCTION_BOX)55 SFX_IMPL_DOCKINGWINDOW( ScFunctionChildWindow, FID_FUNCTION_BOX )
56 
57 /*************************************************************************
58 #*	Member:		ScFunctionChildWindow						Datum:06.10.97
59 #*------------------------------------------------------------------------
60 #*
61 #*  Klasse:		ScFunctionChildWindow
62 #*
63 #*  Funktion:	Konstruktor der Klasse ScFunctionChildWindow
64 #*				Ableitung vom SfxChildWindow als "Behaelter" fuer
65 #*				Funktions- Fenster in Clac
66 #*
67 #*  Input:		---
68 #*
69 #*	Output:		---
70 #*
71 #************************************************************************/
72 
73 __EXPORT ScFunctionChildWindow::ScFunctionChildWindow( Window* pParentP,
74 									sal_uInt16 nId,
75 									SfxBindings* pBindings,
76 									SfxChildWinInfo* pInfo ) :
77     SfxChildWindow( pParentP, nId )
78 {
79 	ScFunctionDockWin* pWin = new ScFunctionDockWin( pBindings, this,
80                                         pParentP, ScResId( FID_FUNCTION_BOX ) );
81 	pWindow = pWin;
82 
83 	eChildAlignment = SFX_ALIGN_RIGHT;
84 
85 	pWin->Initialize( pInfo );
86 }
87 
88 /*************************************************************************
89 #*	Member:		ScFunctionDockWin							Datum:06.10.97
90 #*------------------------------------------------------------------------
91 #*
92 #*  Klasse:		ScFunctionDockWin
93 #*
94 #*  Funktion:	Konstruktor der Klasse ScFunctionDockWin
95 #*
96 #*  Input:		Sfx- Verknuepfungen, Fenster, Resource
97 #*
98 #*	Output:		---
99 #*
100 #************************************************************************/
101 
ScFunctionDockWin(SfxBindings * pBindingsP,SfxChildWindow * pCW,Window * pParent,const ResId & rResId)102 ScFunctionDockWin::ScFunctionDockWin( SfxBindings* pBindingsP,
103 				SfxChildWindow *pCW, Window* pParent, const ResId& rResId ) :
104 
105     SfxDockingWindow( pBindingsP, pCW, pParent, rResId ),
106 	aPrivatSplit	( this, ResId( FT_SPLIT, *rResId.GetResMgr()  ),SC_SPLIT_VERT),
107 	aCatBox			( this, ResId( CB_CAT, *rResId.GetResMgr()  ) ),
108 	aFuncList		( this, ResId( LB_FUNC, *rResId.GetResMgr()  ) ),
109 	aDDFuncList		( this, ResId( DDLB_FUNC, *rResId.GetResMgr()  ) ),
110 	aInsertButton	( this, ResId( IMB_INSERT, *rResId.GetResMgr()  ) ),
111 	aFiFuncDesc		( this, ResId( FI_FUNCDESC, *rResId.GetResMgr()  ) ),
112 	aOldSize		(0,0)
113 {
114 	FreeResource();
115 	InitLRUList();
116 	SetStyle(GetStyle()|WB_CLIPCHILDREN);
117 
118 	aTimer.SetTimeout(200);
119 	aTimer.SetTimeoutHdl(LINK( this, ScFunctionDockWin, TimerHdl));
120 
121     if (pCW != NULL)
122         eSfxNewAlignment=GetAlignment();
123     else
124         eSfxNewAlignment=SFX_ALIGN_RIGHT;
125 	eSfxOldAlignment=eSfxNewAlignment;
126 	aFiFuncDesc.SetUpdateMode(sal_True);
127 	pAllFuncList=&aFuncList;
128 	aDDFuncList.Disable();
129 	aDDFuncList.Hide();
130 	nArgs=0;
131 	nDockMode=0;
132 	bSizeFlag=sal_False;
133 	aCatBox.SetDropDownLineCount(9);
134 	Font aFont=aFiFuncDesc.GetFont();
135 	aFont.SetColor(Color(COL_BLACK));
136 	aFiFuncDesc.SetFont(aFont);
137 	aFiFuncDesc.SetBackground( GetBackground() );		//! never transparent?
138 //?	SetBackground();
139 
140 	Link aLink=LINK( this, ScFunctionDockWin, SelHdl);
141 	aCatBox.SetSelectHdl(aLink);
142 	aFuncList.SetSelectHdl(aLink);
143 	aDDFuncList.SetSelectHdl(aLink);
144 
145 	Link a2Link=LINK( this, ScFunctionDockWin, SetSelectionHdl);
146 	aFuncList.SetDoubleClickHdl(a2Link);
147 	aDDFuncList.SetSelectHdl(aLink);
148 	aInsertButton.SetClickHdl(a2Link);
149 
150 	Link a3Link=LINK( this, ScFunctionDockWin, SetSplitHdl);
151 	aPrivatSplit.SetCtrModifiedHdl(a3Link);
152 	StartListening( *pBindingsP, sal_True );
153 
154 	Point aTopLeft=aCatBox.GetPosPixel();
155 	//String aString=aCatBox.GetEntry( 0)+String("www");
156 	String aString=String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("ww"));
157 	Size aTxtSize( aFiFuncDesc.GetTextWidth(aString), aFiFuncDesc.GetTextHeight() );
158 	nMinWidth=aTxtSize.Width()+aTopLeft.X()
159 			+2*aFuncList.GetPosPixel().X();
160 	nMinHeight=19*aTxtSize.Height();
161 	aCatBox.SelectEntryPos(0);
162 
163 	Range aYRange(3*aTxtSize.Height()+aFuncList.GetPosPixel().Y(),
164 				GetOutputSizePixel().Height()-2*aTxtSize.Height());
165 	aPrivatSplit.SetYRange(aYRange);
166 	SelHdl(&aCatBox);
167 	bInit=sal_True;
168 }
169 
170 /*************************************************************************
171 #*	Member:		ScFunctionDockWin							Datum:06.10.97
172 #*------------------------------------------------------------------------
173 #*
174 #*  Klasse:		ScFunctionDockWin
175 #*
176 #*  Funktion:	Destruktor der Klasse ScFunctionDockWin
177 #*
178 #*  Input:		---
179 #*
180 #*	Output:		---
181 #*
182 #************************************************************************/
183 
~ScFunctionDockWin()184 __EXPORT ScFunctionDockWin::~ScFunctionDockWin()
185 {
186 	EndListening( GetBindings() );
187 }
188 
189 /*************************************************************************
190 #*	Member:		UpdateFunctionList							Datum:06.10.97
191 #*------------------------------------------------------------------------
192 #*
193 #*  Klasse:		ScFunctionDockWin
194 #*
195 #*  Funktion:	Aktualisiert die Liste der Funktionen ab-
196 #*				haengig von der eingestellten Kategorie.
197 #*
198 #*  Input:		---
199 #*
200 #*	Output:		---
201 #*
202 #************************************************************************/
203 
InitLRUList()204 void ScFunctionDockWin::InitLRUList()
205 {
206 	const ScAppOptions& rAppOpt = SC_MOD()->GetAppOptions();
207 	sal_uInt16 nLRUFuncCount = Min( rAppOpt.GetLRUFuncListCount(), (sal_uInt16)LRU_MAX );
208 	sal_uInt16*	pLRUListIds = rAppOpt.GetLRUFuncList();
209 
210 	sal_uInt16 i;
211 	for ( i=0; i<LRU_MAX; i++ )
212 		aLRUList[i] = NULL;
213 
214 	if ( pLRUListIds )
215 	{
216 		ScFunctionMgr* pFuncMgr = ScGlobal::GetStarCalcFunctionMgr();
217 		for ( i=0; i<nLRUFuncCount; i++ )
218 			aLRUList[i] = pFuncMgr->Get( pLRUListIds[i] );
219 	}
220 
221 	sal_uInt16	nSelPos	  = aCatBox.GetSelectEntryPos();
222 
223 	if(nSelPos == 0)
224 		UpdateFunctionList();
225 }
226 
227 /*************************************************************************
228 #*	Member:		UpdateFunctionList							Datum:10.12.99
229 #*------------------------------------------------------------------------
230 #*
231 #*  Klasse:		ScFunctionDockWin
232 #*
233 #*  Funktion:	Aktualisiert die Liste der zuletzt verwendeten Funktionen.
234 #*
235 #*  Input:		---
236 #*
237 #*	Output:		---
238 #*
239 #************************************************************************/
240 
UpdateLRUList()241 void ScFunctionDockWin::UpdateLRUList()
242 {
243 	if (pFuncDesc && pFuncDesc->nFIndex!=0)
244 	{
245 		ScModule* pScMod = SC_MOD();
246 		pScMod->InsertEntryToLRUList(pFuncDesc->nFIndex);
247 	}
248 }
249 
250 
251 /*************************************************************************
252 #*	Member:		SetSize										Datum:06.10.97
253 #*------------------------------------------------------------------------
254 #*
255 #*  Klasse:		ScFunctionDockWin
256 #*
257 #*  Funktion:	Groesse fuer die einzelnen Controls einzustellen.
258 #*
259 #*  Input:		---
260 #*
261 #*	Output:		---
262 #*
263 #************************************************************************/
264 
SetSize()265 void ScFunctionDockWin::SetSize()
266 {
267 	sal_uInt16 nSelEntry=0;
268 	SfxChildAlignment  aChildAlign=eSfxOldAlignment;//GetAlignment();
269 	short nNewDockMode;
270 	switch(aChildAlign)
271 	{
272 		case SFX_ALIGN_HIGHESTTOP:
273 		case SFX_ALIGN_TOP:
274 		case SFX_ALIGN_LOWESTTOP:
275 		case SFX_ALIGN_LOWESTBOTTOM:
276 		case SFX_ALIGN_BOTTOM:
277 		case SFX_ALIGN_TOOLBOXTOP:
278 		case SFX_ALIGN_TOOLBOXBOTTOM:
279 
280 
281 						nNewDockMode=1;
282 						if(nDockMode!=nNewDockMode)
283 						{
284 							nDockMode=nNewDockMode;
285 							nSelEntry=aFuncList.GetSelectEntryPos();
286 							aFuncList.Clear();
287 							aFiFuncDesc.SetPosPixel(aFuncList.GetPosPixel());
288 							aDDFuncList.Enable();
289 							aDDFuncList.Show();
290 							aPrivatSplit.Disable();
291 							aPrivatSplit.Hide();
292 							aFuncList.Disable();
293 							aFuncList.Hide();
294 							pAllFuncList=&aDDFuncList;
295 							SelHdl(&aCatBox);
296 							aDDFuncList.SelectEntryPos(nSelEntry);
297 						}
298 						break;
299 
300 		default:		nNewDockMode=0;
301 						if(nDockMode!=nNewDockMode)
302 						{
303 							nDockMode=nNewDockMode;
304 							nSelEntry=aDDFuncList.GetSelectEntryPos();
305 							aDDFuncList.Clear();
306 							aDDFuncList.Disable();
307 							aDDFuncList.Hide();
308 							aPrivatSplit.Enable();
309 							aPrivatSplit.Show();
310 							aFuncList.Enable();
311 							aFuncList.Show();
312 							pAllFuncList=&aFuncList;
313 							SelHdl(&aCatBox);
314 							aFuncList.SelectEntryPos(nSelEntry);
315 						}
316 						break;
317 	}
318 
319 	if(nDockMode==0)
320 	{
321 		SetLeftRightSize();
322 	}
323 	else
324 	{
325 		SetTopBottonSize();
326 	}
327 }
328 /*************************************************************************
329 #*	Member:		SetLeftRightSize							Datum:15.10.97
330 #*------------------------------------------------------------------------
331 #*
332 #*  Klasse:		ScFunctionDockWin
333 #*
334 #*  Funktion:	Groesse fuer die einzelnen Controls einstellen,
335 #*				wenn Links oder Rechts angedockt wird.
336 #*
337 #*  Input:		---
338 #*
339 #*	Output:		---
340 #*
341 #************************************************************************/
342 
SetLeftRightSize()343 void ScFunctionDockWin::SetLeftRightSize()
344 {
345 	if(bSizeFlag==sal_False)
346 	{
347 		bSizeFlag=sal_True;
348 
349 		Size aDiffSize=GetSizePixel();
350 		Size aNewSize=GetOutputSizePixel();
351 		aDiffSize.Width()-=aNewSize.Width();
352 		aDiffSize.Height()-=aNewSize.Height();
353 
354 		//@ SetUpdateMode( sal_False);
355 
356 		String aString = String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("ww"));
357 
358 		Size aTxtSize( aFuncList.GetTextWidth(aString), aFuncList.GetTextHeight() );
359 
360 		Range aYRange(3*aTxtSize.Height()+aFuncList.GetPosPixel().Y(),
361 					GetOutputSizePixel().Height()-2*aTxtSize.Height());
362 		aPrivatSplit.SetYRange(aYRange);
363 
364 
365 		if(aOldSize.Width()!=aNewSize.Width())
366 			SetMyWidthLeRi(aNewSize);
367 
368 		if(aOldSize.Height()!=aNewSize.Height())
369 			SetMyHeightLeRi(aNewSize);
370 
371 		aOldSize=aNewSize;
372 		aNewSize.Width()+=aDiffSize.Width();
373 		aNewSize.Height()+=aDiffSize.Height();
374 		//SetSizePixel(aNewSize);
375 		//@ SetUpdateMode( sal_True);
376 		bSizeFlag=sal_False;
377 	}
378 
379 }
380 /*************************************************************************
381 #*	Member:		SetTopBottonSize							Datum:15.10.97
382 #*------------------------------------------------------------------------
383 #*
384 #*  Klasse:		ScFunctionDockWin
385 #*
386 #*  Funktion:	Groesse fuer die einzelnen Controls einzustellen.
387 #*				wenn oben oder unten angedockt wird.
388 #*
389 #*  Input:		---
390 #*
391 #*	Output:		---
392 #*
393 #************************************************************************/
394 
SetTopBottonSize()395 void ScFunctionDockWin::SetTopBottonSize()
396 {
397 	if(bSizeFlag==sal_False)
398 	{
399 		bSizeFlag=sal_True;
400 		Size aDiffSize=GetSizePixel();
401 		Size aNewSize=GetOutputSizePixel();
402 		aDiffSize.Width()-=aNewSize.Width();
403 		aDiffSize.Height()-=aNewSize.Height();
404 
405 		SetMyWidthToBo(aNewSize);
406 		SetMyHeightToBo(aNewSize);
407 
408 		aNewSize.Width()+=aDiffSize.Width();
409 		aNewSize.Height()+=aDiffSize.Height();
410 		//SetSizePixel(aNewSize);
411 		//@ SetUpdateMode( sal_True);
412 		bSizeFlag=sal_False;
413 	}
414 }
415 
416 /*************************************************************************
417 #*	Member:		SetMyWidthLeRi								Datum:15.10.97
418 #*------------------------------------------------------------------------
419 #*
420 #*  Klasse:		ScFunctionDockWin
421 #*
422 #*  Funktion:	Breite fuer die einzelnen Controls und
423 #*				das Fenster einstellen,wenn Li oder Re
424 #*
425 #*  Input:		neue Fenstergroesse
426 #*
427 #*	Output:		---
428 #*
429 #************************************************************************/
430 
SetMyWidthLeRi(Size & aNewSize)431 void ScFunctionDockWin::SetMyWidthLeRi(Size &aNewSize)
432 {
433 	if((sal_uLong)aNewSize.Width()<nMinWidth)	aNewSize.Width()=nMinWidth;
434 
435 	Size aCDSize=aCatBox.GetSizePixel();
436 	Size aFLSize=aFuncList.GetSizePixel();
437 	Size aSplitterSize=aPrivatSplit.GetSizePixel();
438 	Size aFDSize=aFiFuncDesc.GetSizePixel();
439 
440 	Point aCDTopLeft=aCatBox.GetPosPixel();
441 	Point aFLTopLeft=aFuncList.GetPosPixel();
442 	Point aSplitterTopLeft=aPrivatSplit.GetPosPixel();
443 	Point aFDTopLeft=aFiFuncDesc.GetPosPixel();
444 
445 	aCDSize.Width()=aNewSize.Width()-aCDTopLeft.X()-aFLTopLeft.X();
446 	aFLSize.Width()=aNewSize.Width()-2*aFLTopLeft.X();
447 	aFDSize.Width()=aFLSize.Width();
448 	aSplitterSize.Width()=aFLSize.Width();
449 
450 	aCatBox.SetSizePixel(aCDSize);
451 	aFuncList.SetSizePixel(aFLSize);
452 	aPrivatSplit.SetSizePixel(aSplitterSize);
453 	aFiFuncDesc.SetSizePixel(aFDSize);
454 }
455 
456 /*************************************************************************
457 #*	Member:		SetHeight									Datum:06.10.97
458 #*------------------------------------------------------------------------
459 #*
460 #*  Klasse:		ScFunctionDockWin
461 #*
462 #*  Funktion:	Hoehe fuer die einzelnen Controls und
463 #*				das Fenster einstellen bei Li oder Re
464 #*
465 #*  Input:		neue Fenstergroesse
466 #*
467 #*	Output:		---
468 #*
469 #************************************************************************/
470 
SetMyHeightLeRi(Size & aNewSize)471 void ScFunctionDockWin::SetMyHeightLeRi(Size &aNewSize)
472 {
473 	if((sal_uLong)aNewSize.Height()<nMinHeight) aNewSize.Height()=nMinHeight;
474 
475 	Size aFLSize=aFuncList.GetSizePixel();
476 	Size aSplitterSize=aPrivatSplit.GetSizePixel();
477 	Size aFDSize=aFiFuncDesc.GetSizePixel();
478 
479 	Point aFLTopLeft=aFuncList.GetPosPixel();
480 	Point aSplitterTopLeft=aPrivatSplit.GetPosPixel();
481 	Point aFDTopLeft=aFiFuncDesc.GetPosPixel();
482 
483 	long nTxtHeight = aFuncList.GetTextHeight();
484 
485 	short nY=(short)(3*nTxtHeight+
486 		aFuncList.GetPosPixel().Y()+aSplitterSize.Height());
487 
488 	aFDTopLeft.Y()=aNewSize.Height()-aFDSize.Height()-4;
489 	if(nY>aFDTopLeft.Y())
490 	{
491 		aFDSize.Height()-=nY-aFDTopLeft.Y();
492 		aFDTopLeft.Y()=nY;
493 	}
494 	aSplitterTopLeft.Y()=aFDTopLeft.Y()-aSplitterSize.Height()-1;
495 	aFLSize.Height()=aSplitterTopLeft.Y()-aFLTopLeft.Y()-1;
496 
497 	aFuncList.SetSizePixel(aFLSize);
498 	aPrivatSplit.SetPosPixel(aSplitterTopLeft);
499 	aFiFuncDesc.SetPosPixel(aFDTopLeft);
500 	aFiFuncDesc.SetSizePixel(aFDSize);
501 
502 }
503 
504 /*************************************************************************
505 #*	Member:		SetMyWidthToBo								Datum:16.10.97
506 #*------------------------------------------------------------------------
507 #*
508 #*  Klasse:		ScFunctionDockWin
509 #*
510 #*  Funktion:	Breite fuer die einzelnen Controls und
511 #*				das Fenster einstellen, wenn oben oder
512 #*				unten angedockt werden soll.
513 #*
514 #*  Input:		neue Fenstergroesse
515 #*
516 #*	Output:		---
517 #*
518 #************************************************************************/
519 
SetMyWidthToBo(Size & aNewSize)520 void ScFunctionDockWin::SetMyWidthToBo(Size &aNewSize)
521 {
522 	if((sal_uLong)aNewSize.Width()<nMinWidth)	aNewSize.Width()=nMinWidth;
523 
524 	Size aCDSize=aCatBox.GetSizePixel();
525 	Size aDdFLSize=aDDFuncList.GetSizePixel();
526 	Size aFDSize=aFiFuncDesc.GetSizePixel();
527 
528 	Point aCDTopLeft=aCatBox.GetPosPixel();
529 	Point aDdFLTopLeft=aDDFuncList.GetPosPixel();
530 	Point aFDTopLeft=aFiFuncDesc.GetPosPixel();
531 
532 	aCDSize.Width()=aDdFLTopLeft.X()-aFDTopLeft.X()-aCDTopLeft.X();
533 	aDdFLTopLeft.X()=aCDSize.Width()+aCDTopLeft.X()+aFDTopLeft.X();
534 
535 	aDdFLSize.Width()=aNewSize.Width()-aDdFLTopLeft.X()-aFDTopLeft.X();
536 
537 	aFDSize.Width()=aNewSize.Width()-2*aFDTopLeft.X();
538 
539 	aDDFuncList.SetPosPixel(aDdFLTopLeft);
540 	aDDFuncList.SetSizePixel(aDdFLSize);
541 	aCatBox.SetSizePixel(aCDSize);
542 	aFiFuncDesc.SetSizePixel(aFDSize);
543 }
544 
545 /*************************************************************************
546 #*	Member:		SetHeight									Datum:16.10.97
547 #*------------------------------------------------------------------------
548 #*
549 #*  Klasse:		ScFunctionDockWin
550 #*
551 #*  Funktion:	Hoehe fuer die einzelnen Controls und
552 #*				das Fenster einstellen, wenn oben oder
553 #*				unten angedockt werden soll.
554 #*
555 #*  Input:		neue Fenstergroesse
556 #*
557 #*	Output:		---
558 #*
559 #************************************************************************/
560 
SetMyHeightToBo(Size & aNewSize)561 void ScFunctionDockWin::SetMyHeightToBo(Size &aNewSize)
562 {
563 	if((sal_uLong)aNewSize.Height()<nMinHeight) aNewSize.Height()=nMinHeight;
564 
565 	Size aFDSize=aFiFuncDesc.GetSizePixel();
566 
567 	Point aFDTopLeft=aFiFuncDesc.GetPosPixel();
568 	Point aCBTopLeft=aCatBox.GetPosPixel();
569 	aFDSize.Height()=aNewSize.Height()-aFDTopLeft.Y()-aCBTopLeft.Y();
570 	aFiFuncDesc.SetSizePixel(aFDSize);
571 
572 }
573 
574 /*************************************************************************
575 #*	Member:		SetDescription								Datum:13.10.97
576 #*------------------------------------------------------------------------
577 #*
578 #*  Klasse:		ScFunctionDockWin
579 #*
580 #*  Funktion:	Erklaerungstext fuer die Funktion einstellen.
581 #*
582 #*  Input:		---
583 #*
584 #*	Output:		---
585 #*
586 #************************************************************************/
587 
SetDescription()588 void ScFunctionDockWin::SetDescription()
589 {
590 	aFiFuncDesc.SetText( EMPTY_STRING );
591 	const ScFuncDesc* pDesc =
592 			 (const ScFuncDesc*)pAllFuncList->GetEntryData(
593 					pAllFuncList->GetSelectEntryPos() );
594 	if (pDesc)
595 	{
596         pDesc->initArgumentInfo();      // full argument info is needed
597 
598 		String	aString=pAllFuncList->GetSelectEntry();
599 		if(nDockMode==0)
600 		{
601 			aString.AppendAscii(RTL_CONSTASCII_STRINGPARAM( ":\n\n" ));
602 		}
603 		else
604 		{
605 			aString.AppendAscii(RTL_CONSTASCII_STRINGPARAM( ":   " ));
606 		}
607 
608         aString+=pDesc->GetParamList();
609 
610 		if(nDockMode==0)
611 		{
612 			aString.AppendAscii(RTL_CONSTASCII_STRINGPARAM( "\n\n" ));
613 		}
614 		else
615 		{
616 			aString += '\n';
617 		}
618 
619 		aString+=*(pDesc->pFuncDesc);
620 
621 		aFiFuncDesc.SetText(aString);
622 		aFiFuncDesc.StateChanged(STATE_CHANGE_TEXT);
623 		aFiFuncDesc.Invalidate();
624 		aFiFuncDesc.Update();
625 
626 	}
627  }
628 
629 /*************************************************************************
630 #*	Member:		Resizing									Datum:06.10.97
631 #*------------------------------------------------------------------------
632 #*
633 #*  Klasse:		ScFunctionDockWin
634 #*
635 #*  Funktion:	Ueberladene Funktion um die Groesse der
636 #*				einzelnen Controls einzustellen.
637 #*
638 #*  Input:		neue Groesse
639 #*
640 #*	Output:		---
641 #*
642 #************************************************************************/
643 
Resizing(Size & rNewSize)644 void __EXPORT ScFunctionDockWin::Resizing( Size& rNewSize )
645 {
646 	if((sal_uLong)rNewSize.Width()<nMinWidth) rNewSize.Width()=nMinWidth;
647 	if((sal_uLong)rNewSize.Height()<nMinHeight) rNewSize.Height()=nMinHeight;
648 
649 }
650 
651 /*************************************************************************
652 #*	Member:		Close										Datum:07.10.97
653 #*------------------------------------------------------------------------
654 #*
655 #*  Klasse:		ScFunctionDockWin
656 #*
657 #*  Funktion:	Schliessen des Fensters
658 #*
659 #*  Input:		---
660 #*
661 #*	Output:		TRUE
662 #*
663 #************************************************************************/
664 
Close()665 sal_Bool __EXPORT ScFunctionDockWin::Close()
666 {
667 	SfxBoolItem aItem( FID_FUNCTION_BOX, sal_False );
668 
669 	GetBindings().GetDispatcher()->Execute( FID_FUNCTION_BOX,
670 								SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD,
671 								&aItem, 0L );
672 
673 	SfxDockingWindow::Close();
674 
675 	return( sal_True );
676 }
677 
678 
679 /*************************************************************************
680 #*	Member:		CheckAlignment								Datum:16.10.97
681 #*------------------------------------------------------------------------
682 #*
683 #*  Klasse:		ScFunctionDockWin
684 #*
685 #*  Funktion:	Ueberprueft den Andockmodus und stellt die
686 #*				Groessen dementsprechend ein.
687 #*
688 #*  Input:		Das neue Alignment
689 #*
690 #*	Output:		Das uebergebene Alignment
691 #*
692 #************************************************************************/
CheckAlignment(SfxChildAlignment,SfxChildAlignment aChildAlign)693 SfxChildAlignment __EXPORT ScFunctionDockWin::CheckAlignment(SfxChildAlignment /* abla */,
694 								SfxChildAlignment aChildAlign)
695 {
696 	String aString = String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("ww"));
697 	Size aTxtSize( aFiFuncDesc.GetTextWidth(aString), aFiFuncDesc.GetTextHeight() );
698 	if(!bInit)
699 	{
700 		eSfxOldAlignment=eSfxNewAlignment;
701 		eSfxNewAlignment=aChildAlign;
702 	}
703 	else
704 	{
705 		bInit=sal_False;
706 		eSfxOldAlignment=aChildAlign;
707 		eSfxNewAlignment=aChildAlign;
708 	}
709 
710 	switch(eSfxOldAlignment)
711 	{
712 		case SFX_ALIGN_HIGHESTTOP:
713 		case SFX_ALIGN_TOP:
714 		case SFX_ALIGN_LOWESTTOP:
715 		case SFX_ALIGN_LOWESTBOTTOM:
716 		case SFX_ALIGN_BOTTOM:
717 		case SFX_ALIGN_TOOLBOXTOP:
718 		case SFX_ALIGN_TOOLBOXBOTTOM:
719 
720 						nMinWidth= 0;/*aDDFuncList.GetPosPixel().X()+
721 									10*aTxtSize.Width()+
722 									aFuncList.GetPosPixel().X();*/
723 						nMinHeight=0;
724 
725 						break;
726 
727 		case SFX_ALIGN_NOALIGNMENT:
728 
729 						aString = aCatBox.GetEntry(0);
730 						aString.AppendAscii(RTL_CONSTASCII_STRINGPARAM("www"));
731 						aTxtSize = Size( aFiFuncDesc.GetTextWidth(aString),
732 											aFiFuncDesc.GetTextHeight() );
733 
734 		default:		Point aTopLeft=aCatBox.GetPosPixel();
735 						nMinWidth=aTxtSize.Width()+aTopLeft.X()
736 								+2*aFuncList.GetPosPixel().X();
737 						nMinHeight=19*aTxtSize.Height();
738 							//aCatBox.SelectEntryPos(0);
739 
740 						break;
741 	}
742 
743 	return aChildAlign;
744 }
745 /*************************************************************************
746 #*	Member:		Close										Datum:07.10.97
747 #*------------------------------------------------------------------------
748 #*
749 #*  Klasse:		ScFunctionDockWin
750 #*
751 #*  Funktion:	Aenderungen erkennen
752 #*
753 #*  Input:		---
754 #*
755 #*	Output:		TRUE
756 #*
757 #************************************************************************/
Notify(SfxBroadcaster &,const SfxHint &)758 void ScFunctionDockWin::Notify( SfxBroadcaster&, const SfxHint& /* rHint */ )
759 {
760 //    const SfxPoolItemHint *pPoolItemHint = PTR_CAST(SfxPoolItemHint, &rHint);
761 	/*
762 	if ( pPoolItemHint
763 		 && ( pPoolItemHint->GetObject()->ISA( SvxColorTableItem ) ) )
764 	{
765 		// Die Liste der Farben hat sich geaendert
766 		pColorTable = ( (SvxColorTableItem*) pPoolItemHint->GetObject() )->GetColorTable();
767 		FillValueSet();
768 	}
769 	*/
770 }
771 
772 
773 /*************************************************************************
774 #*	Member:		Resize									Datum:06.10.97
775 #*------------------------------------------------------------------------
776 #*
777 #*  Klasse:		ScFunctionDockWin
778 #*
779 #*  Funktion:	Ueberladene Funktion um die Groesse der
780 #*				einzelnen Controls einzustellen.
781 #*
782 #*  Input:		neue Groesse
783 #*
784 #*	Output:		---
785 #*
786 #************************************************************************/
787 
Resize()788 void __EXPORT ScFunctionDockWin::Resize()
789 {
790 	if ( !IsFloatingMode() ||
791 		 !GetFloatingWindow()->IsRollUp() )
792 	{
793 		Size aQSize=GetOutputSizePixel();
794 		Resizing( aQSize);
795 		SetSize();
796 	}
797 	SfxDockingWindow::Resize();
798 }
799 
800 /*************************************************************************
801 #*	Member:		UpdateFunctionList							Datum:06.10.97
802 #*------------------------------------------------------------------------
803 #*
804 #*  Klasse:		ScFunctionDockWin
805 #*
806 #*  Funktion:	Aktualisiert die Liste der Funktionen ab-
807 #*				haengig von der eingestellten Kategorie.
808 #*
809 #*  Input:		---
810 #*
811 #*	Output:		---
812 #*
813 #************************************************************************/
814 
UpdateFunctionList()815 void ScFunctionDockWin::UpdateFunctionList()
816 {
817 	sal_uInt16	nSelPos	  = aCatBox.GetSelectEntryPos();
818 	sal_uInt16	nCategory = ( LISTBOX_ENTRY_NOTFOUND != nSelPos )
819 							? (nSelPos-1) : 0;
820 
821 	pAllFuncList->Clear();
822 	pAllFuncList->SetUpdateMode( sal_False );
823 
824 	if ( nSelPos > 0 )
825 	{
826 		ScFunctionMgr* pFuncMgr = ScGlobal::GetStarCalcFunctionMgr();
827 
828 		const ScFuncDesc* pDesc = pFuncMgr->First( nCategory );
829 		while ( pDesc )
830 		{
831 			pAllFuncList->SetEntryData(
832 				pAllFuncList->InsertEntry( *(pDesc->pFuncName) ),
833 				(void*)pDesc );
834 			pDesc = pFuncMgr->Next();
835 		}
836 	}
837 	else // LRU-Liste
838 	{
839 		for ( sal_uInt16 i=0; i<LRU_MAX && aLRUList[i]; i++ )
840 		{
841 			const ScFuncDesc* pDesc = aLRUList[i];
842 			pAllFuncList->SetEntryData(
843 					pAllFuncList->InsertEntry( *(pDesc->pFuncName) ),
844 					(void*)pDesc );
845 		}
846 	}
847 
848 
849 	//------------------------------------------------------
850 	pAllFuncList->SetUpdateMode( sal_True );
851 
852 	if ( pAllFuncList->GetEntryCount() > 0 )
853 	{
854 		pAllFuncList->Enable();
855 		pAllFuncList->SelectEntryPos( 0 );
856 	}
857 	else
858 	{
859 		pAllFuncList->Disable();
860 	}
861 }
862 
863 /*************************************************************************
864 #*	Member:		DoEnter										Datum:06.10.97
865 #*------------------------------------------------------------------------
866 #*
867 #*  Klasse:		ScFunctionDockWin
868 #*
869 #*  Funktion:	Eingabe ins Dokument uebernehmen. Wird aufgerufen
870 #*				nach betaetigen der Uebernehmen- Schaltflaeche
871 #*				oder einem Doppelklick in die Funktionsliste.
872 #*
873 #*  Input:		---
874 #*
875 #*	Output:		---
876 #*
877 #************************************************************************/
878 
DoEnter(sal_Bool)879 void ScFunctionDockWin::DoEnter(sal_Bool /* bOk */) //@@ ???
880 {
881 	String aFirstArgStr;
882 	String aParaStr;
883 	String aArgStr;
884 	String aString=pAllFuncList->GetSelectEntry();
885 	SfxViewShell* pCurSh = SfxViewShell::Current();
886 	nArgs=0;
887 
888 	if(aString.Len()>0)
889 	{
890 
891 		ScModule* pScMod = SC_MOD();
892 		ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, pCurSh);
893 		ScInputHandler* pHdl = pScMod->GetInputHdl( pViewSh );
894 		if(!pScMod->IsEditMode())
895 		{
896 			pScMod->SetInputMode(SC_INPUT_TABLE);
897 			aString = '=';
898 			aString += pAllFuncList->GetSelectEntry();
899 			if (pHdl)
900 				pHdl->ClearText();
901 		}
902 		const ScFuncDesc* pDesc =
903 			 (const ScFuncDesc*)pAllFuncList->GetEntryData(
904 					pAllFuncList->GetSelectEntryPos() );
905 		if (pDesc)
906 		{
907 			pFuncDesc=pDesc;
908 			UpdateLRUList();
909 			nArgs = pDesc->nArgCount;
910 			if(nArgs>0)
911 			{
912                 // NOTE: Theoretically the first parameter could have the
913                 // suppress flag as well, but practically it doesn't.
914 				aFirstArgStr = *(pDesc->ppDefArgNames[0]);
915 				aFirstArgStr.EraseLeadingAndTrailingChars();
916                 aFirstArgStr.SearchAndReplaceAll(' ', '_');
917 				aArgStr = aFirstArgStr;
918 				if ( nArgs != VAR_ARGS && nArgs != PAIRED_VAR_ARGS )
919 				{	// no VarArgs or Fix plus VarArgs, but not VarArgs only
920 					String aArgSep = String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM( "; " ));
921 					sal_uInt16 nFix;
922 					if (nArgs >= PAIRED_VAR_ARGS)
923 					    nFix = nArgs - PAIRED_VAR_ARGS + 2;
924 					else if (nArgs >= VAR_ARGS)
925 					    nFix = nArgs - VAR_ARGS + 1;
926 					else
927 					    nFix = nArgs;
928 					for ( sal_uInt16 nArg = 1;
929 							nArg < nFix && !pDesc->pDefArgFlags[nArg].bOptional; nArg++ )
930 					{
931                         if (!pDesc->pDefArgFlags[nArg].bSuppress)
932                         {
933                             aArgStr += aArgSep;
934                             String sTmp(*(pDesc->ppDefArgNames[nArg]));
935                             sTmp.EraseLeadingAndTrailingChars();
936                             sTmp.SearchAndReplaceAll(' ', '_');
937                             aArgStr += sTmp;
938                         }
939 					}
940 				}
941 			}
942 		}
943 		if (pHdl)
944 		{
945 			if(pHdl->GetEditString().Len()==0)
946 			{
947 				aString = '=';
948 				aString += pAllFuncList->GetSelectEntry();
949 			}
950 			EditView *pEdView=pHdl->GetActiveView();
951 			if(pEdView!=NULL) // @ Wegen Absturz bei Namen festlegen
952 			{
953 				if(nArgs>0)
954 				{
955 					pHdl->InsertFunction(aString);
956 					pEdView->InsertText(aArgStr,sal_True);
957 					ESelection	aESel=pEdView->GetSelection();
958 					aESel.nEndPos=aESel.nStartPos+aFirstArgStr.Len();
959 					pEdView->SetSelection(aESel);
960 					pHdl->DataChanged();
961 				}
962 				else
963 				{
964 					aString.AppendAscii(RTL_CONSTASCII_STRINGPARAM( "()" ));
965 					pEdView->InsertText(aString,sal_False);
966 					pHdl->DataChanged();
967 				}
968 			}
969 		}
970 		InitLRUList();
971 	}
972 	if ( pCurSh )
973 	{
974 		Window* pShellWnd = pCurSh->GetWindow();
975 
976 		if ( pShellWnd )
977 			pShellWnd->GrabFocus();
978 	}
979 
980 
981 }
982 
983 
984 
985 /*************************************************************************
986 #*	Handle:		SelHdl										Datum:06.10.97
987 #*------------------------------------------------------------------------
988 #*
989 #*  Klasse:		ScFunctionDockWin
990 #*
991 #*  Funktion:	Bei einer Aenderung der Kategorie wird die
992 #*				die Liste der Funktionen aktualisiert.
993 #*
994 #*  Input:		---
995 #*
996 #*	Output:		---
997 #*
998 #************************************************************************/
999 
IMPL_LINK(ScFunctionDockWin,SelHdl,ListBox *,pLb)1000 IMPL_LINK( ScFunctionDockWin, SelHdl, ListBox*, pLb )
1001 {
1002 	if ( pLb == &aCatBox)
1003 	{
1004 		UpdateFunctionList();
1005 		SetDescription();
1006 	}
1007 
1008 	if ( pLb == &aFuncList||pLb == &aDDFuncList)
1009 	{
1010 		SetDescription();
1011 	}
1012 
1013 
1014 	//SetSize();
1015 	return 0;
1016 }
1017 
1018 /*************************************************************************
1019 #*	Handle:		SelHdl										Datum:06.10.97
1020 #*------------------------------------------------------------------------
1021 #*
1022 #*  Klasse:		ScFunctionDockWin
1023 #*
1024 #*  Funktion:	Bei einer Aenderung der Kategorie wird die
1025 #*				die Liste der Funktionen aktualisiert.
1026 #*
1027 #*  Input:		---
1028 #*
1029 #*	Output:		---
1030 #*
1031 #************************************************************************/
1032 
IMPL_LINK(ScFunctionDockWin,SetSelectionHdl,void *,pCtrl)1033 IMPL_LINK( ScFunctionDockWin, SetSelectionHdl, void*, pCtrl )
1034 {
1035 	if ((ImageButton *)pCtrl == &aInsertButton ||
1036 		(ListBox *)pCtrl == &aFuncList)
1037 	{
1038 		DoEnter(sal_True);			// Uebernimmt die Eingabe
1039 	}
1040 	//...
1041 
1042 	return 0;
1043 }
1044 
1045 /*************************************************************************
1046 #*	Handle:		SetSplitHdl									Datum:13.10.97
1047 #*------------------------------------------------------------------------
1048 #*
1049 #*  Klasse:		ScFunctionDockWin
1050 #*
1051 #*  Funktion:	Bei einer Aenderung des Split- Controls werden die
1052 #*				einzelnen Controls an die neue Groesse angepasst.
1053 #*
1054 #*  Input:		Zeiger auf Control
1055 #*
1056 #*	Output:		---
1057 #*
1058 #************************************************************************/
1059 
IMPL_LINK(ScFunctionDockWin,SetSplitHdl,ScPrivatSplit *,pCtrl)1060 IMPL_LINK( ScFunctionDockWin, SetSplitHdl, ScPrivatSplit*, pCtrl )
1061 {
1062 	if (pCtrl == &aPrivatSplit)
1063 	{
1064 		short nDeltaY=aPrivatSplit.GetDeltaY();
1065 		Size aFLSize=aFuncList.GetSizePixel();
1066 		Size aFDSize=aFiFuncDesc.GetSizePixel();
1067 		Point aFDTopLeft=aFiFuncDesc.GetPosPixel();
1068 
1069 		aFLSize.Height()+=nDeltaY;
1070 		aFDSize.Height()-=nDeltaY;
1071 		aFDTopLeft.Y()+=nDeltaY;
1072 		aFuncList.SetSizePixel(aFLSize);
1073 		aFiFuncDesc.SetPosPixel(aFDTopLeft);
1074 		aFiFuncDesc.SetSizePixel(aFDSize);
1075 		/*
1076 		aFuncList.Invalidate();
1077 		aFuncList.Update();
1078 		aFiFuncDesc.Invalidate();
1079 		aFiFuncDesc.Update();
1080 		*/
1081 	}
1082 	//...
1083 
1084 	return 0;
1085 }
1086 
ToggleFloatingMode()1087 void ScFunctionDockWin::ToggleFloatingMode()
1088 {
1089 	aSplitterInitPos = Point();
1090 	SfxDockingWindow::ToggleFloatingMode();
1091 
1092 	eSfxNewAlignment=GetAlignment();
1093 	eSfxOldAlignment=eSfxNewAlignment;
1094 
1095 	aOldSize.Height()=0;
1096 	aOldSize.Width()=0;
1097 	aTimer.Start();
1098 }
1099 
IMPL_LINK(ScFunctionDockWin,TimerHdl,Timer *,EMPTYARG)1100 IMPL_LINK( ScFunctionDockWin, TimerHdl, Timer*, EMPTYARG )
1101 {
1102 	CheckAlignment(eSfxOldAlignment,eSfxNewAlignment);
1103 	SetSize();
1104 	return 0;
1105 }
1106 
Initialize(SfxChildWinInfo * pInfo)1107 void ScFunctionDockWin::Initialize(SfxChildWinInfo *pInfo)
1108 {
1109 	String aStr;
1110 	if(pInfo!=NULL)
1111 	{
1112 		if ( pInfo->aExtraString.Len() )
1113 		{
1114 			xub_StrLen nPos = pInfo->aExtraString.Search(
1115 				String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("ScFuncList:")));
1116 
1117 			// Versuche, den Alignment-String "ALIGN:(...)" einzulesen; wenn
1118 			// er nicht vorhanden ist, liegt eine "altere Version vor
1119 			if ( nPos != STRING_NOTFOUND )
1120 			{
1121 				xub_StrLen n1 = pInfo->aExtraString.Search('(', nPos);
1122 				if ( n1 != STRING_NOTFOUND )
1123 				{
1124 					xub_StrLen n2 = pInfo->aExtraString.Search(')', n1);
1125 					if ( n2 != STRING_NOTFOUND )
1126 					{
1127 						// Alignment-String herausschneiden
1128 						aStr = pInfo->aExtraString.Copy(nPos, n2 - nPos + 1);
1129 						pInfo->aExtraString.Erase(nPos, n2 - nPos + 1);
1130 						aStr.Erase(0, n1-nPos+1);
1131 					}
1132 				}
1133 			}
1134 		}
1135 	}
1136 	SfxDockingWindow::Initialize(pInfo);
1137 
1138 	if ( aStr.Len())
1139 	{
1140 		aSplitterInitPos=aPrivatSplit.GetPosPixel();
1141 		aSplitterInitPos.Y()=(sal_uInt16) aStr.ToInt32();
1142 		xub_StrLen n1 = aStr.Search(';');
1143 		aStr.Erase(0, n1+1);
1144         sal_uInt16 nSelPos=sal::static_int_cast<sal_uInt16>( aStr.ToInt32() );
1145 		aCatBox.SelectEntryPos(nSelPos);
1146 		SelHdl(&aCatBox);
1147 
1148 		//	if the window has already been shown (from SfxDockingWindow::Initialize if docked),
1149 		//	set the splitter position now, otherwise it is set in StateChanged with type INITSHOW
1150 
1151 		UseSplitterInitPos();
1152 	}
1153 }
1154 
1155 //-------------------------------------------------------------------------
1156 
FillInfo(SfxChildWinInfo & rInfo) const1157 void ScFunctionDockWin::FillInfo(SfxChildWinInfo& rInfo) const
1158 {
1159 	SfxDockingWindow::FillInfo(rInfo);
1160 	Point aPoint=aPrivatSplit.GetPosPixel();
1161 	rInfo.aExtraString.AppendAscii(RTL_CONSTASCII_STRINGPARAM( "ScFuncList:(" ));
1162 	rInfo.aExtraString += String::CreateFromInt32(aPoint.Y());
1163 	rInfo.aExtraString += ';';
1164 	rInfo.aExtraString += String::CreateFromInt32(aCatBox.GetSelectEntryPos());
1165 	rInfo.aExtraString += ')';
1166 }
1167 
UseSplitterInitPos()1168 void ScFunctionDockWin::UseSplitterInitPos()
1169 {
1170 	if ( IsVisible() && aPrivatSplit.IsEnabled() && aSplitterInitPos != Point() )
1171 	{
1172 		aPrivatSplit.MoveSplitTo(aSplitterInitPos);
1173 		aSplitterInitPos = Point();		// use only once
1174 	}
1175 }
1176 
StateChanged(StateChangedType nStateChange)1177 void ScFunctionDockWin::StateChanged( StateChangedType nStateChange )
1178 {
1179 	SfxDockingWindow::StateChanged( nStateChange );
1180 
1181 	if (nStateChange == STATE_CHANGE_INITSHOW)
1182 	{
1183 		UseSplitterInitPos();			//	set initial splitter position if necessary
1184 	}
1185 }
1186 
1187 
1188