xref: /aoo42x/main/vcl/source/components/display.cxx (revision cdf0e10c)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_vcl.hxx"
30 #include <com/sun/star/container/XIndexAccess.hpp>
31 #include <com/sun/star/lang/XServiceInfo.hpp>
32 #include <com/sun/star/beans/XPropertySet.hpp>
33 #include <com/sun/star/beans/PropertyAttribute.hpp>
34 #include <com/sun/star/awt/Rectangle.hpp>
35 #include <com/sun/star/lang/DisposedException.hpp>
36 
37 #include <vcl/svapp.hxx>
38 
39 #include <cppuhelper/implbase3.hxx>
40 #include <cppuhelper/implbase4.hxx>
41 
42 #include <vector>
43 #include <tools/debug.hxx>
44 
45 
46 using ::rtl::OUString;
47 using namespace ::com::sun::star::uno;
48 using namespace ::com::sun::star::lang;
49 using namespace ::com::sun::star::container;
50 using namespace ::com::sun::star::beans;
51 
52 // -----------------------------------------------------------------------
53 
54 namespace vcl
55 {
56 
57 class DisplayInfo : public ::cppu::WeakAggImplHelper3< XPropertySet, XPropertySetInfo, XServiceInfo >
58 {
59 public:
60 	DisplayInfo( sal_uInt32 nDisplay );
61 
62     // XPropertySet
63     virtual Reference< XPropertySetInfo > SAL_CALL getPropertySetInfo(  ) throw (RuntimeException);
64     virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const Any& aValue ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException);
65     virtual Any SAL_CALL getPropertyValue( const OUString& PropertyName ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException);
66     virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const Reference< XPropertyChangeListener >& xListener ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException);
67     virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const Reference< XPropertyChangeListener >& aListener ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException);
68     virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName, const Reference< XVetoableChangeListener >& aListener ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException);
69     virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName, const Reference< XVetoableChangeListener >& aListener ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException);
70 
71     // XPropertySetInfo
72     virtual Sequence< Property > SAL_CALL getProperties(  ) throw (RuntimeException);
73     virtual Property SAL_CALL getPropertyByName( const OUString& aName ) throw (UnknownPropertyException, RuntimeException);
74     virtual ::sal_Bool SAL_CALL hasPropertyByName( const OUString& Name ) throw (RuntimeException);
75 
76 	// XServiceInfo
77     virtual OUString SAL_CALL getImplementationName(  ) throw (RuntimeException);
78     virtual ::sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw (RuntimeException);
79     virtual Sequence< OUString > SAL_CALL getSupportedServiceNames(  ) throw (RuntimeException);
80 
81 private:
82 	sal_uInt32 mnDisplay;
83 };
84 
85 static const char* pScreenAreaName = "ScreenArea";
86 static const char* pWorkAreaName = "WorkArea";
87 static const char* pScreenName = "ScreenName";
88 
89 // --------------------------------------------------------------------
90 
91 DisplayInfo::DisplayInfo( sal_uInt32 nDisplay )
92 : mnDisplay( nDisplay )
93 {
94 }
95 
96 // XPropertySet
97 Reference< XPropertySetInfo > SAL_CALL DisplayInfo::getPropertySetInfo(  ) throw (RuntimeException)
98 {
99 	return this;
100 }
101 
102 void SAL_CALL DisplayInfo::setPropertyValue( const OUString& /*aPropertyName* */, const Any& /*aValue*/ ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
103 {
104 	throw PropertyVetoException();
105 }
106 
107 Any SAL_CALL DisplayInfo::getPropertyValue( const OUString& PropertyName ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
108 {
109     Rectangle aRect;
110 	if( PropertyName.equalsAscii( pScreenAreaName ) )
111 	{
112 		aRect = Application::GetScreenPosSizePixel( mnDisplay );
113 	}
114 	else if( PropertyName.equalsAscii( pWorkAreaName ) )
115 	{
116 		aRect = Application::GetWorkAreaPosSizePixel( mnDisplay );
117 	}
118 	else if( PropertyName.equalsAscii( pScreenName ) )
119 	{
120 		return Any( Application::GetScreenName( mnDisplay ) );
121 	}
122     else
123         throw UnknownPropertyException();
124 
125 	return Any( com::sun::star::awt::Rectangle( aRect.Left(), aRect.Top(), aRect.getWidth(), aRect.getHeight() ) );
126 }
127 
128 void SAL_CALL DisplayInfo::addPropertyChangeListener( const OUString&, const Reference< XPropertyChangeListener >& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException) {}
129 void SAL_CALL DisplayInfo::removePropertyChangeListener( const OUString&, const Reference< XPropertyChangeListener >& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException) {}
130 void SAL_CALL DisplayInfo::addVetoableChangeListener( const OUString&, const Reference< XVetoableChangeListener >& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException) {}
131 void SAL_CALL DisplayInfo::removeVetoableChangeListener( const OUString&, const Reference< XVetoableChangeListener >& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException) {}
132 
133 // XPropertySetInfo
134 Sequence< Property > SAL_CALL DisplayInfo::getProperties(  ) throw (RuntimeException)
135 {
136 	Sequence< Property > aProps(2);
137 	aProps[0] = getPropertyByName( OUString::createFromAscii( pScreenAreaName ) );
138 	aProps[1] = getPropertyByName( OUString::createFromAscii( pWorkAreaName ) );
139 	return aProps;
140 }
141 
142 Property SAL_CALL DisplayInfo::getPropertyByName( const OUString& aName ) throw (UnknownPropertyException, RuntimeException)
143 {
144 	if( aName.equalsAscii( pScreenAreaName ) ||
145         aName.equalsAscii( pWorkAreaName ) )
146 		return Property( aName, 0, ::getCppuType( (::com::sun::star::awt::Rectangle const *)0 ), PropertyAttribute::READONLY );
147 	throw UnknownPropertyException();
148 }
149 
150 ::sal_Bool SAL_CALL DisplayInfo::hasPropertyByName( const OUString& Name ) throw (RuntimeException)
151 {
152 	return Name.equalsAscii( pScreenAreaName ) ||
153            Name.equalsAscii( pWorkAreaName );
154 }
155 
156 // XServiceInfo
157 OUString SAL_CALL DisplayInfo::getImplementationName(  ) throw (RuntimeException)
158 {
159 	static OUString aImplementationName( RTL_CONSTASCII_USTRINGPARAM( "vcl::DisplayInfo" ) );
160 	return aImplementationName;
161 }
162 
163 ::sal_Bool SAL_CALL DisplayInfo::supportsService( const OUString& ServiceName ) throw (RuntimeException)
164 {
165 	Sequence< OUString > aSN( getSupportedServiceNames() );
166 	for( sal_Int32 nService = 0; nService < aSN.getLength(); nService++ )
167 	{
168 		if( aSN[nService] == ServiceName )
169 			return sal_True;
170 	}
171 	return sal_False;
172 }
173 
174 Sequence< OUString > SAL_CALL DisplayInfo::getSupportedServiceNames(  ) throw (RuntimeException)
175 {
176 	static OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.DisplayInfo" ) );
177 	static Sequence< OUString > aServiceNames( &aServiceName, 1  );
178 	return aServiceNames;
179 }
180 
181 // ====================================================================
182 
183 class DisplayAccess : public ::cppu::WeakAggImplHelper4< XPropertySet, XPropertySetInfo, XIndexAccess, XServiceInfo >
184 {
185 public:
186 	DisplayAccess ();
187 
188     // XPropertySet
189     virtual Reference< XPropertySetInfo > SAL_CALL getPropertySetInfo(  ) throw (RuntimeException);
190     virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const Any& aValue ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException);
191     virtual Any SAL_CALL getPropertyValue( const OUString& PropertyName ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException);
192     virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const Reference< XPropertyChangeListener >& xListener ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException);
193     virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const Reference< XPropertyChangeListener >& aListener ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException);
194     virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName, const Reference< XVetoableChangeListener >& aListener ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException);
195     virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName, const Reference< XVetoableChangeListener >& aListener ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException);
196 
197     // XPropertySetInfo
198     virtual Sequence< Property > SAL_CALL getProperties(  ) throw (RuntimeException);
199     virtual Property SAL_CALL getPropertyByName( const OUString& aName ) throw (UnknownPropertyException, RuntimeException);
200     virtual ::sal_Bool SAL_CALL hasPropertyByName( const OUString& Name ) throw (RuntimeException);
201 
202     // XIndexAccess
203     virtual ::sal_Int32 SAL_CALL getCount() throw (RuntimeException);
204     virtual Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (IndexOutOfBoundsException, WrappedTargetException, RuntimeException);
205 
206     // XElementAccess
207     virtual Type SAL_CALL getElementType(  ) throw (RuntimeException);
208     virtual ::sal_Bool SAL_CALL hasElements(  ) throw (RuntimeException);
209 
210 	// XServiceInfo
211     virtual OUString SAL_CALL getImplementationName(  ) throw (RuntimeException);
212     virtual ::sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw (RuntimeException);
213     virtual Sequence< OUString > SAL_CALL getSupportedServiceNames(  ) throw (RuntimeException);
214 };
215 
216 Sequence< OUString > DisplayAccess_getSupportedServiceNames()
217 {
218 	static OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.DisplayAccess" ) );
219 	static Sequence< OUString > aServiceNames( &aServiceName, 1 );
220 	return aServiceNames;
221 }
222 
223 OUString DisplayAccess_getImplementationName()
224 {
225 	return OUString( RTL_CONSTASCII_USTRINGPARAM( "vcl::DisplayAccess" ) );
226 }
227 
228 Reference< XInterface > SAL_CALL DisplayAccess_createInstance( const Reference< XMultiServiceFactory >&  )
229 {
230 	return static_cast< ::cppu::OWeakObject * >( new DisplayAccess );
231 }
232 
233 DisplayAccess::DisplayAccess()
234 {
235 }
236 
237 static const char* pMultiDisplayName = "MultiDisplay";
238 static const char* pDefaultDisplayName = "DefaultDisplay";
239 
240 // XPropertySet
241 Reference< XPropertySetInfo > SAL_CALL DisplayAccess::getPropertySetInfo(  ) throw (RuntimeException)
242 {
243 	return this;
244 }
245 
246 void SAL_CALL DisplayAccess::setPropertyValue( const OUString& /*aPropertyName* */, const Any& /*aValue*/ ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
247 {
248 	throw PropertyVetoException();
249 }
250 
251 Any SAL_CALL DisplayAccess::getPropertyValue( const OUString& PropertyName ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
252 {
253     Any aRet;
254 	if( PropertyName.equalsAscii( pMultiDisplayName ) )
255 	{
256         aRet <<= sal_Bool( Application::IsMultiDisplay() );
257 	}
258 	else if( PropertyName.equalsAscii( pDefaultDisplayName ) )
259 	{
260         aRet <<= sal_Int32( Application::GetDefaultDisplayNumber() );
261 	}
262     else
263         throw UnknownPropertyException();
264 
265 	return aRet;
266 }
267 
268 void SAL_CALL DisplayAccess::addPropertyChangeListener( const OUString&, const Reference< XPropertyChangeListener >& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException) {}
269 void SAL_CALL DisplayAccess::removePropertyChangeListener( const OUString&, const Reference< XPropertyChangeListener >& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException) {}
270 void SAL_CALL DisplayAccess::addVetoableChangeListener( const OUString&, const Reference< XVetoableChangeListener >& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException) {}
271 void SAL_CALL DisplayAccess::removeVetoableChangeListener( const OUString&, const Reference< XVetoableChangeListener >& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException) {}
272 
273 // XPropertySetInfo
274 Sequence< Property > SAL_CALL DisplayAccess::getProperties(  ) throw (RuntimeException)
275 {
276 	Sequence< Property > aProps(2);
277 	aProps[0] = getPropertyByName( OUString::createFromAscii( pMultiDisplayName ) );
278 	aProps[1] = getPropertyByName( OUString::createFromAscii( pDefaultDisplayName ) );
279 	return aProps;
280 }
281 
282 Property SAL_CALL DisplayAccess::getPropertyByName( const OUString& aName ) throw (UnknownPropertyException, RuntimeException)
283 {
284 	if( aName.equalsAscii( pMultiDisplayName ) )
285 		return Property( aName, 0, ::getCppuType( (sal_Bool const *)0 ), PropertyAttribute::READONLY );
286 
287     if( aName.equalsAscii( pDefaultDisplayName ) )
288 		return Property( aName, 0, ::getCppuType( (sal_Int32 const *)0 ), PropertyAttribute::READONLY );
289 	throw UnknownPropertyException();
290 }
291 
292 ::sal_Bool SAL_CALL DisplayAccess::hasPropertyByName( const OUString& Name ) throw (RuntimeException)
293 {
294 	return Name.equalsAscii( pMultiDisplayName ) ||
295            Name.equalsAscii( pDefaultDisplayName );
296 }
297 
298 // XIndexAccess
299 ::sal_Int32 SAL_CALL DisplayAccess::getCount() throw (RuntimeException)
300 {
301 	return Application::GetScreenCount();
302 }
303 
304 Any SAL_CALL DisplayAccess::getByIndex( ::sal_Int32 Index ) throw (IndexOutOfBoundsException, WrappedTargetException, RuntimeException)
305 {
306 	if( (Index < 0) || (Index >= getCount()) )
307 		throw IndexOutOfBoundsException();
308 
309 	return makeAny( Reference< XPropertySet >( new DisplayInfo( Index ) ) );
310 }
311 
312 // XElementAccess
313 Type SAL_CALL DisplayAccess::getElementType(  ) throw (RuntimeException)
314 {
315 	return XPropertySet::static_type();
316 }
317 
318 ::sal_Bool SAL_CALL DisplayAccess::hasElements() throw (RuntimeException)
319 {
320 	return true;
321 }
322 
323 // XServiceInfo
324 OUString SAL_CALL DisplayAccess::getImplementationName(  ) throw (RuntimeException)
325 {
326 	return DisplayAccess_getImplementationName();
327 }
328 
329 ::sal_Bool SAL_CALL DisplayAccess::supportsService( const OUString& ServiceName ) throw (RuntimeException)
330 {
331 	Sequence< OUString > aSN( DisplayAccess_getSupportedServiceNames() );
332 	for( sal_Int32 nService = 0; nService < aSN.getLength(); nService++ )
333 	{
334 		if( aSN[nService] == ServiceName )
335 			return sal_True;
336 	}
337 	return sal_False;
338 }
339 
340 Sequence< OUString > SAL_CALL DisplayAccess::getSupportedServiceNames(  ) throw (RuntimeException)
341 {
342 	return DisplayAccess_getSupportedServiceNames();
343 }
344 
345 } // namespace vcl
346