merge the formfield patch from ooo-build
[ooovba.git] / sc / source / ui / formdlg / dwfunctr.cxx
blobdf6c8ee4d473ccdc658e5de73b65ba0307ef0444
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: dwfunctr.cxx,v $
10 * $Revision: 1.15 $
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_sc.hxx"
36 // INCLUDE ---------------------------------------------------------------
38 #include <svx/editview.hxx>
39 #include <sfx2/bindings.hxx>
40 #include <sfx2/dispatch.hxx>
41 #include <sfx2/objsh.hxx>
42 #include <sfx2/viewsh.hxx>
44 #include "sc.hrc"
45 #include "global.hxx" // ScAddress
46 #include "scresid.hxx"
47 #include "reffact.hxx"
48 #include "document.hxx"
49 #include "cell.hxx"
50 #include "scmod.hxx"
51 #include "inputhdl.hxx"
52 #include "tabvwsh.hxx"
53 #include "appoptio.hxx"
54 #include "compiler.hxx"
56 #include "dwfunctr.hrc"
57 #include "dwfunctr.hxx"
59 // -----------------------------------------------------------------------
61 #define ARG_SEPERATOR String("; ")
62 SFX_IMPL_DOCKINGWINDOW( ScFunctionChildWindow, FID_FUNCTION_BOX )
64 /*************************************************************************
65 #* Member: ScFunctionChildWindow Datum:06.10.97
66 #*------------------------------------------------------------------------
68 #* Klasse: ScFunctionChildWindow
70 #* Funktion: Konstruktor der Klasse ScFunctionChildWindow
71 #* Ableitung vom SfxChildWindow als "Behaelter" fuer
72 #* Funktions- Fenster in Clac
74 #* Input: ---
76 #* Output: ---
78 #************************************************************************/
80 __EXPORT ScFunctionChildWindow::ScFunctionChildWindow( Window* pParentP,
81 USHORT nId,
82 SfxBindings* pBindings,
83 SfxChildWinInfo* pInfo ) :
84 SfxChildWindow( pParentP, nId )
86 ScFunctionDockWin* pWin = new ScFunctionDockWin( pBindings, this,
87 pParentP, ScResId( FID_FUNCTION_BOX ) );
88 pWindow = pWin;
90 eChildAlignment = SFX_ALIGN_RIGHT;
92 pWin->Initialize( pInfo );
95 /*************************************************************************
96 #* Member: ScFunctionDockWin Datum:06.10.97
97 #*------------------------------------------------------------------------
99 #* Klasse: ScFunctionDockWin
101 #* Funktion: Konstruktor der Klasse ScFunctionDockWin
103 #* Input: Sfx- Verknuepfungen, Fenster, Resource
105 #* Output: ---
107 #************************************************************************/
109 ScFunctionDockWin::ScFunctionDockWin( SfxBindings* pBindingsP,
110 SfxChildWindow *pCW, Window* pParent, const ResId& rResId ) :
112 SfxDockingWindow( pBindingsP, pCW, pParent, rResId ),
113 aPrivatSplit ( this, ResId( FT_SPLIT, *rResId.GetResMgr() ),SC_SPLIT_VERT),
114 aCatBox ( this, ResId( CB_CAT, *rResId.GetResMgr() ) ),
115 aFuncList ( this, ResId( LB_FUNC, *rResId.GetResMgr() ) ),
116 aDDFuncList ( this, ResId( DDLB_FUNC, *rResId.GetResMgr() ) ),
117 aInsertButton ( this, ResId( IMB_INSERT, *rResId.GetResMgr() ) ),
118 aFiFuncDesc ( this, ResId( FI_FUNCDESC, *rResId.GetResMgr() ) ),
119 aOldSize (0,0)
121 FreeResource();
122 InitLRUList();
123 SetStyle(GetStyle()|WB_CLIPCHILDREN);
125 aTimer.SetTimeout(200);
126 aTimer.SetTimeoutHdl(LINK( this, ScFunctionDockWin, TimerHdl));
128 eSfxNewAlignment=GetAlignment();
129 eSfxOldAlignment=eSfxNewAlignment;
130 aFiFuncDesc.SetUpdateMode(TRUE);
131 pAllFuncList=&aFuncList;
132 aDDFuncList.Disable();
133 aDDFuncList.Hide();
134 nArgs=0;
135 nDockMode=0;
136 bSizeFlag=FALSE;
137 aCatBox.SetDropDownLineCount(9);
138 Font aFont=aFiFuncDesc.GetFont();
139 aFont.SetColor(Color(COL_BLACK));
140 aFiFuncDesc.SetFont(aFont);
141 aFiFuncDesc.SetBackground( GetBackground() ); //! never transparent?
142 //? SetBackground();
144 Link aLink=LINK( this, ScFunctionDockWin, SelHdl);
145 aCatBox.SetSelectHdl(aLink);
146 aFuncList.SetSelectHdl(aLink);
147 aDDFuncList.SetSelectHdl(aLink);
149 Link a2Link=LINK( this, ScFunctionDockWin, SetSelectionHdl);
150 aFuncList.SetDoubleClickHdl(a2Link);
151 aDDFuncList.SetSelectHdl(aLink);
152 aInsertButton.SetClickHdl(a2Link);
154 Link a3Link=LINK( this, ScFunctionDockWin, SetSplitHdl);
155 aPrivatSplit.SetCtrModifiedHdl(a3Link);
156 StartListening( *pBindingsP, TRUE );
158 Point aTopLeft=aCatBox.GetPosPixel();
159 //String aString=aCatBox.GetEntry( 0)+String("www");
160 String aString=String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("ww"));
161 Size aTxtSize( aFiFuncDesc.GetTextWidth(aString), aFiFuncDesc.GetTextHeight() );
162 nMinWidth=aTxtSize.Width()+aTopLeft.X()
163 +2*aFuncList.GetPosPixel().X();
164 nMinHeight=19*aTxtSize.Height();
165 aCatBox.SelectEntryPos(0);
167 Range aYRange(3*aTxtSize.Height()+aFuncList.GetPosPixel().Y(),
168 GetOutputSizePixel().Height()-2*aTxtSize.Height());
169 aPrivatSplit.SetYRange(aYRange);
170 SelHdl(&aCatBox);
171 bInit=TRUE;
174 /*************************************************************************
175 #* Member: ScFunctionDockWin Datum:06.10.97
176 #*------------------------------------------------------------------------
178 #* Klasse: ScFunctionDockWin
180 #* Funktion: Destruktor der Klasse ScFunctionDockWin
182 #* Input: ---
184 #* Output: ---
186 #************************************************************************/
188 __EXPORT ScFunctionDockWin::~ScFunctionDockWin()
190 EndListening( GetBindings() );
193 /*************************************************************************
194 #* Member: UpdateFunctionList Datum:06.10.97
195 #*------------------------------------------------------------------------
197 #* Klasse: ScFunctionDockWin
199 #* Funktion: Aktualisiert die Liste der Funktionen ab-
200 #* haengig von der eingestellten Kategorie.
202 #* Input: ---
204 #* Output: ---
206 #************************************************************************/
208 void ScFunctionDockWin::InitLRUList()
210 const ScAppOptions& rAppOpt = SC_MOD()->GetAppOptions();
211 USHORT nLRUFuncCount = Min( rAppOpt.GetLRUFuncListCount(), (USHORT)LRU_MAX );
212 USHORT* pLRUListIds = rAppOpt.GetLRUFuncList();
214 USHORT i;
215 for ( i=0; i<LRU_MAX; i++ )
216 aLRUList[i] = NULL;
218 if ( pLRUListIds )
220 ScFunctionMgr* pFuncMgr = ScGlobal::GetStarCalcFunctionMgr();
221 for ( i=0; i<nLRUFuncCount; i++ )
222 aLRUList[i] = pFuncMgr->Get( pLRUListIds[i] );
225 USHORT nSelPos = aCatBox.GetSelectEntryPos();
227 if(nSelPos == 0)
228 UpdateFunctionList();
231 /*************************************************************************
232 #* Member: UpdateFunctionList Datum:10.12.99
233 #*------------------------------------------------------------------------
235 #* Klasse: ScFunctionDockWin
237 #* Funktion: Aktualisiert die Liste der zuletzt verwendeten Funktionen.
239 #* Input: ---
241 #* Output: ---
243 #************************************************************************/
245 void ScFunctionDockWin::UpdateLRUList()
247 if (pFuncDesc && pFuncDesc->nFIndex!=0)
249 ScModule* pScMod = SC_MOD();
250 pScMod->InsertEntryToLRUList(pFuncDesc->nFIndex);
255 /*************************************************************************
256 #* Member: SetSize Datum:06.10.97
257 #*------------------------------------------------------------------------
259 #* Klasse: ScFunctionDockWin
261 #* Funktion: Groesse fuer die einzelnen Controls einzustellen.
263 #* Input: ---
265 #* Output: ---
267 #************************************************************************/
269 void ScFunctionDockWin::SetSize()
271 USHORT nSelEntry=0;
272 SfxChildAlignment aChildAlign=eSfxOldAlignment;//GetAlignment();
273 short nNewDockMode;
274 switch(aChildAlign)
276 case SFX_ALIGN_HIGHESTTOP:
277 case SFX_ALIGN_TOP:
278 case SFX_ALIGN_LOWESTTOP:
279 case SFX_ALIGN_LOWESTBOTTOM:
280 case SFX_ALIGN_BOTTOM:
281 case SFX_ALIGN_TOOLBOXTOP:
282 case SFX_ALIGN_TOOLBOXBOTTOM:
285 nNewDockMode=1;
286 if(nDockMode!=nNewDockMode)
288 nDockMode=nNewDockMode;
289 nSelEntry=aFuncList.GetSelectEntryPos();
290 aFuncList.Clear();
291 aFiFuncDesc.SetPosPixel(aFuncList.GetPosPixel());
292 aDDFuncList.Enable();
293 aDDFuncList.Show();
294 aPrivatSplit.Disable();
295 aPrivatSplit.Hide();
296 aFuncList.Disable();
297 aFuncList.Hide();
298 pAllFuncList=&aDDFuncList;
299 SelHdl(&aCatBox);
300 aDDFuncList.SelectEntryPos(nSelEntry);
302 break;
304 default: nNewDockMode=0;
305 if(nDockMode!=nNewDockMode)
307 nDockMode=nNewDockMode;
308 nSelEntry=aDDFuncList.GetSelectEntryPos();
309 aDDFuncList.Clear();
310 aDDFuncList.Disable();
311 aDDFuncList.Hide();
312 aPrivatSplit.Enable();
313 aPrivatSplit.Show();
314 aFuncList.Enable();
315 aFuncList.Show();
316 pAllFuncList=&aFuncList;
317 SelHdl(&aCatBox);
318 aFuncList.SelectEntryPos(nSelEntry);
320 break;
323 if(nDockMode==0)
325 SetLeftRightSize();
327 else
329 SetTopBottonSize();
332 /*************************************************************************
333 #* Member: SetLeftRightSize Datum:15.10.97
334 #*------------------------------------------------------------------------
336 #* Klasse: ScFunctionDockWin
338 #* Funktion: Groesse fuer die einzelnen Controls einstellen,
339 #* wenn Links oder Rechts angedockt wird.
341 #* Input: ---
343 #* Output: ---
345 #************************************************************************/
347 void ScFunctionDockWin::SetLeftRightSize()
349 if(bSizeFlag==FALSE)
351 bSizeFlag=TRUE;
353 Size aDiffSize=GetSizePixel();
354 Size aNewSize=GetOutputSizePixel();
355 aDiffSize.Width()-=aNewSize.Width();
356 aDiffSize.Height()-=aNewSize.Height();
358 //@ SetUpdateMode( FALSE);
360 String aString = String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("ww"));
362 Size aTxtSize( aFuncList.GetTextWidth(aString), aFuncList.GetTextHeight() );
364 Range aYRange(3*aTxtSize.Height()+aFuncList.GetPosPixel().Y(),
365 GetOutputSizePixel().Height()-2*aTxtSize.Height());
366 aPrivatSplit.SetYRange(aYRange);
369 if(aOldSize.Width()!=aNewSize.Width())
370 SetMyWidthLeRi(aNewSize);
372 if(aOldSize.Height()!=aNewSize.Height())
373 SetMyHeightLeRi(aNewSize);
375 aOldSize=aNewSize;
376 aNewSize.Width()+=aDiffSize.Width();
377 aNewSize.Height()+=aDiffSize.Height();
378 //SetSizePixel(aNewSize);
379 //@ SetUpdateMode( TRUE);
380 bSizeFlag=FALSE;
384 /*************************************************************************
385 #* Member: SetTopBottonSize Datum:15.10.97
386 #*------------------------------------------------------------------------
388 #* Klasse: ScFunctionDockWin
390 #* Funktion: Groesse fuer die einzelnen Controls einzustellen.
391 #* wenn oben oder unten angedockt wird.
393 #* Input: ---
395 #* Output: ---
397 #************************************************************************/
399 void ScFunctionDockWin::SetTopBottonSize()
401 if(bSizeFlag==FALSE)
403 bSizeFlag=TRUE;
404 Size aDiffSize=GetSizePixel();
405 Size aNewSize=GetOutputSizePixel();
406 aDiffSize.Width()-=aNewSize.Width();
407 aDiffSize.Height()-=aNewSize.Height();
409 SetMyWidthToBo(aNewSize);
410 SetMyHeightToBo(aNewSize);
412 aNewSize.Width()+=aDiffSize.Width();
413 aNewSize.Height()+=aDiffSize.Height();
414 //SetSizePixel(aNewSize);
415 //@ SetUpdateMode( TRUE);
416 bSizeFlag=FALSE;
420 /*************************************************************************
421 #* Member: SetMyWidthLeRi Datum:15.10.97
422 #*------------------------------------------------------------------------
424 #* Klasse: ScFunctionDockWin
426 #* Funktion: Breite fuer die einzelnen Controls und
427 #* das Fenster einstellen,wenn Li oder Re
429 #* Input: neue Fenstergroesse
431 #* Output: ---
433 #************************************************************************/
435 void ScFunctionDockWin::SetMyWidthLeRi(Size &aNewSize)
437 if((ULONG)aNewSize.Width()<nMinWidth) aNewSize.Width()=nMinWidth;
439 Size aCDSize=aCatBox.GetSizePixel();
440 Size aFLSize=aFuncList.GetSizePixel();
441 Size aSplitterSize=aPrivatSplit.GetSizePixel();
442 Size aFDSize=aFiFuncDesc.GetSizePixel();
444 Point aCDTopLeft=aCatBox.GetPosPixel();
445 Point aFLTopLeft=aFuncList.GetPosPixel();
446 Point aSplitterTopLeft=aPrivatSplit.GetPosPixel();
447 Point aFDTopLeft=aFiFuncDesc.GetPosPixel();
449 aCDSize.Width()=aNewSize.Width()-aCDTopLeft.X()-aFLTopLeft.X();
450 aFLSize.Width()=aNewSize.Width()-2*aFLTopLeft.X();
451 aFDSize.Width()=aFLSize.Width();
452 aSplitterSize.Width()=aFLSize.Width();
454 aCatBox.SetSizePixel(aCDSize);
455 aFuncList.SetSizePixel(aFLSize);
456 aPrivatSplit.SetSizePixel(aSplitterSize);
457 aFiFuncDesc.SetSizePixel(aFDSize);
460 /*************************************************************************
461 #* Member: SetHeight Datum:06.10.97
462 #*------------------------------------------------------------------------
464 #* Klasse: ScFunctionDockWin
466 #* Funktion: Hoehe fuer die einzelnen Controls und
467 #* das Fenster einstellen bei Li oder Re
469 #* Input: neue Fenstergroesse
471 #* Output: ---
473 #************************************************************************/
475 void ScFunctionDockWin::SetMyHeightLeRi(Size &aNewSize)
477 if((ULONG)aNewSize.Height()<nMinHeight) aNewSize.Height()=nMinHeight;
479 Size aFLSize=aFuncList.GetSizePixel();
480 Size aSplitterSize=aPrivatSplit.GetSizePixel();
481 Size aFDSize=aFiFuncDesc.GetSizePixel();
483 Point aFLTopLeft=aFuncList.GetPosPixel();
484 Point aSplitterTopLeft=aPrivatSplit.GetPosPixel();
485 Point aFDTopLeft=aFiFuncDesc.GetPosPixel();
487 long nTxtHeight = aFuncList.GetTextHeight();
489 short nY=(short)(3*nTxtHeight+
490 aFuncList.GetPosPixel().Y()+aSplitterSize.Height());
492 aFDTopLeft.Y()=aNewSize.Height()-aFDSize.Height()-4;
493 if(nY>aFDTopLeft.Y())
495 aFDSize.Height()-=nY-aFDTopLeft.Y();
496 aFDTopLeft.Y()=nY;
498 aSplitterTopLeft.Y()=aFDTopLeft.Y()-aSplitterSize.Height()-1;
499 aFLSize.Height()=aSplitterTopLeft.Y()-aFLTopLeft.Y()-1;
501 aFuncList.SetSizePixel(aFLSize);
502 aPrivatSplit.SetPosPixel(aSplitterTopLeft);
503 aFiFuncDesc.SetPosPixel(aFDTopLeft);
504 aFiFuncDesc.SetSizePixel(aFDSize);
508 /*************************************************************************
509 #* Member: SetMyWidthToBo Datum:16.10.97
510 #*------------------------------------------------------------------------
512 #* Klasse: ScFunctionDockWin
514 #* Funktion: Breite fuer die einzelnen Controls und
515 #* das Fenster einstellen, wenn oben oder
516 #* unten angedockt werden soll.
518 #* Input: neue Fenstergroesse
520 #* Output: ---
522 #************************************************************************/
524 void ScFunctionDockWin::SetMyWidthToBo(Size &aNewSize)
526 if((ULONG)aNewSize.Width()<nMinWidth) aNewSize.Width()=nMinWidth;
528 Size aCDSize=aCatBox.GetSizePixel();
529 Size aDdFLSize=aDDFuncList.GetSizePixel();
530 Size aFDSize=aFiFuncDesc.GetSizePixel();
532 Point aCDTopLeft=aCatBox.GetPosPixel();
533 Point aDdFLTopLeft=aDDFuncList.GetPosPixel();
534 Point aFDTopLeft=aFiFuncDesc.GetPosPixel();
536 aCDSize.Width()=aDdFLTopLeft.X()-aFDTopLeft.X()-aCDTopLeft.X();
537 aDdFLTopLeft.X()=aCDSize.Width()+aCDTopLeft.X()+aFDTopLeft.X();
539 aDdFLSize.Width()=aNewSize.Width()-aDdFLTopLeft.X()-aFDTopLeft.X();
541 aFDSize.Width()=aNewSize.Width()-2*aFDTopLeft.X();
543 aDDFuncList.SetPosPixel(aDdFLTopLeft);
544 aDDFuncList.SetSizePixel(aDdFLSize);
545 aCatBox.SetSizePixel(aCDSize);
546 aFiFuncDesc.SetSizePixel(aFDSize);
549 /*************************************************************************
550 #* Member: SetHeight Datum:16.10.97
551 #*------------------------------------------------------------------------
553 #* Klasse: ScFunctionDockWin
555 #* Funktion: Hoehe fuer die einzelnen Controls und
556 #* das Fenster einstellen, wenn oben oder
557 #* unten angedockt werden soll.
559 #* Input: neue Fenstergroesse
561 #* Output: ---
563 #************************************************************************/
565 void ScFunctionDockWin::SetMyHeightToBo(Size &aNewSize)
567 if((ULONG)aNewSize.Height()<nMinHeight) aNewSize.Height()=nMinHeight;
569 Size aFDSize=aFiFuncDesc.GetSizePixel();
571 Point aFDTopLeft=aFiFuncDesc.GetPosPixel();
572 Point aCBTopLeft=aCatBox.GetPosPixel();
573 aFDSize.Height()=aNewSize.Height()-aFDTopLeft.Y()-aCBTopLeft.Y();
574 aFiFuncDesc.SetSizePixel(aFDSize);
578 /*************************************************************************
579 #* Member: SetDescription Datum:13.10.97
580 #*------------------------------------------------------------------------
582 #* Klasse: ScFunctionDockWin
584 #* Funktion: Erklaerungstext fuer die Funktion einstellen.
586 #* Input: ---
588 #* Output: ---
590 #************************************************************************/
592 void ScFunctionDockWin::SetDescription()
594 aFiFuncDesc.SetText( EMPTY_STRING );
595 const ScFuncDesc* pDesc =
596 (const ScFuncDesc*)pAllFuncList->GetEntryData(
597 pAllFuncList->GetSelectEntryPos() );
598 if (pDesc)
600 pDesc->initArgumentInfo(); // full argument info is needed
602 String aString=pAllFuncList->GetSelectEntry();
603 if(nDockMode==0)
605 aString.AppendAscii(RTL_CONSTASCII_STRINGPARAM( ":\n\n" ));
607 else
609 aString.AppendAscii(RTL_CONSTASCII_STRINGPARAM( ": " ));
612 aString+=pDesc->GetParamList();
614 if(nDockMode==0)
616 aString.AppendAscii(RTL_CONSTASCII_STRINGPARAM( "\n\n" ));
618 else
620 aString += '\n';
623 aString+=*(pDesc->pFuncDesc);
625 aFiFuncDesc.SetText(aString);
626 aFiFuncDesc.StateChanged(STATE_CHANGE_TEXT);
627 aFiFuncDesc.Invalidate();
628 aFiFuncDesc.Update();
633 /*************************************************************************
634 #* Member: Resizing Datum:06.10.97
635 #*------------------------------------------------------------------------
637 #* Klasse: ScFunctionDockWin
639 #* Funktion: Ueberladene Funktion um die Groesse der
640 #* einzelnen Controls einzustellen.
642 #* Input: neue Groesse
644 #* Output: ---
646 #************************************************************************/
648 void __EXPORT ScFunctionDockWin::Resizing( Size& rNewSize )
650 if((ULONG)rNewSize.Width()<nMinWidth) rNewSize.Width()=nMinWidth;
651 if((ULONG)rNewSize.Height()<nMinHeight) rNewSize.Height()=nMinHeight;
655 /*************************************************************************
656 #* Member: Close Datum:07.10.97
657 #*------------------------------------------------------------------------
659 #* Klasse: ScFunctionDockWin
661 #* Funktion: Schliessen des Fensters
663 #* Input: ---
665 #* Output: TRUE
667 #************************************************************************/
669 BOOL __EXPORT ScFunctionDockWin::Close()
671 SfxBoolItem aItem( FID_FUNCTION_BOX, FALSE );
673 GetBindings().GetDispatcher()->Execute( FID_FUNCTION_BOX,
674 SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD,
675 &aItem, 0L );
677 SfxDockingWindow::Close();
679 return( TRUE );
683 /*************************************************************************
684 #* Member: CheckAlignment Datum:16.10.97
685 #*------------------------------------------------------------------------
687 #* Klasse: ScFunctionDockWin
689 #* Funktion: Ueberprueft den Andockmodus und stellt die
690 #* Groessen dementsprechend ein.
692 #* Input: Das neue Alignment
694 #* Output: Das uebergebene Alignment
696 #************************************************************************/
697 SfxChildAlignment __EXPORT ScFunctionDockWin::CheckAlignment(SfxChildAlignment /* abla */,
698 SfxChildAlignment aChildAlign)
700 String aString = String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("ww"));
701 Size aTxtSize( aFiFuncDesc.GetTextWidth(aString), aFiFuncDesc.GetTextHeight() );
702 if(!bInit)
704 eSfxOldAlignment=eSfxNewAlignment;
705 eSfxNewAlignment=aChildAlign;
707 else
709 bInit=FALSE;
710 eSfxOldAlignment=aChildAlign;
711 eSfxNewAlignment=aChildAlign;
714 switch(eSfxOldAlignment)
716 case SFX_ALIGN_HIGHESTTOP:
717 case SFX_ALIGN_TOP:
718 case SFX_ALIGN_LOWESTTOP:
719 case SFX_ALIGN_LOWESTBOTTOM:
720 case SFX_ALIGN_BOTTOM:
721 case SFX_ALIGN_TOOLBOXTOP:
722 case SFX_ALIGN_TOOLBOXBOTTOM:
724 nMinWidth= 0;/*aDDFuncList.GetPosPixel().X()+
725 10*aTxtSize.Width()+
726 aFuncList.GetPosPixel().X();*/
727 nMinHeight=0;
729 break;
731 case SFX_ALIGN_NOALIGNMENT:
733 aString = aCatBox.GetEntry(0);
734 aString.AppendAscii(RTL_CONSTASCII_STRINGPARAM("www"));
735 aTxtSize = Size( aFiFuncDesc.GetTextWidth(aString),
736 aFiFuncDesc.GetTextHeight() );
738 default: Point aTopLeft=aCatBox.GetPosPixel();
739 nMinWidth=aTxtSize.Width()+aTopLeft.X()
740 +2*aFuncList.GetPosPixel().X();
741 nMinHeight=19*aTxtSize.Height();
742 //aCatBox.SelectEntryPos(0);
744 break;
747 return aChildAlign;
749 /*************************************************************************
750 #* Member: Close Datum:07.10.97
751 #*------------------------------------------------------------------------
753 #* Klasse: ScFunctionDockWin
755 #* Funktion: Aenderungen erkennen
757 #* Input: ---
759 #* Output: TRUE
761 #************************************************************************/
762 void ScFunctionDockWin::Notify( SfxBroadcaster&, const SfxHint& /* rHint */ )
764 // const SfxPoolItemHint *pPoolItemHint = PTR_CAST(SfxPoolItemHint, &rHint);
766 if ( pPoolItemHint
767 && ( pPoolItemHint->GetObject()->ISA( SvxColorTableItem ) ) )
769 // Die Liste der Farben hat sich geaendert
770 pColorTable = ( (SvxColorTableItem*) pPoolItemHint->GetObject() )->GetColorTable();
771 FillValueSet();
777 /*************************************************************************
778 #* Member: Resize Datum:06.10.97
779 #*------------------------------------------------------------------------
781 #* Klasse: ScFunctionDockWin
783 #* Funktion: Ueberladene Funktion um die Groesse der
784 #* einzelnen Controls einzustellen.
786 #* Input: neue Groesse
788 #* Output: ---
790 #************************************************************************/
792 void __EXPORT ScFunctionDockWin::Resize()
794 if ( !IsFloatingMode() ||
795 !GetFloatingWindow()->IsRollUp() )
797 Size aQSize=GetOutputSizePixel();
798 Resizing( aQSize);
799 SetSize();
801 SfxDockingWindow::Resize();
804 /*************************************************************************
805 #* Member: UpdateFunctionList Datum:06.10.97
806 #*------------------------------------------------------------------------
808 #* Klasse: ScFunctionDockWin
810 #* Funktion: Aktualisiert die Liste der Funktionen ab-
811 #* haengig von der eingestellten Kategorie.
813 #* Input: ---
815 #* Output: ---
817 #************************************************************************/
819 void ScFunctionDockWin::UpdateFunctionList()
821 USHORT nSelPos = aCatBox.GetSelectEntryPos();
822 USHORT nCategory = ( LISTBOX_ENTRY_NOTFOUND != nSelPos )
823 ? (nSelPos-1) : 0;
825 pAllFuncList->Clear();
826 pAllFuncList->SetUpdateMode( FALSE );
828 if ( nSelPos > 0 )
830 ScFunctionMgr* pFuncMgr = ScGlobal::GetStarCalcFunctionMgr();
832 const ScFuncDesc* pDesc = pFuncMgr->First( nCategory );
833 while ( pDesc )
835 pAllFuncList->SetEntryData(
836 pAllFuncList->InsertEntry( *(pDesc->pFuncName) ),
837 (void*)pDesc );
838 pDesc = pFuncMgr->Next();
841 else // LRU-Liste
843 for ( USHORT i=0; i<LRU_MAX && aLRUList[i]; i++ )
845 const ScFuncDesc* pDesc = aLRUList[i];
846 pAllFuncList->SetEntryData(
847 pAllFuncList->InsertEntry( *(pDesc->pFuncName) ),
848 (void*)pDesc );
853 //------------------------------------------------------
854 pAllFuncList->SetUpdateMode( TRUE );
856 if ( pAllFuncList->GetEntryCount() > 0 )
858 pAllFuncList->Enable();
859 pAllFuncList->SelectEntryPos( 0 );
861 else
863 pAllFuncList->Disable();
867 /*************************************************************************
868 #* Member: DoEnter Datum:06.10.97
869 #*------------------------------------------------------------------------
871 #* Klasse: ScFunctionDockWin
873 #* Funktion: Eingabe ins Dokument uebernehmen. Wird aufgerufen
874 #* nach betaetigen der Uebernehmen- Schaltflaeche
875 #* oder einem Doppelklick in die Funktionsliste.
877 #* Input: ---
879 #* Output: ---
881 #************************************************************************/
883 void ScFunctionDockWin::DoEnter(BOOL /* bOk */) //@@ ???
885 String aFirstArgStr;
886 String aParaStr;
887 String aArgStr;
888 String aString=pAllFuncList->GetSelectEntry();
889 SfxViewShell* pCurSh = SfxViewShell::Current();
890 nArgs=0;
892 if(aString.Len()>0)
895 ScModule* pScMod = SC_MOD();
896 ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, pCurSh);
897 ScInputHandler* pHdl = pScMod->GetInputHdl( pViewSh );
898 if(!pScMod->IsEditMode())
900 pScMod->SetInputMode(SC_INPUT_TABLE);
901 aString = '=';
902 aString += pAllFuncList->GetSelectEntry();
903 if (pHdl)
904 pHdl->ClearText();
906 const ScFuncDesc* pDesc =
907 (const ScFuncDesc*)pAllFuncList->GetEntryData(
908 pAllFuncList->GetSelectEntryPos() );
909 if (pDesc)
911 pFuncDesc=pDesc;
912 UpdateLRUList();
913 nArgs = pDesc->nArgCount;
914 if(nArgs>0)
916 // NOTE: Theoretically the first parameter could have the
917 // suppress flag as well, but practically it doesn't.
918 aFirstArgStr = *(pDesc->ppDefArgNames[0]);
919 aFirstArgStr.EraseLeadingAndTrailingChars();
920 aFirstArgStr.SearchAndReplaceAll(' ', '_');
921 aArgStr = aFirstArgStr;
922 if ( nArgs != VAR_ARGS )
923 { // no VarArgs or Fix plus VarArgs, but not VarArgs only
924 String aArgSep = String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM( "; " ));
925 USHORT nFix = ( nArgs < VAR_ARGS ? nArgs : nArgs - VAR_ARGS + 1 );
926 for ( USHORT nArg = 1;
927 nArg < nFix && !pDesc->pDefArgFlags[nArg].bOptional; nArg++ )
929 if (!pDesc->pDefArgFlags[nArg].bSuppress)
931 aArgStr += aArgSep;
932 String sTmp(*(pDesc->ppDefArgNames[nArg]));
933 sTmp.EraseLeadingAndTrailingChars();
934 sTmp.SearchAndReplaceAll(' ', '_');
935 aArgStr += sTmp;
941 if (pHdl)
943 if(pHdl->GetEditString().Len()==0)
945 aString = '=';
946 aString += pAllFuncList->GetSelectEntry();
948 EditView *pEdView=pHdl->GetActiveView();
949 if(pEdView!=NULL) // @ Wegen Absturz bei Namen festlegen
951 if(nArgs>0)
953 pHdl->InsertFunction(aString);
954 pEdView->InsertText(aArgStr,TRUE);
955 ESelection aESel=pEdView->GetSelection();
956 aESel.nEndPos=aESel.nStartPos+aFirstArgStr.Len();
957 pEdView->SetSelection(aESel);
958 pHdl->DataChanged();
960 else
962 aString.AppendAscii(RTL_CONSTASCII_STRINGPARAM( "()" ));
963 pEdView->InsertText(aString,FALSE);
964 pHdl->DataChanged();
968 InitLRUList();
970 if ( pCurSh )
972 Window* pShellWnd = pCurSh->GetWindow();
974 if ( pShellWnd )
975 pShellWnd->GrabFocus();
983 /*************************************************************************
984 #* Handle: SelHdl Datum:06.10.97
985 #*------------------------------------------------------------------------
987 #* Klasse: ScFunctionDockWin
989 #* Funktion: Bei einer Aenderung der Kategorie wird die
990 #* die Liste der Funktionen aktualisiert.
992 #* Input: ---
994 #* Output: ---
996 #************************************************************************/
998 IMPL_LINK( ScFunctionDockWin, SelHdl, ListBox*, pLb )
1000 if ( pLb == &aCatBox)
1002 UpdateFunctionList();
1003 SetDescription();
1006 if ( pLb == &aFuncList||pLb == &aDDFuncList)
1008 SetDescription();
1012 //SetSize();
1013 return 0;
1016 /*************************************************************************
1017 #* Handle: SelHdl Datum:06.10.97
1018 #*------------------------------------------------------------------------
1020 #* Klasse: ScFunctionDockWin
1022 #* Funktion: Bei einer Aenderung der Kategorie wird die
1023 #* die Liste der Funktionen aktualisiert.
1025 #* Input: ---
1027 #* Output: ---
1029 #************************************************************************/
1031 IMPL_LINK( ScFunctionDockWin, SetSelectionHdl, void*, pCtrl )
1033 if ((ImageButton *)pCtrl == &aInsertButton ||
1034 (ListBox *)pCtrl == &aFuncList)
1036 DoEnter(TRUE); // Uebernimmt die Eingabe
1038 //...
1040 return 0;
1043 /*************************************************************************
1044 #* Handle: SetSplitHdl Datum:13.10.97
1045 #*------------------------------------------------------------------------
1047 #* Klasse: ScFunctionDockWin
1049 #* Funktion: Bei einer Aenderung des Split- Controls werden die
1050 #* einzelnen Controls an die neue Groesse angepasst.
1052 #* Input: Zeiger auf Control
1054 #* Output: ---
1056 #************************************************************************/
1058 IMPL_LINK( ScFunctionDockWin, SetSplitHdl, ScPrivatSplit*, pCtrl )
1060 if (pCtrl == &aPrivatSplit)
1062 short nDeltaY=aPrivatSplit.GetDeltaY();
1063 Size aFLSize=aFuncList.GetSizePixel();
1064 Size aFDSize=aFiFuncDesc.GetSizePixel();
1065 Point aFDTopLeft=aFiFuncDesc.GetPosPixel();
1067 aFLSize.Height()+=nDeltaY;
1068 aFDSize.Height()-=nDeltaY;
1069 aFDTopLeft.Y()+=nDeltaY;
1070 aFuncList.SetSizePixel(aFLSize);
1071 aFiFuncDesc.SetPosPixel(aFDTopLeft);
1072 aFiFuncDesc.SetSizePixel(aFDSize);
1074 aFuncList.Invalidate();
1075 aFuncList.Update();
1076 aFiFuncDesc.Invalidate();
1077 aFiFuncDesc.Update();
1080 //...
1082 return 0;
1085 void ScFunctionDockWin::ToggleFloatingMode()
1087 aSplitterInitPos = Point();
1088 SfxDockingWindow::ToggleFloatingMode();
1090 eSfxNewAlignment=GetAlignment();
1091 eSfxOldAlignment=eSfxNewAlignment;
1093 aOldSize.Height()=0;
1094 aOldSize.Width()=0;
1095 aTimer.Start();
1098 IMPL_LINK( ScFunctionDockWin, TimerHdl, Timer*, EMPTYARG )
1100 CheckAlignment(eSfxOldAlignment,eSfxNewAlignment);
1101 SetSize();
1102 return 0;
1105 void ScFunctionDockWin::Initialize(SfxChildWinInfo *pInfo)
1107 String aStr;
1108 if(pInfo!=NULL)
1110 if ( pInfo->aExtraString.Len() )
1112 xub_StrLen nPos = pInfo->aExtraString.Search(
1113 String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("ScFuncList:")));
1115 // Versuche, den Alignment-String "ALIGN:(...)" einzulesen; wenn
1116 // er nicht vorhanden ist, liegt eine "altere Version vor
1117 if ( nPos != STRING_NOTFOUND )
1119 xub_StrLen n1 = pInfo->aExtraString.Search('(', nPos);
1120 if ( n1 != STRING_NOTFOUND )
1122 xub_StrLen n2 = pInfo->aExtraString.Search(')', n1);
1123 if ( n2 != STRING_NOTFOUND )
1125 // Alignment-String herausschneiden
1126 aStr = pInfo->aExtraString.Copy(nPos, n2 - nPos + 1);
1127 pInfo->aExtraString.Erase(nPos, n2 - nPos + 1);
1128 aStr.Erase(0, n1-nPos+1);
1134 SfxDockingWindow::Initialize(pInfo);
1136 if ( aStr.Len())
1138 aSplitterInitPos=aPrivatSplit.GetPosPixel();
1139 aSplitterInitPos.Y()=(USHORT) aStr.ToInt32();
1140 xub_StrLen n1 = aStr.Search(';');
1141 aStr.Erase(0, n1+1);
1142 USHORT nSelPos=sal::static_int_cast<USHORT>( aStr.ToInt32() );
1143 aCatBox.SelectEntryPos(nSelPos);
1144 SelHdl(&aCatBox);
1146 // if the window has already been shown (from SfxDockingWindow::Initialize if docked),
1147 // set the splitter position now, otherwise it is set in StateChanged with type INITSHOW
1149 UseSplitterInitPos();
1153 //-------------------------------------------------------------------------
1155 void ScFunctionDockWin::FillInfo(SfxChildWinInfo& rInfo) const
1157 SfxDockingWindow::FillInfo(rInfo);
1158 Point aPoint=aPrivatSplit.GetPosPixel();
1159 rInfo.aExtraString.AppendAscii(RTL_CONSTASCII_STRINGPARAM( "ScFuncList:(" ));
1160 rInfo.aExtraString += String::CreateFromInt32(aPoint.Y());
1161 rInfo.aExtraString += ';';
1162 rInfo.aExtraString += String::CreateFromInt32(aCatBox.GetSelectEntryPos());
1163 rInfo.aExtraString += ')';
1166 void ScFunctionDockWin::UseSplitterInitPos()
1168 if ( IsVisible() && aPrivatSplit.IsEnabled() && aSplitterInitPos != Point() )
1170 aPrivatSplit.MoveSplitTo(aSplitterInitPos);
1171 aSplitterInitPos = Point(); // use only once
1175 void ScFunctionDockWin::StateChanged( StateChangedType nStateChange )
1177 SfxDockingWindow::StateChanged( nStateChange );
1179 if (nStateChange == STATE_CHANGE_INITSHOW)
1181 UseSplitterInitPos(); // set initial splitter position if necessary