Mercurial > projects > dwt-mac
comparison dwt/widgets/Control.d @ 37:642f460a0908
Fixed a lot of compile errors, a "hello world" app compiles now
author | Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com> |
---|---|
date | Fri, 10 Oct 2008 12:29:48 +0200 |
parents | 453387bb0706 |
children | d8635bb48c7c |
comparison
equal
deleted
inserted
replaced
36:db5a898b2119 | 37:642f460a0908 |
---|---|
89 * IMPORTANT: This class is intended to be subclassed <em>only</em> | 89 * IMPORTANT: This class is intended to be subclassed <em>only</em> |
90 * within the DWT implementation. | 90 * within the DWT implementation. |
91 * </p> | 91 * </p> |
92 */ | 92 */ |
93 public abstract class Control : Widget , Drawable { | 93 public abstract class Control : Widget , Drawable { |
94 | |
95 alias Widget.setInputState setInputState; | |
96 | |
94 /** | 97 /** |
95 * the handle to the OS resource | 98 * the handle to the OS resource |
96 * (Warning: This field is platform dependent) | 99 * (Warning: This field is platform dependent) |
97 * <p> | 100 * <p> |
98 * <b>IMPORTANT:</b> This field is <em>not</em> part of the DWT | 101 * <b>IMPORTANT:</b> This field is <em>not</em> part of the DWT |
158 | 161 |
159 bool acceptsFirstResponder () { | 162 bool acceptsFirstResponder () { |
160 objc_super super_struct = objc_super(); | 163 objc_super super_struct = objc_super(); |
161 super_struct.receiver = view.id_; | 164 super_struct.receiver = view.id_; |
162 super_struct.cls = cast(objc.Class) OS.objc_msgSend(view.id_, OS.sel_superclass); | 165 super_struct.cls = cast(objc.Class) OS.objc_msgSend(view.id_, OS.sel_superclass); |
163 return OS.objc_msgSendSuper(super_struct, OS.sel_acceptsFirstResponder) !is null; | 166 return OS.objc_msgSendSuper(&super_struct, OS.sel_acceptsFirstResponder) !is null; |
164 } | 167 } |
165 | 168 |
166 bool becomeFirstResponder () { | 169 bool becomeFirstResponder () { |
167 //TODO - query focusControl() in DWT.FocusIn/Out is the control | 170 //TODO - query focusControl() in DWT.FocusIn/Out is the control |
168 sendEvent (DWT.FocusIn); | 171 sendEvent (DWT.FocusIn); |
169 objc_super super_struct = objc_super(); | 172 objc_super super_struct = objc_super(); |
170 super_struct.receiver = view.id_; | 173 super_struct.receiver = view.id_; |
171 super_struct.cls = OS.objc_msgSend(view.id_, OS.sel_superclass); | 174 super_struct.cls = cast(objc.Class) OS.objc_msgSend(view.id_, OS.sel_superclass); |
172 return OS.objc_msgSendSuper(super_struct, OS.sel_becomeFirstResponder) !is null; | 175 return OS.objc_msgSendSuper(&super_struct, OS.sel_becomeFirstResponder) !is null; |
173 } | 176 } |
174 | 177 |
175 bool resignFirstResponder () { | 178 bool resignFirstResponder () { |
176 //TODO - query focusControl() in DWT.FocusIn/Out is the control | 179 //TODO - query focusControl() in DWT.FocusIn/Out is the control |
177 sendEvent (DWT.FocusOut); | 180 sendEvent (DWT.FocusOut); |
178 objc_super super_struct = objc_super(); | 181 objc_super super_struct = objc_super(); |
179 super_struct.receiver = view.id_; | 182 super_struct.receiver = view.id_; |
180 super_struct.cls = OS.objc_msgSend(view.id_, OS.sel_superclass); | 183 super_struct.cls = cast(objc.Class) OS.objc_msgSend(view.id_, OS.sel_superclass); |
181 return OS.objc_msgSendSuper(super_struct, OS.sel_resignFirstResponder) !is null; | 184 return OS.objc_msgSendSuper(&super_struct, OS.sel_resignFirstResponder) !is null; |
182 } | 185 } |
183 | 186 |
184 /** | 187 /** |
185 * Adds the listener to the collection of listeners who will | 188 * Adds the listener to the collection of listeners who will |
186 * be notified when the control is moved or resized, by sending | 189 * be notified when the control is moved or resized, by sending |
637 } | 640 } |
638 | 641 |
639 Control[] computeTabList() { | 642 Control[] computeTabList() { |
640 if (isTabGroup()) { | 643 if (isTabGroup()) { |
641 if (getVisible() && getEnabled()) { | 644 if (getVisible() && getEnabled()) { |
642 return new Control[] [this]; | 645 return [this]; |
643 } | 646 } |
644 } | 647 } |
645 return new Control[0]; | 648 return new Control[0]; |
646 } | 649 } |
647 | 650 |
804 | 807 |
805 bool drawGripper (int x, int y, int width, int height, bool vertical) { | 808 bool drawGripper (int x, int y, int width, int height, bool vertical) { |
806 return false; | 809 return false; |
807 } | 810 } |
808 | 811 |
809 void drawRect(int id, NSRect rect) { | 812 void drawRect(objc.id id, NSRect rect) { |
810 super.drawRect(id, rect); | 813 super.drawRect(id, rect); |
811 if (!hooks (DWT.Paint) && !filters (DWT.Paint)) return; | 814 if (!hooks (DWT.Paint) && !filters (DWT.Paint)) return; |
812 | 815 |
813 /* Send paint event */ | 816 /* Send paint event */ |
814 GCData data = new GCData (); | 817 GCData data = new GCData (); |
815 data.paintRect = rect; | 818 data.paintRectStruct = rect; |
819 data.paintRect = &data.paintRectStruct; | |
816 GC gc = GC.cocoa_new (this, data); | 820 GC gc = GC.cocoa_new (this, data); |
817 Event event = new Event (); | 821 Event event = new Event (); |
818 event.gc = gc; | 822 event.gc = gc; |
819 event.x = cast(int)rect.x; | 823 event.x = cast(int)rect.x; |
820 event.y = cast(int)rect.y; | 824 event.y = cast(int)rect.y; |
841 if (backgroundImage !is null || background !is null) return this; | 845 if (backgroundImage !is null || background !is null) return this; |
842 return (state & PARENT_BACKGROUND) !is 0 ? parent.findBackgroundControl () : null; | 846 return (state & PARENT_BACKGROUND) !is 0 ? parent.findBackgroundControl () : null; |
843 } | 847 } |
844 | 848 |
845 Menu [] findMenus (Control control) { | 849 Menu [] findMenus (Control control) { |
846 if (menu !is null && this !is control) return new Menu [] [menu]; | 850 if (menu !is null && this !is control) return [menu]; |
847 return new Menu [0]; | 851 return new Menu [0]; |
848 } | 852 } |
849 | 853 |
850 void fixChildren (Shell newShell, Shell oldShell, Decorations newDecorations, Decorations oldDecorations, Menu [] menus) { | 854 void fixChildren (Shell newShell, Shell oldShell, Decorations newDecorations, Decorations oldDecorations, Menu [] menus) { |
851 oldShell.fixShell (newShell, this); | 855 oldShell.fixShell (newShell, this); |
1349 * </p> | 1353 * </p> |
1350 * | 1354 * |
1351 * @param hDC the platform specific GC handle | 1355 * @param hDC the platform specific GC handle |
1352 * @param data the platform specific GC data | 1356 * @param data the platform specific GC data |
1353 */ | 1357 */ |
1354 public void internal_dispose_GC (int context, GCData data) { | 1358 public void internal_dispose_GC (objc.id context, GCData data) { |
1355 checkWidget (); | 1359 checkWidget (); |
1356 } | 1360 } |
1357 | 1361 |
1358 /** | 1362 /** |
1359 * Returns <code>true</code> if the receiver is enabled and all | 1363 * Returns <code>true</code> if the receiver is enabled and all |
1490 int y = cast(int) pt.y; | 1494 int y = cast(int) pt.y; |
1491 Event event = new Event (); | 1495 Event event = new Event (); |
1492 event.x = x; | 1496 event.x = x; |
1493 event.y = y; | 1497 event.y = y; |
1494 sendEvent (DWT.MenuDetect, event); | 1498 sendEvent (DWT.MenuDetect, event); |
1495 if (!event.doit) return 0; | 1499 if (!event.doit) return null; |
1496 Menu menu = getMenu (); | 1500 Menu menu = getMenu (); |
1497 if (menu !is null && !menu.isDisposed ()) { | 1501 if (menu !is null && !menu.isDisposed ()) { |
1498 if (x !is event.x || y !is event.y) { | 1502 if (x !is event.x || y !is event.y) { |
1499 menu.setLocation (event.x, event.y); | 1503 menu.setLocation (event.x, event.y); |
1500 } | 1504 } |
1501 return menu.nsMenu.id_; | 1505 return menu.nsMenu.id_; |
1502 } | 1506 } |
1503 objc_super super_struct = objc_super(); | 1507 objc_super super_struct = objc_super(); |
1504 super_struct.receiver = view.id_; | 1508 super_struct.receiver = view.id_; |
1505 super_struct.cls = OS.objc_msgSend(view.id_, OS.sel_superclass); | 1509 super_struct.cls = cast(objc.Class) OS.objc_msgSend(view.id_, OS.sel_superclass); |
1506 return OS.objc_msgSendSuper(super_struct, OS.sel_menuForEvent_1, nsEvent); | 1510 return OS.objc_msgSendSuper(&super_struct, OS.sel_menuForEvent_1, nsEvent); |
1507 } | 1511 } |
1508 | 1512 |
1509 Decorations menuShell () { | 1513 Decorations menuShell () { |
1510 return parent.menuShell (); | 1514 return parent.menuShell (); |
1511 } | 1515 } |
1572 event.y = cast(int) point.y; | 1576 event.y = cast(int) point.y; |
1573 setInputState (event, nsEvent, type); | 1577 setInputState (event, nsEvent, type); |
1574 sendEvent (type, event); | 1578 sendEvent (type, event); |
1575 } | 1579 } |
1576 | 1580 |
1577 void mouseDown(int theEvent) { | 1581 void mouseDown(objc.id theEvent) { |
1578 NSEvent nsEvent = new NSEvent (theEvent); | 1582 NSEvent nsEvent = new NSEvent (theEvent); |
1579 sendMouseEvent (nsEvent, DWT.MouseDown, 1); | 1583 sendMouseEvent (nsEvent, DWT.MouseDown, 1); |
1580 } | 1584 } |
1581 | 1585 |
1582 void mouseDragged(objc.id theEvent) { | 1586 void mouseDragged(objc.id theEvent) { |
1583 NSEvent nsEvent = new NSEvent (objc.id); | 1587 NSEvent nsEvent = new NSEvent (theEvent); |
1584 sendMouseEvent (nsEvent, DWT.MouseMove, 1); | 1588 sendMouseEvent (nsEvent, DWT.MouseMove, 1); |
1585 } | 1589 } |
1586 | 1590 |
1587 void mouseUp(objc.id theEvent) { | 1591 void mouseUp(objc.id theEvent) { |
1588 NSEvent nsEvent = new NSEvent (theEvent); | 1592 NSEvent nsEvent = new NSEvent (theEvent); |
1612 //TODO - get unshifted values for Shift+1 | 1616 //TODO - get unshifted values for Shift+1 |
1613 event.keyCode = keyCodes.characterAtIndex (i); | 1617 event.keyCode = keyCodes.characterAtIndex (i); |
1614 } | 1618 } |
1615 setInputState (event, nsEvent, type); | 1619 setInputState (event, nsEvent, type); |
1616 if (!setKeyState(event, type, nsEvent)) return false; | 1620 if (!setKeyState(event, type, nsEvent)) return false; |
1617 if (sendKeyEvent (type, event)) { | 1621 if ((cast(Widget)this).sendKeyEvent (type, event)) { |
1618 chars [count++] = chars [i]; | 1622 chars [count++] = chars [i]; |
1619 } | 1623 } |
1620 } | 1624 } |
1621 // if (count is 0) return false; | 1625 // if (count is 0) return false; |
1622 if (count !is keys.length () - 1) { | 1626 if (count !is keys.length () - 1) { |
2523 */ | 2527 */ |
2524 public void setEnabled (bool enabled) { | 2528 public void setEnabled (bool enabled) { |
2525 checkWidget(); | 2529 checkWidget(); |
2526 if (((state & DISABLED) is 0) is enabled) return; | 2530 if (((state & DISABLED) is 0) is enabled) return; |
2527 Control control = null; | 2531 Control control = null; |
2528 bool fixFocus = false; | 2532 bool fixFocus_ = false; |
2529 if (!enabled) { | 2533 if (!enabled) { |
2530 // if (display.focusEvent !is DWT.FocusOut) { | 2534 // if (display.focusEvent !is DWT.FocusOut) { |
2531 control = display.getFocusControl (); | 2535 control = display.getFocusControl (); |
2532 fixFocus = isFocusAncestor (control); | 2536 fixFocus_ = isFocusAncestor (control); |
2533 // } | 2537 // } |
2534 } | 2538 } |
2535 if (enabled) { | 2539 if (enabled) { |
2536 state &= ~DISABLED; | 2540 state &= ~DISABLED; |
2537 } else { | 2541 } else { |
2538 state |= DISABLED; | 2542 state |= DISABLED; |
2539 } | 2543 } |
2540 enableWidget (enabled); | 2544 enableWidget (enabled); |
2541 if (fixFocus) fixFocus (control); | 2545 if (fixFocus_) fixFocus (control); |
2542 } | 2546 } |
2543 | 2547 |
2544 /** | 2548 /** |
2545 * Causes the receiver to have the <em>keyboard focus</em>, | 2549 * Causes the receiver to have the <em>keyboard focus</em>, |
2546 * such that all keyboard events will be delivered to it. Focus | 2550 * such that all keyboard events will be delivered to it. Focus |
2933 * the caret. The fix is to assign focus to the first ancestor | 2937 * the caret. The fix is to assign focus to the first ancestor |
2934 * control that takes focus. If no control will take focus, clear | 2938 * control that takes focus. If no control will take focus, clear |
2935 * the focus control. | 2939 * the focus control. |
2936 */ | 2940 */ |
2937 Control control = null; | 2941 Control control = null; |
2938 bool fixFocus = false; | 2942 bool fixFocus_ = false; |
2939 if (!visible) { | 2943 if (!visible) { |
2940 // if (display.focusEvent !is DWT.FocusOut) { | 2944 // if (display.focusEvent !is DWT.FocusOut) { |
2941 control = display.getFocusControl (); | 2945 control = display.getFocusControl (); |
2942 fixFocus = isFocusAncestor (control); | 2946 fixFocus_ = isFocusAncestor (control); |
2943 // } | 2947 // } |
2944 } | 2948 } |
2945 topView().setHidden(!visible); | 2949 topView().setHidden(!visible); |
2946 if (!visible) { | 2950 if (!visible) { |
2947 /* | 2951 /* |
2950 * event. If this happens, just return. | 2954 * event. If this happens, just return. |
2951 */ | 2955 */ |
2952 sendEvent (DWT.Hide); | 2956 sendEvent (DWT.Hide); |
2953 if (isDisposed ()) return; | 2957 if (isDisposed ()) return; |
2954 } | 2958 } |
2955 if (fixFocus) fixFocus (control); | 2959 if (fixFocus_) fixFocus (control); |
2956 } | 2960 } |
2957 | 2961 |
2958 void setZOrder () { | 2962 void setZOrder () { |
2959 // int topHandle = topHandle (); | 2963 // int topHandle = topHandle (); |
2960 // int parentHandle = parent.handle; | 2964 // int parentHandle = parent.handle; |
2968 | 2972 |
2969 void setZOrder (Control control, bool above) { | 2973 void setZOrder (Control control, bool above) { |
2970 NSView otherView = control is null ? null : control.topView (); | 2974 NSView otherView = control is null ? null : control.topView (); |
2971 view.retain(); | 2975 view.retain(); |
2972 view.removeFromSuperview(); | 2976 view.removeFromSuperview(); |
2973 parent.contentView().addSubview_positioned_relativeTo_(view, above ? OS.NSWindowAbove : OS.NSWindowBelow, otherView); | 2977 parent.contentView().addSubview_positioned_relativeTo_(view, above ? NSWindowAbove : NSWindowBelow, otherView); |
2974 view.release(); | 2978 view.release(); |
2975 } | 2979 } |
2976 | 2980 |
2977 void sort (int [] items) { | 2981 void sort (int [] items) { |
2978 /* Shell Sort from K&R, pg 108 */ | 2982 /* Shell Sort from K&R, pg 108 */ |