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