LCOV - code coverage report
Current view: top level - sc/source/filter/excel - xlescher.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 44 147 29.9 %
Date: 2012-08-25 Functions: 13 24 54.2 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 14 82 17.1 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include "xlescher.hxx"
      31                 :            : 
      32                 :            : #include <com/sun/star/drawing/XControlShape.hpp>
      33                 :            : #include <com/sun/star/script/ScriptEventDescriptor.hpp>
      34                 :            : #include <svx/unoapi.hxx>
      35                 :            : #include "document.hxx"
      36                 :            : #include "xestream.hxx"
      37                 :            : #include "xistream.hxx"
      38                 :            : #include "xlroot.hxx"
      39                 :            : #include "xltools.hxx"
      40                 :            : 
      41                 :            : using ::rtl::OUString;
      42                 :            : using ::com::sun::star::uno::Reference;
      43                 :            : using ::com::sun::star::uno::UNO_QUERY;
      44                 :            : using ::com::sun::star::drawing::XShape;
      45                 :            : using ::com::sun::star::drawing::XControlShape;
      46                 :            : using ::com::sun::star::awt::XControlModel;
      47                 :            : using ::com::sun::star::script::ScriptEventDescriptor;
      48                 :            : 
      49                 :            : namespace {
      50                 :            : 
      51                 :            : /** Returns the scaling factor to calculate coordinates from twips. */
      52                 :        101 : double lclGetTwipsScale( MapUnit eMapUnit )
      53                 :            : {
      54                 :            :     /*  We cannot use OutputDevice::LogicToLogic() or the XclTools
      55                 :            :         conversion functions to calculate drawing layer coordinates due to
      56                 :            :         Calc's strange definition of a point (1 inch == 72.27 points, instead
      57                 :            :         of 72 points).
      58                 :            :         NOTE: Calc's definition changed from TeX points (72.27) to PS points
      59                 :            :         (72), so the MAP_TWIP case now actually also delivers a scale of 1.0
      60                 :            :     */
      61                 :        101 :     double fScale = 1.0;
      62      [ -  +  - ]:        101 :     switch( eMapUnit )
      63                 :            :     {
      64                 :          0 :         case MAP_TWIP:      fScale = PS_POINTS_PER_INCH / POINTS_PER_INCH;  break;  // Calc twips <-> real twips
      65                 :        101 :         case MAP_100TH_MM:  fScale = HMM_PER_TWIPS;                         break;  // Calc twips <-> 1/100mm
      66                 :            :         default:            OSL_FAIL( "lclGetTwipsScale - map unit not implemented" );
      67                 :            :     }
      68                 :        101 :     return fScale;
      69                 :            : }
      70                 :            : 
      71                 :            : /** Calculates a drawing layer X position (in twips) from an object column position. */
      72                 :        202 : long lclGetXFromCol( ScDocument& rDoc, SCTAB nScTab, sal_uInt16 nXclCol, sal_uInt16 nOffset, double fScale )
      73                 :            : {
      74                 :        202 :     SCCOL nScCol = static_cast< SCCOL >( nXclCol );
      75                 :        202 :     return static_cast< long >( fScale * (rDoc.GetColOffset( nScCol, nScTab ) +
      76 [ +  - ][ +  - ]:        202 :         ::std::min( nOffset / 1024.0, 1.0 ) * rDoc.GetColWidth( nScCol, nScTab )) + 0.5 );
      77                 :            : }
      78                 :            : 
      79                 :            : /** Calculates a drawing layer Y position (in twips) from an object row position. */
      80                 :        202 : long lclGetYFromRow( ScDocument& rDoc, SCTAB nScTab, sal_uInt16 nXclRow, sal_uInt16 nOffset, double fScale )
      81                 :            : {
      82                 :        202 :     SCROW nScRow = static_cast< SCROW >( nXclRow );
      83                 :        202 :     return static_cast< long >( fScale * (rDoc.GetRowOffset( nScRow, nScTab ) +
      84 [ +  - ][ +  - ]:        202 :         ::std::min( nOffset / 256.0, 1.0 ) * rDoc.GetRowHeight( nScRow, nScTab )) + 0.5 );
      85                 :            : }
      86                 :            : 
      87                 :            : /** Calculates an object column position from a drawing layer X position (in twips). */
      88                 :          0 : void lclGetColFromX(
      89                 :            :         ScDocument& rDoc, SCTAB nScTab, sal_uInt16& rnXclCol,
      90                 :            :         sal_uInt16& rnOffset, sal_uInt16 nXclStartCol, sal_uInt16 nXclMaxCol,
      91                 :            :         long& rnStartW, long nX, double fScale )
      92                 :            : {
      93                 :            :     // rnStartW in conjunction with nXclStartCol is used as buffer for previously calculated width
      94                 :          0 :     long nTwipsX = static_cast< long >( nX / fScale + 0.5 );
      95                 :          0 :     long nColW = 0;
      96         [ #  # ]:          0 :     for( rnXclCol = nXclStartCol; rnXclCol <= nXclMaxCol; ++rnXclCol )
      97                 :            :     {
      98                 :          0 :         nColW = rDoc.GetColWidth( static_cast< SCCOL >( rnXclCol ), nScTab );
      99         [ #  # ]:          0 :         if( rnStartW + nColW > nTwipsX )
     100                 :          0 :             break;
     101                 :          0 :         rnStartW += nColW;
     102                 :            :     }
     103         [ #  # ]:          0 :     rnOffset = nColW ? static_cast< sal_uInt16 >( (nTwipsX - rnStartW) * 1024.0 / nColW + 0.5 ) : 0;
     104                 :          0 : }
     105                 :            : 
     106                 :            : /** Calculates an object row position from a drawing layer Y position (in twips). */
     107                 :          0 : void lclGetRowFromY(
     108                 :            :         ScDocument& rDoc, SCTAB nScTab, sal_uInt32& rnXclRow,
     109                 :            :         sal_uInt32& rnOffset, sal_uInt32 nXclStartRow, sal_uInt32 nXclMaxRow,
     110                 :            :         long& rnStartH, long nY, double fScale )
     111                 :            : {
     112                 :            :     // rnStartH in conjunction with nXclStartRow is used as buffer for previously calculated height
     113                 :          0 :     long nTwipsY = static_cast< long >( nY / fScale + 0.5 );
     114                 :          0 :     long nRowH = 0;
     115                 :          0 :     bool bFound = false;
     116         [ #  # ]:          0 :     for( SCROW nRow = static_cast< SCROW >( nXclStartRow ); static_cast<unsigned>(nRow) <= nXclMaxRow; ++nRow )
     117                 :            :     {
     118                 :          0 :         nRowH = rDoc.GetRowHeight( nRow, nScTab );
     119         [ #  # ]:          0 :         if( rnStartH + nRowH > nTwipsY )
     120                 :            :         {
     121                 :          0 :             rnXclRow = static_cast< sal_uInt32 >( nRow );
     122                 :          0 :             bFound = true;
     123                 :          0 :             break;
     124                 :            :         }
     125                 :          0 :         rnStartH += nRowH;
     126                 :            :     }
     127         [ #  # ]:          0 :     if( !bFound )
     128                 :          0 :         rnXclRow = nXclMaxRow;
     129         [ #  # ]:          0 :     rnOffset = static_cast< sal_uInt32 >( nRowH ? ((nTwipsY - rnStartH) * 256.0 / nRowH + 0.5) : 0 );
     130                 :          0 : }
     131                 :            : 
     132                 :            : /** Mirrors a rectangle (from LTR to RTL layout or vice versa). */
     133                 :          0 : void lclMirrorRectangle( Rectangle& rRect )
     134                 :            : {
     135                 :          0 :     long nLeft = rRect.Left();
     136                 :          0 :     rRect.Left() = -rRect.Right();
     137                 :          0 :     rRect.Right() = -nLeft;
     138                 :          0 : }
     139                 :            : 
     140                 :          0 : sal_uInt16 lclGetEmbeddedScale( long nPageSize, sal_Int32 nPageScale, long nPos, double fPosScale )
     141                 :            : {
     142                 :          0 :     return static_cast< sal_uInt16 >( nPos * fPosScale / nPageSize * nPageScale + 0.5 );
     143                 :            : }
     144                 :            : 
     145                 :            : } // namespace
     146                 :            : 
     147                 :            : // ----------------------------------------------------------------------------
     148                 :            : 
     149                 :        202 : XclObjAnchor::XclObjAnchor() :
     150                 :            :     mnLX( 0 ),
     151                 :            :     mnTY( 0 ),
     152                 :            :     mnRX( 0 ),
     153                 :        202 :     mnBY( 0 )
     154                 :            : {
     155                 :        202 : }
     156                 :            : 
     157                 :        101 : Rectangle XclObjAnchor::GetRect( const XclRoot& rRoot, SCTAB nScTab, MapUnit eMapUnit ) const
     158                 :            : {
     159                 :        101 :     ScDocument& rDoc = rRoot.GetDoc();
     160                 :        101 :     double fScale = lclGetTwipsScale( eMapUnit );
     161                 :            :     Rectangle aRect(
     162                 :            :         lclGetXFromCol( rDoc, nScTab, maFirst.mnCol, mnLX, fScale ),
     163                 :            :         lclGetYFromRow( rDoc, nScTab, maFirst.mnRow, mnTY, fScale ),
     164                 :            :         lclGetXFromCol( rDoc, nScTab, maLast.mnCol,  mnRX + 1, fScale ),
     165                 :        101 :         lclGetYFromRow( rDoc, nScTab, maLast.mnRow,  mnBY, fScale ) );
     166                 :            : 
     167                 :            :     // adjust coordinates in mirrored sheets
     168         [ -  + ]:        101 :     if( rDoc.IsLayoutRTL( nScTab ) )
     169                 :          0 :         lclMirrorRectangle( aRect );
     170                 :        101 :     return aRect;
     171                 :            : }
     172                 :            : 
     173                 :          0 : void XclObjAnchor::SetRect( const XclRoot& rRoot, SCTAB nScTab, const Rectangle& rRect, MapUnit eMapUnit )
     174                 :            : {
     175                 :          0 :     ScDocument& rDoc = rRoot.GetDoc();
     176                 :          0 :     sal_uInt16 nXclMaxCol = rRoot.GetXclMaxPos().Col();
     177                 :          0 :     sal_uInt16 nXclMaxRow = static_cast<sal_uInt16>( rRoot.GetXclMaxPos().Row());
     178                 :            : 
     179                 :            :     // adjust coordinates in mirrored sheets
     180                 :          0 :     Rectangle aRect( rRect );
     181 [ #  # ][ #  # ]:          0 :     if( rDoc.IsLayoutRTL( nScTab ) )
     182                 :          0 :         lclMirrorRectangle( aRect );
     183                 :            : 
     184                 :          0 :     double fScale = lclGetTwipsScale( eMapUnit );
     185                 :          0 :     long nDummy = 0;
     186         [ #  # ]:          0 :     lclGetColFromX( rDoc, nScTab, maFirst.mnCol, mnLX, 0,             nXclMaxCol, nDummy, aRect.Left(),   fScale );
     187         [ #  # ]:          0 :     lclGetColFromX( rDoc, nScTab, maLast.mnCol,  mnRX, maFirst.mnCol, nXclMaxCol, nDummy, aRect.Right(),  fScale );
     188                 :          0 :     nDummy = 0;
     189         [ #  # ]:          0 :     lclGetRowFromY( rDoc, nScTab, maFirst.mnRow, mnTY, 0,             nXclMaxRow, nDummy, aRect.Top(),    fScale );
     190         [ #  # ]:          0 :     lclGetRowFromY( rDoc, nScTab, maLast.mnRow,  mnBY, maFirst.mnRow, nXclMaxRow, nDummy, aRect.Bottom(), fScale );
     191                 :          0 : }
     192                 :            : 
     193                 :          0 : void XclObjAnchor::SetRect( const Size& rPageSize, sal_Int32 nScaleX, sal_Int32 nScaleY,
     194                 :            :         const Rectangle& rRect, MapUnit eMapUnit, bool bDffAnchor )
     195                 :            : {
     196                 :          0 :     double fScale = 1.0;
     197      [ #  #  # ]:          0 :     switch( eMapUnit )
     198                 :            :     {
     199                 :          0 :         case MAP_TWIP:      fScale = HMM_PER_TWIPS; break;  // Calc twips -> 1/100mm
     200                 :          0 :         case MAP_100TH_MM:  fScale = 1.0;           break;  // Calc 1/100mm -> 1/100mm
     201                 :            :         default:            OSL_FAIL( "XclObjAnchor::SetRect - map unit not implemented" );
     202                 :            :     }
     203                 :            : 
     204                 :            :     /*  In objects with DFF client anchor, the position of the shape is stored
     205                 :            :         in the cell address components of the client anchor. In old BIFF3-BIFF5
     206                 :            :         objects, the position is stored in the offset components of the anchor. */
     207         [ #  # ]:          0 :     (bDffAnchor ? maFirst.mnCol : mnLX) = lclGetEmbeddedScale( rPageSize.Width(),  nScaleX, rRect.Left(),   fScale );
     208         [ #  # ]:          0 :     (bDffAnchor ? maFirst.mnRow : mnTY) = lclGetEmbeddedScale( rPageSize.Height(), nScaleY, rRect.Top(),    fScale );
     209         [ #  # ]:          0 :     (bDffAnchor ? maLast.mnCol  : mnRX) = lclGetEmbeddedScale( rPageSize.Width(),  nScaleX, rRect.Right(),  fScale );
     210         [ #  # ]:          0 :     (bDffAnchor ? maLast.mnRow  : mnBY) = lclGetEmbeddedScale( rPageSize.Height(), nScaleY, rRect.Bottom(), fScale );
     211                 :            : 
     212                 :            :     // for safety, clear the other members
     213         [ #  # ]:          0 :     if( bDffAnchor )
     214                 :          0 :         mnLX = mnTY = mnRX = mnBY = 0;
     215                 :            :     else
     216                 :          0 :         Set( 0, 0, 0, 0 );
     217                 :          0 : }
     218                 :            : 
     219                 :            : // ----------------------------------------------------------------------------
     220                 :            : 
     221                 :        101 : XclObjLineData::XclObjLineData() :
     222                 :            :     mnColorIdx( EXC_OBJ_LINE_AUTOCOLOR ),
     223                 :            :     mnStyle( EXC_OBJ_LINE_SOLID ),
     224                 :            :     mnWidth( EXC_OBJ_LINE_HAIR ),
     225                 :        101 :     mnAuto( EXC_OBJ_LINE_AUTO )
     226                 :            : {
     227                 :        101 : }
     228                 :            : 
     229                 :          0 : XclImpStream& operator>>( XclImpStream& rStrm, XclObjLineData& rLineData )
     230                 :            : {
     231                 :            :     return rStrm
     232                 :          0 :         >> rLineData.mnColorIdx
     233                 :          0 :         >> rLineData.mnStyle
     234                 :          0 :         >> rLineData.mnWidth
     235                 :          0 :         >> rLineData.mnAuto;
     236                 :            : }
     237                 :            : 
     238                 :            : // ----------------------------------------------------------------------------
     239                 :            : 
     240                 :        101 : XclObjFillData::XclObjFillData() :
     241                 :            :     mnBackColorIdx( EXC_OBJ_LINE_AUTOCOLOR ),
     242                 :            :     mnPattColorIdx( EXC_OBJ_FILL_AUTOCOLOR ),
     243                 :            :     mnPattern( EXC_PATT_SOLID ),
     244                 :        101 :     mnAuto( EXC_OBJ_FILL_AUTO )
     245                 :            : {
     246                 :        101 : }
     247                 :            : 
     248                 :          0 : XclImpStream& operator>>( XclImpStream& rStrm, XclObjFillData& rFillData )
     249                 :            : {
     250                 :            :     return rStrm
     251                 :          0 :         >> rFillData.mnBackColorIdx
     252                 :          0 :         >> rFillData.mnPattColorIdx
     253                 :          0 :         >> rFillData.mnPattern
     254                 :          0 :         >> rFillData.mnAuto;
     255                 :            : }
     256                 :            : 
     257                 :            : // ----------------------------------------------------------------------------
     258                 :            : 
     259                 :        129 : XclObjTextData::XclObjTextData() :
     260                 :            :     mnTextLen( 0 ),
     261                 :            :     mnFormatSize( 0 ),
     262                 :            :     mnLinkSize( 0 ),
     263                 :            :     mnDefFontIdx( EXC_FONT_APP ),
     264                 :            :     mnFlags( 0 ),
     265                 :            :     mnOrient( EXC_OBJ_ORIENT_NONE ),
     266                 :            :     mnButtonFlags( 0 ),
     267                 :            :     mnShortcut( 0 ),
     268                 :        129 :     mnShortcutEA( 0 )
     269                 :            : {
     270                 :        129 : }
     271                 :            : 
     272                 :          0 : void XclObjTextData::ReadObj3( XclImpStream& rStrm )
     273                 :            : {
     274                 :          0 :     rStrm >> mnTextLen;
     275                 :          0 :     rStrm.Ignore( 2 );
     276                 :          0 :     rStrm >> mnFormatSize >> mnDefFontIdx;
     277                 :          0 :     rStrm.Ignore( 2 );
     278                 :          0 :     rStrm >> mnFlags >> mnOrient;
     279                 :          0 :     rStrm.Ignore( 8 );
     280                 :          0 : }
     281                 :            : 
     282                 :          0 : void XclObjTextData::ReadObj5( XclImpStream& rStrm )
     283                 :            : {
     284                 :          0 :     rStrm >> mnTextLen;
     285                 :          0 :     rStrm.Ignore( 2 );
     286                 :          0 :     rStrm >> mnFormatSize >> mnDefFontIdx;
     287                 :          0 :     rStrm.Ignore( 2 );
     288                 :          0 :     rStrm >> mnFlags >> mnOrient;
     289                 :          0 :     rStrm.Ignore( 2 );
     290                 :          0 :     rStrm >> mnLinkSize;
     291                 :          0 :     rStrm.Ignore( 2 );
     292                 :          0 :     rStrm >> mnButtonFlags >> mnShortcut >> mnShortcutEA;
     293                 :          0 : }
     294                 :            : 
     295                 :         48 : void XclObjTextData::ReadTxo8( XclImpStream& rStrm )
     296                 :            : {
     297                 :         48 :     rStrm >> mnFlags >> mnOrient >> mnButtonFlags >> mnShortcut >> mnShortcutEA >> mnTextLen >> mnFormatSize;
     298                 :         48 : }
     299                 :            : 
     300                 :            : // ============================================================================
     301                 :            : 
     302                 :         73 : Reference< XControlModel > XclControlHelper::GetControlModel( Reference< XShape > xShape )
     303                 :            : {
     304                 :         73 :     Reference< XControlModel > xCtrlModel;
     305         [ +  - ]:         73 :     Reference< XControlShape > xCtrlShape( xShape, UNO_QUERY );
     306         [ +  - ]:         73 :     if( xCtrlShape.is() )
     307 [ +  - ][ +  - ]:         73 :         xCtrlModel = xCtrlShape->getControl();
                 [ +  - ]
     308                 :         73 :     return xCtrlModel;
     309                 :            : }
     310                 :            : 
     311                 :            : namespace {
     312                 :            : 
     313                 :            : static const struct
     314                 :            : {
     315                 :            :     const sal_Char*     mpcListenerType;
     316                 :            :     const sal_Char*     mpcEventMethod;
     317                 :            : }
     318                 :            : spTbxListenerData[] =
     319                 :            : {
     320                 :            :     // Attention: MUST be in order of the XclTbxEventType enum!
     321                 :            :     /*EXC_TBX_EVENT_ACTION*/    { "XActionListener",     "actionPerformed"        },
     322                 :            :     /*EXC_TBX_EVENT_MOUSE*/     { "XMouseListener",      "mouseReleased"          },
     323                 :            :     /*EXC_TBX_EVENT_TEXT*/      { "XTextListener",       "textChanged"            },
     324                 :            :     /*EXC_TBX_EVENT_VALUE*/     { "XAdjustmentListener", "adjustmentValueChanged" },
     325                 :            :     /*EXC_TBX_EVENT_CHANGE*/    { "XChangeListener",     "changed"                }
     326                 :            : };
     327                 :            : 
     328                 :            : } // namespace
     329                 :            : 
     330                 :         15 : bool XclControlHelper::FillMacroDescriptor( ScriptEventDescriptor& rDescriptor,
     331                 :            :         XclTbxEventType eEventType, const String& rXclMacroName, SfxObjectShell* pDocShell )
     332                 :            : {
     333         [ -  + ]:         15 :     if( rXclMacroName.Len() > 0 )
     334                 :            :     {
     335                 :          0 :         rDescriptor.ListenerType = OUString::createFromAscii( spTbxListenerData[ eEventType ].mpcListenerType );
     336                 :          0 :         rDescriptor.EventMethod = OUString::createFromAscii( spTbxListenerData[ eEventType ].mpcEventMethod );
     337                 :          0 :         rDescriptor.ScriptType = CREATE_OUSTRING( "Script" );
     338         [ #  # ]:          0 :         rDescriptor.ScriptCode = XclTools::GetSbMacroUrl( rXclMacroName, pDocShell );
     339                 :          0 :         return true;
     340                 :            :     }
     341                 :         15 :     return false;
     342                 :            : }
     343                 :            : 
     344                 :          0 : String XclControlHelper::ExtractFromMacroDescriptor(
     345                 :            :         const ScriptEventDescriptor& rDescriptor, XclTbxEventType eEventType, SfxObjectShell* /*pShell*/ )
     346                 :            : {
     347   [ #  #  #  #  :          0 :     if( (!rDescriptor.ScriptCode.isEmpty()) &&
             #  #  #  # ]
                 [ #  # ]
     348                 :          0 :             rDescriptor.ScriptType.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("Script")) &&
     349                 :          0 :             rDescriptor.ListenerType.equalsAscii( spTbxListenerData[ eEventType ].mpcListenerType ) &&
     350                 :          0 :             rDescriptor.EventMethod.equalsAscii( spTbxListenerData[ eEventType ].mpcEventMethod ) )
     351         [ #  # ]:          0 :         return XclTools::GetXclMacroName( rDescriptor.ScriptCode );
     352                 :          0 :     return String::EmptyString();
     353 [ +  - ][ +  - ]:         24 : }
     354                 :            : 
     355                 :            : // ============================================================================
     356                 :            : 
     357                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10