1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: funcpage.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_formula.hxx"
36 //----------------------------------------------------------------------------
38 #include <sfx2/dispatch.hxx>
39 #include <sfx2/docfile.hxx>
40 #include <svtools/zforlist.hxx>
41 #include <svtools/stritem.hxx>
42 #include "formula/IFunctionDescription.hxx"
44 #include "funcpage.hxx"
45 #include "formdlgs.hrc"
46 #include "ForResId.hrc"
47 #include "ModuleHelper.hxx"
48 //============================================================================
52 FormulaListBox::FormulaListBox( Window
* pParent
, WinBits nWinStyle
):
53 ListBox(pParent
,nWinStyle
)
56 FormulaListBox::FormulaListBox( Window
* pParent
, const ResId
& rResId
):
57 ListBox(pParent
,rResId
)
60 void FormulaListBox::KeyInput( const KeyEvent
& rKEvt
)
63 //ListBox::KeyInput(rKEvt);
65 if(aKEvt
.GetCharCode()==' ')
69 long FormulaListBox::PreNotify( NotifyEvent
& rNEvt
)
71 NotifyEvent aNotifyEvt
=rNEvt
;
73 long nResult
=ListBox::PreNotify(rNEvt
);
75 USHORT nSwitch
=aNotifyEvt
.GetType();
76 if(nSwitch
==EVENT_KEYINPUT
)
78 KeyInput(*aNotifyEvt
.GetKeyEvent());
85 //============================================================================
87 inline USHORT
Lb2Cat( USHORT nLbPos
)
89 // Kategorie 0 == LRU, sonst Categories == LbPos-1
96 //============================================================================
98 FuncPage::FuncPage(Window
* pParent
,const IFunctionManager
* _pFunctionManager
):
99 TabPage(pParent
,ModuleRes(RID_FORMULATAB_FUNCTION
)),
101 aFtCategory ( this, ModuleRes( FT_CATEGORY
) ),
102 aLbCategory ( this, ModuleRes( LB_CATEGORY
) ),
103 aFtFunction ( this, ModuleRes( FT_FUNCTION
) ),
104 aLbFunction ( this, ModuleRes( LB_FUNCTION
) ),
105 m_pFunctionManager(_pFunctionManager
)
108 m_aSmartHelpId
= aLbFunction
.GetSmartHelpId();
109 aLbFunction
.SetSmartUniqueId(m_aSmartHelpId
);
113 const sal_uInt32 nCategoryCount
= m_pFunctionManager
->getCount();
114 for(sal_uInt32 j
= 0; j
< nCategoryCount
; ++j
)
116 const IFunctionCategory
* pCategory
= m_pFunctionManager
->getCategory(j
);
117 aLbCategory
.SetEntryData(aLbCategory
.InsertEntry(pCategory
->getName()),(void*)pCategory
);
120 aLbCategory
.SelectEntryPos(1);
121 UpdateFunctionList();
122 aLbCategory
.SetSelectHdl( LINK( this, FuncPage
, SelHdl
) );
123 aLbFunction
.SetSelectHdl( LINK( this, FuncPage
, SelHdl
) );
124 aLbFunction
.SetDoubleClickHdl( LINK( this, FuncPage
, DblClkHdl
) );
126 // -----------------------------------------------------------------------------
127 void FuncPage::impl_addFunctions(const IFunctionCategory
* _pCategory
)
129 const sal_uInt32 nCount
= _pCategory
->getCount();
130 for(sal_uInt32 i
= 0 ; i
< nCount
; ++i
)
132 TFunctionDesc
pDesc(_pCategory
->getFunction(i
));
133 aLbFunction
.SetEntryData(
134 aLbFunction
.InsertEntry(pDesc
->getFunctionName() ),(void*)pDesc
);
135 } // for(sal_uInt32 i = 0 ; i < nCount; ++i)
138 void FuncPage::UpdateFunctionList()
140 USHORT nSelPos
= aLbCategory
.GetSelectEntryPos();
141 const IFunctionCategory
* pCategory
= static_cast<const IFunctionCategory
*>(aLbCategory
.GetEntryData(nSelPos
));
142 USHORT nCategory
= ( LISTBOX_ENTRY_NOTFOUND
!= nSelPos
)
143 ? Lb2Cat( nSelPos
) : 0;
148 aLbFunction
.SetUpdateMode( FALSE
);
149 //------------------------------------------------------
153 if ( pCategory
== NULL
)
155 const sal_uInt32 nCount
= m_pFunctionManager
->getCount();
156 for(sal_uInt32 i
= 0 ; i
< nCount
; ++i
)
158 impl_addFunctions(m_pFunctionManager
->getCategory(i
));
163 impl_addFunctions(pCategory
);
168 ::std::vector
< TFunctionDesc
>::iterator aIter
= aLRUList
.begin();
169 ::std::vector
< TFunctionDesc
>::iterator aEnd
= aLRUList
.end();
171 for ( ; aIter
!= aEnd
; ++aIter
)
173 const IFunctionDescription
* pDesc
= *aIter
;
174 if (pDesc
) // may be null if a function is no longer available
176 aLbFunction
.SetEntryData(
177 aLbFunction
.InsertEntry( pDesc
->getFunctionName() ), (void*)pDesc
);
182 //------------------------------------------------------
183 aLbFunction
.SetUpdateMode( TRUE
);
184 aLbFunction
.SelectEntryPos(0);
186 if(IsVisible()) SelHdl(&aLbFunction
);
189 IMPL_LINK( FuncPage
, SelHdl
, ListBox
*, pLb
)
191 if(pLb
==&aLbFunction
)
193 const IFunctionDescription
* pDesc
= GetFuncDesc( GetFunction() );
196 const long nHelpId
= pDesc
->getHelpId();
198 aLbFunction
.SetSmartHelpId(SmartId(nHelpId
));
200 aSelectionLink
.Call(this);
204 aLbFunction
.SetSmartHelpId(m_aSmartHelpId
);
205 UpdateFunctionList();
210 IMPL_LINK( FuncPage
, DblClkHdl
, ListBox
*, EMPTYARG
)
212 aDoubleClickLink
.Call(this);
216 void FuncPage::SetCategory(USHORT nCat
)
218 aLbCategory
.SelectEntryPos(nCat
);
219 UpdateFunctionList();
221 USHORT
FuncPage::GetFuncPos(const IFunctionDescription
* _pDesc
)
223 return aLbFunction
.GetEntryPos(_pDesc
);
225 void FuncPage::SetFunction(USHORT nFunc
)
227 aLbFunction
.SelectEntryPos(nFunc
);
230 void FuncPage::SetFocus()
232 aLbFunction
.GrabFocus();
235 USHORT
FuncPage::GetCategory()
237 return aLbCategory
.GetSelectEntryPos();
240 USHORT
FuncPage::GetFunction()
242 return aLbFunction
.GetSelectEntryPos();
245 USHORT
FuncPage::GetFunctionEntryCount()
247 return aLbFunction
.GetSelectEntryCount();
250 String
FuncPage::GetSelFunctionName() const
252 return aLbFunction
.GetSelectEntry();
254 const IFunctionDescription
* FuncPage::GetFuncDesc( USHORT nPos
) const
256 // nicht schoen, aber hoffentlich selten
257 return (const IFunctionDescription
*) aLbFunction
.GetEntryData(nPos
);
260 void FuncPage::InitLRUList()
262 ::std::vector
< const IFunctionDescription
*> aRUFunctions
;
263 m_pFunctionManager
->fillLastRecentlyUsedFunctions(aLRUList
);