LCOV - code coverage report
Current view: top level - sc/source/filter/excel - xeview.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 208 270 77.0 %
Date: 2015-06-13 12:38:46 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          72 : XclExpWindow1::XclExpWindow1( const XclExpRoot& rRoot )
      32             :     : XclExpRecord(EXC_ID_WINDOW1, 18)
      33             :     , mnFlags(0)
      34          72 :     , mnTabBarSize(600)
      35             : {
      36          72 :     const ScViewOptions& rViewOpt = rRoot.GetDoc().GetViewOptions();
      37          72 :     ::set_flag( mnFlags, EXC_WIN1_HOR_SCROLLBAR,    rViewOpt.GetOption( VOPT_HSCROLL ) );
      38          72 :     ::set_flag( mnFlags, EXC_WIN1_VER_SCROLLBAR,    rViewOpt.GetOption( VOPT_VSCROLL ) );
      39          72 :     ::set_flag( mnFlags, EXC_WIN1_TABBAR,           rViewOpt.GetOption( VOPT_TABCONTROLS ) );
      40             : 
      41          72 :     double fTabBarWidth = rRoot.GetExtDocOptions().GetDocSettings().mfTabBarWidth;
      42          72 :     if( (0.0 <= fTabBarWidth) && (fTabBarWidth <= 1.0) )
      43          32 :         mnTabBarSize = static_cast< sal_uInt16 >( fTabBarWidth * 1000.0 + 0.5 );
      44          72 : }
      45             : 
      46          55 : void XclExpWindow1::SaveXml( XclExpXmlStream& rStrm )
      47             : {
      48          55 :     const XclExpTabInfo& rTabInfo = rStrm.GetRoot().GetTabInfo();
      49             : 
      50          55 :     rStrm.GetCurrentStream()->singleElement( XML_workbookView,
      51             :             // OOXTODO: XML_visibility, // ST_visibilty
      52             :             // OOXTODO: XML_minimized,  // bool
      53          55 :             XML_showHorizontalScroll,   XclXmlUtils::ToPsz( ::get_flag( mnFlags, EXC_WIN1_HOR_SCROLLBAR ) ),
      54          55 :             XML_showVerticalScroll,     XclXmlUtils::ToPsz( ::get_flag( mnFlags, EXC_WIN1_VER_SCROLLBAR ) ),
      55          55 :             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          55 :             XML_firstSheet,             OString::number( rTabInfo.GetFirstVisXclTab() ).getStr(),
      62          55 :             XML_activeTab,              OString::number( rTabInfo.GetDisplayedXclTab() ).getStr(),
      63             :             // OOXTODO: XML_autoFilterDateGrouping,     // bool; AUTOFILTER12? 87Eh
      64         330 :             FSEND );
      65          55 : }
      66             : 
      67          17 : void XclExpWindow1::WriteBody( XclExpStream& rStrm )
      68             : {
      69          17 :     const XclExpTabInfo& rTabInfo = rStrm.GetRoot().GetTabInfo();
      70             : 
      71          17 :     rStrm   << sal_uInt16( 0 )              // X position of the window
      72          17 :             << sal_uInt16( 0 )              // Y position of the window
      73          17 :             << sal_uInt16( 0x4000 )         // width of the window
      74          17 :             << sal_uInt16( 0x2000 )         // height of the window
      75          34 :             << mnFlags
      76          34 :             << rTabInfo.GetDisplayedXclTab()
      77          34 :             << rTabInfo.GetFirstVisXclTab()
      78          34 :             << rTabInfo.GetXclSelectedCount()
      79          34 :             << mnTabBarSize;
      80          17 : }
      81             : 
      82             : // Sheet view settings records ================================================
      83             : 
      84          29 : XclExpWindow2::XclExpWindow2( const XclExpRoot& rRoot,
      85             :         const XclTabViewData& rData, sal_uInt32 nGridColorId ) :
      86          29 :     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          29 :     mnPageZoom( rData.mnPageZoom )
      93             : {
      94          29 :     ::set_flag( mnFlags, EXC_WIN2_SHOWFORMULAS,     rData.mbShowFormulas );
      95          29 :     ::set_flag( mnFlags, EXC_WIN2_SHOWGRID,         rData.mbShowGrid );
      96          29 :     ::set_flag( mnFlags, EXC_WIN2_SHOWHEADINGS,     rData.mbShowHeadings );
      97          29 :     ::set_flag( mnFlags, EXC_WIN2_FROZEN,           rData.mbFrozenPanes );
      98          29 :     ::set_flag( mnFlags, EXC_WIN2_SHOWZEROS,        rData.mbShowZeros );
      99          29 :     ::set_flag( mnFlags, EXC_WIN2_DEFGRIDCOLOR,     rData.mbDefGridColor );
     100          29 :     ::set_flag( mnFlags, EXC_WIN2_MIRRORED,         rData.mbMirrored );
     101          29 :     ::set_flag( mnFlags, EXC_WIN2_SHOWOUTLINE,      rData.mbShowOutline );
     102          29 :     ::set_flag( mnFlags, EXC_WIN2_FROZENNOSPLIT,    rData.mbFrozenPanes );
     103          29 :     ::set_flag( mnFlags, EXC_WIN2_SELECTED,         rData.mbSelected );
     104          29 :     ::set_flag( mnFlags, EXC_WIN2_DISPLAYED,        rData.mbDisplayed );
     105          29 :     ::set_flag( mnFlags, EXC_WIN2_PAGEBREAKMODE,    rData.mbPageMode );
     106          29 : }
     107             : 
     108          29 : void XclExpWindow2::WriteBody( XclExpStream& rStrm )
     109             : {
     110          29 :     const XclExpRoot& rRoot = rStrm.GetRoot();
     111             : 
     112          29 :     rStrm   << mnFlags
     113          58 :             << maFirstXclPos;
     114             : 
     115          29 :     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          29 :             rStrm   << rRoot.GetPalette().GetColorIndex( mnGridColorId )
     124          29 :                     << sal_uInt16( 0 )
     125          58 :                     << mnPageZoom
     126          58 :                     << mnNormalZoom
     127          29 :                     << sal_uInt32( 0 );
     128          29 :         break;
     129             :         default:    DBG_ERROR_BIFF();
     130             :     }
     131          29 : }
     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         100 : static const char* lcl_GetActivePane( sal_uInt8 nActivePane )
     169             : {
     170         100 :     switch( nActivePane )
     171             :     {
     172         100 :         case EXC_PANE_TOPLEFT:      return "topLeft";
     173           0 :         case EXC_PANE_TOPRIGHT:     return "topRight";
     174           0 :         case EXC_PANE_BOTTOMLEFT:   return "bottomLeft";
     175           0 :         case EXC_PANE_BOTTOMRIGHT:  return "bottomRight";
     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           0 :             XML_topLeftCell,    XclXmlUtils::ToOString( rStrm.GetRoot().GetStringBuf(), 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         129 : XclExpSelection::XclExpSelection( const XclTabViewData& rData, sal_uInt8 nPane ) :
     202             :     XclExpRecord( EXC_ID_SELECTION, 15 ),
     203         129 :     mnPane( nPane )
     204             : {
     205         129 :     if( const XclSelectionData* pSelData = rData.GetSelectionData( nPane ) )
     206          46 :         maSelData = *pSelData;
     207             : 
     208             :     // find the cursor position in the selection list (or add it)
     209         129 :     XclRangeList& rXclSel = maSelData.maXclSelection;
     210         129 :     bool bFound = false;
     211         143 :     for( XclRangeVector::const_iterator aIt = rXclSel.begin(), aEnd = rXclSel.end(); !bFound && (aIt != aEnd); ++aIt )
     212          14 :         if( (bFound = aIt->Contains( maSelData.maXclCursor )) )
     213          14 :             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         129 :     if( !bFound )
     218             :     {
     219         115 :         maSelData.mnCursorIdx = static_cast< sal_uInt16 >( rXclSel.size() );
     220         115 :         rXclSel.push_back( XclRange( maSelData.maXclCursor ) );
     221             :     }
     222         129 : }
     223             : 
     224         100 : void XclExpSelection::SaveXml( XclExpXmlStream& rStrm )
     225             : {
     226         100 :     rStrm.GetCurrentStream()->singleElement( XML_selection,
     227             :             XML_pane,           lcl_GetActivePane( mnPane ),
     228         100 :             XML_activeCell,     XclXmlUtils::ToOString( rStrm.GetRoot().GetStringBuf(), maSelData.maXclCursor ).getStr(),
     229             :             XML_activeCellId,   OString::number(  maSelData.mnCursorIdx ).getStr(),
     230             :             XML_sqref,          XclXmlUtils::ToOString( maSelData.maXclSelection ).getStr(),
     231         300 :             FSEND );
     232         100 : }
     233             : 
     234          29 : void XclExpSelection::WriteBody( XclExpStream& rStrm )
     235             : {
     236          29 :     rStrm   << mnPane                   // pane for this selection
     237          58 :             << maSelData.maXclCursor    // cell cursor
     238          58 :             << maSelData.mnCursorIdx;   // index to range containing cursor
     239          29 :     maSelData.maXclSelection.Write( rStrm, false );
     240          29 : }
     241             : 
     242           2 : XclExpTabBgColor::XclExpTabBgColor( const XclTabViewData& rTabViewData ) :
     243             :     XclExpRecord( EXC_ID_SHEETEXT, 18 ),
     244           2 :     mrTabViewData( rTabViewData )
     245             : {
     246           2 : }
     247             : //TODO Fix savexml...
     248             : /*void XclExpTabBgColor::SaveXml( XclExpXmlStream& rStrm )
     249             : {
     250             : }*/
     251             : 
     252           2 : void XclExpTabBgColor::WriteBody( XclExpStream& rStrm )
     253             : {
     254           2 :     if ( mrTabViewData.IsDefaultTabBgColor() )
     255           2 :         return;
     256           2 :     sal_uInt16 rt = 0x0862; //rt
     257           2 :     sal_uInt16 grbitFrt = 0x0000; //grbit must be set to 0
     258           2 :     sal_uInt32 unused = 0x00000000; //Use twice...
     259           2 :     sal_uInt32 cb = 0x00000014; // Record Size, may be larger in future...
     260           2 :     sal_uInt16 reserved = 0x0000; //trailing bits are 0
     261             :     sal_uInt16 TabBgColorIndex;
     262           2 :     XclExpPalette& rPal = rStrm.GetRoot().GetPalette();
     263           2 :     TabBgColorIndex = rPal.GetColorIndex(mrTabViewData.mnTabBgColorId);
     264           2 :     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           2 :     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          92 : sal_uInt16 lclGetXclZoom( long nScZoom, sal_uInt16 nDefXclZoom )
     275             : {
     276          92 :     sal_uInt16 nXclZoom = limit_cast< sal_uInt16 >( nScZoom, EXC_ZOOM_MIN, EXC_ZOOM_MAX );
     277          92 :     return (nXclZoom == nDefXclZoom) ? 0 : nXclZoom;
     278             : }
     279             : 
     280             : } // namespace
     281             : 
     282         129 : XclExpTabViewSettings::XclExpTabViewSettings( const XclExpRoot& rRoot, SCTAB nScTab ) :
     283             :     XclExpRoot( rRoot ),
     284         129 :     mnGridColorId( XclExpPalette::GetColorIdFromIndex( EXC_COLOR_WINDOWTEXT ) )
     285             : {
     286             :     // *** sheet flags ***
     287             : 
     288         129 :     const XclExpTabInfo& rTabInfo = GetTabInfo();
     289         129 :     maData.mbSelected       = rTabInfo.IsSelectedTab( nScTab );
     290         129 :     maData.mbDisplayed      = rTabInfo.IsDisplayedTab( nScTab );
     291         129 :     maData.mbMirrored       = rTabInfo.IsMirroredTab( nScTab );
     292             : 
     293         129 :     const ScViewOptions& rViewOpt = GetDoc().GetViewOptions();
     294         129 :     maData.mbShowFormulas   = rViewOpt.GetOption( VOPT_FORMULAS );
     295         129 :     maData.mbShowHeadings   = rViewOpt.GetOption( VOPT_HEADER );
     296         129 :     maData.mbShowZeros      = rViewOpt.GetOption( VOPT_NULLVALS );
     297         129 :     maData.mbShowOutline    = rViewOpt.GetOption( VOPT_OUTLINER );
     298             : 
     299             :     // *** sheet options: cursor, selection, splits, grid color, zoom ***
     300             : 
     301         129 :     if( const ScExtTabSettings* pTabSett = GetExtDocOptions().GetTabSettings( nScTab ) )
     302             :     {
     303          46 :         const ScExtTabSettings& rTabSett = *pTabSett;
     304          46 :         XclExpAddressConverter& rAddrConv = GetAddressConverter();
     305             : 
     306             :         // first visible cell in top-left pane
     307          46 :         if( (rTabSett.maFirstVis.Col() >= 0) && (rTabSett.maFirstVis.Row() >= 0) )
     308          46 :             maData.maFirstXclPos = rAddrConv.CreateValidAddress( rTabSett.maFirstVis, false );
     309             : 
     310             :         // first visible cell in additional pane(s)
     311          46 :         if( (rTabSett.maSecondVis.Col() >= 0) && (rTabSett.maSecondVis.Row() >= 0) )
     312          46 :             maData.maSecondXclPos = rAddrConv.CreateValidAddress( rTabSett.maSecondVis, false );
     313             : 
     314             :         // active pane
     315          46 :         switch( rTabSett.meActivePane )
     316             :         {
     317          46 :             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          46 :         maData.mbFrozenPanes = rTabSett.mbFrozenPanes;
     325          46 :         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          46 :             maData.mnSplitX = static_cast<sal_uInt16>(rTabSett.maSplitPos.X());
     350          46 :             maData.mnSplitY = static_cast<sal_uInt32>(rTabSett.maSplitPos.Y());
     351             :         }
     352             : 
     353             :         // selection
     354          46 :         CreateSelectionData( EXC_PANE_TOPLEFT,     rTabSett.maCursor, rTabSett.maSelection );
     355          46 :         CreateSelectionData( EXC_PANE_TOPRIGHT,    rTabSett.maCursor, rTabSett.maSelection );
     356          46 :         CreateSelectionData( EXC_PANE_BOTTOMLEFT,  rTabSett.maCursor, rTabSett.maSelection );
     357          46 :         CreateSelectionData( EXC_PANE_BOTTOMRIGHT, rTabSett.maCursor, rTabSett.maSelection );
     358             : 
     359             :         // grid color
     360          46 :         const Color& rGridColor = rTabSett.maGridColor;
     361          46 :         maData.mbDefGridColor = rGridColor.GetColor() == COL_AUTO;
     362          46 :         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          46 :         maData.mbShowGrid       = rTabSett.mbShowGrid;
     370             : 
     371             :         // view mode and zoom
     372          46 :         maData.mbPageMode       = (GetBiff() == EXC_BIFF8) && rTabSett.mbPageMode;
     373          46 :         maData.mnNormalZoom     = lclGetXclZoom( rTabSett.mnNormalZoom, EXC_WIN2_NORMALZOOM_DEF );
     374          46 :         maData.mnPageZoom       = lclGetXclZoom( rTabSett.mnPageZoom, EXC_WIN2_PAGEZOOM_DEF );
     375          46 :         maData.mnCurrentZoom    = maData.mbPageMode ? maData.mnPageZoom : maData.mnNormalZoom;
     376             :     }
     377             : 
     378             :     // Tab Bg Color
     379         129 :     if ( GetBiff() == EXC_BIFF8 && !GetDoc().IsDefaultTabBgColor(nScTab) )
     380             :     {
     381           9 :         XclExpPalette& rPal = GetPalette();
     382           9 :         maData.maTabBgColor = GetDoc().GetTabBgColor(nScTab);
     383           9 :         maData.mnTabBgColorId = rPal.InsertColor(maData.maTabBgColor, EXC_COLOR_TABBG, EXC_COLOR_NOTABBG );
     384             :     }
     385         129 : }
     386             : 
     387          29 : void XclExpTabViewSettings::Save( XclExpStream& rStrm )
     388             : {
     389          29 :     WriteWindow2( rStrm );
     390          29 :     WriteScl( rStrm );
     391          29 :     WritePane( rStrm );
     392          29 :     WriteSelection( rStrm, EXC_PANE_TOPLEFT );
     393          29 :     WriteSelection( rStrm, EXC_PANE_TOPRIGHT );
     394          29 :     WriteSelection( rStrm, EXC_PANE_BOTTOMLEFT );
     395          29 :     WriteSelection( rStrm, EXC_PANE_BOTTOMRIGHT );
     396          29 :     WriteTabBgColor( rStrm );
     397          29 : }
     398             : 
     399         400 : static void lcl_WriteSelection( XclExpXmlStream& rStrm, const XclTabViewData& rData, sal_uInt8 nPane )
     400             : {
     401         400 :     if( rData.HasPane( nPane ) )
     402         100 :         XclExpSelection( rData, nPane ).SaveXml( rStrm );
     403         400 : }
     404             : 
     405         300 : static OString lcl_GetZoom( sal_uInt16 nZoom )
     406             : {
     407         300 :     if( nZoom )
     408         140 :         return OString::number( nZoom );
     409         160 :     return OString( "100" );
     410             : }
     411             : 
     412         100 : void XclExpTabViewSettings::SaveXml( XclExpXmlStream& rStrm )
     413             : {
     414         100 :     sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
     415         100 :     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         100 :             XML_defaultGridColor,           mnGridColorId == XclExpPalette::GetColorIdFromIndex( EXC_COLOR_WINDOWTEXT ) ? "true" : "false",
     427             :             // OOXTODO: XML_showWhiteSpace,
     428             :             XML_view,                       maData.mbPageMode ? "pageBreakPreview" : "normal",  // OOXTODO: pageLayout
     429         100 :             XML_topLeftCell,                XclXmlUtils::ToOString( rStrm.GetRoot().GetStringBuf(), maData.maFirstXclPos ).getStr(),
     430         100 :             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         400 :             FSEND );
     438         100 :     if( maData.IsSplit() )
     439             :     {
     440           0 :         XclExpPane aPane( maData );
     441           0 :         aPane.SaveXml( rStrm );
     442             :     }
     443         100 :     lcl_WriteSelection( rStrm, maData, EXC_PANE_TOPLEFT );
     444         100 :     lcl_WriteSelection( rStrm, maData, EXC_PANE_TOPRIGHT );
     445         100 :     lcl_WriteSelection( rStrm, maData, EXC_PANE_BOTTOMLEFT );
     446         100 :     lcl_WriteSelection( rStrm, maData, EXC_PANE_BOTTOMRIGHT );
     447         100 :     rWorksheet->endElement( XML_sheetView );
     448             :     // OOXTODO: XML_extLst
     449         100 :     rWorksheet->endElement( XML_sheetViews );
     450         100 : }
     451             : 
     452             : // private --------------------------------------------------------------------
     453             : 
     454         184 : void XclExpTabViewSettings::CreateSelectionData( sal_uInt8 nPane,
     455             :         const ScAddress& rCursor, const ScRangeList& rSelection )
     456             : {
     457         184 :     if( maData.HasPane( nPane ) )
     458             :     {
     459          46 :         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          92 :             maData.maFirstXclPos.mnCol : maData.maSecondXclPos.mnCol;
     464           0 :         rSelData.maXclCursor.mnRow = ((nPane == EXC_PANE_TOPLEFT) || (nPane == EXC_PANE_TOPRIGHT)) ?
     465          92 :             maData.maFirstXclPos.mnRow : maData.maSecondXclPos.mnRow;
     466             : 
     467             :         // second step, active pane: create actual selection data with current cursor position
     468          46 :         if( nPane == maData.mnActivePane )
     469             :         {
     470          46 :             XclExpAddressConverter& rAddrConv = GetAddressConverter();
     471             :             // cursor position (keep top-left pane position from above, if rCursor is invalid)
     472          46 :             if( (rCursor.Col() >= 0) && (rCursor.Row() >= 0) )
     473          46 :                 rSelData.maXclCursor = rAddrConv.CreateValidAddress( rCursor, false );
     474             :             // selection
     475          46 :             rAddrConv.ConvertRangeList( rSelData.maXclSelection, rSelection, false );
     476             :         }
     477             :     }
     478         184 : }
     479             : 
     480          29 : void XclExpTabViewSettings::WriteWindow2( XclExpStream& rStrm ) const
     481             : {
     482             : //  #i43553# GCC 3.3 parse error
     483             : //    XclExpWindow2( GetRoot(), maData, mnGridColorId ).Save( rStrm );
     484          29 :     XclExpWindow2 aWindow2( GetRoot(), maData, mnGridColorId );
     485          29 :     aWindow2.Save( rStrm );
     486          29 : }
     487             : 
     488          29 : void XclExpTabViewSettings::WriteScl( XclExpStream& rStrm ) const
     489             : {
     490          29 :     if( maData.mnCurrentZoom != 0 )
     491           0 :         XclExpScl( maData.mnCurrentZoom ).Save( rStrm );
     492          29 : }
     493             : 
     494          29 : void XclExpTabViewSettings::WritePane( XclExpStream& rStrm ) const
     495             : {
     496          29 :     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          29 : }
     504             : 
     505         116 : void XclExpTabViewSettings::WriteSelection( XclExpStream& rStrm, sal_uInt8 nPane ) const
     506             : {
     507         116 :     if( maData.HasPane( nPane ) )
     508          29 :         XclExpSelection( maData, nPane ).Save( rStrm );
     509         116 : }
     510             : 
     511          29 : void XclExpTabViewSettings::WriteTabBgColor( XclExpStream& rStrm ) const
     512             : {
     513          29 :     if ( !maData.IsDefaultTabBgColor() )
     514           2 :         XclExpTabBgColor( maData ).Save( rStrm );
     515          59 : }
     516             : 
     517             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11