1c25918c1SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3c25918c1SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4c25918c1SAndrew Rist * or more contributor license agreements. See the NOTICE file
5c25918c1SAndrew Rist * distributed with this work for additional information
6c25918c1SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7c25918c1SAndrew Rist * to you under the Apache License, Version 2.0 (the
8c25918c1SAndrew Rist * "License"); you may not use this file except in compliance
9c25918c1SAndrew Rist * with the License. You may obtain a copy of the License at
10c25918c1SAndrew Rist *
11c25918c1SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12c25918c1SAndrew Rist *
13c25918c1SAndrew Rist * Unless required by applicable law or agreed to in writing,
14c25918c1SAndrew Rist * software distributed under the License is distributed on an
15c25918c1SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16c25918c1SAndrew Rist * KIND, either express or implied. See the License for the
17c25918c1SAndrew Rist * specific language governing permissions and limitations
18c25918c1SAndrew Rist * under the License.
19c25918c1SAndrew Rist *
20c25918c1SAndrew Rist *************************************************************/
21c25918c1SAndrew Rist
22c25918c1SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_formula.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir
29cdf0e10cSrcweir //----------------------------------------------------------------------------
30cdf0e10cSrcweir
31cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
32cdf0e10cSrcweir #include <sfx2/docfile.hxx>
33cdf0e10cSrcweir #include <svl/zforlist.hxx>
34cdf0e10cSrcweir #include <svl/stritem.hxx>
35cdf0e10cSrcweir #include "formula/IFunctionDescription.hxx"
36cdf0e10cSrcweir
37cdf0e10cSrcweir #include "funcpage.hxx"
38cdf0e10cSrcweir #include "formdlgs.hrc"
39cdf0e10cSrcweir #include "ForResId.hrc"
40cdf0e10cSrcweir #include "ModuleHelper.hxx"
41cdf0e10cSrcweir //============================================================================
42cdf0e10cSrcweir namespace formula
43cdf0e10cSrcweir {
44cdf0e10cSrcweir
FormulaListBox(Window * pParent,WinBits nWinStyle)45cdf0e10cSrcweir FormulaListBox::FormulaListBox( Window* pParent, WinBits nWinStyle):
46cdf0e10cSrcweir ListBox(pParent,nWinStyle)
47cdf0e10cSrcweir {}
48cdf0e10cSrcweir
FormulaListBox(Window * pParent,const ResId & rResId)49cdf0e10cSrcweir FormulaListBox::FormulaListBox( Window* pParent, const ResId& rResId ):
50cdf0e10cSrcweir ListBox(pParent,rResId)
51cdf0e10cSrcweir {}
52cdf0e10cSrcweir
KeyInput(const KeyEvent & rKEvt)53cdf0e10cSrcweir void FormulaListBox::KeyInput( const KeyEvent& rKEvt )
54cdf0e10cSrcweir {
55cdf0e10cSrcweir KeyEvent aKEvt=rKEvt;
56cdf0e10cSrcweir //ListBox::KeyInput(rKEvt);
57cdf0e10cSrcweir
58cdf0e10cSrcweir if(aKEvt.GetCharCode()==' ')
59cdf0e10cSrcweir DoubleClick();
60cdf0e10cSrcweir }
61cdf0e10cSrcweir
PreNotify(NotifyEvent & rNEvt)62cdf0e10cSrcweir long FormulaListBox::PreNotify( NotifyEvent& rNEvt )
63cdf0e10cSrcweir {
64cdf0e10cSrcweir NotifyEvent aNotifyEvt=rNEvt;
65cdf0e10cSrcweir
66cdf0e10cSrcweir long nResult=ListBox::PreNotify(rNEvt);
67cdf0e10cSrcweir
68cdf0e10cSrcweir sal_uInt16 nSwitch=aNotifyEvt.GetType();
69cdf0e10cSrcweir if(nSwitch==EVENT_KEYINPUT)
70cdf0e10cSrcweir {
71cdf0e10cSrcweir KeyInput(*aNotifyEvt.GetKeyEvent());
72cdf0e10cSrcweir }
73cdf0e10cSrcweir return nResult;
74cdf0e10cSrcweir }
75cdf0e10cSrcweir
76cdf0e10cSrcweir
77cdf0e10cSrcweir
78cdf0e10cSrcweir //============================================================================
79cdf0e10cSrcweir
Lb2Cat(sal_uInt16 nLbPos)80cdf0e10cSrcweir inline sal_uInt16 Lb2Cat( sal_uInt16 nLbPos )
81cdf0e10cSrcweir {
82cdf0e10cSrcweir // Kategorie 0 == LRU, sonst Categories == LbPos-1
83cdf0e10cSrcweir if ( nLbPos > 0 )
84cdf0e10cSrcweir nLbPos -= 1;
85cdf0e10cSrcweir
86cdf0e10cSrcweir return nLbPos;
87cdf0e10cSrcweir }
88cdf0e10cSrcweir
89cdf0e10cSrcweir //============================================================================
90cdf0e10cSrcweir
FuncPage(Window * pParent,const IFunctionManager * _pFunctionManager)91cdf0e10cSrcweir FuncPage::FuncPage(Window* pParent,const IFunctionManager* _pFunctionManager):
92cdf0e10cSrcweir TabPage(pParent,ModuleRes(RID_FORMULATAB_FUNCTION)),
93cdf0e10cSrcweir //
94cdf0e10cSrcweir aFtCategory ( this, ModuleRes( FT_CATEGORY ) ),
95cdf0e10cSrcweir aLbCategory ( this, ModuleRes( LB_CATEGORY ) ),
96cdf0e10cSrcweir aFtFunction ( this, ModuleRes( FT_FUNCTION ) ),
97cdf0e10cSrcweir aLbFunction ( this, ModuleRes( LB_FUNCTION ) ),
98cdf0e10cSrcweir m_pFunctionManager(_pFunctionManager)
99cdf0e10cSrcweir {
100cdf0e10cSrcweir FreeResource();
101cdf0e10cSrcweir m_aHelpId = aLbFunction.GetHelpId();
102cdf0e10cSrcweir aLbFunction.SetUniqueId(m_aHelpId);
103cdf0e10cSrcweir
104cdf0e10cSrcweir InitLRUList();
105cdf0e10cSrcweir
106cdf0e10cSrcweir const sal_uInt32 nCategoryCount = m_pFunctionManager->getCount();
107cdf0e10cSrcweir for(sal_uInt32 j= 0; j < nCategoryCount; ++j)
108cdf0e10cSrcweir {
109cdf0e10cSrcweir const IFunctionCategory* pCategory = m_pFunctionManager->getCategory(j);
110cdf0e10cSrcweir aLbCategory.SetEntryData(aLbCategory.InsertEntry(pCategory->getName()),(void*)pCategory);
111cdf0e10cSrcweir }
112cdf0e10cSrcweir
113*a4efec7aSKay Schenk aLbCategory.SetDropDownLineCount( aLbCategory.GetEntryCount() );
114cdf0e10cSrcweir aLbCategory.SelectEntryPos(1);
115cdf0e10cSrcweir UpdateFunctionList();
116cdf0e10cSrcweir aLbCategory.SetSelectHdl( LINK( this, FuncPage, SelHdl ) );
117cdf0e10cSrcweir aLbFunction.SetSelectHdl( LINK( this, FuncPage, SelHdl ) );
118cdf0e10cSrcweir aLbFunction.SetDoubleClickHdl( LINK( this, FuncPage, DblClkHdl ) );
119cdf0e10cSrcweir }
120cdf0e10cSrcweir // -----------------------------------------------------------------------------
impl_addFunctions(const IFunctionCategory * _pCategory)121cdf0e10cSrcweir void FuncPage::impl_addFunctions(const IFunctionCategory* _pCategory)
122cdf0e10cSrcweir {
123cdf0e10cSrcweir const sal_uInt32 nCount = _pCategory->getCount();
124cdf0e10cSrcweir for(sal_uInt32 i = 0 ; i < nCount; ++i)
125cdf0e10cSrcweir {
126cdf0e10cSrcweir TFunctionDesc pDesc(_pCategory->getFunction(i));
127cdf0e10cSrcweir aLbFunction.SetEntryData(
128cdf0e10cSrcweir aLbFunction.InsertEntry(pDesc->getFunctionName() ),(void*)pDesc );
129cdf0e10cSrcweir } // for(sal_uInt32 i = 0 ; i < nCount; ++i)
130cdf0e10cSrcweir }
131cdf0e10cSrcweir
UpdateFunctionList()132cdf0e10cSrcweir void FuncPage::UpdateFunctionList()
133cdf0e10cSrcweir {
134cdf0e10cSrcweir sal_uInt16 nSelPos = aLbCategory.GetSelectEntryPos();
135cdf0e10cSrcweir const IFunctionCategory* pCategory = static_cast<const IFunctionCategory*>(aLbCategory.GetEntryData(nSelPos));
136cdf0e10cSrcweir sal_uInt16 nCategory = ( LISTBOX_ENTRY_NOTFOUND != nSelPos )
137cdf0e10cSrcweir ? Lb2Cat( nSelPos ) : 0;
138cdf0e10cSrcweir
139cdf0e10cSrcweir (void)nCategory;
140cdf0e10cSrcweir
141cdf0e10cSrcweir aLbFunction.Clear();
142cdf0e10cSrcweir aLbFunction.SetUpdateMode( sal_False );
143cdf0e10cSrcweir //------------------------------------------------------
144cdf0e10cSrcweir
145cdf0e10cSrcweir if ( nSelPos > 0 )
146cdf0e10cSrcweir {
147cdf0e10cSrcweir if ( pCategory == NULL )
148cdf0e10cSrcweir {
149cdf0e10cSrcweir const sal_uInt32 nCount = m_pFunctionManager->getCount();
150cdf0e10cSrcweir for(sal_uInt32 i = 0 ; i < nCount; ++i)
151cdf0e10cSrcweir {
152cdf0e10cSrcweir impl_addFunctions(m_pFunctionManager->getCategory(i));
153cdf0e10cSrcweir }
154cdf0e10cSrcweir }
155cdf0e10cSrcweir else
156cdf0e10cSrcweir {
157cdf0e10cSrcweir impl_addFunctions(pCategory);
158cdf0e10cSrcweir }
159cdf0e10cSrcweir }
160cdf0e10cSrcweir else // LRU-Liste
161cdf0e10cSrcweir {
162cdf0e10cSrcweir ::std::vector< TFunctionDesc >::iterator aIter = aLRUList.begin();
163cdf0e10cSrcweir ::std::vector< TFunctionDesc >::iterator aEnd = aLRUList.end();
164cdf0e10cSrcweir
165cdf0e10cSrcweir for ( ; aIter != aEnd; ++aIter )
166cdf0e10cSrcweir {
167cdf0e10cSrcweir const IFunctionDescription* pDesc = *aIter;
168cdf0e10cSrcweir if (pDesc) // may be null if a function is no longer available
169cdf0e10cSrcweir {
170cdf0e10cSrcweir aLbFunction.SetEntryData(
171cdf0e10cSrcweir aLbFunction.InsertEntry( pDesc->getFunctionName() ), (void*)pDesc );
172cdf0e10cSrcweir }
173cdf0e10cSrcweir }
174cdf0e10cSrcweir }
175cdf0e10cSrcweir
176cdf0e10cSrcweir //------------------------------------------------------
177cdf0e10cSrcweir aLbFunction.SetUpdateMode( sal_True );
178cdf0e10cSrcweir aLbFunction.SelectEntryPos(0);
179cdf0e10cSrcweir
180cdf0e10cSrcweir if(IsVisible()) SelHdl(&aLbFunction);
181cdf0e10cSrcweir }
182cdf0e10cSrcweir
IMPL_LINK(FuncPage,SelHdl,ListBox *,pLb)183cdf0e10cSrcweir IMPL_LINK( FuncPage, SelHdl, ListBox*, pLb )
184cdf0e10cSrcweir {
185cdf0e10cSrcweir if(pLb==&aLbFunction)
186cdf0e10cSrcweir {
187cdf0e10cSrcweir const IFunctionDescription* pDesc = GetFuncDesc( GetFunction() );
188cdf0e10cSrcweir if ( pDesc )
189cdf0e10cSrcweir {
190cdf0e10cSrcweir const rtl::OString sHelpId = pDesc->getHelpId();
191cdf0e10cSrcweir if ( sHelpId.getLength() )
192cdf0e10cSrcweir aLbFunction.SetHelpId(sHelpId);
193cdf0e10cSrcweir }
194cdf0e10cSrcweir aSelectionLink.Call(this);
195cdf0e10cSrcweir }
196cdf0e10cSrcweir else
197cdf0e10cSrcweir {
198cdf0e10cSrcweir aLbFunction.SetHelpId(m_aHelpId);
199cdf0e10cSrcweir UpdateFunctionList();
200cdf0e10cSrcweir }
201cdf0e10cSrcweir return 0;
202cdf0e10cSrcweir }
203cdf0e10cSrcweir
IMPL_LINK(FuncPage,DblClkHdl,ListBox *,EMPTYARG)204cdf0e10cSrcweir IMPL_LINK( FuncPage, DblClkHdl, ListBox*, EMPTYARG )
205cdf0e10cSrcweir {
206cdf0e10cSrcweir aDoubleClickLink.Call(this);
207cdf0e10cSrcweir return 0;
208cdf0e10cSrcweir }
209cdf0e10cSrcweir
SetCategory(sal_uInt16 nCat)210cdf0e10cSrcweir void FuncPage::SetCategory(sal_uInt16 nCat)
211cdf0e10cSrcweir {
212cdf0e10cSrcweir aLbCategory.SelectEntryPos(nCat);
213cdf0e10cSrcweir UpdateFunctionList();
214cdf0e10cSrcweir }
GetFuncPos(const IFunctionDescription * _pDesc)215cdf0e10cSrcweir sal_uInt16 FuncPage::GetFuncPos(const IFunctionDescription* _pDesc)
216cdf0e10cSrcweir {
217cdf0e10cSrcweir return aLbFunction.GetEntryPos(_pDesc);
218cdf0e10cSrcweir }
SetFunction(sal_uInt16 nFunc)219cdf0e10cSrcweir void FuncPage::SetFunction(sal_uInt16 nFunc)
220cdf0e10cSrcweir {
221cdf0e10cSrcweir aLbFunction.SelectEntryPos(nFunc);
222cdf0e10cSrcweir }
223cdf0e10cSrcweir
SetFocus()224cdf0e10cSrcweir void FuncPage::SetFocus()
225cdf0e10cSrcweir {
226cdf0e10cSrcweir aLbFunction.GrabFocus();
227cdf0e10cSrcweir }
228cdf0e10cSrcweir
GetCategory()229cdf0e10cSrcweir sal_uInt16 FuncPage::GetCategory()
230cdf0e10cSrcweir {
231cdf0e10cSrcweir return aLbCategory.GetSelectEntryPos();
232cdf0e10cSrcweir }
233cdf0e10cSrcweir
GetFunction()234cdf0e10cSrcweir sal_uInt16 FuncPage::GetFunction()
235cdf0e10cSrcweir {
236cdf0e10cSrcweir return aLbFunction.GetSelectEntryPos();
237cdf0e10cSrcweir }
238cdf0e10cSrcweir
GetFunctionEntryCount()239cdf0e10cSrcweir sal_uInt16 FuncPage::GetFunctionEntryCount()
240cdf0e10cSrcweir {
241cdf0e10cSrcweir return aLbFunction.GetSelectEntryCount();
242cdf0e10cSrcweir }
243cdf0e10cSrcweir
GetSelFunctionName() const244cdf0e10cSrcweir String FuncPage::GetSelFunctionName() const
245cdf0e10cSrcweir {
246cdf0e10cSrcweir return aLbFunction.GetSelectEntry();
247cdf0e10cSrcweir }
GetFuncDesc(sal_uInt16 nPos) const248cdf0e10cSrcweir const IFunctionDescription* FuncPage::GetFuncDesc( sal_uInt16 nPos ) const
249cdf0e10cSrcweir {
250cdf0e10cSrcweir // nicht schoen, aber hoffentlich selten
251cdf0e10cSrcweir return (const IFunctionDescription*) aLbFunction.GetEntryData(nPos);
252cdf0e10cSrcweir }
253cdf0e10cSrcweir
InitLRUList()254cdf0e10cSrcweir void FuncPage::InitLRUList()
255cdf0e10cSrcweir {
256cdf0e10cSrcweir ::std::vector< const IFunctionDescription*> aRUFunctions;
257cdf0e10cSrcweir m_pFunctionManager->fillLastRecentlyUsedFunctions(aLRUList);
258cdf0e10cSrcweir }
259cdf0e10cSrcweir
260cdf0e10cSrcweir
261cdf0e10cSrcweir } // formula
262cdf0e10cSrcweir
263