xref: /aoo41x/main/sw/source/ui/vba/vbaapplication.cxx (revision cdf0e10c)
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 <stdio.h>
28*cdf0e10cSrcweir #include "vbaapplication.hxx"
29*cdf0e10cSrcweir #include "vbadocument.hxx"
30*cdf0e10cSrcweir #include <osl/file.hxx>
31*cdf0e10cSrcweir #include <vbahelper/vbahelper.hxx>
32*cdf0e10cSrcweir #include "vbawindow.hxx"
33*cdf0e10cSrcweir #include "vbasystem.hxx"
34*cdf0e10cSrcweir #include "vbaoptions.hxx"
35*cdf0e10cSrcweir #include "vbaselection.hxx"
36*cdf0e10cSrcweir #include "vbadocuments.hxx"
37*cdf0e10cSrcweir #include "vbaaddins.hxx"
38*cdf0e10cSrcweir #include "vbadialogs.hxx"
39*cdf0e10cSrcweir #include <ooo/vba/word/WdEnableCancelKey.hpp>
40*cdf0e10cSrcweir #include <editeng/acorrcfg.hxx>
41*cdf0e10cSrcweir #include "wordvbahelper.hxx"
42*cdf0e10cSrcweir #include <docsh.hxx>
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir using namespace ::ooo;
45*cdf0e10cSrcweir using namespace ::ooo::vba;
46*cdf0e10cSrcweir using namespace ::com::sun::star;
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
49*cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY_THROW;
50*cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY;
51*cdf0e10cSrcweir using ::rtl::OUString;
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir // Enable our own join detection for Intersection and Union
54*cdf0e10cSrcweir // should be more efficient than using ScRangeList::Join ( because
55*cdf0e10cSrcweir // we already are testing the same things )
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir #define OWN_JOIN 1
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir // #TODO is this defined somewhere else?
60*cdf0e10cSrcweir #if ( defined UNX ) || ( defined OS2 ) //unix
61*cdf0e10cSrcweir #define FILE_PATH_SEPERATOR "/"
62*cdf0e10cSrcweir #else // windows
63*cdf0e10cSrcweir #define FILE_PATH_SEPERATOR "\\"
64*cdf0e10cSrcweir #endif
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir #define EXCELVERSION "11.0"
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir uno::Any sbxToUnoValue( SbxVariable* pVar );
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir SwVbaApplication::SwVbaApplication( uno::Reference<uno::XComponentContext >& xContext ): SwVbaApplication_BASE( xContext )
71*cdf0e10cSrcweir {
72*cdf0e10cSrcweir }
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir SwVbaApplication::~SwVbaApplication()
75*cdf0e10cSrcweir {
76*cdf0e10cSrcweir }
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir SfxObjectShell* SwVbaApplication::GetDocShell( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException)
79*cdf0e10cSrcweir {
80*cdf0e10cSrcweir     return static_cast< SfxObjectShell* >( word::getDocShell( xModel ) );
81*cdf0e10cSrcweir }
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir rtl::OUString SAL_CALL
84*cdf0e10cSrcweir SwVbaApplication::getName() throw (uno::RuntimeException)
85*cdf0e10cSrcweir {
86*cdf0e10cSrcweir     static rtl::OUString appName( RTL_CONSTASCII_USTRINGPARAM("Microsoft Word" ) );
87*cdf0e10cSrcweir     return appName;
88*cdf0e10cSrcweir }
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir uno::Reference< word::XDocument > SAL_CALL
91*cdf0e10cSrcweir SwVbaApplication::getActiveDocument() throw (uno::RuntimeException)
92*cdf0e10cSrcweir {
93*cdf0e10cSrcweir     return new SwVbaDocument( this, mxContext, getCurrentDocument() );
94*cdf0e10cSrcweir }
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir uno::Reference< word::XWindow > SAL_CALL
97*cdf0e10cSrcweir SwVbaApplication::getActiveWindow() throw (uno::RuntimeException)
98*cdf0e10cSrcweir {
99*cdf0e10cSrcweir 	// #FIXME sofar can't determine Parent
100*cdf0e10cSrcweir 	uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_SET_THROW );
101*cdf0e10cSrcweir 	uno::Reference< frame::XController > xController( xModel->getCurrentController(), uno::UNO_SET_THROW );
102*cdf0e10cSrcweir 	return new SwVbaWindow( uno::Reference< XHelperInterface >(), mxContext, xModel, xController );
103*cdf0e10cSrcweir }
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir uno::Reference<word::XSystem > SAL_CALL
106*cdf0e10cSrcweir SwVbaApplication::getSystem() throw (uno::RuntimeException)
107*cdf0e10cSrcweir {
108*cdf0e10cSrcweir     return uno::Reference< word::XSystem >( new SwVbaSystem( mxContext ) );
109*cdf0e10cSrcweir }
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir uno::Reference<word::XOptions > SAL_CALL
112*cdf0e10cSrcweir SwVbaApplication::getOptions() throw (uno::RuntimeException)
113*cdf0e10cSrcweir {
114*cdf0e10cSrcweir     return uno::Reference< word::XOptions >( new SwVbaOptions( mxContext ) );
115*cdf0e10cSrcweir }
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir uno::Any SAL_CALL
118*cdf0e10cSrcweir SwVbaApplication::CommandBars( const uno::Any& aIndex ) throw (uno::RuntimeException)
119*cdf0e10cSrcweir {
120*cdf0e10cSrcweir     return VbaApplicationBase::CommandBars( aIndex );
121*cdf0e10cSrcweir }
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir uno::Reference< word::XSelection > SAL_CALL
124*cdf0e10cSrcweir SwVbaApplication::getSelection() throw (uno::RuntimeException)
125*cdf0e10cSrcweir {
126*cdf0e10cSrcweir     return new SwVbaSelection( this, mxContext, getCurrentDocument() );
127*cdf0e10cSrcweir }
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir uno::Any SAL_CALL
130*cdf0e10cSrcweir SwVbaApplication::Documents( const uno::Any& index ) throw (uno::RuntimeException)
131*cdf0e10cSrcweir {
132*cdf0e10cSrcweir     uno::Reference< XCollection > xCol( new SwVbaDocuments( this, mxContext ) );
133*cdf0e10cSrcweir     if ( index.hasValue() )
134*cdf0e10cSrcweir         return xCol->Item( index, uno::Any() );
135*cdf0e10cSrcweir     return uno::makeAny( xCol );
136*cdf0e10cSrcweir }
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir uno::Any SAL_CALL
139*cdf0e10cSrcweir SwVbaApplication::Addins( const uno::Any& index ) throw (uno::RuntimeException)
140*cdf0e10cSrcweir {
141*cdf0e10cSrcweir     static uno::Reference< XCollection > xCol( new SwVbaAddins( this, mxContext ) );
142*cdf0e10cSrcweir     if ( index.hasValue() )
143*cdf0e10cSrcweir         return xCol->Item( index, uno::Any() );
144*cdf0e10cSrcweir     return uno::makeAny( xCol );
145*cdf0e10cSrcweir }
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir uno::Any SAL_CALL
148*cdf0e10cSrcweir SwVbaApplication::Dialogs( const uno::Any& index ) throw (uno::RuntimeException)
149*cdf0e10cSrcweir {
150*cdf0e10cSrcweir     uno::Reference< word::XDialogs > xCol( new SwVbaDialogs( this, mxContext, getCurrentDocument() ));
151*cdf0e10cSrcweir     if ( index.hasValue() )
152*cdf0e10cSrcweir         return xCol->Item( index );
153*cdf0e10cSrcweir     return uno::makeAny( xCol );
154*cdf0e10cSrcweir }
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir sal_Bool SAL_CALL SwVbaApplication::getDisplayAutoCompleteTips() throw (css::uno::RuntimeException)
157*cdf0e10cSrcweir {
158*cdf0e10cSrcweir     return SvxAutoCorrCfg::Get()->IsAutoTextTip();
159*cdf0e10cSrcweir }
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir void SAL_CALL SwVbaApplication::setDisplayAutoCompleteTips( sal_Bool _displayAutoCompleteTips ) throw (css::uno::RuntimeException)
162*cdf0e10cSrcweir {
163*cdf0e10cSrcweir     SvxAutoCorrCfg::Get()->SetAutoTextTip( _displayAutoCompleteTips );
164*cdf0e10cSrcweir }
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir sal_Int32 SAL_CALL SwVbaApplication::getEnableCancelKey() throw (css::uno::RuntimeException)
167*cdf0e10cSrcweir {
168*cdf0e10cSrcweir     // the default value is wdCancelInterrupt in Word
169*cdf0e10cSrcweir     return word::WdEnableCancelKey::wdCancelInterrupt;
170*cdf0e10cSrcweir }
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir void SAL_CALL SwVbaApplication::setEnableCancelKey( sal_Int32/* _enableCancelKey */) throw (css::uno::RuntimeException)
173*cdf0e10cSrcweir {
174*cdf0e10cSrcweir     // seems not supported in Writer
175*cdf0e10cSrcweir }
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir float SAL_CALL SwVbaApplication::CentimetersToPoints( float _Centimeters ) throw (uno::RuntimeException)
178*cdf0e10cSrcweir {
179*cdf0e10cSrcweir     return VbaApplicationBase::CentimetersToPoints( _Centimeters );
180*cdf0e10cSrcweir }
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir uno::Reference< frame::XModel >
183*cdf0e10cSrcweir SwVbaApplication::getCurrentDocument() throw (css::uno::RuntimeException)
184*cdf0e10cSrcweir {
185*cdf0e10cSrcweir     return getCurrentWordDoc( mxContext );
186*cdf0e10cSrcweir }
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir rtl::OUString&
189*cdf0e10cSrcweir SwVbaApplication::getServiceImplName()
190*cdf0e10cSrcweir {
191*cdf0e10cSrcweir 	static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaApplication") );
192*cdf0e10cSrcweir 	return sImplName;
193*cdf0e10cSrcweir }
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir uno::Sequence< rtl::OUString >
196*cdf0e10cSrcweir SwVbaApplication::getServiceNames()
197*cdf0e10cSrcweir {
198*cdf0e10cSrcweir 	static uno::Sequence< rtl::OUString > aServiceNames;
199*cdf0e10cSrcweir 	if ( aServiceNames.getLength() == 0 )
200*cdf0e10cSrcweir 	{
201*cdf0e10cSrcweir 		aServiceNames.realloc( 1 );
202*cdf0e10cSrcweir 		aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Application" ) );
203*cdf0e10cSrcweir 	}
204*cdf0e10cSrcweir 	return aServiceNames;
205*cdf0e10cSrcweir }
206