Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / formula / source / ui / dlg / funcpage.cxx
blobeaaf6fafeeffb87a8994792aa3e64312b7be7522
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 <sfx2/dispatch.hxx>
21 #include <sfx2/docfile.hxx>
22 #include <svl/zforlist.hxx>
23 #include <svl/stritem.hxx>
24 #include "formula/IFunctionDescription.hxx"
26 #include "funcpage.hxx"
27 #include "formdlgs.hrc"
28 #include "ForResId.hrc"
29 #include "ModuleHelper.hxx"
30 //============================================================================
31 namespace formula
34 FormulaListBox::FormulaListBox( Window* pParent, const ResId& rResId ):
35 ListBox(pParent,rResId)
38 void FormulaListBox::KeyInput( const KeyEvent& rKEvt )
40 KeyEvent aKEvt=rKEvt;
42 if(aKEvt.GetCharCode()==' ')
43 DoubleClick();
46 long FormulaListBox::PreNotify( NotifyEvent& rNEvt )
48 NotifyEvent aNotifyEvt=rNEvt;
50 long nResult=ListBox::PreNotify(rNEvt);
52 sal_uInt16 nSwitch=aNotifyEvt.GetType();
53 if(nSwitch==EVENT_KEYINPUT)
55 KeyInput(*aNotifyEvt.GetKeyEvent());
57 return nResult;
62 //============================================================================
64 inline sal_uInt16 Lb2Cat( sal_uInt16 nLbPos )
66 // Category 0 == LRU, otherwise Categories == LbPos-1
67 if ( nLbPos > 0 )
68 nLbPos -= 1;
70 return nLbPos;
73 //============================================================================
75 FuncPage::FuncPage(Window* pParent,const IFunctionManager* _pFunctionManager):
76 TabPage(pParent,ModuleRes(RID_FORMULATAB_FUNCTION)),
77 aFtCategory ( this, ModuleRes( FT_CATEGORY ) ),
78 aLbCategory ( this, ModuleRes( LB_CATEGORY ) ),
79 aFtFunction ( this, ModuleRes( FT_FUNCTION ) ),
80 aLbFunction ( this, ModuleRes( LB_FUNCTION ) ),
81 m_pFunctionManager(_pFunctionManager)
83 FreeResource();
84 m_aHelpId = aLbFunction.GetHelpId();
85 aLbFunction.SetUniqueId(m_aHelpId);
87 InitLRUList();
89 const sal_uInt32 nCategoryCount = m_pFunctionManager->getCount();
90 for(sal_uInt32 j= 0; j < nCategoryCount; ++j)
92 const IFunctionCategory* pCategory = m_pFunctionManager->getCategory(j);
93 aLbCategory.SetEntryData(aLbCategory.InsertEntry(pCategory->getName()),(void*)pCategory);
96 aLbCategory.SelectEntryPos(1);
97 UpdateFunctionList();
98 aLbCategory.SetSelectHdl( LINK( this, FuncPage, SelHdl ) );
99 aLbFunction.SetSelectHdl( LINK( this, FuncPage, SelHdl ) );
100 aLbFunction.SetDoubleClickHdl( LINK( this, FuncPage, DblClkHdl ) );
102 // -----------------------------------------------------------------------------
103 void FuncPage::impl_addFunctions(const IFunctionCategory* _pCategory)
105 const sal_uInt32 nCount = _pCategory->getCount();
106 for(sal_uInt32 i = 0 ; i < nCount; ++i)
108 TFunctionDesc pDesc(_pCategory->getFunction(i));
109 aLbFunction.SetEntryData(
110 aLbFunction.InsertEntry(pDesc->getFunctionName() ),(void*)pDesc );
111 } // for(sal_uInt32 i = 0 ; i < nCount; ++i)
114 void FuncPage::UpdateFunctionList()
116 sal_uInt16 nSelPos = aLbCategory.GetSelectEntryPos();
117 const IFunctionCategory* pCategory = static_cast<const IFunctionCategory*>(aLbCategory.GetEntryData(nSelPos));
118 sal_uInt16 nCategory = ( LISTBOX_ENTRY_NOTFOUND != nSelPos )
119 ? Lb2Cat( nSelPos ) : 0;
121 (void)nCategory;
123 aLbFunction.Clear();
124 aLbFunction.SetUpdateMode( sal_False );
125 //------------------------------------------------------
127 if ( nSelPos > 0 )
129 if ( pCategory == NULL )
131 const sal_uInt32 nCount = m_pFunctionManager->getCount();
132 for(sal_uInt32 i = 0 ; i < nCount; ++i)
134 impl_addFunctions(m_pFunctionManager->getCategory(i));
137 else
139 impl_addFunctions(pCategory);
142 else // LRU-List
144 ::std::vector< TFunctionDesc >::iterator aIter = aLRUList.begin();
145 ::std::vector< TFunctionDesc >::iterator aEnd = aLRUList.end();
147 for ( ; aIter != aEnd; ++aIter )
149 const IFunctionDescription* pDesc = *aIter;
150 if (pDesc) // may be null if a function is no longer available
152 aLbFunction.SetEntryData(
153 aLbFunction.InsertEntry( pDesc->getFunctionName() ), (void*)pDesc );
158 //------------------------------------------------------
159 aLbFunction.SetUpdateMode( sal_True );
160 aLbFunction.SelectEntryPos(0);
162 if(IsVisible()) SelHdl(&aLbFunction);
165 IMPL_LINK( FuncPage, SelHdl, ListBox*, pLb )
167 if(pLb==&aLbFunction)
169 const IFunctionDescription* pDesc = GetFuncDesc( GetFunction() );
170 if ( pDesc )
172 const rtl::OString sHelpId = pDesc->getHelpId();
173 if ( !sHelpId.isEmpty() )
174 aLbFunction.SetHelpId(sHelpId);
176 aSelectionLink.Call(this);
178 else
180 aLbFunction.SetHelpId(m_aHelpId);
181 UpdateFunctionList();
183 return 0;
186 IMPL_LINK_NOARG(FuncPage, DblClkHdl)
188 aDoubleClickLink.Call(this);
189 return 0;
192 void FuncPage::SetCategory(sal_uInt16 nCat)
194 aLbCategory.SelectEntryPos(nCat);
195 UpdateFunctionList();
197 sal_uInt16 FuncPage::GetFuncPos(const IFunctionDescription* _pDesc)
199 return aLbFunction.GetEntryPos(_pDesc);
201 void FuncPage::SetFunction(sal_uInt16 nFunc)
203 aLbFunction.SelectEntryPos(nFunc);
206 void FuncPage::SetFocus()
208 aLbFunction.GrabFocus();
211 sal_uInt16 FuncPage::GetCategory()
213 return aLbCategory.GetSelectEntryPos();
216 sal_uInt16 FuncPage::GetFunction()
218 return aLbFunction.GetSelectEntryPos();
221 sal_uInt16 FuncPage::GetFunctionEntryCount()
223 return aLbFunction.GetSelectEntryCount();
226 String FuncPage::GetSelFunctionName() const
228 return aLbFunction.GetSelectEntry();
230 const IFunctionDescription* FuncPage::GetFuncDesc( sal_uInt16 nPos ) const
232 // not pretty, but hopefully rare
233 return (const IFunctionDescription*) aLbFunction.GetEntryData(nPos);
236 void FuncPage::InitLRUList()
238 ::std::vector< const IFunctionDescription*> aRUFunctions;
239 m_pFunctionManager->fillLastRecentlyUsedFunctions(aLRUList);
243 } // formula
245 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */