2018-06-14 19:42:18 -04:00
|
|
|
#![allow(non_camel_case_types, non_snake_case, non_upper_case_globals)]
|
|
|
|
|
|
2015-06-05 16:38:21 +03:00
|
|
|
use std::ffi::CString;
|
2018-06-14 19:42:18 -04:00
|
|
|
use std::mem;
|
|
|
|
|
use std::os::raw::*;
|
2015-06-05 16:38:21 +03:00
|
|
|
|
2018-07-19 10:02:33 -06:00
|
|
|
use objc::runtime::Object;
|
2015-06-05 16:38:21 +03:00
|
|
|
|
|
|
|
|
pub type id = *mut Object;
|
|
|
|
|
pub const nil: id = 0 as id;
|
|
|
|
|
|
2018-06-14 19:42:18 -04:00
|
|
|
pub type CFStringRef = *const c_void;
|
2015-06-05 16:38:21 +03:00
|
|
|
pub type CFTimeInterval = f64;
|
|
|
|
|
pub type Boolean = u32;
|
|
|
|
|
|
|
|
|
|
pub const kCFRunLoopRunHandledSource: i32 = 4;
|
|
|
|
|
|
2018-06-14 19:42:18 -04:00
|
|
|
pub const UIViewAutoresizingFlexibleWidth: NSUInteger = 1 << 1;
|
|
|
|
|
pub const UIViewAutoresizingFlexibleHeight: NSUInteger = 1 << 4;
|
|
|
|
|
|
2015-06-05 16:38:21 +03:00
|
|
|
#[cfg(target_pointer_width = "32")]
|
|
|
|
|
pub type CGFloat = f32;
|
|
|
|
|
#[cfg(target_pointer_width = "64")]
|
|
|
|
|
pub type CGFloat = f64;
|
|
|
|
|
|
|
|
|
|
#[cfg(target_pointer_width = "32")]
|
|
|
|
|
pub type NSUInteger = u32;
|
|
|
|
|
#[cfg(target_pointer_width = "64")]
|
|
|
|
|
pub type NSUInteger = u64;
|
|
|
|
|
|
|
|
|
|
#[repr(C)]
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub struct CGPoint {
|
|
|
|
|
pub x: CGFloat,
|
|
|
|
|
pub y: CGFloat,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[repr(C)]
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub struct CGRect {
|
|
|
|
|
pub origin: CGPoint,
|
2018-06-14 19:42:18 -04:00
|
|
|
pub size: CGSize,
|
2015-06-05 16:38:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[repr(C)]
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub struct CGSize {
|
|
|
|
|
pub width: CGFloat,
|
2018-06-14 19:42:18 -04:00
|
|
|
pub height: CGFloat,
|
2015-06-05 16:38:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[link(name = "UIKit", kind = "framework")]
|
|
|
|
|
#[link(name = "CoreFoundation", kind = "framework")]
|
|
|
|
|
#[link(name = "GlKit", kind = "framework")]
|
|
|
|
|
extern {
|
|
|
|
|
pub static kCFRunLoopDefaultMode: CFStringRef;
|
|
|
|
|
|
|
|
|
|
// int UIApplicationMain ( int argc, char *argv[], NSString *principalClassName, NSString *delegateClassName );
|
2018-06-14 19:42:18 -04:00
|
|
|
pub fn UIApplicationMain(
|
|
|
|
|
argc: c_int,
|
|
|
|
|
argv: *const c_char,
|
|
|
|
|
principalClassName: id,
|
|
|
|
|
delegateClassName: id,
|
|
|
|
|
) -> c_int;
|
2015-06-05 16:38:21 +03:00
|
|
|
|
|
|
|
|
// SInt32 CFRunLoopRunInMode ( CFStringRef mode, CFTimeInterval seconds, Boolean returnAfterSourceHandled );
|
2018-06-14 19:42:18 -04:00
|
|
|
pub fn CFRunLoopRunInMode(
|
|
|
|
|
mode: CFStringRef,
|
|
|
|
|
seconds: CFTimeInterval,
|
|
|
|
|
returnAfterSourceHandled: Boolean,
|
|
|
|
|
) -> i32;
|
2015-06-05 16:38:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extern {
|
2018-06-14 19:42:18 -04:00
|
|
|
pub fn setjmp(env: *mut c_void) -> c_int;
|
|
|
|
|
pub fn longjmp(env: *mut c_void, val: c_int);
|
2015-06-05 16:38:21 +03:00
|
|
|
}
|
|
|
|
|
|
2017-07-01 16:47:53 +10:00
|
|
|
pub trait NSString: Sized {
|
2015-06-05 16:38:21 +03:00
|
|
|
unsafe fn alloc(_: Self) -> id {
|
2018-07-19 10:02:33 -06:00
|
|
|
msg_send![class!(NSString), alloc]
|
2015-06-05 16:38:21 +03:00
|
|
|
}
|
|
|
|
|
|
2018-06-14 19:42:18 -04:00
|
|
|
unsafe fn initWithUTF8String_(self, c_string: *const c_char) -> id;
|
2015-06-05 16:38:21 +03:00
|
|
|
unsafe fn stringByAppendingString_(self, other: id) -> id;
|
|
|
|
|
unsafe fn init_str(self, string: &str) -> Self;
|
2018-06-14 19:42:18 -04:00
|
|
|
unsafe fn UTF8String(self) -> *const c_char;
|
2015-06-05 16:38:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl NSString for id {
|
2018-06-14 19:42:18 -04:00
|
|
|
unsafe fn initWithUTF8String_(self, c_string: *const c_char) -> id {
|
2015-06-05 16:38:21 +03:00
|
|
|
msg_send![self, initWithUTF8String:c_string as id]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsafe fn stringByAppendingString_(self, other: id) -> id {
|
|
|
|
|
msg_send![self, stringByAppendingString:other]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsafe fn init_str(self, string: &str) -> id {
|
|
|
|
|
let cstring = CString::new(string).unwrap();
|
|
|
|
|
self.initWithUTF8String_(cstring.as_ptr())
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-14 19:42:18 -04:00
|
|
|
unsafe fn UTF8String(self) -> *const c_char {
|
2015-06-05 16:38:21 +03:00
|
|
|
msg_send![self, UTF8String]
|
|
|
|
|
}
|
|
|
|
|
}
|