xref: /aoo41x/main/toolkit/source/awt/vclxregion.cxx (revision b0724fc6)
1*b0724fc6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b0724fc6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b0724fc6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b0724fc6SAndrew Rist  * distributed with this work for additional information
6*b0724fc6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b0724fc6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b0724fc6SAndrew Rist  * "License"); you may not use this file except in compliance
9*b0724fc6SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*b0724fc6SAndrew Rist  *
11*b0724fc6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*b0724fc6SAndrew Rist  *
13*b0724fc6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b0724fc6SAndrew Rist  * software distributed under the License is distributed on an
15*b0724fc6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b0724fc6SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b0724fc6SAndrew Rist  * specific language governing permissions and limitations
18*b0724fc6SAndrew Rist  * under the License.
19*b0724fc6SAndrew Rist  *
20*b0724fc6SAndrew Rist  *************************************************************/
21*b0724fc6SAndrew Rist 
22*b0724fc6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_toolkit.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <toolkit/awt/vclxregion.hxx>
29cdf0e10cSrcweir #include <toolkit/helper/macros.hxx>
30cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
31cdf0e10cSrcweir #include <toolkit/helper/convert.hxx>
32cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
33cdf0e10cSrcweir #include <rtl/memory.h>
34cdf0e10cSrcweir #include <rtl/uuid.h>
35cdf0e10cSrcweir #include <vcl/svapp.hxx>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir //	----------------------------------------------------
38cdf0e10cSrcweir //	class VCLXRegion
39cdf0e10cSrcweir //	----------------------------------------------------
40cdf0e10cSrcweir VCLXRegion::VCLXRegion()
41cdf0e10cSrcweir {
42cdf0e10cSrcweir }
43cdf0e10cSrcweir 
44cdf0e10cSrcweir VCLXRegion::~VCLXRegion()
45cdf0e10cSrcweir {
46cdf0e10cSrcweir }
47cdf0e10cSrcweir 
48cdf0e10cSrcweir // ::com::sun::star::uno::XInterface
49cdf0e10cSrcweir ::com::sun::star::uno::Any VCLXRegion::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException)
50cdf0e10cSrcweir {
51cdf0e10cSrcweir 	::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType,
52cdf0e10cSrcweir 										SAL_STATIC_CAST( ::com::sun::star::awt::XRegion*, this ),
53cdf0e10cSrcweir 										SAL_STATIC_CAST( ::com::sun::star::lang::XUnoTunnel*, this ),
54cdf0e10cSrcweir 										SAL_STATIC_CAST( ::com::sun::star::lang::XTypeProvider*, this ) );
55cdf0e10cSrcweir 	return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ));
56cdf0e10cSrcweir }
57cdf0e10cSrcweir 
58cdf0e10cSrcweir // ::com::sun::star::lang::XUnoTunnel
59cdf0e10cSrcweir IMPL_XUNOTUNNEL( VCLXRegion )
60cdf0e10cSrcweir 
61cdf0e10cSrcweir // ::com::sun::star::lang::XTypeProvider
62cdf0e10cSrcweir IMPL_XTYPEPROVIDER_START( VCLXRegion )
63cdf0e10cSrcweir 	getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XRegion>* ) NULL )
64cdf0e10cSrcweir IMPL_XTYPEPROVIDER_END
65cdf0e10cSrcweir 
66cdf0e10cSrcweir 
67cdf0e10cSrcweir 
68cdf0e10cSrcweir ::com::sun::star::awt::Rectangle VCLXRegion::getBounds() throw(::com::sun::star::uno::RuntimeException)
69cdf0e10cSrcweir {
70cdf0e10cSrcweir 	::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 	return AWTRectangle( maRegion.GetBoundRect() );
73cdf0e10cSrcweir }
74cdf0e10cSrcweir 
75cdf0e10cSrcweir void VCLXRegion::clear() throw(::com::sun::star::uno::RuntimeException)
76cdf0e10cSrcweir {
77cdf0e10cSrcweir 	::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
78cdf0e10cSrcweir 
79cdf0e10cSrcweir 	maRegion.SetEmpty();
80cdf0e10cSrcweir }
81cdf0e10cSrcweir 
82cdf0e10cSrcweir void VCLXRegion::move( sal_Int32 nHorzMove, sal_Int32 nVertMove ) throw(::com::sun::star::uno::RuntimeException)
83cdf0e10cSrcweir {
84cdf0e10cSrcweir 	::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
85cdf0e10cSrcweir 
86cdf0e10cSrcweir 	maRegion.Move( nHorzMove, nVertMove );
87cdf0e10cSrcweir }
88cdf0e10cSrcweir 
89cdf0e10cSrcweir void VCLXRegion::unionRectangle( const ::com::sun::star::awt::Rectangle& rRect ) throw(::com::sun::star::uno::RuntimeException)
90cdf0e10cSrcweir {
91cdf0e10cSrcweir 	::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 	maRegion.Union( VCLRectangle( rRect ) );
94cdf0e10cSrcweir }
95cdf0e10cSrcweir 
96cdf0e10cSrcweir void VCLXRegion::intersectRectangle( const ::com::sun::star::awt::Rectangle& rRect ) throw(::com::sun::star::uno::RuntimeException)
97cdf0e10cSrcweir {
98cdf0e10cSrcweir 	::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
99cdf0e10cSrcweir 
100cdf0e10cSrcweir 	maRegion.Intersect( VCLRectangle( rRect ) );
101cdf0e10cSrcweir }
102cdf0e10cSrcweir 
103cdf0e10cSrcweir void VCLXRegion::excludeRectangle( const ::com::sun::star::awt::Rectangle& rRect ) throw(::com::sun::star::uno::RuntimeException)
104cdf0e10cSrcweir {
105cdf0e10cSrcweir 	::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 	maRegion.Exclude( VCLRectangle( rRect ) );
108cdf0e10cSrcweir }
109cdf0e10cSrcweir 
110cdf0e10cSrcweir void VCLXRegion::xOrRectangle( const ::com::sun::star::awt::Rectangle& rRect ) throw(::com::sun::star::uno::RuntimeException)
111cdf0e10cSrcweir {
112cdf0e10cSrcweir 	::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
113cdf0e10cSrcweir 
114cdf0e10cSrcweir 	maRegion.XOr( VCLRectangle( rRect ) );
115cdf0e10cSrcweir }
116cdf0e10cSrcweir 
117cdf0e10cSrcweir void VCLXRegion::unionRegion( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XRegion >& rxRegion ) throw(::com::sun::star::uno::RuntimeException)
118cdf0e10cSrcweir {
119cdf0e10cSrcweir 	::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 	if ( rxRegion.is() )
122cdf0e10cSrcweir 		maRegion.Union( VCLUnoHelper::GetRegion( rxRegion ) );
123cdf0e10cSrcweir }
124cdf0e10cSrcweir 
125cdf0e10cSrcweir void VCLXRegion::intersectRegion( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XRegion >& rxRegion ) throw(::com::sun::star::uno::RuntimeException)
126cdf0e10cSrcweir {
127cdf0e10cSrcweir 	::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 	if ( rxRegion.is() )
130cdf0e10cSrcweir 		maRegion.Intersect( VCLUnoHelper::GetRegion( rxRegion ) );
131cdf0e10cSrcweir }
132cdf0e10cSrcweir 
133cdf0e10cSrcweir void VCLXRegion::excludeRegion( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XRegion >& rxRegion ) throw(::com::sun::star::uno::RuntimeException)
134cdf0e10cSrcweir {
135cdf0e10cSrcweir 	::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 	if ( rxRegion.is() )
138cdf0e10cSrcweir 		maRegion.Exclude( VCLUnoHelper::GetRegion( rxRegion ) );
139cdf0e10cSrcweir }
140cdf0e10cSrcweir 
141cdf0e10cSrcweir void VCLXRegion::xOrRegion( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XRegion >& rxRegion ) throw(::com::sun::star::uno::RuntimeException)
142cdf0e10cSrcweir {
143cdf0e10cSrcweir 	::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 	if ( rxRegion.is() )
146cdf0e10cSrcweir 		maRegion.XOr( VCLUnoHelper::GetRegion( rxRegion ) );
147cdf0e10cSrcweir }
148cdf0e10cSrcweir 
149cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::awt::Rectangle > VCLXRegion::getRectangles() throw(::com::sun::star::uno::RuntimeException)
150cdf0e10cSrcweir {
151cdf0e10cSrcweir 	::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 	sal_uLong nRects = maRegion.GetRectCount();
154cdf0e10cSrcweir 	::com::sun::star::uno::Sequence< ::com::sun::star::awt::Rectangle > aRects( nRects );
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 	Rectangle aRect;
157cdf0e10cSrcweir 	sal_uInt32 nR = 0;
158cdf0e10cSrcweir 	RegionHandle h = maRegion.BeginEnumRects();
159cdf0e10cSrcweir 	while ( maRegion.GetNextEnumRect( h, aRect ) )
160cdf0e10cSrcweir 		aRects.getArray()[nR++] = AWTRectangle( aRect );
161cdf0e10cSrcweir 	maRegion.EndEnumRects( h );
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 	return aRects;
164cdf0e10cSrcweir }
165cdf0e10cSrcweir 
166cdf0e10cSrcweir 
167cdf0e10cSrcweir 
168