2016-01-17 10:12:21 +11:00
|
|
|
#![cfg(target_os = "macos")]
|
|
|
|
|
2016-04-29 09:30:44 +10:00
|
|
|
use std::convert::From;
|
2016-01-17 10:12:21 +11:00
|
|
|
use std::os::raw::c_void;
|
2016-04-29 09:30:44 +10:00
|
|
|
use cocoa::appkit::NSApplicationActivationPolicy;
|
|
|
|
use {Window, WindowBuilder};
|
2016-01-17 10:12:21 +11:00
|
|
|
|
|
|
|
/// Additional methods on `Window` that are specific to MacOS.
|
|
|
|
pub trait WindowExt {
|
|
|
|
/// Returns a pointer to the cocoa `NSWindow` that is used by this window.
|
|
|
|
///
|
2016-10-07 03:58:15 +11:00
|
|
|
/// The pointer will become invalid when the `Window` is destroyed.
|
2016-01-17 10:12:21 +11:00
|
|
|
fn get_nswindow(&self) -> *mut c_void;
|
|
|
|
|
2016-10-07 03:58:15 +11:00
|
|
|
/// Returns a pointer to the cocoa `NSView` that is used by this window.
|
|
|
|
///
|
|
|
|
/// The pointer will become invalid when the `Window` is destroyed.
|
|
|
|
fn get_nsview(&self) -> *mut c_void;
|
2016-01-17 10:12:21 +11:00
|
|
|
}
|
2016-04-29 09:30:44 +10:00
|
|
|
|
2016-10-08 18:18:00 +11:00
|
|
|
impl WindowExt for Window {
|
|
|
|
#[inline]
|
|
|
|
fn get_nswindow(&self) -> *mut c_void {
|
|
|
|
self.window.get_nswindow()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn get_nsview(&self) -> *mut c_void {
|
|
|
|
self.window.get_nsview()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-29 09:30:44 +10:00
|
|
|
/// Corresponds to `NSApplicationActivationPolicy`.
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
|
|
|
pub enum ActivationPolicy {
|
|
|
|
/// Corresponds to `NSApplicationActivationPolicyRegular`.
|
|
|
|
Regular,
|
|
|
|
/// Corresponds to `NSApplicationActivationPolicyAccessory`.
|
|
|
|
Accessory,
|
|
|
|
/// Corresponds to `NSApplicationActivationPolicyProhibited`.
|
|
|
|
Prohibited,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for ActivationPolicy {
|
|
|
|
fn default() -> Self {
|
|
|
|
ActivationPolicy::Regular
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<ActivationPolicy> for NSApplicationActivationPolicy {
|
|
|
|
fn from(activation_policy: ActivationPolicy) -> Self {
|
|
|
|
match activation_policy {
|
|
|
|
ActivationPolicy::Regular =>
|
|
|
|
NSApplicationActivationPolicy::NSApplicationActivationPolicyRegular,
|
|
|
|
ActivationPolicy::Accessory =>
|
|
|
|
NSApplicationActivationPolicy::NSApplicationActivationPolicyAccessory,
|
|
|
|
ActivationPolicy::Prohibited =>
|
|
|
|
NSApplicationActivationPolicy::NSApplicationActivationPolicyProhibited,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Additional methods on `WindowBuilder` that are specific to MacOS.
|
2016-09-20 04:05:48 +10:00
|
|
|
pub trait WindowBuilderExt {
|
|
|
|
fn with_activation_policy(mut self, activation_policy: ActivationPolicy) -> WindowBuilder;
|
2016-04-29 09:30:44 +10:00
|
|
|
}
|
|
|
|
|
2016-09-20 04:05:48 +10:00
|
|
|
impl WindowBuilderExt for WindowBuilder {
|
2016-04-29 09:30:44 +10:00
|
|
|
/// Sets the activation policy for the window being built
|
|
|
|
#[inline]
|
2016-09-20 04:05:48 +10:00
|
|
|
fn with_activation_policy(mut self, activation_policy: ActivationPolicy) -> WindowBuilder {
|
2016-04-29 09:30:44 +10:00
|
|
|
self.platform_specific.activation_policy = activation_policy;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|