1use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6#[cfg(feature = "objc2-core-foundation")]
7use objc2_core_foundation::*;
8use objc2_foundation::*;
9
10use crate::*;
11
12#[repr(transparent)]
15#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
16pub struct NSColorPanelMode(pub NSInteger);
17impl NSColorPanelMode {
18 #[doc(alias = "NSColorPanelModeNone")]
19 pub const None: Self = Self(-1);
20 #[doc(alias = "NSColorPanelModeGray")]
21 pub const Gray: Self = Self(0);
22 #[doc(alias = "NSColorPanelModeRGB")]
23 pub const RGB: Self = Self(1);
24 #[doc(alias = "NSColorPanelModeCMYK")]
25 pub const CMYK: Self = Self(2);
26 #[doc(alias = "NSColorPanelModeHSB")]
27 pub const HSB: Self = Self(3);
28 #[doc(alias = "NSColorPanelModeCustomPalette")]
29 pub const CustomPalette: Self = Self(4);
30 #[doc(alias = "NSColorPanelModeColorList")]
31 pub const ColorList: Self = Self(5);
32 #[doc(alias = "NSColorPanelModeWheel")]
33 pub const Wheel: Self = Self(6);
34 #[doc(alias = "NSColorPanelModeCrayon")]
35 pub const Crayon: Self = Self(7);
36}
37
38unsafe impl Encode for NSColorPanelMode {
39 const ENCODING: Encoding = NSInteger::ENCODING;
40}
41
42unsafe impl RefEncode for NSColorPanelMode {
43 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
44}
45
46#[repr(transparent)]
49#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
50pub struct NSColorPanelOptions(pub NSUInteger);
51bitflags::bitflags! {
52 impl NSColorPanelOptions: NSUInteger {
53 #[doc(alias = "NSColorPanelGrayModeMask")]
54 const GrayModeMask = 0x00000001;
55 #[doc(alias = "NSColorPanelRGBModeMask")]
56 const RGBModeMask = 0x00000002;
57 #[doc(alias = "NSColorPanelCMYKModeMask")]
58 const CMYKModeMask = 0x00000004;
59 #[doc(alias = "NSColorPanelHSBModeMask")]
60 const HSBModeMask = 0x00000008;
61 #[doc(alias = "NSColorPanelCustomPaletteModeMask")]
62 const CustomPaletteModeMask = 0x00000010;
63 #[doc(alias = "NSColorPanelColorListModeMask")]
64 const ColorListModeMask = 0x00000020;
65 #[doc(alias = "NSColorPanelWheelModeMask")]
66 const WheelModeMask = 0x00000040;
67 #[doc(alias = "NSColorPanelCrayonModeMask")]
68 const CrayonModeMask = 0x00000080;
69 #[doc(alias = "NSColorPanelAllModesMask")]
70 const AllModesMask = 0x0000ffff;
71 }
72}
73
74unsafe impl Encode for NSColorPanelOptions {
75 const ENCODING: Encoding = NSUInteger::ENCODING;
76}
77
78unsafe impl RefEncode for NSColorPanelOptions {
79 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
80}
81
82extern_class!(
83 #[unsafe(super(NSPanel, NSWindow, NSResponder, NSObject))]
85 #[derive(Debug, PartialEq, Eq, Hash)]
86 #[cfg(all(feature = "NSPanel", feature = "NSResponder", feature = "NSWindow"))]
87 pub struct NSColorPanel;
88);
89
90#[cfg(all(
91 feature = "NSAccessibilityProtocols",
92 feature = "NSPanel",
93 feature = "NSResponder",
94 feature = "NSWindow"
95))]
96extern_conformance!(
97 unsafe impl NSAccessibility for NSColorPanel {}
98);
99
100#[cfg(all(
101 feature = "NSAccessibilityProtocols",
102 feature = "NSPanel",
103 feature = "NSResponder",
104 feature = "NSWindow"
105))]
106extern_conformance!(
107 unsafe impl NSAccessibilityElementProtocol for NSColorPanel {}
108);
109
110#[cfg(all(
111 feature = "NSAnimation",
112 feature = "NSPanel",
113 feature = "NSResponder",
114 feature = "NSWindow"
115))]
116extern_conformance!(
117 unsafe impl NSAnimatablePropertyContainer for NSColorPanel {}
118);
119
120#[cfg(all(
121 feature = "NSAppearance",
122 feature = "NSPanel",
123 feature = "NSResponder",
124 feature = "NSWindow"
125))]
126extern_conformance!(
127 unsafe impl NSAppearanceCustomization for NSColorPanel {}
128);
129
130#[cfg(all(feature = "NSPanel", feature = "NSResponder", feature = "NSWindow"))]
131extern_conformance!(
132 unsafe impl NSCoding for NSColorPanel {}
133);
134
135#[cfg(all(
136 feature = "NSMenu",
137 feature = "NSPanel",
138 feature = "NSResponder",
139 feature = "NSWindow"
140))]
141extern_conformance!(
142 unsafe impl NSMenuItemValidation for NSColorPanel {}
143);
144
145#[cfg(all(feature = "NSPanel", feature = "NSResponder", feature = "NSWindow"))]
146extern_conformance!(
147 unsafe impl NSObjectProtocol for NSColorPanel {}
148);
149
150#[cfg(all(
151 feature = "NSPanel",
152 feature = "NSResponder",
153 feature = "NSUserInterfaceItemIdentification",
154 feature = "NSWindow"
155))]
156extern_conformance!(
157 unsafe impl NSUserInterfaceItemIdentification for NSColorPanel {}
158);
159
160#[cfg(all(
161 feature = "NSPanel",
162 feature = "NSResponder",
163 feature = "NSUserInterfaceValidation",
164 feature = "NSWindow"
165))]
166extern_conformance!(
167 unsafe impl NSUserInterfaceValidations for NSColorPanel {}
168);
169
170#[cfg(all(feature = "NSPanel", feature = "NSResponder", feature = "NSWindow"))]
171impl NSColorPanel {
172 extern_methods!(
173 #[unsafe(method(sharedColorPanel))]
174 #[unsafe(method_family = none)]
175 pub unsafe fn sharedColorPanel(mtm: MainThreadMarker) -> Retained<NSColorPanel>;
176
177 #[unsafe(method(sharedColorPanelExists))]
178 #[unsafe(method_family = none)]
179 pub unsafe fn sharedColorPanelExists(mtm: MainThreadMarker) -> bool;
180
181 #[cfg(all(feature = "NSColor", feature = "NSEvent", feature = "NSView"))]
182 #[unsafe(method(dragColor:withEvent:fromView:))]
183 #[unsafe(method_family = none)]
184 pub unsafe fn dragColor_withEvent_fromView(
185 color: &NSColor,
186 event: &NSEvent,
187 source_view: &NSView,
188 ) -> bool;
189
190 #[unsafe(method(setPickerMask:))]
191 #[unsafe(method_family = none)]
192 pub unsafe fn setPickerMask(mask: NSColorPanelOptions, mtm: MainThreadMarker);
193
194 #[unsafe(method(setPickerMode:))]
195 #[unsafe(method_family = none)]
196 pub unsafe fn setPickerMode(mode: NSColorPanelMode, mtm: MainThreadMarker);
197
198 #[cfg(feature = "NSView")]
199 #[unsafe(method(accessoryView))]
200 #[unsafe(method_family = none)]
201 pub unsafe fn accessoryView(&self) -> Option<Retained<NSView>>;
202
203 #[cfg(feature = "NSView")]
204 #[unsafe(method(setAccessoryView:))]
206 #[unsafe(method_family = none)]
207 pub unsafe fn setAccessoryView(&self, accessory_view: Option<&NSView>);
208
209 #[unsafe(method(isContinuous))]
210 #[unsafe(method_family = none)]
211 pub unsafe fn isContinuous(&self) -> bool;
212
213 #[unsafe(method(setContinuous:))]
215 #[unsafe(method_family = none)]
216 pub unsafe fn setContinuous(&self, continuous: bool);
217
218 #[unsafe(method(showsAlpha))]
219 #[unsafe(method_family = none)]
220 pub unsafe fn showsAlpha(&self) -> bool;
221
222 #[unsafe(method(setShowsAlpha:))]
224 #[unsafe(method_family = none)]
225 pub unsafe fn setShowsAlpha(&self, shows_alpha: bool);
226
227 #[unsafe(method(mode))]
228 #[unsafe(method_family = none)]
229 pub unsafe fn mode(&self) -> NSColorPanelMode;
230
231 #[unsafe(method(setMode:))]
233 #[unsafe(method_family = none)]
234 pub unsafe fn setMode(&self, mode: NSColorPanelMode);
235
236 #[cfg(feature = "NSColor")]
237 #[unsafe(method(color))]
238 #[unsafe(method_family = none)]
239 pub unsafe fn color(&self) -> Retained<NSColor>;
240
241 #[cfg(feature = "NSColor")]
242 #[unsafe(method(setColor:))]
244 #[unsafe(method_family = none)]
245 pub unsafe fn setColor(&self, color: &NSColor);
246
247 #[cfg(feature = "objc2-core-foundation")]
248 #[unsafe(method(alpha))]
249 #[unsafe(method_family = none)]
250 pub unsafe fn alpha(&self) -> CGFloat;
251
252 #[unsafe(method(setAction:))]
253 #[unsafe(method_family = none)]
254 pub unsafe fn setAction(&self, selector: Option<Sel>);
255
256 #[unsafe(method(setTarget:))]
257 #[unsafe(method_family = none)]
258 pub unsafe fn setTarget(&self, target: Option<&AnyObject>);
259
260 #[cfg(feature = "NSColorList")]
261 #[unsafe(method(attachColorList:))]
262 #[unsafe(method_family = none)]
263 pub unsafe fn attachColorList(&self, color_list: &NSColorList);
264
265 #[cfg(feature = "NSColorList")]
266 #[unsafe(method(detachColorList:))]
267 #[unsafe(method_family = none)]
268 pub unsafe fn detachColorList(&self, color_list: &NSColorList);
269 );
270}
271
272#[cfg(all(feature = "NSPanel", feature = "NSResponder", feature = "NSWindow"))]
274impl NSColorPanel {
275 extern_methods!(
276 #[cfg(feature = "NSGraphics")]
277 #[unsafe(method(initWithContentRect:styleMask:backing:defer:))]
278 #[unsafe(method_family = init)]
279 pub unsafe fn initWithContentRect_styleMask_backing_defer(
280 this: Allocated<Self>,
281 content_rect: NSRect,
282 style: NSWindowStyleMask,
283 backing_store_type: NSBackingStoreType,
284 flag: bool,
285 ) -> Retained<Self>;
286
287 #[cfg(all(feature = "NSGraphics", feature = "NSScreen"))]
288 #[unsafe(method(initWithContentRect:styleMask:backing:defer:screen:))]
289 #[unsafe(method_family = init)]
290 pub unsafe fn initWithContentRect_styleMask_backing_defer_screen(
291 this: Allocated<Self>,
292 content_rect: NSRect,
293 style: NSWindowStyleMask,
294 backing_store_type: NSBackingStoreType,
295 flag: bool,
296 screen: Option<&NSScreen>,
297 ) -> Retained<Self>;
298
299 #[unsafe(method(initWithCoder:))]
300 #[unsafe(method_family = init)]
301 pub unsafe fn initWithCoder(this: Allocated<Self>, coder: &NSCoder) -> Retained<Self>;
302
303 #[cfg(feature = "NSViewController")]
304 #[unsafe(method(windowWithContentViewController:))]
306 #[unsafe(method_family = none)]
307 pub unsafe fn windowWithContentViewController(
308 content_view_controller: &NSViewController,
309 ) -> Retained<Self>;
310 );
311}
312
313#[cfg(all(feature = "NSPanel", feature = "NSResponder", feature = "NSWindow"))]
315impl NSColorPanel {
316 extern_methods!(
317 #[unsafe(method(init))]
318 #[unsafe(method_family = init)]
319 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
320 );
321}
322
323#[cfg(all(feature = "NSPanel", feature = "NSResponder", feature = "NSWindow"))]
325impl NSColorPanel {
326 extern_methods!(
327 #[unsafe(method(new))]
328 #[unsafe(method_family = new)]
329 pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
330 );
331}
332
333#[cfg(all(feature = "NSApplication", feature = "NSResponder"))]
335impl NSApplication {
336 extern_methods!(
337 #[unsafe(method(orderFrontColorPanel:))]
338 #[unsafe(method_family = none)]
339 pub unsafe fn orderFrontColorPanel(&self, sender: Option<&AnyObject>);
340 );
341}
342
343extern_protocol!(
344 pub unsafe trait NSColorChanging: NSObjectProtocol {
346 #[cfg(all(feature = "NSPanel", feature = "NSResponder", feature = "NSWindow"))]
347 #[unsafe(method(changeColor:))]
348 #[unsafe(method_family = none)]
349 unsafe fn changeColor(&self, sender: Option<&NSColorPanel>);
350 }
351);
352
353extern "C" {
354 pub static NSColorPanelColorDidChangeNotification: &'static NSNotificationName;
356}
357
358pub static NSNoModeColorPanel: NSColorPanelMode = NSColorPanelMode(NSColorPanelMode::None.0);
360
361pub static NSGrayModeColorPanel: NSColorPanelMode = NSColorPanelMode(NSColorPanelMode::Gray.0);
363
364pub static NSRGBModeColorPanel: NSColorPanelMode = NSColorPanelMode(NSColorPanelMode::RGB.0);
366
367pub static NSCMYKModeColorPanel: NSColorPanelMode = NSColorPanelMode(NSColorPanelMode::CMYK.0);
369
370pub static NSHSBModeColorPanel: NSColorPanelMode = NSColorPanelMode(NSColorPanelMode::HSB.0);
372
373pub static NSCustomPaletteModeColorPanel: NSColorPanelMode =
375 NSColorPanelMode(NSColorPanelMode::CustomPalette.0);
376
377pub static NSColorListModeColorPanel: NSColorPanelMode =
379 NSColorPanelMode(NSColorPanelMode::ColorList.0);
380
381pub static NSWheelModeColorPanel: NSColorPanelMode = NSColorPanelMode(NSColorPanelMode::Wheel.0);
383
384pub static NSCrayonModeColorPanel: NSColorPanelMode = NSColorPanelMode(NSColorPanelMode::Crayon.0);