LibreOffice Module sc (master)  1
miscuno.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #ifndef INCLUDED_SC_INC_MISCUNO_HXX
21 #define INCLUDED_SC_INC_MISCUNO_HXX
22 
23 #include <vector>
24 
25 #include <com/sun/star/lang/XServiceInfo.hpp>
26 #include <com/sun/star/beans/XPropertySet.hpp>
27 #include <com/sun/star/container/XNameAccess.hpp>
28 #include <com/sun/star/container/XEnumeration.hpp>
29 #include <com/sun/star/container/XIndexAccess.hpp>
30 #include <cppuhelper/implbase.hxx>
32 #include <osl/diagnose.h>
33 #include "scdllapi.h"
34 
35 #define SC_SIMPLE_SERVICE_INFO_IMPL( ClassName, ClassNameAscii ) \
36 OUString SAL_CALL ClassName::getImplementationName() \
37 { \
38  return ClassNameAscii; \
39 } \
40 sal_Bool SAL_CALL ClassName::supportsService( const OUString& ServiceName ) \
41 { \
42  return cppu::supportsService(this, ServiceName); \
43 }
44 
45 #define SC_SIMPLE_SERVICE_INFO_NAME( ClassName, ServiceAscii ) \
46 css::uno::Sequence< OUString > \
47  SAL_CALL ClassName::getSupportedServiceNames() \
48 { \
49  css::uno::Sequence< OUString > aRet { ServiceAscii }; \
50  return aRet; \
51 }
52 
53 // Place the old mistyped variant as first element so existing code can
54 // continue to ask aRet[0] if it doesn't iterate; new code can iterate over the
55 // sequence. This mostly should be used by supportsService() iterating anyway.
56 #define SC_SIMPLE_SERVICE_INFO_TYPO( ClassName, ServiceAscii, ServiceAsciiMistyped ) \
57 css::uno::Sequence< OUString > \
58  SAL_CALL ClassName::getSupportedServiceNames() \
59 { \
60  css::uno::Sequence< OUString > aRet { ServiceAsciiMistyped, ServiceAscii }; \
61  return aRet; \
62 }
63 
64 #define SC_SIMPLE_SERVICE_INFO( ClassName, ClassNameAscii, ServiceAscii ) \
65  SC_SIMPLE_SERVICE_INFO_IMPL( ClassName, ClassNameAscii ) \
66  SC_SIMPLE_SERVICE_INFO_NAME( ClassName, ServiceAscii )
67 
68 #define SC_SIMPLE_SERVICE_INFO_COMPAT( ClassName, ClassNameAscii, ServiceAscii, ServiceAsciiMistyped ) \
69  SC_SIMPLE_SERVICE_INFO_IMPL( ClassName, ClassNameAscii ) \
70  SC_SIMPLE_SERVICE_INFO_TYPO( ClassName, ServiceAscii, ServiceAsciiMistyped )
71 
72 
73 #define SC_IMPL_DUMMY_PROPERTY_LISTENER( ClassName ) \
74  void SAL_CALL ClassName::addPropertyChangeListener( const OUString&, \
75  const uno::Reference<beans::XPropertyChangeListener>&) \
76  { OSL_FAIL("not implemented"); } \
77  void SAL_CALL ClassName::removePropertyChangeListener( const OUString&, \
78  const uno::Reference<beans::XPropertyChangeListener>&) \
79  { OSL_FAIL("not implemented"); } \
80  void SAL_CALL ClassName::addVetoableChangeListener( const OUString&, \
81  const uno::Reference<beans::XVetoableChangeListener>&) \
82  { OSL_FAIL("not implemented"); } \
83  void SAL_CALL ClassName::removeVetoableChangeListener( const OUString&, \
84  const uno::Reference<beans::XVetoableChangeListener>&) \
85  { OSL_FAIL("not implemented"); }
86 
87 #define SC_QUERYINTERFACE(x) \
88  if (rType == cppu::UnoType<x>::get()) \
89  { return uno::makeAny(uno::Reference<x>(this)); }
90 
91 // SC_QUERY_MULTIPLE( XElementAccess, XIndexAccess ):
92 // use if interface is used several times in one class
93 
94 #define SC_QUERY_MULTIPLE(x,y) \
95  if (rType == cppu::UnoType<x>::get()) \
96  { uno::Any aR; aR <<= uno::Reference<x>(static_cast<y*>(this)); return aR; }
97 
98 class ScIndexEnumeration final : public cppu::WeakImplHelper<
99  css::container::XEnumeration,
100  css::lang::XServiceInfo >
101 {
102 private:
103  css::uno::Reference<css::container::XIndexAccess> xIndex;
104  OUString sServiceName;
105  sal_Int32 nPos;
106 
107 public:
108  ScIndexEnumeration(const css::uno::Reference<
109  css::container::XIndexAccess>& rInd, const OUString& rServiceName);
110  virtual ~ScIndexEnumeration() override;
111 
112  // XEnumeration
113  virtual sal_Bool SAL_CALL hasMoreElements() override;
114  virtual css::uno::Any SAL_CALL nextElement() override;
115 
116  // XServiceInfo
117  virtual OUString SAL_CALL getImplementationName( ) override;
118  virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
119  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
120 };
121 
122 // new (uno 3) variant
123 class ScNameToIndexAccess final : public cppu::WeakImplHelper<
124  css::container::XIndexAccess,
125  css::lang::XServiceInfo >
126 {
127 private:
128  css::uno::Reference<css::container::XNameAccess> xNameAccess;
129  css::uno::Sequence<OUString> aNames;
130 
131 public:
133  const css::uno::Reference< css::container::XNameAccess>& rNameObj );
134  virtual ~ScNameToIndexAccess() override;
135 
136  // XIndexAccess
137  virtual sal_Int32 SAL_CALL getCount( ) override;
138  virtual css::uno::Any SAL_CALL getByIndex( sal_Int32 Index ) override;
139 
140  // XElementAccess
141  virtual css::uno::Type SAL_CALL getElementType( ) override;
142  virtual sal_Bool SAL_CALL hasElements( ) override;
143 
144  // XServiceInfo
145  virtual OUString SAL_CALL getImplementationName( ) override;
146  virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
147  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
148 };
149 
151 {
152 public:
153  static bool GetBoolProperty( const css::uno::Reference< css::beans::XPropertySet>& xProp,
154  const OUString& rName, bool bDefault = false );
155  static sal_Int16 GetShortProperty( const css::uno::Reference< css::beans::XPropertySet>& xProp,
156  const OUString& rName, sal_Int16 nDefault );
157  static sal_Int32 GetLongProperty( const css::uno::Reference< css::beans::XPropertySet>& xProp,
158  const OUString& rName );
159  template<typename EnumT>
160  static EnumT GetEnumProperty( const css::uno::Reference< css::beans::XPropertySet>& xProp,
161  const OUString& rName, EnumT nDefault )
162  { return static_cast<EnumT>(GetEnumPropertyImpl(xProp, rName, static_cast<sal_Int32>(nDefault))); }
163 
164  static OUString GetStringProperty(
165  const css::uno::Reference<css::beans::XPropertySet>& xProp,
166  const OUString& rName, const OUString& rDefault );
167 
168  static bool GetBoolFromAny( const css::uno::Any& aAny );
169  static sal_Int16 GetInt16FromAny( const css::uno::Any& aAny );
170  static sal_Int32 GetInt32FromAny( const css::uno::Any& aAny );
171  static sal_Int32 GetEnumFromAny( const css::uno::Any& aAny );
172 
173  static void SetOptionalPropertyValue(
174  const css::uno::Reference< css::beans::XPropertySet >& rPropSet,
175  const char* pPropName, const css::uno::Any& rVal );
176 
177  template<typename ValueType>
179  const css::uno::Reference< css::beans::XPropertySet >& rPropSet,
180  const char* pPropName, const ValueType& rVal )
181  {
182  css::uno::Any any;
183  any <<= rVal;
184  SetOptionalPropertyValue(rPropSet, pPropName, any);
185  }
186 
187  template<typename ValueType>
188  static css::uno::Sequence<ValueType> VectorToSequence( const std::vector<ValueType>& rVector )
189  {
190  if (rVector.empty())
191  return css::uno::Sequence<ValueType>();
192 
193  return css::uno::Sequence<ValueType>(&rVector[0], static_cast<sal_Int32>(rVector.size()));
194  }
195 private:
196  static sal_Int32 GetEnumPropertyImpl( const css::uno::Reference< css::beans::XPropertySet>& xProp,
197  const OUString& rName, sal_Int32 nDefault );
198 };
199 
200 #endif
201 
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 Index) override
Definition: miscuno.cxx:255
virtual sal_Int32 SAL_CALL getCount() override
Definition: miscuno.cxx:250
virtual sal_Bool SAL_CALL hasElements() override
Definition: miscuno.cxx:273
static css::uno::Sequence< ValueType > VectorToSequence(const std::vector< ValueType > &rVector)
Definition: miscuno.hxx:188
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: miscuno.cxx:223
OUString sServiceName
Definition: miscuno.hxx:104
virtual ~ScNameToIndexAccess() override
Definition: miscuno.cxx:244
static EnumT GetEnumProperty(const css::uno::Reference< css::beans::XPropertySet > &xProp, const OUString &rName, EnumT nDefault)
Definition: miscuno.hxx:160
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual css::uno::Type SAL_CALL getElementType() override
Definition: miscuno.cxx:265
virtual OUString SAL_CALL getImplementationName() override
Definition: miscuno.cxx:218
static void SetOptionalPropertyValue(const css::uno::Reference< css::beans::XPropertySet > &rPropSet, const char *pPropName, const ValueType &rVal)
Definition: miscuno.hxx:178
virtual sal_Bool SAL_CALL hasMoreElements() override
Definition: miscuno.cxx:197
sal_Int32 nPos
Definition: miscuno.hxx:105
css::uno::Reference< css::container::XNameAccess > xNameAccess
Definition: miscuno.hxx:128
virtual ~ScIndexEnumeration() override
Definition: miscuno.cxx:191
const Any & any
unsigned char sal_Bool
ScIndexEnumeration(const css::uno::Reference< css::container::XIndexAccess > &rInd, const OUString &rServiceName)
Definition: miscuno.cxx:183
ScNameToIndexAccess(const css::uno::Reference< css::container::XNameAccess > &rNameObj)
Definition: miscuno.cxx:234
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: miscuno.cxx:229
virtual css::uno::Any SAL_CALL nextElement() override
Definition: miscuno.cxx:203
css::uno::Reference< css::container::XIndexAccess > xIndex
Definition: miscuno.hxx:103
ValueType
css::uno::Sequence< OUString > aNames
Definition: miscuno.hxx:129
virtual OUString SAL_CALL getImplementationName() override
struct _ADOIndex Index
#define SC_DLLPUBLIC
Definition: scdllapi.h:28
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override