comparison dstep/appkit/NSControl.d @ 16:19885b43130e

Huge update, the bridge actually works now
author Jacob Carlborg <doob@me.com>
date Sun, 03 Jan 2010 22:06:11 +0100
parents
children b9de51448c6b
comparison
equal deleted inserted replaced
15:7ff919f595d5 16:19885b43130e
1 /**
2 * Copyright: Copyright (c) 2009 Jacob Carlborg.
3 * Authors: Jacob Carlborg
4 * Version: Initial created: Sep 24, 2009
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
6 */
7 module dstep.appkit.NSControl;
8
9 import dstep.appkit.NSCell;
10 import dstep.appkit.NSEvent;
11 import dstep.appkit.NSFont;
12 import dstep.appkit.NSText;
13 import dstep.appkit.NSTextView;
14 import dstep.appkit.NSView;
15 import dstep.foundation.NSAttributedString;
16 import dstep.foundation.NSFormatter;
17 import dstep.foundation.NSGeometry;
18 import dstep.foundation.NSObjCRuntime;
19 import dstep.foundation.NSObject;
20 import dstep.foundation.NSNotification;
21 import dstep.foundation.NSString;
22 import dstep.objc.bridge.Bridge;
23 import dstep.objc.objc;
24
25 import bindings = dstep.appkit.NSControl_bindings;
26
27 private
28 {
29 NSString NSControlTextDidBeginEditingNotification_;
30 NSString NSControlTextDidEndEditingNotification_;
31 NSString NSControlTextDidChangeNotification_;
32 }
33
34 NSString NSControlTextDidBeginEditingNotification ()
35 {
36 if (NSControlTextDidBeginEditingNotification_)
37 return NSControlTextDidBeginEditingNotification_;
38
39 return NSControlTextDidBeginEditingNotification_ = new NSString(bindings.NSControlTextDidBeginEditingNotification);
40 }
41
42 NSString NSControlTextDidEndEditingNotification ()
43 {
44 if (NSControlTextDidEndEditingNotification_)
45 return NSControlTextDidEndEditingNotification_;
46
47 return NSControlTextDidEndEditingNotification_ = new NSString(bindings.NSControlTextDidEndEditingNotification);
48 }
49
50 NSString NSControlTextDidChangeNotification ()
51 {
52 if (NSControlTextDidChangeNotification_)
53 return NSControlTextDidChangeNotification_;
54
55 return NSControlTextDidChangeNotification_ = new NSString(bindings.NSControlTextDidChangeNotification);
56 }
57
58 const TNSControlSubclassNotifications = `
59
60 void controlTextDidBeginEditing (NSNotification obj)
61 {
62 return invokeObjcSelf!(void, "controlTextDidBeginEditing:", NSNotification)(obj);
63 }
64
65 void controlTextDidEndEditing (NSNotification obj)
66 {
67 return invokeObjcSelf!(void, "controlTextDidEndEditing:", NSNotification)(obj);
68 }
69
70 void controlTextDidChange (NSNotification obj)
71 {
72 return invokeObjcSelf!(void, "controlTextDidChange:", NSNotification)(obj);
73 }
74
75 //mixin ObjcBindMethod!(controlTextDidBeginEditing, "controlTextDidBeginEditing:");
76 //mixin ObjcBindMethod!(controlTextDidEndEditing, "controlTextDidEndEditing:");
77 //mixin ObjcBindMethod!(controlTextDidChange, "controlTextDidChange:");
78
79 `;
80
81 const TNSControlAttributedStringMethods = `
82
83 NSAttributedString attributedStringValue ()
84 {
85 return invokeObjcSelf!(NSAttributedString, "attributedStringValue");
86 }
87
88 void setAttributedStringValue (NSAttributedString obj)
89 {
90 return invokeObjcSelf!(void, "setAttributedStringValue:", NSAttributedString)(obj);
91 }
92
93 //mixin ObjcBindMethod!(attributedStringValue, "attributedStringValue");
94 //mixin ObjcBindMethod!(setAttributedStringValue, "setAttributedStringValue:");
95
96 `;
97
98 const TNSControlSubclassDelegate = `
99
100 bool control (NSControl control, NSText fieldEditor)
101 {
102 return invokeObjcSelf!(bool, "control:textShouldBeginEditing:", NSControl, NSText)(control, fieldEditor);
103 }
104
105 bool control (NSControl control, NSText fieldEditor)
106 {
107 return invokeObjcSelf!(bool, "control:textShouldEndEditing:", NSControl, NSText)(control, fieldEditor);
108 }
109
110 bool control (NSControl control, NSString string, NSString error)
111 {
112 return invokeObjcSelf!(bool, "control:didFailToFormatString:errorDescription:", NSControl, NSString, NSString)(control, string, error);
113 }
114
115 void control (NSControl control, NSString string, NSString error)
116 {
117 return invokeObjcSelf!(void, "control:didFailToValidatePartialString:errorDescription:", NSControl, NSString, NSString)(control, string, error);
118 }
119
120 bool control (NSControl control, Object obj)
121 {
122 return invokeObjcSelf!(bool, "control:isValidObject:", NSControl, Object)(control, obj);
123 }
124
125 bool control (NSControl control, NSTextView textView, SEL commandSelector)
126 {
127 return invokeObjcSelf!(bool, "control:textView:doCommandBySelector:", NSControl, NSTextView, SEL)(control, textView, commandSelector);
128 }
129
130 NSArray control (NSControl control, NSTextView textView, NSArray words, NSRange charRange, NSInteger* index)
131 {
132 return invokeObjcSelf!(NSArray, "control:textView:completions:forPartialWordRange:indexOfSelectedItem:", NSControl, NSTextView, NSArray, NSRange, NSInteger*)(control, textView, words, charRange, index);
133 }
134
135 //mixin ObjcBindMethod!(control, "control:textShouldBeginEditing:");
136 //mixin ObjcBindMethod!(control, "control:textShouldEndEditing:");
137 //mixin ObjcBindMethod!(control, "control:didFailToFormatString:errorDescription:");
138 //mixin ObjcBindMethod!(control, "control:didFailToValidatePartialString:errorDescription:");
139 //mixin ObjcBindMethod!(control, "control:isValidObject:");
140 //mixin ObjcBindMethod!(control, "control:textView:doCommandBySelector:");
141 //mixin ObjcBindMethod!(control, "control:textView:completions:forPartialWordRange:indexOfSelectedItem:");
142
143 `;
144
145 class NSControl : NSView
146 {
147 mixin (ObjcWrap);
148
149 static void setCellClass (Class factoryId)
150 {
151 return invokeObjcSelfClass!(void, "setCellClass:", Class)(factoryId);
152 }
153
154 static Class cellClass ()
155 {
156 return invokeObjcSelfClass!(Class, "cellClass");
157 }
158
159 NSControl initWithFrame (NSRect frameRect)
160 {
161 id result = invokeObjcSelf!(id, "initWithFrame:", NSRect)(frameRect);
162 return result is this.objcObject ? this : (result !is null ? new NSControl(result) : null);
163 }
164
165 this (NSRect frameRect)
166 {
167 super(NSControl.alloc.initWithFrame(frameRect).objcObject);
168 }
169
170 void sizeToFit ()
171 {
172 return invokeObjcSelf!(void, "sizeToFit");
173 }
174
175 void calcSize ()
176 {
177 return invokeObjcSelf!(void, "calcSize");
178 }
179
180 Object cell ()
181 {
182 return invokeObjcSelf!(Object, "cell");
183 }
184
185 void setCell (NSCell aCell)
186 {
187 return invokeObjcSelf!(void, "setCell:", NSCell)(aCell);
188 }
189
190 Object selectedCell ()
191 {
192 return invokeObjcSelf!(Object, "selectedCell");
193 }
194
195 Object target ()
196 {
197 return invokeObjcSelf!(Object, "target");
198 }
199
200 void setTarget (Object anObject)
201 {
202 return invokeObjcSelf!(void, "setTarget:", Object)(anObject);
203 }
204
205 SEL action ()
206 {
207 return invokeObjcSelf!(SEL, "action");
208 }
209
210 void setAction (SEL aSelector)
211 {
212 return invokeObjcSelf!(void, "setAction:", SEL)(aSelector);
213 }
214
215 NSInteger tag ()
216 {
217 return invokeObjcSelf!(NSInteger, "tag");
218 }
219
220 void setTag (NSInteger anInt)
221 {
222 return invokeObjcSelf!(void, "setTag:", NSInteger)(anInt);
223 }
224
225 NSInteger selectedTag ()
226 {
227 return invokeObjcSelf!(NSInteger, "selectedTag");
228 }
229
230 void setIgnoresMultiClick (bool flag)
231 {
232 return invokeObjcSelf!(void, "setIgnoresMultiClick:", bool)(flag);
233 }
234
235 bool ignoresMultiClick ()
236 {
237 return invokeObjcSelf!(bool, "ignoresMultiClick");
238 }
239
240 NSInteger sendActionOn (NSInteger mask)
241 {
242 return invokeObjcSelf!(NSInteger, "sendActionOn:", NSInteger)(mask);
243 }
244
245 bool isContinuous ()
246 {
247 return invokeObjcSelf!(bool, "isContinuous");
248 }
249
250 void setContinuous (bool flag)
251 {
252 return invokeObjcSelf!(void, "setContinuous:", bool)(flag);
253 }
254
255 bool isEnabled ()
256 {
257 return invokeObjcSelf!(bool, "isEnabled");
258 }
259
260 void setEnabled (bool flag)
261 {
262 return invokeObjcSelf!(void, "setEnabled:", bool)(flag);
263 }
264
265 void setFloatingPointFormat (bool autoRange, NSUInteger leftDigits, NSUInteger rightDigits)
266 {
267 return invokeObjcSelf!(void, "setFloatingPointFormat:left:right:", bool, NSUInteger, NSUInteger)(autoRange, leftDigits, rightDigits);
268 }
269
270 uint alignment ()
271 {
272 return invokeObjcSelf!(uint, "alignment");
273 }
274
275 void setAlignment (uint mode)
276 {
277 return invokeObjcSelf!(void, "setAlignment:", uint)(mode);
278 }
279
280 NSFont font ()
281 {
282 return invokeObjcSelf!(NSFont, "font");
283 }
284
285 void setFont (NSFont fontObj)
286 {
287 return invokeObjcSelf!(void, "setFont:", NSFont)(fontObj);
288 }
289
290 void setFormatter (NSFormatter newFormatter)
291 {
292 return invokeObjcSelf!(void, "setFormatter:", NSFormatter)(newFormatter);
293 }
294
295 Object formatter ()
296 {
297 return invokeObjcSelf!(Object, "formatter");
298 }
299
300 void setObjectValue (INSCopying obj)
301 {
302 return invokeObjcSelf!(void, "setObjectValue:", INSCopying)(obj);
303 }
304
305 void setStringValue (NSString aString)
306 {
307 return invokeObjcSelf!(void, "setStringValue:", NSString)(aString);
308 }
309
310 void setIntValue (int anInt)
311 {
312 return invokeObjcSelf!(void, "setIntValue:", int)(anInt);
313 }
314
315 void setFloatValue (float aFloat)
316 {
317 return invokeObjcSelf!(void, "setFloatValue:", float)(aFloat);
318 }
319
320 void setDoubleValue (double aDouble)
321 {
322 return invokeObjcSelf!(void, "setDoubleValue:", double)(aDouble);
323 }
324
325 Object objectValue ()
326 {
327 return invokeObjcSelf!(Object, "objectValue");
328 }
329
330 NSString stringValue ()
331 {
332 return invokeObjcSelf!(NSString, "stringValue");
333 }
334
335 int intValue ()
336 {
337 return invokeObjcSelf!(int, "intValue");
338 }
339
340 float floatValue ()
341 {
342 return invokeObjcSelf!(float, "floatValue");
343 }
344
345 double doubleValue ()
346 {
347 return invokeObjcSelf!(double, "doubleValue");
348 }
349
350 void setNeedsDisplay ()
351 {
352 return invokeObjcSelf!(void, "setNeedsDisplay");
353 }
354
355 void updateCell (NSCell aCell)
356 {
357 return invokeObjcSelf!(void, "updateCell:", NSCell)(aCell);
358 }
359
360 void updateCellInside (NSCell aCell)
361 {
362 return invokeObjcSelf!(void, "updateCellInside:", NSCell)(aCell);
363 }
364
365 void drawCellInside (NSCell aCell)
366 {
367 return invokeObjcSelf!(void, "drawCellInside:", NSCell)(aCell);
368 }
369
370 void drawCell (NSCell aCell)
371 {
372 return invokeObjcSelf!(void, "drawCell:", NSCell)(aCell);
373 }
374
375 void selectCell (NSCell aCell)
376 {
377 return invokeObjcSelf!(void, "selectCell:", NSCell)(aCell);
378 }
379
380 bool sendAction (SEL theAction, Object theTarget)
381 {
382 return invokeObjcSelf!(bool, "sendAction:to:", SEL, Object)(theAction, theTarget);
383 }
384
385 void takeIntValueFrom (Object sender)
386 {
387 return invokeObjcSelf!(void, "takeIntValueFrom:", Object)(sender);
388 }
389
390 void takeFloatValueFrom (Object sender)
391 {
392 return invokeObjcSelf!(void, "takeFloatValueFrom:", Object)(sender);
393 }
394
395 void takeDoubleValueFrom (Object sender)
396 {
397 return invokeObjcSelf!(void, "takeDoubleValueFrom:", Object)(sender);
398 }
399
400 void takeStringValueFrom (Object sender)
401 {
402 return invokeObjcSelf!(void, "takeStringValueFrom:", Object)(sender);
403 }
404
405 void takeObjectValueFrom (Object sender)
406 {
407 return invokeObjcSelf!(void, "takeObjectValueFrom:", Object)(sender);
408 }
409
410 NSText currentEditor ()
411 {
412 return invokeObjcSelf!(NSText, "currentEditor");
413 }
414
415 bool abortEditing ()
416 {
417 return invokeObjcSelf!(bool, "abortEditing");
418 }
419
420 void validateEditing ()
421 {
422 return invokeObjcSelf!(void, "validateEditing");
423 }
424
425 void mouseDown (NSEvent theEvent)
426 {
427 return invokeObjcSelf!(void, "mouseDown:", NSEvent)(theEvent);
428 }
429
430 int baseWritingDirection ()
431 {
432 return invokeObjcSelf!(int, "baseWritingDirection");
433 }
434
435 void setBaseWritingDirection (int writingDirection)
436 {
437 return invokeObjcSelf!(void, "setBaseWritingDirection:", int)(writingDirection);
438 }
439
440 NSInteger integerValue ()
441 {
442 return invokeObjcSelf!(NSInteger, "integerValue");
443 }
444
445 void setIntegerValue (NSInteger anInteger)
446 {
447 return invokeObjcSelf!(void, "setIntegerValue:", NSInteger)(anInteger);
448 }
449
450 void takeIntegerValueFrom (Object sender)
451 {
452 return invokeObjcSelf!(void, "takeIntegerValueFrom:", Object)(sender);
453 }
454
455 // NSControlAttributedStringMethods
456 NSAttributedString attributedStringValue ()
457 {
458 return invokeObjcSelf!(NSAttributedString, "attributedStringValue");
459 }
460
461 void setAttributedStringValue (NSAttributedString obj)
462 {
463 return invokeObjcSelf!(void, "setAttributedStringValue:", NSAttributedString)(obj);
464 }
465 }