1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
29 #include "scresid.hxx"
30 #include "reffact.hxx"
31 #include "document.hxx"
32 #include "formulacell.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
58 #************************************************************************/
60 ScFunctionChildWindow::ScFunctionChildWindow( vcl::Window
* pParentP
,
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
) );
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
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() ) ) ),
104 SetStyle(GetStyle()|WB_CLIPCHILDREN
);
106 aIdle
.SetPriority(SchedulerPriority::LOWER
);
107 aIdle
.SetIdleHdl(LINK( this, ScFunctionDockWin
, TimerHdl
));
110 eSfxNewAlignment
=GetAlignment();
112 eSfxNewAlignment
=SfxChildAlignment::RIGHT
;
113 eSfxOldAlignment
=eSfxNewAlignment
;
114 aFiFuncDesc
->SetUpdateMode(true);
115 pAllFuncList
=aFuncList
.get();
116 aDDFuncList
->Disable();
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());
156 /*************************************************************************
157 #* Member: ScFunctionDockWin
158 #*------------------------------------------------------------------------
160 #* Klasse: ScFunctionDockWin
162 #* Funktion: Destruktor der Klasse ScFunctionDockWin
168 #************************************************************************/
170 ScFunctionDockWin::~ScFunctionDockWin()
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.
201 #************************************************************************/
203 void ScFunctionDockWin::InitLRUList()
205 ScFunctionMgr
* pFuncMgr
= ScGlobal::GetStarCalcFunctionMgr();
206 pFuncMgr
->fillLastRecentlyUsedFunctions(aLRUList
);
208 sal_Int32 nSelPos
= aCatBox
->GetSelectEntryPos();
211 UpdateFunctionList();
214 /*************************************************************************
215 #* Member: UpdateFunctionList
216 #*------------------------------------------------------------------------
218 #* Klasse: ScFunctionDockWin
220 #* Funktion: Aktualisiert die Liste der zuletzt verwendeten Funktionen.
226 #************************************************************************/
228 void ScFunctionDockWin::UpdateLRUList()
230 if (pFuncDesc
&& pFuncDesc
->nFIndex
!=0)
232 ScModule
* pScMod
= SC_MOD();
233 pScMod
->InsertEntryToLRUList(pFuncDesc
->nFIndex
);
237 /*************************************************************************
239 #*------------------------------------------------------------------------
241 #* Klasse: ScFunctionDockWin
243 #* Funktion: Groesse fuer die einzelnen Controls einzustellen.
249 #************************************************************************/
251 void ScFunctionDockWin::SetSize()
253 sal_Int32 nSelEntry
=0;
254 SfxChildAlignment aChildAlign
=eSfxOldAlignment
;//GetAlignment();
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
:
267 if(nDockMode
!=nNewDockMode
)
269 nDockMode
=nNewDockMode
;
270 nSelEntry
=aFuncList
->GetSelectEntryPos();
272 aFiFuncDesc
->SetPosPixel(aFuncList
->GetPosPixel());
273 aDDFuncList
->Enable();
275 aPrivatSplit
->Disable();
276 aPrivatSplit
->Hide();
277 aFuncList
->Disable();
279 pAllFuncList
=aDDFuncList
.get();
280 SelHdl(aCatBox
.get());
281 aDDFuncList
->SelectEntryPos(nSelEntry
);
285 default: nNewDockMode
=0;
286 if(nDockMode
!=nNewDockMode
)
288 nDockMode
=nNewDockMode
;
289 nSelEntry
=aDDFuncList
->GetSelectEntryPos();
290 aDDFuncList
->Clear();
291 aDDFuncList
->Disable();
293 aPrivatSplit
->Enable();
294 aPrivatSplit
->Show();
297 pAllFuncList
=aFuncList
.get();
298 SelHdl(aCatBox
.get());
299 aFuncList
->SelectEntryPos(nSelEntry
);
313 /*************************************************************************
314 #* Member: SetLeftRightSize
315 #*------------------------------------------------------------------------
317 #* Klasse: ScFunctionDockWin
319 #* Funktion: Groesse fuer die einzelnen Controls einstellen,
320 #* wenn Links oder Rechts angedockt wird.
326 #************************************************************************/
328 void ScFunctionDockWin::SetLeftRightSize()
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
);
353 aNewSize
.Width()+=aDiffSize
.Width();
354 aNewSize
.Height()+=aDiffSize
.Height();
359 /*************************************************************************
360 #* Member: SetTopBottonSize
361 #*------------------------------------------------------------------------
363 #* Klasse: ScFunctionDockWin
365 #* Funktion: Groesse fuer die einzelnen Controls einzustellen.
366 #* wenn oben oder unten angedockt wird.
372 #************************************************************************/
374 void ScFunctionDockWin::SetTopBottonSize()
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();
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
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 /*************************************************************************
433 #*------------------------------------------------------------------------
435 #* Klasse: ScFunctionDockWin
437 #* Funktion: Hoehe fuer die einzelnen Controls und
438 #* das Fenster einstellen bei Li oder Re
440 #* Input: neue Fenstergroesse
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();
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
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 /*************************************************************************
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
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.
561 #************************************************************************/
563 void ScFunctionDockWin::SetDescription()
565 aFiFuncDesc
->SetText( EMPTY_OUSTRING
);
566 const ScFuncDesc
* pDesc
=
567 static_cast<const ScFuncDesc
*>(pAllFuncList
->GetEntryData(
568 pAllFuncList
->GetSelectEntryPos() ));
571 pDesc
->initArgumentInfo(); // full argument info is needed
573 OUStringBuffer
aBuf(pAllFuncList
->GetSelectEntry());
576 aBuf
.appendAscii(":\n\n");
580 aBuf
.appendAscii(": ");
583 aBuf
.append(pDesc
->GetParamList());
587 aBuf
.appendAscii("\n\n");
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 /*************************************************************************
614 #*------------------------------------------------------------------------
616 #* Klasse: ScFunctionDockWin
618 #* Funktion: Schliessen des Fensters
624 #************************************************************************/
626 bool ScFunctionDockWin::Close()
628 SfxBoolItem
aItem( FID_FUNCTION_BOX
, false );
630 GetBindings().GetDispatcher()->Execute( FID_FUNCTION_BOX
,
631 SfxCallMode::ASYNCHRON
| SfxCallMode::RECORD
,
634 SfxDockingWindow::Close();
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() );
660 eSfxOldAlignment
=eSfxNewAlignment
;
661 eSfxNewAlignment
=aChildAlign
;
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
:
685 case SfxChildAlignment::NOALIGNMENT
:
687 aString
= aCatBox
->GetEntry(0);
689 aTxtSize
= Size( aFiFuncDesc
->GetTextWidth(aString
),
690 aFiFuncDesc
->GetTextHeight() );
692 default: Point aTopLeft
=aCatBox
->GetPosPixel();
693 nMinWidth
=aTxtSize
.Width()+aTopLeft
.X()
694 +2*aFuncList
->GetPosPixel().X();
695 nMinHeight
=19*aTxtSize
.Height();
702 /*************************************************************************
704 #*------------------------------------------------------------------------
706 #* Klasse: ScFunctionDockWin
708 #* Funktion: Aenderungen erkennen
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();
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.
745 #************************************************************************/
747 void ScFunctionDockWin::UpdateFunctionList()
749 sal_Int32 nSelPos
= aCatBox
->GetSelectEntryPos();
750 sal_Int32 nCategory
= ( LISTBOX_ENTRY_NOTFOUND
!= nSelPos
)
753 pAllFuncList
->Clear();
754 pAllFuncList
->SetUpdateMode( false );
758 ScFunctionMgr
* pFuncMgr
= ScGlobal::GetStarCalcFunctionMgr();
760 const ScFuncDesc
* pDesc
= pFuncMgr
->First( nCategory
);
763 pAllFuncList
->SetEntryData(
764 pAllFuncList
->InsertEntry( *(pDesc
->pFuncName
) ),
766 pDesc
= pFuncMgr
->Next();
771 for (::std::vector
<const formula::IFunctionDescription
*>::iterator iter
=aLRUList
.begin();
772 iter
!= aLRUList
.end(); ++iter
)
774 const formula::IFunctionDescription
* pDesc
= *iter
;
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 );
789 pAllFuncList
->Disable();
793 /*************************************************************************
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.
807 #************************************************************************/
809 void ScFunctionDockWin::DoEnter()
811 OUString aFirstArgStr
;
813 OUString aString
=pAllFuncList
->GetSelectEntry();
814 SfxViewShell
* pCurSh
= SfxViewShell::Current();
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
);
827 aString
+= pAllFuncList
->GetSelectEntry();
831 const ScFuncDesc
* pDesc
=
832 static_cast<const ScFuncDesc
*>(pAllFuncList
->GetEntryData(
833 pAllFuncList
->GetSelectEntryPos() ));
838 nArgs
= pDesc
->nArgCount
;
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("; ");
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;
857 for ( sal_uInt16 nArg
= 1;
858 nArg
< nFix
&& !pDesc
->pDefArgFlags
[nArg
].bOptional
; nArg
++ )
860 if (!pDesc
->pDefArgFlags
[nArg
].bSuppress
)
863 OUString sTmp
= pDesc
->maDefArgNames
[nArg
];
864 sTmp
= comphelper::string::strip(sTmp
, ' ');
865 sTmp
= sTmp
.replaceAll(" ", "_");
874 if (pHdl
->GetEditString().isEmpty())
877 aString
+= pAllFuncList
->GetSelectEntry();
879 EditView
*pEdView
=pHdl
->GetActiveView();
880 if(pEdView
!=NULL
) // @ Wegen Absturz bei Namen festlegen
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
);
894 pEdView
->InsertText(aString
,false);
903 vcl::Window
* pShellWnd
= pCurSh
->GetWindow();
906 pShellWnd
->GrabFocus();
911 /*************************************************************************
913 #*------------------------------------------------------------------------
915 #* Klasse: ScFunctionDockWin
917 #* Funktion: Bei einer Aenderung der Kategorie wird die
918 #* die Liste der Funktionen aktualisiert.
924 #************************************************************************/
926 IMPL_LINK( ScFunctionDockWin
, SelHdl
, ListBox
*, pLb
)
928 if ( pLb
== aCatBox
.get() )
930 UpdateFunctionList();
934 if ( pLb
== aFuncList
.get() || pLb
== aDDFuncList
.get() )
943 /*************************************************************************
945 #*------------------------------------------------------------------------
947 #* Klasse: ScFunctionDockWin
949 #* Funktion: Bei einer Aenderung der Kategorie wird die
950 #* die Liste der Funktionen aktualisiert.
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
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
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
);
1004 void ScFunctionDockWin::ToggleFloatingMode()
1006 aSplitterInitPos
= Point();
1007 SfxDockingWindow::ToggleFloatingMode();
1009 eSfxNewAlignment
=GetAlignment();
1010 eSfxOldAlignment
=eSfxNewAlignment
;
1012 aOldSize
.Height()=0;
1017 IMPL_LINK_NOARG_TYPED(ScFunctionDockWin
, TimerHdl
, Idle
*, void)
1019 CheckAlignment(eSfxOldAlignment
,eSfxNewAlignment
);
1023 void ScFunctionDockWin::Initialize(SfxChildWinInfo
*pInfo
)
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
1036 sal_Int32 n1
= pInfo
->aExtraString
.indexOf('(', nPos
);
1039 sal_Int32 n2
= pInfo
->aExtraString
.indexOf(')', n1
);
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: */