LCOV - code coverage report
Current view: top level - formula/source/ui/dlg - funcpage.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 114 0.9 %
Date: 2015-06-13 12:38:46 Functions: 2 26 7.7 %
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 <vcl/builderfactory.hxx>
      25             : #include "formula/IFunctionDescription.hxx"
      26             : 
      27             : #include "funcpage.hxx"
      28             : #include "formdlgs.hrc"
      29             : #include "ForResId.hrc"
      30             : #include "ModuleHelper.hxx"
      31             : 
      32             : namespace formula
      33             : {
      34             : 
      35           0 : FormulaListBox::FormulaListBox( vcl::Window* pParent, WinBits nBits ):
      36           0 :     ListBox(pParent, nBits)
      37           0 : {}
      38             : 
      39           0 : void FormulaListBox::KeyInput( const KeyEvent& rKEvt )
      40             : {
      41           0 :     KeyEvent aKEvt=rKEvt;
      42             : 
      43           0 :     if(aKEvt.GetCharCode()==' ')
      44           0 :         DoubleClick();
      45           0 : }
      46             : 
      47           0 : bool FormulaListBox::PreNotify( NotifyEvent& rNEvt )
      48             : {
      49           0 :     NotifyEvent aNotifyEvt=rNEvt;
      50             : 
      51           0 :     bool nResult = ListBox::PreNotify(rNEvt);
      52             : 
      53           0 :     MouseNotifyEvent nSwitch=aNotifyEvt.GetType();
      54           0 :     if(nSwitch==MouseNotifyEvent::KEYINPUT)
      55             :     {
      56           0 :         KeyInput(*aNotifyEvt.GetKeyEvent());
      57             :     }
      58           0 :     return nResult;
      59             : }
      60             : 
      61           0 : VCL_BUILDER_FACTORY_ARGS(FormulaListBox, WB_BORDER | WB_SORT)
      62             : 
      63           0 : FuncPage::FuncPage(vcl::Window* pParent,const IFunctionManager* _pFunctionManager):
      64             :     TabPage(pParent, "FunctionPage", "formula/ui/functionpage.ui"),
      65           0 :     m_pFunctionManager(_pFunctionManager)
      66             : {
      67           0 :     get(m_pLbCategory, "category");
      68           0 :     get(m_pLbFunction, "function");
      69           0 :     m_pLbFunction->SetStyle(m_pLbFunction->GetStyle() | WB_SORT);
      70           0 :     Size aSize(LogicToPixel(Size(86 , 162), MAP_APPFONT));
      71           0 :     m_pLbFunction->set_height_request(aSize.Height());
      72           0 :     m_pLbFunction->set_width_request(aSize.Width());
      73           0 :     m_aHelpId = m_pLbFunction->GetHelpId();
      74           0 :     m_pLbFunction->SetUniqueId(m_aHelpId);
      75             : 
      76           0 :     InitLRUList();
      77             : 
      78           0 :     const sal_uInt32 nCategoryCount = m_pFunctionManager->getCount();
      79           0 :     for(sal_uInt32 j= 0; j < nCategoryCount; ++j)
      80             :     {
      81           0 :         const IFunctionCategory* pCategory = m_pFunctionManager->getCategory(j);
      82           0 :         m_pLbCategory->SetEntryData(m_pLbCategory->InsertEntry(pCategory->getName()),const_cast<IFunctionCategory *>(pCategory));
      83             :     }
      84             : 
      85           0 :     m_pLbCategory->SelectEntryPos(1);
      86           0 :     UpdateFunctionList();
      87           0 :     m_pLbCategory->SetSelectHdl( LINK( this, FuncPage, SelHdl ) );
      88           0 :     m_pLbFunction->SetSelectHdl( LINK( this, FuncPage, SelHdl ) );
      89           0 :     m_pLbFunction->SetDoubleClickHdl( LINK( this, FuncPage, DblClkHdl ) );
      90           0 : }
      91             : 
      92           0 : FuncPage::~FuncPage()
      93             : {
      94           0 :     disposeOnce();
      95           0 : }
      96             : 
      97           0 : void FuncPage::dispose()
      98             : {
      99           0 :     m_pLbCategory.clear();
     100           0 :     m_pLbFunction.clear();
     101           0 :     TabPage::dispose();
     102           0 : }
     103             : 
     104           0 : void FuncPage::impl_addFunctions(const IFunctionCategory* _pCategory)
     105             : {
     106           0 :     const sal_uInt32 nCount = _pCategory->getCount();
     107           0 :     for(sal_uInt32 i = 0 ; i < nCount; ++i)
     108             :     {
     109           0 :         TFunctionDesc pDesc(_pCategory->getFunction(i));
     110           0 :         m_pLbFunction->SetEntryData(
     111           0 :             m_pLbFunction->InsertEntry(pDesc->getFunctionName() ),const_cast<IFunctionDescription *>(pDesc) );
     112             :     }
     113           0 : }
     114             : 
     115           0 : void FuncPage::UpdateFunctionList()
     116             : {
     117           0 :     sal_Int32  nSelPos   = m_pLbCategory->GetSelectEntryPos();
     118           0 :     const IFunctionCategory* pCategory = static_cast<const IFunctionCategory*>(m_pLbCategory->GetEntryData(nSelPos));
     119             : 
     120           0 :     m_pLbFunction->Clear();
     121           0 :     m_pLbFunction->SetUpdateMode( false );
     122             : 
     123             : 
     124           0 :     if ( nSelPos > 0 )
     125             :     {
     126           0 :         if ( pCategory == NULL )
     127             :         {
     128           0 :             const sal_uInt32 nCount = m_pFunctionManager->getCount();
     129           0 :             for(sal_uInt32 i = 0 ; i < nCount; ++i)
     130             :             {
     131           0 :                 impl_addFunctions(m_pFunctionManager->getCategory(i));
     132             :             }
     133             :         }
     134             :         else
     135             :         {
     136           0 :             impl_addFunctions(pCategory);
     137             :         }
     138             :     }
     139             :     else // LRU-List
     140             :     {
     141           0 :         ::std::vector< TFunctionDesc >::iterator aIter = aLRUList.begin();
     142           0 :         ::std::vector< TFunctionDesc >::iterator aEnd = aLRUList.end();
     143             : 
     144           0 :         for ( ; aIter != aEnd; ++aIter )
     145             :         {
     146           0 :             const IFunctionDescription* pDesc = *aIter;
     147           0 :             if (pDesc)  // may be null if a function is no longer available
     148             :             {
     149           0 :                 m_pLbFunction->SetEntryData(
     150           0 :                     m_pLbFunction->InsertEntry( pDesc->getFunctionName() ), const_cast<IFunctionDescription *>(pDesc) );
     151             :             }
     152             :         }
     153             :     }
     154             : 
     155             : 
     156           0 :     m_pLbFunction->SetUpdateMode( true );
     157           0 :     m_pLbFunction->SelectEntryPos(0);
     158             : 
     159           0 :     if(IsVisible()) SelHdl(m_pLbFunction);
     160           0 : }
     161             : 
     162           0 : IMPL_LINK( FuncPage, SelHdl, ListBox*, pLb )
     163             : {
     164           0 :     if(pLb==m_pLbFunction)
     165             :     {
     166           0 :         const IFunctionDescription* pDesc = GetFuncDesc( GetFunction() );
     167           0 :         if ( pDesc )
     168             :         {
     169           0 :             const OString sHelpId = pDesc->getHelpId();
     170           0 :             if ( !sHelpId.isEmpty() )
     171           0 :                 m_pLbFunction->SetHelpId(sHelpId);
     172             :         }
     173           0 :         aSelectionLink.Call(this);
     174             :     }
     175             :     else
     176             :     {
     177           0 :         m_pLbFunction->SetHelpId(m_aHelpId);
     178           0 :         UpdateFunctionList();
     179             :     }
     180           0 :     return 0;
     181             : }
     182             : 
     183           0 : IMPL_LINK_NOARG(FuncPage, DblClkHdl)
     184             : {
     185           0 :     aDoubleClickLink.Call(this);
     186           0 :     return 0;
     187             : }
     188             : 
     189           0 : void FuncPage::SetCategory(sal_Int32 nCat)
     190             : {
     191           0 :     m_pLbCategory->SelectEntryPos(nCat);
     192           0 :     UpdateFunctionList();
     193           0 : }
     194             : 
     195           0 : sal_Int32 FuncPage::GetFuncPos(const IFunctionDescription* _pDesc)
     196             : {
     197           0 :     return m_pLbFunction->GetEntryPos(_pDesc);
     198             : }
     199             : 
     200           0 : void FuncPage::SetFunction(sal_Int32 nFunc)
     201             : {
     202           0 :     m_pLbFunction->SelectEntryPos(nFunc);
     203           0 : }
     204             : 
     205           0 : void FuncPage::SetFocus()
     206             : {
     207           0 :     m_pLbFunction->GrabFocus();
     208           0 : }
     209             : 
     210           0 : sal_Int32 FuncPage::GetCategory()
     211             : {
     212           0 :     return m_pLbCategory->GetSelectEntryPos();
     213             : }
     214             : 
     215           0 : sal_Int32 FuncPage::GetFunction()
     216             : {
     217           0 :     return m_pLbFunction->GetSelectEntryPos();
     218             : }
     219             : 
     220           0 : sal_Int32 FuncPage::GetFunctionEntryCount()
     221             : {
     222           0 :     return m_pLbFunction->GetSelectEntryCount();
     223             : }
     224             : 
     225           0 : OUString FuncPage::GetSelFunctionName() const
     226             : {
     227           0 :     return m_pLbFunction->GetSelectEntry();
     228             : }
     229             : 
     230           0 : const IFunctionDescription* FuncPage::GetFuncDesc( sal_Int32 nPos ) const
     231             : {
     232             :     // not pretty, but hopefully rare
     233           0 :     return static_cast<const IFunctionDescription*>(m_pLbFunction->GetEntryData(nPos));
     234             : }
     235             : 
     236           0 : void FuncPage::InitLRUList()
     237             : {
     238           0 :     m_pFunctionManager->fillLastRecentlyUsedFunctions(aLRUList);
     239           0 : }
     240             : 
     241             : 
     242         183 : } // formula
     243             : 
     244             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11