LCOV - code coverage report
Current view: top level - libreoffice/sc/source/filter/excel - xistyle.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 735 1045 70.3 %
Date: 2012-12-17 Functions: 87 122 71.3 %
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 "xistyle.hxx"
      21             : #include <sfx2/printer.hxx>
      22             : #include <sfx2/objsh.hxx>
      23             : #include <svtools/ctrltool.hxx>
      24             : #include <editeng/editobj.hxx>
      25             : #include "scitems.hxx"
      26             : #include <editeng/fontitem.hxx>
      27             : #include <editeng/fhgtitem.hxx>
      28             : #include <editeng/wghtitem.hxx>
      29             : #include <editeng/udlnitem.hxx>
      30             : #include <editeng/postitem.hxx>
      31             : #include <editeng/crsditem.hxx>
      32             : #include <editeng/cntritem.hxx>
      33             : #include <editeng/shdditem.hxx>
      34             : #include <editeng/escpitem.hxx>
      35             : #include <svx/algitem.hxx>
      36             : #include <editeng/boxitem.hxx>
      37             : #include <editeng/bolnitem.hxx>
      38             : #include <svx/rotmodit.hxx>
      39             : #include <editeng/colritem.hxx>
      40             : #include <editeng/brshitem.hxx>
      41             : #include <editeng/frmdiritem.hxx>
      42             : #include <editeng/eeitem.hxx>
      43             : #include <editeng/flstitem.hxx>
      44             : #include <editeng/justifyitem.hxx>
      45             : #include <sal/macros.h>
      46             : #include "document.hxx"
      47             : #include "docpool.hxx"
      48             : #include "attrib.hxx"
      49             : #include "stlpool.hxx"
      50             : #include "stlsheet.hxx"
      51             : #include "cell.hxx"
      52             : #include "globstr.hrc"
      53             : #include "attarray.hxx"
      54             : #include "xltracer.hxx"
      55             : #include "xistream.hxx"
      56             : #include "xicontent.hxx"
      57             : 
      58             : #include "root.hxx"
      59             : #include "colrowst.hxx"
      60             : #include "svl/poolcach.hxx"
      61             : 
      62             : #include <list>
      63             : 
      64             : using ::std::list;
      65             : 
      66             : #include <cppuhelper/implbase1.hxx>
      67             : #include <com/sun/star/container/XIndexAccess.hpp>
      68             : #include <com/sun/star/beans/XPropertySet.hpp>
      69             : using namespace ::com::sun::star;
      70             : 
      71             : typedef ::cppu::WeakImplHelper1< container::XIndexAccess > XIndexAccess_BASE;
      72             : typedef ::std::vector< ColorData > ColorDataVec;
      73             : 
      74           8 : class PaletteIndex : public XIndexAccess_BASE
      75             : {
      76             : public:
      77           4 :     PaletteIndex( const ColorDataVec& rColorDataTable ) : maColorData( rColorDataTable ) {}
      78             : 
      79             :     // Methods XIndexAccess
      80           0 :     virtual ::sal_Int32 SAL_CALL getCount() throw (uno::RuntimeException)
      81             :     {
      82           0 :          return  maColorData.size();
      83             :     }
      84             : 
      85           0 :     virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
      86             :     {
      87             :         //--Index;  // apparently the palette is already 1 based
      88           0 :         return uno::makeAny( sal_Int32( maColorData[ Index ] ) );
      89             :     }
      90             : 
      91             :     // Methods XElementAcess
      92           0 :     virtual uno::Type SAL_CALL getElementType() throw (uno::RuntimeException)
      93             :     {
      94           0 :         return ::getCppuType( (sal_Int32*)0 );
      95             :     }
      96           0 :     virtual ::sal_Bool SAL_CALL hasElements() throw (uno::RuntimeException)
      97             :     {
      98           0 :         return (maColorData.size() > 0);
      99             :     }
     100             : 
     101             : private:
     102             :     ColorDataVec        maColorData;
     103             : };
     104             : 
     105             : void
     106           4 : XclImpPalette::ExportPalette()
     107             : {
     108           4 :     if( SfxObjectShell* pDocShell = mrRoot.GetDocShell() )
     109             :     {
     110             :         // copy values in color palette
     111           4 :         sal_Int16 nColors =  maColorTable.size();
     112           4 :         ColorDataVec aColors;
     113           4 :         aColors.resize( nColors );
     114        1138 :         for( sal_uInt16 nIndex = 0; nIndex < nColors; ++nIndex )
     115        1134 :             aColors[ nIndex ] = GetColorData( nIndex );
     116             : 
     117           4 :         uno::Reference< beans::XPropertySet > xProps( pDocShell->GetModel(), uno::UNO_QUERY );
     118           4 :         if ( xProps.is() )
     119             :         {
     120           4 :             uno::Reference< container::XIndexAccess > xIndex( new PaletteIndex( aColors ) );
     121           4 :             xProps->setPropertyValue( "ColorPalette", uno::makeAny( xIndex ) );
     122           4 :         }
     123             :     }
     124             : 
     125           4 : }
     126             : // PALETTE record - color information =========================================
     127             : 
     128          44 : XclImpPalette::XclImpPalette( const XclImpRoot& rRoot ) :
     129          44 :     XclDefaultPalette( rRoot ), mrRoot( rRoot )
     130             : {
     131          44 : }
     132             : 
     133           0 : void XclImpPalette::Initialize()
     134             : {
     135           0 :     maColorTable.clear();
     136           0 : }
     137             : 
     138       15220 : ColorData XclImpPalette::GetColorData( sal_uInt16 nXclIndex ) const
     139             : {
     140       15220 :     if( nXclIndex >= EXC_COLOR_USEROFFSET )
     141             :     {
     142       15188 :         sal_uInt32 nIx = nXclIndex - EXC_COLOR_USEROFFSET;
     143       15188 :         if( nIx < maColorTable.size() )
     144        1106 :             return maColorTable[ nIx ];
     145             :     }
     146       14114 :     return GetDefColorData( nXclIndex );
     147             : }
     148             : 
     149           4 : void XclImpPalette::ReadPalette( XclImpStream& rStrm )
     150             : {
     151             :     sal_uInt16 nCount;
     152           4 :     rStrm >> nCount;
     153             :     OSL_ENSURE( rStrm.GetRecLeft() == static_cast< sal_Size >( 4 * nCount ),
     154             :         "XclImpPalette::ReadPalette - size mismatch" );
     155             : 
     156           4 :     maColorTable.resize( nCount );
     157           4 :     Color aColor;
     158        1138 :     for( sal_uInt16 nIndex = 0; nIndex < nCount; ++nIndex )
     159             :     {
     160        1134 :         rStrm >> aColor;
     161        1134 :         maColorTable[ nIndex ] = aColor.GetColor();
     162             :     }
     163           4 :     ExportPalette();
     164           4 : }
     165             : 
     166             : // FONT record - font information =============================================
     167             : 
     168         752 : XclImpFont::XclImpFont( const XclImpRoot& rRoot ) :
     169             :     XclImpRoot( rRoot ),
     170             :     mbHasCharSet( false ),
     171             :     mbHasWstrn( true ),
     172             :     mbHasAsian( false ),
     173         752 :     mbHasCmplx( false )
     174             : {
     175         752 :     SetAllUsedFlags( false );
     176         752 : }
     177             : 
     178          66 : XclImpFont::XclImpFont( const XclImpRoot& rRoot, const XclFontData& rFontData ) :
     179          66 :     XclImpRoot( rRoot )
     180             : {
     181          66 :     SetFontData( rFontData, false );
     182          66 : }
     183             : 
     184        1610 : void XclImpFont::SetAllUsedFlags( bool bUsed )
     185             : {
     186             :     mbFontNameUsed = mbHeightUsed = mbColorUsed = mbWeightUsed = mbEscapemUsed =
     187        1610 :         mbUnderlUsed = mbItalicUsed = mbStrikeUsed = mbOutlineUsed = mbShadowUsed = bUsed;
     188        1610 : }
     189             : 
     190         194 : void XclImpFont::SetFontData( const XclFontData& rFontData, bool bHasCharSet )
     191             : {
     192         194 :     maData = rFontData;
     193         194 :     mbHasCharSet = bHasCharSet;
     194         194 :     if( maData.maStyle.Len() )
     195             :     {
     196           4 :         if( SfxObjectShell* pDocShell = GetDocShell() )
     197             :         {
     198           4 :             if( const SvxFontListItem* pInfoItem = static_cast< const SvxFontListItem* >(
     199           4 :                 pDocShell->GetItem( SID_ATTR_CHAR_FONTLIST ) ) )
     200             :             {
     201           4 :                 if( const FontList* pFontList = pInfoItem->GetFontList() )
     202             :                 {
     203           4 :                     FontInfo aFontInfo( pFontList->Get( maData.maName, maData.maStyle ) );
     204           4 :                     maData.SetScWeight( aFontInfo.GetWeight() );
     205           4 :                     maData.SetScPosture( aFontInfo.GetItalic() );
     206             :                 }
     207             :             }
     208             :         }
     209           4 :         maData.maStyle.Erase();
     210             :     }
     211         194 :     GuessScriptType();
     212         194 :     SetAllUsedFlags( true );
     213         194 : }
     214             : 
     215          40 : rtl_TextEncoding XclImpFont::GetFontEncoding() const
     216             : {
     217             :     // #i63105# use text encoding from FONT record
     218             :     // #i67768# BIFF2-BIFF4 FONT records do not contain character set
     219          40 :     rtl_TextEncoding eFontEnc = mbHasCharSet ? maData.GetFontEncoding() : GetTextEncoding();
     220          40 :     return (eFontEnc == RTL_TEXTENCODING_DONTKNOW) ? GetTextEncoding() : eFontEnc;
     221             : }
     222             : 
     223         664 : void XclImpFont::ReadFont( XclImpStream& rStrm )
     224             : {
     225         664 :     switch( GetBiff() )
     226             :     {
     227             :         case EXC_BIFF2:
     228           0 :             ReadFontData2( rStrm );
     229           0 :             ReadFontName2( rStrm );
     230           0 :         break;
     231             :         case EXC_BIFF3:
     232             :         case EXC_BIFF4:
     233           0 :             ReadFontData2( rStrm );
     234           0 :             ReadFontColor( rStrm );
     235           0 :             ReadFontName2( rStrm );
     236           0 :         break;
     237             :         case EXC_BIFF5:
     238           0 :             ReadFontData5( rStrm );
     239           0 :             ReadFontName2( rStrm );
     240           0 :         break;
     241             :         case EXC_BIFF8:
     242         664 :             ReadFontData5( rStrm );
     243         664 :             ReadFontName8( rStrm );
     244         664 :         break;
     245             :         default:
     246             :             DBG_ERROR_BIFF();
     247         664 :             return;
     248             :     }
     249         664 :     GuessScriptType();
     250         664 :     SetAllUsedFlags( true );
     251             : }
     252             : 
     253           0 : void XclImpFont::ReadEfont( XclImpStream& rStrm )
     254             : {
     255           0 :     ReadFontColor( rStrm );
     256           0 : }
     257             : 
     258           0 : void XclImpFont::ReadCFFontBlock( XclImpStream& rStrm )
     259             : {
     260             :     OSL_ENSURE_BIFF( GetBiff() == EXC_BIFF8 );
     261           0 :     if( GetBiff() != EXC_BIFF8 )
     262           0 :         return;
     263             : 
     264             :     sal_uInt32 nHeight, nStyle, nColor, nFontFlags1, nFontFlags2, nFontFlags3;
     265             :     sal_uInt16 nWeight, nEscapem;
     266             :     sal_uInt8 nUnderl;
     267             : 
     268           0 :     rStrm.Ignore( 64 );
     269           0 :     rStrm >> nHeight >> nStyle >> nWeight >> nEscapem >> nUnderl;
     270           0 :     rStrm.Ignore( 3 );
     271           0 :     rStrm >> nColor;
     272           0 :     rStrm.Ignore( 4 );
     273           0 :     rStrm >> nFontFlags1 >> nFontFlags2 >> nFontFlags3;
     274           0 :     rStrm.Ignore( 18 );
     275             : 
     276           0 :     if( (mbHeightUsed = (nHeight <= 0x7FFF)) == true )
     277           0 :         maData.mnHeight = static_cast< sal_uInt16 >( nHeight );
     278           0 :     if( (mbWeightUsed = !::get_flag( nFontFlags1, EXC_CF_FONT_STYLE ) && (nWeight < 0x7FFF)) == true )
     279           0 :         maData.mnWeight = static_cast< sal_uInt16 >( nWeight );
     280           0 :     if( (mbItalicUsed = !::get_flag( nFontFlags1, EXC_CF_FONT_STYLE )) == true )
     281           0 :         maData.mbItalic = ::get_flag( nStyle, EXC_CF_FONT_STYLE );
     282           0 :     if( (mbUnderlUsed = !::get_flag( nFontFlags3, EXC_CF_FONT_UNDERL ) && (nUnderl <= 0x7F)) == true )
     283           0 :         maData.mnUnderline = nUnderl;
     284           0 :     if( (mbColorUsed = (nColor <= 0x7FFF)) == true )
     285           0 :         maData.maColor = GetPalette().GetColor( static_cast< sal_uInt16 >( nColor ) );
     286           0 :     if( (mbStrikeUsed = !::get_flag( nFontFlags1, EXC_CF_FONT_STRIKEOUT )) == true )
     287           0 :         maData.mbStrikeout = ::get_flag( nStyle, EXC_CF_FONT_STRIKEOUT );
     288             : }
     289             : 
     290        2004 : void XclImpFont::FillToItemSet( SfxItemSet& rItemSet, XclFontItemType eType, bool bSkipPoolDefs ) const
     291             : {
     292             :     // true = edit engine Which-IDs (EE_CHAR_*); false = Calc Which-IDs (ATTR_*)
     293        2004 :     bool bEE = eType != EXC_FONTITEM_CELL;
     294             : 
     295             : // item = the item to put into the item set
     296             : // sc_which = the Calc Which-ID of the item
     297             : // ee_which = the edit engine Which-ID of the item
     298             : #define PUTITEM( item, sc_which, ee_which ) \
     299             :     ScfTools::PutItem( rItemSet, item, (bEE ? (ee_which) : (sc_which)), bSkipPoolDefs )
     300             : 
     301             : // Font item
     302             :     // #i36997# do not set default Tahoma font from notes
     303        2004 :     bool bDefNoteFont = (eType == EXC_FONTITEM_NOTE) && (maData.maName.EqualsIgnoreCaseAscii( "Tahoma" ));
     304        2004 :     if( mbFontNameUsed && !bDefNoteFont )
     305             :     {
     306        2004 :         rtl_TextEncoding eFontEnc = maData.GetFontEncoding();
     307         240 :         rtl_TextEncoding eTempTextEnc = (bEE && (eFontEnc == GetTextEncoding())) ?
     308        2244 :             ScfTools::GetSystemTextEncoding() : eFontEnc;
     309             : 
     310        4008 :         SvxFontItem aFontItem( maData.GetScFamily( GetTextEncoding() ), maData.maName, EMPTY_STRING,
     311        6012 :                 PITCH_DONTKNOW, eTempTextEnc, ATTR_FONT );
     312             :         // set only for valid script types
     313        2004 :         if( mbHasWstrn )
     314        2004 :             PUTITEM( aFontItem, ATTR_FONT,      EE_CHAR_FONTINFO );
     315        2004 :         if( mbHasAsian )
     316           0 :             PUTITEM( aFontItem, ATTR_CJK_FONT,  EE_CHAR_FONTINFO_CJK );
     317        2004 :         if( mbHasCmplx )
     318        1456 :             PUTITEM( aFontItem, ATTR_CTL_FONT,  EE_CHAR_FONTINFO_CTL );
     319             :     }
     320             : 
     321             : // Font height (for all script types)
     322        2004 :     if( mbHeightUsed )
     323             :     {
     324        2004 :         sal_Int32 nHeight = maData.mnHeight;
     325        2004 :         if( bEE && (eType != EXC_FONTITEM_HF) )     // do not convert header/footer height
     326         174 :             nHeight = (nHeight * 127 + 36) / EXC_POINTS_PER_INCH;   // 1 in == 72 pt
     327             : 
     328        2004 :         SvxFontHeightItem aHeightItem( nHeight, 100, ATTR_FONT_HEIGHT );
     329        2004 :         PUTITEM( aHeightItem,   ATTR_FONT_HEIGHT,       EE_CHAR_FONTHEIGHT );
     330        2004 :         PUTITEM( aHeightItem,   ATTR_CJK_FONT_HEIGHT,   EE_CHAR_FONTHEIGHT_CJK );
     331        2004 :         PUTITEM( aHeightItem,   ATTR_CTL_FONT_HEIGHT,   EE_CHAR_FONTHEIGHT_CTL );
     332             :     }
     333             : 
     334             : // Font color - pass AUTO_COL to item
     335        2004 :     if( mbColorUsed )
     336        2004 :         PUTITEM( SvxColorItem( maData.maColor, ATTR_FONT_COLOR  ), ATTR_FONT_COLOR, EE_CHAR_COLOR );
     337             : 
     338             : // Font weight (for all script types)
     339        2004 :     if( mbWeightUsed )
     340             :     {
     341        2004 :         SvxWeightItem aWeightItem( maData.GetScWeight(), ATTR_FONT_WEIGHT );
     342        2004 :         PUTITEM( aWeightItem,   ATTR_FONT_WEIGHT,       EE_CHAR_WEIGHT );
     343        2004 :         PUTITEM( aWeightItem,   ATTR_CJK_FONT_WEIGHT,   EE_CHAR_WEIGHT_CJK );
     344        2004 :         PUTITEM( aWeightItem,   ATTR_CTL_FONT_WEIGHT,   EE_CHAR_WEIGHT_CTL );
     345             :     }
     346             : 
     347             : // Font underline
     348        2004 :     if( mbUnderlUsed )
     349             :     {
     350        2004 :         SvxUnderlineItem aUnderlItem( maData.GetScUnderline(), ATTR_FONT_UNDERLINE );
     351        2004 :         PUTITEM( aUnderlItem,   ATTR_FONT_UNDERLINE,    EE_CHAR_UNDERLINE );
     352             :     }
     353             : 
     354             : // Font posture (for all script types)
     355        2004 :     if( mbItalicUsed )
     356             :     {
     357        2004 :         SvxPostureItem aPostItem( maData.GetScPosture(), ATTR_FONT_POSTURE );
     358        2004 :         PUTITEM( aPostItem, ATTR_FONT_POSTURE,      EE_CHAR_ITALIC );
     359        2004 :         PUTITEM( aPostItem, ATTR_CJK_FONT_POSTURE,  EE_CHAR_ITALIC_CJK );
     360        2004 :         PUTITEM( aPostItem, ATTR_CTL_FONT_POSTURE,  EE_CHAR_ITALIC_CTL );
     361             :     }
     362             : 
     363             : // Boolean attributes crossed out, contoured, shadowed
     364        2004 :     if( mbStrikeUsed )
     365        2004 :         PUTITEM( SvxCrossedOutItem( maData.GetScStrikeout(), ATTR_FONT_CROSSEDOUT ), ATTR_FONT_CROSSEDOUT, EE_CHAR_STRIKEOUT );
     366        2004 :     if( mbOutlineUsed )
     367        2004 :         PUTITEM( SvxContourItem( maData.mbOutline, ATTR_FONT_CONTOUR ), ATTR_FONT_CONTOUR, EE_CHAR_OUTLINE );
     368        2004 :     if( mbShadowUsed )
     369        2004 :         PUTITEM( SvxShadowedItem( maData.mbShadow, ATTR_FONT_SHADOWED ), ATTR_FONT_SHADOWED, EE_CHAR_SHADOW );
     370             : 
     371             : // Super-/subscript: only on edit engine objects
     372        2004 :     if( mbEscapemUsed && bEE )
     373         240 :         rItemSet.Put( SvxEscapementItem( maData.GetScEscapement(), EE_CHAR_ESCAPEMENT ) );
     374             : 
     375             : #undef PUTITEM
     376        2004 : }
     377             : 
     378         372 : void XclImpFont::WriteFontProperties( ScfPropertySet& rPropSet,
     379             :         XclFontPropSetType eType, const Color* pFontColor ) const
     380             : {
     381         372 :     GetFontPropSetHelper().WriteFontProperties(
     382         744 :         rPropSet, eType, maData, mbHasWstrn, mbHasAsian, mbHasCmplx, pFontColor );
     383         372 : }
     384             : 
     385           0 : void XclImpFont::ReadFontData2( XclImpStream& rStrm )
     386             : {
     387             :     sal_uInt16 nFlags;
     388           0 :     rStrm >> maData.mnHeight >> nFlags;
     389             : 
     390           0 :     maData.mnWeight     = ::get_flagvalue( nFlags, EXC_FONTATTR_BOLD, EXC_FONTWGHT_BOLD, EXC_FONTWGHT_NORMAL );
     391           0 :     maData.mnUnderline  = ::get_flagvalue( nFlags, EXC_FONTATTR_UNDERLINE, EXC_FONTUNDERL_SINGLE, EXC_FONTUNDERL_NONE );
     392           0 :     maData.mbItalic     = ::get_flag( nFlags, EXC_FONTATTR_ITALIC );
     393           0 :     maData.mbStrikeout  = ::get_flag( nFlags, EXC_FONTATTR_STRIKEOUT );
     394           0 :     maData.mbOutline    = ::get_flag( nFlags, EXC_FONTATTR_OUTLINE );
     395           0 :     maData.mbShadow     = ::get_flag( nFlags, EXC_FONTATTR_SHADOW );
     396           0 :     mbHasCharSet = false;
     397           0 : }
     398             : 
     399         664 : void XclImpFont::ReadFontData5( XclImpStream& rStrm )
     400             : {
     401             :     sal_uInt16 nFlags;
     402             : 
     403         664 :     rStrm >> maData.mnHeight >> nFlags;
     404         664 :     ReadFontColor( rStrm );
     405         664 :     rStrm >> maData.mnWeight >> maData.mnEscapem >> maData.mnUnderline >> maData.mnFamily >> maData.mnCharSet;
     406         664 :     rStrm.Ignore( 1 );
     407             : 
     408         664 :     maData.mbItalic     = ::get_flag( nFlags, EXC_FONTATTR_ITALIC );
     409         664 :     maData.mbStrikeout  = ::get_flag( nFlags, EXC_FONTATTR_STRIKEOUT );
     410         664 :     maData.mbOutline    = ::get_flag( nFlags, EXC_FONTATTR_OUTLINE );
     411         664 :     maData.mbShadow     = ::get_flag( nFlags, EXC_FONTATTR_SHADOW );
     412         664 :     mbHasCharSet = true;
     413         664 : }
     414             : 
     415         664 : void XclImpFont::ReadFontColor( XclImpStream& rStrm )
     416             : {
     417         664 :     maData.maColor = GetPalette().GetColor( rStrm.ReaduInt16() );
     418         664 : }
     419             : 
     420           0 : void XclImpFont::ReadFontName2( XclImpStream& rStrm )
     421             : {
     422           0 :     maData.maName = rStrm.ReadByteString( false );
     423           0 : }
     424             : 
     425         664 : void XclImpFont::ReadFontName8( XclImpStream& rStrm )
     426             : {
     427         664 :     maData.maName = rStrm.ReadUniString( rStrm.ReaduInt8() );
     428         664 : }
     429             : 
     430         858 : void XclImpFont::GuessScriptType()
     431             : {
     432         858 :     mbHasWstrn = true;
     433         858 :     mbHasAsian = mbHasCmplx = false;
     434             : 
     435             :     // find the script types for which the font contains characters
     436         858 :     if( OutputDevice* pPrinter = GetPrinter() )
     437             :     {
     438         858 :         Font aFont( maData.maName, Size( 0, 10 ) );
     439         858 :         FontCharMap aCharMap;
     440             : 
     441         858 :         pPrinter->SetFont( aFont );
     442         858 :         if( pPrinter->GetFontCharMap( aCharMap ) )
     443             :         {
     444             :             // CJK fonts
     445             :             mbHasAsian =
     446         858 :                 aCharMap.HasChar( 0x3041 ) ||   // 3040-309F: Hiragana
     447         858 :                 aCharMap.HasChar( 0x30A1 ) ||   // 30A0-30FF: Katakana
     448         858 :                 aCharMap.HasChar( 0x3111 ) ||   // 3100-312F: Bopomofo
     449         858 :                 aCharMap.HasChar( 0x3131 ) ||   // 3130-318F: Hangul Compatibility Jamo
     450         858 :                 aCharMap.HasChar( 0x3301 ) ||   // 3300-33FF: CJK Compatibility
     451         858 :                 aCharMap.HasChar( 0x3401 ) ||   // 3400-4DBF: CJK Unified Ideographs Extension A
     452         858 :                 aCharMap.HasChar( 0x4E01 ) ||   // 4E00-9FAF: CJK Unified Ideographs
     453         858 :                 aCharMap.HasChar( 0x7E01 ) ||   // 4E00-9FAF: CJK unified ideographs
     454         858 :                 aCharMap.HasChar( 0xA001 ) ||   // A001-A48F: Yi Syllables
     455         858 :                 aCharMap.HasChar( 0xAC01 ) ||   // AC00-D7AF: Hangul Syllables
     456         858 :                 aCharMap.HasChar( 0xCC01 ) ||   // AC00-D7AF: Hangul Syllables
     457         858 :                 aCharMap.HasChar( 0xF901 ) ||   // F900-FAFF: CJK Compatibility Ideographs
     458       10296 :                 aCharMap.HasChar( 0xFF71 );     // FF00-FFEF: Halfwidth/Fullwidth Forms
     459             :             // CTL fonts
     460             :             mbHasCmplx =
     461         858 :                 aCharMap.HasChar( 0x05D1 ) ||   // 0590-05FF: Hebrew
     462         376 :                 aCharMap.HasChar( 0x0631 ) ||   // 0600-06FF: Arabic
     463         376 :                 aCharMap.HasChar( 0x0721 ) ||   // 0700-074F: Syriac
     464         376 :                 aCharMap.HasChar( 0x0911 ) ||   // 0900-0DFF: Indic scripts
     465         376 :                 aCharMap.HasChar( 0x0E01 ) ||   // 0E00-0E7F: Thai
     466         376 :                 aCharMap.HasChar( 0xFB21 ) ||   // FB1D-FB4F: Hebrew Presentation Forms
     467         376 :                 aCharMap.HasChar( 0xFB51 ) ||   // FB50-FDFF: Arabic Presentation Forms-A
     468        3114 :                 aCharMap.HasChar( 0xFE71 );     // FE70-FEFF: Arabic Presentation Forms-B
     469             :             // Western fonts
     470         858 :             mbHasWstrn = (!mbHasAsian && !mbHasCmplx) || aCharMap.HasChar( 'A' );
     471         858 :         }
     472             :     }
     473         858 : }
     474             : 
     475             : // ----------------------------------------------------------------------------
     476             : 
     477          44 : XclImpFontBuffer::XclImpFontBuffer( const XclImpRoot& rRoot ) :
     478             :     XclImpRoot( rRoot ),
     479             :     maFont4( rRoot ),
     480          44 :     maCtrlFont( rRoot )
     481             : {
     482          44 :     Initialize();
     483             : 
     484             :     // default font for form controls without own font information
     485          44 :     XclFontData aCtrlFontData;
     486          44 :     switch( GetBiff() )
     487             :     {
     488             :         case EXC_BIFF2:
     489             :         case EXC_BIFF3:
     490             :         case EXC_BIFF4:
     491             :         case EXC_BIFF5:
     492           0 :             aCtrlFontData.maName.AssignAscii( "Helv" );
     493           0 :             aCtrlFontData.mnHeight = 160;
     494           0 :             aCtrlFontData.mnWeight = EXC_FONTWGHT_BOLD;
     495           0 :         break;
     496             :         case EXC_BIFF8:
     497          44 :             aCtrlFontData.maName.AssignAscii( "Tahoma" );
     498          44 :             aCtrlFontData.mnHeight = 160;
     499          44 :             aCtrlFontData.mnWeight = EXC_FONTWGHT_NORMAL;
     500          44 :         break;
     501             :         default:
     502             :             DBG_ERROR_BIFF();
     503             :     }
     504          44 :     maCtrlFont.SetFontData( aCtrlFontData, false );
     505          44 : }
     506             : 
     507          44 : void XclImpFontBuffer::Initialize()
     508             : {
     509          44 :     maFontList.clear();
     510             : 
     511             :     // application font for column width calculation, later filled with first font from font list
     512          44 :     XclFontData aAppFontData;
     513          44 :     aAppFontData.maName.AssignAscii( "Arial" );
     514          44 :     aAppFontData.mnHeight = 200;
     515          44 :     aAppFontData.mnWeight = EXC_FONTWGHT_NORMAL;
     516          44 :     UpdateAppFont( aAppFontData, false );
     517          44 : }
     518             : 
     519       24882 : const XclImpFont* XclImpFontBuffer::GetFont( sal_uInt16 nFontIndex ) const
     520             : {
     521             :     /*  Font with index 4 is not stored in an Excel file, but used e.g. by
     522             :         BIFF5 form pushbutton objects. It is the bold default font.
     523             :         This also means that entries above 4 are out by one in the list. */
     524             : 
     525       24882 :     if (nFontIndex == 4)
     526           0 :         return &maFont4;
     527             : 
     528       24882 :     if (nFontIndex < 4)
     529             :     {
     530             :         // Font ID is zero-based when it's less than 4.
     531       17902 :         return nFontIndex >= maFontList.size() ? NULL : &maFontList[nFontIndex];
     532             :     }
     533             : 
     534             :     // Font ID is greater than 4.  It is now 1-based.
     535        6980 :     return nFontIndex > maFontList.size() ? NULL : &maFontList[nFontIndex-1];
     536             : }
     537             : 
     538         664 : void XclImpFontBuffer::ReadFont( XclImpStream& rStrm )
     539             : {
     540         664 :     XclImpFont* pFont = new XclImpFont( GetRoot() );
     541         664 :     pFont->ReadFont( rStrm );
     542         664 :     maFontList.push_back( pFont );
     543             : 
     544         664 :     if( maFontList.size() == 1 )
     545             :     {
     546          40 :         UpdateAppFont( pFont->GetFontData(), pFont->HasCharSet() );
     547             :         // #i71033# set text encoding from application font, if CODEPAGE is missing
     548          40 :         SetAppFontEncoding( pFont->GetFontEncoding() );
     549             :     }
     550         664 : }
     551             : 
     552           0 : void XclImpFontBuffer::ReadEfont( XclImpStream& rStrm )
     553             : {
     554           0 :     if( !maFontList.empty() )
     555           0 :         maFontList.back().ReadEfont( rStrm );
     556           0 : }
     557             : 
     558        1938 : void XclImpFontBuffer::FillToItemSet(
     559             :         SfxItemSet& rItemSet, XclFontItemType eType,
     560             :         sal_uInt16 nFontIdx, bool bSkipPoolDefs ) const
     561             : {
     562        1938 :     if( const XclImpFont* pFont = GetFont( nFontIdx ) )
     563        1938 :         pFont->FillToItemSet( rItemSet, eType, bSkipPoolDefs );
     564        1938 : }
     565             : 
     566         372 : void XclImpFontBuffer::WriteFontProperties( ScfPropertySet& rPropSet,
     567             :         XclFontPropSetType eType, sal_uInt16 nFontIdx, const Color* pFontColor ) const
     568             : {
     569         372 :     if( const XclImpFont* pFont = GetFont( nFontIdx ) )
     570         372 :         pFont->WriteFontProperties( rPropSet, eType, pFontColor );
     571         372 : }
     572             : 
     573           0 : void XclImpFontBuffer::WriteDefaultCtrlFontProperties( ScfPropertySet& rPropSet ) const
     574             : {
     575           0 :     maCtrlFont.WriteFontProperties( rPropSet, EXC_FONTPROPSET_CONTROL );
     576           0 : }
     577             : 
     578          84 : void XclImpFontBuffer::UpdateAppFont( const XclFontData& rFontData, bool bHasCharSet )
     579             : {
     580          84 :     maAppFont = rFontData;
     581             :     // #i3006# Calculate the width of '0' from first font and current printer.
     582          84 :     SetCharWidth( maAppFont );
     583             : 
     584             :     // font 4 is bold font 0
     585          84 :     XclFontData aFont4Data( maAppFont );
     586          84 :     aFont4Data.mnWeight = EXC_FONTWGHT_BOLD;
     587          84 :     maFont4.SetFontData( aFont4Data, bHasCharSet );
     588          84 : }
     589             : 
     590             : // FORMAT record - number formats =============================================
     591             : 
     592          44 : XclImpNumFmtBuffer::XclImpNumFmtBuffer( const XclImpRoot& rRoot ) :
     593             :     XclNumFmtBuffer( rRoot ),
     594             :     XclImpRoot( rRoot ),
     595          44 :     mnNextXclIdx( 0 )
     596             : {
     597          44 : }
     598             : 
     599           0 : void XclImpNumFmtBuffer::Initialize()
     600             : {
     601           0 :     maIndexMap.clear();
     602           0 :     mnNextXclIdx = 0;
     603           0 :     InitializeImport();     // base class
     604           0 : }
     605             : 
     606         420 : void XclImpNumFmtBuffer::ReadFormat( XclImpStream& rStrm )
     607             : {
     608         420 :     String aFormat;
     609         420 :     switch( GetBiff() )
     610             :     {
     611             :         case EXC_BIFF2:
     612             :         case EXC_BIFF3:
     613           0 :             aFormat = rStrm.ReadByteString( false );
     614           0 :         break;
     615             : 
     616             :         case EXC_BIFF4:
     617           0 :             rStrm.Ignore( 2 );  // in BIFF4 the index field exists, but is undefined
     618           0 :             aFormat = rStrm.ReadByteString( false );
     619           0 :         break;
     620             : 
     621             :         case EXC_BIFF5:
     622           0 :             rStrm >> mnNextXclIdx;
     623           0 :             aFormat = rStrm.ReadByteString( false );
     624           0 :         break;
     625             : 
     626             :         case EXC_BIFF8:
     627         420 :             rStrm >> mnNextXclIdx;
     628         420 :             aFormat = rStrm.ReadUniString();
     629         420 :         break;
     630             : 
     631             :         default:
     632             :             DBG_ERROR_BIFF();
     633         420 :             return;
     634             :     }
     635             : 
     636         420 :     if( mnNextXclIdx < 0xFFFF )
     637             :     {
     638         420 :         InsertFormat( mnNextXclIdx, aFormat );
     639         420 :         ++mnNextXclIdx;
     640         420 :     }
     641             : }
     642             : 
     643          42 : void XclImpNumFmtBuffer::CreateScFormats()
     644             : {
     645             :     OSL_ENSURE( maIndexMap.empty(), "XclImpNumFmtBuffer::CreateScFormats - already created" );
     646             : 
     647          42 :     SvNumberFormatter& rFormatter = GetFormatter();
     648        3554 :     for( XclNumFmtMap::const_iterator aIt = GetFormatMap().begin(), aEnd = GetFormatMap().end(); aIt != aEnd; ++aIt )
     649             :     {
     650        3512 :         const XclNumFmt& rNumFmt = aIt->second;
     651             : 
     652             :         // insert/convert the Excel number format
     653             :         sal_Int32 nCheckPos;
     654        3512 :         short nType = NUMBERFORMAT_DEFINED;
     655             :         sal_uInt32 nKey;
     656        3512 :         if( rNumFmt.maFormat.Len() )
     657             :         {
     658        2562 :             OUString aFormat( rNumFmt.maFormat );
     659             :             rFormatter.PutandConvertEntry( aFormat, nCheckPos,
     660        2562 :                                            nType, nKey, LANGUAGE_ENGLISH_US, rNumFmt.meLanguage );
     661             :         }
     662             :         else
     663         950 :             nKey = rFormatter.GetFormatIndex( rNumFmt.meOffset, rNumFmt.meLanguage );
     664             : 
     665             :         // insert the resulting format key into the Excel->Calc index map
     666        3512 :         maIndexMap[ aIt->first ] = nKey;
     667             :     }
     668          42 : }
     669             : 
     670        1294 : sal_uLong XclImpNumFmtBuffer::GetScFormat( sal_uInt16 nXclNumFmt ) const
     671             : {
     672        1294 :     XclImpIndexMap::const_iterator aIt = maIndexMap.find( nXclNumFmt );
     673        1294 :     return (aIt != maIndexMap.end()) ? aIt->second : NUMBERFORMAT_ENTRY_NOT_FOUND;
     674             : }
     675             : 
     676        1134 : void XclImpNumFmtBuffer::FillToItemSet( SfxItemSet& rItemSet, sal_uInt16 nXclNumFmt, bool bSkipPoolDefs ) const
     677             : {
     678        1134 :     sal_uLong nScNumFmt = GetScFormat( nXclNumFmt );
     679        1134 :     if( nScNumFmt == NUMBERFORMAT_ENTRY_NOT_FOUND )
     680           0 :         nScNumFmt = GetStdScNumFmt();
     681        1134 :     FillScFmtToItemSet( rItemSet, nScNumFmt, bSkipPoolDefs );
     682        1134 : }
     683             : 
     684        1134 : void XclImpNumFmtBuffer::FillScFmtToItemSet( SfxItemSet& rItemSet, sal_uLong nScNumFmt, bool bSkipPoolDefs ) const
     685             : {
     686             :     OSL_ENSURE( nScNumFmt != NUMBERFORMAT_ENTRY_NOT_FOUND, "XclImpNumFmtBuffer::FillScFmtToItemSet - invalid number format" );
     687        1134 :     ScfTools::PutItem( rItemSet, SfxUInt32Item( ATTR_VALUE_FORMAT, nScNumFmt ), bSkipPoolDefs );
     688        1134 :     if( rItemSet.GetItemState( ATTR_VALUE_FORMAT, false ) == SFX_ITEM_SET )
     689        1098 :         ScGlobal::AddLanguage( rItemSet, GetFormatter() );
     690        1134 : }
     691             : 
     692             : // XF, STYLE record - Cell formatting =========================================
     693             : 
     694           0 : void XclImpCellProt::FillFromXF2( sal_uInt8 nNumFmt )
     695             : {
     696           0 :     mbLocked = ::get_flag( nNumFmt, EXC_XF2_LOCKED );
     697           0 :     mbHidden = ::get_flag( nNumFmt, EXC_XF2_HIDDEN );
     698           0 : }
     699             : 
     700        3610 : void XclImpCellProt::FillFromXF3( sal_uInt16 nProt )
     701             : {
     702        3610 :     mbLocked = ::get_flag( nProt, EXC_XF_LOCKED );
     703        3610 :     mbHidden = ::get_flag( nProt, EXC_XF_HIDDEN );
     704        3610 : }
     705             : 
     706          92 : void XclImpCellProt::FillToItemSet( SfxItemSet& rItemSet, bool bSkipPoolDefs ) const
     707             : {
     708          92 :     ScfTools::PutItem( rItemSet, ScProtectionAttr( mbLocked, mbHidden ), bSkipPoolDefs );
     709          92 : }
     710             : 
     711             : 
     712             : // ----------------------------------------------------------------------------
     713             : 
     714           0 : void XclImpCellAlign::FillFromXF2( sal_uInt8 nFlags )
     715             : {
     716           0 :     mnHorAlign = ::extract_value< sal_uInt8 >( nFlags, 0, 3 );
     717           0 : }
     718             : 
     719           0 : void XclImpCellAlign::FillFromXF3( sal_uInt16 nAlign )
     720             : {
     721           0 :     mnHorAlign = ::extract_value< sal_uInt8 >( nAlign, 0, 3 );
     722           0 :     mbLineBreak = ::get_flag( nAlign, EXC_XF_LINEBREAK );   // new in BIFF3
     723           0 : }
     724             : 
     725           0 : void XclImpCellAlign::FillFromXF4( sal_uInt16 nAlign )
     726             : {
     727           0 :     FillFromXF3( nAlign );
     728           0 :     mnVerAlign = ::extract_value< sal_uInt8 >( nAlign, 4, 2 );  // new in BIFF4
     729           0 :     mnOrient = ::extract_value< sal_uInt8 >( nAlign, 6, 2 );    // new in BIFF4
     730           0 : }
     731             : 
     732           0 : void XclImpCellAlign::FillFromXF5( sal_uInt16 nAlign )
     733             : {
     734           0 :     mnHorAlign = ::extract_value< sal_uInt8 >( nAlign, 0, 3 );
     735           0 :     mnVerAlign = ::extract_value< sal_uInt8 >( nAlign, 4, 3 );
     736           0 :     mbLineBreak = ::get_flag( nAlign, EXC_XF_LINEBREAK );
     737           0 :     mnOrient = ::extract_value< sal_uInt8 >( nAlign, 8, 2 );
     738           0 : }
     739             : 
     740        3610 : void XclImpCellAlign::FillFromXF8( sal_uInt16 nAlign, sal_uInt16 nMiscAttrib )
     741             : {
     742        3610 :     mnHorAlign = ::extract_value< sal_uInt8 >( nAlign, 0, 3 );
     743        3610 :     mnVerAlign = ::extract_value< sal_uInt8 >( nAlign, 4, 3 );
     744        3610 :     mbLineBreak = ::get_flag( nAlign, EXC_XF_LINEBREAK );
     745        3610 :     mnRotation = ::extract_value< sal_uInt8 >( nAlign, 8, 8 );      // new in BIFF8
     746        3610 :     mnIndent = ::extract_value< sal_uInt8 >( nMiscAttrib, 0, 4 );   // new in BIFF8
     747        3610 :     mbShrink = ::get_flag( nMiscAttrib, EXC_XF8_SHRINK );           // new in BIFF8
     748        3610 :     mnTextDir = ::extract_value< sal_uInt8 >( nMiscAttrib, 6, 2 );  // new in BIFF8
     749        3610 : }
     750             : 
     751        1540 : void XclImpCellAlign::FillToItemSet( SfxItemSet& rItemSet, const XclImpFont* pFont, bool bSkipPoolDefs ) const
     752             : {
     753             :     // horizontal alignment
     754        1540 :     ScfTools::PutItem( rItemSet, SvxHorJustifyItem( GetScHorAlign(), ATTR_HOR_JUSTIFY ), bSkipPoolDefs );
     755        1540 :     ScfTools::PutItem( rItemSet, SvxJustifyMethodItem( GetScHorJustifyMethod(), ATTR_HOR_JUSTIFY_METHOD ), bSkipPoolDefs );
     756             : 
     757             :     // text wrap (#i74508# always if vertical alignment is justified or distributed)
     758        1540 :     bool bLineBreak = mbLineBreak || (mnVerAlign == EXC_XF_VER_JUSTIFY) || (mnVerAlign == EXC_XF_VER_DISTRIB);
     759        1540 :     ScfTools::PutItem( rItemSet, SfxBoolItem( ATTR_LINEBREAK, bLineBreak ), bSkipPoolDefs );
     760             : 
     761             :     // vertical alignment
     762        1540 :     ScfTools::PutItem( rItemSet, SvxVerJustifyItem( GetScVerAlign(), ATTR_VER_JUSTIFY ), bSkipPoolDefs );
     763        1540 :     ScfTools::PutItem( rItemSet, SvxJustifyMethodItem( GetScVerJustifyMethod(), ATTR_VER_JUSTIFY_METHOD ), bSkipPoolDefs );
     764             : 
     765             :     // indent
     766        1540 :     sal_uInt16 nScIndent = mnIndent * 200; // 1 Excel unit == 10 pt == 200 twips
     767        1540 :     ScfTools::PutItem( rItemSet, SfxUInt16Item( ATTR_INDENT, nScIndent ), bSkipPoolDefs );
     768             : 
     769             :     // shrink to fit
     770        1540 :     ScfTools::PutItem( rItemSet, SfxBoolItem( ATTR_SHRINKTOFIT, mbShrink ), bSkipPoolDefs );
     771             : 
     772             :     // text orientation/rotation (BIFF2-BIFF7 sets mnOrient)
     773        1540 :     sal_uInt8 nXclRot = (mnOrient == EXC_ORIENT_NONE) ? mnRotation : XclTools::GetXclRotFromOrient( mnOrient );
     774        1540 :     bool bStacked = (nXclRot == EXC_ROT_STACKED);
     775        1540 :     ScfTools::PutItem( rItemSet, SfxBoolItem( ATTR_STACKED, bStacked ), bSkipPoolDefs );
     776             :     // set an angle in the range from -90 to 90 degrees
     777        1540 :     sal_Int32 nAngle = XclTools::GetScRotation( nXclRot, 0 );
     778        1540 :     ScfTools::PutItem( rItemSet, SfxInt32Item( ATTR_ROTATE_VALUE, nAngle ), bSkipPoolDefs );
     779             :     // set "Use asian vertical layout", if cell is stacked and font contains CKJ characters
     780        1540 :     bool bAsianVert = bStacked && pFont && pFont->HasAsianChars();
     781        1540 :     ScfTools::PutItem( rItemSet, SfxBoolItem( ATTR_VERTICAL_ASIAN, bAsianVert ), bSkipPoolDefs );
     782             : 
     783             :     // CTL text direction
     784        1540 :     ScfTools::PutItem( rItemSet, SvxFrameDirectionItem( GetScFrameDir(), ATTR_WRITINGDIR ), bSkipPoolDefs );
     785        1540 : }
     786             : 
     787             : // ----------------------------------------------------------------------------
     788             : 
     789        3610 : XclImpCellBorder::XclImpCellBorder()
     790             : {
     791        3610 :     SetUsedFlags( false, false );
     792        3610 : }
     793             : 
     794        7220 : void XclImpCellBorder::SetUsedFlags( bool bOuterUsed, bool bDiagUsed )
     795             : {
     796        7220 :     mbLeftUsed = mbRightUsed = mbTopUsed = mbBottomUsed = bOuterUsed;
     797        7220 :     mbDiagUsed = bDiagUsed;
     798        7220 : }
     799             : 
     800           0 : void XclImpCellBorder::FillFromXF2( sal_uInt8 nFlags )
     801             : {
     802           0 :     mnLeftLine   = ::get_flagvalue( nFlags, EXC_XF2_LEFTLINE,   EXC_LINE_THIN, EXC_LINE_NONE );
     803           0 :     mnRightLine  = ::get_flagvalue( nFlags, EXC_XF2_RIGHTLINE,  EXC_LINE_THIN, EXC_LINE_NONE );
     804           0 :     mnTopLine    = ::get_flagvalue( nFlags, EXC_XF2_TOPLINE,    EXC_LINE_THIN, EXC_LINE_NONE );
     805           0 :     mnBottomLine = ::get_flagvalue( nFlags, EXC_XF2_BOTTOMLINE, EXC_LINE_THIN, EXC_LINE_NONE );
     806           0 :     mnLeftColor = mnRightColor = mnTopColor = mnBottomColor = EXC_COLOR_BIFF2_BLACK;
     807           0 :     SetUsedFlags( true, false );
     808           0 : }
     809             : 
     810           0 : void XclImpCellBorder::FillFromXF3( sal_uInt32 nBorder )
     811             : {
     812           0 :     mnTopLine     = ::extract_value< sal_uInt8  >( nBorder,  0, 3 );
     813           0 :     mnLeftLine    = ::extract_value< sal_uInt8  >( nBorder,  8, 3 );
     814           0 :     mnBottomLine  = ::extract_value< sal_uInt8  >( nBorder, 16, 3 );
     815           0 :     mnRightLine   = ::extract_value< sal_uInt8  >( nBorder, 24, 3 );
     816           0 :     mnTopColor    = ::extract_value< sal_uInt16 >( nBorder,  3, 5 );
     817           0 :     mnLeftColor   = ::extract_value< sal_uInt16 >( nBorder, 11, 5 );
     818           0 :     mnBottomColor = ::extract_value< sal_uInt16 >( nBorder, 19, 5 );
     819           0 :     mnRightColor  = ::extract_value< sal_uInt16 >( nBorder, 27, 5 );
     820           0 :     SetUsedFlags( true, false );
     821           0 : }
     822             : 
     823           0 : void XclImpCellBorder::FillFromXF5( sal_uInt32 nBorder, sal_uInt32 nArea )
     824             : {
     825           0 :     mnTopLine     = ::extract_value< sal_uInt8  >( nBorder,  0, 3 );
     826           0 :     mnLeftLine    = ::extract_value< sal_uInt8  >( nBorder,  3, 3 );
     827           0 :     mnBottomLine  = ::extract_value< sal_uInt8  >( nArea,   22, 3 );
     828           0 :     mnRightLine   = ::extract_value< sal_uInt8  >( nBorder,  6, 3 );
     829           0 :     mnTopColor    = ::extract_value< sal_uInt16 >( nBorder,  9, 7 );
     830           0 :     mnLeftColor   = ::extract_value< sal_uInt16 >( nBorder, 16, 7 );
     831           0 :     mnBottomColor = ::extract_value< sal_uInt16 >( nArea,   25, 7 );
     832           0 :     mnRightColor  = ::extract_value< sal_uInt16 >( nBorder, 23, 7 );
     833           0 :     SetUsedFlags( true, false );
     834           0 : }
     835             : 
     836        3610 : void XclImpCellBorder::FillFromXF8( sal_uInt32 nBorder1, sal_uInt32 nBorder2 )
     837             : {
     838        3610 :     mnLeftLine    = ::extract_value< sal_uInt8  >( nBorder1,  0, 4 );
     839        3610 :     mnRightLine   = ::extract_value< sal_uInt8  >( nBorder1,  4, 4 );
     840        3610 :     mnTopLine     = ::extract_value< sal_uInt8  >( nBorder1,  8, 4 );
     841        3610 :     mnBottomLine  = ::extract_value< sal_uInt8  >( nBorder1, 12, 4 );
     842        3610 :     mnLeftColor   = ::extract_value< sal_uInt16 >( nBorder1, 16, 7 );
     843        3610 :     mnRightColor  = ::extract_value< sal_uInt16 >( nBorder1, 23, 7 );
     844        3610 :     mnTopColor    = ::extract_value< sal_uInt16 >( nBorder2,  0, 7 );
     845        3610 :     mnBottomColor = ::extract_value< sal_uInt16 >( nBorder2,  7, 7 );
     846        3610 :     mbDiagTLtoBR  = ::get_flag( nBorder1, EXC_XF_DIAGONAL_TL_TO_BR );
     847        3610 :     mbDiagBLtoTR  = ::get_flag( nBorder1, EXC_XF_DIAGONAL_BL_TO_TR );
     848        3610 :     if( mbDiagTLtoBR || mbDiagBLtoTR )
     849             :     {
     850           0 :         mnDiagLine  = ::extract_value< sal_uInt8 >( nBorder2, 21, 4 );
     851           0 :         mnDiagColor = ::extract_value< sal_uInt16 >( nBorder2, 14, 7 );
     852             :     }
     853        3610 :     SetUsedFlags( true, true );
     854        3610 : }
     855             : 
     856           0 : void XclImpCellBorder::FillFromCF8( sal_uInt16 nLineStyle, sal_uInt32 nLineColor, sal_uInt32 nFlags )
     857             : {
     858           0 :     mnLeftLine    = ::extract_value< sal_uInt8  >( nLineStyle,  0, 4 );
     859           0 :     mnRightLine   = ::extract_value< sal_uInt8  >( nLineStyle,  4, 4 );
     860           0 :     mnTopLine     = ::extract_value< sal_uInt8  >( nLineStyle,  8, 4 );
     861           0 :     mnBottomLine  = ::extract_value< sal_uInt8  >( nLineStyle, 12, 4 );
     862           0 :     mnLeftColor   = ::extract_value< sal_uInt16 >( nLineColor,  0, 7 );
     863           0 :     mnRightColor  = ::extract_value< sal_uInt16 >( nLineColor,  7, 7 );
     864           0 :     mnTopColor    = ::extract_value< sal_uInt16 >( nLineColor, 16, 7 );
     865           0 :     mnBottomColor = ::extract_value< sal_uInt16 >( nLineColor, 23, 7 );
     866           0 :     mbLeftUsed    = !::get_flag( nFlags, EXC_CF_BORDER_LEFT );
     867           0 :     mbRightUsed   = !::get_flag( nFlags, EXC_CF_BORDER_RIGHT );
     868           0 :     mbTopUsed     = !::get_flag( nFlags, EXC_CF_BORDER_TOP );
     869           0 :     mbBottomUsed  = !::get_flag( nFlags, EXC_CF_BORDER_BOTTOM );
     870           0 :     mbDiagUsed    = false;
     871           0 : }
     872             : 
     873           0 : bool XclImpCellBorder::HasAnyOuterBorder() const
     874             : {
     875             :     return
     876             :         (mbLeftUsed   && (mnLeftLine != EXC_LINE_NONE)) ||
     877             :         (mbRightUsed  && (mnRightLine != EXC_LINE_NONE)) ||
     878             :         (mbTopUsed    && (mnTopLine != EXC_LINE_NONE)) ||
     879           0 :         (mbBottomUsed && (mnBottomLine != EXC_LINE_NONE));
     880             : }
     881             : 
     882             : namespace {
     883             : 
     884             : /** Converts the passed line style to a ::editeng::SvxBorderLine, or returns false, if style is "no line". */
     885        9570 : bool lclConvertBorderLine( ::editeng::SvxBorderLine& rLine, const XclImpPalette& rPalette, sal_uInt8 nXclLine, sal_uInt16 nXclColor )
     886             : {
     887             :     static const sal_uInt16 ppnLineParam[][ 4 ] =
     888             :     {
     889             :         //  outer width,        type
     890             :         {   0,                  table::BorderLineStyle::SOLID },  // 0 = none
     891             :         {   EXC_BORDER_THIN,    table::BorderLineStyle::SOLID },  // 1 = thin
     892             :         {   EXC_BORDER_MEDIUM,  table::BorderLineStyle::SOLID },  // 2 = medium
     893             :         {   EXC_BORDER_THIN,    table::BorderLineStyle::DASHED }, // 3 = dashed
     894             :         {   EXC_BORDER_THIN,    table::BorderLineStyle::DOTTED }, // 4 = dotted
     895             :         {   EXC_BORDER_THICK,   table::BorderLineStyle::SOLID },  // 5 = thick
     896             :         {   EXC_BORDER_THIN,    table::BorderLineStyle::DOUBLE }, // 6 = double
     897             :         {   EXC_BORDER_HAIR,    table::BorderLineStyle::SOLID },  // 7 = hair
     898             :         {   EXC_BORDER_MEDIUM,  table::BorderLineStyle::DASHED }, // 8 = med dash
     899             :         {   EXC_BORDER_THIN,    table::BorderLineStyle::SOLID },  // 9 = thin dashdot
     900             :         {   EXC_BORDER_MEDIUM,  table::BorderLineStyle::SOLID },  // A = med dashdot
     901             :         {   EXC_BORDER_THIN,    table::BorderLineStyle::SOLID },  // B = thin dashdotdot
     902             :         {   EXC_BORDER_MEDIUM,  table::BorderLineStyle::SOLID },  // C = med dashdotdot
     903             :         {   EXC_BORDER_MEDIUM,  table::BorderLineStyle::SOLID }   // D = med slant dashdot
     904             :     };
     905             : 
     906        9570 :     if( nXclLine == EXC_LINE_NONE )
     907        2824 :         return false;
     908        6746 :     if( nXclLine >= SAL_N_ELEMENTS( ppnLineParam ) )
     909           0 :         nXclLine = EXC_LINE_THIN;
     910             : 
     911        6746 :     rLine.SetColor( rPalette.GetColor( nXclColor ) );
     912        6746 :     rLine.SetWidth( ppnLineParam[ nXclLine ][ 0 ] );
     913             :     rLine.SetBorderLineStyle( static_cast< ::editeng::SvxBorderStyle>(
     914        6746 :                 ppnLineParam[ nXclLine ][ 1 ]) );
     915        6746 :     return true;
     916             : }
     917             : 
     918             : } // namespace
     919             : 
     920        1914 : void XclImpCellBorder::FillToItemSet( SfxItemSet& rItemSet, const XclImpPalette& rPalette, bool bSkipPoolDefs ) const
     921             : {
     922        1914 :     if( mbLeftUsed || mbRightUsed || mbTopUsed || mbBottomUsed )
     923             :     {
     924        1914 :         SvxBoxItem aBoxItem( ATTR_BORDER );
     925        1914 :         ::editeng::SvxBorderLine aLine;
     926        1914 :         if( mbLeftUsed && lclConvertBorderLine( aLine, rPalette, mnLeftLine, mnLeftColor ) )
     927        1600 :             aBoxItem.SetLine( &aLine, BOX_LINE_LEFT );
     928        1914 :         if( mbRightUsed && lclConvertBorderLine( aLine, rPalette, mnRightLine, mnRightColor ) )
     929        1628 :             aBoxItem.SetLine( &aLine, BOX_LINE_RIGHT );
     930        1914 :         if( mbTopUsed && lclConvertBorderLine( aLine, rPalette, mnTopLine, mnTopColor ) )
     931        1756 :             aBoxItem.SetLine( &aLine, BOX_LINE_TOP );
     932        1914 :         if( mbBottomUsed && lclConvertBorderLine( aLine, rPalette, mnBottomLine, mnBottomColor ) )
     933        1762 :             aBoxItem.SetLine( &aLine, BOX_LINE_BOTTOM );
     934        1914 :         ScfTools::PutItem( rItemSet, aBoxItem, bSkipPoolDefs );
     935             :     }
     936        1914 :     if( mbDiagUsed )
     937             :     {
     938        1914 :         SvxLineItem aTLBRItem( ATTR_BORDER_TLBR );
     939        1914 :         SvxLineItem aBLTRItem( ATTR_BORDER_BLTR );
     940        1914 :         ::editeng::SvxBorderLine aLine;
     941        1914 :         if( lclConvertBorderLine( aLine, rPalette, mnDiagLine, mnDiagColor ) )
     942             :         {
     943           0 :             if( mbDiagTLtoBR )
     944           0 :                 aTLBRItem.SetLine( &aLine );
     945           0 :             if( mbDiagBLtoTR )
     946           0 :                 aBLTRItem.SetLine( &aLine );
     947             :         }
     948        1914 :         ScfTools::PutItem( rItemSet, aTLBRItem, bSkipPoolDefs );
     949        1914 :         ScfTools::PutItem( rItemSet, aBLTRItem, bSkipPoolDefs );
     950             :     }
     951        1914 : }
     952             : 
     953             : // ----------------------------------------------------------------------------
     954             : 
     955        3610 : XclImpCellArea::XclImpCellArea()
     956             : {
     957        3610 :     SetUsedFlags( false );
     958        3610 : }
     959             : 
     960        7220 : void XclImpCellArea::SetUsedFlags( bool bUsed )
     961             : {
     962        7220 :     mbForeUsed = mbBackUsed = mbPattUsed = bUsed;
     963        7220 : }
     964             : 
     965           0 : void XclImpCellArea::FillFromXF2( sal_uInt8 nFlags )
     966             : {
     967           0 :     mnPattern = ::get_flagvalue( nFlags, EXC_XF2_BACKGROUND, EXC_PATT_12_5_PERC, EXC_PATT_NONE );
     968           0 :     mnForeColor = EXC_COLOR_BIFF2_BLACK;
     969           0 :     mnBackColor = EXC_COLOR_BIFF2_WHITE;
     970           0 :     SetUsedFlags( true );
     971           0 : }
     972             : 
     973           0 : void XclImpCellArea::FillFromXF3( sal_uInt16 nArea )
     974             : {
     975           0 :     mnPattern   = ::extract_value< sal_uInt8  >( nArea,  0, 6 );
     976           0 :     mnForeColor = ::extract_value< sal_uInt16 >( nArea,  6, 5 );
     977           0 :     mnBackColor = ::extract_value< sal_uInt16 >( nArea, 11, 5 );
     978           0 :     SetUsedFlags( true );
     979           0 : }
     980             : 
     981           0 : void XclImpCellArea::FillFromXF5( sal_uInt32 nArea )
     982             : {
     983           0 :     mnPattern   = ::extract_value< sal_uInt8  >( nArea, 16, 6 );
     984           0 :     mnForeColor = ::extract_value< sal_uInt16 >( nArea,  0, 7 );
     985           0 :     mnBackColor = ::extract_value< sal_uInt16 >( nArea,  7, 7 );
     986           0 :     SetUsedFlags( true );
     987           0 : }
     988             : 
     989        3610 : void XclImpCellArea::FillFromXF8( sal_uInt32 nBorder2, sal_uInt16 nArea )
     990             : {
     991        3610 :     mnPattern   = ::extract_value< sal_uInt8  >( nBorder2, 26, 6 );
     992        3610 :     mnForeColor = ::extract_value< sal_uInt16 >( nArea,     0, 7 );
     993        3610 :     mnBackColor = ::extract_value< sal_uInt16 >( nArea,     7, 7 );
     994        3610 :     SetUsedFlags( true );
     995        3610 : }
     996             : 
     997           0 : void XclImpCellArea::FillFromCF8( sal_uInt16 nPattern, sal_uInt16 nColor, sal_uInt32 nFlags )
     998             : {
     999           0 :     mnForeColor = ::extract_value< sal_uInt16 >( nColor,    0, 7 );
    1000           0 :     mnBackColor = ::extract_value< sal_uInt16 >( nColor,    7, 7 );
    1001           0 :     mnPattern   = ::extract_value< sal_uInt8  >( nPattern, 10, 6 );
    1002           0 :     mbForeUsed  = !::get_flag( nFlags, EXC_CF_AREA_FGCOLOR );
    1003           0 :     mbBackUsed  = !::get_flag( nFlags, EXC_CF_AREA_BGCOLOR );
    1004           0 :     mbPattUsed  = !::get_flag( nFlags, EXC_CF_AREA_PATTERN );
    1005             : 
    1006           0 :     if( mbBackUsed && (!mbPattUsed || (mnPattern == EXC_PATT_SOLID)) )
    1007             :     {
    1008           0 :         mnForeColor = mnBackColor;
    1009           0 :         mnPattern = EXC_PATT_SOLID;
    1010           0 :         mbForeUsed = mbPattUsed = true;
    1011             :     }
    1012           0 :     else if( !mbBackUsed && mbPattUsed && (mnPattern == EXC_PATT_SOLID) )
    1013             :     {
    1014           0 :         mbPattUsed = false;
    1015             :     }
    1016           0 : }
    1017             : 
    1018        2042 : void XclImpCellArea::FillToItemSet( SfxItemSet& rItemSet, const XclImpPalette& rPalette, bool bSkipPoolDefs ) const
    1019             : {
    1020        2042 :     if( mbPattUsed )    // colors may be both unused in cond. formats
    1021             :     {
    1022        2042 :         SvxBrushItem aBrushItem( ATTR_BACKGROUND );
    1023             : 
    1024             :         // do not use IsTransparent() - old Calc filter writes tranparency with different color indexes
    1025        2042 :         if( mnPattern == EXC_PATT_NONE )
    1026             :         {
    1027          96 :             aBrushItem.SetColor( Color( COL_TRANSPARENT ) );
    1028             :         }
    1029             :         else
    1030             :         {
    1031        1946 :             Color aFore( rPalette.GetColor( mbForeUsed ? mnForeColor : EXC_COLOR_WINDOWTEXT ) );
    1032        1946 :             Color aBack( rPalette.GetColor( mbBackUsed ? mnBackColor : EXC_COLOR_WINDOWBACK ) );
    1033        1946 :             aBrushItem.SetColor( XclTools::GetPatternColor( aFore, aBack, mnPattern ) );
    1034             :         }
    1035             : 
    1036        2042 :         ScfTools::PutItem( rItemSet, aBrushItem, bSkipPoolDefs );
    1037             :     }
    1038        2042 : }
    1039             : 
    1040             : 
    1041             : // ----------------------------------------------------------------------------
    1042             : 
    1043        3610 : XclImpXF::XclImpXF( const XclImpRoot& rRoot ) :
    1044             :     XclXFBase( true ),      // default is cell XF
    1045             :     XclImpRoot( rRoot ),
    1046             :     mpStyleSheet( 0 ),
    1047             :     mnXclNumFmt( 0 ),
    1048        3610 :     mnXclFont( 0 )
    1049             : {
    1050        3610 : }
    1051             : 
    1052        7220 : XclImpXF::~XclImpXF()
    1053             : {
    1054        7220 : }
    1055             : 
    1056           0 : void XclImpXF::ReadXF2( XclImpStream& rStrm )
    1057             : {
    1058             :     sal_uInt8 nReadFont, nReadNumFmt, nFlags;
    1059           0 :     rStrm >> nReadFont;
    1060           0 :     rStrm.Ignore( 1 );
    1061           0 :     rStrm >> nReadNumFmt >> nFlags;
    1062             : 
    1063             :     // XF type always cell, no parent, used flags always true
    1064           0 :     SetAllUsedFlags( true );
    1065             : 
    1066             :     // attributes
    1067           0 :     maProtection.FillFromXF2( nReadNumFmt );
    1068           0 :     mnXclFont = nReadFont;
    1069           0 :     mnXclNumFmt = nReadNumFmt & EXC_XF2_VALFMT_MASK;
    1070           0 :     maAlignment.FillFromXF2( nFlags );
    1071           0 :     maBorder.FillFromXF2( nFlags );
    1072           0 :     maArea.FillFromXF2( nFlags );
    1073           0 : }
    1074             : 
    1075           0 : void XclImpXF::ReadXF3( XclImpStream& rStrm )
    1076             : {
    1077             :     sal_uInt32 nBorder;
    1078             :     sal_uInt16 nTypeProt, nAlign, nArea;
    1079             :     sal_uInt8 nReadFont, nReadNumFmt;
    1080           0 :     rStrm >> nReadFont >> nReadNumFmt >> nTypeProt >> nAlign >> nArea >> nBorder;
    1081             : 
    1082             :     // XF type/parent, attribute used flags
    1083           0 :     mbCellXF = !::get_flag( nTypeProt, EXC_XF_STYLE );          // new in BIFF3
    1084           0 :     mnParent = ::extract_value< sal_uInt16 >( nAlign, 4, 12 );  // new in BIFF3
    1085           0 :     SetUsedFlags( ::extract_value< sal_uInt8 >( nTypeProt, 10, 6 ) );
    1086             : 
    1087             :     // attributes
    1088           0 :     maProtection.FillFromXF3( nTypeProt );
    1089           0 :     mnXclFont = nReadFont;
    1090           0 :     mnXclNumFmt = nReadNumFmt;
    1091           0 :     maAlignment.FillFromXF3( nAlign );
    1092           0 :     maBorder.FillFromXF3( nBorder );
    1093           0 :     maArea.FillFromXF3( nArea );                        // new in BIFF3
    1094           0 : }
    1095             : 
    1096           0 : void XclImpXF::ReadXF4( XclImpStream& rStrm )
    1097             : {
    1098             :     sal_uInt32 nBorder;
    1099             :     sal_uInt16 nTypeProt, nAlign, nArea;
    1100             :     sal_uInt8 nReadFont, nReadNumFmt;
    1101           0 :     rStrm >> nReadFont >> nReadNumFmt >> nTypeProt >> nAlign >> nArea >> nBorder;
    1102             : 
    1103             :     // XF type/parent, attribute used flags
    1104           0 :     mbCellXF = !::get_flag( nTypeProt, EXC_XF_STYLE );
    1105           0 :     mnParent = ::extract_value< sal_uInt16 >( nTypeProt, 4, 12 );
    1106           0 :     SetUsedFlags( ::extract_value< sal_uInt8 >( nAlign, 10, 6 ) );
    1107             : 
    1108             :     // attributes
    1109           0 :     maProtection.FillFromXF3( nTypeProt );
    1110           0 :     mnXclFont = nReadFont;
    1111           0 :     mnXclNumFmt = nReadNumFmt;
    1112           0 :     maAlignment.FillFromXF4( nAlign );
    1113           0 :     maBorder.FillFromXF3( nBorder );
    1114           0 :     maArea.FillFromXF3( nArea );
    1115           0 : }
    1116             : 
    1117           0 : void XclImpXF::ReadXF5( XclImpStream& rStrm )
    1118             : {
    1119             :     sal_uInt32 nArea, nBorder;
    1120             :     sal_uInt16 nTypeProt, nAlign;
    1121           0 :     rStrm >> mnXclFont >> mnXclNumFmt >> nTypeProt >> nAlign >> nArea >> nBorder;
    1122             : 
    1123             :     // XF type/parent, attribute used flags
    1124           0 :     mbCellXF = !::get_flag( nTypeProt, EXC_XF_STYLE );
    1125           0 :     mnParent = ::extract_value< sal_uInt16 >( nTypeProt, 4, 12 );
    1126           0 :     SetUsedFlags( ::extract_value< sal_uInt8 >( nAlign, 10, 6 ) );
    1127             : 
    1128             :     // attributes
    1129           0 :     maProtection.FillFromXF3( nTypeProt );
    1130           0 :     maAlignment.FillFromXF5( nAlign );
    1131           0 :     maBorder.FillFromXF5( nBorder, nArea );
    1132           0 :     maArea.FillFromXF5( nArea );
    1133           0 : }
    1134             : 
    1135        3610 : void XclImpXF::ReadXF8( XclImpStream& rStrm )
    1136             : {
    1137             :     sal_uInt32 nBorder1, nBorder2;
    1138             :     sal_uInt16 nTypeProt, nAlign, nMiscAttrib, nArea;
    1139        3610 :     rStrm >> mnXclFont >> mnXclNumFmt >> nTypeProt >> nAlign >> nMiscAttrib >> nBorder1 >> nBorder2 >> nArea;
    1140             : 
    1141             :     // XF type/parent, attribute used flags
    1142        3610 :     mbCellXF = !::get_flag( nTypeProt, EXC_XF_STYLE );
    1143        3610 :     mnParent = ::extract_value< sal_uInt16 >( nTypeProt, 4, 12 );
    1144        3610 :     SetUsedFlags( ::extract_value< sal_uInt8 >( nMiscAttrib, 10, 6 ) );
    1145             : 
    1146             :     // attributes
    1147        3610 :     maProtection.FillFromXF3( nTypeProt );
    1148        3610 :     maAlignment.FillFromXF8( nAlign, nMiscAttrib );
    1149        3610 :     maBorder.FillFromXF8( nBorder1, nBorder2 );
    1150        3610 :     maArea.FillFromXF8( nBorder2, nArea );
    1151        3610 : }
    1152             : 
    1153        3610 : void XclImpXF::ReadXF( XclImpStream& rStrm )
    1154             : {
    1155        3610 :     switch( GetBiff() )
    1156             :     {
    1157           0 :         case EXC_BIFF2: ReadXF2( rStrm );   break;
    1158           0 :         case EXC_BIFF3: ReadXF3( rStrm );   break;
    1159           0 :         case EXC_BIFF4: ReadXF4( rStrm );   break;
    1160           0 :         case EXC_BIFF5: ReadXF5( rStrm );   break;
    1161        3610 :         case EXC_BIFF8: ReadXF8( rStrm );   break;
    1162             :         default:        DBG_ERROR_BIFF();
    1163             :     }
    1164        3610 : }
    1165             : 
    1166      201288 : const ScPatternAttr& XclImpXF::CreatePattern( bool bSkipPoolDefs )
    1167             : {
    1168      201288 :     if( mpPattern.get() )
    1169      198862 :         return *mpPattern;
    1170             : 
    1171             :     // create new pattern attribute set
    1172        2426 :     mpPattern.reset( new ScPatternAttr( GetDoc().GetPool() ) );
    1173        2426 :     SfxItemSet& rItemSet = mpPattern->GetItemSet();
    1174        2426 :     XclImpXF* pParentXF = IsCellXF() ? GetXFBuffer().GetXF( mnParent ) : 0;
    1175             : 
    1176             :     // parent cell style
    1177        2426 :     if( IsCellXF() && !mpStyleSheet )
    1178             :     {
    1179        2102 :         mpStyleSheet = GetXFBuffer().CreateStyleSheet( mnParent );
    1180             : 
    1181             :         /*  Enables mb***Used flags, if the formatting attributes differ from
    1182             :             the passed XF record. In cell XFs Excel uses the cell attributes,
    1183             :             if they differ from the parent style XF.
    1184             :             ...or if the respective flag is not set in parent style XF. */
    1185        2102 :         if( pParentXF )
    1186             :         {
    1187        2102 :             if( !mbProtUsed )
    1188        2062 :                 mbProtUsed = !pParentXF->mbProtUsed || !(maProtection == pParentXF->maProtection);
    1189        2102 :             if( !mbFontUsed )
    1190         652 :                 mbFontUsed = !pParentXF->mbFontUsed || (mnXclFont != pParentXF->mnXclFont);
    1191        2102 :             if( !mbFmtUsed )
    1192        1036 :                 mbFmtUsed = !pParentXF->mbFmtUsed || (mnXclNumFmt != pParentXF->mnXclNumFmt);
    1193        2102 :             if( !mbAlignUsed )
    1194         606 :                 mbAlignUsed = !pParentXF->mbAlignUsed || !(maAlignment == pParentXF->maAlignment);
    1195        2102 :             if( !mbBorderUsed )
    1196         294 :                 mbBorderUsed = !pParentXF->mbBorderUsed || !(maBorder == pParentXF->maBorder);
    1197        2102 :             if( !mbAreaUsed )
    1198         300 :                 mbAreaUsed = !pParentXF->mbAreaUsed || !(maArea == pParentXF->maArea);
    1199             :         }
    1200             :     }
    1201             : 
    1202             :     // cell protection
    1203        2426 :     if( mbProtUsed )
    1204          92 :         maProtection.FillToItemSet( rItemSet, bSkipPoolDefs );
    1205             : 
    1206             :     // font
    1207        2426 :     if( mbFontUsed )
    1208        1764 :         GetFontBuffer().FillToItemSet( rItemSet, EXC_FONTITEM_CELL, mnXclFont, bSkipPoolDefs );
    1209             : 
    1210             :     // value format
    1211        2426 :     if( mbFmtUsed )
    1212             :     {
    1213        1134 :         GetNumFmtBuffer().FillToItemSet( rItemSet, mnXclNumFmt, bSkipPoolDefs );
    1214             :         // Trace occurrences of Windows date formats
    1215        1134 :         GetTracer().TraceDates( mnXclNumFmt );
    1216             :     }
    1217             : 
    1218             :     // alignment
    1219        2426 :     if( mbAlignUsed )
    1220        1540 :         maAlignment.FillToItemSet( rItemSet, GetFontBuffer().GetFont( mnXclFont ), bSkipPoolDefs );
    1221             : 
    1222             :     // border
    1223        2426 :     if( mbBorderUsed )
    1224             :     {
    1225        1914 :         maBorder.FillToItemSet( rItemSet, GetPalette(), bSkipPoolDefs );
    1226        1914 :         GetTracer().TraceBorderLineStyle(maBorder.mnLeftLine > EXC_LINE_HAIR ||
    1227             :             maBorder.mnRightLine > EXC_LINE_HAIR || maBorder.mnTopLine > EXC_LINE_HAIR ||
    1228        3828 :             maBorder.mnBottomLine > EXC_LINE_HAIR );
    1229             :     }
    1230             : 
    1231             :     // area
    1232        2426 :     if( mbAreaUsed )
    1233             :     {
    1234        2042 :         maArea.FillToItemSet( rItemSet, GetPalette(), bSkipPoolDefs );
    1235        2042 :         GetTracer().TraceFillPattern(maArea.mnPattern != EXC_PATT_NONE &&
    1236        4084 :             maArea.mnPattern != EXC_PATT_SOLID);
    1237             :     }
    1238             : 
    1239             :     /*  #i38709# Decide which rotation reference mode to use. If any outer
    1240             :         border line of the cell is set (either explicitly or via cell style),
    1241             :         and the cell contents are rotated, set rotation reference to bottom of
    1242             :         cell. This causes the borders to be painted rotated with the text. */
    1243        2426 :     if( mbAlignUsed || mbBorderUsed )
    1244             :     {
    1245        2018 :         SvxRotateMode eRotateMode = SVX_ROTATE_MODE_STANDARD;
    1246        2018 :         const XclImpCellAlign* pAlign = mbAlignUsed ? &maAlignment : (pParentXF ? &pParentXF->maAlignment : 0);
    1247        2018 :         const XclImpCellBorder* pBorder = mbBorderUsed ? &maBorder : (pParentXF ? &pParentXF->maBorder : 0);
    1248        2018 :         if( pAlign && pBorder && (0 < pAlign->mnRotation) && (pAlign->mnRotation <= 180) && pBorder->HasAnyOuterBorder() )
    1249           0 :             eRotateMode = SVX_ROTATE_MODE_BOTTOM;
    1250        2018 :         ScfTools::PutItem( rItemSet, SvxRotateModeItem( eRotateMode, ATTR_ROTATE_MODE ), bSkipPoolDefs );
    1251             :     }
    1252             : 
    1253             :     // Excel's cell margins are different from Calc's default margins.
    1254        2426 :     SvxMarginItem aItem(40, 40, 40, 40, ATTR_MARGIN);
    1255        2426 :     ScfTools::PutItem(rItemSet, aItem, bSkipPoolDefs);
    1256             : 
    1257        2426 :     return *mpPattern;
    1258             : }
    1259             : 
    1260      200974 : void XclImpXF::ApplyPatternToAttrList(
    1261             :     list<ScAttrEntry>& rAttrs, SCROW nRow1, SCROW nRow2, sal_uInt32 nForceScNumFmt)
    1262             : {
    1263             :     // force creation of cell style and hard formatting, do it here to have mpStyleSheet
    1264      200974 :     CreatePattern();
    1265      200974 :     ScPatternAttr& rPat = *mpPattern;
    1266             : 
    1267             :     // insert into document
    1268      200974 :     ScDocument& rDoc = GetDoc();
    1269             : 
    1270      200974 :     if (IsCellXF())
    1271             :     {
    1272      200434 :         if (mpStyleSheet)
    1273             :         {
    1274             :             // Apply style sheet.  Don't clear the direct formats.
    1275      200434 :             rPat.SetStyleSheet(mpStyleSheet, false);
    1276             :         }
    1277             :         else
    1278             :         {
    1279             :             // When the cell format is not associated with any style, use the
    1280             :             // 'Default' style.  Some buggy XLS docs generated by apps other
    1281             :             // than Excel (such as 1C) may not have any built-in styles at
    1282             :             // all.
    1283           0 :             ScStyleSheetPool* pStylePool = rDoc.GetStyleSheetPool();
    1284           0 :             if (pStylePool)
    1285             :             {
    1286             :                 ScStyleSheet* pStyleSheet = static_cast<ScStyleSheet*>(
    1287             :                     pStylePool->Find(
    1288           0 :                         ScGlobal::GetRscString(STR_STYLENAME_STANDARD), SFX_STYLE_FAMILY_PARA));
    1289             : 
    1290           0 :                 if (pStyleSheet)
    1291           0 :                     rPat.SetStyleSheet(pStyleSheet, false);
    1292             :             }
    1293             : 
    1294             :         }
    1295             :     }
    1296             : 
    1297      200974 :     if (nForceScNumFmt != NUMBERFORMAT_ENTRY_NOT_FOUND)
    1298             :     {
    1299           0 :         ScPatternAttr aNumPat(rDoc.GetPool());
    1300           0 :         GetNumFmtBuffer().FillScFmtToItemSet(aNumPat.GetItemSet(), nForceScNumFmt);
    1301           0 :         rPat.GetItemSet().Put(aNumPat.GetItemSet());
    1302             :     }
    1303             : 
    1304             :     // Make sure we skip unnamed styles.
    1305      200974 :     if (rPat.GetStyleName())
    1306             :     {
    1307             :         // Check for a gap between the last entry and this one.
    1308      200434 :         bool bHasGap = false;
    1309      200434 :         if (rAttrs.empty() && nRow1 > 0)
    1310             :             // First attribute range doesn't start at row 0.
    1311        7358 :             bHasGap = true;
    1312             : 
    1313      200434 :         if (!rAttrs.empty() && rAttrs.back().nRow + 1 < nRow1)
    1314       29712 :             bHasGap = true;
    1315             : 
    1316      200434 :         if (bHasGap)
    1317             :         {
    1318             :             // Fill this gap with the default pattern.
    1319             :             ScAttrEntry aEntry;
    1320       37070 :             aEntry.nRow = nRow1 - 1;
    1321       37070 :             aEntry.pPattern = rDoc.GetDefPattern();
    1322       37070 :             rAttrs.push_back(aEntry);
    1323             :         }
    1324             : 
    1325             :         ScAttrEntry aEntry;
    1326      200434 :         aEntry.nRow = nRow2;
    1327      200434 :         aEntry.pPattern = static_cast<const ScPatternAttr*>(&rDoc.GetPool()->Put(rPat));
    1328      200434 :         rAttrs.push_back(aEntry);
    1329             :     }
    1330      200974 : }
    1331             : 
    1332           0 : void XclImpXF::ApplyPattern(
    1333             :         SCCOL nScCol1, SCROW nScRow1, SCCOL nScCol2, SCROW nScRow2,
    1334             :         SCTAB nScTab, sal_uLong nForceScNumFmt )
    1335             : {
    1336             :     // force creation of cell style and hard formatting, do it here to have mpStyleSheet
    1337           0 :     const ScPatternAttr& rPattern = CreatePattern();
    1338             : 
    1339             :     // insert into document
    1340           0 :     ScDocument& rDoc = GetDoc();
    1341           0 :     if( IsCellXF() && mpStyleSheet )
    1342           0 :         rDoc.ApplyStyleAreaTab( nScCol1, nScRow1, nScCol2, nScRow2, nScTab, *mpStyleSheet );
    1343           0 :     if( HasUsedFlags() )
    1344           0 :         rDoc.ApplyPatternAreaTab( nScCol1, nScRow1, nScCol2, nScRow2, nScTab, rPattern );
    1345             : 
    1346             :     // #108770# apply special number format
    1347           0 :     if( nForceScNumFmt != NUMBERFORMAT_ENTRY_NOT_FOUND )
    1348             :     {
    1349           0 :         ScPatternAttr aPattern( GetDoc().GetPool() );
    1350           0 :         GetNumFmtBuffer().FillScFmtToItemSet( aPattern.GetItemSet(), nForceScNumFmt );
    1351           0 :         rDoc.ApplyPatternAreaTab( nScCol1, nScRow1, nScCol2, nScRow2, nScTab, aPattern );
    1352             :     }
    1353           0 : }
    1354             : 
    1355           0 : /*static*/ void XclImpXF::ApplyPatternForBiff2CellFormat( const XclImpRoot& rRoot,
    1356             :         const ScAddress& rScPos, sal_uInt8 nFlags1, sal_uInt8 nFlags2, sal_uInt8 nFlags3 )
    1357             : {
    1358             :     /*  Create an XF object and let it do the work. We will have access to its
    1359             :         private members here. */
    1360           0 :     XclImpXF aXF( rRoot );
    1361             : 
    1362             :     // no used flags available in BIFF2 (always true)
    1363           0 :     aXF.SetAllUsedFlags( true );
    1364             : 
    1365             :     // set the attributes
    1366           0 :     aXF.maProtection.FillFromXF2( nFlags1 );
    1367           0 :     aXF.maAlignment.FillFromXF2( nFlags3 );
    1368           0 :     aXF.maBorder.FillFromXF2( nFlags3 );
    1369           0 :     aXF.maArea.FillFromXF2( nFlags3 );
    1370           0 :     aXF.mnXclNumFmt = ::extract_value< sal_uInt16 >( nFlags2, 0, 6 );
    1371           0 :     aXF.mnXclFont = ::extract_value< sal_uInt16 >( nFlags2, 6, 2 );
    1372             : 
    1373             :     // write the attributes to the cell
    1374           0 :     aXF.ApplyPattern( rScPos.Col(), rScPos.Row(), rScPos.Col(), rScPos.Row(), rScPos.Tab() );
    1375           0 : }
    1376             : 
    1377        3610 : void XclImpXF::SetUsedFlags( sal_uInt8 nUsedFlags )
    1378             : {
    1379             :     /*  Notes about finding the mb***Used flags:
    1380             :         - In cell XFs a *set* bit means a used attribute.
    1381             :         - In style XFs a *cleared* bit means a used attribute.
    1382             :         The mb***Used members always store true, if the attribute is used.
    1383             :         The "mbCellXF == ::get_flag(...)" construct evaluates to true in
    1384             :         both mentioned cases: cell XF and set bit; or style XF and cleared bit.
    1385             :      */
    1386        3610 :     mbProtUsed   = (mbCellXF == ::get_flag( nUsedFlags, EXC_XF_DIFF_PROT ));
    1387        3610 :     mbFontUsed   = (mbCellXF == ::get_flag( nUsedFlags, EXC_XF_DIFF_FONT ));
    1388        3610 :     mbFmtUsed    = (mbCellXF == ::get_flag( nUsedFlags, EXC_XF_DIFF_VALFMT ));
    1389        3610 :     mbAlignUsed  = (mbCellXF == ::get_flag( nUsedFlags, EXC_XF_DIFF_ALIGN ));
    1390        3610 :     mbBorderUsed = (mbCellXF == ::get_flag( nUsedFlags, EXC_XF_DIFF_BORDER ));
    1391        3610 :     mbAreaUsed   = (mbCellXF == ::get_flag( nUsedFlags, EXC_XF_DIFF_AREA ));
    1392        3610 : }
    1393             : 
    1394             : // ----------------------------------------------------------------------------
    1395             : 
    1396         962 : XclImpStyle::XclImpStyle( const XclImpRoot& rRoot ) :
    1397             :     XclImpRoot( rRoot ),
    1398             :     mnXfId( EXC_XF_NOTFOUND ),
    1399             :     mnBuiltinId( EXC_STYLE_USERDEF ),
    1400             :     mnLevel( EXC_STYLE_NOLEVEL ),
    1401             :     mbBuiltin( false ),
    1402             :     mbCustom( false ),
    1403             :     mbHidden( false ),
    1404         962 :     mpStyleSheet( 0 )
    1405             : {
    1406         962 : }
    1407             : 
    1408         962 : void XclImpStyle::ReadStyle( XclImpStream& rStrm )
    1409             : {
    1410             :     OSL_ENSURE_BIFF( GetBiff() >= EXC_BIFF3 );
    1411             : 
    1412             :     sal_uInt16 nXFIndex;
    1413         962 :     rStrm >> nXFIndex;
    1414         962 :     mnXfId = nXFIndex & EXC_STYLE_XFMASK;
    1415         962 :     mbBuiltin = ::get_flag( nXFIndex, EXC_STYLE_BUILTIN );
    1416             : 
    1417         962 :     if( mbBuiltin )
    1418             :     {
    1419         278 :         rStrm >> mnBuiltinId >> mnLevel;
    1420             :     }
    1421             :     else
    1422             :     {
    1423         684 :         maName = (GetBiff() <= EXC_BIFF5) ? rStrm.ReadByteString( false ) : rStrm.ReadUniString();
    1424             :         // #i103281# check if this is a new built-in style introduced in XL2007
    1425         684 :         if( (GetBiff() == EXC_BIFF8) && (rStrm.GetNextRecId() == EXC_ID_STYLEEXT) && rStrm.StartNextRecord() )
    1426             :         {
    1427             :             sal_uInt8 nExtFlags;
    1428         414 :             rStrm.Ignore( 12 );
    1429         414 :             rStrm >> nExtFlags;
    1430         414 :             mbBuiltin = ::get_flag( nExtFlags, EXC_STYLEEXT_BUILTIN );
    1431         414 :             mbCustom = ::get_flag( nExtFlags, EXC_STYLEEXT_CUSTOM );
    1432         414 :             mbHidden = ::get_flag( nExtFlags, EXC_STYLEEXT_HIDDEN );
    1433         414 :             if( mbBuiltin )
    1434             :             {
    1435         410 :                 rStrm.Ignore( 1 );  // category
    1436         410 :                 rStrm >> mnBuiltinId >> mnLevel;
    1437             :             }
    1438             :         }
    1439             :     }
    1440         962 : }
    1441             : 
    1442        2376 : ScStyleSheet* XclImpStyle::CreateStyleSheet()
    1443             : {
    1444             :     // #i1624# #i1768# ignore unnamed user styles
    1445        2376 :     if( !mpStyleSheet && (maFinalName.Len() > 0) )
    1446             :     {
    1447         314 :         bool bCreatePattern = false;
    1448         314 :         XclImpXF* pXF = GetXFBuffer().GetXF( mnXfId );
    1449             : 
    1450         314 :         bool bDefStyle = mbBuiltin && (mnBuiltinId == EXC_STYLE_NORMAL);
    1451         314 :         if( bDefStyle )
    1452             :         {
    1453             :             // set all flags to true to get all items in XclImpXF::CreatePattern()
    1454          36 :             if( pXF ) pXF->SetAllUsedFlags( true );
    1455             :             // use existing "Default" style sheet
    1456          36 :             mpStyleSheet = static_cast< ScStyleSheet* >( GetStyleSheetPool().Find(
    1457          36 :                 ScGlobal::GetRscString( STR_STYLENAME_STANDARD ), SFX_STYLE_FAMILY_PARA ) );
    1458             :             OSL_ENSURE( mpStyleSheet, "XclImpStyle::CreateStyleSheet - Default style not found" );
    1459          36 :             bCreatePattern = true;
    1460             :         }
    1461             :         else
    1462             :         {
    1463             :             /*  #i103281# do not create another style sheet of the same name,
    1464             :                 if it exists already. This is needed to prevent that styles
    1465             :                 pasted from clipboard get duplicated over and over. */
    1466         278 :             mpStyleSheet = static_cast< ScStyleSheet* >( GetStyleSheetPool().Find( maFinalName, SFX_STYLE_FAMILY_PARA ) );
    1467         278 :             if( !mpStyleSheet )
    1468             :             {
    1469         278 :                 mpStyleSheet = &static_cast< ScStyleSheet& >( GetStyleSheetPool().Make( maFinalName, SFX_STYLE_FAMILY_PARA, SFXSTYLEBIT_USERDEF ) );
    1470         278 :                 bCreatePattern = true;
    1471             :             }
    1472             :         }
    1473             : 
    1474             :         // bDefStyle==true omits default pool items in CreatePattern()
    1475         314 :         if( bCreatePattern && mpStyleSheet && pXF )
    1476         314 :             mpStyleSheet->GetItemSet().Put( pXF->CreatePattern( bDefStyle ).GetItemSet() );
    1477             :     }
    1478        2376 :     return mpStyleSheet;
    1479             : }
    1480             : 
    1481         962 : void XclImpStyle::CreateUserStyle( const String& rFinalName )
    1482             : {
    1483         962 :     maFinalName = rFinalName;
    1484         962 :     if( !IsBuiltin() || mbCustom )
    1485         274 :         CreateStyleSheet();
    1486         962 : }
    1487             : 
    1488             : // ----------------------------------------------------------------------------
    1489             : 
    1490          44 : XclImpXFBuffer::XclImpXFBuffer( const XclImpRoot& rRoot ) :
    1491          44 :     XclImpRoot( rRoot )
    1492             : {
    1493          44 : }
    1494             : 
    1495           0 : void XclImpXFBuffer::Initialize()
    1496             : {
    1497           0 :     maXFList.clear();
    1498           0 :     maBuiltinStyles.clear();
    1499           0 :     maUserStyles.clear();
    1500           0 :     maStylesByXf.clear();
    1501           0 : }
    1502             : 
    1503        3610 : void XclImpXFBuffer::ReadXF( XclImpStream& rStrm )
    1504             : {
    1505        3610 :     XclImpXF* pXF = new XclImpXF( GetRoot() );
    1506        3610 :     pXF->ReadXF( rStrm );
    1507        3610 :     maXFList.push_back( pXF );
    1508        3610 : }
    1509             : 
    1510         962 : void XclImpXFBuffer::ReadStyle( XclImpStream& rStrm )
    1511             : {
    1512         962 :     XclImpStyle* pStyle = new XclImpStyle( GetRoot() );
    1513         962 :     pStyle->ReadStyle( rStrm );
    1514         962 :     (pStyle->IsBuiltin() ? maBuiltinStyles : maUserStyles).push_back( pStyle );
    1515             :     OSL_ENSURE( maStylesByXf.count( pStyle->GetXfId() ) == 0, "XclImpXFBuffer::ReadStyle - multiple styles with equal XF identifier" );
    1516         962 :     maStylesByXf[ pStyle->GetXfId() ] = pStyle;
    1517         962 : }
    1518             : 
    1519       20962 : sal_uInt16 XclImpXFBuffer::GetFontIndex( sal_uInt16 nXFIndex ) const
    1520             : {
    1521       20962 :     const XclImpXF* pXF = GetXF( nXFIndex );
    1522       20962 :     return pXF ? pXF->GetFontIndex() : EXC_FONT_NOTFOUND;
    1523             : }
    1524             : 
    1525       20962 : const XclImpFont* XclImpXFBuffer::GetFont( sal_uInt16 nXFIndex ) const
    1526             : {
    1527       20962 :     return GetFontBuffer().GetFont( GetFontIndex( nXFIndex ) );
    1528             : }
    1529             : 
    1530             : namespace {
    1531             : 
    1532             : /** Functor for case-insensitive string comparison, usable in maps etc. */
    1533             : struct IgnoreCaseCompare
    1534             : {
    1535       16556 :     inline bool operator()( const String& rName1, const String& rName2 ) const
    1536       16556 :         { return rName1.CompareIgnoreCaseToAscii( rName2 ) == COMPARE_LESS; }
    1537             : };
    1538             : 
    1539             : } // namespace
    1540             : 
    1541          42 : void XclImpXFBuffer::CreateUserStyles()
    1542             : {
    1543             :     // calculate final names of all styles
    1544             :     typedef ::std::map< String, XclImpStyle*, IgnoreCaseCompare > CellStyleNameMap;
    1545             :     typedef ::std::vector< XclImpStyle* > XclImpStyleVector;
    1546             : 
    1547          42 :     CellStyleNameMap aCellStyles;
    1548          42 :     XclImpStyleVector aConflictNameStyles;
    1549             : 
    1550             :     /*  First, reserve style names that are built-in in Calc. This causes that
    1551             :         imported cell styles get different unused names and thus do not try to
    1552             :         overwrite these built-in styles. For BIFF4 workbooks (which contain a
    1553             :         separate list of cell styles per sheet), reserve all existing styles if
    1554             :         current sheet is not the first sheet (this styles buffer will be
    1555             :         initialized again for every new sheet). This will create unique names
    1556             :         for styles in different sheets with the same name. Assuming that the
    1557             :         BIFF4W import filter is never used to import from clipboard... */
    1558          42 :     bool bReserveAll = (GetBiff() == EXC_BIFF4) && (GetCurrScTab() > 0);
    1559          42 :     SfxStyleSheetIterator aStyleIter( GetDoc().GetStyleSheetPool(), SFX_STYLE_FAMILY_PARA );
    1560          42 :     String aStandardName = ScGlobal::GetRscString( STR_STYLENAME_STANDARD );
    1561         252 :     for( SfxStyleSheetBase* pStyleSheet = aStyleIter.First(); pStyleSheet; pStyleSheet = aStyleIter.Next() )
    1562         210 :         if( (pStyleSheet->GetName() != aStandardName) && (bReserveAll || !pStyleSheet->IsUserDefined()) )
    1563         168 :             if( aCellStyles.count( pStyleSheet->GetName() ) == 0 )
    1564         168 :                 aCellStyles[ pStyleSheet->GetName() ] = 0;
    1565             : 
    1566             :     /*  Calculate names of built-in styles. Store styles with reserved names
    1567             :         in the aConflictNameStyles list. */
    1568         730 :     for( XclImpStyleList::iterator itStyle = maBuiltinStyles.begin(); itStyle != maBuiltinStyles.end(); ++itStyle )
    1569             :     {
    1570         688 :         String aStyleName = XclTools::GetBuiltInStyleName( itStyle->GetBuiltinId(), itStyle->GetName(), itStyle->GetLevel() );
    1571             :         OSL_ENSURE( bReserveAll || (aCellStyles.count( aStyleName ) == 0),
    1572             :             "XclImpXFBuffer::CreateUserStyles - multiple styles with equal built-in identifier" );
    1573         688 :         if( aCellStyles.count( aStyleName ) > 0 )
    1574           0 :             aConflictNameStyles.push_back( &(*itStyle) );
    1575             :         else
    1576         688 :             aCellStyles[ aStyleName ] = &(*itStyle);
    1577         688 :     }
    1578             : 
    1579             :     /*  Calculate names of user defined styles. Store styles with reserved
    1580             :         names in the aConflictNameStyles list. */
    1581         316 :     for( XclImpStyleList::iterator itStyle = maUserStyles.begin(); itStyle != maUserStyles.end(); ++itStyle )
    1582             :     {
    1583             :         // #i1624# #i1768# ignore unnamed user styles
    1584         274 :         if( itStyle->GetName().Len() > 0 )
    1585             :         {
    1586         274 :             if( aCellStyles.count( itStyle->GetName() ) > 0 )
    1587           0 :                 aConflictNameStyles.push_back( &(*itStyle) );
    1588             :             else
    1589         274 :                 aCellStyles[ itStyle->GetName() ] = &(*itStyle);
    1590             :         }
    1591             :     }
    1592             : 
    1593             :     // find unused names for all styles with conflicting names
    1594          42 :     for( XclImpStyleVector::iterator aIt = aConflictNameStyles.begin(), aEnd = aConflictNameStyles.end(); aIt != aEnd; ++aIt )
    1595             :     {
    1596           0 :         XclImpStyle* pStyle = *aIt;
    1597           0 :         String aUnusedName;
    1598           0 :         sal_Int32 nIndex = 0;
    1599           0 :         do
    1600             :         {
    1601           0 :             aUnusedName.Assign( pStyle->GetName() ).Append( ' ' ).Append( String::CreateFromInt32( ++nIndex ) );
    1602             :         }
    1603           0 :         while( aCellStyles.count( aUnusedName ) > 0 );
    1604           0 :         aCellStyles[ aUnusedName ] = pStyle;
    1605           0 :     }
    1606             : 
    1607             :     // set final names and create user-defined and modified built-in cell styles
    1608        1172 :     for( CellStyleNameMap::iterator aIt = aCellStyles.begin(), aEnd = aCellStyles.end(); aIt != aEnd; ++aIt )
    1609        1130 :         if( aIt->second )
    1610        1004 :             aIt->second->CreateUserStyle( aIt->first );
    1611          42 : }
    1612             : 
    1613        2102 : ScStyleSheet* XclImpXFBuffer::CreateStyleSheet( sal_uInt16 nXFIndex )
    1614             : {
    1615        2102 :     XclImpStyleMap::iterator aIt = maStylesByXf.find( nXFIndex );
    1616        2102 :     return (aIt == maStylesByXf.end()) ? 0 : aIt->second->CreateStyleSheet();
    1617             : }
    1618             : 
    1619             : // Buffer for XF indexes in cells =============================================
    1620             : 
    1621           8 : IMPL_FIXEDMEMPOOL_NEWDEL( XclImpXFRange )
    1622             : 
    1623      690392 : bool XclImpXFRange::Expand( SCROW nScRow, const XclImpXFIndex& rXFIndex )
    1624             : {
    1625      690392 :     if( maXFIndex != rXFIndex )
    1626      123246 :         return false;
    1627             : 
    1628      567146 :     if( mnScRow2 + 1 == nScRow )
    1629             :     {
    1630      554798 :         ++mnScRow2;
    1631      554798 :         return true;
    1632             :     }
    1633       12348 :     if( mnScRow1 > 0 && (mnScRow1 - 1 == nScRow) )
    1634             :     {
    1635           0 :         --mnScRow1;
    1636           0 :         return true;
    1637             :     }
    1638             : 
    1639       12348 :     return false;
    1640             : }
    1641             : 
    1642        4396 : bool XclImpXFRange::Expand( const XclImpXFRange& rNextRange )
    1643             : {
    1644             :     OSL_ENSURE( mnScRow2 < rNextRange.mnScRow1, "XclImpXFRange::Expand - rows out of order" );
    1645        4396 :     if( (maXFIndex == rNextRange.maXFIndex) && (mnScRow2 + 1 == rNextRange.mnScRow1) )
    1646             :     {
    1647        1140 :         mnScRow2 = rNextRange.mnScRow2;
    1648        1140 :         return true;
    1649             :     }
    1650        3256 :     return false;
    1651             : }
    1652             : 
    1653             : // ----------------------------------------------------------------------------
    1654             : 
    1655       21812 : void XclImpXFRangeColumn::SetDefaultXF( const XclImpXFIndex& rXFIndex )
    1656             : {
    1657             :     // List should be empty when inserting the default column format.
    1658             :     // Later explicit SetXF() calls will break up this range.
    1659             :     OSL_ENSURE( maIndexList.empty(), "XclImpXFRangeColumn::SetDefaultXF - Setting Default Column XF is not empty" );
    1660             : 
    1661             :     // insert a complete row range with one insert.
    1662       21812 :     maIndexList.push_back( new XclImpXFRange( 0, MAXROW, rXFIndex ) );
    1663       21812 : }
    1664             : 
    1665             : // ----------------------------------------------------------------------------
    1666             : 
    1667      728684 : void XclImpXFRangeColumn::SetXF( SCROW nScRow, const XclImpXFIndex& rXFIndex )
    1668             : {
    1669             :     XclImpXFRange* pPrevRange;
    1670             :     XclImpXFRange* pNextRange;
    1671             :     sal_uLong nNextIndex;
    1672             : 
    1673      728684 :     Find( pPrevRange, pNextRange, nNextIndex, nScRow );
    1674             : 
    1675             :     // previous range:
    1676             :     // try to overwrite XF (if row is contained in) or try to expand range
    1677      728684 :     if( pPrevRange )
    1678             :     {
    1679      707840 :         if( pPrevRange->Contains( nScRow ) )        // overwrite old XF
    1680             :         {
    1681      207658 :             if( rXFIndex == pPrevRange->maXFIndex )
    1682             :                 return;
    1683             : 
    1684      205710 :             SCROW nFirstScRow = pPrevRange->mnScRow1;
    1685      205710 :             SCROW nLastScRow = pPrevRange->mnScRow2;
    1686      205710 :             sal_uLong nIndex = nNextIndex - 1;
    1687      205710 :             XclImpXFRange* pThisRange = pPrevRange;
    1688      205710 :             pPrevRange = (nIndex > 0 && nIndex <= maIndexList.size()) ? &(maIndexList[ nIndex - 1 ]) : 0;
    1689             : 
    1690      205710 :             if( nFirstScRow == nLastScRow )         // replace solely XF
    1691             :             {
    1692        2134 :                 pThisRange->maXFIndex = rXFIndex;
    1693        2134 :                 TryConcatPrev( nNextIndex );        // try to concat. next with this
    1694        2134 :                 TryConcatPrev( nIndex );            // try to concat. this with previous
    1695             :             }
    1696      203576 :             else if( nFirstScRow == nScRow )        // replace first XF
    1697             :             {
    1698      191964 :                 ++(pThisRange->mnScRow1);
    1699             :                 // try to concatenate with previous of this
    1700      191964 :                 if( !pPrevRange || !pPrevRange->Expand( nScRow, rXFIndex ) )
    1701       36822 :                     Insert( new XclImpXFRange( nScRow, rXFIndex ), nIndex );
    1702             :             }
    1703       11612 :             else if( nLastScRow == nScRow )         // replace last XF
    1704             :             {
    1705           0 :                 --(pThisRange->mnScRow2);
    1706           0 :                 if( !pNextRange || !pNextRange->Expand( nScRow, rXFIndex ) )
    1707           0 :                     Insert( new XclImpXFRange( nScRow, rXFIndex ), nNextIndex );
    1708             :             }
    1709             :             else                                    // insert in the middle of the range
    1710             :             {
    1711       11612 :                 pThisRange->mnScRow1 = nScRow + 1;
    1712             :                 // List::Insert() moves entries towards end of list, so insert twice at nIndex
    1713       11612 :                 Insert( new XclImpXFRange( nScRow, rXFIndex ), nIndex );
    1714       11612 :                 Insert( new XclImpXFRange( nFirstScRow, nScRow - 1, pThisRange->maXFIndex ), nIndex );
    1715             :             }
    1716             :             return;
    1717             :         }
    1718      500182 :         else if( pPrevRange->Expand( nScRow, rXFIndex ) )    // try to expand
    1719             :         {
    1720      399656 :             TryConcatPrev( nNextIndex );    // try to concatenate next with expanded
    1721             :             return;
    1722             :         }
    1723             :     }
    1724             : 
    1725             :     // try to expand next range
    1726      121370 :     if( pNextRange && pNextRange->Expand( nScRow, rXFIndex ) )
    1727             :         return;
    1728             : 
    1729             :     // create new range
    1730      121370 :     Insert( new XclImpXFRange( nScRow, rXFIndex ), nNextIndex );
    1731             : }
    1732             : 
    1733      181416 : void XclImpXFRangeColumn::Insert(XclImpXFRange* pXFRange, sal_uLong nIndex)
    1734             : {
    1735      181416 :     maIndexList.insert( maIndexList.begin() + nIndex, pXFRange );
    1736      181416 : }
    1737             : 
    1738      728684 : void XclImpXFRangeColumn::Find(
    1739             :         XclImpXFRange*& rpPrevRange, XclImpXFRange*& rpNextRange,
    1740             :         sal_uLong& rnNextIndex, SCROW nScRow )
    1741             : {
    1742             : 
    1743             :     // test whether list is empty
    1744      728684 :     if( maIndexList.empty() )
    1745             :     {
    1746       20804 :         rpPrevRange = rpNextRange = 0;
    1747       20804 :         rnNextIndex = 0;
    1748       20804 :         return;
    1749             :     }
    1750             : 
    1751      707880 :     rpPrevRange = &maIndexList.front();
    1752      707880 :     rpNextRange = &maIndexList.back();
    1753             : 
    1754             :     // test whether row is at end of list (contained in or behind last range)
    1755             :     // rpPrevRange will contain a possible existing row
    1756      707880 :     if( rpNextRange->mnScRow1 <= nScRow )
    1757             :     {
    1758      688368 :         rpPrevRange = rpNextRange;
    1759      688368 :         rpNextRange = 0;
    1760      688368 :         rnNextIndex = maIndexList.size();
    1761      688368 :         return;
    1762             :     }
    1763             : 
    1764             :     // test whether row is at beginning of list (really before first range)
    1765       19512 :     if( nScRow < rpPrevRange->mnScRow1 )
    1766             :     {
    1767          40 :         rpNextRange = rpPrevRange;
    1768          40 :         rpPrevRange = 0;
    1769          40 :         rnNextIndex = 0;
    1770          40 :         return;
    1771             :     }
    1772             : 
    1773             :     // loop: find range entries before and after new row
    1774             :     // break the loop if there is no more range between first and last -or-
    1775             :     // if rpPrevRange contains nScRow (rpNextRange will never contain nScRow)
    1776       19472 :     sal_uLong nPrevIndex = 0;
    1777             :     sal_uLong nMidIndex;
    1778       19472 :     rnNextIndex = maIndexList.size() - 1;
    1779             :     XclImpXFRange* pMidRange;
    1780      104840 :     while( ((rnNextIndex - nPrevIndex) > 1) && (rpPrevRange->mnScRow2 < nScRow) )
    1781             :     {
    1782       65896 :         nMidIndex = (nPrevIndex + rnNextIndex) / 2;
    1783       65896 :         pMidRange = &maIndexList[nMidIndex];
    1784             :         OSL_ENSURE( pMidRange, "XclImpXFRangeColumn::Find - missing XF index range" );
    1785       65896 :         if( nScRow < pMidRange->mnScRow1 )      // row is really before pMidRange
    1786             :         {
    1787       11090 :             rpNextRange = pMidRange;
    1788       11090 :             rnNextIndex = nMidIndex;
    1789             :         }
    1790             :         else                                    // row is in or after pMidRange
    1791             :         {
    1792       54806 :             rpPrevRange = pMidRange;
    1793       54806 :             nPrevIndex = nMidIndex;
    1794             :         }
    1795             :     }
    1796             : 
    1797             :     // find next rpNextRange if rpPrevRange contains nScRow
    1798       19472 :     if( nScRow <= rpPrevRange->mnScRow2 )
    1799             :     {
    1800       17226 :         rnNextIndex = nPrevIndex + 1;
    1801       17226 :         rpNextRange = &maIndexList[rnNextIndex];
    1802             :     }
    1803             : }
    1804             : 
    1805      403924 : void XclImpXFRangeColumn::TryConcatPrev( sal_uLong nIndex )
    1806             : {
    1807      403924 :     if( !nIndex || nIndex >= maIndexList.size() )
    1808      803452 :         return;
    1809             : 
    1810        4396 :     XclImpXFRange& prevRange = maIndexList[ nIndex - 1 ];
    1811        4396 :     XclImpXFRange& nextRange = maIndexList[ nIndex ];
    1812             : 
    1813        4396 :     if( prevRange.Expand( nextRange ) )
    1814        1140 :         maIndexList.erase( maIndexList.begin() + nIndex );
    1815             : }
    1816             : 
    1817             : // ----------------------------------------------------------------------------
    1818             : 
    1819          44 : XclImpXFRangeBuffer::XclImpXFRangeBuffer( const XclImpRoot& rRoot ) :
    1820          44 :     XclImpRoot( rRoot )
    1821             : {
    1822          44 : }
    1823             : 
    1824          88 : XclImpXFRangeBuffer::~XclImpXFRangeBuffer()
    1825             : {
    1826          88 : }
    1827             : 
    1828         162 : void XclImpXFRangeBuffer::Initialize()
    1829             : {
    1830         162 :     maColumns.clear();
    1831         162 :     maHyperlinks.clear();
    1832         162 :     maMergeList.RemoveAll();
    1833         162 : }
    1834             : 
    1835      728684 : void XclImpXFRangeBuffer::SetXF( const ScAddress& rScPos, sal_uInt16 nXFIndex, XclImpXFInsertMode eMode )
    1836             : {
    1837      728684 :     SCCOL nScCol = rScPos.Col();
    1838      728684 :     SCROW nScRow = rScPos.Row();
    1839             : 
    1840             :     // set cell XF's
    1841      728684 :     size_t nIndex = static_cast< size_t >( nScCol );
    1842      728684 :     if( maColumns.size() <= nIndex )
    1843       20576 :         maColumns.resize( nIndex + 1 );
    1844      728684 :     if( !maColumns[ nIndex ] )
    1845       20804 :         maColumns[ nIndex ].reset( new XclImpXFRangeColumn );
    1846             :     // remember all Boolean cells, they will get 'Standard' number format
    1847      728684 :     maColumns[ nIndex ]->SetXF( nScRow, XclImpXFIndex( nXFIndex, eMode == xlXFModeBoolCell ) );
    1848             : 
    1849             :     // set "center across selection" and "fill" attribute for all following empty cells
    1850             :     // ignore it on row default XFs
    1851      728684 :     if( eMode != xlXFModeRow )
    1852             :     {
    1853       93804 :         const XclImpXF* pXF = GetXFBuffer().GetXF( nXFIndex );
    1854       93804 :         if( pXF && ((pXF->GetHorAlign() == EXC_XF_HOR_CENTER_AS) || (pXF->GetHorAlign() == EXC_XF_HOR_FILL)) )
    1855             :         {
    1856             :             // expand last merged range if this attribute is set repeatedly
    1857           0 :             ScRange* pRange = maMergeList.empty() ? NULL : maMergeList.back();
    1858           0 :             if (pRange && (pRange->aEnd.Row() == nScRow) && (pRange->aEnd.Col() + 1 == nScCol) && (eMode == xlXFModeBlank))
    1859           0 :                 pRange->aEnd.IncCol();
    1860           0 :             else if( eMode != xlXFModeBlank )   // do not merge empty cells
    1861           0 :                 SetMerge( nScCol, nScRow );
    1862             :         }
    1863             :     }
    1864      728684 : }
    1865             : 
    1866       55686 : void XclImpXFRangeBuffer::SetXF( const ScAddress& rScPos, sal_uInt16 nXFIndex )
    1867             : {
    1868       55686 :     SetXF( rScPos, nXFIndex, xlXFModeCell );
    1869       55686 : }
    1870             : 
    1871       38118 : void XclImpXFRangeBuffer::SetBlankXF( const ScAddress& rScPos, sal_uInt16 nXFIndex )
    1872             : {
    1873       38118 :     SetXF( rScPos, nXFIndex, xlXFModeBlank );
    1874       38118 : }
    1875             : 
    1876           0 : void XclImpXFRangeBuffer::SetBoolXF( const ScAddress& rScPos, sal_uInt16 nXFIndex )
    1877             : {
    1878           0 :     SetXF( rScPos, nXFIndex, xlXFModeBoolCell );
    1879           0 : }
    1880             : 
    1881         620 : void XclImpXFRangeBuffer::SetRowDefXF( SCROW nScRow, sal_uInt16 nXFIndex )
    1882             : {
    1883      635500 :     for( SCCOL nScCol = 0; nScCol <= MAXCOL; ++nScCol )
    1884      634880 :         SetXF( ScAddress( nScCol, nScRow, 0 ), nXFIndex, xlXFModeRow );
    1885         620 : }
    1886             : 
    1887       21812 : void XclImpXFRangeBuffer::SetColumnDefXF( SCCOL nScCol, sal_uInt16 nXFIndex )
    1888             : {
    1889             :     // our array should not have values when creating the default column format.
    1890       21812 :     size_t nIndex = static_cast< size_t >( nScCol );
    1891       21812 :     if( maColumns.size() <= nIndex )
    1892       21812 :         maColumns.resize( nIndex + 1 );
    1893             :     OSL_ENSURE( !maColumns[ nIndex ], "XclImpXFRangeBuffer::SetColumnDefXF - default column of XFs already has values" );
    1894       21812 :     maColumns[ nIndex ].reset( new XclImpXFRangeColumn );
    1895       21812 :     maColumns[ nIndex ]->SetDefaultXF( XclImpXFIndex( nXFIndex ) );
    1896       21812 : }
    1897             : 
    1898         860 : void XclImpXFRangeBuffer::SetBorderLine( const ScRange& rRange, SCTAB nScTab, sal_uInt16 nLine )
    1899             : {
    1900         860 :     SCCOL nFromScCol = (nLine == BOX_LINE_RIGHT) ? rRange.aEnd.Col() : rRange.aStart.Col();
    1901         860 :     SCROW nFromScRow = (nLine == BOX_LINE_BOTTOM) ? rRange.aEnd.Row() : rRange.aStart.Row();
    1902         860 :     ScDocument& rDoc = GetDoc();
    1903             : 
    1904             :     const SvxBoxItem* pFromItem = static_cast< const SvxBoxItem* >(
    1905         860 :         rDoc.GetAttr( nFromScCol, nFromScRow, nScTab, ATTR_BORDER ) );
    1906             :     const SvxBoxItem* pToItem = static_cast< const SvxBoxItem* >(
    1907         860 :         rDoc.GetAttr( rRange.aStart.Col(), rRange.aStart.Row(), nScTab, ATTR_BORDER ) );
    1908             : 
    1909         860 :     SvxBoxItem aNewItem( *pToItem );
    1910         860 :     aNewItem.SetLine( pFromItem->GetLine( nLine ), nLine );
    1911         860 :     rDoc.ApplyAttr( rRange.aStart.Col(), rRange.aStart.Row(), nScTab, aNewItem );
    1912         860 : }
    1913             : 
    1914          16 : void XclImpXFRangeBuffer::SetHyperlink( const XclRange& rXclRange, const String& rUrl )
    1915             : {
    1916          16 :     maHyperlinks.push_back( XclImpHyperlinkRange( rXclRange, rUrl ) );
    1917          16 : }
    1918             : 
    1919           0 : void XclImpXFRangeBuffer::SetMerge( SCCOL nScCol, SCROW nScRow )
    1920             : {
    1921           0 :     maMergeList.Append( ScRange( nScCol, nScRow, 0 ) );
    1922           0 : }
    1923             : 
    1924         858 : void XclImpXFRangeBuffer::SetMerge( SCCOL nScCol1, SCROW nScRow1, SCCOL nScCol2, SCROW nScRow2 )
    1925             : {
    1926         858 :     if( (nScCol1 < nScCol2) || (nScRow1 < nScRow2) )
    1927         858 :         maMergeList.Append( ScRange( nScCol1, nScRow1, 0, nScCol2, nScRow2, 0 ) );
    1928         858 : }
    1929             : 
    1930         162 : void XclImpXFRangeBuffer::Finalize()
    1931             : {
    1932         162 :     ScDocument& rDoc = GetDoc();
    1933         162 :     SCTAB nScTab = GetCurrScTab();
    1934             : 
    1935             :     // apply patterns
    1936         162 :     XclImpXFBuffer& rXFBuffer = GetXFBuffer();
    1937       42832 :     for( XclImpXFRangeColumnVec::const_iterator aVBeg = maColumns.begin(), aVEnd = maColumns.end(), aVIt = aVBeg; aVIt != aVEnd; ++aVIt )
    1938             :     {
    1939             :         // apply all cell styles of an existing column
    1940       42670 :         if( aVIt->get() )
    1941             :         {
    1942       42616 :             XclImpXFRangeColumn& rColumn = **aVIt;
    1943       42616 :             SCCOL nScCol = static_cast< SCCOL >( aVIt - aVBeg );
    1944       42616 :             list<ScAttrEntry> aAttrs;
    1945             : 
    1946      244704 :             for (XclImpXFRangeColumn::IndexList::iterator itr = rColumn.begin(), itrEnd = rColumn.end();
    1947             :                  itr != itrEnd; ++itr)
    1948             :             {
    1949      202088 :                 XclImpXFRange& rStyle = *itr;
    1950      202088 :                 const XclImpXFIndex& rXFIndex = rStyle.maXFIndex;
    1951      202088 :                 XclImpXF* pXF = rXFBuffer.GetXF( rXFIndex.GetXFIndex() );
    1952      202088 :                 if (!pXF)
    1953        1114 :                     continue;
    1954             : 
    1955      200974 :                 sal_uInt32 nForceScNumFmt = rXFIndex.IsBoolCell() ?
    1956      200974 :                     GetNumFmtBuffer().GetStdScNumFmt() : NUMBERFORMAT_ENTRY_NOT_FOUND;
    1957             : 
    1958      200974 :                 pXF->ApplyPatternToAttrList(aAttrs, rStyle.mnScRow1, rStyle.mnScRow2, nForceScNumFmt);
    1959             :             }
    1960             : 
    1961       42616 :             if (aAttrs.empty() || aAttrs.back().nRow != MAXROW)
    1962             :             {
    1963             :                 ScAttrEntry aEntry;
    1964       20804 :                 aEntry.nRow = MAXROW;
    1965       20804 :                 aEntry.pPattern = rDoc.GetDefPattern();
    1966       20804 :                 aAttrs.push_back(aEntry);
    1967             :             }
    1968             : 
    1969       42616 :             size_t nAttrSize = aAttrs.size();
    1970       42616 :             ScAttrEntry* pData = new ScAttrEntry[nAttrSize];
    1971       42616 :             list<ScAttrEntry>::const_iterator itr = aAttrs.begin(), itrEnd = aAttrs.end();
    1972      300924 :             for (size_t i = 0; itr != itrEnd; ++itr, ++i)
    1973      258308 :                 pData[i] = *itr;
    1974             : 
    1975       42616 :             rDoc.SetAttrEntries(nScCol, nScTab, pData, static_cast<SCSIZE>(nAttrSize));
    1976             :         }
    1977             :     }
    1978             : 
    1979             :     // insert hyperlink cells
    1980         178 :     for( XclImpHyperlinkList::const_iterator aLIt = maHyperlinks.begin(), aLEnd = maHyperlinks.end(); aLIt != aLEnd; ++aLIt )
    1981          16 :         XclImpHyperlink::InsertUrl( GetRoot(), aLIt->first, aLIt->second );
    1982             : 
    1983             :     // apply cell merging
    1984        1020 :     for ( size_t i = 0, nRange = maMergeList.size(); i < nRange; ++i )
    1985             :     {
    1986         858 :         const ScRange* pRange = maMergeList[ i ];
    1987         858 :         const ScAddress& rStart = pRange->aStart;
    1988         858 :         const ScAddress& rEnd = pRange->aEnd;
    1989         858 :         bool bMultiCol = rStart.Col() != rEnd.Col();
    1990         858 :         bool bMultiRow = rStart.Row() != rEnd.Row();
    1991             :         // set correct right border
    1992         858 :         if( bMultiCol )
    1993         858 :             SetBorderLine( *pRange, nScTab, BOX_LINE_RIGHT );
    1994             :         // set correct lower border
    1995         858 :         if( bMultiRow )
    1996           2 :             SetBorderLine( *pRange, nScTab, BOX_LINE_BOTTOM );
    1997             :         // do merge
    1998         858 :         if( bMultiCol || bMultiRow )
    1999         858 :             rDoc.DoMerge( nScTab, rStart.Col(), rStart.Row(), rEnd.Col(), rEnd.Row() );
    2000             :         // #i93609# merged range in a single row: test if manual row height is needed
    2001         858 :         if( !bMultiRow )
    2002             :         {
    2003         856 :             bool bTextWrap = static_cast< const SfxBoolItem* >( rDoc.GetAttr( rStart.Col(), rStart.Row(), rStart.Tab(), ATTR_LINEBREAK ) )->GetValue();
    2004         856 :             if( !bTextWrap && (rDoc.GetCellType( rStart ) == CELLTYPE_EDIT) )
    2005           0 :                 if( const EditTextObject* pEditObj = static_cast< const ScEditCell* >( rDoc.GetCell( rStart ) )->GetData() )
    2006           0 :                     bTextWrap = pEditObj->GetParagraphCount() > 1;
    2007         856 :             if( bTextWrap )
    2008          10 :                 GetOldRoot().pColRowBuff->SetManualRowHeight( rStart.Row() );
    2009             :         }
    2010             :     }
    2011         186 : }
    2012             : 
    2013             : // ============================================================================
    2014             : 
    2015             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10