1 /*******************************************************************************
2 * Copyright (c) 2000, 2014 IBM Corporation and others.
3 *
4 * This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
8 *
9 * SPDX-License-Identifier: EPL-2.0
10 *
11 * Contributors:
12 * IBM Corporation - initial API and implementation
13 *******************************************************************************/
14 package org.eclipse.swt.graphics;
15
16
17 import org.eclipse.swt.*;
18 import org.eclipse.swt.internal.*;
19 import org.eclipse.swt.internal.win32.*;
20
21 /**
22 * Instances of this class represent areas of an x-y coordinate
23 * system that are aggregates of the areas covered by a number
24 * of polygons.
25 * <p>
26 * Application code must explicitly invoke the <code>Region.dispose()</code>
27 * method to release the operating system resources managed by each instance
28 * when those instances are no longer required.
29 * </p>
30 *
31 * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: GraphicsExample</a>
32 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
33 */
34 public final class Region extends Resource {
35
36 /**
37 * the OS resource for the region
38 * (Warning: This field is platform dependent)
39 * <p>
40 * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
41 * public API. It is marked public only so that it can be shared
42 * within the packages provided by SWT. It is not available on all
43 * platforms and should never be accessed from application code.
44 * </p>
45 *
46 * @noreference This field is not intended to be referenced by clients.
47 */
48 public long handle;
49
50 /**
51 * Constructs a new empty region.
52 * <p>
53 * You must dispose the region when it is no longer required.
54 * </p>
55 *
56 * @exception SWTError <ul>
57 * <li>ERROR_NO_HANDLES if a handle could not be obtained for region creation</li>
58 * </ul>
59 *
60 * @see #dispose()
61 */
Region()62 public Region () {
63 this(null);
64 }
65
66 /**
67 * Constructs a new empty region.
68 * <p>
69 * You must dispose the region when it is no longer required.
70 * </p>
71 *
72 * @param device the device on which to allocate the region
73 *
74 * @exception IllegalArgumentException <ul>
75 * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
76 * </ul>
77 * @exception SWTError <ul>
78 * <li>ERROR_NO_HANDLES if a handle could not be obtained for region creation</li>
79 * </ul>
80 *
81 * @see #dispose()
82 *
83 * @since 3.0
84 */
Region(Device device)85 public Region (Device device) {
86 super(device);
87 handle = OS.CreateRectRgn (0, 0, 0, 0);
88 if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
89 init();
90 }
91
92 /**
93 * Constructs a new region given a handle to the operating
94 * system resources that it should represent.
95 *
96 * @param handle the handle for the result
97 */
Region(Device device, int handle)98 Region(Device device, int handle) {
99 super(device);
100 this.handle = handle;
101 }
102
103 /**
104 * Adds the given polygon to the collection of polygons
105 * the receiver maintains to describe its area.
106 *
107 * @param pointArray points that describe the polygon to merge with the receiver
108 *
109 * @exception IllegalArgumentException <ul>
110 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
111 * </ul>
112 * @exception SWTException <ul>
113 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
114 * </ul>
115 *
116 * @since 3.0
117 *
118 */
add(int[] pointArray)119 public void add (int[] pointArray) {
120 if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
121 if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
122 addInPixels(DPIUtil.autoScaleUp(pointArray));
123 }
124
addInPixels(int[] pointArray)125 void addInPixels (int[] pointArray) {
126 long polyRgn = OS.CreatePolygonRgn(pointArray, pointArray.length / 2, OS.ALTERNATE);
127 OS.CombineRgn (handle, handle, polyRgn, OS.RGN_OR);
128 OS.DeleteObject (polyRgn);
129 }
130
131 /**
132 * Adds the given rectangle to the collection of polygons
133 * the receiver maintains to describe its area.
134 *
135 * @param rect the rectangle to merge with the receiver
136 *
137 * @exception IllegalArgumentException <ul>
138 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
139 * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
140 * </ul>
141 * @exception SWTException <ul>
142 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
143 * </ul>
144 */
add(Rectangle rect)145 public void add (Rectangle rect) {
146 if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
147 if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
148 rect = DPIUtil.autoScaleUp(rect);
149 addInPixels(rect.x, rect.y, rect.width, rect.height);
150 }
151
152 /**
153 * Adds the given rectangle to the collection of polygons
154 * the receiver maintains to describe its area.
155 *
156 * @param x the x coordinate of the rectangle
157 * @param y the y coordinate of the rectangle
158 * @param width the width coordinate of the rectangle
159 * @param height the height coordinate of the rectangle
160 *
161 * @exception IllegalArgumentException <ul>
162 * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
163 * </ul>
164 * @exception SWTException <ul>
165 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
166 * </ul>
167 *
168 * @since 3.1
169 */
add(int x, int y, int width, int height)170 public void add (int x, int y, int width, int height) {
171 if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
172 addInPixels(DPIUtil.autoScaleUp(x), DPIUtil.autoScaleUp(y), DPIUtil.autoScaleUp(width), DPIUtil.autoScaleUp(height));
173 }
174
addInPixels(int x, int y, int width, int height)175 void addInPixels (int x, int y, int width, int height) {
176 if (width < 0 || height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
177 long rectRgn = OS.CreateRectRgn (x, y, x + width, y + height);
178 OS.CombineRgn (handle, handle, rectRgn, OS.RGN_OR);
179 OS.DeleteObject (rectRgn);
180 }
181
182 /**
183 * Adds all of the polygons which make up the area covered
184 * by the argument to the collection of polygons the receiver
185 * maintains to describe its area.
186 *
187 * @param region the region to merge
188 *
189 * @exception IllegalArgumentException <ul>
190 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
191 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
192 * </ul>
193 * @exception SWTException <ul>
194 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
195 * </ul>
196 */
add(Region region)197 public void add (Region region) {
198 if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
199 if (region == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
200 if (region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
201 OS.CombineRgn (handle, handle, region.handle, OS.RGN_OR);
202 }
203
204 /**
205 * Returns <code>true</code> if the point specified by the
206 * arguments is inside the area specified by the receiver,
207 * and <code>false</code> otherwise.
208 *
209 * @param x the x coordinate of the point to test for containment
210 * @param y the y coordinate of the point to test for containment
211 * @return <code>true</code> if the region contains the point and <code>false</code> otherwise
212 *
213 * @exception SWTException <ul>
214 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
215 * </ul>
216 */
contains(int x, int y)217 public boolean contains (int x, int y) {
218 if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
219 return containsInPixels(DPIUtil.autoScaleUp(x), DPIUtil.autoScaleUp(y));
220 }
221
containsInPixels(int x, int y)222 boolean containsInPixels (int x, int y) {
223 return OS.PtInRegion (handle, x, y);
224 }
225
226 /**
227 * Returns <code>true</code> if the given point is inside the
228 * area specified by the receiver, and <code>false</code>
229 * otherwise.
230 *
231 * @param pt the point to test for containment
232 * @return <code>true</code> if the region contains the point and <code>false</code> otherwise
233 *
234 * @exception IllegalArgumentException <ul>
235 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
236 * </ul>
237 * @exception SWTException <ul>
238 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
239 * </ul>
240 */
contains(Point pt)241 public boolean contains (Point pt) {
242 if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
243 if (pt == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
244 pt = DPIUtil.autoScaleUp(pt);
245 return containsInPixels(pt.x, pt.y);
246 }
247
248 @Override
destroy()249 void destroy () {
250 OS.DeleteObject(handle);
251 handle = 0;
252 }
253
254 /**
255 * Compares the argument to the receiver, and returns true
256 * if they represent the <em>same</em> object using a class
257 * specific comparison.
258 *
259 * @param object the object to compare with this object
260 * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
261 *
262 * @see #hashCode
263 */
264 @Override
equals(Object object)265 public boolean equals (Object object) {
266 if (this == object) return true;
267 if (!(object instanceof Region)) return false;
268 Region rgn = (Region)object;
269 return handle == rgn.handle;
270 }
271
272 /**
273 * Returns a rectangle which represents the rectangular
274 * union of the collection of polygons the receiver
275 * maintains to describe its area.
276 *
277 * @return a bounding rectangle for the region
278 *
279 * @exception SWTException <ul>
280 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
281 * </ul>
282 *
283 * @see Rectangle#union
284 */
getBounds()285 public Rectangle getBounds () {
286 if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
287 return DPIUtil.autoScaleDown(getBoundsInPixels());
288 }
289
getBoundsInPixels()290 Rectangle getBoundsInPixels() {
291 RECT rect = new RECT();
292 OS.GetRgnBox(handle, rect);
293 return new Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
294 }
295
296 /**
297 * Returns an integer hash code for the receiver. Any two
298 * objects that return <code>true</code> when passed to
299 * <code>equals</code> must return the same value for this
300 * method.
301 *
302 * @return the receiver's hash
303 *
304 * @see #equals
305 */
306 @Override
hashCode()307 public int hashCode () {
308 return (int)handle;
309 }
310
311 /**
312 * Intersects the given rectangle to the collection of polygons
313 * the receiver maintains to describe its area.
314 *
315 * @param rect the rectangle to intersect with the receiver
316 *
317 * @exception IllegalArgumentException <ul>
318 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
319 * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
320 * </ul>
321 * @exception SWTException <ul>
322 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
323 * </ul>
324 *
325 * @since 3.0
326 */
intersect(Rectangle rect)327 public void intersect (Rectangle rect) {
328 if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
329 if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
330 rect = DPIUtil.autoScaleUp(rect);
331 intersectInPixels(rect.x, rect.y, rect.width, rect.height);
332 }
333
334 /**
335 * Intersects the given rectangle to the collection of polygons
336 * the receiver maintains to describe its area.
337 *
338 * @param x the x coordinate of the rectangle
339 * @param y the y coordinate of the rectangle
340 * @param width the width coordinate of the rectangle
341 * @param height the height coordinate of the rectangle
342 *
343 * @exception IllegalArgumentException <ul>
344 * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
345 * </ul>
346 * @exception SWTException <ul>
347 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
348 * </ul>
349 *
350 * @since 3.1
351 */
intersect(int x, int y, int width, int height)352 public void intersect (int x, int y, int width, int height) {
353 if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
354 intersectInPixels(DPIUtil.autoScaleUp(x), DPIUtil.autoScaleUp(y), DPIUtil.autoScaleUp(width), DPIUtil.autoScaleUp(height));
355 }
356
intersectInPixels(int x, int y, int width, int height)357 void intersectInPixels (int x, int y, int width, int height) {
358 if (width < 0 || height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
359 long rectRgn = OS.CreateRectRgn (x, y, x + width, y + height);
360 OS.CombineRgn (handle, handle, rectRgn, OS.RGN_AND);
361 OS.DeleteObject (rectRgn);
362 }
363
364 /**
365 * Intersects all of the polygons which make up the area covered
366 * by the argument to the collection of polygons the receiver
367 * maintains to describe its area.
368 *
369 * @param region the region to intersect
370 *
371 * @exception IllegalArgumentException <ul>
372 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
373 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
374 * </ul>
375 * @exception SWTException <ul>
376 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
377 * </ul>
378 *
379 * @since 3.0
380 */
intersect(Region region)381 public void intersect (Region region) {
382 if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
383 if (region == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
384 if (region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
385 OS.CombineRgn (handle, handle, region.handle, OS.RGN_AND);
386 }
387
388 /**
389 * Returns <code>true</code> if the rectangle described by the
390 * arguments intersects with any of the polygons the receiver
391 * maintains to describe its area, and <code>false</code> otherwise.
392 *
393 * @param x the x coordinate of the origin of the rectangle
394 * @param y the y coordinate of the origin of the rectangle
395 * @param width the width of the rectangle
396 * @param height the height of the rectangle
397 * @return <code>true</code> if the rectangle intersects with the receiver, and <code>false</code> otherwise
398 *
399 * @exception SWTException <ul>
400 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
401 * </ul>
402 *
403 * @see Rectangle#intersects(Rectangle)
404 */
intersects(int x, int y, int width, int height)405 public boolean intersects (int x, int y, int width, int height) {
406 if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
407 return intersectsInPixels(DPIUtil.autoScaleUp(x), DPIUtil.autoScaleUp(y), DPIUtil.autoScaleUp(width), DPIUtil.autoScaleUp(height));
408 }
409
intersectsInPixels(int x, int y, int width, int height)410 boolean intersectsInPixels (int x, int y, int width, int height) {
411 RECT r = new RECT ();
412 OS.SetRect (r, x, y, x + width, y + height);
413 return OS.RectInRegion (handle, r);
414 }
415
416 /**
417 * Returns <code>true</code> if the given rectangle intersects
418 * with any of the polygons the receiver maintains to describe
419 * its area and <code>false</code> otherwise.
420 *
421 * @param rect the rectangle to test for intersection
422 * @return <code>true</code> if the rectangle intersects with the receiver, and <code>false</code> otherwise
423 *
424 * @exception IllegalArgumentException <ul>
425 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
426 * </ul>
427 * @exception SWTException <ul>
428 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
429 * </ul>
430 *
431 * @see Rectangle#intersects(Rectangle)
432 */
intersects(Rectangle rect)433 public boolean intersects (Rectangle rect) {
434 if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
435 if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
436 rect = DPIUtil.autoScaleUp(rect);
437 return intersectsInPixels(rect.x, rect.y, rect.width, rect.height);
438 }
439
440 /**
441 * Returns <code>true</code> if the region has been disposed,
442 * and <code>false</code> otherwise.
443 * <p>
444 * This method gets the dispose state for the region.
445 * When a region has been disposed, it is an error to
446 * invoke any other method (except {@link #dispose()}) using the region.
447 *
448 * @return <code>true</code> when the region is disposed, and <code>false</code> otherwise
449 */
450 @Override
isDisposed()451 public boolean isDisposed() {
452 return handle == 0;
453 }
454
455 /**
456 * Returns <code>true</code> if the receiver does not cover any
457 * area in the (x, y) coordinate plane, and <code>false</code> if
458 * the receiver does cover some area in the plane.
459 *
460 * @return <code>true</code> if the receiver is empty, and <code>false</code> otherwise
461 *
462 * @exception SWTException <ul>
463 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
464 * </ul>
465 */
isEmpty()466 public boolean isEmpty () {
467 if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
468 RECT rect = new RECT ();
469 int result = OS.GetRgnBox (handle, rect);
470 if (result == OS.NULLREGION) return true;
471 return ((rect.right - rect.left) <= 0) || ((rect.bottom - rect.top) <= 0);
472 }
473
474 /**
475 * Subtracts the given polygon from the collection of polygons
476 * the receiver maintains to describe its area.
477 *
478 * @param pointArray points that describe the polygon to merge with the receiver
479 *
480 * @exception IllegalArgumentException <ul>
481 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
482 * </ul>
483 * @exception SWTException <ul>
484 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
485 * </ul>
486 *
487 * @since 3.0
488 */
subtract(int[] pointArray)489 public void subtract (int[] pointArray) {
490 if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
491 if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
492 subtractInPixels(DPIUtil.autoScaleUp(pointArray));
493 }
494
subtractInPixels(int[] pointArray)495 void subtractInPixels (int[] pointArray) {
496 long polyRgn = OS.CreatePolygonRgn(pointArray, pointArray.length / 2, OS.ALTERNATE);
497 OS.CombineRgn (handle, handle, polyRgn, OS.RGN_DIFF);
498 OS.DeleteObject (polyRgn);
499 }
500
501 /**
502 * Subtracts the given rectangle from the collection of polygons
503 * the receiver maintains to describe its area.
504 *
505 * @param rect the rectangle to subtract from the receiver
506 *
507 * @exception IllegalArgumentException <ul>
508 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
509 * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
510 * </ul>
511 * @exception SWTException <ul>
512 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
513 * </ul>
514 *
515 * @since 3.0
516 */
subtract(Rectangle rect)517 public void subtract (Rectangle rect) {
518 if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
519 if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
520 rect = DPIUtil.autoScaleUp(rect);
521 subtractInPixels(rect.x, rect.y, rect.width, rect.height);
522 }
523
524 /**
525 * Subtracts the given rectangle from the collection of polygons
526 * the receiver maintains to describe its area.
527 *
528 * @param x the x coordinate of the rectangle
529 * @param y the y coordinate of the rectangle
530 * @param width the width coordinate of the rectangle
531 * @param height the height coordinate of the rectangle
532 *
533 * @exception IllegalArgumentException <ul>
534 * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
535 * </ul>
536 * @exception SWTException <ul>
537 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
538 * </ul>
539 *
540 * @since 3.1
541 */
subtract(int x, int y, int width, int height)542 public void subtract (int x, int y, int width, int height) {
543 if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
544 subtractInPixels(DPIUtil.autoScaleUp(x), DPIUtil.autoScaleUp(y), DPIUtil.autoScaleUp(width), DPIUtil.autoScaleUp(height));
545 }
546
subtractInPixels(int x, int y, int width, int height)547 void subtractInPixels (int x, int y, int width, int height) {
548 if (width < 0 || height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
549 long rectRgn = OS.CreateRectRgn (x, y, x + width, y + height);
550 OS.CombineRgn (handle, handle, rectRgn, OS.RGN_DIFF);
551 OS.DeleteObject (rectRgn);
552 }
553
554 /**
555 * Subtracts all of the polygons which make up the area covered
556 * by the argument from the collection of polygons the receiver
557 * maintains to describe its area.
558 *
559 * @param region the region to subtract
560 *
561 * @exception IllegalArgumentException <ul>
562 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
563 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
564 * </ul>
565 * @exception SWTException <ul>
566 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
567 * </ul>
568 *
569 * @since 3.0
570 */
subtract(Region region)571 public void subtract (Region region) {
572 if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
573 if (region == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
574 if (region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
575 OS.CombineRgn (handle, handle, region.handle, OS.RGN_DIFF);
576 }
577
578 /**
579 * Translate all of the polygons the receiver maintains to describe
580 * its area by the specified point.
581 *
582 * @param x the x coordinate of the point to translate
583 * @param y the y coordinate of the point to translate
584 *
585 * @exception SWTException <ul>
586 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
587 * </ul>
588 *
589 * @since 3.1
590 */
translate(int x, int y)591 public void translate (int x, int y) {
592 if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
593 translateInPixels(DPIUtil.autoScaleUp(x), DPIUtil.autoScaleUp(y));
594 }
595
translateInPixels(int x, int y)596 void translateInPixels (int x, int y) {
597 OS.OffsetRgn (handle, x, y);
598 }
599
600 /**
601 * Translate all of the polygons the receiver maintains to describe
602 * its area by the specified point.
603 *
604 * @param pt the point to translate
605 *
606 * @exception IllegalArgumentException <ul>
607 * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
608 * </ul>
609 * @exception SWTException <ul>
610 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
611 * </ul>
612 *
613 * @since 3.1
614 */
translate(Point pt)615 public void translate (Point pt) {
616 if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
617 if (pt == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
618 pt = DPIUtil.autoScaleUp(pt);
619 translateInPixels(pt.x, pt.y);
620 }
621
622 /**
623 * Returns a string containing a concise, human-readable
624 * description of the receiver.
625 *
626 * @return a string representation of the receiver
627 */
628 @Override
toString()629 public String toString () {
630 if (isDisposed()) return "Region {*DISPOSED*}";
631 return "Region {" + handle + "}";
632 }
633
634 /**
635 * Invokes platform specific functionality to allocate a new region.
636 * <p>
637 * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
638 * API for <code>Region</code>. It is marked public only so that it
639 * can be shared within the packages provided by SWT. It is not
640 * available on all platforms, and should never be called from
641 * application code.
642 * </p>
643 *
644 * @param device the device on which to allocate the region
645 * @param handle the handle for the region
646 * @return a new region object containing the specified device and handle
647 *
648 * @noreference This method is not intended to be referenced by clients.
649 */
win32_new(Device device, int handle)650 public static Region win32_new(Device device, int handle) {
651 return new Region(device, handle);
652 }
653
654 }
655