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