1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir #include "vbasystem.hxx" 28*cdf0e10cSrcweir #include <vbahelper/vbahelper.hxx> 29*cdf0e10cSrcweir #include <ooo/vba/word/WdCursorType.hpp> 30*cdf0e10cSrcweir #include <tools/diagnose_ex.h> 31*cdf0e10cSrcweir #include <tools/config.hxx> 32*cdf0e10cSrcweir #include <tools/string.hxx> 33*cdf0e10cSrcweir #include <osl/file.hxx> 34*cdf0e10cSrcweir #include <tools/urlobj.hxx> 35*cdf0e10cSrcweir #include <tools/string.hxx> 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir using namespace ::ooo::vba; 38*cdf0e10cSrcweir using namespace ::com::sun::star; 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir PrivateProfileStringListener::~PrivateProfileStringListener() 41*cdf0e10cSrcweir { 42*cdf0e10cSrcweir } 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir void PrivateProfileStringListener::Initialize( const rtl::OUString& rFileName, const ByteString& rGroupName, const ByteString& rKey ) 45*cdf0e10cSrcweir { 46*cdf0e10cSrcweir maFileName = rFileName; 47*cdf0e10cSrcweir maGroupName = rGroupName; 48*cdf0e10cSrcweir maKey = rKey; 49*cdf0e10cSrcweir } 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir uno::Any PrivateProfileStringListener::getValueEvent() 52*cdf0e10cSrcweir { 53*cdf0e10cSrcweir // get the private profile string 54*cdf0e10cSrcweir Config aCfg( maFileName ); 55*cdf0e10cSrcweir aCfg.SetGroup( maGroupName ); 56*cdf0e10cSrcweir rtl::OUString sValue = String( aCfg.ReadKey( maKey ), RTL_TEXTENCODING_DONTKNOW ); 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir return uno::makeAny( sValue ); 59*cdf0e10cSrcweir } 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir void PrivateProfileStringListener::setValueEvent( const css::uno::Any& value ) 62*cdf0e10cSrcweir { 63*cdf0e10cSrcweir // set the private profile string 64*cdf0e10cSrcweir Config aCfg( maFileName ); 65*cdf0e10cSrcweir aCfg.SetGroup( maGroupName ); 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir rtl::OUString aValue; 68*cdf0e10cSrcweir value >>= aValue; 69*cdf0e10cSrcweir aCfg.WriteKey( maKey, ByteString( aValue.getStr(), RTL_TEXTENCODING_DONTKNOW ) ); 70*cdf0e10cSrcweir } 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir SwVbaSystem::SwVbaSystem( uno::Reference<uno::XComponentContext >& xContext ): SwVbaSystem_BASE( uno::Reference< XHelperInterface >(), xContext ) 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir } 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir SwVbaSystem::~SwVbaSystem() 77*cdf0e10cSrcweir { 78*cdf0e10cSrcweir } 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir sal_Int32 SAL_CALL 81*cdf0e10cSrcweir SwVbaSystem::getCursor() throw (uno::RuntimeException) 82*cdf0e10cSrcweir { 83*cdf0e10cSrcweir sal_Int32 nPointerStyle = getPointerStyle( getCurrentWordDoc(mxContext) ); 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir switch( nPointerStyle ) 86*cdf0e10cSrcweir { 87*cdf0e10cSrcweir case POINTER_ARROW: 88*cdf0e10cSrcweir return word::WdCursorType::wdCursorNorthwestArrow; 89*cdf0e10cSrcweir case POINTER_NULL: 90*cdf0e10cSrcweir return word::WdCursorType::wdCursorNormal; 91*cdf0e10cSrcweir case POINTER_WAIT: 92*cdf0e10cSrcweir return word::WdCursorType::wdCursorWait; 93*cdf0e10cSrcweir case POINTER_TEXT: 94*cdf0e10cSrcweir return word::WdCursorType::wdCursorIBeam; 95*cdf0e10cSrcweir default: 96*cdf0e10cSrcweir return word::WdCursorType::wdCursorNormal; 97*cdf0e10cSrcweir } 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir void SAL_CALL 101*cdf0e10cSrcweir SwVbaSystem::setCursor( sal_Int32 _cursor ) throw (uno::RuntimeException) 102*cdf0e10cSrcweir { 103*cdf0e10cSrcweir try 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir switch( _cursor ) 106*cdf0e10cSrcweir { 107*cdf0e10cSrcweir case word::WdCursorType::wdCursorNorthwestArrow: 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir const Pointer& rPointer( POINTER_ARROW ); 110*cdf0e10cSrcweir setCursorHelper( getCurrentWordDoc(mxContext), rPointer, sal_False ); 111*cdf0e10cSrcweir break; 112*cdf0e10cSrcweir } 113*cdf0e10cSrcweir case word::WdCursorType::wdCursorWait: 114*cdf0e10cSrcweir { 115*cdf0e10cSrcweir const Pointer& rPointer( static_cast< PointerStyle >( POINTER_WAIT ) ); 116*cdf0e10cSrcweir //It will set the edit window, toobar and statusbar's mouse pointer. 117*cdf0e10cSrcweir setCursorHelper( getCurrentWordDoc(mxContext), rPointer, sal_True ); 118*cdf0e10cSrcweir break; 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir case word::WdCursorType::wdCursorIBeam: 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir const Pointer& rPointer( static_cast< PointerStyle >( POINTER_TEXT ) ); 123*cdf0e10cSrcweir //It will set the edit window, toobar and statusbar's mouse pointer. 124*cdf0e10cSrcweir setCursorHelper( getCurrentWordDoc( mxContext ), rPointer, sal_True ); 125*cdf0e10cSrcweir break; 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir case word::WdCursorType::wdCursorNormal: 128*cdf0e10cSrcweir { 129*cdf0e10cSrcweir const Pointer& rPointer( POINTER_NULL ); 130*cdf0e10cSrcweir setCursorHelper( getCurrentWordDoc( mxContext ), rPointer, sal_False ); 131*cdf0e10cSrcweir break; 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir default: 134*cdf0e10cSrcweir throw uno::RuntimeException( rtl::OUString( 135*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("Unknown value for Cursor pointer")), uno::Reference< uno::XInterface >() ); 136*cdf0e10cSrcweir // TODO: isn't this a flaw in the API? It should be allowed to throw an 137*cdf0e10cSrcweir // IllegalArgumentException, or so 138*cdf0e10cSrcweir } 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir catch( const uno::Exception& ) 141*cdf0e10cSrcweir { 142*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir uno::Any SAL_CALL 147*cdf0e10cSrcweir SwVbaSystem::PrivateProfileString( const rtl::OUString& rFilename, const rtl::OUString& rSection, const rtl::OUString& rKey ) throw ( uno::RuntimeException ) 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir if( rFilename.getLength() == 0 ) 150*cdf0e10cSrcweir throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Failed to access document from shell" ) ), uno::Reference< uno::XInterface >() ); 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir // FIXME: need to detect whether it is a relative file path 153*cdf0e10cSrcweir // we need to detect if this is a URL, if not then assume its a file path 154*cdf0e10cSrcweir rtl::OUString sFileUrl; 155*cdf0e10cSrcweir INetURLObject aObj; 156*cdf0e10cSrcweir aObj.SetURL( rFilename ); 157*cdf0e10cSrcweir bool bIsURL = aObj.GetProtocol() != INET_PROT_NOT_VALID; 158*cdf0e10cSrcweir if ( bIsURL ) 159*cdf0e10cSrcweir sFileUrl = rFilename; 160*cdf0e10cSrcweir else 161*cdf0e10cSrcweir osl::FileBase::getFileURLFromSystemPath( rFilename, sFileUrl); 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir ByteString aGroupName = ByteString( rSection.getStr(), RTL_TEXTENCODING_DONTKNOW); 164*cdf0e10cSrcweir ByteString aKey = ByteString( rKey.getStr(), RTL_TEXTENCODING_DONTKNOW); 165*cdf0e10cSrcweir maPrivateProfileStringListener.Initialize( sFileUrl, aGroupName, aKey ); 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir return uno::makeAny( uno::Reference< XPropValue > ( new ScVbaPropValue( &maPrivateProfileStringListener ) ) ); 168*cdf0e10cSrcweir } 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir rtl::OUString& 171*cdf0e10cSrcweir SwVbaSystem::getServiceImplName() 172*cdf0e10cSrcweir { 173*cdf0e10cSrcweir static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaSystem") ); 174*cdf0e10cSrcweir return sImplName; 175*cdf0e10cSrcweir } 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir uno::Sequence< rtl::OUString > 178*cdf0e10cSrcweir SwVbaSystem::getServiceNames() 179*cdf0e10cSrcweir { 180*cdf0e10cSrcweir static uno::Sequence< rtl::OUString > aServiceNames; 181*cdf0e10cSrcweir if ( aServiceNames.getLength() == 0 ) 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir aServiceNames.realloc( 1 ); 184*cdf0e10cSrcweir aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.System" ) ); 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir return aServiceNames; 187*cdf0e10cSrcweir } 188