LCOV - code coverage report
Current view: top level - formula/source/ui/dlg - funcpage.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 110 0.9 %
Date: 2014-11-03 Functions: 2 24 8.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <sfx2/dispatch.hxx>
      21             : #include <sfx2/docfile.hxx>
      22             : #include <svl/zforlist.hxx>
      23             : #include <svl/stritem.hxx>
      24             : #include "formula/IFunctionDescription.hxx"
      25             : 
      26             : #include "funcpage.hxx"
      27             : #include "formdlgs.hrc"
      28             : #include "ForResId.hrc"
      29             : #include "ModuleHelper.hxx"
      30             : 
      31             : namespace formula
      32             : {
      33             : 
      34           0 : FormulaListBox::FormulaListBox( vcl::Window* pParent, WinBits nBits ):
      35           0 :     ListBox(pParent, nBits)
      36           0 : {}
      37             : 
      38           0 : void FormulaListBox::KeyInput( const KeyEvent& rKEvt )
      39             : {
      40           0 :     KeyEvent aKEvt=rKEvt;
      41             : 
      42           0 :     if(aKEvt.GetCharCode()==' ')
      43           0 :         DoubleClick();
      44           0 : }
      45             : 
      46           0 : bool FormulaListBox::PreNotify( NotifyEvent& rNEvt )
      47             : {
      48           0 :     NotifyEvent aNotifyEvt=rNEvt;
      49             : 
      50           0 :     bool nResult = ListBox::PreNotify(rNEvt);
      51             : 
      52           0 :     sal_uInt16 nSwitch=aNotifyEvt.GetType();
      53           0 :     if(nSwitch==EVENT_KEYINPUT)
      54             :     {
      55           0 :         KeyInput(*aNotifyEvt.GetKeyEvent());
      56             :     }
      57           0 :     return nResult;
      58             : }
      59             : 
      60           0 : extern "C" SAL_DLLPUBLIC_EXPORT vcl::Window* SAL_CALL makeFormulaListBox(vcl::Window *pParent, VclBuilder::stringmap &)
      61             : {
      62           0 :     return new FormulaListBox(pParent, WB_BORDER | WB_SORT);
      63             : }
      64             : 
      65           0 : inline sal_uInt16 Lb2Cat( sal_uInt16 nLbPos )
      66             : {
      67             :     // Category 0 == LRU, otherwise Categories == LbPos-1
      68           0 :     if ( nLbPos > 0 )
      69           0 :         nLbPos -= 1;
      70             : 
      71           0 :     return nLbPos;
      72             : }
      73             : 
      74           0 : FuncPage::FuncPage(vcl::Window* pParent,const IFunctionManager* _pFunctionManager):
      75             :     TabPage(pParent, "FunctionPage", "formula/ui/functionpage.ui"),
      76           0 :     m_pFunctionManager(_pFunctionManager)
      77             : {
      78           0 :     get(m_pLbCategory, "category");
      79           0 :     get(m_pLbFunction, "function");
      80           0 :     m_pLbFunction->SetStyle(m_pLbFunction->GetStyle() | WB_SORT);
      81           0 :     Size aSize(LogicToPixel(Size(86 , 162), MAP_APPFONT));
      82           0 :     m_pLbFunction->set_height_request(aSize.Height());
      83           0 :     m_pLbFunction->set_width_request(aSize.Width());
      84           0 :     m_aHelpId = m_pLbFunction->GetHelpId();
      85           0 :     m_pLbFunction->SetUniqueId(m_aHelpId);
      86             : 
      87           0 :     InitLRUList();
      88             : 
      89           0 :     const sal_uInt32 nCategoryCount = m_pFunctionManager->getCount();
      90           0 :     for(sal_uInt32 j= 0; j < nCategoryCount; ++j)
      91             :     {
      92           0 :         const IFunctionCategory* pCategory = m_pFunctionManager->getCategory(j);
      93           0 :         m_pLbCategory->SetEntryData(m_pLbCategory->InsertEntry(pCategory->getName()),(void*)pCategory);
      94             :     }
      95             : 
      96           0 :     m_pLbCategory->SelectEntryPos(1);
      97           0 :     UpdateFunctionList();
      98           0 :     m_pLbCategory->SetSelectHdl( LINK( this, FuncPage, SelHdl ) );
      99           0 :     m_pLbFunction->SetSelectHdl( LINK( this, FuncPage, SelHdl ) );
     100           0 :     m_pLbFunction->SetDoubleClickHdl( LINK( this, FuncPage, DblClkHdl ) );
     101           0 : }
     102             : 
     103           0 : void FuncPage::impl_addFunctions(const IFunctionCategory* _pCategory)
     104             : {
     105           0 :     const sal_uInt32 nCount = _pCategory->getCount();
     106           0 :     for(sal_uInt32 i = 0 ; i < nCount; ++i)
     107             :     {
     108           0 :         TFunctionDesc pDesc(_pCategory->getFunction(i));
     109             :         m_pLbFunction->SetEntryData(
     110           0 :             m_pLbFunction->InsertEntry(pDesc->getFunctionName() ),(void*)pDesc );
     111             :     }
     112           0 : }
     113             : 
     114           0 : void FuncPage::UpdateFunctionList()
     115             : {
     116           0 :     sal_Int32  nSelPos   = m_pLbCategory->GetSelectEntryPos();
     117           0 :     const IFunctionCategory* pCategory = static_cast<const IFunctionCategory*>(m_pLbCategory->GetEntryData(nSelPos));
     118             :     sal_Int32  nCategory = ( LISTBOX_ENTRY_NOTFOUND != nSelPos )
     119           0 :                             ? Lb2Cat( nSelPos ) : 0;
     120             : 
     121             :     (void)nCategory;
     122             : 
     123           0 :     m_pLbFunction->Clear();
     124           0 :     m_pLbFunction->SetUpdateMode( false );
     125             : 
     126             : 
     127           0 :     if ( nSelPos > 0 )
     128             :     {
     129           0 :         if ( pCategory == NULL )
     130             :         {
     131           0 :             const sal_uInt32 nCount = m_pFunctionManager->getCount();
     132           0 :             for(sal_uInt32 i = 0 ; i < nCount; ++i)
     133             :             {
     134           0 :                 impl_addFunctions(m_pFunctionManager->getCategory(i));
     135             :             }
     136             :         }
     137             :         else
     138             :         {
     139           0 :             impl_addFunctions(pCategory);
     140             :         }
     141             :     }
     142             :     else // LRU-List
     143             :     {
     144           0 :         ::std::vector< TFunctionDesc >::iterator aIter = aLRUList.begin();
     145           0 :         ::std::vector< TFunctionDesc >::iterator aEnd = aLRUList.end();
     146             : 
     147           0 :         for ( ; aIter != aEnd; ++aIter )
     148             :         {
     149           0 :             const IFunctionDescription* pDesc = *aIter;
     150           0 :             if (pDesc)  // may be null if a function is no longer available
     151             :             {
     152             :                 m_pLbFunction->SetEntryData(
     153           0 :                     m_pLbFunction->InsertEntry( pDesc->getFunctionName() ), (void*)pDesc );
     154             :             }
     155             :         }
     156             :     }
     157             : 
     158             : 
     159           0 :     m_pLbFunction->SetUpdateMode( true );
     160           0 :     m_pLbFunction->SelectEntryPos(0);
     161             : 
     162           0 :     if(IsVisible()) SelHdl(m_pLbFunction);
     163           0 : }
     164             : 
     165           0 : IMPL_LINK( FuncPage, SelHdl, ListBox*, pLb )
     166             : {
     167           0 :     if(pLb==m_pLbFunction)
     168             :     {
     169           0 :         const IFunctionDescription* pDesc = GetFuncDesc( GetFunction() );
     170           0 :         if ( pDesc )
     171             :         {
     172           0 :             const OString sHelpId = pDesc->getHelpId();
     173           0 :             if ( !sHelpId.isEmpty() )
     174           0 :                 m_pLbFunction->SetHelpId(sHelpId);
     175             :         }
     176           0 :         aSelectionLink.Call(this);
     177             :     }
     178             :     else
     179             :     {
     180           0 :         m_pLbFunction->SetHelpId(m_aHelpId);
     181           0 :         UpdateFunctionList();
     182             :     }
     183           0 :     return 0;
     184             : }
     185             : 
     186           0 : IMPL_LINK_NOARG(FuncPage, DblClkHdl)
     187             : {
     188           0 :     aDoubleClickLink.Call(this);
     189           0 :     return 0;
     190             : }
     191             : 
     192           0 : void FuncPage::SetCategory(sal_Int32 nCat)
     193             : {
     194           0 :     m_pLbCategory->SelectEntryPos(nCat);
     195           0 :     UpdateFunctionList();
     196           0 : }
     197             : 
     198           0 : sal_Int32 FuncPage::GetFuncPos(const IFunctionDescription* _pDesc)
     199             : {
     200           0 :     return m_pLbFunction->GetEntryPos(_pDesc);
     201             : }
     202             : 
     203           0 : void FuncPage::SetFunction(sal_Int32 nFunc)
     204             : {
     205           0 :     m_pLbFunction->SelectEntryPos(nFunc);
     206           0 : }
     207             : 
     208           0 : void FuncPage::SetFocus()
     209             : {
     210           0 :     m_pLbFunction->GrabFocus();
     211           0 : }
     212             : 
     213           0 : sal_Int32 FuncPage::GetCategory()
     214             : {
     215           0 :     return m_pLbCategory->GetSelectEntryPos();
     216             : }
     217             : 
     218           0 : sal_Int32 FuncPage::GetFunction()
     219             : {
     220           0 :     return m_pLbFunction->GetSelectEntryPos();
     221             : }
     222             : 
     223           0 : sal_Int32 FuncPage::GetFunctionEntryCount()
     224             : {
     225           0 :     return m_pLbFunction->GetSelectEntryCount();
     226             : }
     227             : 
     228           0 : OUString FuncPage::GetSelFunctionName() const
     229             : {
     230           0 :     return m_pLbFunction->GetSelectEntry();
     231             : }
     232             : 
     233           0 : const IFunctionDescription* FuncPage::GetFuncDesc( sal_Int32 nPos ) const
     234             : {
     235             :     // not pretty, but hopefully rare
     236           0 :     return (const IFunctionDescription*) m_pLbFunction->GetEntryData(nPos);
     237             : }
     238             : 
     239           0 : void FuncPage::InitLRUList()
     240             : {
     241           0 :     m_pFunctionManager->fillLastRecentlyUsedFunctions(aLRUList);
     242           0 : }
     243             : 
     244             : 
     245         276 : } // formula
     246             : 
     247             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10