1 module bindbc.cocoa.controls.nsbutton;
2 
3 import bindbc.cocoa.controls.nscontrol;
4 import bindbc.cocoa.controls.nsimage;
5 import bindbc.cocoa.controls.nssound;
6 import bindbc.cocoa.runtime;
7 import bindbc.cocoa.foundation;
8 import bindbc.cocoa.appkit;
9 
10 alias NSButtonType = NSUInteger;
11 enum : NSButtonType
12 {
13     NSMomentaryLightButton,
14     NSPushOnPushOffButton,
15     NSToggleButton,
16     NSSwitchButton,
17     NSRadioButton,
18     NSMomentaryChangeButton,
19     NSOnOffButton,
20     NSMomentaryPushInButton,
21 
22     NSAcceleratorButton,
23     NSMultiLevelAcceleratorButton,
24 
25     // These are old names
26     NSMomentaryLight = NSMomentaryPushInButton,
27     NSMomentaryPushButton = NSMomentaryLightButton
28 }
29 
30 alias NSBezelStyle = NSUInteger;
31 enum : NSBezelStyle {
32   NSRoundedBezelStyle = 1,
33   NSLargeIconButtonBezelStyle
34 }
35 
36 struct NSButton
37 {
38 nothrow @nogc:
39     NSControl parent;
40     alias parent this;
41 
42     mixin NSObjectTemplate!(NSButton, "NSButton");
43 
44     NSView contentView()
45     {
46         return NSView(_id);
47     }
48 
49     NSControl control(){
50         return NSControl(_id);
51     }
52 
53     void setButtonType(NSButtonType aType)
54     {
55         alias fun_t = extern(C) void function (id, SEL, NSButtonType) nothrow @nogc;
56         (cast(fun_t)objc_msgSend)(_id, sel!"setButtonType:", aType);
57     }
58 
59     void setHighlightsBy(NSInteger aType)
60     {
61         alias fun_t = extern(C) void function (id, SEL, NSInteger) nothrow @nogc;
62         (cast(fun_t)objc_msgSend)(_id, sel!"setHighlightsBy:", aType);
63     }
64 
65     void setShowsStateBy(NSInteger aType)
66     {
67         alias fun_t = extern(C) void function (id, SEL, NSInteger) nothrow @nogc;
68         (cast(fun_t)objc_msgSend)(_id, sel!"setShowsStateBy:", aType);
69     }
70 
71     void setState(NSInteger value)
72     {
73         alias fun_t = extern(C) void function (id, SEL, NSInteger) nothrow @nogc;
74         (cast(fun_t)objc_msgSend)(_id, sel!"setState:", value);
75     }
76 
77     NSInteger state()
78     {
79         alias fun_t = extern(C) NSInteger function (id, SEL) nothrow @nogc;
80         return (cast(fun_t)objc_msgSend)(_id, sel!"state");
81     }
82 
83     BOOL allowsMixedState()
84     {
85         alias fun_t = extern(C) BOOL function (id, SEL) nothrow @nogc;
86         return (cast(fun_t)objc_msgSend)(_id, sel!"allowsMixedState");
87     }
88 
89     void setAllowsMixedState(BOOL flag)
90     {
91         alias fun_t = extern(C) void function (id, SEL, BOOL) nothrow @nogc;
92         (cast(fun_t)objc_msgSend)(_id, sel!"setAllowsMixedState:", flag);
93     }
94 
95     void setNextState()
96     {
97         alias fun_t = extern(C) void function (id, SEL) nothrow @nogc;
98         (cast(fun_t)objc_msgSend)(_id, sel!"setNextState");
99     }
100 
101     void getPeriodicDelay(CGFloat* delay, CGFloat* interval)
102     {
103         alias fun_t = extern(C) void function (id, SEL, CGFloat*, CGFloat*) nothrow @nogc;
104         (cast(fun_t)objc_msgSend)(_id, sel!"getPeriodicDelay:", delay, interval);
105     }
106 
107     void setPeriodicDelay(CGFloat delay, CGFloat interval)
108     {
109         alias fun_t = extern(C) void function (id, SEL, CGFloat, CGFloat) nothrow @nogc;
110         (cast(fun_t)objc_msgSend)(_id, sel!"setPeriodicDelay:", delay, interval);
111     }
112 
113     NSString alternateTitle()
114     {
115         alias fun_t = extern(C) id function (id, SEL) nothrow @nogc;
116         return NSString((cast(fun_t)objc_msgSend)(_id, sel!"alternateTitle"));
117     }
118 
119     void setAlternateTitle(NSString aString)
120     {
121         alias fun_t = extern(C) void function (id, SEL, id) nothrow @nogc;
122         (cast(fun_t)objc_msgSend)(_id, sel!"setAlternateTitle:", aString._id);
123     }
124 
125     void setTitle(NSString title)
126     {
127         alias fun_t = extern(C) void function (id, SEL, id) nothrow @nogc;
128         (cast(fun_t)objc_msgSend)(_id, sel!"setTitle:", title._id);
129     }
130 
131     NSString title()
132     {
133         alias fun_t = extern(C) id function (id, SEL) nothrow @nogc;
134         return NSString((cast(fun_t)objc_msgSend)(_id, sel!"title"));
135     }
136     /+
137     #if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST)
138     - (NSAttributedString *)attributedAlternateTitle;
139     - (NSAttributedString *)attributedTitle;
140     - (void)setAttributedAlternateTitle:(NSAttributedString *)aString;
141     - (void)setAttributedTitle:(NSAttributedString *)aString;
142     - (void)setTitleWithMnemonic:(NSString *)aString;
143     #endif
144     +/
145 
146     NSImage alternateImage()
147     {
148         alias fun_t = extern(C) id function (id, SEL) nothrow @nogc;
149         return NSImage((cast(fun_t)objc_msgSend)(_id, sel!"alternateImage"));
150     }
151 
152     NSImage image()
153     {
154         alias fun_t = extern(C) id function (id, SEL) nothrow @nogc;
155         return NSImage((cast(fun_t)objc_msgSend)(_id, sel!"image"));
156     }
157 
158     NSCellImagePosition imagePosition()
159     {
160         alias fun_t = extern(C) NSCellImagePosition function (id, SEL) nothrow @nogc;
161         return (cast(fun_t)objc_msgSend)(_id, sel!"imagePosition");
162     }
163 
164     void setAlternateImage(NSImage anImage)
165     {
166         alias fun_t = extern(C) void function (id, SEL, id) nothrow @nogc;
167         (cast(fun_t)objc_msgSend)(_id, sel!"setAlternateImage:", anImage._id);
168     }
169 
170     void setImage(NSImage anImage)
171     {
172         alias fun_t = extern(C) void function (id, SEL, id) nothrow @nogc;
173         (cast(fun_t)objc_msgSend)(_id, sel!"setImage:", anImage._id);
174     }
175 
176     void setImagePosition(NSCellImagePosition aPosition)
177     {
178         alias fun_t = extern(C) void function (id, SEL, NSCellImagePosition) nothrow @nogc;
179         (cast(fun_t)objc_msgSend)(_id, sel!"setImagePosition:", aPosition);
180     }
181 
182     BOOL isBordered()
183     {
184         alias fun_t = extern(C) BOOL function (id, SEL) nothrow @nogc;
185         return (cast(fun_t)objc_msgSend)(_id, sel!"isBordered");
186     }
187 
188     BOOL isTransparent()
189     {
190         alias fun_t = extern(C) BOOL function (id, SEL) nothrow @nogc;
191         return (cast(fun_t)objc_msgSend)(_id, sel!"isTransparent");
192     }
193 
194     void setBordered(BOOL flag)
195     {
196         alias fun_t = extern(C) void function (id, SEL, BOOL) nothrow @nogc;
197         (cast(fun_t)objc_msgSend)(_id, sel!"setBordered:", flag);
198     }
199 
200     void setTransparent(BOOL flag)
201     {
202         alias fun_t = extern(C) void function (id, SEL, BOOL) nothrow @nogc;
203         (cast(fun_t)objc_msgSend)(_id, sel!"setTransparent:", flag);
204     }
205 
206     NSBezelStyle bezelStyle()
207     {
208         alias fun_t = extern(C) NSBezelStyle function (id, SEL) nothrow @nogc;
209         return (cast(fun_t)objc_msgSend)(_id, sel!"bezelStyle");
210     }
211 
212     void setBezelStyle(NSBezelStyle bezelStyle)
213     {
214         alias fun_t = extern(C) void function (id, SEL, NSBezelStyle) nothrow @nogc;
215         (cast(fun_t)objc_msgSend)(_id, sel!"setBezelStyle:", bezelStyle);
216     }
217 
218     void setShowsBorderOnlyWhileMouseInside(BOOL show)
219     {
220         alias fun_t = extern(C) void function (id, SEL, BOOL) nothrow @nogc;
221         (cast(fun_t)objc_msgSend)(_id, sel!"setShowsBorderOnlyWhileMouseInside:", show);
222     }
223 
224     BOOL showsBorderOnlyWhileMouseInside()
225     {
226         alias fun_t = extern(C) BOOL function (id, SEL) nothrow @nogc;
227         return (cast(fun_t)objc_msgSend)(_id, sel!"showsBorderOnlyWhileMouseInside");
228     }
229 
230     void highlight(BOOL flag)
231     {
232         alias fun_t = extern(C) void function (id, SEL, BOOL) nothrow @nogc;
233         (cast(fun_t)objc_msgSend)(_id, sel!"highlight:", flag);
234     }
235 
236     NSString keyEquivalent()
237     {
238         alias fun_t = extern(C) id function (id, SEL) nothrow @nogc;
239         return NSString((cast(fun_t)objc_msgSend)(_id, sel!"keyEquivalent"));
240     }
241 
242     NSUInteger keyEquivalentModifierMask()
243     {
244         alias fun_t = extern(C) NSUInteger function (id, SEL) nothrow @nogc;
245         return (cast(fun_t)objc_msgSend)(_id, sel!"keyEquivalentModifierMask");
246     }
247 
248     void setKeyEquivalent(NSString aKeyEquivalent)
249     {
250         alias fun_t = extern(C) void function (id, SEL, id) nothrow @nogc;
251         (cast(fun_t)objc_msgSend)(_id, sel!"setKeyEquivalent:", aKeyEquivalent._id);
252     }
253 
254     void setKeyEquivalentModifierMask(NSUInteger mask)
255     {
256         alias fun_t = extern(C) void function (id, SEL, NSUInteger) nothrow @nogc;
257         (cast(fun_t)objc_msgSend)(_id, sel!"setKeyEquivalentModifierMask:", mask);
258     }
259 
260     BOOL performKeyEquivalent(NSEvent anEvent)
261     {
262         alias fun_t = extern(C) BOOL function (id, SEL, id) nothrow @nogc;
263         return (cast(fun_t)objc_msgSend)(_id, sel!"performKeyEquivalent", anEvent._id);
264     }
265 
266     void setSound(NSSound aSound)
267     {
268         alias fun_t = extern(C) void function (id, SEL, id) nothrow @nogc;
269         (cast(fun_t)objc_msgSend)(_id, sel!"setSound:", aSound._id);
270     }
271 
272     NSSound sound()
273     {
274         alias fun_t = extern(C) id function (id, SEL) nothrow @nogc;
275         return NSSound((cast(fun_t)objc_msgSend)(_id, sel!"sound"));
276     }
277 }