xref: /aoo42x/main/sw/source/ui/vba/vbaglobals.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #include <vbahelper/helperdecl.hxx>
28 #include "vbaglobals.hxx"
29 
30 #include <comphelper/unwrapargs.hxx>
31 
32 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
33 #include <com/sun/star/beans/XPropertySet.hpp>
34 #include <com/sun/star/container/XNameContainer.hpp>
35 #include <cppuhelper/bootstrap.hxx>
36 #include "vbaapplication.hxx"
37 using namespace ::com::sun::star;
38 using namespace ::com::sun::star::uno;
39 using namespace ::ooo::vba;
40 
41 
42 rtl::OUString sDocCtxName( RTL_CONSTASCII_USTRINGPARAM("WordDocumentContext") );
43 
44 // =============================================================================
45 // SwVbaGlobals
46 // =============================================================================
47 
48 SwVbaGlobals::SwVbaGlobals(  uno::Sequence< uno::Any > const& aArgs, uno::Reference< uno::XComponentContext >const& rxContext ) : SwVbaGlobals_BASE( uno::Reference< XHelperInterface >(), rxContext, sDocCtxName )
49 {
50 	OSL_TRACE("SwVbaGlobals::SwVbaGlobals()");
51         uno::Sequence< beans::PropertyValue > aInitArgs( 2 );
52         aInitArgs[ 0 ].Name = rtl::OUString::createFromAscii("Application");
53         aInitArgs[ 0 ].Value = uno::makeAny( getApplication() );
54         aInitArgs[ 1 ].Name = sDocCtxName;
55         aInitArgs[ 1 ].Value = uno::makeAny( getXSomethingFromArgs< frame::XModel >( aArgs, 0 ) );
56 
57         init( aInitArgs );
58 }
59 
60 SwVbaGlobals::~SwVbaGlobals()
61 {
62 	OSL_TRACE("SwVbaGlobals::~SwVbaGlobals");
63 }
64 
65 // =============================================================================
66 // XGlobals
67 // =============================================================================
68 uno::Reference<word::XApplication >
69 SwVbaGlobals::getApplication() throw (uno::RuntimeException)
70 {
71 	OSL_TRACE("In SwVbaGlobals::getApplication");
72 	if ( !mxApplication.is() )
73 		 mxApplication.set( new SwVbaApplication( mxContext) );
74 
75    	return mxApplication;
76 }
77 
78 uno::Reference<word::XSystem > SAL_CALL
79 SwVbaGlobals::getSystem() throw (uno::RuntimeException)
80 {
81 	return getApplication()->getSystem();
82 }
83 
84 uno::Reference< word::XDocument > SAL_CALL
85 SwVbaGlobals::getActiveDocument() throw (uno::RuntimeException)
86 {
87 	return getApplication()->getActiveDocument();
88 }
89 
90 uno::Reference< word::XWindow > SAL_CALL
91 SwVbaGlobals::getActiveWindow() throw (uno::RuntimeException)
92 {
93 	return getApplication()->getActiveWindow();
94 }
95 
96 rtl::OUString SAL_CALL
97 SwVbaGlobals::getName() throw (uno::RuntimeException)
98 {
99 	return getApplication()->getName();
100 }
101 
102 uno::Reference<word::XOptions > SAL_CALL
103 SwVbaGlobals::getOptions() throw (uno::RuntimeException)
104 {
105 	return getApplication()->getOptions();
106 }
107 
108 uno::Any SAL_CALL
109 SwVbaGlobals::CommandBars( const uno::Any& aIndex ) throw (uno::RuntimeException)
110 {
111     return getApplication()->CommandBars( aIndex );
112 }
113 
114 uno::Any SAL_CALL
115 SwVbaGlobals::Documents( const uno::Any& index ) throw (uno::RuntimeException)
116 {
117     return getApplication()->Documents( index );
118 }
119 
120 uno::Any SAL_CALL
121 SwVbaGlobals::Addins( const uno::Any& index ) throw (uno::RuntimeException)
122 {
123     return getApplication()->Addins( index );
124 }
125 
126 uno::Any SAL_CALL
127 SwVbaGlobals::Dialogs( const uno::Any& index ) throw (uno::RuntimeException)
128 {
129     return getApplication()->Dialogs( index );
130 }
131 
132 uno::Reference<word::XSelection > SAL_CALL
133 SwVbaGlobals::getSelection() throw (uno::RuntimeException)
134 {
135 	return getApplication()->getSelection();
136 }
137 
138 float SAL_CALL SwVbaGlobals::CentimetersToPoints( float _Centimeters ) throw (uno::RuntimeException)
139 {
140     return getApplication()->CentimetersToPoints( _Centimeters );
141 }
142 
143 rtl::OUString&
144 SwVbaGlobals::getServiceImplName()
145 {
146         static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaGlobals") );
147         return sImplName;
148 }
149 
150 uno::Sequence< rtl::OUString >
151 SwVbaGlobals::getServiceNames()
152 {
153         static uno::Sequence< rtl::OUString > aServiceNames;
154         if ( aServiceNames.getLength() == 0 )
155         {
156                 aServiceNames.realloc( 1 );
157                 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Globals" ) );
158         }
159         return aServiceNames;
160 }
161 
162 uno::Sequence< rtl::OUString >
163 SwVbaGlobals::getAvailableServiceNames(  ) throw (uno::RuntimeException)
164 {
165     static bool bInit = false;
166     static uno::Sequence< rtl::OUString > serviceNames( SwVbaGlobals_BASE::getAvailableServiceNames() );
167     if ( !bInit )
168     {
169          rtl::OUString names[] = {
170             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "ooo.vba.word.Document" ) ),
171 //            #FIXME #TODO make Application a proper service
172 //            ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "ooo.vba.word.Application" ) ),
173         };
174         sal_Int32 nWordServices = ( sizeof( names )/ sizeof( names[0] ) );
175         sal_Int32 startIndex = serviceNames.getLength();
176         serviceNames.realloc( serviceNames.getLength() + nWordServices );
177         for ( sal_Int32 index = 0; index < nWordServices; ++index )
178              serviceNames[ startIndex + index ] = names[ index ];
179         bInit = true;
180     }
181     return serviceNames;
182 }
183 
184 namespace globals
185 {
186 namespace sdecl = comphelper::service_decl;
187 sdecl::vba_service_class_<SwVbaGlobals, sdecl::with_args<true> > serviceImpl;
188 extern sdecl::ServiceDecl const serviceDecl(
189     serviceImpl,
190     "SwVbaGlobals",
191     "ooo.vba.word.Globals" );
192 }
193 
194