LCOV - code coverage report
Current view: top level - sc/source/filter/excel - xeview.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 206 267 77.2 %
Date: 2014-11-03 Functions: 25 31 80.6 %
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 "xeview.hxx"
      21             : #include "document.hxx"
      22             : #include "scextopt.hxx"
      23             : #include "viewopti.hxx"
      24             : #include "xelink.hxx"
      25             : #include "xestyle.hxx"
      26             : 
      27             : using namespace ::oox;
      28             : 
      29             : // Workbook view settings records =============================================
      30             : 
      31          64 : XclExpWindow1::XclExpWindow1( const XclExpRoot& rRoot )
      32             :     : XclExpRecord(EXC_ID_WINDOW1, 18)
      33             :     , mnFlags(0)
      34          64 :     , mnTabBarSize(600)
      35             : {
      36          64 :     const ScViewOptions& rViewOpt = rRoot.GetDoc().GetViewOptions();
      37          64 :     ::set_flag( mnFlags, EXC_WIN1_HOR_SCROLLBAR,    rViewOpt.GetOption( VOPT_HSCROLL ) );
      38          64 :     ::set_flag( mnFlags, EXC_WIN1_VER_SCROLLBAR,    rViewOpt.GetOption( VOPT_VSCROLL ) );
      39          64 :     ::set_flag( mnFlags, EXC_WIN1_TABBAR,           rViewOpt.GetOption( VOPT_TABCONTROLS ) );
      40             : 
      41          64 :     double fTabBarWidth = rRoot.GetExtDocOptions().GetDocSettings().mfTabBarWidth;
      42          64 :     if( (0.0 <= fTabBarWidth) && (fTabBarWidth <= 1.0) )
      43          26 :         mnTabBarSize = static_cast< sal_uInt16 >( fTabBarWidth * 1000.0 + 0.5 );
      44          64 : }
      45             : 
      46          38 : void XclExpWindow1::SaveXml( XclExpXmlStream& rStrm )
      47             : {
      48          38 :     const XclExpTabInfo& rTabInfo = rStrm.GetRoot().GetTabInfo();
      49             : 
      50          38 :     rStrm.GetCurrentStream()->singleElement( XML_workbookView,
      51             :             // OOXTODO: XML_visibility, // ST_visibilty
      52             :             // OOXTODO: XML_minimized,  // bool
      53          38 :             XML_showHorizontalScroll,   XclXmlUtils::ToPsz( ::get_flag( mnFlags, EXC_WIN1_HOR_SCROLLBAR ) ),
      54          38 :             XML_showVerticalScroll,     XclXmlUtils::ToPsz( ::get_flag( mnFlags, EXC_WIN1_VER_SCROLLBAR ) ),
      55          38 :             XML_showSheetTabs,          XclXmlUtils::ToPsz( ::get_flag( mnFlags, EXC_WIN1_TABBAR ) ),
      56             :             XML_xWindow,                "0",
      57             :             XML_yWindow,                "0",
      58             :             XML_windowWidth,            OString::number( 0x4000 ).getStr(),
      59             :             XML_windowHeight,           OString::number( 0x2000 ).getStr(),
      60             :             XML_tabRatio,               OString::number( mnTabBarSize ).getStr(),
      61          38 :             XML_firstSheet,             OString::number( rTabInfo.GetFirstVisXclTab() ).getStr(),
      62          38 :             XML_activeTab,              OString::number( rTabInfo.GetDisplayedXclTab() ).getStr(),
      63             :             // OOXTODO: XML_autoFilterDateGrouping,     // bool; AUTOFILTER12? 87Eh
      64         228 :             FSEND );
      65          38 : }
      66             : 
      67          26 : void XclExpWindow1::WriteBody( XclExpStream& rStrm )
      68             : {
      69          26 :     const XclExpTabInfo& rTabInfo = rStrm.GetRoot().GetTabInfo();
      70             : 
      71          26 :     rStrm   << sal_uInt16( 0 )              // X position of the window
      72          26 :             << sal_uInt16( 0 )              // Y position of the window
      73          26 :             << sal_uInt16( 0x4000 )         // width of the window
      74          26 :             << sal_uInt16( 0x2000 )         // height of the window
      75          52 :             << mnFlags
      76          52 :             << rTabInfo.GetDisplayedXclTab()
      77          52 :             << rTabInfo.GetFirstVisXclTab()
      78          52 :             << rTabInfo.GetXclSelectedCount()
      79          52 :             << mnTabBarSize;
      80          26 : }
      81             : 
      82             : // Sheet view settings records ================================================
      83             : 
      84          50 : XclExpWindow2::XclExpWindow2( const XclExpRoot& rRoot,
      85             :         const XclTabViewData& rData, sal_uInt32 nGridColorId ) :
      86          50 :     XclExpRecord( EXC_ID_WINDOW2, (rRoot.GetBiff() == EXC_BIFF8) ? 18 : 10 ),
      87             :     maGridColor( rData.maGridColor ),
      88             :     mnGridColorId( nGridColorId ),
      89             :     mnFlags( 0 ),
      90             :     maFirstXclPos( rData.maFirstXclPos ),
      91             :     mnNormalZoom( rData.mnNormalZoom ),
      92          50 :     mnPageZoom( rData.mnPageZoom )
      93             : {
      94          50 :     ::set_flag( mnFlags, EXC_WIN2_SHOWFORMULAS,     rData.mbShowFormulas );
      95          50 :     ::set_flag( mnFlags, EXC_WIN2_SHOWGRID,         rData.mbShowGrid );
      96          50 :     ::set_flag( mnFlags, EXC_WIN2_SHOWHEADINGS,     rData.mbShowHeadings );
      97          50 :     ::set_flag( mnFlags, EXC_WIN2_FROZEN,           rData.mbFrozenPanes );
      98          50 :     ::set_flag( mnFlags, EXC_WIN2_SHOWZEROS,        rData.mbShowZeros );
      99          50 :     ::set_flag( mnFlags, EXC_WIN2_DEFGRIDCOLOR,     rData.mbDefGridColor );
     100          50 :     ::set_flag( mnFlags, EXC_WIN2_MIRRORED,         rData.mbMirrored );
     101          50 :     ::set_flag( mnFlags, EXC_WIN2_SHOWOUTLINE,      rData.mbShowOutline );
     102          50 :     ::set_flag( mnFlags, EXC_WIN2_FROZENNOSPLIT,    rData.mbFrozenPanes );
     103          50 :     ::set_flag( mnFlags, EXC_WIN2_SELECTED,         rData.mbSelected );
     104          50 :     ::set_flag( mnFlags, EXC_WIN2_DISPLAYED,        rData.mbDisplayed );
     105          50 :     ::set_flag( mnFlags, EXC_WIN2_PAGEBREAKMODE,    rData.mbPageMode );
     106          50 : }
     107             : 
     108          50 : void XclExpWindow2::WriteBody( XclExpStream& rStrm )
     109             : {
     110          50 :     const XclExpRoot& rRoot = rStrm.GetRoot();
     111             : 
     112          50 :     rStrm   << mnFlags
     113         100 :             << maFirstXclPos;
     114             : 
     115          50 :     switch( rRoot.GetBiff() )
     116             :     {
     117             :         case EXC_BIFF3:
     118             :         case EXC_BIFF4:
     119             :         case EXC_BIFF5:
     120           0 :             rStrm   << maGridColor;
     121           0 :         break;
     122             :         case EXC_BIFF8:
     123          50 :             rStrm   << rRoot.GetPalette().GetColorIndex( mnGridColorId )
     124          50 :                     << sal_uInt16( 0 )
     125         100 :                     << mnPageZoom
     126         100 :                     << mnNormalZoom
     127          50 :                     << sal_uInt32( 0 );
     128          50 :         break;
     129             :         default:    DBG_ERROR_BIFF();
     130             :     }
     131          50 : }
     132             : 
     133           0 : XclExpScl::XclExpScl( sal_uInt16 nZoom ) :
     134             :     XclExpRecord( EXC_ID_SCL, 4 ),
     135             :     mnNum( nZoom ),
     136           0 :     mnDenom( 100 )
     137             : {
     138           0 :     Shorten( 2 );
     139           0 :     Shorten( 5 );
     140           0 : }
     141             : 
     142           0 : void XclExpScl::Shorten( sal_uInt16 nFactor )
     143             : {
     144           0 :     while( (mnNum % nFactor == 0) && (mnDenom % nFactor == 0) )
     145             :     {
     146           0 :         mnNum = mnNum / nFactor;
     147           0 :         mnDenom = mnDenom / nFactor;
     148             :     }
     149           0 : }
     150             : 
     151           0 : void XclExpScl::WriteBody( XclExpStream& rStrm )
     152             : {
     153             :     OSL_ENSURE_BIFF( rStrm.GetRoot().GetBiff() >= EXC_BIFF4 );
     154           0 :     rStrm << mnNum << mnDenom;
     155           0 : }
     156             : 
     157           0 : XclExpPane::XclExpPane( const XclTabViewData& rData ) :
     158             :     XclExpRecord( EXC_ID_PANE, 10 ),
     159             :     mnSplitX( rData.mnSplitX ),
     160             :     mnSplitY( rData.mnSplitY ),
     161             :     maSecondXclPos( rData.maSecondXclPos ),
     162             :     mnActivePane( rData.mnActivePane ),
     163           0 :     mbFrozenPanes( rData.mbFrozenPanes )
     164             : {
     165             :     OSL_ENSURE( rData.IsSplit(), "XclExpPane::XclExpPane - no PANE record for unsplit view" );
     166           0 : }
     167             : 
     168          74 : static const char* lcl_GetActivePane( sal_uInt8 nActivePane )
     169             : {
     170          74 :     switch( nActivePane )
     171             :     {
     172          74 :         case EXC_PANE_TOPLEFT:      return "topLeft";       //break;
     173           0 :         case EXC_PANE_TOPRIGHT:     return "topRight";      //break;
     174           0 :         case EXC_PANE_BOTTOMLEFT:   return "bottomLeft";    //break;
     175           0 :         case EXC_PANE_BOTTOMRIGHT:  return "bottomRight";   //break;
     176             :     }
     177           0 :     return "**error: lcl_GetActivePane";
     178             : }
     179             : 
     180           0 : void XclExpPane::SaveXml( XclExpXmlStream& rStrm )
     181             : {
     182           0 :     rStrm.GetCurrentStream()->singleElement( XML_pane,
     183             :             XML_xSplit,         OString::number( mnSplitX ).getStr(),
     184             :             XML_ySplit,         OString::number( mnSplitY ).getStr(),
     185             :             XML_topLeftCell,    XclXmlUtils::ToOString( maSecondXclPos ).getStr(),
     186             :             XML_activePane,     lcl_GetActivePane( mnActivePane ),
     187             :             XML_state,          mbFrozenPanes ? "frozen" : "split",
     188           0 :             FSEND );
     189           0 : }
     190             : 
     191           0 : void XclExpPane::WriteBody( XclExpStream& rStrm )
     192             : {
     193           0 :     rStrm   << mnSplitX
     194           0 :             << static_cast<sal_uInt16>( mnSplitY )
     195           0 :             << maSecondXclPos
     196           0 :             << mnActivePane;
     197           0 :     if( rStrm.GetRoot().GetBiff() >= EXC_BIFF5 )
     198           0 :         rStrm << sal_uInt8( 0 );
     199           0 : }
     200             : 
     201         124 : XclExpSelection::XclExpSelection( const XclTabViewData& rData, sal_uInt8 nPane ) :
     202             :     XclExpRecord( EXC_ID_SELECTION, 15 ),
     203         124 :     mnPane( nPane )
     204             : {
     205         124 :     if( const XclSelectionData* pSelData = rData.GetSelectionData( nPane ) )
     206          42 :         maSelData = *pSelData;
     207             : 
     208             :     // find the cursor position in the selection list (or add it)
     209         124 :     XclRangeList& rXclSel = maSelData.maXclSelection;
     210         124 :     bool bFound = false;
     211         150 :     for( XclRangeVector::const_iterator aIt = rXclSel.begin(), aEnd = rXclSel.end(); !bFound && (aIt != aEnd); ++aIt )
     212          26 :         if( (bFound = aIt->Contains( maSelData.maXclCursor )) == true )
     213          26 :             maSelData.mnCursorIdx = static_cast< sal_uInt16 >( aIt - rXclSel.begin() );
     214             :     /*  Cursor cell not found in list? (e.g. inactive pane, or removed in
     215             :         ConvertRangeList(), because Calc cursor on invalid pos)
     216             :         -> insert the valid Excel cursor. */
     217         124 :     if( !bFound )
     218             :     {
     219          98 :         maSelData.mnCursorIdx = static_cast< sal_uInt16 >( rXclSel.size() );
     220          98 :         rXclSel.push_back( XclRange( maSelData.maXclCursor ) );
     221             :     }
     222         124 : }
     223             : 
     224          74 : void XclExpSelection::SaveXml( XclExpXmlStream& rStrm )
     225             : {
     226          74 :     rStrm.GetCurrentStream()->singleElement( XML_selection,
     227             :             XML_pane,           lcl_GetActivePane( mnPane ),
     228             :             XML_activeCell,     XclXmlUtils::ToOString( maSelData.maXclCursor ).getStr(),
     229             :             XML_activeCellId,   OString::number(  maSelData.mnCursorIdx ).getStr(),
     230             :             XML_sqref,          XclXmlUtils::ToOString( maSelData.maXclSelection ).getStr(),
     231         148 :             FSEND );
     232          74 : }
     233             : 
     234          50 : void XclExpSelection::WriteBody( XclExpStream& rStrm )
     235             : {
     236          50 :     rStrm   << mnPane                   // pane for this selection
     237         100 :             << maSelData.maXclCursor    // cell cursor
     238         100 :             << maSelData.mnCursorIdx;   // index to range containing cursor
     239          50 :     maSelData.maXclSelection.Write( rStrm, false );
     240          50 : }
     241             : 
     242           4 : XclExpTabBgColor::XclExpTabBgColor( const XclTabViewData& rTabViewData ) :
     243             :     XclExpRecord( EXC_ID_SHEETEXT, 18 ),
     244           4 :     mrTabViewData( rTabViewData )
     245             : {
     246           4 : }
     247             : //TODO Fix savexml...
     248             : /*void XclExpTabBgColor::SaveXml( XclExpXmlStream& rStrm )
     249             : {
     250             : }*/
     251             : 
     252           4 : void XclExpTabBgColor::WriteBody( XclExpStream& rStrm )
     253             : {
     254           4 :     if ( mrTabViewData.IsDefaultTabBgColor() )
     255           4 :         return;
     256           4 :     sal_uInt16 rt = 0x0862; //rt
     257           4 :     sal_uInt16 grbitFrt = 0x0000; //grbit must be set to 0
     258           4 :     sal_uInt32 unused = 0x00000000; //Use twice...
     259           4 :     sal_uInt32 cb = 0x00000014; // Record Size, may be larger in future...
     260           4 :     sal_uInt16 reserved = 0x0000; //trailing bits are 0
     261             :     sal_uInt16 TabBgColorIndex;
     262           4 :     XclExpPalette& rPal = rStrm.GetRoot().GetPalette();
     263           4 :     TabBgColorIndex = rPal.GetColorIndex(mrTabViewData.mnTabBgColorId);
     264           4 :     if (TabBgColorIndex < 8 || TabBgColorIndex > 63 ) // only numbers 8 - 63 are valid numbers
     265           0 :         TabBgColorIndex = 127; //Excel specs: 127 makes excel ignore tab color information.
     266           4 :     rStrm << rt << grbitFrt << unused << unused << cb << TabBgColorIndex << reserved;
     267             : }
     268             : 
     269             : // Sheet view settings ========================================================
     270             : 
     271             : namespace {
     272             : 
     273             : /** Converts a Calc zoom factor into an Excel zoom factor. Returns 0 for a default zoom value. */
     274          84 : sal_uInt16 lclGetXclZoom( long nScZoom, sal_uInt16 nDefXclZoom )
     275             : {
     276          84 :     sal_uInt16 nXclZoom = limit_cast< sal_uInt16 >( nScZoom, EXC_ZOOM_MIN, EXC_ZOOM_MAX );
     277          84 :     return (nXclZoom == nDefXclZoom) ? 0 : nXclZoom;
     278             : }
     279             : 
     280             : } // namespace
     281             : 
     282         124 : XclExpTabViewSettings::XclExpTabViewSettings( const XclExpRoot& rRoot, SCTAB nScTab ) :
     283             :     XclExpRoot( rRoot ),
     284         124 :     mnGridColorId( XclExpPalette::GetColorIdFromIndex( EXC_COLOR_WINDOWTEXT ) )
     285             : {
     286             :     // *** sheet flags ***
     287             : 
     288         124 :     const XclExpTabInfo& rTabInfo = GetTabInfo();
     289         124 :     maData.mbSelected       = rTabInfo.IsSelectedTab( nScTab );
     290         124 :     maData.mbDisplayed      = rTabInfo.IsDisplayedTab( nScTab );
     291         124 :     maData.mbMirrored       = rTabInfo.IsMirroredTab( nScTab );
     292             : 
     293         124 :     const ScViewOptions& rViewOpt = GetDoc().GetViewOptions();
     294         124 :     maData.mbShowFormulas   = rViewOpt.GetOption( VOPT_FORMULAS );
     295         124 :     maData.mbShowHeadings   = rViewOpt.GetOption( VOPT_HEADER );
     296         124 :     maData.mbShowZeros      = rViewOpt.GetOption( VOPT_NULLVALS );
     297         124 :     maData.mbShowOutline    = rViewOpt.GetOption( VOPT_OUTLINER );
     298             : 
     299             :     // *** sheet options: cursor, selection, splits, grid color, zoom ***
     300             : 
     301         124 :     if( const ScExtTabSettings* pTabSett = GetExtDocOptions().GetTabSettings( nScTab ) )
     302             :     {
     303          42 :         const ScExtTabSettings& rTabSett = *pTabSett;
     304          42 :         XclExpAddressConverter& rAddrConv = GetAddressConverter();
     305             : 
     306             :         // first visible cell in top-left pane
     307          42 :         if( (rTabSett.maFirstVis.Col() >= 0) && (rTabSett.maFirstVis.Row() >= 0) )
     308          42 :             maData.maFirstXclPos = rAddrConv.CreateValidAddress( rTabSett.maFirstVis, false );
     309             : 
     310             :         // first visible cell in additional pane(s)
     311          42 :         if( (rTabSett.maSecondVis.Col() >= 0) && (rTabSett.maSecondVis.Row() >= 0) )
     312          42 :             maData.maSecondXclPos = rAddrConv.CreateValidAddress( rTabSett.maSecondVis, false );
     313             : 
     314             :         // active pane
     315          42 :         switch( rTabSett.meActivePane )
     316             :         {
     317          42 :             case SCEXT_PANE_TOPLEFT:        maData.mnActivePane = EXC_PANE_TOPLEFT;     break;
     318           0 :             case SCEXT_PANE_TOPRIGHT:       maData.mnActivePane = EXC_PANE_TOPRIGHT;    break;
     319           0 :             case SCEXT_PANE_BOTTOMLEFT:     maData.mnActivePane = EXC_PANE_BOTTOMLEFT;  break;
     320           0 :             case SCEXT_PANE_BOTTOMRIGHT:    maData.mnActivePane = EXC_PANE_BOTTOMRIGHT; break;
     321             :         }
     322             : 
     323             :         // freeze/split position
     324          42 :         maData.mbFrozenPanes = rTabSett.mbFrozenPanes;
     325          42 :         if( maData.mbFrozenPanes )
     326             :         {
     327             :             /*  Frozen panes: handle split position as row/column positions.
     328             :                 #i35812# Excel uses number of visible rows/columns, Calc uses position of freeze. */
     329           0 :             SCCOL nFreezeScCol = rTabSett.maFreezePos.Col();
     330           0 :             if( (0 < nFreezeScCol) && (nFreezeScCol <= GetXclMaxPos().Col()) )
     331           0 :                 maData.mnSplitX = static_cast< sal_uInt16 >( nFreezeScCol ) - maData.maFirstXclPos.mnCol;
     332           0 :             SCROW nFreezeScRow = rTabSett.maFreezePos.Row();
     333           0 :             if( (0 < nFreezeScRow) && (nFreezeScRow <= GetXclMaxPos().Row()) )
     334           0 :                 maData.mnSplitY = static_cast< sal_uInt32 >( nFreezeScRow ) - maData.maFirstXclPos.mnRow;
     335             :             // if both splits are left out (address overflow), remove the frozen flag
     336           0 :             maData.mbFrozenPanes = maData.IsSplit();
     337             : 
     338             :             // #i20671# frozen panes: mostright/mostbottom pane is active regardless of cursor position
     339           0 :             if( maData.HasPane( EXC_PANE_BOTTOMRIGHT ) )
     340           0 :                 maData.mnActivePane = EXC_PANE_BOTTOMRIGHT;
     341           0 :             else if( maData.HasPane( EXC_PANE_TOPRIGHT ) )
     342           0 :                 maData.mnActivePane = EXC_PANE_TOPRIGHT;
     343           0 :             else if( maData.HasPane( EXC_PANE_BOTTOMLEFT ) )
     344           0 :                 maData.mnActivePane = EXC_PANE_BOTTOMLEFT;
     345             :         }
     346             :         else
     347             :         {
     348             :             // split window: position is in twips
     349          42 :             maData.mnSplitX = static_cast<sal_uInt16>(rTabSett.maSplitPos.X());
     350          42 :             maData.mnSplitY = static_cast<sal_uInt32>(rTabSett.maSplitPos.Y());
     351             :         }
     352             : 
     353             :         // selection
     354          42 :         CreateSelectionData( EXC_PANE_TOPLEFT,     rTabSett.maCursor, rTabSett.maSelection );
     355          42 :         CreateSelectionData( EXC_PANE_TOPRIGHT,    rTabSett.maCursor, rTabSett.maSelection );
     356          42 :         CreateSelectionData( EXC_PANE_BOTTOMLEFT,  rTabSett.maCursor, rTabSett.maSelection );
     357          42 :         CreateSelectionData( EXC_PANE_BOTTOMRIGHT, rTabSett.maCursor, rTabSett.maSelection );
     358             : 
     359             :         // grid color
     360          42 :         const Color& rGridColor = rTabSett.maGridColor;
     361          42 :         maData.mbDefGridColor = rGridColor.GetColor() == COL_AUTO;
     362          42 :         if( !maData.mbDefGridColor )
     363             :         {
     364           0 :             if( GetBiff() == EXC_BIFF8 )
     365           0 :                 mnGridColorId = GetPalette().InsertColor( rGridColor, EXC_COLOR_GRID );
     366             :             else
     367           0 :                 maData.maGridColor = rGridColor;
     368             :         }
     369          42 :         maData.mbShowGrid       = rTabSett.mbShowGrid;
     370             : 
     371             :         // view mode and zoom
     372          42 :         maData.mbPageMode       = (GetBiff() == EXC_BIFF8) && rTabSett.mbPageMode;
     373          42 :         maData.mnNormalZoom     = lclGetXclZoom( rTabSett.mnNormalZoom, EXC_WIN2_NORMALZOOM_DEF );
     374          42 :         maData.mnPageZoom       = lclGetXclZoom( rTabSett.mnPageZoom, EXC_WIN2_PAGEZOOM_DEF );
     375          42 :         maData.mnCurrentZoom    = maData.mbPageMode ? maData.mnPageZoom : maData.mnNormalZoom;
     376             :     }
     377             : 
     378             :     // Tab Bg Color
     379         124 :     if ( GetBiff() == EXC_BIFF8 && !GetDoc().IsDefaultTabBgColor(nScTab) )
     380             :     {
     381          16 :         XclExpPalette& rPal = GetPalette();
     382          16 :         maData.maTabBgColor = GetDoc().GetTabBgColor(nScTab);
     383          16 :         maData.mnTabBgColorId = rPal.InsertColor(maData.maTabBgColor, EXC_COLOR_TABBG, EXC_COLOR_NOTABBG );
     384             :     }
     385         124 : }
     386             : 
     387          50 : void XclExpTabViewSettings::Save( XclExpStream& rStrm )
     388             : {
     389          50 :     WriteWindow2( rStrm );
     390          50 :     WriteScl( rStrm );
     391          50 :     WritePane( rStrm );
     392          50 :     WriteSelection( rStrm, EXC_PANE_TOPLEFT );
     393          50 :     WriteSelection( rStrm, EXC_PANE_TOPRIGHT );
     394          50 :     WriteSelection( rStrm, EXC_PANE_BOTTOMLEFT );
     395          50 :     WriteSelection( rStrm, EXC_PANE_BOTTOMRIGHT );
     396          50 :     WriteTabBgColor( rStrm );
     397          50 : }
     398             : 
     399         296 : static void lcl_WriteSelection( XclExpXmlStream& rStrm, const XclTabViewData& rData, sal_uInt8 nPane )
     400             : {
     401         296 :     if( rData.HasPane( nPane ) )
     402          74 :         XclExpSelection( rData, nPane ).SaveXml( rStrm );
     403         296 : }
     404             : 
     405         222 : static OString lcl_GetZoom( sal_uInt16 nZoom )
     406             : {
     407         222 :     if( nZoom )
     408         124 :         return OString::number( nZoom );
     409          98 :     return OString( "100" );
     410             : }
     411             : 
     412          74 : void XclExpTabViewSettings::SaveXml( XclExpXmlStream& rStrm )
     413             : {
     414          74 :     sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
     415          74 :     rWorksheet->startElement( XML_sheetViews, FSEND );
     416             :     rWorksheet->startElement( XML_sheetView,
     417             :             XML_windowProtection,           XclXmlUtils::ToPsz( maData.mbFrozenPanes ),
     418             :             XML_showFormulas,               XclXmlUtils::ToPsz( maData.mbShowFormulas ),
     419             :             XML_showGridLines,              XclXmlUtils::ToPsz( maData.mbShowGrid ),
     420             :             XML_showRowColHeaders,          XclXmlUtils::ToPsz( maData.mbShowHeadings ),
     421             :             XML_showZeros,                  XclXmlUtils::ToPsz( maData.mbShowZeros ),
     422             :             XML_rightToLeft,                XclXmlUtils::ToPsz( maData.mbMirrored ),
     423             :             XML_tabSelected,                XclXmlUtils::ToPsz( maData.mbSelected ),
     424             :             // OOXTODO: XML_showRuler,
     425             :             XML_showOutlineSymbols,         XclXmlUtils::ToPsz( maData.mbShowOutline ),
     426          74 :             XML_defaultGridColor,           mnGridColorId == XclExpPalette::GetColorIdFromIndex( EXC_COLOR_WINDOWTEXT ) ? "true" : "false",
     427             :             // OOXTODO: XML_showWhiteSpace,
     428             :             XML_view,                       maData.mbPageMode ? "pageBreakPreview" : "normal",  // OOXTODO: pageLayout
     429             :             XML_topLeftCell,                XclXmlUtils::ToOString( maData.maFirstXclPos ).getStr(),
     430          74 :             XML_colorId,                    OString::number(  rStrm.GetRoot().GetPalette().GetColorIndex( mnGridColorId ) ).getStr(),
     431             :             XML_zoomScale,                  lcl_GetZoom( maData.mnCurrentZoom ).getStr(),
     432             :             XML_zoomScaleNormal,            lcl_GetZoom( maData.mnNormalZoom ).getStr(),
     433             :             // OOXTODO: XML_zoomScaleSheetLayoutView,
     434             :             XML_zoomScalePageLayoutView,    lcl_GetZoom( maData.mnPageZoom ).getStr(),
     435             :             XML_workbookViewId,             "0",    // OOXTODO? 0-based index of document(xl/workbook.xml)/workbook/bookviews/workbookView
     436             :                                                     //          should always be 0, as we only generate 1 such element.
     437         222 :             FSEND );
     438          74 :     if( maData.IsSplit() )
     439             :     {
     440           0 :         XclExpPane aPane( maData );
     441           0 :         aPane.SaveXml( rStrm );
     442             :     }
     443          74 :     lcl_WriteSelection( rStrm, maData, EXC_PANE_TOPLEFT );
     444          74 :     lcl_WriteSelection( rStrm, maData, EXC_PANE_TOPRIGHT );
     445          74 :     lcl_WriteSelection( rStrm, maData, EXC_PANE_BOTTOMLEFT );
     446          74 :     lcl_WriteSelection( rStrm, maData, EXC_PANE_BOTTOMRIGHT );
     447          74 :     rWorksheet->endElement( XML_sheetView );
     448             :     // OOXTODO: XML_extLst
     449          74 :     rWorksheet->endElement( XML_sheetViews );
     450          74 : }
     451             : 
     452             : // private --------------------------------------------------------------------
     453             : 
     454         168 : void XclExpTabViewSettings::CreateSelectionData( sal_uInt8 nPane,
     455             :         const ScAddress& rCursor, const ScRangeList& rSelection )
     456             : {
     457         168 :     if( maData.HasPane( nPane ) )
     458             :     {
     459          42 :         XclSelectionData& rSelData = maData.CreateSelectionData( nPane );
     460             : 
     461             :         // first step: use top-left visible cell as cursor
     462           0 :         rSelData.maXclCursor.mnCol = ((nPane == EXC_PANE_TOPLEFT) || (nPane == EXC_PANE_BOTTOMLEFT)) ?
     463          84 :             maData.maFirstXclPos.mnCol : maData.maSecondXclPos.mnCol;
     464           0 :         rSelData.maXclCursor.mnRow = ((nPane == EXC_PANE_TOPLEFT) || (nPane == EXC_PANE_TOPRIGHT)) ?
     465          84 :             maData.maFirstXclPos.mnRow : maData.maSecondXclPos.mnRow;
     466             : 
     467             :         // second step, active pane: create actual selection data with current cursor position
     468          42 :         if( nPane == maData.mnActivePane )
     469             :         {
     470          42 :             XclExpAddressConverter& rAddrConv = GetAddressConverter();
     471             :             // cursor position (keep top-left pane position from above, if rCursor is invalid)
     472          42 :             if( (rCursor.Col() >= 0) && (rCursor.Row() >= 0) )
     473          42 :                 rSelData.maXclCursor = rAddrConv.CreateValidAddress( rCursor, false );
     474             :             // selection
     475          42 :             rAddrConv.ConvertRangeList( rSelData.maXclSelection, rSelection, false );
     476             :         }
     477             :     }
     478         168 : }
     479             : 
     480          50 : void XclExpTabViewSettings::WriteWindow2( XclExpStream& rStrm ) const
     481             : {
     482             : //  #i43553# GCC 3.3 parse error
     483             : //    XclExpWindow2( GetRoot(), maData, mnGridColorId ).Save( rStrm );
     484          50 :     XclExpWindow2 aWindow2( GetRoot(), maData, mnGridColorId );
     485          50 :     aWindow2.Save( rStrm );
     486          50 : }
     487             : 
     488          50 : void XclExpTabViewSettings::WriteScl( XclExpStream& rStrm ) const
     489             : {
     490          50 :     if( maData.mnCurrentZoom != 0 )
     491           0 :         XclExpScl( maData.mnCurrentZoom ).Save( rStrm );
     492          50 : }
     493             : 
     494          50 : void XclExpTabViewSettings::WritePane( XclExpStream& rStrm ) const
     495             : {
     496          50 :     if( maData.IsSplit() )
     497             : //  #i43553# GCC 3.3 parse error
     498             : //        XclExpPane( GetRoot(), maData ).Save( rStrm );
     499             :     {
     500           0 :         XclExpPane aPane( maData );
     501           0 :         aPane.Save( rStrm );
     502             :     }
     503          50 : }
     504             : 
     505         200 : void XclExpTabViewSettings::WriteSelection( XclExpStream& rStrm, sal_uInt8 nPane ) const
     506             : {
     507         200 :     if( maData.HasPane( nPane ) )
     508          50 :         XclExpSelection( maData, nPane ).Save( rStrm );
     509         200 : }
     510             : 
     511          50 : void XclExpTabViewSettings::WriteTabBgColor( XclExpStream& rStrm ) const
     512             : {
     513          50 :     if ( !maData.IsDefaultTabBgColor() )
     514           4 :         XclExpTabBgColor( maData ).Save( rStrm );
     515          98 : }
     516             : 
     517             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10