LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sc/source/ui/namedlg - namemgrtable.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 166 0.6 %
Date: 2013-07-09 Functions: 2 23 8.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             : 
      10             : //ScRangeManagerTable
      11             : #include "global.hxx"
      12             : #include "reffact.hxx"
      13             : #include "document.hxx"
      14             : #include "docfunc.hxx"
      15             : #include "scresid.hxx"
      16             : #include "globstr.hrc"
      17             : #include "namedlg.hxx"
      18             : #include "viewdata.hxx"
      19             : #include "globalnames.hxx"
      20             : 
      21             : #include "sfx2/app.hxx"
      22             : 
      23             : #define ITEMID_NAME 1
      24             : #define ITEMID_RANGE 2
      25             : #define ITEMID_SCOPE 3
      26             : 
      27             : #define MINSIZE 80
      28             : 
      29             : 
      30           0 : String createEntryString(const ScRangeNameLine& rLine)
      31             : {
      32           0 :     String aRet(rLine.aName);
      33           0 :     aRet += '\t';
      34           0 :     aRet += String(rLine.aExpression);
      35           0 :     aRet += '\t';
      36           0 :     aRet += String(rLine.aScope);
      37           0 :     return aRet;
      38             : }
      39             : 
      40           0 : ScRangeManagerTable::ScRangeManagerTable( SvxSimpleTableContainer& rParent, boost::ptr_map<OUString, ScRangeName>& rRangeMap, const ScAddress& rPos ):
      41             :     SvxSimpleTable( rParent, WB_SORT | WB_HSCROLL | WB_CLIPCHILDREN | WB_TABSTOP ),
      42           0 :     maGlobalString( ScGlobal::GetRscString(STR_GLOBAL_SCOPE)),
      43             :     mrRangeMap( rRangeMap ),
      44           0 :     maPos( rPos )
      45             : {
      46             :     static long aStaticTabs[] = {3, 0, 0, 0 };
      47           0 :     SetTabs( &aStaticTabs[0], MAP_PIXEL );
      48             : 
      49           0 :     OUString aNameStr(ScGlobal::GetRscString(STR_HEADER_NAME));
      50           0 :     OUString aRangeStr(ScGlobal::GetRscString(STR_HEADER_RANGE));
      51           0 :     OUString aScopeStr(ScGlobal::GetRscString(STR_HEADER_SCOPE));
      52             : 
      53           0 :     HeaderBar& rHeaderBar = GetTheHeaderBar();
      54           0 :     rHeaderBar.InsertItem( ITEMID_NAME, aNameStr, 0, HIB_LEFT| HIB_VCENTER );
      55           0 :     rHeaderBar.InsertItem( ITEMID_RANGE, aRangeStr, 0, HIB_LEFT| HIB_VCENTER );
      56           0 :     rHeaderBar.InsertItem( ITEMID_SCOPE, aScopeStr, 0, HIB_LEFT| HIB_VCENTER );
      57           0 :     rHeaderBar.SetEndDragHdl( LINK( this, ScRangeManagerTable, HeaderEndDragHdl ) );
      58             : 
      59           0 :     setColWidths();
      60           0 :     UpdateViewSize();
      61           0 :     Init();
      62           0 :     ShowTable();
      63           0 :     SetSelectionMode(MULTIPLE_SELECTION);
      64           0 :     if (GetEntryCount())
      65             :     {
      66           0 :         SetCurEntry(GetEntryOnPos(0));
      67           0 :         CheckForFormulaString();
      68             :     }
      69           0 :     SetScrolledHdl( LINK( this, ScRangeManagerTable, ScrollHdl ) );
      70           0 :     void* pNull = NULL;
      71           0 :     HeaderEndDragHdl(pNull);
      72           0 : }
      73             : 
      74           0 : void ScRangeManagerTable::Resize()
      75             : {
      76           0 :     SvxSimpleTable::Resize();
      77           0 :     if (isInitialLayout(this))
      78           0 :         setColWidths();
      79           0 : }
      80             : 
      81           0 : void ScRangeManagerTable::setColWidths()
      82             : {
      83           0 :     HeaderBar &rHeaderBar = GetTheHeaderBar();
      84           0 :     if (rHeaderBar.GetItemCount() < 3)
      85           0 :         return;
      86           0 :     long nTabSize = GetSizePixel().Width() / 3;
      87           0 :     rHeaderBar.SetItemSize( ITEMID_NAME, nTabSize);
      88           0 :     rHeaderBar.SetItemSize( ITEMID_RANGE, nTabSize);
      89           0 :     rHeaderBar.SetItemSize( ITEMID_SCOPE, nTabSize);
      90           0 :     static long aStaticTabs[] = {3, 0, nTabSize, 2*nTabSize };
      91           0 :     SetTabs( &aStaticTabs[0], MAP_PIXEL );
      92           0 :     void* pNull = NULL;
      93           0 :     HeaderEndDragHdl(pNull);
      94             : }
      95             : 
      96           0 : ScRangeManagerTable::~ScRangeManagerTable()
      97             : {
      98           0 :     Clear();
      99           0 : }
     100             : 
     101           0 : void ScRangeManagerTable::addEntry(const ScRangeNameLine& rLine, bool bSetCurEntry)
     102             : {
     103           0 :     SvTreeListEntry* pEntry = InsertEntryToColumn( createEntryString(rLine), LIST_APPEND, 0xffff);
     104           0 :     if (bSetCurEntry)
     105           0 :         SetCurEntry(pEntry);
     106           0 : }
     107             : 
     108           0 : void ScRangeManagerTable::GetCurrentLine(ScRangeNameLine& rLine)
     109             : {
     110           0 :     SvTreeListEntry* pCurrentEntry = GetCurEntry();
     111           0 :     GetLine(rLine, pCurrentEntry);
     112           0 : }
     113             : 
     114           0 : void ScRangeManagerTable::GetLine(ScRangeNameLine& rLine, SvTreeListEntry* pEntry)
     115             : {
     116           0 :     rLine.aName = GetEntryText( pEntry, 0);
     117           0 :     rLine.aExpression = GetEntryText(pEntry, 1);
     118           0 :     rLine.aScope = GetEntryText(pEntry, 2);
     119           0 : }
     120             : 
     121           0 : void ScRangeManagerTable::Init()
     122             : {
     123           0 :     SetUpdateMode(false);
     124           0 :     Clear();
     125           0 :     for (boost::ptr_map<OUString, ScRangeName>::const_iterator itr = mrRangeMap.begin();
     126           0 :             itr != mrRangeMap.end(); ++itr)
     127             :     {
     128           0 :         const ScRangeName* pLocalRangeName = itr->second;
     129           0 :         ScRangeNameLine aLine;
     130           0 :         if ( itr->first == STR_GLOBAL_RANGE_NAME )
     131           0 :             aLine.aScope = maGlobalString;
     132             :         else
     133           0 :             aLine.aScope = itr->first;
     134           0 :         for (ScRangeName::const_iterator it = pLocalRangeName->begin();
     135           0 :                 it != pLocalRangeName->end(); ++it)
     136             :         {
     137           0 :             if (!it->second->HasType(RT_DATABASE) && !it->second->HasType(RT_SHARED))
     138             :             {
     139           0 :                 aLine.aName = it->second->GetName();
     140           0 :                 addEntry(aLine, false);
     141             :             }
     142             :         }
     143           0 :     }
     144           0 :     SetUpdateMode(true);
     145           0 : }
     146             : 
     147           0 : const ScRangeData* ScRangeManagerTable::findRangeData(const ScRangeNameLine& rLine)
     148             : {
     149             :     const ScRangeName* pRangeName;
     150           0 :     if (rLine.aScope == maGlobalString)
     151           0 :         pRangeName = mrRangeMap.find(OUString(STR_GLOBAL_RANGE_NAME))->second;
     152             :     else
     153           0 :         pRangeName = mrRangeMap.find(rLine.aScope)->second;
     154             : 
     155           0 :     return pRangeName->findByUpperName(ScGlobal::pCharClass->uppercase(rLine.aName));
     156             : }
     157             : 
     158             : 
     159             : 
     160           0 : void ScRangeManagerTable::CheckForFormulaString()
     161             : {
     162           0 :     for (SvTreeListEntry* pEntry = GetFirstEntryInView(); pEntry ; pEntry = GetNextEntryInView(pEntry))
     163             :     {
     164           0 :         std::map<SvTreeListEntry*, bool>::const_iterator itr = maCalculatedFormulaEntries.find(pEntry);
     165           0 :         if (itr == maCalculatedFormulaEntries.end() || itr->second == false)
     166             :         {
     167           0 :             ScRangeNameLine aLine;
     168           0 :             GetLine( aLine, pEntry);
     169           0 :             const ScRangeData* pData = findRangeData( aLine );
     170           0 :             OUString aFormulaString;
     171           0 :             pData->GetSymbol(aFormulaString, maPos);
     172           0 :             SetEntryText(aFormulaString, pEntry, 1);
     173           0 :             maCalculatedFormulaEntries.insert( std::pair<SvTreeListEntry*, bool>(pEntry, true) );
     174             :         }
     175             : 
     176             :     }
     177           0 : }
     178             : 
     179           0 : void ScRangeManagerTable::DeleteSelectedEntries()
     180             : {
     181           0 :     if (GetSelectionCount())
     182           0 :         RemoveSelection();
     183           0 : }
     184             : 
     185           0 : bool ScRangeManagerTable::IsMultiSelection()
     186             : {
     187           0 :     return GetSelectionCount() > 1;
     188             : }
     189             : 
     190           0 : std::vector<ScRangeNameLine> ScRangeManagerTable::GetSelectedEntries()
     191             : {
     192           0 :     std::vector<ScRangeNameLine> aSelectedEntries;
     193           0 :     if (GetSelectionCount())
     194             :     {
     195           0 :         for (SvTreeListEntry* pEntry = FirstSelected(); pEntry != LastSelected(); pEntry = NextSelected(pEntry))
     196             :         {
     197           0 :             ScRangeNameLine aLine;
     198           0 :             GetLine( aLine, pEntry );
     199           0 :             aSelectedEntries.push_back(aLine);
     200           0 :         }
     201           0 :         SvTreeListEntry* pEntry = LastSelected();
     202           0 :         ScRangeNameLine aLine;
     203           0 :         GetLine( aLine, pEntry );
     204           0 :         aSelectedEntries.push_back(aLine);
     205             :     }
     206           0 :     return aSelectedEntries;
     207             : }
     208             : 
     209           0 : void ScRangeManagerTable::SetEntry(const ScRangeNameLine& rLine)
     210             : {
     211           0 :     for (SvTreeListEntry* pEntry = First(); pEntry; pEntry = Next(pEntry))
     212             :     {
     213           0 :         if (rLine.aName == OUString(GetEntryText(pEntry, 0))
     214           0 :                 && rLine.aScope == OUString(GetEntryText(pEntry, 2)))
     215             :         {
     216           0 :             SetCurEntry(pEntry);
     217             :         }
     218             :     }
     219           0 : }
     220             : 
     221             : namespace {
     222             : 
     223             : //ensure that the minimum column size is respected
     224           0 : void CalculateItemSize(const long& rTableSize, long& rItemNameSize, long& rItemRangeSize)
     225             : {
     226           0 :     long aItemScopeSize = rTableSize - rItemNameSize - rItemRangeSize;
     227             : 
     228           0 :     if (rItemNameSize >= MINSIZE && rItemRangeSize >= MINSIZE && aItemScopeSize >= MINSIZE)
     229           0 :         return;
     230             : 
     231           0 :     if (rItemNameSize < MINSIZE)
     232             :     {
     233           0 :         long aDiffSize = MINSIZE - rItemNameSize;
     234           0 :         if (rItemRangeSize > aItemScopeSize)
     235           0 :             rItemRangeSize -= aDiffSize;
     236             :         else
     237           0 :             aItemScopeSize -= aDiffSize;
     238           0 :         rItemNameSize = MINSIZE;
     239             :     }
     240             : 
     241           0 :     if (rItemRangeSize < MINSIZE)
     242             :     {
     243           0 :         long aDiffSize = MINSIZE - rItemRangeSize;
     244           0 :         if (rItemNameSize > aItemScopeSize)
     245           0 :             rItemNameSize -= aDiffSize;
     246             :         else
     247           0 :             aItemScopeSize -= aDiffSize;
     248           0 :         rItemRangeSize = MINSIZE;
     249             :     }
     250             : 
     251           0 :     if (aItemScopeSize < MINSIZE)
     252             :     {
     253           0 :         long aDiffSize = MINSIZE - aItemScopeSize;
     254           0 :         if (rItemNameSize > rItemRangeSize)
     255           0 :             rItemNameSize -= aDiffSize;
     256             :         else
     257           0 :             rItemRangeSize -= aDiffSize;
     258             :     }
     259             : }
     260             : 
     261             : }
     262             : 
     263           0 : IMPL_LINK_NOARG(ScRangeManagerTable, HeaderEndDragHdl)
     264             : {
     265           0 :     HeaderBar& rHeaderBar = GetTheHeaderBar();
     266             : 
     267           0 :     long nTableSize = rHeaderBar.GetSizePixel().Width();
     268           0 :     long nItemNameSize = rHeaderBar.GetItemSize(ITEMID_NAME);
     269           0 :     long nItemRangeSize = rHeaderBar.GetItemSize(ITEMID_RANGE);
     270             : 
     271             :     //calculate column size based on user input and minimum size
     272           0 :     CalculateItemSize(nTableSize, nItemNameSize, nItemRangeSize);
     273           0 :     long nItemScopeSize = nTableSize - nItemNameSize - nItemRangeSize;
     274             : 
     275           0 :     Size aSz(nItemNameSize, 0);
     276           0 :     rHeaderBar.SetItemSize(ITEMID_NAME, nItemNameSize);
     277           0 :     rHeaderBar.SetItemSize(ITEMID_RANGE, nItemRangeSize);
     278           0 :     rHeaderBar.SetItemSize(ITEMID_SCOPE, nItemScopeSize);
     279             : 
     280           0 :     SetTab(0, 0, MAP_APPFONT );
     281           0 :     SetTab(1, PixelToLogic( aSz, MapMode(MAP_APPFONT) ).Width(), MAP_APPFONT );
     282           0 :     aSz.Width() += nItemRangeSize;
     283           0 :     SetTab(2, PixelToLogic( aSz, MapMode(MAP_APPFONT) ).Width(), MAP_APPFONT );
     284             : 
     285           0 :     return 0;
     286             : }
     287             : 
     288           0 : IMPL_LINK_NOARG(ScRangeManagerTable, ScrollHdl)
     289             : {
     290           0 :     CheckForFormulaString();
     291           0 :     return 0;
     292          93 : }
     293             : 
     294             : 
     295             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10