comparison dwt/widgets/Control.d @ 46:cfa563df4fdd

Updated Widget and Display to 3.514
author Jacob Carlborg <doob@me.com>
date Fri, 05 Dec 2008 16:00:41 +0100
parents d8635bb48c7c
children 9dd4a17513f9
comparison
equal deleted inserted replaced
45:d8635bb48c7c 46:cfa563df4fdd
57 import dwt.internal.cocoa.NSRect; 57 import dwt.internal.cocoa.NSRect;
58 import dwt.internal.cocoa.NSSize; 58 import dwt.internal.cocoa.NSSize;
59 import dwt.internal.cocoa.NSString; 59 import dwt.internal.cocoa.NSString;
60 import dwt.internal.cocoa.NSView; 60 import dwt.internal.cocoa.NSView;
61 import dwt.internal.cocoa.OS; 61 import dwt.internal.cocoa.OS;
62 import dwt.internal.cocoa.id; 62 import cocoa = dwt.internal.cocoa.id;
63 63
64 import tango.core.Thread; 64 import tango.core.Thread;
65 65
66 import dwt.dwthelper.utils; 66 import dwt.dwthelper.utils;
67 import dwt.dwthelper.System; 67 import dwt.dwthelper.System;
169 super (parent, style); 169 super (parent, style);
170 this.parent = parent; 170 this.parent = parent;
171 createWidget (); 171 createWidget ();
172 } 172 }
173 173
174 int accessibilityActionNames(int /*long*/ id, int /*long*/ sel) { 174 objc.id accessibilityActionNames(objc.id id, objc.SEL sel) {
175 if (accessible !is null) { 175 if (accessible !is null) {
176 NSArray returnValue = accessible.internal_accessibilityActionNames(ACC.CHILDID_SELF); 176 NSArray returnValue = accessible.internal_accessibilityActionNames(ACC.CHILDID_SELF);
177 if (returnValue !is null) return returnValue.id_; 177 if (returnValue !is null) return returnValue.id;
178 } 178 }
179 179
180 return super.accessibilityActionNames(id, sel); 180 return super.accessibilityActionNames(id, sel);
181 } 181 }
182 182
183 int accessibilityAttributeNames(objc.id id, objc.SEL sel) { 183 objc.id accessibilityAttributeNames(objc.id id, objc.SEL sel) {
184 184
185 if (id is view.id_ || (cast(NSControl)view && (cast(NSControl)view).cell() !is null && (cast(NSControl)view).cell().id_ is id)) { 185 if (id is view.id || (cast(NSControl)view && (cast(NSControl)view).cell() !is null && (cast(NSControl)view).cell().id is id)) {
186 if (accessible !is null) { 186 if (accessible !is null) {
187 187
188 // First, see if the accessible is going to define a set of attributes for the control. 188 // First, see if the accessible is going to define a set of attributes for the control.
189 // If it does, return that. 189 // If it does, return that.
190 NSArray returnValue = accessible.internal_accessibilityAttributeNames(ACC.CHILDID_SELF); 190 NSArray returnValue = accessible.internal_accessibilityAttributeNames(ACC.CHILDID_SELF);
203 extraAttributes.removeObjectAtIndex(i); 203 extraAttributes.removeObjectAtIndex(i);
204 } 204 }
205 } 205 }
206 206
207 if (extraAttributes.count() > 0) { 207 if (extraAttributes.count() > 0) {
208 int superResult = super.accessibilityAttributeNames(id, sel); 208 objc.id superResult = super.accessibilityAttributeNames(id, sel);
209 NSArray baseAttributes = new NSArray(superResult); 209 NSArray baseAttributes = new NSArray(superResult);
210 NSMutableArray mutableAttributes = NSMutableArray.arrayWithCapacity(baseAttributes.count() + 1); 210 NSMutableArray mutableAttributes = NSMutableArray.arrayWithCapacity(baseAttributes.count() + 1);
211 mutableAttributes.addObjectsFromArray(baseAttributes); 211 mutableAttributes.addObjectsFromArray(baseAttributes);
212 212
213 for (int i = 0; i < extraAttributes.count(); i++) { 213 for (int i = 0; i < extraAttributes.count(); i++) {
214 id currAttribute = extraAttributes.objectAtIndex(i); 214 cocoa.id currAttribute = extraAttributes.objectAtIndex(i);
215 if (!mutableAttributes.containsObject(currAttribute)) { 215 if (!mutableAttributes.containsObject(currAttribute)) {
216 mutableAttributes.addObject(currAttribute); 216 mutableAttributes.addObject(currAttribute);
217 } 217 }
218 } 218 }
219 219
223 } 223 }
224 224
225 return super.accessibilityAttributeNames(id, sel); 225 return super.accessibilityAttributeNames(id, sel);
226 } 226 }
227 227
228 int accessibilityParameterizedAttributeNames(int /*long*/ id, int /*long*/ sel) { 228 objc.id accessibilityParameterizedAttributeNames(objc.id id, objc.SEL sel) {
229 229
230 if (id is view.id || (view instanceof NSControl && ((NSControl)view).cell() !is null && ((NSControl)view).cell().id is id)) { 230 if (id is view.id || (cast(NSControl)view && (cast(NSControl)view).cell() !is null && (cast(NSControl)view).cell().id is id)) {
231 if (accessible !is null) { 231 if (accessible !is null) {
232 NSArray returnValue = accessible.internal_accessibilityParameterizedAttributeNames(ACC.CHILDID_SELF); 232 NSArray returnValue = accessible.internal_accessibilityParameterizedAttributeNames(ACC.CHILDID_SELF);
233 if (returnValue !is null) return returnValue.id; 233 if (returnValue !is null) return returnValue.id;
234 } 234 }
235 } 235 }
236 236
237 return super.accessibilityParameterizedAttributeNames(id, sel); 237 return super.accessibilityParameterizedAttributeNames(id, sel);
238 } 238 }
239 239
240 240
241 bool accessibilityIsAttributeSettable(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) { 241 bool accessibilityIsAttributeSettable(objc.id id, objc.SEL sel, int /*long*/ arg0) {
242 242
243 // TODO: Carbon didn't support setting attributes, so for now Cocoa doesn't as well. 243 // TODO: Carbon didn't support setting attributes, so for now Cocoa doesn't as well.
244 // NSString attribute = new NSString(arg0); 244 // NSString attribute = new NSString(arg0);
245 // 245 //
246 // if (accessible !is null) { 246 // if (accessible !is null) {
249 // 249 //
250 // return super.accessibilityIsAttributeSettable(id, sel, arg0); 250 // return super.accessibilityIsAttributeSettable(id, sel, arg0);
251 return false; 251 return false;
252 } 252 }
253 253
254 int accessibilityFocusedUIElement(int /*long*/ id, int /*long*/ sel) { 254 objc.id accessibilityFocusedUIElement(objc.id id, objc.SEL sel) {
255 id returnValue = null; 255 cocoa.id returnValue = null;
256 256
257 if (id is view.id || (view instanceof NSControl && ((NSControl)view).cell() !is null && ((NSControl)view).cell().id is id)) { 257 if (id is view.id || (cast(NSControl)view && (cast(NSControl)view).cell() !is null && (cast(NSControl)view).cell().id is id)) {
258 if (accessible !is null) { 258 if (accessible !is null) {
259 returnValue = accessible.internal_accessibilityFocusedUIElement(ACC.CHILDID_SELF); 259 returnValue = accessible.internal_accessibilityFocusedUIElement(ACC.CHILDID_SELF);
260 } 260 }
261 } 261 }
262 262
266 return super.accessibilityFocusedUIElement(id, sel); 266 return super.accessibilityFocusedUIElement(id, sel);
267 else 267 else
268 return returnValue.id; 268 return returnValue.id;
269 } 269 }
270 270
271 int accessibilityHitTest(int /*long*/ id, int /*long*/ sel, NSPoint point) { 271 objc.id accessibilityHitTest(objc.id id, objc.SEL sel, NSPoint point) {
272 id returnValue = null; 272 cocoa.id returnValue = null;
273 273
274 if (id is view.id || (view instanceof NSControl && ((NSControl)view).cell() !is null && ((NSControl)view).cell().id is id)) { 274 if (id is view.id || (cast(NSControl)view && (cast(NSControl)view).cell() !is null && (cast(NSControl)view).cell().id is id)) {
275 if (accessible !is null) { 275 if (accessible !is null) {
276 returnValue = accessible.internal_accessibilityHitTest(point, ACC.CHILDID_SELF); 276 returnValue = accessible.internal_accessibilityHitTest(point, ACC.CHILDID_SELF);
277 } 277 }
278 } 278 }
279 279
283 return super.accessibilityHitTest(id, sel, point); 283 return super.accessibilityHitTest(id, sel, point);
284 else 284 else
285 return returnValue.id; 285 return returnValue.id;
286 } 286 }
287 287
288 int accessibilityAttributeValue(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) { 288 objc.id accessibilityAttributeValue(objc.id id, objc.SEL sel, objc.id arg0) {
289 NSString attribute = new NSString(arg0); 289 NSString attribute = new NSString(arg0);
290 int returnValue = 0; 290 objc.id returnValue = null;
291 id returnObject = null; 291 cocoa.id returnObject = null;
292 292
293 if (accessible !is null) { 293 if (accessible !is null) {
294 returnObject = accessible.internal_accessibilityAttributeValue(attribute, ACC.CHILDID_SELF); 294 returnObject = accessible.internal_accessibilityAttributeValue(attribute, ACC.CHILDID_SELF);
295 } 295 }
296 296
303 } 303 }
304 304
305 return returnValue; 305 return returnValue;
306 } 306 }
307 307
308 int accessibilityAttributeValue_forParameter(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0, int /*long*/ arg1) { 308 objc.id accessibilityAttributeValue_forParameter(objc.id id, objc.SEL sel, objc.id arg0, objc.id arg1) {
309 NSString attribute = new NSString(arg0); 309 NSString attribute = new NSString(arg0);
310 310
311 id returnValue = null; 311 cocoa.id returnValue = null;
312 312
313 if (accessible !is null) { 313 if (accessible !is null) {
314 id parameter = new id(arg1); 314 cocoa.id parameter = new cocoa.id(arg1);
315 returnValue = accessible.internal_accessibilityAttributeValue_forParameter(attribute, parameter, ACC.CHILDID_SELF); 315 returnValue = accessible.internal_accessibilityAttributeValue_forParameter(attribute, parameter, ACC.CHILDID_SELF);
316 } 316 }
317 317
318 // If we had an accessible and it didn't handle the attribute request, let the 318 // If we had an accessible and it didn't handle the attribute request, let the
319 // superclass handle it. 319 // superclass handle it.
848 NSView view = topView (); 848 NSView view = topView ();
849 view.removeFromSuperview (); 849 view.removeFromSuperview ();
850 releaseHandle (); 850 releaseHandle ();
851 } 851 }
852 852
853 void doCommandBySelector (int /*long*/ id, int /*long*/ sel, int /*long*/ selector) { 853 void doCommandBySelector (objc.id id, objc.SEL sel, int /*long*/ selector) {
854 if (view.window ().firstResponder ().id is id) { 854 if (view.window ().firstResponder ().id is id) {
855 NSEvent nsEvent = NSApplication.sharedApplication ().currentEvent (); 855 NSEvent nsEvent = NSApplication.sharedApplication ().currentEvent ();
856 if (nsEvent !is null && nsEvent.type () is OS.NSKeyDown) { 856 if (nsEvent !is null && nsEvent.type () is OS.NSKeyDown) {
857 // TODO is this workaround ok? 857 // TODO is this workaround ok?
858 /* 858 /*
1004 if (control is null) control = this; 1004 if (control is null) control = this;
1005 Image image = control.backgroundImage; 1005 Image image = control.backgroundImage;
1006 if (image !is null && !image.isDisposed()) { 1006 if (image !is null && !image.isDisposed()) {
1007 context.saveGraphicsState(); 1007 context.saveGraphicsState();
1008 NSColor.colorWithPatternImage(image.handle).setFill(); 1008 NSColor.colorWithPatternImage(image.handle).setFill();
1009 NSPoint phase = new NSPoint(); 1009 NSPoint phase = NSPoint();
1010 NSView controlView = control.view; 1010 NSView controlView = control.view;
1011 NSView contentView = controlView.window().contentView(); 1011 NSView contentView = controlView.window().contentView();
1012 phase = controlView.convertPoint_toView_(phase, contentView); 1012 phase = controlView.convertPoint_toView_(phase, contentView);
1013 phase.y = contentView.bounds().height - phase.y; 1013 phase.y = contentView.bounds().height - phase.y;
1014 context.setPatternPhase(phase); 1014 context.setPatternPhase(phase);
1056 shell.setSavedFocus (focusControl); 1056 shell.setSavedFocus (focusControl);
1057 // int window = OS.GetControlOwner (handle); 1057 // int window = OS.GetControlOwner (handle);
1058 // OS.ClearKeyboardFocus (window); 1058 // OS.ClearKeyboardFocus (window);
1059 } 1059 }
1060 1060
1061 void flagsChanged (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) { 1061 void flagsChanged (objc.id id, objc.SEL sel, int /*long*/ theEvent) {
1062 if (view.window ().firstResponder ().id is id) { 1062 if (view.window ().firstResponder ().id is id) {
1063 if ((state & SAFARI_EVENTS_FIX) is 0) { 1063 if ((state & SAFARI_EVENTS_FIX) is 0) {
1064 int mask = 0; 1064 int mask = 0;
1065 NSEvent nsEvent = new NSEvent (theEvent); 1065 NSEvent nsEvent = new NSEvent (theEvent);
1066 int /*long*/ modifiers = nsEvent.modifierFlags (); 1066 int /*long*/ modifiers = nsEvent.modifierFlags ();
1553 1553
1554 bool hasFocus () { 1554 bool hasFocus () {
1555 return (view.window().firstResponder().id is view.id); 1555 return (view.window().firstResponder().id is view.id);
1556 } 1556 }
1557 1557
1558 int /*long*/ hitTest (int /*long*/ id, int /*long*/ sel, NSPoint point) { 1558 int /*long*/ hitTest (objc.id id, objc.SEL sel, NSPoint point) {
1559 if ((state & DISABLED) !is 0) return 0; 1559 if ((state & DISABLED) !is 0) return 0;
1560 return super.hitTest(id, sel, point); 1560 return super.hitTest(id, sel, point);
1561 } 1561 }
1562 1562
1563 bool insertText (int /*long*/ id, int /*long*/ sel, int /*long*/ string) { 1563 bool insertText (objc.id id, objc.SEL sel, int /*long*/ string) {
1564 if (view.window ().firstResponder ().id is id) { 1564 if (view.window ().firstResponder ().id is id) {
1565 NSEvent nsEvent = NSApplication.sharedApplication ().currentEvent (); 1565 NSEvent nsEvent = NSApplication.sharedApplication ().currentEvent ();
1566 if (nsEvent !is null && nsEvent.type () is OS.NSKeyDown) { 1566 if (nsEvent !is null && nsEvent.type () is OS.NSKeyDown) {
1567 NSString str = new NSString (string); 1567 NSString str = new NSString (string);
1568 if (str.isKindOfClass (OS.objc_getClass ("NSAttributedString"))) { 1568 if (str.isKindOfClass (OS.objc_getClass ("NSAttributedString"))) {
1598 */ 1598 */
1599 public objc.id internal_new_GC (GCData data) { 1599 public objc.id internal_new_GC (GCData data) {
1600 checkWidget(); 1600 checkWidget();
1601 objc.id context = null; 1601 objc.id context = null;
1602 if (data !is null && data.paintRect !is null) { 1602 if (data !is null && data.paintRect !is null) {
1603 context = NSGraphicsContext.currentContext().id_; 1603 context = NSGraphicsContext.currentContext().id;
1604 } else { 1604 } else {
1605 NSGraphicsContext graphicsContext = NSGraphicsContext.graphicsContextWithWindow (view.window ()); 1605 NSGraphicsContext graphicsContext = NSGraphicsContext.graphicsContextWithWindow (view.window ());
1606 display.addContext (graphicsContext); 1606 display.addContext (graphicsContext);
1607 context = graphicsContext.id_; 1607 context = graphicsContext.id;
1608 } 1608 }
1609 if (data !is null) { 1609 if (data !is null) {
1610 int mask = DWT.LEFT_TO_RIGHT | DWT.RIGHT_TO_LEFT; 1610 int mask = DWT.LEFT_TO_RIGHT | DWT.RIGHT_TO_LEFT;
1611 if ((data.style & mask) is 0) { 1611 if ((data.style & mask) is 0) {
1612 data.style |= style & (mask | DWT.MIRRORED); 1612 data.style |= style & (mask | DWT.MIRRORED);
1775 checkWidget(); 1775 checkWidget();
1776 return getVisible () && parent.isVisible (); 1776 return getVisible () && parent.isVisible ();
1777 } 1777 }
1778 1778
1779 void keyDown (objc.id id, objc.SEL sel, objc.id theEvent) { 1779 void keyDown (objc.id id, objc.SEL sel, objc.id theEvent) {
1780 if (view.window ().firstResponder ().id_ is id) { 1780 if (view.window ().firstResponder ().id is id) {
1781 bool textInput = OS.objc_msgSend (id, OS.sel_conformsToProtocol_, OS.objc_getProtocol ("NSTextInput")) !is null; 1781 bool textInput = OS.objc_msgSend (id, OS.sel_conformsToProtocol_, OS.objc_getProtocol ("NSTextInput")) !is null;
1782 if (!textInput) { 1782 if (!textInput) {
1783 NSEvent nsEvent = new NSEvent (theEvent); 1783 NSEvent nsEvent = new NSEvent (theEvent);
1784 bool [] consume = new bool [1]; 1784 bool [] consume = new bool [1];
1785 if (translateTraversal (nsEvent.keyCode (), nsEvent, consume)) return; 1785 if (translateTraversal (nsEvent.keyCode (), nsEvent, consume)) return;
1789 } 1789 }
1790 } 1790 }
1791 super.keyDown (id, sel, theEvent); 1791 super.keyDown (id, sel, theEvent);
1792 } 1792 }
1793 1793
1794 void keyUp (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) { 1794 void keyUp (objc.id id, objc.SEL sel, int /*long*/ theEvent) {
1795 if (view.window ().firstResponder ().id is id) { 1795 if (view.window ().firstResponder ().id is id) {
1796 NSEvent nsEvent = new NSEvent (theEvent); 1796 NSEvent nsEvent = new NSEvent (theEvent);
1797 if (!sendKeyEvent (nsEvent, DWT.KeyUp)) return; 1797 if (!sendKeyEvent (nsEvent, DWT.KeyUp)) return;
1798 } 1798 }
1799 super.keyUp (id, sel, theEvent); 1799 super.keyUp (id, sel, theEvent);
1801 1801
1802 void markLayout (bool changed, bool all) { 1802 void markLayout (bool changed, bool all) {
1803 /* Do nothing */ 1803 /* Do nothing */
1804 } 1804 }
1805 1805
1806 int /*long*/ menuForEvent (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) { 1806 int /*long*/ menuForEvent (objc.id id, objc.SEL sel, int /*long*/ theEvent) {
1807 NSPoint pt = NSEvent.mouseLocation(); 1807 NSPoint pt = NSEvent.mouseLocation();
1808 pt.y = (int) (display.getPrimaryFrame().height - pt.y); 1808 pt.y = (int) (display.getPrimaryFrame().height - pt.y);
1809 int x = cast(int) pt.x; 1809 int x = cast(int) pt.x;
1810 int y = cast(int) pt.y; 1810 int y = cast(int) pt.y;
1811 Event event = new Event (); 1811 Event event = new Event ();
1816 Menu menu = getMenu (); 1816 Menu menu = getMenu ();
1817 if (menu !is null && !menu.isDisposed ()) { 1817 if (menu !is null && !menu.isDisposed ()) {
1818 if (x !is event.x || y !is event.y) { 1818 if (x !is event.x || y !is event.y) {
1819 menu.setLocation (event.x, event.y); 1819 menu.setLocation (event.x, event.y);
1820 } 1820 }
1821 return menu.nsMenu.id_; 1821 return menu.nsMenu.id;
1822 } 1822 }
1823 return super.menuForEvent (id, sel, theEvent); 1823 return super.menuForEvent (id, sel, theEvent);
1824 } 1824 }
1825 1825
1826 Decorations menuShell () { 1826 Decorations menuShell () {
1827 return parent.menuShell (); 1827 return parent.menuShell ();
1828 } 1828 }
1829 1829
1830 void scrollWheel (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) { 1830 void scrollWheel (objc.id id, objc.SEL sel, int /*long*/ theEvent) {
1831 if (id is view.id) { 1831 if (id is view.id) {
1832 if (hooks (DWT.MouseWheel) || filters (DWT.MouseWheel)) { 1832 if (hooks (DWT.MouseWheel) || filters (DWT.MouseWheel)) {
1833 NSEvent nsEvent = new NSEvent(theEvent); 1833 NSEvent nsEvent = new NSEvent(theEvent);
1834 if (nsEvent.deltaY() !is 0) { 1834 if (nsEvent.deltaY() !is 0) {
1835 if (!sendMouseEvent(nsEvent, DWT.MouseWheel, true)) { 1835 if (!sendMouseEvent(nsEvent, DWT.MouseWheel, true)) {
1839 } 1839 }
1840 } 1840 }
1841 super.scrollWheel(id, sel, theEvent); 1841 super.scrollWheel(id, sel, theEvent);
1842 } 1842 }
1843 1843
1844 void mouseDown(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) { 1844 void mouseDown(objc.id id, objc.SEL sel, int /*long*/ theEvent) {
1845 Display display = this.display; 1845 Display display = this.display;
1846 display.trackingControl = this; 1846 display.trackingControl = this;
1847 super.mouseDown(id, sel, theEvent); 1847 super.mouseDown(id, sel, theEvent);
1848 display.trackingControl = null; 1848 display.trackingControl = null;
1849 } 1849 }
2608 } 2608 }
2609 2609
2610 void setBounds (int x, int y, int width, int height, bool move, bool resize) { 2610 void setBounds (int x, int y, int width, int height, bool move, bool resize) {
2611 NSView topView = topView(); 2611 NSView topView = topView();
2612 if (move && resize) { 2612 if (move && resize) {
2613 NSRect rect = new NSRect(); 2613 NSRect rect = NSRect();
2614 rect.x = x; 2614 rect.x = x;
2615 rect.y = y; 2615 rect.y = y;
2616 rect.width = width; 2616 rect.width = width;
2617 rect.height = height; 2617 rect.height = height;
2618 topView.setFrame (rect); 2618 topView.setFrame (rect);
2849 // fontStyle.flags &= ~OS.kControlUseForeColorMask; 2849 // fontStyle.flags &= ~OS.kControlUseForeColorMask;
2850 // } 2850 // }
2851 // OS.SetControlFontStyle (control, fontStyle); 2851 // OS.SetControlFontStyle (control, fontStyle);
2852 } 2852 }
2853 2853
2854 void setFrameOrigin (int /*long*/ id, int /*long*/ sel, NSPoint point) { 2854 void setFrameOrigin (objc.id id, objc.SEL sel, NSPoint point) {
2855 NSView topView = topView (); 2855 NSView topView = topView ();
2856 if (topView.id !is id) { 2856 if (topView.id !is id) {
2857 super.setFrameOrigin(id, sel, point); 2857 super.setFrameOrigin(id, sel, point);
2858 return; 2858 return;
2859 } 2859 }
2862 if (frame.x !is point.x || frame.y !is point.y) { 2862 if (frame.x !is point.x || frame.y !is point.y) {
2863 moved (); 2863 moved ();
2864 } 2864 }
2865 } 2865 }
2866 2866
2867 void setFrameSize (int /*long*/ id, int /*long*/ sel, NSSize size) { 2867 void setFrameSize (objc.id id, objc.SEL sel, NSSize size) {
2868 NSView topView = topView (); 2868 NSView topView = topView ();
2869 if (topView.id !is id) { 2869 if (topView.id !is id) {
2870 super.setFrameSize(id, sel, size); 2870 super.setFrameSize(id, sel, size);
2871 return; 2871 return;
2872 } 2872 }