xref: /aoo4110/main/sc/inc/miscuno.hxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SC_MISCUNO_HXX
25 #define SC_MISCUNO_HXX
26 
27 #include <com/sun/star/lang/XServiceInfo.hpp>
28 #include <com/sun/star/beans/XPropertySet.hpp>
29 #include <com/sun/star/container/XEnumerationAccess.hpp>
30 #include <com/sun/star/container/XNameAccess.hpp>
31 #include <com/sun/star/container/XEnumeration.hpp>
32 #include <com/sun/star/container/XIndexAccess.hpp>
33 #include <cppuhelper/implbase2.hxx>
34 #include "scdllapi.h"
35 
36 #define SC_SIMPLE_SERVICE_INFO( ClassName, ClassNameAscii, ServiceAscii )			 \
37 ::rtl::OUString SAL_CALL ClassName::getImplementationName()						 \
38 	throw(::com::sun::star::uno::RuntimeException)									 \
39 {																					 \
40 	return ::rtl::OUString::createFromAscii(ClassNameAscii);						 \
41 }																					 \
42 sal_Bool SAL_CALL ClassName::supportsService( const ::rtl::OUString& ServiceName ) \
43 	throw(::com::sun::star::uno::RuntimeException)									 \
44 {																					 \
45 	return !ServiceName.compareToAscii(ServiceAscii);								 \
46 }																					 \
47 ::com::sun::star::uno::Sequence< ::rtl::OUString >									 \
48 	SAL_CALL ClassName::getSupportedServiceNames(void)							 \
49 	throw(::com::sun::star::uno::RuntimeException)									 \
50 {																					 \
51 	::com::sun::star::uno::Sequence< ::rtl::OUString > aRet(1);						 \
52 	::rtl::OUString* pArray = aRet.getArray();										 \
53 	pArray[0] = ::rtl::OUString::createFromAscii(ServiceAscii);					 \
54 	return aRet;																	 \
55 }
56 
57 #define SC_IMPL_DUMMY_PROPERTY_LISTENER( ClassName )								\
58 	void SAL_CALL ClassName::addPropertyChangeListener( const rtl::OUString&,		\
59 							const uno::Reference<beans::XPropertyChangeListener>&)	\
60 							throw(beans::UnknownPropertyException,					\
61 							lang::WrappedTargetException, uno::RuntimeException)	\
62 	{ DBG_ERROR("not implemented"); }												\
63 	void SAL_CALL ClassName::removePropertyChangeListener( const rtl::OUString&,	\
64 							const uno::Reference<beans::XPropertyChangeListener>&)	\
65 							throw(beans::UnknownPropertyException,					\
66 							lang::WrappedTargetException, uno::RuntimeException)	\
67 	{ DBG_ERROR("not implemented"); }												\
68 	void SAL_CALL ClassName::addVetoableChangeListener( const rtl::OUString&,		\
69 							const uno::Reference<beans::XVetoableChangeListener>&)	\
70 							throw(beans::UnknownPropertyException,					\
71 							lang::WrappedTargetException, uno::RuntimeException)	\
72 	{ DBG_ERROR("not implemented"); }												\
73 	void SAL_CALL ClassName::removeVetoableChangeListener( const rtl::OUString&,	\
74 							const uno::Reference<beans::XVetoableChangeListener>&)	\
75 							throw(beans::UnknownPropertyException,					\
76 							lang::WrappedTargetException, uno::RuntimeException)	\
77 	{ DBG_ERROR("not implemented"); }
78 
79 
80 #define SC_QUERYINTERFACE(x)	\
81 	if (rType == getCppuType((const uno::Reference<x>*)0))	\
82     { return uno::makeAny(uno::Reference<x>(this)); }
83 
84 // SC_QUERY_MULTIPLE( XElementAccess, XIndexAccess ):
85 //	use if interface is used several times in one class
86 
87 #define SC_QUERY_MULTIPLE(x,y)	\
88 	if (rType == getCppuType((const uno::Reference<x>*)0))	\
89 	{ uno::Any aR; aR <<= uno::Reference<x>(static_cast<y*>(this)); return aR; }
90 
91 
92 class ScIndexEnumeration : public cppu::WeakImplHelper2<
93 								com::sun::star::container::XEnumeration,
94 								com::sun::star::lang::XServiceInfo >
95 {
96 private:
97 	com::sun::star::uno::Reference<com::sun::star::container::XIndexAccess> xIndex;
98     rtl::OUString           sServiceName;
99 	sal_Int32				nPos;
100 
101 public:
102 							ScIndexEnumeration(const com::sun::star::uno::Reference<
103                                 com::sun::star::container::XIndexAccess>& rInd, const rtl::OUString& rServiceName);
104 	virtual					~ScIndexEnumeration();
105 
106 							// XEnumeration
107 	virtual sal_Bool SAL_CALL hasMoreElements() throw(::com::sun::star::uno::RuntimeException);
108 	virtual ::com::sun::star::uno::Any SAL_CALL nextElement()
109 								throw(::com::sun::star::container::NoSuchElementException,
110 										::com::sun::star::lang::WrappedTargetException,
111 										::com::sun::star::uno::RuntimeException);
112 
113 							// XServiceInfo
114 	virtual ::rtl::OUString SAL_CALL getImplementationName(  )
115 								throw(::com::sun::star::uno::RuntimeException);
116 	virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
117 								throw(::com::sun::star::uno::RuntimeException);
118 	virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  )
119 								throw(::com::sun::star::uno::RuntimeException);
120 };
121 
122 //UNUSED2008-05  class ScEmptyEnumerationAccess : public cppu::WeakImplHelper2<
123 //UNUSED2008-05                                  com::sun::star::container::XEnumerationAccess,
124 //UNUSED2008-05                                  com::sun::star::lang::XServiceInfo >
125 //UNUSED2008-05  {
126 //UNUSED2008-05  public:
127 //UNUSED2008-05                              ScEmptyEnumerationAccess();
128 //UNUSED2008-05      virtual                 ~ScEmptyEnumerationAccess();
129 //UNUSED2008-05
130 //UNUSED2008-05                              // XEnumerationAccess
131 //UNUSED2008-05      virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL
132 //UNUSED2008-05                              createEnumeration() throw(::com::sun::star::uno::RuntimeException);
133 //UNUSED2008-05
134 //UNUSED2008-05                              // XElementAccess
135 //UNUSED2008-05      virtual ::com::sun::star::uno::Type SAL_CALL getElementType()
136 //UNUSED2008-05                                  throw(::com::sun::star::uno::RuntimeException);
137 //UNUSED2008-05      virtual sal_Bool SAL_CALL hasElements() throw(::com::sun::star::uno::RuntimeException);
138 //UNUSED2008-05
139 //UNUSED2008-05                              // XServiceInfo
140 //UNUSED2008-05      virtual ::rtl::OUString SAL_CALL getImplementationName(  )
141 //UNUSED2008-05                                  throw(::com::sun::star::uno::RuntimeException);
142 //UNUSED2008-05      virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
143 //UNUSED2008-05                                  throw(::com::sun::star::uno::RuntimeException);
144 //UNUSED2008-05      virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  )
145 //UNUSED2008-05                                  throw(::com::sun::star::uno::RuntimeException);
146 //UNUSED2008-05  };
147 
148 //UNUSED2008-05  class ScEmptyEnumeration : public cppu::WeakImplHelper2<
149 //UNUSED2008-05                                  com::sun::star::container::XEnumeration,
150 //UNUSED2008-05                                  com::sun::star::lang::XServiceInfo >
151 //UNUSED2008-05  {
152 //UNUSED2008-05  public:
153 //UNUSED2008-05                              ScEmptyEnumeration();
154 //UNUSED2008-05      virtual                 ~ScEmptyEnumeration();
155 //UNUSED2008-05
156 //UNUSED2008-05                              // XEnumeration
157 //UNUSED2008-05      virtual sal_Bool SAL_CALL hasMoreElements() throw(::com::sun::star::uno::RuntimeException);
158 //UNUSED2008-05      virtual ::com::sun::star::uno::Any SAL_CALL nextElement()
159 //UNUSED2008-05                                  throw(::com::sun::star::container::NoSuchElementException,
160 //UNUSED2008-05                                          ::com::sun::star::lang::WrappedTargetException,
161 //UNUSED2008-05                                          ::com::sun::star::uno::RuntimeException);
162 //UNUSED2008-05
163 //UNUSED2008-05                              // XServiceInfo
164 //UNUSED2008-05      virtual ::rtl::OUString SAL_CALL getImplementationName(  )
165 //UNUSED2008-05                                  throw(::com::sun::star::uno::RuntimeException);
166 //UNUSED2008-05      virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
167 //UNUSED2008-05                                  throw(::com::sun::star::uno::RuntimeException);
168 //UNUSED2008-05      virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  )
169 //UNUSED2008-05                                  throw(::com::sun::star::uno::RuntimeException);
170 //UNUSED2008-05  };
171 
172 //	new (uno 3) variant
173 class ScNameToIndexAccess : public cppu::WeakImplHelper2<
174 								com::sun::star::container::XIndexAccess,
175 								com::sun::star::lang::XServiceInfo >
176 {
177 private:
178 	com::sun::star::uno::Reference<com::sun::star::container::XNameAccess> xNameAccess;
179 	com::sun::star::uno::Sequence<rtl::OUString> aNames;
180 
181 public:
182 							ScNameToIndexAccess(
183 								const com::sun::star::uno::Reference<
184 									com::sun::star::container::XNameAccess>& rNameObj );
185 	virtual					~ScNameToIndexAccess();
186 
187 							// XIndexAccess
188 	virtual sal_Int32 SAL_CALL getCount(  ) throw(::com::sun::star::uno::RuntimeException);
189 	virtual ::com::sun::star::uno::Any SAL_CALL getByIndex( sal_Int32 Index )
190 								throw(::com::sun::star::lang::IndexOutOfBoundsException,
191 										::com::sun::star::lang::WrappedTargetException,
192 										::com::sun::star::uno::RuntimeException);
193 
194 							// XElementAccess
195 	virtual ::com::sun::star::uno::Type SAL_CALL getElementType(  )
196 								throw(::com::sun::star::uno::RuntimeException);
197 	virtual sal_Bool SAL_CALL hasElements(  ) throw(::com::sun::star::uno::RuntimeException);
198 
199 							// XServiceInfo
200 	virtual ::rtl::OUString SAL_CALL getImplementationName(  )
201 								throw(::com::sun::star::uno::RuntimeException);
202 	virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
203 								throw(::com::sun::star::uno::RuntimeException);
204 	virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  )
205 								throw(::com::sun::star::uno::RuntimeException);
206 };
207 
208 //UNUSED2008-05  class ScPrintSettingsObj : public cppu::WeakImplHelper2<
209 //UNUSED2008-05                                  com::sun::star::beans::XPropertySet,
210 //UNUSED2008-05                                  com::sun::star::lang::XServiceInfo >
211 //UNUSED2008-05  {
212 //UNUSED2008-05  public:
213 //UNUSED2008-05                              ScPrintSettingsObj();
214 //UNUSED2008-05      virtual                 ~ScPrintSettingsObj();
215 //UNUSED2008-05
216 //UNUSED2008-05                              // XPropertySet
217 //UNUSED2008-05      virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo >
218 //UNUSED2008-05                              SAL_CALL getPropertySetInfo()
219 //UNUSED2008-05                                  throw(::com::sun::star::uno::RuntimeException);
220 //UNUSED2008-05      virtual void SAL_CALL   setPropertyValue( const ::rtl::OUString& aPropertyName,
221 //UNUSED2008-05                                      const ::com::sun::star::uno::Any& aValue )
222 //UNUSED2008-05                                  throw(::com::sun::star::beans::UnknownPropertyException,
223 //UNUSED2008-05                                      ::com::sun::star::beans::PropertyVetoException,
224 //UNUSED2008-05                                      ::com::sun::star::lang::IllegalArgumentException,
225 //UNUSED2008-05                                      ::com::sun::star::lang::WrappedTargetException,
226 //UNUSED2008-05                                      ::com::sun::star::uno::RuntimeException);
227 //UNUSED2008-05      virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue(
228 //UNUSED2008-05                                      const ::rtl::OUString& PropertyName )
229 //UNUSED2008-05                                  throw(::com::sun::star::beans::UnknownPropertyException,
230 //UNUSED2008-05                                      ::com::sun::star::lang::WrappedTargetException,
231 //UNUSED2008-05                                      ::com::sun::star::uno::RuntimeException);
232 //UNUSED2008-05      virtual void SAL_CALL   addPropertyChangeListener( const ::rtl::OUString& aPropertyName,
233 //UNUSED2008-05                                      const ::com::sun::star::uno::Reference<
234 //UNUSED2008-05                                          ::com::sun::star::beans::XPropertyChangeListener >& xListener )
235 //UNUSED2008-05                                  throw(::com::sun::star::beans::UnknownPropertyException,
236 //UNUSED2008-05                                      ::com::sun::star::lang::WrappedTargetException,
237 //UNUSED2008-05                                      ::com::sun::star::uno::RuntimeException);
238 //UNUSED2008-05      virtual void SAL_CALL   removePropertyChangeListener( const ::rtl::OUString& aPropertyName,
239 //UNUSED2008-05                                      const ::com::sun::star::uno::Reference<
240 //UNUSED2008-05                                          ::com::sun::star::beans::XPropertyChangeListener >& aListener )
241 //UNUSED2008-05                                  throw(::com::sun::star::beans::UnknownPropertyException,
242 //UNUSED2008-05                                      ::com::sun::star::lang::WrappedTargetException,
243 //UNUSED2008-05                                      ::com::sun::star::uno::RuntimeException);
244 //UNUSED2008-05      virtual void SAL_CALL   addVetoableChangeListener( const ::rtl::OUString& PropertyName,
245 //UNUSED2008-05                                      const ::com::sun::star::uno::Reference<
246 //UNUSED2008-05                                          ::com::sun::star::beans::XVetoableChangeListener >& aListener )
247 //UNUSED2008-05                                  throw(::com::sun::star::beans::UnknownPropertyException,
248 //UNUSED2008-05                                      ::com::sun::star::lang::WrappedTargetException,
249 //UNUSED2008-05                                      ::com::sun::star::uno::RuntimeException);
250 //UNUSED2008-05      virtual void SAL_CALL   removeVetoableChangeListener( const ::rtl::OUString& PropertyName,
251 //UNUSED2008-05                                      const ::com::sun::star::uno::Reference<
252 //UNUSED2008-05                                          ::com::sun::star::beans::XVetoableChangeListener >& aListener )
253 //UNUSED2008-05                                  throw(::com::sun::star::beans::UnknownPropertyException,
254 //UNUSED2008-05                                      ::com::sun::star::lang::WrappedTargetException,
255 //UNUSED2008-05                                      ::com::sun::star::uno::RuntimeException);
256 //UNUSED2008-05
257 //UNUSED2008-05                              // XServiceInfo
258 //UNUSED2008-05      virtual ::rtl::OUString SAL_CALL getImplementationName(  )
259 //UNUSED2008-05                                  throw(::com::sun::star::uno::RuntimeException);
260 //UNUSED2008-05      virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
261 //UNUSED2008-05                                  throw(::com::sun::star::uno::RuntimeException);
262 //UNUSED2008-05      virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  )
263 //UNUSED2008-05                                  throw(::com::sun::star::uno::RuntimeException);
264 //UNUSED2008-05  };
265 
266 
267 class SC_DLLPUBLIC ScUnoHelpFunctions
268 {
269 public:
270 	static com::sun::star::uno::Reference<com::sun::star::uno::XInterface>
271 							AnyToInterface( const com::sun::star::uno::Any& rAny );
272 	static sal_Bool			GetBoolProperty( const com::sun::star::uno::Reference<
273 												com::sun::star::beans::XPropertySet>& xProp,
274 											const ::rtl::OUString& rName, sal_Bool bDefault = sal_False );
275 	static sal_Int32		GetLongProperty( const com::sun::star::uno::Reference<
276 												com::sun::star::beans::XPropertySet>& xProp,
277 											const ::rtl::OUString& rName, long nDefault = 0 );
278 	static sal_Int32		GetEnumProperty( const com::sun::star::uno::Reference<
279 												com::sun::star::beans::XPropertySet>& xProp,
280 											const ::rtl::OUString& rName, long nDefault );
281     static ::rtl::OUString  GetStringProperty(
282         const com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet>& xProp,
283         const ::rtl::OUString& rName, const ::rtl::OUString& rDefault );
284 
285 	static sal_Bool			GetBoolFromAny( const com::sun::star::uno::Any& aAny );
286 	static sal_Int16		GetInt16FromAny( const com::sun::star::uno::Any& aAny );
287 	static sal_Int32		GetInt32FromAny( const com::sun::star::uno::Any& aAny );
288 	static sal_Int32		GetEnumFromAny( const com::sun::star::uno::Any& aAny );
289 	static void				SetBoolInAny( com::sun::star::uno::Any& rAny, sal_Bool bValue );
290 
291     static void             SetOptionalPropertyValue(
292         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& rPropSet,
293         const sal_Char* pPropName, const ::com::sun::star::uno::Any& rVal );
294 
295     template<typename ValueType>
SetOptionalPropertyValue(::com::sun::star::uno::Reference<::com::sun::star::beans::XPropertySet> & rPropSet,const sal_Char * pPropName,const ValueType & rVal)296     static void             SetOptionalPropertyValue(
297         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& rPropSet,
298         const sal_Char* pPropName, const ValueType& rVal )
299     {
300         ::com::sun::star::uno::Any any;
301         any <<= rVal;
302         SetOptionalPropertyValue(rPropSet, pPropName, any);
303     }
304 };
305 
306 
307 
308 #endif
309 
310