Mercurial > projects > dwt-mac
diff dwt/widgets/Control.d @ 15:2952d5604c0a
Ported some widgets, added some stuff to the runtime bindings
author | Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com> |
---|---|
date | Fri, 29 Aug 2008 21:46:05 +0200 |
parents | 380af2bdd8e5 |
children | 5b53d338c709 |
line wrap: on
line diff
--- a/dwt/widgets/Control.d Sat Aug 23 13:49:00 2008 +0200 +++ b/dwt/widgets/Control.d Fri Aug 29 21:46:05 2008 +0200 @@ -7,10 +7,12 @@ * * Contributors: * IBM Corporation - initial API and implementation + * + * Port to the D programming language: + * Jacob Carlborg <jacob.carlborg@gmail.com> *******************************************************************************/ module dwt.widgets.Control; -import dwt.dwthelper.utils; import dwt.DWT; import dwt.DWTException; @@ -51,6 +53,25 @@ import dwt.internal.cocoa.OS; import dwt.internal.cocoa.objc_super; +import tango.core.Thread; + +import dwt.dwthelper.utils; +import dwt.dwthelper.System; +import objc = dwt.internal.objc.runtime; +import dwt.widgets.Composite; +import dwt.widgets.Decorations; +import dwt.widgets.Display; +import dwt.widgets.Event; +import dwt.widgets.Listener; +import dwt.widgets.Menu; +import dwt.widgets.Monitor; +import dwt.widgets.Shell; +import dwt.widgets.TypedListener; +import dwt.widgets.Widget; + + + + /** * Control is the abstract superclass of all windowed user interface classes. * <p> @@ -69,7 +90,7 @@ * within the DWT implementation. * </p> */ -public abstract class Control extends Widget implements Drawable { +public abstract class Control : Widget , Drawable { /** * the handle to the OS resource * (Warning: This field is platform dependent) @@ -97,7 +118,7 @@ // static final String RESET_VISIBLE_REGION = "dwt.internal.resetVisibleRegion"; -Control () { +this () { /* Do nothing */ } @@ -129,35 +150,35 @@ * @see Widget#checkSubclass * @see Widget#getStyle */ -public Control (Composite parent, int style) { +public this (Composite parent, int style) { super (parent, style); this.parent = parent; createWidget (); } bool acceptsFirstResponder () { - objc_super super_struct = new objc_super(); - super_struct.receiver = view.id; - super_struct.cls = OS.objc_msgSend(view.id, OS.sel_superclass); - return OS.objc_msgSendSuper(super_struct, OS.sel_acceptsFirstResponder) !is 0; + objc_super super_struct = objc_super(); + super_struct.receiver = view.id_; + super_struct.cls = cast(objc.Class) OS.objc_msgSend(view.id_, OS.sel_superclass); + return OS.objc_msgSendSuper(super_struct, OS.sel_acceptsFirstResponder) !is null; } bool becomeFirstResponder () { //TODO - query focusControl() in DWT.FocusIn/Out is the control sendEvent (DWT.FocusIn); - objc_super super_struct = new objc_super(); - super_struct.receiver = view.id; - super_struct.cls = OS.objc_msgSend(view.id, OS.sel_superclass); - return OS.objc_msgSendSuper(super_struct, OS.sel_becomeFirstResponder) !is 0; + objc_super super_struct = objc_super(); + super_struct.receiver = view.id_; + super_struct.cls = OS.objc_msgSend(view.id_, OS.sel_superclass); + return OS.objc_msgSendSuper(super_struct, OS.sel_becomeFirstResponder) !is null; } bool resignFirstResponder () { //TODO - query focusControl() in DWT.FocusIn/Out is the control sendEvent (DWT.FocusOut); - objc_super super_struct = new objc_super(); - super_struct.receiver = view.id; - super_struct.cls = OS.objc_msgSend(view.id, OS.sel_superclass); - return OS.objc_msgSendSuper(super_struct, OS.sel_resignFirstResponder) !is 0; + objc_super super_struct = objc_super(); + super_struct.receiver = view.id_; + super_struct.cls = OS.objc_msgSend(view.id_, OS.sel_superclass); + return OS.objc_msgSendSuper(super_struct, OS.sel_resignFirstResponder) !is null; } /** @@ -600,12 +621,12 @@ // width += border * 2; // height += border * 2; // return new Point (width, height); - if (topView() instanceof NSControl) { + if (cast(NSControl) topView()) { NSRect oldRect = topView().frame(); - ((NSControl)topView()).sizeToFit(); + (cast(NSControl)topView()).sizeToFit(); NSRect newRect = topView().frame(); topView().setFrame (oldRect); - return new Point ((int)newRect.width, (int)newRect.height); + return new Point (cast(int)newRect.width, cast(int)newRect.height); } return new Point (width, height); } @@ -618,7 +639,7 @@ Control[] computeTabList() { if (isTabGroup()) { if (getVisible() && getEnabled()) { - return new Control[] {this}; + return new Control[] [this]; } } return new Control[0]; @@ -655,8 +676,8 @@ Font defaultFont () { //TODO - Controls only, does this leak? - if (view instanceof NSControl) { - NSFont nsFont = ((NSControl)view).font (); + if (cast(NSControl) view) { + NSFont nsFont = (cast(NSControl)view).font (); if (nsFont !is null) { return Font.cocoa_new (display, nsFont); } @@ -795,10 +816,10 @@ GC gc = GC.cocoa_new (this, data); Event event = new Event (); event.gc = gc; - event.x = (int)rect.x; - event.y = (int)rect.y; - event.width = (int)rect.width; - event.height = (int)rect.height; + event.x = cast(int)rect.x; + event.y = cast(int)rect.y; + event.width = cast(int)rect.width; + event.height = cast(int)rect.height; sendEvent (DWT.Paint, event); event.gc = null; gc.dispose (); @@ -806,8 +827,8 @@ void enableWidget (bool enabled) { //TODO - other views - if (view instanceof NSControl) { - ((NSControl)view).setEnabled(enabled); + if (cast(NSControl) view) { + (cast(NSControl)view).setEnabled(enabled); } } @@ -822,7 +843,7 @@ } Menu [] findMenus (Control control) { - if (menu !is null && this !is control) return new Menu [] {menu}; + if (menu !is null && this !is control) return new Menu [] [menu]; return new Menu [0]; } @@ -965,7 +986,7 @@ public Rectangle getBounds () { checkWidget(); NSRect rect = topView().frame(); - return new Rectangle((int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height); + return new Rectangle(cast(int)rect.x, cast(int)rect.y, cast(int)rect.width, cast(int)rect.height); } /** @@ -1090,7 +1111,7 @@ public Point getLocation () { checkWidget(); NSRect rect = topView().frame(); - return new Point((int)rect.x, (int)rect.y); + return new Point(cast(int)rect.x, cast(int)rect.y); } /** @@ -1124,9 +1145,9 @@ * * @since 3.0 */ -public Monitor getMonitor () { +public dwt.widgets.Monitor.Monitor getMonitor () { checkWidget(); - Monitor [] monitors = display.getMonitors (); + dwt.widgets.Monitor.Monitor [] monitors = display.getMonitors (); if (monitors.length is 1) return monitors [0]; int index = -1, value = -1; Rectangle bounds = getBounds (); @@ -1231,7 +1252,7 @@ public Point getSize () { checkWidget(); NSRect rect = topView().frame(); - return new Point((int)rect.width, (int)rect.height); + return new Point(cast(int)rect.width, cast(int)rect.height); } /** @@ -1293,13 +1314,13 @@ * @param data the platform specific GC data * @return the platform specific GC handle */ -public int internal_new_GC (GCData data) { +public objc.id internal_new_GC (GCData data) { checkWidget(); - int context = 0; + objc.id context = null; if (data !is null && data.paintRect !is null) { - context = NSGraphicsContext.currentContext().id; + context = NSGraphicsContext.currentContext().id_; } else { - context = NSGraphicsContext.graphicsContextWithWindow(view.window()).id; + context = NSGraphicsContext.graphicsContextWithWindow(view.window()).id_; } if (data !is null) { int mask = DWT.LEFT_TO_RIGHT | DWT.RIGHT_TO_LEFT; @@ -1360,7 +1381,7 @@ } bool isFocusAncestor (Control control) { - while (control !is null && control !is this && !(control instanceof Shell)) { + while (control !is null && control !is this && !(cast(Shell) control)) { control = control.parent; } return control is this; @@ -1461,12 +1482,12 @@ return getVisible () && parent.isVisible (); } -int menuForEvent (int nsEvent) { +objc.id menuForEvent (objc.id nsEvent) { NSPoint pt = NSEvent.mouseLocation(); NSWindow window = view.window(); - pt.y = (int) (window.screen().frame().height - pt.y); - int x = (int) pt.x; - int y = (int) pt.y; + pt.y = cast(int) (window.screen().frame().height - pt.y); + int x = cast(int) pt.x; + int y = cast(int) pt.y; Event event = new Event (); event.x = x; event.y = y; @@ -1477,11 +1498,11 @@ if (x !is event.x || y !is event.y) { menu.setLocation (event.x, event.y); } - return menu.nsMenu.id; + return menu.nsMenu.id_; } - objc_super super_struct = new objc_super(); - super_struct.receiver = view.id; - super_struct.cls = OS.objc_msgSend(view.id, OS.sel_superclass); + objc_super super_struct = objc_super(); + super_struct.receiver = view.id_; + super_struct.cls = OS.objc_msgSend(view.id_, OS.sel_superclass); return OS.objc_msgSendSuper(super_struct, OS.sel_menuForEvent_1, nsEvent); } @@ -1547,8 +1568,8 @@ event.count = nsEvent.clickCount(); NSPoint location = nsEvent.locationInWindow(); NSPoint point = view.convertPoint_fromView_(location, null); - event.x = (int) point.x; - event.y = (int) point.y; + event.x = cast(int) point.x; + event.y = cast(int) point.y; setInputState (event, nsEvent, type); sendEvent (type, event); } @@ -1558,12 +1579,12 @@ sendMouseEvent (nsEvent, DWT.MouseDown, 1); } -void mouseDragged(int theEvent) { - NSEvent nsEvent = new NSEvent (theEvent); +void mouseDragged(objc.id theEvent) { + NSEvent nsEvent = new NSEvent (objc.id); sendMouseEvent (nsEvent, DWT.MouseMove, 1); } -void mouseUp(int theEvent) { +void mouseUp(objc.id theEvent) { NSEvent nsEvent = new NSEvent (theEvent); sendMouseEvent (nsEvent, DWT.MouseUp, 1); } @@ -1587,7 +1608,7 @@ if (keyCode !is 0) { event.keyCode = keyCode; } else { - event.character = (char) keys.characterAtIndex (i); + event.character = cast(char) keys.characterAtIndex (i); //TODO - get unshifted values for Shift+1 event.keyCode = keyCodes.characterAtIndex (i); } @@ -1794,7 +1815,7 @@ */ public void redraw (int x, int y, int width, int height, bool all) { checkWidget (); - NSRect rect = new NSRect(); + NSRect rect = NSRect(); rect.x = x; rect.y = y; rect.width = width; @@ -1805,7 +1826,7 @@ void releaseHandle () { super.releaseHandle (); if (view !is null) { - OS.objc_msgSend(view.id, OS.sel_setTag_1, -1); + OS.objc_msgSend(view.id_, OS.sel_setTag_1, -1); view.release(); } view = null; @@ -2370,7 +2391,7 @@ } else if (move) { if (rect.x !is x || rect.y !is y) { result |= MOVED; - NSPoint point = new NSPoint(); + NSPoint point = NSPoint(); point.x = x; point.y = y; topView.setFrameOrigin(point); @@ -2378,7 +2399,7 @@ } else if (resize) { if (rect.width !is width || rect.height !is height) { result |= RESIZED; - NSSize size = new NSSize(); + NSSize size = NSSize(); size.width = width; size.height = height; topView.setFrameSize(size); @@ -2566,8 +2587,8 @@ void setFont (NSFont font) { //TODO - bad cast - if (view instanceof NSControl) { - ((NSControl)view).setFont(font); + if (cast(NSControl) view) { + (cast(NSControl)view).setFont(font); } }