comparison dwt/widgets/CoolBar.d @ 63:a3f5118c8b37

Ported CoolBar and CoolItem
author Jacob Carlborg <doob@me.com>
date Tue, 23 Dec 2008 22:38:33 +0100
parents d8635bb48c7c
children c7f7f4d7091a
comparison
equal deleted inserted replaced
62:10eaa644646f 63:a3f5118c8b37
5 * which accompanies this distribution, and is available at 5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html 6 * http://www.eclipse.org/legal/epl-v10.html
7 * 7 *
8 * Contributors: 8 * Contributors:
9 * IBM Corporation - initial API and implementation 9 * IBM Corporation - initial API and implementation
10 *
11 * Port to the D programming language:
12 * Jacob Carlborg <doob@me.com>
10 *******************************************************************************/ 13 *******************************************************************************/
11 module dwt.widgets.CoolBar; 14 module dwt.widgets.CoolBar;
12 15
13 import dwt.dwthelper.utils; 16 import dwt.dwthelper.utils;
14 17
18 import dwt.graphics.Color; 21 import dwt.graphics.Color;
19 import dwt.graphics.Cursor; 22 import dwt.graphics.Cursor;
20 import dwt.graphics.GC; 23 import dwt.graphics.GC;
21 import dwt.graphics.Point; 24 import dwt.graphics.Point;
22 import dwt.graphics.Rectangle; 25 import dwt.graphics.Rectangle;
26
27 import dwt.widgets.CoolItem;
28 import dwt.widgets.Composite;
29 import dwt.widgets.Control;
30 import dwt.widgets.Event;
31 import dwt.widgets.Listener;
23 32
24 /** 33 /**
25 * Instances of this class provide an area for dynamically 34 * Instances of this class provide an area for dynamically
26 * positioning the items they contain. 35 * positioning the items they contain.
27 * <p> 36 * <p>
47 * @see <a href="http://www.eclipse.org/swt/snippets/#coolbar">CoolBar snippets</a> 56 * @see <a href="http://www.eclipse.org/swt/snippets/#coolbar">CoolBar snippets</a>
48 * @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>
49 * @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>
50 */ 59 */
51 public class CoolBar : Composite { 60 public class CoolBar : Composite {
52 CoolItem[][] items = new CoolItem[0][0]; 61 CoolItem[][] items;
53 CoolItem[] originalItems = new CoolItem[0]; 62 CoolItem[] originalItems = new CoolItem[0];
54 Cursor hoverCursor, dragCursor, cursor; 63 Cursor hoverCursor, dragCursor, cursor;
55 CoolItem dragging = null; 64 CoolItem dragging = null;
56 int mouseXOffset, itemXOffset; 65 int mouseXOffset, itemXOffset;
57 bool isLocked = false; 66 bool isLocked = false;
58 bool inDispose = false; 67 bool inDispose = false;
59 static final int ROW_SPACING = 2; 68 static const int ROW_SPACING = 2;
60 static final int CLICK_DISTANCE = 3; 69 static const int CLICK_DISTANCE = 3;
61 static final int DEFAULT_COOLBAR_WIDTH = 0; 70 static const int DEFAULT_COOLBAR_WIDTH = 0;
62 static final int DEFAULT_COOLBAR_HEIGHT = 0; 71 static const int DEFAULT_COOLBAR_HEIGHT = 0;
63 72
64 /** 73 /**
65 * Constructs a new instance of this class given its parent 74 * Constructs a new instance of this class given its parent
66 * and a style value describing its behavior and appearance. 75 * and a style value describing its behavior and appearance.
67 * <p> 76 * <p>
97 } else { 106 } else {
98 this.style |= DWT.HORIZONTAL; 107 this.style |= DWT.HORIZONTAL;
99 hoverCursor = new Cursor(display, DWT.CURSOR_SIZEWE); 108 hoverCursor = new Cursor(display, DWT.CURSOR_SIZEWE);
100 } 109 }
101 dragCursor = new Cursor(display, DWT.CURSOR_SIZEALL); 110 dragCursor = new Cursor(display, DWT.CURSOR_SIZEALL);
102 Listener listener = new Listener() { 111 Listener listener = new class () Listener {
103 public void handleEvent(Event event) { 112 public void handleEvent(Event event) {
104 switch (event.type) { 113 switch (event.type) {
105 case DWT.Dispose: onDispose(event); break; 114 case DWT.Dispose: onDispose(event); break;
106 case DWT.MouseDown: onMouseDown(event); break; 115 case DWT.MouseDown: onMouseDown(event); break;
107 case DWT.MouseExit: onMouseExit(); break; 116 case DWT.MouseExit: onMouseExit(); break;
108 case DWT.MouseMove: onMouseMove(event); break; 117 case DWT.MouseMove: onMouseMove(event); break;
109 case DWT.MouseUp: onMouseUp(event); break; 118 case DWT.MouseUp: onMouseUp(event); break;
110 case DWT.MouseDoubleClick: onMouseDoubleClick(event); break; 119 case DWT.MouseDoubleClick: onMouseDoubleClick(event); break;
111 case DWT.Paint: onPaint(event); break; 120 case DWT.Paint: onPaint(event); break;
112 case DWT.Resize: onResize(); break; 121 case DWT.Resize: onResize(); break;
122 default:
113 } 123 }
114 } 124 }
115 }; 125 };
116 int[] events = new int[] { 126 int[] events = [
117 DWT.Dispose, 127 DWT.Dispose,
118 DWT.MouseDown, 128 DWT.MouseDown,
119 DWT.MouseExit, 129 DWT.MouseExit,
120 DWT.MouseMove, 130 DWT.MouseMove,
121 DWT.MouseUp, 131 DWT.MouseUp,
122 DWT.MouseDoubleClick, 132 DWT.MouseDoubleClick,
123 DWT.Paint, 133 DWT.Paint,
124 DWT.Resize 134 DWT.Resize
125 }; 135 ];
126 for (int i = 0; i < events.length; i++) { 136 for (int i = 0; i < events.length; i++) {
127 addListener(events[i], listener); 137 addListener(events[i], listener);
128 } 138 }
129 } 139 }
130 static int checkStyle (int style) { 140 static int checkStyle (int style) {
1024 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 1034 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1025 * </ul> 1035 * </ul>
1026 */ 1036 */
1027 public int[] getWrapIndices () { 1037 public int[] getWrapIndices () {
1028 checkWidget(); 1038 checkWidget();
1029 if (items.length <= 1) return new int[]{}; 1039 if (items.length <= 1) return [];
1030 int[] wrapIndices = new int[items.length - 1]; 1040 int[] wrapIndices = new int[items.length - 1];
1031 int i = 0, nextWrap = items[0].length; 1041 int i = 0, nextWrap = items[0].length;
1032 for (int row = 1; row < items.length; row++) { 1042 for (int row = 1; row < items.length; row++) {
1033 if (items[row][0].wrap) wrapIndices[i++] = nextWrap; 1043 if (items[row][0].wrap) wrapIndices[i++] = nextWrap;
1034 nextWrap += items[row].length; 1044 nextWrap += items[row].length;