Mercurial > projects > dwt-mac
comparison dwt/widgets/CoolBar.d @ 90:c7f7f4d7091a
All widgets are ported
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Tue, 30 Dec 2008 18:54:31 +0100 |
parents | a3f5118c8b37 |
children | 63a09873578e |
comparison
equal
deleted
inserted
replaced
89:8e3c85e1733d | 90:c7f7f4d7091a |
---|---|
57 * @see <a href="http://www.eclipse.org/swt/examples.php">DWT Example: ControlExample</a> | 57 * @see <a href="http://www.eclipse.org/swt/examples.php">DWT Example: ControlExample</a> |
58 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> | 58 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> |
59 */ | 59 */ |
60 public class CoolBar : Composite { | 60 public class CoolBar : Composite { |
61 CoolItem[][] items; | 61 CoolItem[][] items; |
62 CoolItem[] originalItems = new CoolItem[0]; | 62 CoolItem[] originalItems; |
63 Cursor hoverCursor, dragCursor, cursor; | 63 Cursor hoverCursor, dragCursor, cursor; |
64 CoolItem dragging = null; | 64 CoolItem dragging = null; |
65 int mouseXOffset, itemXOffset; | 65 int mouseXOffset, itemXOffset; |
66 bool isLocked = false; | 66 bool isLocked = false; |
67 bool inDispose = false; | 67 bool inDispose = false; |
134 DWT.Resize | 134 DWT.Resize |
135 ]; | 135 ]; |
136 for (int i = 0; i < events.length; i++) { | 136 for (int i = 0; i < events.length; i++) { |
137 addListener(events[i], listener); | 137 addListener(events[i], listener); |
138 } | 138 } |
139 | |
140 originalItems = new CoolItem[0]; | |
139 } | 141 } |
140 static int checkStyle (int style) { | 142 static int checkStyle (int style) { |
141 style |= DWT.NO_FOCUS; | 143 style |= DWT.NO_FOCUS; |
142 return (style | DWT.NO_REDRAW_RESIZE) & ~(DWT.V_SCROLL | DWT.H_SCROLL); | 144 return (style | DWT.NO_REDRAW_RESIZE) & ~(DWT.V_SCROLL | DWT.H_SCROLL); |
143 } | 145 } |
257 return result; | 259 return result; |
258 } | 260 } |
259 Point findItem (CoolItem item) { | 261 Point findItem (CoolItem item) { |
260 for (int row = 0; row < items.length; row++) { | 262 for (int row = 0; row < items.length; row++) { |
261 for (int i = 0; i < items[row].length; i++) { | 263 for (int i = 0; i < items[row].length; i++) { |
262 if (items[row][i].equals(item)) return new Point(i, row); | 264 if (items[row][i].opEquals(item)) return new Point(i, row); |
263 } | 265 } |
264 } | 266 } |
265 return new Point(-1, -1); | 267 return new Point(-1, -1); |
266 } | 268 } |
267 void fixEvent (Event event) { | 269 void fixEvent (Event event) { |
306 if (item is null) error (DWT.ERROR_NULL_ARGUMENT); | 308 if (item is null) error (DWT.ERROR_NULL_ARGUMENT); |
307 if (item.isDisposed()) error (DWT.ERROR_INVALID_ARGUMENT); | 309 if (item.isDisposed()) error (DWT.ERROR_INVALID_ARGUMENT); |
308 int answer = 0; | 310 int answer = 0; |
309 for (int row = 0; row < items.length; row++) { | 311 for (int row = 0; row < items.length; row++) { |
310 for (int i = 0; i < items[row].length; i++) { | 312 for (int i = 0; i < items[row].length; i++) { |
311 if (items[row][i].equals(item)) { | 313 if (items[row][i].opEquals(item)) { |
312 return answer; | 314 return answer; |
313 } else { | 315 } else { |
314 answer++; | 316 answer++; |
315 } | 317 } |
316 } | 318 } |
384 } | 386 } |
385 void createItem (CoolItem item, int index) { | 387 void createItem (CoolItem item, int index) { |
386 int itemCount = getItemCount(), row = 0; | 388 int itemCount = getItemCount(), row = 0; |
387 if (!(0 <= index && index <= itemCount)) error (DWT.ERROR_INVALID_RANGE); | 389 if (!(0 <= index && index <= itemCount)) error (DWT.ERROR_INVALID_RANGE); |
388 if (items.length is 0) { | 390 if (items.length is 0) { |
389 items = new CoolItem[1][1]; | 391 items = new CoolItem[][](1, 1); |
390 items[0][0] = item; | 392 items[0][0] = item; |
391 } else { | 393 } else { |
392 int i = index; | 394 int i = index; |
393 /* find the row to insert into */ | 395 /* find the row to insert into */ |
394 if (index < itemCount) { | 396 if (index < itemCount) { |
467 removeItemFromRow(item, oldRowIndex, false); | 469 removeItemFromRow(item, oldRowIndex, false); |
468 Rectangle old = item.internalGetBounds(); | 470 Rectangle old = item.internalGetBounds(); |
469 internalRedraw(old.x, old.y, CoolItem.MINIMUM_WIDTH, old.height); | 471 internalRedraw(old.x, old.y, CoolItem.MINIMUM_WIDTH, old.height); |
470 if (newRowIndex is items.length) { | 472 if (newRowIndex is items.length) { |
471 /* Create a new bottom row for the item. */ | 473 /* Create a new bottom row for the item. */ |
472 CoolItem[][] newRows = new CoolItem[items.length + 1][]; | 474 CoolItem[][] newRows = new CoolItem[][](items.length + 1); |
473 System.arraycopy(items, 0, newRows, 0, items.length); | 475 SimpleType!(CoolItem[]).arraycopy(items, 0, newRows, 0, items.length); |
474 int row = items.length; | 476 int row = items.length; |
475 newRows[row] = new CoolItem[1]; | 477 newRows[row] = new CoolItem[1]; |
476 newRows[row][0] = item; | 478 newRows[row][0] = item; |
477 items = newRows; | 479 items = newRows; |
478 resize = true; | 480 resize = true; |
567 Rectangle old = item.internalGetBounds(); | 569 Rectangle old = item.internalGetBounds(); |
568 internalRedraw(old.x, old.y, CoolItem.MINIMUM_WIDTH, old.height); | 570 internalRedraw(old.x, old.y, CoolItem.MINIMUM_WIDTH, old.height); |
569 int newRowIndex = Math.max(0, oldRowIndex - 1); | 571 int newRowIndex = Math.max(0, oldRowIndex - 1); |
570 if (oldRowIndex is 0) { | 572 if (oldRowIndex is 0) { |
571 /* Create a new top row for the item. */ | 573 /* Create a new top row for the item. */ |
572 CoolItem[][] newRows = new CoolItem[items.length + 1][]; | 574 CoolItem[][] newRows = new CoolItem[][](items.length + 1); |
573 System.arraycopy(items, 0, newRows, 1, items.length); | 575 SimpleType!(CoolItem[]).arraycopy(items, 0, newRows, 1, items.length); |
574 newRows[0] = new CoolItem[1]; | 576 newRows[0] = new CoolItem[1]; |
575 newRows[0][0] = item; | 577 newRows[0][0] = item; |
576 items = newRows; | 578 items = newRows; |
577 resize = true; | 579 resize = true; |
578 item.wrap = true; | 580 item.wrap = true; |
803 System.arraycopy(items[rowIndex], 0, newRow, 0, index); | 805 System.arraycopy(items[rowIndex], 0, newRow, 0, index); |
804 System.arraycopy(items[rowIndex], index + 1, newRow, index, newRow.length - index); | 806 System.arraycopy(items[rowIndex], index + 1, newRow, index, newRow.length - index); |
805 items[rowIndex] = newRow; | 807 items[rowIndex] = newRow; |
806 items[rowIndex][0].wrap = true; | 808 items[rowIndex][0].wrap = true; |
807 } else { | 809 } else { |
808 CoolItem[][] newRows = new CoolItem[items.length - 1][]; | 810 CoolItem[][] newRows = new CoolItem[][](items.length - 1); |
809 System.arraycopy(items, 0, newRows, 0, rowIndex); | 811 SimpleType!(CoolItem[]).arraycopy(items, 0, newRows, 0, rowIndex); |
810 System.arraycopy(items, rowIndex + 1, newRows, rowIndex, newRows.length - rowIndex); | 812 SimpleType!(CoolItem[]).arraycopy(items, rowIndex + 1, newRows, rowIndex, newRows.length - rowIndex); |
811 items = newRows; | 813 items = newRows; |
812 return; | 814 return; |
813 } | 815 } |
814 if (!disposed) { | 816 if (!disposed) { |
815 if (index is 0) { | 817 if (index is 0) { |
966 | 968 |
967 CoolItem[] row = new CoolItem[count]; | 969 CoolItem[] row = new CoolItem[count]; |
968 for (int i = 0; i < count; i++) { | 970 for (int i = 0; i < count; i++) { |
969 row[i] = originalItems[itemOrder[i]]; | 971 row[i] = originalItems[itemOrder[i]]; |
970 } | 972 } |
971 items = new CoolItem[1][count]; | 973 items = new CoolItem[][](1, count); |
972 items[0] = row; | 974 items[0] = row; |
973 } | 975 } |
974 /** | 976 /** |
975 * Returns an array of points whose x and y coordinates describe | 977 * Returns an array of points whose x and y coordinates describe |
976 * the widths and heights (respectively) of the items in the receiver | 978 * the widths and heights (respectively) of the items in the receiver |
1162 int start = 0; | 1164 int start = 0; |
1163 for (int row = 0; row < items.length; row++) { | 1165 for (int row = 0; row < items.length; row++) { |
1164 System.arraycopy(items[row], 0, itemsVisual, start, items[row].length); | 1166 System.arraycopy(items[row], 0, itemsVisual, start, items[row].length); |
1165 start += items[row].length; | 1167 start += items[row].length; |
1166 } | 1168 } |
1167 CoolItem[][] newItems = new CoolItem[itemCount][]; | 1169 CoolItem[][] newItems = new CoolItem[][](itemCount); |
1168 int rowCount = 0, rowWidth = 0; | 1170 int rowCount = 0, rowWidth = 0; |
1169 start = 0; | 1171 start = 0; |
1170 for (int i = 0; i < itemCount; i++) { | 1172 for (int i = 0; i < itemCount; i++) { |
1171 CoolItem item = itemsVisual[i]; | 1173 CoolItem item = itemsVisual[i]; |
1172 int itemWidth = item.internalGetMinimumWidth(); | 1174 int itemWidth = item.internalGetMinimumWidth(); |
1193 newItems[rowCount] = new CoolItem[count]; | 1195 newItems[rowCount] = new CoolItem[count]; |
1194 System.arraycopy(itemsVisual, start, newItems[rowCount], 0, count); | 1196 System.arraycopy(itemsVisual, start, newItems[rowCount], 0, count); |
1195 rowCount++; | 1197 rowCount++; |
1196 } | 1198 } |
1197 if (newItems.length !is rowCount) { | 1199 if (newItems.length !is rowCount) { |
1198 CoolItem[][] tmp = new CoolItem[rowCount][]; | 1200 CoolItem[][] tmp = new CoolItem[][](rowCount); |
1199 System.arraycopy(newItems, 0, tmp, 0, rowCount); | 1201 SimpleType!(CoolItem[]).arraycopy(newItems, 0, tmp, 0, rowCount); |
1200 items = tmp; | 1202 items = tmp; |
1201 } else { | 1203 } else { |
1202 items = newItems; | 1204 items = newItems; |
1203 } | 1205 } |
1204 } | 1206 } |