Bug 435531 ? problem saving login when form or existing login is password-only. r...
[wine-gecko.git] / gfx / src / beos / nsRegionBeOS.cpp
blobf4b9372cf42e4db3a29ea08cb355f65ca849fd6b
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
13 * License.
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.
22 * Contributor(s):
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 ***** */
38 #include <Region.h>
40 #include "nsRegionBeOS.h"
41 #include "prmem.h"
43 #ifdef DEBUG_REGIONS
44 static int nRegions;
45 #endif
48 nsRegionBeOS :: nsRegionBeOS()
50 #ifdef DEBUG_REGIONS
51 ++nRegions;
52 printf("REGIONS+ = %i\n", nRegions);
53 #endif
55 mRegion.MakeEmpty();
56 mRegionType = eRegionComplexity_empty;
59 nsRegionBeOS :: ~nsRegionBeOS()
61 #ifdef DEBUG_REGIONS
62 --nRegions;
63 printf("REGIONS- = %i\n", nRegions);
64 #endif
66 mRegion.MakeEmpty();
69 NS_IMPL_ISUPPORTS1(nsRegionBeOS, nsIRegion)
71 nsresult nsRegionBeOS :: Init(void)
73 mRegion.MakeEmpty();
74 mRegionType = eRegionComplexity_empty;
75 return NS_OK;
78 void nsRegionBeOS :: SetTo(const nsIRegion &aRegion)
80 Init();
82 nsRegionBeOS *pRegion = (nsRegionBeOS *)&aRegion;
84 mRegion = pRegion->mRegion;
85 SetRegionType();
88 void nsRegionBeOS :: SetTo(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
90 Init();
92 mRegion.Set(BRect(aX, aY, aX + aWidth - 1, aY + aHeight - 1));
93 SetRegionType();
96 void nsRegionBeOS :: Intersect(const nsIRegion &aRegion)
98 nsRegionBeOS *pRegion = (nsRegionBeOS*)&aRegion;
100 mRegion.IntersectWith(&pRegion->mRegion);
101 SetRegionType();
104 void nsRegionBeOS :: Intersect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
106 BRegion tRegion;
107 tRegion.Set( BRect( aX, aY, aX + aWidth - 1, aY + aHeight - 1 ) );
108 mRegion.IntersectWith(&tRegion);
109 SetRegionType();
112 void nsRegionBeOS :: Union(const nsIRegion &aRegion)
114 nsRegionBeOS *pRegion = (nsRegionBeOS*)&aRegion;
116 mRegion.Include(&pRegion->mRegion);
117 SetRegionType();
120 void nsRegionBeOS :: Union(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
122 mRegion.Include(BRect(aX, aY, aX + aWidth - 1, aY + aHeight - 1));
123 SetRegionType();
126 void nsRegionBeOS :: Subtract(const nsIRegion &aRegion)
128 nsRegionBeOS *pRegion = (nsRegionBeOS*)&aRegion;
130 mRegion.Exclude(&pRegion->mRegion);
131 SetRegionType();
134 void nsRegionBeOS :: Subtract(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
136 mRegion.Exclude(BRect(aX, aY, aX + aWidth - 1, aY + aHeight - 1));
137 SetRegionType();
140 PRBool nsRegionBeOS :: IsEmpty(void)
142 if( mRegionType == eRegionComplexity_empty )
143 return PR_TRUE;
144 return PR_FALSE;
147 PRBool nsRegionBeOS :: IsEqual(const nsIRegion &aRegion)
149 #ifdef DEBUG
150 printf(" - nsRegionBeOS :: IsEqual not implemented!\n");
151 #endif
152 return PR_FALSE;
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);
164 else
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 ;
181 else
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;
193 int nbox;
194 nsRegionRect *rect;
196 NS_ASSERTION(!(nsnull == aRects), "bad ptr");
198 //code lifted from old xfe. MMP
200 nbox = mRegion.CountRects();
202 rects = *aRects;
204 if ((nsnull == rects) || (rects->mRectsLen < (PRUint32)nbox))
206 void *buf = PR_Realloc(rects, sizeof(nsRegionRectSet) + (sizeof(nsRegionRect) * (nbox - 1)));
208 if(nsnull == buf)
210 if(nsnull != rects)
211 rects->mNumRects = 0;
213 return NS_OK;
216 rects = (nsRegionRectSet *)buf;
217 rects->mRectsLen = nbox;
220 rects->mNumRects = nbox;
221 rects->mArea = 0;
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;
234 rect++;
237 *aRects = rects;
239 return NS_OK;
242 NS_IMETHODIMP nsRegionBeOS :: FreeRects(nsRegionRectSet *aRects)
244 if(nsnull != aRects)
245 PR_Free((void *)aRects);
247 return NS_OK;
250 NS_IMETHODIMP nsRegionBeOS :: GetNativeRegion(void *&aRegion) const
252 aRegion = (void *)&mRegion;
253 return NS_OK;
256 NS_IMETHODIMP nsRegionBeOS :: GetRegionComplexity(nsRegionComplexity &aComplexity) const
258 aComplexity = mRegionType;
259 return NS_OK;