1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
40 #include "nsRegionBeOS.h"
48 nsRegionBeOS :: nsRegionBeOS()
52 printf("REGIONS+ = %i\n", nRegions
);
56 mRegionType
= eRegionComplexity_empty
;
59 nsRegionBeOS :: ~nsRegionBeOS()
63 printf("REGIONS- = %i\n", nRegions
);
69 NS_IMPL_ISUPPORTS1(nsRegionBeOS
, nsIRegion
)
71 nsresult
nsRegionBeOS :: Init(void)
74 mRegionType
= eRegionComplexity_empty
;
78 void nsRegionBeOS :: SetTo(const nsIRegion
&aRegion
)
82 nsRegionBeOS
*pRegion
= (nsRegionBeOS
*)&aRegion
;
84 mRegion
= pRegion
->mRegion
;
88 void nsRegionBeOS :: SetTo(PRInt32 aX
, PRInt32 aY
, PRInt32 aWidth
, PRInt32 aHeight
)
92 mRegion
.Set(BRect(aX
, aY
, aX
+ aWidth
- 1, aY
+ aHeight
- 1));
96 void nsRegionBeOS :: Intersect(const nsIRegion
&aRegion
)
98 nsRegionBeOS
*pRegion
= (nsRegionBeOS
*)&aRegion
;
100 mRegion
.IntersectWith(&pRegion
->mRegion
);
104 void nsRegionBeOS :: Intersect(PRInt32 aX
, PRInt32 aY
, PRInt32 aWidth
, PRInt32 aHeight
)
107 tRegion
.Set( BRect( aX
, aY
, aX
+ aWidth
- 1, aY
+ aHeight
- 1 ) );
108 mRegion
.IntersectWith(&tRegion
);
112 void nsRegionBeOS :: Union(const nsIRegion
&aRegion
)
114 nsRegionBeOS
*pRegion
= (nsRegionBeOS
*)&aRegion
;
116 mRegion
.Include(&pRegion
->mRegion
);
120 void nsRegionBeOS :: Union(PRInt32 aX
, PRInt32 aY
, PRInt32 aWidth
, PRInt32 aHeight
)
122 mRegion
.Include(BRect(aX
, aY
, aX
+ aWidth
- 1, aY
+ aHeight
- 1));
126 void nsRegionBeOS :: Subtract(const nsIRegion
&aRegion
)
128 nsRegionBeOS
*pRegion
= (nsRegionBeOS
*)&aRegion
;
130 mRegion
.Exclude(&pRegion
->mRegion
);
134 void nsRegionBeOS :: Subtract(PRInt32 aX
, PRInt32 aY
, PRInt32 aWidth
, PRInt32 aHeight
)
136 mRegion
.Exclude(BRect(aX
, aY
, aX
+ aWidth
- 1, aY
+ aHeight
- 1));
140 PRBool
nsRegionBeOS :: IsEmpty(void)
142 if( mRegionType
== eRegionComplexity_empty
)
147 PRBool
nsRegionBeOS :: IsEqual(const nsIRegion
&aRegion
)
150 printf(" - nsRegionBeOS :: IsEqual not implemented!\n");
155 void nsRegionBeOS :: GetBoundingBox(PRInt32
*aX
, PRInt32
*aY
, PRInt32
*aWidth
, PRInt32
*aHeight
)
157 if( mRegion
.CountRects() ) {
158 BRect rect
= mRegion
.Frame();
159 *aX
= nscoord(rect
.left
);
160 *aY
= nscoord(rect
.top
);
161 *aWidth
= nscoord(rect
.Width()+1);
162 *aHeight
= nscoord(rect
.Height()+1);
166 *aX
= *aY
= *aWidth
= *aHeight
= 0;
170 void nsRegionBeOS :: Offset(PRInt32 aXOffset
, PRInt32 aYOffset
)
172 mRegion
.OffsetBy( aXOffset
, aYOffset
);
175 void nsRegionBeOS :: SetRegionType(void)
177 if(mRegion
.CountRects() == 1)
178 mRegionType
= eRegionComplexity_rect
;
179 else if(mRegion
.CountRects() > 1)
180 mRegionType
= eRegionComplexity_complex
;
182 mRegionType
= eRegionComplexity_empty
;
185 PRBool
nsRegionBeOS :: ContainsRect(PRInt32 aX
, PRInt32 aY
, PRInt32 aWidth
, PRInt32 aHeight
)
187 return mRegion
.Intersects(BRect(aX
, aY
, aX
+ aWidth
- 1, aY
+ aHeight
- 1));
190 NS_IMETHODIMP
nsRegionBeOS :: GetRects(nsRegionRectSet
**aRects
)
192 nsRegionRectSet
*rects
;
196 NS_ASSERTION(!(nsnull
== aRects
), "bad ptr");
198 //code lifted from old xfe. MMP
200 nbox
= mRegion
.CountRects();
204 if ((nsnull
== rects
) || (rects
->mRectsLen
< (PRUint32
)nbox
))
206 void *buf
= PR_Realloc(rects
, sizeof(nsRegionRectSet
) + (sizeof(nsRegionRect
) * (nbox
- 1)));
211 rects
->mNumRects
= 0;
216 rects
= (nsRegionRectSet
*)buf
;
217 rects
->mRectsLen
= nbox
;
220 rects
->mNumRects
= nbox
;
222 rect
= &rects
->mRects
[0];
224 for(int32 i
= 0; i
< nbox
; i
++)
226 BRect r
= mRegion
.RectAt(i
);
227 rect
->x
= nscoord(r
.left
);
228 rect
->width
= nscoord(r
.right
- r
.left
+ 1);
229 rect
->y
= nscoord(r
.top
);
230 rect
->height
= nscoord(r
.bottom
- r
.top
+ 1);
232 rects
->mArea
+= rect
->width
* rect
->height
;
242 NS_IMETHODIMP
nsRegionBeOS :: FreeRects(nsRegionRectSet
*aRects
)
245 PR_Free((void *)aRects
);
250 NS_IMETHODIMP
nsRegionBeOS :: GetNativeRegion(void *&aRegion
) const
252 aRegion
= (void *)&mRegion
;
256 NS_IMETHODIMP
nsRegionBeOS :: GetRegionComplexity(nsRegionComplexity
&aComplexity
) const
258 aComplexity
= mRegionType
;