1*efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*efeef26fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*efeef26fSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*efeef26fSAndrew Rist * distributed with this work for additional information
6*efeef26fSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*efeef26fSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*efeef26fSAndrew Rist * "License"); you may not use this file except in compliance
9*efeef26fSAndrew Rist * with the License. You may obtain a copy of the License at
10*efeef26fSAndrew Rist *
11*efeef26fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*efeef26fSAndrew Rist *
13*efeef26fSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*efeef26fSAndrew Rist * software distributed under the License is distributed on an
15*efeef26fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*efeef26fSAndrew Rist * KIND, either express or implied. See the License for the
17*efeef26fSAndrew Rist * specific language governing permissions and limitations
18*efeef26fSAndrew Rist * under the License.
19*efeef26fSAndrew Rist *
20*efeef26fSAndrew Rist *************************************************************/
21*efeef26fSAndrew Rist
22*efeef26fSAndrew Rist
23cdf0e10cSrcweir #include "vbasystem.hxx"
24cdf0e10cSrcweir #include <vbahelper/vbahelper.hxx>
25cdf0e10cSrcweir #include <ooo/vba/word/WdCursorType.hpp>
26cdf0e10cSrcweir #include <tools/diagnose_ex.h>
27cdf0e10cSrcweir #include <tools/config.hxx>
28cdf0e10cSrcweir #include <tools/string.hxx>
29cdf0e10cSrcweir #include <osl/file.hxx>
30cdf0e10cSrcweir #include <tools/urlobj.hxx>
31cdf0e10cSrcweir #include <tools/string.hxx>
32cdf0e10cSrcweir
33cdf0e10cSrcweir using namespace ::ooo::vba;
34cdf0e10cSrcweir using namespace ::com::sun::star;
35cdf0e10cSrcweir
~PrivateProfileStringListener()36cdf0e10cSrcweir PrivateProfileStringListener::~PrivateProfileStringListener()
37cdf0e10cSrcweir {
38cdf0e10cSrcweir }
39cdf0e10cSrcweir
Initialize(const rtl::OUString & rFileName,const ByteString & rGroupName,const ByteString & rKey)40cdf0e10cSrcweir void PrivateProfileStringListener::Initialize( const rtl::OUString& rFileName, const ByteString& rGroupName, const ByteString& rKey )
41cdf0e10cSrcweir {
42cdf0e10cSrcweir maFileName = rFileName;
43cdf0e10cSrcweir maGroupName = rGroupName;
44cdf0e10cSrcweir maKey = rKey;
45cdf0e10cSrcweir }
46cdf0e10cSrcweir
getValueEvent()47cdf0e10cSrcweir uno::Any PrivateProfileStringListener::getValueEvent()
48cdf0e10cSrcweir {
49cdf0e10cSrcweir // get the private profile string
50cdf0e10cSrcweir Config aCfg( maFileName );
51cdf0e10cSrcweir aCfg.SetGroup( maGroupName );
52cdf0e10cSrcweir rtl::OUString sValue = String( aCfg.ReadKey( maKey ), RTL_TEXTENCODING_DONTKNOW );
53cdf0e10cSrcweir
54cdf0e10cSrcweir return uno::makeAny( sValue );
55cdf0e10cSrcweir }
56cdf0e10cSrcweir
setValueEvent(const css::uno::Any & value)57cdf0e10cSrcweir void PrivateProfileStringListener::setValueEvent( const css::uno::Any& value )
58cdf0e10cSrcweir {
59cdf0e10cSrcweir // set the private profile string
60cdf0e10cSrcweir Config aCfg( maFileName );
61cdf0e10cSrcweir aCfg.SetGroup( maGroupName );
62cdf0e10cSrcweir
63cdf0e10cSrcweir rtl::OUString aValue;
64cdf0e10cSrcweir value >>= aValue;
65cdf0e10cSrcweir aCfg.WriteKey( maKey, ByteString( aValue.getStr(), RTL_TEXTENCODING_DONTKNOW ) );
66cdf0e10cSrcweir }
67cdf0e10cSrcweir
SwVbaSystem(uno::Reference<uno::XComponentContext> & xContext)68cdf0e10cSrcweir SwVbaSystem::SwVbaSystem( uno::Reference<uno::XComponentContext >& xContext ): SwVbaSystem_BASE( uno::Reference< XHelperInterface >(), xContext )
69cdf0e10cSrcweir {
70cdf0e10cSrcweir }
71cdf0e10cSrcweir
~SwVbaSystem()72cdf0e10cSrcweir SwVbaSystem::~SwVbaSystem()
73cdf0e10cSrcweir {
74cdf0e10cSrcweir }
75cdf0e10cSrcweir
76cdf0e10cSrcweir sal_Int32 SAL_CALL
getCursor()77cdf0e10cSrcweir SwVbaSystem::getCursor() throw (uno::RuntimeException)
78cdf0e10cSrcweir {
79cdf0e10cSrcweir sal_Int32 nPointerStyle = getPointerStyle( getCurrentWordDoc(mxContext) );
80cdf0e10cSrcweir
81cdf0e10cSrcweir switch( nPointerStyle )
82cdf0e10cSrcweir {
83cdf0e10cSrcweir case POINTER_ARROW:
84cdf0e10cSrcweir return word::WdCursorType::wdCursorNorthwestArrow;
85cdf0e10cSrcweir case POINTER_NULL:
86cdf0e10cSrcweir return word::WdCursorType::wdCursorNormal;
87cdf0e10cSrcweir case POINTER_WAIT:
88cdf0e10cSrcweir return word::WdCursorType::wdCursorWait;
89cdf0e10cSrcweir case POINTER_TEXT:
90cdf0e10cSrcweir return word::WdCursorType::wdCursorIBeam;
91cdf0e10cSrcweir default:
92cdf0e10cSrcweir return word::WdCursorType::wdCursorNormal;
93cdf0e10cSrcweir }
94cdf0e10cSrcweir }
95cdf0e10cSrcweir
96cdf0e10cSrcweir void SAL_CALL
setCursor(sal_Int32 _cursor)97cdf0e10cSrcweir SwVbaSystem::setCursor( sal_Int32 _cursor ) throw (uno::RuntimeException)
98cdf0e10cSrcweir {
99cdf0e10cSrcweir try
100cdf0e10cSrcweir {
101cdf0e10cSrcweir switch( _cursor )
102cdf0e10cSrcweir {
103cdf0e10cSrcweir case word::WdCursorType::wdCursorNorthwestArrow:
104cdf0e10cSrcweir {
105cdf0e10cSrcweir const Pointer& rPointer( POINTER_ARROW );
106cdf0e10cSrcweir setCursorHelper( getCurrentWordDoc(mxContext), rPointer, sal_False );
107cdf0e10cSrcweir break;
108cdf0e10cSrcweir }
109cdf0e10cSrcweir case word::WdCursorType::wdCursorWait:
110cdf0e10cSrcweir {
111cdf0e10cSrcweir const Pointer& rPointer( static_cast< PointerStyle >( POINTER_WAIT ) );
112cdf0e10cSrcweir //It will set the edit window, toobar and statusbar's mouse pointer.
113cdf0e10cSrcweir setCursorHelper( getCurrentWordDoc(mxContext), rPointer, sal_True );
114cdf0e10cSrcweir break;
115cdf0e10cSrcweir }
116cdf0e10cSrcweir case word::WdCursorType::wdCursorIBeam:
117cdf0e10cSrcweir {
118cdf0e10cSrcweir const Pointer& rPointer( static_cast< PointerStyle >( POINTER_TEXT ) );
119cdf0e10cSrcweir //It will set the edit window, toobar and statusbar's mouse pointer.
120cdf0e10cSrcweir setCursorHelper( getCurrentWordDoc( mxContext ), rPointer, sal_True );
121cdf0e10cSrcweir break;
122cdf0e10cSrcweir }
123cdf0e10cSrcweir case word::WdCursorType::wdCursorNormal:
124cdf0e10cSrcweir {
125cdf0e10cSrcweir const Pointer& rPointer( POINTER_NULL );
126cdf0e10cSrcweir setCursorHelper( getCurrentWordDoc( mxContext ), rPointer, sal_False );
127cdf0e10cSrcweir break;
128cdf0e10cSrcweir }
129cdf0e10cSrcweir default:
130cdf0e10cSrcweir throw uno::RuntimeException( rtl::OUString(
131cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("Unknown value for Cursor pointer")), uno::Reference< uno::XInterface >() );
132cdf0e10cSrcweir // TODO: isn't this a flaw in the API? It should be allowed to throw an
133cdf0e10cSrcweir // IllegalArgumentException, or so
134cdf0e10cSrcweir }
135cdf0e10cSrcweir }
136cdf0e10cSrcweir catch( const uno::Exception& )
137cdf0e10cSrcweir {
138cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION();
139cdf0e10cSrcweir }
140cdf0e10cSrcweir }
141cdf0e10cSrcweir
142cdf0e10cSrcweir uno::Any SAL_CALL
PrivateProfileString(const rtl::OUString & rFilename,const rtl::OUString & rSection,const rtl::OUString & rKey)143cdf0e10cSrcweir SwVbaSystem::PrivateProfileString( const rtl::OUString& rFilename, const rtl::OUString& rSection, const rtl::OUString& rKey ) throw ( uno::RuntimeException )
144cdf0e10cSrcweir {
145cdf0e10cSrcweir if( rFilename.getLength() == 0 )
146cdf0e10cSrcweir throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Failed to access document from shell" ) ), uno::Reference< uno::XInterface >() );
147cdf0e10cSrcweir
148cdf0e10cSrcweir // FIXME: need to detect whether it is a relative file path
149cdf0e10cSrcweir // we need to detect if this is a URL, if not then assume its a file path
150cdf0e10cSrcweir rtl::OUString sFileUrl;
151cdf0e10cSrcweir INetURLObject aObj;
152cdf0e10cSrcweir aObj.SetURL( rFilename );
153cdf0e10cSrcweir bool bIsURL = aObj.GetProtocol() != INET_PROT_NOT_VALID;
154cdf0e10cSrcweir if ( bIsURL )
155cdf0e10cSrcweir sFileUrl = rFilename;
156cdf0e10cSrcweir else
157cdf0e10cSrcweir osl::FileBase::getFileURLFromSystemPath( rFilename, sFileUrl);
158cdf0e10cSrcweir
159cdf0e10cSrcweir ByteString aGroupName = ByteString( rSection.getStr(), RTL_TEXTENCODING_DONTKNOW);
160cdf0e10cSrcweir ByteString aKey = ByteString( rKey.getStr(), RTL_TEXTENCODING_DONTKNOW);
161cdf0e10cSrcweir maPrivateProfileStringListener.Initialize( sFileUrl, aGroupName, aKey );
162cdf0e10cSrcweir
163cdf0e10cSrcweir return uno::makeAny( uno::Reference< XPropValue > ( new ScVbaPropValue( &maPrivateProfileStringListener ) ) );
164cdf0e10cSrcweir }
165cdf0e10cSrcweir
166cdf0e10cSrcweir rtl::OUString&
getServiceImplName()167cdf0e10cSrcweir SwVbaSystem::getServiceImplName()
168cdf0e10cSrcweir {
169cdf0e10cSrcweir static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaSystem") );
170cdf0e10cSrcweir return sImplName;
171cdf0e10cSrcweir }
172cdf0e10cSrcweir
173cdf0e10cSrcweir uno::Sequence< rtl::OUString >
getServiceNames()174cdf0e10cSrcweir SwVbaSystem::getServiceNames()
175cdf0e10cSrcweir {
176cdf0e10cSrcweir static uno::Sequence< rtl::OUString > aServiceNames;
177cdf0e10cSrcweir if ( aServiceNames.getLength() == 0 )
178cdf0e10cSrcweir {
179cdf0e10cSrcweir aServiceNames.realloc( 1 );
180cdf0e10cSrcweir aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.System" ) );
181cdf0e10cSrcweir }
182cdf0e10cSrcweir return aServiceNames;
183cdf0e10cSrcweir }
184