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

Generated by: LCOV version 1.10