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