comparison dstep/appkit/NSMenu.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.NSMenu;
8
9 import dstep.appkit.AppKitDefines;
10 import dstep.appkit.NSEvent;
11 import dstep.appkit.NSFont;
12 import dstep.appkit.NSMenuItem;
13 import dstep.appkit.NSView;
14 import dstep.applicationservices.coregraphics.CGBase;
15 import dstep.foundation.NSArray;
16 import dstep.foundation.NSCoder;
17 import dstep.foundation.NSGeometry;
18 import dstep.foundation.NSObjCRuntime;
19 import dstep.foundation.NSObject;
20 import dstep.foundation.NSString;
21 import dstep.foundation.NSZone;
22 import dstep.objc.bridge.Bridge;
23 import dstep.objc.objc;
24
25 import bindings = dstep.appkit.NSMenu_bindings;
26
27 private
28 {
29 NSString NSMenuWillSendActionNotification_;
30 NSString NSMenuDidSendActionNotification_;
31 NSString NSMenuDidAddItemNotification_;
32 NSString NSMenuDidRemoveItemNotification_;
33 NSString NSMenuDidChangeItemNotification_;
34 NSString NSMenuDidBeginTrackingNotification_;
35 NSString NSMenuDidEndTrackingNotification_;
36 }
37
38 NSString NSMenuWillSendActionNotification ()
39 {
40 if (NSMenuWillSendActionNotification_)
41 return NSMenuWillSendActionNotification_;
42
43 return NSMenuWillSendActionNotification_ = new NSString(bindings.NSMenuWillSendActionNotification);
44 }
45
46 NSString NSMenuDidSendActionNotification ()
47 {
48 if (NSMenuDidSendActionNotification_)
49 return NSMenuDidSendActionNotification_;
50
51 return NSMenuDidSendActionNotification_ = new NSString(bindings.NSMenuDidSendActionNotification);
52 }
53
54 NSString NSMenuDidAddItemNotification ()
55 {
56 if (NSMenuDidAddItemNotification_)
57 return NSMenuDidAddItemNotification_;
58
59 return NSMenuDidAddItemNotification_ = new NSString(bindings.NSMenuDidAddItemNotification);
60 }
61
62 NSString NSMenuDidRemoveItemNotification ()
63 {
64 if (NSMenuDidRemoveItemNotification_)
65 return NSMenuDidRemoveItemNotification_;
66
67 return NSMenuDidRemoveItemNotification_ = new NSString(bindings.NSMenuDidRemoveItemNotification);
68 }
69
70 NSString NSMenuDidChangeItemNotification ()
71 {
72 if (NSMenuDidChangeItemNotification_)
73 return NSMenuDidChangeItemNotification_;
74
75 return NSMenuDidChangeItemNotification_ = new NSString(bindings.NSMenuDidChangeItemNotification);
76 }
77
78 NSString NSMenuDidBeginTrackingNotification ()
79 {
80 if (NSMenuDidBeginTrackingNotification_)
81 return NSMenuDidBeginTrackingNotification_;
82
83 return NSMenuDidBeginTrackingNotification_ = new NSString(bindings.NSMenuDidBeginTrackingNotification);
84 }
85
86 NSString NSMenuDidEndTrackingNotification ()
87 {
88 if (NSMenuDidEndTrackingNotification_)
89 return NSMenuDidEndTrackingNotification_;
90
91 return NSMenuDidEndTrackingNotification_ = new NSString(bindings.NSMenuDidEndTrackingNotification);
92 }
93
94 const TNSMenuDelegate = `
95
96 void menuNeedsUpdate (NSMenu menu)
97 {
98 return invokeObjcSelf!(void, "menuNeedsUpdate:", NSMenu)(menu);
99 }
100
101 NSInteger numberOfItemsInMenu (NSMenu menu)
102 {
103 return invokeObjcSelf!(NSInteger, "numberOfItemsInMenu:", NSMenu)(menu);
104 }
105
106 bool menu (NSMenu menu, NSMenuItem item, NSInteger index, bool shouldCancel)
107 {
108 return invokeObjcSelf!(bool, "menu:updateItem:atIndex:shouldCancel:", NSMenu, NSMenuItem, NSInteger, bool)(menu, item, index, shouldCancel);
109 }
110
111 bool menuHasKeyEquivalent (NSMenu menu, NSEvent event, id* target, SEL* action)
112 {
113 return invokeObjcSelf!(bool, "menuHasKeyEquivalent:forEvent:target:action:", NSMenu, NSEvent, id*, SEL*)(menu, event, target, action);
114 }
115
116 void menuWillOpen (NSMenu menu)
117 {
118 return invokeObjcSelf!(void, "menuWillOpen:", NSMenu)(menu);
119 }
120
121 void menuDidClose (NSMenu menu)
122 {
123 return invokeObjcSelf!(void, "menuDidClose:", NSMenu)(menu);
124 }
125
126 void menu (NSMenu menu, NSMenuItem item)
127 {
128 return invokeObjcSelf!(void, "menu:willHighlightItem:", NSMenu, NSMenuItem)(menu, item);
129 }
130
131 //mixin ObjcBindMethod!(menuNeedsUpdate, "menuNeedsUpdate:");
132 //mixin ObjcBindMethod!(numberOfItemsInMenu, "numberOfItemsInMenu:");
133 //mixin ObjcBindMethod!(menu, "menu:updateItem:atIndex:shouldCancel:");
134 //mixin ObjcBindMethod!(menuHasKeyEquivalent, "menuHasKeyEquivalent:forEvent:target:action:");
135 //mixin ObjcBindMethod!(menuWillOpen, "menuWillOpen:");
136 //mixin ObjcBindMethod!(menuDidClose, "menuDidClose:");
137 //mixin ObjcBindMethod!(menu, "menu:willHighlightItem:");
138
139 `;
140
141 const TNSSubmenuAction = `
142
143 void submenuAction (Object sender)
144 {
145 return invokeObjcSelf!(void, "submenuAction:", Object)(sender);
146 }
147
148 //mixin ObjcBindMethod!(submenuAction, "submenuAction:");
149
150 `;
151
152 const TNSMenuValidation = `
153
154 bool validateMenuItem (NSMenuItem menuItem)
155 {
156 return invokeObjcSelf!(bool, "validateMenuItem:", NSMenuItem)(menuItem);
157 }
158
159 //mixin ObjcBindMethod!(validateMenuItem, "validateMenuItem:");
160
161 `;
162
163 class NSMenu : NSObject, INSCopying, INSCoding
164 {
165 mixin (ObjcWrap);
166
167 this (NSCoder aDecoder)
168 {
169 super(typeof(this).alloc.initWithCoder(aDecoder).objcObject);
170 }
171
172 void encodeWithCoder (NSCoder aCoder)
173 {
174 return invokeObjcSelf!(void, "encodeWithCoder:", NSCoder)(aCoder);
175 }
176
177 typeof(this) initWithCoder (NSCoder aDecoder)
178 {
179 return invokeObjcSelf!(typeof(this), "initWithCoder:", NSCoder)(aDecoder);
180 }
181
182 typeof(this) copyWithZone (NSZone* zone)
183 {
184 return invokeObjcSelf!(typeof(this), "copyWithZone:", NSZone*)(zone);
185 }
186
187 static void setMenuZone (NSZone* aZone)
188 {
189 return invokeObjcSelfClass!(void, "setMenuZone:", NSZone*)(aZone);
190 }
191
192 static NSZone* menuZone ()
193 {
194 return invokeObjcSelfClass!(NSZone*, "menuZone");
195 }
196
197 static void popUpContextMenu (NSMenu menu, NSEvent event, NSView view)
198 {
199 return invokeObjcSelfClass!(void, "popUpContextMenu:withEvent:forView:", NSMenu, NSEvent, NSView)(menu, event, view);
200 }
201
202 static void popUpContextMenu (NSMenu menu, NSEvent event, NSView view, NSFont font)
203 {
204 return invokeObjcSelfClass!(void, "popUpContextMenu:withEvent:forView:withFont:", NSMenu, NSEvent, NSView, NSFont)(menu, event, view, font);
205 }
206
207 static void setMenuBarVisible (bool visible)
208 {
209 return invokeObjcSelfClass!(void, "setMenuBarVisible:", bool)(visible);
210 }
211
212 static bool menuBarVisible ()
213 {
214 return invokeObjcSelfClass!(bool, "menuBarVisible");
215 }
216
217 NSMenu initWithTitle (NSString aTitle)
218 {
219 id result = invokeObjcSelf!(id, "initWithTitle:", NSString)(aTitle);
220 return result is this.objcObject ? this : (result !is null ? new NSMenu(result) : null);
221 }
222
223 this (NSString aTitle)
224 {
225 super(NSMenu.alloc.initWithTitle(aTitle).objcObject);
226 }
227
228 void setTitle (NSString aString)
229 {
230 return invokeObjcSelf!(void, "setTitle:", NSString)(aString);
231 }
232
233 NSString title ()
234 {
235 return invokeObjcSelf!(NSString, "title");
236 }
237
238 void setSupermenu (NSMenu supermenu)
239 {
240 return invokeObjcSelf!(void, "setSupermenu:", NSMenu)(supermenu);
241 }
242
243 NSMenu supermenu ()
244 {
245 id result = invokeObjcSelf!(id, "supermenu");
246 return result is this.objcObject ? this : (result !is null ? new NSMenu(result) : null);
247 }
248
249 void insertItem (NSMenuItem newItem, NSInteger index)
250 {
251 return invokeObjcSelf!(void, "insertItem:atIndex:", NSMenuItem, NSInteger)(newItem, index);
252 }
253
254 void addItem (NSMenuItem newItem)
255 {
256 return invokeObjcSelf!(void, "addItem:", NSMenuItem)(newItem);
257 }
258
259 NSMenuItem insertItemWithTitle (NSString aString, SEL aSelector, NSString charCode, NSInteger index)
260 {
261 return invokeObjcSelf!(NSMenuItem, "insertItemWithTitle:action:keyEquivalent:atIndex:", NSString, SEL, NSString, NSInteger)(aString, aSelector, charCode, index);
262 }
263
264 NSMenuItem addItemWithTitle (NSString aString, SEL aSelector, NSString charCode)
265 {
266 return invokeObjcSelf!(NSMenuItem, "addItemWithTitle:action:keyEquivalent:", NSString, SEL, NSString)(aString, aSelector, charCode);
267 }
268
269 void removeItemAtIndex (NSInteger index)
270 {
271 return invokeObjcSelf!(void, "removeItemAtIndex:", NSInteger)(index);
272 }
273
274 void removeItem (NSMenuItem item)
275 {
276 return invokeObjcSelf!(void, "removeItem:", NSMenuItem)(item);
277 }
278
279 void setSubmenu (NSMenu aMenu, NSMenuItem anItem)
280 {
281 return invokeObjcSelf!(void, "setSubmenu:forItem:", NSMenu, NSMenuItem)(aMenu, anItem);
282 }
283
284 NSArray itemArray ()
285 {
286 return invokeObjcSelf!(NSArray, "itemArray");
287 }
288
289 NSInteger numberOfItems ()
290 {
291 return invokeObjcSelf!(NSInteger, "numberOfItems");
292 }
293
294 NSInteger indexOfItem (NSMenuItem index)
295 {
296 return invokeObjcSelf!(NSInteger, "indexOfItem:", NSMenuItem)(index);
297 }
298
299 NSInteger indexOfItemWithTitle (NSString aTitle)
300 {
301 return invokeObjcSelf!(NSInteger, "indexOfItemWithTitle:", NSString)(aTitle);
302 }
303
304 NSInteger indexOfItemWithTag (NSInteger aTag)
305 {
306 return invokeObjcSelf!(NSInteger, "indexOfItemWithTag:", NSInteger)(aTag);
307 }
308
309 NSInteger indexOfItemWithRepresentedObject (Object object)
310 {
311 return invokeObjcSelf!(NSInteger, "indexOfItemWithRepresentedObject:", Object)(object);
312 }
313
314 NSInteger indexOfItemWithSubmenu (NSMenu submenu)
315 {
316 return invokeObjcSelf!(NSInteger, "indexOfItemWithSubmenu:", NSMenu)(submenu);
317 }
318
319 NSInteger indexOfItemWithTarget (Object target, SEL actionSelector)
320 {
321 return invokeObjcSelf!(NSInteger, "indexOfItemWithTarget:andAction:", Object, SEL)(target, actionSelector);
322 }
323
324 NSMenuItem itemAtIndex (NSInteger index)
325 {
326 return invokeObjcSelf!(NSMenuItem, "itemAtIndex:", NSInteger)(index);
327 }
328
329 NSMenuItem itemWithTitle (NSString aTitle)
330 {
331 return invokeObjcSelf!(NSMenuItem, "itemWithTitle:", NSString)(aTitle);
332 }
333
334 NSMenuItem itemWithTag (NSInteger tag)
335 {
336 return invokeObjcSelf!(NSMenuItem, "itemWithTag:", NSInteger)(tag);
337 }
338
339 void setAutoenablesItems (bool flag)
340 {
341 return invokeObjcSelf!(void, "setAutoenablesItems:", bool)(flag);
342 }
343
344 bool autoenablesItems ()
345 {
346 return invokeObjcSelf!(bool, "autoenablesItems");
347 }
348
349 bool performKeyEquivalent (NSEvent theEvent)
350 {
351 return invokeObjcSelf!(bool, "performKeyEquivalent:", NSEvent)(theEvent);
352 }
353
354 void update ()
355 {
356 return invokeObjcSelf!(void, "update");
357 }
358
359 void setMenuChangedMessagesEnabled (bool flag)
360 {
361 return invokeObjcSelf!(void, "setMenuChangedMessagesEnabled:", bool)(flag);
362 }
363
364 bool menuChangedMessagesEnabled ()
365 {
366 return invokeObjcSelf!(bool, "menuChangedMessagesEnabled");
367 }
368
369 void itemChanged (NSMenuItem item)
370 {
371 return invokeObjcSelf!(void, "itemChanged:", NSMenuItem)(item);
372 }
373
374 void helpRequested (NSEvent eventPtr)
375 {
376 return invokeObjcSelf!(void, "helpRequested:", NSEvent)(eventPtr);
377 }
378
379 void setMenuRepresentation (Object menuRep)
380 {
381 return invokeObjcSelf!(void, "setMenuRepresentation:", Object)(menuRep);
382 }
383
384 Object menuRepresentation ()
385 {
386 return invokeObjcSelf!(Object, "menuRepresentation");
387 }
388
389 void setContextMenuRepresentation (Object menuRep)
390 {
391 return invokeObjcSelf!(void, "setContextMenuRepresentation:", Object)(menuRep);
392 }
393
394 Object contextMenuRepresentation ()
395 {
396 return invokeObjcSelf!(Object, "contextMenuRepresentation");
397 }
398
399 void setTearOffMenuRepresentation (Object menuRep)
400 {
401 return invokeObjcSelf!(void, "setTearOffMenuRepresentation:", Object)(menuRep);
402 }
403
404 Object tearOffMenuRepresentation ()
405 {
406 return invokeObjcSelf!(Object, "tearOffMenuRepresentation");
407 }
408
409 bool isTornOff ()
410 {
411 return invokeObjcSelf!(bool, "isTornOff");
412 }
413
414 NSMenu attachedMenu ()
415 {
416 id result = invokeObjcSelf!(id, "attachedMenu");
417 return result is this.objcObject ? this : (result !is null ? new NSMenu(result) : null);
418 }
419
420 bool isAttached ()
421 {
422 return invokeObjcSelf!(bool, "isAttached");
423 }
424
425 void sizeToFit ()
426 {
427 return invokeObjcSelf!(void, "sizeToFit");
428 }
429
430 NSPoint locationForSubmenu (NSMenu aSubmenu)
431 {
432 return invokeObjcSelf!(NSPoint, "locationForSubmenu:", NSMenu)(aSubmenu);
433 }
434
435 void performActionForItemAtIndex (NSInteger index)
436 {
437 return invokeObjcSelf!(void, "performActionForItemAtIndex:", NSInteger)(index);
438 }
439
440 void setDelegate (Object anObject)
441 {
442 return invokeObjcSelf!(void, "setDelegate:", Object)(anObject);
443 }
444
445 Object delegate_ ()
446 {
447 return invokeObjcSelf!(Object, "delegate");
448 }
449
450 CGFloat menuBarHeight ()
451 {
452 return invokeObjcSelf!(CGFloat, "menuBarHeight");
453 }
454
455 void cancelTracking ()
456 {
457 return invokeObjcSelf!(void, "cancelTracking");
458 }
459
460 NSMenuItem highlightedItem ()
461 {
462 return invokeObjcSelf!(NSMenuItem, "highlightedItem");
463 }
464
465 void setShowsStateColumn (bool showsState)
466 {
467 return invokeObjcSelf!(void, "setShowsStateColumn:", bool)(showsState);
468 }
469
470 bool showsStateColumn ()
471 {
472 return invokeObjcSelf!(bool, "showsStateColumn");
473 }
474
475 // NSSubmenuAction
476 void submenuAction (Object sender)
477 {
478 return invokeObjcSelf!(void, "submenuAction:", Object)(sender);
479 }
480 }