comparison dwtx/ui/internal/forms/widgets/SelectionData.d @ 104:04b47443bb01

Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections. These new wrappers now use the tango.util.containers instead of the tango.util.collections.
author Frank Benoit <benoit@tionex.de>
date Thu, 07 Aug 2008 15:01:33 +0200
parents 26c6c9dfd13c
children
comparison
equal deleted inserted replaced
103:2d6540440fe6 104:04b47443bb01
19 import dwt.graphics.Color; 19 import dwt.graphics.Color;
20 import dwt.graphics.Point; 20 import dwt.graphics.Point;
21 import dwt.widgets.Display; 21 import dwt.widgets.Display;
22 22
23 import dwt.dwthelper.utils; 23 import dwt.dwthelper.utils;
24 import tango.util.collection.ArraySeq; 24 import dwtx.dwtxhelper.Collection;
25
25 static import tango.text.Text; 26 static import tango.text.Text;
26 27
27 public class SelectionData { 28 public class SelectionData {
28 public Display display; 29 public Display display;
29 public Color bg; 30 public Color bg;
30 public Color fg; 31 public Color fg;
31 private Point start; 32 private Point start;
32 private Point stop; 33 private Point stop;
33 private ArraySeq!(String) segments; 34 private ArrayList segments;
34 private bool newLineNeeded; 35 private bool newLineNeeded;
35 36
36 public this(MouseEvent e) { 37 public this(MouseEvent e) {
37 display = e.display; 38 display = e.display;
38 segments = new ArraySeq!(String); 39 segments = new ArrayList();
39 start = new Point(e.x, e.y); 40 start = new Point(e.x, e.y);
40 stop = new Point(e.x, e.y); 41 stop = new Point(e.x, e.y);
41 bg = e.display.getSystemColor(DWT.COLOR_LIST_SELECTION); 42 bg = e.display.getSystemColor(DWT.COLOR_LIST_SELECTION);
42 fg = e.display.getSystemColor(DWT.COLOR_LIST_SELECTION_TEXT); 43 fg = e.display.getSystemColor(DWT.COLOR_LIST_SELECTION_TEXT);
43 } 44 }
45 public void markNewLine() { 46 public void markNewLine() {
46 newLineNeeded=true; 47 newLineNeeded=true;
47 } 48 }
48 public void addSegment(String text) { 49 public void addSegment(String text) {
49 if (newLineNeeded) { 50 if (newLineNeeded) {
50 segments.append(System.getProperty("line.separator")); //$NON-NLS-1$ 51 segments.add(System.getProperty("line.separator")); //$NON-NLS-1$
51 newLineNeeded=false; 52 newLineNeeded=false;
52 } 53 }
53 segments.append(text); 54 segments.add(text);
54 } 55 }
55 56
56 public void update(MouseEvent e) { 57 public void update(MouseEvent e) {
57 //Control c = (Control)e.widget; 58 //Control c = (Control)e.widget;
58 stop.x = e.x; 59 stop.x = e.x;
62 segments.clear(); 63 segments.clear();
63 } 64 }
64 public String getSelectionText() { 65 public String getSelectionText() {
65 auto buf = new tango.text.Text.Text!(char); 66 auto buf = new tango.text.Text.Text!(char);
66 for (int i=0; i<segments.size(); i++) { 67 for (int i=0; i<segments.size(); i++) {
67 buf.append(segments.get(i)); 68 buf.append(stringcast(segments.get(i)));
68 } 69 }
69 return buf.toString(); 70 return buf.toString();
70 } 71 }
71 public bool canCopy() { 72 public bool canCopy() {
72 return segments.size()>0; 73 return segments.size()>0;
89 } 90 }
90 public int getRightOffset(int rowHeight) { 91 public int getRightOffset(int rowHeight) {
91 return isInverted(rowHeight) ? start.x:stop.x; 92 return isInverted(rowHeight) ? start.x:stop.x;
92 } 93 }
93 private bool isInverted(Locator locator) { 94 private bool isInverted(Locator locator) {
94 int rowHeight = locator.heights.get(locator.rowCounter).array[0]; 95 int rowHeight = arrayFromObject!(Integer)(locator.heights.get(locator.rowCounter))[0].value;
95 return isInverted(rowHeight); 96 return isInverted(rowHeight);
96 } 97 }
97 private bool isInverted(int rowHeight) { 98 private bool isInverted(int rowHeight) {
98 int deltaY = start.y - stop.y; 99 int deltaY = start.y - stop.y;
99 if (Math.abs(deltaY) > rowHeight) { 100 if (Math.abs(deltaY) > rowHeight) {
108 } 109 }
109 110
110 public bool isSelectedRow(Locator locator) { 111 public bool isSelectedRow(Locator locator) {
111 if (!isEnclosed()) 112 if (!isEnclosed())
112 return false; 113 return false;
113 int rowHeight = locator.heights.get(locator.rowCounter).array[0]; 114 int rowHeight = arrayFromObject!(Integer)(locator.heights.get(locator.rowCounter))[0].value;
114 return isSelectedRow(locator.y, rowHeight); 115 return isSelectedRow(locator.y, rowHeight);
115 } 116 }
116 public bool isSelectedRow(int y, int rowHeight) { 117 public bool isSelectedRow(int y, int rowHeight) {
117 if (!isEnclosed()) 118 if (!isEnclosed())
118 return false; 119 return false;
120 y <= getBottomOffset()); 121 y <= getBottomOffset());
121 } 122 }
122 public bool isFirstSelectionRow(Locator locator) { 123 public bool isFirstSelectionRow(Locator locator) {
123 if (!isEnclosed()) 124 if (!isEnclosed())
124 return false; 125 return false;
125 int rowHeight = locator.heights.get(locator.rowCounter).array[0]; 126 int rowHeight = arrayFromObject!(Integer)(locator.heights.get(locator.rowCounter))[0].value;
126 return (locator.y + rowHeight >= getTopOffset() && 127 return (locator.y + rowHeight >= getTopOffset() &&
127 locator.y <= getTopOffset()); 128 locator.y <= getTopOffset());
128 } 129 }
129 public bool isFirstSelectionRow(int y, int rowHeight) { 130 public bool isFirstSelectionRow(int y, int rowHeight) {
130 if (!isEnclosed()) 131 if (!isEnclosed())
133 y <= getTopOffset()); 134 y <= getTopOffset());
134 } 135 }
135 public bool isLastSelectionRow(Locator locator) { 136 public bool isLastSelectionRow(Locator locator) {
136 if (!isEnclosed()) 137 if (!isEnclosed())
137 return false; 138 return false;
138 int rowHeight = locator.heights.get(locator.rowCounter).array[0]; 139 int rowHeight = arrayFromObject!(Integer)(locator.heights.get(locator.rowCounter))[0].value;
139 return (locator.y + rowHeight >=getBottomOffset() && 140 return (locator.y + rowHeight >=getBottomOffset() &&
140 locator.y <= getBottomOffset()); 141 locator.y <= getBottomOffset());
141 } 142 }
142 public bool isLastSelectionRow(int y, int rowHeight) { 143 public bool isLastSelectionRow(int y, int rowHeight) {
143 if (!isEnclosed()) 144 if (!isEnclosed())