Lines 28-34
Link Here
|
28 |
* <dt><b>Styles:</b></dt> |
28 |
* <dt><b>Styles:</b></dt> |
29 |
* <dd>LEFT, RIGHT, UP, DOWN, RESIZE</dd> |
29 |
* <dd>LEFT, RIGHT, UP, DOWN, RESIZE</dd> |
30 |
* <dt><b>Events:</b></dt> |
30 |
* <dt><b>Events:</b></dt> |
31 |
* <dd>Move, Resize</dd> |
31 |
* <dd>Move, Resize, KeyUp, KeyDown</dd> |
32 |
* </dl> |
32 |
* </dl> |
33 |
* <p> |
33 |
* <p> |
34 |
* Note: Rectangle move behavior is assumed unless RESIZE is specified. |
34 |
* Note: Rectangle move behavior is assumed unless RESIZE is specified. |
Lines 37-48
Link Here
|
37 |
* </p> |
37 |
* </p> |
38 |
*/ |
38 |
*/ |
39 |
public class Tracker extends Widget { |
39 |
public class Tracker extends Widget { |
40 |
Control parent; |
40 |
Composite parent; |
41 |
boolean tracking, cancelled, stippled; |
41 |
boolean tracking, cancelled, stippled, inEvent, constrain; |
42 |
Rectangle [] rectangles = new Rectangle [0], proportions = rectangles; |
42 |
Rectangle [] rectangles = new Rectangle [0], proportions = rectangles; |
43 |
Rectangle bounds; |
43 |
Rectangle bounds; |
44 |
int resizeCursor, clientCursor, cursorOrientation = SWT.NONE; |
44 |
int resizeCursor, clientCursor, cursorOrientation = SWT.NONE; |
45 |
boolean inEvent = false; |
|
|
46 |
int oldProc, oldX, oldY; |
45 |
int oldProc, oldX, oldY; |
47 |
|
46 |
|
48 |
/* |
47 |
/* |
Lines 88-93
Link Here
|
88 |
this.parent = parent; |
87 |
this.parent = parent; |
89 |
} |
88 |
} |
90 |
|
89 |
|
|
|
90 |
public Tracker (Composite parent, int style, boolean constrain) { |
91 |
super (parent, checkStyle (style)); |
92 |
this.parent = parent; |
93 |
this.constrain = constrain; |
94 |
} |
95 |
|
91 |
/** |
96 |
/** |
92 |
* Constructs a new instance of this class given the display |
97 |
* Constructs a new instance of this class given the display |
93 |
* to create it on and a style value describing its behavior |
98 |
* to create it on and a style value describing its behavior |
Lines 319-337
Link Here
|
319 |
|
324 |
|
320 |
Rectangle [] computeProportions (Rectangle [] rects) { |
325 |
Rectangle [] computeProportions (Rectangle [] rects) { |
321 |
Rectangle [] result = new Rectangle [rects.length]; |
326 |
Rectangle [] result = new Rectangle [rects.length]; |
322 |
bounds = computeBounds (); |
|
|
323 |
if (bounds != null) { |
327 |
if (bounds != null) { |
324 |
for (int i = 0; i < rects.length; i++) { |
328 |
for (int i = 0; i < rects.length; i++) { |
325 |
int x = 0, y = 0, width = 0, height = 0; |
329 |
int x = 0, y = 0, width = 0, height = 0; |
326 |
if (bounds.width != 0) { |
330 |
if (bounds.width != 0) { |
327 |
x = (rects [i].x - bounds.x) * 100 / bounds.width; |
331 |
x = Math.round ((float)((rects [i].x - bounds.x /*+ 1*/) * 100) / bounds.width); |
328 |
width = rects [i].width * 100 / bounds.width; |
332 |
width = Math.round ((float)(rects [i].width * 100) / bounds.width); |
329 |
} else { |
333 |
} else { |
330 |
width = 100; |
334 |
width = 100; |
331 |
} |
335 |
} |
332 |
if (bounds.height != 0) { |
336 |
if (bounds.height != 0) { |
333 |
y = (rects [i].y - bounds.y) * 100 / bounds.height; |
337 |
y = Math.round ((float)((rects [i].y - bounds.y /*+ 1*/) * 100) / bounds.height); |
334 |
height = rects [i].height * 100 / bounds.height; |
338 |
height = Math.round ((float)(rects [i].height * 100) / bounds.height); |
335 |
} else { |
339 |
} else { |
336 |
height = 100; |
340 |
height = 100; |
337 |
} |
341 |
} |
Lines 364-369
Link Here
|
364 |
OS.PatBlt (hDC, rect.x + rect.width - bandWidth, rect.y + bandWidth, bandWidth, rect.height - (bandWidth * 2), OS.PATINVERT); |
368 |
OS.PatBlt (hDC, rect.x + rect.width - bandWidth, rect.y + bandWidth, bandWidth, rect.height - (bandWidth * 2), OS.PATINVERT); |
365 |
OS.PatBlt (hDC, rect.x, rect.y + rect.height - bandWidth, rect.width, bandWidth, OS.PATINVERT); |
369 |
OS.PatBlt (hDC, rect.x, rect.y + rect.height - bandWidth, rect.width, bandWidth, OS.PATINVERT); |
366 |
} |
370 |
} |
|
|
371 |
|
367 |
if (stippled) { |
372 |
if (stippled) { |
368 |
OS.SelectObject (hDC, oldBrush); |
373 |
OS.SelectObject (hDC, oldBrush); |
369 |
OS.DeleteObject (hBrush); |
374 |
OS.DeleteObject (hBrush); |
Lines 415-420
Link Here
|
415 |
if (xChange > 0 && ((style & SWT.RIGHT) == 0)) xChange = 0; |
420 |
if (xChange > 0 && ((style & SWT.RIGHT) == 0)) xChange = 0; |
416 |
if (yChange < 0 && ((style & SWT.UP) == 0)) yChange = 0; |
421 |
if (yChange < 0 && ((style & SWT.UP) == 0)) yChange = 0; |
417 |
if (yChange > 0 && ((style & SWT.DOWN) == 0)) yChange = 0; |
422 |
if (yChange > 0 && ((style & SWT.DOWN) == 0)) yChange = 0; |
|
|
423 |
if (constrain) { |
424 |
if (xChange < 0) { |
425 |
if ((bounds.x + xChange) < parent.getClientArea ().x) xChange = Math.min (parent.getClientArea ().x, -(bounds.x - parent.getClientArea ().x)); |
426 |
} |
427 |
if (xChange > 0) { |
428 |
int right = bounds.x + bounds.width - 1; |
429 |
int width = parent.getClientArea ().x + parent.getClientArea ().width; |
430 |
if (right + xChange >= width) { |
431 |
xChange = Math.max (0, width - right - 1); |
432 |
} |
433 |
} |
434 |
if (yChange < 0) { |
435 |
if ((bounds.y + yChange) < parent.getClientArea ().y) yChange = Math.min (parent.getClientArea ().y, -(bounds.y - parent.getClientArea ().y)); |
436 |
} |
437 |
if (yChange > 0) { |
438 |
int bottom = bounds.y + bounds.height - 1; |
439 |
int height = parent.getClientArea ().y + parent.getClientArea ().height; |
440 |
if (bottom + yChange >= height) { |
441 |
yChange = Math.max (0, height - bottom - 1); |
442 |
} |
443 |
} |
444 |
} |
418 |
if (xChange == 0 && yChange == 0) return; |
445 |
if (xChange == 0 && yChange == 0) return; |
419 |
bounds.x += xChange; bounds.y += yChange; |
446 |
bounds.x += xChange; bounds.y += yChange; |
420 |
for (int i = 0; i < rectangles.length; i++) { |
447 |
for (int i = 0; i < rectangles.length; i++) { |
Lines 635-641
Link Here
|
635 |
if (yChange > 0 && ((style & SWT.DOWN) != 0) && ((cursorOrientation & SWT.UP) == 0)) { |
662 |
if (yChange > 0 && ((style & SWT.DOWN) != 0) && ((cursorOrientation & SWT.UP) == 0)) { |
636 |
cursorOrientation |= SWT.DOWN; |
663 |
cursorOrientation |= SWT.DOWN; |
637 |
} |
664 |
} |
638 |
|
665 |
|
|
|
666 |
if (constrain) { |
667 |
if (xChange < 0) { |
668 |
if (((cursorOrientation & SWT.LEFT) != 0) && (bounds.x + xChange) < parent.getClientArea ().x) { |
669 |
if ((bounds.x + xChange) < parent.getClientArea ().x) xChange = Math.min (parent.getClientArea ().x, -(bounds.x - parent.getClientArea ().x)); |
670 |
xChange = Math.min (parent.getClientArea ().x, -(bounds.x - parent.getClientArea ().x)); |
671 |
} |
672 |
if (((cursorOrientation & SWT.RIGHT) != 0) && (bounds.x + bounds.width - 1 + xChange) < 0) { |
673 |
/* will flip about y axis before hitting edge */ |
674 |
xChange = Math.min (parent.getClientArea ().x, -(bounds.x - parent.getClientArea ().x + bounds.width - 1)); |
675 |
} |
676 |
} |
677 |
if (xChange > 0) { |
678 |
int right = bounds.x + bounds.width - 1; |
679 |
int width = parent.getClientArea ().x + parent.getClientArea ().width; |
680 |
if ((cursorOrientation & SWT.RIGHT) != 0 && (right + xChange) >= width) { |
681 |
xChange = Math.max (0, width - right - 1); |
682 |
} |
683 |
if ((cursorOrientation & SWT.LEFT) != 0 && (bounds.x + xChange) >= width) { |
684 |
/* will flip about y axis before hitting edge */ |
685 |
xChange = Math.max (0, width - bounds.x - 1); |
686 |
} |
687 |
} |
688 |
if (yChange < 0) { |
689 |
if (((cursorOrientation & SWT.TOP) != 0) && (bounds.y + yChange) < parent.getClientArea ().y) { |
690 |
yChange = Math.min (parent.getClientArea ().y, -(bounds.y - parent.getClientArea ().y)); |
691 |
} |
692 |
if (((cursorOrientation & SWT.BOTTOM) != 0) && (bounds.y + bounds.height - 1 + yChange) < 0) { |
693 |
/* will flip about x axis before hitting edge */ |
694 |
yChange = Math.min (parent.getClientArea ().y, -(bounds.y - parent.getClientArea ().y + bounds.height - 1)); |
695 |
} |
696 |
} |
697 |
if (yChange > 0) { |
698 |
int bottom = bounds.y + bounds.height - 1; |
699 |
int height = parent.getClientArea ().y + parent.getClientArea ().height; |
700 |
if ((cursorOrientation & SWT.BOTTOM) != 0 && (bottom + yChange) >= height) { |
701 |
yChange = Math.max (0, height - bottom - 1); |
702 |
} |
703 |
if ((cursorOrientation & SWT.BOTTOM) != 0 && (bounds.y + yChange) >= height) { |
704 |
/* will flip about x axis before hitting edge */ |
705 |
yChange = Math.max (0, height - bounds.y - 1); |
706 |
} |
707 |
} |
708 |
if (xChange == 0 && yChange == 0) return; |
709 |
} |
710 |
|
639 |
/* |
711 |
/* |
640 |
* If the bounds will flip about the x or y axis then apply the adjustment |
712 |
* If the bounds will flip about the x or y axis then apply the adjustment |
641 |
* up to the axis (ie.- where bounds width/height becomes 0), change the |
713 |
* up to the axis (ie.- where bounds width/height becomes 0), change the |
Lines 726-732
Link Here
|
726 |
proportion.width * bounds.width / 100, |
798 |
proportion.width * bounds.width / 100, |
727 |
proportion.height * bounds.height / 100); |
799 |
proportion.height * bounds.height / 100); |
728 |
} |
800 |
} |
729 |
rectangles = newRects; |
801 |
rectangles = newRects; |
|
|
802 |
System.out.println("bounds: " + bounds); |
803 |
System.out.println("rect2: " + rectangles[1].toString()); |
804 |
System.out.println("----"); |
730 |
} |
805 |
} |
731 |
|
806 |
|
732 |
/** |
807 |
/** |
Lines 772-778
Link Here
|
772 |
if (current == null) error (SWT.ERROR_NULL_ARGUMENT); |
847 |
if (current == null) error (SWT.ERROR_NULL_ARGUMENT); |
773 |
this.rectangles [i] = new Rectangle (current.x, current.y, current.width, current.height); |
848 |
this.rectangles [i] = new Rectangle (current.x, current.y, current.width, current.height); |
774 |
} |
849 |
} |
775 |
proportions = computeProportions (rectangles); |
850 |
bounds = computeBounds (); |
|
|
851 |
if ((style & SWT.RESIZE) != 0) { |
852 |
proportions = computeProportions (rectangles); |
853 |
} |
776 |
} |
854 |
} |
777 |
|
855 |
|
778 |
/** |
856 |
/** |