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