1*c25918c1SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*c25918c1SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*c25918c1SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*c25918c1SAndrew Rist * distributed with this work for additional information 6*c25918c1SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*c25918c1SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*c25918c1SAndrew Rist * "License"); you may not use this file except in compliance 9*c25918c1SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*c25918c1SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*c25918c1SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*c25918c1SAndrew Rist * software distributed under the License is distributed on an 15*c25918c1SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*c25918c1SAndrew Rist * KIND, either express or implied. See the License for the 17*c25918c1SAndrew Rist * specific language governing permissions and limitations 18*c25918c1SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*c25918c1SAndrew Rist *************************************************************/ 21*c25918c1SAndrew Rist 22*c25918c1SAndrew 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 45cdf0e10cSrcweir FormulaListBox::FormulaListBox( Window* pParent, WinBits nWinStyle): 46cdf0e10cSrcweir ListBox(pParent,nWinStyle) 47cdf0e10cSrcweir {} 48cdf0e10cSrcweir 49cdf0e10cSrcweir FormulaListBox::FormulaListBox( Window* pParent, const ResId& rResId ): 50cdf0e10cSrcweir ListBox(pParent,rResId) 51cdf0e10cSrcweir {} 52cdf0e10cSrcweir 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 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 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 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 113cdf0e10cSrcweir aLbCategory.SelectEntryPos(1); 114cdf0e10cSrcweir UpdateFunctionList(); 115cdf0e10cSrcweir aLbCategory.SetSelectHdl( LINK( this, FuncPage, SelHdl ) ); 116cdf0e10cSrcweir aLbFunction.SetSelectHdl( LINK( this, FuncPage, SelHdl ) ); 117cdf0e10cSrcweir aLbFunction.SetDoubleClickHdl( LINK( this, FuncPage, DblClkHdl ) ); 118cdf0e10cSrcweir } 119cdf0e10cSrcweir // ----------------------------------------------------------------------------- 120cdf0e10cSrcweir void FuncPage::impl_addFunctions(const IFunctionCategory* _pCategory) 121cdf0e10cSrcweir { 122cdf0e10cSrcweir const sal_uInt32 nCount = _pCategory->getCount(); 123cdf0e10cSrcweir for(sal_uInt32 i = 0 ; i < nCount; ++i) 124cdf0e10cSrcweir { 125cdf0e10cSrcweir TFunctionDesc pDesc(_pCategory->getFunction(i)); 126cdf0e10cSrcweir aLbFunction.SetEntryData( 127cdf0e10cSrcweir aLbFunction.InsertEntry(pDesc->getFunctionName() ),(void*)pDesc ); 128cdf0e10cSrcweir } // for(sal_uInt32 i = 0 ; i < nCount; ++i) 129cdf0e10cSrcweir } 130cdf0e10cSrcweir 131cdf0e10cSrcweir void FuncPage::UpdateFunctionList() 132cdf0e10cSrcweir { 133cdf0e10cSrcweir sal_uInt16 nSelPos = aLbCategory.GetSelectEntryPos(); 134cdf0e10cSrcweir const IFunctionCategory* pCategory = static_cast<const IFunctionCategory*>(aLbCategory.GetEntryData(nSelPos)); 135cdf0e10cSrcweir sal_uInt16 nCategory = ( LISTBOX_ENTRY_NOTFOUND != nSelPos ) 136cdf0e10cSrcweir ? Lb2Cat( nSelPos ) : 0; 137cdf0e10cSrcweir 138cdf0e10cSrcweir (void)nCategory; 139cdf0e10cSrcweir 140cdf0e10cSrcweir aLbFunction.Clear(); 141cdf0e10cSrcweir aLbFunction.SetUpdateMode( sal_False ); 142cdf0e10cSrcweir //------------------------------------------------------ 143cdf0e10cSrcweir 144cdf0e10cSrcweir if ( nSelPos > 0 ) 145cdf0e10cSrcweir { 146cdf0e10cSrcweir if ( pCategory == NULL ) 147cdf0e10cSrcweir { 148cdf0e10cSrcweir const sal_uInt32 nCount = m_pFunctionManager->getCount(); 149cdf0e10cSrcweir for(sal_uInt32 i = 0 ; i < nCount; ++i) 150cdf0e10cSrcweir { 151cdf0e10cSrcweir impl_addFunctions(m_pFunctionManager->getCategory(i)); 152cdf0e10cSrcweir } 153cdf0e10cSrcweir } 154cdf0e10cSrcweir else 155cdf0e10cSrcweir { 156cdf0e10cSrcweir impl_addFunctions(pCategory); 157cdf0e10cSrcweir } 158cdf0e10cSrcweir } 159cdf0e10cSrcweir else // LRU-Liste 160cdf0e10cSrcweir { 161cdf0e10cSrcweir ::std::vector< TFunctionDesc >::iterator aIter = aLRUList.begin(); 162cdf0e10cSrcweir ::std::vector< TFunctionDesc >::iterator aEnd = aLRUList.end(); 163cdf0e10cSrcweir 164cdf0e10cSrcweir for ( ; aIter != aEnd; ++aIter ) 165cdf0e10cSrcweir { 166cdf0e10cSrcweir const IFunctionDescription* pDesc = *aIter; 167cdf0e10cSrcweir if (pDesc) // may be null if a function is no longer available 168cdf0e10cSrcweir { 169cdf0e10cSrcweir aLbFunction.SetEntryData( 170cdf0e10cSrcweir aLbFunction.InsertEntry( pDesc->getFunctionName() ), (void*)pDesc ); 171cdf0e10cSrcweir } 172cdf0e10cSrcweir } 173cdf0e10cSrcweir } 174cdf0e10cSrcweir 175cdf0e10cSrcweir //------------------------------------------------------ 176cdf0e10cSrcweir aLbFunction.SetUpdateMode( sal_True ); 177cdf0e10cSrcweir aLbFunction.SelectEntryPos(0); 178cdf0e10cSrcweir 179cdf0e10cSrcweir if(IsVisible()) SelHdl(&aLbFunction); 180cdf0e10cSrcweir } 181cdf0e10cSrcweir 182cdf0e10cSrcweir IMPL_LINK( FuncPage, SelHdl, ListBox*, pLb ) 183cdf0e10cSrcweir { 184cdf0e10cSrcweir if(pLb==&aLbFunction) 185cdf0e10cSrcweir { 186cdf0e10cSrcweir const IFunctionDescription* pDesc = GetFuncDesc( GetFunction() ); 187cdf0e10cSrcweir if ( pDesc ) 188cdf0e10cSrcweir { 189cdf0e10cSrcweir const rtl::OString sHelpId = pDesc->getHelpId(); 190cdf0e10cSrcweir if ( sHelpId.getLength() ) 191cdf0e10cSrcweir aLbFunction.SetHelpId(sHelpId); 192cdf0e10cSrcweir } 193cdf0e10cSrcweir aSelectionLink.Call(this); 194cdf0e10cSrcweir } 195cdf0e10cSrcweir else 196cdf0e10cSrcweir { 197cdf0e10cSrcweir aLbFunction.SetHelpId(m_aHelpId); 198cdf0e10cSrcweir UpdateFunctionList(); 199cdf0e10cSrcweir } 200cdf0e10cSrcweir return 0; 201cdf0e10cSrcweir } 202cdf0e10cSrcweir 203cdf0e10cSrcweir IMPL_LINK( FuncPage, DblClkHdl, ListBox*, EMPTYARG ) 204cdf0e10cSrcweir { 205cdf0e10cSrcweir aDoubleClickLink.Call(this); 206cdf0e10cSrcweir return 0; 207cdf0e10cSrcweir } 208cdf0e10cSrcweir 209cdf0e10cSrcweir void FuncPage::SetCategory(sal_uInt16 nCat) 210cdf0e10cSrcweir { 211cdf0e10cSrcweir aLbCategory.SelectEntryPos(nCat); 212cdf0e10cSrcweir UpdateFunctionList(); 213cdf0e10cSrcweir } 214cdf0e10cSrcweir sal_uInt16 FuncPage::GetFuncPos(const IFunctionDescription* _pDesc) 215cdf0e10cSrcweir { 216cdf0e10cSrcweir return aLbFunction.GetEntryPos(_pDesc); 217cdf0e10cSrcweir } 218cdf0e10cSrcweir void FuncPage::SetFunction(sal_uInt16 nFunc) 219cdf0e10cSrcweir { 220cdf0e10cSrcweir aLbFunction.SelectEntryPos(nFunc); 221cdf0e10cSrcweir } 222cdf0e10cSrcweir 223cdf0e10cSrcweir void FuncPage::SetFocus() 224cdf0e10cSrcweir { 225cdf0e10cSrcweir aLbFunction.GrabFocus(); 226cdf0e10cSrcweir } 227cdf0e10cSrcweir 228cdf0e10cSrcweir sal_uInt16 FuncPage::GetCategory() 229cdf0e10cSrcweir { 230cdf0e10cSrcweir return aLbCategory.GetSelectEntryPos(); 231cdf0e10cSrcweir } 232cdf0e10cSrcweir 233cdf0e10cSrcweir sal_uInt16 FuncPage::GetFunction() 234cdf0e10cSrcweir { 235cdf0e10cSrcweir return aLbFunction.GetSelectEntryPos(); 236cdf0e10cSrcweir } 237cdf0e10cSrcweir 238cdf0e10cSrcweir sal_uInt16 FuncPage::GetFunctionEntryCount() 239cdf0e10cSrcweir { 240cdf0e10cSrcweir return aLbFunction.GetSelectEntryCount(); 241cdf0e10cSrcweir } 242cdf0e10cSrcweir 243cdf0e10cSrcweir String FuncPage::GetSelFunctionName() const 244cdf0e10cSrcweir { 245cdf0e10cSrcweir return aLbFunction.GetSelectEntry(); 246cdf0e10cSrcweir } 247cdf0e10cSrcweir const IFunctionDescription* FuncPage::GetFuncDesc( sal_uInt16 nPos ) const 248cdf0e10cSrcweir { 249cdf0e10cSrcweir // nicht schoen, aber hoffentlich selten 250cdf0e10cSrcweir return (const IFunctionDescription*) aLbFunction.GetEntryData(nPos); 251cdf0e10cSrcweir } 252cdf0e10cSrcweir 253cdf0e10cSrcweir void FuncPage::InitLRUList() 254cdf0e10cSrcweir { 255cdf0e10cSrcweir ::std::vector< const IFunctionDescription*> aRUFunctions; 256cdf0e10cSrcweir m_pFunctionManager->fillLastRecentlyUsedFunctions(aLRUList); 257cdf0e10cSrcweir } 258cdf0e10cSrcweir 259cdf0e10cSrcweir 260cdf0e10cSrcweir } // formula 261cdf0e10cSrcweir 262