From 70e97ade2f8dd6f61574dca985074f550db0630f Mon Sep 17 00:00:00 2001 From: Abhilash Singh Date: Fri, 21 Oct 2016 02:33:18 +0530 Subject: tdf#67974 UI: Add a search box in function wizard in Spreadsheet Change-Id: Idd243824a25ba99b2163f094c531dad7fe1153c8 Reviewed-on: https://gerrit.libreoffice.org/30118 Tested-by: Jenkins Reviewed-by: Eike Rathke Tested-by: Eike Rathke --- formula/source/ui/dlg/funcpage.cxx | 85 +++++++++++++++++++++++++++---------- formula/source/ui/dlg/funcpage.hxx | 5 ++- formula/uiconfig/ui/functionpage.ui | 40 ++++++++++++++--- 3 files changed, 100 insertions(+), 30 deletions(-) diff --git a/formula/source/ui/dlg/funcpage.cxx b/formula/source/ui/dlg/funcpage.cxx index 9a20545c9228..096822499d92 100644 --- a/formula/source/ui/dlg/funcpage.cxx +++ b/formula/source/ui/dlg/funcpage.cxx @@ -28,6 +28,8 @@ #include "formdlgs.hrc" #include "ForResId.hrc" #include "ModuleHelper.hxx" +#include +#include namespace formula { @@ -64,6 +66,7 @@ FuncPage::FuncPage(vcl::Window* pParent,const IFunctionManager* _pFunctionManage { get(m_pLbCategory, "category"); get(m_pLbFunction, "function"); + get(m_plbFunctionSearchString, "search"); m_pLbFunction->SetStyle(m_pLbFunction->GetStyle() | WB_SORT); Size aSize(LogicToPixel(Size(86 , 162), MapUnit::MapAppFont)); m_pLbFunction->set_height_request(aSize.Height()); @@ -81,10 +84,12 @@ FuncPage::FuncPage(vcl::Window* pParent,const IFunctionManager* _pFunctionManage m_pLbCategory->SetDropDownLineCount(m_pLbCategory->GetEntryCount()); m_pLbCategory->SelectEntryPos(1); - UpdateFunctionList(); + OUString searchStr = m_plbFunctionSearchString->GetText(); + UpdateFunctionList(searchStr); m_pLbCategory->SetSelectHdl( LINK( this, FuncPage, SelHdl ) ); m_pLbFunction->SetSelectHdl( LINK( this, FuncPage, SelHdl ) ); m_pLbFunction->SetDoubleClickHdl( LINK( this, FuncPage, DblClkHdl ) ); + m_plbFunctionSearchString->SetModifyHdl( LINK( this, FuncPage, ModifyHdl ) ); } FuncPage::~FuncPage() @@ -96,6 +101,7 @@ void FuncPage::dispose() { m_pLbCategory.clear(); m_pLbFunction.clear(); + m_plbFunctionSearchString.clear(); TabPage::dispose(); } @@ -111,47 +117,72 @@ void FuncPage::impl_addFunctions(const IFunctionCategory* _pCategory) } } -void FuncPage::UpdateFunctionList() +//aStr is non-empty when user types in the search box to search some function +void FuncPage::UpdateFunctionList(const OUString& aStr) { - sal_Int32 nSelPos = m_pLbCategory->GetSelectEntryPos(); - const IFunctionCategory* pCategory = static_cast(m_pLbCategory->GetEntryData(nSelPos)); m_pLbFunction->Clear(); m_pLbFunction->SetUpdateMode( false ); - - if ( nSelPos > 0 ) + if(aStr.isEmpty()) { - if ( pCategory == nullptr ) + sal_Int32 nSelPos = m_pLbCategory->GetSelectEntryPos(); + const IFunctionCategory* pCategory = static_cast(m_pLbCategory->GetEntryData(nSelPos)); + + if ( nSelPos > 0 ) { - const sal_uInt32 nCount = m_pFunctionManager->getCount(); - for(sal_uInt32 i = 0 ; i < nCount; ++i) + if ( pCategory == nullptr ) + { + const sal_uInt32 nCount = m_pFunctionManager->getCount(); + for(sal_uInt32 i = 0 ; i < nCount; ++i) + { + impl_addFunctions(m_pFunctionManager->getCategory(i)); + } + } + else { - impl_addFunctions(m_pFunctionManager->getCategory(i)); + impl_addFunctions(pCategory); } } - else + else // LRU-List { - impl_addFunctions(pCategory); + ::std::vector< TFunctionDesc >::iterator aIter = aLRUList.begin(); + ::std::vector< TFunctionDesc >::iterator aEnd = aLRUList.end(); + + for ( ; aIter != aEnd; ++aIter ) + { + const IFunctionDescription* pDesc = *aIter; + if (pDesc) // may be null if a function is no longer available + { + m_pLbFunction->SetEntryData( + m_pLbFunction->InsertEntry( pDesc->getFunctionName() ), const_cast(pDesc) ); + } + } } } - else // LRU-List + else { - ::std::vector< TFunctionDesc >::iterator aIter = aLRUList.begin(); - ::std::vector< TFunctionDesc >::iterator aEnd = aLRUList.end(); + SvtSysLocale aSysLocale; + const CharClass* pCharClassPtr = aSysLocale.GetCharClassPtr(); + OUString aSearchStr = pCharClassPtr->uppercase(aStr); - for ( ; aIter != aEnd; ++aIter ) + const sal_uInt32 nCategoryCount = m_pFunctionManager->getCount(); + for (sal_uInt32 i = 0; i < nCategoryCount; i++) { - const IFunctionDescription* pDesc = *aIter; - if (pDesc) // may be null if a function is no longer available + const IFunctionCategory* pCategory = m_pFunctionManager->getCategory(i); + const sal_uInt32 functionCount = pCategory->getCount(); + for (sal_uInt32 j = 0; j < functionCount; ++j) { - m_pLbFunction->SetEntryData( - m_pLbFunction->InsertEntry( pDesc->getFunctionName() ), const_cast(pDesc) ); + TFunctionDesc pDesc(pCategory->getFunction(j)); + if (pCharClassPtr->uppercase(pDesc->getFunctionName()).indexOf(aSearchStr) >= 0) + { + m_pLbFunction->SetEntryData( + m_pLbFunction->InsertEntry(pDesc->getFunctionName()), const_cast(pDesc)); + } } } } - m_pLbFunction->SetUpdateMode( true ); // Ensure no function is selected so the Next button doesn't overwrite a // function that is not in the list with an arbitrary selected one. @@ -175,8 +206,9 @@ IMPL_LINK( FuncPage, SelHdl, ListBox&, rLb, void ) } else { + OUString searchStr = m_plbFunctionSearchString->GetText(); m_pLbFunction->SetHelpId(m_aHelpId); - UpdateFunctionList(); + UpdateFunctionList(searchStr); } } @@ -185,10 +217,17 @@ IMPL_LINK_NOARG(FuncPage, DblClkHdl, ListBox&, void) aDoubleClickLink.Call(*this); } +IMPL_LINK_NOARG(FuncPage, ModifyHdl, Edit&, void) +{ + OUString searchStr = m_plbFunctionSearchString->GetText(); + UpdateFunctionList(searchStr); +} + void FuncPage::SetCategory(sal_Int32 nCat) { + OUString searchStr = m_plbFunctionSearchString->GetText(); m_pLbCategory->SelectEntryPos(nCat); - UpdateFunctionList(); + UpdateFunctionList(searchStr); } sal_Int32 FuncPage::GetFuncPos(const IFunctionDescription* _pDesc) diff --git a/formula/source/ui/dlg/funcpage.hxx b/formula/source/ui/dlg/funcpage.hxx index b47a6d9f4be8..f2780492458c 100644 --- a/formula/source/ui/dlg/funcpage.hxx +++ b/formula/source/ui/dlg/funcpage.hxx @@ -61,8 +61,10 @@ private: OModuleClient m_aModuleClient; Link aDoubleClickLink; Link aSelectionLink; + Link aModifyLink; VclPtr m_pLbCategory; VclPtr m_pLbFunction; + VclPtr m_plbFunctionSearchString; const IFunctionManager* m_pFunctionManager; ::std::vector< TFunctionDesc > aLRUList; @@ -72,10 +74,11 @@ private: void impl_addFunctions(const IFunctionCategory* _pCategory); DECL_LINK( SelHdl, ListBox&, void ); DECL_LINK(DblClkHdl, ListBox&, void); + DECL_LINK(ModifyHdl, Edit&, void); protected: - void UpdateFunctionList(); + void UpdateFunctionList(const OUString&); void InitLRUList(); diff --git a/formula/uiconfig/ui/functionpage.ui b/formula/uiconfig/ui/functionpage.ui index 00b98df5b869..a382836741a4 100644 --- a/formula/uiconfig/ui/functionpage.ui +++ b/formula/uiconfig/ui/functionpage.ui @@ -1,8 +1,8 @@ - + - + True False @@ -11,6 +11,34 @@ 6 vertical 6 + + + True + False + start + _Search + True + search + + + False + True + 0 + + + + + True + True + start + True + + + False + True + 1 + + True @@ -23,7 +51,7 @@ False True - 0 + 2 @@ -39,7 +67,7 @@ False True - 1 + 3 @@ -54,7 +82,7 @@ False True - 2 + 4 @@ -70,7 +98,7 @@ True True - 3 + 5 -- cgit v1.2.3