objc2_app_kit/generated/
NSToolbarItemGroup.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
10/// `NSToolbarItemGroup` is a subclass of `NSToolbarItem` which can be used to create sets of `NSToolbarItems` that are always attached to one another and that are added, removed, or reordered as a single unit.
11/// Properties that get set on the parent toolbar item, such as label or view, apply to the entire item.
12/// Otherwise, the individual properties are displayed adjacent to one another.
13/// Subitems will inherit the group's action if no action is defined on the subitem and will validate based on that action when autovalidates is enabled.
14///
15/// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nstoolbaritemgroupselectionmode?language=objc)
16// NS_ENUM
17#[repr(transparent)]
18#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
19pub struct NSToolbarItemGroupSelectionMode(pub NSInteger);
20impl NSToolbarItemGroupSelectionMode {
21    #[doc(alias = "NSToolbarItemGroupSelectionModeSelectOne")]
22    pub const SelectOne: Self = Self(0);
23    #[doc(alias = "NSToolbarItemGroupSelectionModeSelectAny")]
24    pub const SelectAny: Self = Self(1);
25    #[doc(alias = "NSToolbarItemGroupSelectionModeMomentary")]
26    pub const Momentary: Self = Self(2);
27}
28
29unsafe impl Encode for NSToolbarItemGroupSelectionMode {
30    const ENCODING: Encoding = NSInteger::ENCODING;
31}
32
33unsafe impl RefEncode for NSToolbarItemGroupSelectionMode {
34    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
35}
36
37/// [Apple's documentation](https://developer.apple.com/documentation/appkit/nstoolbaritemgroupcontrolrepresentation?language=objc)
38// NS_ENUM
39#[repr(transparent)]
40#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
41pub struct NSToolbarItemGroupControlRepresentation(pub NSInteger);
42impl NSToolbarItemGroupControlRepresentation {
43    #[doc(alias = "NSToolbarItemGroupControlRepresentationAutomatic")]
44    pub const Automatic: Self = Self(0);
45    #[doc(alias = "NSToolbarItemGroupControlRepresentationExpanded")]
46    pub const Expanded: Self = Self(1);
47    #[doc(alias = "NSToolbarItemGroupControlRepresentationCollapsed")]
48    pub const Collapsed: Self = Self(2);
49}
50
51unsafe impl Encode for NSToolbarItemGroupControlRepresentation {
52    const ENCODING: Encoding = NSInteger::ENCODING;
53}
54
55unsafe impl RefEncode for NSToolbarItemGroupControlRepresentation {
56    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
57}
58
59extern_class!(
60    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nstoolbaritemgroup?language=objc)
61    #[unsafe(super(NSToolbarItem, NSObject))]
62    #[derive(Debug, PartialEq, Eq, Hash)]
63    #[cfg(feature = "NSToolbarItem")]
64    pub struct NSToolbarItemGroup;
65);
66
67#[cfg(feature = "NSToolbarItem")]
68extern_conformance!(
69    unsafe impl NSCopying for NSToolbarItemGroup {}
70);
71
72#[cfg(feature = "NSToolbarItem")]
73unsafe impl CopyingHelper for NSToolbarItemGroup {
74    type Result = Self;
75}
76
77#[cfg(feature = "NSToolbarItem")]
78extern_conformance!(
79    unsafe impl NSObjectProtocol for NSToolbarItemGroup {}
80);
81
82#[cfg(feature = "NSToolbarItem")]
83impl NSToolbarItemGroup {
84    extern_methods!(
85        #[cfg(feature = "NSToolbar")]
86        /// Convenience constructors for creating segmented control based toolbar items with images or text.
87        /// The item returned will have a custom view for representing the control and automatically create subitems for the group.
88        /// The labels array, if not nil, will be used to provide individual labels under the item for each segment of the control.
89        /// When space in the toolbar is tight, the control may switch to a smaller alternate representation as necessary to remain in the toolbar.
90        ///
91        /// # Safety
92        ///
93        /// - `target` should be of the correct type.
94        /// - `action` must be a valid selector.
95        #[unsafe(method(groupWithItemIdentifier:titles:selectionMode:labels:target:action:))]
96        #[unsafe(method_family = none)]
97        pub unsafe fn groupWithItemIdentifier_titles_selectionMode_labels_target_action(
98            item_identifier: &NSToolbarItemIdentifier,
99            titles: &NSArray<NSString>,
100            selection_mode: NSToolbarItemGroupSelectionMode,
101            labels: Option<&NSArray<NSString>>,
102            target: Option<&AnyObject>,
103            action: Option<Sel>,
104            mtm: MainThreadMarker,
105        ) -> Retained<Self>;
106
107        #[cfg(all(feature = "NSImage", feature = "NSToolbar"))]
108        /// # Safety
109        ///
110        /// - `target` should be of the correct type.
111        /// - `action` must be a valid selector.
112        #[unsafe(method(groupWithItemIdentifier:images:selectionMode:labels:target:action:))]
113        #[unsafe(method_family = none)]
114        pub unsafe fn groupWithItemIdentifier_images_selectionMode_labels_target_action(
115            item_identifier: &NSToolbarItemIdentifier,
116            images: &NSArray<NSImage>,
117            selection_mode: NSToolbarItemGroupSelectionMode,
118            labels: Option<&NSArray<NSString>>,
119            target: Option<&AnyObject>,
120            action: Option<Sel>,
121            mtm: MainThreadMarker,
122        ) -> Retained<Self>;
123
124        /// Set or get the array of subitems for the toolbar item.
125        /// By default, a `NSToolbarItemGroup` has an empty array of subitems.
126        /// You should call this to set the subitems before returning the item to the toolbar.
127        /// `NSToolbarItemGroups` may not contain other `NSToolbarItemGroups` as subitems.
128        #[unsafe(method(subitems))]
129        #[unsafe(method_family = none)]
130        pub fn subitems(&self) -> Retained<NSArray<NSToolbarItem>>;
131
132        /// Setter for [`subitems`][Self::subitems].
133        ///
134        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
135        #[unsafe(method(setSubitems:))]
136        #[unsafe(method_family = none)]
137        pub fn setSubitems(&self, subitems: &NSArray<NSToolbarItem>);
138
139        /// The style in which this item will be represented to the user.
140        /// Defaults to `NSToolbarItemGroupControlRepresentationAutomatic`.
141        #[unsafe(method(controlRepresentation))]
142        #[unsafe(method_family = none)]
143        pub fn controlRepresentation(&self) -> NSToolbarItemGroupControlRepresentation;
144
145        /// Setter for [`controlRepresentation`][Self::controlRepresentation].
146        #[unsafe(method(setControlRepresentation:))]
147        #[unsafe(method_family = none)]
148        pub fn setControlRepresentation(
149            &self,
150            control_representation: NSToolbarItemGroupControlRepresentation,
151        );
152
153        /// Get and set how selection is handled by the control.
154        /// Only applies when using one of the constructors to create the item with a system defined control representation.
155        #[unsafe(method(selectionMode))]
156        #[unsafe(method_family = none)]
157        pub fn selectionMode(&self) -> NSToolbarItemGroupSelectionMode;
158
159        /// Setter for [`selectionMode`][Self::selectionMode].
160        #[unsafe(method(setSelectionMode:))]
161        #[unsafe(method_family = none)]
162        pub fn setSelectionMode(&self, selection_mode: NSToolbarItemGroupSelectionMode);
163
164        /// The most recently selected item of the group, or -1 if nothing is selected.
165        #[unsafe(method(selectedIndex))]
166        #[unsafe(method_family = none)]
167        pub fn selectedIndex(&self) -> NSInteger;
168
169        /// Setter for [`selectedIndex`][Self::selectedIndex].
170        #[unsafe(method(setSelectedIndex:))]
171        #[unsafe(method_family = none)]
172        pub fn setSelectedIndex(&self, selected_index: NSInteger);
173
174        /// Get and set selection of individual subitems of the group item.
175        #[unsafe(method(setSelected:atIndex:))]
176        #[unsafe(method_family = none)]
177        pub fn setSelected_atIndex(&self, selected: bool, index: NSInteger);
178
179        #[unsafe(method(isSelectedAtIndex:))]
180        #[unsafe(method_family = none)]
181        pub fn isSelectedAtIndex(&self, index: NSInteger) -> bool;
182    );
183}
184
185/// Methods declared on superclass `NSToolbarItem`.
186#[cfg(feature = "NSToolbarItem")]
187impl NSToolbarItemGroup {
188    extern_methods!(
189        #[cfg(feature = "NSToolbar")]
190        /// Initialize the toolbar item with an identifier which is a development language string used by the toolbar and its delegate for identification purposes.
191        #[unsafe(method(initWithItemIdentifier:))]
192        #[unsafe(method_family = init)]
193        pub fn initWithItemIdentifier(
194            this: Allocated<Self>,
195            item_identifier: &NSToolbarItemIdentifier,
196        ) -> Retained<Self>;
197    );
198}
199
200/// Methods declared on superclass `NSObject`.
201#[cfg(feature = "NSToolbarItem")]
202impl NSToolbarItemGroup {
203    extern_methods!(
204        #[unsafe(method(init))]
205        #[unsafe(method_family = init)]
206        pub fn init(this: Allocated<Self>) -> Retained<Self>;
207
208        #[unsafe(method(new))]
209        #[unsafe(method_family = new)]
210        pub fn new(mtm: MainThreadMarker) -> Retained<Self>;
211    );
212}