Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <com/sun/star/container/XIndexAccess.hpp>
30 : : #include <com/sun/star/lang/XServiceInfo.hpp>
31 : : #include <com/sun/star/beans/XPropertySet.hpp>
32 : : #include <com/sun/star/beans/PropertyAttribute.hpp>
33 : : #include <com/sun/star/awt/Rectangle.hpp>
34 : : #include <com/sun/star/lang/DisposedException.hpp>
35 : :
36 : : #include <vcl/svapp.hxx>
37 : :
38 : : #include <cppuhelper/implbase3.hxx>
39 : : #include <cppuhelper/implbase4.hxx>
40 : :
41 : : #include <vector>
42 : :
43 : :
44 : : using ::rtl::OUString;
45 : : using namespace ::com::sun::star::uno;
46 : : using namespace ::com::sun::star::lang;
47 : : using namespace ::com::sun::star::container;
48 : : using namespace ::com::sun::star::beans;
49 : :
50 : : // -----------------------------------------------------------------------
51 : :
52 : : namespace vcl
53 : : {
54 : :
55 [ # # ]: 0 : class DisplayInfo : public ::cppu::WeakAggImplHelper3< XPropertySet, XPropertySetInfo, XServiceInfo >
56 : : {
57 : : public:
58 : : DisplayInfo( sal_uInt32 nDisplayScreen );
59 : :
60 : : // XPropertySet
61 : : virtual Reference< XPropertySetInfo > SAL_CALL getPropertySetInfo() throw (RuntimeException);
62 : : virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const Any& aValue ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException);
63 : : virtual Any SAL_CALL getPropertyValue( const OUString& PropertyName ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException);
64 : : virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const Reference< XPropertyChangeListener >& xListener ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException);
65 : : virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const Reference< XPropertyChangeListener >& aListener ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException);
66 : : virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName, const Reference< XVetoableChangeListener >& aListener ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException);
67 : : virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName, const Reference< XVetoableChangeListener >& aListener ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException);
68 : :
69 : : // XPropertySetInfo
70 : : virtual Sequence< Property > SAL_CALL getProperties() throw (RuntimeException);
71 : : virtual Property SAL_CALL getPropertyByName( const OUString& aName ) throw (UnknownPropertyException, RuntimeException);
72 : : virtual ::sal_Bool SAL_CALL hasPropertyByName( const OUString& Name ) throw (RuntimeException);
73 : :
74 : : // XServiceInfo
75 : : virtual OUString SAL_CALL getImplementationName() throw (RuntimeException);
76 : : virtual ::sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw (RuntimeException);
77 : : virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw (RuntimeException);
78 : :
79 : : private:
80 : : sal_uInt32 mnDisplayScreen;
81 : : };
82 : :
83 : : static const char* pScreenAreaName = "ScreenArea";
84 : : static const char* pWorkAreaName = "WorkArea";
85 : : static const char* pScreenName = "ScreenName";
86 : :
87 : : // --------------------------------------------------------------------
88 : :
89 : 0 : DisplayInfo::DisplayInfo( sal_uInt32 nDisplayScreen )
90 : 0 : : mnDisplayScreen( nDisplayScreen )
91 : : {
92 : 0 : }
93 : :
94 : : // XPropertySet
95 : 0 : Reference< XPropertySetInfo > SAL_CALL DisplayInfo::getPropertySetInfo() throw (RuntimeException)
96 : : {
97 : 0 : return this;
98 : : }
99 : :
100 : 0 : void SAL_CALL DisplayInfo::setPropertyValue( const OUString& /*aPropertyName* */, const Any& /*aValue*/ ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
101 : : {
102 [ # # ]: 0 : throw PropertyVetoException();
103 : : }
104 : :
105 : 0 : Any SAL_CALL DisplayInfo::getPropertyValue( const OUString& PropertyName ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
106 : : {
107 [ # # ]: 0 : Rectangle aRect;
108 [ # # ]: 0 : if( PropertyName.equalsAscii( pScreenAreaName ) )
109 : : {
110 [ # # ]: 0 : aRect = Application::GetScreenPosSizePixel( mnDisplayScreen );
111 : : }
112 [ # # ]: 0 : else if( PropertyName.equalsAscii( pWorkAreaName ) )
113 : : {
114 [ # # ]: 0 : aRect = Application::GetWorkAreaPosSizePixel( mnDisplayScreen );
115 : : }
116 [ # # ]: 0 : else if( PropertyName.equalsAscii( pScreenName ) )
117 : : {
118 [ # # ][ # # ]: 0 : return Any( Application::GetDisplayScreenName( mnDisplayScreen ) );
119 : : }
120 : : else
121 [ # # ]: 0 : throw UnknownPropertyException();
122 : :
123 [ # # ]: 0 : return Any( com::sun::star::awt::Rectangle( aRect.Left(), aRect.Top(), aRect.getWidth(), aRect.getHeight() ) );
124 : : }
125 : :
126 : 0 : void SAL_CALL DisplayInfo::addPropertyChangeListener( const OUString&, const Reference< XPropertyChangeListener >& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException) {}
127 : 0 : void SAL_CALL DisplayInfo::removePropertyChangeListener( const OUString&, const Reference< XPropertyChangeListener >& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException) {}
128 : 0 : void SAL_CALL DisplayInfo::addVetoableChangeListener( const OUString&, const Reference< XVetoableChangeListener >& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException) {}
129 : 0 : void SAL_CALL DisplayInfo::removeVetoableChangeListener( const OUString&, const Reference< XVetoableChangeListener >& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException) {}
130 : :
131 : : // XPropertySetInfo
132 : 0 : Sequence< Property > SAL_CALL DisplayInfo::getProperties() throw (RuntimeException)
133 : : {
134 : 0 : Sequence< Property > aProps(2);
135 [ # # ][ # # ]: 0 : aProps[0] = getPropertyByName( OUString::createFromAscii( pScreenAreaName ) );
136 [ # # ][ # # ]: 0 : aProps[1] = getPropertyByName( OUString::createFromAscii( pWorkAreaName ) );
137 : 0 : return aProps;
138 : : }
139 : :
140 : 0 : Property SAL_CALL DisplayInfo::getPropertyByName( const OUString& aName ) throw (UnknownPropertyException, RuntimeException)
141 : : {
142 [ # # # # ]: 0 : if( aName.equalsAscii( pScreenAreaName ) ||
[ # # ]
143 : 0 : aName.equalsAscii( pWorkAreaName ) )
144 : 0 : return Property( aName, 0, ::getCppuType( (::com::sun::star::awt::Rectangle const *)0 ), PropertyAttribute::READONLY );
145 [ # # ]: 0 : throw UnknownPropertyException();
146 : : }
147 : :
148 : 0 : ::sal_Bool SAL_CALL DisplayInfo::hasPropertyByName( const OUString& Name ) throw (RuntimeException)
149 : : {
150 : 0 : return Name.equalsAscii( pScreenAreaName ) ||
151 [ # # ][ # # ]: 0 : Name.equalsAscii( pWorkAreaName );
152 : : }
153 : :
154 : : // XServiceInfo
155 : 0 : OUString SAL_CALL DisplayInfo::getImplementationName() throw (RuntimeException)
156 : : {
157 : 0 : return OUString(RTL_CONSTASCII_USTRINGPARAM("vcl::DisplayInfo"));
158 : : }
159 : :
160 : 0 : ::sal_Bool SAL_CALL DisplayInfo::supportsService( const OUString& ServiceName ) throw (RuntimeException)
161 : : {
162 [ # # ]: 0 : Sequence< OUString > aSN( getSupportedServiceNames() );
163 [ # # ]: 0 : for( sal_Int32 nService = 0; nService < aSN.getLength(); nService++ )
164 : : {
165 [ # # ][ # # ]: 0 : if( aSN[nService] == ServiceName )
166 : 0 : return sal_True;
167 : : }
168 [ # # ]: 0 : return sal_False;
169 : : }
170 : :
171 : 0 : Sequence< OUString > SAL_CALL DisplayInfo::getSupportedServiceNames() throw (RuntimeException)
172 : : {
173 [ # # ]: 0 : OUString aServiceName(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.DisplayInfo"));
174 [ # # ]: 0 : return Sequence< OUString >(&aServiceName, 1);
175 : : }
176 : :
177 : : // ====================================================================
178 : :
179 [ - + ]: 2366 : class DisplayAccess : public ::cppu::WeakAggImplHelper4< XPropertySet, XPropertySetInfo, XIndexAccess, XServiceInfo >
180 : : {
181 : : public:
182 : : DisplayAccess ();
183 : :
184 : : // XPropertySet
185 : : virtual Reference< XPropertySetInfo > SAL_CALL getPropertySetInfo() throw (RuntimeException);
186 : : virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const Any& aValue ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException);
187 : : virtual Any SAL_CALL getPropertyValue( const OUString& PropertyName ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException);
188 : : virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const Reference< XPropertyChangeListener >& xListener ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException);
189 : : virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const Reference< XPropertyChangeListener >& aListener ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException);
190 : : virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName, const Reference< XVetoableChangeListener >& aListener ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException);
191 : : virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName, const Reference< XVetoableChangeListener >& aListener ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException);
192 : :
193 : : // XPropertySetInfo
194 : : virtual Sequence< Property > SAL_CALL getProperties() throw (RuntimeException);
195 : : virtual Property SAL_CALL getPropertyByName( const OUString& aName ) throw (UnknownPropertyException, RuntimeException);
196 : : virtual ::sal_Bool SAL_CALL hasPropertyByName( const OUString& Name ) throw (RuntimeException);
197 : :
198 : : // XIndexAccess
199 : : virtual ::sal_Int32 SAL_CALL getCount() throw (RuntimeException);
200 : : virtual Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (IndexOutOfBoundsException, WrappedTargetException, RuntimeException);
201 : :
202 : : // XElementAccess
203 : : virtual Type SAL_CALL getElementType() throw (RuntimeException);
204 : : virtual ::sal_Bool SAL_CALL hasElements() throw (RuntimeException);
205 : :
206 : : // XServiceInfo
207 : : virtual OUString SAL_CALL getImplementationName() throw (RuntimeException);
208 : : virtual ::sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw (RuntimeException);
209 : : virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw (RuntimeException);
210 : : };
211 : :
212 : 62 : Sequence< OUString > DisplayAccess_getSupportedServiceNames()
213 : : {
214 [ + - ]: 62 : OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.DisplayAccess" ) );
215 [ + - ]: 62 : return Sequence< OUString >( &aServiceName, 1 );
216 : : }
217 : :
218 : 310 : OUString DisplayAccess_getImplementationName()
219 : : {
220 : 310 : return OUString( RTL_CONSTASCII_USTRINGPARAM( "vcl::DisplayAccess" ) );
221 : : }
222 : :
223 : 1183 : Reference< XInterface > SAL_CALL DisplayAccess_createInstance( const Reference< XMultiServiceFactory >& )
224 : : {
225 [ + - ]: 1183 : return static_cast< ::cppu::OWeakObject * >( new DisplayAccess );
226 : : }
227 : :
228 : 1183 : DisplayAccess::DisplayAccess()
229 : : {
230 : 1183 : }
231 : :
232 : : static const char* pUnifiedDisplayName = "IsUnifiedDisplay";
233 : : static const char* pDefaultDisplayName = "DefaultDisplay";
234 : : static const char* pBuiltInDisplayName = "BuiltInDisplay";
235 : : static const char* pExternalDisplayName = "ExternalDisplay";
236 : :
237 : : // XPropertySet
238 : 0 : Reference< XPropertySetInfo > SAL_CALL DisplayAccess::getPropertySetInfo() throw (RuntimeException)
239 : : {
240 : 0 : return this;
241 : : }
242 : :
243 : 0 : void SAL_CALL DisplayAccess::setPropertyValue( const OUString& /*aPropertyName* */, const Any& /*aValue*/ ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
244 : : {
245 [ # # ]: 0 : throw PropertyVetoException();
246 : : }
247 : :
248 : 0 : Any SAL_CALL DisplayAccess::getPropertyValue( const OUString& PropertyName ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
249 : : {
250 : 0 : Any aRet;
251 [ # # ]: 0 : if( PropertyName.equalsAscii( pUnifiedDisplayName ) )
252 : : {
253 [ # # ][ # # ]: 0 : aRet <<= sal_Bool( Application::IsUnifiedDisplay() );
254 : : }
255 [ # # # # ]: 0 : else if( PropertyName.equalsAscii( pDefaultDisplayName ) || // Unhelpful name, legacy setting
[ # # ]
256 : 0 : PropertyName.equalsAscii( pBuiltInDisplayName ) )
257 : : {
258 [ # # ][ # # ]: 0 : aRet <<= sal_Int32( Application::GetDisplayBuiltInScreen() );
259 : : }
260 [ # # ]: 0 : else if( PropertyName.equalsAscii( pExternalDisplayName ) )
261 : : {
262 : : // This is really unpleasant, in theory we could have multiple
263 : : // external displays etc.
264 : 0 : sal_Int32 nExternal(0);
265 [ # # ]: 0 : switch (Application::GetDisplayBuiltInScreen())
[ # # # ]
266 : : {
267 : : case 0:
268 : 0 : nExternal = 1;
269 : 0 : break;
270 : : case 1:
271 : 0 : nExternal = 0;
272 : 0 : break;
273 : : default:
274 : : // When the built-in display is neither 0 nor 1
275 : : // then place the full-screen presentation on the
276 : : // first available screen.
277 : 0 : nExternal = 0;
278 : 0 : break;
279 : : }
280 [ # # ]: 0 : aRet <<= nExternal;
281 : : }
282 : : else
283 [ # # ]: 0 : throw UnknownPropertyException();
284 : :
285 : 0 : return aRet;
286 : : }
287 : :
288 : 0 : void SAL_CALL DisplayAccess::addPropertyChangeListener( const OUString&, const Reference< XPropertyChangeListener >& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException) {}
289 : 0 : void SAL_CALL DisplayAccess::removePropertyChangeListener( const OUString&, const Reference< XPropertyChangeListener >& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException) {}
290 : 0 : void SAL_CALL DisplayAccess::addVetoableChangeListener( const OUString&, const Reference< XVetoableChangeListener >& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException) {}
291 : 0 : void SAL_CALL DisplayAccess::removeVetoableChangeListener( const OUString&, const Reference< XVetoableChangeListener >& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException) {}
292 : :
293 : : // XPropertySetInfo
294 : 0 : Sequence< Property > SAL_CALL DisplayAccess::getProperties() throw (RuntimeException)
295 : : {
296 : 0 : Sequence< Property > aProps(4);
297 [ # # ][ # # ]: 0 : aProps[0] = getPropertyByName( OUString::createFromAscii( pUnifiedDisplayName ) );
298 [ # # ][ # # ]: 0 : aProps[1] = getPropertyByName( OUString::createFromAscii( pDefaultDisplayName ) );
299 [ # # ][ # # ]: 0 : aProps[2] = getPropertyByName( OUString::createFromAscii( pBuiltInDisplayName ) );
300 [ # # ][ # # ]: 0 : aProps[3] = getPropertyByName( OUString::createFromAscii( pExternalDisplayName ) );
301 : 0 : return aProps;
302 : : }
303 : :
304 : 0 : Property SAL_CALL DisplayAccess::getPropertyByName( const OUString& aName ) throw (UnknownPropertyException, RuntimeException)
305 : : {
306 [ # # ]: 0 : if( aName.equalsAscii( pUnifiedDisplayName ) )
307 : 0 : return Property( aName, 0, ::getCppuType( (sal_Bool const *)0 ), PropertyAttribute::READONLY );
308 : :
309 [ # # # # : 0 : if( aName.equalsAscii( pDefaultDisplayName ) ||
# # ][ # # ]
310 : 0 : aName.equalsAscii( pBuiltInDisplayName ) ||
311 : 0 : aName.equalsAscii( pExternalDisplayName ) )
312 : 0 : return Property( aName, 0, ::getCppuType( (sal_Int32 const *)0 ), PropertyAttribute::READONLY );
313 : :
314 [ # # ]: 0 : throw UnknownPropertyException();
315 : : }
316 : :
317 : 0 : ::sal_Bool SAL_CALL DisplayAccess::hasPropertyByName( const OUString& Name ) throw (RuntimeException)
318 : : {
319 : 0 : return Name.equalsAscii( pUnifiedDisplayName ) ||
320 : 0 : Name.equalsAscii( pDefaultDisplayName ) ||
321 : 0 : Name.equalsAscii( pBuiltInDisplayName ) ||
322 [ # # ][ # # : 0 : Name.equalsAscii( pExternalDisplayName );
# # # # ]
323 : : }
324 : :
325 : : // XIndexAccess
326 : 0 : ::sal_Int32 SAL_CALL DisplayAccess::getCount() throw (RuntimeException)
327 : : {
328 : 0 : return Application::GetScreenCount();
329 : : }
330 : :
331 : 0 : Any SAL_CALL DisplayAccess::getByIndex( ::sal_Int32 Index ) throw (IndexOutOfBoundsException, WrappedTargetException, RuntimeException)
332 : : {
333 [ # # ][ # # ]: 0 : if( (Index < 0) || (Index >= getCount()) )
[ # # ]
334 [ # # ]: 0 : throw IndexOutOfBoundsException();
335 : :
336 [ # # ][ # # ]: 0 : return makeAny( Reference< XPropertySet >( new DisplayInfo( Index ) ) );
[ # # ]
337 : : }
338 : :
339 : : // XElementAccess
340 : 0 : Type SAL_CALL DisplayAccess::getElementType() throw (RuntimeException)
341 : : {
342 : 0 : return XPropertySet::static_type();
343 : : }
344 : :
345 : 0 : ::sal_Bool SAL_CALL DisplayAccess::hasElements() throw (RuntimeException)
346 : : {
347 : 0 : return true;
348 : : }
349 : :
350 : : // XServiceInfo
351 : 0 : OUString SAL_CALL DisplayAccess::getImplementationName() throw (RuntimeException)
352 : : {
353 : 0 : return DisplayAccess_getImplementationName();
354 : : }
355 : :
356 : 0 : ::sal_Bool SAL_CALL DisplayAccess::supportsService( const OUString& ServiceName ) throw (RuntimeException)
357 : : {
358 [ # # ]: 0 : Sequence< OUString > aSN( DisplayAccess_getSupportedServiceNames() );
359 [ # # ]: 0 : for( sal_Int32 nService = 0; nService < aSN.getLength(); nService++ )
360 : : {
361 [ # # ][ # # ]: 0 : if( aSN[nService] == ServiceName )
362 : 0 : return sal_True;
363 : : }
364 [ # # ]: 0 : return sal_False;
365 : : }
366 : :
367 : 0 : Sequence< OUString > SAL_CALL DisplayAccess::getSupportedServiceNames() throw (RuntimeException)
368 : : {
369 : 0 : return DisplayAccess_getSupportedServiceNames();
370 : : }
371 : :
372 : : } // namespace vcl
373 : :
374 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|