xref: /aoo4110/main/toolkit/source/awt/vclxregion.cxx (revision b1cdbd2c)
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_toolkit.hxx"
26 
27 
28 #include <toolkit/awt/vclxregion.hxx>
29 #include <toolkit/helper/macros.hxx>
30 #include <toolkit/helper/vclunohelper.hxx>
31 #include <toolkit/helper/convert.hxx>
32 #include <cppuhelper/typeprovider.hxx>
33 #include <rtl/memory.h>
34 #include <rtl/uuid.h>
35 #include <vcl/svapp.hxx>
36 
37 //	----------------------------------------------------
38 //	class VCLXRegion
39 //	----------------------------------------------------
VCLXRegion()40 VCLXRegion::VCLXRegion()
41 {
42 }
43 
~VCLXRegion()44 VCLXRegion::~VCLXRegion()
45 {
46 }
47 
48 // ::com::sun::star::uno::XInterface
queryInterface(const::com::sun::star::uno::Type & rType)49 ::com::sun::star::uno::Any VCLXRegion::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException)
50 {
51 	::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType,
52 										SAL_STATIC_CAST( ::com::sun::star::awt::XRegion*, this ),
53 										SAL_STATIC_CAST( ::com::sun::star::lang::XUnoTunnel*, this ),
54 										SAL_STATIC_CAST( ::com::sun::star::lang::XTypeProvider*, this ) );
55 	return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ));
56 }
57 
58 // ::com::sun::star::lang::XUnoTunnel
59 IMPL_XUNOTUNNEL( VCLXRegion )
60 
61 // ::com::sun::star::lang::XTypeProvider
IMPL_XTYPEPROVIDER_START(VCLXRegion)62 IMPL_XTYPEPROVIDER_START( VCLXRegion )
63 	getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XRegion>* ) NULL )
64 IMPL_XTYPEPROVIDER_END
65 
66 
67 
68 ::com::sun::star::awt::Rectangle VCLXRegion::getBounds() throw(::com::sun::star::uno::RuntimeException)
69 {
70 	::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
71 
72 	return AWTRectangle( maRegion.GetBoundRect() );
73 }
74 
clear()75 void VCLXRegion::clear() throw(::com::sun::star::uno::RuntimeException)
76 {
77 	::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
78 
79 	maRegion.SetEmpty();
80 }
81 
move(sal_Int32 nHorzMove,sal_Int32 nVertMove)82 void VCLXRegion::move( sal_Int32 nHorzMove, sal_Int32 nVertMove ) throw(::com::sun::star::uno::RuntimeException)
83 {
84 	::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
85 
86 	maRegion.Move( nHorzMove, nVertMove );
87 }
88 
unionRectangle(const::com::sun::star::awt::Rectangle & rRect)89 void VCLXRegion::unionRectangle( const ::com::sun::star::awt::Rectangle& rRect ) throw(::com::sun::star::uno::RuntimeException)
90 {
91 	::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
92 
93 	maRegion.Union( VCLRectangle( rRect ) );
94 }
95 
intersectRectangle(const::com::sun::star::awt::Rectangle & rRect)96 void VCLXRegion::intersectRectangle( const ::com::sun::star::awt::Rectangle& rRect ) throw(::com::sun::star::uno::RuntimeException)
97 {
98 	::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
99 
100 	maRegion.Intersect( VCLRectangle( rRect ) );
101 }
102 
excludeRectangle(const::com::sun::star::awt::Rectangle & rRect)103 void VCLXRegion::excludeRectangle( const ::com::sun::star::awt::Rectangle& rRect ) throw(::com::sun::star::uno::RuntimeException)
104 {
105 	::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
106 
107 	maRegion.Exclude( VCLRectangle( rRect ) );
108 }
109 
xOrRectangle(const::com::sun::star::awt::Rectangle & rRect)110 void VCLXRegion::xOrRectangle( const ::com::sun::star::awt::Rectangle& rRect ) throw(::com::sun::star::uno::RuntimeException)
111 {
112 	::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
113 
114 	maRegion.XOr( VCLRectangle( rRect ) );
115 }
116 
unionRegion(const::com::sun::star::uno::Reference<::com::sun::star::awt::XRegion> & rxRegion)117 void VCLXRegion::unionRegion( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XRegion >& rxRegion ) throw(::com::sun::star::uno::RuntimeException)
118 {
119 	::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
120 
121 	if ( rxRegion.is() )
122 		maRegion.Union( VCLUnoHelper::GetRegion( rxRegion ) );
123 }
124 
intersectRegion(const::com::sun::star::uno::Reference<::com::sun::star::awt::XRegion> & rxRegion)125 void VCLXRegion::intersectRegion( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XRegion >& rxRegion ) throw(::com::sun::star::uno::RuntimeException)
126 {
127 	::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
128 
129 	if ( rxRegion.is() )
130 		maRegion.Intersect( VCLUnoHelper::GetRegion( rxRegion ) );
131 }
132 
excludeRegion(const::com::sun::star::uno::Reference<::com::sun::star::awt::XRegion> & rxRegion)133 void VCLXRegion::excludeRegion( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XRegion >& rxRegion ) throw(::com::sun::star::uno::RuntimeException)
134 {
135 	::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
136 
137 	if ( rxRegion.is() )
138 		maRegion.Exclude( VCLUnoHelper::GetRegion( rxRegion ) );
139 }
140 
xOrRegion(const::com::sun::star::uno::Reference<::com::sun::star::awt::XRegion> & rxRegion)141 void VCLXRegion::xOrRegion( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XRegion >& rxRegion ) throw(::com::sun::star::uno::RuntimeException)
142 {
143 	::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
144 
145 	if ( rxRegion.is() )
146 		maRegion.XOr( VCLUnoHelper::GetRegion( rxRegion ) );
147 }
148 
getRectangles()149 ::com::sun::star::uno::Sequence< ::com::sun::star::awt::Rectangle > VCLXRegion::getRectangles() throw(::com::sun::star::uno::RuntimeException)
150 {
151 	::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
152 
153     RectangleVector aRectangles;
154     maRegion.GetRegionRectangles(aRectangles);
155 
156 //    sal_uLong nRects = maRegion.GetRectCount();
157 	::com::sun::star::uno::Sequence< ::com::sun::star::awt::Rectangle > aRects(aRectangles.size());
158     sal_uInt32 a(0);
159 
160     for(RectangleVector::const_iterator aRectIter(aRectangles.begin()); aRectIter != aRectangles.end(); aRectIter++)
161     {
162         aRects.getArray()[a++] = AWTRectangle(*aRectIter);
163     }
164 
165 	//Rectangle aRect;
166 	//sal_uInt32 nR = 0;
167 	//RegionHandle h = maRegion.BeginEnumRects();
168 	//while ( maRegion.GetEnumRects( h, aRect ) )
169 	//	aRects.getArray()[nR++] = AWTRectangle( aRect );
170 	//maRegion.EndEnumRects( h );
171 
172 	return aRects;
173 }
174 
175 
176 
177