objc2_app_kit/generated/
NSPopUpButton.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10extern_class!(
11    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspopupbutton?language=objc)
12    #[unsafe(super(NSButton, NSControl, NSView, NSResponder, NSObject))]
13    #[derive(Debug, PartialEq, Eq, Hash)]
14    #[cfg(all(
15        feature = "NSButton",
16        feature = "NSControl",
17        feature = "NSResponder",
18        feature = "NSView"
19    ))]
20    pub struct NSPopUpButton;
21);
22
23#[cfg(all(
24    feature = "NSAccessibilityProtocols",
25    feature = "NSButton",
26    feature = "NSControl",
27    feature = "NSResponder",
28    feature = "NSView"
29))]
30extern_conformance!(
31    unsafe impl NSAccessibility for NSPopUpButton {}
32);
33
34#[cfg(all(
35    feature = "NSAccessibilityProtocols",
36    feature = "NSButton",
37    feature = "NSControl",
38    feature = "NSResponder",
39    feature = "NSView"
40))]
41extern_conformance!(
42    unsafe impl NSAccessibilityButton for NSPopUpButton {}
43);
44
45#[cfg(all(
46    feature = "NSAccessibilityProtocols",
47    feature = "NSButton",
48    feature = "NSControl",
49    feature = "NSResponder",
50    feature = "NSView"
51))]
52extern_conformance!(
53    unsafe impl NSAccessibilityElementProtocol for NSPopUpButton {}
54);
55
56#[cfg(all(
57    feature = "NSAnimation",
58    feature = "NSButton",
59    feature = "NSControl",
60    feature = "NSResponder",
61    feature = "NSView"
62))]
63extern_conformance!(
64    unsafe impl NSAnimatablePropertyContainer for NSPopUpButton {}
65);
66
67#[cfg(all(
68    feature = "NSAppearance",
69    feature = "NSButton",
70    feature = "NSControl",
71    feature = "NSResponder",
72    feature = "NSView"
73))]
74extern_conformance!(
75    unsafe impl NSAppearanceCustomization for NSPopUpButton {}
76);
77
78#[cfg(all(
79    feature = "NSButton",
80    feature = "NSControl",
81    feature = "NSResponder",
82    feature = "NSView"
83))]
84extern_conformance!(
85    unsafe impl NSCoding for NSPopUpButton {}
86);
87
88#[cfg(all(
89    feature = "NSButton",
90    feature = "NSControl",
91    feature = "NSDragging",
92    feature = "NSResponder",
93    feature = "NSView"
94))]
95extern_conformance!(
96    unsafe impl NSDraggingDestination for NSPopUpButton {}
97);
98
99#[cfg(all(
100    feature = "NSButton",
101    feature = "NSControl",
102    feature = "NSResponder",
103    feature = "NSView"
104))]
105extern_conformance!(
106    unsafe impl NSObjectProtocol for NSPopUpButton {}
107);
108
109#[cfg(all(
110    feature = "NSButton",
111    feature = "NSControl",
112    feature = "NSResponder",
113    feature = "NSUserInterfaceCompression",
114    feature = "NSView"
115))]
116extern_conformance!(
117    unsafe impl NSUserInterfaceCompression for NSPopUpButton {}
118);
119
120#[cfg(all(
121    feature = "NSButton",
122    feature = "NSControl",
123    feature = "NSResponder",
124    feature = "NSUserInterfaceItemIdentification",
125    feature = "NSView"
126))]
127extern_conformance!(
128    unsafe impl NSUserInterfaceItemIdentification for NSPopUpButton {}
129);
130
131#[cfg(all(
132    feature = "NSButton",
133    feature = "NSControl",
134    feature = "NSResponder",
135    feature = "NSUserInterfaceValidation",
136    feature = "NSView"
137))]
138extern_conformance!(
139    unsafe impl NSUserInterfaceValidations for NSPopUpButton {}
140);
141
142#[cfg(all(
143    feature = "NSButton",
144    feature = "NSControl",
145    feature = "NSResponder",
146    feature = "NSView"
147))]
148impl NSPopUpButton {
149    extern_methods!(
150        #[cfg(feature = "NSMenu")]
151        /// Creates a standard pop-up button with a menu, target, and action.
152        ///
153        /// Parameter `menu`: A menu presented by the pop-up button, containing items that the user can choose between.
154        ///
155        /// Parameter `target`: The target object that receives action messages from the control.
156        ///
157        /// Parameter `action`: The action message sent by the control.
158        ///
159        /// If `menu` is non-empty, the pop-up button uses the first item for its initial selection.
160        ///
161        /// Returns: An initialized pop-up button object.
162        ///
163        /// # Safety
164        ///
165        /// - `target` should be of the correct type.
166        /// - `action` must be a valid selector.
167        #[unsafe(method(popUpButtonWithMenu:target:action:))]
168        #[unsafe(method_family = none)]
169        pub unsafe fn popUpButtonWithMenu_target_action(
170            menu: &NSMenu,
171            target: Option<&AnyObject>,
172            action: Option<Sel>,
173        ) -> Retained<Self>;
174
175        #[cfg(feature = "NSMenu")]
176        /// Creates a standard pull-down button with a title and menu.
177        ///
178        /// Parameter `title`: The localized title string that is displayed on the button.
179        ///
180        /// Parameter `menu`: The pull-down menu to present when interacting with the button.
181        ///
182        /// Pull-down buttons created using this method have the `usesItemFromMenu` property set to `NO`.
183        ///
184        /// Returns: An initialized pull-down button object.
185        #[unsafe(method(pullDownButtonWithTitle:menu:))]
186        #[unsafe(method_family = none)]
187        pub fn pullDownButtonWithTitle_menu(title: &NSString, menu: &NSMenu) -> Retained<Self>;
188
189        #[cfg(all(feature = "NSImage", feature = "NSMenu"))]
190        /// Creates a standard pull-down button with an image and menu.
191        ///
192        /// Parameter `image`: The icon that is displayed on the button.
193        ///
194        /// Parameter `menu`: The pull-down menu to present when interacting with the button.
195        ///
196        /// Pull-down buttons created using this method have the `usesItemFromMenu` property set to `NO`.
197        ///
198        /// Returns: An initialized pull-down button object.
199        #[unsafe(method(pullDownButtonWithImage:menu:))]
200        #[unsafe(method_family = none)]
201        pub fn pullDownButtonWithImage_menu(image: &NSImage, menu: &NSMenu) -> Retained<Self>;
202
203        #[cfg(all(feature = "NSImage", feature = "NSMenu"))]
204        /// Creates a standard pull-down button with a title, image, and menu.
205        ///
206        /// Parameter `title`: The localized title string that is displayed on the button.
207        ///
208        /// Parameter `image`: The icon that is displayed on the button.
209        ///
210        /// Parameter `menu`: The pull-down menu to present when interacting with the button.
211        ///
212        /// Pull-down buttons created using this method have the `usesItemFromMenu` property set to `NO`.
213        ///
214        /// Returns: An initialized pull-down button object.
215        #[unsafe(method(pullDownButtonWithTitle:image:menu:))]
216        #[unsafe(method_family = none)]
217        pub fn pullDownButtonWithTitle_image_menu(
218            title: &NSString,
219            image: &NSImage,
220            menu: &NSMenu,
221        ) -> Retained<Self>;
222
223        #[unsafe(method(initWithFrame:pullsDown:))]
224        #[unsafe(method_family = init)]
225        pub fn initWithFrame_pullsDown(
226            this: Allocated<Self>,
227            button_frame: NSRect,
228            flag: bool,
229        ) -> Retained<Self>;
230
231        #[cfg(feature = "NSMenu")]
232        /// The menu that is presented by the popup button. This overrides the inherited NSView property and replaces NSView's standard context menu behavior.
233        #[unsafe(method(menu))]
234        #[unsafe(method_family = none)]
235        pub fn menu(&self) -> Option<Retained<NSMenu>>;
236
237        #[cfg(feature = "NSMenu")]
238        /// Setter for [`menu`][Self::menu].
239        #[unsafe(method(setMenu:))]
240        #[unsafe(method_family = none)]
241        pub fn setMenu(&self, menu: Option<&NSMenu>);
242
243        /// When the value of this property is `YES` the button adopts 'pull-down' behavior, displaying static button contents and presenting its menu at the edge of the button. When the value of this property is `NO` the button behaves as a popup, displaying the currently-selected menu item and presenting its menu above the button, positioning the selected menu item to match the button's contents.
244        #[unsafe(method(pullsDown))]
245        #[unsafe(method_family = none)]
246        pub fn pullsDown(&self) -> bool;
247
248        /// Setter for [`pullsDown`][Self::pullsDown].
249        #[unsafe(method(setPullsDown:))]
250        #[unsafe(method_family = none)]
251        pub fn setPullsDown(&self, pulls_down: bool);
252
253        /// When the value of this property is `YES`, the popup button automatically enables and disables its menu items according to the `NSMenuValidation` protocol prior to user interaction.
254        #[unsafe(method(autoenablesItems))]
255        #[unsafe(method_family = none)]
256        pub fn autoenablesItems(&self) -> bool;
257
258        /// Setter for [`autoenablesItems`][Self::autoenablesItems].
259        #[unsafe(method(setAutoenablesItems:))]
260        #[unsafe(method_family = none)]
261        pub fn setAutoenablesItems(&self, autoenables_items: bool);
262
263        /// For pull-down buttons and for popups under severe screen position restrictions, this property specifies the edge of the control that the menu should present from.
264        #[unsafe(method(preferredEdge))]
265        #[unsafe(method_family = none)]
266        pub fn preferredEdge(&self) -> NSRectEdge;
267
268        /// Setter for [`preferredEdge`][Self::preferredEdge].
269        #[unsafe(method(setPreferredEdge:))]
270        #[unsafe(method_family = none)]
271        pub fn setPreferredEdge(&self, preferred_edge: NSRectEdge);
272
273        /// When `usesItemFromMenu` is `YES`, a pull-down button uses the title of the first menu item and hides the first menu item. A pop-up button uses the title of the currently selected menu. The default value is `YES`.
274        #[unsafe(method(usesItemFromMenu))]
275        #[unsafe(method_family = none)]
276        pub fn usesItemFromMenu(&self) -> bool;
277
278        /// Setter for [`usesItemFromMenu`][Self::usesItemFromMenu].
279        #[unsafe(method(setUsesItemFromMenu:))]
280        #[unsafe(method_family = none)]
281        pub fn setUsesItemFromMenu(&self, uses_item_from_menu: bool);
282
283        /// When the value of this property is `YES`, the selected menu item's `state` is set to `NSControlStateValueOn`. When the value of this property is `NO`, the menu item's `state` is not changed. When this property changes, the `state` of the currently selected item is updated appropriately. This property is ignored for pull-down buttons.
284        #[unsafe(method(altersStateOfSelectedItem))]
285        #[unsafe(method_family = none)]
286        pub fn altersStateOfSelectedItem(&self) -> bool;
287
288        /// Setter for [`altersStateOfSelectedItem`][Self::altersStateOfSelectedItem].
289        #[unsafe(method(setAltersStateOfSelectedItem:))]
290        #[unsafe(method_family = none)]
291        pub fn setAltersStateOfSelectedItem(&self, alters_state_of_selected_item: bool);
292
293        #[unsafe(method(addItemWithTitle:))]
294        #[unsafe(method_family = none)]
295        pub fn addItemWithTitle(&self, title: &NSString);
296
297        #[unsafe(method(addItemsWithTitles:))]
298        #[unsafe(method_family = none)]
299        pub fn addItemsWithTitles(&self, item_titles: &NSArray<NSString>);
300
301        #[unsafe(method(insertItemWithTitle:atIndex:))]
302        #[unsafe(method_family = none)]
303        pub fn insertItemWithTitle_atIndex(&self, title: &NSString, index: NSInteger);
304
305        #[unsafe(method(removeItemWithTitle:))]
306        #[unsafe(method_family = none)]
307        pub fn removeItemWithTitle(&self, title: &NSString);
308
309        #[unsafe(method(removeItemAtIndex:))]
310        #[unsafe(method_family = none)]
311        pub fn removeItemAtIndex(&self, index: NSInteger);
312
313        #[unsafe(method(removeAllItems))]
314        #[unsafe(method_family = none)]
315        pub fn removeAllItems(&self);
316
317        #[cfg(feature = "NSMenuItem")]
318        #[unsafe(method(itemArray))]
319        #[unsafe(method_family = none)]
320        pub fn itemArray(&self) -> Retained<NSArray<NSMenuItem>>;
321
322        #[unsafe(method(numberOfItems))]
323        #[unsafe(method_family = none)]
324        pub fn numberOfItems(&self) -> NSInteger;
325
326        #[cfg(feature = "NSMenuItem")]
327        #[unsafe(method(indexOfItem:))]
328        #[unsafe(method_family = none)]
329        pub fn indexOfItem(&self, item: &NSMenuItem) -> NSInteger;
330
331        #[unsafe(method(indexOfItemWithTitle:))]
332        #[unsafe(method_family = none)]
333        pub fn indexOfItemWithTitle(&self, title: &NSString) -> NSInteger;
334
335        #[unsafe(method(indexOfItemWithTag:))]
336        #[unsafe(method_family = none)]
337        pub fn indexOfItemWithTag(&self, tag: NSInteger) -> NSInteger;
338
339        /// # Safety
340        ///
341        /// `obj` should be of the correct type.
342        #[unsafe(method(indexOfItemWithRepresentedObject:))]
343        #[unsafe(method_family = none)]
344        pub unsafe fn indexOfItemWithRepresentedObject(&self, obj: Option<&AnyObject>)
345            -> NSInteger;
346
347        /// # Safety
348        ///
349        /// - `target` should be of the correct type.
350        /// - `action_selector` must be a valid selector.
351        #[unsafe(method(indexOfItemWithTarget:andAction:))]
352        #[unsafe(method_family = none)]
353        pub unsafe fn indexOfItemWithTarget_andAction(
354            &self,
355            target: Option<&AnyObject>,
356            action_selector: Option<Sel>,
357        ) -> NSInteger;
358
359        #[cfg(feature = "NSMenuItem")]
360        #[unsafe(method(itemAtIndex:))]
361        #[unsafe(method_family = none)]
362        pub fn itemAtIndex(&self, index: NSInteger) -> Option<Retained<NSMenuItem>>;
363
364        #[cfg(feature = "NSMenuItem")]
365        #[unsafe(method(itemWithTitle:))]
366        #[unsafe(method_family = none)]
367        pub fn itemWithTitle(&self, title: &NSString) -> Option<Retained<NSMenuItem>>;
368
369        #[cfg(feature = "NSMenuItem")]
370        #[unsafe(method(lastItem))]
371        #[unsafe(method_family = none)]
372        pub fn lastItem(&self) -> Option<Retained<NSMenuItem>>;
373
374        #[cfg(feature = "NSMenuItem")]
375        #[unsafe(method(selectItem:))]
376        #[unsafe(method_family = none)]
377        pub fn selectItem(&self, item: Option<&NSMenuItem>);
378
379        #[unsafe(method(selectItemAtIndex:))]
380        #[unsafe(method_family = none)]
381        pub fn selectItemAtIndex(&self, index: NSInteger);
382
383        #[unsafe(method(selectItemWithTitle:))]
384        #[unsafe(method_family = none)]
385        pub fn selectItemWithTitle(&self, title: &NSString);
386
387        #[unsafe(method(selectItemWithTag:))]
388        #[unsafe(method_family = none)]
389        pub fn selectItemWithTag(&self, tag: NSInteger) -> bool;
390
391        #[unsafe(method(setTitle:))]
392        #[unsafe(method_family = none)]
393        pub fn setTitle(&self, string: &NSString);
394
395        #[cfg(feature = "NSMenuItem")]
396        #[unsafe(method(selectedItem))]
397        #[unsafe(method_family = none)]
398        pub fn selectedItem(&self) -> Option<Retained<NSMenuItem>>;
399
400        #[unsafe(method(indexOfSelectedItem))]
401        #[unsafe(method_family = none)]
402        pub fn indexOfSelectedItem(&self) -> NSInteger;
403
404        #[unsafe(method(selectedTag))]
405        #[unsafe(method_family = none)]
406        pub fn selectedTag(&self) -> NSInteger;
407
408        #[unsafe(method(synchronizeTitleAndSelectedItem))]
409        #[unsafe(method_family = none)]
410        pub fn synchronizeTitleAndSelectedItem(&self);
411
412        #[unsafe(method(itemTitleAtIndex:))]
413        #[unsafe(method_family = none)]
414        pub fn itemTitleAtIndex(&self, index: NSInteger) -> Retained<NSString>;
415
416        #[unsafe(method(itemTitles))]
417        #[unsafe(method_family = none)]
418        pub fn itemTitles(&self) -> Retained<NSArray<NSString>>;
419
420        #[unsafe(method(titleOfSelectedItem))]
421        #[unsafe(method_family = none)]
422        pub fn titleOfSelectedItem(&self) -> Option<Retained<NSString>>;
423    );
424}
425
426/// Methods declared on superclass `NSButton`.
427#[cfg(all(
428    feature = "NSButton",
429    feature = "NSControl",
430    feature = "NSResponder",
431    feature = "NSView"
432))]
433impl NSPopUpButton {
434    extern_methods!(
435        #[cfg(feature = "NSImage")]
436        /// Creates a standard push button with a title and image.
437        ///
438        /// Parameter `title`: The localized title string that is displayed on the button.
439        ///
440        /// Parameter `image`: The image that is displayed alongside the title. In left-to-right localizations, the image is displayed to the left of the title. In right-to-left localizations, it is displayed to the right.
441        ///
442        /// Parameter `target`: The target object that receives action messages from the control.
443        ///
444        /// Parameter `action`: The action message sent by the control.
445        ///
446        /// Returns: An initialized button object.
447        ///
448        /// # Safety
449        ///
450        /// - `target` should be of the correct type.
451        /// - `action` must be a valid selector.
452        #[unsafe(method(buttonWithTitle:image:target:action:))]
453        #[unsafe(method_family = none)]
454        pub unsafe fn buttonWithTitle_image_target_action(
455            title: &NSString,
456            image: &NSImage,
457            target: Option<&AnyObject>,
458            action: Option<Sel>,
459            mtm: MainThreadMarker,
460        ) -> Retained<Self>;
461
462        /// Creates a standard push button with the provided title.
463        ///
464        /// Parameter `title`: The localized title string that is displayed on the button.
465        ///
466        /// Parameter `target`: The target object that receives action messages from the control.
467        ///
468        /// Parameter `action`: The action message sent by the control.
469        ///
470        /// Returns: An initialized button object.
471        ///
472        /// # Safety
473        ///
474        /// - `target` should be of the correct type.
475        /// - `action` must be a valid selector.
476        #[unsafe(method(buttonWithTitle:target:action:))]
477        #[unsafe(method_family = none)]
478        pub unsafe fn buttonWithTitle_target_action(
479            title: &NSString,
480            target: Option<&AnyObject>,
481            action: Option<Sel>,
482            mtm: MainThreadMarker,
483        ) -> Retained<Self>;
484
485        #[cfg(feature = "NSImage")]
486        /// Creates a standard push button with the provided image. Set the image's accessibilityDescription property to ensure accessibility for this control.
487        ///
488        /// Parameter `image`: The image to display in the body of the button.
489        ///
490        /// Parameter `target`: The target object that receives action messages from the control.
491        ///
492        /// Parameter `action`: The action message sent by the control.
493        ///
494        /// Returns: An initialized button object.
495        ///
496        /// # Safety
497        ///
498        /// - `target` should be of the correct type.
499        /// - `action` must be a valid selector.
500        #[unsafe(method(buttonWithImage:target:action:))]
501        #[unsafe(method_family = none)]
502        pub unsafe fn buttonWithImage_target_action(
503            image: &NSImage,
504            target: Option<&AnyObject>,
505            action: Option<Sel>,
506            mtm: MainThreadMarker,
507        ) -> Retained<Self>;
508
509        /// Creates a standard checkbox with the provided title.
510        ///
511        /// Parameter `title`: The localized title string that is displayed alongside the checkbox.
512        ///
513        /// Parameter `target`: The target object that receives action messages from the control.
514        ///
515        /// Parameter `action`: The action message sent by the control.
516        ///
517        /// Returns: An initialized button object.
518        ///
519        /// # Safety
520        ///
521        /// - `target` should be of the correct type.
522        /// - `action` must be a valid selector.
523        #[unsafe(method(checkboxWithTitle:target:action:))]
524        #[unsafe(method_family = none)]
525        pub unsafe fn checkboxWithTitle_target_action(
526            title: &NSString,
527            target: Option<&AnyObject>,
528            action: Option<Sel>,
529            mtm: MainThreadMarker,
530        ) -> Retained<Self>;
531
532        /// Creates a standard radio button with the provided title.
533        ///
534        /// Parameter `title`: The localized title string that is displayed alongside the radio button.
535        ///
536        /// Parameter `target`: The target object that receives action messages from the control.
537        ///
538        /// Parameter `action`: The action message sent by the control.
539        ///
540        /// Returns: An initialized button object.
541        ///
542        /// # Safety
543        ///
544        /// - `target` should be of the correct type.
545        /// - `action` must be a valid selector.
546        #[unsafe(method(radioButtonWithTitle:target:action:))]
547        #[unsafe(method_family = none)]
548        pub unsafe fn radioButtonWithTitle_target_action(
549            title: &NSString,
550            target: Option<&AnyObject>,
551            action: Option<Sel>,
552            mtm: MainThreadMarker,
553        ) -> Retained<Self>;
554    );
555}
556
557/// Methods declared on superclass `NSControl`.
558#[cfg(all(
559    feature = "NSButton",
560    feature = "NSControl",
561    feature = "NSResponder",
562    feature = "NSView"
563))]
564impl NSPopUpButton {
565    extern_methods!(
566        #[unsafe(method(initWithFrame:))]
567        #[unsafe(method_family = init)]
568        pub fn initWithFrame(this: Allocated<Self>, frame_rect: NSRect) -> Retained<Self>;
569
570        /// # Safety
571        ///
572        /// `coder` possibly has further requirements.
573        #[unsafe(method(initWithCoder:))]
574        #[unsafe(method_family = init)]
575        pub unsafe fn initWithCoder(
576            this: Allocated<Self>,
577            coder: &NSCoder,
578        ) -> Option<Retained<Self>>;
579    );
580}
581
582/// Methods declared on superclass `NSResponder`.
583#[cfg(all(
584    feature = "NSButton",
585    feature = "NSControl",
586    feature = "NSResponder",
587    feature = "NSView"
588))]
589impl NSPopUpButton {
590    extern_methods!(
591        #[unsafe(method(init))]
592        #[unsafe(method_family = init)]
593        pub fn init(this: Allocated<Self>) -> Retained<Self>;
594    );
595}
596
597/// Methods declared on superclass `NSObject`.
598#[cfg(all(
599    feature = "NSButton",
600    feature = "NSControl",
601    feature = "NSResponder",
602    feature = "NSView"
603))]
604impl NSPopUpButton {
605    extern_methods!(
606        #[unsafe(method(new))]
607        #[unsafe(method_family = new)]
608        pub fn new(mtm: MainThreadMarker) -> Retained<Self>;
609    );
610}
611
612extern "C" {
613    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspopupbuttonwillpopupnotification?language=objc)
614    pub static NSPopUpButtonWillPopUpNotification: &'static NSNotificationName;
615}