LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sc/source/ui/view - tabvwsh5.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 75 173 43.4 %
Date: 2013-07-09 Functions: 3 5 60.0 %
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 "scitems.hxx"
      21             : #include <svl/smplhint.hxx>
      22             : #include <svl/zforlist.hxx>
      23             : #include <svx/numfmtsh.hxx>
      24             : #include <svx/numinf.hxx>
      25             : #include <svx/svxids.hrc>
      26             : #include <sfx2/dispatch.hxx>
      27             : #include <sfx2/objsh.hxx>
      28             : 
      29             : #include "tabvwsh.hxx"
      30             : #include "sc.hrc"
      31             : #include "global.hxx"
      32             : #include "docsh.hxx"
      33             : #include "document.hxx"
      34             : #include "formulacell.hxx"
      35             : #include "globstr.hrc"
      36             : #include "scmod.hxx"
      37             : #include "uiitems.hxx"
      38             : #include "editsh.hxx"
      39             : #include "hints.hxx"
      40             : #include "cellvalue.hxx"
      41             : 
      42             : //==================================================================
      43             : 
      44       36781 : void ScTabViewShell::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
      45             : {
      46       36781 :     if (rHint.ISA(SfxSimpleHint))                       // ohne Parameter
      47             :     {
      48       28916 :         sal_uLong nSlot = ((SfxSimpleHint&)rHint).GetId();
      49       28916 :         switch ( nSlot )
      50             :         {
      51             :             case FID_DATACHANGED:
      52        8261 :                 UpdateFormulas();
      53        8261 :                 break;
      54             : 
      55             :             case FID_REFMODECHANGED:
      56             :                 {
      57           0 :                     sal_Bool bRefMode = SC_MOD()->IsFormulaMode();
      58           0 :                     if (!bRefMode)
      59           0 :                         StopRefMode();
      60             :                     else
      61             :                     {
      62           0 :                         GetSelEngine()->Reset();
      63           0 :                         GetFunctionSet()->SetAnchorFlag(sal_True);
      64             :                         //  AnchorFlag, damit gleich mit Control angehaengt werden kann
      65             :                     }
      66             :                 }
      67           0 :                 break;
      68             : 
      69             :             case FID_KILLEDITVIEW:
      70             :             case FID_KILLEDITVIEW_NOPAINT:
      71        1408 :                 StopEditShell();
      72        1408 :                 KillEditView( nSlot == FID_KILLEDITVIEW_NOPAINT );
      73        1408 :                 break;
      74             : 
      75             :             case SFX_HINT_DOCCHANGED:
      76             :                 {
      77        8527 :                     ScDocument* pDoc = GetViewData()->GetDocument();
      78        8527 :                     if (!pDoc->HasTable( GetViewData()->GetTabNo() ))
      79             :                     {
      80           0 :                         SetTabNo(0);
      81             :                     }
      82             :                 }
      83        8527 :                 break;
      84             : 
      85             :             case SC_HINT_DRWLAYER_NEW:
      86         162 :                 MakeDrawView();
      87         162 :                 break;
      88             : 
      89             :             case SC_HINT_DOC_SAVED:
      90             :                 {
      91             :                     //  beim "Save as" kann ein vorher schreibgeschuetztes Dokument
      92             :                     //  bearbeitbar werden, deshalb die Layer-Locks neu (#39884#)
      93             :                     //  (Invalidate etc. passiert schon vom Sfx her)
      94             :                     //  bei SID_EDITDOC kommt kein SFX_HINT_TITLECHANGED, darum
      95             :                     //  der eigene Hint aus DoSaveCompleted
      96             :                     //! was ist mit SFX_HINT_SAVECOMPLETED ?
      97             : 
      98           5 :                     UpdateLayerLocks();
      99             : 
     100             :                     //  Design-Modus bei jedem Speichern anzupassen, waere zuviel
     101             :                     //  (beim Speichern unter gleichem Namen soll er unveraendert bleiben)
     102             :                     //  Darum nur bei SFX_HINT_MODECHANGED (vom ViewFrame)
     103             :                 }
     104           5 :                 break;
     105             : 
     106             :             case SFX_HINT_MODECHANGED:
     107             :                 //  Da man sich nicht mehr darauf verlassen kann, woher
     108             :                 //  dieser Hint kommt, den Design-Modus immer dann umschalten, wenn der
     109             :                 //  ReadOnly-Status sich wirklich geaendert hat:
     110             : 
     111           3 :                 if ( GetViewData()->GetSfxDocShell()->IsReadOnly() != bReadOnly )
     112             :                 {
     113           0 :                     bReadOnly = GetViewData()->GetSfxDocShell()->IsReadOnly();
     114             : 
     115           0 :                     SfxBoolItem aItem( SID_FM_DESIGN_MODE, !bReadOnly);
     116           0 :                     GetViewData()->GetDispatcher().Execute( SID_FM_DESIGN_MODE, SFX_CALLMODE_ASYNCHRON,
     117           0 :                                                 &aItem, 0L );
     118             : 
     119           0 :                     UpdateInputContext();
     120             :                 }
     121           3 :                 break;
     122             : 
     123             :             case SC_HINT_SHOWRANGEFINDER:
     124           0 :                 PaintRangeFinder();
     125           0 :                 break;
     126             : 
     127             :             case SC_HINT_FORCESETTAB:
     128           0 :                 SetTabNo( GetViewData()->GetTabNo(), sal_True );
     129           0 :                 break;
     130             : 
     131             :             default:
     132       10550 :                 break;
     133             :         }
     134             :     }
     135        7865 :     else if (rHint.ISA(ScPaintHint))                    // neu zeichnen
     136             :     {
     137        3709 :         ScPaintHint* pHint = (ScPaintHint*) &rHint;
     138        3709 :         sal_uInt16 nParts = pHint->GetParts();
     139        3709 :         SCTAB nTab = GetViewData()->GetTabNo();
     140        3709 :         if (pHint->GetStartTab() <= nTab && pHint->GetEndTab() >= nTab)
     141             :         {
     142        3569 :             if (nParts & PAINT_EXTRAS)          // zuerst, falls Tabelle weg ist !!!
     143          97 :                 if (PaintExtras())
     144           0 :                     nParts = PAINT_ALL;
     145             : 
     146             :             // if the current sheet has pending row height updates (sheet links refreshed),
     147             :             // execute them before invalidating the window
     148        3569 :             GetViewData()->GetDocShell()->UpdatePendingRowHeights( GetViewData()->GetTabNo() );
     149             : 
     150        3569 :             if (nParts & PAINT_SIZE)
     151          58 :                 RepeatResize();                     //! InvalidateBorder ???
     152        3569 :             if (nParts & PAINT_GRID)
     153        3483 :                 PaintArea( pHint->GetStartCol(), pHint->GetStartRow(),
     154        6966 :                            pHint->GetEndCol(), pHint->GetEndRow() );
     155        3569 :             if (nParts & PAINT_MARKS)
     156           0 :                 PaintArea( pHint->GetStartCol(), pHint->GetStartRow(),
     157           0 :                            pHint->GetEndCol(), pHint->GetEndRow(), SC_UPDATE_MARKS );
     158        3569 :             if (nParts & PAINT_LEFT)
     159         371 :                 PaintLeftArea( pHint->GetStartRow(), pHint->GetEndRow() );
     160        3569 :             if (nParts & PAINT_TOP)
     161          85 :                 PaintTopArea( pHint->GetStartCol(), pHint->GetEndCol() );
     162             : 
     163             :             // #i84689# call UpdateAllOverlays here instead of in ScTabView::PaintArea
     164        3569 :             if (nParts & ( PAINT_LEFT | PAINT_TOP ))    // only if widths or heights changed
     165         381 :                 UpdateAllOverlays();
     166             : 
     167        3569 :             HideNoteMarker();
     168             :         }
     169             :     }
     170        4156 :     else if (rHint.ISA(ScEditViewHint))                 // Edit-View anlegen
     171             :     {
     172             :         //  ScEditViewHint kommt nur an aktiver View an
     173             : 
     174           0 :         ScEditViewHint* pHint = (ScEditViewHint*) &rHint;
     175           0 :         SCTAB nTab = GetViewData()->GetTabNo();
     176           0 :         if ( pHint->GetTab() == nTab )
     177             :         {
     178           0 :             SCCOL nCol = pHint->GetCol();
     179           0 :             SCROW nRow = pHint->GetRow();
     180             :             {
     181           0 :                 HideNoteMarker();
     182             : 
     183           0 :                 MakeEditView( pHint->GetEngine(), nCol, nRow );
     184             : 
     185           0 :                 StopEditShell();                    // sollte nicht gesetzt sein
     186             : 
     187           0 :                 ScSplitPos eActive = GetViewData()->GetActivePart();
     188           0 :                 if ( GetViewData()->HasEditView(eActive) )
     189             :                 {
     190             :                     //  MakeEditView geht schief, wenn der Cursor ausserhalb des
     191             :                     //  Bildschirms steht. GetEditView gibt dann eine nicht aktive
     192             :                     //  View zurueck, darum die Abfrage HasEditView.
     193             : 
     194           0 :                     EditView* pView = GetViewData()->GetEditView(eActive);  // ist nicht 0
     195             : 
     196           0 :                     SetEditShell(pView ,sal_True);
     197             :                 }
     198             :             }
     199             :         }
     200             :     }
     201        4156 :     else if (rHint.ISA(ScTablesHint))               // Tabelle eingefuegt / geloescht
     202             :     {
     203             :             //  aktuelle Tabelle zuerst holen (kann bei DeleteTab an ViewData geaendert werden)
     204          56 :         SCTAB nActiveTab = GetViewData()->GetTabNo();
     205             : 
     206          56 :         const ScTablesHint& rTabHint = (const ScTablesHint&)rHint;
     207          56 :         SCTAB nTab1 = rTabHint.GetTab1();
     208          56 :         SCTAB nTab2 = rTabHint.GetTab2();
     209          56 :         sal_uInt16 nId  = rTabHint.GetId();
     210          56 :         switch (nId)
     211             :         {
     212             :             case SC_TAB_INSERTED:
     213          37 :                 GetViewData()->InsertTab( nTab1 );
     214          37 :                 break;
     215             :             case SC_TAB_DELETED:
     216          18 :                 GetViewData()->DeleteTab( nTab1 );
     217          18 :                 break;
     218             :             case SC_TAB_MOVED:
     219           0 :                 GetViewData()->MoveTab( nTab1, nTab2 );
     220           0 :                 break;
     221             :             case SC_TAB_COPIED:
     222           0 :                 GetViewData()->CopyTab( nTab1, nTab2 );
     223           0 :                 break;
     224             :             case SC_TAB_HIDDEN:
     225           1 :                 break;
     226             :             case SC_TABS_INSERTED:
     227           0 :                 GetViewData()->InsertTabs( nTab1, nTab2 );
     228           0 :                 break;
     229             :             case SC_TABS_DELETED:
     230           0 :                 GetViewData()->DeleteTabs( nTab1, nTab2 );
     231           0 :                 break;
     232             :             default:
     233             :                 OSL_FAIL("unbekannter ScTablesHint");
     234             :         }
     235             : 
     236             :         //  hier keine Abfrage auf IsActive() mehr, weil die Aktion von Basic ausgehen
     237             :         //  kann und dann auch die aktive View umgeschaltet werden muss.
     238             : 
     239          56 :         SCTAB nNewTab = nActiveTab;
     240          56 :         bool bStayOnActiveTab = true;
     241          56 :         switch (nId)
     242             :         {
     243             :             case SC_TAB_INSERTED:
     244          37 :                 if ( nTab1 <= nNewTab )             // vorher eingefuegt
     245          29 :                     ++nNewTab;
     246          37 :                 break;
     247             :             case SC_TAB_DELETED:
     248          18 :                 if ( nTab1 < nNewTab )              // vorher geloescht
     249           1 :                     --nNewTab;
     250          17 :                 else if ( nTab1 == nNewTab )        // aktuelle geloescht
     251          17 :                     bStayOnActiveTab = false;
     252          18 :                 break;
     253             :             case SC_TAB_MOVED:
     254           0 :                 if ( nNewTab == nTab1 )             // verschobene Tabelle
     255           0 :                     nNewTab = nTab2;
     256           0 :                 else if ( nTab1 < nTab2 )           // nach hinten verschoben
     257             :                 {
     258           0 :                     if ( nNewTab > nTab1 && nNewTab <= nTab2 )      // nachrueckender Bereich
     259           0 :                         --nNewTab;
     260             :                 }
     261             :                 else                                // nach vorne verschoben
     262             :                 {
     263           0 :                     if ( nNewTab >= nTab2 && nNewTab < nTab1 )      // nachrueckender Bereich
     264           0 :                         ++nNewTab;
     265             :                 }
     266           0 :                 break;
     267             :             case SC_TAB_COPIED:
     268           0 :                 if ( nNewTab >= nTab2 )             // vorher eingefuegt
     269           0 :                     ++nNewTab;
     270           0 :                 break;
     271             :             case SC_TAB_HIDDEN:
     272           1 :                 if ( nTab1 == nNewTab )             // aktuelle ausgeblendet
     273           1 :                     bStayOnActiveTab = false;
     274           1 :                 break;
     275             :             case SC_TABS_INSERTED:
     276           0 :                 if ( nTab1 <= nNewTab )
     277           0 :                     nNewTab += nTab2;
     278           0 :                 break;
     279             :             case SC_TABS_DELETED:
     280           0 :                 if ( nTab1 < nNewTab )
     281           0 :                     nNewTab -= nTab2;
     282           0 :                 break;
     283             :         }
     284             : 
     285          56 :         ScDocument* pDoc = GetViewData()->GetDocument();
     286          56 :         if ( nNewTab >= pDoc->GetTableCount() )
     287           0 :             nNewTab = pDoc->GetTableCount() - 1;
     288             : 
     289          56 :         sal_Bool bForce = !bStayOnActiveTab;
     290          56 :         SetTabNo( nNewTab, bForce, false, bStayOnActiveTab );
     291             :     }
     292        4100 :     else if (rHint.ISA(ScIndexHint))
     293             :     {
     294           0 :         const ScIndexHint& rIndexHint = (const ScIndexHint&)rHint;
     295           0 :         sal_uInt16 nId = rIndexHint.GetId();
     296           0 :         sal_uInt16 nIndex = rIndexHint.GetIndex();
     297           0 :         switch (nId)
     298             :         {
     299             :             case SC_HINT_SHOWRANGEFINDER:
     300           0 :                 PaintRangeFinder( nIndex );
     301           0 :                 break;
     302             :         }
     303             :     }
     304             : 
     305       36781 :     SfxViewShell::Notify( rBC, rHint );
     306       36781 : }
     307             : 
     308             : //------------------------------------------------------------------
     309             : 
     310           0 : void ScTabViewShell::MakeNumberInfoItem( ScDocument*         pDoc,
     311             :                                          ScViewData*         pViewData,
     312             :                                          SvxNumberInfoItem** ppItem )
     313             : {
     314             :     //------------------------------
     315             :     // NumberInfo-Item konstruieren:
     316             :     //------------------------------
     317           0 :     SvxNumberValueType  eValType        = SVX_VALUE_TYPE_UNDEFINED;
     318           0 :     double              nCellValue      = 0;
     319           0 :     OUString aCellString;
     320             : 
     321           0 :     ScRefCellValue aCell;
     322           0 :     aCell.assign(*pDoc, pViewData->GetCurPos());
     323             : 
     324           0 :     switch (aCell.meType)
     325             :     {
     326             :         case CELLTYPE_VALUE:
     327             :         {
     328           0 :             nCellValue = aCell.mfValue;
     329           0 :             eValType = SVX_VALUE_TYPE_NUMBER;
     330             :         }
     331           0 :         break;
     332             : 
     333             :         case CELLTYPE_STRING:
     334             :         {
     335           0 :             aCellString = *aCell.mpString;
     336           0 :             eValType = SVX_VALUE_TYPE_STRING;
     337             :         }
     338           0 :         break;
     339             : 
     340             :         case CELLTYPE_FORMULA:
     341             :         {
     342           0 :             if (aCell.mpFormula->IsValue())
     343             :             {
     344           0 :                 nCellValue = aCell.mpFormula->GetValue();
     345           0 :                 eValType = SVX_VALUE_TYPE_NUMBER;
     346             :             }
     347             :             else
     348             :             {
     349           0 :                 nCellValue = 0;
     350           0 :                 eValType   = SVX_VALUE_TYPE_UNDEFINED;
     351             :             }
     352             :         }
     353           0 :         break;
     354             : 
     355             :         default:
     356           0 :             nCellValue = 0;
     357           0 :             eValType   = SVX_VALUE_TYPE_UNDEFINED;
     358             :     }
     359             : 
     360           0 :     switch ( eValType )
     361             :     {
     362             :         case SVX_VALUE_TYPE_STRING:
     363             :             *ppItem = new SvxNumberInfoItem(
     364             :                                 pDoc->GetFormatTable(),
     365             :                                 aCellString,
     366           0 :                                 SID_ATTR_NUMBERFORMAT_INFO );
     367           0 :             break;
     368             : 
     369             :         case SVX_VALUE_TYPE_NUMBER:
     370             :             *ppItem = new SvxNumberInfoItem(
     371             :                                 pDoc->GetFormatTable(),
     372             :                                 nCellValue,
     373           0 :                                 SID_ATTR_NUMBERFORMAT_INFO );
     374           0 :             break;
     375             : 
     376             :         case SVX_VALUE_TYPE_UNDEFINED:
     377             :         default:
     378             :             *ppItem = new SvxNumberInfoItem(
     379             :                                 pDoc->GetFormatTable(),
     380             :                                 (const sal_uInt16)
     381           0 :                                 SID_ATTR_NUMBERFORMAT_INFO );
     382           0 :     }
     383           0 : }
     384             : 
     385             : //------------------------------------------------------------------
     386             : 
     387           0 : void ScTabViewShell::UpdateNumberFormatter(
     388             :                         const SvxNumberInfoItem& rInfoItem )
     389             : {
     390           0 :     const sal_uInt32 nDelCount = rInfoItem.GetDelCount();
     391             : 
     392           0 :     if ( nDelCount > 0 )
     393             :     {
     394           0 :         const sal_uInt32* pDelArr = rInfoItem.GetDelArray();
     395             : 
     396           0 :         for ( sal_uInt16 i=0; i<nDelCount; i++ )
     397           0 :             rInfoItem.GetNumberFormatter()->DeleteEntry( pDelArr[i] );
     398             :     }
     399          93 : }
     400             : 
     401             : 
     402             : 
     403             : 
     404             : 
     405             : 
     406             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10