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