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