rust_macios/appkit/
ns_status_bar_button.rs

1#![allow(trivial_casts)]
2
3use objc::{msg_send, sel, sel_impl};
4
5use crate::{object, objective_c_runtime::traits::PNSObject, utils::to_bool};
6
7use super::{interface_impl, ActionHandler, INSButton, INSControl, INSResponder, INSView};
8
9object! {
10    /// The appearance and behavior of an item in the systemwide menu bar.
11    unsafe pub struct NSStatusBarButton;
12}
13
14/// This is an action handler for `NSStatusBarButton`
15pub static mut NSSTATUS_BAR_BUTTON_HANDLER: Option<ActionHandler> = None;
16
17impl NSStatusBarButton {
18    /// Sets the default action-message selector associated with the control.
19    ///
20    /// # Arguments
21    ///
22    /// * `action` - The new action-message.
23    pub fn set_action<F: Fn() + Send + Sync + 'static>(&mut self, action: F) {
24        let this = self.m_self();
25        let handler = ActionHandler::new(unsafe { &*this }, action);
26        unsafe {
27            NSSTATUS_BAR_BUTTON_HANDLER = Some(handler);
28        }
29    }
30}
31
32impl INSResponder for NSStatusBarButton {}
33
34impl INSView for NSStatusBarButton {}
35
36impl INSControl for NSStatusBarButton {}
37
38impl INSButton for NSStatusBarButton {}
39
40#[interface_impl(NSButton)]
41impl NSStatusBarButton {
42    ///
43    #[property]
44    pub fn appears_disabled(&self) -> bool {
45        unsafe { to_bool(msg_send![self.m_self(), appearsDisabled]) }
46    }
47}