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 fn initWithFrame(this: Allocated<Self>, frame_rect: NSRect) -> Retained<Self>;
76
77 #[unsafe(method(initWithCoder:))]
81 #[unsafe(method_family = init)]
82 pub unsafe fn initWithCoder(
83 this: Allocated<Self>,
84 coder: &NSCoder,
85 ) -> Option<Retained<Self>>;
86
87 #[unsafe(method(target))]
88 #[unsafe(method_family = none)]
89 pub fn target(&self) -> Option<Retained<AnyObject>>;
90
91 #[unsafe(method(setTarget:))]
99 #[unsafe(method_family = none)]
100 pub unsafe fn setTarget(&self, target: Option<&AnyObject>);
101
102 #[unsafe(method(action))]
103 #[unsafe(method_family = none)]
104 pub fn action(&self) -> Option<Sel>;
105
106 #[unsafe(method(setAction:))]
112 #[unsafe(method_family = none)]
113 pub unsafe fn setAction(&self, action: Option<Sel>);
114
115 #[unsafe(method(tag))]
116 #[unsafe(method_family = none)]
117 pub fn tag(&self) -> NSInteger;
118
119 #[unsafe(method(setTag:))]
121 #[unsafe(method_family = none)]
122 pub fn setTag(&self, tag: NSInteger);
123
124 #[unsafe(method(ignoresMultiClick))]
125 #[unsafe(method_family = none)]
126 pub fn ignoresMultiClick(&self) -> bool;
127
128 #[unsafe(method(setIgnoresMultiClick:))]
130 #[unsafe(method_family = none)]
131 pub fn setIgnoresMultiClick(&self, ignores_multi_click: bool);
132
133 #[unsafe(method(isContinuous))]
134 #[unsafe(method_family = none)]
135 pub fn isContinuous(&self) -> bool;
136
137 #[unsafe(method(setContinuous:))]
139 #[unsafe(method_family = none)]
140 pub fn setContinuous(&self, continuous: bool);
141
142 #[unsafe(method(isEnabled))]
143 #[unsafe(method_family = none)]
144 pub fn isEnabled(&self) -> bool;
145
146 #[unsafe(method(setEnabled:))]
148 #[unsafe(method_family = none)]
149 pub fn setEnabled(&self, enabled: bool);
150
151 #[unsafe(method(refusesFirstResponder))]
152 #[unsafe(method_family = none)]
153 pub fn refusesFirstResponder(&self) -> bool;
154
155 #[unsafe(method(setRefusesFirstResponder:))]
157 #[unsafe(method_family = none)]
158 pub fn setRefusesFirstResponder(&self, refuses_first_responder: bool);
159
160 #[unsafe(method(isHighlighted))]
161 #[unsafe(method_family = none)]
162 pub fn isHighlighted(&self) -> bool;
163
164 #[unsafe(method(setHighlighted:))]
166 #[unsafe(method_family = none)]
167 pub fn setHighlighted(&self, highlighted: bool);
168
169 #[cfg(feature = "NSCell")]
170 #[unsafe(method(controlSize))]
171 #[unsafe(method_family = none)]
172 pub fn controlSize(&self) -> NSControlSize;
173
174 #[cfg(feature = "NSCell")]
175 #[unsafe(method(setControlSize:))]
177 #[unsafe(method_family = none)]
178 pub fn setControlSize(&self, control_size: NSControlSize);
179
180 #[unsafe(method(formatter))]
181 #[unsafe(method_family = none)]
182 pub fn formatter(&self) -> Option<Retained<NSFormatter>>;
183
184 #[unsafe(method(setFormatter:))]
186 #[unsafe(method_family = none)]
187 pub fn setFormatter(&self, formatter: Option<&NSFormatter>);
188
189 #[unsafe(method(objectValue))]
190 #[unsafe(method_family = none)]
191 pub fn objectValue(&self) -> Option<Retained<AnyObject>>;
192
193 #[unsafe(method(setObjectValue:))]
201 #[unsafe(method_family = none)]
202 pub unsafe fn setObjectValue(&self, object_value: Option<&AnyObject>);
203
204 #[unsafe(method(stringValue))]
205 #[unsafe(method_family = none)]
206 pub fn stringValue(&self) -> Retained<NSString>;
207
208 #[unsafe(method(setStringValue:))]
212 #[unsafe(method_family = none)]
213 pub fn setStringValue(&self, string_value: &NSString);
214
215 #[unsafe(method(attributedStringValue))]
216 #[unsafe(method_family = none)]
217 pub fn attributedStringValue(&self) -> Retained<NSAttributedString>;
218
219 #[unsafe(method(setAttributedStringValue:))]
223 #[unsafe(method_family = none)]
224 pub fn setAttributedStringValue(&self, attributed_string_value: &NSAttributedString);
225
226 #[unsafe(method(intValue))]
227 #[unsafe(method_family = none)]
228 pub fn intValue(&self) -> c_int;
229
230 #[unsafe(method(setIntValue:))]
232 #[unsafe(method_family = none)]
233 pub fn setIntValue(&self, int_value: c_int);
234
235 #[unsafe(method(integerValue))]
236 #[unsafe(method_family = none)]
237 pub fn integerValue(&self) -> NSInteger;
238
239 #[unsafe(method(setIntegerValue:))]
241 #[unsafe(method_family = none)]
242 pub fn setIntegerValue(&self, integer_value: NSInteger);
243
244 #[unsafe(method(floatValue))]
245 #[unsafe(method_family = none)]
246 pub fn floatValue(&self) -> c_float;
247
248 #[unsafe(method(setFloatValue:))]
250 #[unsafe(method_family = none)]
251 pub fn setFloatValue(&self, float_value: c_float);
252
253 #[unsafe(method(doubleValue))]
254 #[unsafe(method_family = none)]
255 pub fn doubleValue(&self) -> c_double;
256
257 #[unsafe(method(setDoubleValue:))]
259 #[unsafe(method_family = none)]
260 pub fn setDoubleValue(&self, double_value: c_double);
261
262 #[unsafe(method(sizeThatFits:))]
263 #[unsafe(method_family = none)]
264 pub fn sizeThatFits(&self, size: NSSize) -> NSSize;
265
266 #[unsafe(method(sizeToFit))]
267 #[unsafe(method_family = none)]
268 pub fn sizeToFit(&self);
269
270 #[cfg(feature = "NSEvent")]
271 #[unsafe(method(sendActionOn:))]
272 #[unsafe(method_family = none)]
273 pub fn sendActionOn(&self, mask: NSEventMask) -> NSInteger;
274
275 #[unsafe(method(sendAction:to:))]
280 #[unsafe(method_family = none)]
281 pub unsafe fn sendAction_to(&self, action: Option<Sel>, target: Option<&AnyObject>)
282 -> bool;
283
284 #[unsafe(method(takeIntValueFrom:))]
288 #[unsafe(method_family = none)]
289 pub unsafe fn takeIntValueFrom(&self, sender: Option<&AnyObject>);
290
291 #[unsafe(method(takeFloatValueFrom:))]
295 #[unsafe(method_family = none)]
296 pub unsafe fn takeFloatValueFrom(&self, sender: Option<&AnyObject>);
297
298 #[unsafe(method(takeDoubleValueFrom:))]
302 #[unsafe(method_family = none)]
303 pub unsafe fn takeDoubleValueFrom(&self, sender: Option<&AnyObject>);
304
305 #[unsafe(method(takeStringValueFrom:))]
309 #[unsafe(method_family = none)]
310 pub unsafe fn takeStringValueFrom(&self, sender: Option<&AnyObject>);
311
312 #[unsafe(method(takeObjectValueFrom:))]
316 #[unsafe(method_family = none)]
317 pub unsafe fn takeObjectValueFrom(&self, sender: Option<&AnyObject>);
318
319 #[unsafe(method(takeIntegerValueFrom:))]
323 #[unsafe(method_family = none)]
324 pub unsafe fn takeIntegerValueFrom(&self, sender: Option<&AnyObject>);
325
326 #[unsafe(method(performClick:))]
330 #[unsafe(method_family = none)]
331 pub unsafe fn performClick(&self, sender: Option<&AnyObject>);
332
333 #[cfg(feature = "NSFont")]
334 #[unsafe(method(font))]
335 #[unsafe(method_family = none)]
336 pub fn font(&self) -> Option<Retained<NSFont>>;
337
338 #[cfg(feature = "NSFont")]
339 #[unsafe(method(setFont:))]
343 #[unsafe(method_family = none)]
344 pub fn setFont(&self, font: Option<&NSFont>);
345
346 #[unsafe(method(usesSingleLineMode))]
347 #[unsafe(method_family = none)]
348 pub fn usesSingleLineMode(&self) -> bool;
349
350 #[unsafe(method(setUsesSingleLineMode:))]
352 #[unsafe(method_family = none)]
353 pub fn setUsesSingleLineMode(&self, uses_single_line_mode: bool);
354
355 #[cfg(feature = "NSParagraphStyle")]
356 #[unsafe(method(lineBreakMode))]
357 #[unsafe(method_family = none)]
358 pub fn lineBreakMode(&self) -> NSLineBreakMode;
359
360 #[cfg(feature = "NSParagraphStyle")]
361 #[unsafe(method(setLineBreakMode:))]
363 #[unsafe(method_family = none)]
364 pub fn setLineBreakMode(&self, line_break_mode: NSLineBreakMode);
365
366 #[cfg(feature = "NSText")]
367 #[unsafe(method(alignment))]
368 #[unsafe(method_family = none)]
369 pub fn alignment(&self) -> NSTextAlignment;
370
371 #[cfg(feature = "NSText")]
372 #[unsafe(method(setAlignment:))]
374 #[unsafe(method_family = none)]
375 pub fn setAlignment(&self, alignment: NSTextAlignment);
376
377 #[cfg(feature = "NSText")]
378 #[unsafe(method(baseWritingDirection))]
379 #[unsafe(method_family = none)]
380 pub fn baseWritingDirection(&self) -> NSWritingDirection;
381
382 #[cfg(feature = "NSText")]
383 #[unsafe(method(setBaseWritingDirection:))]
385 #[unsafe(method_family = none)]
386 pub fn setBaseWritingDirection(&self, base_writing_direction: NSWritingDirection);
387
388 #[unsafe(method(allowsExpansionToolTips))]
389 #[unsafe(method_family = none)]
390 pub fn allowsExpansionToolTips(&self) -> bool;
391
392 #[unsafe(method(setAllowsExpansionToolTips:))]
394 #[unsafe(method_family = none)]
395 pub fn setAllowsExpansionToolTips(&self, allows_expansion_tool_tips: bool);
396
397 #[unsafe(method(expansionFrameWithFrame:))]
398 #[unsafe(method_family = none)]
399 pub fn expansionFrameWithFrame(&self, content_frame: NSRect) -> NSRect;
400
401 #[unsafe(method(drawWithExpansionFrame:inView:))]
402 #[unsafe(method_family = none)]
403 pub fn drawWithExpansionFrame_inView(&self, content_frame: NSRect, view: &NSView);
404 );
405}
406
407#[cfg(all(feature = "NSResponder", feature = "NSView"))]
409impl NSControl {
410 extern_methods!(
411 #[unsafe(method(init))]
412 #[unsafe(method_family = init)]
413 pub fn init(this: Allocated<Self>) -> Retained<Self>;
414 );
415}
416
417#[cfg(all(feature = "NSResponder", feature = "NSView"))]
419impl NSControl {
420 extern_methods!(
421 #[unsafe(method(new))]
422 #[unsafe(method_family = new)]
423 pub fn new(mtm: MainThreadMarker) -> Retained<Self>;
424 );
425}
426
427#[cfg(all(feature = "NSResponder", feature = "NSView"))]
429impl NSControl {
430 extern_methods!(
431 #[cfg(feature = "NSText")]
432 #[unsafe(method(currentEditor))]
433 #[unsafe(method_family = none)]
434 pub fn currentEditor(&self) -> Option<Retained<NSText>>;
435
436 #[unsafe(method(abortEditing))]
437 #[unsafe(method_family = none)]
438 pub fn abortEditing(&self) -> bool;
439
440 #[unsafe(method(validateEditing))]
441 #[unsafe(method_family = none)]
442 pub fn validateEditing(&self);
443
444 #[cfg(all(feature = "NSEvent", feature = "NSText"))]
445 #[unsafe(method(editWithFrame:editor:delegate:event:))]
449 #[unsafe(method_family = none)]
450 pub unsafe fn editWithFrame_editor_delegate_event(
451 &self,
452 rect: NSRect,
453 text_obj: &NSText,
454 delegate: Option<&AnyObject>,
455 event: &NSEvent,
456 );
457
458 #[cfg(feature = "NSText")]
459 #[unsafe(method(selectWithFrame:editor:delegate:start:length:))]
463 #[unsafe(method_family = none)]
464 pub unsafe fn selectWithFrame_editor_delegate_start_length(
465 &self,
466 rect: NSRect,
467 text_obj: &NSText,
468 delegate: Option<&AnyObject>,
469 sel_start: NSInteger,
470 sel_length: NSInteger,
471 );
472
473 #[cfg(feature = "NSText")]
474 #[unsafe(method(endEditing:))]
475 #[unsafe(method_family = none)]
476 pub fn endEditing(&self, text_obj: &NSText);
477 );
478}
479
480extern_protocol!(
481 pub unsafe trait NSControlTextEditingDelegate:
483 NSObjectProtocol + MainThreadOnly
484 {
485 #[optional]
486 #[unsafe(method(controlTextDidBeginEditing:))]
487 #[unsafe(method_family = none)]
488 fn controlTextDidBeginEditing(&self, obj: &NSNotification);
489
490 #[optional]
491 #[unsafe(method(controlTextDidEndEditing:))]
492 #[unsafe(method_family = none)]
493 fn controlTextDidEndEditing(&self, obj: &NSNotification);
494
495 #[optional]
496 #[unsafe(method(controlTextDidChange:))]
497 #[unsafe(method_family = none)]
498 fn controlTextDidChange(&self, obj: &NSNotification);
499
500 #[cfg(all(feature = "NSResponder", feature = "NSText", feature = "NSView"))]
501 #[optional]
502 #[unsafe(method(control:textShouldBeginEditing:))]
503 #[unsafe(method_family = none)]
504 fn control_textShouldBeginEditing(
505 &self,
506 control: &NSControl,
507 field_editor: &NSText,
508 ) -> bool;
509
510 #[cfg(all(feature = "NSResponder", feature = "NSText", feature = "NSView"))]
511 #[optional]
512 #[unsafe(method(control:textShouldEndEditing:))]
513 #[unsafe(method_family = none)]
514 fn control_textShouldEndEditing(&self, control: &NSControl, field_editor: &NSText) -> bool;
515
516 #[cfg(all(feature = "NSResponder", feature = "NSView"))]
517 #[optional]
518 #[unsafe(method(control:didFailToFormatString:errorDescription:))]
519 #[unsafe(method_family = none)]
520 fn control_didFailToFormatString_errorDescription(
521 &self,
522 control: &NSControl,
523 string: &NSString,
524 error: Option<&NSString>,
525 ) -> bool;
526
527 #[cfg(all(feature = "NSResponder", feature = "NSView"))]
528 #[optional]
529 #[unsafe(method(control:didFailToValidatePartialString:errorDescription:))]
530 #[unsafe(method_family = none)]
531 fn control_didFailToValidatePartialString_errorDescription(
532 &self,
533 control: &NSControl,
534 string: &NSString,
535 error: Option<&NSString>,
536 );
537
538 #[cfg(all(feature = "NSResponder", feature = "NSView"))]
539 #[optional]
543 #[unsafe(method(control:isValidObject:))]
544 #[unsafe(method_family = none)]
545 unsafe fn control_isValidObject(
546 &self,
547 control: &NSControl,
548 obj: Option<&AnyObject>,
549 ) -> bool;
550
551 #[cfg(all(
552 feature = "NSResponder",
553 feature = "NSText",
554 feature = "NSTextView",
555 feature = "NSView"
556 ))]
557 #[optional]
561 #[unsafe(method(control:textView:doCommandBySelector:))]
562 #[unsafe(method_family = none)]
563 unsafe fn control_textView_doCommandBySelector(
564 &self,
565 control: &NSControl,
566 text_view: &NSTextView,
567 command_selector: Sel,
568 ) -> bool;
569
570 #[cfg(all(
571 feature = "NSResponder",
572 feature = "NSText",
573 feature = "NSTextView",
574 feature = "NSView"
575 ))]
576 #[optional]
580 #[unsafe(method(control:textView:completions:forPartialWordRange:indexOfSelectedItem:))]
581 #[unsafe(method_family = none)]
582 unsafe fn control_textView_completions_forPartialWordRange_indexOfSelectedItem(
583 &self,
584 control: &NSControl,
585 text_view: &NSTextView,
586 words: &NSArray<NSString>,
587 char_range: NSRange,
588 index: NonNull<NSInteger>,
589 ) -> Retained<NSArray<NSString>>;
590 }
591);
592
593extern "C" {
594 pub static NSControlTextDidBeginEditingNotification: &'static NSNotificationName;
596}
597
598extern "C" {
599 pub static NSControlTextDidEndEditingNotification: &'static NSNotificationName;
601}
602
603extern "C" {
604 pub static NSControlTextDidChangeNotification: &'static NSNotificationName;
606}
607
608#[cfg(all(feature = "NSResponder", feature = "NSView"))]
610impl NSControl {
611 extern_methods!(
612 #[deprecated]
613 #[unsafe(method(setFloatingPointFormat:left:right:))]
614 #[unsafe(method_family = none)]
615 pub fn setFloatingPointFormat_left_right(
616 &self,
617 auto_range: bool,
618 left_digits: NSUInteger,
619 right_digits: NSUInteger,
620 );
621
622 #[unsafe(method(cellClass))]
623 #[unsafe(method_family = none)]
624 pub fn cellClass(mtm: MainThreadMarker) -> Option<&'static AnyClass>;
625
626 #[unsafe(method(setCellClass:))]
632 #[unsafe(method_family = none)]
633 pub unsafe fn setCellClass(cell_class: Option<&AnyClass>, mtm: MainThreadMarker);
634
635 #[cfg(feature = "NSCell")]
636 #[unsafe(method(cell))]
637 #[unsafe(method_family = none)]
638 pub fn cell(&self) -> Option<Retained<NSCell>>;
639
640 #[cfg(feature = "NSCell")]
641 #[unsafe(method(setCell:))]
643 #[unsafe(method_family = none)]
644 pub fn setCell(&self, cell: Option<&NSCell>);
645
646 #[cfg(feature = "NSCell")]
647 #[unsafe(method(selectedCell))]
648 #[unsafe(method_family = none)]
649 pub fn selectedCell(&self) -> Option<Retained<NSCell>>;
650
651 #[unsafe(method(selectedTag))]
652 #[unsafe(method_family = none)]
653 pub fn selectedTag(&self) -> NSInteger;
654
655 #[deprecated = "Set the needsDisplay property to YES instead"]
656 #[unsafe(method(setNeedsDisplay))]
657 #[unsafe(method_family = none)]
658 pub fn setNeedsDisplay(&self);
659
660 #[deprecated = "Override -layout instead. This method should never be called"]
661 #[unsafe(method(calcSize))]
662 #[unsafe(method_family = none)]
663 pub fn calcSize(&self);
664
665 #[cfg(feature = "NSCell")]
666 #[unsafe(method(updateCell:))]
667 #[unsafe(method_family = none)]
668 pub fn updateCell(&self, cell: &NSCell);
669
670 #[cfg(feature = "NSCell")]
671 #[unsafe(method(updateCellInside:))]
672 #[unsafe(method_family = none)]
673 pub fn updateCellInside(&self, cell: &NSCell);
674
675 #[cfg(feature = "NSCell")]
676 #[unsafe(method(drawCellInside:))]
677 #[unsafe(method_family = none)]
678 pub fn drawCellInside(&self, cell: &NSCell);
679
680 #[cfg(feature = "NSCell")]
681 #[unsafe(method(drawCell:))]
682 #[unsafe(method_family = none)]
683 pub fn drawCell(&self, cell: &NSCell);
684
685 #[cfg(feature = "NSCell")]
686 #[unsafe(method(selectCell:))]
687 #[unsafe(method_family = none)]
688 pub fn selectCell(&self, cell: &NSCell);
689 );
690}
691
692#[repr(transparent)]
695#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
696pub struct NSControlBorderShape(pub NSInteger);
697impl NSControlBorderShape {
698 #[doc(alias = "NSControlBorderShapeAutomatic")]
700 pub const Automatic: Self = Self(0);
701 #[doc(alias = "NSControlBorderShapeCapsule")]
703 pub const Capsule: Self = Self(1);
704 #[doc(alias = "NSControlBorderShapeRoundedRectangle")]
706 pub const RoundedRectangle: Self = Self(2);
707 #[doc(alias = "NSControlBorderShapeCircle")]
709 pub const Circle: Self = Self(3);
710}
711
712unsafe impl Encode for NSControlBorderShape {
713 const ENCODING: Encoding = NSInteger::ENCODING;
714}
715
716unsafe impl RefEncode for NSControlBorderShape {
717 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
718}