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