fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / formdlg / dwfunctr.cxx
blobd1a331f270aa2a6d5c9d5e7c3d103a1793404165
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <comphelper/string.hxx>
21 #include <editeng/editview.hxx>
22 #include <sfx2/bindings.hxx>
23 #include <sfx2/dispatch.hxx>
24 #include <sfx2/objsh.hxx>
25 #include <sfx2/viewsh.hxx>
27 #include "sc.hrc"
28 #include "global.hxx"
29 #include "scresid.hxx"
30 #include "reffact.hxx"
31 #include "document.hxx"
32 #include "formulacell.hxx"
33 #include "scmod.hxx"
34 #include "inputhdl.hxx"
35 #include "tabvwsh.hxx"
36 #include "appoptio.hxx"
37 #include "compiler.hxx"
39 #include "dwfunctr.hrc"
40 #include "dwfunctr.hxx"
42 SFX_IMPL_DOCKINGWINDOW_WITHID( ScFunctionChildWindow, FID_FUNCTION_BOX )
44 /*************************************************************************
45 #* Member: ScFunctionChildWindow
46 #*------------------------------------------------------------------------
48 #* Klasse: ScFunctionChildWindow
50 #* Funktion: Konstruktor der Klasse ScFunctionChildWindow
51 #* Ableitung vom SfxChildWindow als "Behaelter" fuer
52 #* Funktions- Fenster in Clac
54 #* Input: ---
56 #* Output: ---
58 #************************************************************************/
60 ScFunctionChildWindow::ScFunctionChildWindow( vcl::Window* pParentP,
61 sal_uInt16 nId,
62 SfxBindings* pBindings,
63 SfxChildWinInfo* pInfo ) :
64 SfxChildWindow( pParentP, nId )
66 VclPtr<ScFunctionDockWin> pWin = VclPtr<ScFunctionDockWin>::Create( pBindings, this,
67 pParentP, ScResId( FID_FUNCTION_BOX ) );
68 pWindow = pWin;
70 eChildAlignment = SfxChildAlignment::RIGHT;
72 pWin->Initialize( pInfo );
75 /*************************************************************************
76 #* Member: ScFunctionDockWin
77 #*------------------------------------------------------------------------
79 #* Klasse: ScFunctionDockWin
81 #* Funktion: Konstruktor der Klasse ScFunctionDockWin
83 #* Input: Sfx- Verknuepfungen, Fenster, Resource
85 #* Output: ---
87 #************************************************************************/
89 ScFunctionDockWin::ScFunctionDockWin( SfxBindings* pBindingsP,
90 SfxChildWindow *pCW, vcl::Window* pParent, const ResId& rResId ) :
92 SfxDockingWindow( pBindingsP, pCW, pParent, rResId ),
93 aPrivatSplit ( VclPtr<ScPrivatSplit>::Create( this, ResId( FT_SPLIT, *rResId.GetResMgr() ),SC_SPLIT_VERT) ),
94 aCatBox ( VclPtr<ListBox>::Create( this, ResId( CB_CAT, *rResId.GetResMgr() ) ) ),
95 aFuncList ( VclPtr<ListBox>::Create( this, ResId( LB_FUNC, *rResId.GetResMgr() ) ) ),
96 aDDFuncList ( VclPtr<ListBox>::Create( this, ResId( DDLB_FUNC, *rResId.GetResMgr() ) ) ),
97 aInsertButton ( VclPtr<ImageButton>::Create( this, ResId( IMB_INSERT, *rResId.GetResMgr() ) ) ),
98 aFiFuncDesc ( VclPtr<FixedText>::Create( this, ResId( FI_FUNCDESC, *rResId.GetResMgr() ) ) ),
99 aOldSize (0,0),
100 pFuncDesc (NULL)
102 FreeResource();
103 InitLRUList();
104 SetStyle(GetStyle()|WB_CLIPCHILDREN);
106 aIdle.SetPriority(SchedulerPriority::LOWER);
107 aIdle.SetIdleHdl(LINK( this, ScFunctionDockWin, TimerHdl));
109 if (pCW != NULL)
110 eSfxNewAlignment=GetAlignment();
111 else
112 eSfxNewAlignment=SfxChildAlignment::RIGHT;
113 eSfxOldAlignment=eSfxNewAlignment;
114 aFiFuncDesc->SetUpdateMode(true);
115 pAllFuncList=aFuncList.get();
116 aDDFuncList->Disable();
117 aDDFuncList->Hide();
118 nArgs=0;
119 nDockMode=0;
120 bSizeFlag=false;
121 aCatBox->SetDropDownLineCount(9);
122 vcl::Font aFont=aFiFuncDesc->GetFont();
123 aFont.SetColor(Color(COL_BLACK));
124 aFiFuncDesc->SetFont(aFont);
125 aFiFuncDesc->SetBackground( GetBackground() ); //! never transparent?
127 Link<> aLink=LINK( this, ScFunctionDockWin, SelHdl);
128 aCatBox->SetSelectHdl(aLink);
129 aFuncList->SetSelectHdl(aLink);
130 aDDFuncList->SetSelectHdl(aLink);
132 Link<> a2Link=LINK( this, ScFunctionDockWin, SetSelectionHdl);
133 aFuncList->SetDoubleClickHdl(a2Link);
134 aDDFuncList->SetSelectHdl(aLink);
135 aInsertButton->SetClickHdl(a2Link);
137 Link<> a3Link=LINK( this, ScFunctionDockWin, SetSplitHdl);
138 aPrivatSplit->SetCtrModifiedHdl(a3Link);
139 StartListening( *pBindingsP, true );
141 Point aTopLeft=aCatBox->GetPosPixel();
142 OUString aString("ww");
143 Size aTxtSize( aFiFuncDesc->GetTextWidth(aString), aFiFuncDesc->GetTextHeight() );
144 nMinWidth=aTxtSize.Width()+aTopLeft.X()
145 +2*aFuncList->GetPosPixel().X();
146 nMinHeight=19*aTxtSize.Height();
147 aCatBox->SelectEntryPos(0);
149 Range aYRange(3*aTxtSize.Height()+aFuncList->GetPosPixel().Y(),
150 GetOutputSizePixel().Height()-2*aTxtSize.Height());
151 aPrivatSplit->SetYRange(aYRange);
152 SelHdl(aCatBox.get());
153 bInit = true;
156 /*************************************************************************
157 #* Member: ScFunctionDockWin
158 #*------------------------------------------------------------------------
160 #* Klasse: ScFunctionDockWin
162 #* Funktion: Destruktor der Klasse ScFunctionDockWin
164 #* Input: ---
166 #* Output: ---
168 #************************************************************************/
170 ScFunctionDockWin::~ScFunctionDockWin()
172 disposeOnce();
175 void ScFunctionDockWin::dispose()
177 EndListening( GetBindings() );
178 aPrivatSplit.disposeAndClear();
179 aCatBox.disposeAndClear();
180 aFuncList.disposeAndClear();
181 aDDFuncList.disposeAndClear();
182 aInsertButton.disposeAndClear();
183 aFiFuncDesc.disposeAndClear();
184 pAllFuncList.clear();
185 SfxDockingWindow::dispose();
188 /*************************************************************************
189 #* Member: UpdateFunctionList
190 #*------------------------------------------------------------------------
192 #* Klasse: ScFunctionDockWin
194 #* Funktion: Aktualisiert die Liste der Funktionen ab-
195 #* haengig von der eingestellten Kategorie.
197 #* Input: ---
199 #* Output: ---
201 #************************************************************************/
203 void ScFunctionDockWin::InitLRUList()
205 ScFunctionMgr* pFuncMgr = ScGlobal::GetStarCalcFunctionMgr();
206 pFuncMgr->fillLastRecentlyUsedFunctions(aLRUList);
208 sal_Int32 nSelPos = aCatBox->GetSelectEntryPos();
210 if(nSelPos == 0)
211 UpdateFunctionList();
214 /*************************************************************************
215 #* Member: UpdateFunctionList
216 #*------------------------------------------------------------------------
218 #* Klasse: ScFunctionDockWin
220 #* Funktion: Aktualisiert die Liste der zuletzt verwendeten Funktionen.
222 #* Input: ---
224 #* Output: ---
226 #************************************************************************/
228 void ScFunctionDockWin::UpdateLRUList()
230 if (pFuncDesc && pFuncDesc->nFIndex!=0)
232 ScModule* pScMod = SC_MOD();
233 pScMod->InsertEntryToLRUList(pFuncDesc->nFIndex);
237 /*************************************************************************
238 #* Member: SetSize
239 #*------------------------------------------------------------------------
241 #* Klasse: ScFunctionDockWin
243 #* Funktion: Groesse fuer die einzelnen Controls einzustellen.
245 #* Input: ---
247 #* Output: ---
249 #************************************************************************/
251 void ScFunctionDockWin::SetSize()
253 sal_Int32 nSelEntry=0;
254 SfxChildAlignment aChildAlign=eSfxOldAlignment;//GetAlignment();
255 short nNewDockMode;
256 switch(aChildAlign)
258 case SfxChildAlignment::HIGHESTTOP:
259 case SfxChildAlignment::TOP:
260 case SfxChildAlignment::LOWESTTOP:
261 case SfxChildAlignment::LOWESTBOTTOM:
262 case SfxChildAlignment::BOTTOM:
263 case SfxChildAlignment::TOOLBOXTOP:
264 case SfxChildAlignment::TOOLBOXBOTTOM:
266 nNewDockMode=1;
267 if(nDockMode!=nNewDockMode)
269 nDockMode=nNewDockMode;
270 nSelEntry=aFuncList->GetSelectEntryPos();
271 aFuncList->Clear();
272 aFiFuncDesc->SetPosPixel(aFuncList->GetPosPixel());
273 aDDFuncList->Enable();
274 aDDFuncList->Show();
275 aPrivatSplit->Disable();
276 aPrivatSplit->Hide();
277 aFuncList->Disable();
278 aFuncList->Hide();
279 pAllFuncList=aDDFuncList.get();
280 SelHdl(aCatBox.get());
281 aDDFuncList->SelectEntryPos(nSelEntry);
283 break;
285 default: nNewDockMode=0;
286 if(nDockMode!=nNewDockMode)
288 nDockMode=nNewDockMode;
289 nSelEntry=aDDFuncList->GetSelectEntryPos();
290 aDDFuncList->Clear();
291 aDDFuncList->Disable();
292 aDDFuncList->Hide();
293 aPrivatSplit->Enable();
294 aPrivatSplit->Show();
295 aFuncList->Enable();
296 aFuncList->Show();
297 pAllFuncList=aFuncList.get();
298 SelHdl(aCatBox.get());
299 aFuncList->SelectEntryPos(nSelEntry);
301 break;
304 if(nDockMode==0)
306 SetLeftRightSize();
308 else
310 SetTopBottonSize();
313 /*************************************************************************
314 #* Member: SetLeftRightSize
315 #*------------------------------------------------------------------------
317 #* Klasse: ScFunctionDockWin
319 #* Funktion: Groesse fuer die einzelnen Controls einstellen,
320 #* wenn Links oder Rechts angedockt wird.
322 #* Input: ---
324 #* Output: ---
326 #************************************************************************/
328 void ScFunctionDockWin::SetLeftRightSize()
330 if(!bSizeFlag)
332 bSizeFlag = true;
334 Size aDiffSize=GetSizePixel();
335 Size aNewSize=GetOutputSizePixel();
336 aDiffSize.Width()-=aNewSize.Width();
337 aDiffSize.Height()-=aNewSize.Height();
339 OUString aString("ww");
340 Size aTxtSize( aFuncList->GetTextWidth(aString), aFuncList->GetTextHeight() );
342 Range aYRange(3*aTxtSize.Height()+aFuncList->GetPosPixel().Y(),
343 GetOutputSizePixel().Height()-2*aTxtSize.Height());
344 aPrivatSplit->SetYRange(aYRange);
346 if(aOldSize.Width()!=aNewSize.Width())
347 SetMyWidthLeRi(aNewSize);
349 if(aOldSize.Height()!=aNewSize.Height())
350 SetMyHeightLeRi(aNewSize);
352 aOldSize=aNewSize;
353 aNewSize.Width()+=aDiffSize.Width();
354 aNewSize.Height()+=aDiffSize.Height();
355 bSizeFlag=false;
359 /*************************************************************************
360 #* Member: SetTopBottonSize
361 #*------------------------------------------------------------------------
363 #* Klasse: ScFunctionDockWin
365 #* Funktion: Groesse fuer die einzelnen Controls einzustellen.
366 #* wenn oben oder unten angedockt wird.
368 #* Input: ---
370 #* Output: ---
372 #************************************************************************/
374 void ScFunctionDockWin::SetTopBottonSize()
376 if(!bSizeFlag)
378 bSizeFlag = true;
379 Size aDiffSize=GetSizePixel();
380 Size aNewSize=GetOutputSizePixel();
381 aDiffSize.Width()-=aNewSize.Width();
382 aDiffSize.Height()-=aNewSize.Height();
384 SetMyWidthToBo(aNewSize);
385 SetMyHeightToBo(aNewSize);
387 aNewSize.Width()+=aDiffSize.Width();
388 aNewSize.Height()+=aDiffSize.Height();
389 bSizeFlag=false;
393 /*************************************************************************
394 #* Member: SetMyWidthLeRi
395 #*------------------------------------------------------------------------
397 #* Klasse: ScFunctionDockWin
399 #* Funktion: Breite fuer die einzelnen Controls und
400 #* das Fenster einstellen,wenn Li oder Re
402 #* Input: neue Fenstergroesse
404 #* Output: ---
406 #************************************************************************/
408 void ScFunctionDockWin::SetMyWidthLeRi(Size &aNewSize)
410 if((sal_uLong)aNewSize.Width()<nMinWidth) aNewSize.Width()=nMinWidth;
412 Size aCDSize=aCatBox->GetSizePixel();
413 Size aFLSize=aFuncList->GetSizePixel();
414 Size aSplitterSize=aPrivatSplit->GetSizePixel();
415 Size aFDSize=aFiFuncDesc->GetSizePixel();
417 Point aCDTopLeft=aCatBox->GetPosPixel();
418 Point aFLTopLeft=aFuncList->GetPosPixel();
420 aCDSize.Width()=aNewSize.Width()-aCDTopLeft.X()-aFLTopLeft.X();
421 aFLSize.Width()=aNewSize.Width()-2*aFLTopLeft.X();
422 aFDSize.Width()=aFLSize.Width();
423 aSplitterSize.Width()=aFLSize.Width();
425 aCatBox->SetSizePixel(aCDSize);
426 aFuncList->SetSizePixel(aFLSize);
427 aPrivatSplit->SetSizePixel(aSplitterSize);
428 aFiFuncDesc->SetSizePixel(aFDSize);
431 /*************************************************************************
432 #* Member: SetHeight
433 #*------------------------------------------------------------------------
435 #* Klasse: ScFunctionDockWin
437 #* Funktion: Hoehe fuer die einzelnen Controls und
438 #* das Fenster einstellen bei Li oder Re
440 #* Input: neue Fenstergroesse
442 #* Output: ---
444 #************************************************************************/
446 void ScFunctionDockWin::SetMyHeightLeRi(Size &aNewSize)
448 if((sal_uLong)aNewSize.Height()<nMinHeight) aNewSize.Height()=nMinHeight;
450 Size aFLSize=aFuncList->GetSizePixel();
451 Size aSplitterSize=aPrivatSplit->GetSizePixel();
452 Size aFDSize=aFiFuncDesc->GetSizePixel();
454 Point aFLTopLeft=aFuncList->GetPosPixel();
455 Point aSplitterTopLeft=aPrivatSplit->GetPosPixel();
456 Point aFDTopLeft=aFiFuncDesc->GetPosPixel();
458 long nTxtHeight = aFuncList->GetTextHeight();
460 short nY=(short)(3*nTxtHeight+
461 aFuncList->GetPosPixel().Y()+aSplitterSize.Height());
463 aFDTopLeft.Y()=aNewSize.Height()-aFDSize.Height()-4;
464 if(nY>aFDTopLeft.Y())
466 aFDSize.Height()-=nY-aFDTopLeft.Y();
467 aFDTopLeft.Y()=nY;
469 aSplitterTopLeft.Y()=aFDTopLeft.Y()-aSplitterSize.Height()-1;
470 aFLSize.Height()=aSplitterTopLeft.Y()-aFLTopLeft.Y()-1;
472 aFuncList->SetSizePixel(aFLSize);
473 aPrivatSplit->SetPosPixel(aSplitterTopLeft);
474 aFiFuncDesc->SetPosPixel(aFDTopLeft);
475 aFiFuncDesc->SetSizePixel(aFDSize);
479 /*************************************************************************
480 #* Member: SetMyWidthToBo
481 #*------------------------------------------------------------------------
483 #* Klasse: ScFunctionDockWin
485 #* Funktion: Breite fuer die einzelnen Controls und
486 #* das Fenster einstellen, wenn oben oder
487 #* unten angedockt werden soll.
489 #* Input: neue Fenstergroesse
491 #* Output: ---
493 #************************************************************************/
495 void ScFunctionDockWin::SetMyWidthToBo(Size &aNewSize)
497 if((sal_uLong)aNewSize.Width()<nMinWidth) aNewSize.Width()=nMinWidth;
499 Size aCDSize=aCatBox->GetSizePixel();
500 Size aDdFLSize=aDDFuncList->GetSizePixel();
501 Size aFDSize=aFiFuncDesc->GetSizePixel();
503 Point aCDTopLeft=aCatBox->GetPosPixel();
504 Point aDdFLTopLeft=aDDFuncList->GetPosPixel();
505 Point aFDTopLeft=aFiFuncDesc->GetPosPixel();
507 aCDSize.Width()=aDdFLTopLeft.X()-aFDTopLeft.X()-aCDTopLeft.X();
508 aDdFLTopLeft.X()=aCDSize.Width()+aCDTopLeft.X()+aFDTopLeft.X();
510 aDdFLSize.Width()=aNewSize.Width()-aDdFLTopLeft.X()-aFDTopLeft.X();
512 aFDSize.Width()=aNewSize.Width()-2*aFDTopLeft.X();
514 aDDFuncList->SetPosPixel(aDdFLTopLeft);
515 aDDFuncList->SetSizePixel(aDdFLSize);
516 aCatBox->SetSizePixel(aCDSize);
517 aFiFuncDesc->SetSizePixel(aFDSize);
520 /*************************************************************************
521 #* Member: SetHeight
522 #*------------------------------------------------------------------------
524 #* Klasse: ScFunctionDockWin
526 #* Funktion: Hoehe fuer die einzelnen Controls und
527 #* das Fenster einstellen, wenn oben oder
528 #* unten angedockt werden soll.
530 #* Input: neue Fenstergroesse
532 #* Output: ---
534 #************************************************************************/
536 void ScFunctionDockWin::SetMyHeightToBo(Size &aNewSize)
538 if((sal_uLong)aNewSize.Height()<nMinHeight) aNewSize.Height()=nMinHeight;
540 Size aFDSize=aFiFuncDesc->GetSizePixel();
542 Point aFDTopLeft=aFiFuncDesc->GetPosPixel();
543 Point aCBTopLeft=aCatBox->GetPosPixel();
544 aFDSize.Height()=aNewSize.Height()-aFDTopLeft.Y()-aCBTopLeft.Y();
545 aFiFuncDesc->SetSizePixel(aFDSize);
549 /*************************************************************************
550 #* Member: SetDescription
551 #*------------------------------------------------------------------------
553 #* Klasse: ScFunctionDockWin
555 #* Funktion: Erklaerungstext fuer die Funktion einstellen.
557 #* Input: ---
559 #* Output: ---
561 #************************************************************************/
563 void ScFunctionDockWin::SetDescription()
565 aFiFuncDesc->SetText( EMPTY_OUSTRING );
566 const ScFuncDesc* pDesc =
567 static_cast<const ScFuncDesc*>(pAllFuncList->GetEntryData(
568 pAllFuncList->GetSelectEntryPos() ));
569 if (pDesc)
571 pDesc->initArgumentInfo(); // full argument info is needed
573 OUStringBuffer aBuf(pAllFuncList->GetSelectEntry());
574 if(nDockMode==0)
576 aBuf.appendAscii(":\n\n");
578 else
580 aBuf.appendAscii(": ");
583 aBuf.append(pDesc->GetParamList());
585 if(nDockMode==0)
587 aBuf.appendAscii("\n\n");
589 else
591 aBuf.appendAscii("\n");
594 aBuf.append(*pDesc->pFuncDesc);
596 aFiFuncDesc->SetText(aBuf.makeStringAndClear());
597 aFiFuncDesc->StateChanged(StateChangedType::Text);
598 aFiFuncDesc->Invalidate();
599 aFiFuncDesc->Update();
604 /// override to set new size of the controls
605 void ScFunctionDockWin::Resizing( Size& rNewSize )
607 if((sal_uLong)rNewSize.Width()<nMinWidth) rNewSize.Width()=nMinWidth;
608 if((sal_uLong)rNewSize.Height()<nMinHeight) rNewSize.Height()=nMinHeight;
612 /*************************************************************************
613 #* Member: Close
614 #*------------------------------------------------------------------------
616 #* Klasse: ScFunctionDockWin
618 #* Funktion: Schliessen des Fensters
620 #* Input: ---
622 #* Output: TRUE
624 #************************************************************************/
626 bool ScFunctionDockWin::Close()
628 SfxBoolItem aItem( FID_FUNCTION_BOX, false );
630 GetBindings().GetDispatcher()->Execute( FID_FUNCTION_BOX,
631 SfxCallMode::ASYNCHRON | SfxCallMode::RECORD,
632 &aItem, 0L );
634 SfxDockingWindow::Close();
636 return true;
639 /*************************************************************************
640 #* Member: CheckAlignment
641 #*------------------------------------------------------------------------
643 #* Klasse: ScFunctionDockWin
645 #* Funktion: Ueberprueft den Andockmodus und stellt die
646 #* Groessen dementsprechend ein.
648 #* Input: Das neue Alignment
650 #* Output: Das uebergebene Alignment
652 #************************************************************************/
653 SfxChildAlignment ScFunctionDockWin::CheckAlignment(SfxChildAlignment /* abla */,
654 SfxChildAlignment aChildAlign)
656 OUString aString("ww");
657 Size aTxtSize( aFiFuncDesc->GetTextWidth(aString), aFiFuncDesc->GetTextHeight() );
658 if(!bInit)
660 eSfxOldAlignment=eSfxNewAlignment;
661 eSfxNewAlignment=aChildAlign;
663 else
665 bInit=false;
666 eSfxOldAlignment=aChildAlign;
667 eSfxNewAlignment=aChildAlign;
670 switch(eSfxOldAlignment)
672 case SfxChildAlignment::HIGHESTTOP:
673 case SfxChildAlignment::TOP:
674 case SfxChildAlignment::LOWESTTOP:
675 case SfxChildAlignment::LOWESTBOTTOM:
676 case SfxChildAlignment::BOTTOM:
677 case SfxChildAlignment::TOOLBOXTOP:
678 case SfxChildAlignment::TOOLBOXBOTTOM:
680 nMinWidth= 0;
681 nMinHeight=0;
683 break;
685 case SfxChildAlignment::NOALIGNMENT:
687 aString = aCatBox->GetEntry(0);
688 aString += "www";
689 aTxtSize = Size( aFiFuncDesc->GetTextWidth(aString),
690 aFiFuncDesc->GetTextHeight() );
691 // fall-through
692 default: Point aTopLeft=aCatBox->GetPosPixel();
693 nMinWidth=aTxtSize.Width()+aTopLeft.X()
694 +2*aFuncList->GetPosPixel().X();
695 nMinHeight=19*aTxtSize.Height();
697 break;
700 return aChildAlign;
702 /*************************************************************************
703 #* Member: Close
704 #*------------------------------------------------------------------------
706 #* Klasse: ScFunctionDockWin
708 #* Funktion: Aenderungen erkennen
710 #* Input: ---
712 #* Output: TRUE
714 #************************************************************************/
715 void ScFunctionDockWin::Notify( SfxBroadcaster&, const SfxHint& /* rHint */ )
719 /// override to set new size of the controls
720 void ScFunctionDockWin::Resize()
722 if ( !IsFloatingMode() ||
723 !GetFloatingWindow()->IsRollUp() )
725 Size aQSize=GetOutputSizePixel();
726 Resizing( aQSize);
727 SetSize();
729 SfxDockingWindow::Resize();
732 /*************************************************************************
733 #* Member: UpdateFunctionList
734 #*------------------------------------------------------------------------
736 #* Klasse: ScFunctionDockWin
738 #* Funktion: Aktualisiert die Liste der Funktionen ab-
739 #* haengig von der eingestellten Kategorie.
741 #* Input: ---
743 #* Output: ---
745 #************************************************************************/
747 void ScFunctionDockWin::UpdateFunctionList()
749 sal_Int32 nSelPos = aCatBox->GetSelectEntryPos();
750 sal_Int32 nCategory = ( LISTBOX_ENTRY_NOTFOUND != nSelPos )
751 ? (nSelPos-1) : 0;
753 pAllFuncList->Clear();
754 pAllFuncList->SetUpdateMode( false );
756 if ( nSelPos > 0 )
758 ScFunctionMgr* pFuncMgr = ScGlobal::GetStarCalcFunctionMgr();
760 const ScFuncDesc* pDesc = pFuncMgr->First( nCategory );
761 while ( pDesc )
763 pAllFuncList->SetEntryData(
764 pAllFuncList->InsertEntry( *(pDesc->pFuncName) ),
765 (void*)pDesc );
766 pDesc = pFuncMgr->Next();
769 else // LRU-Liste
771 for (::std::vector<const formula::IFunctionDescription*>::iterator iter=aLRUList.begin();
772 iter != aLRUList.end(); ++iter)
774 const formula::IFunctionDescription* pDesc = *iter;
775 if (pDesc)
776 pAllFuncList->SetEntryData( pAllFuncList->InsertEntry( pDesc->getFunctionName()), (void*)pDesc);
780 pAllFuncList->SetUpdateMode( true );
782 if ( pAllFuncList->GetEntryCount() > 0 )
784 pAllFuncList->Enable();
785 pAllFuncList->SelectEntryPos( 0 );
787 else
789 pAllFuncList->Disable();
793 /*************************************************************************
794 #* Member: DoEnter
795 #*------------------------------------------------------------------------
797 #* Klasse: ScFunctionDockWin
799 #* Funktion: Eingabe ins Dokument uebernehmen. Wird aufgerufen
800 #* nach betaetigen der Uebernehmen- Schaltflaeche
801 #* oder einem Doppelklick in die Funktionsliste.
803 #* Input: ---
805 #* Output: ---
807 #************************************************************************/
809 void ScFunctionDockWin::DoEnter()
811 OUString aFirstArgStr;
812 OUString aArgStr;
813 OUString aString=pAllFuncList->GetSelectEntry();
814 SfxViewShell* pCurSh = SfxViewShell::Current();
815 nArgs=0;
817 if(!aString.isEmpty())
820 ScModule* pScMod = SC_MOD();
821 ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, pCurSh);
822 ScInputHandler* pHdl = pScMod->GetInputHdl( pViewSh );
823 if(!pScMod->IsEditMode())
825 pScMod->SetInputMode(SC_INPUT_TABLE);
826 aString = "=";
827 aString += pAllFuncList->GetSelectEntry();
828 if (pHdl)
829 pHdl->ClearText();
831 const ScFuncDesc* pDesc =
832 static_cast<const ScFuncDesc*>(pAllFuncList->GetEntryData(
833 pAllFuncList->GetSelectEntryPos() ));
834 if (pDesc)
836 pFuncDesc=pDesc;
837 UpdateLRUList();
838 nArgs = pDesc->nArgCount;
839 if(nArgs>0)
841 // NOTE: Theoretically the first parameter could have the
842 // suppress flag as well, but practically it doesn't.
843 aFirstArgStr = pDesc->maDefArgNames[0];
844 aFirstArgStr = comphelper::string::strip(aFirstArgStr, ' ');
845 aFirstArgStr = aFirstArgStr.replaceAll(" ", "_");
846 aArgStr = aFirstArgStr;
847 if ( nArgs != VAR_ARGS && nArgs != PAIRED_VAR_ARGS )
848 { // no VarArgs or Fix plus VarArgs, but not VarArgs only
849 OUString aArgSep("; ");
850 sal_uInt16 nFix;
851 if (nArgs >= PAIRED_VAR_ARGS)
852 nFix = nArgs - PAIRED_VAR_ARGS + 2;
853 else if (nArgs >= VAR_ARGS)
854 nFix = nArgs - VAR_ARGS + 1;
855 else
856 nFix = nArgs;
857 for ( sal_uInt16 nArg = 1;
858 nArg < nFix && !pDesc->pDefArgFlags[nArg].bOptional; nArg++ )
860 if (!pDesc->pDefArgFlags[nArg].bSuppress)
862 aArgStr += aArgSep;
863 OUString sTmp = pDesc->maDefArgNames[nArg];
864 sTmp = comphelper::string::strip(sTmp, ' ');
865 sTmp = sTmp.replaceAll(" ", "_");
866 aArgStr += sTmp;
872 if (pHdl)
874 if (pHdl->GetEditString().isEmpty())
876 aString = "=";
877 aString += pAllFuncList->GetSelectEntry();
879 EditView *pEdView=pHdl->GetActiveView();
880 if(pEdView!=NULL) // @ Wegen Absturz bei Namen festlegen
882 if(nArgs>0)
884 pHdl->InsertFunction(aString);
885 pEdView->InsertText(aArgStr,true);
886 ESelection aESel=pEdView->GetSelection();
887 aESel.nEndPos = aESel.nStartPos + aFirstArgStr.getLength();
888 pEdView->SetSelection(aESel);
889 pHdl->DataChanged();
891 else
893 aString += "()";
894 pEdView->InsertText(aString,false);
895 pHdl->DataChanged();
899 InitLRUList();
901 if ( pCurSh )
903 vcl::Window* pShellWnd = pCurSh->GetWindow();
905 if ( pShellWnd )
906 pShellWnd->GrabFocus();
911 /*************************************************************************
912 #* Handle: SelHdl
913 #*------------------------------------------------------------------------
915 #* Klasse: ScFunctionDockWin
917 #* Funktion: Bei einer Aenderung der Kategorie wird die
918 #* die Liste der Funktionen aktualisiert.
920 #* Input: ---
922 #* Output: ---
924 #************************************************************************/
926 IMPL_LINK( ScFunctionDockWin, SelHdl, ListBox*, pLb )
928 if ( pLb == aCatBox.get() )
930 UpdateFunctionList();
931 SetDescription();
934 if ( pLb == aFuncList.get() || pLb == aDDFuncList.get() )
936 SetDescription();
939 //SetSize();
940 return 0;
943 /*************************************************************************
944 #* Handle: SelHdl
945 #*------------------------------------------------------------------------
947 #* Klasse: ScFunctionDockWin
949 #* Funktion: Bei einer Aenderung der Kategorie wird die
950 #* die Liste der Funktionen aktualisiert.
952 #* Input: ---
954 #* Output: ---
956 #************************************************************************/
958 IMPL_LINK( ScFunctionDockWin, SetSelectionHdl, void*, pCtrl )
960 if (static_cast<ImageButton *>(pCtrl) == aInsertButton.get() ||
961 static_cast<ListBox *>(pCtrl) == aFuncList.get())
963 DoEnter(); // Uebernimmt die Eingabe
966 return 0;
969 /*************************************************************************
970 #* Handle: SetSplitHdl
971 #*------------------------------------------------------------------------
973 #* Klasse: ScFunctionDockWin
975 #* Funktion: Bei einer Aenderung des Split- Controls werden die
976 #* einzelnen Controls an die neue Groesse angepasst.
978 #* Input: Zeiger auf Control
980 #* Output: ---
982 #************************************************************************/
984 IMPL_LINK( ScFunctionDockWin, SetSplitHdl, ScPrivatSplit*, pCtrl )
986 if (pCtrl == aPrivatSplit.get())
988 short nDeltaY=aPrivatSplit->GetDeltaY();
989 Size aFLSize=aFuncList->GetSizePixel();
990 Size aFDSize=aFiFuncDesc->GetSizePixel();
991 Point aFDTopLeft=aFiFuncDesc->GetPosPixel();
993 aFLSize.Height()+=nDeltaY;
994 aFDSize.Height()-=nDeltaY;
995 aFDTopLeft.Y()+=nDeltaY;
996 aFuncList->SetSizePixel(aFLSize);
997 aFiFuncDesc->SetPosPixel(aFDTopLeft);
998 aFiFuncDesc->SetSizePixel(aFDSize);
1001 return 0;
1004 void ScFunctionDockWin::ToggleFloatingMode()
1006 aSplitterInitPos = Point();
1007 SfxDockingWindow::ToggleFloatingMode();
1009 eSfxNewAlignment=GetAlignment();
1010 eSfxOldAlignment=eSfxNewAlignment;
1012 aOldSize.Height()=0;
1013 aOldSize.Width()=0;
1014 aIdle.Start();
1017 IMPL_LINK_NOARG_TYPED(ScFunctionDockWin, TimerHdl, Idle *, void)
1019 CheckAlignment(eSfxOldAlignment,eSfxNewAlignment);
1020 SetSize();
1023 void ScFunctionDockWin::Initialize(SfxChildWinInfo *pInfo)
1025 OUString aStr;
1026 if(pInfo!=NULL)
1028 if ( !pInfo->aExtraString.isEmpty() )
1030 sal_Int32 nPos = pInfo->aExtraString.indexOf( "ScFuncList:" );
1032 // Versuche, den Alignment-String "ALIGN:(...)" einzulesen; wenn
1033 // er nicht vorhanden ist, liegt eine "altere Version vor
1034 if ( nPos != -1 )
1036 sal_Int32 n1 = pInfo->aExtraString.indexOf('(', nPos);
1037 if ( n1 != -1 )
1039 sal_Int32 n2 = pInfo->aExtraString.indexOf(')', n1);
1040 if ( n2 != -1 )
1042 // Alignment-String herausschneiden
1043 aStr = pInfo->aExtraString.copy(nPos, n2 - nPos + 1);
1044 pInfo->aExtraString = pInfo->aExtraString.replaceAt(nPos, n2 - nPos + 1, "");
1045 aStr = aStr.copy( n1-nPos+1 );
1051 SfxDockingWindow::Initialize(pInfo);
1053 if ( !aStr.isEmpty())
1055 aSplitterInitPos = aPrivatSplit->GetPosPixel();
1056 aSplitterInitPos.Y() = (sal_uInt16) aStr.toInt32();
1057 sal_Int32 n1 = aStr.indexOf(';');
1058 aStr = aStr.copy( n1+1 );
1059 sal_Int32 nSelPos = aStr.toInt32();
1060 aCatBox->SelectEntryPos(nSelPos);
1061 SelHdl(aCatBox.get());
1063 // if the window has already been shown (from SfxDockingWindow::Initialize if docked),
1064 // set the splitter position now, otherwise it is set in StateChanged with type INITSHOW
1066 UseSplitterInitPos();
1070 void ScFunctionDockWin::FillInfo(SfxChildWinInfo& rInfo) const
1072 SfxDockingWindow::FillInfo(rInfo);
1073 Point aPoint=aPrivatSplit->GetPosPixel();
1074 rInfo.aExtraString += "ScFuncList:(" +
1075 OUString::number(aPoint.Y()) + ";" +
1076 OUString::number(aCatBox->GetSelectEntryPos()) + ")";
1079 void ScFunctionDockWin::UseSplitterInitPos()
1081 if ( IsVisible() && aPrivatSplit->IsEnabled() && aSplitterInitPos != Point() )
1083 aPrivatSplit->MoveSplitTo(aSplitterInitPos);
1084 aSplitterInitPos = Point(); // use only once
1088 void ScFunctionDockWin::StateChanged( StateChangedType nStateChange )
1090 SfxDockingWindow::StateChanged( nStateChange );
1092 if (nStateChange == StateChangedType::InitShow)
1094 UseSplitterInitPos(); // set initial splitter position if necessary
1098 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */