LCOV - code coverage report
Current view: top level - libreoffice/sc/source/filter/excel - xeescher.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 48 746 6.4 %
Date: 2012-12-27 Functions: 13 80 16.2 %
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             : 
      21             : #include "xeescher.hxx"
      22             : 
      23             : #include <com/sun/star/lang/XServiceInfo.hpp>
      24             : #include <com/sun/star/frame/XModel.hpp>
      25             : #include <com/sun/star/form/FormComponentType.hpp>
      26             : #include <com/sun/star/awt/VisualEffect.hpp>
      27             : #include <com/sun/star/awt/ScrollBarOrientation.hpp>
      28             : #include <com/sun/star/drawing/XShape.hpp>
      29             : #include <com/sun/star/form/binding/XBindableValue.hpp>
      30             : #include <com/sun/star/form/binding/XValueBinding.hpp>
      31             : #include <com/sun/star/form/binding/XListEntrySink.hpp>
      32             : #include <com/sun/star/form/binding/XListEntrySource.hpp>
      33             : #include <com/sun/star/script/ScriptEventDescriptor.hpp>
      34             : #include <com/sun/star/chart2/XChartDocument.hpp>
      35             : #include <com/sun/star/awt/Point.hpp>
      36             : #include <com/sun/star/awt/Size.hpp>
      37             : #include <com/sun/star/container/XNamed.hpp>
      38             : 
      39             : #include <set>
      40             : #include <rtl/ustrbuf.h>
      41             : #include <vcl/bmpacc.hxx>
      42             : #include <svx/svdoole2.hxx>
      43             : #include <svx/svdocapt.hxx>
      44             : #include <editeng/outlobj.hxx>
      45             : #include <editeng/editobj.hxx>
      46             : #include <unotools/tempfile.hxx>
      47             : #include <unotools/ucbstreamhelper.hxx>
      48             : 
      49             : #include "editutil.hxx"
      50             : #include "unonames.hxx"
      51             : #include "convuno.hxx"
      52             : #include "postit.hxx"
      53             : 
      54             : #include "fapihelper.hxx"
      55             : #include "xechart.hxx"
      56             : #include "xeformula.hxx"
      57             : #include "xelink.hxx"
      58             : #include "xename.hxx"
      59             : #include "xestyle.hxx"
      60             : #include "userdat.hxx"
      61             : #include "drwlayer.hxx"
      62             : #include "svx/unoapi.hxx"
      63             : #include "svx/algitem.hxx"
      64             : #include "scitems.hxx"
      65             : #include <editeng/justifyitem.hxx>
      66             : #include "svx/sdtaitm.hxx"
      67             : #include "attrib.hxx"
      68             : #include "document.hxx"
      69             : #include <svx/svdattr.hxx>
      70             : #include "svx/sdr/properties/properties.hxx"
      71             : #include "detfunc.hxx"
      72             : #include "svx/xflclit.hxx"
      73             : #include "svx/xlnstwit.hxx"
      74             : #include "svx/xlnstit.hxx"
      75             : #include "svx/sxmspitm.hxx"
      76             : 
      77             : #include <oox/token/tokens.hxx>
      78             : #include <oox/export/drawingml.hxx>
      79             : #include <oox/export/chartexport.hxx>
      80             : #include <oox/export/utils.hxx>
      81             : #include <boost/shared_ptr.hpp>
      82             : 
      83             : using ::rtl::OString;
      84             : using ::rtl::OUString;
      85             : using ::rtl::OUStringBuffer;
      86             : using ::com::sun::star::uno::UNO_QUERY;
      87             : using ::com::sun::star::uno::Reference;
      88             : using ::com::sun::star::uno::Sequence;
      89             : using ::com::sun::star::lang::XServiceInfo;
      90             : using ::com::sun::star::beans::XPropertySet;
      91             : using ::com::sun::star::drawing::XShape;
      92             : using ::com::sun::star::drawing::XShapes;
      93             : using ::com::sun::star::frame::XModel;
      94             : using ::com::sun::star::embed::XEmbeddedObject;
      95             : using ::com::sun::star::awt::XControlModel;
      96             : using ::com::sun::star::form::binding::XBindableValue;
      97             : using ::com::sun::star::form::binding::XValueBinding;
      98             : using ::com::sun::star::form::binding::XListEntrySink;
      99             : using ::com::sun::star::form::binding::XListEntrySource;
     100             : using ::com::sun::star::script::ScriptEventDescriptor;
     101             : using ::com::sun::star::table::CellAddress;
     102             : using ::com::sun::star::table::CellRangeAddress;
     103             : using ::com::sun::star::chart2::XChartDocument;
     104             : using ::com::sun::star::container::XNamed;
     105             : using ::oox::drawingml::DrawingML;
     106             : using ::oox::drawingml::ChartExport;
     107             : using namespace oox;
     108             : 
     109             : #define  HMM2XL(x)        ((x)/26.5)+0.5
     110             : 
     111             : #if 1//def XLSX_OOXML_FUTURE
     112             : // these function are only used within that context
     113             : // Static Function Helpers
     114           0 : static const char *ToHorizAlign( SdrTextHorzAdjust eAdjust )
     115             : {
     116           0 :     switch( eAdjust )
     117             :     {
     118             :         case SDRTEXTHORZADJUST_CENTER:
     119           0 :             return "center";
     120             :         case SDRTEXTHORZADJUST_RIGHT:
     121           0 :             return "right";
     122             :         case SDRTEXTHORZADJUST_BLOCK:
     123           0 :             return "justify";
     124             :         case SDRTEXTHORZADJUST_LEFT:
     125             :         default:
     126           0 :             return "left";
     127             :     }
     128             : }
     129             : 
     130           0 : static const char *ToVertAlign( SdrTextVertAdjust eAdjust )
     131             : {
     132           0 :     switch( eAdjust )
     133             :     {
     134             :         case SDRTEXTVERTADJUST_CENTER:
     135           0 :             return "center";
     136             :         case SDRTEXTVERTADJUST_BOTTOM:
     137           0 :             return "bottom";
     138             :         case SDRTEXTVERTADJUST_BLOCK:
     139           0 :             return "justify";
     140             :         case SDRTEXTVERTADJUST_TOP:
     141             :         default:
     142           0 :             return "top";
     143             :     }
     144             : }
     145             : 
     146           0 : static void lcl_WriteAnchorVertex( sax_fastparser::FSHelperPtr rComments, Rectangle &aRect )
     147             : {
     148           0 :     rComments->startElement( FSNS( XML_xdr, XML_col ), FSEND );
     149           0 :     rComments->writeEscaped( OUString::valueOf( aRect.Left() ) );
     150           0 :     rComments->endElement( FSNS( XML_xdr, XML_col ) );
     151           0 :     rComments->startElement( FSNS( XML_xdr, XML_colOff ), FSEND );
     152           0 :     rComments->writeEscaped( OUString::valueOf( aRect.Top() ) );
     153           0 :     rComments->endElement( FSNS( XML_xdr, XML_colOff ) );
     154           0 :     rComments->startElement( FSNS( XML_xdr, XML_row ), FSEND );
     155           0 :     rComments->writeEscaped( OUString::valueOf( aRect.Right() ) );
     156           0 :     rComments->endElement( FSNS( XML_xdr, XML_row ) );
     157           0 :     rComments->startElement( FSNS( XML_xdr, XML_rowOff ), FSEND );
     158           0 :     rComments->writeEscaped( OUString::valueOf( aRect.Bottom() ) );
     159           0 :     rComments->endElement( FSNS( XML_xdr, XML_rowOff ) );
     160           0 : }
     161             : #endif
     162             : 
     163           0 : static void lcl_GetFromTo( const XclExpRoot& rRoot, const Rectangle &aRect, sal_Int32 nTab, Rectangle &aFrom, Rectangle &aTo )
     164             : {
     165           0 :     bool bTo = false;
     166           0 :     sal_Int32 nCol = 0, nRow = 0;
     167           0 :     sal_Int32 nColOff = 0, nRowOff= 0;
     168             : 
     169           0 :     while(1)
     170             :     {
     171           0 :         Rectangle r = rRoot.GetDocPtr()->GetMMRect( nCol,nRow,nCol,nRow,nTab );
     172           0 :         if( !bTo )
     173             :         {
     174           0 :             if( r.Left() <= aRect.Left() )
     175             :             {
     176           0 :                 nCol++;
     177           0 :                 nColOff = aRect.Left() - r.Left();
     178             :             }
     179           0 :             if( r.Top() <= aRect.Top() )
     180             :             {
     181           0 :                 nRow++;
     182           0 :                 nRowOff = aRect.Top() - r.Top();
     183             :             }
     184           0 :             if( r.Left() > aRect.Left() && r.Top() > aRect.Top() )
     185             :             {
     186             :                 aFrom = Rectangle( nCol-1, static_cast<long>(HMM2XL( nColOff )),
     187           0 :                                    nRow-1, static_cast<long>(HMM2XL( nRowOff )) );
     188           0 :                 bTo=true;
     189             :             }
     190             :         }
     191           0 :         if( bTo )
     192             :         {
     193           0 :             if( r.Right() < aRect.Right() )
     194           0 :                 nCol++;
     195           0 :             if( r.Bottom() < aRect.Bottom() )
     196           0 :                 nRow++;
     197           0 :             if( r.Right() >= aRect.Right() && r.Bottom() >= aRect.Bottom() )
     198             :             {
     199           0 :                 aTo = Rectangle( nCol, static_cast<long>(HMM2XL( aRect.Right() - r.Left() )),
     200           0 :                                  nRow, static_cast<long>(HMM2XL( aRect.Bottom() - r.Top() )));
     201             :                 break;
     202             :             }
     203             :         }
     204             :     }
     205           0 :     return;
     206             : }
     207             : 
     208             : // Escher client anchor =======================================================
     209             : 
     210           0 : XclExpDffAnchorBase::XclExpDffAnchorBase( const XclExpRoot& rRoot, sal_uInt16 nFlags ) :
     211             :     XclExpRoot( rRoot ),
     212           0 :     mnFlags( nFlags )
     213             : {
     214           0 : }
     215             : 
     216           0 : void XclExpDffAnchorBase::SetFlags( const SdrObject& rSdrObj )
     217             : {
     218           0 :     ImplSetFlags( rSdrObj );
     219           0 : }
     220             : 
     221           0 : void XclExpDffAnchorBase::SetSdrObject( const SdrObject& rSdrObj )
     222             : {
     223           0 :     ImplSetFlags( rSdrObj );
     224           0 :     ImplCalcAnchorRect( rSdrObj.GetCurrentBoundRect(), MAP_100TH_MM );
     225           0 : }
     226             : 
     227           0 : void XclExpDffAnchorBase::WriteDffData( EscherEx& rEscherEx ) const
     228             : {
     229           0 :     rEscherEx.AddAtom( 18, ESCHER_ClientAnchor );
     230           0 :     rEscherEx.GetStream() << mnFlags << maAnchor;
     231           0 : }
     232             : 
     233           0 : void XclExpDffAnchorBase::WriteData( EscherEx& rEscherEx, const Rectangle& rRect )
     234             : {
     235             :     // the passed rectangle is in twips
     236           0 :     ImplCalcAnchorRect( rRect, MAP_TWIP );
     237           0 :     WriteDffData( rEscherEx );
     238           0 : }
     239             : 
     240           0 : void XclExpDffAnchorBase::ImplSetFlags( const SdrObject& )
     241             : {
     242             :     OSL_FAIL( "XclExpDffAnchorBase::ImplSetFlags - not implemented" );
     243           0 : }
     244             : 
     245           0 : void XclExpDffAnchorBase::ImplCalcAnchorRect( const Rectangle&, MapUnit )
     246             : {
     247             :     OSL_FAIL( "XclExpDffAnchorBase::ImplCalcAnchorRect - not implemented" );
     248           0 : }
     249             : 
     250             : // ----------------------------------------------------------------------------
     251             : 
     252           0 : XclExpDffSheetAnchor::XclExpDffSheetAnchor( const XclExpRoot& rRoot ) :
     253             :     XclExpDffAnchorBase( rRoot ),
     254           0 :     mnScTab( rRoot.GetCurrScTab() )
     255             : {
     256           0 : }
     257             : 
     258           0 : void XclExpDffSheetAnchor::ImplSetFlags( const SdrObject& rSdrObj )
     259             : {
     260             :     // Special case "page anchor" (X==0,Y==1) -> lock pos and size.
     261           0 :     const Point& rPos = rSdrObj.GetAnchorPos();
     262           0 :     mnFlags = ((rPos.X() == 0) && (rPos.Y() == 1)) ? EXC_ESC_ANCHOR_LOCKED : 0;
     263           0 : }
     264             : 
     265           0 : void XclExpDffSheetAnchor::ImplCalcAnchorRect( const Rectangle& rRect, MapUnit eMapUnit )
     266             : {
     267           0 :     maAnchor.SetRect( GetRoot(), mnScTab, rRect, eMapUnit );
     268           0 : }
     269             : 
     270             : // ----------------------------------------------------------------------------
     271             : 
     272           0 : XclExpDffEmbeddedAnchor::XclExpDffEmbeddedAnchor( const XclExpRoot& rRoot,
     273             :         const Size& rPageSize, sal_Int32 nScaleX, sal_Int32 nScaleY ) :
     274             :     XclExpDffAnchorBase( rRoot ),
     275             :     maPageSize( rPageSize ),
     276             :     mnScaleX( nScaleX ),
     277           0 :     mnScaleY( nScaleY )
     278             : {
     279           0 : }
     280             : 
     281           0 : void XclExpDffEmbeddedAnchor::ImplSetFlags( const SdrObject& /*rSdrObj*/ )
     282             : {
     283             :     // TODO (unsupported feature): fixed size
     284           0 : }
     285             : 
     286           0 : void XclExpDffEmbeddedAnchor::ImplCalcAnchorRect( const Rectangle& rRect, MapUnit eMapUnit )
     287             : {
     288           0 :     maAnchor.SetRect( maPageSize, mnScaleX, mnScaleY, rRect, eMapUnit, true );
     289           0 : }
     290             : 
     291             : // ----------------------------------------------------------------------------
     292             : 
     293           0 : XclExpDffNoteAnchor::XclExpDffNoteAnchor( const XclExpRoot& rRoot, const Rectangle& rRect ) :
     294           0 :     XclExpDffAnchorBase( rRoot, EXC_ESC_ANCHOR_SIZELOCKED )
     295             : {
     296           0 :     maAnchor.SetRect( rRoot, rRoot.GetCurrScTab(), rRect, MAP_100TH_MM );
     297           0 : }
     298             : 
     299             : // ----------------------------------------------------------------------------
     300             : 
     301           0 : XclExpDffDropDownAnchor::XclExpDffDropDownAnchor( const XclExpRoot& rRoot, const ScAddress& rScPos ) :
     302           0 :     XclExpDffAnchorBase( rRoot, EXC_ESC_ANCHOR_POSLOCKED )
     303             : {
     304           0 :     GetAddressConverter().ConvertAddress( maAnchor.maFirst, rScPos, true );
     305           0 :     maAnchor.maLast.mnCol = maAnchor.maFirst.mnCol + 1;
     306           0 :     maAnchor.maLast.mnRow = maAnchor.maFirst.mnRow + 1;
     307           0 :     maAnchor.mnLX = maAnchor.mnTY = maAnchor.mnRX = maAnchor.mnBY = 0;
     308           0 : }
     309             : 
     310             : // MSODRAWING* records ========================================================
     311             : 
     312           2 : XclExpMsoDrawingBase::XclExpMsoDrawingBase( XclEscherEx& rEscherEx, sal_uInt16 nRecId ) :
     313             :     XclExpRecord( nRecId ),
     314             :     mrEscherEx( rEscherEx ),
     315           2 :     mnFragmentKey( rEscherEx.InitNextDffFragment() )
     316             : {
     317           2 : }
     318             : 
     319           0 : void XclExpMsoDrawingBase::WriteBody( XclExpStream& rStrm )
     320             : {
     321             :     OSL_ENSURE( mrEscherEx.GetStreamPos() == mrEscherEx.GetDffFragmentPos( mnFragmentKey ),
     322             :         "XclExpMsoDrawingBase::WriteBody - DFF stream position mismatch" );
     323           0 :     rStrm.CopyFromStream( mrEscherEx.GetStream(), mrEscherEx.GetDffFragmentSize( mnFragmentKey ) );
     324           0 : }
     325             : 
     326             : // ----------------------------------------------------------------------------
     327             : 
     328           1 : XclExpMsoDrawingGroup::XclExpMsoDrawingGroup( XclEscherEx& rEscherEx ) :
     329           1 :     XclExpMsoDrawingBase( rEscherEx, EXC_ID_MSODRAWINGGROUP )
     330             : {
     331           1 :     SvStream& rDffStrm = mrEscherEx.GetStream();
     332             : 
     333             :     // write the DGGCONTAINER with some default settings
     334           1 :     mrEscherEx.OpenContainer( ESCHER_DggContainer );
     335             : 
     336             :     // TODO: stuff the OPT atom with our own document defaults?
     337             :     static const sal_uInt8 spnDffOpt[] = {
     338             :         0xBF, 0x00, 0x08, 0x00, 0x08, 0x00, 0x81, 0x01,
     339             :         0x09, 0x00, 0x00, 0x08, 0xC0, 0x01, 0x40, 0x00,
     340             :         0x00, 0x08
     341             :     };
     342           1 :     mrEscherEx.AddAtom( sizeof( spnDffOpt ), ESCHER_OPT, 3, 3 );
     343           1 :     rDffStrm.Write( spnDffOpt, sizeof( spnDffOpt ) );
     344             : 
     345             :     // SPLITMENUCOLORS contains colors in toolbar
     346             :     static const sal_uInt8 spnDffSplitMenuColors[] = {
     347             :         0x0D, 0x00, 0x00, 0x08, 0x0C, 0x00, 0x00, 0x08,
     348             :         0x17, 0x00, 0x00, 0x08, 0xF7, 0x00, 0x00, 0x10
     349             :     };
     350           1 :     mrEscherEx.AddAtom( sizeof( spnDffSplitMenuColors ), ESCHER_SplitMenuColors, 0, 4 );
     351           1 :     rDffStrm.Write( spnDffSplitMenuColors, sizeof( spnDffSplitMenuColors ) );
     352             : 
     353             :     // close the DGGCONTAINER
     354           1 :     mrEscherEx.CloseContainer();
     355           1 :     mrEscherEx.UpdateDffFragmentEnd();
     356           1 : }
     357             : 
     358             : // ----------------------------------------------------------------------------
     359             : 
     360           1 : XclExpMsoDrawing::XclExpMsoDrawing( XclEscherEx& rEscherEx ) :
     361           1 :     XclExpMsoDrawingBase( rEscherEx, EXC_ID_MSODRAWING )
     362             : {
     363           1 : }
     364             : 
     365             : // ============================================================================
     366             : 
     367           0 : XclExpImgData::XclExpImgData( const Graphic& rGraphic, sal_uInt16 nRecId ) :
     368             :     maGraphic( rGraphic ),
     369           0 :     mnRecId( nRecId )
     370             : {
     371           0 : }
     372             : 
     373           0 : void XclExpImgData::Save( XclExpStream& rStrm )
     374             : {
     375           0 :     Bitmap aBmp = maGraphic.GetBitmap();
     376           0 :     if( aBmp.GetBitCount() != 24 )
     377           0 :         aBmp.Convert( BMP_CONVERSION_24BIT );
     378             : 
     379           0 :     if( BitmapReadAccess* pAccess = aBmp.AcquireReadAccess() )
     380             :     {
     381           0 :         sal_Int32 nWidth = ::std::min< sal_Int32 >( pAccess->Width(), 0xFFFF );
     382           0 :         sal_Int32 nHeight = ::std::min< sal_Int32 >( pAccess->Height(), 0xFFFF );
     383           0 :         if( (nWidth > 0) && (nHeight > 0) )
     384             :         {
     385           0 :             sal_uInt8 nPadding = static_cast< sal_uInt8 >( nWidth & 0x03 );
     386           0 :             sal_uInt32 nTmpSize = static_cast< sal_uInt32 >( (nWidth * 3 + nPadding) * nHeight + 12 );
     387             : 
     388           0 :             rStrm.StartRecord( mnRecId, nTmpSize + 4 );
     389             : 
     390           0 :             rStrm   << EXC_IMGDATA_BMP                      // BMP format
     391           0 :                     << EXC_IMGDATA_WIN                      // Windows
     392           0 :                     << nTmpSize                             // size after _this_ field
     393           0 :                     << sal_uInt32( 12 )                     // BITMAPCOREHEADER size
     394           0 :                     << static_cast< sal_uInt16 >( nWidth )  // width
     395           0 :                     << static_cast< sal_uInt16 >( nHeight ) // height
     396           0 :                     << sal_uInt16( 1 )                      // planes
     397           0 :                     << sal_uInt16( 24 );                    // bits per pixel
     398             : 
     399           0 :             for( sal_Int32 nY = nHeight - 1; nY >= 0; --nY )
     400             :             {
     401           0 :                 for( sal_Int32 nX = 0; nX < nWidth; ++nX )
     402             :                 {
     403           0 :                     const BitmapColor& rBmpColor = pAccess->GetPixel( nY, nX );
     404           0 :                     rStrm << rBmpColor.GetBlue() << rBmpColor.GetGreen() << rBmpColor.GetRed();
     405           0 :                 }
     406           0 :                 rStrm.WriteZeroBytes( nPadding );
     407             :             }
     408             : 
     409           0 :             rStrm.EndRecord();
     410             :         }
     411           0 :         aBmp.ReleaseAccess( pAccess );
     412           0 :     }
     413           0 : }
     414             : 
     415           0 : void XclExpImgData::SaveXml( XclExpXmlStream& rStrm )
     416             : {
     417           0 :     sax_fastparser::FSHelperPtr pWorksheet = rStrm.GetCurrentStream();
     418             : 
     419           0 :     DrawingML aDML( pWorksheet, &rStrm, DrawingML::DOCUMENT_XLSX );
     420           0 :     OUString rId = aDML.WriteImage( maGraphic );
     421             :     pWorksheet->singleElement( XML_picture,
     422             :             FSNS( XML_r, XML_id ),  XclXmlUtils::ToOString( rId ).getStr(),
     423           0 :             FSEND );
     424           0 : }
     425             : 
     426             : // ============================================================================
     427             : 
     428           0 : XclExpControlHelper::XclExpControlHelper( const XclExpRoot& rRoot ) :
     429             :     XclExpRoot( rRoot ),
     430           0 :     mnEntryCount( 0 )
     431             : {
     432           0 : }
     433             : 
     434           0 : XclExpControlHelper::~XclExpControlHelper()
     435             : {
     436           0 : }
     437             : 
     438           0 : void XclExpControlHelper::ConvertSheetLinks( Reference< XShape > xShape )
     439             : {
     440           0 :     mxCellLink.reset();
     441           0 :     mxSrcRange.reset();
     442           0 :     mnEntryCount = 0;
     443             : 
     444             :     // get control model
     445           0 :     Reference< XControlModel > xCtrlModel = XclControlHelper::GetControlModel( xShape );
     446           0 :     if( !xCtrlModel.is() )
     447           0 :         return;
     448             : 
     449             :     // *** cell link *** ------------------------------------------------------
     450             : 
     451           0 :     Reference< XBindableValue > xBindable( xCtrlModel, UNO_QUERY );
     452           0 :     if( xBindable.is() )
     453             :     {
     454           0 :         Reference< XServiceInfo > xServInfo( xBindable->getValueBinding(), UNO_QUERY );
     455           0 :         if( xServInfo.is() && xServInfo->supportsService( SC_SERVICENAME_VALBIND ) )
     456             :         {
     457           0 :             ScfPropertySet aBindProp( xServInfo );
     458           0 :             CellAddress aApiAddress;
     459           0 :             if( aBindProp.GetProperty( aApiAddress, SC_UNONAME_BOUNDCELL ) )
     460             :             {
     461           0 :                 ScAddress aCellLink;
     462           0 :                 ScUnoConversion::FillScAddress( aCellLink, aApiAddress );
     463           0 :                 if( GetTabInfo().IsExportTab( aCellLink.Tab() ) )
     464           0 :                     mxCellLink = GetFormulaCompiler().CreateFormula( EXC_FMLATYPE_CONTROL, aCellLink );
     465           0 :             }
     466           0 :         }
     467             :     }
     468             : 
     469             :     // *** source range *** ---------------------------------------------------
     470             : 
     471           0 :     Reference< XListEntrySink > xEntrySink( xCtrlModel, UNO_QUERY );
     472           0 :     if( xEntrySink.is() )
     473             :     {
     474           0 :         Reference< XServiceInfo > xServInfo( xEntrySink->getListEntrySource(), UNO_QUERY );
     475           0 :         if( xServInfo.is() && xServInfo->supportsService( SC_SERVICENAME_LISTSOURCE ) )
     476             :         {
     477           0 :             ScfPropertySet aSinkProp( xServInfo );
     478           0 :             CellRangeAddress aApiRange;
     479           0 :             if( aSinkProp.GetProperty( aApiRange, SC_UNONAME_CELLRANGE ) )
     480             :             {
     481           0 :                 ScRange aSrcRange;
     482           0 :                 ScUnoConversion::FillScRange( aSrcRange, aApiRange );
     483           0 :                 if( (aSrcRange.aStart.Tab() == aSrcRange.aEnd.Tab()) && GetTabInfo().IsExportTab( aSrcRange.aStart.Tab() ) )
     484           0 :                     mxSrcRange = GetFormulaCompiler().CreateFormula( EXC_FMLATYPE_CONTROL, aSrcRange );
     485           0 :                 mnEntryCount = static_cast< sal_uInt16 >( aSrcRange.aEnd.Col() - aSrcRange.aStart.Col() + 1 );
     486           0 :             }
     487           0 :         }
     488           0 :     }
     489             : }
     490             : 
     491           0 : void XclExpControlHelper::WriteFormula( XclExpStream& rStrm, const XclTokenArray& rTokArr ) const
     492             : {
     493           0 :     sal_uInt16 nFmlaSize = rTokArr.GetSize();
     494           0 :     rStrm << nFmlaSize << sal_uInt32( 0 );
     495           0 :     rTokArr.WriteArray( rStrm );
     496           0 :     if( nFmlaSize & 1 )             // pad to 16-bit
     497           0 :         rStrm << sal_uInt8( 0 );
     498           0 : }
     499             : 
     500           0 : void XclExpControlHelper::WriteFormulaSubRec( XclExpStream& rStrm, sal_uInt16 nSubRecId, const XclTokenArray& rTokArr ) const
     501             : {
     502           0 :     rStrm.StartRecord( nSubRecId, (rTokArr.GetSize() + 5) & ~1 );
     503           0 :     WriteFormula( rStrm, rTokArr );
     504           0 :     rStrm.EndRecord();
     505           0 : }
     506             : 
     507             : // ----------------------------------------------------------------------------
     508             : 
     509             : #if EXC_EXP_OCX_CTRL
     510             : 
     511             : XclExpOcxControlObj::XclExpOcxControlObj( XclExpObjectManager& rObjMgr, Reference< XShape > xShape,
     512             :         const Rectangle* pChildAnchor, const String& rClassName, sal_uInt32 nStrmStart, sal_uInt32 nStrmSize ) :
     513             :     XclObj( rObjMgr, EXC_OBJTYPE_PICTURE, true ),
     514             :     XclExpControlHelper( rObjMgr.GetRoot() ),
     515             :     maClassName( rClassName ),
     516             :     mnStrmStart( nStrmStart ),
     517             :     mnStrmSize( nStrmSize )
     518             : {
     519             :     ScfPropertySet aCtrlProp( XclControlHelper::GetControlModel( xShape ) );
     520             : 
     521             :     // OBJ record flags
     522             :     SetLocked( sal_True );
     523             :     SetPrintable( aCtrlProp.GetBoolProperty( "Printable" ) );
     524             :     SetAutoFill( false );
     525             :     SetAutoLine( false );
     526             : 
     527             :     // fill DFF property set
     528             :     mrEscherEx.OpenContainer( ESCHER_SpContainer );
     529             :     mrEscherEx.AddShape( ESCHER_ShpInst_HostControl, SHAPEFLAG_HAVESPT | SHAPEFLAG_HAVEANCHOR | SHAPEFLAG_OLESHAPE );
     530             :     Rectangle aDummyRect;
     531             :     EscherPropertyContainer aPropOpt( mrEscherEx, mrEscherEx.QueryPicStream(), aDummyRect );
     532             :     aPropOpt.AddOpt( ESCHER_Prop_FitTextToShape,    0x00080008 );   // bool field
     533             :     aPropOpt.AddOpt( ESCHER_Prop_lineColor,         0x08000040 );
     534             :     aPropOpt.AddOpt( ESCHER_Prop_fNoLineDrawDash,   0x00080000 );   // bool field
     535             : 
     536             :     // #i51348# name of the control, may overwrite shape name
     537             :     OUString aCtrlName;
     538             :     if( aCtrlProp.GetProperty( aCtrlName, "Name" ) && !aCtrlName.isEmpty() )
     539             :         aPropOpt.AddOpt( ESCHER_Prop_wzName, aCtrlName );
     540             : 
     541             :     // meta file
     542             :     //! TODO - needs check
     543             :     Reference< XPropertySet > xShapePS( xShape, UNO_QUERY );
     544             :     if( xShapePS.is() && aPropOpt.CreateGraphicProperties( xShapePS, CREATE_STRING( "MetaFile" ), false ) )
     545             :     {
     546             :         sal_uInt32 nBlipId;
     547             :         if( aPropOpt.GetOpt( ESCHER_Prop_pib, nBlipId ) )
     548             :             aPropOpt.AddOpt( ESCHER_Prop_pictureId, nBlipId );
     549             :     }
     550             : 
     551             :     // write DFF property set to stream
     552             :     aPropOpt.Commit( mrEscherEx.GetStream() );
     553             : 
     554             :     // anchor
     555             :     ImplWriteAnchor( GetRoot(), SdrObject::getSdrObjectFromXShape( xShape ), pChildAnchor );
     556             : 
     557             :     mrEscherEx.AddAtom( 0, ESCHER_ClientData );                       // OBJ record
     558             :     mrEscherEx.CloseContainer();  // ESCHER_SpContainer
     559             :     mrEscherEx.UpdateDffFragmentEnd();
     560             : 
     561             :     // spreadsheet links
     562             :     ConvertSheetLinks( xShape );
     563             : }
     564             : 
     565             : void XclExpOcxControlObj::WriteSubRecs( XclExpStream& rStrm )
     566             : {
     567             :     // OBJCF - clipboard format
     568             :     rStrm.StartRecord( EXC_ID_OBJCF, 2 );
     569             :     rStrm << sal_uInt16( 2 );
     570             :     rStrm.EndRecord();
     571             : 
     572             :     // OBJFLAGS
     573             :     rStrm.StartRecord( EXC_ID_OBJFLAGS, 2 );
     574             :     rStrm << sal_uInt16( 0x0031 );
     575             :     rStrm.EndRecord();
     576             : 
     577             :     // OBJPICTFMLA
     578             :     XclExpString aClass( maClassName );
     579             :     sal_uInt16 nClassNameSize = static_cast< sal_uInt16 >( aClass.GetSize() );
     580             :     sal_uInt16 nClassNamePad = nClassNameSize & 1;
     581             :     sal_uInt16 nFirstPartSize = 12 + nClassNameSize + nClassNamePad;
     582             : 
     583             :     const XclTokenArray* pCellLink = GetCellLinkTokArr();
     584             :     sal_uInt16 nCellLinkSize = pCellLink ? ((pCellLink->GetSize() + 7) & 0xFFFE) : 0;
     585             : 
     586             :     const XclTokenArray* pSrcRange = GetSourceRangeTokArr();
     587             :     sal_uInt16 nSrcRangeSize = pSrcRange ? ((pSrcRange->GetSize() + 7) & 0xFFFE) : 0;
     588             : 
     589             :     sal_uInt16 nPictFmlaSize = nFirstPartSize + nCellLinkSize + nSrcRangeSize + 18;
     590             :     rStrm.StartRecord( EXC_ID_OBJPICTFMLA, nPictFmlaSize );
     591             : 
     592             :     rStrm   << sal_uInt16( nFirstPartSize )             // size of first part
     593             :             << sal_uInt16( 5 )                          // formula size
     594             :             << sal_uInt32( 0 )                          // unknown ID
     595             :             << sal_uInt8( 0x02 ) << sal_uInt32( 0 )     // tTbl token with unknown ID
     596             :             << sal_uInt8( 3 )                           // pad to word
     597             :             << aClass;                                  // "Forms.***.1"
     598             :     rStrm.WriteZeroBytes( nClassNamePad );              // pad to word
     599             :     rStrm   << mnStrmStart                              // start in 'Ctls' stream
     600             :             << mnStrmSize                               // size in 'Ctls' stream
     601             :             << sal_uInt32( 0 );                         // class ID size
     602             :     // cell link
     603             :     rStrm << nCellLinkSize;
     604             :     if( pCellLink )
     605             :         WriteFormula( rStrm, *pCellLink );
     606             :     // list source range
     607             :     rStrm << nSrcRangeSize;
     608             :     if( pSrcRange )
     609             :         WriteFormula( rStrm, *pSrcRange );
     610             : 
     611             :     rStrm.EndRecord();
     612             : }
     613             : 
     614             : #else
     615             : 
     616           0 : XclExpTbxControlObj::XclExpTbxControlObj( XclExpObjectManager& rRoot, Reference< XShape > xShape , const Rectangle* pChildAnchor ) :
     617             :     XclObj( rRoot, EXC_OBJTYPE_UNKNOWN, true ),
     618             :     XclMacroHelper( rRoot ),
     619             :     mnHeight( 0 ),
     620             :     mnState( 0 ),
     621             :     mnLineCount( 0 ),
     622             :     mnSelEntry( 0 ),
     623             :     mnScrollValue( 0 ),
     624             :     mnScrollMin( 0 ),
     625             :     mnScrollMax( 100 ),
     626             :     mnScrollStep( 1 ),
     627             :     mnScrollPage( 10 ),
     628             :     mbFlatButton( false ),
     629             :     mbFlatBorder( false ),
     630             :     mbMultiSel( false ),
     631           0 :     mbScrollHor( false )
     632             : {
     633             :     namespace FormCompType = ::com::sun::star::form::FormComponentType;
     634             :     namespace AwtVisualEffect = ::com::sun::star::awt::VisualEffect;
     635             :     namespace AwtScrollOrient = ::com::sun::star::awt::ScrollBarOrientation;
     636             : 
     637           0 :     ScfPropertySet aCtrlProp( XclControlHelper::GetControlModel( xShape ) );
     638           0 :     if( !xShape.is() || !aCtrlProp.Is() )
     639             :         return;
     640             : 
     641           0 :     mnHeight = xShape->getSize().Height;
     642           0 :     if( mnHeight <= 0 )
     643             :         return;
     644             : 
     645             :     // control type
     646           0 :     sal_Int16 nClassId = 0;
     647           0 :     if( aCtrlProp.GetProperty( nClassId, "ClassId" ) )
     648             :     {
     649           0 :         switch( nClassId )
     650             :         {
     651           0 :             case FormCompType::COMMANDBUTTON:   mnObjType = EXC_OBJTYPE_BUTTON;       meEventType = EXC_TBX_EVENT_ACTION; break;
     652           0 :             case FormCompType::RADIOBUTTON:     mnObjType = EXC_OBJTYPE_OPTIONBUTTON; meEventType = EXC_TBX_EVENT_ACTION; break;
     653           0 :             case FormCompType::CHECKBOX:        mnObjType = EXC_OBJTYPE_CHECKBOX;     meEventType = EXC_TBX_EVENT_ACTION; break;
     654           0 :             case FormCompType::LISTBOX:         mnObjType = EXC_OBJTYPE_LISTBOX;      meEventType = EXC_TBX_EVENT_CHANGE; break;
     655           0 :             case FormCompType::COMBOBOX:        mnObjType = EXC_OBJTYPE_DROPDOWN;     meEventType = EXC_TBX_EVENT_CHANGE; break;
     656           0 :             case FormCompType::GROUPBOX:        mnObjType = EXC_OBJTYPE_GROUPBOX;     meEventType = EXC_TBX_EVENT_MOUSE;  break;
     657           0 :             case FormCompType::FIXEDTEXT:       mnObjType = EXC_OBJTYPE_LABEL;        meEventType = EXC_TBX_EVENT_MOUSE;  break;
     658           0 :             case FormCompType::SCROLLBAR:       mnObjType = EXC_OBJTYPE_SCROLLBAR;    meEventType = EXC_TBX_EVENT_VALUE;  break;
     659           0 :             case FormCompType::SPINBUTTON:      mnObjType = EXC_OBJTYPE_SPIN;         meEventType = EXC_TBX_EVENT_VALUE;  break;
     660             :         }
     661             :     }
     662           0 :     if( mnObjType == EXC_OBJTYPE_UNKNOWN )
     663             :         return;
     664             : 
     665             :     // OBJ record flags
     666           0 :     SetLocked( sal_True );
     667           0 :     SetPrintable( aCtrlProp.GetBoolProperty( "Printable" ) );
     668           0 :     SetAutoFill( false );
     669           0 :     SetAutoLine( false );
     670             : 
     671             :     // fill DFF property set
     672           0 :     mrEscherEx.OpenContainer( ESCHER_SpContainer );
     673           0 :     mrEscherEx.AddShape( ESCHER_ShpInst_HostControl, SHAPEFLAG_HAVEANCHOR | SHAPEFLAG_HAVESPT );
     674           0 :     EscherPropertyContainer aPropOpt;
     675           0 :     bool bVisible = aCtrlProp.GetBoolProperty( "EnableVisible" );
     676           0 :     aPropOpt.AddOpt( ESCHER_Prop_fPrint, bVisible ? 0x00080000 : 0x00080002 ); // visible flag
     677             : 
     678           0 :     aPropOpt.AddOpt( ESCHER_Prop_LockAgainstGrouping, 0x01000100 ); // bool field
     679           0 :     aPropOpt.AddOpt( ESCHER_Prop_lTxid, 0 );                        // Text ID
     680           0 :     aPropOpt.AddOpt( ESCHER_Prop_WrapText, 0x00000001 );
     681           0 :     aPropOpt.AddOpt( ESCHER_Prop_FitTextToShape, 0x001A0008 );      // bool field
     682           0 :     aPropOpt.AddOpt( ESCHER_Prop_fNoFillHitTest, 0x00100000 );      // bool field
     683           0 :     aPropOpt.AddOpt( ESCHER_Prop_fNoLineDrawDash, 0x00080000 );     // bool field
     684             : 
     685             :     // #i51348# name of the control, may overwrite shape name
     686           0 :     OUString aCtrlName;
     687           0 :     if( aCtrlProp.GetProperty( aCtrlName, "Name" ) && !aCtrlName.isEmpty() )
     688           0 :         aPropOpt.AddOpt( ESCHER_Prop_wzName, aCtrlName );
     689             : 
     690             :     // write DFF property set to stream
     691           0 :     aPropOpt.Commit( mrEscherEx.GetStream() );
     692             : 
     693             :     // anchor
     694           0 :     ImplWriteAnchor( GetRoot(), SdrObject::getSdrObjectFromXShape( xShape ), pChildAnchor );
     695             : 
     696           0 :     mrEscherEx.AddAtom( 0, ESCHER_ClientData );                       // OBJ record
     697           0 :     mrEscherEx.UpdateDffFragmentEnd();
     698             : 
     699             :     // control label
     700           0 :     OUString aString;
     701           0 :     if( aCtrlProp.GetProperty( aString, "Label" ) )
     702             :     {
     703             :         /*  Be sure to construct the MSODRAWING record containing the
     704             :             ClientTextbox atom after the base OBJ's MSODRAWING record data is
     705             :             completed. */
     706           0 :         pClientTextbox = new XclExpMsoDrawing( mrEscherEx );
     707           0 :         mrEscherEx.AddAtom( 0, ESCHER_ClientTextbox );  // TXO record
     708           0 :         mrEscherEx.UpdateDffFragmentEnd();
     709             : 
     710           0 :         sal_uInt16 nXclFont = EXC_FONT_APP;
     711           0 :         if( !aString.isEmpty() )
     712             :         {
     713           0 :             XclFontData aFontData;
     714           0 :             GetFontPropSetHelper().ReadFontProperties( aFontData, aCtrlProp, EXC_FONTPROPSET_CONTROL );
     715           0 :             if( (aFontData.maName.Len() > 0) && (aFontData.mnHeight > 0) )
     716           0 :                 nXclFont = GetFontBuffer().Insert( aFontData, EXC_COLOR_CTRLTEXT );
     717             :         }
     718             : 
     719           0 :         pTxo = new XclTxo( aString, nXclFont );
     720           0 :         pTxo->SetHorAlign( (mnObjType == EXC_OBJTYPE_BUTTON) ? EXC_OBJ_HOR_CENTER : EXC_OBJ_HOR_LEFT );
     721           0 :         pTxo->SetVerAlign( EXC_OBJ_VER_CENTER );
     722             :     }
     723             : 
     724           0 :     mrEscherEx.CloseContainer();  // ESCHER_SpContainer
     725             : 
     726             :     // other properties
     727           0 :     aCtrlProp.GetProperty( mnLineCount, "LineCount" );
     728             : 
     729             :     // border style
     730           0 :     sal_Int16 nApiButton = AwtVisualEffect::LOOK3D;
     731           0 :     sal_Int16 nApiBorder = AwtVisualEffect::LOOK3D;
     732           0 :     switch( nClassId )
     733             :     {
     734             :         case FormCompType::LISTBOX:
     735             :         case FormCompType::COMBOBOX:
     736           0 :             aCtrlProp.GetProperty( nApiBorder, "Border" );
     737           0 :         break;
     738             :         case FormCompType::CHECKBOX:
     739             :         case FormCompType::RADIOBUTTON:
     740           0 :             aCtrlProp.GetProperty( nApiButton, "VisualEffect" );
     741           0 :             nApiBorder = AwtVisualEffect::NONE;
     742           0 :         break;
     743             :         // Push button cannot be set to flat in Excel
     744             :         case FormCompType::COMMANDBUTTON:
     745           0 :             nApiBorder = AwtVisualEffect::LOOK3D;
     746           0 :         break;
     747             :         // Label does not support a border in Excel
     748             :         case FormCompType::FIXEDTEXT:
     749           0 :             nApiBorder = AwtVisualEffect::NONE;
     750           0 :         break;
     751             :         /*  Scroll bar and spin button have a "Border" property, but it is
     752             :             really used for a border, and not for own 3D/flat look (#i34712#). */
     753             :         case FormCompType::SCROLLBAR:
     754             :         case FormCompType::SPINBUTTON:
     755           0 :             nApiButton = AwtVisualEffect::LOOK3D;
     756           0 :             nApiBorder = AwtVisualEffect::NONE;
     757           0 :         break;
     758             :         // Group box does not support flat style (#i34712#)
     759             :         case FormCompType::GROUPBOX:
     760           0 :             nApiBorder = AwtVisualEffect::LOOK3D;
     761           0 :         break;
     762             :     }
     763           0 :     mbFlatButton = nApiButton != AwtVisualEffect::LOOK3D;
     764           0 :     mbFlatBorder = nApiBorder != AwtVisualEffect::LOOK3D;
     765             : 
     766             :     // control state
     767           0 :     sal_Int16 nApiState = 0;
     768           0 :     if( aCtrlProp.GetProperty( nApiState, "State" ) )
     769             :     {
     770           0 :         switch( nApiState )
     771             :         {
     772           0 :             case 0: mnState = EXC_OBJ_CHECKBOX_UNCHECKED;  break;
     773           0 :             case 1: mnState = EXC_OBJ_CHECKBOX_CHECKED;    break;
     774           0 :             case 2: mnState = EXC_OBJ_CHECKBOX_TRISTATE;   break;
     775             :         }
     776             :     }
     777             : 
     778             :     // special control contents
     779           0 :     switch( nClassId )
     780             :     {
     781             :         case FormCompType::LISTBOX:
     782             :         {
     783           0 :             mbMultiSel = aCtrlProp.GetBoolProperty( "MultiSelection" );
     784           0 :             Sequence< sal_Int16 > aSelection;
     785           0 :             if( aCtrlProp.GetProperty( aSelection, "SelectedItems" ) )
     786             :             {
     787           0 :                 sal_Int32 nLen = aSelection.getLength();
     788           0 :                 if( nLen > 0 )
     789             :                 {
     790           0 :                     mnSelEntry = aSelection[ 0 ] + 1;
     791           0 :                     maMultiSel.resize( nLen );
     792           0 :                     const sal_Int16* pnBegin = aSelection.getConstArray();
     793           0 :                     ::std::copy( pnBegin, pnBegin + nLen, maMultiSel.begin() );
     794             :                 }
     795             :             }
     796             : 
     797             :             // convert listbox with dropdown button to Excel dropdown
     798           0 :             if( aCtrlProp.GetBoolProperty( "Dropdown" ) )
     799           0 :                 mnObjType = EXC_OBJTYPE_DROPDOWN;
     800             :         }
     801           0 :         break;
     802             : 
     803             :         case FormCompType::COMBOBOX:
     804             :         {
     805           0 :             Sequence< OUString > aStringList;
     806           0 :             OUString aDefText;
     807           0 :             if( aCtrlProp.GetProperty( aStringList, "StringItemList" ) &&
     808           0 :                 aCtrlProp.GetProperty( aDefText, "Text" ) &&
     809           0 :                 aStringList.getLength() && !aDefText.isEmpty() )
     810             :             {
     811           0 :                 const OUString* pBegin = aStringList.getConstArray();
     812           0 :                 const OUString* pEnd = pBegin + aStringList.getLength();
     813           0 :                 const OUString* pString = ::std::find( pBegin, pEnd, aDefText );
     814           0 :                 if( pString != pEnd )
     815           0 :                     mnSelEntry = static_cast< sal_Int16 >( pString - pBegin + 1 );  // 1-based
     816           0 :                 if( mnSelEntry > 0 )
     817           0 :                     maMultiSel.resize( 1, mnSelEntry - 1 );
     818             :             }
     819             : 
     820             :             // convert combobox without dropdown button to Excel listbox
     821           0 :             if( !aCtrlProp.GetBoolProperty( "Dropdown" ) )
     822           0 :                 mnObjType = EXC_OBJTYPE_LISTBOX;
     823             :         }
     824           0 :         break;
     825             : 
     826             :         case FormCompType::SCROLLBAR:
     827             :         {
     828           0 :             sal_Int32 nApiValue = 0;
     829           0 :             if( aCtrlProp.GetProperty( nApiValue, "ScrollValueMin" ) )
     830           0 :                 mnScrollMin = limit_cast< sal_uInt16 >( nApiValue, EXC_OBJ_SCROLLBAR_MIN, EXC_OBJ_SCROLLBAR_MAX );
     831           0 :             if( aCtrlProp.GetProperty( nApiValue, "ScrollValueMax" ) )
     832           0 :                 mnScrollMax = limit_cast< sal_uInt16 >( nApiValue, mnScrollMin, EXC_OBJ_SCROLLBAR_MIN );
     833           0 :             if( aCtrlProp.GetProperty( nApiValue, "ScrollValue" ) )
     834           0 :                 mnScrollValue = limit_cast< sal_uInt16 >( nApiValue, mnScrollMin, mnScrollMax );
     835           0 :             if( aCtrlProp.GetProperty( nApiValue, "LineIncrement" ) )
     836           0 :                 mnScrollStep = limit_cast< sal_uInt16 >( nApiValue, EXC_OBJ_SCROLLBAR_MIN, EXC_OBJ_SCROLLBAR_MAX );
     837           0 :             if( aCtrlProp.GetProperty( nApiValue, "BlockIncrement" ) )
     838           0 :                 mnScrollPage = limit_cast< sal_uInt16 >( nApiValue, EXC_OBJ_SCROLLBAR_MIN, EXC_OBJ_SCROLLBAR_MAX );
     839           0 :             if( aCtrlProp.GetProperty( nApiValue, "Orientation" ) )
     840           0 :                 mbScrollHor = nApiValue == AwtScrollOrient::HORIZONTAL;
     841             :         }
     842           0 :         break;
     843             : 
     844             :         case FormCompType::SPINBUTTON:
     845             :         {
     846           0 :             sal_Int32 nApiValue = 0;
     847           0 :             if( aCtrlProp.GetProperty( nApiValue, "SpinValueMin" ) )
     848           0 :                 mnScrollMin = limit_cast< sal_uInt16 >( nApiValue, EXC_OBJ_SCROLLBAR_MIN, EXC_OBJ_SCROLLBAR_MAX );
     849           0 :             if( aCtrlProp.GetProperty( nApiValue, "SpinValueMax" ) )
     850           0 :                 mnScrollMax = limit_cast< sal_uInt16 >( nApiValue, mnScrollMin, EXC_OBJ_SCROLLBAR_MAX );
     851           0 :             if( aCtrlProp.GetProperty( nApiValue, "SpinValue" ) )
     852           0 :                 mnScrollValue = limit_cast< sal_uInt16 >( nApiValue, mnScrollMin, mnScrollMax );
     853           0 :             if( aCtrlProp.GetProperty( nApiValue, "SpinIncrement" ) )
     854           0 :                 mnScrollStep = limit_cast< sal_uInt16 >( nApiValue, EXC_OBJ_SCROLLBAR_MIN, EXC_OBJ_SCROLLBAR_MAX );
     855           0 :             if( aCtrlProp.GetProperty( nApiValue, "Orientation" ) )
     856           0 :                 mbScrollHor = nApiValue == AwtScrollOrient::HORIZONTAL;
     857             :         }
     858           0 :         break;
     859             :     }
     860             : 
     861             :     // spreadsheet links
     862           0 :     ConvertSheetLinks( xShape );
     863             : }
     864             : 
     865           0 : bool XclExpTbxControlObj::SetMacroLink( const ScriptEventDescriptor& rEvent )
     866             : {
     867           0 :     return XclMacroHelper::SetMacroLink( rEvent, meEventType );
     868             : }
     869             : 
     870           0 : void XclExpTbxControlObj::WriteSubRecs( XclExpStream& rStrm )
     871             : {
     872           0 :     switch( mnObjType )
     873             :     {
     874             :         // *** Push buttons, labels ***
     875             : 
     876             :         case EXC_OBJTYPE_BUTTON:
     877             :         case EXC_OBJTYPE_LABEL:
     878             :             // ftMacro - macro link
     879           0 :             WriteMacroSubRec( rStrm );
     880           0 :         break;
     881             : 
     882             :         // *** Check boxes, option buttons ***
     883             : 
     884             :         case EXC_OBJTYPE_CHECKBOX:
     885             :         case EXC_OBJTYPE_OPTIONBUTTON:
     886             :         {
     887             :             // ftCbls - box properties
     888           0 :             sal_uInt16 nStyle = 0;
     889           0 :             ::set_flag( nStyle, EXC_OBJ_CHECKBOX_FLAT, mbFlatButton );
     890             : 
     891           0 :             rStrm.StartRecord( EXC_ID_OBJCBLS, 12 );
     892           0 :             rStrm << mnState;
     893           0 :             rStrm.WriteZeroBytes( 8 );
     894           0 :             rStrm << nStyle;
     895           0 :             rStrm.EndRecord();
     896             : 
     897             :             // ftMacro - macro link
     898           0 :             WriteMacroSubRec( rStrm );
     899             :             // ftCblsFmla subrecord - cell link
     900           0 :             WriteCellLinkSubRec( rStrm, EXC_ID_OBJCBLSFMLA );
     901             : 
     902             :             // ftCblsData subrecord - box properties, again
     903           0 :             rStrm.StartRecord( EXC_ID_OBJCBLS, 8 );
     904           0 :             rStrm << mnState;
     905           0 :             rStrm.WriteZeroBytes( 4 );
     906           0 :             rStrm << nStyle;
     907           0 :             rStrm.EndRecord();
     908             :         }
     909           0 :         break;
     910             : 
     911             :         // *** List boxes, combo boxes ***
     912             : 
     913             :         case EXC_OBJTYPE_LISTBOX:
     914             :         case EXC_OBJTYPE_DROPDOWN:
     915             :         {
     916           0 :             sal_uInt16 nEntryCount = GetSourceEntryCount();
     917             : 
     918             :             // ftSbs subrecord - Scroll bars
     919           0 :             sal_Int32 nLineHeight = XclTools::GetHmmFromTwips( 200 );   // always 10pt
     920           0 :             if( mnObjType == EXC_OBJTYPE_LISTBOX )
     921           0 :                 mnLineCount = static_cast< sal_uInt16 >( mnHeight / nLineHeight );
     922           0 :             mnScrollValue = 0;
     923           0 :             mnScrollMin = 0;
     924           0 :             sal_uInt16 nInvisLines = (nEntryCount >= mnLineCount) ? (nEntryCount - mnLineCount) : 0;
     925           0 :             mnScrollMax = limit_cast< sal_uInt16 >( nInvisLines, EXC_OBJ_SCROLLBAR_MIN, EXC_OBJ_SCROLLBAR_MAX );
     926           0 :             mnScrollStep = 1;
     927           0 :             mnScrollPage = limit_cast< sal_uInt16 >( mnLineCount, EXC_OBJ_SCROLLBAR_MIN, EXC_OBJ_SCROLLBAR_MAX );
     928           0 :             mbScrollHor = false;
     929           0 :             WriteSbs( rStrm );
     930             : 
     931             :             // ftMacro - macro link
     932           0 :             WriteMacroSubRec( rStrm );
     933             :             // ftSbsFmla subrecord - cell link
     934           0 :             WriteCellLinkSubRec( rStrm, EXC_ID_OBJSBSFMLA );
     935             : 
     936             :             // ftLbsData - source data range and box properties
     937           0 :             sal_uInt16 nStyle = 0;
     938           0 :             ::insert_value( nStyle, mbMultiSel ? EXC_OBJ_LISTBOX_MULTI : EXC_OBJ_LISTBOX_SINGLE, 4, 2 );
     939           0 :             ::set_flag( nStyle, EXC_OBJ_LISTBOX_FLAT, mbFlatBorder );
     940             : 
     941           0 :             rStrm.StartRecord( EXC_ID_OBJLBSDATA, 0 );
     942             : 
     943           0 :             if( const XclTokenArray* pSrcRange = GetSourceRangeTokArr() )
     944             :             {
     945           0 :                 rStrm << static_cast< sal_uInt16 >( (pSrcRange->GetSize() + 7) & 0xFFFE );
     946           0 :                 WriteFormula( rStrm, *pSrcRange );
     947             :             }
     948             :             else
     949           0 :                 rStrm << sal_uInt16( 0 );
     950             : 
     951           0 :             rStrm << nEntryCount << mnSelEntry << nStyle << sal_uInt16( 0 );
     952           0 :             if( mnObjType == EXC_OBJTYPE_LISTBOX )
     953             :             {
     954           0 :                 if( nEntryCount )
     955             :                 {
     956           0 :                     ScfUInt8Vec aSelEx( nEntryCount, 0 );
     957           0 :                     for( ScfInt16Vec::const_iterator aIt = maMultiSel.begin(), aEnd = maMultiSel.end(); aIt != aEnd; ++aIt )
     958           0 :                         if( *aIt < nEntryCount )
     959           0 :                             aSelEx[ *aIt ] = 1;
     960           0 :                     rStrm.Write( &aSelEx[ 0 ], aSelEx.size() );
     961             :                 }
     962             :             }
     963           0 :             else if( mnObjType == EXC_OBJTYPE_DROPDOWN )
     964             :             {
     965           0 :                 rStrm << sal_uInt16( 0 ) << mnLineCount << sal_uInt16( 0 ) << sal_uInt16( 0 );
     966             :             }
     967             : 
     968           0 :             rStrm.EndRecord();
     969             :         }
     970           0 :         break;
     971             : 
     972             :         // *** Spin buttons, scrollbars ***
     973             : 
     974             :         case EXC_OBJTYPE_SPIN:
     975             :         case EXC_OBJTYPE_SCROLLBAR:
     976             :         {
     977             :             // ftSbs subrecord - scroll bars
     978           0 :             WriteSbs( rStrm );
     979             :             // ftMacro - macro link
     980           0 :             WriteMacroSubRec( rStrm );
     981             :             // ftSbsFmla subrecord - cell link
     982           0 :             WriteCellLinkSubRec( rStrm, EXC_ID_OBJSBSFMLA );
     983             :         }
     984           0 :         break;
     985             : 
     986             :         // *** Group boxes ***
     987             : 
     988             :         case EXC_OBJTYPE_GROUPBOX:
     989             :         {
     990             :             // ftMacro - macro link
     991           0 :             WriteMacroSubRec( rStrm );
     992             : 
     993             :             // ftGboData subrecord - group box properties
     994           0 :             sal_uInt16 nStyle = 0;
     995           0 :             ::set_flag( nStyle, EXC_OBJ_GROUPBOX_FLAT, mbFlatBorder );
     996             : 
     997           0 :             rStrm.StartRecord( EXC_ID_OBJGBODATA, 6 );
     998           0 :             rStrm   << sal_uInt32( 0 )
     999           0 :                     << nStyle;
    1000           0 :             rStrm.EndRecord();
    1001             :         }
    1002           0 :         break;
    1003             :     }
    1004           0 : }
    1005             : 
    1006           0 : void XclExpTbxControlObj::WriteCellLinkSubRec( XclExpStream& rStrm, sal_uInt16 nSubRecId )
    1007             : {
    1008           0 :     if( const XclTokenArray* pCellLink = GetCellLinkTokArr() )
    1009           0 :         WriteFormulaSubRec( rStrm, nSubRecId, *pCellLink );
    1010           0 : }
    1011             : 
    1012           0 : void XclExpTbxControlObj::WriteSbs( XclExpStream& rStrm )
    1013             : {
    1014           0 :     sal_uInt16 nOrient = 0;
    1015           0 :     ::set_flag( nOrient, EXC_OBJ_SCROLLBAR_HOR, mbScrollHor );
    1016           0 :     sal_uInt16 nStyle = EXC_OBJ_SCROLLBAR_DEFFLAGS;
    1017           0 :     ::set_flag( nStyle, EXC_OBJ_SCROLLBAR_FLAT, mbFlatButton );
    1018             : 
    1019           0 :     rStrm.StartRecord( EXC_ID_OBJSBS, 20 );
    1020           0 :     rStrm   << sal_uInt32( 0 )              // reserved
    1021           0 :             << mnScrollValue                // thumb position
    1022           0 :             << mnScrollMin                  // thumb min pos
    1023           0 :             << mnScrollMax                  // thumb max pos
    1024           0 :             << mnScrollStep                 // line increment
    1025           0 :             << mnScrollPage                 // page increment
    1026           0 :             << nOrient                      // 0 = vertical, 1 = horizontal
    1027           0 :             << sal_uInt16( 15 )             // thumb width
    1028           0 :             << nStyle;                      // flags/style
    1029           0 :     rStrm.EndRecord();
    1030           0 : }
    1031             : 
    1032             : #endif
    1033             : 
    1034             : // ----------------------------------------------------------------------------
    1035             : 
    1036           0 : XclExpChartObj::XclExpChartObj( XclExpObjectManager& rObjMgr, Reference< XShape > xShape, const Rectangle* pChildAnchor ) :
    1037             :     XclObj( rObjMgr, EXC_OBJTYPE_CHART ),
    1038           0 :     XclExpRoot( rObjMgr.GetRoot() ), mxShape( xShape )
    1039             : {
    1040             :     // create the MSODRAWING record contents for the chart object
    1041           0 :     mrEscherEx.OpenContainer( ESCHER_SpContainer );
    1042           0 :     mrEscherEx.AddShape( ESCHER_ShpInst_HostControl, SHAPEFLAG_HAVEANCHOR | SHAPEFLAG_HAVESPT );
    1043           0 :     EscherPropertyContainer aPropOpt;
    1044           0 :     aPropOpt.AddOpt( ESCHER_Prop_LockAgainstGrouping, 0x01040104 );
    1045           0 :     aPropOpt.AddOpt( ESCHER_Prop_FitTextToShape, 0x00080008 );
    1046           0 :     aPropOpt.AddOpt( ESCHER_Prop_fillColor, 0x0800004E );
    1047           0 :     aPropOpt.AddOpt( ESCHER_Prop_fillBackColor, 0x0800004D );
    1048           0 :     aPropOpt.AddOpt( ESCHER_Prop_fNoFillHitTest, 0x00110010 );
    1049           0 :     aPropOpt.AddOpt( ESCHER_Prop_lineColor, 0x0800004D );
    1050           0 :     aPropOpt.AddOpt( ESCHER_Prop_fNoLineDrawDash, 0x00080008 );
    1051           0 :     aPropOpt.AddOpt( ESCHER_Prop_fshadowObscured, 0x00020000 );
    1052           0 :     aPropOpt.AddOpt( ESCHER_Prop_fPrint, 0x00080000 );
    1053           0 :     aPropOpt.Commit( mrEscherEx.GetStream() );
    1054             : 
    1055             :     // anchor
    1056           0 :     SdrObject* pSdrObj = SdrObject::getSdrObjectFromXShape( xShape );
    1057           0 :     ImplWriteAnchor( GetRoot(), pSdrObj, pChildAnchor );
    1058             : 
    1059             :     // client data (the following OBJ record)
    1060           0 :     mrEscherEx.AddAtom( 0, ESCHER_ClientData );
    1061           0 :     mrEscherEx.CloseContainer();  // ESCHER_SpContainer
    1062           0 :     mrEscherEx.UpdateDffFragmentEnd();
    1063             : 
    1064             :     // load the chart OLE object
    1065           0 :     if( SdrOle2Obj* pSdrOleObj = dynamic_cast< SdrOle2Obj* >( pSdrObj ) )
    1066           0 :         svt::EmbeddedObjectRef::TryRunningState( pSdrOleObj->GetObjRef() );
    1067             : 
    1068             :     // create the chart substream object
    1069           0 :     ScfPropertySet aShapeProp( xShape );
    1070           0 :     Reference< XModel > xModel;
    1071           0 :     aShapeProp.GetProperty( xModel, "Model" );
    1072           0 :     mxChartDoc.set( xModel,UNO_QUERY );
    1073           0 :     ::com::sun::star::awt::Rectangle aBoundRect;
    1074           0 :     aShapeProp.GetProperty( aBoundRect, "BoundRect" );
    1075           0 :     Rectangle aChartRect( Point( aBoundRect.X, aBoundRect.Y ), Size( aBoundRect.Width, aBoundRect.Height ) );
    1076           0 :     mxChart.reset( new XclExpChart( GetRoot(), xModel, aChartRect ) );
    1077           0 : }
    1078             : 
    1079           0 : XclExpChartObj::~XclExpChartObj()
    1080             : {
    1081           0 : }
    1082             : 
    1083           0 : void XclExpChartObj::Save( XclExpStream& rStrm )
    1084             : {
    1085             :     // content of OBJ record
    1086           0 :     XclObj::Save( rStrm );
    1087             :     // chart substream
    1088           0 :     mxChart->Save( rStrm );
    1089           0 : }
    1090             : 
    1091           0 : void XclExpChartObj::SaveXml( XclExpXmlStream& rStrm )
    1092             : {
    1093             :     OSL_TRACE("XclExpChartObj::SaveXml -- Entry point to export chart");
    1094           0 :     sax_fastparser::FSHelperPtr pDrawing = rStrm.GetCurrentStream();
    1095             : 
    1096             :     // FIXME: two cell? it seems the two cell anchor is incorrect.
    1097             :     pDrawing->startElement( FSNS( XML_xdr, XML_twoCellAnchor ), // OOXTODO: oneCellAnchor, absoluteAnchor
    1098             :             XML_editAs, "oneCell",
    1099           0 :             FSEND );
    1100           0 :     Reference< XPropertySet > xPropSet( mxShape, UNO_QUERY );
    1101           0 :     if (xPropSet.is())
    1102             :     {
    1103           0 :         XclObjAny::WriteFromTo( rStrm, mxShape, GetTab() );
    1104           0 :         Reference< XModel > xModel( mxChartDoc, UNO_QUERY );
    1105           0 :         ChartExport aChartExport( XML_xdr, pDrawing, xModel, &rStrm, DrawingML::DOCUMENT_XLSX );
    1106             :         static sal_Int32 nChartCount = 0;
    1107           0 :         nChartCount++;
    1108           0 :         aChartExport.WriteChartObj( mxShape, nChartCount );
    1109             :         // TODO: get the correcto chart number
    1110             :     }
    1111             : 
    1112             :     pDrawing->singleElement( FSNS( XML_xdr, XML_clientData),
    1113             :             // OOXTODO: XML_fLocksWithSheet
    1114             :             // OOXTODO: XML_fPrintsWithSheet
    1115           0 :             FSEND );
    1116           0 :     pDrawing->endElement( FSNS( XML_xdr, XML_twoCellAnchor ) );
    1117           0 : }
    1118             : 
    1119           0 : void XclExpChartObj::WriteChartObj( sax_fastparser::FSHelperPtr pDrawing, XclExpXmlStream& rStrm )
    1120             : {
    1121           0 :     pDrawing->startElement(  FSNS( XML_xdr, XML_graphicFrame ), FSEND );
    1122             : 
    1123           0 :     pDrawing->startElement(  FSNS( XML_xdr, XML_nvGraphicFramePr ), FSEND );
    1124             : 
    1125             :     // TODO: get the correct chart name chart id
    1126           0 :     OUString sName = "Object 1";
    1127           0 :     Reference< XNamed > xNamed( mxShape, UNO_QUERY );
    1128           0 :     if (xNamed.is())
    1129             :     {
    1130           0 :         sName = xNamed->getName();
    1131             :     }
    1132           0 :     sal_Int32 nID = rStrm.GetUniqueId();
    1133             : 
    1134             :     pDrawing->singleElement( FSNS( XML_xdr, XML_cNvPr ),
    1135             :                           XML_id,     I32S( nID ),
    1136             :                           XML_name,   USS( sName ),
    1137           0 :                           FSEND );
    1138             : 
    1139             :     pDrawing->singleElement( FSNS( XML_xdr, XML_cNvGraphicFramePr ),
    1140           0 :                           FSEND );
    1141             : 
    1142           0 :     pDrawing->endElement( FSNS( XML_xdr, XML_nvGraphicFramePr ) );
    1143             : 
    1144             :     // visual chart properties
    1145           0 :     WriteShapeTransformation( pDrawing, mxShape );
    1146             : 
    1147             :     // writer chart object
    1148           0 :     pDrawing->startElement( FSNS( XML_a, XML_graphic ), FSEND );
    1149             :     pDrawing->startElement( FSNS( XML_a, XML_graphicData ),
    1150             :                        XML_uri, "http://schemas.openxmlformats.org/drawingml/2006/chart",
    1151           0 :                        FSEND );
    1152           0 :     OUString sId;
    1153             :     // TODO:
    1154             :     static sal_Int32 nChartCount = 0;
    1155           0 :     nChartCount++;
    1156             :     sax_fastparser::FSHelperPtr pChart = rStrm.CreateOutputStream(
    1157             :             XclXmlUtils::GetStreamName( "xl/", "charts/chart", nChartCount ),
    1158             :             XclXmlUtils::GetStreamName( "../", "charts/chart", nChartCount ),
    1159           0 :             rStrm.GetCurrentStream()->getOutputStream(),
    1160             :             "application/vnd.openxmlformats-officedocument.drawingml.chart+xml",
    1161             :             "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart",
    1162           0 :             &sId );
    1163             : 
    1164             :     pDrawing->singleElement(  FSNS( XML_c, XML_chart ),
    1165             :             FSNS( XML_xmlns, XML_c ), "http://schemas.openxmlformats.org/drawingml/2006/chart",
    1166             :             FSNS( XML_xmlns, XML_r ), "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
    1167             :             FSNS( XML_r, XML_id ), XclXmlUtils::ToOString( sId ).getStr(),
    1168           0 :             FSEND );
    1169             : 
    1170           0 :     rStrm.PushStream( pChart );
    1171           0 :     Reference< XModel > xModel( mxChartDoc, UNO_QUERY );
    1172           0 :     ChartExport aChartExport( XML_xdr, pChart, xModel, &rStrm, DrawingML::DOCUMENT_XLSX );
    1173           0 :     aChartExport.ExportContent();
    1174             : 
    1175           0 :     rStrm.PopStream();
    1176             : 
    1177           0 :     pDrawing->endElement( FSNS( XML_a, XML_graphicData ) );
    1178           0 :     pDrawing->endElement( FSNS( XML_a, XML_graphic ) );
    1179           0 :     pDrawing->endElement( FSNS( XML_xdr, XML_graphicFrame ) );
    1180             : 
    1181           0 : }
    1182             : 
    1183           0 : void XclExpChartObj::WriteShapeTransformation( sax_fastparser::FSHelperPtr pFS, const XShapeRef& rXShape, sal_Bool bFlipH, sal_Bool bFlipV, sal_Int32 nRotation )
    1184             : {
    1185           0 :     ::com::sun::star::awt::Point aPos = rXShape->getPosition();
    1186           0 :     ::com::sun::star::awt::Size aSize = rXShape->getSize();
    1187             : 
    1188             :     pFS->startElementNS( XML_xdr, XML_xfrm,
    1189             :                           XML_flipH, bFlipH ? "1" : NULL,
    1190             :                           XML_flipV, bFlipV ? "1" : NULL,
    1191           0 :                           XML_rot, nRotation ? I32S( nRotation ) : NULL,
    1192           0 :                           FSEND );
    1193             : 
    1194           0 :     pFS->singleElementNS( XML_a, XML_off, XML_x, IS( MM100toEMU( aPos.X ) ), XML_y, IS( MM100toEMU( aPos.Y ) ), FSEND );
    1195           0 :     pFS->singleElementNS( XML_a, XML_ext, XML_cx, IS( MM100toEMU( aSize.Width ) ), XML_cy, IS( MM100toEMU( aSize.Height ) ), FSEND );
    1196             : 
    1197           0 :     pFS->endElementNS( XML_xdr, XML_xfrm );
    1198           0 : }
    1199             : 
    1200             : // ============================================================================
    1201             : 
    1202           0 : XclExpNote::XclExpNote( const XclExpRoot& rRoot, const ScAddress& rScPos,
    1203             :         const ScPostIt* pScNote, const String& rAddText ) :
    1204             :     XclExpRecord( EXC_ID_NOTE ),
    1205             :     maScPos( rScPos ),
    1206             :     mnObjId( EXC_OBJ_INVALID_ID ),
    1207           0 :     mbVisible( pScNote && pScNote->IsCaptionShown() )
    1208             : {
    1209             :     // get the main note text
    1210           0 :     String aNoteText;
    1211           0 :     if( pScNote )
    1212             :     {
    1213           0 :         aNoteText = pScNote->GetText();
    1214           0 :         const EditTextObject *pEditObj = pScNote->GetEditTextObject();
    1215           0 :         if( pEditObj )
    1216           0 :             mpNoteContents = XclExpStringHelper::CreateString( rRoot, *pEditObj );
    1217             :     }
    1218             :     // append additional text
    1219           0 :     aNoteText = ScGlobal::addToken( aNoteText, rAddText, '\n', 2 );
    1220           0 :     maOrigNoteText = aNoteText;
    1221             : 
    1222             :     // initialize record dependent on BIFF type
    1223           0 :     switch( rRoot.GetBiff() )
    1224             :     {
    1225             :         case EXC_BIFF5:
    1226           0 :             maNoteText = rtl::OUStringToOString(aNoteText, rRoot.GetTextEncoding());
    1227           0 :         break;
    1228             : 
    1229             :         case EXC_BIFF8:
    1230             :         {
    1231             :             // TODO: additional text
    1232           0 :             if( pScNote )
    1233           0 :                 if( SdrCaptionObj* pCaption = pScNote->GetOrCreateCaption( maScPos ) )
    1234             :                 {
    1235           0 :                     lcl_GetFromTo( rRoot, pCaption->GetLogicRect(), maScPos.Tab(), maCommentFrom, maCommentTo );
    1236           0 :                     if( const OutlinerParaObject* pOPO = pCaption->GetOutlinerParaObject() )
    1237           0 :                         mnObjId = rRoot.GetObjectManager().AddObj( new XclObjComment( rRoot.GetObjectManager(), pCaption->GetLogicRect(), pOPO->GetTextObject(), pCaption, mbVisible, maScPos, maCommentFrom, maCommentTo ) );
    1238             : 
    1239           0 :                     SfxItemSet aItemSet = pCaption->GetMergedItemSet();
    1240           0 :                     meTVA       = pCaption->GetTextVerticalAdjust();
    1241           0 :                     meTHA       = pCaption->GetTextHorizontalAdjust();
    1242           0 :                     mbAutoScale = pCaption->GetFitToSize()?true:false;
    1243           0 :                     mbLocked    = pCaption->IsMoveProtect() | pCaption->IsResizeProtect();
    1244             : 
    1245             :                     // AutoFill style would change if Postit.cxx object creation values are changed
    1246           0 :                     OUString aCol(((XFillColorItem &)GETITEM(aItemSet, XFillColorItem , XATTR_FILLCOLOR)).GetValue());
    1247           0 :                     mbAutoFill  = aCol.isEmpty() && (GETITEMVALUE(aItemSet, XFillStyleItem, XATTR_FILLSTYLE, sal_uLong) == XFILL_SOLID);
    1248           0 :                     mbAutoLine  = true;
    1249           0 :                     mbRowHidden = (rRoot.GetDoc().RowHidden(maScPos.Row(),maScPos.Tab()));
    1250           0 :                     mbColHidden = (rRoot.GetDoc().ColHidden(maScPos.Col(),maScPos.Tab()));
    1251             :                 }
    1252             : 
    1253           0 :             SetRecSize( 9 + maAuthor.GetSize() );
    1254             :         }
    1255           0 :         break;
    1256             : 
    1257             :         default:    DBG_ERROR_BIFF();
    1258           0 :     }
    1259           0 : }
    1260             : 
    1261           0 : void XclExpNote::Save( XclExpStream& rStrm )
    1262             : {
    1263           0 :     switch( rStrm.GetRoot().GetBiff() )
    1264             :     {
    1265             :         case EXC_BIFF5:
    1266             :         {
    1267             :             // write the NOTE record directly, there may be the need to create more than one
    1268           0 :             const sal_Char* pcBuffer = maNoteText.getStr();
    1269           0 :             sal_uInt16 nCharsLeft = static_cast< sal_uInt16 >( maNoteText.getLength() );
    1270             : 
    1271           0 :             while( nCharsLeft )
    1272             :             {
    1273           0 :                 sal_uInt16 nWriteChars = ::std::min( nCharsLeft, EXC_NOTE5_MAXLEN );
    1274             : 
    1275           0 :                 rStrm.StartRecord( EXC_ID_NOTE, 6 + nWriteChars );
    1276           0 :                 if( pcBuffer == maNoteText.getStr() )
    1277             :                 {
    1278             :                     // first record: row, col, length of complete text
    1279           0 :                     rStrm   << static_cast< sal_uInt16 >( maScPos.Row() )
    1280           0 :                             << static_cast< sal_uInt16 >( maScPos.Col() )
    1281           0 :                             << nCharsLeft;  // still contains full length
    1282             :                 }
    1283             :                 else
    1284             :                 {
    1285             :                     // next records: -1, 0, length of current text segment
    1286           0 :                     rStrm   << sal_uInt16( 0xFFFF )
    1287           0 :                             << sal_uInt16( 0 )
    1288           0 :                             << nWriteChars;
    1289             :                 }
    1290           0 :                 rStrm.Write( pcBuffer, nWriteChars );
    1291           0 :                 rStrm.EndRecord();
    1292             : 
    1293           0 :                 pcBuffer += nWriteChars;
    1294           0 :                 nCharsLeft = nCharsLeft - nWriteChars;
    1295             :             }
    1296             :         }
    1297           0 :         break;
    1298             : 
    1299             :         case EXC_BIFF8:
    1300           0 :             if( mnObjId != EXC_OBJ_INVALID_ID )
    1301           0 :                 XclExpRecord::Save( rStrm );
    1302           0 :         break;
    1303             : 
    1304             :         default:    DBG_ERROR_BIFF();
    1305             :     }
    1306           0 : }
    1307             : 
    1308           0 : void XclExpNote::WriteBody( XclExpStream& rStrm )
    1309             : {
    1310             :     // BIFF5/BIFF7 is written separately
    1311             :     OSL_ENSURE_BIFF( rStrm.GetRoot().GetBiff() == EXC_BIFF8 );
    1312             : 
    1313           0 :     sal_uInt16 nFlags = 0;
    1314           0 :     ::set_flag( nFlags, EXC_NOTE_VISIBLE, mbVisible );
    1315             : 
    1316           0 :     rStrm   << static_cast< sal_uInt16 >( maScPos.Row() )
    1317           0 :             << static_cast< sal_uInt16 >( maScPos.Col() )
    1318           0 :             << nFlags
    1319           0 :             << mnObjId
    1320           0 :             << maAuthor
    1321           0 :             << sal_uInt8( 0 );
    1322           0 : }
    1323             : 
    1324           0 : void XclExpNote::WriteXml( sal_Int32 nAuthorId, XclExpXmlStream& rStrm )
    1325             : {
    1326           0 :     sax_fastparser::FSHelperPtr rComments = rStrm.GetCurrentStream();
    1327             : 
    1328             :     rComments->startElement( XML_comment,
    1329             :             XML_ref,        XclXmlUtils::ToOString( maScPos ).getStr(),
    1330             :             XML_authorId,   OString::valueOf( nAuthorId ).getStr(),
    1331             :             // OOXTODO: XML_guid,
    1332           0 :             FSEND );
    1333           0 :     rComments->startElement( XML_text, FSEND );
    1334             :     // OOXTODO: phoneticPr, rPh, r
    1335           0 :     if( mpNoteContents )
    1336           0 :         mpNoteContents->WriteXml( rStrm );
    1337           0 :     rComments->endElement( XML_text );
    1338             : 
    1339             : /*
    1340             :    Export of commentPr is disabled, since the current (Oct 2010)
    1341             :    version of MSO 2010 doesn't yet support commentPr
    1342             :  */
    1343             : #if 1//def XLSX_OOXML_FUTURE
    1344           0 :     if( rStrm.getVersion() == oox::core::ISOIEC_29500_2008 )
    1345             :     {
    1346           0 :         rComments->startElement( FSNS( XML_mc, XML_AlternateContent ), FSEND );
    1347           0 :         rComments->startElement( FSNS( XML_mc, XML_Choice ), XML_Requires, "v2", FSEND );
    1348             :         rComments->startElement( XML_commentPr,
    1349             :                 XML_autoFill,       XclXmlUtils::ToPsz( mbAutoFill ),
    1350             :                 XML_autoScale,      XclXmlUtils::ToPsz( mbAutoScale ),
    1351             :                 XML_colHidden,      XclXmlUtils::ToPsz( mbColHidden ),
    1352             :                 XML_locked,         XclXmlUtils::ToPsz( mbLocked ),
    1353             :                 XML_rowHidden,      XclXmlUtils::ToPsz( mbRowHidden ),
    1354             :                 XML_textHAlign,     ToHorizAlign( meTHA ),
    1355             :                 XML_textVAlign,     ToVertAlign( meTVA ) ,
    1356           0 :                 FSEND );
    1357             :         rComments->startElement( XML_anchor,
    1358             :                 XML_moveWithCells, "false",
    1359             :                 XML_sizeWithCells, "false",
    1360           0 :                 FSEND );
    1361           0 :         rComments->startElement( FSNS( XML_xdr, XML_from ), FSEND );
    1362           0 :         lcl_WriteAnchorVertex( rComments, maCommentFrom );
    1363           0 :         rComments->endElement( FSNS( XML_xdr, XML_from ) );
    1364           0 :         rComments->startElement( FSNS( XML_xdr, XML_to ), FSEND );
    1365           0 :         lcl_WriteAnchorVertex( rComments, maCommentTo );
    1366           0 :         rComments->endElement( FSNS( XML_xdr, XML_to ) );
    1367           0 :         rComments->endElement( XML_anchor );
    1368           0 :         rComments->endElement( XML_commentPr );
    1369             : 
    1370           0 :         rComments->endElement( FSNS( XML_mc, XML_Choice ) );
    1371           0 :         rComments->startElement( FSNS( XML_mc, XML_Fallback ), FSEND );
    1372             :         // Any fallback code ?
    1373           0 :         rComments->endElement( FSNS( XML_mc, XML_Fallback ) );
    1374           0 :         rComments->endElement( FSNS( XML_mc, XML_AlternateContent ) );
    1375             :     }
    1376             : #endif
    1377           0 :     rComments->endElement( XML_comment );
    1378           0 : }
    1379             : 
    1380             : // ============================================================================
    1381             : 
    1382           0 : XclMacroHelper::XclMacroHelper( const XclExpRoot& rRoot ) :
    1383           0 :     XclExpControlHelper( rRoot )
    1384             : {
    1385           0 : }
    1386             : 
    1387           0 : XclMacroHelper::~XclMacroHelper()
    1388             : {
    1389           0 : }
    1390             : 
    1391           0 : void XclMacroHelper::WriteMacroSubRec( XclExpStream& rStrm )
    1392             : {
    1393           0 :     if( mxMacroLink )
    1394           0 :         WriteFormulaSubRec( rStrm, EXC_ID_OBJMACRO, *mxMacroLink );
    1395           0 : }
    1396             : 
    1397             : bool
    1398           0 : XclMacroHelper::SetMacroLink( const ScriptEventDescriptor& rEvent, const XclTbxEventType& nEventType )
    1399             : {
    1400           0 :     String aMacroName = XclControlHelper::ExtractFromMacroDescriptor( rEvent, nEventType, GetDocShell() );
    1401           0 :     if( aMacroName.Len() )
    1402             :     {
    1403           0 :         return SetMacroLink( aMacroName );
    1404             :     }
    1405           0 :     return false;
    1406             : }
    1407             : 
    1408             : bool
    1409           0 : XclMacroHelper::SetMacroLink( const String& rMacroName )
    1410             : {
    1411             :     OSL_TRACE("SetMacroLink( macroname:=%s )", rtl::OUStringToOString( rMacroName, RTL_TEXTENCODING_UTF8 ).getStr() );
    1412           0 :     if( rMacroName.Len() )
    1413             :     {
    1414           0 :         sal_uInt16 nExtSheet = GetLocalLinkManager().FindExtSheet( EXC_EXTSH_OWNDOC );
    1415           0 :         sal_uInt16 nNameIdx = GetNameManager().InsertMacroCall( rMacroName, true, false );
    1416           0 :         mxMacroLink = GetFormulaCompiler().CreateNameXFormula( nExtSheet, nNameIdx );
    1417           0 :         return true;
    1418             :     }
    1419           0 :     return false;
    1420             : }
    1421             : 
    1422           0 : XclExpShapeObj::XclExpShapeObj( XclExpObjectManager& rRoot, ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > xShape ) :
    1423             :     XclObjAny( rRoot, xShape ),
    1424           0 :     XclMacroHelper( rRoot )
    1425             : {
    1426           0 :     if( SdrObject* pSdrObj = ::GetSdrObjectFromXShape( xShape ) )
    1427             :     {
    1428           0 :         ScMacroInfo* pInfo = ScDrawLayer::GetMacroInfo( pSdrObj );
    1429           0 :         if ( pInfo && !pInfo->GetMacro().isEmpty() )
    1430             : // FIXME ooo330-m2: XclControlHelper::GetXclMacroName was removed in upstream sources; they started to call XclTools::GetXclMacroName instead; is this enough? it has only one parameter
    1431             : //            SetMacroLink( XclControlHelper::GetXclMacroName( pInfo->GetMacro(), rRoot.GetDocShell() ) );
    1432           0 :             SetMacroLink( XclTools::GetXclMacroName( pInfo->GetMacro() ) );
    1433             :     }
    1434           0 : }
    1435             : 
    1436           0 : XclExpShapeObj::~XclExpShapeObj()
    1437             : {
    1438           0 : }
    1439             : 
    1440           0 : void XclExpShapeObj::WriteSubRecs( XclExpStream& rStrm )
    1441             : {
    1442           0 :     XclObjAny::WriteSubRecs( rStrm );
    1443           0 :     WriteMacroSubRec( rStrm );
    1444           0 : }
    1445             : 
    1446             : // ============================================================================
    1447             : 
    1448           0 : XclExpComments::XclExpComments( SCTAB nTab, XclExpRecordList< XclExpNote >& rNotes )
    1449           0 :     : mnTab( nTab ), mrNotes( rNotes )
    1450             : {
    1451           0 : }
    1452             : 
    1453             : struct OUStringLess : public std::binary_function<OUString, OUString, bool>
    1454             : {
    1455           0 :     bool operator()(const OUString& x, const OUString& y) const
    1456             :     {
    1457           0 :         return x.compareTo( y ) < 0;
    1458             :     }
    1459             : };
    1460             : 
    1461           0 : void XclExpComments::SaveXml( XclExpXmlStream& rStrm )
    1462             : {
    1463           0 :     if( mrNotes.IsEmpty() )
    1464           0 :         return;
    1465             : 
    1466             :     sax_fastparser::FSHelperPtr rComments = rStrm.CreateOutputStream(
    1467             :             XclXmlUtils::GetStreamName( "xl/", "comments", mnTab + 1 ),
    1468             :             XclXmlUtils::GetStreamName( "../", "comments", mnTab + 1 ),
    1469           0 :             rStrm.GetCurrentStream()->getOutputStream(),
    1470             :             "application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml",
    1471           0 :             "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments" );
    1472           0 :     rStrm.PushStream( rComments );
    1473             : 
    1474           0 :     if( rStrm.getVersion() == oox::core::ISOIEC_29500_2008 )
    1475             :         rComments->startElement( XML_comments,
    1476             :             XML_xmlns, "http://schemas.openxmlformats.org/spreadsheetml/2006/main",
    1477             :             FSNS( XML_xmlns, XML_mc ), "http://schemas.openxmlformats.org/markup-compatibility/2006",
    1478             :             FSNS( XML_xmlns, XML_xdr ), "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing",
    1479             :             FSNS( XML_xmlns, XML_v2 ), "http://schemas.openxmlformats.org/spreadsheetml/2006/main/v2",
    1480             :             FSNS( XML_mc, XML_Ignorable ), "v2",
    1481           0 :             FSEND );
    1482             :     else
    1483             :         rComments->startElement( XML_comments,
    1484             :             XML_xmlns, "http://schemas.openxmlformats.org/spreadsheetml/2006/main",
    1485             :             FSNS( XML_xmlns, XML_xdr ), "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing",
    1486           0 :             FSEND );
    1487             : 
    1488           0 :     rComments->startElement( XML_authors, FSEND );
    1489             : 
    1490             :     typedef std::set< OUString, OUStringLess > Authors;
    1491           0 :     Authors aAuthors;
    1492             : 
    1493           0 :     size_t nNotes = mrNotes.GetSize();
    1494           0 :     for( size_t i = 0; i < nNotes; ++i )
    1495             :     {
    1496           0 :         aAuthors.insert( XclXmlUtils::ToOUString( mrNotes.GetRecord( i )->GetAuthor() ) );
    1497             :     }
    1498             : 
    1499           0 :     for( Authors::const_iterator b = aAuthors.begin(), e = aAuthors.end(); b != e; ++b )
    1500             :     {
    1501           0 :         rComments->startElement( XML_author, FSEND );
    1502           0 :         rComments->writeEscaped( *b );
    1503           0 :         rComments->endElement( XML_author );
    1504             :     }
    1505             : 
    1506           0 :     rComments->endElement( XML_authors );
    1507           0 :     rComments->startElement( XML_commentList, FSEND );
    1508             : 
    1509           0 :     for( size_t i = 0; i < nNotes; ++i )
    1510             :     {
    1511           0 :         XclExpNoteList::RecordRefType xNote = mrNotes.GetRecord( i );
    1512             :         Authors::iterator aAuthor = aAuthors.find(
    1513           0 :                 XclXmlUtils::ToOUString( xNote->GetAuthor() ) );
    1514           0 :         sal_Int32 nAuthorId = distance( aAuthors.begin(), aAuthor );
    1515           0 :         xNote->WriteXml( nAuthorId, rStrm );
    1516           0 :     }
    1517             : 
    1518           0 :     rComments->endElement( XML_commentList );
    1519           0 :     rComments->endElement( XML_comments );
    1520             : 
    1521           0 :     rStrm.PopStream();
    1522             : }
    1523             : 
    1524             : // object manager =============================================================
    1525             : 
    1526           1 : XclExpObjectManager::XclExpObjectManager( const XclExpRoot& rRoot ) :
    1527           1 :     XclExpRoot( rRoot )
    1528             : {
    1529           1 :     InitStream( true );
    1530           1 :     mxEscherEx.reset( new XclEscherEx( GetRoot(), *this, *mxDffStrm ) );
    1531           1 : }
    1532             : 
    1533           0 : XclExpObjectManager::XclExpObjectManager( const XclExpObjectManager& rParent ) :
    1534           0 :     XclExpRoot( rParent.GetRoot() )
    1535             : {
    1536           0 :     InitStream( false );
    1537           0 :     mxEscherEx.reset( new XclEscherEx( GetRoot(), *this, *mxDffStrm, rParent.mxEscherEx.get() ) );
    1538           0 : }
    1539             : 
    1540           2 : XclExpObjectManager::~XclExpObjectManager()
    1541             : {
    1542           2 : }
    1543             : 
    1544           0 : XclExpDffAnchorBase* XclExpObjectManager::CreateDffAnchor() const
    1545             : {
    1546           0 :     return new XclExpDffSheetAnchor( GetRoot() );
    1547             : }
    1548             : 
    1549           1 : boost::shared_ptr< XclExpRecordBase > XclExpObjectManager::CreateDrawingGroup()
    1550             : {
    1551           1 :     return boost::shared_ptr< XclExpRecordBase >( new XclExpMsoDrawingGroup( *mxEscherEx ) );
    1552             : }
    1553             : 
    1554           1 : void XclExpObjectManager::StartSheet()
    1555             : {
    1556           1 :     mxObjList.reset( new XclExpObjList( GetRoot(), *mxEscherEx ) );
    1557           1 : }
    1558             : 
    1559           1 : boost::shared_ptr< XclExpRecordBase > XclExpObjectManager::ProcessDrawing( SdrPage* pSdrPage )
    1560             : {
    1561           1 :     if( pSdrPage )
    1562           1 :         mxEscherEx->AddSdrPage( *pSdrPage );
    1563             :     // the first dummy object may still be open
    1564             :     OSL_ENSURE( mxEscherEx->GetGroupLevel() <= 1, "XclExpObjectManager::ProcessDrawing - still groups open?" );
    1565           2 :     while( mxEscherEx->GetGroupLevel() )
    1566           0 :         mxEscherEx->LeaveGroup();
    1567           1 :     mxObjList->EndSheet();
    1568           1 :     return mxObjList;
    1569             : }
    1570             : 
    1571           0 : boost::shared_ptr< XclExpRecordBase > XclExpObjectManager::ProcessDrawing( const Reference< XShapes >& rxShapes )
    1572             : {
    1573           0 :     if( rxShapes.is() )
    1574           0 :         mxEscherEx->AddUnoShapes( rxShapes );
    1575             :     // the first dummy object may still be open
    1576             :     OSL_ENSURE( mxEscherEx->GetGroupLevel() <= 1, "XclExpObjectManager::ProcessDrawing - still groups open?" );
    1577           0 :     while( mxEscherEx->GetGroupLevel() )
    1578           0 :         mxEscherEx->LeaveGroup();
    1579           0 :     mxObjList->EndSheet();
    1580           0 :     return mxObjList;
    1581             : }
    1582             : 
    1583           1 : void XclExpObjectManager::EndDocument()
    1584             : {
    1585           1 :     mxEscherEx->EndDocument();
    1586           1 : }
    1587             : 
    1588           0 : XclExpMsoDrawing* XclExpObjectManager::GetMsodrawingPerSheet()
    1589             : {
    1590           0 :     return mxObjList->GetMsodrawingPerSheet();
    1591             : }
    1592             : 
    1593           0 : bool XclExpObjectManager::HasObj() const
    1594             : {
    1595           0 :     return !mxObjList->empty();
    1596             : }
    1597             : 
    1598           0 : sal_uInt16 XclExpObjectManager::AddObj( XclObj* pObjRec )
    1599             : {
    1600           0 :     return mxObjList->Add( pObjRec );
    1601             : }
    1602             : 
    1603           0 : XclObj* XclExpObjectManager::RemoveLastObj()
    1604             : {
    1605           0 :     XclObj* pLastObj = mxObjList->back();
    1606           0 :     mxObjList->pop_back();
    1607           0 :     return pLastObj;
    1608             : }
    1609             : 
    1610           1 : void XclExpObjectManager::InitStream( bool bTempFile )
    1611             : {
    1612           1 :     if( bTempFile )
    1613             :     {
    1614           1 :         mxTempFile.reset( new ::utl::TempFile );
    1615           1 :         if( mxTempFile->IsValid() )
    1616             :         {
    1617           1 :             mxTempFile->EnableKillingFile();
    1618           1 :             mxDffStrm.reset( ::utl::UcbStreamHelper::CreateStream( mxTempFile->GetURL(), STREAM_STD_READWRITE ) );
    1619             :         }
    1620             :     }
    1621             : 
    1622           1 :     if( !mxDffStrm.get() )
    1623           0 :         mxDffStrm.reset( new SvMemoryStream );
    1624             : 
    1625           1 :     mxDffStrm->SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN );
    1626           1 : }
    1627             : 
    1628             : // ----------------------------------------------------------------------------
    1629             : 
    1630           0 : XclExpEmbeddedObjectManager::XclExpEmbeddedObjectManager(
    1631             :         const XclExpObjectManager& rParent, const Size& rPageSize, sal_Int32 nScaleX, sal_Int32 nScaleY ) :
    1632             :     XclExpObjectManager( rParent ),
    1633             :     maPageSize( rPageSize ),
    1634             :     mnScaleX( nScaleX ),
    1635           0 :     mnScaleY( nScaleY )
    1636             : {
    1637           0 : }
    1638             : 
    1639           0 : XclExpDffAnchorBase* XclExpEmbeddedObjectManager::CreateDffAnchor() const
    1640             : {
    1641           0 :     return new XclExpDffEmbeddedAnchor( GetRoot(), maPageSize, mnScaleX, mnScaleY );
    1642           9 : }
    1643             : 
    1644             : // ============================================================================
    1645             : 
    1646             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10