use std::ffi::c_void;
use std::num::NonZeroIsize;
use std::ptr;
use objc2::foundation::{NSObject, NSPoint, NSRect};
use objc2::rc::{Id, Shared};
use objc2::runtime::Object;
use objc2::{extern_class, extern_methods, msg_send_id, ClassType};
use super::{NSCursor, NSResponder, NSTextInputContext, NSWindow};
extern_class!(
#[derive(Debug, PartialEq, Eq, Hash)]
pub(crate) struct NSView;
unsafe impl ClassType for NSView {
#[inherits(NSObject)]
type Super = NSResponder;
}
);
extern_methods!(
unsafe impl NSView {
#[sel(frame)]
pub fn frame(&self) -> NSRect;
#[sel(bounds)]
pub fn bounds(&self) -> NSRect;
pub fn inputContext(
&self,
) -> Option<Id<NSTextInputContext, Shared>> {
unsafe { msg_send_id![self, inputContext] }
}
#[sel(visibleRect)]
pub fn visibleRect(&self) -> NSRect;
#[sel(hasMarkedText)]
pub fn hasMarkedText(&self) -> bool;
#[sel(convertPoint:fromView:)]
pub fn convertPoint_fromView(&self, point: NSPoint, view: Option<&NSView>) -> NSPoint;
pub fn window(&self) -> Option<Id<NSWindow, Shared>> {
unsafe { msg_send_id![self, window] }
}
}
unsafe impl NSView {
#[sel(setWantsBestResolutionOpenGLSurface:)]
pub fn setWantsBestResolutionOpenGLSurface(&self, value: bool);
#[sel(setWantsLayer:)]
pub fn setWantsLayer(&self, wants_layer: bool);
#[sel(setPostsFrameChangedNotifications:)]
pub fn setPostsFrameChangedNotifications(&mut self, value: bool);
#[sel(removeTrackingRect:)]
pub fn removeTrackingRect(&self, tag: NSTrackingRectTag);
#[sel(addTrackingRect:owner:userData:assumeInside:)]
unsafe fn inner_addTrackingRect(
&self,
rect: NSRect,
owner: &Object,
user_data: *mut c_void,
assume_inside: bool,
) -> Option<NSTrackingRectTag>;
pub fn add_tracking_rect(&self, rect: NSRect, assume_inside: bool) -> NSTrackingRectTag {
unsafe { self.inner_addTrackingRect(rect, self, ptr::null_mut(), assume_inside) }
.expect("failed creating tracking rect")
}
#[sel(addCursorRect:cursor:)]
pub fn addCursorRect(&self, rect: NSRect, cursor: &NSCursor);
#[sel(setHidden:)]
pub fn setHidden(&self, hidden: bool);
}
);
pub type NSTrackingRectTag = NonZeroIsize;