1use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10extern_class!(
11 #[unsafe(super(NSView, NSResponder, NSObject))]
13 #[derive(Debug, PartialEq, Eq, Hash)]
14 #[cfg(all(feature = "NSResponder", feature = "NSView"))]
15 pub struct NSControl;
16);
17
18#[cfg(all(
19 feature = "NSAccessibilityProtocols",
20 feature = "NSResponder",
21 feature = "NSView"
22))]
23extern_conformance!(
24 unsafe impl NSAccessibility for NSControl {}
25);
26
27#[cfg(all(
28 feature = "NSAccessibilityProtocols",
29 feature = "NSResponder",
30 feature = "NSView"
31))]
32extern_conformance!(
33 unsafe impl NSAccessibilityElementProtocol for NSControl {}
34);
35
36#[cfg(all(feature = "NSAnimation", feature = "NSResponder", feature = "NSView"))]
37extern_conformance!(
38 unsafe impl NSAnimatablePropertyContainer for NSControl {}
39);
40
41#[cfg(all(feature = "NSAppearance", feature = "NSResponder", feature = "NSView"))]
42extern_conformance!(
43 unsafe impl NSAppearanceCustomization for NSControl {}
44);
45
46#[cfg(all(feature = "NSResponder", feature = "NSView"))]
47extern_conformance!(
48 unsafe impl NSCoding for NSControl {}
49);
50
51#[cfg(all(feature = "NSDragging", feature = "NSResponder", feature = "NSView"))]
52extern_conformance!(
53 unsafe impl NSDraggingDestination for NSControl {}
54);
55
56#[cfg(all(feature = "NSResponder", feature = "NSView"))]
57extern_conformance!(
58 unsafe impl NSObjectProtocol for NSControl {}
59);
60
61#[cfg(all(
62 feature = "NSResponder",
63 feature = "NSUserInterfaceItemIdentification",
64 feature = "NSView"
65))]
66extern_conformance!(
67 unsafe impl NSUserInterfaceItemIdentification for NSControl {}
68);
69
70#[cfg(all(feature = "NSResponder", feature = "NSView"))]
71impl NSControl {
72 extern_methods!(
73 #[unsafe(method(initWithFrame:))]
74 #[unsafe(method_family = init)]
75 pub unsafe fn initWithFrame(this: Allocated<Self>, frame_rect: NSRect) -> Retained<Self>;
76
77 #[unsafe(method(initWithCoder:))]
78 #[unsafe(method_family = init)]
79 pub unsafe fn initWithCoder(
80 this: Allocated<Self>,
81 coder: &NSCoder,
82 ) -> Option<Retained<Self>>;
83
84 #[unsafe(method(target))]
85 #[unsafe(method_family = none)]
86 pub unsafe fn target(&self) -> Option<Retained<AnyObject>>;
87
88 #[unsafe(method(setTarget:))]
91 #[unsafe(method_family = none)]
92 pub unsafe fn setTarget(&self, target: Option<&AnyObject>);
93
94 #[unsafe(method(action))]
95 #[unsafe(method_family = none)]
96 pub unsafe fn action(&self) -> Option<Sel>;
97
98 #[unsafe(method(setAction:))]
100 #[unsafe(method_family = none)]
101 pub unsafe fn setAction(&self, action: Option<Sel>);
102
103 #[unsafe(method(tag))]
104 #[unsafe(method_family = none)]
105 pub unsafe fn tag(&self) -> NSInteger;
106
107 #[unsafe(method(setTag:))]
109 #[unsafe(method_family = none)]
110 pub unsafe fn setTag(&self, tag: NSInteger);
111
112 #[unsafe(method(ignoresMultiClick))]
113 #[unsafe(method_family = none)]
114 pub unsafe fn ignoresMultiClick(&self) -> bool;
115
116 #[unsafe(method(setIgnoresMultiClick:))]
118 #[unsafe(method_family = none)]
119 pub unsafe fn setIgnoresMultiClick(&self, ignores_multi_click: bool);
120
121 #[unsafe(method(isContinuous))]
122 #[unsafe(method_family = none)]
123 pub unsafe fn isContinuous(&self) -> bool;
124
125 #[unsafe(method(setContinuous:))]
127 #[unsafe(method_family = none)]
128 pub unsafe fn setContinuous(&self, continuous: bool);
129
130 #[unsafe(method(isEnabled))]
131 #[unsafe(method_family = none)]
132 pub fn isEnabled(&self) -> bool;
133
134 #[unsafe(method(setEnabled:))]
136 #[unsafe(method_family = none)]
137 pub fn setEnabled(&self, enabled: bool);
138
139 #[unsafe(method(refusesFirstResponder))]
140 #[unsafe(method_family = none)]
141 pub unsafe fn refusesFirstResponder(&self) -> bool;
142
143 #[unsafe(method(setRefusesFirstResponder:))]
145 #[unsafe(method_family = none)]
146 pub unsafe fn setRefusesFirstResponder(&self, refuses_first_responder: bool);
147
148 #[unsafe(method(isHighlighted))]
149 #[unsafe(method_family = none)]
150 pub unsafe fn isHighlighted(&self) -> bool;
151
152 #[unsafe(method(setHighlighted:))]
154 #[unsafe(method_family = none)]
155 pub unsafe fn setHighlighted(&self, highlighted: bool);
156
157 #[cfg(feature = "NSCell")]
158 #[unsafe(method(controlSize))]
159 #[unsafe(method_family = none)]
160 pub unsafe fn controlSize(&self) -> NSControlSize;
161
162 #[cfg(feature = "NSCell")]
163 #[unsafe(method(setControlSize:))]
165 #[unsafe(method_family = none)]
166 pub unsafe fn setControlSize(&self, control_size: NSControlSize);
167
168 #[unsafe(method(formatter))]
169 #[unsafe(method_family = none)]
170 pub unsafe fn formatter(&self) -> Option<Retained<NSFormatter>>;
171
172 #[unsafe(method(setFormatter:))]
174 #[unsafe(method_family = none)]
175 pub unsafe fn setFormatter(&self, formatter: Option<&NSFormatter>);
176
177 #[unsafe(method(objectValue))]
178 #[unsafe(method_family = none)]
179 pub unsafe fn objectValue(&self) -> Option<Retained<AnyObject>>;
180
181 #[unsafe(method(setObjectValue:))]
183 #[unsafe(method_family = none)]
184 pub unsafe fn setObjectValue(&self, object_value: Option<&AnyObject>);
185
186 #[unsafe(method(stringValue))]
187 #[unsafe(method_family = none)]
188 pub unsafe fn stringValue(&self) -> Retained<NSString>;
189
190 #[unsafe(method(setStringValue:))]
192 #[unsafe(method_family = none)]
193 pub unsafe fn setStringValue(&self, string_value: &NSString);
194
195 #[unsafe(method(attributedStringValue))]
196 #[unsafe(method_family = none)]
197 pub unsafe fn attributedStringValue(&self) -> Retained<NSAttributedString>;
198
199 #[unsafe(method(setAttributedStringValue:))]
201 #[unsafe(method_family = none)]
202 pub unsafe fn setAttributedStringValue(&self, attributed_string_value: &NSAttributedString);
203
204 #[unsafe(method(intValue))]
205 #[unsafe(method_family = none)]
206 pub unsafe fn intValue(&self) -> c_int;
207
208 #[unsafe(method(setIntValue:))]
210 #[unsafe(method_family = none)]
211 pub unsafe fn setIntValue(&self, int_value: c_int);
212
213 #[unsafe(method(integerValue))]
214 #[unsafe(method_family = none)]
215 pub unsafe fn integerValue(&self) -> NSInteger;
216
217 #[unsafe(method(setIntegerValue:))]
219 #[unsafe(method_family = none)]
220 pub unsafe fn setIntegerValue(&self, integer_value: NSInteger);
221
222 #[unsafe(method(floatValue))]
223 #[unsafe(method_family = none)]
224 pub unsafe fn floatValue(&self) -> c_float;
225
226 #[unsafe(method(setFloatValue:))]
228 #[unsafe(method_family = none)]
229 pub unsafe fn setFloatValue(&self, float_value: c_float);
230
231 #[unsafe(method(doubleValue))]
232 #[unsafe(method_family = none)]
233 pub unsafe fn doubleValue(&self) -> c_double;
234
235 #[unsafe(method(setDoubleValue:))]
237 #[unsafe(method_family = none)]
238 pub unsafe fn setDoubleValue(&self, double_value: c_double);
239
240 #[unsafe(method(sizeThatFits:))]
241 #[unsafe(method_family = none)]
242 pub unsafe fn sizeThatFits(&self, size: NSSize) -> NSSize;
243
244 #[unsafe(method(sizeToFit))]
245 #[unsafe(method_family = none)]
246 pub unsafe fn sizeToFit(&self);
247
248 #[cfg(feature = "NSEvent")]
249 #[unsafe(method(sendActionOn:))]
250 #[unsafe(method_family = none)]
251 pub unsafe fn sendActionOn(&self, mask: NSEventMask) -> NSInteger;
252
253 #[unsafe(method(sendAction:to:))]
254 #[unsafe(method_family = none)]
255 pub unsafe fn sendAction_to(&self, action: Option<Sel>, target: Option<&AnyObject>)
256 -> bool;
257
258 #[unsafe(method(takeIntValueFrom:))]
259 #[unsafe(method_family = none)]
260 pub unsafe fn takeIntValueFrom(&self, sender: Option<&AnyObject>);
261
262 #[unsafe(method(takeFloatValueFrom:))]
263 #[unsafe(method_family = none)]
264 pub unsafe fn takeFloatValueFrom(&self, sender: Option<&AnyObject>);
265
266 #[unsafe(method(takeDoubleValueFrom:))]
267 #[unsafe(method_family = none)]
268 pub unsafe fn takeDoubleValueFrom(&self, sender: Option<&AnyObject>);
269
270 #[unsafe(method(takeStringValueFrom:))]
271 #[unsafe(method_family = none)]
272 pub unsafe fn takeStringValueFrom(&self, sender: Option<&AnyObject>);
273
274 #[unsafe(method(takeObjectValueFrom:))]
275 #[unsafe(method_family = none)]
276 pub unsafe fn takeObjectValueFrom(&self, sender: Option<&AnyObject>);
277
278 #[unsafe(method(takeIntegerValueFrom:))]
279 #[unsafe(method_family = none)]
280 pub unsafe fn takeIntegerValueFrom(&self, sender: Option<&AnyObject>);
281
282 #[cfg(feature = "NSEvent")]
283 #[unsafe(method(mouseDown:))]
284 #[unsafe(method_family = none)]
285 pub unsafe fn mouseDown(&self, event: &NSEvent);
286
287 #[unsafe(method(performClick:))]
288 #[unsafe(method_family = none)]
289 pub unsafe fn performClick(&self, sender: Option<&AnyObject>);
290
291 #[cfg(feature = "NSFont")]
292 #[unsafe(method(font))]
293 #[unsafe(method_family = none)]
294 pub unsafe fn font(&self) -> Option<Retained<NSFont>>;
295
296 #[cfg(feature = "NSFont")]
297 #[unsafe(method(setFont:))]
299 #[unsafe(method_family = none)]
300 pub unsafe fn setFont(&self, font: Option<&NSFont>);
301
302 #[unsafe(method(usesSingleLineMode))]
303 #[unsafe(method_family = none)]
304 pub unsafe fn usesSingleLineMode(&self) -> bool;
305
306 #[unsafe(method(setUsesSingleLineMode:))]
308 #[unsafe(method_family = none)]
309 pub unsafe fn setUsesSingleLineMode(&self, uses_single_line_mode: bool);
310
311 #[cfg(feature = "NSParagraphStyle")]
312 #[unsafe(method(lineBreakMode))]
313 #[unsafe(method_family = none)]
314 pub unsafe fn lineBreakMode(&self) -> NSLineBreakMode;
315
316 #[cfg(feature = "NSParagraphStyle")]
317 #[unsafe(method(setLineBreakMode:))]
319 #[unsafe(method_family = none)]
320 pub unsafe fn setLineBreakMode(&self, line_break_mode: NSLineBreakMode);
321
322 #[cfg(feature = "NSText")]
323 #[unsafe(method(alignment))]
324 #[unsafe(method_family = none)]
325 pub unsafe fn alignment(&self) -> NSTextAlignment;
326
327 #[cfg(feature = "NSText")]
328 #[unsafe(method(setAlignment:))]
330 #[unsafe(method_family = none)]
331 pub unsafe fn setAlignment(&self, alignment: NSTextAlignment);
332
333 #[cfg(feature = "NSText")]
334 #[unsafe(method(baseWritingDirection))]
335 #[unsafe(method_family = none)]
336 pub unsafe fn baseWritingDirection(&self) -> NSWritingDirection;
337
338 #[cfg(feature = "NSText")]
339 #[unsafe(method(setBaseWritingDirection:))]
341 #[unsafe(method_family = none)]
342 pub unsafe fn setBaseWritingDirection(&self, base_writing_direction: NSWritingDirection);
343
344 #[unsafe(method(allowsExpansionToolTips))]
345 #[unsafe(method_family = none)]
346 pub unsafe fn allowsExpansionToolTips(&self) -> bool;
347
348 #[unsafe(method(setAllowsExpansionToolTips:))]
350 #[unsafe(method_family = none)]
351 pub unsafe fn setAllowsExpansionToolTips(&self, allows_expansion_tool_tips: bool);
352
353 #[unsafe(method(expansionFrameWithFrame:))]
354 #[unsafe(method_family = none)]
355 pub unsafe fn expansionFrameWithFrame(&self, content_frame: NSRect) -> NSRect;
356
357 #[unsafe(method(drawWithExpansionFrame:inView:))]
358 #[unsafe(method_family = none)]
359 pub unsafe fn drawWithExpansionFrame_inView(&self, content_frame: NSRect, view: &NSView);
360 );
361}
362
363#[cfg(all(feature = "NSResponder", feature = "NSView"))]
365impl NSControl {
366 extern_methods!(
367 #[unsafe(method(init))]
368 #[unsafe(method_family = init)]
369 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
370 );
371}
372
373#[cfg(all(feature = "NSResponder", feature = "NSView"))]
375impl NSControl {
376 extern_methods!(
377 #[unsafe(method(new))]
378 #[unsafe(method_family = new)]
379 pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
380 );
381}
382
383#[cfg(all(feature = "NSResponder", feature = "NSView"))]
385impl NSControl {
386 extern_methods!(
387 #[cfg(feature = "NSText")]
388 #[unsafe(method(currentEditor))]
389 #[unsafe(method_family = none)]
390 pub unsafe fn currentEditor(&self) -> Option<Retained<NSText>>;
391
392 #[unsafe(method(abortEditing))]
393 #[unsafe(method_family = none)]
394 pub unsafe fn abortEditing(&self) -> bool;
395
396 #[unsafe(method(validateEditing))]
397 #[unsafe(method_family = none)]
398 pub unsafe fn validateEditing(&self);
399
400 #[cfg(all(feature = "NSEvent", feature = "NSText"))]
401 #[unsafe(method(editWithFrame:editor:delegate:event:))]
402 #[unsafe(method_family = none)]
403 pub unsafe fn editWithFrame_editor_delegate_event(
404 &self,
405 rect: NSRect,
406 text_obj: &NSText,
407 delegate: Option<&AnyObject>,
408 event: &NSEvent,
409 );
410
411 #[cfg(feature = "NSText")]
412 #[unsafe(method(selectWithFrame:editor:delegate:start:length:))]
413 #[unsafe(method_family = none)]
414 pub unsafe fn selectWithFrame_editor_delegate_start_length(
415 &self,
416 rect: NSRect,
417 text_obj: &NSText,
418 delegate: Option<&AnyObject>,
419 sel_start: NSInteger,
420 sel_length: NSInteger,
421 );
422
423 #[cfg(feature = "NSText")]
424 #[unsafe(method(endEditing:))]
425 #[unsafe(method_family = none)]
426 pub unsafe fn endEditing(&self, text_obj: &NSText);
427 );
428}
429
430extern_protocol!(
431 pub unsafe trait NSControlTextEditingDelegate:
433 NSObjectProtocol + MainThreadOnly
434 {
435 #[optional]
436 #[unsafe(method(controlTextDidBeginEditing:))]
437 #[unsafe(method_family = none)]
438 unsafe fn controlTextDidBeginEditing(&self, obj: &NSNotification);
439
440 #[optional]
441 #[unsafe(method(controlTextDidEndEditing:))]
442 #[unsafe(method_family = none)]
443 unsafe fn controlTextDidEndEditing(&self, obj: &NSNotification);
444
445 #[optional]
446 #[unsafe(method(controlTextDidChange:))]
447 #[unsafe(method_family = none)]
448 unsafe fn controlTextDidChange(&self, obj: &NSNotification);
449
450 #[cfg(all(feature = "NSResponder", feature = "NSText", feature = "NSView"))]
451 #[optional]
452 #[unsafe(method(control:textShouldBeginEditing:))]
453 #[unsafe(method_family = none)]
454 unsafe fn control_textShouldBeginEditing(
455 &self,
456 control: &NSControl,
457 field_editor: &NSText,
458 ) -> bool;
459
460 #[cfg(all(feature = "NSResponder", feature = "NSText", feature = "NSView"))]
461 #[optional]
462 #[unsafe(method(control:textShouldEndEditing:))]
463 #[unsafe(method_family = none)]
464 unsafe fn control_textShouldEndEditing(
465 &self,
466 control: &NSControl,
467 field_editor: &NSText,
468 ) -> bool;
469
470 #[cfg(all(feature = "NSResponder", feature = "NSView"))]
471 #[optional]
472 #[unsafe(method(control:didFailToFormatString:errorDescription:))]
473 #[unsafe(method_family = none)]
474 unsafe fn control_didFailToFormatString_errorDescription(
475 &self,
476 control: &NSControl,
477 string: &NSString,
478 error: Option<&NSString>,
479 ) -> bool;
480
481 #[cfg(all(feature = "NSResponder", feature = "NSView"))]
482 #[optional]
483 #[unsafe(method(control:didFailToValidatePartialString:errorDescription:))]
484 #[unsafe(method_family = none)]
485 unsafe fn control_didFailToValidatePartialString_errorDescription(
486 &self,
487 control: &NSControl,
488 string: &NSString,
489 error: Option<&NSString>,
490 );
491
492 #[cfg(all(feature = "NSResponder", feature = "NSView"))]
493 #[optional]
494 #[unsafe(method(control:isValidObject:))]
495 #[unsafe(method_family = none)]
496 unsafe fn control_isValidObject(
497 &self,
498 control: &NSControl,
499 obj: Option<&AnyObject>,
500 ) -> bool;
501
502 #[cfg(all(
503 feature = "NSResponder",
504 feature = "NSText",
505 feature = "NSTextView",
506 feature = "NSView"
507 ))]
508 #[optional]
509 #[unsafe(method(control:textView:doCommandBySelector:))]
510 #[unsafe(method_family = none)]
511 unsafe fn control_textView_doCommandBySelector(
512 &self,
513 control: &NSControl,
514 text_view: &NSTextView,
515 command_selector: Sel,
516 ) -> bool;
517
518 #[cfg(all(
519 feature = "NSResponder",
520 feature = "NSText",
521 feature = "NSTextView",
522 feature = "NSView"
523 ))]
524 #[optional]
525 #[unsafe(method(control:textView:completions:forPartialWordRange:indexOfSelectedItem:))]
526 #[unsafe(method_family = none)]
527 unsafe fn control_textView_completions_forPartialWordRange_indexOfSelectedItem(
528 &self,
529 control: &NSControl,
530 text_view: &NSTextView,
531 words: &NSArray<NSString>,
532 char_range: NSRange,
533 index: NonNull<NSInteger>,
534 ) -> Retained<NSArray<NSString>>;
535 }
536);
537
538extern "C" {
539 pub static NSControlTextDidBeginEditingNotification: &'static NSNotificationName;
541}
542
543extern "C" {
544 pub static NSControlTextDidEndEditingNotification: &'static NSNotificationName;
546}
547
548extern "C" {
549 pub static NSControlTextDidChangeNotification: &'static NSNotificationName;
551}
552
553#[cfg(all(feature = "NSResponder", feature = "NSView"))]
555impl NSControl {
556 extern_methods!(
557 #[deprecated]
558 #[unsafe(method(setFloatingPointFormat:left:right:))]
559 #[unsafe(method_family = none)]
560 pub unsafe fn setFloatingPointFormat_left_right(
561 &self,
562 auto_range: bool,
563 left_digits: NSUInteger,
564 right_digits: NSUInteger,
565 );
566
567 #[unsafe(method(cellClass))]
568 #[unsafe(method_family = none)]
569 pub unsafe fn cellClass(mtm: MainThreadMarker) -> Option<&'static AnyClass>;
570
571 #[unsafe(method(setCellClass:))]
573 #[unsafe(method_family = none)]
574 pub unsafe fn setCellClass(cell_class: Option<&AnyClass>, mtm: MainThreadMarker);
575
576 #[cfg(feature = "NSCell")]
577 #[unsafe(method(cell))]
578 #[unsafe(method_family = none)]
579 pub unsafe fn cell(&self) -> Option<Retained<NSCell>>;
580
581 #[cfg(feature = "NSCell")]
582 #[unsafe(method(setCell:))]
584 #[unsafe(method_family = none)]
585 pub unsafe fn setCell(&self, cell: Option<&NSCell>);
586
587 #[cfg(feature = "NSCell")]
588 #[unsafe(method(selectedCell))]
589 #[unsafe(method_family = none)]
590 pub unsafe fn selectedCell(&self) -> Option<Retained<NSCell>>;
591
592 #[unsafe(method(selectedTag))]
593 #[unsafe(method_family = none)]
594 pub unsafe fn selectedTag(&self) -> NSInteger;
595
596 #[deprecated = "Set the needsDisplay property to YES instead"]
597 #[unsafe(method(setNeedsDisplay))]
598 #[unsafe(method_family = none)]
599 pub unsafe fn setNeedsDisplay(&self);
600
601 #[deprecated = "Override -layout instead. This method should never be called"]
602 #[unsafe(method(calcSize))]
603 #[unsafe(method_family = none)]
604 pub unsafe fn calcSize(&self);
605
606 #[cfg(feature = "NSCell")]
607 #[unsafe(method(updateCell:))]
608 #[unsafe(method_family = none)]
609 pub unsafe fn updateCell(&self, cell: &NSCell);
610
611 #[cfg(feature = "NSCell")]
612 #[unsafe(method(updateCellInside:))]
613 #[unsafe(method_family = none)]
614 pub unsafe fn updateCellInside(&self, cell: &NSCell);
615
616 #[cfg(feature = "NSCell")]
617 #[unsafe(method(drawCellInside:))]
618 #[unsafe(method_family = none)]
619 pub unsafe fn drawCellInside(&self, cell: &NSCell);
620
621 #[cfg(feature = "NSCell")]
622 #[unsafe(method(drawCell:))]
623 #[unsafe(method_family = none)]
624 pub unsafe fn drawCell(&self, cell: &NSCell);
625
626 #[cfg(feature = "NSCell")]
627 #[unsafe(method(selectCell:))]
628 #[unsafe(method_family = none)]
629 pub unsafe fn selectCell(&self, cell: &NSCell);
630 );
631}