Mercurial > projects > dwt-mac
comparison dwt/widgets/Control.d @ 7:e831403a80a9
Add 'cast' to casts
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Wed, 27 Aug 2008 14:30:35 +0200 |
parents | 1a8b3cb347e0 |
children | a9ab4c738ed8 |
comparison
equal
deleted
inserted
replaced
6:b903c16b6f48 | 7:e831403a80a9 |
---|---|
600 // width += border * 2; | 600 // width += border * 2; |
601 // height += border * 2; | 601 // height += border * 2; |
602 // return new Point (width, height); | 602 // return new Point (width, height); |
603 if (topView() instanceof NSControl) { | 603 if (topView() instanceof NSControl) { |
604 NSRect oldRect = topView().frame(); | 604 NSRect oldRect = topView().frame(); |
605 ((NSControl)topView()).sizeToFit(); | 605 (cast(NSControl)topView()).sizeToFit(); |
606 NSRect newRect = topView().frame(); | 606 NSRect newRect = topView().frame(); |
607 topView().setFrame (oldRect); | 607 topView().setFrame (oldRect); |
608 return new Point ((int)newRect.width, (int)newRect.height); | 608 return new Point (cast(int)newRect.width, cast(int)newRect.height); |
609 } | 609 } |
610 return new Point (width, height); | 610 return new Point (width, height); |
611 } | 611 } |
612 | 612 |
613 Control computeTabGroup () { | 613 Control computeTabGroup () { |
654 } | 654 } |
655 | 655 |
656 Font defaultFont () { | 656 Font defaultFont () { |
657 //TODO - Controls only, does this leak? | 657 //TODO - Controls only, does this leak? |
658 if (view instanceof NSControl) { | 658 if (view instanceof NSControl) { |
659 NSFont nsFont = ((NSControl)view).font (); | 659 NSFont nsFont = (cast(NSControl)view).font (); |
660 if (nsFont !is null) { | 660 if (nsFont !is null) { |
661 return Font.cocoa_new (display, nsFont); | 661 return Font.cocoa_new (display, nsFont); |
662 } | 662 } |
663 } | 663 } |
664 return display.getSystemFont (); | 664 return display.getSystemFont (); |
767 bool dragDetect (int x, int y, bool filter, bool [] consume) { | 767 bool dragDetect (int x, int y, bool filter, bool [] consume) { |
768 // Rect rect = new Rect (); | 768 // Rect rect = new Rect (); |
769 // int window = OS.GetControlOwner (handle); | 769 // int window = OS.GetControlOwner (handle); |
770 // CGPoint pt = new CGPoint (); | 770 // CGPoint pt = new CGPoint (); |
771 // OS.HIViewConvertPoint (pt, handle, 0); | 771 // OS.HIViewConvertPoint (pt, handle, 0); |
772 // x += (int) pt.x; | 772 // x += cast(int) pt.x; |
773 // y += (int) pt.y; | 773 // y += cast(int) pt.y; |
774 // OS.GetWindowBounds (window, (short) OS.kWindowStructureRgn, rect); | 774 // OS.GetWindowBounds (window, cast(short) OS.kWindowStructureRgn, rect); |
775 // x += rect.left; | 775 // x += rect.left; |
776 // y += rect.top; | 776 // y += rect.top; |
777 // dwt.internal.carbon.Point pt1 = new dwt.internal.carbon.Point (); | 777 // dwt.internal.carbon.Point pt1 = new dwt.internal.carbon.Point (); |
778 // pt1.h = (short) x; | 778 // pt1.h = cast(short) x; |
779 // pt1.v = (short) y; | 779 // pt1.v = cast(short) y; |
780 // return OS.WaitMouseMoved (pt1); | 780 // return OS.WaitMouseMoved (pt1); |
781 return false; | 781 return false; |
782 } | 782 } |
783 | 783 |
784 bool drawGripper (int x, int y, int width, int height, bool vertical) { | 784 bool drawGripper (int x, int y, int width, int height, bool vertical) { |
793 GCData data = new GCData (); | 793 GCData data = new GCData (); |
794 data.paintRect = rect; | 794 data.paintRect = rect; |
795 GC gc = GC.cocoa_new (this, data); | 795 GC gc = GC.cocoa_new (this, data); |
796 Event event = new Event (); | 796 Event event = new Event (); |
797 event.gc = gc; | 797 event.gc = gc; |
798 event.x = (int)rect.x; | 798 event.x = cast(int)rect.x; |
799 event.y = (int)rect.y; | 799 event.y = cast(int)rect.y; |
800 event.width = (int)rect.width; | 800 event.width = cast(int)rect.width; |
801 event.height = (int)rect.height; | 801 event.height = cast(int)rect.height; |
802 sendEvent (DWT.Paint, event); | 802 sendEvent (DWT.Paint, event); |
803 event.gc = null; | 803 event.gc = null; |
804 gc.dispose (); | 804 gc.dispose (); |
805 } | 805 } |
806 | 806 |
807 void enableWidget (bool enabled) { | 807 void enableWidget (bool enabled) { |
808 //TODO - other views | 808 //TODO - other views |
809 if (view instanceof NSControl) { | 809 if (view instanceof NSControl) { |
810 ((NSControl)view).setEnabled(enabled); | 810 (cast(NSControl)view).setEnabled(enabled); |
811 } | 811 } |
812 } | 812 } |
813 | 813 |
814 Cursor findCursor () { | 814 Cursor findCursor () { |
815 if (cursor !is null) return cursor; | 815 if (cursor !is null) return cursor; |
963 * </ul> | 963 * </ul> |
964 */ | 964 */ |
965 public Rectangle getBounds () { | 965 public Rectangle getBounds () { |
966 checkWidget(); | 966 checkWidget(); |
967 NSRect rect = topView().frame(); | 967 NSRect rect = topView().frame(); |
968 return new Rectangle((int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height); | 968 return new Rectangle(cast(int)rect.x, cast(int)rect.y, cast(int)rect.width, cast(int)rect.height); |
969 } | 969 } |
970 | 970 |
971 /** | 971 /** |
972 * Returns <code>true</code> if the receiver is detecting | 972 * Returns <code>true</code> if the receiver is detecting |
973 * drag gestures, and <code>false</code> otherwise. | 973 * drag gestures, and <code>false</code> otherwise. |
1088 * </ul> | 1088 * </ul> |
1089 */ | 1089 */ |
1090 public Point getLocation () { | 1090 public Point getLocation () { |
1091 checkWidget(); | 1091 checkWidget(); |
1092 NSRect rect = topView().frame(); | 1092 NSRect rect = topView().frame(); |
1093 return new Point((int)rect.x, (int)rect.y); | 1093 return new Point(cast(int)rect.x, cast(int)rect.y); |
1094 } | 1094 } |
1095 | 1095 |
1096 /** | 1096 /** |
1097 * Returns the receiver's pop up menu if it has one, or null | 1097 * Returns the receiver's pop up menu if it has one, or null |
1098 * if it does not. All controls may optionally have a pop up | 1098 * if it does not. All controls may optionally have a pop up |
1229 * </ul> | 1229 * </ul> |
1230 */ | 1230 */ |
1231 public Point getSize () { | 1231 public Point getSize () { |
1232 checkWidget(); | 1232 checkWidget(); |
1233 NSRect rect = topView().frame(); | 1233 NSRect rect = topView().frame(); |
1234 return new Point((int)rect.width, (int)rect.height); | 1234 return new Point(cast(int)rect.width, cast(int)rect.height); |
1235 } | 1235 } |
1236 | 1236 |
1237 /** | 1237 /** |
1238 * Returns the receiver's tool tip text, or null if it has | 1238 * Returns the receiver's tool tip text, or null if it has |
1239 * not been set. | 1239 * not been set. |
1462 } | 1462 } |
1463 | 1463 |
1464 int menuForEvent (int nsEvent) { | 1464 int menuForEvent (int nsEvent) { |
1465 NSPoint pt = NSEvent.mouseLocation(); | 1465 NSPoint pt = NSEvent.mouseLocation(); |
1466 NSWindow window = view.window(); | 1466 NSWindow window = view.window(); |
1467 pt.y = (int) (window.screen().frame().height - pt.y); | 1467 pt.y = cast(int) (window.screen().frame().height - pt.y); |
1468 int x = (int) pt.x; | 1468 int x = cast(int) pt.x; |
1469 int y = (int) pt.y; | 1469 int y = cast(int) pt.y; |
1470 Event event = new Event (); | 1470 Event event = new Event (); |
1471 event.x = x; | 1471 event.x = x; |
1472 event.y = y; | 1472 event.y = y; |
1473 sendEvent (DWT.MenuDetect, event); | 1473 sendEvent (DWT.MenuDetect, event); |
1474 if (!event.doit) return 0; | 1474 if (!event.doit) return 0; |
1545 event.button = button; | 1545 event.button = button; |
1546 // event.detail = detail; | 1546 // event.detail = detail; |
1547 event.count = nsEvent.clickCount(); | 1547 event.count = nsEvent.clickCount(); |
1548 NSPoint location = nsEvent.locationInWindow(); | 1548 NSPoint location = nsEvent.locationInWindow(); |
1549 NSPoint point = view.convertPoint_fromView_(location, null); | 1549 NSPoint point = view.convertPoint_fromView_(location, null); |
1550 event.x = (int) point.x; | 1550 event.x = cast(int) point.x; |
1551 event.y = (int) point.y; | 1551 event.y = cast(int) point.y; |
1552 setInputState (event, nsEvent, type); | 1552 setInputState (event, nsEvent, type); |
1553 sendEvent (type, event); | 1553 sendEvent (type, event); |
1554 } | 1554 } |
1555 | 1555 |
1556 void mouseDown(int theEvent) { | 1556 void mouseDown(int theEvent) { |
1585 Event event = new Event (); | 1585 Event event = new Event (); |
1586 int keyCode = Display.translateKey (keys.characterAtIndex (i) & 0xFFFF); | 1586 int keyCode = Display.translateKey (keys.characterAtIndex (i) & 0xFFFF); |
1587 if (keyCode !is 0) { | 1587 if (keyCode !is 0) { |
1588 event.keyCode = keyCode; | 1588 event.keyCode = keyCode; |
1589 } else { | 1589 } else { |
1590 event.character = (char) keys.characterAtIndex (i); | 1590 event.character = cast(wchar) keys.characterAtIndex (i); |
1591 //TODO - get unshifted values for Shift+1 | 1591 //TODO - get unshifted values for Shift+1 |
1592 event.keyCode = keyCodes.characterAtIndex (i); | 1592 event.keyCode = keyCodes.characterAtIndex (i); |
1593 } | 1593 } |
1594 setInputState (event, nsEvent, type); | 1594 setInputState (event, nsEvent, type); |
1595 if (!setKeyState(event, type, nsEvent)) return false; | 1595 if (!setKeyState(event, type, nsEvent)) return false; |
2199 | 2199 |
2200 bool sendMouseEvent (int type, short button, int count, int detail, bool send, int theEvent) { | 2200 bool sendMouseEvent (int type, short button, int count, int detail, bool send, int theEvent) { |
2201 // CGPoint pt = new CGPoint (); | 2201 // CGPoint pt = new CGPoint (); |
2202 // OS.GetEventParameter (theEvent, OS.kEventParamWindowMouseLocation, OS.typeHIPoint, null, CGPoint.sizeof, null, pt); | 2202 // OS.GetEventParameter (theEvent, OS.kEventParamWindowMouseLocation, OS.typeHIPoint, null, CGPoint.sizeof, null, pt); |
2203 // OS.HIViewConvertPoint (pt, 0, handle); | 2203 // OS.HIViewConvertPoint (pt, 0, handle); |
2204 // int x = (int) pt.x; | 2204 // int x = cast(int) pt.x; |
2205 // int y = (int) pt.y; | 2205 // int y = cast(int) pt.y; |
2206 // display.lastX = x; | 2206 // display.lastX = x; |
2207 // display.lastY = y; | 2207 // display.lastY = y; |
2208 // int [] chord = new int [1]; | 2208 // int [] chord = new int [1]; |
2209 // OS.GetEventParameter (theEvent, OS.kEventParamMouseChord, OS.typeUInt32, null, 4, null, chord); | 2209 // OS.GetEventParameter (theEvent, OS.kEventParamMouseChord, OS.typeUInt32, null, 4, null, chord); |
2210 // int [] modifiers = new int [1]; | 2210 // int [] modifiers = new int [1]; |
2211 // OS.GetEventParameter (theEvent, OS.kEventParamKeyModifiers, OS.typeUInt32, null, 4, null, modifiers); | 2211 // OS.GetEventParameter (theEvent, OS.kEventParamKeyModifiers, OS.typeUInt32, null, 4, null, modifiers); |
2212 // return sendMouseEvent (type, button, count, detail, send, chord [0], (short) x, (short) y, modifiers [0]); | 2212 // return sendMouseEvent (type, button, count, detail, send, chord [0], cast(short) x, cast(short) y, modifiers [0]); |
2213 return false; | 2213 return false; |
2214 } | 2214 } |
2215 | 2215 |
2216 bool sendMouseEvent (int type, short button, int count, bool send, int chord, short x, short y, int modifiers) { | 2216 bool sendMouseEvent (int type, short button, int count, bool send, int chord, short x, short y, int modifiers) { |
2217 return sendMouseEvent (type, button, count, 0, send, chord, x, y, modifiers); | 2217 return sendMouseEvent (type, button, count, 0, send, chord, x, y, modifiers); |
2311 void setBackground (float [] color) { | 2311 void setBackground (float [] color) { |
2312 } | 2312 } |
2313 | 2313 |
2314 void setBackground (int control, float [] color) { | 2314 void setBackground (int control, float [] color) { |
2315 // ControlFontStyleRec fontStyle = new ControlFontStyleRec (); | 2315 // ControlFontStyleRec fontStyle = new ControlFontStyleRec (); |
2316 // OS.GetControlData (control, (short) OS.kControlEntireControl, OS.kControlFontStyleTag, ControlFontStyleRec.sizeof, fontStyle, null); | 2316 // OS.GetControlData (control, cast(short) OS.kControlEntireControl, OS.kControlFontStyleTag, ControlFontStyleRec.sizeof, fontStyle, null); |
2317 // if (color !is null) { | 2317 // if (color !is null) { |
2318 // fontStyle.backColor_red = (short) (color [0] * 0xffff); | 2318 // fontStyle.backColor_red = cast(short) (color [0] * 0xffff); |
2319 // fontStyle.backColor_green = (short) (color [1] * 0xffff); | 2319 // fontStyle.backColor_green = cast(short) (color [1] * 0xffff); |
2320 // fontStyle.backColor_blue = (short) (color [2] * 0xffff); | 2320 // fontStyle.backColor_blue = cast(short) (color [2] * 0xffff); |
2321 // fontStyle.flags |= OS.kControlUseBackColorMask; | 2321 // fontStyle.flags |= OS.kControlUseBackColorMask; |
2322 // } else { | 2322 // } else { |
2323 // fontStyle.flags &= ~OS.kControlUseBackColorMask; | 2323 // fontStyle.flags &= ~OS.kControlUseBackColorMask; |
2324 // } | 2324 // } |
2325 // OS.SetControlFontStyle (control, fontStyle); | 2325 // OS.SetControlFontStyle (control, fontStyle); |
2565 } | 2565 } |
2566 | 2566 |
2567 void setFont (NSFont font) { | 2567 void setFont (NSFont font) { |
2568 //TODO - bad cast | 2568 //TODO - bad cast |
2569 if (view instanceof NSControl) { | 2569 if (view instanceof NSControl) { |
2570 ((NSControl)view).setFont(font); | 2570 (cast(NSControl)view).setFont(font); |
2571 } | 2571 } |
2572 } | 2572 } |
2573 | 2573 |
2574 /** | 2574 /** |
2575 * Sets the receiver's foreground color to the color specified | 2575 * Sets the receiver's foreground color to the color specified |
2602 void setForeground (float [] color) { | 2602 void setForeground (float [] color) { |
2603 } | 2603 } |
2604 | 2604 |
2605 void setForeground (int control, float [] color) { | 2605 void setForeground (int control, float [] color) { |
2606 // ControlFontStyleRec fontStyle = new ControlFontStyleRec (); | 2606 // ControlFontStyleRec fontStyle = new ControlFontStyleRec (); |
2607 // OS.GetControlData (control, (short) OS.kControlEntireControl, OS.kControlFontStyleTag, ControlFontStyleRec.sizeof, fontStyle, null); | 2607 // OS.GetControlData (control, cast(short) OS.kControlEntireControl, OS.kControlFontStyleTag, ControlFontStyleRec.sizeof, fontStyle, null); |
2608 // if (color !is null) { | 2608 // if (color !is null) { |
2609 // fontStyle.foreColor_red = (short) (color [0] * 0xffff); | 2609 // fontStyle.foreColor_red = cast(short) (color [0] * 0xffff); |
2610 // fontStyle.foreColor_green = (short) (color [1] * 0xffff); | 2610 // fontStyle.foreColor_green = cast(short) (color [1] * 0xffff); |
2611 // fontStyle.foreColor_blue = (short) (color [2] * 0xffff); | 2611 // fontStyle.foreColor_blue = cast(short) (color [2] * 0xffff); |
2612 // fontStyle.flags |= OS.kControlUseForeColorMask; | 2612 // fontStyle.flags |= OS.kControlUseForeColorMask; |
2613 // } else { | 2613 // } else { |
2614 // fontStyle.flags &= ~OS.kControlUseForeColorMask; | 2614 // fontStyle.flags &= ~OS.kControlUseForeColorMask; |
2615 // } | 2615 // } |
2616 // OS.SetControlFontStyle (control, fontStyle); | 2616 // OS.SetControlFontStyle (control, fontStyle); |