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