LCOV - code coverage report
Current view: top level - libreoffice/vbahelper/source/vbahelper - vbahelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 564 0.0 %
Date: 2012-12-27 Functions: 0 91 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             : #include <cppuhelper/bootstrap.hxx>
      20             : #include <com/sun/star/util/URLTransformer.hpp>
      21             : #include <com/sun/star/util/XURLTransformer.hpp>
      22             : #include <com/sun/star/frame/XDispatchProvider.hpp>
      23             : #include <com/sun/star/frame/XModel.hpp>
      24             : #include <com/sun/star/frame/XFrame.hpp>
      25             : #include <com/sun/star/frame/XDesktop.hpp>
      26             : #include <com/sun/star/frame/XController.hpp>
      27             : #include <com/sun/star/frame/XModel2.hpp>
      28             : #include <com/sun/star/frame/XNotifyingDispatch.hpp>
      29             : #include <com/sun/star/script/XDefaultProperty.hpp>
      30             : #include <com/sun/star/script/Converter.hpp>
      31             : #include <com/sun/star/uno/XComponentContext.hpp>
      32             : #include <com/sun/star/lang/XUnoTunnel.hpp>
      33             : #include <com/sun/star/beans/XPropertySet.hpp>
      34             : #include <com/sun/star/beans/Introspection.hpp>
      35             : #include <com/sun/star/util/MeasureUnit.hpp>
      36             : #include <com/sun/star/awt/XWindow.hpp>
      37             : #include <com/sun/star/awt/XDialog.hpp>
      38             : #include <com/sun/star/awt/PosSize.hpp>
      39             : 
      40             : #include <ooo/vba/msforms/XShape.hpp>
      41             : 
      42             : #include <comphelper/processfactory.hxx>
      43             : 
      44             : #include <sfx2/objsh.hxx>
      45             : #include <sfx2/viewfrm.hxx>
      46             : #include <sfx2/dispatch.hxx>
      47             : #include <sfx2/app.hxx>
      48             : #include <svl/stritem.hxx>
      49             : #include <svl/eitem.hxx>
      50             : #include <svl/intitem.hxx>
      51             : #include <svl/itemset.hxx>
      52             : #include <sfx2/docfac.hxx>
      53             : #include <sfx2/viewfac.hxx>
      54             : 
      55             : #include <basic/sbx.hxx>
      56             : #include <basic/sbstar.hxx>
      57             : #include <basic/basmgr.hxx>
      58             : #include <basic/sbmod.hxx>
      59             : #include <basic/sbmeth.hxx>
      60             : #include <basic/sbuno.hxx>
      61             : #include <rtl/math.hxx>
      62             : #include <sfx2/viewsh.hxx>
      63             : #include <math.h>
      64             : #include <osl/file.hxx>
      65             : #include <toolkit/awt/vclxwindow.hxx>
      66             : #include <toolkit/helper/vclunohelper.hxx>
      67             : #include <vcl/window.hxx>
      68             : #include <vcl/syswin.hxx>
      69             : #include <tools/diagnose_ex.h>
      70             : 
      71             : #ifndef OOVBA_DLLIMPLEMENTATION
      72             : #define OOVBA_DLLIMPLEMENTATION
      73             : #endif
      74             : 
      75             : #include <vbahelper/vbahelper.hxx>
      76             : 
      77             : using namespace ::com::sun::star;
      78             : using namespace ::ooo::vba;
      79             : 
      80             : 
      81             : namespace ooo
      82             : {
      83             : namespace vba
      84             : {
      85             : 
      86             : namespace { const double factor =  2540.0 / 72.0; }
      87             : 
      88             : // helper method to determine if the view ( calc ) is in print-preview mode
      89           0 : bool isInPrintPreview( SfxViewFrame* pView )
      90             : {
      91           0 :     sal_uInt16 nViewNo = SID_VIEWSHELL1 - SID_VIEWSHELL0;
      92           0 :     if ( pView->GetObjectShell()->GetFactory().GetViewFactoryCount() >
      93           0 : nViewNo && !pView->GetObjectShell()->IsInPlaceActive() )
      94             :     {
      95             :         SfxViewFactory &rViewFactory =
      96           0 :             pView->GetObjectShell()->GetFactory().GetViewFactory(nViewNo);
      97           0 :         if (  pView->GetCurViewId() == rViewFactory.GetOrdinal() )
      98           0 :             return true;
      99             :     }
     100           0 :     return false;
     101             : }
     102             : 
     103             : uno::Reference< beans::XIntrospectionAccess >
     104           0 : getIntrospectionAccess( const uno::Any& aObject ) throw (uno::RuntimeException)
     105             : {
     106           0 :     static uno::Reference< beans::XIntrospection > xIntrospection;
     107           0 :     if( !xIntrospection.is() )
     108             :     {
     109           0 :         uno::Reference< uno::XComponentContext > xContext( comphelper::getProcessComponentContext() );
     110           0 :         xIntrospection.set( beans::Introspection::create( xContext ) );
     111             :     }
     112           0 :     return xIntrospection->inspect( aObject );
     113             : }
     114             : 
     115             : uno::Reference< script::XTypeConverter >
     116           0 : getTypeConverter( const uno::Reference< uno::XComponentContext >& xContext ) throw (uno::RuntimeException)
     117             : {
     118           0 :     static uno::Reference< script::XTypeConverter > xTypeConv( script::Converter::create(xContext) );
     119           0 :     return xTypeConv;
     120             : }
     121             : const uno::Any&
     122           0 : aNULL()
     123             : {
     124           0 :      static  uno::Any aNULLL = uno::makeAny( uno::Reference< uno::XInterface >() );
     125           0 :     return aNULLL;
     126             : }
     127             : 
     128           0 : void dispatchExecute(SfxViewShell* pViewShell, sal_uInt16 nSlot, SfxCallMode nCall)
     129             : {
     130           0 :     SfxViewFrame* pViewFrame = NULL;
     131           0 :     if ( pViewShell )
     132           0 :         pViewFrame = pViewShell->GetViewFrame();
     133           0 :     if ( pViewFrame )
     134             :     {
     135           0 :         SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher();
     136           0 :         if( pDispatcher )
     137             :         {
     138           0 :             pDispatcher->Execute( nSlot , nCall );
     139             :         }
     140             :     }
     141           0 : }
     142             : 
     143             : void
     144           0 : dispatchRequests (const uno::Reference< frame::XModel>& xModel, const OUString & aUrl, const uno::Sequence< beans::PropertyValue >& sProps )
     145             : {
     146           0 :     util::URL url;
     147           0 :     url.Complete = aUrl;
     148           0 :     OUString emptyString( "" );
     149           0 :     uno::Reference<frame::XController> xController = xModel->getCurrentController();
     150           0 :     uno::Reference<frame::XFrame> xFrame = xController->getFrame();
     151           0 :     uno::Reference<frame::XDispatchProvider> xDispatchProvider (xFrame,uno::UNO_QUERY_THROW);
     152             :     try
     153             :     {
     154             :         uno::Reference<uno::XComponentContext > xContext(
     155           0 :             comphelper::getProcessComponentContext() );
     156           0 :         uno::Reference<util::XURLTransformer> xParser( util::URLTransformer::create(xContext) );
     157           0 :         xParser->parseStrict (url);
     158             :     }
     159           0 :     catch (const uno::Exception&)
     160             :     {
     161           0 :         return;
     162             :     }
     163             : 
     164           0 :     uno::Reference<frame::XDispatch> xDispatcher = xDispatchProvider->queryDispatch(url,emptyString,0);
     165             : 
     166           0 :     uno::Sequence<beans::PropertyValue> dispatchProps(1);
     167             : 
     168           0 :     sal_Int32 nProps = sProps.getLength();
     169           0 :     beans::PropertyValue* pDest = dispatchProps.getArray();
     170           0 :     if ( nProps )
     171             :     {
     172           0 :         dispatchProps.realloc( nProps + 1 );
     173             :         // need to reaccquire pDest after realloc
     174           0 :         pDest = dispatchProps.getArray();
     175           0 :         const beans::PropertyValue* pSrc = sProps.getConstArray();
     176           0 :         for ( sal_Int32 index=0; index<nProps; ++index, ++pSrc, ++pDest )
     177           0 :             *pDest = *pSrc;
     178             :     }
     179             : 
     180           0 :     if ( xDispatcher.is() )
     181             :     {
     182           0 :         xDispatcher->dispatch( url, dispatchProps );
     183           0 :     }
     184             : }
     185             : 
     186             : void
     187           0 : dispatchRequests( const uno::Reference< frame::XModel>& xModel, const OUString& aUrl )
     188             : {
     189           0 :     uno::Sequence<beans::PropertyValue> dispatchProps;
     190           0 :     dispatchRequests( xModel, aUrl, dispatchProps );
     191           0 : }
     192             : 
     193             : uno::Reference< frame::XModel >
     194           0 : getCurrentDoc( const OUString& sKey ) throw (uno::RuntimeException)
     195             : {
     196           0 :     uno::Reference< frame::XModel > xModel;
     197           0 :     SbxObject* pBasic = dynamic_cast< SbxObject* > ( SFX_APP()->GetBasic() );
     198           0 :     SbxObject* basicChosen =  pBasic ;
     199           0 :     if ( basicChosen == NULL)
     200             :     {
     201             :         OSL_TRACE("getModelFromBasic() StarBASIC* is NULL" );
     202             :         return xModel;
     203             :     }
     204           0 :     SbxObject* p = pBasic;
     205           0 :     SbxObject* pParent = p->GetParent();
     206           0 :     SbxObject* pParentParent = pParent ? pParent->GetParent() : NULL;
     207             : 
     208           0 :     if( pParentParent )
     209             :     {
     210           0 :         basicChosen = pParentParent;
     211             :     }
     212           0 :     else if( pParent )
     213             :     {
     214           0 :         basicChosen = pParent;
     215             :     }
     216             : 
     217             : 
     218           0 :     uno::Any aModel;
     219           0 :     SbxVariable *pCompVar = basicChosen->Find(  sKey, SbxCLASS_OBJECT );
     220             : 
     221           0 :     if ( pCompVar )
     222             :     {
     223           0 :         aModel = sbxToUnoValue( pCompVar );
     224           0 :         if ( sal_False == ( aModel >>= xModel ) ||
     225           0 :             !xModel.is() )
     226             :         {
     227             :             throw uno::RuntimeException(
     228           0 :                 "Can't extract model from basic ( it's obviously not set yet  therefore don't know the current document context)" , uno::Reference< uno::XInterface >() );
     229             :         }
     230             :         else
     231             :         {
     232             :             OSL_TRACE("Have model points to url %s",
     233             :                 OUStringToOString( xModel->getURL(),
     234             :                 RTL_TEXTENCODING_ASCII_US ).pData->buffer );
     235             :         }
     236             :     }
     237             :     else
     238             :     {
     239             :         OSL_TRACE("Failed to get %s", OUStringToOString( sKey, RTL_TEXTENCODING_UTF8 ).getStr() );
     240             :         throw uno::RuntimeException(
     241             :             "Can't determine the currently selected document" ,
     242           0 :             uno::Reference< uno::XInterface >() );
     243             :     }
     244           0 :     return xModel;
     245             : }
     246             : 
     247             :  uno::Reference< frame::XModel >
     248           0 : getCurrentDocCtx( const OUString& ctxName, const uno::Reference< uno::XComponentContext >& xContext ) throw (uno::RuntimeException)
     249             : {
     250           0 :     uno::Reference< frame::XModel > xModel;
     251             :      // try fallback to calling doc
     252           0 :      css::uno::Reference< css::container::XNameAccess > xNameAccess( xContext, css::uno::UNO_QUERY_THROW );
     253           0 :      xModel.set( xNameAccess->getByName( ctxName ), uno::UNO_QUERY_THROW );
     254           0 :      return xModel;
     255             : }
     256             : 
     257             : uno::Reference< frame::XModel >
     258           0 : getThisExcelDoc( const uno::Reference< uno::XComponentContext >& xContext ) throw (uno::RuntimeException)
     259             : {
     260           0 :     return getCurrentDocCtx( "ExcelDocumentContext" , xContext );
     261             : }
     262             : 
     263             : uno::Reference< frame::XModel >
     264           0 : getThisWordDoc( const uno::Reference< uno::XComponentContext >& xContext ) throw (uno::RuntimeException)
     265             : {
     266           0 :     return getCurrentDocCtx( "WordDocumentContext" , xContext );
     267             : }
     268             : 
     269             :  uno::Reference< frame::XModel >
     270           0 : getCurrentExcelDoc( const uno::Reference< uno::XComponentContext >& xContext ) throw (uno::RuntimeException)
     271             : {
     272           0 :     static const OUString sThisExcelDoc( "ThisExcelDoc"  );
     273           0 :     uno::Reference< frame::XModel > xModel;
     274             :     try
     275             :     {
     276           0 :         xModel = getCurrentDoc( sThisExcelDoc );
     277             :     }
     278           0 :     catch (const uno::Exception&)
     279             :     {
     280           0 :         xModel = getThisExcelDoc( xContext );
     281             :     }
     282           0 :     return xModel;
     283             : }
     284             : 
     285             :  uno::Reference< frame::XModel >
     286           0 : getCurrentWordDoc( const uno::Reference< uno::XComponentContext >& xContext ) throw (uno::RuntimeException)
     287             : {
     288           0 :     static const OUString sThisWordDoc( "ThisWordDoc"  );
     289           0 :     uno::Reference< frame::XModel > xModel;
     290             :     try
     291             :     {
     292           0 :         xModel = getCurrentDoc( sThisWordDoc );
     293             :     }
     294           0 :     catch (const uno::Exception&)
     295             :     {
     296           0 :         xModel = getThisWordDoc( xContext );
     297             :     }
     298           0 :     return xModel;
     299             : }
     300             : 
     301             : sal_Int32
     302           0 : OORGBToXLRGB( sal_Int32 nCol )
     303             : {
     304           0 :         sal_Int32 nAutoBits = nCol;
     305           0 :         nAutoBits &= 0xFF000000;
     306           0 :     sal_Int32 nRed = nCol;
     307           0 :     nRed &= 0x00FF0000;
     308           0 :     nRed >>= 16;
     309           0 :     sal_Int32 nGreen = nCol;
     310           0 :     nGreen &= 0x0000FF00;
     311           0 :     nGreen >>= 8;
     312           0 :     sal_Int32 nBlue = nCol;
     313           0 :     nBlue &= 0x000000FF;
     314           0 :     sal_Int32 nRGB =  ( nAutoBits | (nBlue << 16) | (nGreen << 8) | nRed );
     315           0 :     return nRGB;
     316             : }
     317             : sal_Int32
     318           0 : XLRGBToOORGB( sal_Int32 nCol )
     319             : {
     320           0 :         sal_Int32 nAutoBits = nCol;
     321           0 :         nAutoBits &= 0xFF000000;
     322             : 
     323           0 :     sal_Int32 nBlue = nCol;
     324           0 :     nBlue &= 0x00FF0000;
     325           0 :     nBlue >>= 16;
     326           0 :     sal_Int32 nGreen = nCol;
     327           0 :     nGreen &= 0x0000FF00;
     328           0 :     nGreen >>= 8;
     329           0 :     sal_Int32 nRed = nCol;
     330           0 :     nRed &= 0x000000FF;
     331           0 :     sal_Int32 nRGB =  ( nAutoBits | (nRed << 16) | (nGreen << 8) | nBlue );
     332           0 :     return nRGB;
     333             : }
     334             : uno::Any
     335           0 : OORGBToXLRGB( const uno::Any& aCol )
     336             : {
     337           0 :     sal_Int32 nCol(0);
     338           0 :     aCol >>= nCol;
     339           0 :     nCol = OORGBToXLRGB( nCol );
     340           0 :     return uno::makeAny( nCol );
     341             : }
     342             : uno::Any
     343           0 : XLRGBToOORGB(  const uno::Any& aCol )
     344             : {
     345           0 :     sal_Int32 nCol(0);
     346           0 :     aCol >>= nCol;
     347           0 :     nCol = XLRGBToOORGB( nCol );
     348           0 :     return uno::makeAny( nCol );
     349             : }
     350             : 
     351           0 : void PrintOutHelper( SfxViewShell* pViewShell, const uno::Any& From, const uno::Any& To, const uno::Any& Copies, const uno::Any& Preview, const uno::Any& /*ActivePrinter*/, const uno::Any& /*PrintToFile*/, const uno::Any& Collate, const uno::Any& PrToFileName, sal_Bool bUseSelection  )
     352             : {
     353           0 :     sal_Int32 nTo = 0;
     354           0 :     sal_Int32 nFrom = 0;
     355           0 :     sal_Int16 nCopies = 1;
     356           0 :     sal_Bool bPreview = sal_False;
     357           0 :     sal_Bool bCollate = sal_False;
     358           0 :     sal_Bool bSelection = bUseSelection;
     359           0 :     From >>= nFrom;
     360           0 :     To >>= nTo;
     361           0 :     Copies >>= nCopies;
     362           0 :     Preview >>= bPreview;
     363           0 :     if ( nCopies > 1 ) // Collate only useful when more that 1 copy
     364           0 :         Collate >>= bCollate;
     365             : 
     366           0 :     OUString sRange(   "-"  );
     367           0 :     OUString sFileName;
     368             : 
     369           0 :     if (( nFrom || nTo ) )
     370             :     {
     371           0 :         if ( nFrom )
     372           0 :             sRange = ( OUString::valueOf( nFrom ) + sRange );
     373           0 :         if ( nTo )
     374           0 :             sRange += OUString::valueOf( nTo );
     375             :     }
     376             : 
     377           0 :     if (  PrToFileName.getValue() )
     378             :     {
     379           0 :         PrToFileName >>= sFileName;
     380             :     }
     381           0 :     SfxViewFrame* pViewFrame = NULL;
     382           0 :     if ( pViewShell )
     383           0 :         pViewFrame = pViewShell->GetViewFrame();
     384           0 :     if ( pViewFrame )
     385             :     {
     386           0 :         SfxAllItemSet aArgs( SFX_APP()->GetPool() );
     387             : 
     388           0 :         SfxBoolItem sfxCollate( SID_PRINT_COLLATE, bCollate );
     389           0 :         aArgs.Put( sfxCollate, sfxCollate.Which() );
     390           0 :         SfxInt16Item sfxCopies( SID_PRINT_COPIES, nCopies );
     391           0 :         aArgs.Put( sfxCopies, sfxCopies.Which() );
     392           0 :         if ( !sFileName.isEmpty() )
     393             :         {
     394           0 :             SfxStringItem sfxFileName( SID_FILE_NAME, sFileName);
     395           0 :             aArgs.Put( sfxFileName, sfxFileName.Which() );
     396             : 
     397             :         }
     398           0 :         if (  !sRange.isEmpty() )
     399             :         {
     400           0 :             SfxStringItem sfxRange( SID_PRINT_PAGES, sRange );
     401           0 :             aArgs.Put( sfxRange, sfxRange.Which() );
     402             :         }
     403           0 :         SfxBoolItem sfxSelection( SID_SELECTION, bSelection );
     404           0 :         aArgs.Put( sfxSelection, sfxSelection.Which() );
     405           0 :         SfxBoolItem sfxAsync( SID_ASYNCHRON, sal_False );
     406           0 :         aArgs.Put( sfxAsync, sfxAsync.Which() );
     407           0 :         SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher();
     408             : 
     409           0 :         if ( pDispatcher )
     410             :         {
     411           0 :             if ( bPreview )
     412             :             {
     413           0 :                 if ( !pViewFrame->GetFrame().IsInPlace() )
     414             :                 {
     415             :                     // #TODO is this necessary ( calc specific )
     416             : //                  SC_MOD()->InputEnterHandler();
     417           0 :                     pViewFrame->GetDispatcher()->Execute( SID_VIEWSHELL1, SFX_CALLMODE_SYNCHRON );
     418           0 :                     WaitUntilPreviewIsClosed( pViewFrame );
     419             :                 }
     420             :             }
     421             :             else
     422           0 :                 pDispatcher->Execute( (sal_uInt16)SID_PRINTDOC, (SfxCallMode)SFX_CALLMODE_SYNCHRON, aArgs );
     423           0 :         }
     424             : 
     425           0 :     }
     426             : 
     427             :     // #FIXME #TODO
     428             :     // 1 ActivePrinter ( how/can we switch a printer via API? )
     429             :     // 2 PrintToFile ( ms behaviour if this option is specified but no
     430             :     //   filename supplied 'PrToFileName' then the user will be prompted )
     431             :     // 3 Need to check behaviour of Selected sheets with range ( e.g. From & To
     432             :     //    values ) in oOO these options are mutually exclusive
     433             :     // 4 There is a pop up to do with transparent objects in the print source
     434             :     //   should be able to disable that via configuration for the duration
     435             :     //   of this method
     436           0 : }
     437             : 
     438           0 :  void PrintPreviewHelper( const css::uno::Any& /*EnableChanges*/, SfxViewShell* pViewShell )
     439             : {
     440           0 :     SfxViewFrame* pViewFrame = NULL;
     441           0 :     if ( pViewShell )
     442           0 :         pViewFrame = pViewShell->GetViewFrame();
     443           0 :     if ( pViewFrame )
     444             :     {
     445           0 :         if ( !pViewFrame->GetFrame().IsInPlace() )
     446             :         {
     447           0 :             dispatchExecute( pViewShell, SID_VIEWSHELL1 );
     448           0 :             WaitUntilPreviewIsClosed( pViewFrame );
     449             :         }
     450             :     }
     451           0 : }
     452             : 
     453           0 : void WaitUntilPreviewIsClosed( SfxViewFrame* pViewFrame )
     454             : {
     455           0 :     while ( pViewFrame && isInPrintPreview( pViewFrame ) )
     456           0 :         Application::Yield();
     457           0 : }
     458             : 
     459           0 : bool extractBoolFromAny( const uno::Any& rAny ) throw (uno::RuntimeException)
     460             : {
     461           0 :     switch( rAny.getValueType().getTypeClass() )
     462             :     {
     463             :         case uno::TypeClass_BOOLEAN:
     464           0 :             return rAny.get< bool >();
     465             :         case uno::TypeClass_FLOAT:
     466           0 :             return rAny.get< float >() != 0.0;
     467             :         case uno::TypeClass_DOUBLE:
     468           0 :             return rAny.get< double >() != 0.0;
     469             :         case uno::TypeClass_BYTE:
     470             :         case uno::TypeClass_SHORT:
     471             :         case uno::TypeClass_LONG:
     472           0 :             return rAny.get< sal_Int32 >() != 0;
     473             :         case uno::TypeClass_HYPER:
     474           0 :             return rAny.get< sal_Int64 >() != 0;
     475             :         default:;
     476             :     }
     477           0 :     throw uno::RuntimeException( "Invalid type, cannot convert to boolean." , 0 );
     478             : }
     479             : 
     480           0 : OUString extractStringFromAny( const uno::Any& rAny, bool bUppercaseBool ) throw (uno::RuntimeException)
     481             : {
     482           0 :     switch( rAny.getValueType().getTypeClass() )
     483             :     {
     484             :         case uno::TypeClass_STRING:
     485           0 :             return rAny.get< OUString >();
     486             :         case uno::TypeClass_BOOLEAN:
     487             :             return bUppercaseBool ?
     488           0 :                 (rAny.get< bool >() ? OUString(  "TRUE"  ) : OUString(  "FALSE"  )) :
     489           0 :                 OUString::valueOf( (sal_Bool)rAny.get< bool >() );
     490             :         case uno::TypeClass_FLOAT:
     491           0 :             return OUString::valueOf( rAny.get< float >() );
     492             :         case uno::TypeClass_DOUBLE:
     493           0 :             return OUString::valueOf( rAny.get< double >() );
     494             :         case uno::TypeClass_BYTE:
     495             :         case uno::TypeClass_SHORT:
     496             :         case uno::TypeClass_LONG:
     497           0 :             return OUString::valueOf( rAny.get< sal_Int32 >() );
     498             :         case uno::TypeClass_HYPER:
     499           0 :             return OUString::valueOf( rAny.get< sal_Int64 >() );
     500             :         default:;
     501             :     }
     502           0 :     throw uno::RuntimeException( "Invalid type, cannot convert to string." , 0 );
     503             : }
     504             : 
     505           0 : OUString extractStringFromAny( const uno::Any& rAny, const OUString& rDefault, bool bUppercaseBool ) throw (uno::RuntimeException)
     506             : {
     507           0 :     return rAny.hasValue() ? extractStringFromAny( rAny, bUppercaseBool ) : rDefault;
     508             : }
     509             : 
     510           0 : OUString getAnyAsString( const uno::Any& pvargItem ) throw ( uno::RuntimeException )
     511             : {
     512           0 :     return extractStringFromAny( pvargItem );
     513             : }
     514             : 
     515             : 
     516             : OUString
     517           0 : ContainerUtilities::getUniqueName( const uno::Sequence< OUString >&  _slist, const OUString& _sElementName, const OUString& _sSuffixSeparator)
     518             : {
     519           0 :     return getUniqueName(_slist, _sElementName, _sSuffixSeparator, sal_Int32(2));
     520             : }
     521             : 
     522             : OUString
     523           0 : ContainerUtilities::getUniqueName( const uno::Sequence< OUString >& _slist, const OUString _sElementName, const OUString& _sSuffixSeparator, sal_Int32 _nStartSuffix)
     524             : {
     525           0 :     sal_Int32 a = _nStartSuffix;
     526           0 :     OUString scompname = _sElementName;
     527           0 :     bool bElementexists = true;
     528           0 :     sal_Int32 nLen = _slist.getLength();
     529           0 :     if ( nLen == 0 )
     530           0 :         return _sElementName;
     531             : 
     532           0 :     while (bElementexists == true)
     533             :     {
     534           0 :         for (sal_Int32 i = 0; i < nLen; i++)
     535             :         {
     536           0 :             if (FieldInList(_slist, scompname) == -1)
     537             :             {
     538           0 :                 return scompname;
     539             :             }
     540             :         }
     541           0 :         scompname = _sElementName + _sSuffixSeparator + OUString::valueOf( a++ );
     542             :     }
     543           0 :     return OUString();
     544             : }
     545             : 
     546             : sal_Int32
     547           0 : ContainerUtilities::FieldInList( const uno::Sequence< OUString >& SearchList, const OUString& SearchString )
     548             : {
     549           0 :     sal_Int32 FieldLen = SearchList.getLength();
     550           0 :     sal_Int32 retvalue = -1;
     551           0 :     for (sal_Int32 i = 0; i < FieldLen; i++)
     552             :     {
     553             :         // I wonder why comparing lexicographically is done
     554             :         // when its a match is whats interesting?
     555             :         //if (SearchList[i].compareTo(SearchString) == 0)
     556           0 :         if ( SearchList[i].equals( SearchString ) )
     557             :         {
     558           0 :             retvalue = i;
     559           0 :             break;
     560             :         }
     561             :     }
     562           0 :     return retvalue;
     563             : 
     564             : }
     565           0 : bool NeedEsc(sal_Unicode cCode)
     566             : {
     567           0 :     String sEsc(".^$+\\|{}()");
     568           0 :     return (STRING_NOTFOUND != sEsc.Search(cCode));
     569             : }
     570             : 
     571           0 : OUString VBAToRegexp(const OUString &rIn, bool bForLike )
     572             : {
     573           0 :     OUStringBuffer sResult;
     574           0 :     const sal_Unicode *start = rIn.getStr();
     575           0 :     const sal_Unicode *end = start + rIn.getLength();
     576             : 
     577           0 :     int seenright = 0;
     578           0 :     if ( bForLike )
     579           0 :         sResult.append(static_cast<sal_Unicode>('^'));
     580             : 
     581           0 :     while (start < end)
     582             :     {
     583           0 :         switch (*start)
     584             :         {
     585             :             case '?':
     586           0 :                 sResult.append(static_cast<sal_Unicode>('.'));
     587           0 :                 start++;
     588           0 :                 break;
     589             :             case '*':
     590           0 :                 sResult.append(".*");
     591           0 :                 start++;
     592           0 :                 break;
     593             :             case '#':
     594           0 :                 sResult.append("[0-9]");
     595           0 :                 start++;
     596           0 :                 break;
     597             :             case '~':
     598           0 :                 sResult.append(static_cast<sal_Unicode>('\\'));
     599           0 :                 sResult.append(*(++start));
     600           0 :                 start++;
     601           0 :                 break;
     602             :                 // dump the ~ and escape the next characture
     603             :             case ']':
     604           0 :                 sResult.append(static_cast<sal_Unicode>('\\'));
     605           0 :                 sResult.append(*start++);
     606           0 :                 break;
     607             :             case '[':
     608           0 :                 sResult.append(*start++);
     609           0 :                 seenright = 0;
     610           0 :                 while (start < end && !seenright)
     611             :                 {
     612           0 :                     switch (*start)
     613             :                     {
     614             :                         case '[':
     615             :                         case '?':
     616             :                         case '*':
     617           0 :                         sResult.append(static_cast<sal_Unicode>('\\'));
     618           0 :                         sResult.append(*start);
     619           0 :                             break;
     620             :                         case ']':
     621           0 :                         sResult.append(*start);
     622           0 :                             seenright = 1;
     623           0 :                             break;
     624             :                         case '!':
     625           0 :                             sResult.append(static_cast<sal_Unicode>('^'));
     626           0 :                             break;
     627             :                         default:
     628           0 :                         if (NeedEsc(*start))
     629           0 :                             sResult.append(static_cast<sal_Unicode>('\\'));
     630           0 :                         sResult.append(*start);
     631           0 :                             break;
     632             :                     }
     633           0 :                     start++;
     634             :                 }
     635           0 :                 break;
     636             :             default:
     637           0 :                 if (NeedEsc(*start))
     638           0 :                     sResult.append(static_cast<sal_Unicode>('\\'));
     639           0 :                 sResult.append(*start++);
     640             :         }
     641             :     }
     642             : 
     643           0 :     if ( bForLike )
     644           0 :         sResult.append(static_cast<sal_Unicode>('$'));
     645             : 
     646           0 :     return sResult.makeStringAndClear( );
     647             : }
     648             : 
     649           0 : double getPixelTo100thMillimeterConversionFactor( const css::uno::Reference< css::awt::XDevice >& xDevice, sal_Bool bVertical)
     650             : {
     651           0 :     double fConvertFactor = 1.0;
     652           0 :     if( bVertical )
     653             :     {
     654           0 :         fConvertFactor = xDevice->getInfo().PixelPerMeterY/100000;
     655             :     }
     656             :     else
     657             :     {
     658           0 :         fConvertFactor = xDevice->getInfo().PixelPerMeterX/100000;
     659             :     }
     660           0 :     return fConvertFactor;
     661             : }
     662             : 
     663           0 : double PointsToPixels( const css::uno::Reference< css::awt::XDevice >& xDevice, double fPoints, sal_Bool bVertical)
     664             : {
     665           0 :     double fConvertFactor = getPixelTo100thMillimeterConversionFactor( xDevice, bVertical );
     666           0 :     return PointsToHmm( fPoints ) * fConvertFactor;
     667             : }
     668           0 : double PixelsToPoints( const css::uno::Reference< css::awt::XDevice >& xDevice, double fPixels, sal_Bool bVertical)
     669             : {
     670           0 :     double fConvertFactor = getPixelTo100thMillimeterConversionFactor( xDevice, bVertical );
     671           0 :     return HmmToPoints(static_cast<sal_Int32>(fPixels/fConvertFactor));
     672             : }
     673             : 
     674           0 : sal_Int32 PointsToHmm( double fPoints )
     675             : {
     676           0 :     return static_cast<sal_Int32>( fPoints * factor + 0.5 );
     677             : }
     678             : 
     679           0 : double HmmToPoints( sal_Int32 nHmm )
     680             : {
     681           0 :     return nHmm / factor;
     682             : }
     683             : 
     684           0 : ConcreteXShapeGeometryAttributes::ConcreteXShapeGeometryAttributes( const css::uno::Reference< css::uno::XComponentContext >& /*xContext*/, const css::uno::Reference< css::drawing::XShape >& xShape )
     685             : {
     686           0 :     m_pShapeHelper.reset( new ShapeHelper( xShape ) );
     687           0 : }
     688           0 : ConcreteXShapeGeometryAttributes::~ConcreteXShapeGeometryAttributes()
     689             : {
     690           0 : }
     691             : 
     692           0 : sal_Int32 getPointerStyle( const uno::Reference< frame::XModel >& xModel )
     693             : {
     694             : 
     695           0 :     sal_Int32 nPointerStyle( POINTER_ARROW );
     696             :     try
     697             :     {
     698           0 :         const uno::Reference< frame::XController > xController( xModel->getCurrentController(),     uno::UNO_SET_THROW );
     699           0 :         const uno::Reference< frame::XFrame >      xFrame     ( xController->getFrame(),        uno::UNO_SET_THROW );
     700           0 :         const uno::Reference< awt::XWindow >       xWindow    ( xFrame->getContainerWindow(),   uno::UNO_SET_THROW );
     701             :         // why the heck isn't there an XWindowPeer::getPointer, but a setPointer only?
     702           0 :         const Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
     703           0 :         if ( pWindow )
     704           0 :             nPointerStyle = pWindow->GetSystemWindow()->GetPointer().GetStyle();
     705             :     }
     706           0 :     catch (const uno::Exception&)
     707             :     {
     708             :         DBG_UNHANDLED_EXCEPTION();
     709             :     }
     710           0 :     return nPointerStyle;
     711             : }
     712             : 
     713             : // #FIXME this method looks wrong, shouldn't it just affect calc *or* writer
     714             : // document/frame/window(s) but not both ( and depending on what api called
     715             : // this )
     716           0 : void setCursorHelper( const uno::Reference< frame::XModel >& xModel, const Pointer& rPointer, sal_Bool bOverWrite )
     717             : {
     718           0 :     ::std::vector< uno::Reference< frame::XController > > aControllers;
     719             : 
     720           0 :     uno::Reference< frame::XModel2 > xModel2( xModel, uno::UNO_QUERY );
     721           0 :     if ( xModel2.is() )
     722             :     {
     723           0 :         const uno::Reference< container::XEnumeration > xEnumControllers( xModel2->getControllers(), uno::UNO_SET_THROW );
     724           0 :         while ( xEnumControllers->hasMoreElements() )
     725             :         {
     726           0 :             const uno::Reference< frame::XController > xController( xEnumControllers->nextElement(), uno::UNO_QUERY_THROW );
     727           0 :             aControllers.push_back( xController );
     728           0 :         }
     729             :     }
     730             :     else
     731             :     {
     732           0 :         if ( xModel.is() )
     733             :         {
     734           0 :             const uno::Reference< frame::XController > xController( xModel->getCurrentController(), uno::UNO_SET_THROW );
     735           0 :             aControllers.push_back( xController );
     736             :         }
     737             :     }
     738             : 
     739           0 :     for (   ::std::vector< uno::Reference< frame::XController > >::const_iterator controller = aControllers.begin();
     740           0 :             controller != aControllers.end();
     741             :             ++controller
     742             :         )
     743             :     {
     744           0 :         const uno::Reference< frame::XFrame >      xFrame     ( (*controller)->getFrame(),       uno::UNO_SET_THROW   );
     745           0 :         const uno::Reference< awt::XWindow >       xWindow    ( xFrame->getContainerWindow(),    uno::UNO_SET_THROW   );
     746             : 
     747           0 :         Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
     748             :         OSL_ENSURE( pWindow, "ScVbaApplication::setCursor: no window!" );
     749           0 :         if ( !pWindow )
     750           0 :             continue;
     751             : 
     752           0 :         pWindow->GetSystemWindow()->SetPointer( rPointer );
     753           0 :         pWindow->GetSystemWindow()->EnableChildPointerOverwrite( bOverWrite );
     754           0 :     }
     755           0 : }
     756             : 
     757           0 : void setDefaultPropByIntrospection( const uno::Any& aObj, const uno::Any& aValue  ) throw ( uno::RuntimeException )
     758             : {
     759           0 :     uno::Reference< beans::XIntrospectionAccess > xUnoAccess( getIntrospectionAccess( aObj ) );
     760             : 
     761             :     // #MAYBE #FIXME sort of a bit of a hack,
     762           0 :     uno::Reference<  script::XDefaultProperty > xDflt( aObj, uno::UNO_QUERY_THROW );
     763           0 :     uno::Reference< beans::XPropertySet > xPropSet;
     764             : 
     765           0 :     if ( xUnoAccess.is() )
     766           0 :         xPropSet.set( xUnoAccess->queryAdapter( ::getCppuType( (const uno::Reference< beans::XPropertySet > *)0 ) ), uno::UNO_QUERY);
     767             : 
     768           0 :     if ( xPropSet.is() )
     769           0 :         xPropSet->setPropertyValue( xDflt->getDefaultPropertyName(), aValue );
     770             :     else
     771           0 :         throw uno::RuntimeException();
     772           0 : }
     773             : 
     774           0 : uno::Any getPropertyValue( const uno::Sequence< beans::PropertyValue >& aProp, const OUString& aName )
     775             : {
     776           0 :     uno::Any result;
     777           0 :     for ( sal_Int32 i = 0; i < aProp.getLength(); i++ )
     778             :     {
     779           0 :         if ( aProp[i].Name.equals(aName) )
     780             :         {
     781           0 :             aProp[i].Value >>= result;
     782           0 :             return result;
     783             :         }
     784             :     }
     785           0 :     return result;
     786             : }
     787             : 
     788           0 : sal_Bool setPropertyValue( uno::Sequence< beans::PropertyValue >& aProp, const OUString& aName, const uno::Any& aValue )
     789             : {
     790           0 :     for ( sal_Int32 i = 0; i < aProp.getLength(); i++ )
     791             :     {
     792           0 :         if ( aProp[i].Name.equals(aName) )
     793             :         {
     794           0 :             aProp[i].Value = aValue;
     795           0 :             return sal_True;
     796             :         }
     797             :     }
     798           0 :     return sal_False;
     799             : }
     800             : 
     801           0 : void setOrAppendPropertyValue( uno::Sequence< beans::PropertyValue >& aProp, const OUString& aName, const uno::Any& aValue )
     802             : {
     803           0 :    if( setPropertyValue( aProp, aName, aValue ) )
     804           0 :     return;
     805             : 
     806             :   // append the property
     807           0 :   sal_Int32 nLength = aProp.getLength();
     808           0 :   aProp.realloc( nLength + 1 );
     809           0 :   aProp[ nLength ].Name = aName;
     810           0 :   aProp[ nLength ].Value = aValue;
     811             : }
     812             : 
     813             : // ====UserFormGeomentryHelper====
     814             : //---------------------------------------------
     815           0 : UserFormGeometryHelper::UserFormGeometryHelper(
     816             :         const uno::Reference< uno::XComponentContext >& /*xContext*/,
     817             :         const uno::Reference< awt::XControl >& xControl,
     818             :         double fOffsetX, double fOffsetY ) :
     819             :     mfOffsetX( fOffsetX ),
     820             :     mfOffsetY( fOffsetY ),
     821           0 :     mbDialog( uno::Reference< awt::XDialog >( xControl, uno::UNO_QUERY ).is() )
     822             : {
     823           0 :     if ( !xControl.is() )
     824           0 :         throw uno::RuntimeException( "No control is provided!", uno::Reference< uno::XInterface >() );
     825             : 
     826           0 :     mxWindow.set( xControl->getPeer(), uno::UNO_QUERY_THROW );
     827           0 :     mxModelProps.set( xControl->getModel(), uno::UNO_QUERY_THROW );
     828           0 :     mxUnitConv.set( mxWindow, uno::UNO_QUERY_THROW );
     829           0 : }
     830             : 
     831           0 : double UserFormGeometryHelper::getLeft() const
     832             : {
     833           0 :     return implGetPos( false );
     834             : }
     835             : 
     836           0 : void UserFormGeometryHelper::setLeft( double fLeft )
     837             : {
     838           0 :     implSetPos( fLeft, false );
     839           0 : }
     840             : 
     841           0 : double UserFormGeometryHelper::getTop() const
     842             : {
     843           0 :     return implGetPos( true );
     844             : }
     845             : 
     846           0 : void UserFormGeometryHelper::setTop( double fTop )
     847             : {
     848           0 :     implSetPos( fTop, true );
     849           0 : }
     850             : 
     851           0 : double UserFormGeometryHelper::getWidth() const
     852             : {
     853           0 :     return implGetSize( false, true );
     854             : }
     855             : 
     856           0 : void UserFormGeometryHelper::setWidth( double fWidth )
     857             : {
     858           0 :     implSetSize( fWidth, false, true );
     859           0 : }
     860             : 
     861           0 : double UserFormGeometryHelper::getHeight() const
     862             : {
     863           0 :     return implGetSize( true, true );
     864             : }
     865             : 
     866           0 : void UserFormGeometryHelper::setHeight( double fHeight )
     867             : {
     868           0 :     implSetSize( fHeight, true, true );
     869           0 : }
     870             : 
     871           0 : double UserFormGeometryHelper::getInnerWidth() const
     872             : {
     873           0 :     return implGetSize( false, false );
     874             : }
     875             : 
     876           0 : void UserFormGeometryHelper::setInnerWidth( double fWidth )
     877             : {
     878           0 :     implSetSize( fWidth, false, false );
     879           0 : }
     880             : 
     881           0 : double UserFormGeometryHelper::getInnerHeight() const
     882             : {
     883           0 :     return implGetSize( true, false );
     884             : }
     885             : 
     886           0 : void UserFormGeometryHelper::setInnerHeight( double fHeight )
     887             : {
     888           0 :     implSetSize( fHeight, true, false );
     889           0 : }
     890             : 
     891           0 : double UserFormGeometryHelper::getOffsetX() const
     892             : {
     893           0 :     return mfOffsetX;
     894             : }
     895             : 
     896           0 : double UserFormGeometryHelper::getOffsetY() const
     897             : {
     898           0 :     return mfOffsetY;
     899             : }
     900             : 
     901             : // ----------------------------------------------------------------------------
     902             : 
     903             : static const char saPosXName[] = "PositionX";
     904             : static const char saPosYName[] = "PositionY";
     905             : static const char saWidthName[] = "Width";
     906             : static const char saHeightName[] = "Height";
     907             : 
     908           0 : double UserFormGeometryHelper::implGetPos( bool bPosY ) const
     909             : {
     910           0 :     sal_Int32 nPosAppFont = mxModelProps->getPropertyValue( bPosY ? OUString(saPosYName) : OUString(saPosXName) ).get< sal_Int32 >();
     911             :     // appfont to pixel
     912           0 :     awt::Point aPosPixel = mxUnitConv->convertPointToPixel( awt::Point( nPosAppFont, nPosAppFont ), util::MeasureUnit::APPFONT );
     913             :     // pixel to VBA points
     914           0 :     awt::Point aPosPoint = mxUnitConv->convertPointToLogic( aPosPixel, util::MeasureUnit::POINT );
     915           0 :     return bPosY ? (aPosPoint.Y - mfOffsetY) : (aPosPoint.X - mfOffsetX);
     916             : }
     917             : 
     918           0 : void UserFormGeometryHelper::implSetPos( double fPos, bool bPosY )
     919             : {
     920             :     // convert passed VBA points to pixels
     921           0 :     sal_Int32 nPosPixel = static_cast< sal_Int32 >( fPos + (bPosY ? mfOffsetY : mfOffsetX) );
     922           0 :     awt::Point aPosPixel = mxUnitConv->convertPointToPixel( awt::Point( nPosPixel, nPosPixel ), util::MeasureUnit::POINT );
     923             :     // pixel to appfont
     924           0 :     awt::Point aPosAppFont = mxUnitConv->convertPointToLogic( aPosPixel, util::MeasureUnit::APPFONT );
     925           0 :     mxModelProps->setPropertyValue( bPosY ? OUString(saPosYName) : OUString(saPosXName), uno::Any( bPosY ? aPosAppFont.Y : aPosAppFont.X ) );
     926           0 : }
     927             : 
     928           0 : double UserFormGeometryHelper::implGetSize( bool bHeight, bool bOuter ) const
     929             : {
     930           0 :     sal_Int32 nSizeAppFont = mxModelProps->getPropertyValue( bHeight ? OUString(saHeightName) : OUString(saWidthName) ).get< sal_Int32 >();
     931             :     // appfont to pixel
     932           0 :     awt::Size aSizePixel = mxUnitConv->convertSizeToPixel( awt::Size( nSizeAppFont, nSizeAppFont ), util::MeasureUnit::APPFONT );
     933             : 
     934             :     /*  The VBA symbols 'Width' and 'Height' return the outer size including
     935             :         window decoration (in difference to the symbols 'InnerWidth' and
     936             :         'InnerHeight'), but the window API returns the inner size. */
     937           0 :     if( mbDialog && bOuter )
     938             :     {
     939           0 :         if( const Window* pWindow = VCLUnoHelper::GetWindow( mxWindow ) )
     940             :         {
     941           0 :             Rectangle aOuterRect = pWindow->GetWindowExtentsRelative( NULL );
     942           0 :             aSizePixel = awt::Size( aOuterRect.getWidth(), aOuterRect.getHeight() );
     943             :         }
     944             :     }
     945             : 
     946             :     // pixel to VBA points
     947           0 :     awt::Size aSizePoint = mxUnitConv->convertSizeToLogic( aSizePixel, util::MeasureUnit::POINT );
     948           0 :     return bHeight ? aSizePoint.Height : aSizePoint.Width;
     949             : }
     950             : 
     951           0 : void UserFormGeometryHelper::implSetSize( double fSize, bool bHeight, bool bOuter )
     952             : {
     953             :     // convert passed VBA points to pixels
     954           0 :     sal_Int32 nSize = static_cast< sal_Int32 >( fSize );
     955           0 :     awt::Size aSizePixel = mxUnitConv->convertSizeToPixel( awt::Size( nSize, nSize ), util::MeasureUnit::POINT );
     956             : 
     957             :     /*  The VBA symbols 'Width' and 'Height' set the outer size (in difference
     958             :         to the symbols 'InnerWidth' and 'InnerHeight'), but the dialog model
     959             :         expects the inner size. We have to remove the window extents from the
     960             :         pixel height to get the same result. */
     961           0 :     if ( mbDialog && bOuter )
     962             :     {
     963           0 :         if( const Window* pWindow = VCLUnoHelper::GetWindow( mxWindow ) )
     964             :         {
     965           0 :             Rectangle aOuterRect = pWindow->GetWindowExtentsRelative( NULL );
     966           0 :             if( !aOuterRect.IsEmpty() )
     967             :             {
     968           0 :                 awt::Rectangle aInnerRect = mxWindow->getPosSize();
     969           0 :                 sal_Int32 nDecorWidth = aOuterRect.getWidth() - aInnerRect.Width;
     970           0 :                 sal_Int32 nDecorHeight = aOuterRect.getHeight() - aInnerRect.Height;
     971           0 :                 aSizePixel.Width = ::std::max< sal_Int32 >( aSizePixel.Width - nDecorWidth, 1 );
     972           0 :                 aSizePixel.Height = ::std::max< sal_Int32 >( aSizePixel.Height - nDecorHeight, 1 );
     973             :             }
     974             :         }
     975             :     }
     976             : 
     977           0 :     awt::Size aSizeAppFont = mxUnitConv->convertSizeToLogic( aSizePixel, util::MeasureUnit::APPFONT );
     978           0 :     mxModelProps->setPropertyValue( bHeight ? OUString(saHeightName) : OUString(saWidthName), uno::Any( bHeight ? aSizeAppFont.Height : aSizeAppFont.Width ) );
     979           0 : }
     980             : 
     981             : // ============================================================================
     982             : 
     983           0 : double ConcreteXShapeGeometryAttributes::getLeft() const
     984             : {
     985           0 :     return m_pShapeHelper->getLeft();
     986             : }
     987           0 : void ConcreteXShapeGeometryAttributes::setLeft( double nLeft )
     988             : {
     989           0 :     m_pShapeHelper->setLeft( nLeft );
     990           0 : }
     991           0 : double ConcreteXShapeGeometryAttributes::getTop() const
     992             : {
     993           0 :     return m_pShapeHelper->getTop();
     994             : }
     995           0 : void ConcreteXShapeGeometryAttributes::setTop( double nTop )
     996             : {
     997           0 :     m_pShapeHelper->setTop( nTop );
     998           0 : }
     999             : 
    1000           0 : double ConcreteXShapeGeometryAttributes::getHeight() const
    1001             : {
    1002           0 :     return m_pShapeHelper->getHeight();
    1003             : }
    1004           0 : void ConcreteXShapeGeometryAttributes::setHeight( double nHeight )
    1005             : {
    1006           0 :     m_pShapeHelper->setHeight( nHeight );
    1007           0 : }
    1008           0 : double ConcreteXShapeGeometryAttributes::getWidth() const
    1009             : {
    1010           0 :     return m_pShapeHelper->getWidth();
    1011             : }
    1012           0 : void ConcreteXShapeGeometryAttributes::setWidth( double nWidth)
    1013             : {
    1014           0 :     m_pShapeHelper->setWidth( nWidth );
    1015           0 : }
    1016             : 
    1017             : 
    1018           0 : ShapeHelper::ShapeHelper( const css::uno::Reference< css::drawing::XShape >& _xShape) throw (css::script::BasicErrorException ) : xShape( _xShape )
    1019             : {
    1020           0 :     if( !xShape.is() )
    1021           0 :         throw css::uno::RuntimeException( "No valid shape for helper" , css::uno::Reference< css::uno::XInterface >() );
    1022           0 : }
    1023             : 
    1024           0 : double ShapeHelper::getHeight() const
    1025             : {
    1026           0 :         return  Millimeter::getInPoints(xShape->getSize().Height);
    1027             :     }
    1028             : 
    1029             : 
    1030           0 :     void ShapeHelper::setHeight(double _fheight) throw ( css::script::BasicErrorException )
    1031             : {
    1032             :     try
    1033             :     {
    1034           0 :         css::awt::Size aSize = xShape->getSize();
    1035           0 :         aSize.Height = Millimeter::getInHundredthsOfOneMillimeter(_fheight);
    1036           0 :         xShape->setSize(aSize);
    1037             :     }
    1038           0 :     catch (const css::uno::Exception&)
    1039             :     {
    1040           0 :         throw css::script::BasicErrorException( OUString(), css::uno::Reference< css::uno::XInterface >(), SbERR_METHOD_FAILED, OUString() );
    1041             :         }
    1042           0 : }
    1043           0 : double ShapeHelper::getWidth() const
    1044             : {
    1045           0 :     return Millimeter::getInPoints(xShape->getSize().Width);
    1046             :     }
    1047             : 
    1048           0 : void ShapeHelper::setWidth(double _fWidth) throw ( css::script::BasicErrorException )
    1049             : {
    1050             :     try
    1051             :     {
    1052           0 :         css::awt::Size aSize = xShape->getSize();
    1053           0 :         aSize.Width = Millimeter::getInHundredthsOfOneMillimeter(_fWidth);
    1054           0 :         xShape->setSize(aSize);
    1055             :     }
    1056           0 :     catch (const css::uno::Exception&)
    1057             :     {
    1058           0 :         throw css::script::BasicErrorException( OUString(), css::uno::Reference< css::uno::XInterface >(), SbERR_METHOD_FAILED, OUString() );
    1059             :     }
    1060           0 : }
    1061             : 
    1062             : 
    1063           0 : double ShapeHelper::getLeft() const
    1064             : {
    1065           0 :     return Millimeter::getInPoints(xShape->getPosition().X);
    1066             : }
    1067             : 
    1068             : 
    1069           0 : void ShapeHelper::setLeft(double _fLeft)
    1070             : {
    1071           0 :     css::awt::Point aPoint = xShape->getPosition();
    1072           0 :     aPoint.X = Millimeter::getInHundredthsOfOneMillimeter(_fLeft);
    1073           0 :     xShape->setPosition(aPoint);
    1074           0 : }
    1075             : 
    1076             : 
    1077           0 : double ShapeHelper::getTop() const
    1078             : {
    1079           0 :         return Millimeter::getInPoints(xShape->getPosition().Y);
    1080             : }
    1081             : 
    1082             : 
    1083           0 : void ShapeHelper::setTop(double _fTop)
    1084             : {
    1085           0 :     css::awt::Point aPoint = xShape->getPosition();
    1086           0 :     aPoint.Y = Millimeter::getInHundredthsOfOneMillimeter(_fTop);
    1087           0 :     xShape->setPosition(aPoint);
    1088           0 : }
    1089             : 
    1090           0 : void DebugHelper::exception( const OUString&  DetailedMessage, const css::uno::Exception& ex,  int err, const OUString& /*additionalArgument*/ ) throw( css::script::BasicErrorException )
    1091             : {
    1092             :     // #TODO #FIXME ( do we want to support additionalArg here )
    1093           0 :     throw css::script::BasicErrorException( DetailedMessage.concat( " " ).concat( ex.Message ), css::uno::Reference< css::uno::XInterface >(), err, OUString() );
    1094             : }
    1095             : 
    1096           0 : void DebugHelper::exception( int err,  const OUString& additionalArgument ) throw( css::script::BasicErrorException )
    1097             : {
    1098           0 :     exception( OUString(), css::uno::Exception(), err, additionalArgument );
    1099           0 : }
    1100           0 : void DebugHelper::exception( const css::uno::Exception& ex ) throw( css::script::BasicErrorException )
    1101             : {
    1102           0 :     exception( OUString(), ex, SbERR_INTERNAL_ERROR, OUString() );
    1103           0 : }
    1104             : 
    1105           0 : Millimeter::Millimeter():m_nMillimeter(0) {}
    1106             : 
    1107           0 : Millimeter::Millimeter(double mm):m_nMillimeter(mm) {}
    1108             : 
    1109           0 : void Millimeter::setInPoints(double points)
    1110             : {
    1111           0 :     m_nMillimeter = points * factor / 100.0;
    1112           0 : }
    1113             : 
    1114           0 : double Millimeter::getInHundredthsOfOneMillimeter()
    1115             : {
    1116           0 :     return m_nMillimeter * 100;
    1117             : }
    1118             : 
    1119           0 : sal_Int32 Millimeter::getInHundredthsOfOneMillimeter(double points)
    1120             : {
    1121           0 :     sal_Int32 mm = static_cast<sal_Int32>(points * factor);
    1122           0 :     return mm;
    1123             : }
    1124             : 
    1125           0 : double Millimeter::getInPoints(int _hmm)
    1126             : {
    1127           0 :     double points = double( static_cast<double>(_hmm) / factor);
    1128           0 :     return points;
    1129             : }
    1130             : 
    1131           0 : uno::Reference< XHelperInterface > getVBADocument( const uno::Reference< frame::XModel >& xModel )
    1132             : {
    1133           0 :     uno::Reference< XHelperInterface > xIf;
    1134             :     try
    1135             :     {
    1136           0 :         uno::Reference< beans::XPropertySet > xDocProps( xModel, uno::UNO_QUERY_THROW );
    1137           0 :         OUString aCodeName;
    1138           0 :         xDocProps->getPropertyValue( "CodeName" ) >>= aCodeName;
    1139           0 :         xIf = getUnoDocModule( aCodeName, getSfxObjShell( xModel ) );
    1140             :     }
    1141           0 :     catch (const uno::Exception&)
    1142             :     {
    1143             :     }
    1144           0 :     return xIf;
    1145             : }
    1146             : 
    1147           0 : uno::Reference< XHelperInterface > getUnoDocModule( const String& aModName, SfxObjectShell* pShell )
    1148             : {
    1149           0 :     uno::Reference< XHelperInterface > xIf;
    1150           0 :     if ( pShell )
    1151             :     {
    1152           0 :         OUString sProj( "Standard" );
    1153           0 :         BasicManager* pBasMgr = pShell->GetBasicManager();
    1154           0 :         if ( pBasMgr && !pBasMgr->GetName().isEmpty() )
    1155           0 :             sProj = pBasMgr->GetName();
    1156           0 :         if( StarBASIC* pBasic = pShell->GetBasicManager()->GetLib( sProj ) )
    1157           0 :             if( SbModule* pMod = pBasic->FindModule( aModName ) )
    1158           0 :                 xIf.set( pMod->GetUnoModule(), uno::UNO_QUERY );
    1159             :     }
    1160           0 :     return xIf;
    1161             : }
    1162             : 
    1163           0 : SfxObjectShell* getSfxObjShell( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException)
    1164             : {
    1165           0 :     SfxObjectShell* pFoundShell = NULL;
    1166           0 :     if ( xModel.is() )
    1167             :     {
    1168           0 :         uno::Reference< lang::XUnoTunnel >  xObjShellTunnel( xModel, uno::UNO_QUERY_THROW );
    1169           0 :         pFoundShell = reinterpret_cast<SfxObjectShell*>( xObjShellTunnel->getSomething(SfxObjectShell::getUnoTunnelId()));
    1170             :     }
    1171           0 :     if ( !pFoundShell )
    1172           0 :         throw uno::RuntimeException();
    1173           0 :     return pFoundShell;
    1174             : }
    1175             : 
    1176             : } // openoffice
    1177             : } //org
    1178             : 
    1179             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10