LCOV - code coverage report
Current view: top level - sc/source/filter/excel - xlescher.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 147 0.0 %
Date: 2014-04-14 Functions: 0 24 0.0 %
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 "xlescher.hxx"
      22             : 
      23             : #include <com/sun/star/drawing/XControlShape.hpp>
      24             : #include <com/sun/star/script/ScriptEventDescriptor.hpp>
      25             : #include <svx/unoapi.hxx>
      26             : #include "document.hxx"
      27             : #include "xestream.hxx"
      28             : #include "xistream.hxx"
      29             : #include "xlroot.hxx"
      30             : #include "xltools.hxx"
      31             : 
      32             : using ::com::sun::star::uno::Reference;
      33             : using ::com::sun::star::uno::UNO_QUERY;
      34             : using ::com::sun::star::drawing::XShape;
      35             : using ::com::sun::star::drawing::XControlShape;
      36             : using ::com::sun::star::awt::XControlModel;
      37             : using ::com::sun::star::script::ScriptEventDescriptor;
      38             : 
      39             : namespace {
      40             : 
      41             : /** Returns the scaling factor to calculate coordinates from twips. */
      42           0 : double lclGetTwipsScale( MapUnit eMapUnit )
      43             : {
      44             :     /*  We cannot use OutputDevice::LogicToLogic() or the XclTools
      45             :         conversion functions to calculate drawing layer coordinates due to
      46             :         Calc's strange definition of a point (1 inch == 72.27 points, instead
      47             :         of 72 points).
      48             :         NOTE: Calc's definition changed from TeX points (72.27) to PS points
      49             :         (72), so the MAP_TWIP case now actually also delivers a scale of 1.0
      50             :     */
      51           0 :     double fScale = 1.0;
      52           0 :     switch( eMapUnit )
      53             :     {
      54           0 :         case MAP_TWIP:      fScale = PS_POINTS_PER_INCH / POINTS_PER_INCH;  break;  // Calc twips <-> real twips
      55           0 :         case MAP_100TH_MM:  fScale = HMM_PER_TWIPS;                         break;  // Calc twips <-> 1/100mm
      56             :         default:            OSL_FAIL( "lclGetTwipsScale - map unit not implemented" );
      57             :     }
      58           0 :     return fScale;
      59             : }
      60             : 
      61             : /** Calculates a drawing layer X position (in twips) from an object column position. */
      62           0 : long lclGetXFromCol( ScDocument& rDoc, SCTAB nScTab, sal_uInt16 nXclCol, sal_uInt16 nOffset, double fScale )
      63             : {
      64           0 :     SCCOL nScCol = static_cast< SCCOL >( nXclCol );
      65           0 :     return static_cast< long >( fScale * (rDoc.GetColOffset( nScCol, nScTab ) +
      66           0 :         ::std::min( nOffset / 1024.0, 1.0 ) * rDoc.GetColWidth( nScCol, nScTab )) + 0.5 );
      67             : }
      68             : 
      69             : /** Calculates a drawing layer Y position (in twips) from an object row position. */
      70           0 : long lclGetYFromRow( ScDocument& rDoc, SCTAB nScTab, sal_uInt16 nXclRow, sal_uInt16 nOffset, double fScale )
      71             : {
      72           0 :     SCROW nScRow = static_cast< SCROW >( nXclRow );
      73           0 :     return static_cast< long >( fScale * (rDoc.GetRowOffset( nScRow, nScTab ) +
      74           0 :         ::std::min( nOffset / 256.0, 1.0 ) * rDoc.GetRowHeight( nScRow, nScTab )) + 0.5 );
      75             : }
      76             : 
      77             : /** Calculates an object column position from a drawing layer X position (in twips). */
      78           0 : void lclGetColFromX(
      79             :         ScDocument& rDoc, SCTAB nScTab, sal_uInt16& rnXclCol,
      80             :         sal_uInt16& rnOffset, sal_uInt16 nXclStartCol, sal_uInt16 nXclMaxCol,
      81             :         long& rnStartW, long nX, double fScale )
      82             : {
      83             :     // rnStartW in conjunction with nXclStartCol is used as buffer for previously calculated width
      84           0 :     long nTwipsX = static_cast< long >( nX / fScale + 0.5 );
      85           0 :     long nColW = 0;
      86           0 :     for( rnXclCol = nXclStartCol; rnXclCol <= nXclMaxCol; ++rnXclCol )
      87             :     {
      88           0 :         nColW = rDoc.GetColWidth( static_cast< SCCOL >( rnXclCol ), nScTab );
      89           0 :         if( rnStartW + nColW > nTwipsX )
      90           0 :             break;
      91           0 :         rnStartW += nColW;
      92             :     }
      93           0 :     rnOffset = nColW ? static_cast< sal_uInt16 >( (nTwipsX - rnStartW) * 1024.0 / nColW + 0.5 ) : 0;
      94           0 : }
      95             : 
      96             : /** Calculates an object row position from a drawing layer Y position (in twips). */
      97           0 : void lclGetRowFromY(
      98             :         ScDocument& rDoc, SCTAB nScTab, sal_uInt32& rnXclRow,
      99             :         sal_uInt32& rnOffset, sal_uInt32 nXclStartRow, sal_uInt32 nXclMaxRow,
     100             :         long& rnStartH, long nY, double fScale )
     101             : {
     102             :     // rnStartH in conjunction with nXclStartRow is used as buffer for previously calculated height
     103           0 :     long nTwipsY = static_cast< long >( nY / fScale + 0.5 );
     104           0 :     long nRowH = 0;
     105           0 :     bool bFound = false;
     106           0 :     for( SCROW nRow = static_cast< SCROW >( nXclStartRow ); static_cast<unsigned>(nRow) <= nXclMaxRow; ++nRow )
     107             :     {
     108           0 :         nRowH = rDoc.GetRowHeight( nRow, nScTab );
     109           0 :         if( rnStartH + nRowH > nTwipsY )
     110             :         {
     111           0 :             rnXclRow = static_cast< sal_uInt32 >( nRow );
     112           0 :             bFound = true;
     113           0 :             break;
     114             :         }
     115           0 :         rnStartH += nRowH;
     116             :     }
     117           0 :     if( !bFound )
     118           0 :         rnXclRow = nXclMaxRow;
     119           0 :     rnOffset = static_cast< sal_uInt32 >( nRowH ? ((nTwipsY - rnStartH) * 256.0 / nRowH + 0.5) : 0 );
     120           0 : }
     121             : 
     122             : /** Mirrors a rectangle (from LTR to RTL layout or vice versa). */
     123           0 : void lclMirrorRectangle( Rectangle& rRect )
     124             : {
     125           0 :     long nLeft = rRect.Left();
     126           0 :     rRect.Left() = -rRect.Right();
     127           0 :     rRect.Right() = -nLeft;
     128           0 : }
     129             : 
     130           0 : sal_uInt16 lclGetEmbeddedScale( long nPageSize, sal_Int32 nPageScale, long nPos, double fPosScale )
     131             : {
     132           0 :     return static_cast< sal_uInt16 >( nPos * fPosScale / nPageSize * nPageScale + 0.5 );
     133             : }
     134             : 
     135             : } // namespace
     136             : 
     137           0 : XclObjAnchor::XclObjAnchor() :
     138             :     mnLX( 0 ),
     139             :     mnTY( 0 ),
     140             :     mnRX( 0 ),
     141           0 :     mnBY( 0 )
     142             : {
     143           0 : }
     144             : 
     145           0 : Rectangle XclObjAnchor::GetRect( const XclRoot& rRoot, SCTAB nScTab, MapUnit eMapUnit ) const
     146             : {
     147           0 :     ScDocument& rDoc = rRoot.GetDoc();
     148           0 :     double fScale = lclGetTwipsScale( eMapUnit );
     149             :     Rectangle aRect(
     150             :         lclGetXFromCol( rDoc, nScTab, maFirst.mnCol, mnLX, fScale ),
     151             :         lclGetYFromRow( rDoc, nScTab, maFirst.mnRow, mnTY, fScale ),
     152             :         lclGetXFromCol( rDoc, nScTab, maLast.mnCol,  mnRX + 1, fScale ),
     153           0 :         lclGetYFromRow( rDoc, nScTab, maLast.mnRow,  mnBY, fScale ) );
     154             : 
     155             :     // adjust coordinates in mirrored sheets
     156           0 :     if( rDoc.IsLayoutRTL( nScTab ) )
     157           0 :         lclMirrorRectangle( aRect );
     158           0 :     return aRect;
     159             : }
     160             : 
     161           0 : void XclObjAnchor::SetRect( const XclRoot& rRoot, SCTAB nScTab, const Rectangle& rRect, MapUnit eMapUnit )
     162             : {
     163           0 :     ScDocument& rDoc = rRoot.GetDoc();
     164           0 :     sal_uInt16 nXclMaxCol = rRoot.GetXclMaxPos().Col();
     165           0 :     sal_uInt16 nXclMaxRow = static_cast<sal_uInt16>( rRoot.GetXclMaxPos().Row());
     166             : 
     167             :     // adjust coordinates in mirrored sheets
     168           0 :     Rectangle aRect( rRect );
     169           0 :     if( rDoc.IsLayoutRTL( nScTab ) )
     170           0 :         lclMirrorRectangle( aRect );
     171             : 
     172           0 :     double fScale = lclGetTwipsScale( eMapUnit );
     173           0 :     long nDummy = 0;
     174           0 :     lclGetColFromX( rDoc, nScTab, maFirst.mnCol, mnLX, 0,             nXclMaxCol, nDummy, aRect.Left(),   fScale );
     175           0 :     lclGetColFromX( rDoc, nScTab, maLast.mnCol,  mnRX, maFirst.mnCol, nXclMaxCol, nDummy, aRect.Right(),  fScale );
     176           0 :     nDummy = 0;
     177           0 :     lclGetRowFromY( rDoc, nScTab, maFirst.mnRow, mnTY, 0,             nXclMaxRow, nDummy, aRect.Top(),    fScale );
     178           0 :     lclGetRowFromY( rDoc, nScTab, maLast.mnRow,  mnBY, maFirst.mnRow, nXclMaxRow, nDummy, aRect.Bottom(), fScale );
     179           0 : }
     180             : 
     181           0 : void XclObjAnchor::SetRect( const Size& rPageSize, sal_Int32 nScaleX, sal_Int32 nScaleY,
     182             :         const Rectangle& rRect, MapUnit eMapUnit, bool bDffAnchor )
     183             : {
     184           0 :     double fScale = 1.0;
     185           0 :     switch( eMapUnit )
     186             :     {
     187           0 :         case MAP_TWIP:      fScale = HMM_PER_TWIPS; break;  // Calc twips -> 1/100mm
     188           0 :         case MAP_100TH_MM:  fScale = 1.0;           break;  // Calc 1/100mm -> 1/100mm
     189             :         default:            OSL_FAIL( "XclObjAnchor::SetRect - map unit not implemented" );
     190             :     }
     191             : 
     192             :     /*  In objects with DFF client anchor, the position of the shape is stored
     193             :         in the cell address components of the client anchor. In old BIFF3-BIFF5
     194             :         objects, the position is stored in the offset components of the anchor. */
     195           0 :     (bDffAnchor ? maFirst.mnCol : mnLX) = lclGetEmbeddedScale( rPageSize.Width(),  nScaleX, rRect.Left(),   fScale );
     196           0 :     (bDffAnchor ? maFirst.mnRow : mnTY) = lclGetEmbeddedScale( rPageSize.Height(), nScaleY, rRect.Top(),    fScale );
     197           0 :     (bDffAnchor ? maLast.mnCol  : mnRX) = lclGetEmbeddedScale( rPageSize.Width(),  nScaleX, rRect.Right(),  fScale );
     198           0 :     (bDffAnchor ? maLast.mnRow  : mnBY) = lclGetEmbeddedScale( rPageSize.Height(), nScaleY, rRect.Bottom(), fScale );
     199             : 
     200             :     // for safety, clear the other members
     201           0 :     if( bDffAnchor )
     202           0 :         mnLX = mnTY = mnRX = mnBY = 0;
     203             :     else
     204           0 :         Set( 0, 0, 0, 0 );
     205           0 : }
     206             : 
     207           0 : XclObjLineData::XclObjLineData() :
     208             :     mnColorIdx( EXC_OBJ_LINE_AUTOCOLOR ),
     209             :     mnStyle( EXC_OBJ_LINE_SOLID ),
     210             :     mnWidth( EXC_OBJ_LINE_HAIR ),
     211           0 :     mnAuto( EXC_OBJ_LINE_AUTO )
     212             : {
     213           0 : }
     214             : 
     215           0 : XclImpStream& operator>>( XclImpStream& rStrm, XclObjLineData& rLineData )
     216             : {
     217             :     return rStrm
     218           0 :         >> rLineData.mnColorIdx
     219           0 :         >> rLineData.mnStyle
     220           0 :         >> rLineData.mnWidth
     221           0 :         >> rLineData.mnAuto;
     222             : }
     223             : 
     224           0 : XclObjFillData::XclObjFillData() :
     225             :     mnBackColorIdx( EXC_OBJ_LINE_AUTOCOLOR ),
     226             :     mnPattColorIdx( EXC_OBJ_FILL_AUTOCOLOR ),
     227             :     mnPattern( EXC_PATT_SOLID ),
     228           0 :     mnAuto( EXC_OBJ_FILL_AUTO )
     229             : {
     230           0 : }
     231             : 
     232           0 : XclImpStream& operator>>( XclImpStream& rStrm, XclObjFillData& rFillData )
     233             : {
     234             :     return rStrm
     235           0 :         >> rFillData.mnBackColorIdx
     236           0 :         >> rFillData.mnPattColorIdx
     237           0 :         >> rFillData.mnPattern
     238           0 :         >> rFillData.mnAuto;
     239             : }
     240             : 
     241           0 : XclObjTextData::XclObjTextData() :
     242             :     mnTextLen( 0 ),
     243             :     mnFormatSize( 0 ),
     244             :     mnLinkSize( 0 ),
     245             :     mnDefFontIdx( EXC_FONT_APP ),
     246             :     mnFlags( 0 ),
     247             :     mnOrient( EXC_OBJ_ORIENT_NONE ),
     248             :     mnButtonFlags( 0 ),
     249             :     mnShortcut( 0 ),
     250           0 :     mnShortcutEA( 0 )
     251             : {
     252           0 : }
     253             : 
     254           0 : void XclObjTextData::ReadObj3( XclImpStream& rStrm )
     255             : {
     256           0 :     rStrm >> mnTextLen;
     257           0 :     rStrm.Ignore( 2 );
     258           0 :     rStrm >> mnFormatSize >> mnDefFontIdx;
     259           0 :     rStrm.Ignore( 2 );
     260           0 :     rStrm >> mnFlags >> mnOrient;
     261           0 :     rStrm.Ignore( 8 );
     262           0 : }
     263             : 
     264           0 : void XclObjTextData::ReadObj5( XclImpStream& rStrm )
     265             : {
     266           0 :     rStrm >> mnTextLen;
     267           0 :     rStrm.Ignore( 2 );
     268           0 :     rStrm >> mnFormatSize >> mnDefFontIdx;
     269           0 :     rStrm.Ignore( 2 );
     270           0 :     rStrm >> mnFlags >> mnOrient;
     271           0 :     rStrm.Ignore( 2 );
     272           0 :     rStrm >> mnLinkSize;
     273           0 :     rStrm.Ignore( 2 );
     274           0 :     rStrm >> mnButtonFlags >> mnShortcut >> mnShortcutEA;
     275           0 : }
     276             : 
     277           0 : void XclObjTextData::ReadTxo8( XclImpStream& rStrm )
     278             : {
     279           0 :     rStrm >> mnFlags >> mnOrient >> mnButtonFlags >> mnShortcut >> mnShortcutEA >> mnTextLen >> mnFormatSize;
     280           0 : }
     281             : 
     282           0 : Reference< XControlModel > XclControlHelper::GetControlModel( Reference< XShape > xShape )
     283             : {
     284           0 :     Reference< XControlModel > xCtrlModel;
     285           0 :     Reference< XControlShape > xCtrlShape( xShape, UNO_QUERY );
     286           0 :     if( xCtrlShape.is() )
     287           0 :         xCtrlModel = xCtrlShape->getControl();
     288           0 :     return xCtrlModel;
     289             : }
     290             : 
     291             : namespace {
     292             : 
     293             : static const struct
     294             : {
     295             :     const sal_Char*     mpcListenerType;
     296             :     const sal_Char*     mpcEventMethod;
     297             : }
     298             : spTbxListenerData[] =
     299             : {
     300             :     // Attention: MUST be in order of the XclTbxEventType enum!
     301             :     /*EXC_TBX_EVENT_ACTION*/    { "XActionListener",     "actionPerformed"        },
     302             :     /*EXC_TBX_EVENT_MOUSE*/     { "XMouseListener",      "mouseReleased"          },
     303             :     /*EXC_TBX_EVENT_TEXT*/      { "XTextListener",       "textChanged"            },
     304             :     /*EXC_TBX_EVENT_VALUE*/     { "XAdjustmentListener", "adjustmentValueChanged" },
     305             :     /*EXC_TBX_EVENT_CHANGE*/    { "XChangeListener",     "changed"                }
     306             : };
     307             : 
     308             : } // namespace
     309             : 
     310           0 : bool XclControlHelper::FillMacroDescriptor( ScriptEventDescriptor& rDescriptor,
     311             :         XclTbxEventType eEventType, const OUString& rXclMacroName, SfxObjectShell* pDocShell )
     312             : {
     313           0 :     if( !rXclMacroName.isEmpty() )
     314             :     {
     315           0 :         rDescriptor.ListenerType = OUString::createFromAscii( spTbxListenerData[ eEventType ].mpcListenerType );
     316           0 :         rDescriptor.EventMethod = OUString::createFromAscii( spTbxListenerData[ eEventType ].mpcEventMethod );
     317           0 :         rDescriptor.ScriptType = "Script";
     318           0 :         rDescriptor.ScriptCode = XclTools::GetSbMacroUrl( rXclMacroName, pDocShell );
     319           0 :         return true;
     320             :     }
     321           0 :     return false;
     322             : }
     323             : 
     324           0 : OUString XclControlHelper::ExtractFromMacroDescriptor(
     325             :         const ScriptEventDescriptor& rDescriptor, XclTbxEventType eEventType, SfxObjectShell* /*pShell*/ )
     326             : {
     327           0 :     if( (!rDescriptor.ScriptCode.isEmpty()) &&
     328           0 :             rDescriptor.ScriptType.equalsIgnoreAsciiCase("Script") &&
     329           0 :             rDescriptor.ListenerType.equalsAscii( spTbxListenerData[ eEventType ].mpcListenerType ) &&
     330           0 :             rDescriptor.EventMethod.equalsAscii( spTbxListenerData[ eEventType ].mpcEventMethod ) )
     331           0 :         return XclTools::GetXclMacroName( rDescriptor.ScriptCode );
     332           0 :     return OUString();
     333           0 : }
     334             : 
     335             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10