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