~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/gfx/src/beos/nsRegionBeOS.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
4
 *
 
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/
 
9
 *
 
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.
 
14
 *
 
15
 * The Original Code is mozilla.org code.
 
16
 *
 
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.
 
21
 *
 
22
 * Contributor(s):
 
23
 *
 
24
 *
 
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.
 
36
 *
 
37
 * ***** END LICENSE BLOCK ***** */
 
38
 
 
39
#include <Region.h>
 
40
 
 
41
#include "nsRegionBeOS.h"
 
42
#include "prmem.h"
 
43
 
 
44
#ifdef DEBUG_REGIONS 
 
45
static int nRegions; 
 
46
#endif 
 
47
 
 
48
 
 
49
nsRegionBeOS :: nsRegionBeOS()
 
50
{
 
51
#ifdef DEBUG_REGIONS 
 
52
  ++nRegions; 
 
53
  printf("REGIONS+ = %i\n", nRegions); 
 
54
#endif 
 
55
 
 
56
  mRegion.MakeEmpty();
 
57
  mRegionType = eRegionComplexity_empty;
 
58
}
 
59
 
 
60
nsRegionBeOS :: ~nsRegionBeOS()
 
61
{
 
62
#ifdef DEBUG_REGIONS 
 
63
  --nRegions; 
 
64
  printf("REGIONS- = %i\n", nRegions); 
 
65
#endif 
 
66
 
 
67
  mRegion.MakeEmpty();
 
68
}
 
69
 
 
70
NS_IMPL_ISUPPORTS1(nsRegionBeOS, nsIRegion)
 
71
 
 
72
nsresult nsRegionBeOS :: Init(void)
 
73
{
 
74
  mRegion.MakeEmpty();
 
75
  mRegionType = eRegionComplexity_empty;
 
76
  return NS_OK;
 
77
}
 
78
 
 
79
void nsRegionBeOS :: SetTo(const nsIRegion &aRegion)
 
80
{
 
81
  Init();
 
82
  
 
83
  nsRegionBeOS *pRegion = (nsRegionBeOS *)&aRegion;
 
84
 
 
85
  mRegion = pRegion->mRegion;
 
86
  SetRegionType();
 
87
}
 
88
 
 
89
void nsRegionBeOS :: SetTo(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
 
90
{
 
91
  Init();
 
92
  
 
93
        mRegion.Set(BRect(aX, aY, aX + aWidth - 1, aY + aHeight - 1));
 
94
        SetRegionType();
 
95
}
 
96
 
 
97
void nsRegionBeOS :: Intersect(const nsIRegion &aRegion)
 
98
{
 
99
        nsRegionBeOS *pRegion = (nsRegionBeOS*)&aRegion;
 
100
 
 
101
        mRegion.IntersectWith(&pRegion->mRegion);
 
102
        SetRegionType();
 
103
}
 
104
 
 
105
void nsRegionBeOS :: Intersect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
 
106
{
 
107
  BRegion tRegion;
 
108
  tRegion.Set( BRect( aX, aY, aX + aWidth - 1, aY + aHeight - 1 ) );
 
109
  mRegion.IntersectWith(&tRegion);
 
110
  SetRegionType();
 
111
}
 
112
 
 
113
void nsRegionBeOS :: Union(const nsIRegion &aRegion)
 
114
{
 
115
        nsRegionBeOS *pRegion = (nsRegionBeOS*)&aRegion;
 
116
 
 
117
        mRegion.Include(&pRegion->mRegion);
 
118
        SetRegionType();
 
119
}
 
120
 
 
121
void nsRegionBeOS :: Union(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
 
122
{
 
123
        mRegion.Include(BRect(aX, aY, aX + aWidth - 1, aY + aHeight - 1));
 
124
        SetRegionType();
 
125
}
 
126
 
 
127
void nsRegionBeOS :: Subtract(const nsIRegion &aRegion)
 
128
{
 
129
  nsRegionBeOS *pRegion = (nsRegionBeOS*)&aRegion;
 
130
 
 
131
  mRegion.Exclude(&pRegion->mRegion);
 
132
  SetRegionType();
 
133
}
 
134
 
 
135
void nsRegionBeOS :: Subtract(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
 
136
{
 
137
        mRegion.Exclude(BRect(aX, aY, aX + aWidth - 1, aY + aHeight - 1));
 
138
        SetRegionType();
 
139
}
 
140
 
 
141
PRBool nsRegionBeOS :: IsEmpty(void)
 
142
{
 
143
  if( mRegionType == eRegionComplexity_empty )
 
144
    return PR_TRUE;
 
145
  return PR_FALSE;
 
146
}
 
147
 
 
148
PRBool nsRegionBeOS :: IsEqual(const nsIRegion &aRegion)
 
149
{
 
150
#ifdef DEBUG
 
151
  printf(" - nsRegionBeOS :: IsEqual not implemented!\n");
 
152
#endif
 
153
  return PR_FALSE;
 
154
}
 
155
 
 
156
void nsRegionBeOS :: GetBoundingBox(PRInt32 *aX, PRInt32 *aY, PRInt32 *aWidth, PRInt32 *aHeight)
 
157
{
 
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);
 
164
  }
 
165
  else
 
166
  {
 
167
        *aX = *aY = *aWidth = *aHeight = 0;
 
168
  }
 
169
}
 
170
 
 
171
void nsRegionBeOS :: Offset(PRInt32 aXOffset, PRInt32 aYOffset)
 
172
{
 
173
        mRegion.OffsetBy( aXOffset, aYOffset );
 
174
}
 
175
 
 
176
void nsRegionBeOS :: SetRegionType(void)
 
177
{
 
178
  if(mRegion.CountRects() == 1)
 
179
    mRegionType = eRegionComplexity_rect ;
 
180
  else if(mRegion.CountRects() > 1)
 
181
    mRegionType = eRegionComplexity_complex ;
 
182
  else
 
183
    mRegionType = eRegionComplexity_empty;
 
184
}
 
185
 
 
186
PRBool nsRegionBeOS :: ContainsRect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
 
187
{
 
188
        return mRegion.Intersects(BRect(aX, aY, aX + aWidth - 1, aY + aHeight - 1));
 
189
}
 
190
 
 
191
NS_IMETHODIMP nsRegionBeOS :: GetRects(nsRegionRectSet **aRects)
 
192
{
 
193
        nsRegionRectSet   *rects;
 
194
        int               nbox;
 
195
        nsRegionRect      *rect;
 
196
        
 
197
        NS_ASSERTION(!(nsnull == aRects), "bad ptr");
 
198
        
 
199
        //code lifted from old xfe. MMP
 
200
        
 
201
        nbox = mRegion.CountRects();
 
202
        
 
203
        rects = *aRects;
 
204
        
 
205
        if ((nsnull == rects) || (rects->mRectsLen < (PRUint32)nbox))
 
206
        {
 
207
                void *buf = PR_Realloc(rects, sizeof(nsRegionRectSet) + (sizeof(nsRegionRect) * (nbox - 1)));
 
208
 
 
209
                if(nsnull == buf)
 
210
                {
 
211
                        if(nsnull != rects)
 
212
                                rects->mNumRects = 0;
 
213
 
 
214
                        return NS_OK;
 
215
                }
 
216
 
 
217
                rects = (nsRegionRectSet *)buf;
 
218
                rects->mRectsLen = nbox;
 
219
        }
 
220
 
 
221
        rects->mNumRects = nbox;
 
222
        rects->mArea = 0;
 
223
        rect = &rects->mRects[0];
 
224
 
 
225
        for(int32 i = 0; i < nbox; i++)
 
226
        {
 
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); 
 
232
 
 
233
                rects->mArea += rect->width * rect->height;
 
234
 
 
235
                rect++;
 
236
        }
 
237
 
 
238
        *aRects = rects;
 
239
 
 
240
        return NS_OK;
 
241
}
 
242
 
 
243
NS_IMETHODIMP nsRegionBeOS :: FreeRects(nsRegionRectSet *aRects)
 
244
{
 
245
        if(nsnull != aRects)
 
246
                PR_Free((void *)aRects);
 
247
 
 
248
        return NS_OK;
 
249
}
 
250
 
 
251
NS_IMETHODIMP nsRegionBeOS :: GetNativeRegion(void *&aRegion) const
 
252
{
 
253
        aRegion = (void *)&mRegion;
 
254
        return NS_OK;
 
255
}
 
256
 
 
257
NS_IMETHODIMP nsRegionBeOS :: GetRegionComplexity(nsRegionComplexity &aComplexity) const
 
258
{
 
259
        aComplexity = mRegionType;
 
260
        return NS_OK;
 
261
}