1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #include "vbasystem.hxx"
31 #include <vbahelper/vbahelper.hxx>
32 #include <ooo/vba/word/WdCursorType.hpp>
33 #include <tools/diagnose_ex.h>
34 #include <tools/config.hxx>
35 #include <tools/string.hxx>
36 #include <osl/file.hxx>
37 #include <tools/urlobj.hxx>
38 #include <tools/string.hxx>
40 using namespace ::ooo::vba
;
41 using namespace ::com::sun::star
;
43 PrivateProfileStringListener::PrivateProfileStringListener( const rtl::OUString
& rFileName
, const ByteString
& rGroupName
, const ByteString
& rKey
)
44 :maFileName( rFileName
), maGroupName( rGroupName
), maKey( rKey
)
48 PrivateProfileStringListener::~PrivateProfileStringListener()
52 void PrivateProfileStringListener::Initialize( const rtl::OUString
& rFileName
, const ByteString
& rGroupName
, const ByteString
& rKey
)
54 maFileName
= rFileName
;
55 maGroupName
= rGroupName
;
59 uno::Any
PrivateProfileStringListener::getValueEvent()
61 // get the private profile string
62 Config
aCfg( maFileName
);
63 aCfg
.SetGroup( maGroupName
);
64 rtl::OUString sValue
= String( aCfg
.ReadKey( maKey
), RTL_TEXTENCODING_DONTKNOW
);
66 return uno::makeAny( sValue
);
69 void PrivateProfileStringListener::setValueEvent( const css::uno::Any
& value
)
71 // set the private profile string
72 Config
aCfg( maFileName
);
73 aCfg
.SetGroup( maGroupName
);
77 aCfg
.WriteKey( maKey
, ByteString( aValue
.getStr(), RTL_TEXTENCODING_DONTKNOW
) );
80 SwVbaSystem::SwVbaSystem( uno::Reference
<uno::XComponentContext
>& xContext
): SwVbaSystem_BASE( uno::Reference
< XHelperInterface
>(), xContext
)
84 SwVbaSystem::~SwVbaSystem()
89 SwVbaSystem::getCursor() throw (uno::RuntimeException
)
91 sal_Int32 nPointerStyle
= getPointerStyle( getCurrentWordDoc(mxContext
) );
93 switch( nPointerStyle
)
96 return word::WdCursorType::wdCursorNorthwestArrow
;
98 return word::WdCursorType::wdCursorNormal
;
100 return word::WdCursorType::wdCursorWait
;
102 return word::WdCursorType::wdCursorIBeam
;
104 return word::WdCursorType::wdCursorNormal
;
109 SwVbaSystem::setCursor( sal_Int32 _cursor
) throw (uno::RuntimeException
)
115 case word::WdCursorType::wdCursorNorthwestArrow
:
117 const Pointer
& rPointer( POINTER_ARROW
);
118 setCursorHelper( getCurrentWordDoc(mxContext
), rPointer
, sal_False
);
121 case word::WdCursorType::wdCursorWait
:
123 const Pointer
& rPointer( static_cast< PointerStyle
>( POINTER_WAIT
) );
124 //It will set the edit window, toobar and statusbar's mouse pointer.
125 setCursorHelper( getCurrentWordDoc(mxContext
), rPointer
, sal_True
);
128 case word::WdCursorType::wdCursorIBeam
:
130 const Pointer
& rPointer( static_cast< PointerStyle
>( POINTER_TEXT
) );
131 //It will set the edit window, toobar and statusbar's mouse pointer.
132 setCursorHelper( getCurrentWordDoc( mxContext
), rPointer
, sal_True
);
135 case word::WdCursorType::wdCursorNormal
:
137 const Pointer
& rPointer( POINTER_NULL
);
138 setCursorHelper( getCurrentWordDoc( mxContext
), rPointer
, sal_False
);
142 throw uno::RuntimeException( rtl::OUString(
143 RTL_CONSTASCII_USTRINGPARAM("Unknown value for Cursor pointer")), uno::Reference
< uno::XInterface
>() );
144 // TODO: isn't this a flaw in the API? It should be allowed to throw an
145 // IllegalArgumentException, or so
148 catch( const uno::Exception
& )
150 DBG_UNHANDLED_EXCEPTION();
155 SwVbaSystem::PrivateProfileString( const rtl::OUString
& rFilename
, const rtl::OUString
& rSection
, const rtl::OUString
& rKey
) throw ( uno::RuntimeException
)
157 if( rFilename
.getLength() == 0 )
158 throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Failed to access document from shell" ) ), uno::Reference
< uno::XInterface
>() );
160 // FIXME: need to detect whether it is a relative file path
161 // we need to detect if this is a URL, if not then assume its a file path
162 rtl::OUString sFileUrl
;
164 aObj
.SetURL( rFilename
);
165 bool bIsURL
= aObj
.GetProtocol() != INET_PROT_NOT_VALID
;
167 sFileUrl
= rFilename
;
169 osl::FileBase::getFileURLFromSystemPath( rFilename
, sFileUrl
);
171 ByteString aGroupName
= ByteString( rSection
.getStr(), RTL_TEXTENCODING_DONTKNOW
);
172 ByteString aKey
= ByteString( rKey
.getStr(), RTL_TEXTENCODING_DONTKNOW
);
173 maPrivateProfileStringListener
.Initialize( sFileUrl
, aGroupName
, aKey
);
175 return uno::makeAny( uno::Reference
< XPropValue
> ( new ScVbaPropValue( &maPrivateProfileStringListener
) ) );
179 SwVbaSystem::getServiceImplName()
181 static rtl::OUString
sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaSystem") );
185 uno::Sequence
< rtl::OUString
>
186 SwVbaSystem::getServiceNames()
188 static uno::Sequence
< rtl::OUString
> aServiceNames
;
189 if ( aServiceNames
.getLength() == 0 )
191 aServiceNames
.realloc( 1 );
192 aServiceNames
[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.System" ) );
194 return aServiceNames
;