Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
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"
25 : :
26 : : #include "funcpage.hxx"
27 : : #include "formdlgs.hrc"
28 : : #include "ForResId.hrc"
29 : : #include "ModuleHelper.hxx"
30 : : //============================================================================
31 : : namespace formula
32 : : {
33 : :
34 : 0 : FormulaListBox::FormulaListBox( Window* pParent, const ResId& rResId ):
35 : 0 : ListBox(pParent,rResId)
36 : 0 : {}
37 : :
38 : 0 : void FormulaListBox::KeyInput( const KeyEvent& rKEvt )
39 : : {
40 [ # # ]: 0 : KeyEvent aKEvt=rKEvt;
41 : :
42 [ # # ]: 0 : if(aKEvt.GetCharCode()==' ')
43 [ # # ]: 0 : DoubleClick();
44 : 0 : }
45 : :
46 : 0 : long FormulaListBox::PreNotify( NotifyEvent& rNEvt )
47 : : {
48 : 0 : NotifyEvent aNotifyEvt=rNEvt;
49 : :
50 [ # # ]: 0 : long nResult=ListBox::PreNotify(rNEvt);
51 : :
52 : 0 : sal_uInt16 nSwitch=aNotifyEvt.GetType();
53 [ # # ]: 0 : if(nSwitch==EVENT_KEYINPUT)
54 : : {
55 [ # # ][ # # ]: 0 : KeyInput(*aNotifyEvt.GetKeyEvent());
56 : : }
57 : 0 : return nResult;
58 : : }
59 : :
60 : :
61 : :
62 : : //============================================================================
63 : :
64 : 0 : inline sal_uInt16 Lb2Cat( sal_uInt16 nLbPos )
65 : : {
66 : : // Category 0 == LRU, otherwise Categories == LbPos-1
67 [ # # ]: 0 : if ( nLbPos > 0 )
68 : 0 : nLbPos -= 1;
69 : :
70 : 0 : return nLbPos;
71 : : }
72 : :
73 : : //============================================================================
74 : :
75 : 0 : 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 [ # # ][ # # ]: 0 : m_pFunctionManager(_pFunctionManager)
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
82 : : {
83 [ # # ]: 0 : FreeResource();
84 [ # # ]: 0 : m_aHelpId = aLbFunction.GetHelpId();
85 [ # # ]: 0 : aLbFunction.SetUniqueId(m_aHelpId);
86 : :
87 [ # # ]: 0 : InitLRUList();
88 : :
89 [ # # ]: 0 : const sal_uInt32 nCategoryCount = m_pFunctionManager->getCount();
90 [ # # ]: 0 : for(sal_uInt32 j= 0; j < nCategoryCount; ++j)
91 : : {
92 [ # # ]: 0 : const IFunctionCategory* pCategory = m_pFunctionManager->getCategory(j);
93 [ # # ][ # # ]: 0 : aLbCategory.SetEntryData(aLbCategory.InsertEntry(pCategory->getName()),(void*)pCategory);
[ # # ][ # # ]
[ # # ]
94 : : }
95 : :
96 [ # # ]: 0 : aLbCategory.SelectEntryPos(1);
97 [ # # ]: 0 : UpdateFunctionList();
98 [ # # ]: 0 : aLbCategory.SetSelectHdl( LINK( this, FuncPage, SelHdl ) );
99 [ # # ]: 0 : aLbFunction.SetSelectHdl( LINK( this, FuncPage, SelHdl ) );
100 [ # # ]: 0 : aLbFunction.SetDoubleClickHdl( LINK( this, FuncPage, DblClkHdl ) );
101 : 0 : }
102 : : // -----------------------------------------------------------------------------
103 : 0 : void FuncPage::impl_addFunctions(const IFunctionCategory* _pCategory)
104 : : {
105 : 0 : const sal_uInt32 nCount = _pCategory->getCount();
106 [ # # ]: 0 : for(sal_uInt32 i = 0 ; i < nCount; ++i)
107 : : {
108 : 0 : TFunctionDesc pDesc(_pCategory->getFunction(i));
109 : : aLbFunction.SetEntryData(
110 [ # # ][ # # ]: 0 : aLbFunction.InsertEntry(pDesc->getFunctionName() ),(void*)pDesc );
[ # # ][ # # ]
111 : : } // for(sal_uInt32 i = 0 ; i < nCount; ++i)
112 : 0 : }
113 : :
114 : 0 : void FuncPage::UpdateFunctionList()
115 : : {
116 : 0 : sal_uInt16 nSelPos = aLbCategory.GetSelectEntryPos();
117 : 0 : const IFunctionCategory* pCategory = static_cast<const IFunctionCategory*>(aLbCategory.GetEntryData(nSelPos));
118 : : sal_uInt16 nCategory = ( LISTBOX_ENTRY_NOTFOUND != nSelPos )
119 [ # # ]: 0 : ? Lb2Cat( nSelPos ) : 0;
120 : :
121 : : (void)nCategory;
122 : :
123 : 0 : aLbFunction.Clear();
124 : 0 : aLbFunction.SetUpdateMode( sal_False );
125 : : //------------------------------------------------------
126 : :
127 [ # # ]: 0 : if ( nSelPos > 0 )
128 : : {
129 [ # # ]: 0 : if ( pCategory == NULL )
130 : : {
131 : 0 : const sal_uInt32 nCount = m_pFunctionManager->getCount();
132 [ # # ]: 0 : for(sal_uInt32 i = 0 ; i < nCount; ++i)
133 : : {
134 : 0 : impl_addFunctions(m_pFunctionManager->getCategory(i));
135 : : }
136 : : }
137 : : else
138 : : {
139 : 0 : impl_addFunctions(pCategory);
140 : : }
141 : : }
142 : : else // LRU-List
143 : : {
144 : 0 : ::std::vector< TFunctionDesc >::iterator aIter = aLRUList.begin();
145 : 0 : ::std::vector< TFunctionDesc >::iterator aEnd = aLRUList.end();
146 : :
147 [ # # ][ # # ]: 0 : for ( ; aIter != aEnd; ++aIter )
148 : : {
149 : 0 : const IFunctionDescription* pDesc = *aIter;
150 [ # # ]: 0 : if (pDesc) // may be null if a function is no longer available
151 : : {
152 : : aLbFunction.SetEntryData(
153 [ # # ][ # # ]: 0 : aLbFunction.InsertEntry( pDesc->getFunctionName() ), (void*)pDesc );
[ # # ][ # # ]
[ # # ]
154 : : }
155 : : }
156 : : }
157 : :
158 : : //------------------------------------------------------
159 : 0 : aLbFunction.SetUpdateMode( sal_True );
160 : 0 : aLbFunction.SelectEntryPos(0);
161 : :
162 [ # # ]: 0 : if(IsVisible()) SelHdl(&aLbFunction);
163 : 0 : }
164 : :
165 : 0 : IMPL_LINK( FuncPage, SelHdl, ListBox*, pLb )
166 : : {
167 [ # # ]: 0 : if(pLb==&aLbFunction)
168 : : {
169 : 0 : const IFunctionDescription* pDesc = GetFuncDesc( GetFunction() );
170 [ # # ]: 0 : if ( pDesc )
171 : : {
172 [ # # ]: 0 : const rtl::OString sHelpId = pDesc->getHelpId();
173 [ # # ]: 0 : if ( !sHelpId.isEmpty() )
174 [ # # ]: 0 : aLbFunction.SetHelpId(sHelpId);
175 : : }
176 : 0 : aSelectionLink.Call(this);
177 : : }
178 : : else
179 : : {
180 : 0 : aLbFunction.SetHelpId(m_aHelpId);
181 : 0 : UpdateFunctionList();
182 : : }
183 : 0 : return 0;
184 : : }
185 : :
186 : 0 : IMPL_LINK_NOARG(FuncPage, DblClkHdl)
187 : : {
188 : 0 : aDoubleClickLink.Call(this);
189 : 0 : return 0;
190 : : }
191 : :
192 : 0 : void FuncPage::SetCategory(sal_uInt16 nCat)
193 : : {
194 : 0 : aLbCategory.SelectEntryPos(nCat);
195 : 0 : UpdateFunctionList();
196 : 0 : }
197 : 0 : sal_uInt16 FuncPage::GetFuncPos(const IFunctionDescription* _pDesc)
198 : : {
199 : 0 : return aLbFunction.GetEntryPos(_pDesc);
200 : : }
201 : 0 : void FuncPage::SetFunction(sal_uInt16 nFunc)
202 : : {
203 : 0 : aLbFunction.SelectEntryPos(nFunc);
204 : 0 : }
205 : :
206 : 0 : void FuncPage::SetFocus()
207 : : {
208 : 0 : aLbFunction.GrabFocus();
209 : 0 : }
210 : :
211 : 0 : sal_uInt16 FuncPage::GetCategory()
212 : : {
213 : 0 : return aLbCategory.GetSelectEntryPos();
214 : : }
215 : :
216 : 0 : sal_uInt16 FuncPage::GetFunction()
217 : : {
218 : 0 : return aLbFunction.GetSelectEntryPos();
219 : : }
220 : :
221 : 0 : sal_uInt16 FuncPage::GetFunctionEntryCount()
222 : : {
223 : 0 : return aLbFunction.GetSelectEntryCount();
224 : : }
225 : :
226 : 0 : String FuncPage::GetSelFunctionName() const
227 : : {
228 : 0 : return aLbFunction.GetSelectEntry();
229 : : }
230 : 0 : const IFunctionDescription* FuncPage::GetFuncDesc( sal_uInt16 nPos ) const
231 : : {
232 : : // not pretty, but hopefully rare
233 : 0 : return (const IFunctionDescription*) aLbFunction.GetEntryData(nPos);
234 : : }
235 : :
236 : 0 : void FuncPage::InitLRUList()
237 : : {
238 [ # # ]: 0 : ::std::vector< const IFunctionDescription*> aRUFunctions;
239 [ # # ]: 0 : m_pFunctionManager->fillLastRecentlyUsedFunctions(aLRUList);
240 : 0 : }
241 : :
242 : :
243 : : } // formula
244 : :
245 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|