comparison dstep/foundation/NSNotification.d @ 14:89f3c3ef1fd2

Added the Foundation framework
author Jacob Carlborg <doob@me.com>
date Mon, 03 Aug 2009 15:23:15 +0200
parents
children 19885b43130e
comparison
equal deleted inserted replaced
13:4f583f7e242e 14:89f3c3ef1fd2
1 /**
2 * Copyright: Copyright (c) 2009 Jacob Carlborg.
3 * Authors: Jacob Carlborg
4 * Version: Initial created: Aug 3, 2009
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
6 */
7 module dstep.foundation.NSNotification;
8
9 import dstep.foundation.NSDictionary;
10 import dstep.foundation.NSObject;
11 import dstep.foundation.NSString;
12 import dstep.objc.bridge.Bridge;
13 import dstep.objc.objc : id;
14
15 class NSNotification : NSObject, INSCopying, INSCoding
16 {
17 mixin ObjcWrap;
18 mixin TNSNotificationCreation;
19
20 NSString name ()
21 {
22 return invokeObjcSelf!(NSString, "name");
23 }
24
25 Object object ()
26 {
27 return invokeObjcSelf!(Object, "object");
28 }
29
30 NSDictionary userInfo ()
31 {
32 return invokeObjcSelf!(NSDictionary, "userInfo");
33 }
34
35 Object copyWithZone (NSZone* zone)
36 {
37 return invokeObjcSelf!(Object, "copyWithZone:", NSZone*)(zone);
38 }
39
40 void encodeWithCoder (NSCoder aCoder)
41 {
42 return invokeObjcSelf!(void, "encodeWithCoder:", NSCoder)(aCoder);
43 }
44
45 Object initWithCoder (NSCoder aDecoder)
46 {
47 return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder);
48 }
49
50 this (NSCoder aDecoder)
51 {
52 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
53 id result = Bridge.invokeObjcMethod!(id, "initWithCoder:", NSCoder)(objcObject, aDecoder);
54
55 if (result)
56 objcObject = ret;
57
58 dObject = this;
59 }
60 }
61
62 class NSNotificationCenter : NSObject
63 {
64 mixin ObjcWrap;
65
66 static Object defaultCenter ()
67 {
68 return invokeObjcSelfClass!(Object, "defaultCenter");
69 }
70
71 void addObserver (Object observer, SEL aSelector, NSString aName, Object anObject)
72 {
73 return invokeObjcSelf!(void, "addObserver:selector:name:object:", Object, SEL, NSString, Object)(observer, aSelector, aName, anObject);
74 }
75
76 void postNotification (NSNotification notification)
77 {
78 return invokeObjcSelf!(void, "postNotification:", NSNotification)(notification);
79 }
80
81 void postNotificationName (NSString aName, Object anObject)
82 {
83 return invokeObjcSelf!(void, "postNotificationName:object:", NSString, Object)(aName, anObject);
84 }
85
86 void postNotificationName (NSString aName, Object anObject, NSDictionary aUserInfo)
87 {
88 return invokeObjcSelf!(void, "postNotificationName:object:userInfo:", NSString, Object, NSDictionary)(aName, anObject, aUserInfo);
89 }
90
91 void removeObserver (Object observer)
92 {
93 return invokeObjcSelf!(void, "removeObserver:", Object)(observer);
94 }
95
96 void removeObserver (Object observer, NSString aName, Object anObject)
97 {
98 return invokeObjcSelf!(void, "removeObserver:name:object:", Object, NSString, Object)(observer, aName, anObject);
99 }
100 }
101
102 template TNSNotificationCreation ()
103 {
104 static Object notificationWithName (NSString aName, Object anObject)
105 {
106 return invokeObjcSelfClass!(Object, "notificationWithName:object:", NSString, Object)(aName, anObject);
107 }
108
109 static Object notificationWithName (NSString aName, Object anObject, NSDictionary aUserInfo)
110 {
111 return invokeObjcSelfClass!(Object, "notificationWithName:object:userInfo:", NSString, Object, NSDictionary)(aName, anObject, aUserInfo);
112 }
113 }
114