├── .gitignore ├── .travis.yml ├── COPYRIGHT ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md ├── examples ├── hello_world.rs └── tab_view.rs ├── src ├── appkit.rs ├── base.rs ├── foundation.rs └── lib.rs └── tests └── foundation.rs /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | build 3 | /target 4 | /Cargo.lock 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | os: osx 2 | 3 | language: rust 4 | 5 | notifications: 6 | webhooks: http://build.servo.org:54856/travis 7 | -------------------------------------------------------------------------------- /COPYRIGHT: -------------------------------------------------------------------------------- 1 | Licensed under the Apache License, Version 2.0 or the MIT license 3 | , at your 4 | option. All files in the project carrying such notice may not be 5 | copied, modified, or distributed except according to those terms. 6 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | 2 | [package] 3 | name = "cocoa" 4 | description = "Bindings to Cocoa for OS X" 5 | homepage = "https://github.com/servo/cocoa-rs" 6 | repository = "https://github.com/servo/cocoa-rs" 7 | version = "0.14.0" 8 | authors = ["The Servo Project Developers"] 9 | license = "MIT / Apache-2.0" 10 | 11 | [lib] 12 | name = "cocoa" 13 | crate-type = ["rlib"] 14 | 15 | [dependencies] 16 | block = "0.1" 17 | bitflags = "1.0" 18 | libc = "0.2" 19 | core-graphics = "0.13" 20 | objc = "0.2" 21 | -------------------------------------------------------------------------------- /LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012-2013 Mozilla Foundation 2 | 3 | Permission is hereby granted, free of charge, to any 4 | person obtaining a copy of this software and associated 5 | documentation files (the "Software"), to deal in the 6 | Software without restriction, including without 7 | limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software 10 | is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice 14 | shall be included in all copies or substantial portions 15 | of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 18 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 19 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 21 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 24 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | DEALINGS IN THE SOFTWARE. 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Cocoa-rs 2 | -------- 3 | 4 | This repository has been merged into the [core-foundation](https://github.com/servo/core-foundation-rs/tree/master/cocoa) repository and is now outdated. 5 | -------------------------------------------------------------------------------- /examples/hello_world.rs: -------------------------------------------------------------------------------- 1 | extern crate cocoa; 2 | 3 | use cocoa::base::{selector, nil, NO}; 4 | use cocoa::foundation::{NSRect, NSPoint, NSSize, NSAutoreleasePool, NSProcessInfo, 5 | NSString}; 6 | use cocoa::appkit::{NSApp, NSApplication, NSApplicationActivationPolicyRegular, NSWindow, 7 | NSBackingStoreBuffered, NSMenu, NSMenuItem, NSWindowStyleMask, 8 | NSRunningApplication, NSApplicationActivateIgnoringOtherApps}; 9 | 10 | fn main() { 11 | unsafe { 12 | let _pool = NSAutoreleasePool::new(nil); 13 | 14 | let app = NSApp(); 15 | app.setActivationPolicy_(NSApplicationActivationPolicyRegular); 16 | 17 | // create Menu Bar 18 | let menubar = NSMenu::new(nil).autorelease(); 19 | let app_menu_item = NSMenuItem::new(nil).autorelease(); 20 | menubar.addItem_(app_menu_item); 21 | app.setMainMenu_(menubar); 22 | 23 | // create Application menu 24 | let app_menu = NSMenu::new(nil).autorelease(); 25 | let quit_prefix = NSString::alloc(nil).init_str("Quit "); 26 | let quit_title = 27 | quit_prefix.stringByAppendingString_(NSProcessInfo::processInfo(nil).processName()); 28 | let quit_action = selector("terminate:"); 29 | let quit_key = NSString::alloc(nil).init_str("q"); 30 | let quit_item = NSMenuItem::alloc(nil) 31 | .initWithTitle_action_keyEquivalent_(quit_title, quit_action, quit_key) 32 | .autorelease(); 33 | app_menu.addItem_(quit_item); 34 | app_menu_item.setSubmenu_(app_menu); 35 | 36 | // create Window 37 | let window = NSWindow::alloc(nil) 38 | .initWithContentRect_styleMask_backing_defer_(NSRect::new(NSPoint::new(0., 0.), 39 | NSSize::new(200., 200.)), 40 | NSWindowStyleMask::NSTitledWindowMask, 41 | NSBackingStoreBuffered, 42 | NO) 43 | .autorelease(); 44 | window.cascadeTopLeftFromPoint_(NSPoint::new(20., 20.)); 45 | window.center(); 46 | let title = NSString::alloc(nil).init_str("Hello World!"); 47 | window.setTitle_(title); 48 | window.makeKeyAndOrderFront_(nil); 49 | let current_app = NSRunningApplication::currentApplication(nil); 50 | current_app.activateWithOptions_(NSApplicationActivateIgnoringOtherApps); 51 | app.run(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /examples/tab_view.rs: -------------------------------------------------------------------------------- 1 | extern crate cocoa; 2 | 3 | use cocoa::base::{selector, id, nil, NO}; 4 | 5 | 6 | use cocoa::foundation::{NSRect, NSPoint, NSSize, NSAutoreleasePool, NSProcessInfo, 7 | NSString}; 8 | use cocoa::appkit::{NSApp, NSApplication, NSApplicationActivationPolicyRegular, NSWindow, 9 | NSMenu, NSMenuItem, NSTabView, NSWindowStyleMask, NSBackingStoreType, 10 | NSTabViewItem, NSRunningApplication, NSApplicationActivateIgnoringOtherApps}; 11 | 12 | 13 | fn main() { 14 | unsafe { 15 | 16 | // create a tab View 17 | let tab_view = NSTabView::new(nil) 18 | .initWithFrame_(NSRect::new(NSPoint::new(0., 0.), NSSize::new(200., 200.))); 19 | 20 | // create a tab view item 21 | let tab_view_item = NSTabViewItem::new(nil) 22 | .initWithIdentifier_(NSString::alloc(nil).init_str("TabView1")); 23 | 24 | tab_view_item.setLabel_(NSString::alloc(nil).init_str("Tab view item 1")); 25 | tab_view.addTabViewItem_(tab_view_item); 26 | 27 | // create a second tab view item 28 | let tab_view_item2 = NSTabViewItem::new(nil) 29 | .initWithIdentifier_(NSString::alloc(nil).init_str("TabView2")); 30 | 31 | tab_view_item2.setLabel_(NSString::alloc(nil).init_str("Tab view item 2")); 32 | tab_view.addTabViewItem_(tab_view_item2); 33 | 34 | // Create the app and set the content. 35 | let app = create_app(NSString::alloc(nil).init_str("Tab View"), tab_view); 36 | app.run(); 37 | } 38 | } 39 | 40 | unsafe fn create_app(title: id, content: id) -> id { 41 | let _pool = NSAutoreleasePool::new(nil); 42 | 43 | let app = NSApp(); 44 | app.setActivationPolicy_(NSApplicationActivationPolicyRegular); 45 | 46 | // create Menu Bar 47 | let menubar = NSMenu::new(nil).autorelease(); 48 | let app_menu_item = NSMenuItem::new(nil).autorelease(); 49 | menubar.addItem_(app_menu_item); 50 | app.setMainMenu_(menubar); 51 | 52 | // create Application menu 53 | let app_menu = NSMenu::new(nil).autorelease(); 54 | let quit_prefix = NSString::alloc(nil).init_str("Quit "); 55 | let quit_title = 56 | quit_prefix.stringByAppendingString_(NSProcessInfo::processInfo(nil).processName()); 57 | let quit_action = selector("terminate:"); 58 | let quit_key = NSString::alloc(nil).init_str("q"); 59 | let quit_item = NSMenuItem::alloc(nil) 60 | .initWithTitle_action_keyEquivalent_(quit_title, quit_action, quit_key) 61 | .autorelease(); 62 | app_menu.addItem_(quit_item); 63 | app_menu_item.setSubmenu_(app_menu); 64 | 65 | // create Window 66 | let window = NSWindow::alloc(nil).initWithContentRect_styleMask_backing_defer_( 67 | NSRect::new(NSPoint::new(0., 0.), NSSize::new(200., 200.)), 68 | NSWindowStyleMask::NSTitledWindowMask | 69 | NSWindowStyleMask::NSClosableWindowMask | 70 | NSWindowStyleMask::NSResizableWindowMask | 71 | NSWindowStyleMask::NSMiniaturizableWindowMask | 72 | NSWindowStyleMask::NSUnifiedTitleAndToolbarWindowMask, 73 | NSBackingStoreType::NSBackingStoreBuffered, 74 | NO 75 | ).autorelease(); 76 | window.cascadeTopLeftFromPoint_(NSPoint::new(20., 20.)); 77 | window.center(); 78 | 79 | window.setTitle_(title); 80 | window.makeKeyAndOrderFront_(nil); 81 | 82 | window.setContentView_(content); 83 | let current_app = NSRunningApplication::currentApplication(nil); 84 | current_app.activateWithOptions_(NSApplicationActivateIgnoringOtherApps); 85 | 86 | return app; 87 | } 88 | -------------------------------------------------------------------------------- /src/appkit.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Servo Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution. 3 | // 4 | // Licensed under the Apache License, Version 2.0 or the MIT license 6 | // , at your 7 | // option. This file may not be copied, modified, or distributed 8 | // except according to those terms. 9 | 10 | #![allow(non_upper_case_globals)] 11 | 12 | use base::{id, class, BOOL, SEL}; 13 | use block::Block; 14 | use foundation::{NSInteger, NSUInteger, NSTimeInterval, 15 | NSPoint, NSSize, NSRect, NSRectEdge}; 16 | use libc; 17 | 18 | pub use core_graphics::base::CGFloat; 19 | pub use core_graphics::geometry::CGPoint; 20 | 21 | pub use self::NSApplicationActivationPolicy::*; 22 | pub use self::NSApplicationActivationOptions::*; 23 | pub use self::NSBackingStoreType::*; 24 | pub use self::NSOpenGLPixelFormatAttribute::*; 25 | pub use self::NSOpenGLPFAOpenGLProfiles::*; 26 | pub use self::NSEventType::*; 27 | 28 | pub type CGLContextObj = *mut libc::c_void; 29 | 30 | pub type GLint = libc::int32_t; 31 | 32 | #[link(name = "AppKit", kind = "framework")] 33 | extern { 34 | pub static NSAppKitVersionNumber: f64; 35 | 36 | // Types for Standard Data - OS X v10.6 and later. (NSString *const) 37 | pub static NSPasteboardTypeString: id; 38 | pub static NSPasteboardTypePDF: id; 39 | pub static NSPasteboardTypeTIFF: id; 40 | pub static NSPasteboardTypePNG: id; 41 | pub static NSPasteboardTypeRTF: id; 42 | pub static NSPasteboardTypeRTFD: id; 43 | pub static NSPasteboardTypeHTML: id; 44 | pub static NSPasteboardTypeTabularText: id; 45 | pub static NSPasteboardTypeFont: id; 46 | pub static NSPasteboardTypeRuler: id; 47 | pub static NSPasteboardTypeColor: id; 48 | pub static NSPasteboardTypeSound: id; 49 | pub static NSPasteboardTypeMultipleTextSelection: id; 50 | pub static NSPasteboardTypeFindPanelSearchOptions: id; 51 | 52 | // Types for Standard Data - OS X v10.5 and earlier. (NSString *) 53 | pub static NSStringPboardType: id; 54 | pub static NSFilenamesPboardType: id; 55 | pub static NSPostScriptPboardType: id; 56 | pub static NSTIFFPboardType: id; 57 | pub static NSRTFPboardType: id; 58 | pub static NSTabularTextPboardType: id; 59 | pub static NSFontPboardType: id; 60 | pub static NSRulerPboardType: id; 61 | pub static NSFileContentsPboardType: id; 62 | pub static NSColorPboardType: id; 63 | pub static NSRTFDPboardType: id; 64 | pub static NSHTMLPboardType: id; 65 | pub static NSPICTPboardType: id; 66 | pub static NSURLPboardType: id; 67 | pub static NSPDFPboardType: id; 68 | pub static NSVCardPboardType: id; 69 | pub static NSFilesPromisePboardType: id; 70 | pub static NSMultipleTextSelectionPboardType: id; 71 | pub static NSSoundPboardType: id; 72 | 73 | // Names of provided pasteboards. (NSString *) 74 | pub static NSGeneralPboard: id; 75 | pub static NSFontPboard: id; 76 | pub static NSRulerPboard: id; 77 | pub static NSFindPboard: id; 78 | pub static NSDragPboard: id; 79 | 80 | // Pasteboard reading options - OS X v10.6 and later. (NSString *) 81 | pub static NSPasteboardURLReadingFileURLsOnlyKey: id; 82 | pub static NSPasteboardURLReadingContentsConformToTypesKey: id; 83 | 84 | // NSAppearance names. (NSString *) 85 | pub static NSAppearanceNameVibrantDark: id; 86 | pub static NSAppearanceNameVibrantLight: id; 87 | } 88 | 89 | pub const NSAppKitVersionNumber10_0: f64 = 577.0; 90 | pub const NSAppKitVersionNumber10_1: f64 = 620.0; 91 | pub const NSAppKitVersionNumber10_2: f64 = 663.0; 92 | pub const NSAppKitVersionNumber10_2_3: f64 = 663.6; 93 | pub const NSAppKitVersionNumber10_3: f64 = 743.0; 94 | pub const NSAppKitVersionNumber10_3_2: f64 = 743.14; 95 | pub const NSAppKitVersionNumber10_3_3: f64 = 743.2; 96 | pub const NSAppKitVersionNumber10_3_5: f64 = 743.24; 97 | pub const NSAppKitVersionNumber10_3_7: f64 = 743.33; 98 | pub const NSAppKitVersionNumber10_3_9: f64 = 743.36; 99 | pub const NSAppKitVersionNumber10_4: f64 = 824.0; 100 | pub const NSAppKitVersionNumber10_4_1: f64 = 824.1; 101 | pub const NSAppKitVersionNumber10_4_3: f64 = 824.23; 102 | pub const NSAppKitVersionNumber10_4_4: f64 = 824.33; 103 | pub const NSAppKitVersionNumber10_4_7: f64 = 824.41; 104 | pub const NSAppKitVersionNumber10_5: f64 = 949.0; 105 | pub const NSAppKitVersionNumber10_5_2: f64 = 949.27; 106 | pub const NSAppKitVersionNumber10_5_3: f64 = 949.33; 107 | pub const NSAppKitVersionNumber10_6: f64 = 1038.0; 108 | pub const NSAppKitVersionNumber10_7: f64 = 1138.0; 109 | pub const NSAppKitVersionNumber10_7_2: f64 = 1138.23; 110 | pub const NSAppKitVersionNumber10_7_3: f64 = 1138.32; 111 | pub const NSAppKitVersionNumber10_7_4: f64 = 1138.47; 112 | pub const NSAppKitVersionNumber10_8: f64 = 1187.0; 113 | pub const NSAppKitVersionNumber10_9: f64 = 1265.0; 114 | 115 | pub unsafe fn NSApp() -> id { 116 | msg_send![class("NSApplication"), sharedApplication] 117 | } 118 | 119 | #[repr(i64)] 120 | #[derive(Clone, Copy, Debug, PartialEq)] 121 | pub enum NSApplicationActivationPolicy { 122 | NSApplicationActivationPolicyRegular = 0, 123 | NSApplicationActivationPolicyAccessory = 1, 124 | NSApplicationActivationPolicyProhibited = 2, 125 | NSApplicationActivationPolicyERROR = -1 126 | } 127 | 128 | #[repr(u64)] 129 | #[derive(Clone, Copy, Debug, PartialEq)] 130 | pub enum NSApplicationActivationOptions { 131 | NSApplicationActivateAllWindows = 1 << 0, 132 | NSApplicationActivateIgnoringOtherApps = 1 << 1 133 | } 134 | 135 | #[repr(u64)] 136 | #[derive(Clone, Copy, Debug, PartialEq)] 137 | pub enum NSApplicationTerminateReply { 138 | NSTerminateCancel = 0, 139 | NSTerminateNow = 1, 140 | NSTerminateLater = 2, 141 | } 142 | 143 | bitflags! { 144 | pub struct NSWindowStyleMask: NSUInteger { 145 | const NSBorderlessWindowMask = 0; 146 | const NSTitledWindowMask = 1 << 0; 147 | const NSClosableWindowMask = 1 << 1; 148 | const NSMiniaturizableWindowMask = 1 << 2; 149 | const NSResizableWindowMask = 1 << 3; 150 | 151 | const NSTexturedBackgroundWindowMask = 1 << 8; 152 | 153 | const NSUnifiedTitleAndToolbarWindowMask = 1 << 12; 154 | 155 | const NSFullScreenWindowMask = 1 << 14; 156 | 157 | const NSFullSizeContentViewWindowMask = 1 << 15; 158 | } 159 | } 160 | 161 | #[repr(u64)] 162 | #[derive(Clone, Copy, Debug, PartialEq)] 163 | pub enum NSWindowTitleVisibility { 164 | NSWindowTitleVisible = 0, 165 | NSWindowTitleHidden = 1 166 | } 167 | 168 | #[repr(u64)] 169 | #[derive(Clone, Copy, Debug, PartialEq)] 170 | pub enum NSBackingStoreType { 171 | NSBackingStoreRetained = 0, 172 | NSBackingStoreNonretained = 1, 173 | NSBackingStoreBuffered = 2 174 | } 175 | 176 | bitflags! { 177 | pub struct NSWindowOrderingMode: NSInteger { 178 | const NSWindowAbove = 1; 179 | const NSWindowBelow = -1; 180 | const NSWindowOut = 0; 181 | } 182 | } 183 | 184 | bitflags! { 185 | pub struct NSAlignmentOptions: libc::c_ulonglong { 186 | const NSAlignMinXInward = 1 << 0; 187 | const NSAlignMinYInward = 1 << 1; 188 | const NSAlignMaxXInward = 1 << 2; 189 | const NSAlignMaxYInward = 1 << 3; 190 | const NSAlignWidthInward = 1 << 4; 191 | const NSAlignHeightInward = 1 << 5; 192 | const NSAlignMinXOutward = 1 << 8; 193 | const NSAlignMinYOutward = 1 << 9; 194 | const NSAlignMaxXOutward = 1 << 10; 195 | const NSAlignMaxYOutward = 1 << 11; 196 | const NSAlignWidthOutward = 1 << 12; 197 | const NSAlignHeightOutward = 1 << 13; 198 | const NSAlignMinXNearest = 1 << 16; 199 | const NSAlignMinYNearest = 1 << 17; 200 | const NSAlignMaxXNearest = 1 << 18; 201 | const NSAlignMaxYNearest = 1 << 19; 202 | const NSAlignWidthNearest = 1 << 20; 203 | const NSAlignHeightNearest = 1 << 21; 204 | const NSAlignRectFlipped = 1 << 63; 205 | const NSAlignAllEdgesInward = NSAlignmentOptions::NSAlignMinXInward.bits 206 | | NSAlignmentOptions::NSAlignMaxXInward.bits 207 | | NSAlignmentOptions::NSAlignMinYInward.bits 208 | | NSAlignmentOptions::NSAlignMaxYInward.bits; 209 | const NSAlignAllEdgesOutward = NSAlignmentOptions::NSAlignMinXOutward.bits 210 | | NSAlignmentOptions::NSAlignMaxXOutward.bits 211 | | NSAlignmentOptions::NSAlignMinYOutward.bits 212 | | NSAlignmentOptions::NSAlignMaxYOutward.bits; 213 | const NSAlignAllEdgesNearest = NSAlignmentOptions::NSAlignMinXNearest.bits 214 | | NSAlignmentOptions::NSAlignMaxXNearest.bits 215 | | NSAlignmentOptions::NSAlignMinYNearest.bits 216 | | NSAlignmentOptions::NSAlignMaxYNearest.bits; 217 | } 218 | } 219 | 220 | #[repr(u64)] 221 | #[derive(Clone, Copy, Debug, PartialEq)] 222 | pub enum NSOpenGLPixelFormatAttribute { 223 | NSOpenGLPFAAllRenderers = 1, 224 | NSOpenGLPFATripleBuffer = 3, 225 | NSOpenGLPFADoubleBuffer = 5, 226 | NSOpenGLPFAStereo = 6, 227 | NSOpenGLPFAAuxBuffers = 7, 228 | NSOpenGLPFAColorSize = 8, 229 | NSOpenGLPFAAlphaSize = 11, 230 | NSOpenGLPFADepthSize = 12, 231 | NSOpenGLPFAStencilSize = 13, 232 | NSOpenGLPFAAccumSize = 14, 233 | NSOpenGLPFAMinimumPolicy = 51, 234 | NSOpenGLPFAMaximumPolicy = 52, 235 | NSOpenGLPFAOffScreen = 53, 236 | NSOpenGLPFAFullScreen = 54, 237 | NSOpenGLPFASampleBuffers = 55, 238 | NSOpenGLPFASamples = 56, 239 | NSOpenGLPFAAuxDepthStencil = 57, 240 | NSOpenGLPFAColorFloat = 58, 241 | NSOpenGLPFAMultisample = 59, 242 | NSOpenGLPFASupersample = 60, 243 | NSOpenGLPFASampleAlpha = 61, 244 | NSOpenGLPFARendererID = 70, 245 | NSOpenGLPFASingleRenderer = 71, 246 | NSOpenGLPFANoRecovery = 72, 247 | NSOpenGLPFAAccelerated = 73, 248 | NSOpenGLPFAClosestPolicy = 74, 249 | NSOpenGLPFARobust = 75, 250 | NSOpenGLPFABackingStore = 76, 251 | NSOpenGLPFAMPSafe = 78, 252 | NSOpenGLPFAWindow = 80, 253 | NSOpenGLPFAMultiScreen = 81, 254 | NSOpenGLPFACompliant = 83, 255 | NSOpenGLPFAScreenMask = 84, 256 | NSOpenGLPFAPixelBuffer = 90, 257 | NSOpenGLPFARemotePixelBuffer = 91, 258 | NSOpenGLPFAAllowOfflineRenderers = 96, 259 | NSOpenGLPFAAcceleratedCompute = 97, 260 | NSOpenGLPFAOpenGLProfile = 99, 261 | NSOpenGLPFAVirtualScreenCount = 128, 262 | } 263 | 264 | #[repr(u64)] 265 | #[allow(non_camel_case_types)] 266 | #[derive(Clone, Copy, Debug, PartialEq)] 267 | pub enum NSOpenGLPFAOpenGLProfiles { 268 | NSOpenGLProfileVersionLegacy = 0x1000, 269 | NSOpenGLProfileVersion3_2Core = 0x3200, 270 | NSOpenGLProfileVersion4_1Core = 0x4100, 271 | } 272 | 273 | #[repr(u64)] 274 | #[derive(Clone, Copy, Debug, PartialEq)] 275 | pub enum NSOpenGLContextParameter { 276 | NSOpenGLCPSwapInterval = 222, 277 | NSOpenGLCPSurfaceOrder = 235, 278 | NSOpenGLCPSurfaceOpacity = 236, 279 | NSOpenGLCPSurfaceBackingSize = 304, 280 | NSOpenGLCPReclaimResources = 308, 281 | NSOpenGLCPCurrentRendererID = 309, 282 | NSOpenGLCPGPUVertexProcessing = 310, 283 | NSOpenGLCPGPUFragmentProcessing = 311, 284 | NSOpenGLCPHasDrawable = 314, 285 | NSOpenGLCPMPSwapsInFlight = 315, 286 | } 287 | 288 | #[repr(u64)] 289 | #[derive(Clone, Copy, Debug, PartialEq)] 290 | pub enum NSWindowButton { 291 | NSWindowCloseButton = 0, 292 | NSWindowMiniaturizeButton = 1, 293 | NSWindowZoomButton = 2, 294 | NSWindowToolbarButton = 3, 295 | NSWindowDocumentIconButton = 4, 296 | NSWindowDocumentVersionsButton = 6, 297 | NSWindowFullScreenButton = 7, 298 | } 299 | 300 | #[repr(u64)] 301 | #[derive(Clone, Copy, Debug, PartialEq)] 302 | pub enum NSBezelStyle { 303 | NSRoundedBezelStyle = 1, 304 | NSRegularSquareBezelStyle = 2, 305 | NSDisclosureBezelStyle = 5, 306 | NSShadowlessSquareBezelStyle = 6, 307 | NSCircularBezelStyle = 7, 308 | NSTexturedSquareBezelStyle = 8, 309 | NSHelpButtonBezelStyle = 9, 310 | NSSmallSquareBezelStyle = 10, 311 | NSTexturedRoundedBezelStyle = 11, 312 | NSRoundRectBezelStyle = 12, 313 | NSRecessedBezelStyle = 13, 314 | NSRoundedDisclosureBezelStyle = 14, 315 | } 316 | 317 | #[repr(u64)] 318 | #[derive(Clone, Copy, Debug, PartialEq)] 319 | pub enum NSRequestUserAttentionType { 320 | NSCriticalRequest = 0, 321 | NSInformationalRequest = 10, 322 | } 323 | 324 | pub static NSMainMenuWindowLevel: libc::int32_t = 24; 325 | 326 | pub trait NSApplication: Sized { 327 | unsafe fn sharedApplication(_: Self) -> id { 328 | msg_send![class("NSApplication"), sharedApplication] 329 | } 330 | 331 | unsafe fn mainMenu(self) -> id; 332 | unsafe fn setActivationPolicy_(self, policy: NSApplicationActivationPolicy) -> BOOL; 333 | unsafe fn setMainMenu_(self, menu: id); 334 | unsafe fn setServicesMenu_(self, menu: id); 335 | unsafe fn setWindowsMenu_(self, menu: id); 336 | unsafe fn activateIgnoringOtherApps_(self, ignore: BOOL); 337 | unsafe fn run(self); 338 | unsafe fn finishLaunching(self); 339 | unsafe fn nextEventMatchingMask_untilDate_inMode_dequeue_(self, 340 | mask: NSUInteger, 341 | expiration: id, 342 | in_mode: id, 343 | dequeue: BOOL) -> id; 344 | unsafe fn sendEvent_(self, an_event: id); 345 | unsafe fn postEvent_atStart_(self, anEvent: id, flag: BOOL); 346 | unsafe fn stop_(self, sender: id); 347 | unsafe fn setApplicationIconImage_(self, image: id); 348 | unsafe fn requestUserAttention_(self, requestType: NSRequestUserAttentionType); 349 | } 350 | 351 | impl NSApplication for id { 352 | unsafe fn mainMenu(self) -> id { 353 | msg_send![self, mainMenu] 354 | } 355 | 356 | unsafe fn setActivationPolicy_(self, policy: NSApplicationActivationPolicy) -> BOOL { 357 | msg_send![self, setActivationPolicy:policy as NSInteger] 358 | } 359 | 360 | unsafe fn setMainMenu_(self, menu: id) { 361 | msg_send![self, setMainMenu:menu] 362 | } 363 | 364 | unsafe fn setServicesMenu_(self, menu: id) { 365 | msg_send![self, setServicesMenu:menu] 366 | } 367 | 368 | unsafe fn setWindowsMenu_(self, menu: id) { 369 | msg_send![self, setWindowsMenu:menu] 370 | } 371 | 372 | unsafe fn activateIgnoringOtherApps_(self, ignore: BOOL) { 373 | msg_send![self, activateIgnoringOtherApps:ignore] 374 | } 375 | 376 | unsafe fn run(self) { 377 | msg_send![self, run] 378 | } 379 | 380 | unsafe fn finishLaunching(self) { 381 | msg_send![self, finishLaunching] 382 | } 383 | 384 | unsafe fn nextEventMatchingMask_untilDate_inMode_dequeue_(self, 385 | mask: NSUInteger, 386 | expiration: id, 387 | in_mode: id, 388 | dequeue: BOOL) -> id { 389 | msg_send![self, nextEventMatchingMask:mask 390 | untilDate:expiration 391 | inMode:in_mode 392 | dequeue:dequeue] 393 | } 394 | 395 | unsafe fn sendEvent_(self, an_event: id) { 396 | msg_send![self, sendEvent:an_event] 397 | } 398 | 399 | unsafe fn postEvent_atStart_(self, anEvent: id, flag: BOOL) { 400 | msg_send![self, postEvent:anEvent atStart:flag] 401 | } 402 | 403 | unsafe fn stop_(self, sender: id) { 404 | msg_send![self, stop:sender] 405 | } 406 | 407 | unsafe fn setApplicationIconImage_(self, icon: id) { 408 | msg_send![self, setApplicationIconImage:icon] 409 | } 410 | 411 | unsafe fn requestUserAttention_(self, requestType: NSRequestUserAttentionType) { 412 | msg_send![self, requestUserAttention:requestType] 413 | } 414 | } 415 | 416 | pub trait NSRunningApplication: Sized { 417 | unsafe fn currentApplication(_: Self) -> id { 418 | msg_send![class("NSRunningApplication"), currentApplication] 419 | } 420 | unsafe fn activateWithOptions_(self, options: NSApplicationActivationOptions) -> BOOL; 421 | } 422 | 423 | impl NSRunningApplication for id { 424 | unsafe fn activateWithOptions_(self, options: NSApplicationActivationOptions) -> BOOL { 425 | msg_send![self, activateWithOptions:options as NSUInteger] 426 | } 427 | } 428 | 429 | pub trait NSPasteboard: Sized { 430 | unsafe fn generalPasteboard(_: Self) -> id { 431 | msg_send![class("NSPasteboard"), generalPasteboard] 432 | } 433 | 434 | unsafe fn pasteboardByFilteringData_ofType(_: Self, data: id, _type: id) -> id { 435 | msg_send![class("NSPasteboard"), pasteboardByFilteringData:data ofType:_type] 436 | } 437 | 438 | unsafe fn pasteboardByFilteringFile(_: Self, file: id) -> id { 439 | msg_send![class("NSPasteboard"), pasteboardByFilteringFile:file] 440 | } 441 | 442 | unsafe fn pasteboardByFilteringTypesInPasteboard(_: Self, pboard: id) -> id { 443 | msg_send![class("NSPasteboard"), pasteboardByFilteringTypesInPasteboard:pboard] 444 | } 445 | 446 | unsafe fn pasteboardWithName(_: Self, name: id) -> id { 447 | msg_send![class("NSPasteboard"), pasteboardWithName:name] 448 | } 449 | 450 | unsafe fn pasteboardWithUniqueName(_: Self) -> id { 451 | msg_send![class("NSPasteboard"), pasteboardWithUniqueName] 452 | } 453 | 454 | unsafe fn releaseGlobally(self); 455 | 456 | unsafe fn clearContents(self) -> NSInteger; 457 | unsafe fn writeObjects(self, objects: id) -> BOOL; 458 | unsafe fn sendData_forType(self, data: id, dataType: id) -> BOOL; 459 | unsafe fn setPropertyList_forType(self, plist: id, dataType: id) -> BOOL; 460 | unsafe fn setString_forType(self, string: id, dataType: id) -> BOOL; 461 | 462 | unsafe fn readObjectsForClasses_options(self, classArray: id, options: id) -> id; 463 | unsafe fn pasteboardItems(self) -> id; 464 | unsafe fn indexOfPasteboardItem(self, pasteboardItem: id) -> NSInteger; 465 | unsafe fn dataForType(self, dataType: id) -> id; 466 | unsafe fn propertyListForType(self, dataType: id) -> id; 467 | unsafe fn stringForType(self, dataType: id) -> id; 468 | 469 | unsafe fn availableTypeFromArray(self, types: id) -> id; 470 | unsafe fn canReadItemWithDataConformingToTypes(self, types: id) -> BOOL; 471 | unsafe fn canReadObjectForClasses_options(self, classArray: id, options: id) -> BOOL; 472 | unsafe fn types(self) -> id; 473 | unsafe fn typesFilterableTo(_: Self, _type: id) -> id { 474 | msg_send![class("NSPasteboard"), typesFilterableTo:_type] 475 | } 476 | 477 | unsafe fn name(self) -> id; 478 | unsafe fn changeCount(self) -> NSInteger; 479 | 480 | unsafe fn declareTypes_owner(self, newTypes: id, newOwner: id) -> NSInteger; 481 | unsafe fn addTypes_owner(self, newTypes: id, newOwner: id) -> NSInteger; 482 | unsafe fn writeFileContents(self, filename: id) -> BOOL; 483 | unsafe fn writeFileWrapper(self, wrapper: id) -> BOOL; 484 | 485 | unsafe fn readFileContentsType_toFile(self, _type: id, filename: id) -> id; 486 | unsafe fn readFileWrapper(self) -> id; 487 | } 488 | 489 | impl NSPasteboard for id { 490 | unsafe fn releaseGlobally(self) { 491 | msg_send![self, releaseGlobally]; 492 | } 493 | 494 | unsafe fn clearContents(self) -> NSInteger { 495 | msg_send![self, clearContents] 496 | } 497 | 498 | unsafe fn writeObjects(self, objects: id) -> BOOL { 499 | msg_send![self, writeObjects:objects] 500 | } 501 | 502 | unsafe fn sendData_forType(self, data: id, dataType: id) -> BOOL { 503 | msg_send![self, sendData:data forType:dataType] 504 | } 505 | 506 | unsafe fn setPropertyList_forType(self, plist: id, dataType: id) -> BOOL { 507 | msg_send![self, setPropertyList:plist forType:dataType] 508 | } 509 | 510 | unsafe fn setString_forType(self, string: id, dataType: id) -> BOOL { 511 | msg_send![self, setString:string forType:dataType] 512 | } 513 | 514 | unsafe fn readObjectsForClasses_options(self, classArray: id, options: id) -> id { 515 | msg_send![self, readObjectsForClasses:classArray options:options] 516 | } 517 | 518 | unsafe fn pasteboardItems(self) -> id { 519 | msg_send![self, pasteboardItems] 520 | } 521 | 522 | unsafe fn indexOfPasteboardItem(self, pasteboardItem: id) -> NSInteger { 523 | msg_send![self, indexOfPasteboardItem:pasteboardItem] 524 | } 525 | 526 | unsafe fn dataForType(self, dataType: id) -> id { 527 | msg_send![self, dataForType:dataType] 528 | } 529 | 530 | unsafe fn propertyListForType(self, dataType: id) -> id { 531 | msg_send![self, propertyListForType:dataType] 532 | } 533 | 534 | unsafe fn stringForType(self, dataType: id) -> id { 535 | msg_send![self, stringForType:dataType] 536 | } 537 | 538 | unsafe fn availableTypeFromArray(self, types: id) -> id { 539 | msg_send![self, availableTypeFromArray:types] 540 | } 541 | 542 | unsafe fn canReadItemWithDataConformingToTypes(self, types: id) -> BOOL { 543 | msg_send![self, canReadItemWithDataConformingToTypes:types] 544 | } 545 | 546 | unsafe fn canReadObjectForClasses_options(self, classArray: id, options: id) -> BOOL { 547 | msg_send![self, canReadObjectForClasses:classArray options:options] 548 | } 549 | 550 | unsafe fn types(self) -> id { 551 | msg_send![self, types] 552 | } 553 | 554 | unsafe fn name(self) -> id { 555 | msg_send![self, name] 556 | } 557 | 558 | unsafe fn changeCount(self) -> NSInteger { 559 | msg_send![self, changeCount] 560 | } 561 | 562 | unsafe fn declareTypes_owner(self, newTypes: id, newOwner: id) -> NSInteger { 563 | msg_send![self, declareTypes:newTypes owner:newOwner] 564 | } 565 | 566 | unsafe fn addTypes_owner(self, newTypes: id, newOwner: id) -> NSInteger { 567 | msg_send![self, addTypes:newTypes owner:newOwner] 568 | } 569 | 570 | unsafe fn writeFileContents(self, filename: id) -> BOOL { 571 | msg_send![self, writeFileContents:filename] 572 | } 573 | 574 | unsafe fn writeFileWrapper(self, wrapper: id) -> BOOL { 575 | msg_send![self, writeFileWrapper:wrapper] 576 | } 577 | 578 | unsafe fn readFileContentsType_toFile(self, _type: id, filename: id) -> id { 579 | msg_send![self, readFileContentsType:_type toFile:filename] 580 | } 581 | 582 | unsafe fn readFileWrapper(self) -> id { 583 | msg_send![self, readFileWrapper] 584 | } 585 | 586 | } 587 | 588 | pub trait NSPasteboardItem: Sized { 589 | unsafe fn types(self) -> id; 590 | 591 | unsafe fn setDataProvider_forTypes(self, dataProvider: id, types: id) -> BOOL; 592 | unsafe fn setData_forType(self, data: id, _type: id) -> BOOL; 593 | unsafe fn setString_forType(self, string: id, _type: id) -> BOOL; 594 | unsafe fn setPropertyList_forType(self, propertyList: id, _type: id) -> BOOL; 595 | 596 | unsafe fn dataForType(self, _type: id) -> id; 597 | unsafe fn stringForType(self, _type: id) -> id; 598 | unsafe fn propertyListForType(self, _type: id) -> id; 599 | } 600 | 601 | impl NSPasteboardItem for id { 602 | unsafe fn types(self) -> id { 603 | msg_send![self, types] 604 | } 605 | 606 | unsafe fn setDataProvider_forTypes(self, dataProvider: id, types: id) -> BOOL { 607 | msg_send![self, setDataProvider:dataProvider forTypes:types] 608 | } 609 | 610 | unsafe fn setData_forType(self, data: id, _type: id) -> BOOL { 611 | msg_send![self, setData:data forType:_type] 612 | } 613 | 614 | unsafe fn setString_forType(self, string: id, _type: id) -> BOOL { 615 | msg_send![self, setString:string forType:_type] 616 | } 617 | 618 | unsafe fn setPropertyList_forType(self, propertyList: id, _type: id) -> BOOL { 619 | msg_send![self, setPropertyList:propertyList forType:_type] 620 | } 621 | 622 | unsafe fn dataForType(self, _type: id) -> id { 623 | msg_send![self, dataForType:_type] 624 | } 625 | 626 | unsafe fn stringForType(self, _type: id) -> id { 627 | msg_send![self, stringForType:_type] 628 | } 629 | 630 | unsafe fn propertyListForType(self, _type: id) -> id { 631 | msg_send![self, propertyListForType:_type] 632 | } 633 | } 634 | 635 | pub trait NSPasteboardItemDataProvider: Sized { 636 | unsafe fn pasteboard_item_provideDataForType(self, pasteboard: id, item: id, _type: id); 637 | unsafe fn pasteboardFinishedWithDataProvider(self, pasteboard: id); 638 | } 639 | 640 | impl NSPasteboardItemDataProvider for id { 641 | unsafe fn pasteboard_item_provideDataForType(self, pasteboard: id, item: id, _type: id) { 642 | msg_send![self, pasteboard:pasteboard item:item provideDataForType:_type] 643 | } 644 | 645 | unsafe fn pasteboardFinishedWithDataProvider(self, pasteboard: id) { 646 | msg_send![self, pasteboardFinishedWithDataProvider:pasteboard] 647 | } 648 | } 649 | 650 | pub trait NSPasteboardWriting: Sized { 651 | unsafe fn writableTypesForPasteboard(self, pasteboard: id) -> id; 652 | unsafe fn writingOptionsForType_pasteboard(self, _type: id, pasteboard: id) -> NSPasteboardWritingOptions; 653 | 654 | unsafe fn pasteboardPropertyListForType(self, _type: id) -> id; 655 | } 656 | 657 | impl NSPasteboardWriting for id { 658 | unsafe fn writableTypesForPasteboard(self, pasteboard: id) -> id { 659 | msg_send![self, writableTypesForPasteboard:pasteboard] 660 | } 661 | 662 | unsafe fn writingOptionsForType_pasteboard(self, _type: id, pasteboard: id) -> NSPasteboardWritingOptions { 663 | msg_send![self, writingOptionsForType:_type pasteboard:pasteboard] 664 | } 665 | 666 | unsafe fn pasteboardPropertyListForType(self, _type: id) -> id { 667 | msg_send![self, pasteboardPropertyListForType:_type] 668 | } 669 | } 670 | 671 | pub trait NSPasteboardReading: Sized { 672 | unsafe fn initWithPasteboardPropertyList_ofType(self, propertyList: id, _type: id) -> id; 673 | 674 | unsafe fn readableTypesForPasteboard(self, pasteboard: id) -> id; 675 | unsafe fn readingOptionsForType_pasteboard(self, _type: id, pasteboard: id) -> NSPasteboardReadingOptions; 676 | } 677 | 678 | impl NSPasteboardReading for id { 679 | unsafe fn initWithPasteboardPropertyList_ofType(self, propertyList: id, _type: id) -> id { 680 | msg_send![self, initWithPasteboardPropertyList:propertyList ofType:_type] 681 | } 682 | 683 | unsafe fn readableTypesForPasteboard(self, pasteboard: id) -> id { 684 | let class: id = msg_send![self, class]; 685 | msg_send![class, readableTypesForPasteboard:pasteboard] 686 | } 687 | unsafe fn readingOptionsForType_pasteboard(self, _type: id, pasteboard: id) -> NSPasteboardReadingOptions { 688 | let class: id = msg_send![self, class]; 689 | msg_send![class, readingOptionsForType:_type pasteboard:pasteboard] 690 | } 691 | } 692 | 693 | #[repr(u64)] 694 | #[derive(Clone, Copy, Debug, PartialEq)] 695 | pub enum NSPasteboardReadingOptions { 696 | NSPasteboardReadingAsData = 0, 697 | NSPasteboardReadingAsString = 1 << 0, 698 | NSPasteboardReadingAsPropertyList = 1 << 1, 699 | NSPasteboardReadingAsKeyedArchive = 1 << 2 700 | } 701 | 702 | #[repr(u64)] 703 | #[derive(Clone, Copy, Debug, PartialEq)] 704 | pub enum NSPasteboardWritingOptions { 705 | NSPasteboardWritingPromised = 1 << 9, 706 | } 707 | 708 | pub trait NSMenu: Sized { 709 | unsafe fn alloc(_: Self) -> id { 710 | msg_send![class("NSMenu"), alloc] 711 | } 712 | 713 | unsafe fn new(_: Self) -> id { 714 | msg_send![class("NSMenu"), new] 715 | } 716 | 717 | unsafe fn initWithTitle_(self, title: id /* NSString */) -> id; 718 | unsafe fn setAutoenablesItems(self, state: BOOL); 719 | 720 | unsafe fn addItem_(self, menu_item: id); 721 | unsafe fn addItemWithTitle_action_keyEquivalent(self, title: id, action: SEL, key: id) -> id; 722 | unsafe fn itemAtIndex_(self, index: NSInteger) -> id; 723 | } 724 | 725 | impl NSMenu for id { 726 | unsafe fn initWithTitle_(self, title: id /* NSString */) -> id { 727 | msg_send![self, initWithTitle:title] 728 | } 729 | 730 | unsafe fn setAutoenablesItems(self, state: BOOL) { 731 | msg_send![self, setAutoenablesItems: state] 732 | } 733 | 734 | unsafe fn addItem_(self, menu_item: id) { 735 | msg_send![self, addItem:menu_item] 736 | } 737 | 738 | unsafe fn addItemWithTitle_action_keyEquivalent(self, title: id, action: SEL, key: id) -> id { 739 | msg_send![self, addItemWithTitle:title action:action keyEquivalent:key] 740 | } 741 | 742 | unsafe fn itemAtIndex_(self, index: NSInteger) -> id { 743 | msg_send![self, itemAtIndex:index] 744 | } 745 | } 746 | 747 | pub trait NSMenuItem: Sized { 748 | unsafe fn alloc(_: Self) -> id { 749 | msg_send![class("NSMenuItem"), alloc] 750 | } 751 | 752 | unsafe fn new(_: Self) -> id { 753 | msg_send![class("NSMenuItem"), new] 754 | } 755 | 756 | unsafe fn separatorItem(_: Self) -> id { 757 | msg_send![class("NSMenuItem"), separatorItem] 758 | } 759 | 760 | unsafe fn initWithTitle_action_keyEquivalent_(self, title: id, action: SEL, key: id) -> id; 761 | unsafe fn setKeyEquivalentModifierMask_(self, mask: NSEventModifierFlags); 762 | unsafe fn setSubmenu_(self, submenu: id); 763 | } 764 | 765 | impl NSMenuItem for id { 766 | unsafe fn initWithTitle_action_keyEquivalent_(self, title: id, action: SEL, key: id) -> id { 767 | msg_send![self, initWithTitle:title action:action keyEquivalent:key] 768 | } 769 | 770 | unsafe fn setKeyEquivalentModifierMask_(self, mask: NSEventModifierFlags) { 771 | msg_send![self, setKeyEquivalentModifierMask:mask] 772 | } 773 | 774 | unsafe fn setSubmenu_(self, submenu: id) { 775 | msg_send![self, setSubmenu:submenu] 776 | } 777 | } 778 | 779 | pub type NSWindowDepth = libc::c_int; 780 | 781 | bitflags! { 782 | pub struct NSWindowCollectionBehavior: NSUInteger { 783 | const NSWindowCollectionBehaviorDefault = 0; 784 | const NSWindowCollectionBehaviorCanJoinAllSpaces = 1 << 0; 785 | const NSWindowCollectionBehaviorMoveToActiveSpace = 1 << 1; 786 | 787 | const NSWindowCollectionBehaviorManaged = 1 << 2; 788 | const NSWindowCollectionBehaviorTransient = 1 << 3; 789 | const NSWindowCollectionBehaviorStationary = 1 << 4; 790 | 791 | const NSWindowCollectionBehaviorParticipatesInCycle = 1 << 5; 792 | const NSWindowCollectionBehaviorIgnoresCycle = 1 << 6; 793 | 794 | const NSWindowCollectionBehaviorFullScreenPrimary = 1 << 7; 795 | const NSWindowCollectionBehaviorFullScreenAuxiliary = 1 << 8; 796 | } 797 | } 798 | 799 | bitflags! { 800 | pub struct NSWindowOcclusionState: NSUInteger { 801 | const NSWindowOcclusionStateVisible = 1 << 1; 802 | } 803 | } 804 | 805 | pub trait NSWindow: Sized { 806 | unsafe fn alloc(_: Self) -> id { 807 | msg_send![class("NSWindow"), alloc] 808 | } 809 | 810 | // Creating Windows 811 | unsafe fn initWithContentRect_styleMask_backing_defer_(self, 812 | rect: NSRect, 813 | style: NSWindowStyleMask, 814 | backing: NSBackingStoreType, 815 | defer: BOOL) -> id; 816 | unsafe fn initWithContentRect_styleMask_backing_defer_screen_(self, 817 | rect: NSRect, 818 | style: NSWindowStyleMask, 819 | backing: NSBackingStoreType, 820 | defer: BOOL, 821 | screen: id) -> id; 822 | 823 | // Configuring Windows 824 | unsafe fn styleMask(self) -> NSWindowStyleMask; 825 | unsafe fn setStyleMask_(self, styleMask: NSWindowStyleMask); 826 | unsafe fn toggleFullScreen_(self, sender: id); 827 | unsafe fn worksWhenModal(self) -> BOOL; 828 | unsafe fn alphaValue(self) -> CGFloat; 829 | unsafe fn setAlphaValue_(self, windowAlpha: CGFloat); 830 | unsafe fn backgroundColor(self) -> id; 831 | unsafe fn setBackgroundColor_(self, color: id); 832 | unsafe fn colorSpace(self) -> id; 833 | unsafe fn setColorSpace_(self, colorSpace: id); 834 | unsafe fn contentView(self) -> id; 835 | unsafe fn setContentView_(self, view: id); 836 | unsafe fn canHide(self) -> BOOL; 837 | unsafe fn setCanHide_(self, canHide: BOOL); 838 | unsafe fn hidesOnDeactivate(self) -> BOOL; 839 | unsafe fn setHidesOnDeactivate_(self, hideOnDeactivate: BOOL); 840 | unsafe fn collectionBehavior(self) -> NSWindowCollectionBehavior; 841 | unsafe fn setCollectionBehavior_(self, collectionBehavior: NSWindowCollectionBehavior); 842 | unsafe fn setOpaque_(self, opaque: BOOL); 843 | unsafe fn hasShadow(self) -> BOOL; 844 | unsafe fn setHasShadow_(self, hasShadow: BOOL); 845 | unsafe fn invalidateShadow(self); 846 | unsafe fn autorecalculatesContentBorderThicknessForEdge_(self, edge: NSRectEdge) -> BOOL; 847 | unsafe fn setAutorecalculatesContentBorderThickness_forEdge_(self, 848 | autorecalculateContentBorderThickness: BOOL, 849 | edge: NSRectEdge) -> BOOL; 850 | unsafe fn contentBorderThicknessForEdge_(self, edge: NSRectEdge) -> CGFloat; 851 | unsafe fn setContentBorderThickness_forEdge_(self, borderThickness: CGFloat, edge: NSRectEdge); 852 | unsafe fn delegate(self) -> id; 853 | unsafe fn setDelegate_(self, delegate: id); 854 | unsafe fn preventsApplicationTerminationWhenModal(self) -> BOOL; 855 | unsafe fn setPreventsApplicationTerminationWhenModal_(self, flag: BOOL); 856 | 857 | // TODO: Accessing Window Information 858 | 859 | // Getting Layout Information 860 | unsafe fn contentRectForFrameRect_styleMask_(self, windowFrame: NSRect, windowStyle: NSWindowStyleMask) -> NSRect; 861 | unsafe fn frameRectForContentRect_styleMask_(self, windowContentRect: NSRect, windowStyle: NSWindowStyleMask) -> NSRect; 862 | unsafe fn minFrameWidthWithTitle_styleMask_(self, windowTitle: id, windowStyle: NSWindowStyleMask) -> CGFloat; 863 | unsafe fn contentRectForFrameRect_(self, windowFrame: NSRect) -> NSRect; 864 | unsafe fn frameRectForContentRect_(self, windowContent: NSRect) -> NSRect; 865 | 866 | // Managing Windows 867 | unsafe fn drawers(self) -> id; 868 | unsafe fn windowController(self) -> id; 869 | unsafe fn setWindowController_(self, windowController: id); 870 | 871 | // TODO: Managing Sheets 872 | 873 | // Sizing Windows 874 | unsafe fn frame(self) -> NSRect; 875 | unsafe fn setFrameOrigin_(self, point: NSPoint); 876 | unsafe fn setFrameTopLeftPoint_(self, point: NSPoint); 877 | unsafe fn constrainFrameRect_toScreen_(self, frameRect: NSRect, screen: id); 878 | unsafe fn cascadeTopLeftFromPoint_(self, topLeft: NSPoint) -> NSPoint; 879 | unsafe fn setFrame_display_(self, windowFrame: NSRect, display: BOOL); 880 | unsafe fn setFrame_displayViews_(self, windowFrame: NSRect, display: BOOL); 881 | unsafe fn aspectRatio(self) -> NSSize; 882 | unsafe fn setAspectRatio_(self, aspectRatio: NSSize); 883 | unsafe fn minSize(self) -> NSSize; 884 | unsafe fn setMinSize_(self, minSize: NSSize); 885 | unsafe fn maxSize(self) -> NSSize; 886 | unsafe fn setMaxSize_(self, maxSize: NSSize); 887 | unsafe fn performZoom_(self, sender: id); 888 | unsafe fn zoom_(self, sender: id); 889 | unsafe fn resizeFlags(self) -> NSInteger; 890 | unsafe fn showsResizeIndicator(self) -> BOOL; 891 | unsafe fn setShowsResizeIndicator_(self, showsResizeIndicator: BOOL); 892 | unsafe fn resizeIncrements(self) -> NSSize; 893 | unsafe fn setResizeIncrements_(self, resizeIncrements: NSSize); 894 | unsafe fn preservesContentDuringLiveResize(self) -> BOOL; 895 | unsafe fn setPreservesContentDuringLiveResize_(self, preservesContentDuringLiveResize: BOOL); 896 | unsafe fn inLiveResize(self) -> BOOL; 897 | 898 | // Sizing Content 899 | unsafe fn contentAspectRatio(self) -> NSSize; 900 | unsafe fn setContentAspectRatio_(self, contentAspectRatio: NSSize); 901 | unsafe fn contentMinSize(self) -> NSSize; 902 | unsafe fn setContentMinSize_(self, contentMinSize: NSSize); 903 | unsafe fn contentSize(self) -> NSSize; 904 | unsafe fn setContentSize_(self, contentSize: NSSize); 905 | unsafe fn contentMaxSize(self) -> NSSize; 906 | unsafe fn setContentMaxSize_(self, contentMaxSize: NSSize); 907 | unsafe fn contentResizeIncrements(self) -> NSSize; 908 | unsafe fn setContentResizeIncrements_(self, contentResizeIncrements: NSSize); 909 | 910 | // Managing Window Visibility and Occlusion State 911 | unsafe fn isVisible(self) -> BOOL; // NOTE: Deprecated in 10.9 912 | unsafe fn occlusionState(self) -> NSWindowOcclusionState; 913 | 914 | // Managing Window Layers 915 | unsafe fn orderOut_(self, sender: id); 916 | unsafe fn orderBack_(self, sender: id); 917 | unsafe fn orderFront_(self, sender: id); 918 | unsafe fn orderFrontRegardless(self); 919 | unsafe fn orderFrontWindow_relativeTo_(self, orderingMode: NSWindowOrderingMode, otherWindowNumber: NSInteger); 920 | unsafe fn level(self) -> NSInteger; 921 | unsafe fn setLevel_(self, level: NSInteger); 922 | 923 | // Managing Key Status 924 | unsafe fn canBecomeKeyWindow(self) -> BOOL; 925 | unsafe fn makeKeyWindow(self); 926 | unsafe fn makeKeyAndOrderFront_(self, sender: id); 927 | // skipped: becomeKeyWindow (should not be invoked directly, according to Apple's documentation) 928 | // skipped: resignKeyWindow (should not be invoked directly, according to Apple's documentation) 929 | 930 | // Managing Main Status 931 | unsafe fn canBecomeMainWindow(self) -> BOOL; 932 | unsafe fn makeMainWindow(self); 933 | // skipped: becomeMainWindow (should not be invoked directly, according to Apple's documentation) 934 | // skipped: resignMainWindow (should not be invoked directly, according to Apple's documentation) 935 | 936 | // TODO: Managing Toolbars 937 | // TODO: Managing Attached Windows 938 | // TODO: Managing Window Buffers 939 | // TODO: Managing Default Buttons 940 | // TODO: Managing Field Editors 941 | // TODO: Managing the Window Menu 942 | // TODO: Managing Cursor Rectangles 943 | 944 | // Managing Title Bars 945 | unsafe fn standardWindowButton_(self, windowButtonKind: NSWindowButton) -> id; 946 | 947 | // TODO: Managing Tooltips 948 | // TODO: Handling Events 949 | 950 | // Managing Responders 951 | unsafe fn initialFirstResponder(self) -> id; 952 | unsafe fn firstResponder(self) -> id; 953 | unsafe fn setInitialFirstResponder_(self, responder: id); 954 | unsafe fn makeFirstResponder_(self, responder: id) -> BOOL; 955 | 956 | // TODO: Managing the Key View Loop 957 | 958 | // Handling Keyboard Events 959 | unsafe fn keyDown_(self, event: id); 960 | 961 | // Handling Mouse Events 962 | unsafe fn acceptsMouseMovedEvents(self) -> BOOL; 963 | unsafe fn ignoresMouseEvents(self) -> BOOL; 964 | unsafe fn setIgnoresMouseEvents_(self, ignoreMouseEvents: BOOL); 965 | unsafe fn mouseLocationOutsideOfEventStream(self) -> NSPoint; 966 | unsafe fn setAcceptsMouseMovedEvents_(self, acceptMouseMovedEvents: BOOL); 967 | unsafe fn windowNumberAtPoint_belowWindowWithWindowNumber_(self, 968 | point: NSPoint, 969 | windowNumber: NSInteger) -> NSInteger; 970 | 971 | // TODO: Handling Window Restoration 972 | // TODO: Bracketing Drawing Operations 973 | // TODO: Drawing Windows 974 | // TODO: Window Animation 975 | // TODO: Updating Windows 976 | // TODO: Dragging Items 977 | 978 | // Converting Coordinates 979 | unsafe fn backingScaleFactor(self) -> CGFloat; 980 | unsafe fn backingAlignedRect_options_(self, rect: NSRect, options: NSAlignmentOptions) -> NSRect; 981 | unsafe fn convertRectFromBacking_(self, rect: NSRect) -> NSRect; 982 | unsafe fn convertRectToBacking_(self, rect: NSRect) -> NSRect; 983 | unsafe fn convertRectToScreen_(self, rect: NSRect) -> NSRect; 984 | unsafe fn convertRectFromScreen_(self, rect: NSRect) -> NSRect; 985 | 986 | // Accessing Edited Status 987 | unsafe fn setDocumentEdited_(self, documentEdited: BOOL); 988 | 989 | // Managing Titles 990 | unsafe fn title(self) -> id; 991 | unsafe fn setTitle_(self, title: id); 992 | unsafe fn setTitleWithRepresentedFilename_(self, filePath: id); 993 | unsafe fn setTitleVisibility_(self, visibility: NSWindowTitleVisibility); 994 | unsafe fn setTitlebarAppearsTransparent_(self, transparent: BOOL); 995 | unsafe fn representedFilename(self) -> id; 996 | unsafe fn setRepresentedFilename_(self, filePath: id); 997 | unsafe fn representedURL(self) -> id; 998 | unsafe fn setRepresentedURL_(self, representedURL: id); 999 | 1000 | // Accessing Screen Information 1001 | unsafe fn screen(self) -> id; 1002 | unsafe fn deepestScreen(self) -> id; 1003 | unsafe fn displaysWhenScreenProfileChanges(self) -> BOOL; 1004 | unsafe fn setDisplaysWhenScreenProfileChanges_(self, displaysWhenScreenProfileChanges: BOOL); 1005 | 1006 | // Moving Windows 1007 | unsafe fn setMovableByWindowBackground_(self, movableByWindowBackground: BOOL); 1008 | unsafe fn setMovable_(self, movable: BOOL); 1009 | unsafe fn center(self); 1010 | 1011 | // Closing Windows 1012 | unsafe fn performClose_(self, sender: id); 1013 | unsafe fn close(self); 1014 | unsafe fn setReleasedWhenClosed_(self, releasedWhenClosed: BOOL); 1015 | 1016 | // Minimizing Windows 1017 | unsafe fn performMiniaturize_(self, sender: id); 1018 | unsafe fn miniaturize_(self, sender: id); 1019 | unsafe fn deminiaturize_(self, sender: id); 1020 | unsafe fn miniwindowImage(self) -> id; 1021 | unsafe fn setMiniwindowImage_(self, miniwindowImage: id); 1022 | unsafe fn miniwindowTitle(self) -> id; 1023 | unsafe fn setMiniwindowTitle_(self, miniwindowTitle: id); 1024 | 1025 | // TODO: Getting the Dock Tile 1026 | // TODO: Printing Windows 1027 | // TODO: Providing Services 1028 | // TODO: Working with Carbon 1029 | // TODO: Triggering Constraint-Based Layout 1030 | // TODO: Debugging Constraint-Based Layout 1031 | // TODO: Constraint-Based Layouts 1032 | } 1033 | 1034 | impl NSWindow for id { 1035 | // Creating Windows 1036 | 1037 | unsafe fn initWithContentRect_styleMask_backing_defer_(self, 1038 | rect: NSRect, 1039 | style: NSWindowStyleMask, 1040 | backing: NSBackingStoreType, 1041 | defer: BOOL) -> id { 1042 | msg_send![self, initWithContentRect:rect 1043 | styleMask:style.bits 1044 | backing:backing as NSUInteger 1045 | defer:defer] 1046 | } 1047 | 1048 | unsafe fn initWithContentRect_styleMask_backing_defer_screen_(self, 1049 | rect: NSRect, 1050 | style: NSWindowStyleMask, 1051 | backing: NSBackingStoreType, 1052 | defer: BOOL, 1053 | screen: id) -> id { 1054 | msg_send![self, initWithContentRect:rect 1055 | styleMask:style.bits 1056 | backing:backing as NSUInteger 1057 | defer:defer 1058 | screen:screen] 1059 | } 1060 | 1061 | // Configuring Windows 1062 | 1063 | unsafe fn styleMask(self) -> NSWindowStyleMask { 1064 | let styleMask = NSWindowStyleMask::from_bits_truncate(msg_send![self, styleMask]); 1065 | styleMask 1066 | } 1067 | 1068 | unsafe fn setStyleMask_(self, styleMask: NSWindowStyleMask) { 1069 | msg_send![self, setStyleMask:styleMask.bits] 1070 | } 1071 | 1072 | unsafe fn toggleFullScreen_(self, sender: id) { 1073 | msg_send![self, toggleFullScreen:sender] 1074 | } 1075 | 1076 | unsafe fn worksWhenModal(self) -> BOOL { 1077 | msg_send![self, worksWhenModal] 1078 | } 1079 | 1080 | unsafe fn alphaValue(self) -> CGFloat { 1081 | msg_send![self, alphaValue] 1082 | } 1083 | 1084 | unsafe fn setAlphaValue_(self, windowAlpha: CGFloat) { 1085 | msg_send![self, setAlphaValue:windowAlpha] 1086 | } 1087 | 1088 | unsafe fn backgroundColor(self) -> id { 1089 | msg_send![self, backgroundColor] 1090 | } 1091 | 1092 | unsafe fn setBackgroundColor_(self, color: id) { 1093 | msg_send![self, setBackgroundColor:color] 1094 | } 1095 | 1096 | unsafe fn colorSpace(self) -> id { 1097 | msg_send![self, colorSpace] 1098 | } 1099 | 1100 | unsafe fn setColorSpace_(self, colorSpace: id) { 1101 | msg_send![self, setColorSpace:colorSpace] 1102 | } 1103 | 1104 | unsafe fn contentView(self) -> id { 1105 | msg_send![self, contentView] 1106 | } 1107 | 1108 | unsafe fn setContentView_(self, view: id) { 1109 | msg_send![self, setContentView:view] 1110 | } 1111 | 1112 | unsafe fn canHide(self) -> BOOL { 1113 | msg_send![self, canHide] 1114 | } 1115 | 1116 | unsafe fn setCanHide_(self, canHide: BOOL) { 1117 | msg_send![self, setCanHide:canHide] 1118 | } 1119 | 1120 | unsafe fn hidesOnDeactivate(self) -> BOOL { 1121 | msg_send![self, hidesOnDeactivate] 1122 | } 1123 | 1124 | unsafe fn setHidesOnDeactivate_(self, hideOnDeactivate: BOOL) { 1125 | msg_send![self, setHidesOnDeactivate:hideOnDeactivate] 1126 | } 1127 | 1128 | unsafe fn collectionBehavior(self) -> NSWindowCollectionBehavior { 1129 | msg_send![self, collectionBehavior] 1130 | } 1131 | 1132 | unsafe fn setCollectionBehavior_(self, collectionBehavior: NSWindowCollectionBehavior) { 1133 | msg_send![self, setCollectionBehavior:collectionBehavior] 1134 | } 1135 | 1136 | unsafe fn setOpaque_(self, opaque: BOOL) { 1137 | msg_send![self, setOpaque:opaque] 1138 | } 1139 | 1140 | unsafe fn hasShadow(self) -> BOOL { 1141 | msg_send![self, hasShadow] 1142 | } 1143 | 1144 | unsafe fn setHasShadow_(self, hasShadow: BOOL) { 1145 | msg_send![self, setHasShadow:hasShadow] 1146 | } 1147 | 1148 | unsafe fn invalidateShadow(self) { 1149 | msg_send![self, invalidateShadow] 1150 | } 1151 | 1152 | unsafe fn autorecalculatesContentBorderThicknessForEdge_(self, edge: NSRectEdge) -> BOOL { 1153 | msg_send![self, autorecalculatesContentBorderThicknessForEdge:edge] 1154 | } 1155 | 1156 | unsafe fn setAutorecalculatesContentBorderThickness_forEdge_(self, 1157 | autorecalculateContentBorderThickness: BOOL, 1158 | edge: NSRectEdge) -> BOOL { 1159 | msg_send![self, setAutorecalculatesContentBorderThickness: 1160 | autorecalculateContentBorderThickness forEdge:edge] 1161 | } 1162 | 1163 | unsafe fn contentBorderThicknessForEdge_(self, edge: NSRectEdge) -> CGFloat { 1164 | msg_send![self, contentBorderThicknessForEdge:edge] 1165 | } 1166 | 1167 | unsafe fn setContentBorderThickness_forEdge_(self, borderThickness: CGFloat, edge: NSRectEdge) { 1168 | msg_send![self, setContentBorderThickness:borderThickness forEdge:edge] 1169 | } 1170 | 1171 | unsafe fn delegate(self) -> id { 1172 | msg_send![self, delegate] 1173 | } 1174 | 1175 | unsafe fn setDelegate_(self, delegate: id) { 1176 | msg_send![self, setDelegate:delegate] 1177 | } 1178 | 1179 | unsafe fn preventsApplicationTerminationWhenModal(self) -> BOOL { 1180 | msg_send![self, preventsApplicationTerminationWhenModal] 1181 | } 1182 | 1183 | unsafe fn setPreventsApplicationTerminationWhenModal_(self, flag: BOOL) { 1184 | msg_send![self, setPreventsApplicationTerminationWhenModal:flag] 1185 | } 1186 | 1187 | // TODO: Accessing Window Information 1188 | 1189 | // Getting Layout Information 1190 | 1191 | unsafe fn contentRectForFrameRect_styleMask_(self, windowFrame: NSRect, windowStyle: NSWindowStyleMask) -> NSRect { 1192 | msg_send![self, contentRectForFrameRect:windowFrame styleMask:windowStyle.bits] 1193 | } 1194 | 1195 | unsafe fn frameRectForContentRect_styleMask_(self, windowContentRect: NSRect, windowStyle: NSWindowStyleMask) -> NSRect { 1196 | msg_send![self, frameRectForContentRect:windowContentRect styleMask:windowStyle.bits] 1197 | } 1198 | 1199 | unsafe fn minFrameWidthWithTitle_styleMask_(self, windowTitle: id, windowStyle: NSWindowStyleMask) -> CGFloat { 1200 | msg_send![self, minFrameWidthWithTitle:windowTitle styleMask:windowStyle.bits] 1201 | } 1202 | 1203 | unsafe fn contentRectForFrameRect_(self, windowFrame: NSRect) -> NSRect { 1204 | msg_send![self, contentRectForFrameRect:windowFrame] 1205 | } 1206 | 1207 | unsafe fn frameRectForContentRect_(self, windowContent: NSRect) -> NSRect { 1208 | msg_send![self, frameRectForContentRect:windowContent] 1209 | } 1210 | 1211 | // Managing Windows 1212 | 1213 | unsafe fn drawers(self) -> id { 1214 | msg_send![self, drawers] 1215 | } 1216 | 1217 | unsafe fn windowController(self) -> id { 1218 | msg_send![self, windowController] 1219 | } 1220 | 1221 | unsafe fn setWindowController_(self, windowController: id) { 1222 | msg_send![self, setWindowController:windowController] 1223 | } 1224 | 1225 | // TODO: Managing Sheets 1226 | 1227 | // Sizing Windows 1228 | 1229 | unsafe fn frame(self) -> NSRect { 1230 | msg_send![self, frame] 1231 | } 1232 | 1233 | unsafe fn setFrameOrigin_(self, point: NSPoint) { 1234 | msg_send![self, setFrameOrigin:point] 1235 | } 1236 | 1237 | unsafe fn setFrameTopLeftPoint_(self, point: NSPoint) { 1238 | msg_send![self, setFrameTopLeftPoint:point] 1239 | } 1240 | 1241 | unsafe fn constrainFrameRect_toScreen_(self, frameRect: NSRect, screen: id) { 1242 | msg_send![self, constrainFrameRect:frameRect toScreen:screen] 1243 | } 1244 | 1245 | unsafe fn cascadeTopLeftFromPoint_(self, topLeft: NSPoint) -> NSPoint { 1246 | msg_send![self, cascadeTopLeftFromPoint:topLeft] 1247 | } 1248 | 1249 | unsafe fn setFrame_display_(self, windowFrame: NSRect, display: BOOL) { 1250 | msg_send![self, setFrame:windowFrame display:display] 1251 | } 1252 | 1253 | unsafe fn setFrame_displayViews_(self, windowFrame: NSRect, display: BOOL) { 1254 | msg_send![self, setFrame:windowFrame displayViews:display] 1255 | } 1256 | 1257 | unsafe fn aspectRatio(self) -> NSSize { 1258 | msg_send![self, aspectRatio] 1259 | } 1260 | 1261 | unsafe fn setAspectRatio_(self, aspectRatio: NSSize) { 1262 | msg_send![self, setAspectRatio:aspectRatio] 1263 | } 1264 | 1265 | unsafe fn minSize(self) -> NSSize { 1266 | msg_send![self, minSize] 1267 | } 1268 | 1269 | unsafe fn setMinSize_(self, minSize: NSSize) { 1270 | msg_send![self, setMinSize:minSize] 1271 | } 1272 | 1273 | unsafe fn maxSize(self) -> NSSize { 1274 | msg_send![self, maxSize] 1275 | } 1276 | 1277 | unsafe fn setMaxSize_(self, maxSize: NSSize) { 1278 | msg_send![self, setMaxSize:maxSize] 1279 | } 1280 | 1281 | unsafe fn performZoom_(self, sender: id) { 1282 | msg_send![self, performZoom:sender] 1283 | } 1284 | 1285 | unsafe fn zoom_(self, sender: id) { 1286 | msg_send![self, zoom:sender] 1287 | } 1288 | 1289 | unsafe fn resizeFlags(self) -> NSInteger { 1290 | msg_send![self, resizeFlags] 1291 | } 1292 | 1293 | unsafe fn showsResizeIndicator(self) -> BOOL { 1294 | msg_send![self, showsResizeIndicator] 1295 | } 1296 | 1297 | unsafe fn setShowsResizeIndicator_(self, showsResizeIndicator: BOOL) { 1298 | msg_send![self, setShowsResizeIndicator:showsResizeIndicator] 1299 | } 1300 | 1301 | unsafe fn resizeIncrements(self) -> NSSize { 1302 | msg_send![self, resizeIncrements] 1303 | } 1304 | 1305 | unsafe fn setResizeIncrements_(self, resizeIncrements: NSSize) { 1306 | msg_send![self, setResizeIncrements:resizeIncrements] 1307 | } 1308 | 1309 | unsafe fn preservesContentDuringLiveResize(self) -> BOOL { 1310 | msg_send![self, preservesContentDuringLiveResize] 1311 | } 1312 | 1313 | unsafe fn setPreservesContentDuringLiveResize_(self, preservesContentDuringLiveResize: BOOL) { 1314 | msg_send![self, setPreservesContentDuringLiveResize:preservesContentDuringLiveResize] 1315 | } 1316 | 1317 | unsafe fn inLiveResize(self) -> BOOL { 1318 | msg_send![self, inLiveResize] 1319 | } 1320 | 1321 | // Sizing Content 1322 | 1323 | unsafe fn contentAspectRatio(self) -> NSSize { 1324 | msg_send![self, contentAspectRatio] 1325 | } 1326 | 1327 | unsafe fn setContentAspectRatio_(self, contentAspectRatio: NSSize) { 1328 | msg_send![self, setContentAspectRatio:contentAspectRatio] 1329 | } 1330 | 1331 | unsafe fn contentMinSize(self) -> NSSize { 1332 | msg_send![self, contentMinSize] 1333 | } 1334 | 1335 | unsafe fn setContentMinSize_(self, contentMinSize: NSSize) { 1336 | msg_send![self, setContentMinSize:contentMinSize] 1337 | } 1338 | 1339 | unsafe fn contentSize(self) -> NSSize { 1340 | msg_send![self, contentSize] 1341 | } 1342 | 1343 | unsafe fn setContentSize_(self, contentSize: NSSize) { 1344 | msg_send![self, setContentSize:contentSize] 1345 | } 1346 | 1347 | unsafe fn contentMaxSize(self) -> NSSize { 1348 | msg_send![self, contentMaxSize] 1349 | } 1350 | 1351 | unsafe fn setContentMaxSize_(self, contentMaxSize: NSSize) { 1352 | msg_send![self, setContentMaxSize:contentMaxSize] 1353 | } 1354 | 1355 | unsafe fn contentResizeIncrements(self) -> NSSize { 1356 | msg_send![self, contentResizeIncrements] 1357 | } 1358 | 1359 | unsafe fn setContentResizeIncrements_(self, contentResizeIncrements: NSSize) { 1360 | msg_send![self, setContentResizeIncrements:contentResizeIncrements] 1361 | } 1362 | 1363 | // Managing Window Visibility and Occlusion State 1364 | 1365 | unsafe fn isVisible(self) -> BOOL { 1366 | msg_send![self, isVisible] 1367 | } 1368 | 1369 | unsafe fn occlusionState(self) -> NSWindowOcclusionState { 1370 | msg_send![self, occlusionState] 1371 | } 1372 | 1373 | // Managing Window Layers 1374 | 1375 | unsafe fn orderOut_(self, sender: id) { 1376 | msg_send![self, orderOut:sender] 1377 | } 1378 | 1379 | unsafe fn orderBack_(self, sender: id) { 1380 | msg_send![self, orderBack:sender] 1381 | } 1382 | 1383 | unsafe fn orderFront_(self, sender: id) { 1384 | msg_send![self, orderFront:sender] 1385 | } 1386 | 1387 | unsafe fn orderFrontRegardless(self) { 1388 | msg_send![self, orderFrontRegardless] 1389 | } 1390 | 1391 | unsafe fn orderFrontWindow_relativeTo_(self, ordering_mode: NSWindowOrderingMode, other_window_number: NSInteger) { 1392 | msg_send![self, orderWindow:ordering_mode relativeTo:other_window_number] 1393 | } 1394 | 1395 | unsafe fn level(self) -> NSInteger { 1396 | msg_send![self, level] 1397 | } 1398 | 1399 | unsafe fn setLevel_(self, level: NSInteger) { 1400 | msg_send![self, setLevel:level] 1401 | } 1402 | 1403 | // Managing Key Status 1404 | 1405 | unsafe fn canBecomeKeyWindow(self) -> BOOL { 1406 | msg_send![self, canBecomeKeyWindow] 1407 | } 1408 | 1409 | unsafe fn makeKeyWindow(self) { 1410 | msg_send![self, makeKeyWindow] 1411 | } 1412 | 1413 | unsafe fn makeKeyAndOrderFront_(self, sender: id) { 1414 | msg_send![self, makeKeyAndOrderFront:sender] 1415 | } 1416 | 1417 | // Managing Main Status 1418 | 1419 | unsafe fn canBecomeMainWindow(self) -> BOOL { 1420 | msg_send![self, canBecomeMainWindow] 1421 | } 1422 | 1423 | unsafe fn makeMainWindow(self) { 1424 | msg_send![self, makeMainWindow] 1425 | } 1426 | 1427 | // TODO: Managing Toolbars 1428 | // TODO: Managing Attached Windows 1429 | // TODO: Managing Window Buffers 1430 | // TODO: Managing Default Buttons 1431 | // TODO: Managing Field Editors 1432 | // TODO: Managing the Window Menu 1433 | // TODO: Managing Cursor Rectangles 1434 | 1435 | // Managing Title Bars 1436 | 1437 | unsafe fn standardWindowButton_(self, windowButtonKind: NSWindowButton) -> id { 1438 | msg_send![self, standardWindowButton:windowButtonKind] 1439 | } 1440 | 1441 | // TODO: Managing Tooltips 1442 | // TODO: Handling Events 1443 | 1444 | // Managing Responders 1445 | 1446 | unsafe fn initialFirstResponder(self) -> id { 1447 | msg_send![self, initialFirstResponder] 1448 | } 1449 | 1450 | unsafe fn firstResponder(self) -> id { 1451 | msg_send![self, firstResponder] 1452 | } 1453 | 1454 | unsafe fn setInitialFirstResponder_(self, responder: id) { 1455 | msg_send![self, setInitialFirstResponder:responder] 1456 | } 1457 | 1458 | unsafe fn makeFirstResponder_(self, responder: id) -> BOOL { 1459 | msg_send![self, makeFirstResponder:responder] 1460 | } 1461 | 1462 | // TODO: Managing the Key View Loop 1463 | 1464 | // Handling Keyboard Events 1465 | 1466 | unsafe fn keyDown_(self, event: id) { 1467 | msg_send![self, keyDown:event] 1468 | } 1469 | 1470 | // Handling Mouse Events 1471 | 1472 | unsafe fn acceptsMouseMovedEvents(self) -> BOOL { 1473 | msg_send![self, acceptsMouseMovedEvents] 1474 | } 1475 | 1476 | unsafe fn ignoresMouseEvents(self) -> BOOL { 1477 | msg_send![self, ignoresMouseEvents] 1478 | } 1479 | 1480 | unsafe fn setIgnoresMouseEvents_(self, ignoreMouseEvents: BOOL) { 1481 | msg_send![self, setIgnoresMouseEvents:ignoreMouseEvents] 1482 | } 1483 | 1484 | unsafe fn mouseLocationOutsideOfEventStream(self) -> NSPoint { 1485 | msg_send![self, mouseLocationOutsideOfEventStream] 1486 | } 1487 | 1488 | unsafe fn setAcceptsMouseMovedEvents_(self, acceptMouseMovedEvents: BOOL) { 1489 | msg_send![self, setAcceptsMouseMovedEvents:acceptMouseMovedEvents] 1490 | } 1491 | 1492 | unsafe fn windowNumberAtPoint_belowWindowWithWindowNumber_(self, 1493 | point: NSPoint, 1494 | windowNumber: NSInteger) -> NSInteger { 1495 | msg_send![self, windowNumberAtPoint:point belowWindowWithWindowNumber:windowNumber] 1496 | } 1497 | 1498 | // Converting Coordinates 1499 | 1500 | unsafe fn backingScaleFactor(self) -> CGFloat { 1501 | msg_send![self, backingScaleFactor] 1502 | } 1503 | 1504 | unsafe fn backingAlignedRect_options_(self, rect: NSRect, options: NSAlignmentOptions) -> NSRect { 1505 | msg_send![self, backingAlignedRect:rect options:options] 1506 | } 1507 | 1508 | unsafe fn convertRectFromBacking_(self, rect: NSRect) -> NSRect { 1509 | msg_send![self, convertRectFromBacking:rect] 1510 | } 1511 | 1512 | unsafe fn convertRectToBacking_(self, rect: NSRect) -> NSRect { 1513 | msg_send![self, convertRectToBacking:rect] 1514 | } 1515 | 1516 | unsafe fn convertRectToScreen_(self, rect: NSRect) -> NSRect { 1517 | msg_send![self, convertRectToScreen:rect] 1518 | } 1519 | 1520 | unsafe fn convertRectFromScreen_(self, rect: NSRect) -> NSRect { 1521 | msg_send![self, convertRectFromScreen:rect] 1522 | } 1523 | 1524 | // Accessing Edited Status 1525 | 1526 | unsafe fn setDocumentEdited_(self, documentEdited: BOOL) { 1527 | msg_send![self, setDocumentEdited:documentEdited] 1528 | } 1529 | 1530 | // Managing Titles 1531 | 1532 | unsafe fn title(self) -> id { 1533 | msg_send![self, title] 1534 | } 1535 | 1536 | unsafe fn setTitle_(self, title: id) { 1537 | msg_send![self, setTitle:title] 1538 | } 1539 | 1540 | unsafe fn setTitleWithRepresentedFilename_(self, filePath: id) { 1541 | msg_send![self, setTitleWithRepresentedFilename:filePath] 1542 | } 1543 | 1544 | unsafe fn setTitleVisibility_(self, visibility: NSWindowTitleVisibility) { 1545 | msg_send![self, setTitleVisibility:visibility] 1546 | } 1547 | 1548 | unsafe fn setTitlebarAppearsTransparent_(self, transparent: BOOL) { 1549 | msg_send![self, setTitlebarAppearsTransparent:transparent] 1550 | } 1551 | 1552 | unsafe fn representedFilename(self) -> id { 1553 | msg_send![self, representedFilename] 1554 | } 1555 | 1556 | unsafe fn setRepresentedFilename_(self, filePath: id) { 1557 | msg_send![self, setRepresentedFilename:filePath] 1558 | } 1559 | 1560 | unsafe fn representedURL(self) -> id { 1561 | msg_send![self, representedURL] 1562 | } 1563 | 1564 | unsafe fn setRepresentedURL_(self, representedURL: id) { 1565 | msg_send![self, setRepresentedURL:representedURL] 1566 | } 1567 | 1568 | // Accessing Screen Information 1569 | 1570 | unsafe fn screen(self) -> id { 1571 | msg_send![self, screen] 1572 | } 1573 | 1574 | unsafe fn deepestScreen(self) -> id { 1575 | msg_send![self, deepestScreen] 1576 | } 1577 | 1578 | unsafe fn displaysWhenScreenProfileChanges(self) -> BOOL { 1579 | msg_send![self, displaysWhenScreenProfileChanges] 1580 | } 1581 | 1582 | unsafe fn setDisplaysWhenScreenProfileChanges_(self, displaysWhenScreenProfileChanges: BOOL) { 1583 | msg_send![self, setDisplaysWhenScreenProfileChanges:displaysWhenScreenProfileChanges] 1584 | } 1585 | 1586 | // Moving Windows 1587 | 1588 | unsafe fn setMovableByWindowBackground_(self, movableByWindowBackground: BOOL) { 1589 | msg_send![self, setMovableByWindowBackground:movableByWindowBackground] 1590 | } 1591 | 1592 | unsafe fn setMovable_(self, movable: BOOL) { 1593 | msg_send![self, setMovable:movable] 1594 | } 1595 | 1596 | unsafe fn center(self) { 1597 | msg_send![self, center] 1598 | } 1599 | 1600 | // Closing Windows 1601 | 1602 | unsafe fn performClose_(self, sender: id) { 1603 | msg_send![self, performClose:sender] 1604 | } 1605 | 1606 | unsafe fn close(self) { 1607 | msg_send![self, close] 1608 | } 1609 | 1610 | unsafe fn setReleasedWhenClosed_(self, releasedWhenClosed: BOOL) { 1611 | msg_send![self, setReleasedWhenClosed:releasedWhenClosed] 1612 | } 1613 | 1614 | // Minimizing Windows 1615 | 1616 | unsafe fn performMiniaturize_(self, sender: id) { 1617 | msg_send![self, performMiniaturize:sender] 1618 | } 1619 | 1620 | unsafe fn miniaturize_(self, sender: id) { 1621 | msg_send![self, miniaturize:sender] 1622 | } 1623 | 1624 | unsafe fn deminiaturize_(self, sender: id) { 1625 | msg_send![self, deminiaturize:sender] 1626 | } 1627 | 1628 | unsafe fn miniwindowImage(self) -> id { 1629 | msg_send![self, miniwindowImage] 1630 | } 1631 | 1632 | unsafe fn setMiniwindowImage_(self, miniwindowImage: id) { 1633 | msg_send![self, setMiniwindowImage:miniwindowImage] 1634 | } 1635 | 1636 | unsafe fn miniwindowTitle(self) -> id { 1637 | msg_send![self, miniwindowTitle] 1638 | } 1639 | 1640 | unsafe fn setMiniwindowTitle_(self, miniwindowTitle: id) { 1641 | msg_send![self, setMiniwindowTitle:miniwindowTitle] 1642 | } 1643 | 1644 | // TODO: Getting the Dock Tile 1645 | // TODO: Printing Windows 1646 | // TODO: Providing Services 1647 | // TODO: Working with Carbon 1648 | // TODO: Triggering Constraint-Based Layout 1649 | // TODO: Debugging Constraint-Based Layout 1650 | // TODO: Constraint-Based Layouts 1651 | } 1652 | 1653 | pub trait NSView: Sized { 1654 | unsafe fn alloc(_: Self) -> id { 1655 | msg_send![class("NSView"), alloc] 1656 | } 1657 | 1658 | unsafe fn init(self) -> id; 1659 | unsafe fn initWithFrame_(self, frameRect: NSRect) -> id; 1660 | unsafe fn bounds(self) -> NSRect; 1661 | unsafe fn frame(self) -> NSRect; 1662 | unsafe fn display_(self); 1663 | unsafe fn setWantsBestResolutionOpenGLSurface_(self, flag: BOOL); 1664 | unsafe fn convertPoint_fromView_(self, point: NSPoint, view: id) -> NSPoint; 1665 | unsafe fn addSubview_(self, view: id); 1666 | unsafe fn superview(self) -> id; 1667 | unsafe fn removeFromSuperview(self); 1668 | unsafe fn setAutoresizingMask_(self, autoresizingMask: NSAutoresizingMaskOptions); 1669 | 1670 | unsafe fn wantsLayer(self) -> BOOL; 1671 | unsafe fn setWantsLayer(self, wantsLayer: BOOL); 1672 | unsafe fn layer(self) -> id; 1673 | unsafe fn setLayer(self, layer: id); 1674 | 1675 | unsafe fn widthAnchor(self) -> id; 1676 | unsafe fn heightAnchor(self) -> id; 1677 | } 1678 | 1679 | impl NSView for id { 1680 | unsafe fn init(self) -> id { 1681 | msg_send![self, init] 1682 | } 1683 | 1684 | unsafe fn initWithFrame_(self, frameRect: NSRect) -> id { 1685 | msg_send![self, initWithFrame:frameRect] 1686 | } 1687 | 1688 | unsafe fn bounds(self) -> NSRect { 1689 | msg_send![self, bounds] 1690 | } 1691 | 1692 | unsafe fn frame(self) -> NSRect { 1693 | msg_send![self, frame] 1694 | } 1695 | 1696 | unsafe fn display_(self) { 1697 | msg_send![self, display] 1698 | } 1699 | 1700 | unsafe fn setWantsBestResolutionOpenGLSurface_(self, flag: BOOL) { 1701 | msg_send![self, setWantsBestResolutionOpenGLSurface:flag] 1702 | } 1703 | 1704 | unsafe fn convertPoint_fromView_(self, point: NSPoint, view: id) -> NSPoint { 1705 | msg_send![self, convertPoint:point fromView:view] 1706 | } 1707 | 1708 | unsafe fn addSubview_(self, view: id) { 1709 | msg_send![self, addSubview:view] 1710 | } 1711 | 1712 | unsafe fn superview(self) -> id { 1713 | msg_send![self, superview] 1714 | } 1715 | 1716 | unsafe fn removeFromSuperview(self) { 1717 | msg_send![self, removeFromSuperview] 1718 | } 1719 | 1720 | unsafe fn setAutoresizingMask_(self, autoresizingMask: NSAutoresizingMaskOptions) { 1721 | msg_send![self, setAutoresizingMask:autoresizingMask] 1722 | } 1723 | 1724 | unsafe fn wantsLayer(self) -> BOOL { 1725 | msg_send![self, wantsLayer] 1726 | } 1727 | 1728 | unsafe fn setWantsLayer(self, wantsLayer: BOOL) { 1729 | msg_send![self, setWantsLayer:wantsLayer] 1730 | } 1731 | 1732 | unsafe fn layer(self) -> id { 1733 | msg_send![self, layer] 1734 | } 1735 | 1736 | unsafe fn setLayer(self, layer: id) { 1737 | msg_send![self, setLayer:layer] 1738 | } 1739 | 1740 | unsafe fn widthAnchor(self) -> id { 1741 | msg_send![self, widthAnchor] 1742 | } 1743 | 1744 | unsafe fn heightAnchor(self) -> id { 1745 | msg_send![self, heightAnchor] 1746 | } 1747 | } 1748 | 1749 | pub type NSAutoresizingMaskOptions = u64; 1750 | 1751 | pub const NSViewNotSizable: u64 = 0; 1752 | pub const NSViewMinXMargin: u64 = 1; 1753 | pub const NSViewWidthSizable: u64 = 2; 1754 | pub const NSViewMaxXMargin: u64 = 4; 1755 | pub const NSViewMinYMargin: u64 = 8; 1756 | pub const NSViewHeightSizable: u64 = 16; 1757 | pub const NSViewMaxYMargin: u64 = 32; 1758 | 1759 | pub trait NSOpenGLView: Sized { 1760 | unsafe fn alloc(_: Self) -> id { 1761 | msg_send![class("NSOpenGLView"), alloc] 1762 | } 1763 | 1764 | unsafe fn initWithFrame_pixelFormat_(self, frameRect: NSRect, format: id) -> id; 1765 | unsafe fn display_(self); 1766 | unsafe fn setOpenGLContext_(self, context: id); 1767 | unsafe fn setPixelFormat_(self, pixelformat: id); 1768 | } 1769 | 1770 | impl NSOpenGLView for id { 1771 | unsafe fn initWithFrame_pixelFormat_(self, frameRect: NSRect, format: id) -> id { 1772 | msg_send![self, initWithFrame:frameRect pixelFormat:format] 1773 | } 1774 | 1775 | unsafe fn display_(self) { 1776 | msg_send![self, display] 1777 | } 1778 | 1779 | unsafe fn setOpenGLContext_(self, context: id) { 1780 | msg_send![self, setOpenGLContext:context] 1781 | } 1782 | 1783 | unsafe fn setPixelFormat_(self, pixelformat: id) { 1784 | msg_send![self, setPixelFormat:pixelformat] 1785 | } 1786 | } 1787 | 1788 | pub trait NSOpenGLPixelFormat: Sized { 1789 | unsafe fn alloc(_: Self) -> id { 1790 | msg_send![class("NSOpenGLPixelFormat"), alloc] 1791 | } 1792 | 1793 | // Creating an NSOpenGLPixelFormat Object 1794 | 1795 | unsafe fn initWithAttributes_(self, attributes: &[u32]) -> id; 1796 | 1797 | // Managing the Pixel Format 1798 | 1799 | unsafe fn getValues_forAttribute_forVirtualScreen_(self, val: *mut GLint, attrib: NSOpenGLPixelFormatAttribute, screen: GLint); 1800 | unsafe fn numberOfVirtualScreens(self) -> GLint; 1801 | 1802 | } 1803 | 1804 | impl NSOpenGLPixelFormat for id { 1805 | // Creating an NSOpenGLPixelFormat Object 1806 | 1807 | unsafe fn initWithAttributes_(self, attributes: &[u32]) -> id { 1808 | msg_send![self, initWithAttributes:attributes] 1809 | } 1810 | 1811 | // Managing the Pixel Format 1812 | 1813 | unsafe fn getValues_forAttribute_forVirtualScreen_(self, val: *mut GLint, attrib: NSOpenGLPixelFormatAttribute, screen: GLint) { 1814 | msg_send![self, getValues:val forAttribute:attrib forVirtualScreen:screen] 1815 | } 1816 | 1817 | unsafe fn numberOfVirtualScreens(self) -> GLint { 1818 | msg_send![self, numberOfVirtualScreens] 1819 | } 1820 | } 1821 | 1822 | pub trait NSOpenGLContext: Sized { 1823 | unsafe fn alloc(_: Self) -> id { 1824 | msg_send![class("NSOpenGLContext"), alloc] 1825 | } 1826 | 1827 | // Context Creation 1828 | unsafe fn initWithFormat_shareContext_(self, format: id /* (NSOpenGLPixelFormat *) */, shareContext: id /* (NSOpenGLContext *) */) -> id /* (instancetype) */; 1829 | unsafe fn initWithCGLContextObj_(self, context: CGLContextObj) -> id /* (instancetype) */; 1830 | 1831 | // Managing the Current Context 1832 | unsafe fn clearCurrentContext(_: Self); 1833 | unsafe fn currentContext(_: Self) -> id /* (NSOpenGLContext *) */; 1834 | unsafe fn makeCurrentContext(self); 1835 | 1836 | // Drawable Object Management 1837 | unsafe fn setView_(self, view: id /* (NSView *) */); 1838 | unsafe fn view(self) -> id /* (NSView *) */; 1839 | unsafe fn clearDrawable(self); 1840 | unsafe fn update(self); 1841 | 1842 | // Flushing the Drawing Buffer 1843 | unsafe fn flushBuffer(self); 1844 | 1845 | // Context Parameter Handling 1846 | unsafe fn setValues_forParameter_(self, vals: *const GLint, param: NSOpenGLContextParameter); 1847 | unsafe fn getValues_forParameter_(self, vals: *mut GLint, param: NSOpenGLContextParameter); 1848 | 1849 | // Working with Virtual Screens 1850 | unsafe fn setCurrentVirtualScreen_(self, screen: GLint); 1851 | unsafe fn currentVirtualScreen(self) -> GLint; 1852 | 1853 | // Getting the CGL Context Object 1854 | unsafe fn CGLContextObj(self) -> CGLContextObj; 1855 | } 1856 | 1857 | impl NSOpenGLContext for id { 1858 | // Context Creation 1859 | 1860 | unsafe fn initWithFormat_shareContext_(self, format: id /* (NSOpenGLPixelFormat *) */, shareContext: id /* (NSOpenGLContext *) */) -> id /* (instancetype) */ { 1861 | msg_send![self, initWithFormat:format shareContext:shareContext] 1862 | } 1863 | 1864 | unsafe fn initWithCGLContextObj_(self, context: CGLContextObj) -> id /* (instancetype) */ { 1865 | msg_send![self, initWithCGLContextObj:context] 1866 | } 1867 | 1868 | // Managing the Current Context 1869 | 1870 | unsafe fn clearCurrentContext(_: Self) { 1871 | msg_send![class("NSOpenGLContext"), clearCurrentContext] 1872 | } 1873 | 1874 | unsafe fn currentContext(_: Self) -> id /* (NSOpenGLContext *) */ { 1875 | msg_send![class("NSOpenGLContext"), currentContext] 1876 | } 1877 | 1878 | unsafe fn makeCurrentContext(self) { 1879 | msg_send![self, makeCurrentContext] 1880 | } 1881 | 1882 | // Drawable Object Management 1883 | 1884 | unsafe fn setView_(self, view: id /* (NSView *) */) { 1885 | msg_send![self, setView:view] 1886 | } 1887 | 1888 | unsafe fn view(self) -> id /* (NSView *) */ { 1889 | msg_send![self, view] 1890 | } 1891 | 1892 | unsafe fn clearDrawable(self) { 1893 | msg_send![self, clearDrawable] 1894 | } 1895 | 1896 | unsafe fn update(self) { 1897 | msg_send![self, update] 1898 | } 1899 | 1900 | // Flushing the Drawing Buffer 1901 | 1902 | unsafe fn flushBuffer(self) { 1903 | msg_send![self, flushBuffer] 1904 | } 1905 | 1906 | // Context Parameter Handling 1907 | 1908 | unsafe fn setValues_forParameter_(self, vals: *const GLint, param: NSOpenGLContextParameter) { 1909 | msg_send![self, setValues:vals forParameter:param] 1910 | } 1911 | 1912 | unsafe fn getValues_forParameter_(self, vals: *mut GLint, param: NSOpenGLContextParameter) { 1913 | msg_send![self, getValues:vals forParameter:param] 1914 | } 1915 | 1916 | // Working with Virtual Screens 1917 | 1918 | unsafe fn setCurrentVirtualScreen_(self, screen: GLint) { 1919 | msg_send![self, setCurrentVirtualScreen:screen] 1920 | } 1921 | 1922 | unsafe fn currentVirtualScreen(self) -> GLint { 1923 | msg_send![self, currentVirtualScreen] 1924 | } 1925 | 1926 | // Getting the CGL Context Object 1927 | 1928 | unsafe fn CGLContextObj(self) -> CGLContextObj { 1929 | msg_send![self, CGLContextObj] 1930 | } 1931 | } 1932 | 1933 | bitflags! { 1934 | pub struct NSEventSwipeTrackingOptions: NSUInteger { 1935 | const NSEventSwipeTrackingLockDirection = 0x1 << 0; 1936 | const NSEventSwipeTrackingClampGestureAmount = 0x1 << 1; 1937 | } 1938 | } 1939 | 1940 | #[repr(i64)] // NSInteger 1941 | pub enum NSEventGestureAxis { 1942 | NSEventGestureAxisNone = 0, 1943 | NSEventGestureAxisHorizontal, 1944 | NSEventGestureAxisVertical, 1945 | } 1946 | 1947 | bitflags! { 1948 | pub struct NSEventPhase: NSUInteger { 1949 | const NSEventPhaseNone = 0; 1950 | const NSEventPhaseBegan = 0x1 << 0; 1951 | const NSEventPhaseStationary = 0x1 << 1; 1952 | const NSEventPhaseChanged = 0x1 << 2; 1953 | const NSEventPhaseEnded = 0x1 << 3; 1954 | const NSEventPhaseCancelled = 0x1 << 4; 1955 | const NSEventPhaseMayBegin = 0x1 << 5; 1956 | } 1957 | } 1958 | 1959 | bitflags! { 1960 | pub struct NSTouchPhase: NSUInteger { 1961 | const NSTouchPhaseBegan = 1 << 0; 1962 | const NSTouchPhaseMoved = 1 << 1; 1963 | const NSTouchPhaseStationary = 1 << 2; 1964 | const NSTouchPhaseEnded = 1 << 3; 1965 | const NSTouchPhaseCancelled = 1 << 4; 1966 | const NSTouchPhaseTouching = NSTouchPhase::NSTouchPhaseBegan.bits 1967 | | NSTouchPhase::NSTouchPhaseMoved.bits 1968 | | NSTouchPhase::NSTouchPhaseStationary.bits; 1969 | const NSTouchPhaseAny = !0; // NSUIntegerMax 1970 | } 1971 | } 1972 | 1973 | #[derive(Clone, Copy, Debug, PartialEq)] 1974 | #[repr(u64)] // NSUInteger 1975 | pub enum NSEventType { 1976 | NSLeftMouseDown = 1, 1977 | NSLeftMouseUp = 2, 1978 | NSRightMouseDown = 3, 1979 | NSRightMouseUp = 4, 1980 | NSMouseMoved = 5, 1981 | NSLeftMouseDragged = 6, 1982 | NSRightMouseDragged = 7, 1983 | NSMouseEntered = 8, 1984 | NSMouseExited = 9, 1985 | NSKeyDown = 10, 1986 | NSKeyUp = 11, 1987 | NSFlagsChanged = 12, 1988 | NSAppKitDefined = 13, 1989 | NSSystemDefined = 14, 1990 | NSApplicationDefined = 15, 1991 | NSPeriodic = 16, 1992 | NSCursorUpdate = 17, 1993 | NSScrollWheel = 22, 1994 | NSTabletPoint = 23, 1995 | NSTabletProximity = 24, 1996 | NSOtherMouseDown = 25, 1997 | NSOtherMouseUp = 26, 1998 | NSOtherMouseDragged = 27, 1999 | NSEventTypeGesture = 29, 2000 | NSEventTypeMagnify = 30, 2001 | NSEventTypeSwipe = 31, 2002 | NSEventTypeRotate = 18, 2003 | NSEventTypeBeginGesture = 19, 2004 | NSEventTypeEndGesture = 20, 2005 | NSEventTypePressure = 34, 2006 | } 2007 | 2008 | bitflags! { 2009 | pub struct NSEventMask: libc::c_ulonglong { 2010 | const NSLeftMouseDownMask = 1 << NSLeftMouseDown as libc::c_ulonglong; 2011 | const NSLeftMouseUpMask = 1 << NSLeftMouseUp as libc::c_ulonglong; 2012 | const NSRightMouseDownMask = 1 << NSRightMouseDown as libc::c_ulonglong; 2013 | const NSRightMouseUpMask = 1 << NSRightMouseUp as libc::c_ulonglong; 2014 | const NSMouseMovedMask = 1 << NSMouseMoved as libc::c_ulonglong; 2015 | const NSLeftMouseDraggedMask = 1 << NSLeftMouseDragged as libc::c_ulonglong; 2016 | const NSRightMouseDraggedMask = 1 << NSRightMouseDragged as libc::c_ulonglong; 2017 | const NSMouseEnteredMask = 1 << NSMouseEntered as libc::c_ulonglong; 2018 | const NSMouseExitedMask = 1 << NSMouseExited as libc::c_ulonglong; 2019 | const NSKeyDownMask = 1 << NSKeyDown as libc::c_ulonglong; 2020 | const NSKeyUpMask = 1 << NSKeyUp as libc::c_ulonglong; 2021 | const NSFlagsChangedMask = 1 << NSFlagsChanged as libc::c_ulonglong; 2022 | const NSAppKitDefinedMask = 1 << NSAppKitDefined as libc::c_ulonglong; 2023 | const NSSystemDefinedMask = 1 << NSSystemDefined as libc::c_ulonglong; 2024 | const NSApplicationDefinedMask = 1 << NSApplicationDefined as libc::c_ulonglong; 2025 | const NSPeriodicMask = 1 << NSPeriodic as libc::c_ulonglong; 2026 | const NSCursorUpdateMask = 1 << NSCursorUpdate as libc::c_ulonglong; 2027 | const NSScrollWheelMask = 1 << NSScrollWheel as libc::c_ulonglong; 2028 | const NSTabletPointMask = 1 << NSTabletPoint as libc::c_ulonglong; 2029 | const NSTabletProximityMask = 1 << NSTabletProximity as libc::c_ulonglong; 2030 | const NSOtherMouseDownMask = 1 << NSOtherMouseDown as libc::c_ulonglong; 2031 | const NSOtherMouseUpMask = 1 << NSOtherMouseUp as libc::c_ulonglong; 2032 | const NSOtherMouseDraggedMask = 1 << NSOtherMouseDragged as libc::c_ulonglong; 2033 | const NSEventMaskGesture = 1 << NSEventTypeGesture as libc::c_ulonglong; 2034 | const NSEventMaskSwipe = 1 << NSEventTypeSwipe as libc::c_ulonglong; 2035 | const NSEventMaskRotate = 1 << NSEventTypeRotate as libc::c_ulonglong; 2036 | const NSEventMaskBeginGesture = 1 << NSEventTypeBeginGesture as libc::c_ulonglong; 2037 | const NSEventMaskEndGesture = 1 << NSEventTypeEndGesture as libc::c_ulonglong; 2038 | const NSEventMaskPressure = 1 << NSEventTypePressure as libc::c_ulonglong; 2039 | const NSAnyEventMask = 0xffffffffffffffff; 2040 | } 2041 | } 2042 | 2043 | impl NSEventMask { 2044 | pub fn from_type(ty: NSEventType) -> NSEventMask { 2045 | NSEventMask { bits: 1 << ty as libc::c_ulonglong } 2046 | } 2047 | } 2048 | 2049 | bitflags! { 2050 | pub struct NSEventModifierFlags: NSUInteger { 2051 | const NSAlphaShiftKeyMask = 1 << 16; 2052 | const NSShiftKeyMask = 1 << 17; 2053 | const NSControlKeyMask = 1 << 18; 2054 | const NSAlternateKeyMask = 1 << 19; 2055 | const NSCommandKeyMask = 1 << 20; 2056 | const NSNumericPadKeyMask = 1 << 21; 2057 | const NSHelpKeyMask = 1 << 22; 2058 | const NSFunctionKeyMask = 1 << 23; 2059 | const NSDeviceIndependentModifierFlagsMask = 0xffff0000; 2060 | } 2061 | } 2062 | 2063 | // Not sure of the type here 2064 | pub enum NSPointingDeviceType { 2065 | // TODO: Not sure what these values are 2066 | // NSUnknownPointingDevice = NX_TABLET_POINTER_UNKNOWN, 2067 | // NSPenPointingDevice = NX_TABLET_POINTER_PEN, 2068 | // NSCursorPointingDevice = NX_TABLET_POINTER_CURSOR, 2069 | // NSEraserPointingDevice = NX_TABLET_POINTER_ERASER, 2070 | } 2071 | 2072 | // Not sure of the type here 2073 | pub enum NSEventButtonMask { 2074 | // TODO: Not sure what these values are 2075 | // NSPenTipMask = NX_TABLET_BUTTON_PENTIPMASK, 2076 | // NSPenLowerSideMask = NX_TABLET_BUTTON_PENLOWERSIDEMASK, 2077 | // NSPenUpperSideMask = NX_TABLET_BUTTON_PENUPPERSIDEMASK, 2078 | } 2079 | 2080 | #[repr(i16)] 2081 | pub enum NSEventSubtype { 2082 | // TODO: Not sure what these values are 2083 | // NSMouseEventSubtype = NX_SUBTYPE_DEFAULT, 2084 | // NSTabletPointEventSubtype = NX_SUBTYPE_TABLET_POINT, 2085 | // NSTabletProximityEventSubtype = NX_SUBTYPE_TABLET_PROXIMITY 2086 | // NSTouchEventSubtype = NX_SUBTYPE_MOUSE_TOUCH, 2087 | NSWindowExposedEventType = 0, 2088 | NSApplicationActivatedEventType = 1, 2089 | NSApplicationDeactivatedEventType = 2, 2090 | NSWindowMovedEventType = 4, 2091 | NSScreenChangedEventType = 8, 2092 | NSAWTEventType = 16, 2093 | } 2094 | 2095 | pub const NSUpArrowFunctionKey: libc::c_ushort = 0xF700; 2096 | pub const NSDownArrowFunctionKey: libc::c_ushort = 0xF701; 2097 | pub const NSLeftArrowFunctionKey: libc::c_ushort = 0xF702; 2098 | pub const NSRightArrowFunctionKey: libc::c_ushort = 0xF703; 2099 | pub const NSF1FunctionKey: libc::c_ushort = 0xF704; 2100 | pub const NSF2FunctionKey: libc::c_ushort = 0xF705; 2101 | pub const NSF3FunctionKey: libc::c_ushort = 0xF706; 2102 | pub const NSF4FunctionKey: libc::c_ushort = 0xF707; 2103 | pub const NSF5FunctionKey: libc::c_ushort = 0xF708; 2104 | pub const NSF6FunctionKey: libc::c_ushort = 0xF709; 2105 | pub const NSF7FunctionKey: libc::c_ushort = 0xF70A; 2106 | pub const NSF8FunctionKey: libc::c_ushort = 0xF70B; 2107 | pub const NSF9FunctionKey: libc::c_ushort = 0xF70C; 2108 | pub const NSF10FunctionKey: libc::c_ushort = 0xF70D; 2109 | pub const NSF11FunctionKey: libc::c_ushort = 0xF70E; 2110 | pub const NSF12FunctionKey: libc::c_ushort = 0xF70F; 2111 | pub const NSF13FunctionKey: libc::c_ushort = 0xF710; 2112 | pub const NSF14FunctionKey: libc::c_ushort = 0xF711; 2113 | pub const NSF15FunctionKey: libc::c_ushort = 0xF712; 2114 | pub const NSF16FunctionKey: libc::c_ushort = 0xF713; 2115 | pub const NSF17FunctionKey: libc::c_ushort = 0xF714; 2116 | pub const NSF18FunctionKey: libc::c_ushort = 0xF715; 2117 | pub const NSF19FunctionKey: libc::c_ushort = 0xF716; 2118 | pub const NSF20FunctionKey: libc::c_ushort = 0xF717; 2119 | pub const NSF21FunctionKey: libc::c_ushort = 0xF718; 2120 | pub const NSF22FunctionKey: libc::c_ushort = 0xF719; 2121 | pub const NSF23FunctionKey: libc::c_ushort = 0xF71A; 2122 | pub const NSF24FunctionKey: libc::c_ushort = 0xF71B; 2123 | pub const NSF25FunctionKey: libc::c_ushort = 0xF71C; 2124 | pub const NSF26FunctionKey: libc::c_ushort = 0xF71D; 2125 | pub const NSF27FunctionKey: libc::c_ushort = 0xF71E; 2126 | pub const NSF28FunctionKey: libc::c_ushort = 0xF71F; 2127 | pub const NSF29FunctionKey: libc::c_ushort = 0xF720; 2128 | pub const NSF30FunctionKey: libc::c_ushort = 0xF721; 2129 | pub const NSF31FunctionKey: libc::c_ushort = 0xF722; 2130 | pub const NSF32FunctionKey: libc::c_ushort = 0xF723; 2131 | pub const NSF33FunctionKey: libc::c_ushort = 0xF724; 2132 | pub const NSF34FunctionKey: libc::c_ushort = 0xF725; 2133 | pub const NSF35FunctionKey: libc::c_ushort = 0xF726; 2134 | pub const NSInsertFunctionKey: libc::c_ushort = 0xF727; 2135 | pub const NSDeleteFunctionKey: libc::c_ushort = 0xF728; 2136 | pub const NSHomeFunctionKey: libc::c_ushort = 0xF729; 2137 | pub const NSBeginFunctionKey: libc::c_ushort = 0xF72A; 2138 | pub const NSEndFunctionKey: libc::c_ushort = 0xF72B; 2139 | pub const NSPageUpFunctionKey: libc::c_ushort = 0xF72C; 2140 | pub const NSPageDownFunctionKey: libc::c_ushort = 0xF72D; 2141 | pub const NSPrintScreenFunctionKey: libc::c_ushort = 0xF72E; 2142 | pub const NSScrollLockFunctionKey: libc::c_ushort = 0xF72F; 2143 | pub const NSPauseFunctionKey: libc::c_ushort = 0xF730; 2144 | pub const NSSysReqFunctionKey: libc::c_ushort = 0xF731; 2145 | pub const NSBreakFunctionKey: libc::c_ushort = 0xF732; 2146 | pub const NSResetFunctionKey: libc::c_ushort = 0xF733; 2147 | pub const NSStopFunctionKey: libc::c_ushort = 0xF734; 2148 | pub const NSMenuFunctionKey: libc::c_ushort = 0xF735; 2149 | pub const NSUserFunctionKey: libc::c_ushort = 0xF736; 2150 | pub const NSSystemFunctionKey: libc::c_ushort = 0xF737; 2151 | pub const NSPrintFunctionKey: libc::c_ushort = 0xF738; 2152 | pub const NSClearLineFunctionKey: libc::c_ushort = 0xF739; 2153 | pub const NSClearDisplayFunctionKey: libc::c_ushort = 0xF73A; 2154 | pub const NSInsertLineFunctionKey: libc::c_ushort = 0xF73B; 2155 | pub const NSDeleteLineFunctionKey: libc::c_ushort = 0xF73C; 2156 | pub const NSInsertCharFunctionKey: libc::c_ushort = 0xF73D; 2157 | pub const NSDeleteCharFunctionKey: libc::c_ushort = 0xF73E; 2158 | pub const NSPrevFunctionKey: libc::c_ushort = 0xF73F; 2159 | pub const NSNextFunctionKey: libc::c_ushort = 0xF740; 2160 | pub const NSSelectFunctionKey: libc::c_ushort = 0xF741; 2161 | pub const NSExecuteFunctionKey: libc::c_ushort = 0xF742; 2162 | pub const NSUndoFunctionKey: libc::c_ushort = 0xF743; 2163 | pub const NSRedoFunctionKey: libc::c_ushort = 0xF744; 2164 | pub const NSFindFunctionKey: libc::c_ushort = 0xF745; 2165 | pub const NSHelpFunctionKey: libc::c_ushort = 0xF746; 2166 | pub const NSModeSwitchFunctionKey: libc::c_ushort = 0xF747; 2167 | 2168 | pub trait NSEvent: Sized { 2169 | // Creating Events 2170 | unsafe fn keyEventWithType_location_modifierFlags_timestamp_windowNumber_context_characters_charactersIgnoringModifiers_isARepeat_keyCode_( 2171 | _: Self, 2172 | eventType: NSEventType, 2173 | location: NSPoint, 2174 | modifierFlags: NSEventModifierFlags, 2175 | timestamp: NSTimeInterval, 2176 | windowNumber: NSInteger, 2177 | context: id /* (NSGraphicsContext *) */, 2178 | characters: id /* (NSString *) */, 2179 | unmodCharacters: id /* (NSString *) */, 2180 | repeatKey: BOOL, 2181 | code: libc::c_ushort) -> id /* (NSEvent *) */; 2182 | unsafe fn mouseEventWithType_location_modifierFlags_timestamp_windowNumber_context_eventNumber_clickCount_pressure_( 2183 | _: Self, 2184 | eventType: NSEventType, 2185 | location: NSPoint, 2186 | modifierFlags: NSEventModifierFlags, 2187 | timestamp: NSTimeInterval, 2188 | windowNumber: NSInteger, 2189 | context: id /* (NSGraphicsContext *) */, 2190 | eventNumber: NSInteger, 2191 | clickCount: NSInteger, 2192 | pressure: libc::c_float) -> id /* (NSEvent *) */; 2193 | unsafe fn enterExitEventWithType_location_modifierFlags_timestamp_windowNumber_context_eventNumber_trackingNumber_userData_( 2194 | _: Self, 2195 | eventType: NSEventType, 2196 | location: NSPoint, 2197 | modifierFlags: NSEventModifierFlags, 2198 | timestamp: NSTimeInterval, 2199 | windowNumber: NSInteger, 2200 | context: id /* (NSGraphicsContext *) */, 2201 | eventNumber: NSInteger, 2202 | trackingNumber: NSInteger, 2203 | userData: *mut libc::c_void) -> id /* (NSEvent *) */; 2204 | unsafe fn otherEventWithType_location_modifierFlags_timestamp_windowNumber_context_subtype_data1_data2_( 2205 | _: Self, 2206 | eventType: NSEventType, 2207 | location: NSPoint, 2208 | modifierFlags: NSEventModifierFlags, 2209 | timestamp: NSTimeInterval, 2210 | windowNumber: NSInteger, 2211 | context: id /* (NSGraphicsContext *) */, 2212 | subtype: NSEventSubtype, 2213 | data1: NSInteger, 2214 | data2: NSInteger) -> id /* (NSEvent *) */; 2215 | unsafe fn eventWithEventRef_(_: Self, eventRef: *const libc::c_void) -> id; 2216 | unsafe fn eventWithCGEvent_(_: Self, cgEvent: *mut libc::c_void /* CGEventRef */) -> id; 2217 | 2218 | // Getting General Event Information 2219 | unsafe fn context(self) -> id /* (NSGraphicsContext *) */; 2220 | unsafe fn locationInWindow(self) -> NSPoint; 2221 | unsafe fn modifierFlags(self) -> NSEventModifierFlags; 2222 | unsafe fn timestamp(self) -> NSTimeInterval; 2223 | // NOTE: renamed from `- type` due to Rust keyword collision 2224 | unsafe fn eventType(self) -> NSEventType; 2225 | unsafe fn window(self) -> id /* (NSWindow *) */; 2226 | unsafe fn windowNumber(self) -> NSInteger; 2227 | unsafe fn eventRef(self) -> *const libc::c_void; 2228 | unsafe fn CGEvent(self) -> *mut libc::c_void /* CGEventRef */; 2229 | 2230 | // Getting Key Event Information 2231 | // NOTE: renamed from `+ modifierFlags` due to conflict with `- modifierFlags` 2232 | unsafe fn currentModifierFlags(_: Self) -> NSEventModifierFlags; 2233 | unsafe fn keyRepeatDelay(_: Self) -> NSTimeInterval; 2234 | unsafe fn keyRepeatInterval(_: Self) -> NSTimeInterval; 2235 | unsafe fn characters(self) -> id /* (NSString *) */; 2236 | unsafe fn charactersIgnoringModifiers(self) -> id /* (NSString *) */; 2237 | unsafe fn keyCode(self) -> libc::c_ushort; 2238 | 2239 | // Getting Mouse Event Information 2240 | unsafe fn pressedMouseButtons(_: Self) -> NSUInteger; 2241 | unsafe fn doubleClickInterval(_: Self) -> NSTimeInterval; 2242 | unsafe fn mouseLocation(_: Self) -> NSPoint; 2243 | unsafe fn buttonNumber(self) -> NSInteger; 2244 | unsafe fn clickCount(self) -> NSInteger; 2245 | unsafe fn pressure(self) -> libc::c_float; 2246 | unsafe fn stage(self) -> NSInteger; 2247 | unsafe fn setMouseCoalescingEnabled_(_: Self, flag: BOOL); 2248 | unsafe fn isMouseCoalescingEnabled(_: Self) -> BOOL; 2249 | 2250 | // Getting Mouse-Tracking Event Information 2251 | unsafe fn eventNumber(self) -> NSInteger; 2252 | unsafe fn trackingNumber(self) -> NSInteger; 2253 | unsafe fn trackingArea(self) -> id /* (NSTrackingArea *) */; 2254 | unsafe fn userData(self) -> *const libc::c_void; 2255 | 2256 | // Getting Custom Event Information 2257 | unsafe fn data1(self) -> NSInteger; 2258 | unsafe fn data2(self) -> NSInteger; 2259 | unsafe fn subtype(self) -> NSEventSubtype; 2260 | 2261 | // Getting Scroll Wheel Event Information 2262 | unsafe fn deltaX(self) -> CGFloat; 2263 | unsafe fn deltaY(self) -> CGFloat; 2264 | unsafe fn deltaZ(self) -> CGFloat; 2265 | 2266 | // Getting Tablet Proximity Information 2267 | unsafe fn capabilityMask(self) -> NSUInteger; 2268 | unsafe fn deviceID(self) -> NSUInteger; 2269 | unsafe fn pointingDeviceID(self) -> NSUInteger; 2270 | unsafe fn pointingDeviceSerialNumber(self) -> NSUInteger; 2271 | unsafe fn pointingDeviceType(self) -> NSPointingDeviceType; 2272 | unsafe fn systemTabletID(self) -> NSUInteger; 2273 | unsafe fn tabletID(self) -> NSUInteger; 2274 | unsafe fn uniqueID(self) -> libc::c_ulonglong; 2275 | unsafe fn vendorID(self) -> NSUInteger; 2276 | unsafe fn vendorPointingDeviceType(self) -> NSUInteger; 2277 | 2278 | // Getting Tablet Pointing Information 2279 | unsafe fn absoluteX(self) -> NSInteger; 2280 | unsafe fn absoluteY(self) -> NSInteger; 2281 | unsafe fn absoluteZ(self) -> NSInteger; 2282 | unsafe fn buttonMask(self) -> NSEventButtonMask; 2283 | unsafe fn rotation(self) -> libc::c_float; 2284 | unsafe fn tangentialPressure(self) -> libc::c_float; 2285 | unsafe fn tilt(self) -> NSPoint; 2286 | unsafe fn vendorDefined(self) -> id; 2287 | 2288 | // Requesting and Stopping Periodic Events 2289 | unsafe fn startPeriodicEventsAfterDelay_withPeriod_(_: Self, delaySeconds: NSTimeInterval, periodSeconds: NSTimeInterval); 2290 | unsafe fn stopPeriodicEvents(_: Self); 2291 | 2292 | // Getting Touch and Gesture Information 2293 | unsafe fn magnification(self) -> CGFloat; 2294 | unsafe fn touchesMatchingPhase_inView_(self, phase: NSTouchPhase, view: id /* (NSView *) */) -> id /* (NSSet *) */; 2295 | unsafe fn isSwipeTrackingFromScrollEventsEnabled(_: Self) -> BOOL; 2296 | 2297 | // Monitoring Application Events 2298 | // TODO: addGlobalMonitorForEventsMatchingMask_handler_ (unsure how to bind to blocks) 2299 | // TODO: addLocalMonitorForEventsMatchingMask_handler_ (unsure how to bind to blocks) 2300 | unsafe fn removeMonitor_(_: Self, eventMonitor: id); 2301 | 2302 | // Scroll Wheel and Flick Events 2303 | unsafe fn hasPreciseScrollingDeltas(self) -> BOOL; 2304 | unsafe fn scrollingDeltaX(self) -> CGFloat; 2305 | unsafe fn scrollingDeltaY(self) -> CGFloat; 2306 | unsafe fn momentumPhase(self) -> NSEventPhase; 2307 | unsafe fn phase(self) -> NSEventPhase; 2308 | // TODO: trackSwipeEventWithOptions_dampenAmountThresholdMin_max_usingHandler_ (unsure how to bind to blocks) 2309 | 2310 | // Converting a Mouse Event’s Position into a Sprite Kit Node’s Coordinate Space 2311 | unsafe fn locationInNode_(self, node: id /* (SKNode *) */) -> CGPoint; 2312 | } 2313 | 2314 | impl NSEvent for id { 2315 | // Creating Events 2316 | 2317 | unsafe fn keyEventWithType_location_modifierFlags_timestamp_windowNumber_context_characters_charactersIgnoringModifiers_isARepeat_keyCode_( 2318 | _: Self, 2319 | eventType: NSEventType, 2320 | location: NSPoint, 2321 | modifierFlags: NSEventModifierFlags, 2322 | timestamp: NSTimeInterval, 2323 | windowNumber: NSInteger, 2324 | context: id /* (NSGraphicsContext *) */, 2325 | characters: id /* (NSString *) */, 2326 | unmodCharacters: id /* (NSString *) */, 2327 | repeatKey: BOOL, 2328 | code: libc::c_ushort) -> id /* (NSEvent *) */ 2329 | { 2330 | msg_send![class("NSEvent"), keyEventWithType:eventType 2331 | location:location 2332 | modifierFlags:modifierFlags 2333 | timestamp:timestamp 2334 | windowNumber:windowNumber 2335 | context:context 2336 | characters:characters 2337 | charactersIgnoringModifiers:unmodCharacters 2338 | isARepeat:repeatKey 2339 | keyCode:code] 2340 | } 2341 | 2342 | unsafe fn mouseEventWithType_location_modifierFlags_timestamp_windowNumber_context_eventNumber_clickCount_pressure_( 2343 | _: Self, 2344 | eventType: NSEventType, 2345 | location: NSPoint, 2346 | modifierFlags: NSEventModifierFlags, 2347 | timestamp: NSTimeInterval, 2348 | windowNumber: NSInteger, 2349 | context: id /* (NSGraphicsContext *) */, 2350 | eventNumber: NSInteger, 2351 | clickCount: NSInteger, 2352 | pressure: libc::c_float) -> id /* (NSEvent *) */ 2353 | { 2354 | msg_send![class("NSEvent"), mouseEventWithType:eventType 2355 | location:location 2356 | modifierFlags:modifierFlags 2357 | timestamp:timestamp 2358 | windowNumber:windowNumber 2359 | context:context 2360 | eventNumber:eventNumber 2361 | clickCount:clickCount 2362 | pressure:pressure] 2363 | } 2364 | 2365 | unsafe fn enterExitEventWithType_location_modifierFlags_timestamp_windowNumber_context_eventNumber_trackingNumber_userData_( 2366 | _: Self, 2367 | eventType: NSEventType, 2368 | location: NSPoint, 2369 | modifierFlags: NSEventModifierFlags, 2370 | timestamp: NSTimeInterval, 2371 | windowNumber: NSInteger, 2372 | context: id /* (NSGraphicsContext *) */, 2373 | eventNumber: NSInteger, 2374 | trackingNumber: NSInteger, 2375 | userData: *mut libc::c_void) -> id /* (NSEvent *) */ 2376 | { 2377 | msg_send![class("NSEvent"), enterExitEventWithType:eventType 2378 | location:location 2379 | modifierFlags:modifierFlags 2380 | timestamp:timestamp 2381 | windowNumber:windowNumber 2382 | context:context 2383 | eventNumber:eventNumber 2384 | trackingNumber:trackingNumber 2385 | userData:userData] 2386 | } 2387 | 2388 | unsafe fn otherEventWithType_location_modifierFlags_timestamp_windowNumber_context_subtype_data1_data2_( 2389 | _: Self, 2390 | eventType: NSEventType, 2391 | location: NSPoint, 2392 | modifierFlags: NSEventModifierFlags, 2393 | timestamp: NSTimeInterval, 2394 | windowNumber: NSInteger, 2395 | context: id /* (NSGraphicsContext *) */, 2396 | subtype: NSEventSubtype, 2397 | data1: NSInteger, 2398 | data2: NSInteger) -> id /* (NSEvent *) */ 2399 | { 2400 | msg_send![class("NSEvent"), otherEventWithType:eventType 2401 | location:location 2402 | modifierFlags:modifierFlags 2403 | timestamp:timestamp 2404 | windowNumber:windowNumber 2405 | context:context 2406 | subtype:subtype 2407 | data1:data1 2408 | data2:data2] 2409 | } 2410 | 2411 | unsafe fn eventWithEventRef_(_: Self, eventRef: *const libc::c_void) -> id { 2412 | msg_send![class("NSEvent"), eventWithEventRef:eventRef] 2413 | } 2414 | 2415 | unsafe fn eventWithCGEvent_(_: Self, cgEvent: *mut libc::c_void /* CGEventRef */) -> id { 2416 | msg_send![class("NSEvent"), eventWithCGEvent:cgEvent] 2417 | } 2418 | 2419 | // Getting General Event Information 2420 | 2421 | unsafe fn context(self) -> id /* (NSGraphicsContext *) */ { 2422 | msg_send![self, context] 2423 | } 2424 | 2425 | unsafe fn locationInWindow(self) -> NSPoint { 2426 | msg_send![self, locationInWindow] 2427 | } 2428 | 2429 | unsafe fn modifierFlags(self) -> NSEventModifierFlags { 2430 | msg_send![self, modifierFlags] 2431 | } 2432 | 2433 | unsafe fn timestamp(self) -> NSTimeInterval { 2434 | msg_send![self, timestamp] 2435 | } 2436 | // NOTE: renamed from `- type` due to Rust keyword collision 2437 | 2438 | unsafe fn eventType(self) -> NSEventType { 2439 | msg_send![self, type] 2440 | } 2441 | 2442 | unsafe fn window(self) -> id /* (NSWindow *) */ { 2443 | msg_send![self, window] 2444 | } 2445 | 2446 | unsafe fn windowNumber(self) -> NSInteger { 2447 | msg_send![self, windowNumber] 2448 | } 2449 | 2450 | unsafe fn eventRef(self) -> *const libc::c_void { 2451 | msg_send![self, eventRef] 2452 | } 2453 | 2454 | unsafe fn CGEvent(self) -> *mut libc::c_void /* CGEventRef */ { 2455 | msg_send![self, CGEvent] 2456 | } 2457 | 2458 | // Getting Key Event Information 2459 | 2460 | // NOTE: renamed from `+ modifierFlags` due to conflict with `- modifierFlags` 2461 | 2462 | unsafe fn currentModifierFlags(_: Self) -> NSEventModifierFlags { 2463 | msg_send![class("NSEvent"), currentModifierFlags] 2464 | } 2465 | 2466 | unsafe fn keyRepeatDelay(_: Self) -> NSTimeInterval { 2467 | msg_send![class("NSEvent"), keyRepeatDelay] 2468 | } 2469 | 2470 | unsafe fn keyRepeatInterval(_: Self) -> NSTimeInterval { 2471 | msg_send![class("NSEvent"), keyRepeatInterval] 2472 | } 2473 | 2474 | unsafe fn characters(self) -> id /* (NSString *) */ { 2475 | msg_send![self, characters] 2476 | } 2477 | 2478 | unsafe fn charactersIgnoringModifiers(self) -> id /* (NSString *) */ { 2479 | msg_send![self, charactersIgnoringModifiers] 2480 | } 2481 | 2482 | unsafe fn keyCode(self) -> libc::c_ushort { 2483 | msg_send![self, keyCode] 2484 | } 2485 | 2486 | // Getting Mouse Event Information 2487 | 2488 | unsafe fn pressedMouseButtons(_: Self) -> NSUInteger { 2489 | msg_send![class("NSEvent"), pressedMouseButtons] 2490 | } 2491 | 2492 | unsafe fn doubleClickInterval(_: Self) -> NSTimeInterval { 2493 | msg_send![class("NSEvent"), doubleClickInterval] 2494 | } 2495 | 2496 | unsafe fn mouseLocation(_: Self) -> NSPoint { 2497 | msg_send![class("NSEvent"), mouseLocation] 2498 | } 2499 | 2500 | unsafe fn buttonNumber(self) -> NSInteger { 2501 | msg_send![self, buttonNumber] 2502 | } 2503 | 2504 | unsafe fn clickCount(self) -> NSInteger { 2505 | msg_send![self, clickCount] 2506 | } 2507 | 2508 | unsafe fn pressure(self) -> libc::c_float { 2509 | msg_send![self, pressure] 2510 | } 2511 | 2512 | unsafe fn stage(self) -> NSInteger{ 2513 | msg_send![self, stage] 2514 | } 2515 | 2516 | unsafe fn setMouseCoalescingEnabled_(_: Self, flag: BOOL) { 2517 | msg_send![class("NSEvent"), setMouseCoalescingEnabled:flag] 2518 | } 2519 | 2520 | unsafe fn isMouseCoalescingEnabled(_: Self) -> BOOL { 2521 | msg_send![class("NSEvent"), isMouseCoalescingEnabled] 2522 | } 2523 | 2524 | // Getting Mouse-Tracking Event Information 2525 | 2526 | unsafe fn eventNumber(self) -> NSInteger { 2527 | msg_send![self, eventNumber] 2528 | } 2529 | 2530 | unsafe fn trackingNumber(self) -> NSInteger { 2531 | msg_send![self, trackingNumber] 2532 | } 2533 | 2534 | unsafe fn trackingArea(self) -> id /* (NSTrackingArea *) */ { 2535 | msg_send![self, trackingArea] 2536 | } 2537 | 2538 | unsafe fn userData(self) -> *const libc::c_void { 2539 | msg_send![self, userData] 2540 | } 2541 | 2542 | // Getting Custom Event Information 2543 | 2544 | unsafe fn data1(self) -> NSInteger { 2545 | msg_send![self, data1] 2546 | } 2547 | 2548 | unsafe fn data2(self) -> NSInteger { 2549 | msg_send![self, data2] 2550 | } 2551 | 2552 | unsafe fn subtype(self) -> NSEventSubtype { 2553 | msg_send![self, subtype] 2554 | } 2555 | 2556 | // Getting Scroll Wheel Event Information 2557 | 2558 | unsafe fn deltaX(self) -> CGFloat { 2559 | msg_send![self, deltaX] 2560 | } 2561 | 2562 | unsafe fn deltaY(self) -> CGFloat { 2563 | msg_send![self, deltaY] 2564 | } 2565 | 2566 | unsafe fn deltaZ(self) -> CGFloat { 2567 | msg_send![self, deltaZ] 2568 | } 2569 | 2570 | // Getting Tablet Proximity Information 2571 | 2572 | unsafe fn capabilityMask(self) -> NSUInteger { 2573 | msg_send![self, capabilityMask] 2574 | } 2575 | 2576 | unsafe fn deviceID(self) -> NSUInteger { 2577 | msg_send![self, deviceID] 2578 | } 2579 | 2580 | unsafe fn pointingDeviceID(self) -> NSUInteger { 2581 | msg_send![self, pointingDeviceID] 2582 | } 2583 | 2584 | unsafe fn pointingDeviceSerialNumber(self) -> NSUInteger { 2585 | msg_send![self, pointingDeviceSerialNumber] 2586 | } 2587 | 2588 | unsafe fn pointingDeviceType(self) -> NSPointingDeviceType { 2589 | msg_send![self, pointingDeviceType] 2590 | } 2591 | 2592 | unsafe fn systemTabletID(self) -> NSUInteger { 2593 | msg_send![self, systemTabletID] 2594 | } 2595 | 2596 | unsafe fn tabletID(self) -> NSUInteger { 2597 | msg_send![self, tabletID] 2598 | } 2599 | 2600 | unsafe fn uniqueID(self) -> libc::c_ulonglong { 2601 | msg_send![self, uniqueID] 2602 | } 2603 | 2604 | unsafe fn vendorID(self) -> NSUInteger { 2605 | msg_send![self, vendorID] 2606 | } 2607 | 2608 | unsafe fn vendorPointingDeviceType(self) -> NSUInteger { 2609 | msg_send![self, vendorPointingDeviceType] 2610 | } 2611 | 2612 | // Getting Tablet Pointing Information 2613 | 2614 | unsafe fn absoluteX(self) -> NSInteger { 2615 | msg_send![self, absoluteX] 2616 | } 2617 | 2618 | unsafe fn absoluteY(self) -> NSInteger { 2619 | msg_send![self, absoluteY] 2620 | } 2621 | 2622 | unsafe fn absoluteZ(self) -> NSInteger { 2623 | msg_send![self, absoluteZ] 2624 | } 2625 | 2626 | unsafe fn buttonMask(self) -> NSEventButtonMask { 2627 | msg_send![self, buttonMask] 2628 | } 2629 | 2630 | unsafe fn rotation(self) -> libc::c_float { 2631 | msg_send![self, rotation] 2632 | } 2633 | 2634 | unsafe fn tangentialPressure(self) -> libc::c_float { 2635 | msg_send![self, tangentialPressure] 2636 | } 2637 | 2638 | unsafe fn tilt(self) -> NSPoint { 2639 | msg_send![self, tilt] 2640 | } 2641 | 2642 | unsafe fn vendorDefined(self) -> id { 2643 | msg_send![self, vendorDefined] 2644 | } 2645 | 2646 | // Requesting and Stopping Periodic Events 2647 | 2648 | unsafe fn startPeriodicEventsAfterDelay_withPeriod_(_: Self, delaySeconds: NSTimeInterval, periodSeconds: NSTimeInterval) { 2649 | msg_send![class("NSEvent"), startPeriodicEventsAfterDelay:delaySeconds withPeriod:periodSeconds] 2650 | } 2651 | 2652 | unsafe fn stopPeriodicEvents(_: Self) { 2653 | msg_send![class("NSEvent"), stopPeriodicEvents] 2654 | } 2655 | 2656 | // Getting Touch and Gesture Information 2657 | 2658 | unsafe fn magnification(self) -> CGFloat { 2659 | msg_send![self, magnification] 2660 | } 2661 | 2662 | unsafe fn touchesMatchingPhase_inView_(self, phase: NSTouchPhase, view: id /* (NSView *) */) -> id /* (NSSet *) */ { 2663 | msg_send![self, touchesMatchingPhase:phase inView:view] 2664 | } 2665 | 2666 | unsafe fn isSwipeTrackingFromScrollEventsEnabled(_: Self) -> BOOL { 2667 | msg_send![class("NSEvent"), isSwipeTrackingFromScrollEventsEnabled] 2668 | } 2669 | 2670 | // Monitoring Application Events 2671 | 2672 | // TODO: addGlobalMonitorForEventsMatchingMask_handler_ (unsure how to bind to blocks) 2673 | // TODO: addLocalMonitorForEventsMatchingMask_handler_ (unsure how to bind to blocks) 2674 | 2675 | unsafe fn removeMonitor_(_: Self, eventMonitor: id) { 2676 | msg_send![class("NSEvent"), removeMonitor:eventMonitor] 2677 | } 2678 | 2679 | // Scroll Wheel and Flick Events 2680 | 2681 | unsafe fn hasPreciseScrollingDeltas(self) -> BOOL { 2682 | msg_send![self, hasPreciseScrollingDeltas] 2683 | } 2684 | 2685 | unsafe fn scrollingDeltaX(self) -> CGFloat { 2686 | msg_send![self, scrollingDeltaX] 2687 | } 2688 | 2689 | unsafe fn scrollingDeltaY(self) -> CGFloat { 2690 | msg_send![self, scrollingDeltaY] 2691 | } 2692 | 2693 | unsafe fn momentumPhase(self) -> NSEventPhase { 2694 | msg_send![self, momentumPhase] 2695 | } 2696 | 2697 | unsafe fn phase(self) -> NSEventPhase { 2698 | msg_send![self, phase] 2699 | } 2700 | 2701 | // TODO: trackSwipeEventWithOptions_dampenAmountThresholdMin_max_usingHandler_ (unsure how to bind to blocks) 2702 | 2703 | // Converting a Mouse Event’s Position into a Sprite Kit Node’s Coordinate Space 2704 | unsafe fn locationInNode_(self, node: id /* (SKNode *) */) -> CGPoint { 2705 | msg_send![self, locationInNode:node] 2706 | } 2707 | } 2708 | 2709 | pub trait NSScreen: Sized { 2710 | // Getting NSScreen Objects 2711 | unsafe fn mainScreen(_: Self) -> id /* (NSScreen *) */; 2712 | unsafe fn deepestScreen(_: Self) -> id /* (NSScreen *) */; 2713 | unsafe fn screens(_: Self) -> id /* (NSArray *) */; 2714 | 2715 | // Getting Screen Information 2716 | unsafe fn depth(self) -> NSWindowDepth; 2717 | unsafe fn frame(self) -> NSRect; 2718 | unsafe fn supportedWindowDepths(self) -> *const NSWindowDepth; 2719 | unsafe fn deviceDescription(self) -> id /* (NSDictionary *) */; 2720 | unsafe fn visibleFrame(self) -> NSRect; 2721 | unsafe fn colorSpace(self) -> id /* (NSColorSpace *) */; 2722 | unsafe fn screensHaveSeparateSpaces(_: Self) -> BOOL; 2723 | 2724 | // Screen Backing Coordinate Conversion 2725 | unsafe fn backingAlignedRect_options_(self, aRect: NSRect, options: NSAlignmentOptions) -> NSRect; 2726 | unsafe fn backingScaleFactor(self) -> CGFloat; 2727 | unsafe fn convertRectFromBacking_(self, aRect: NSRect) -> NSRect; 2728 | unsafe fn convertRectToBacking_(self, aRect: NSRect) -> NSRect; 2729 | } 2730 | 2731 | impl NSScreen for id { 2732 | // Getting NSScreen Objects 2733 | 2734 | unsafe fn mainScreen(_: Self) -> id /* (NSScreen *) */ { 2735 | msg_send![class("NSScreen"), mainScreen] 2736 | } 2737 | 2738 | unsafe fn deepestScreen(_: Self) -> id /* (NSScreen *) */ { 2739 | msg_send![class("NSScreen"), deepestScreen] 2740 | } 2741 | 2742 | unsafe fn screens(_: Self) -> id /* (NSArray *) */ { 2743 | msg_send![class("NSScreen"), screens] 2744 | } 2745 | 2746 | // Getting Screen Information 2747 | 2748 | unsafe fn depth(self) -> NSWindowDepth { 2749 | msg_send![self, depth] 2750 | } 2751 | 2752 | unsafe fn frame(self) -> NSRect { 2753 | msg_send![self, frame] 2754 | } 2755 | 2756 | unsafe fn supportedWindowDepths(self) -> *const NSWindowDepth { 2757 | msg_send![self, supportedWindowDepths] 2758 | } 2759 | 2760 | unsafe fn deviceDescription(self) -> id /* (NSDictionary *) */ { 2761 | msg_send![self, deviceDescription] 2762 | } 2763 | 2764 | unsafe fn visibleFrame(self) -> NSRect { 2765 | msg_send![self, visibleFrame] 2766 | } 2767 | 2768 | unsafe fn colorSpace(self) -> id /* (NSColorSpace *) */ { 2769 | msg_send![self, colorSpace] 2770 | } 2771 | 2772 | unsafe fn screensHaveSeparateSpaces(_: Self) -> BOOL { 2773 | msg_send![class("NSScreen"), screensHaveSeparateSpaces] 2774 | } 2775 | 2776 | // Screen Backing Coordinate Conversion 2777 | 2778 | unsafe fn backingAlignedRect_options_(self, aRect: NSRect, options: NSAlignmentOptions) -> NSRect { 2779 | msg_send![self, backingAlignedRect:aRect options:options] 2780 | } 2781 | 2782 | unsafe fn backingScaleFactor(self) -> CGFloat { 2783 | msg_send![self, backingScaleFactor] 2784 | } 2785 | 2786 | unsafe fn convertRectFromBacking_(self, aRect: NSRect) -> NSRect { 2787 | msg_send![self, convertRectFromBacking:aRect] 2788 | } 2789 | 2790 | unsafe fn convertRectToBacking_(self, aRect: NSRect) -> NSRect { 2791 | msg_send![self, convertRectToBacking:aRect] 2792 | } 2793 | } 2794 | 2795 | pub trait NSButton: Sized { 2796 | unsafe fn setImage_(self, img: id /* (NSImage *) */); 2797 | unsafe fn setBezelStyle_(self, style: NSBezelStyle); 2798 | unsafe fn setTitle_(self, title: id /* (NSString*) */); 2799 | unsafe fn alloc(_: Self) -> id { 2800 | msg_send![class("NSButton"), alloc] 2801 | } 2802 | unsafe fn initWithFrame_(self, frameRect: NSRect) -> id; 2803 | } 2804 | 2805 | impl NSButton for id { 2806 | unsafe fn initWithFrame_(self, frameRect: NSRect) -> id { 2807 | msg_send![self, initWithFrame:frameRect] 2808 | } 2809 | unsafe fn setBezelStyle_(self, style: NSBezelStyle) { 2810 | msg_send![self, setBezelStyle:style]; 2811 | } 2812 | unsafe fn setTitle_(self, title: id /* (NSString*) */) { 2813 | msg_send![self, setTitle:title] 2814 | } 2815 | unsafe fn setImage_(self, img: id /* (NSImage *) */) { 2816 | msg_send![self, setImage:img] 2817 | } 2818 | } 2819 | 2820 | pub trait NSImage: Sized { 2821 | unsafe fn alloc(_: Self) -> id { 2822 | msg_send![class("NSImage"), alloc] 2823 | } 2824 | 2825 | unsafe fn initByReferencingFile_(self, file_name: id /* (NSString *) */) -> id; 2826 | unsafe fn initWithContentsOfFile_(self, file_name: id /* (NSString *) */) -> id; 2827 | unsafe fn initWithData_(self, data: id /* (NSData *) */) -> id; 2828 | unsafe fn initWithDataIgnoringOrientation_(self, data: id /* (NSData *) */) -> id; 2829 | unsafe fn initWithPasteboard_(self, pasteboard: id /* (NSPasteboard *) */) -> id; 2830 | unsafe fn initWithSize_flipped_drawingHandler_(self, size: NSSize, 2831 | drawingHandlerShouldBeCalledWithFlippedContext: BOOL, 2832 | drawingHandler: *mut Block<(NSRect,), BOOL>); 2833 | unsafe fn initWithSize_(self, aSize: NSSize) -> id; 2834 | 2835 | unsafe fn imageNamed_(_: Self, name: id /* (NSString *) */) -> id { 2836 | msg_send![class("NSImage"), imageNamed:name] 2837 | } 2838 | 2839 | unsafe fn name(self) -> id /* (NSString *) */; 2840 | unsafe fn setName_(self, name: id /* (NSString *) */) -> BOOL; 2841 | 2842 | unsafe fn size(self) -> NSSize; 2843 | unsafe fn template(self) -> BOOL; 2844 | 2845 | unsafe fn canInitWithPasteboard_(self, pasteboard: id /* (NSPasteboard *) */) -> BOOL; 2846 | unsafe fn imageTypes(self) -> id /* (NSArray ) */; 2847 | unsafe fn imageUnfilteredTypes(self) -> id /* (NSArray ) */; 2848 | 2849 | unsafe fn addRepresentation_(self, imageRep: id /* (NSImageRep *) */); 2850 | unsafe fn addRepresentations_(self, imageReps: id /* (NSArray *) */); 2851 | unsafe fn representations(self) -> id /* (NSArray *) */; 2852 | unsafe fn removeRepresentation_(self, imageRep: id /* (NSImageRep *) */); 2853 | unsafe fn bestRepresentationForRect_context_hints_(self, rect: NSRect, 2854 | referenceContext: id /* (NSGraphicsContext *) */, 2855 | hints: id /* (NSDictionary *) */) 2856 | -> id /* (NSImageRep *) */; 2857 | unsafe fn prefersColorMatch(self) -> BOOL; 2858 | unsafe fn usesEPSOnResolutionMismatch(self) -> BOOL; 2859 | unsafe fn matchesOnMultipleResolution(self) -> BOOL; 2860 | 2861 | unsafe fn drawInRect_(self, rect: NSRect); 2862 | unsafe fn drawAtPoint_fromRect_operation_fraction_(self, point: NSPoint, srcRect: NSRect, 2863 | op: NSCompositingOperation, delta: CGFloat); 2864 | unsafe fn drawInRect_fromRect_operation_fraction_(self, dstRect: NSRect, srcRect: NSRect, 2865 | op: NSCompositingOperation, delta: CGFloat); 2866 | unsafe fn drawInRect_fromRect_operation_fraction_respectFlipped_hints_(self, dstSpacePortionRect: NSRect, 2867 | srcSpacePortionRect: NSRect, op: NSCompositingOperation, delta: CGFloat, respectContextIsFlipped: BOOL, 2868 | hints: id /* (NSDictionary *) */); 2869 | unsafe fn drawRepresentation_inRect_(self, imageRep: id /* (NSImageRep *) */, dstRect: NSRect); 2870 | 2871 | unsafe fn isValid(self) -> BOOL; 2872 | unsafe fn backgroundColor(self) -> id /* (NSColor *) */; 2873 | 2874 | unsafe fn lockFocus(self); 2875 | unsafe fn lockFocusFlipped_(self, flipped: BOOL); 2876 | unsafe fn unlockFocus(self); 2877 | 2878 | unsafe fn alignmentRect(self) -> NSRect; 2879 | 2880 | unsafe fn cacheMode(self) -> NSImageCacheMode; 2881 | unsafe fn recache(self); 2882 | 2883 | unsafe fn delegate(self) -> id /* (id *) */; 2884 | 2885 | unsafe fn TIFFRepresentation(self) -> id /* (NSData *) */; 2886 | unsafe fn TIFFRepresentationUsingCompression_factor_(self, comp: NSTIFFCompression, aFloat: f32) 2887 | -> id /* (NSData *) */; 2888 | 2889 | unsafe fn cancelIncrementalLoad(self); 2890 | 2891 | unsafe fn hitTestRect_withImageDestinationRect_context_hints_flipped_(self, testRectDestSpace: NSRect, 2892 | imageRectDestSpace: NSRect, referenceContext: id /* (NSGraphicsContext *) */, 2893 | hints: id /* (NSDictionary *) */, flipped: BOOL) -> BOOL; 2894 | 2895 | unsafe fn accessibilityDescription(self) -> id /* (NSString *) */; 2896 | 2897 | unsafe fn layerContentsForContentsScale_(self, layerContentsScale: CGFloat) -> id /* (id) */; 2898 | unsafe fn recommendedLayerContentsScale_(self, preferredContentsScale: CGFloat) -> CGFloat; 2899 | 2900 | unsafe fn matchesOnlyOnBestFittingAxis(self) -> BOOL; 2901 | } 2902 | 2903 | impl NSImage for id { 2904 | unsafe fn initByReferencingFile_(self, file_name: id /* (NSString *) */) -> id { 2905 | msg_send![self, initByReferencingFile:file_name] 2906 | } 2907 | 2908 | unsafe fn initWithContentsOfFile_(self, file_name: id /* (NSString *) */) -> id { 2909 | msg_send![self, initWithContentsOfFile:file_name] 2910 | } 2911 | 2912 | unsafe fn initWithData_(self, data: id /* (NSData *) */) -> id { 2913 | msg_send![self, initWithData:data] 2914 | } 2915 | 2916 | unsafe fn initWithDataIgnoringOrientation_(self, data: id /* (NSData *) */) -> id { 2917 | msg_send![self, initWithDataIgnoringOrientation:data] 2918 | } 2919 | 2920 | unsafe fn initWithPasteboard_(self, pasteboard: id /* (NSPasteboard *) */) -> id { 2921 | msg_send![self, initWithPasteboard:pasteboard] 2922 | } 2923 | 2924 | unsafe fn initWithSize_flipped_drawingHandler_(self, size: NSSize, 2925 | drawingHandlerShouldBeCalledWithFlippedContext: BOOL, 2926 | drawingHandler: *mut Block<(NSRect,), BOOL>) { 2927 | msg_send![self, initWithSize:size 2928 | flipped:drawingHandlerShouldBeCalledWithFlippedContext 2929 | drawingHandler:drawingHandler] 2930 | } 2931 | 2932 | unsafe fn initWithSize_(self, aSize: NSSize) -> id { 2933 | msg_send![self, initWithSize:aSize] 2934 | } 2935 | 2936 | unsafe fn name(self) -> id /* (NSString *) */ { 2937 | msg_send![self, name] 2938 | } 2939 | 2940 | unsafe fn setName_(self, name: id /* (NSString *) */) -> BOOL { 2941 | msg_send![self, setName:name] 2942 | } 2943 | 2944 | unsafe fn size(self) -> NSSize { 2945 | msg_send![self, size] 2946 | } 2947 | 2948 | unsafe fn template(self) -> BOOL { 2949 | msg_send![self, template] 2950 | } 2951 | 2952 | unsafe fn canInitWithPasteboard_(self, pasteboard: id /* (NSPasteboard *) */) -> BOOL { 2953 | msg_send![self, canInitWithPasteboard:pasteboard] 2954 | } 2955 | 2956 | unsafe fn imageTypes(self) -> id /* (NSArray ) */ { 2957 | msg_send![self, imageTypes] 2958 | } 2959 | 2960 | unsafe fn imageUnfilteredTypes(self) -> id /* (NSArray ) */ { 2961 | msg_send![self, imageUnfilteredTypes] 2962 | } 2963 | 2964 | unsafe fn addRepresentation_(self, imageRep: id /* (NSImageRep *) */) { 2965 | msg_send![self, addRepresentation:imageRep] 2966 | } 2967 | 2968 | unsafe fn addRepresentations_(self, imageReps: id /* (NSArray *) */) { 2969 | msg_send![self, addRepresentations:imageReps] 2970 | } 2971 | 2972 | unsafe fn representations(self) -> id /* (NSArray *) */ { 2973 | msg_send![self, representations] 2974 | } 2975 | 2976 | unsafe fn removeRepresentation_(self, imageRep: id /* (NSImageRep *) */) { 2977 | msg_send![self, removeRepresentation:imageRep] 2978 | } 2979 | 2980 | unsafe fn bestRepresentationForRect_context_hints_(self, rect: NSRect, 2981 | referenceContext: id /* (NSGraphicsContext *) */, 2982 | hints: id /* (NSDictionary *) */) 2983 | -> id /* (NSImageRep *) */ { 2984 | msg_send![self, bestRepresentationForRect:rect context:referenceContext hints:hints] 2985 | } 2986 | 2987 | unsafe fn prefersColorMatch(self) -> BOOL { 2988 | msg_send![self, prefersColorMatch] 2989 | } 2990 | 2991 | unsafe fn usesEPSOnResolutionMismatch(self) -> BOOL { 2992 | msg_send![self, usesEPSOnResolutionMismatch] 2993 | } 2994 | 2995 | unsafe fn matchesOnMultipleResolution(self) -> BOOL { 2996 | msg_send![self, matchesOnMultipleResolution] 2997 | } 2998 | 2999 | unsafe fn drawInRect_(self, rect: NSRect) { 3000 | msg_send![self, drawInRect:rect] 3001 | } 3002 | 3003 | unsafe fn drawAtPoint_fromRect_operation_fraction_(self, point: NSPoint, srcRect: NSRect, 3004 | op: NSCompositingOperation, delta: CGFloat) { 3005 | msg_send![self, drawAtPoint:point fromRect:srcRect operation:op fraction:delta] 3006 | } 3007 | 3008 | unsafe fn drawInRect_fromRect_operation_fraction_(self, dstRect: NSRect, srcRect: NSRect, 3009 | op: NSCompositingOperation, delta: CGFloat) { 3010 | msg_send![self, drawInRect:dstRect fromRect:srcRect operation:op fraction:delta] 3011 | } 3012 | 3013 | unsafe fn drawInRect_fromRect_operation_fraction_respectFlipped_hints_(self, dstSpacePortionRect: NSRect, 3014 | srcSpacePortionRect: NSRect, op: NSCompositingOperation, delta: CGFloat, respectContextIsFlipped: BOOL, 3015 | hints: id /* (NSDictionary *) */) { 3016 | msg_send![self, drawInRect:dstSpacePortionRect 3017 | fromRect:srcSpacePortionRect 3018 | operation:op 3019 | fraction:delta 3020 | respectFlipped:respectContextIsFlipped 3021 | hints:hints] 3022 | } 3023 | 3024 | unsafe fn drawRepresentation_inRect_(self, imageRep: id /* (NSImageRep *) */, dstRect: NSRect) { 3025 | msg_send![self, drawRepresentation:imageRep inRect:dstRect] 3026 | } 3027 | 3028 | unsafe fn isValid(self) -> BOOL { 3029 | msg_send![self, isValid] 3030 | } 3031 | 3032 | unsafe fn backgroundColor(self) -> id /* (NSColor *) */ { 3033 | msg_send![self, backgroundColor] 3034 | } 3035 | 3036 | unsafe fn lockFocus(self) { 3037 | msg_send![self, lockFocus] 3038 | } 3039 | 3040 | unsafe fn lockFocusFlipped_(self, flipped: BOOL) { 3041 | msg_send![self, lockFocusFlipped:flipped] 3042 | } 3043 | 3044 | unsafe fn unlockFocus(self) { 3045 | msg_send![self, unlockFocus] 3046 | } 3047 | 3048 | unsafe fn alignmentRect(self) -> NSRect { 3049 | msg_send![self, alignmentRect] 3050 | } 3051 | 3052 | unsafe fn cacheMode(self) -> NSImageCacheMode { 3053 | msg_send![self, cacheMode] 3054 | } 3055 | 3056 | unsafe fn recache(self) { 3057 | msg_send![self, recache] 3058 | } 3059 | 3060 | unsafe fn delegate(self) -> id /* (id *) */ { 3061 | msg_send![self, delegate] 3062 | } 3063 | 3064 | unsafe fn TIFFRepresentation(self) -> id /* (NSData *) */ { 3065 | msg_send![self, TIFFRepresentation] 3066 | } 3067 | 3068 | unsafe fn TIFFRepresentationUsingCompression_factor_(self, comp: NSTIFFCompression, aFloat: f32) 3069 | -> id /* (NSData *) */ { 3070 | msg_send![self, TIFFRepresentationUsingCompression:comp factor:aFloat] 3071 | } 3072 | 3073 | unsafe fn cancelIncrementalLoad(self) { 3074 | msg_send![self, cancelIncrementalLoad] 3075 | } 3076 | 3077 | unsafe fn hitTestRect_withImageDestinationRect_context_hints_flipped_(self, testRectDestSpace: NSRect, 3078 | imageRectDestSpace: NSRect, referenceContext: id /* (NSGraphicsContext *) */, 3079 | hints: id /* (NSDictionary *) */, flipped: BOOL) -> BOOL { 3080 | msg_send![self, hitTestRect:testRectDestSpace 3081 | withImageDestinationRect:imageRectDestSpace 3082 | context:referenceContext 3083 | hints:hints 3084 | flipped:flipped] 3085 | } 3086 | 3087 | unsafe fn accessibilityDescription(self) -> id /* (NSString *) */ { 3088 | msg_send![self, accessibilityDescription] 3089 | } 3090 | 3091 | unsafe fn layerContentsForContentsScale_(self, layerContentsScale: CGFloat) -> id /* (id) */ { 3092 | msg_send![self, layerContentsForContentsScale:layerContentsScale] 3093 | } 3094 | 3095 | unsafe fn recommendedLayerContentsScale_(self, preferredContentsScale: CGFloat) -> CGFloat { 3096 | msg_send![self, recommendedLayerContentsScale:preferredContentsScale] 3097 | } 3098 | 3099 | unsafe fn matchesOnlyOnBestFittingAxis(self) -> BOOL { 3100 | msg_send![self, matchesOnlyOnBestFittingAxis] 3101 | } 3102 | } 3103 | 3104 | #[link(name = "AppKit", kind = "framework")] 3105 | extern { 3106 | // Image hints (NSString* const) 3107 | pub static NSImageHintCTM: id; 3108 | pub static NSImageHintInterpolation: id; 3109 | 3110 | // System image names (NSString const*) 3111 | pub static NSImageNameQuickLookTemplate: id; 3112 | pub static NSImageNameBluetoothTemplate: id; 3113 | pub static NSImageNameIChatTheaterTemplate: id; 3114 | pub static NSImageNameSlideshowTemplate: id; 3115 | pub static NSImageNameActionTemplate: id; 3116 | pub static NSImageNameSmartBadgeTemplate: id; 3117 | pub static NSImageNamePathTemplate: id; 3118 | pub static NSImageNameInvalidDataFreestandingTemplate: id; 3119 | pub static NSImageNameLockLockedTemplate: id; 3120 | pub static NSImageNameLockUnlockedTemplate: id; 3121 | pub static NSImageNameGoRightTemplate: id; 3122 | pub static NSImageNameGoLeftTemplate: id; 3123 | pub static NSImageNameRightFacingTriangleTemplate: id; 3124 | pub static NSImageNameLeftFacingTriangleTemplate: id; 3125 | pub static NSImageNameAddTemplate: id; 3126 | pub static NSImageNameRemoveTemplate: id; 3127 | pub static NSImageNameRevealFreestandingTemplate: id; 3128 | pub static NSImageNameFollowLinkFreestandingTemplate: id; 3129 | pub static NSImageNameEnterFullScreenTemplate: id; 3130 | pub static NSImageNameExitFullScreenTemplate: id; 3131 | pub static NSImageNameStopProgressTemplate: id; 3132 | pub static NSImageNameStopProgressFreestandingTemplate: id; 3133 | pub static NSImageNameRefreshTemplate: id; 3134 | pub static NSImageNameRefreshFreestandingTemplate: id; 3135 | 3136 | pub static NSImageNameMultipleDocuments: id; 3137 | 3138 | pub static NSImageNameUser: id; 3139 | pub static NSImageNameUserGroup: id; 3140 | pub static NSImageNameEveryone: id; 3141 | pub static NSImageNameUserGuest: id; 3142 | 3143 | pub static NSImageNameBonjour: id; 3144 | pub static NSImageNameDotMac: id; 3145 | pub static NSImageNameComputer: id; 3146 | pub static NSImageNameFolderBurnable: id; 3147 | pub static NSImageNameFolderSmart: id; 3148 | pub static NSImageNameNetwork: id; 3149 | 3150 | pub static NSImageNameUserAccounts: id; 3151 | pub static NSImageNamePreferencesGeneral: id; 3152 | pub static NSImageNameAdvanced: id; 3153 | pub static NSImageNameInfo: id; 3154 | pub static NSImageNameFontPanel: id; 3155 | pub static NSImageNameColorPanel: id; 3156 | pub static NSImageNameFolder: id; 3157 | pub static NSImageNameTrashEmpty: id; 3158 | pub static NSImageNameTrashFull: id; 3159 | pub static NSImageNameHomeTemplate: id; 3160 | pub static NSImageNameBookmarksTemplate: id; 3161 | pub static NSImageNameCaution: id; 3162 | pub static NSImageNameStatusAvailable: id; 3163 | pub static NSImageNameStatusPartiallyAvailable: id; 3164 | pub static NSImageNameStatusUnavailable: id; 3165 | pub static NSImageNameStatusNone: id; 3166 | pub static NSImageNameApplicationIcon: id; 3167 | pub static NSImageNameMenuOnStateTemplate: id; 3168 | pub static NSImageNameMenuMixedStateTemplate: id; 3169 | pub static NSImageNameMobileMe: id; 3170 | 3171 | pub static NSImageNameIconViewTemplate: id; 3172 | pub static NSImageNameListViewTemplate: id; 3173 | pub static NSImageNameColumnViewTemplate: id; 3174 | pub static NSImageNameFlowViewTemplate: id; 3175 | pub static NSImageNameShareTemplate: id; 3176 | } 3177 | 3178 | #[repr(usize)] 3179 | #[derive(Clone, Copy, Debug, Eq, PartialEq)] 3180 | pub enum NSCompositingOperation { 3181 | NSCompositeClear = 0, 3182 | NSCompositeCopy = 1, 3183 | NSCompositeSourceOver = 2, 3184 | NSCompositeSourceIn = 3, 3185 | NSCompositeSourceOut = 4, 3186 | NSCompositeSourceAtop = 5, 3187 | NSCompositeDestinationOver = 6, 3188 | NSCompositeDestinationIn = 7, 3189 | NSCompositeDestinationOut = 8, 3190 | NSCompositeDestinationAtop = 9, 3191 | NSCompositeXOR = 10, 3192 | NSCompositePlusDarker = 11, 3193 | NSCompositeHighlight = 12, 3194 | NSCompositePlusLighter = 13 3195 | } 3196 | 3197 | #[repr(usize)] 3198 | #[derive(Clone, Copy, Debug, Eq, PartialEq)] 3199 | pub enum NSImageCacheMode { 3200 | NSImageCacheDefault, 3201 | NSImageCacheAlways, 3202 | NSImageCacheBySize, 3203 | NSImageCacheNever 3204 | } 3205 | 3206 | #[repr(usize)] 3207 | #[derive(Clone, Copy, Debug, Eq, PartialEq)] 3208 | pub enum NSTIFFCompression { 3209 | NSTIFFCompressionNone = 1, 3210 | NSTIFFCompressionCCITTFAX3 = 3, 3211 | NSTIFFCompressionCCITTFAX4 = 4, 3212 | NSTIFFCompressionLZW = 5, 3213 | NSTIFFCompressionJPEG = 6, 3214 | NSTIFFCompressionNEXT = 32766, 3215 | NSTIFFCompressionPackBits = 32773, 3216 | NSTIFFCompressionOldJPEG = 32865 3217 | } 3218 | 3219 | #[repr(usize)] 3220 | #[derive(Clone, Copy, Debug, Eq, PartialEq)] 3221 | pub enum NSImageLoadStatus { 3222 | NSImageLoadStatusCompleted, 3223 | NSImageLoadStatusCancelled, 3224 | NSImageLoadStatusInvalidData, 3225 | NSImageLoadStatusUnexpectedEOF, 3226 | NSImageLoadStatusReadError 3227 | } 3228 | 3229 | pub trait NSSound: Sized { 3230 | unsafe fn canInitWithPasteboard_(_: Self, pasteboard: id) -> BOOL { 3231 | msg_send![class("NSSound"), canInitWithPasteboard:pasteboard] 3232 | } 3233 | 3234 | unsafe fn initWithContentsOfFile_withReference_(self, filepath: id, byRef: BOOL) -> id; 3235 | unsafe fn initWithContentsOfURL_withReference_(self, fileUrl: id, byRef: BOOL) -> id; 3236 | unsafe fn initWithData_(self, audioData: id) -> id; 3237 | unsafe fn initWithPasteboard_(self, pasteboard: id) -> id; 3238 | 3239 | unsafe fn name(self) -> id; 3240 | unsafe fn volume(self) -> f32; 3241 | unsafe fn currentTime(self) -> NSTimeInterval; 3242 | unsafe fn loops(self) -> BOOL; 3243 | unsafe fn playbackDeviceIdentifier(self) -> id; 3244 | unsafe fn delegate(self) -> id; 3245 | 3246 | unsafe fn soundUnfilteredTypes(_: Self) -> id { 3247 | msg_send![class("NSSound"), soundUnfilteredTypes] 3248 | } 3249 | 3250 | unsafe fn soundNamed_(_: Self, soundName: id) -> id { 3251 | msg_send![class("NSSound"), soundNamed:soundName] 3252 | } 3253 | 3254 | unsafe fn duration(self) -> NSTimeInterval; 3255 | 3256 | unsafe fn playing(self) -> BOOL; 3257 | unsafe fn pause(self) -> BOOL; 3258 | unsafe fn play(self) -> BOOL; 3259 | unsafe fn resume(self) -> BOOL; 3260 | unsafe fn stop(self) -> BOOL; 3261 | 3262 | unsafe fn writeToPasteboard_(self, pasteboard: id); 3263 | } 3264 | 3265 | impl NSSound for id { 3266 | unsafe fn initWithContentsOfFile_withReference_(self, filepath: id, byRef: BOOL) -> id { 3267 | msg_send![self, initWithContentsOfFile:filepath withReference:byRef] 3268 | } 3269 | 3270 | unsafe fn initWithContentsOfURL_withReference_(self, fileUrl: id, byRef: BOOL) -> id { 3271 | msg_send![self, initWithContentsOfURL:fileUrl withReference:byRef] 3272 | } 3273 | 3274 | unsafe fn initWithData_(self, audioData: id) -> id { 3275 | msg_send![self, initWithData:audioData] 3276 | } 3277 | 3278 | unsafe fn initWithPasteboard_(self, pasteboard: id) -> id { 3279 | msg_send![self, initWithPasteboard:pasteboard] 3280 | } 3281 | 3282 | unsafe fn name(self) -> id { 3283 | msg_send![self, name] 3284 | } 3285 | 3286 | unsafe fn volume(self) -> f32 { 3287 | msg_send![self, volume] 3288 | } 3289 | 3290 | unsafe fn currentTime(self) -> NSTimeInterval { 3291 | msg_send![self, currentTime] 3292 | } 3293 | 3294 | unsafe fn loops(self) -> BOOL { 3295 | msg_send![self, loops] 3296 | } 3297 | 3298 | unsafe fn playbackDeviceIdentifier(self) -> id { 3299 | msg_send![self, playbackDeviceIdentifier] 3300 | } 3301 | 3302 | unsafe fn delegate(self) -> id { 3303 | msg_send![self, delegate] 3304 | } 3305 | 3306 | unsafe fn duration(self) -> NSTimeInterval { 3307 | msg_send![self, duration] 3308 | } 3309 | 3310 | unsafe fn playing(self) -> BOOL { 3311 | msg_send![self, playing] 3312 | } 3313 | 3314 | unsafe fn pause(self) -> BOOL { 3315 | msg_send![self, pause] 3316 | } 3317 | 3318 | unsafe fn play(self) -> BOOL { 3319 | msg_send![self, play] 3320 | } 3321 | 3322 | unsafe fn resume(self) -> BOOL { 3323 | msg_send![self, resume] 3324 | } 3325 | 3326 | unsafe fn stop(self) -> BOOL { 3327 | msg_send![self, stop] 3328 | } 3329 | 3330 | unsafe fn writeToPasteboard_(self, pasteboard: id) { 3331 | msg_send![self, writeToPasteboard:pasteboard] 3332 | } 3333 | } 3334 | 3335 | pub const NSVariableStatusItemLength: CGFloat = -1.0; 3336 | pub const NSSquareStatusItemLength: CGFloat = -2.0; 3337 | 3338 | pub trait NSStatusItem: Sized { 3339 | unsafe fn statusBar(self) -> id /* (NSStatusBar *) */; 3340 | unsafe fn button(self) -> id /* (NSStatusBarButton *) */; 3341 | unsafe fn menu(self) -> id; 3342 | unsafe fn setMenu_(self, menu: id); 3343 | unsafe fn length(self) -> CGFloat; 3344 | unsafe fn setLength_(self, length: CGFloat); 3345 | } 3346 | 3347 | impl NSStatusItem for id { 3348 | unsafe fn statusBar(self) -> id /* (NSStatusBar *) */ { 3349 | msg_send![self, statusBar] 3350 | } 3351 | 3352 | unsafe fn button(self) -> id /* (NSStatusBarButton *) */ { 3353 | msg_send![self, button] 3354 | } 3355 | 3356 | unsafe fn menu(self) -> id { 3357 | msg_send![self, menu] 3358 | } 3359 | 3360 | unsafe fn setMenu_(self, menu: id) { 3361 | msg_send![self, setMenu:menu] 3362 | } 3363 | 3364 | unsafe fn length(self) -> CGFloat { 3365 | msg_send![self, length] 3366 | } 3367 | 3368 | unsafe fn setLength_(self, length: CGFloat) { 3369 | msg_send![self, setLength: length] 3370 | } 3371 | } 3372 | 3373 | pub trait NSStatusBar: Sized { 3374 | unsafe fn systemStatusBar(_: Self) -> id { 3375 | msg_send![class("NSStatusBar"), systemStatusBar] 3376 | } 3377 | 3378 | unsafe fn statusItemWithLength_(self, length: CGFloat) -> id /* (NSStatusItem *) */; 3379 | unsafe fn removeStatusItem_(self, item: id /* (NSStatusItem *) */); 3380 | unsafe fn isVertical(self) -> BOOL; 3381 | } 3382 | 3383 | impl NSStatusBar for id { 3384 | unsafe fn statusItemWithLength_(self, length: CGFloat) -> id /* (NSStatusItem *) */ { 3385 | msg_send![self, statusItemWithLength:length] 3386 | } 3387 | 3388 | unsafe fn removeStatusItem_(self, item: id /* (NSStatusItem *) */) { 3389 | msg_send![self, removeStatusItem:item] 3390 | } 3391 | 3392 | unsafe fn isVertical(self) -> BOOL { 3393 | msg_send![self, isVertical] 3394 | } 3395 | } 3396 | 3397 | extern { 3398 | pub fn NSRectFill(rect: NSRect); 3399 | } 3400 | 3401 | pub trait NSTextField: Sized { 3402 | unsafe fn alloc(_: Self) -> id { 3403 | msg_send![class("NSTextField"), alloc] 3404 | } 3405 | unsafe fn initWithFrame_(self, frameRect: NSRect) -> id; 3406 | unsafe fn setEditable_(self, editable: BOOL); 3407 | unsafe fn setStringValue_(self, label: id /* NSString */); 3408 | } 3409 | 3410 | impl NSTextField for id { 3411 | unsafe fn initWithFrame_(self, frameRect: NSRect) -> id { 3412 | msg_send![self, initWithFrame:frameRect] 3413 | } 3414 | unsafe fn setEditable_(self, editable: BOOL) { 3415 | msg_send![self, setEditable:editable]; 3416 | } 3417 | unsafe fn setStringValue_(self, label: id) { 3418 | msg_send![self, setStringValue:label]; 3419 | } 3420 | } 3421 | 3422 | #[repr(u64)] 3423 | pub enum NSTabViewType { 3424 | NSTopTabsBezelBorder = 0, 3425 | NSLeftTabsBezelBorder = 1, 3426 | NSBottomTabsBezelBorder = 2, 3427 | NSRightTabsBezelBorder = 3, 3428 | NSNoTabsBezelBorder = 4, 3429 | NSNoTabsLineBorder = 5, 3430 | NSNoTabsNoBorder = 6 3431 | } 3432 | 3433 | pub trait NSTabView: Sized { 3434 | unsafe fn new(_: Self) -> id { 3435 | msg_send![class("NSTabView"), new] 3436 | } 3437 | 3438 | unsafe fn initWithFrame_(self, frameRect: NSRect) -> id; 3439 | unsafe fn addTabViewItem_(self, tabViewItem: id); 3440 | unsafe fn insertTabViewItem_atIndex_(self,tabViewItem:id, index:NSInteger); 3441 | unsafe fn removeTabViewItem_(self,tabViewItem:id); 3442 | unsafe fn indexOfTabViewItem_(self, tabViewItem:id) -> id; 3443 | unsafe fn indexOfTabViewItemWithIdentifier_(self,identifier:id) -> id; 3444 | unsafe fn numberOfTabViewItems(self) -> id; 3445 | unsafe fn tabViewItemAtIndex_(self,index:id) -> id; 3446 | unsafe fn tabViewItems(self) -> id; 3447 | unsafe fn selectFirstTabViewItem_(self,sender:id); 3448 | unsafe fn selectLastTabViewItem_(self,sender:id); 3449 | unsafe fn selectNextTabViewItem_(self, sender:id); 3450 | unsafe fn selectPreviousTabViewItem_(self,sender:id); 3451 | unsafe fn selectTabViewItem_(self,tabViewItem:id); 3452 | unsafe fn selectTabViewItemAtIndex_(self,index:id); 3453 | unsafe fn selectTabViewItemWithIdentifier_(self,identifier:id); 3454 | unsafe fn selectedTabViewItem(self) -> id; 3455 | unsafe fn takeSelectedTabViewItemFromSender_(self,sender:id); 3456 | unsafe fn font(self) -> id; 3457 | unsafe fn setFont_(self, font:id); 3458 | unsafe fn tabViewType(self) -> NSTabViewType; 3459 | unsafe fn setTabViewType_(self,tabViewType: NSTabViewType); 3460 | unsafe fn controlTint(self) -> id; 3461 | unsafe fn setControlTint_(self,controlTint:id); 3462 | unsafe fn drawsBackground(self) -> BOOL; 3463 | unsafe fn setDrawsBackground_(self,drawsBackground:BOOL); 3464 | unsafe fn minimumSize(self) -> id; 3465 | unsafe fn contentRect(self) -> id; 3466 | unsafe fn controlSize(self) -> id; 3467 | unsafe fn setControlSize_(self,controlSize:id); 3468 | unsafe fn allowsTruncatedLabels(self) -> BOOL; 3469 | unsafe fn setAllowsTruncatedLabels_(self, allowTruncatedLabels:BOOL); 3470 | unsafe fn setDelegate_(self, delegate:id); 3471 | unsafe fn delegate(self) -> id ; 3472 | unsafe fn tabViewAtPoint_(self, point:id) -> id; 3473 | } 3474 | 3475 | impl NSTabView for id { 3476 | unsafe fn initWithFrame_(self, frameRect: NSRect) -> id { 3477 | msg_send![self, initWithFrame:frameRect] 3478 | } 3479 | 3480 | unsafe fn addTabViewItem_(self, tabViewItem: id) { 3481 | msg_send![self, addTabViewItem:tabViewItem] 3482 | } 3483 | unsafe fn insertTabViewItem_atIndex_(self, tabViewItem: id,index:NSInteger) { 3484 | msg_send![self, addTabViewItem:tabViewItem atIndex:index] 3485 | } 3486 | unsafe fn removeTabViewItem_(self,tabViewItem:id){ 3487 | msg_send![self, removeTabViewItem:tabViewItem] 3488 | } 3489 | 3490 | unsafe fn indexOfTabViewItem_(self, tabViewItem:id) -> id{ 3491 | msg_send![self, indexOfTabViewItem:tabViewItem] 3492 | } 3493 | 3494 | unsafe fn indexOfTabViewItemWithIdentifier_(self,identifier:id) -> id{ 3495 | msg_send![self, indexOfTabViewItemWithIdentifier:identifier] 3496 | } 3497 | unsafe fn numberOfTabViewItems(self) -> id{ 3498 | msg_send![self, numberOfTabViewItems] 3499 | } 3500 | 3501 | unsafe fn tabViewItemAtIndex_(self,index:id)->id{ 3502 | msg_send![self, tabViewItemAtIndex:index] 3503 | } 3504 | 3505 | unsafe fn tabViewItems(self)->id{ 3506 | msg_send![self, tabViewItems] 3507 | } 3508 | 3509 | unsafe fn selectFirstTabViewItem_(self,sender:id){ 3510 | msg_send![self, selectFirstTabViewItem:sender] 3511 | } 3512 | 3513 | unsafe fn selectLastTabViewItem_(self,sender:id){ 3514 | msg_send![self, selectLastTabViewItem:sender] 3515 | } 3516 | unsafe fn selectNextTabViewItem_(self, sender:id){ 3517 | msg_send![self, selectNextTabViewItem:sender] 3518 | } 3519 | unsafe fn selectPreviousTabViewItem_(self,sender:id){ 3520 | msg_send![self, selectPreviousTabViewItem:sender] 3521 | } 3522 | 3523 | unsafe fn selectTabViewItem_(self,tabViewItem:id){ 3524 | msg_send![self, selectTabViewItem:tabViewItem] 3525 | } 3526 | 3527 | unsafe fn selectTabViewItemAtIndex_(self,index:id){ 3528 | msg_send![self, selectTabViewItemAtIndex:index] 3529 | } 3530 | unsafe fn selectTabViewItemWithIdentifier_(self,identifier:id){ 3531 | msg_send![self, selectTabViewItemWithIdentifier:identifier] 3532 | } 3533 | unsafe fn selectedTabViewItem(self) -> id{ 3534 | msg_send![self, selectedTabViewItem] 3535 | } 3536 | unsafe fn takeSelectedTabViewItemFromSender_(self,sender:id){ 3537 | msg_send![self, takeSelectedTabViewItemFromSender:sender] 3538 | } 3539 | 3540 | unsafe fn font(self)->id{ 3541 | msg_send![self, font] 3542 | } 3543 | 3544 | unsafe fn setFont_(self, font:id){ 3545 | msg_send![self, setFont:font] 3546 | } 3547 | 3548 | unsafe fn tabViewType(self)->NSTabViewType{ 3549 | msg_send![self, tabViewType] 3550 | } 3551 | unsafe fn setTabViewType_(self,tabViewType: NSTabViewType){ 3552 | msg_send![self, setTabViewType:tabViewType] 3553 | } 3554 | 3555 | unsafe fn controlTint(self) -> id{ 3556 | msg_send![self, controlTint] 3557 | } 3558 | unsafe fn setControlTint_(self,controlTint:id){ 3559 | msg_send![self, setControlTint:controlTint] 3560 | } 3561 | 3562 | unsafe fn drawsBackground(self) -> BOOL{ 3563 | msg_send![self, drawsBackground] 3564 | } 3565 | unsafe fn setDrawsBackground_(self,drawsBackground:BOOL){ 3566 | msg_send![self, setDrawsBackground:drawsBackground as libc::c_int] 3567 | } 3568 | 3569 | unsafe fn minimumSize(self) -> id{ 3570 | msg_send![self, minimumSize] 3571 | } 3572 | unsafe fn contentRect(self) -> id{ 3573 | msg_send![self, contentRect] 3574 | } 3575 | unsafe fn controlSize(self) -> id{ 3576 | msg_send![self, controlSize] 3577 | } 3578 | unsafe fn setControlSize_(self,controlSize:id){ 3579 | msg_send![self, setControlSize:controlSize] 3580 | } 3581 | 3582 | unsafe fn allowsTruncatedLabels(self) -> BOOL{ 3583 | msg_send![self, allowsTruncatedLabels] 3584 | } 3585 | unsafe fn setAllowsTruncatedLabels_(self, allowTruncatedLabels:BOOL){ 3586 | msg_send![self, setAllowsTruncatedLabels:allowTruncatedLabels as libc::c_int] 3587 | } 3588 | 3589 | unsafe fn setDelegate_(self, delegate:id){ 3590 | msg_send![self, setDelegate:delegate] 3591 | } 3592 | unsafe fn delegate(self) -> id { 3593 | msg_send![self, delegate] 3594 | } 3595 | 3596 | unsafe fn tabViewAtPoint_(self, point:id) -> id{ 3597 | msg_send![self, tabViewAtPoint:point] 3598 | } 3599 | } 3600 | 3601 | #[repr(u64)] 3602 | pub enum NSTabState { 3603 | NSSelectedTab = 0, 3604 | NSBackgroundTab = 1, 3605 | NSPressedTab = 2 3606 | } 3607 | 3608 | pub trait NSTabViewItem: Sized { 3609 | unsafe fn alloc(_: Self) -> id { 3610 | msg_send![class("NSTabViewItem"), alloc] 3611 | } 3612 | unsafe fn new(_: Self) -> id { 3613 | msg_send![class("NSTabViewItem"), new] 3614 | } 3615 | 3616 | unsafe fn initWithIdentifier_(self, identifier:id) -> id; 3617 | unsafe fn drawLabel_inRect_(self,shouldTruncateLabel:BOOL,labelRect:NSRect); 3618 | unsafe fn label(self) -> id; 3619 | unsafe fn setLabel_(self,label:id); 3620 | unsafe fn sizeOfLabel_(self, computeMin:BOOL); 3621 | unsafe fn tabState(self) -> NSTabState; 3622 | unsafe fn identifier(self)-> id; 3623 | unsafe fn setIdentifier_(self,identifier:id); 3624 | unsafe fn color(self)-> id; 3625 | unsafe fn setColor_(self,color:id); 3626 | unsafe fn view(self) -> id; 3627 | unsafe fn setView_(self, view:id); 3628 | unsafe fn initialFirstResponder(self)->id; 3629 | unsafe fn setInitialFirstResponder_(self,initialFirstResponder:id); 3630 | unsafe fn tabView(self) -> id; 3631 | unsafe fn tooltip(self) -> id; 3632 | unsafe fn setTooltip_(self,toolTip:id); 3633 | } 3634 | 3635 | impl NSTabViewItem for id { 3636 | unsafe fn initWithIdentifier_(self, identifier: id) -> id { 3637 | msg_send![self, initWithIdentifier:identifier] 3638 | } 3639 | 3640 | unsafe fn drawLabel_inRect_(self, shouldTruncateLabel:BOOL,labelRect:NSRect){ 3641 | msg_send![self, drawLabel:shouldTruncateLabel as libc::c_int inRect:labelRect] 3642 | } 3643 | 3644 | unsafe fn label(self)->id{ 3645 | msg_send![self, label] 3646 | } 3647 | unsafe fn setLabel_(self,label : id){ 3648 | msg_send![self, setLabel:label] 3649 | } 3650 | 3651 | unsafe fn sizeOfLabel_(self,computeMin:BOOL){ 3652 | msg_send![self, sizeOfLabel:computeMin as libc::c_int] 3653 | } 3654 | 3655 | unsafe fn tabState(self) -> NSTabState{ 3656 | msg_send![self, tabState] 3657 | } 3658 | 3659 | unsafe fn identifier(self)-> id { 3660 | msg_send![self, identifier] 3661 | } 3662 | 3663 | unsafe fn setIdentifier_(self,identifier:id){ 3664 | msg_send![self, identifier:identifier] 3665 | } 3666 | 3667 | unsafe fn color(self)-> id{ 3668 | msg_send![self, color] 3669 | } 3670 | 3671 | unsafe fn setColor_(self,color:id){ 3672 | msg_send![self, color:color] 3673 | } 3674 | 3675 | unsafe fn view(self) -> id { 3676 | msg_send![self, view] 3677 | } 3678 | 3679 | unsafe fn setView_(self, view:id){ 3680 | msg_send![self, setView:view] 3681 | } 3682 | 3683 | unsafe fn initialFirstResponder(self)->id{ 3684 | msg_send![self, initialFirstResponder] 3685 | } 3686 | 3687 | unsafe fn setInitialFirstResponder_(self,initialFirstResponder:id){ 3688 | msg_send![self, setInitialFirstResponder:initialFirstResponder] 3689 | } 3690 | 3691 | unsafe fn tabView(self) -> id{ 3692 | msg_send![self, tabView] 3693 | } 3694 | 3695 | unsafe fn tooltip(self) -> id{ 3696 | msg_send![self, tooltip] 3697 | } 3698 | 3699 | unsafe fn setTooltip_(self,toolTip:id){ 3700 | msg_send![self, setTooltip:toolTip] 3701 | } 3702 | } 3703 | 3704 | pub trait NSLayoutConstraint: Sized { 3705 | unsafe fn activateConstraints(_: Self, constraints: id) -> id; 3706 | } 3707 | 3708 | impl NSLayoutConstraint for id { 3709 | unsafe fn activateConstraints(_: Self, constraints: id) -> id { 3710 | msg_send![class("NSLayoutConstraint"), activateConstraints:constraints] 3711 | } 3712 | } 3713 | 3714 | pub trait NSLayoutDimension: Sized { 3715 | unsafe fn constraintEqualToConstant(self, c: CGFloat) -> id; 3716 | unsafe fn constraintLessThanOrEqualToConstant(self, c: CGFloat) -> id; 3717 | unsafe fn constraintGreaterThanOrEqualToConstant(self, c: CGFloat) -> id; 3718 | } 3719 | 3720 | impl NSLayoutDimension for id { 3721 | unsafe fn constraintEqualToConstant(self, c: CGFloat) -> id { 3722 | msg_send![self, constraintEqualToConstant:c] 3723 | } 3724 | 3725 | unsafe fn constraintLessThanOrEqualToConstant(self, c: CGFloat) -> id { 3726 | msg_send![self, constraintLessThanOrEqualToConstant:c] 3727 | } 3728 | 3729 | unsafe fn constraintGreaterThanOrEqualToConstant(self, c: CGFloat) -> id { 3730 | msg_send![self, constraintGreaterThanOrEqualToConstant:c] 3731 | } 3732 | } 3733 | 3734 | pub trait NSColor: Sized { 3735 | unsafe fn clearColor(_: Self) -> id; 3736 | } 3737 | 3738 | impl NSColor for id { 3739 | unsafe fn clearColor(_: Self) -> id { 3740 | msg_send![class("NSColor"), clearColor] 3741 | } 3742 | } 3743 | 3744 | #[cfg(test)] 3745 | mod test { 3746 | use super::*; 3747 | 3748 | #[test] 3749 | pub fn test_nsapp() { 3750 | unsafe { 3751 | let _nsApp = NSApp(); 3752 | } 3753 | } 3754 | } 3755 | -------------------------------------------------------------------------------- /src/base.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Servo Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution. 3 | // 4 | // Licensed under the Apache License, Version 2.0 or the MIT license 6 | // , at your 7 | // option. This file may not be copied, modified, or distributed 8 | // except according to those terms. 9 | 10 | use objc::runtime; 11 | use std::mem; 12 | 13 | pub use objc::runtime::{BOOL, NO, YES}; 14 | 15 | pub type Class = *mut runtime::Class; 16 | #[allow(non_camel_case_types)] 17 | pub type id = *mut runtime::Object; 18 | pub type SEL = runtime::Sel; 19 | 20 | #[allow(non_upper_case_globals)] 21 | pub const nil: id = 0 as id; 22 | #[allow(non_upper_case_globals)] 23 | pub const Nil: Class = 0 as Class; 24 | 25 | /// A convenience method to convert the name of a class to the class object itself. 26 | #[inline] 27 | pub fn class(name: &str) -> Class { 28 | unsafe { 29 | mem::transmute(runtime::Class::get(name)) 30 | } 31 | } 32 | 33 | /// A convenience method to convert the name of a selector to the selector object. 34 | #[inline] 35 | pub fn selector(name: &str) -> SEL { 36 | runtime::Sel::register(name) 37 | } 38 | -------------------------------------------------------------------------------- /src/foundation.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Servo Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution. 3 | // 4 | // Licensed under the Apache License, Version 2.0 or the MIT license 6 | // , at your 7 | // option. This file may not be copied, modified, or distributed 8 | // except according to those terms. 9 | 10 | #![allow(non_upper_case_globals)] 11 | 12 | use std::ptr; 13 | use base::{id, class, BOOL, NO, SEL, nil}; 14 | use block::Block; 15 | use libc; 16 | 17 | 18 | #[cfg(target_pointer_width = "32")] 19 | pub type NSInteger = libc::c_int; 20 | #[cfg(target_pointer_width = "32")] 21 | pub type NSUInteger = libc::c_uint; 22 | 23 | #[cfg(target_pointer_width = "64")] 24 | pub type NSInteger = libc::c_long; 25 | #[cfg(target_pointer_width = "64")] 26 | pub type NSUInteger = libc::c_ulong; 27 | 28 | const UTF8_ENCODING: usize = 4; 29 | 30 | #[cfg(target_os = "macos")] 31 | mod macos { 32 | use std::mem; 33 | use base::{id, class}; 34 | use core_graphics::base::CGFloat; 35 | use core_graphics::geometry::CGRect; 36 | use objc; 37 | 38 | #[repr(C)] 39 | #[derive(Copy, Clone)] 40 | pub struct NSPoint { 41 | pub x: f64, 42 | pub y: f64, 43 | } 44 | 45 | impl NSPoint { 46 | #[inline] 47 | pub fn new(x: f64, y: f64) -> NSPoint { 48 | NSPoint { 49 | x: x, 50 | y: y, 51 | } 52 | } 53 | } 54 | 55 | unsafe impl objc::Encode for NSPoint { 56 | fn encode() -> objc::Encoding { 57 | let encoding = format!("{{CGPoint={}{}}}", 58 | f64::encode().as_str(), 59 | f64::encode().as_str()); 60 | unsafe { objc::Encoding::from_str(&encoding) } 61 | } 62 | } 63 | 64 | #[repr(C)] 65 | #[derive(Copy, Clone)] 66 | pub struct NSSize { 67 | pub width: f64, 68 | pub height: f64, 69 | } 70 | 71 | impl NSSize { 72 | #[inline] 73 | pub fn new(width: f64, height: f64) -> NSSize { 74 | NSSize { 75 | width: width, 76 | height: height, 77 | } 78 | } 79 | } 80 | 81 | unsafe impl objc::Encode for NSSize { 82 | fn encode() -> objc::Encoding { 83 | let encoding = format!("{{CGSize={}{}}}", 84 | f64::encode().as_str(), 85 | f64::encode().as_str()); 86 | unsafe { objc::Encoding::from_str(&encoding) } 87 | } 88 | } 89 | 90 | #[repr(C)] 91 | #[derive(Copy, Clone)] 92 | pub struct NSRect { 93 | pub origin: NSPoint, 94 | pub size: NSSize, 95 | } 96 | 97 | impl NSRect { 98 | #[inline] 99 | pub fn new(origin: NSPoint, size: NSSize) -> NSRect { 100 | NSRect { 101 | origin: origin, 102 | size: size 103 | } 104 | } 105 | 106 | #[inline] 107 | pub fn as_CGRect(&self) -> &CGRect { 108 | unsafe { 109 | mem::transmute::<&NSRect, &CGRect>(self) 110 | } 111 | } 112 | 113 | #[inline] 114 | pub fn inset(&self, x: CGFloat, y: CGFloat) -> NSRect { 115 | unsafe { 116 | NSInsetRect(*self, x, y) 117 | } 118 | } 119 | } 120 | 121 | unsafe impl objc::Encode for NSRect { 122 | fn encode() -> objc::Encoding { 123 | let encoding = format!("{{CGRect={}{}}}", 124 | NSPoint::encode().as_str(), 125 | NSSize::encode().as_str()); 126 | unsafe { objc::Encoding::from_str(&encoding) } 127 | } 128 | } 129 | 130 | // Same as CGRectEdge 131 | #[repr(u32)] 132 | pub enum NSRectEdge { 133 | NSRectMinXEdge, 134 | NSRectMinYEdge, 135 | NSRectMaxXEdge, 136 | NSRectMaxYEdge, 137 | } 138 | 139 | #[link(name = "Foundation", kind = "framework")] 140 | extern { 141 | fn NSInsetRect(rect: NSRect, x: CGFloat, y: CGFloat) -> NSRect; 142 | } 143 | 144 | pub trait NSValue: Sized { 145 | unsafe fn valueWithPoint(_: Self, point: NSPoint) -> id { 146 | msg_send![class("NSValue"), valueWithPoint:point] 147 | } 148 | 149 | unsafe fn valueWithSize(_: Self, size: NSSize) -> id { 150 | msg_send![class("NSValue"), valueWithSize:size] 151 | } 152 | } 153 | 154 | impl NSValue for id { 155 | } 156 | } 157 | 158 | #[cfg(target_os = "macos")] 159 | pub use self::macos::*; 160 | 161 | #[repr(C)] 162 | pub struct NSRange { 163 | pub location: NSUInteger, 164 | pub length: NSUInteger, 165 | } 166 | 167 | impl NSRange { 168 | #[inline] 169 | pub fn new(location: NSUInteger, length: NSUInteger) -> NSRange { 170 | NSRange { 171 | location: location, 172 | length: length 173 | } 174 | } 175 | } 176 | 177 | #[link(name = "Foundation", kind = "framework")] 178 | extern { 179 | pub static NSDefaultRunLoopMode: id; 180 | } 181 | 182 | pub trait NSAutoreleasePool: Sized { 183 | unsafe fn new(_: Self) -> id { 184 | msg_send![class("NSAutoreleasePool"), new] 185 | } 186 | 187 | unsafe fn autorelease(self) -> Self; 188 | unsafe fn drain(self); 189 | } 190 | 191 | impl NSAutoreleasePool for id { 192 | unsafe fn autorelease(self) -> id { 193 | msg_send![self, autorelease] 194 | } 195 | 196 | unsafe fn drain(self) { 197 | msg_send![self, drain] 198 | } 199 | } 200 | 201 | pub trait NSProcessInfo: Sized { 202 | unsafe fn processInfo(_: Self) -> id { 203 | msg_send![class("NSProcessInfo"), processInfo] 204 | } 205 | 206 | unsafe fn processName(self) -> id; 207 | } 208 | 209 | impl NSProcessInfo for id { 210 | unsafe fn processName(self) -> id { 211 | msg_send![self, processName] 212 | } 213 | } 214 | 215 | pub type NSTimeInterval = libc::c_double; 216 | 217 | pub trait NSArray: Sized { 218 | unsafe fn array(_: Self) -> id { 219 | msg_send![class("NSArray"), array] 220 | } 221 | 222 | unsafe fn arrayWithObjects(_: Self, objects: &[id]) -> id { 223 | msg_send![class("NSArray"), arrayWithObjects:objects.as_ptr() 224 | count:objects.len()] 225 | } 226 | 227 | unsafe fn arrayWithObject(_: Self, object: id) -> id { 228 | msg_send![class("NSArray"), arrayWithObject:object] 229 | } 230 | 231 | unsafe fn arrayByAddingObjectFromArray(self, object: id) -> id; 232 | unsafe fn arrayByAddingObjectsFromArray(self, objects: id) -> id; 233 | } 234 | 235 | impl NSArray for id { 236 | unsafe fn arrayByAddingObjectFromArray(self, object: id) -> id { 237 | msg_send![self, arrayByAddingObjectFromArray:object] 238 | } 239 | 240 | unsafe fn arrayByAddingObjectsFromArray(self, objects: id) -> id { 241 | msg_send![self, arrayByAddingObjectsFromArray:objects] 242 | } 243 | } 244 | 245 | pub trait NSDictionary: Sized { 246 | unsafe fn dictionary(_: Self) -> id { 247 | msg_send![class("NSDictionary"), dictionary] 248 | } 249 | 250 | unsafe fn dictionaryWithContentsOfFile_(_: Self, path: id) -> id { 251 | msg_send![class("NSDictionary"), dictionaryWithContentsOfFile:path] 252 | } 253 | 254 | unsafe fn dictionaryWithContentsOfURL_(_: Self, aURL: id) -> id { 255 | msg_send![class("NSDictionary"), dictionaryWithContentsOfURL:aURL] 256 | } 257 | 258 | unsafe fn dictionaryWithDictionary_(_: Self, otherDictionary: id) -> id { 259 | msg_send![class("NSDictionary"), dictionaryWithDictionary:otherDictionary] 260 | } 261 | 262 | unsafe fn dictionaryWithObject_forKey_(_: Self, anObject: id, aKey: id) -> id { 263 | msg_send![class("NSDictionary"), dictionaryWithObject:anObject forKey:aKey] 264 | } 265 | 266 | unsafe fn dictionaryWithObjects_forKeys_(_: Self, objects: id, keys: id) -> id { 267 | msg_send![class("NSDictionary"), dictionaryWithObjects:objects forKeys:keys] 268 | } 269 | 270 | unsafe fn dictionaryWithObjects_forKeys_count_(_: Self, objects: *const id, keys: *const id, count: NSUInteger) -> id { 271 | msg_send![class("NSDictionary"), dictionaryWithObjects:objects forKeys:keys count:count] 272 | } 273 | 274 | unsafe fn dictionaryWithObjectsAndKeys_(_: Self, firstObject: id) -> id { 275 | msg_send![class("NSDictionary"), dictionaryWithObjectsAndKeys:firstObject] 276 | } 277 | 278 | unsafe fn init(self) -> id; 279 | unsafe fn initWithContentsOfFile_(self, path: id) -> id; 280 | unsafe fn initWithContentsOfURL_(self, aURL: id) -> id; 281 | unsafe fn initWithDictionary_(self, otherDicitonary: id) -> id; 282 | unsafe fn initWithDictionary_copyItems_(self, otherDicitonary: id, flag: BOOL) -> id; 283 | unsafe fn initWithObjects_forKeys_(self, objects: id, keys: id) -> id; 284 | unsafe fn initWithObjects_forKeys_count_(self, objects: id, keys: id, count: NSUInteger) -> id; 285 | unsafe fn initWithObjectsAndKeys_(self, firstObject: id) -> id; 286 | 287 | unsafe fn sharedKeySetForKeys_(_: Self, keys: id) -> id { 288 | msg_send![class("NSDictionary"), sharedKeySetForKeys:keys] 289 | } 290 | 291 | unsafe fn count(self) -> NSUInteger; 292 | 293 | unsafe fn isEqualToDictionary_(self, otherDictionary: id) -> BOOL; 294 | 295 | unsafe fn allKeys(self) -> id; 296 | unsafe fn allKeysForObject_(self, anObject: id) -> id; 297 | unsafe fn allValues(self) -> id; 298 | unsafe fn objectForKey_(self, aKey: id) -> id; 299 | unsafe fn objectForKeyedSubscript_(self, key: id) -> id; 300 | unsafe fn objectsForKeys_notFoundMarker_(self, keys: id, anObject: id) -> id; 301 | unsafe fn valueForKey_(self, key: id) -> id; 302 | 303 | unsafe fn keyEnumerator(self) -> id; 304 | unsafe fn objectEnumerator(self) -> id; 305 | unsafe fn enumerateKeysAndObjectsUsingBlock_(self, block: *mut Block<(id, id, *mut BOOL), ()>); 306 | unsafe fn enumerateKeysAndObjectsWithOptions_usingBlock_(self, opts: NSEnumerationOptions, 307 | block: *mut Block<(id, id, *mut BOOL), ()>); 308 | 309 | unsafe fn keysSortedByValueUsingSelector_(self, comparator: SEL) -> id; 310 | unsafe fn keysSortedByValueUsingComparator_(self, cmptr: NSComparator) -> id; 311 | unsafe fn keysSortedByValueWithOptions_usingComparator_(self, opts: NSEnumerationOptions, cmptr: NSComparator) -> id; 312 | 313 | unsafe fn keysOfEntriesPassingTest_(self, predicate: *mut Block<(id, id, *mut BOOL), BOOL>) -> id; 314 | unsafe fn keysOfEntriesWithOptions_PassingTest_(self, opts: NSEnumerationOptions, 315 | predicate: *mut Block<(id, id, *mut BOOL), BOOL>) -> id; 316 | 317 | unsafe fn writeToFile_atomically_(self, path: id, flag: BOOL) -> BOOL; 318 | unsafe fn writeToURL_atomically_(self, aURL: id, flag: BOOL) -> BOOL; 319 | 320 | unsafe fn fileCreationDate(self) -> id; 321 | unsafe fn fileExtensionHidden(self) -> BOOL; 322 | unsafe fn fileGroupOwnerAccountID(self) -> id; 323 | unsafe fn fileGroupOwnerAccountName(self) -> id; 324 | unsafe fn fileIsAppendOnly(self) -> BOOL; 325 | unsafe fn fileIsImmutable(self) -> BOOL; 326 | unsafe fn fileModificationDate(self) -> id; 327 | unsafe fn fileOwnerAccountID(self) -> id; 328 | unsafe fn fileOwnerAccountName(self) -> id; 329 | unsafe fn filePosixPermissions(self) -> NSUInteger; 330 | unsafe fn fileSize(self) -> libc::c_ulonglong; 331 | unsafe fn fileSystemFileNumber(self) -> NSUInteger; 332 | unsafe fn fileSystemNumber(self) -> NSInteger; 333 | unsafe fn fileType(self) -> id; 334 | 335 | unsafe fn description(self) -> id; 336 | unsafe fn descriptionInStringsFileFormat(self) -> id; 337 | unsafe fn descriptionWithLocale_(self, locale: id) -> id; 338 | unsafe fn descriptionWithLocale_indent_(self, locale: id, indent: NSUInteger) -> id; 339 | } 340 | 341 | impl NSDictionary for id { 342 | unsafe fn init(self) -> id { 343 | msg_send![self, init] 344 | } 345 | 346 | unsafe fn initWithContentsOfFile_(self, path: id) -> id { 347 | msg_send![self, initWithContentsOfFile:path] 348 | } 349 | 350 | unsafe fn initWithContentsOfURL_(self, aURL: id) -> id { 351 | msg_send![self, initWithContentsOfURL:aURL] 352 | } 353 | 354 | unsafe fn initWithDictionary_(self, otherDictionary: id) -> id { 355 | msg_send![self, initWithDictionary:otherDictionary] 356 | } 357 | 358 | unsafe fn initWithDictionary_copyItems_(self, otherDictionary: id, flag: BOOL) -> id { 359 | msg_send![self, initWithDictionary:otherDictionary copyItems:flag] 360 | } 361 | 362 | unsafe fn initWithObjects_forKeys_(self, objects: id, keys: id) -> id { 363 | msg_send![self, initWithObjects:objects forKeys:keys] 364 | } 365 | 366 | unsafe fn initWithObjects_forKeys_count_(self, objects: id, keys: id, count: NSUInteger) -> id { 367 | msg_send![self, initWithObjects:objects forKeys:keys count:count] 368 | } 369 | 370 | unsafe fn initWithObjectsAndKeys_(self, firstObject: id) -> id { 371 | msg_send![self, initWithObjectsAndKeys:firstObject] 372 | } 373 | 374 | unsafe fn count(self) -> NSUInteger { 375 | msg_send![self, count] 376 | } 377 | 378 | unsafe fn isEqualToDictionary_(self, otherDictionary: id) -> BOOL { 379 | msg_send![self, isEqualToDictionary:otherDictionary] 380 | } 381 | 382 | unsafe fn allKeys(self) -> id { 383 | msg_send![self, allKeys] 384 | } 385 | 386 | unsafe fn allKeysForObject_(self, anObject: id) -> id { 387 | msg_send![self, allKeysForObject:anObject] 388 | } 389 | 390 | unsafe fn allValues(self) -> id { 391 | msg_send![self, allValues] 392 | } 393 | 394 | unsafe fn objectForKey_(self, aKey: id) -> id { 395 | msg_send![self, objectForKey:aKey] 396 | } 397 | 398 | unsafe fn objectForKeyedSubscript_(self, key: id) -> id { 399 | msg_send![self, objectForKeyedSubscript:key] 400 | } 401 | 402 | unsafe fn objectsForKeys_notFoundMarker_(self, keys: id, anObject: id) -> id { 403 | msg_send![self, objectsForKeys:keys notFoundMarker:anObject] 404 | } 405 | 406 | unsafe fn valueForKey_(self, key: id) -> id { 407 | msg_send![self, valueForKey:key] 408 | } 409 | 410 | unsafe fn keyEnumerator(self) -> id { 411 | msg_send![self, keyEnumerator] 412 | } 413 | 414 | unsafe fn objectEnumerator(self) -> id { 415 | msg_send![self, objectEnumerator] 416 | } 417 | 418 | unsafe fn enumerateKeysAndObjectsUsingBlock_(self, block: *mut Block<(id, id, *mut BOOL), ()>) { 419 | msg_send![self, enumerateKeysAndObjectsUsingBlock:block] 420 | } 421 | 422 | unsafe fn enumerateKeysAndObjectsWithOptions_usingBlock_(self, opts: NSEnumerationOptions, 423 | block: *mut Block<(id, id, *mut BOOL), ()>) { 424 | msg_send![self, enumerateKeysAndObjectsWithOptions:opts usingBlock:block] 425 | } 426 | 427 | unsafe fn keysSortedByValueUsingSelector_(self, comparator: SEL) -> id { 428 | msg_send![self, keysSortedByValueUsingSelector:comparator] 429 | } 430 | 431 | unsafe fn keysSortedByValueUsingComparator_(self, cmptr: NSComparator) -> id { 432 | msg_send![self, keysSortedByValueUsingComparator:cmptr] 433 | } 434 | 435 | unsafe fn keysSortedByValueWithOptions_usingComparator_(self, opts: NSEnumerationOptions, cmptr: NSComparator) -> id { 436 | let rv: id = msg_send![self, keysSortedByValueWithOptions:opts usingComparator:cmptr]; 437 | rv 438 | } 439 | 440 | unsafe fn keysOfEntriesPassingTest_(self, predicate: *mut Block<(id, id, *mut BOOL), BOOL>) -> id { 441 | msg_send![self, keysOfEntriesPassingTest:predicate] 442 | } 443 | 444 | unsafe fn keysOfEntriesWithOptions_PassingTest_(self, opts: NSEnumerationOptions, 445 | predicate: *mut Block<(id, id, *mut BOOL), BOOL>) -> id { 446 | msg_send![self, keysOfEntriesWithOptions:opts PassingTest:predicate] 447 | } 448 | 449 | unsafe fn writeToFile_atomically_(self, path: id, flag: BOOL) -> BOOL { 450 | msg_send![self, writeToFile:path atomically:flag] 451 | } 452 | 453 | unsafe fn writeToURL_atomically_(self, aURL: id, flag: BOOL) -> BOOL { 454 | msg_send![self, writeToURL:aURL atomically:flag] 455 | } 456 | 457 | unsafe fn fileCreationDate(self) -> id { 458 | msg_send![self, fileCreationDate] 459 | } 460 | 461 | unsafe fn fileExtensionHidden(self) -> BOOL { 462 | msg_send![self, fileExtensionHidden] 463 | } 464 | 465 | unsafe fn fileGroupOwnerAccountID(self) -> id { 466 | msg_send![self, fileGroupOwnerAccountID] 467 | } 468 | 469 | unsafe fn fileGroupOwnerAccountName(self) -> id { 470 | msg_send![self, fileGroupOwnerAccountName] 471 | } 472 | 473 | unsafe fn fileIsAppendOnly(self) -> BOOL { 474 | msg_send![self, fileIsAppendOnly] 475 | } 476 | 477 | unsafe fn fileIsImmutable(self) -> BOOL { 478 | msg_send![self, fileIsImmutable] 479 | } 480 | 481 | unsafe fn fileModificationDate(self) -> id { 482 | msg_send![self, fileModificationDate] 483 | } 484 | 485 | unsafe fn fileOwnerAccountID(self) -> id { 486 | msg_send![self, fileOwnerAccountID] 487 | } 488 | 489 | unsafe fn fileOwnerAccountName(self) -> id { 490 | msg_send![self, fileOwnerAccountName] 491 | } 492 | 493 | unsafe fn filePosixPermissions(self) -> NSUInteger { 494 | msg_send![self, filePosixPermissions] 495 | } 496 | 497 | unsafe fn fileSize(self) -> libc::c_ulonglong { 498 | msg_send![self, fileSize] 499 | } 500 | 501 | unsafe fn fileSystemFileNumber(self) -> NSUInteger { 502 | msg_send![self, fileSystemFileNumber] 503 | } 504 | 505 | unsafe fn fileSystemNumber(self) -> NSInteger { 506 | msg_send![self, fileSystemNumber] 507 | } 508 | 509 | unsafe fn fileType(self) -> id { 510 | msg_send![self, fileType] 511 | } 512 | 513 | unsafe fn description(self) -> id { 514 | msg_send![self, description] 515 | } 516 | 517 | unsafe fn descriptionInStringsFileFormat(self) -> id { 518 | msg_send![self, descriptionInStringsFileFormat] 519 | } 520 | 521 | unsafe fn descriptionWithLocale_(self, locale: id) -> id { 522 | msg_send![self, descriptionWithLocale:locale] 523 | } 524 | 525 | unsafe fn descriptionWithLocale_indent_(self, locale: id, indent: NSUInteger) -> id { 526 | msg_send![self, descriptionWithLocale:locale indent:indent] 527 | } 528 | } 529 | 530 | bitflags! { 531 | pub struct NSEnumerationOptions: libc::c_ulonglong { 532 | const NSEnumerationConcurrent = 1 << 0; 533 | const NSEnumerationReverse = 1 << 1; 534 | } 535 | } 536 | 537 | pub type NSComparator = *mut Block<(id, id), NSComparisonResult>; 538 | 539 | #[repr(isize)] 540 | #[derive(Clone, Copy, Debug, Eq, PartialEq)] 541 | pub enum NSComparisonResult { 542 | NSOrderedAscending = -1, 543 | NSOrderedSame = 0, 544 | NSOrderedDescending = 1 545 | } 546 | 547 | pub trait NSString: Sized { 548 | unsafe fn alloc(_: Self) -> id { 549 | msg_send![class("NSString"), alloc] 550 | } 551 | 552 | unsafe fn stringByAppendingString_(self, other: id) -> id; 553 | unsafe fn init_str(self, string: &str) -> Self; 554 | unsafe fn UTF8String(self) -> *const libc::c_char; 555 | unsafe fn len(self) -> usize; 556 | unsafe fn isEqualToString(self, &str) -> bool; 557 | } 558 | 559 | impl NSString for id { 560 | unsafe fn isEqualToString(self, other: &str) -> bool { 561 | let other = NSString::alloc(nil).init_str(other); 562 | let rv: BOOL = msg_send![self, isEqualToString:other]; 563 | rv != NO 564 | } 565 | 566 | unsafe fn stringByAppendingString_(self, other: id) -> id { 567 | msg_send![self, stringByAppendingString:other] 568 | } 569 | 570 | unsafe fn init_str(self, string: &str) -> id { 571 | return msg_send![self, 572 | initWithBytes:string.as_ptr() 573 | length:string.len() 574 | encoding:UTF8_ENCODING as id]; 575 | } 576 | 577 | unsafe fn len(self) -> usize { 578 | msg_send![self, lengthOfBytesUsingEncoding:UTF8_ENCODING] 579 | } 580 | 581 | unsafe fn UTF8String(self) -> *const libc::c_char { 582 | msg_send![self, UTF8String] 583 | } 584 | } 585 | 586 | pub trait NSDate: Sized { 587 | unsafe fn distantPast(_: Self) -> id { 588 | msg_send![class("NSDate"), distantPast] 589 | } 590 | 591 | unsafe fn distantFuture(_: Self) -> id { 592 | msg_send![class("NSDate"), distantFuture] 593 | } 594 | } 595 | 596 | impl NSDate for id { 597 | 598 | } 599 | 600 | #[repr(C)] 601 | struct NSFastEnumerationState { 602 | pub state: libc::c_ulong, 603 | pub items_ptr: *mut id, 604 | pub mutations_ptr: *mut libc::c_ulong, 605 | pub extra: [libc::c_ulong; 5] 606 | } 607 | 608 | const NS_FAST_ENUM_BUF_SIZE: usize = 16; 609 | 610 | pub struct NSFastIterator { 611 | state: NSFastEnumerationState, 612 | buffer: [id; NS_FAST_ENUM_BUF_SIZE], 613 | mut_val: Option, 614 | len: usize, 615 | idx: usize, 616 | object: id 617 | } 618 | 619 | impl Iterator for NSFastIterator { 620 | type Item = id; 621 | 622 | fn next(&mut self) -> Option { 623 | if self.idx >= self.len { 624 | self.len = unsafe { 625 | msg_send![self.object, countByEnumeratingWithState:&mut self.state objects:self.buffer.as_mut_ptr() count:NS_FAST_ENUM_BUF_SIZE] 626 | }; 627 | self.idx = 0; 628 | } 629 | 630 | let new_mut = unsafe { 631 | *self.state.mutations_ptr 632 | }; 633 | 634 | if let Some(old_mut) = self.mut_val { 635 | assert!(old_mut == new_mut, "The collection was mutated while being enumerated"); 636 | } 637 | 638 | if self.idx < self.len { 639 | let object = unsafe { 640 | *self.state.items_ptr.offset(self.idx as isize) 641 | }; 642 | self.mut_val = Some(new_mut); 643 | self.idx += 1; 644 | Some(object) 645 | } else { 646 | None 647 | } 648 | } 649 | } 650 | 651 | pub trait NSFastEnumeration: Sized { 652 | unsafe fn iter(self) -> NSFastIterator; 653 | } 654 | 655 | impl NSFastEnumeration for id { 656 | unsafe fn iter(self) -> NSFastIterator { 657 | NSFastIterator { 658 | state: NSFastEnumerationState { 659 | state: 0, 660 | items_ptr: ptr::null_mut(), 661 | mutations_ptr: ptr::null_mut(), 662 | extra: [0; 5] 663 | }, 664 | buffer: [nil; NS_FAST_ENUM_BUF_SIZE], 665 | mut_val: None, 666 | len: 0, 667 | idx: 0, 668 | object: self 669 | } 670 | } 671 | } 672 | 673 | pub trait NSRunLoop: Sized { 674 | unsafe fn currentRunLoop() -> Self; 675 | 676 | unsafe fn performSelector_target_argument_order_modes_(self, 677 | aSelector: SEL, 678 | target: id, 679 | anArgument: id, 680 | order: NSUInteger, 681 | modes: id); 682 | } 683 | 684 | impl NSRunLoop for id { 685 | unsafe fn currentRunLoop() -> id { 686 | msg_send![class("NSRunLoop"), currentRunLoop] 687 | } 688 | 689 | unsafe fn performSelector_target_argument_order_modes_(self, 690 | aSelector: SEL, 691 | target: id, 692 | anArgument: id, 693 | order: NSUInteger, 694 | modes: id) { 695 | msg_send![self, performSelector:aSelector 696 | target:target 697 | argument:anArgument 698 | order:order 699 | modes:modes] 700 | } 701 | } 702 | 703 | pub trait NSData: Sized { 704 | unsafe fn data(_: Self) -> id { 705 | msg_send![class("NSData"), data] 706 | } 707 | 708 | unsafe fn dataWithBytes_length_(_: Self, bytes: *const libc::c_void, length: NSUInteger) -> id { 709 | msg_send![class("NSData"), dataWithBytes:bytes length:length] 710 | } 711 | 712 | unsafe fn dataWithBytesNoCopy_length_(_: Self, bytes: *const libc::c_void, length: NSUInteger) -> id { 713 | msg_send![class("NSData"), dataWithBytesNoCopy:bytes length:length] 714 | } 715 | 716 | unsafe fn dataWithBytesNoCopy_length_freeWhenDone_(_: Self, bytes: *const libc::c_void, 717 | length: NSUInteger, freeWhenDone: BOOL) -> id { 718 | msg_send![class("NSData"), dataWithBytesNoCopy:bytes length:length freeWhenDone:freeWhenDone] 719 | } 720 | 721 | unsafe fn dataWithContentsOfFile_(_: Self, path: id) -> id { 722 | msg_send![class("NSData"), dataWithContentsOfFile:path] 723 | } 724 | 725 | unsafe fn dataWithContentsOfFile_options_error_(_: Self, path: id, mask: NSDataReadingOptions, 726 | errorPtr: *mut id) -> id { 727 | msg_send![class("NSData"), dataWithContentsOfFile:path options:mask error:errorPtr] 728 | } 729 | 730 | unsafe fn dataWithContentsOfURL_(_: Self, aURL: id) -> id { 731 | msg_send![class("NSData"), dataWithContentsOfURL:aURL] 732 | } 733 | 734 | unsafe fn dataWithContentsOfURL_options_error_(_: Self, aURL: id, mask: NSDataReadingOptions, 735 | errorPtr: *mut id) -> id { 736 | msg_send![class("NSData"), dataWithContentsOfURL:aURL options:mask error:errorPtr] 737 | } 738 | 739 | unsafe fn dataWithData_(_: Self, aData: id) -> id { 740 | msg_send![class("NSData"), dataWithData:aData] 741 | } 742 | 743 | unsafe fn initWithBase64EncodedData_options_(self, base64Data: id, options: NSDataBase64DecodingOptions) 744 | -> id; 745 | unsafe fn initWithBase64EncodedString_options_(self, base64String: id, options: NSDataBase64DecodingOptions) 746 | -> id; 747 | unsafe fn initWithBytes_length_(self, bytes: *const libc::c_void, length: NSUInteger) -> id; 748 | unsafe fn initWithBytesNoCopy_length_(self, bytes: *const libc::c_void, length: NSUInteger) -> id; 749 | unsafe fn initWithBytesNoCopy_length_deallocator_(self, bytes: *const libc::c_void, length: NSUInteger, 750 | deallocator: *mut Block<(*const libc::c_void, NSUInteger), ()>) 751 | -> id; 752 | unsafe fn initWithBytesNoCopy_length_freeWhenDone_(self, bytes: *const libc::c_void, 753 | length: NSUInteger, freeWhenDone: BOOL) -> id; 754 | unsafe fn initWithContentsOfFile_(self, path: id) -> id; 755 | unsafe fn initWithContentsOfFile_options_error(self, path: id, mask: NSDataReadingOptions, errorPtr: *mut id) 756 | -> id; 757 | unsafe fn initWithContentsOfURL_(self, aURL: id) -> id; 758 | unsafe fn initWithContentsOfURL_options_error_(self, aURL: id, mask: NSDataReadingOptions, errorPtr: *mut id) 759 | -> id; 760 | unsafe fn initWithData_(self, data: id) -> id; 761 | 762 | unsafe fn bytes(self) -> *const libc::c_void; 763 | unsafe fn description(self) -> id; 764 | unsafe fn enumerateByteRangesUsingBlock_(self, block: *mut Block<(*const libc::c_void, NSRange, *mut BOOL), ()>); 765 | unsafe fn getBytes_length_(self, buffer: *mut libc::c_void, length: NSUInteger); 766 | unsafe fn getBytes_range_(self, buffer: *mut libc::c_void, range: NSRange); 767 | unsafe fn subdataWithRange_(self, range: NSRange) -> id; 768 | unsafe fn rangeOfData_options_range_(self, dataToFind: id, options: NSDataSearchOptions, searchRange: NSRange) 769 | -> NSRange; 770 | 771 | unsafe fn base64EncodedDataWithOptions_(self, options: NSDataBase64EncodingOptions) -> id; 772 | unsafe fn base64EncodedStringWithOptions_(self, options: NSDataBase64EncodingOptions) -> id; 773 | 774 | unsafe fn isEqualToData_(self, otherData: id) -> id; 775 | unsafe fn length(self) -> NSUInteger; 776 | 777 | unsafe fn writeToFile_atomically_(self, path: id, atomically: BOOL) -> BOOL; 778 | unsafe fn writeToFile_options_error_(self, path: id, mask: NSDataWritingOptions, errorPtr: *mut id) -> BOOL; 779 | unsafe fn writeToURL_atomically_(self, aURL: id, atomically: BOOL) -> BOOL; 780 | unsafe fn writeToURL_options_error_(self, aURL: id, mask: NSDataWritingOptions, errorPtr: *mut id) -> BOOL; 781 | } 782 | 783 | impl NSData for id { 784 | unsafe fn initWithBase64EncodedData_options_(self, base64Data: id, options: NSDataBase64DecodingOptions) 785 | -> id { 786 | msg_send![self, initWithBase64EncodedData:base64Data options:options] 787 | } 788 | 789 | unsafe fn initWithBase64EncodedString_options_(self, base64String: id, options: NSDataBase64DecodingOptions) 790 | -> id { 791 | msg_send![self, initWithBase64EncodedString:base64String options:options] 792 | } 793 | 794 | unsafe fn initWithBytes_length_(self, bytes: *const libc::c_void, length: NSUInteger) -> id { 795 | msg_send![self,initWithBytes:bytes length:length] 796 | } 797 | 798 | unsafe fn initWithBytesNoCopy_length_(self, bytes: *const libc::c_void, length: NSUInteger) -> id { 799 | msg_send![self, initWithBytesNoCopy:bytes length:length] 800 | } 801 | 802 | unsafe fn initWithBytesNoCopy_length_deallocator_(self, bytes: *const libc::c_void, length: NSUInteger, 803 | deallocator: *mut Block<(*const libc::c_void, NSUInteger), ()>) 804 | -> id { 805 | msg_send![self, initWithBytesNoCopy:bytes length:length deallocator:deallocator] 806 | } 807 | 808 | unsafe fn initWithBytesNoCopy_length_freeWhenDone_(self, bytes: *const libc::c_void, 809 | length: NSUInteger, freeWhenDone: BOOL) -> id { 810 | msg_send![self, initWithBytesNoCopy:bytes length:length freeWhenDone:freeWhenDone] 811 | } 812 | 813 | unsafe fn initWithContentsOfFile_(self, path: id) -> id { 814 | msg_send![self, initWithContentsOfFile:path] 815 | } 816 | 817 | unsafe fn initWithContentsOfFile_options_error(self, path: id, mask: NSDataReadingOptions, errorPtr: *mut id) 818 | -> id { 819 | msg_send![self, initWithContentsOfFile:path options:mask error:errorPtr] 820 | } 821 | 822 | unsafe fn initWithContentsOfURL_(self, aURL: id) -> id { 823 | msg_send![self, initWithContentsOfURL:aURL] 824 | } 825 | 826 | unsafe fn initWithContentsOfURL_options_error_(self, aURL: id, mask: NSDataReadingOptions, errorPtr: *mut id) 827 | -> id { 828 | msg_send![self, initWithContentsOfURL:aURL options:mask error:errorPtr] 829 | } 830 | 831 | unsafe fn initWithData_(self, data: id) -> id { 832 | msg_send![self, initWithData:data] 833 | } 834 | 835 | unsafe fn bytes(self) -> *const libc::c_void { 836 | msg_send![self, bytes] 837 | } 838 | 839 | unsafe fn description(self) -> id { 840 | msg_send![self, description] 841 | } 842 | 843 | unsafe fn enumerateByteRangesUsingBlock_(self, block: *mut Block<(*const libc::c_void, NSRange, *mut BOOL), ()>) { 844 | msg_send![self, enumerateByteRangesUsingBlock:block] 845 | } 846 | 847 | unsafe fn getBytes_length_(self, buffer: *mut libc::c_void, length: NSUInteger) { 848 | msg_send![self, getBytes:buffer length:length] 849 | } 850 | 851 | unsafe fn getBytes_range_(self, buffer: *mut libc::c_void, range: NSRange) { 852 | msg_send![self, getBytes:buffer range:range] 853 | } 854 | 855 | unsafe fn subdataWithRange_(self, range: NSRange) -> id { 856 | msg_send![self, subdataWithRange:range] 857 | } 858 | 859 | unsafe fn rangeOfData_options_range_(self, dataToFind: id, options: NSDataSearchOptions, searchRange: NSRange) 860 | -> NSRange { 861 | msg_send![self, rangeOfData:dataToFind options:options range:searchRange] 862 | } 863 | 864 | unsafe fn base64EncodedDataWithOptions_(self, options: NSDataBase64EncodingOptions) -> id { 865 | msg_send![self, base64EncodedDataWithOptions:options] 866 | } 867 | 868 | unsafe fn base64EncodedStringWithOptions_(self, options: NSDataBase64EncodingOptions) -> id { 869 | msg_send![self, base64EncodedStringWithOptions:options] 870 | } 871 | 872 | unsafe fn isEqualToData_(self, otherData: id) -> id { 873 | msg_send![self, isEqualToData:otherData] 874 | } 875 | 876 | unsafe fn length(self) -> NSUInteger { 877 | msg_send![self, length] 878 | } 879 | 880 | unsafe fn writeToFile_atomically_(self, path: id, atomically: BOOL) -> BOOL { 881 | msg_send![self, writeToFile:path atomically:atomically] 882 | } 883 | 884 | unsafe fn writeToFile_options_error_(self, path: id, mask: NSDataWritingOptions, errorPtr: *mut id) -> BOOL { 885 | msg_send![self, writeToFile:path options:mask error:errorPtr] 886 | } 887 | 888 | unsafe fn writeToURL_atomically_(self, aURL: id, atomically: BOOL) -> BOOL { 889 | msg_send![self, writeToURL:aURL atomically:atomically] 890 | } 891 | 892 | unsafe fn writeToURL_options_error_(self, aURL: id, mask: NSDataWritingOptions, errorPtr: *mut id) -> BOOL { 893 | msg_send![self, writeToURL:aURL options:mask error:errorPtr] 894 | } 895 | } 896 | 897 | bitflags! { 898 | pub struct NSDataReadingOptions: libc::c_ulonglong { 899 | const NSDataReadingMappedIfSafe = 1 << 0; 900 | const NSDataReadingUncached = 1 << 1; 901 | const NSDataReadingMappedAlways = 1 << 3; 902 | } 903 | } 904 | 905 | bitflags! { 906 | pub struct NSDataBase64EncodingOptions: libc::c_ulonglong { 907 | const NSDataBase64Encoding64CharacterLineLength = 1 << 0; 908 | const NSDataBase64Encoding76CharacterLineLength = 1 << 1; 909 | const NSDataBase64EncodingEndLineWithCarriageReturn = 1 << 4; 910 | const NSDataBase64EncodingEndLineWithLineFeed = 1 << 5; 911 | } 912 | } 913 | 914 | bitflags! { 915 | pub struct NSDataBase64DecodingOptions: libc::c_ulonglong { 916 | const NSDataBase64DecodingIgnoreUnknownCharacters = 1 << 0; 917 | } 918 | } 919 | 920 | bitflags! { 921 | pub struct NSDataWritingOptions: libc::c_ulonglong { 922 | const NSDataWritingAtomic = 1 << 0; 923 | const NSDataWritingWithoutOverwriting = 1 << 1; 924 | } 925 | } 926 | 927 | bitflags! { 928 | pub struct NSDataSearchOptions: libc::c_ulonglong { 929 | const NSDataSearchBackwards = 1 << 0; 930 | const NSDataSearchAnchored = 1 << 1; 931 | } 932 | } 933 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Servo Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution. 3 | // 4 | // Licensed under the Apache License, Version 2.0 or the MIT license 6 | // , at your 7 | // option. This file may not be copied, modified, or distributed 8 | // except according to those terms. 9 | 10 | #![crate_name = "cocoa"] 11 | #![crate_type = "rlib"] 12 | 13 | #![allow(non_snake_case)] 14 | 15 | extern crate block; 16 | #[macro_use] 17 | extern crate bitflags; 18 | extern crate libc; 19 | extern crate core_graphics; 20 | #[macro_use] 21 | extern crate objc; 22 | 23 | #[cfg(target_os = "macos")] 24 | pub mod appkit; 25 | pub mod base; 26 | pub mod foundation; 27 | -------------------------------------------------------------------------------- /tests/foundation.rs: -------------------------------------------------------------------------------- 1 | #[macro_use] 2 | extern crate objc; 3 | extern crate block; 4 | extern crate cocoa; 5 | 6 | #[cfg(test)] 7 | mod foundation { 8 | mod nsstring { 9 | use cocoa::foundation::NSString; 10 | use cocoa::base::nil; 11 | use std::slice; 12 | use std::str; 13 | 14 | #[test] 15 | fn test_utf8() { 16 | let expected = "Iñtërnâtiônàlizætiøn"; 17 | unsafe { 18 | let built = NSString::alloc(nil).init_str(expected); 19 | let bytes = built.UTF8String() as *const u8; 20 | let objc_string = str::from_utf8(slice::from_raw_parts(bytes, built.len())) 21 | .unwrap(); 22 | assert!(objc_string.len() == expected.len()); 23 | assert!(objc_string == expected); 24 | } 25 | } 26 | 27 | #[test] 28 | fn test_string() { 29 | let expected = "Hello World!"; 30 | unsafe { 31 | let built = NSString::alloc(nil).init_str(expected); 32 | let bytes = built.UTF8String() as *const u8; 33 | let objc_string = str::from_utf8(slice::from_raw_parts(bytes, built.len())) 34 | .unwrap(); 35 | assert!(objc_string.len() == expected.len()); 36 | assert!(objc_string == expected); 37 | } 38 | } 39 | 40 | #[test] 41 | fn test_length() { 42 | let expected = "Hello!"; 43 | unsafe { 44 | let built = NSString::alloc(nil).init_str(expected); 45 | assert!(built.len() == expected.len()); 46 | } 47 | } 48 | 49 | #[test] 50 | fn test_append_by_appending_string() { 51 | let initial_str = "Iñtërnâtiônàlizætiøn"; 52 | let to_append = "_more_strings"; 53 | let expected = concat!("Iñtërnâtiônàlizætiøn", "_more_strings"); 54 | unsafe { 55 | let built = NSString::alloc(nil).init_str(initial_str); 56 | let built_to_append = NSString::alloc(nil).init_str(to_append); 57 | let append_string = built.stringByAppendingString_(built_to_append); 58 | let bytes = append_string.UTF8String() as *const u8; 59 | let objc_string = str::from_utf8(slice::from_raw_parts(bytes, append_string.len())) 60 | .unwrap(); 61 | assert!(objc_string == expected); 62 | } 63 | } 64 | } 65 | 66 | mod nsfastenumeration { 67 | use std::str; 68 | use std::slice; 69 | use cocoa::foundation::{NSString, NSFastEnumeration}; 70 | use cocoa::base::{id, nil}; 71 | 72 | #[test] 73 | fn test_iter() { 74 | unsafe { 75 | let string = NSString::alloc(nil).init_str("this is a test string"); 76 | let separator = NSString::alloc(nil).init_str(" "); 77 | let components: id = msg_send![string, componentsSeparatedByString: separator]; 78 | 79 | let combined = components.iter() 80 | .map(|s| { 81 | let bytes = s.UTF8String() as *const u8; 82 | str::from_utf8(slice::from_raw_parts(bytes, s.len())).unwrap() 83 | }) 84 | .fold(String::new(), |mut acc, s| { 85 | acc.push_str(s); 86 | acc 87 | }); 88 | 89 | assert_eq!(combined, "thisisateststring"); 90 | } 91 | } 92 | 93 | #[test] 94 | #[should_panic] 95 | fn test_mutation() { 96 | unsafe { 97 | let string = NSString::alloc(nil).init_str("this is a test string"); 98 | let separator = NSString::alloc(nil).init_str(" "); 99 | let components: id = msg_send![string, componentsSeparatedByString: separator]; 100 | let mut_components: id = msg_send![components, mutableCopy]; 101 | let mut iter = mut_components.iter(); 102 | iter.next(); 103 | msg_send![mut_components, removeObjectAtIndex:1]; 104 | iter.next(); 105 | } 106 | } 107 | } 108 | 109 | mod nsdictionary { 110 | use block::ConcreteBlock; 111 | use cocoa::foundation::{NSArray, NSComparisonResult, NSDictionary, NSFastEnumeration, 112 | NSString}; 113 | use cocoa::base::{id, nil}; 114 | 115 | #[test] 116 | fn test_get() { 117 | const KEY: &'static str = "The key"; 118 | const VALUE: &'static str = "Some value"; 119 | unsafe { 120 | let key = NSString::alloc(nil).init_str(KEY); 121 | let value = NSString::alloc(nil).init_str(VALUE); 122 | let dict = NSDictionary::dictionaryWithObject_forKey_(nil, value, key); 123 | 124 | let retrieved_value = dict.objectForKey_(key); 125 | assert!(retrieved_value.isEqualToString(VALUE)); 126 | } 127 | } 128 | 129 | #[test] 130 | fn test_iter() { 131 | let mkstr = |s| unsafe { NSString::alloc(nil).init_str(s) }; 132 | let keys = vec!["a", "b", "c", "d", "e", "f"]; 133 | let objects = vec!["1", "2", "3", "4", "5", "6"]; 134 | unsafe { 135 | use std::{slice, str}; 136 | use std::cmp::{Ord, Ordering}; 137 | 138 | let keys_raw_vec = keys.clone().into_iter().map(&mkstr).collect::>(); 139 | let objs_raw_vec = objects.clone().into_iter().map(&mkstr).collect::>(); 140 | 141 | let keys_array = NSArray::arrayWithObjects(nil, &keys_raw_vec); 142 | let objs_array = NSArray::arrayWithObjects(nil, &objs_raw_vec); 143 | 144 | let dict = 145 | NSDictionary::dictionaryWithObjects_forKeys_(nil, objs_array, keys_array); 146 | 147 | // NSDictionary does not store its contents in order of insertion, so ask for 148 | // sorted iterators to ensure that each item is the same as its counterpart in 149 | // the vector. 150 | 151 | // First test cocoa sorting... 152 | let mut comparator = ConcreteBlock::new(|s0: id, s1: id| { 153 | let (bytes0, len0) = (s0.UTF8String() as *const u8, s0.len()); 154 | let (bytes1, len1) = (s1.UTF8String() as *const u8, s1.len()); 155 | let (s0, s1) = (str::from_utf8(slice::from_raw_parts(bytes0, len0)).unwrap(), 156 | str::from_utf8(slice::from_raw_parts(bytes1, len1)).unwrap()); 157 | let (c0, c1) = (s0.chars().next().unwrap(), s1.chars().next().unwrap()); 158 | match c0.cmp(&c1) { 159 | Ordering::Less => NSComparisonResult::NSOrderedAscending, 160 | Ordering::Equal => NSComparisonResult::NSOrderedSame, 161 | Ordering::Greater => NSComparisonResult::NSOrderedDescending, 162 | } 163 | }); 164 | 165 | let associated_iter = keys.iter().zip(objects.iter()); 166 | for (k_id, (k, v)) in dict.keysSortedByValueUsingComparator_(&mut *comparator) 167 | .iter() 168 | .zip(associated_iter) { 169 | assert!(k_id.isEqualToString(k)); 170 | let v_id = dict.objectForKey_(k_id); 171 | assert!(v_id.isEqualToString(v)); 172 | } 173 | 174 | // Then use rust sorting 175 | let mut keys_arr = dict.allKeys().iter().collect::>(); 176 | keys_arr.sort(); 177 | for (k0, k1) in keys_arr.into_iter().zip(keys.iter()) { 178 | assert!(k0.isEqualToString(k1)); 179 | } 180 | 181 | let mut objects_arr = dict.allValues().iter().collect::>(); 182 | objects_arr.sort(); 183 | for (v0, v1) in objects_arr.into_iter().zip(objects.iter()) { 184 | assert!(v0.isEqualToString(v1)); 185 | } 186 | } 187 | } 188 | } 189 | } 190 | --------------------------------------------------------------------------------