1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Netscape Public License
6
* Version 1.1 (the "License"); you may not use this file except in
7
* compliance with the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/NPL/
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.
25
* Alternatively, the contents of this file may be used under the terms of
26
* either the GNU General Public License Version 2 or later (the "GPL"), or
27
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28
* in which case the provisions of the GPL or the LGPL are applicable instead
29
* of those above. If you wish to allow use of your version of this file only
30
* under the terms of either the GPL or the LGPL, and not to allow others to
31
* use your version of this file under the terms of the NPL, indicate your
32
* decision by deleting the provisions above and replace them with the notice
33
* and other provisions required by the GPL or the LGPL. If you do not delete
34
* the provisions above, a recipient may use your version of this file under
35
* the terms of any one of the NPL, the GPL or the LGPL.
37
* ***** END LICENSE BLOCK ***** */
41
#include "nsRegionBeOS.h"
49
nsRegionBeOS :: nsRegionBeOS()
53
printf("REGIONS+ = %i\n", nRegions);
57
mRegionType = eRegionComplexity_empty;
60
nsRegionBeOS :: ~nsRegionBeOS()
64
printf("REGIONS- = %i\n", nRegions);
70
NS_IMPL_ISUPPORTS1(nsRegionBeOS, nsIRegion)
72
nsresult nsRegionBeOS :: Init(void)
75
mRegionType = eRegionComplexity_empty;
79
void nsRegionBeOS :: SetTo(const nsIRegion &aRegion)
83
nsRegionBeOS *pRegion = (nsRegionBeOS *)&aRegion;
85
mRegion = pRegion->mRegion;
89
void nsRegionBeOS :: SetTo(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
93
mRegion.Set(BRect(aX, aY, aX + aWidth - 1, aY + aHeight - 1));
97
void nsRegionBeOS :: Intersect(const nsIRegion &aRegion)
99
nsRegionBeOS *pRegion = (nsRegionBeOS*)&aRegion;
101
mRegion.IntersectWith(&pRegion->mRegion);
105
void nsRegionBeOS :: Intersect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
108
tRegion.Set( BRect( aX, aY, aX + aWidth - 1, aY + aHeight - 1 ) );
109
mRegion.IntersectWith(&tRegion);
113
void nsRegionBeOS :: Union(const nsIRegion &aRegion)
115
nsRegionBeOS *pRegion = (nsRegionBeOS*)&aRegion;
117
mRegion.Include(&pRegion->mRegion);
121
void nsRegionBeOS :: Union(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
123
mRegion.Include(BRect(aX, aY, aX + aWidth - 1, aY + aHeight - 1));
127
void nsRegionBeOS :: Subtract(const nsIRegion &aRegion)
129
nsRegionBeOS *pRegion = (nsRegionBeOS*)&aRegion;
131
mRegion.Exclude(&pRegion->mRegion);
135
void nsRegionBeOS :: Subtract(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
137
mRegion.Exclude(BRect(aX, aY, aX + aWidth - 1, aY + aHeight - 1));
141
PRBool nsRegionBeOS :: IsEmpty(void)
143
if( mRegionType == eRegionComplexity_empty )
148
PRBool nsRegionBeOS :: IsEqual(const nsIRegion &aRegion)
151
printf(" - nsRegionBeOS :: IsEqual not implemented!\n");
156
void nsRegionBeOS :: GetBoundingBox(PRInt32 *aX, PRInt32 *aY, PRInt32 *aWidth, PRInt32 *aHeight)
158
if( mRegion.CountRects() ) {
159
BRect rect = mRegion.Frame();
160
*aX = nscoord(rect.left);
161
*aY = nscoord(rect.top);
162
*aWidth = nscoord(rect.Width()+1);
163
*aHeight = nscoord(rect.Height()+1);
167
*aX = *aY = *aWidth = *aHeight = 0;
171
void nsRegionBeOS :: Offset(PRInt32 aXOffset, PRInt32 aYOffset)
173
mRegion.OffsetBy( aXOffset, aYOffset );
176
void nsRegionBeOS :: SetRegionType(void)
178
if(mRegion.CountRects() == 1)
179
mRegionType = eRegionComplexity_rect ;
180
else if(mRegion.CountRects() > 1)
181
mRegionType = eRegionComplexity_complex ;
183
mRegionType = eRegionComplexity_empty;
186
PRBool nsRegionBeOS :: ContainsRect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
188
return mRegion.Intersects(BRect(aX, aY, aX + aWidth - 1, aY + aHeight - 1));
191
NS_IMETHODIMP nsRegionBeOS :: GetRects(nsRegionRectSet **aRects)
193
nsRegionRectSet *rects;
197
NS_ASSERTION(!(nsnull == aRects), "bad ptr");
199
//code lifted from old xfe. MMP
201
nbox = mRegion.CountRects();
205
if ((nsnull == rects) || (rects->mRectsLen < (PRUint32)nbox))
207
void *buf = PR_Realloc(rects, sizeof(nsRegionRectSet) + (sizeof(nsRegionRect) * (nbox - 1)));
212
rects->mNumRects = 0;
217
rects = (nsRegionRectSet *)buf;
218
rects->mRectsLen = nbox;
221
rects->mNumRects = nbox;
223
rect = &rects->mRects[0];
225
for(int32 i = 0; i < nbox; i++)
227
BRect r = mRegion.RectAt(i);
228
rect->x = nscoord(r.left);
229
rect->width = nscoord(r.right - r.left + 1);
230
rect->y = nscoord(r.top);
231
rect->height = nscoord(r.bottom - r.top + 1);
233
rects->mArea += rect->width * rect->height;
243
NS_IMETHODIMP nsRegionBeOS :: FreeRects(nsRegionRectSet *aRects)
246
PR_Free((void *)aRects);
251
NS_IMETHODIMP nsRegionBeOS :: GetNativeRegion(void *&aRegion) const
253
aRegion = (void *)&mRegion;
257
NS_IMETHODIMP nsRegionBeOS :: GetRegionComplexity(nsRegionComplexity &aComplexity) const
259
aComplexity = mRegionType;