1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: display.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_vcl.hxx"
33 #include <com/sun/star/container/XIndexAccess.hpp>
34 #include <com/sun/star/lang/XServiceInfo.hpp>
35 #include <com/sun/star/beans/XPropertySet.hpp>
36 #include <com/sun/star/beans/PropertyAttribute.hpp>
37 #include <com/sun/star/awt/Rectangle.hpp>
38 #include <com/sun/star/lang/DisposedException.hpp>
40 #include <vcl/svapp.hxx>
42 #include <cppuhelper/implbase3.hxx>
43 #include <cppuhelper/implbase4.hxx>
46 #include <tools/debug.hxx>
49 using ::rtl::OUString
;
50 using namespace ::com::sun::star::uno
;
51 using namespace ::com::sun::star::lang
;
52 using namespace ::com::sun::star::container
;
53 using namespace ::com::sun::star::beans
;
55 // -----------------------------------------------------------------------
60 class DisplayInfo
: public ::cppu::WeakAggImplHelper3
< XPropertySet
, XPropertySetInfo
, XServiceInfo
>
63 DisplayInfo( sal_uInt32 nDisplay
);
66 virtual Reference
< XPropertySetInfo
> SAL_CALL
getPropertySetInfo( ) throw (RuntimeException
);
67 virtual void SAL_CALL
setPropertyValue( const OUString
& aPropertyName
, const Any
& aValue
) throw (UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
, WrappedTargetException
, RuntimeException
);
68 virtual Any SAL_CALL
getPropertyValue( const OUString
& PropertyName
) throw (UnknownPropertyException
, WrappedTargetException
, RuntimeException
);
69 virtual void SAL_CALL
addPropertyChangeListener( const OUString
& aPropertyName
, const Reference
< XPropertyChangeListener
>& xListener
) throw (UnknownPropertyException
, WrappedTargetException
, RuntimeException
);
70 virtual void SAL_CALL
removePropertyChangeListener( const OUString
& aPropertyName
, const Reference
< XPropertyChangeListener
>& aListener
) throw (UnknownPropertyException
, WrappedTargetException
, RuntimeException
);
71 virtual void SAL_CALL
addVetoableChangeListener( const OUString
& PropertyName
, const Reference
< XVetoableChangeListener
>& aListener
) throw (UnknownPropertyException
, WrappedTargetException
, RuntimeException
);
72 virtual void SAL_CALL
removeVetoableChangeListener( const OUString
& PropertyName
, const Reference
< XVetoableChangeListener
>& aListener
) throw (UnknownPropertyException
, WrappedTargetException
, RuntimeException
);
75 virtual Sequence
< Property
> SAL_CALL
getProperties( ) throw (RuntimeException
);
76 virtual Property SAL_CALL
getPropertyByName( const OUString
& aName
) throw (UnknownPropertyException
, RuntimeException
);
77 virtual ::sal_Bool SAL_CALL
hasPropertyByName( const OUString
& Name
) throw (RuntimeException
);
80 virtual OUString SAL_CALL
getImplementationName( ) throw (RuntimeException
);
81 virtual ::sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) throw (RuntimeException
);
82 virtual Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) throw (RuntimeException
);
88 static const char* pScreenAreaName
= "ScreenArea";
89 static const char* pWorkAreaName
= "WorkArea";
90 static const char* pScreenName
= "ScreenName";
92 // --------------------------------------------------------------------
94 DisplayInfo::DisplayInfo( sal_uInt32 nDisplay
)
95 : mnDisplay( nDisplay
)
100 Reference
< XPropertySetInfo
> SAL_CALL
DisplayInfo::getPropertySetInfo( ) throw (RuntimeException
)
105 void SAL_CALL
DisplayInfo::setPropertyValue( const OUString
& /*aPropertyName* */, const Any
& /*aValue*/ ) throw (UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
, WrappedTargetException
, RuntimeException
)
107 throw PropertyVetoException();
110 Any SAL_CALL
DisplayInfo::getPropertyValue( const OUString
& PropertyName
) throw (UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
113 if( PropertyName
.equalsAscii( pScreenAreaName
) )
115 aRect
= Application::GetScreenPosSizePixel( mnDisplay
);
117 else if( PropertyName
.equalsAscii( pWorkAreaName
) )
119 aRect
= Application::GetWorkAreaPosSizePixel( mnDisplay
);
121 else if( PropertyName
.equalsAscii( pScreenName
) )
123 return Any( Application::GetScreenName( mnDisplay
) );
126 throw UnknownPropertyException();
128 return Any( com::sun::star::awt::Rectangle( aRect
.Left(), aRect
.Top(), aRect
.getWidth(), aRect
.getHeight() ) );
131 void SAL_CALL
DisplayInfo::addPropertyChangeListener( const OUString
&, const Reference
< XPropertyChangeListener
>& ) throw (UnknownPropertyException
, WrappedTargetException
, RuntimeException
) {}
132 void SAL_CALL
DisplayInfo::removePropertyChangeListener( const OUString
&, const Reference
< XPropertyChangeListener
>& ) throw (UnknownPropertyException
, WrappedTargetException
, RuntimeException
) {}
133 void SAL_CALL
DisplayInfo::addVetoableChangeListener( const OUString
&, const Reference
< XVetoableChangeListener
>& ) throw (UnknownPropertyException
, WrappedTargetException
, RuntimeException
) {}
134 void SAL_CALL
DisplayInfo::removeVetoableChangeListener( const OUString
&, const Reference
< XVetoableChangeListener
>& ) throw (UnknownPropertyException
, WrappedTargetException
, RuntimeException
) {}
137 Sequence
< Property
> SAL_CALL
DisplayInfo::getProperties( ) throw (RuntimeException
)
139 Sequence
< Property
> aProps(2);
140 aProps
[0] = getPropertyByName( OUString::createFromAscii( pScreenAreaName
) );
141 aProps
[1] = getPropertyByName( OUString::createFromAscii( pWorkAreaName
) );
145 Property SAL_CALL
DisplayInfo::getPropertyByName( const OUString
& aName
) throw (UnknownPropertyException
, RuntimeException
)
147 if( aName
.equalsAscii( pScreenAreaName
) ||
148 aName
.equalsAscii( pWorkAreaName
) )
149 return Property( aName
, 0, ::getCppuType( (::com::sun::star::awt::Rectangle
const *)0 ), PropertyAttribute::READONLY
);
150 throw UnknownPropertyException();
153 ::sal_Bool SAL_CALL
DisplayInfo::hasPropertyByName( const OUString
& Name
) throw (RuntimeException
)
155 return Name
.equalsAscii( pScreenAreaName
) ||
156 Name
.equalsAscii( pWorkAreaName
);
160 OUString SAL_CALL
DisplayInfo::getImplementationName( ) throw (RuntimeException
)
162 static OUString
aImplementationName( RTL_CONSTASCII_USTRINGPARAM( "vcl::DisplayInfo" ) );
163 return aImplementationName
;
166 ::sal_Bool SAL_CALL
DisplayInfo::supportsService( const OUString
& ServiceName
) throw (RuntimeException
)
168 Sequence
< OUString
> aSN( getSupportedServiceNames() );
169 for( sal_Int32 nService
= 0; nService
< aSN
.getLength(); nService
++ )
171 if( aSN
[nService
] == ServiceName
)
177 Sequence
< OUString
> SAL_CALL
DisplayInfo::getSupportedServiceNames( ) throw (RuntimeException
)
179 static OUString
aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.DisplayInfo" ) );
180 static Sequence
< OUString
> aServiceNames( &aServiceName
, 1 );
181 return aServiceNames
;
184 // ====================================================================
186 class DisplayAccess
: public ::cppu::WeakAggImplHelper4
< XPropertySet
, XPropertySetInfo
, XIndexAccess
, XServiceInfo
>
192 virtual Reference
< XPropertySetInfo
> SAL_CALL
getPropertySetInfo( ) throw (RuntimeException
);
193 virtual void SAL_CALL
setPropertyValue( const OUString
& aPropertyName
, const Any
& aValue
) throw (UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
, WrappedTargetException
, RuntimeException
);
194 virtual Any SAL_CALL
getPropertyValue( const OUString
& PropertyName
) throw (UnknownPropertyException
, WrappedTargetException
, RuntimeException
);
195 virtual void SAL_CALL
addPropertyChangeListener( const OUString
& aPropertyName
, const Reference
< XPropertyChangeListener
>& xListener
) throw (UnknownPropertyException
, WrappedTargetException
, RuntimeException
);
196 virtual void SAL_CALL
removePropertyChangeListener( const OUString
& aPropertyName
, const Reference
< XPropertyChangeListener
>& aListener
) throw (UnknownPropertyException
, WrappedTargetException
, RuntimeException
);
197 virtual void SAL_CALL
addVetoableChangeListener( const OUString
& PropertyName
, const Reference
< XVetoableChangeListener
>& aListener
) throw (UnknownPropertyException
, WrappedTargetException
, RuntimeException
);
198 virtual void SAL_CALL
removeVetoableChangeListener( const OUString
& PropertyName
, const Reference
< XVetoableChangeListener
>& aListener
) throw (UnknownPropertyException
, WrappedTargetException
, RuntimeException
);
201 virtual Sequence
< Property
> SAL_CALL
getProperties( ) throw (RuntimeException
);
202 virtual Property SAL_CALL
getPropertyByName( const OUString
& aName
) throw (UnknownPropertyException
, RuntimeException
);
203 virtual ::sal_Bool SAL_CALL
hasPropertyByName( const OUString
& Name
) throw (RuntimeException
);
206 virtual ::sal_Int32 SAL_CALL
getCount() throw (RuntimeException
);
207 virtual Any SAL_CALL
getByIndex( ::sal_Int32 Index
) throw (IndexOutOfBoundsException
, WrappedTargetException
, RuntimeException
);
210 virtual Type SAL_CALL
getElementType( ) throw (RuntimeException
);
211 virtual ::sal_Bool SAL_CALL
hasElements( ) throw (RuntimeException
);
214 virtual OUString SAL_CALL
getImplementationName( ) throw (RuntimeException
);
215 virtual ::sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) throw (RuntimeException
);
216 virtual Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) throw (RuntimeException
);
219 Sequence
< OUString
> DisplayAccess_getSupportedServiceNames()
221 static OUString
aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.DisplayAccess" ) );
222 static Sequence
< OUString
> aServiceNames( &aServiceName
, 1 );
223 return aServiceNames
;
226 OUString
DisplayAccess_getImplementationName()
228 return OUString( RTL_CONSTASCII_USTRINGPARAM( "vcl::DisplayAccess" ) );
231 Reference
< XInterface
> SAL_CALL
DisplayAccess_createInstance( const Reference
< XMultiServiceFactory
>& )
233 return static_cast< ::cppu::OWeakObject
* >( new DisplayAccess
);
236 DisplayAccess::DisplayAccess()
240 static const char* pMultiDisplayName
= "MultiDisplay";
241 static const char* pDefaultDisplayName
= "DefaultDisplay";
244 Reference
< XPropertySetInfo
> SAL_CALL
DisplayAccess::getPropertySetInfo( ) throw (RuntimeException
)
249 void SAL_CALL
DisplayAccess::setPropertyValue( const OUString
& /*aPropertyName* */, const Any
& /*aValue*/ ) throw (UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
, WrappedTargetException
, RuntimeException
)
251 throw PropertyVetoException();
254 Any SAL_CALL
DisplayAccess::getPropertyValue( const OUString
& PropertyName
) throw (UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
257 if( PropertyName
.equalsAscii( pMultiDisplayName
) )
259 aRet
<<= sal_Bool( Application::IsMultiDisplay() );
261 else if( PropertyName
.equalsAscii( pDefaultDisplayName
) )
263 aRet
<<= sal_Int32( Application::GetDefaultDisplayNumber() );
266 throw UnknownPropertyException();
271 void SAL_CALL
DisplayAccess::addPropertyChangeListener( const OUString
&, const Reference
< XPropertyChangeListener
>& ) throw (UnknownPropertyException
, WrappedTargetException
, RuntimeException
) {}
272 void SAL_CALL
DisplayAccess::removePropertyChangeListener( const OUString
&, const Reference
< XPropertyChangeListener
>& ) throw (UnknownPropertyException
, WrappedTargetException
, RuntimeException
) {}
273 void SAL_CALL
DisplayAccess::addVetoableChangeListener( const OUString
&, const Reference
< XVetoableChangeListener
>& ) throw (UnknownPropertyException
, WrappedTargetException
, RuntimeException
) {}
274 void SAL_CALL
DisplayAccess::removeVetoableChangeListener( const OUString
&, const Reference
< XVetoableChangeListener
>& ) throw (UnknownPropertyException
, WrappedTargetException
, RuntimeException
) {}
277 Sequence
< Property
> SAL_CALL
DisplayAccess::getProperties( ) throw (RuntimeException
)
279 Sequence
< Property
> aProps(2);
280 aProps
[0] = getPropertyByName( OUString::createFromAscii( pMultiDisplayName
) );
281 aProps
[1] = getPropertyByName( OUString::createFromAscii( pDefaultDisplayName
) );
285 Property SAL_CALL
DisplayAccess::getPropertyByName( const OUString
& aName
) throw (UnknownPropertyException
, RuntimeException
)
287 if( aName
.equalsAscii( pMultiDisplayName
) )
288 return Property( aName
, 0, ::getCppuType( (sal_Bool
const *)0 ), PropertyAttribute::READONLY
);
290 if( aName
.equalsAscii( pDefaultDisplayName
) )
291 return Property( aName
, 0, ::getCppuType( (sal_Int32
const *)0 ), PropertyAttribute::READONLY
);
292 throw UnknownPropertyException();
295 ::sal_Bool SAL_CALL
DisplayAccess::hasPropertyByName( const OUString
& Name
) throw (RuntimeException
)
297 return Name
.equalsAscii( pMultiDisplayName
) ||
298 Name
.equalsAscii( pDefaultDisplayName
);
302 ::sal_Int32 SAL_CALL
DisplayAccess::getCount() throw (RuntimeException
)
304 return Application::GetScreenCount();
307 Any SAL_CALL
DisplayAccess::getByIndex( ::sal_Int32 Index
) throw (IndexOutOfBoundsException
, WrappedTargetException
, RuntimeException
)
309 if( (Index
< 0) || (Index
>= getCount()) )
310 throw IndexOutOfBoundsException();
312 return makeAny( Reference
< XPropertySet
>( new DisplayInfo( Index
) ) );
316 Type SAL_CALL
DisplayAccess::getElementType( ) throw (RuntimeException
)
318 return XPropertySet::static_type();
321 ::sal_Bool SAL_CALL
DisplayAccess::hasElements() throw (RuntimeException
)
327 OUString SAL_CALL
DisplayAccess::getImplementationName( ) throw (RuntimeException
)
329 return DisplayAccess_getImplementationName();
332 ::sal_Bool SAL_CALL
DisplayAccess::supportsService( const OUString
& ServiceName
) throw (RuntimeException
)
334 Sequence
< OUString
> aSN( DisplayAccess_getSupportedServiceNames() );
335 for( sal_Int32 nService
= 0; nService
< aSN
.getLength(); nService
++ )
337 if( aSN
[nService
] == ServiceName
)
343 Sequence
< OUString
> SAL_CALL
DisplayAccess::getSupportedServiceNames( ) throw (RuntimeException
)
345 return DisplayAccess_getSupportedServiceNames();