├── cocoa ├── LICENSE-MIT ├── LICENSE-APACHE ├── .travis.yml ├── .gitignore ├── COPYRIGHT ├── README.md ├── Cargo.toml ├── src │ ├── lib.rs │ └── macros.rs └── examples │ ├── hello_world.rs │ ├── tab_view.rs │ ├── nsvisualeffectview_blur.rs │ └── fullscreen.rs ├── core-text ├── LICENSE-MIT ├── README.md ├── LICENSE-APACHE ├── .travis.yml ├── .gitignore ├── COPYRIGHT ├── Cargo.toml └── src │ ├── lib.rs │ ├── string_attributes.rs │ ├── font_manager.rs │ ├── framesetter.rs │ ├── frame.rs │ └── line.rs ├── io-surface ├── LICENSE-MIT ├── LICENSE-APACHE ├── .gitignore ├── .travis.yml ├── COPYRIGHT └── Cargo.toml ├── .gitignore ├── cocoa-foundation ├── LICENSE-MIT ├── LICENSE-APACHE ├── .travis.yml ├── .gitignore ├── src │ ├── lib.rs │ └── base.rs └── Cargo.toml ├── core-foundation ├── LICENSE-MIT ├── LICENSE-APACHE ├── src │ ├── characterset.rs │ ├── mach_port.rs │ ├── date.rs │ ├── set.rs │ ├── boolean.rs │ ├── error.rs │ ├── timezone.rs │ ├── uuid.rs │ ├── attributed_string.rs │ ├── number.rs │ └── data.rs ├── Cargo.toml └── tests │ └── use_macro_outside_crate.rs ├── core-graphics ├── LICENSE-MIT ├── LICENSE-APACHE ├── README.md ├── .gitignore ├── .travis.yml ├── COPYRIGHT ├── src │ ├── geometry.rs │ ├── access.rs │ ├── lib.rs │ ├── sys.rs │ ├── event_source.rs │ ├── base.rs │ ├── color.rs │ ├── gradient.rs │ ├── path.rs │ └── color_space.rs └── Cargo.toml ├── core-foundation-sys ├── LICENSE-MIT ├── LICENSE-APACHE ├── Cargo.toml └── src │ ├── date.rs │ ├── lib.rs │ ├── error.rs │ ├── uuid.rs │ ├── mach_port.rs │ ├── url_enumerator.rs │ ├── tree.rs │ ├── bit_vector.rs │ ├── data.rs │ ├── filedescriptor.rs │ ├── binary_heap.rs │ ├── notification_center.rs │ ├── file_security.rs │ ├── string_tokenizer.rs │ ├── timezone.rs │ ├── set.rs │ ├── number.rs │ ├── preferences.rs │ ├── bag.rs │ ├── messageport.rs │ ├── propertylist.rs │ ├── plugin.rs │ ├── attributed_string.rs │ ├── array.rs │ ├── xml_node.rs │ ├── characterset.rs │ ├── calendar.rs │ └── dictionary.rs ├── core-graphics-types ├── LICENSE-MIT ├── LICENSE-APACHE ├── src │ ├── lib.rs │ └── base.rs └── Cargo.toml ├── clippy.toml ├── COPYRIGHT ├── .travis.yml ├── .typos.toml ├── README.md ├── LICENSE-MIT ├── Cargo.toml └── .github └── workflows └── rust.yml /cocoa/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | ../LICENSE-MIT -------------------------------------------------------------------------------- /cocoa/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | ../LICENSE-APACHE -------------------------------------------------------------------------------- /core-text/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | ../LICENSE-MIT -------------------------------------------------------------------------------- /core-text/README.md: -------------------------------------------------------------------------------- 1 | # core-text-rs 2 | -------------------------------------------------------------------------------- /io-surface/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | ../LICENSE-MIT -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | Cargo.lock 2 | target/ 3 | 4 | -------------------------------------------------------------------------------- /cocoa-foundation/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | ../LICENSE-MIT -------------------------------------------------------------------------------- /core-foundation/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | ../LICENSE-MIT -------------------------------------------------------------------------------- /core-graphics/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | ../LICENSE-MIT -------------------------------------------------------------------------------- /core-text/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | ../LICENSE-APACHE -------------------------------------------------------------------------------- /io-surface/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | ../LICENSE-APACHE -------------------------------------------------------------------------------- /cocoa-foundation/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | ../LICENSE-APACHE -------------------------------------------------------------------------------- /core-foundation-sys/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | ../LICENSE-MIT -------------------------------------------------------------------------------- /core-foundation/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | ../LICENSE-APACHE -------------------------------------------------------------------------------- /core-graphics-types/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | ../LICENSE-MIT -------------------------------------------------------------------------------- /core-graphics/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | ../LICENSE-APACHE -------------------------------------------------------------------------------- /core-graphics/README.md: -------------------------------------------------------------------------------- 1 | # core-graphics-rs 2 | -------------------------------------------------------------------------------- /cocoa/.travis.yml: -------------------------------------------------------------------------------- 1 | os: osx 2 | 3 | language: rust 4 | -------------------------------------------------------------------------------- /core-foundation-sys/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | ../LICENSE-APACHE -------------------------------------------------------------------------------- /core-graphics-types/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | ../LICENSE-APACHE -------------------------------------------------------------------------------- /io-surface/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /doc 3 | /Cargo.lock 4 | -------------------------------------------------------------------------------- /cocoa/.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | build 3 | /target 4 | /Cargo.lock 5 | -------------------------------------------------------------------------------- /cocoa-foundation/.travis.yml: -------------------------------------------------------------------------------- 1 | os: osx 2 | 3 | language: rust 4 | -------------------------------------------------------------------------------- /clippy.toml: -------------------------------------------------------------------------------- 1 | doc-valid-idents = ["ACEScg", "CoreFoundation", ".."] 2 | -------------------------------------------------------------------------------- /cocoa-foundation/.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | build 3 | /target 4 | /Cargo.lock 5 | -------------------------------------------------------------------------------- /core-text/.travis.yml: -------------------------------------------------------------------------------- 1 | language: rust 2 | rust: 3 | - nightly 4 | - beta 5 | - stable 6 | os: osx 7 | -------------------------------------------------------------------------------- /core-text/.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *# 3 | *.o 4 | *.a 5 | *.so 6 | *.dylib 7 | *.dSYM 8 | *.dll 9 | *.dummy 10 | cocoa-test 11 | build 12 | /target 13 | /doc 14 | /Cargo.lock 15 | -------------------------------------------------------------------------------- /io-surface/.travis.yml: -------------------------------------------------------------------------------- 1 | os: osx 2 | language: rust 3 | cache: cargo 4 | rust: 5 | - stable 6 | - beta 7 | - nightly 8 | branches: 9 | except: 10 | - master 11 | -------------------------------------------------------------------------------- /core-graphics/.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *# 3 | *.o 4 | *.a 5 | *.so 6 | *.dylib 7 | *.dSYM 8 | *.dll 9 | *.dummy 10 | cocoa-test 11 | build 12 | /target 13 | /doc 14 | /Cargo.lock 15 | -------------------------------------------------------------------------------- /core-graphics/.travis.yml: -------------------------------------------------------------------------------- 1 | language: rust 2 | os: osx 3 | rust: 4 | - nightly 5 | - beta 6 | - stable 7 | 8 | script: 9 | - cargo test 10 | - cargo test --features="elcapitan" 11 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /cocoa/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 | -------------------------------------------------------------------------------- /core-text/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 | -------------------------------------------------------------------------------- /io-surface/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 | -------------------------------------------------------------------------------- /cocoa/README.md: -------------------------------------------------------------------------------- 1 | Cocoa-rs 2 | -------- 3 | 4 | NOTE: This crate has been deprecated in favour of the `objc2` crates. 5 | 6 | This crate provides Rust bindings to Cocoa for macOS. It's dual-licensed MIT / 7 | Apache 2.0. If you'd like to help improve cocoa-rs, check out [the Servo 8 | contributing guide](https://github.com/servo/servo/blob/main/CONTRIBUTING.md)! 9 | -------------------------------------------------------------------------------- /core-graphics/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 | -------------------------------------------------------------------------------- /core-graphics-types/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 | pub mod base; 11 | pub mod geometry; 12 | -------------------------------------------------------------------------------- /core-graphics/src/geometry.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 | pub use core_graphics_types::geometry::*; 11 | -------------------------------------------------------------------------------- /core-graphics-types/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "core-graphics-types" 3 | description = "Bindings for some fundamental Core Graphics types" 4 | version = "0.2.0" 5 | 6 | authors.workspace = true 7 | edition.workspace = true 8 | license.workspace = true 9 | repository.workspace = true 10 | rust-version.workspace = true 11 | 12 | [package.metadata.docs.rs] 13 | default-target = "x86_64-apple-darwin" 14 | 15 | [lints] 16 | workspace = true 17 | 18 | [dependencies] 19 | core-foundation.workspace = true 20 | 21 | [features] 22 | default = ["link"] 23 | # Disable to manually link. Enabled by default. 24 | link = ["core-foundation/link"] 25 | -------------------------------------------------------------------------------- /cocoa-foundation/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 | //! This crate has been deprecated in favour of the `objc2-foundation` crate. 11 | #![allow(non_snake_case, deprecated)] 12 | 13 | pub mod base; 14 | pub mod foundation; 15 | -------------------------------------------------------------------------------- /core-foundation-sys/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "core-foundation-sys" 3 | description = "Bindings to Core Foundation for macOS" 4 | version = "0.8.7" 5 | 6 | authors.workspace = true 7 | edition.workspace = true 8 | license.workspace = true 9 | repository.workspace = true 10 | rust-version.workspace = true 11 | 12 | [package.metadata.docs.rs] 13 | all-features = true 14 | default-target = "x86_64-apple-darwin" 15 | 16 | [lints] 17 | workspace = true 18 | 19 | [dependencies] 20 | 21 | [features] 22 | default = ["link"] 23 | mac_os_10_7_support = [] # backwards compatibility 24 | mac_os_10_8_features = [] # enables new features 25 | # Disable to manually link. Enabled by default. 26 | link = [] 27 | -------------------------------------------------------------------------------- /io-surface/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "io-surface" 3 | description = "Bindings to IO Surface for macOS" 4 | version = "0.16.1" 5 | 6 | authors.workspace = true 7 | edition.workspace = true 8 | license.workspace = true 9 | repository.workspace = true 10 | rust-version.workspace = true 11 | 12 | [package.metadata.docs.rs] 13 | default-target = "x86_64-apple-darwin" 14 | 15 | [lints] 16 | workspace = true 17 | 18 | [dependencies] 19 | core-foundation.workspace = true 20 | core-foundation-sys.workspace = true 21 | 22 | cgl = "0.3" 23 | leaky-cow = "0.1.1" 24 | 25 | [features] 26 | default = ["link"] 27 | # Disable to manually link. Enabled by default. 28 | link = ["core-foundation/link", "core-foundation-sys/link"] 29 | -------------------------------------------------------------------------------- /cocoa-foundation/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "cocoa-foundation" 3 | description = "Bindings to Cocoa Foundation for macOS" 4 | version = "0.2.1" 5 | 6 | authors.workspace = true 7 | edition.workspace = true 8 | license.workspace = true 9 | repository.workspace = true 10 | rust-version.workspace = true 11 | 12 | [package.metadata.docs.rs] 13 | default-target = "x86_64-apple-darwin" 14 | 15 | [lints] 16 | workspace = true 17 | 18 | [dependencies] 19 | core-foundation.workspace = true 20 | core-graphics-types.workspace = true 21 | 22 | bitflags = "2" 23 | block = "0.1" 24 | objc = "0.2.3" 25 | 26 | [features] 27 | default = ["link"] 28 | # Disable to manually link. Enabled by default. 29 | link = ["core-foundation/link", "core-graphics-types/link"] 30 | -------------------------------------------------------------------------------- /core-graphics/src/access.rs: -------------------------------------------------------------------------------- 1 | #[derive(Default)] 2 | pub struct ScreenCaptureAccess; 3 | 4 | impl ScreenCaptureAccess { 5 | /// If current app not in list, will open window. 6 | /// Return the same result as preflight. 7 | #[inline] 8 | pub fn request(&self) -> bool { 9 | unsafe { CGRequestScreenCaptureAccess() } 10 | } 11 | 12 | /// Return `true` if has access 13 | #[inline] 14 | pub fn preflight(&self) -> bool { 15 | unsafe { CGPreflightScreenCaptureAccess() } 16 | } 17 | } 18 | 19 | #[cfg_attr(feature = "link", link(name = "CoreGraphics", kind = "framework"))] 20 | extern "C" { 21 | // Screen Capture Access 22 | fn CGRequestScreenCaptureAccess() -> bool; 23 | fn CGPreflightScreenCaptureAccess() -> bool; 24 | } 25 | -------------------------------------------------------------------------------- /cocoa/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "cocoa" 3 | description = "Bindings to Cocoa for macOS" 4 | version = "0.26.1" 5 | 6 | authors.workspace = true 7 | edition.workspace = true 8 | license.workspace = true 9 | repository.workspace = true 10 | rust-version.workspace = true 11 | 12 | [package.metadata.docs.rs] 13 | default-target = "x86_64-apple-darwin" 14 | 15 | [lints] 16 | workspace = true 17 | 18 | [dependencies] 19 | cocoa-foundation.workspace = true 20 | core-foundation.workspace = true 21 | core-graphics.workspace = true 22 | 23 | bitflags = "2" 24 | block = "0.1" 25 | foreign-types = "0.5" 26 | libc = "0.2" 27 | objc = "0.2.3" 28 | 29 | [features] 30 | default = ["link"] 31 | # Disable to manually link. Enabled by default. 32 | link = ["core-foundation/link", "cocoa-foundation/link", "core-graphics/link"] 33 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | os: osx 2 | language: rust 3 | rust: stable 4 | if: branch != master OR type != push 5 | matrix: 6 | include: 7 | # macOS 10.11 8 | - osx_image: xcode7.3 9 | env: TARGET=x86_64-apple-darwin CGFEATURES="" 10 | # macOS 10.12 11 | - osx_image: xcode9.2 12 | env: TARGET=x86_64-apple-darwin CGFEATURES="--features elcapitan" 13 | # macOS 10.13 14 | - osx_image: xcode9.4 15 | env: TARGET=x86_64-apple-darwin CGFEATURES="--features highsierra,elcapitan" 16 | # macOS 10.14 17 | - osx_image: xcode11.3 18 | env: TARGET=x86_64-apple-darwin CGFEATURES="--features highsierra,elcapitan" 19 | 20 | install: 21 | - rustup target add $TARGET 22 | script: 23 | - cargo build --all-targets --verbose --target $TARGET 24 | - cargo test --verbose --target $TARGET -- --nocapture 25 | -------------------------------------------------------------------------------- /core-graphics/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "core-graphics" 3 | description = "Bindings to Core Graphics for macOS" 4 | version = "0.25.0" 5 | 6 | authors.workspace = true 7 | edition.workspace = true 8 | license.workspace = true 9 | repository.workspace = true 10 | rust-version.workspace = true 11 | 12 | [package.metadata.docs.rs] 13 | all-features = true 14 | default-target = "x86_64-apple-darwin" 15 | 16 | [lints] 17 | workspace = true 18 | 19 | [dependencies] 20 | core-foundation.workspace = true 21 | core-graphics-types.workspace = true 22 | 23 | bitflags = "2" 24 | foreign-types = "0.5.0" 25 | libc = "0.2" 26 | 27 | [features] 28 | default = ["link"] 29 | elcapitan = [] 30 | highsierra = [] 31 | catalina = [] 32 | # Disable to manually link. Enabled by default. 33 | link = ["core-foundation/link", "core-graphics-types/link"] 34 | -------------------------------------------------------------------------------- /core-foundation/src/characterset.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2019 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 | //! A set of Unicode compliant characters. 11 | 12 | pub use core_foundation_sys::characterset::*; 13 | 14 | declare_TCFType! { 15 | /// An immutable set of Unicode characters. 16 | CFCharacterSet, CFCharacterSetRef 17 | } 18 | impl_TCFType!(CFCharacterSet, CFCharacterSetRef, CFCharacterSetGetTypeID); 19 | impl_CFTypeDescription!(CFCharacterSet); 20 | -------------------------------------------------------------------------------- /cocoa/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 | //! This crate has been deprecated in favour of the `objc2` crates. 11 | #![crate_name = "cocoa"] 12 | #![crate_type = "rlib"] 13 | #![allow(non_snake_case, deprecated)] 14 | 15 | #[cfg(target_os = "macos")] 16 | pub mod appkit; 17 | pub use cocoa_foundation::base; 18 | pub use cocoa_foundation::foundation; 19 | #[cfg(target_os = "macos")] 20 | pub mod quartzcore; 21 | #[macro_use] 22 | mod macros; 23 | -------------------------------------------------------------------------------- /core-text/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "core-text" 3 | version = "21.0.0" 4 | description = "Bindings to the Core Text framework." 5 | 6 | authors.workspace = true 7 | edition.workspace = true 8 | license.workspace = true 9 | repository.workspace = true 10 | rust-version.workspace = true 11 | 12 | [package.metadata.docs.rs] 13 | all-features = true 14 | default-target = "x86_64-apple-darwin" 15 | 16 | [lints] 17 | workspace = true 18 | 19 | [dependencies] 20 | core-foundation.workspace = true 21 | core-graphics.workspace = true 22 | 23 | foreign-types = "0.5" 24 | 25 | [features] 26 | default = ["mountainlion", "link"] 27 | # For OS X 10.7 compat, exclude this feature. It will exclude some things from 28 | # the exposed APIs in the crate. 29 | mountainlion = [] 30 | # Disable to manually link. Enabled by default. 31 | link = ["core-foundation/link", "core-graphics/link"] 32 | -------------------------------------------------------------------------------- /.typos.toml: -------------------------------------------------------------------------------- 1 | # See the configuration reference at 2 | # https://github.com/crate-ci/typos/blob/master/docs/reference.md 3 | 4 | # Corrections take the form of a key/value pair. The key is the incorrect word 5 | # and the value is the correct word. If the key and value are the same, the 6 | # word is treated as always correct. If the value is an empty string, the word 7 | # is treated as always incorrect. 8 | 9 | # Match Identifier - Case Sensitive 10 | [default.extend-identifiers] 11 | setShowsApplicatinBadge_ = "setShowsApplicatinBadge_" 12 | showsApplicatinBadge = "showsApplicatinBadge" 13 | 14 | # Match Inside a Word - Case Insensitive 15 | [default.extend-words] 16 | 17 | [files] 18 | # Include .github, .cargo, etc. 19 | ignore-hidden = false 20 | # /.git isn't in .gitignore, because git never tracks it. 21 | # Typos doesn't know that, though. 22 | extend-exclude = ["/.git"] 23 | 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # core-foundation-rs 2 | 3 | [![Build Status](https://github.com/servo/core-foundation-rs/actions/workflows/rust.yml/badge.svg)](https://github.com/servo/core-foundation-rs/actions) 4 | 5 | ## Compatibility 6 | 7 | Targets macOS 10.7 by default. 8 | 9 | To enable features added in macOS 10.8, set Cargo feature `mac_os_10_8_features`. To have both 10.8 features and 10.7 compatibility, also set `mac_os_10_7_support`. Setting both requires weak linkage, which is a nightly-only feature as of Rust 1.19. 10 | 11 | For more experimental but more complete, generated bindings take a look at https://github.com/michaelwu/RustKit. 12 | Other alternatives are https://github.com/nvzqz/fruity and https://gitlab.com/objrs/objrs 13 | 14 | ## Contributing 15 | 16 | If you wish to start contributing or even make a one-off change, simply submit a pull request with the code or documentation change and we'll go from there. 17 | -------------------------------------------------------------------------------- /core-foundation/src/mach_port.rs: -------------------------------------------------------------------------------- 1 | use crate::base::TCFType; 2 | use crate::runloop::CFRunLoopSource; 3 | use core_foundation_sys::base::kCFAllocatorDefault; 4 | pub use core_foundation_sys::mach_port::*; 5 | 6 | declare_TCFType! { 7 | /// An immutable numeric value. 8 | CFMachPort, CFMachPortRef 9 | } 10 | impl_TCFType!(CFMachPort, CFMachPortRef, CFMachPortGetTypeID); 11 | impl_CFTypeDescription!(CFMachPort); 12 | 13 | impl CFMachPort { 14 | pub fn create_runloop_source(&self, order: CFIndex) -> Result { 15 | unsafe { 16 | let runloop_source_ref = 17 | CFMachPortCreateRunLoopSource(kCFAllocatorDefault, self.0, order); 18 | if runloop_source_ref.is_null() { 19 | Err(()) 20 | } else { 21 | Ok(CFRunLoopSource::wrap_under_create_rule(runloop_source_ref)) 22 | } 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /core-text/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 = "core_text"] 11 | #![crate_type = "rlib"] 12 | #![allow(non_snake_case)] 13 | 14 | /*! 15 | Many of these functions will add objects to the autorelease pool. 16 | If you don't have one this will cause leaks. 17 | */ 18 | 19 | pub mod font; 20 | pub mod font_collection; 21 | pub mod font_descriptor; 22 | pub mod font_manager; 23 | pub mod frame; 24 | pub mod framesetter; 25 | pub mod line; 26 | pub mod run; 27 | pub mod string_attributes; 28 | -------------------------------------------------------------------------------- /core-graphics/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 | #[cfg(target_os = "macos")] 11 | pub mod access; 12 | pub mod base; 13 | pub mod color; 14 | pub mod color_space; 15 | pub mod context; 16 | pub mod data_provider; 17 | #[cfg(target_os = "macos")] 18 | pub mod display; 19 | #[cfg(target_os = "macos")] 20 | pub mod event; 21 | #[cfg(target_os = "macos")] 22 | pub mod event_source; 23 | pub mod font; 24 | pub mod geometry; 25 | pub mod gradient; 26 | pub mod image; 27 | pub mod path; 28 | pub mod sys; 29 | #[cfg(target_os = "macos")] 30 | pub mod window; 31 | -------------------------------------------------------------------------------- /core-text/src/string_attributes.rs: -------------------------------------------------------------------------------- 1 | use core_foundation::string::CFStringRef; 2 | 3 | extern "C" { 4 | pub static kCTCharacterShapeAttributeName: CFStringRef; 5 | pub static kCTFontAttributeName: CFStringRef; 6 | pub static kCTKernAttributeName: CFStringRef; 7 | pub static kCTLigatureAttributeName: CFStringRef; 8 | pub static kCTForegroundColorAttributeName: CFStringRef; 9 | pub static kCTForegroundColorFromContextAttributeName: CFStringRef; 10 | pub static kCTParagraphStyleAttributeName: CFStringRef; 11 | pub static kCTStrokeWidthAttributeName: CFStringRef; 12 | pub static kCTStrokeColorAttributeName: CFStringRef; 13 | pub static kCTSuperscriptAttributeName: CFStringRef; 14 | pub static kCTUnderlineColorAttributeName: CFStringRef; 15 | pub static kCTUnderlineStyleAttributeName: CFStringRef; 16 | pub static kCTVerticalFormsAttributeName: CFStringRef; 17 | pub static kCTGlyphInfoAttributeName: CFStringRef; 18 | pub static kCTRunDelegateAttributeName: CFStringRef; 19 | } 20 | -------------------------------------------------------------------------------- /core-foundation/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "core-foundation" 3 | description = "Bindings to Core Foundation for macOS" 4 | version = "0.10.1" 5 | 6 | categories = ["os::macos-apis"] 7 | keywords = ["macos", "framework", "objc"] 8 | 9 | authors.workspace = true 10 | edition.workspace = true 11 | license.workspace = true 12 | repository.workspace = true 13 | rust-version.workspace = true 14 | 15 | [package.metadata.docs.rs] 16 | all-features = true 17 | default-target = "x86_64-apple-darwin" 18 | 19 | [lints] 20 | workspace = true 21 | 22 | [dependencies] 23 | core-foundation-sys.workspace = true 24 | 25 | libc = "0.2" 26 | uuid = { version = "1", optional = true } 27 | 28 | [features] 29 | default = ["link"] 30 | 31 | mac_os_10_7_support = ["core-foundation-sys/mac_os_10_7_support"] # backwards compatibility 32 | mac_os_10_8_features = ["core-foundation-sys/mac_os_10_8_features"] # enables new features 33 | with-uuid = ["dep:uuid"] 34 | # Disable to manually link. Enabled by default. 35 | link = ["core-foundation-sys/link"] 36 | -------------------------------------------------------------------------------- /cocoa-foundation/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 | #![deprecated = "use the objc2 crate instead"] 10 | 11 | use objc::runtime; 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 selector to the selector object. 26 | #[inline] 27 | pub fn selector(name: &str) -> SEL { 28 | runtime::Sel::register(name) 29 | } 30 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /core-foundation/tests/use_macro_outside_crate.rs: -------------------------------------------------------------------------------- 1 | use core::ffi::c_void; 2 | use core_foundation::base::{CFComparisonResult, TCFType}; 3 | use core_foundation::{declare_TCFType, impl_CFComparison, impl_CFTypeDescription, impl_TCFType}; 4 | 5 | // sys equivalent stuff that must be declared 6 | 7 | #[repr(C)] 8 | pub struct __CFFooBar(c_void); 9 | 10 | pub type CFFooBarRef = *const __CFFooBar; 11 | 12 | extern "C" { 13 | pub fn CFFooBarGetTypeID() -> core_foundation::base::CFTypeID; 14 | pub fn fake_compare( 15 | this: CFFooBarRef, 16 | other: CFFooBarRef, 17 | context: *mut c_void, 18 | ) -> CFComparisonResult; 19 | } 20 | 21 | // Try to use the macros outside of the crate 22 | 23 | declare_TCFType!(CFFooBar, CFFooBarRef); 24 | impl_TCFType!(CFFooBar, CFFooBarRef, CFFooBarGetTypeID); 25 | impl_CFTypeDescription!(CFFooBar); 26 | impl_CFComparison!(CFFooBar, fake_compare); 27 | 28 | declare_TCFType!(CFGenericFooBar, CFFooBarRef); 29 | impl_TCFType!(CFGenericFooBar, CFFooBarRef, CFFooBarGetTypeID); 30 | impl_CFTypeDescription!(CFGenericFooBar); 31 | impl_CFComparison!(CFGenericFooBar, fake_compare); 32 | -------------------------------------------------------------------------------- /core-graphics/src/sys.rs: -------------------------------------------------------------------------------- 1 | use core::ffi::c_void; 2 | 3 | pub enum CGImage {} 4 | pub type CGImageRef = *mut CGImage; 5 | 6 | #[repr(C)] 7 | pub struct __CGColor(c_void); 8 | 9 | pub type CGColorRef = *const __CGColor; 10 | 11 | pub enum CGColorSpace {} 12 | pub type CGColorSpaceRef = *mut CGColorSpace; 13 | 14 | pub enum CGPath {} 15 | pub type CGPathRef = *mut CGPath; 16 | 17 | pub enum CGDataProvider {} 18 | pub type CGDataProviderRef = *mut CGDataProvider; 19 | 20 | pub enum CGFont {} 21 | pub type CGFontRef = *mut CGFont; 22 | 23 | pub enum CGContext {} 24 | pub type CGContextRef = *mut CGContext; 25 | 26 | pub enum CGGradient {} 27 | pub type CGGradientRef = *mut CGGradient; 28 | 29 | #[cfg(target_os = "macos")] 30 | mod macos { 31 | pub enum CGEventTap {} 32 | pub type CGEventTapRef = core_foundation::mach_port::CFMachPortRef; 33 | pub enum CGEvent {} 34 | pub type CGEventRef = *mut CGEvent; 35 | 36 | pub enum CGEventSource {} 37 | pub type CGEventSourceRef = *mut CGEventSource; 38 | 39 | pub enum CGDisplayMode {} 40 | pub type CGDisplayModeRef = *mut CGDisplayMode; 41 | } 42 | 43 | #[cfg(target_os = "macos")] 44 | pub use self::macos::*; 45 | -------------------------------------------------------------------------------- /core-foundation-sys/src/date.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2013-2015 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 core::ffi::c_void; 11 | 12 | use crate::base::{CFAllocatorRef, CFComparisonResult, CFTypeID}; 13 | 14 | #[repr(C)] 15 | pub struct __CFDate(c_void); 16 | 17 | pub type CFDateRef = *const __CFDate; 18 | 19 | pub type CFTimeInterval = f64; 20 | pub type CFAbsoluteTime = CFTimeInterval; 21 | 22 | extern "C" { 23 | pub static kCFAbsoluteTimeIntervalSince1904: CFTimeInterval; 24 | pub static kCFAbsoluteTimeIntervalSince1970: CFTimeInterval; 25 | 26 | pub fn CFAbsoluteTimeGetCurrent() -> CFAbsoluteTime; 27 | 28 | pub fn CFDateCreate(allocator: CFAllocatorRef, at: CFAbsoluteTime) -> CFDateRef; 29 | pub fn CFDateGetAbsoluteTime(date: CFDateRef) -> CFAbsoluteTime; 30 | pub fn CFDateGetTimeIntervalSinceDate(date: CFDateRef, other: CFDateRef) -> CFTimeInterval; 31 | pub fn CFDateCompare( 32 | date: CFDateRef, 33 | other: CFDateRef, 34 | context: *mut c_void, 35 | ) -> CFComparisonResult; 36 | 37 | pub fn CFDateGetTypeID() -> CFTypeID; 38 | } 39 | -------------------------------------------------------------------------------- /core-graphics/src/event_source.rs: -------------------------------------------------------------------------------- 1 | use core_foundation::base::{CFRelease, CFRetain, CFTypeID}; 2 | use foreign_types::{foreign_type, ForeignType}; 3 | 4 | /// Possible source states of an event source. 5 | #[repr(C)] 6 | #[derive(Clone, Copy, Debug)] 7 | pub enum CGEventSourceStateID { 8 | Private = -1, 9 | CombinedSessionState = 0, 10 | HIDSystemState = 1, 11 | } 12 | 13 | foreign_type! { 14 | #[doc(hidden)] 15 | pub unsafe type CGEventSource { 16 | type CType = crate::sys::CGEventSource; 17 | fn drop = |p| CFRelease(p as *mut _); 18 | fn clone = |p| CFRetain(p as *const _) as *mut _; 19 | } 20 | } 21 | 22 | impl CGEventSource { 23 | pub fn type_id() -> CFTypeID { 24 | unsafe { CGEventSourceGetTypeID() } 25 | } 26 | 27 | pub fn new(state_id: CGEventSourceStateID) -> Result { 28 | unsafe { 29 | let event_source_ref = CGEventSourceCreate(state_id); 30 | if !event_source_ref.is_null() { 31 | Ok(Self::from_ptr(event_source_ref)) 32 | } else { 33 | Err(()) 34 | } 35 | } 36 | } 37 | } 38 | 39 | #[cfg_attr(feature = "link", link(name = "CoreGraphics", kind = "framework"))] 40 | extern "C" { 41 | /// Return the type identifier for the opaque type [`CGEventSourceRef`]. 42 | /// 43 | /// [`CGEventSourceRef`]: crate::sys::CGEventSourceRef 44 | fn CGEventSourceGetTypeID() -> CFTypeID; 45 | 46 | /// Return a Quartz event source created with a specified source state. 47 | fn CGEventSourceCreate(stateID: CGEventSourceStateID) -> crate::sys::CGEventSourceRef; 48 | } 49 | -------------------------------------------------------------------------------- /core-graphics-types/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 | // this file defines CGFloat, as well as stubbed data types. 11 | 12 | #![allow(non_camel_case_types)] 13 | #![allow(non_upper_case_globals)] 14 | 15 | #[cfg(any(target_arch = "x86", target_arch = "arm", target_arch = "aarch64"))] 16 | pub type boolean_t = core::ffi::c_int; 17 | #[cfg(target_arch = "x86_64")] 18 | pub type boolean_t = core::ffi::c_uint; 19 | 20 | #[cfg(target_pointer_width = "64")] 21 | pub type CGFloat = core::ffi::c_double; 22 | #[cfg(not(target_pointer_width = "64"))] 23 | pub type CGFloat = core::ffi::c_float; 24 | 25 | pub type CGError = i32; 26 | 27 | pub type CGGlyph = core::ffi::c_ushort; 28 | 29 | pub const kCGErrorSuccess: CGError = 0; 30 | pub const kCGErrorFailure: CGError = 1000; 31 | pub const kCGErrorIllegalArgument: CGError = 1001; 32 | pub const kCGErrorInvalidConnection: CGError = 1002; 33 | pub const kCGErrorInvalidContext: CGError = 1003; 34 | pub const kCGErrorCannotComplete: CGError = 1004; 35 | pub const kCGErrorNotImplemented: CGError = 1006; 36 | pub const kCGErrorRangeCheck: CGError = 1007; 37 | pub const kCGErrorTypeCheck: CGError = 1008; 38 | pub const kCGErrorInvalidOperation: CGError = 1010; 39 | pub const kCGErrorNoneAvailable: CGError = 1011; 40 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = ["core-foundation", "core-foundation-sys", "core-graphics-types", "core-graphics", "core-text", "cocoa", "cocoa-foundation", "io-surface"] 3 | resolver = "2" 4 | 5 | [workspace.package] 6 | authors = ["The Servo Project Developers"] 7 | edition = "2021" 8 | license = "MIT OR Apache-2.0" 9 | repository = "https://github.com/servo/core-foundation-rs" 10 | rust-version = "1.65" 11 | 12 | [workspace.lints] 13 | clippy.doc_markdown = "warn" 14 | 15 | # TODO: Remove most of these by fixing the actual issues. 16 | clippy.assertions_on_constants = "allow" 17 | clippy.len_without_is_empty = "allow" 18 | clippy.manual_range_contains = "allow" 19 | clippy.missing_safety_doc = "allow" 20 | clippy.new_ret_no_self = "allow" 21 | clippy.new_without_default = "allow" 22 | clippy.non_canonical_partial_ord_impl = "allow" 23 | clippy.not_unsafe_ptr_arg_deref = "allow" 24 | clippy.result_unit_err = "allow" 25 | clippy.too_many_arguments = "allow" 26 | clippy.type_complexity = "allow" 27 | 28 | # Work around an issue in the objc crate. 29 | # https://github.com/SSheldon/rust-objc/issues/125 30 | [workspace.lints.rust] 31 | unexpected_cfgs = { level = "warn", check-cfg = ['cfg(feature, values("cargo-clippy"))'] } 32 | 33 | [workspace.dependencies] 34 | cocoa-foundation = { default-features = false, path = "cocoa-foundation", version = "0.2" } 35 | core-foundation = { default-features = false, path = "core-foundation", version = "0.10" } 36 | core-foundation-sys = { default-features = false, path = "core-foundation-sys", version = "0.8" } 37 | core-graphics = { default-features = false, path = "core-graphics", version = "0.25" } 38 | core-graphics-types = { default-features = false, path = "core-graphics-types", version = "0.2" } 39 | -------------------------------------------------------------------------------- /core-graphics/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 | // this file defines CGFloat, as well as stubbed data types. 11 | 12 | #![allow(non_camel_case_types)] 13 | #![allow(non_upper_case_globals)] 14 | 15 | pub use core_graphics_types::base::*; 16 | 17 | pub const kCGImageAlphaNone: u32 = 0; 18 | pub const kCGImageAlphaPremultipliedLast: u32 = 1; 19 | pub const kCGImageAlphaPremultipliedFirst: u32 = 2; 20 | pub const kCGImageAlphaLast: u32 = 3; 21 | pub const kCGImageAlphaFirst: u32 = 4; 22 | pub const kCGImageAlphaNoneSkipLast: u32 = 5; 23 | pub const kCGImageAlphaNoneSkipFirst: u32 = 6; 24 | 25 | pub const kCGBitmapByteOrderDefault: u32 = 0 << 12; 26 | pub const kCGBitmapByteOrder16Little: u32 = 1 << 12; 27 | pub const kCGBitmapByteOrder32Little: u32 = 2 << 12; 28 | pub const kCGBitmapByteOrder16Big: u32 = 3 << 12; 29 | pub const kCGBitmapByteOrder32Big: u32 = 4 << 12; 30 | 31 | pub const kCGRenderingIntentDefault: u32 = 0; 32 | pub const kCGRenderingIntentAbsoluteColorimetric: u32 = 1; 33 | pub const kCGRenderingIntentRelativeColorimetric: u32 = 2; 34 | pub const kCGRenderingIntentPerceptual: u32 = 3; 35 | pub const kCGRenderingIntentSaturation: u32 = 4; 36 | 37 | #[cfg(target_endian = "big")] 38 | pub const kCGBitmapByteOrder16Host: u32 = kCGBitmapByteOrder16Big; 39 | #[cfg(target_endian = "big")] 40 | pub const kCGBitmapByteOrder32Host: u32 = kCGBitmapByteOrder32Big; 41 | 42 | #[cfg(target_endian = "little")] 43 | pub const kCGBitmapByteOrder16Host: u32 = kCGBitmapByteOrder16Little; 44 | #[cfg(target_endian = "little")] 45 | pub const kCGBitmapByteOrder32Host: u32 = kCGBitmapByteOrder32Little; 46 | -------------------------------------------------------------------------------- /core-graphics/src/color.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 super::sys::CGColorRef; 11 | use crate::base::CGFloat; 12 | use core_foundation::base::CFTypeID; 13 | use core_foundation::base::TCFType; 14 | use core_foundation::{declare_TCFType, impl_TCFType}; 15 | 16 | pub use super::sys::CGColorRef as SysCGColorRef; 17 | 18 | declare_TCFType! { 19 | CGColor, CGColorRef 20 | } 21 | impl_TCFType!(CGColor, CGColorRef, CGColorGetTypeID); 22 | 23 | impl CGColor { 24 | pub fn rgb(red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) -> Self { 25 | unsafe { 26 | let ptr = CGColorCreateGenericRGB(red, green, blue, alpha); 27 | CGColor::wrap_under_create_rule(ptr) 28 | } 29 | } 30 | 31 | #[cfg(feature = "catalina")] 32 | pub fn srgb(red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) -> Self { 33 | unsafe { 34 | let ptr = CGColorCreateSRGB(red, green, blue, alpha); 35 | CGColor::wrap_under_create_rule(ptr) 36 | } 37 | } 38 | } 39 | 40 | #[cfg_attr(feature = "link", link(name = "CoreGraphics", kind = "framework"))] 41 | extern "C" { 42 | fn CGColorCreateGenericRGB( 43 | red: CGFloat, 44 | green: CGFloat, 45 | blue: CGFloat, 46 | alpha: CGFloat, 47 | ) -> crate::sys::CGColorRef; 48 | 49 | #[cfg(feature = "catalina")] 50 | fn CGColorCreateSRGB( 51 | red: CGFloat, 52 | green: CGFloat, 53 | blue: CGFloat, 54 | alpha: CGFloat, 55 | ) -> crate::sys::CGColorRef; 56 | 57 | fn CGColorGetTypeID() -> CFTypeID; 58 | } 59 | -------------------------------------------------------------------------------- /core-foundation/src/date.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 | //! Core Foundation date objects. 11 | 12 | use core_foundation_sys::base::kCFAllocatorDefault; 13 | pub use core_foundation_sys::date::*; 14 | 15 | use crate::base::TCFType; 16 | 17 | declare_TCFType! { 18 | /// A date. 19 | CFDate, CFDateRef 20 | } 21 | impl_TCFType!(CFDate, CFDateRef, CFDateGetTypeID); 22 | impl_CFTypeDescription!(CFDate); 23 | impl_CFComparison!(CFDate, CFDateCompare); 24 | 25 | impl CFDate { 26 | #[inline] 27 | pub fn new(time: CFAbsoluteTime) -> CFDate { 28 | unsafe { 29 | let date_ref = CFDateCreate(kCFAllocatorDefault, time); 30 | TCFType::wrap_under_create_rule(date_ref) 31 | } 32 | } 33 | 34 | #[inline] 35 | pub fn now() -> CFDate { 36 | CFDate::new(unsafe { CFAbsoluteTimeGetCurrent() }) 37 | } 38 | 39 | #[inline] 40 | pub fn abs_time(&self) -> CFAbsoluteTime { 41 | unsafe { CFDateGetAbsoluteTime(self.0) } 42 | } 43 | } 44 | 45 | #[cfg(test)] 46 | mod test { 47 | use super::CFDate; 48 | use std::cmp::Ordering; 49 | 50 | #[test] 51 | fn date_comparison() { 52 | let now = CFDate::now(); 53 | let past = CFDate::new(now.abs_time() - 1.0); 54 | assert_eq!(now.cmp(&past), Ordering::Greater); 55 | assert_eq!(now.cmp(&now), Ordering::Equal); 56 | assert_eq!(past.cmp(&now), Ordering::Less); 57 | } 58 | 59 | #[test] 60 | fn date_equality() { 61 | let now = CFDate::now(); 62 | let same_time = CFDate::new(now.abs_time()); 63 | assert_eq!(now, same_time); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /core-foundation/src/set.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 | //! An immutable bag of elements. 11 | 12 | use core_foundation_sys::base::{kCFAllocatorDefault, CFRelease, CFTypeRef}; 13 | pub use core_foundation_sys::set::*; 14 | 15 | use crate::base::{CFIndexConvertible, TCFType}; 16 | 17 | use core::ffi::c_void; 18 | use std::marker::PhantomData; 19 | 20 | /// An immutable bag of elements. 21 | pub struct CFSet(CFSetRef, PhantomData); 22 | 23 | impl Drop for CFSet { 24 | fn drop(&mut self) { 25 | unsafe { CFRelease(self.as_CFTypeRef()) } 26 | } 27 | } 28 | 29 | impl_TCFType!(CFSet, CFSetRef, CFSetGetTypeID); 30 | impl_CFTypeDescription!(CFSet); 31 | 32 | impl CFSet { 33 | /// Creates a new set from a list of `CFType` instances. 34 | pub fn from_slice(elems: &[T]) -> CFSet 35 | where 36 | T: TCFType, 37 | { 38 | unsafe { 39 | let elems: Vec = elems.iter().map(|elem| elem.as_CFTypeRef()).collect(); 40 | let set_ref = CFSetCreate( 41 | kCFAllocatorDefault, 42 | elems.as_ptr(), 43 | elems.len().to_CFIndex(), 44 | &kCFTypeSetCallBacks, 45 | ); 46 | TCFType::wrap_under_create_rule(set_ref) 47 | } 48 | } 49 | } 50 | 51 | impl CFSet { 52 | /// Get the number of elements in the `CFSet`. 53 | pub fn len(&self) -> usize { 54 | unsafe { CFSetGetCount(self.0) as usize } 55 | } 56 | 57 | /// Returns `true` if the set contains no elements. 58 | pub fn is_empty(&self) -> bool { 59 | self.len() == 0 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /core-foundation/src/boolean.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 | //! A Boolean type. 11 | 12 | pub use core_foundation_sys::number::{ 13 | kCFBooleanFalse, kCFBooleanTrue, CFBooleanGetTypeID, CFBooleanRef, 14 | }; 15 | 16 | use crate::base::TCFType; 17 | 18 | declare_TCFType! { 19 | /// A Boolean type. 20 | /// 21 | /// FIXME(pcwalton): Should be a newtype struct, but that fails due to a Rust compiler bug. 22 | CFBoolean, CFBooleanRef 23 | } 24 | impl_TCFType!(CFBoolean, CFBooleanRef, CFBooleanGetTypeID); 25 | impl_CFTypeDescription!(CFBoolean); 26 | 27 | impl CFBoolean { 28 | pub fn true_value() -> CFBoolean { 29 | unsafe { TCFType::wrap_under_get_rule(kCFBooleanTrue) } 30 | } 31 | 32 | pub fn false_value() -> CFBoolean { 33 | unsafe { TCFType::wrap_under_get_rule(kCFBooleanFalse) } 34 | } 35 | } 36 | 37 | impl From for CFBoolean { 38 | fn from(value: bool) -> CFBoolean { 39 | if value { 40 | CFBoolean::true_value() 41 | } else { 42 | CFBoolean::false_value() 43 | } 44 | } 45 | } 46 | 47 | impl From for bool { 48 | fn from(value: CFBoolean) -> bool { 49 | value.0 == unsafe { kCFBooleanTrue } 50 | } 51 | } 52 | 53 | #[cfg(test)] 54 | mod tests { 55 | use super::*; 56 | 57 | #[test] 58 | fn to_and_from_bool() { 59 | let b_false = CFBoolean::from(false); 60 | let b_true = CFBoolean::from(true); 61 | assert_ne!(b_false, b_true); 62 | assert_eq!(b_false, CFBoolean::false_value()); 63 | assert_eq!(b_true, CFBoolean::true_value()); 64 | assert!(!bool::from(b_false)); 65 | assert!(bool::from(b_true)); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /core-foundation/src/error.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2016 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 | //! Core Foundation errors. 11 | 12 | pub use core_foundation_sys::error::*; 13 | 14 | use std::error::Error; 15 | use std::fmt; 16 | 17 | use crate::base::{CFIndex, TCFType}; 18 | use crate::string::CFString; 19 | 20 | declare_TCFType! { 21 | /// An error value. 22 | CFError, CFErrorRef 23 | } 24 | impl_TCFType!(CFError, CFErrorRef, CFErrorGetTypeID); 25 | 26 | impl fmt::Debug for CFError { 27 | fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { 28 | fmt.debug_struct("CFError") 29 | .field("domain", &self.domain()) 30 | .field("code", &self.code()) 31 | .field("description", &self.description()) 32 | .finish() 33 | } 34 | } 35 | 36 | impl fmt::Display for CFError { 37 | fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { 38 | write!(fmt, "{}", self.description()) 39 | } 40 | } 41 | 42 | impl Error for CFError { 43 | fn description(&self) -> &str { 44 | "a Core Foundation error" 45 | } 46 | } 47 | 48 | impl CFError { 49 | /// Returns a string identifying the domain with which this error is 50 | /// associated. 51 | pub fn domain(&self) -> CFString { 52 | unsafe { 53 | let s = CFErrorGetDomain(self.0); 54 | CFString::wrap_under_get_rule(s) 55 | } 56 | } 57 | 58 | /// Returns the code identifying this type of error. 59 | pub fn code(&self) -> CFIndex { 60 | unsafe { CFErrorGetCode(self.0) } 61 | } 62 | 63 | /// Returns a human-presentable description of the error. 64 | pub fn description(&self) -> CFString { 65 | unsafe { 66 | let s = CFErrorCopyDescription(self.0); 67 | CFString::wrap_under_create_rule(s) 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /.github/workflows/rust.yml: -------------------------------------------------------------------------------- 1 | name: Rust 2 | 3 | on: 4 | push: 5 | branches: [main] 6 | pull_request: 7 | branches: ["**"] 8 | merge_group: 9 | types: [checks_requested] 10 | 11 | env: 12 | CARGO_TERM_COLOR: always 13 | RUSTFLAGS: "-D warnings" 14 | 15 | jobs: 16 | rustfmt: 17 | runs-on: ubuntu-latest 18 | steps: 19 | - uses: actions/checkout@v4 20 | - uses: dtolnay/rust-toolchain@master 21 | with: 22 | toolchain: stable 23 | components: rustfmt 24 | - run: cargo fmt --check 25 | semver: 26 | runs-on: macos-14 27 | steps: 28 | - uses: actions/checkout@v4 29 | - name: Check semver 30 | # Allow failure until we update all the package versions. 31 | continue-on-error: true 32 | uses: obi1kenobi/cargo-semver-checks-action@v2 33 | build: 34 | runs-on: ${{ matrix.os }} 35 | strategy: 36 | matrix: 37 | os: [macos-13, macos-14, macos-15] 38 | toolchain: [stable] 39 | include: 40 | - os: macos-14 41 | toolchain: "1.65.0" 42 | steps: 43 | - uses: actions/checkout@v4 44 | - name: Install toolchain 45 | uses: dtolnay/rust-toolchain@master 46 | with: 47 | toolchain: ${{ matrix.toolchain }} 48 | - name: Build 49 | run: cargo build --verbose 50 | - name: Run tests 51 | run: cargo test --verbose 52 | - name: Run clippy 53 | if: matrix.os == 'macos-14' && matrix.toolchain == 'stable' 54 | run: cargo clippy --all-targets --workspace 55 | typos: 56 | # If this fails, consider changing your text or adding something to .typos.toml 57 | runs-on: ubuntu-latest 58 | steps: 59 | - uses: actions/checkout@v4 60 | - name: check typos 61 | uses: crate-ci/typos@v1.29.4 62 | build_result: 63 | name: Result 64 | runs-on: ubuntu-latest 65 | if: always() 66 | needs: 67 | - "build" 68 | - "semver" 69 | - "typos" 70 | steps: 71 | - name: Success 72 | run: exit 0 73 | if: ${{ !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') }} 74 | - name: Failure 75 | run: exit 1 76 | if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') 77 | -------------------------------------------------------------------------------- /core-foundation-sys/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2013-2015 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 | #![allow( 10 | non_snake_case, 11 | non_camel_case_types, 12 | non_upper_case_globals, 13 | improper_ctypes 14 | )] 15 | #![cfg_attr( 16 | all(feature = "mac_os_10_7_support", feature = "mac_os_10_8_features"), 17 | feature(linkage) 18 | )] // back-compat requires weak linkage 19 | 20 | // Link to CoreFoundation on any Apple device. 21 | // 22 | // We don't use `target_vendor` since that is going to be deprecated: 23 | // https://github.com/rust-lang/lang-team/issues/102 24 | #[cfg_attr( 25 | all( 26 | any( 27 | target_os = "macos", 28 | target_os = "ios", 29 | target_os = "tvos", 30 | target_os = "watchos", 31 | target_os = "visionos" 32 | ), 33 | feature = "link" 34 | ), 35 | link(name = "CoreFoundation", kind = "framework") 36 | )] 37 | extern "C" {} 38 | 39 | pub mod array; 40 | pub mod attributed_string; 41 | pub mod bag; 42 | pub mod base; 43 | pub mod binary_heap; 44 | pub mod bit_vector; 45 | pub mod bundle; 46 | pub mod calendar; 47 | pub mod characterset; 48 | pub mod data; 49 | pub mod date; 50 | pub mod date_formatter; 51 | pub mod dictionary; 52 | pub mod error; 53 | pub mod file_security; 54 | pub mod filedescriptor; 55 | pub mod locale; 56 | pub mod mach_port; 57 | pub mod messageport; 58 | pub mod notification_center; 59 | pub mod number; 60 | pub mod number_formatter; 61 | pub mod plugin; 62 | pub mod preferences; 63 | pub mod propertylist; 64 | pub mod runloop; 65 | pub mod set; 66 | pub mod socket; 67 | pub mod stream; 68 | pub mod string; 69 | pub mod string_tokenizer; 70 | pub mod timezone; 71 | pub mod tree; 72 | pub mod url; 73 | pub mod url_enumerator; 74 | #[cfg(target_os = "macos")] 75 | pub mod user_notification; 76 | pub mod uuid; 77 | #[cfg(target_os = "macos")] 78 | pub mod xml_node; 79 | #[cfg(target_os = "macos")] 80 | pub mod xml_parser; 81 | -------------------------------------------------------------------------------- /core-foundation/src/timezone.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 | //! Core Foundation time zone objects. 11 | 12 | use core_foundation_sys::base::kCFAllocatorDefault; 13 | pub use core_foundation_sys::timezone::*; 14 | 15 | use crate::base::TCFType; 16 | use crate::date::{CFDate, CFTimeInterval}; 17 | use crate::string::CFString; 18 | 19 | declare_TCFType! { 20 | /// A time zone. 21 | CFTimeZone, CFTimeZoneRef 22 | } 23 | impl_TCFType!(CFTimeZone, CFTimeZoneRef, CFTimeZoneGetTypeID); 24 | impl_CFTypeDescription!(CFTimeZone); 25 | 26 | impl Default for CFTimeZone { 27 | fn default() -> CFTimeZone { 28 | unsafe { 29 | let tz_ref = CFTimeZoneCopyDefault(); 30 | TCFType::wrap_under_create_rule(tz_ref) 31 | } 32 | } 33 | } 34 | 35 | impl CFTimeZone { 36 | #[inline] 37 | pub fn new(interval: CFTimeInterval) -> CFTimeZone { 38 | unsafe { 39 | let tz_ref = CFTimeZoneCreateWithTimeIntervalFromGMT(kCFAllocatorDefault, interval); 40 | TCFType::wrap_under_create_rule(tz_ref) 41 | } 42 | } 43 | 44 | #[inline] 45 | pub fn system() -> CFTimeZone { 46 | unsafe { 47 | let tz_ref = CFTimeZoneCopySystem(); 48 | TCFType::wrap_under_create_rule(tz_ref) 49 | } 50 | } 51 | 52 | pub fn seconds_from_gmt(&self, date: CFDate) -> CFTimeInterval { 53 | unsafe { CFTimeZoneGetSecondsFromGMT(self.0, date.abs_time()) } 54 | } 55 | 56 | /// The timezone database ID that identifies the time zone. E.g. `"America/Los_Angeles" `or 57 | /// `"Europe/Paris"`. 58 | pub fn name(&self) -> CFString { 59 | unsafe { CFString::wrap_under_get_rule(CFTimeZoneGetName(self.0)) } 60 | } 61 | } 62 | 63 | #[cfg(test)] 64 | mod test { 65 | use super::CFTimeZone; 66 | 67 | #[test] 68 | fn timezone_comparison() { 69 | let system = CFTimeZone::system(); 70 | let default = CFTimeZone::default(); 71 | assert_eq!(system, default); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /cocoa/examples/hello_world.rs: -------------------------------------------------------------------------------- 1 | #![allow(deprecated)] // the cocoa crate is deprecated 2 | use cocoa::appkit::{ 3 | NSApp, NSApplication, NSApplicationActivateIgnoringOtherApps, 4 | NSApplicationActivationPolicyRegular, NSBackingStoreBuffered, NSMenu, NSMenuItem, 5 | NSRunningApplication, NSWindow, NSWindowStyleMask, 6 | }; 7 | use cocoa::base::{nil, selector, NO}; 8 | use cocoa::foundation::{NSAutoreleasePool, NSPoint, NSProcessInfo, NSRect, NSSize, NSString}; 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_( 39 | NSRect::new(NSPoint::new(0., 0.), NSSize::new(200., 200.)), 40 | NSWindowStyleMask::NSTitledWindowMask, 41 | NSBackingStoreBuffered, 42 | NO, 43 | ) 44 | .autorelease(); 45 | window.cascadeTopLeftFromPoint_(NSPoint::new(20., 20.)); 46 | window.center(); 47 | let title = NSString::alloc(nil).init_str("Hello World!"); 48 | window.setTitle_(title); 49 | window.makeKeyAndOrderFront_(nil); 50 | let current_app = NSRunningApplication::currentApplication(nil); 51 | current_app.activateWithOptions_(NSApplicationActivateIgnoringOtherApps); 52 | app.run(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /core-foundation-sys/src/error.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2016 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 core::ffi::c_void; 11 | 12 | use crate::base::{CFAllocatorRef, CFIndex, CFTypeID}; 13 | use crate::dictionary::CFDictionaryRef; 14 | use crate::string::CFStringRef; 15 | 16 | #[repr(C)] 17 | pub struct __CFError(c_void); 18 | 19 | pub type CFErrorRef = *mut __CFError; 20 | pub type CFErrorDomain = CFStringRef; 21 | 22 | extern "C" { 23 | /* 24 | * CFError.h 25 | */ 26 | 27 | /* Error domains */ 28 | pub static kCFErrorDomainPOSIX: CFStringRef; 29 | pub static kCFErrorDomainOSStatus: CFStringRef; 30 | pub static kCFErrorDomainMach: CFStringRef; 31 | pub static kCFErrorDomainCocoa: CFStringRef; 32 | 33 | /* Keys for the user info dictionary */ 34 | pub static kCFErrorLocalizedDescriptionKey: CFStringRef; 35 | // pub static kCFErrorLocalizedFailureKey: CFStringRef; // macos(10.13)+ 36 | pub static kCFErrorLocalizedFailureReasonKey: CFStringRef; 37 | pub static kCFErrorLocalizedRecoverySuggestionKey: CFStringRef; 38 | pub static kCFErrorDescriptionKey: CFStringRef; 39 | pub static kCFErrorUnderlyingErrorKey: CFStringRef; 40 | pub static kCFErrorURLKey: CFStringRef; 41 | pub static kCFErrorFilePathKey: CFStringRef; 42 | 43 | /* Creating a CFError */ 44 | pub fn CFErrorCreate( 45 | allocator: CFAllocatorRef, 46 | domain: CFErrorDomain, 47 | code: CFIndex, 48 | userInfo: CFDictionaryRef, 49 | ) -> CFErrorRef; 50 | //pub fn CFErrorCreateWithUserInfoKeysAndValues 51 | 52 | /* Getting Information About an Error */ 53 | pub fn CFErrorGetDomain(err: CFErrorRef) -> CFStringRef; 54 | pub fn CFErrorGetCode(err: CFErrorRef) -> CFIndex; 55 | pub fn CFErrorCopyUserInfo(err: CFErrorRef) -> CFDictionaryRef; 56 | pub fn CFErrorCopyDescription(err: CFErrorRef) -> CFStringRef; 57 | pub fn CFErrorCopyFailureReason(err: CFErrorRef) -> CFStringRef; 58 | pub fn CFErrorCopyRecoverySuggestion(err: CFErrorRef) -> CFStringRef; 59 | 60 | /* Getting the CFError Type ID */ 61 | pub fn CFErrorGetTypeID() -> CFTypeID; 62 | } 63 | -------------------------------------------------------------------------------- /cocoa/src/macros.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 | /// Creates a Cocoa delegate to use e.g. with `NSWindow.setDelegate_`. 11 | /// Adds instance variables and methods to the definition. 12 | /// 13 | /// # Example with `NSWindowDelegate` 14 | /// ``` no_run 15 | /// use cocoa::appkit::NSWindow; 16 | /// use cocoa::base::{id, nil}; 17 | /// use cocoa::delegate; 18 | /// 19 | /// use objc::runtime::{Object, Sel}; 20 | /// use objc::{msg_send, sel, sel_impl}; 21 | /// 22 | /// # fn main() { 23 | /// unsafe { 24 | /// let my_window: id = NSWindow::alloc(nil); 25 | /// 26 | /// extern fn on_enter_fullscreen(this: &Object, _cmd: Sel, _notification: id) { 27 | /// unsafe { 28 | /// let window: id = *this.get_ivar("window"); 29 | /// window.setToolbar_(nil); 30 | /// } 31 | /// } 32 | /// 33 | /// my_window.setDelegate_(delegate!("MyWindowDelegate", { 34 | /// window: id = my_window, // Declare instance variable(s) 35 | /// (onWindowWillEnterFullscreen:) => on_enter_fullscreen as extern fn(&Object, Sel, id) // Declare function(s) 36 | /// })); 37 | /// } 38 | /// # } 39 | /// ``` 40 | #[macro_export] 41 | #[deprecated = "use the objc2::define_class! macro instead"] 42 | macro_rules! delegate { 43 | ( 44 | $name:expr, { 45 | $( ($($sel:ident :)+) => $func:expr),* 46 | } 47 | ) => ( 48 | delegate!($name, { 49 | , 50 | $( ($($sel :)+) => $func),* 51 | }) 52 | ); 53 | 54 | ( 55 | $name:expr, { 56 | $($var:ident : $var_type:ty = $value:expr),* , 57 | $( ($($sel:ident :)+) => $func:expr),* 58 | } 59 | ) => ({ 60 | let mut decl = objc::declare::ClassDecl::new($name, objc::class!(NSObject)).unwrap(); 61 | 62 | $( 63 | decl.add_ivar::<$var_type>(stringify!($var)); 64 | )* 65 | 66 | $( 67 | decl.add_method(sel!($($sel :)+), $func); 68 | )* 69 | 70 | let cl = decl.register(); 71 | let delegate: id = msg_send![cl, alloc]; 72 | 73 | $( 74 | (*delegate).set_ivar(stringify!($var), $value); 75 | )* 76 | 77 | delegate 78 | }); 79 | } 80 | -------------------------------------------------------------------------------- /core-foundation-sys/src/uuid.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2013-2015 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 core::ffi::c_void; 11 | 12 | use crate::base::{CFAllocatorRef, CFTypeID}; 13 | use crate::string::CFStringRef; 14 | 15 | #[repr(C)] 16 | pub struct __CFUUID(c_void); 17 | 18 | pub type CFUUIDRef = *const __CFUUID; 19 | 20 | #[repr(C)] 21 | #[derive(Debug, Clone, Copy, PartialEq, Default)] 22 | pub struct CFUUIDBytes { 23 | pub byte0: u8, 24 | pub byte1: u8, 25 | pub byte2: u8, 26 | pub byte3: u8, 27 | pub byte4: u8, 28 | pub byte5: u8, 29 | pub byte6: u8, 30 | pub byte7: u8, 31 | pub byte8: u8, 32 | pub byte9: u8, 33 | pub byte10: u8, 34 | pub byte11: u8, 35 | pub byte12: u8, 36 | pub byte13: u8, 37 | pub byte14: u8, 38 | pub byte15: u8, 39 | } 40 | 41 | extern "C" { 42 | /* 43 | * CFUUID.h 44 | */ 45 | 46 | /* Creating CFUUID Objects */ 47 | pub fn CFUUIDCreate(allocator: CFAllocatorRef) -> CFUUIDRef; 48 | pub fn CFUUIDCreateFromString(alloc: CFAllocatorRef, uuidStr: CFStringRef) -> CFUUIDRef; 49 | pub fn CFUUIDCreateFromUUIDBytes(allocator: CFAllocatorRef, bytes: CFUUIDBytes) -> CFUUIDRef; 50 | pub fn CFUUIDCreateWithBytes( 51 | alloc: CFAllocatorRef, 52 | byte0: u8, 53 | byte1: u8, 54 | byte2: u8, 55 | byte3: u8, 56 | byte4: u8, 57 | byte5: u8, 58 | byte6: u8, 59 | byte7: u8, 60 | byte8: u8, 61 | byte9: u8, 62 | byte10: u8, 63 | byte11: u8, 64 | byte12: u8, 65 | byte13: u8, 66 | byte14: u8, 67 | byte15: u8, 68 | ) -> CFUUIDRef; 69 | 70 | /* Getting Information About CFUUID Objects */ 71 | pub fn CFUUIDCreateString(allocator: CFAllocatorRef, uid: CFUUIDRef) -> CFStringRef; 72 | pub fn CFUUIDGetConstantUUIDWithBytes( 73 | alloc: CFAllocatorRef, 74 | byte0: u8, 75 | byte1: u8, 76 | byte2: u8, 77 | byte3: u8, 78 | byte4: u8, 79 | byte5: u8, 80 | byte6: u8, 81 | byte7: u8, 82 | byte8: u8, 83 | byte9: u8, 84 | byte10: u8, 85 | byte11: u8, 86 | byte12: u8, 87 | byte13: u8, 88 | byte14: u8, 89 | byte15: u8, 90 | ) -> CFUUIDRef; 91 | pub fn CFUUIDGetUUIDBytes(uuid: CFUUIDRef) -> CFUUIDBytes; 92 | 93 | /* Getting the CFUUID Type Identifier */ 94 | pub fn CFUUIDGetTypeID() -> CFTypeID; 95 | } 96 | -------------------------------------------------------------------------------- /core-foundation-sys/src/mach_port.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 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 crate::base::{mach_port_t, Boolean}; 11 | pub use crate::base::{CFAllocatorRef, CFIndex, CFTypeID}; 12 | use crate::runloop::CFRunLoopSourceRef; 13 | use crate::string::CFStringRef; 14 | use core::ffi::c_void; 15 | 16 | #[repr(C)] 17 | pub struct __CFMachPort(c_void); 18 | pub type CFMachPortRef = *mut __CFMachPort; 19 | 20 | pub type CFMachPortCallBack = 21 | extern "C" fn(port: CFMachPortRef, msg: *mut c_void, size: CFIndex, info: *mut c_void); 22 | pub type CFMachPortInvalidationCallBack = extern "C" fn(port: CFMachPortRef, info: *mut c_void); 23 | 24 | #[repr(C)] 25 | #[derive(Clone, Copy)] 26 | pub struct CFMachPortContext { 27 | pub version: CFIndex, 28 | pub info: *mut c_void, 29 | pub retain: extern "C" fn(info: *const c_void) -> *const c_void, 30 | pub release: extern "C" fn(info: *const c_void), 31 | pub copyDescription: extern "C" fn(info: *const c_void) -> CFStringRef, 32 | } 33 | 34 | extern "C" { 35 | /* 36 | * CFMachPort.h 37 | */ 38 | 39 | /* Creating a CFMachPort Object */ 40 | pub fn CFMachPortCreate( 41 | allocator: CFAllocatorRef, 42 | callout: CFMachPortCallBack, 43 | context: *mut CFMachPortContext, 44 | shouldFreeInfo: *mut Boolean, 45 | ) -> CFMachPortRef; 46 | pub fn CFMachPortCreateWithPort( 47 | allocator: CFAllocatorRef, 48 | portNum: mach_port_t, 49 | callout: CFMachPortCallBack, 50 | context: *mut CFMachPortContext, 51 | shouldFreeInfo: *mut Boolean, 52 | ) -> CFMachPortRef; 53 | 54 | /* Configuring a CFMachPort Object */ 55 | pub fn CFMachPortInvalidate(port: CFMachPortRef); 56 | pub fn CFMachPortCreateRunLoopSource( 57 | allocator: CFAllocatorRef, 58 | port: CFMachPortRef, 59 | order: CFIndex, 60 | ) -> CFRunLoopSourceRef; 61 | pub fn CFMachPortSetInvalidationCallBack( 62 | port: CFMachPortRef, 63 | callout: CFMachPortInvalidationCallBack, 64 | ); 65 | 66 | /* Examining a CFMachPort Object */ 67 | pub fn CFMachPortGetContext(port: CFMachPortRef, context: *mut CFMachPortContext); 68 | pub fn CFMachPortGetInvalidationCallBack(port: CFMachPortRef) 69 | -> CFMachPortInvalidationCallBack; 70 | pub fn CFMachPortGetPort(port: CFMachPortRef) -> mach_port_t; 71 | pub fn CFMachPortIsValid(port: CFMachPortRef) -> Boolean; 72 | 73 | /* Getting the CFMachPort Type ID */ 74 | pub fn CFMachPortGetTypeID() -> CFTypeID; 75 | } 76 | -------------------------------------------------------------------------------- /core-foundation-sys/src/url_enumerator.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 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 core::ffi::c_void; 11 | 12 | use crate::array::CFArrayRef; 13 | use crate::base::{Boolean, CFAllocatorRef, CFIndex, CFOptionFlags, CFTypeID}; 14 | use crate::error::CFErrorRef; 15 | use crate::url::CFURLRef; 16 | 17 | #[repr(C)] 18 | pub struct __CFURLEnumerator(c_void); 19 | 20 | pub type CFURLEnumeratorRef = *mut __CFURLEnumerator; 21 | 22 | pub type CFURLEnumeratorOptions = CFOptionFlags; 23 | pub const kCFURLEnumeratorDefaultBehavior: CFURLEnumeratorOptions = 0; 24 | pub const kCFURLEnumeratorDescendRecursively: CFURLEnumeratorOptions = 1 << 0; 25 | pub const kCFURLEnumeratorSkipInvisibles: CFURLEnumeratorOptions = 1 << 1; 26 | pub const kCFURLEnumeratorGenerateFileReferenceURLs: CFURLEnumeratorOptions = 1 << 2; 27 | pub const kCFURLEnumeratorSkipPackageContents: CFURLEnumeratorOptions = 1 << 3; 28 | pub const kCFURLEnumeratorIncludeDirectoriesPreOrder: CFURLEnumeratorOptions = 1 << 4; 29 | pub const kCFURLEnumeratorIncludeDirectoriesPostOrder: CFURLEnumeratorOptions = 1 << 5; 30 | //pub const kCFURLEnumeratorGenerateRelativePathURLs = 1UL << 6; // macos(10.15)+ 31 | 32 | pub type CFURLEnumeratorResult = CFIndex; 33 | pub const kCFURLEnumeratorSuccess: CFURLEnumeratorOptions = 1; 34 | pub const kCFURLEnumeratorEnd: CFURLEnumeratorOptions = 2; 35 | pub const kCFURLEnumeratorError: CFURLEnumeratorOptions = 3; 36 | pub const kCFURLEnumeratorDirectoryPostOrderSuccess: CFURLEnumeratorOptions = 4; 37 | 38 | extern "C" { 39 | /* 40 | * CFURLEnumerator.h 41 | */ 42 | pub fn CFURLEnumeratorGetTypeID() -> CFTypeID; 43 | pub fn CFURLEnumeratorCreateForDirectoryURL( 44 | alloc: CFAllocatorRef, 45 | directoryURL: CFURLRef, 46 | option: CFURLEnumeratorOptions, 47 | propertyKeys: CFArrayRef, 48 | ) -> CFURLEnumeratorRef; 49 | pub fn CFURLEnumeratorCreateForMountedVolumes( 50 | alloc: CFAllocatorRef, 51 | option: CFURLEnumeratorOptions, 52 | propertyKeys: CFArrayRef, 53 | ) -> CFURLEnumeratorRef; 54 | pub fn CFURLEnumeratorGetNextURL( 55 | enumerator: CFURLEnumeratorRef, 56 | url: *mut CFURLRef, 57 | error: *mut CFErrorRef, 58 | ) -> CFURLEnumeratorResult; 59 | pub fn CFURLEnumeratorSkipDescendents(enumerator: CFURLEnumeratorRef); 60 | pub fn CFURLEnumeratorGetDescendentLevel(enumerator: CFURLEnumeratorRef) -> CFIndex; 61 | pub fn CFURLEnumeratorGetSourceDidChange(enumerator: CFURLEnumeratorRef) -> Boolean; // deprecated since macos 10.7 62 | } 63 | -------------------------------------------------------------------------------- /core-foundation/src/uuid.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 | //! Core Foundation UUID objects. 11 | 12 | use core_foundation_sys::base::kCFAllocatorDefault; 13 | pub use core_foundation_sys::uuid::*; 14 | 15 | use crate::base::TCFType; 16 | 17 | #[cfg(feature = "with-uuid")] 18 | use uuid::Uuid; 19 | 20 | declare_TCFType! { 21 | /// A UUID. 22 | CFUUID, CFUUIDRef 23 | } 24 | impl_TCFType!(CFUUID, CFUUIDRef, CFUUIDGetTypeID); 25 | impl_CFTypeDescription!(CFUUID); 26 | 27 | impl CFUUID { 28 | #[inline] 29 | pub fn new() -> CFUUID { 30 | unsafe { 31 | let uuid_ref = CFUUIDCreate(kCFAllocatorDefault); 32 | TCFType::wrap_under_create_rule(uuid_ref) 33 | } 34 | } 35 | } 36 | 37 | impl Default for CFUUID { 38 | fn default() -> Self { 39 | Self::new() 40 | } 41 | } 42 | 43 | #[cfg(feature = "with-uuid")] 44 | impl From for Uuid { 45 | fn from(val: CFUUID) -> Self { 46 | let b = unsafe { CFUUIDGetUUIDBytes(val.0) }; 47 | let bytes = [ 48 | b.byte0, b.byte1, b.byte2, b.byte3, b.byte4, b.byte5, b.byte6, b.byte7, b.byte8, 49 | b.byte9, b.byte10, b.byte11, b.byte12, b.byte13, b.byte14, b.byte15, 50 | ]; 51 | Uuid::from_bytes(bytes) 52 | } 53 | } 54 | 55 | #[cfg(feature = "with-uuid")] 56 | impl From for CFUUID { 57 | fn from(uuid: Uuid) -> CFUUID { 58 | let b = uuid.as_bytes(); 59 | let bytes = CFUUIDBytes { 60 | byte0: b[0], 61 | byte1: b[1], 62 | byte2: b[2], 63 | byte3: b[3], 64 | byte4: b[4], 65 | byte5: b[5], 66 | byte6: b[6], 67 | byte7: b[7], 68 | byte8: b[8], 69 | byte9: b[9], 70 | byte10: b[10], 71 | byte11: b[11], 72 | byte12: b[12], 73 | byte13: b[13], 74 | byte14: b[14], 75 | byte15: b[15], 76 | }; 77 | unsafe { 78 | let uuid_ref = CFUUIDCreateFromUUIDBytes(kCFAllocatorDefault, bytes); 79 | TCFType::wrap_under_create_rule(uuid_ref) 80 | } 81 | } 82 | } 83 | 84 | #[cfg(test)] 85 | #[cfg(feature = "with-uuid")] 86 | mod test { 87 | use super::CFUUID; 88 | use uuid::Uuid; 89 | 90 | #[test] 91 | fn uuid_conversion() { 92 | let cf_uuid = CFUUID::new(); 93 | let uuid: Uuid = cf_uuid.clone().into(); 94 | let converted = CFUUID::from(uuid); 95 | assert_eq!(cf_uuid, converted); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /core-foundation-sys/src/tree.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 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 core::ffi::c_void; 11 | 12 | use crate::base::{CFAllocatorRef, CFComparatorFunction, CFIndex, CFTypeID}; 13 | use crate::string::CFStringRef; 14 | 15 | #[repr(C)] 16 | pub struct __CFTree(c_void); 17 | pub type CFTreeRef = *mut __CFTree; 18 | 19 | pub type CFTreeRetainCallBack = extern "C" fn(info: *const c_void) -> *const c_void; 20 | pub type CFTreeReleaseCallBack = extern "C" fn(info: *const c_void); 21 | pub type CFTreeCopyDescriptionCallBack = extern "C" fn(info: *const c_void) -> CFStringRef; 22 | pub type CFTreeApplierFunction = extern "C" fn(value: *const c_void, context: *mut c_void); 23 | 24 | #[repr(C)] 25 | pub struct CFTreeContext { 26 | pub version: CFIndex, 27 | pub info: *mut c_void, 28 | pub retain: CFTreeRetainCallBack, 29 | pub release: CFTreeReleaseCallBack, 30 | pub copyDescription: CFTreeCopyDescriptionCallBack, 31 | } 32 | 33 | extern "C" { 34 | /* 35 | * CFTree.h 36 | */ 37 | /* Creating Trees */ 38 | pub fn CFTreeCreate(allocator: CFAllocatorRef, context: *const CFTreeContext) -> CFTreeRef; 39 | 40 | /* Modifying a Tree */ 41 | pub fn CFTreeAppendChild(tree: CFTreeRef, newChild: CFTreeRef); 42 | pub fn CFTreeInsertSibling(tree: CFTreeRef, newSibling: CFTreeRef); 43 | pub fn CFTreeRemoveAllChildren(tree: CFTreeRef); 44 | pub fn CFTreePrependChild(tree: CFTreeRef, newChild: CFTreeRef); 45 | pub fn CFTreeRemove(tree: CFTreeRef); 46 | pub fn CFTreeSetContext(tree: CFTreeRef, context: *const CFTreeContext); 47 | 48 | /* Sorting a Tree */ 49 | pub fn CFTreeSortChildren( 50 | tree: CFTreeRef, 51 | comparator: CFComparatorFunction, 52 | context: *mut c_void, 53 | ); 54 | 55 | /* Examining a Tree */ 56 | pub fn CFTreeFindRoot(tree: CFTreeRef) -> CFTreeRef; 57 | pub fn CFTreeGetChildAtIndex(tree: CFTreeRef, idx: CFIndex) -> CFTreeRef; 58 | pub fn CFTreeGetChildCount(tree: CFTreeRef) -> CFIndex; 59 | pub fn CFTreeGetChildren(tree: CFTreeRef, children: *mut CFTreeRef); 60 | pub fn CFTreeGetContext(tree: CFTreeRef, context: *mut CFTreeContext); 61 | pub fn CFTreeGetFirstChild(tree: CFTreeRef) -> CFTreeRef; 62 | pub fn CFTreeGetNextSibling(tree: CFTreeRef) -> CFTreeRef; 63 | pub fn CFTreeGetParent(tree: CFTreeRef) -> CFTreeRef; 64 | 65 | /* Performing an Operation on Tree Elements */ 66 | pub fn CFTreeApplyFunctionToChildren( 67 | tree: CFTreeRef, 68 | applier: CFTreeApplierFunction, 69 | context: *mut c_void, 70 | ); 71 | 72 | /* Getting the Tree Type ID */ 73 | pub fn CFTreeGetTypeID() -> CFTypeID; 74 | } 75 | -------------------------------------------------------------------------------- /core-foundation-sys/src/bit_vector.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 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 core::ffi::c_void; 11 | 12 | use crate::base::{Boolean, CFAllocatorRef, CFIndex, CFRange, CFTypeID, UInt32, UInt8}; 13 | 14 | #[repr(C)] 15 | pub struct __CFBitVector(c_void); 16 | 17 | pub type CFBitVectorRef = *const __CFBitVector; 18 | pub type CFMutableBitVectorRef = *mut __CFBitVector; 19 | pub type CFBit = UInt32; 20 | 21 | extern "C" { 22 | /* 23 | * CFBitVector.h 24 | */ 25 | 26 | /* CFBitVector */ 27 | /* Creating a Bit Vector */ 28 | pub fn CFBitVectorCreate( 29 | allocator: CFAllocatorRef, 30 | bytes: *const UInt8, 31 | numBits: CFIndex, 32 | ) -> CFBitVectorRef; 33 | pub fn CFBitVectorCreateCopy(allocator: CFAllocatorRef, bv: CFBitVectorRef) -> CFBitVectorRef; 34 | 35 | /* Getting Information About a Bit Vector */ 36 | pub fn CFBitVectorContainsBit(bv: CFBitVectorRef, range: CFRange, value: CFBit) -> Boolean; 37 | pub fn CFBitVectorGetBitAtIndex(bv: CFBitVectorRef, idx: CFIndex) -> CFBit; 38 | pub fn CFBitVectorGetBits(bv: CFBitVectorRef, range: CFRange, bytes: *mut UInt8); 39 | pub fn CFBitVectorGetCount(bv: CFBitVectorRef) -> CFIndex; 40 | pub fn CFBitVectorGetCountOfBit(bv: CFBitVectorRef, range: CFRange, value: CFBit) -> CFIndex; 41 | pub fn CFBitVectorGetFirstIndexOfBit( 42 | bv: CFBitVectorRef, 43 | range: CFRange, 44 | value: CFBit, 45 | ) -> CFIndex; 46 | pub fn CFBitVectorGetLastIndexOfBit( 47 | bv: CFBitVectorRef, 48 | range: CFRange, 49 | value: CFBit, 50 | ) -> CFIndex; 51 | 52 | /* Getting the CFBitVector Type ID */ 53 | pub fn CFBitVectorGetTypeID() -> CFTypeID; 54 | 55 | /* CFMutableBitVector */ 56 | /* Creating a CFMutableBitVector Object */ 57 | pub fn CFBitVectorCreateMutable( 58 | allocator: CFAllocatorRef, 59 | capacity: CFIndex, 60 | ) -> CFMutableBitVectorRef; 61 | pub fn CFBitVectorCreateMutableCopy( 62 | allocator: CFAllocatorRef, 63 | capacity: CFIndex, 64 | bv: CFBitVectorRef, 65 | ) -> CFMutableBitVectorRef; 66 | 67 | /* Modifying a Bit Vector */ 68 | pub fn CFBitVectorFlipBitAtIndex(bv: CFMutableBitVectorRef, idx: CFIndex); 69 | pub fn CFBitVectorFlipBits(bv: CFMutableBitVectorRef, range: CFRange); 70 | pub fn CFBitVectorSetAllBits(bv: CFMutableBitVectorRef, value: CFBit); 71 | pub fn CFBitVectorSetBitAtIndex(bv: CFMutableBitVectorRef, idx: CFIndex, value: CFBit); 72 | pub fn CFBitVectorSetBits(bv: CFMutableBitVectorRef, range: CFRange, value: CFBit); 73 | pub fn CFBitVectorSetCount(bv: CFMutableBitVectorRef, count: CFIndex); 74 | } 75 | -------------------------------------------------------------------------------- /core-graphics/src/gradient.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 crate::base::CGFloat; 13 | use crate::color::CGColor; 14 | use crate::color_space::CGColorSpace; 15 | 16 | use bitflags::bitflags; 17 | use core_foundation::array::{CFArray, CFArrayRef}; 18 | use core_foundation::base::{CFRelease, CFRetain, TCFType}; 19 | use foreign_types::{foreign_type, ForeignType}; 20 | 21 | bitflags! { 22 | #[repr(C)] 23 | #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] 24 | pub struct CGGradientDrawingOptions: u32 { 25 | const CGGradientDrawsBeforeStartLocation = (1 << 0); 26 | const CGGradientDrawsAfterEndLocation = (1 << 1); 27 | } 28 | } 29 | 30 | foreign_type! { 31 | #[doc(hidden)] 32 | pub unsafe type CGGradient { 33 | type CType = crate::sys::CGGradient; 34 | fn drop = |p| CFRelease(p as *mut _); 35 | fn clone = |p| CFRetain(p as *const _) as *mut _; 36 | } 37 | } 38 | 39 | impl CGGradient { 40 | pub fn create_with_color_components( 41 | color_space: &CGColorSpace, 42 | components: &[CGFloat], 43 | locations: &[CGFloat], 44 | count: usize, 45 | ) -> CGGradient { 46 | unsafe { 47 | let result = CGGradientCreateWithColorComponents( 48 | color_space.as_ptr(), 49 | components.as_ptr(), 50 | locations.as_ptr(), 51 | count, 52 | ); 53 | assert!(!result.is_null()); 54 | Self::from_ptr(result) 55 | } 56 | } 57 | 58 | pub fn create_with_colors( 59 | color_space: &CGColorSpace, 60 | colors: &CFArray, 61 | locations: &[CGFloat], 62 | ) -> CGGradient { 63 | unsafe { 64 | let result = CGGradientCreateWithColors( 65 | color_space.as_ptr(), 66 | colors.as_concrete_TypeRef(), 67 | locations.as_ptr(), 68 | ); 69 | assert!(!result.is_null()); 70 | Self::from_ptr(result) 71 | } 72 | } 73 | } 74 | 75 | #[cfg_attr(feature = "link", link(name = "CoreGraphics", kind = "framework"))] 76 | extern "C" { 77 | fn CGGradientCreateWithColorComponents( 78 | color_space: crate::sys::CGColorSpaceRef, 79 | components: *const CGFloat, 80 | locations: *const CGFloat, 81 | count: usize, 82 | ) -> crate::sys::CGGradientRef; 83 | fn CGGradientCreateWithColors( 84 | color_space: crate::sys::CGColorSpaceRef, 85 | colors: CFArrayRef, 86 | locations: *const CGFloat, 87 | ) -> crate::sys::CGGradientRef; 88 | } 89 | -------------------------------------------------------------------------------- /core-foundation-sys/src/data.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2013-2015 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 crate::base::{CFAllocatorRef, CFIndex, CFOptionFlags, CFRange, CFTypeID}; 11 | use core::ffi::c_void; 12 | 13 | #[repr(C)] 14 | pub struct __CFData(c_void); 15 | 16 | pub type CFDataRef = *const __CFData; 17 | pub type CFMutableDataRef = *mut __CFData; 18 | pub type CFDataSearchFlags = CFOptionFlags; 19 | 20 | // typedef CF_OPTIONS(CFOptionFlags, CFDataSearchFlags) 21 | pub const kCFDataSearchBackwards: CFDataSearchFlags = 1usize << 0; 22 | pub const kCFDataSearchAnchored: CFDataSearchFlags = 1usize << 1; 23 | 24 | extern "C" { 25 | /* 26 | * CFData.h 27 | */ 28 | 29 | /* CFData */ 30 | /* Creating a CFData Object */ 31 | pub fn CFDataCreate(allocator: CFAllocatorRef, bytes: *const u8, length: CFIndex) -> CFDataRef; 32 | pub fn CFDataCreateCopy(allocator: CFAllocatorRef, theData: CFDataRef) -> CFDataRef; 33 | pub fn CFDataCreateWithBytesNoCopy( 34 | allocator: CFAllocatorRef, 35 | bytes: *const u8, 36 | length: CFIndex, 37 | bytesDeallocator: CFAllocatorRef, 38 | ) -> CFDataRef; 39 | 40 | /* Examining a CFData Object */ 41 | pub fn CFDataGetBytePtr(theData: CFDataRef) -> *const u8; 42 | pub fn CFDataGetBytes(theData: CFDataRef, range: CFRange, buffer: *mut u8); 43 | pub fn CFDataGetLength(theData: CFDataRef) -> CFIndex; 44 | pub fn CFDataFind( 45 | theData: CFDataRef, 46 | dataToFind: CFDataRef, 47 | searchRange: CFRange, 48 | compareOptions: CFDataSearchFlags, 49 | ) -> CFRange; 50 | 51 | /* Getting the CFData Type ID */ 52 | pub fn CFDataGetTypeID() -> CFTypeID; 53 | 54 | /* CFMutableData */ 55 | /* Creating a Mutable Data Object */ 56 | pub fn CFDataCreateMutable(allocator: CFAllocatorRef, capacity: CFIndex) -> CFMutableDataRef; 57 | pub fn CFDataCreateMutableCopy( 58 | allocator: CFAllocatorRef, 59 | capacity: CFIndex, 60 | theData: CFDataRef, 61 | ) -> CFMutableDataRef; 62 | 63 | /* Accessing Data */ 64 | pub fn CFDataGetMutableBytePtr(theData: CFMutableDataRef) -> *mut u8; 65 | 66 | /* Modifying a Mutable Data Object */ 67 | pub fn CFDataAppendBytes(theData: CFMutableDataRef, bytes: *const u8, length: CFIndex); 68 | pub fn CFDataDeleteBytes(theData: CFMutableDataRef, range: CFRange); 69 | pub fn CFDataReplaceBytes( 70 | theData: CFMutableDataRef, 71 | range: CFRange, 72 | newBytes: *const u8, 73 | newLength: CFIndex, 74 | ); 75 | pub fn CFDataIncreaseLength(theData: CFMutableDataRef, extraLength: CFIndex); 76 | pub fn CFDataSetLength(theData: CFMutableDataRef, length: CFIndex); 77 | } 78 | -------------------------------------------------------------------------------- /core-foundation-sys/src/filedescriptor.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2013-2015 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 core::ffi::{c_int, c_void}; 11 | 12 | use crate::base::{Boolean, CFAllocatorRef, CFIndex, CFOptionFlags, CFTypeID}; 13 | use crate::runloop::CFRunLoopSourceRef; 14 | use crate::string::CFStringRef; 15 | 16 | pub type CFFileDescriptorNativeDescriptor = c_int; 17 | 18 | #[repr(C)] 19 | pub struct __CFFileDescriptor(c_void); 20 | 21 | pub type CFFileDescriptorRef = *mut __CFFileDescriptor; 22 | 23 | /* Callback Reason Types */ 24 | pub const kCFFileDescriptorReadCallBack: CFOptionFlags = 1 << 0; 25 | pub const kCFFileDescriptorWriteCallBack: CFOptionFlags = 1 << 1; 26 | 27 | pub type CFFileDescriptorCallBack = 28 | extern "C" fn(f: CFFileDescriptorRef, callBackTypes: CFOptionFlags, info: *mut c_void); 29 | 30 | #[repr(C)] 31 | #[derive(Debug, Clone, Copy)] 32 | pub struct CFFileDescriptorContext { 33 | pub version: CFIndex, 34 | pub info: *mut c_void, 35 | pub retain: Option *const c_void>, 36 | pub release: Option, 37 | pub copyDescription: Option CFStringRef>, 38 | } 39 | 40 | extern "C" { 41 | /* 42 | * CFFileDescriptor.h 43 | */ 44 | 45 | /* Creating a CFFileDescriptor */ 46 | pub fn CFFileDescriptorCreate( 47 | allocator: CFAllocatorRef, 48 | fd: CFFileDescriptorNativeDescriptor, 49 | closeOnInvalidate: Boolean, 50 | callout: CFFileDescriptorCallBack, 51 | context: *const CFFileDescriptorContext, 52 | ) -> CFFileDescriptorRef; 53 | 54 | /* Getting Information About a File Descriptor */ 55 | pub fn CFFileDescriptorGetNativeDescriptor( 56 | f: CFFileDescriptorRef, 57 | ) -> CFFileDescriptorNativeDescriptor; 58 | pub fn CFFileDescriptorIsValid(f: CFFileDescriptorRef) -> Boolean; 59 | pub fn CFFileDescriptorGetContext( 60 | f: CFFileDescriptorRef, 61 | context: *mut CFFileDescriptorContext, 62 | ); 63 | 64 | /* Invalidating a File Descriptor */ 65 | pub fn CFFileDescriptorInvalidate(f: CFFileDescriptorRef); 66 | 67 | /* Managing Callbacks */ 68 | pub fn CFFileDescriptorEnableCallBacks(f: CFFileDescriptorRef, callBackTypes: CFOptionFlags); 69 | pub fn CFFileDescriptorDisableCallBacks(f: CFFileDescriptorRef, callBackTypes: CFOptionFlags); 70 | 71 | /* Creating a Run Loop Source */ 72 | pub fn CFFileDescriptorCreateRunLoopSource( 73 | allocator: CFAllocatorRef, 74 | f: CFFileDescriptorRef, 75 | order: CFIndex, 76 | ) -> CFRunLoopSourceRef; 77 | 78 | /* Getting the CFFileDescriptor Type ID */ 79 | pub fn CFFileDescriptorGetTypeID() -> CFTypeID; 80 | } 81 | -------------------------------------------------------------------------------- /core-foundation/src/attributed_string.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 | pub use core_foundation_sys::attributed_string::*; 11 | 12 | use crate::base::TCFType; 13 | use crate::string::{CFString, CFStringRef}; 14 | use core_foundation_sys::base::{kCFAllocatorDefault, CFIndex, CFRange}; 15 | use std::ptr::null; 16 | 17 | declare_TCFType! { 18 | CFAttributedString, CFAttributedStringRef 19 | } 20 | impl_TCFType!( 21 | CFAttributedString, 22 | CFAttributedStringRef, 23 | CFAttributedStringGetTypeID 24 | ); 25 | 26 | impl CFAttributedString { 27 | #[inline] 28 | pub fn new(string: &CFString) -> Self { 29 | unsafe { 30 | let astr_ref = 31 | CFAttributedStringCreate(kCFAllocatorDefault, string.as_concrete_TypeRef(), null()); 32 | 33 | CFAttributedString::wrap_under_create_rule(astr_ref) 34 | } 35 | } 36 | 37 | #[inline] 38 | pub fn char_len(&self) -> CFIndex { 39 | unsafe { CFAttributedStringGetLength(self.0) } 40 | } 41 | } 42 | 43 | declare_TCFType! { 44 | CFMutableAttributedString, CFMutableAttributedStringRef 45 | } 46 | impl_TCFType!( 47 | CFMutableAttributedString, 48 | CFMutableAttributedStringRef, 49 | CFAttributedStringGetTypeID 50 | ); 51 | 52 | impl CFMutableAttributedString { 53 | #[inline] 54 | pub fn new() -> Self { 55 | unsafe { 56 | let astr_ref = CFAttributedStringCreateMutable(kCFAllocatorDefault, 0); 57 | 58 | CFMutableAttributedString::wrap_under_create_rule(astr_ref) 59 | } 60 | } 61 | 62 | #[inline] 63 | pub fn char_len(&self) -> CFIndex { 64 | unsafe { CFAttributedStringGetLength(self.0) } 65 | } 66 | 67 | #[inline] 68 | pub fn replace_str(&mut self, string: &CFString, range: CFRange) { 69 | unsafe { 70 | CFAttributedStringReplaceString(self.0, range, string.as_concrete_TypeRef()); 71 | } 72 | } 73 | 74 | #[inline] 75 | pub fn set_attribute(&mut self, range: CFRange, name: CFStringRef, value: &T) { 76 | unsafe { 77 | CFAttributedStringSetAttribute(self.0, range, name, value.as_CFTypeRef()); 78 | } 79 | } 80 | } 81 | 82 | impl Default for CFMutableAttributedString { 83 | fn default() -> Self { 84 | Self::new() 85 | } 86 | } 87 | 88 | #[cfg(test)] 89 | mod tests { 90 | use super::*; 91 | 92 | #[test] 93 | fn attributed_string_type_id_comparison() { 94 | // CFMutableAttributedString TypeID must be equal to CFAttributedString TypeID. 95 | // Compilation must not fail. 96 | assert_eq!( 97 | ::type_id(), 98 | ::type_id() 99 | ); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /core-text/src/font_manager.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 crate::font_descriptor::{CTFontDescriptor, CTFontDescriptorRef}; 11 | use core_foundation::array::{CFArray, CFArrayRef}; 12 | use core_foundation::base::TCFType; 13 | use core_foundation::data::{CFData, CFDataRef}; 14 | use core_foundation::string::CFString; 15 | use core_foundation::url::CFURLRef; 16 | 17 | pub fn copy_available_font_family_names() -> CFArray { 18 | unsafe { TCFType::wrap_under_create_rule(CTFontManagerCopyAvailableFontFamilyNames()) } 19 | } 20 | 21 | pub fn create_font_descriptor(buffer: &[u8]) -> Result { 22 | let cf_data = CFData::from_buffer(buffer); 23 | unsafe { 24 | let ct_font_descriptor_ref = 25 | CTFontManagerCreateFontDescriptorFromData(cf_data.as_concrete_TypeRef()); 26 | if ct_font_descriptor_ref.is_null() { 27 | return Err(()); 28 | } 29 | Ok(CTFontDescriptor::wrap_under_create_rule( 30 | ct_font_descriptor_ref, 31 | )) 32 | } 33 | } 34 | 35 | pub fn create_font_descriptor_with_data(data: CFData) -> Result { 36 | unsafe { 37 | let ct_font_descriptor_ref = 38 | CTFontManagerCreateFontDescriptorFromData(data.as_concrete_TypeRef()); 39 | if ct_font_descriptor_ref.is_null() { 40 | return Err(()); 41 | } 42 | Ok(CTFontDescriptor::wrap_under_create_rule( 43 | ct_font_descriptor_ref, 44 | )) 45 | } 46 | } 47 | 48 | extern "C" { 49 | /* 50 | * CTFontManager.h 51 | */ 52 | 53 | // Incomplete function bindings are mostly related to CoreText font matching, which 54 | // we implement in a platform-independent manner using FontMatcher. 55 | 56 | //pub fn CTFontManagerCompareFontFamilyNames 57 | pub fn CTFontManagerCopyAvailableFontURLs() -> CFArrayRef; 58 | pub fn CTFontManagerCopyAvailableFontFamilyNames() -> CFArrayRef; 59 | pub fn CTFontManagerCopyAvailablePostScriptNames() -> CFArrayRef; 60 | pub fn CTFontManagerCreateFontDescriptorsFromURL(fileURL: CFURLRef) -> CFArrayRef; 61 | pub fn CTFontManagerCreateFontDescriptorFromData(data: CFDataRef) -> CTFontDescriptorRef; 62 | //pub fn CTFontManagerCreateFontRequestRunLoopSource 63 | //pub fn CTFontManagerEnableFontDescriptors 64 | //pub fn CTFontManagerGetAutoActivationSetting 65 | //pub fn CTFontManagerGetScopeForURL 66 | //pub fn CTFontManagerGetAutoActivationSetting 67 | //pub fn CTFontManagerGetScopeForURL 68 | pub fn CTFontManagerIsSupportedFont(fontURL: CFURLRef) -> bool; 69 | //pub fn CTFontManagerRegisterFontsForURL 70 | //pub fn CTFontManagerRegisterFontsForURLs 71 | //pub fn CTFontManagerRegisterGraphicsFont 72 | //pub fn CTFontManagerSetAutoActivationSetting 73 | //pub fn CTFontManagerUnregisterFontsForURL 74 | //pub fn CTFontManagerUnregisterFontsForURLs 75 | //pub fn CTFontManagerUnregisterGraphicsFont 76 | } 77 | -------------------------------------------------------------------------------- /core-foundation-sys/src/binary_heap.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 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 core::ffi::c_void; 11 | 12 | use crate::base::{Boolean, CFAllocatorRef, CFComparisonResult, CFIndex, CFTypeID}; 13 | use crate::string::CFStringRef; 14 | 15 | #[repr(C)] 16 | pub struct __CFBinaryHeap(c_void); 17 | 18 | pub type CFBinaryHeapRef = *mut __CFBinaryHeap; 19 | 20 | #[repr(C)] 21 | #[derive(Debug, Clone, Copy)] 22 | pub struct CFBinaryHeapCompareContext { 23 | pub version: CFIndex, 24 | pub info: *mut c_void, 25 | pub retain: extern "C" fn(info: *const c_void) -> *const c_void, 26 | pub release: extern "C" fn(info: *const c_void), 27 | pub copyDescription: extern "C" fn(info: *const c_void) -> CFStringRef, 28 | } 29 | 30 | #[repr(C)] 31 | #[derive(Debug, Clone, Copy)] 32 | pub struct CFBinaryHeapCallBacks { 33 | pub version: CFIndex, 34 | pub retain: extern "C" fn(allocator: CFAllocatorRef, ptr: *const c_void) -> *const c_void, 35 | pub release: extern "C" fn(allocator: CFAllocatorRef, ptr: *const c_void), 36 | pub copyDescription: extern "C" fn(ptr: *const c_void) -> CFStringRef, 37 | pub compare: extern "C" fn( 38 | ptr1: *const c_void, 39 | ptr2: *const c_void, 40 | context: *mut c_void, 41 | ) -> CFComparisonResult, 42 | } 43 | 44 | pub type CFBinaryHeapApplierFunction = extern "C" fn(val: *const c_void, context: *const c_void); 45 | 46 | extern "C" { 47 | /* 48 | * CFBinaryHeap.h 49 | */ 50 | /* Predefined Callback Structures */ 51 | pub static kCFStringBinaryHeapCallBacks: CFBinaryHeapCallBacks; 52 | 53 | /* CFBinaryHeap Miscellaneous Functions */ 54 | pub fn CFBinaryHeapAddValue(heap: CFBinaryHeapRef, value: *const c_void); 55 | pub fn CFBinaryHeapApplyFunction( 56 | heap: CFBinaryHeapRef, 57 | applier: CFBinaryHeapApplierFunction, 58 | context: *mut c_void, 59 | ); 60 | pub fn CFBinaryHeapContainsValue(heap: CFBinaryHeapRef, value: *const c_void) -> Boolean; 61 | pub fn CFBinaryHeapCreate( 62 | allocator: CFAllocatorRef, 63 | capacity: CFIndex, 64 | callBacks: *const CFBinaryHeapCallBacks, 65 | compareContext: *const CFBinaryHeapCompareContext, 66 | ) -> CFBinaryHeapRef; 67 | pub fn CFBinaryHeapCreateCopy( 68 | allocator: CFAllocatorRef, 69 | capacity: CFIndex, 70 | heap: CFBinaryHeapRef, 71 | ) -> CFBinaryHeapRef; 72 | pub fn CFBinaryHeapGetCount(heap: CFBinaryHeapRef) -> CFIndex; 73 | pub fn CFBinaryHeapGetCountOfValue(heap: CFBinaryHeapRef, value: *const c_void) -> CFIndex; 74 | pub fn CFBinaryHeapGetMinimum(heap: CFBinaryHeapRef) -> *const c_void; 75 | pub fn CFBinaryHeapGetMinimumIfPresent( 76 | heap: CFBinaryHeapRef, 77 | value: *const *const c_void, 78 | ) -> Boolean; 79 | pub fn CFBinaryHeapGetTypeID() -> CFTypeID; 80 | pub fn CFBinaryHeapGetValues(heap: CFBinaryHeapRef, values: *const *const c_void); 81 | pub fn CFBinaryHeapRemoveAllValues(heap: CFBinaryHeapRef); 82 | pub fn CFBinaryHeapRemoveMinimumValue(heap: CFBinaryHeapRef); 83 | } 84 | -------------------------------------------------------------------------------- /core-foundation-sys/src/notification_center.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 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 core::ffi::c_void; 11 | 12 | use crate::base::{Boolean, CFIndex, CFOptionFlags, CFTypeID}; 13 | use crate::dictionary::CFDictionaryRef; 14 | use crate::string::CFStringRef; 15 | 16 | #[repr(C)] 17 | pub struct __CFNotificationCenter(c_void); 18 | 19 | pub type CFNotificationCenterRef = *mut __CFNotificationCenter; 20 | 21 | pub type CFNotificationName = CFStringRef; 22 | pub type CFNotificationCallback = extern "C" fn( 23 | center: CFNotificationCenterRef, 24 | observer: *mut c_void, 25 | name: CFNotificationName, 26 | object: *const c_void, 27 | userInfo: CFDictionaryRef, 28 | ); 29 | pub type CFNotificationSuspensionBehavior = CFIndex; 30 | 31 | pub const CFNotificationSuspensionBehaviorDrop: CFNotificationSuspensionBehavior = 1; 32 | pub const CFNotificationSuspensionBehaviorCoalesce: CFNotificationSuspensionBehavior = 2; 33 | pub const CFNotificationSuspensionBehaviorHold: CFNotificationSuspensionBehavior = 3; 34 | pub const CFNotificationSuspensionBehaviorDeliverImmediately: CFNotificationSuspensionBehavior = 4; 35 | 36 | /* Notification Posting Options */ 37 | pub const kCFNotificationDeliverImmediately: CFOptionFlags = 1usize << 0; 38 | pub const kCFNotificationPostToAllSessions: CFOptionFlags = 1usize << 1; 39 | 40 | extern "C" { 41 | /* 42 | * CFNotificationCenter.h 43 | */ 44 | 45 | /* Accessing a Notification Center */ 46 | pub fn CFNotificationCenterGetDarwinNotifyCenter() -> CFNotificationCenterRef; 47 | #[cfg(any(target_os = "macos", target_os = "windows"))] 48 | pub fn CFNotificationCenterGetDistributedCenter() -> CFNotificationCenterRef; 49 | pub fn CFNotificationCenterGetLocalCenter() -> CFNotificationCenterRef; 50 | 51 | /* Posting a Notification */ 52 | pub fn CFNotificationCenterPostNotification( 53 | center: CFNotificationCenterRef, 54 | name: CFNotificationName, 55 | object: *const c_void, 56 | userInfo: CFDictionaryRef, 57 | deliverImmediately: Boolean, 58 | ); 59 | pub fn CFNotificationCenterPostNotificationWithOptions( 60 | center: CFNotificationCenterRef, 61 | name: CFNotificationName, 62 | object: *const c_void, 63 | userInfo: CFDictionaryRef, 64 | options: CFOptionFlags, 65 | ); 66 | 67 | /* Adding and Removing Observers */ 68 | pub fn CFNotificationCenterAddObserver( 69 | center: CFNotificationCenterRef, 70 | observer: *const c_void, 71 | callBack: CFNotificationCallback, 72 | name: CFStringRef, 73 | object: *const c_void, 74 | suspensionBehavior: CFNotificationSuspensionBehavior, 75 | ); 76 | pub fn CFNotificationCenterRemoveEveryObserver( 77 | center: CFNotificationCenterRef, 78 | observer: *const c_void, 79 | ); 80 | pub fn CFNotificationCenterRemoveObserver( 81 | center: CFNotificationCenterRef, 82 | observer: *const c_void, 83 | name: CFNotificationName, 84 | object: *const c_void, 85 | ); 86 | 87 | /* Getting the CFNotificationCenter Type ID */ 88 | pub fn CFNotificationCenterGetTypeID() -> CFTypeID; 89 | } 90 | -------------------------------------------------------------------------------- /core-foundation-sys/src/file_security.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 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 core::ffi::c_void; 11 | 12 | #[cfg(feature = "mac_os_10_8_features")] 13 | use crate::base::CFOptionFlags; 14 | use crate::base::{Boolean, CFAllocatorRef, CFTypeID}; 15 | use crate::uuid::CFUUIDRef; 16 | 17 | #[repr(C)] 18 | pub struct __CFFileSecurity(c_void); 19 | pub type CFFileSecurityRef = *mut __CFFileSecurity; 20 | 21 | #[cfg(feature = "mac_os_10_8_features")] 22 | pub type CFFileSecurityClearOptions = CFOptionFlags; 23 | #[cfg(feature = "mac_os_10_8_features")] 24 | pub const kCFFileSecurityClearOwner: CFFileSecurityClearOptions = 1 << 0; 25 | #[cfg(feature = "mac_os_10_8_features")] 26 | pub const kCFFileSecurityClearGroup: CFFileSecurityClearOptions = 1 << 1; 27 | #[cfg(feature = "mac_os_10_8_features")] 28 | pub const kCFFileSecurityClearMode: CFFileSecurityClearOptions = 1 << 2; 29 | #[cfg(feature = "mac_os_10_8_features")] 30 | pub const kCFFileSecurityClearOwnerUUID: CFFileSecurityClearOptions = 1 << 3; 31 | #[cfg(feature = "mac_os_10_8_features")] 32 | pub const kCFFileSecurityClearGroupUUID: CFFileSecurityClearOptions = 1 << 4; 33 | #[cfg(feature = "mac_os_10_8_features")] 34 | pub const kCFFileSecurityClearAccessControlList: CFFileSecurityClearOptions = 1 << 5; 35 | 36 | extern "C" { 37 | /* 38 | * CFFileSecurity.h 39 | */ 40 | pub fn CFFileSecurityGetTypeID() -> CFTypeID; 41 | pub fn CFFileSecurityCreate(allocator: CFAllocatorRef) -> CFFileSecurityRef; 42 | pub fn CFFileSecurityCreateCopy( 43 | allocator: CFAllocatorRef, 44 | fileSec: CFFileSecurityRef, 45 | ) -> CFFileSecurityRef; 46 | pub fn CFFileSecurityCopyOwnerUUID( 47 | fileSec: CFFileSecurityRef, 48 | ownerUUID: *mut CFUUIDRef, 49 | ) -> Boolean; 50 | pub fn CFFileSecuritySetOwnerUUID(fileSec: CFFileSecurityRef, ownerUUID: CFUUIDRef) -> Boolean; 51 | pub fn CFFileSecurityCopyGroupUUID( 52 | fileSec: CFFileSecurityRef, 53 | groupUUID: *mut CFUUIDRef, 54 | ) -> Boolean; 55 | pub fn CFFileSecuritySetGroupUUID(fileSec: CFFileSecurityRef, groupUUID: CFUUIDRef) -> Boolean; 56 | //pub fn CFFileSecurityCopyAccessControlList(fileSec: CFFileSecurityRef, accessControlList: *mut acl_t) -> Boolean; 57 | //pub fn CFFileSecuritySetAccessControlList(fileSec: CFFileSecurityRef, accessControlList: acl_t) -> Boolean; 58 | //pub fn CFFileSecurityGetOwner(fileSec: CFFileSecurityRef, owner: *mut uid_t) -> Boolean; 59 | //pub fn CFFileSecuritySetOwner(fileSec: CFFileSecurityRef, owner: uid_t) -> Boolean; 60 | //pub fn CFFileSecurityGetGroup(fileSec: CFFileSecurityRef, group: *mut gid_t) -> Boolean; 61 | //pub fn CFFileSecuritySetGroup(fileSec: CFFileSecurityRef, group: gid_t) -> Boolean; 62 | //pub fn CFFileSecurityGetMode(fileSec: CFFileSecurityRef, mode: *mut mode_t) -> Boolean; 63 | //pub fn CFFileSecuritySetMode(fileSec: CFFileSecurityRef, mode: mode_t) -> Boolean; 64 | 65 | #[cfg(feature = "mac_os_10_8_features")] 66 | #[cfg_attr(feature = "mac_os_10_7_support", linkage = "extern_weak")] 67 | pub fn CFFileSecurityClearProperties( 68 | fileSec: CFFileSecurityRef, 69 | clearPropertyMask: CFFileSecurityClearOptions, 70 | ) -> Boolean; 71 | } 72 | -------------------------------------------------------------------------------- /cocoa/examples/tab_view.rs: -------------------------------------------------------------------------------- 1 | #![allow(deprecated)] // the cocoa crate is deprecated 2 | use cocoa::base::{id, nil, selector, NO}; 3 | 4 | use cocoa::appkit::{ 5 | NSApp, NSApplication, NSApplicationActivateIgnoringOtherApps, 6 | NSApplicationActivationPolicyRegular, NSBackingStoreType, NSMenu, NSMenuItem, 7 | NSRunningApplication, NSTabView, NSTabViewItem, NSWindow, NSWindowStyleMask, 8 | }; 9 | use cocoa::foundation::{NSAutoreleasePool, NSPoint, NSProcessInfo, NSRect, NSSize, NSString}; 10 | 11 | fn main() { 12 | unsafe { 13 | // create a tab View 14 | let tab_view = NSTabView::new(nil) 15 | .initWithFrame_(NSRect::new(NSPoint::new(0., 0.), NSSize::new(200., 200.))); 16 | 17 | // create a tab view item 18 | let tab_view_item = 19 | NSTabViewItem::new(nil).initWithIdentifier_(NSString::alloc(nil).init_str("TabView1")); 20 | 21 | tab_view_item.setLabel_(NSString::alloc(nil).init_str("Tab view item 1")); 22 | tab_view.addTabViewItem_(tab_view_item); 23 | 24 | // create a second tab view item 25 | let tab_view_item2 = 26 | NSTabViewItem::new(nil).initWithIdentifier_(NSString::alloc(nil).init_str("TabView2")); 27 | 28 | tab_view_item2.setLabel_(NSString::alloc(nil).init_str("Tab view item 2")); 29 | tab_view.addTabViewItem_(tab_view_item2); 30 | 31 | // Create the app and set the content. 32 | let app = create_app(NSString::alloc(nil).init_str("Tab View"), tab_view); 33 | app.run(); 34 | } 35 | } 36 | 37 | unsafe fn create_app(title: id, content: id) -> id { 38 | let _pool = NSAutoreleasePool::new(nil); 39 | 40 | let app = NSApp(); 41 | app.setActivationPolicy_(NSApplicationActivationPolicyRegular); 42 | 43 | // create Menu Bar 44 | let menubar = NSMenu::new(nil).autorelease(); 45 | let app_menu_item = NSMenuItem::new(nil).autorelease(); 46 | menubar.addItem_(app_menu_item); 47 | app.setMainMenu_(menubar); 48 | 49 | // create Application menu 50 | let app_menu = NSMenu::new(nil).autorelease(); 51 | let quit_prefix = NSString::alloc(nil).init_str("Quit "); 52 | let quit_title = 53 | quit_prefix.stringByAppendingString_(NSProcessInfo::processInfo(nil).processName()); 54 | let quit_action = selector("terminate:"); 55 | let quit_key = NSString::alloc(nil).init_str("q"); 56 | let quit_item = NSMenuItem::alloc(nil) 57 | .initWithTitle_action_keyEquivalent_(quit_title, quit_action, quit_key) 58 | .autorelease(); 59 | app_menu.addItem_(quit_item); 60 | app_menu_item.setSubmenu_(app_menu); 61 | 62 | // create Window 63 | let window = NSWindow::alloc(nil) 64 | .initWithContentRect_styleMask_backing_defer_( 65 | NSRect::new(NSPoint::new(0., 0.), NSSize::new(200., 200.)), 66 | NSWindowStyleMask::NSTitledWindowMask 67 | | NSWindowStyleMask::NSClosableWindowMask 68 | | NSWindowStyleMask::NSResizableWindowMask 69 | | NSWindowStyleMask::NSMiniaturizableWindowMask 70 | | NSWindowStyleMask::NSUnifiedTitleAndToolbarWindowMask, 71 | NSBackingStoreType::NSBackingStoreBuffered, 72 | NO, 73 | ) 74 | .autorelease(); 75 | window.cascadeTopLeftFromPoint_(NSPoint::new(20., 20.)); 76 | window.center(); 77 | 78 | window.setTitle_(title); 79 | window.makeKeyAndOrderFront_(nil); 80 | 81 | window.setContentView_(content); 82 | let current_app = NSRunningApplication::currentApplication(nil); 83 | current_app.activateWithOptions_(NSApplicationActivateIgnoringOtherApps); 84 | 85 | app 86 | } 87 | -------------------------------------------------------------------------------- /cocoa/examples/nsvisualeffectview_blur.rs: -------------------------------------------------------------------------------- 1 | #![allow(deprecated)] // the cocoa crate is deprecated 2 | use cocoa::base::{nil, selector, NO}; 3 | use objc::*; 4 | 5 | use cocoa::appkit::{ 6 | NSApp, NSApplication, NSApplicationActivationPolicyRegular, NSBackingStoreType, NSColor, 7 | NSMenu, NSMenuItem, NSView, NSViewHeightSizable, NSViewWidthSizable, 8 | NSVisualEffectBlendingMode, NSVisualEffectMaterial, NSVisualEffectState, NSVisualEffectView, 9 | NSWindow, NSWindowOrderingMode, NSWindowStyleMask, 10 | }; 11 | use cocoa::foundation::{NSAutoreleasePool, NSPoint, NSProcessInfo, NSRect, NSSize, NSString}; 12 | 13 | fn main() { 14 | unsafe { 15 | // Create the app. 16 | let _pool = NSAutoreleasePool::new(nil); 17 | 18 | let app = NSApp(); 19 | app.setActivationPolicy_(NSApplicationActivationPolicyRegular); 20 | 21 | // create Menu Bar 22 | let menubar = NSMenu::new(nil).autorelease(); 23 | let app_menu_item = NSMenuItem::new(nil).autorelease(); 24 | menubar.addItem_(app_menu_item); 25 | app.setMainMenu_(menubar); 26 | 27 | // create Application menu 28 | let app_menu = NSMenu::new(nil).autorelease(); 29 | let quit_prefix = NSString::alloc(nil).init_str("Quit "); 30 | let quit_title = 31 | quit_prefix.stringByAppendingString_(NSProcessInfo::processInfo(nil).processName()); 32 | let quit_action = selector("terminate:"); 33 | let quit_key = NSString::alloc(nil).init_str("q"); 34 | let quit_item = NSMenuItem::alloc(nil) 35 | .initWithTitle_action_keyEquivalent_(quit_title, quit_action, quit_key) 36 | .autorelease(); 37 | app_menu.addItem_(quit_item); 38 | app_menu_item.setSubmenu_(app_menu); 39 | 40 | // Create some colors 41 | let clear = NSColor::clearColor(nil); 42 | 43 | // Create windows with different color types. 44 | let window = NSWindow::alloc(nil) 45 | .initWithContentRect_styleMask_backing_defer_( 46 | NSRect::new(NSPoint::new(0., 0.), NSSize::new(200., 200.)), 47 | NSWindowStyleMask::NSTitledWindowMask 48 | | NSWindowStyleMask::NSClosableWindowMask 49 | | NSWindowStyleMask::NSResizableWindowMask 50 | | NSWindowStyleMask::NSMiniaturizableWindowMask 51 | | NSWindowStyleMask::NSUnifiedTitleAndToolbarWindowMask, 52 | NSBackingStoreType::NSBackingStoreBuffered, 53 | NO, 54 | ) 55 | .autorelease(); 56 | 57 | window.cascadeTopLeftFromPoint_(NSPoint::new(20., 20.)); 58 | window.setTitle_(NSString::alloc(nil).init_str("NSVisualEffectView_blur")); 59 | window.setBackgroundColor_(clear); 60 | window.makeKeyAndOrderFront_(nil); 61 | 62 | //NSVisualEffectView blur 63 | let ns_view = window.contentView(); 64 | let bounds = NSView::bounds(ns_view); 65 | let blurred_view = 66 | NSVisualEffectView::initWithFrame_(NSVisualEffectView::alloc(nil), bounds); 67 | blurred_view.autorelease(); 68 | 69 | blurred_view.setMaterial_(NSVisualEffectMaterial::HudWindow); 70 | blurred_view.setBlendingMode_(NSVisualEffectBlendingMode::BehindWindow); 71 | blurred_view.setState_(NSVisualEffectState::FollowsWindowActiveState); 72 | blurred_view.setAutoresizingMask_(NSViewWidthSizable | NSViewHeightSizable); 73 | 74 | let _: () = msg_send![ns_view, addSubview: blurred_view positioned: NSWindowOrderingMode::NSWindowBelow relativeTo: 0]; 75 | 76 | app.run(); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /core-text/src/framesetter.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 super::frame::{CTFrame, CTFrameRef}; 11 | use core_foundation::attributed_string::CFAttributedStringRef; 12 | use core_foundation::base::{CFRange, CFTypeID, TCFType}; 13 | use core_foundation::dictionary::CFDictionaryRef; 14 | use core_foundation::{declare_TCFType, impl_CFTypeDescription, impl_TCFType}; 15 | use core_graphics::geometry::CGSize; 16 | use core_graphics::path::{CGPath, CGPathRef}; 17 | use foreign_types::{ForeignType, ForeignTypeRef}; 18 | use std::ptr::null; 19 | 20 | #[repr(C)] 21 | pub struct __CTFramesetter(core::ffi::c_void); 22 | 23 | pub type CTFramesetterRef = *const __CTFramesetter; 24 | 25 | declare_TCFType! { 26 | CTFramesetter, CTFramesetterRef 27 | } 28 | impl_TCFType!(CTFramesetter, CTFramesetterRef, CTFramesetterGetTypeID); 29 | impl_CFTypeDescription!(CTFramesetter); 30 | 31 | impl CTFramesetter { 32 | pub fn new_with_attributed_string(string: CFAttributedStringRef) -> Self { 33 | unsafe { 34 | let ptr = CTFramesetterCreateWithAttributedString(string); 35 | CTFramesetter::wrap_under_create_rule(ptr) 36 | } 37 | } 38 | 39 | pub fn create_frame(&self, string_range: CFRange, path: &CGPathRef) -> CTFrame { 40 | unsafe { 41 | let ptr = CTFramesetterCreateFrame( 42 | self.as_concrete_TypeRef(), 43 | string_range, 44 | path.as_ptr(), 45 | null(), 46 | ); 47 | 48 | CTFrame::wrap_under_create_rule(ptr) 49 | } 50 | } 51 | 52 | /// Suggest an appropriate frame size for displaying a text range. 53 | /// 54 | /// Returns a tuple containing an appropriate size (that should be smaller 55 | /// than the provided constraints) as well as the range of text that fits in 56 | /// this frame. 57 | pub fn suggest_frame_size_with_constraints( 58 | &self, 59 | string_range: CFRange, 60 | frame_attributes: CFDictionaryRef, 61 | constraints: CGSize, 62 | ) -> (CGSize, CFRange) { 63 | unsafe { 64 | let mut fit_range = CFRange::init(0, 0); 65 | let size = CTFramesetterSuggestFrameSizeWithConstraints( 66 | self.as_concrete_TypeRef(), 67 | string_range, 68 | frame_attributes, 69 | constraints, 70 | &mut fit_range, 71 | ); 72 | (size, fit_range) 73 | } 74 | } 75 | } 76 | 77 | #[cfg_attr(feature = "link", link(name = "CoreText", kind = "framework"))] 78 | extern "C" { 79 | fn CTFramesetterGetTypeID() -> CFTypeID; 80 | fn CTFramesetterCreateWithAttributedString(string: CFAttributedStringRef) -> CTFramesetterRef; 81 | fn CTFramesetterCreateFrame( 82 | framesetter: CTFramesetterRef, 83 | string_range: CFRange, 84 | path: *mut ::CType, 85 | attributes: *const core::ffi::c_void, 86 | ) -> CTFrameRef; 87 | fn CTFramesetterSuggestFrameSizeWithConstraints( 88 | framesetter: CTFramesetterRef, 89 | string_range: CFRange, 90 | frame_attributes: CFDictionaryRef, 91 | constraints: CGSize, 92 | fitRange: *mut CFRange, 93 | ) -> CGSize; 94 | } 95 | -------------------------------------------------------------------------------- /core-foundation-sys/src/string_tokenizer.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 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 core::ffi::c_void; 11 | 12 | use crate::array::CFMutableArrayRef; 13 | use crate::base::{CFAllocatorRef, CFIndex, CFOptionFlags, CFRange, CFTypeID, CFTypeRef}; 14 | use crate::locale::CFLocaleRef; 15 | use crate::string::CFStringRef; 16 | 17 | #[repr(C)] 18 | pub struct __CFStringTokenizer(c_void); 19 | pub type CFStringTokenizerRef = *mut __CFStringTokenizer; 20 | 21 | pub type CFStringTokenizerTokenType = CFOptionFlags; 22 | 23 | pub const kCFStringTokenizerTokenNone: CFStringTokenizerTokenType = 0; 24 | pub const kCFStringTokenizerTokenNormal: CFStringTokenizerTokenType = 1 << 0; 25 | pub const kCFStringTokenizerTokenHasSubTokensMask: CFStringTokenizerTokenType = 1 << 1; 26 | pub const kCFStringTokenizerTokenHasDerivedSubTokensMask: CFStringTokenizerTokenType = 1 << 2; 27 | pub const kCFStringTokenizerTokenHasHasNumbersMask: CFStringTokenizerTokenType = 1 << 3; 28 | pub const kCFStringTokenizerTokenHasNonLettersMask: CFStringTokenizerTokenType = 1 << 4; 29 | pub const kCFStringTokenizerTokenIsCJWordMask: CFStringTokenizerTokenType = 1 << 5; 30 | 31 | /* Tokenization Modifiers */ 32 | pub const kCFStringTokenizerUnitWord: CFOptionFlags = 0; 33 | pub const kCFStringTokenizerUnitSentence: CFOptionFlags = 1; 34 | pub const kCFStringTokenizerUnitParagraph: CFOptionFlags = 2; 35 | pub const kCFStringTokenizerUnitLineBreak: CFOptionFlags = 3; 36 | pub const kCFStringTokenizerUnitWordBoundary: CFOptionFlags = 4; 37 | pub const kCFStringTokenizerAttributeLatinTranscription: CFOptionFlags = 1 << 16; 38 | pub const kCFStringTokenizerAttributeLanguage: CFOptionFlags = 1 << 17; 39 | 40 | extern "C" { 41 | /* 42 | * CFStringTokenizer.h 43 | */ 44 | 45 | /* Creating a Tokenizer */ 46 | pub fn CFStringTokenizerCreate( 47 | alloc: CFAllocatorRef, 48 | string: CFStringRef, 49 | range: CFRange, 50 | options: CFOptionFlags, 51 | locale: CFLocaleRef, 52 | ) -> CFStringTokenizerRef; 53 | 54 | /* Setting the String */ 55 | pub fn CFStringTokenizerSetString( 56 | tokenizer: CFStringTokenizerRef, 57 | string: CFStringRef, 58 | range: CFRange, 59 | ); 60 | 61 | /* Changing the Location */ 62 | pub fn CFStringTokenizerAdvanceToNextToken( 63 | tokenizer: CFStringTokenizerRef, 64 | ) -> CFStringTokenizerTokenType; 65 | pub fn CFStringTokenizerGoToTokenAtIndex( 66 | tokenizer: CFStringTokenizerRef, 67 | index: CFIndex, 68 | ) -> CFStringTokenizerTokenType; 69 | 70 | /* Getting Information About the Current Token */ 71 | pub fn CFStringTokenizerCopyCurrentTokenAttribute( 72 | tokenizer: CFStringTokenizerRef, 73 | attribute: CFOptionFlags, 74 | ) -> CFTypeRef; 75 | pub fn CFStringTokenizerGetCurrentTokenRange(tokenizer: CFStringTokenizerRef) -> CFRange; 76 | pub fn CFStringTokenizerGetCurrentSubTokens( 77 | tokenizer: CFStringTokenizerRef, 78 | ranges: *mut CFRange, 79 | maxRangeLength: CFIndex, 80 | derivedSubTokens: CFMutableArrayRef, 81 | ) -> CFIndex; 82 | 83 | /* Identifying a Language */ 84 | pub fn CFStringTokenizerCopyBestStringLanguage( 85 | string: CFStringRef, 86 | range: CFRange, 87 | ) -> CFStringRef; 88 | 89 | /* Getting the CFStringTokenizer Type ID */ 90 | pub fn CFStringTokenizerGetTypeID() -> CFTypeID; 91 | } 92 | -------------------------------------------------------------------------------- /core-foundation-sys/src/timezone.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2013-2015 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 core::ffi::c_void; 11 | 12 | use crate::array::CFArrayRef; 13 | use crate::base::{Boolean, CFAllocatorRef, CFIndex, CFTypeID}; 14 | use crate::data::CFDataRef; 15 | use crate::date::{CFAbsoluteTime, CFTimeInterval}; 16 | use crate::dictionary::CFDictionaryRef; 17 | use crate::locale::CFLocaleRef; 18 | use crate::notification_center::CFNotificationName; 19 | use crate::string::CFStringRef; 20 | 21 | #[repr(C)] 22 | pub struct __CFTimeZone(c_void); 23 | 24 | pub type CFTimeZoneRef = *const __CFTimeZone; 25 | pub type CFTimeZoneNameStyle = CFIndex; 26 | 27 | /* Constants to specify styles for time zone names */ 28 | pub const kCFTimeZoneNameStyleStandard: CFTimeZoneNameStyle = 0; 29 | pub const kCFTimeZoneNameStyleShortStandard: CFTimeZoneNameStyle = 1; 30 | pub const kCFTimeZoneNameStyleDaylightSaving: CFTimeZoneNameStyle = 2; 31 | pub const kCFTimeZoneNameStyleShortDaylightSaving: CFTimeZoneNameStyle = 3; 32 | pub const kCFTimeZoneNameStyleGeneric: CFTimeZoneNameStyle = 4; 33 | pub const kCFTimeZoneNameStyleShortGeneric: CFTimeZoneNameStyle = 5; 34 | 35 | extern "C" { 36 | /* 37 | * CFTimeZone.h 38 | */ 39 | 40 | pub static kCFTimeZoneSystemTimeZoneDidChangeNotification: CFNotificationName; 41 | 42 | /* Creating a Time Zone */ 43 | pub fn CFTimeZoneCreate( 44 | allocator: CFAllocatorRef, 45 | name: CFStringRef, 46 | data: CFDataRef, 47 | ) -> CFTimeZoneRef; 48 | pub fn CFTimeZoneCreateWithName( 49 | allocator: CFAllocatorRef, 50 | name: CFStringRef, 51 | tryAbbrev: Boolean, 52 | ) -> CFTimeZoneRef; 53 | pub fn CFTimeZoneCreateWithTimeIntervalFromGMT( 54 | allocator: CFAllocatorRef, 55 | interval: CFTimeInterval, 56 | ) -> CFTimeZoneRef; 57 | 58 | /* System and Default Time Zones and Information */ 59 | pub fn CFTimeZoneCopyAbbreviationDictionary() -> CFDictionaryRef; 60 | pub fn CFTimeZoneCopyAbbreviation(tz: CFTimeZoneRef, at: CFAbsoluteTime) -> CFStringRef; 61 | pub fn CFTimeZoneCopyDefault() -> CFTimeZoneRef; 62 | pub fn CFTimeZoneCopySystem() -> CFTimeZoneRef; 63 | pub fn CFTimeZoneSetDefault(tz: CFTimeZoneRef); 64 | pub fn CFTimeZoneCopyKnownNames() -> CFArrayRef; 65 | pub fn CFTimeZoneResetSystem(); 66 | pub fn CFTimeZoneSetAbbreviationDictionary(dict: CFDictionaryRef); 67 | 68 | /* Getting Information About Time Zones */ 69 | pub fn CFTimeZoneGetName(tz: CFTimeZoneRef) -> CFStringRef; 70 | pub fn CFTimeZoneCopyLocalizedName( 71 | tz: CFTimeZoneRef, 72 | style: CFTimeZoneNameStyle, 73 | locale: CFLocaleRef, 74 | ) -> CFStringRef; 75 | pub fn CFTimeZoneGetSecondsFromGMT(tz: CFTimeZoneRef, time: CFAbsoluteTime) -> CFTimeInterval; 76 | pub fn CFTimeZoneGetData(tz: CFTimeZoneRef) -> CFDataRef; 77 | 78 | /* Getting Daylight Savings Time Information */ 79 | pub fn CFTimeZoneIsDaylightSavingTime(tz: CFTimeZoneRef, at: CFAbsoluteTime) -> Boolean; 80 | pub fn CFTimeZoneGetDaylightSavingTimeOffset( 81 | tz: CFTimeZoneRef, 82 | at: CFAbsoluteTime, 83 | ) -> CFTimeInterval; 84 | pub fn CFTimeZoneGetNextDaylightSavingTimeTransition( 85 | tz: CFTimeZoneRef, 86 | at: CFAbsoluteTime, 87 | ) -> CFAbsoluteTime; 88 | 89 | /* Getting the CFTimeZone Type ID */ 90 | pub fn CFTimeZoneGetTypeID() -> CFTypeID; 91 | } 92 | -------------------------------------------------------------------------------- /core-text/src/frame.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 crate::line::CTLine; 11 | use core_foundation::array::{CFArray, CFArrayRef}; 12 | use core_foundation::base::{CFRange, CFTypeID, TCFType}; 13 | use core_foundation::{declare_TCFType, impl_CFTypeDescription, impl_TCFType}; 14 | use core_graphics::context::{CGContext, CGContextRef}; 15 | use core_graphics::geometry::CGPoint; 16 | use core_graphics::path::{CGPath, SysCGPathRef}; 17 | use foreign_types::{ForeignType, ForeignTypeRef}; 18 | 19 | #[repr(C)] 20 | pub struct __CTFrame(core::ffi::c_void); 21 | 22 | pub type CTFrameRef = *const __CTFrame; 23 | 24 | declare_TCFType! { 25 | CTFrame, CTFrameRef 26 | } 27 | impl_TCFType!(CTFrame, CTFrameRef, CTFrameGetTypeID); 28 | impl_CFTypeDescription!(CTFrame); 29 | 30 | impl CTFrame { 31 | /// The `CGPath` used to create this `CTFrame`. 32 | pub fn get_path(&self) -> CGPath { 33 | unsafe { CGPath::from_ptr(CTFrameGetPath(self.as_concrete_TypeRef())).clone() } 34 | } 35 | 36 | /// Returns an owned copy of the underlying lines. 37 | /// 38 | /// Each line is retained, and will remain valid past the life of this `CTFrame`. 39 | pub fn get_lines(&self) -> Vec { 40 | unsafe { 41 | let array_ref = CTFrameGetLines(self.as_concrete_TypeRef()); 42 | let array: CFArray = CFArray::wrap_under_get_rule(array_ref); 43 | array 44 | .iter() 45 | .map(|l| CTLine::wrap_under_get_rule(l.as_concrete_TypeRef())) 46 | .collect() 47 | } 48 | } 49 | 50 | /// Return the origin of each line in a given range. 51 | /// 52 | /// If no range is provided, returns the origin of each line in the frame. 53 | /// 54 | /// If the length of the range is 0, returns the origin of all lines from 55 | /// the range's start to the end. 56 | /// 57 | /// The origin is the position relative to the path used to create this `CTFFrame`; 58 | /// to get the path use [`get_path`]. 59 | /// 60 | /// [`get_path`]: #method.get_path 61 | pub fn get_line_origins(&self, range: impl Into>) -> Vec { 62 | let range = range.into().unwrap_or_else(|| CFRange::init(0, 0)); 63 | let len = match range.length { 64 | // range length of 0 means 'all remaining lines' 65 | 0 => unsafe { 66 | let array_ref = CTFrameGetLines(self.as_concrete_TypeRef()); 67 | let array: CFArray = CFArray::wrap_under_get_rule(array_ref); 68 | array.len() - range.location 69 | }, 70 | n => n, 71 | }; 72 | let len = len.max(0) as usize; 73 | let mut out = vec![CGPoint::new(0., 0.); len]; 74 | unsafe { 75 | CTFrameGetLineOrigins(self.as_concrete_TypeRef(), range, out.as_mut_ptr()); 76 | } 77 | out 78 | } 79 | 80 | pub fn draw(&self, context: &CGContextRef) { 81 | unsafe { 82 | CTFrameDraw(self.as_concrete_TypeRef(), context.as_ptr()); 83 | } 84 | } 85 | } 86 | 87 | #[cfg_attr(feature = "link", link(name = "CoreText", kind = "framework"))] 88 | extern "C" { 89 | fn CTFrameGetTypeID() -> CFTypeID; 90 | fn CTFrameGetLines(frame: CTFrameRef) -> CFArrayRef; 91 | fn CTFrameDraw(frame: CTFrameRef, context: *mut ::CType); 92 | fn CTFrameGetLineOrigins(frame: CTFrameRef, range: CFRange, origins: *mut CGPoint); 93 | fn CTFrameGetPath(frame: CTFrameRef) -> SysCGPathRef; 94 | } 95 | -------------------------------------------------------------------------------- /core-foundation-sys/src/set.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2013-2015 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 core::ffi::c_void; 11 | 12 | use crate::base::{Boolean, CFAllocatorRef, CFHashCode, CFIndex, CFTypeID}; 13 | use crate::string::CFStringRef; 14 | 15 | pub type CFSetApplierFunction = extern "C" fn(value: *const c_void, context: *const c_void); 16 | pub type CFSetRetainCallBack = 17 | extern "C" fn(allocator: CFAllocatorRef, value: *const c_void) -> *const c_void; 18 | pub type CFSetReleaseCallBack = extern "C" fn(allocator: CFAllocatorRef, value: *const c_void); 19 | pub type CFSetCopyDescriptionCallBack = extern "C" fn(value: *const c_void) -> CFStringRef; 20 | pub type CFSetEqualCallBack = 21 | extern "C" fn(value1: *const c_void, value2: *const c_void) -> Boolean; 22 | pub type CFSetHashCallBack = extern "C" fn(value: *const c_void) -> CFHashCode; 23 | 24 | #[repr(C)] 25 | #[derive(Clone, Copy)] 26 | pub struct CFSetCallBacks { 27 | pub version: CFIndex, 28 | pub retain: CFSetRetainCallBack, 29 | pub release: CFSetReleaseCallBack, 30 | pub copyDescription: CFSetCopyDescriptionCallBack, 31 | pub equal: CFSetEqualCallBack, 32 | pub hash: CFSetHashCallBack, 33 | } 34 | 35 | #[repr(C)] 36 | pub struct __CFSet(c_void); 37 | 38 | pub type CFSetRef = *const __CFSet; 39 | pub type CFMutableSetRef = *mut __CFSet; 40 | 41 | extern "C" { 42 | /* 43 | * CFSet.h 44 | */ 45 | 46 | pub static kCFTypeSetCallBacks: CFSetCallBacks; 47 | pub static kCFCopyStringSetCallBacks: CFSetCallBacks; 48 | 49 | /* CFSet */ 50 | /* Creating Sets */ 51 | pub fn CFSetCreate( 52 | allocator: CFAllocatorRef, 53 | values: *const *const c_void, 54 | numValues: CFIndex, 55 | callBacks: *const CFSetCallBacks, 56 | ) -> CFSetRef; 57 | pub fn CFSetCreateCopy(allocator: CFAllocatorRef, theSet: CFSetRef) -> CFSetRef; 58 | 59 | /* Examining a Set */ 60 | pub fn CFSetContainsValue(theSet: CFSetRef, value: *const c_void) -> Boolean; 61 | pub fn CFSetGetCount(theSet: CFSetRef) -> CFIndex; 62 | pub fn CFSetGetCountOfValue(theSet: CFSetRef, value: *const c_void) -> CFIndex; 63 | pub fn CFSetGetValue(theSet: CFSetRef, value: *const c_void) -> *const c_void; 64 | pub fn CFSetGetValueIfPresent( 65 | theSet: CFSetRef, 66 | candidate: *const c_void, 67 | value: *mut *const c_void, 68 | ) -> Boolean; 69 | pub fn CFSetGetValues(theSet: CFSetRef, values: *mut *const c_void); 70 | 71 | /* Applying a Function to Set Members */ 72 | pub fn CFSetApplyFunction( 73 | theSet: CFSetRef, 74 | applier: CFSetApplierFunction, 75 | context: *const c_void, 76 | ); 77 | 78 | /* Getting the CFSet Type ID */ 79 | pub fn CFSetGetTypeID() -> CFTypeID; 80 | 81 | /* CFMutableSet */ 82 | /* CFMutableSet Miscellaneous Functions */ 83 | pub fn CFSetAddValue(theSet: CFMutableSetRef, value: *const c_void); 84 | pub fn CFSetCreateMutable( 85 | allocator: CFAllocatorRef, 86 | capacity: CFIndex, 87 | callBacks: *const CFSetCallBacks, 88 | ) -> CFMutableSetRef; 89 | pub fn CFSetCreateMutableCopy( 90 | allocator: CFAllocatorRef, 91 | capacity: CFIndex, 92 | theSet: CFSetRef, 93 | ) -> CFMutableSetRef; 94 | pub fn CFSetRemoveAllValues(theSet: CFMutableSetRef); 95 | pub fn CFSetRemoveValue(theSet: CFMutableSetRef, value: *const c_void); 96 | pub fn CFSetReplaceValue(theSet: CFMutableSetRef, value: *const c_void); 97 | pub fn CFSetSetValue(theSet: CFMutableSetRef, value: *const c_void); 98 | } 99 | -------------------------------------------------------------------------------- /core-foundation-sys/src/number.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2013-2015 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 core::ffi::c_void; 11 | 12 | use crate::base::{Boolean, CFAllocatorRef, CFComparisonResult, CFIndex, CFTypeID}; 13 | 14 | #[repr(C)] 15 | pub struct __CFBoolean(c_void); 16 | 17 | pub type CFBooleanRef = *const __CFBoolean; 18 | 19 | pub type CFNumberType = u32; 20 | 21 | // members of enum CFNumberType 22 | pub const kCFNumberSInt8Type: CFNumberType = 1; 23 | pub const kCFNumberSInt16Type: CFNumberType = 2; 24 | pub const kCFNumberSInt32Type: CFNumberType = 3; 25 | pub const kCFNumberSInt64Type: CFNumberType = 4; 26 | pub const kCFNumberFloat32Type: CFNumberType = 5; 27 | pub const kCFNumberFloat64Type: CFNumberType = 6; 28 | pub const kCFNumberCharType: CFNumberType = 7; 29 | pub const kCFNumberShortType: CFNumberType = 8; 30 | pub const kCFNumberIntType: CFNumberType = 9; 31 | pub const kCFNumberLongType: CFNumberType = 10; 32 | pub const kCFNumberLongLongType: CFNumberType = 11; 33 | pub const kCFNumberFloatType: CFNumberType = 12; 34 | pub const kCFNumberDoubleType: CFNumberType = 13; 35 | pub const kCFNumberCFIndexType: CFNumberType = 14; 36 | pub const kCFNumberNSIntegerType: CFNumberType = 15; 37 | pub const kCFNumberCGFloatType: CFNumberType = 16; 38 | pub const kCFNumberMaxType: CFNumberType = 16; 39 | 40 | // This is an enum due to zero-sized types warnings. 41 | // For more details see https://github.com/rust-lang/rust/issues/27303 42 | pub enum __CFNumber {} 43 | 44 | pub type CFNumberRef = *const __CFNumber; 45 | 46 | extern "C" { 47 | /* 48 | * CFNumber.h 49 | */ 50 | pub static kCFBooleanTrue: CFBooleanRef; 51 | pub static kCFBooleanFalse: CFBooleanRef; 52 | pub static kCFNumberPositiveInfinity: CFNumberRef; 53 | pub static kCFNumberNegativeInfinity: CFNumberRef; 54 | pub static kCFNumberNaN: CFNumberRef; 55 | 56 | /* Creating a Number */ 57 | pub fn CFNumberCreate( 58 | allocator: CFAllocatorRef, 59 | theType: CFNumberType, 60 | valuePtr: *const c_void, 61 | ) -> CFNumberRef; 62 | 63 | /* Getting Information About Numbers */ 64 | pub fn CFNumberGetByteSize(number: CFNumberRef) -> CFIndex; 65 | pub fn CFNumberGetType(number: CFNumberRef) -> CFNumberType; 66 | pub fn CFNumberGetValue( 67 | number: CFNumberRef, 68 | theType: CFNumberType, 69 | valuePtr: *mut c_void, 70 | ) -> bool; 71 | pub fn CFNumberIsFloatType(number: CFNumberRef) -> Boolean; 72 | 73 | /* Comparing Numbers */ 74 | pub fn CFNumberCompare( 75 | date: CFNumberRef, 76 | other: CFNumberRef, 77 | context: *mut c_void, 78 | ) -> CFComparisonResult; 79 | 80 | /* Getting the CFNumber Type ID */ 81 | pub fn CFNumberGetTypeID() -> CFTypeID; 82 | 83 | pub fn CFBooleanGetValue(boolean: CFBooleanRef) -> bool; 84 | pub fn CFBooleanGetTypeID() -> CFTypeID; 85 | } 86 | 87 | #[cfg(test)] 88 | mod test { 89 | use super::*; 90 | 91 | #[test] 92 | fn match_for_type_id_should_be_backwards_compatible() { 93 | let type_id = kCFNumberFloat32Type; 94 | // this is the old style of matching for static variables 95 | match type_id { 96 | vf64 if vf64 == kCFNumberFloat32Type => assert!(true), 97 | _ => panic!("should not happen"), 98 | }; 99 | 100 | // this is new style of matching for consts 101 | match type_id { 102 | kCFNumberFloat32Type => assert!(true), 103 | _ => panic!("should not happen"), 104 | }; 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /core-foundation-sys/src/preferences.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 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 crate::array::CFArrayRef; 11 | use crate::base::{Boolean, CFIndex}; 12 | use crate::dictionary::CFDictionaryRef; 13 | use crate::propertylist::CFPropertyListRef; 14 | use crate::string::CFStringRef; 15 | 16 | extern "C" { 17 | /* 18 | * CFPreferences.h 19 | */ 20 | /* Application, Host, and User Keys */ 21 | pub static kCFPreferencesAnyApplication: CFStringRef; 22 | pub static kCFPreferencesCurrentApplication: CFStringRef; 23 | pub static kCFPreferencesAnyHost: CFStringRef; 24 | pub static kCFPreferencesCurrentHost: CFStringRef; 25 | pub static kCFPreferencesAnyUser: CFStringRef; 26 | pub static kCFPreferencesCurrentUser: CFStringRef; 27 | 28 | /* Getting Preference Values */ 29 | pub fn CFPreferencesCopyAppValue( 30 | key: CFStringRef, 31 | applicationID: CFStringRef, 32 | ) -> CFPropertyListRef; 33 | pub fn CFPreferencesCopyKeyList( 34 | applicationID: CFStringRef, 35 | userName: CFStringRef, 36 | hostName: CFStringRef, 37 | ) -> CFArrayRef; 38 | pub fn CFPreferencesCopyMultiple( 39 | keysToFetch: CFArrayRef, 40 | applicationID: CFStringRef, 41 | userName: CFStringRef, 42 | hostName: CFStringRef, 43 | ) -> CFDictionaryRef; 44 | pub fn CFPreferencesCopyValue( 45 | key: CFStringRef, 46 | applicationID: CFStringRef, 47 | userName: CFStringRef, 48 | hostName: CFStringRef, 49 | ) -> CFPropertyListRef; 50 | pub fn CFPreferencesGetAppBooleanValue( 51 | key: CFStringRef, 52 | applicationID: CFStringRef, 53 | keyExistsAndHasValidFormat: *mut Boolean, 54 | ) -> Boolean; 55 | pub fn CFPreferencesGetAppIntegerValue( 56 | key: CFStringRef, 57 | applicationID: CFStringRef, 58 | keyExistsAndHasValidFormat: *mut Boolean, 59 | ) -> CFIndex; 60 | 61 | /* Setting Preference Values */ 62 | pub fn CFPreferencesSetAppValue( 63 | key: CFStringRef, 64 | value: CFPropertyListRef, 65 | applicationID: CFStringRef, 66 | ); 67 | pub fn CFPreferencesSetMultiple( 68 | keysToSet: CFDictionaryRef, 69 | keysToRemove: CFArrayRef, 70 | applicationID: CFStringRef, 71 | userName: CFStringRef, 72 | hostName: CFStringRef, 73 | ); 74 | pub fn CFPreferencesSetValue( 75 | key: CFStringRef, 76 | value: CFPropertyListRef, 77 | applicationID: CFStringRef, 78 | userName: CFStringRef, 79 | hostName: CFStringRef, 80 | ); 81 | 82 | /* Synchronizing Preferences */ 83 | pub fn CFPreferencesAppSynchronize(applicationID: CFStringRef) -> Boolean; 84 | pub fn CFPreferencesSynchronize( 85 | applicationID: CFStringRef, 86 | userName: CFStringRef, 87 | hostName: CFStringRef, 88 | ) -> Boolean; 89 | 90 | /* Adding and Removing Suite Preferences */ 91 | pub fn CFPreferencesAddSuitePreferencesToApp(applicationID: CFStringRef, suiteID: CFStringRef); 92 | pub fn CFPreferencesRemoveSuitePreferencesFromApp( 93 | applicationID: CFStringRef, 94 | suiteID: CFStringRef, 95 | ); 96 | 97 | /* Miscellaneous Functions */ 98 | pub fn CFPreferencesAppValueIsForced(key: CFStringRef, applicationID: CFStringRef) -> Boolean; 99 | pub fn CFPreferencesCopyApplicationList( 100 | userName: CFStringRef, 101 | hostName: CFStringRef, 102 | ) -> CFArrayRef; // deprecated since macos 10.9 103 | } 104 | -------------------------------------------------------------------------------- /core-foundation-sys/src/bag.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 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 core::ffi::c_void; 11 | 12 | use crate::base::{Boolean, CFAllocatorRef, CFHashCode, CFIndex, CFTypeID}; 13 | use crate::string::CFStringRef; 14 | 15 | #[repr(C)] 16 | pub struct __CFBag(c_void); 17 | 18 | pub type CFBagRef = *const __CFBag; 19 | pub type CFMutableBagRef = *mut __CFBag; 20 | 21 | pub type CFBagRetainCallBack = 22 | extern "C" fn(allocator: CFAllocatorRef, value: *const c_void) -> *const c_void; 23 | pub type CFBagReleaseCallBack = extern "C" fn(allocator: CFAllocatorRef, value: *const c_void); 24 | pub type CFBagCopyDescriptionCallBack = extern "C" fn(value: *const c_void) -> CFStringRef; 25 | pub type CFBagEqualCallBack = 26 | extern "C" fn(value1: *const c_void, value2: *const c_void) -> Boolean; 27 | pub type CFBagHashCallBack = extern "C" fn(value: *const c_void) -> CFHashCode; 28 | 29 | #[repr(C)] 30 | #[derive(Debug, Clone, Copy)] 31 | pub struct CFBagCallBacks { 32 | pub version: CFIndex, 33 | pub retain: CFBagRetainCallBack, 34 | pub release: CFBagReleaseCallBack, 35 | pub copyDescription: CFBagCopyDescriptionCallBack, 36 | pub equal: CFBagEqualCallBack, 37 | pub hash: CFBagHashCallBack, 38 | } 39 | 40 | pub type CFBagApplierFunction = extern "C" fn(value: *const c_void, context: *mut c_void); 41 | 42 | extern "C" { 43 | /* 44 | * CFBag.h 45 | */ 46 | /* Predefined Callback Structures */ 47 | pub static kCFTypeBagCallBacks: CFBagCallBacks; 48 | pub static kCFCopyStringBagCallBacks: CFBagCallBacks; 49 | 50 | /* CFBag */ 51 | /* Creating a Bag */ 52 | pub fn CFBagCreate( 53 | allocator: CFAllocatorRef, 54 | values: *const *const c_void, 55 | numValues: CFIndex, 56 | callBacks: *const CFBagCallBacks, 57 | ) -> CFBagRef; 58 | pub fn CFBagCreateCopy(allocator: CFAllocatorRef, theBag: CFBagRef) -> CFBagRef; 59 | 60 | /* Examining a Bag */ 61 | pub fn CFBagContainsValue(theBag: CFBagRef, value: *const c_void) -> Boolean; 62 | pub fn CFBagGetCount(theBag: CFBagRef) -> CFIndex; 63 | pub fn CFBagGetCountOfValue(theBag: CFBagRef, value: *const c_void) -> CFIndex; 64 | pub fn CFBagGetValue(theBag: CFBagRef, value: *const c_void) -> *const c_void; 65 | pub fn CFBagGetValueIfPresent( 66 | theBag: CFBagRef, 67 | candidate: *const c_void, 68 | value: *const *const c_void, 69 | ) -> Boolean; 70 | pub fn CFBagGetValues(theBag: CFBagRef, values: *const *const c_void); 71 | 72 | /* Applying a Function to the Contents of a Bag */ 73 | pub fn CFBagApplyFunction( 74 | theBag: CFBagRef, 75 | applier: CFBagApplierFunction, 76 | context: *mut c_void, 77 | ); 78 | 79 | /* Getting the CFBag Type ID */ 80 | pub fn CFBagGetTypeID() -> CFTypeID; 81 | 82 | /* CFMutableBag */ 83 | /* Creating a Mutable Bag */ 84 | pub fn CFBagCreateMutable( 85 | allocator: CFAllocatorRef, 86 | capacity: CFIndex, 87 | callBacks: *const CFBagCallBacks, 88 | ) -> CFMutableBagRef; 89 | pub fn CFBagCreateMutableCopy( 90 | allocator: CFAllocatorRef, 91 | capacity: CFIndex, 92 | theBag: CFBagRef, 93 | ) -> CFMutableBagRef; 94 | 95 | /* Modifying a Mutable Bag */ 96 | pub fn CFBagAddValue(theBag: CFMutableBagRef, value: *const c_void); 97 | pub fn CFBagRemoveAllValues(theBag: CFMutableBagRef); 98 | pub fn CFBagRemoveValue(theBag: CFMutableBagRef, value: *const c_void); 99 | pub fn CFBagReplaceValue(theBag: CFMutableBagRef, value: *const c_void); 100 | pub fn CFBagSetValue(theBag: CFMutableBagRef, value: *const c_void); 101 | } 102 | -------------------------------------------------------------------------------- /core-foundation-sys/src/messageport.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2013-2015 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 core::ffi::c_void; 11 | 12 | use crate::base::{Boolean, CFAllocatorRef, CFIndex, CFTypeID, SInt32}; 13 | use crate::data::CFDataRef; 14 | use crate::date::CFTimeInterval; 15 | use crate::runloop::CFRunLoopSourceRef; 16 | use crate::string::CFStringRef; 17 | 18 | #[repr(C)] 19 | #[derive(Copy, Clone, Debug)] 20 | pub struct CFMessagePortContext { 21 | pub version: CFIndex, 22 | pub info: *mut c_void, 23 | pub retain: Option *const c_void>, 24 | pub release: Option, 25 | pub copyDescription: Option CFStringRef>, 26 | } 27 | 28 | pub type CFMessagePortCallBack = Option< 29 | unsafe extern "C" fn( 30 | local: CFMessagePortRef, 31 | msgid: i32, 32 | data: CFDataRef, 33 | info: *mut c_void, 34 | ) -> CFDataRef, 35 | >; 36 | 37 | pub type CFMessagePortInvalidationCallBack = 38 | Option; 39 | 40 | /* CFMessagePortSendRequest Error Codes */ 41 | pub const kCFMessagePortSuccess: SInt32 = 0; 42 | pub const kCFMessagePortSendTimeout: SInt32 = -1; 43 | pub const kCFMessagePortReceiveTimeout: SInt32 = -2; 44 | pub const kCFMessagePortIsInvalid: SInt32 = -3; 45 | pub const kCFMessagePortTransportError: SInt32 = -4; 46 | pub const kCFMessagePortBecameInvalidError: SInt32 = -5; 47 | 48 | #[repr(C)] 49 | pub struct __CFMessagePort(c_void); 50 | pub type CFMessagePortRef = *mut __CFMessagePort; 51 | 52 | extern "C" { 53 | /* 54 | * CFMessagePort.h 55 | */ 56 | 57 | /* Creating a CFMessagePort Object */ 58 | pub fn CFMessagePortCreateLocal( 59 | allocator: CFAllocatorRef, 60 | name: CFStringRef, 61 | callout: CFMessagePortCallBack, 62 | context: *const CFMessagePortContext, 63 | shouldFreeInfo: *mut Boolean, 64 | ) -> CFMessagePortRef; 65 | pub fn CFMessagePortCreateRemote( 66 | allocator: CFAllocatorRef, 67 | name: CFStringRef, 68 | ) -> CFMessagePortRef; 69 | 70 | /* Configuring a CFMessagePort Object */ 71 | pub fn CFMessagePortCreateRunLoopSource( 72 | allocator: CFAllocatorRef, 73 | local: CFMessagePortRef, 74 | order: CFIndex, 75 | ) -> CFRunLoopSourceRef; 76 | pub fn CFMessagePortSetInvalidationCallBack( 77 | ms: CFMessagePortRef, 78 | callout: CFMessagePortInvalidationCallBack, 79 | ); 80 | pub fn CFMessagePortSetName(ms: CFMessagePortRef, newName: CFStringRef) -> Boolean; 81 | 82 | /* Using a Message Port */ 83 | pub fn CFMessagePortInvalidate(ms: CFMessagePortRef); 84 | pub fn CFMessagePortSendRequest( 85 | remote: CFMessagePortRef, 86 | msgid: i32, 87 | data: CFDataRef, 88 | sendTimeout: CFTimeInterval, 89 | rcvTimeout: CFTimeInterval, 90 | replyMode: CFStringRef, 91 | returnData: *mut CFDataRef, 92 | ) -> i32; 93 | //pub fn CFMessagePortSetDispatchQueue(ms: CFMessagePortRef, queue: dispatch_queue_t); 94 | 95 | /* Examining a Message Port */ 96 | pub fn CFMessagePortGetContext(ms: CFMessagePortRef, context: *mut CFMessagePortContext); 97 | pub fn CFMessagePortGetInvalidationCallBack( 98 | ms: CFMessagePortRef, 99 | ) -> CFMessagePortInvalidationCallBack; 100 | pub fn CFMessagePortGetName(ms: CFMessagePortRef) -> CFStringRef; 101 | pub fn CFMessagePortIsRemote(ms: CFMessagePortRef) -> Boolean; 102 | pub fn CFMessagePortIsValid(ms: CFMessagePortRef) -> Boolean; 103 | 104 | /* Getting the CFMessagePort Type ID */ 105 | pub fn CFMessagePortGetTypeID() -> CFTypeID; 106 | } 107 | -------------------------------------------------------------------------------- /core-foundation-sys/src/propertylist.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2013-2015 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 crate::base::{Boolean, CFAllocatorRef, CFIndex, CFOptionFlags, CFTypeRef}; 11 | use crate::data::CFDataRef; 12 | use crate::error::CFErrorRef; 13 | use crate::stream::{CFReadStreamRef, CFWriteStreamRef}; 14 | use crate::string::CFStringRef; 15 | 16 | pub type CFPropertyListRef = CFTypeRef; 17 | 18 | pub type CFPropertyListFormat = CFIndex; 19 | pub const kCFPropertyListOpenStepFormat: CFPropertyListFormat = 1; 20 | pub const kCFPropertyListXMLFormat_v1_0: CFPropertyListFormat = 100; 21 | pub const kCFPropertyListBinaryFormat_v1_0: CFPropertyListFormat = 200; 22 | 23 | pub type CFPropertyListMutabilityOptions = CFOptionFlags; 24 | pub const kCFPropertyListImmutable: CFPropertyListMutabilityOptions = 0; 25 | pub const kCFPropertyListMutableContainers: CFPropertyListMutabilityOptions = 1; 26 | pub const kCFPropertyListMutableContainersAndLeaves: CFPropertyListMutabilityOptions = 2; 27 | 28 | /* Reading and Writing Error Codes */ 29 | pub const kCFPropertyListReadCorruptError: CFIndex = 3840; 30 | pub const kCFPropertyListReadUnknownVersionError: CFIndex = 3841; 31 | pub const kCFPropertyListReadStreamError: CFIndex = 3842; 32 | pub const kCFPropertyListWriteStreamError: CFIndex = 3851; 33 | 34 | extern "C" { 35 | /* 36 | * CFPropertyList.h 37 | */ 38 | 39 | /* Creating a Property List */ 40 | pub fn CFPropertyListCreateWithData( 41 | allocator: CFAllocatorRef, 42 | data: CFDataRef, 43 | options: CFPropertyListMutabilityOptions, 44 | format: *mut CFPropertyListFormat, 45 | error: *mut CFErrorRef, 46 | ) -> CFPropertyListRef; 47 | pub fn CFPropertyListCreateWithStream( 48 | allocator: CFAllocatorRef, 49 | stream: CFReadStreamRef, 50 | streamLength: CFIndex, 51 | options: CFOptionFlags, 52 | format: *mut CFPropertyListFormat, 53 | error: *mut CFErrorRef, 54 | ) -> CFPropertyListRef; 55 | pub fn CFPropertyListCreateDeepCopy( 56 | allocator: CFAllocatorRef, 57 | propertyList: CFPropertyListRef, 58 | mutabilityOption: CFOptionFlags, 59 | ) -> CFPropertyListRef; 60 | pub fn CFPropertyListCreateFromXMLData( 61 | allocator: CFAllocatorRef, 62 | xmlData: CFDataRef, 63 | mutabilityOption: CFOptionFlags, 64 | errorString: *mut CFStringRef, 65 | ) -> CFPropertyListRef; // deprecated 66 | pub fn CFPropertyListCreateFromStream( 67 | allocator: CFAllocatorRef, 68 | stream: CFReadStreamRef, 69 | streamLength: CFIndex, 70 | mutabilityOption: CFOptionFlags, 71 | format: *mut CFPropertyListFormat, 72 | errorString: *mut CFStringRef, 73 | ) -> CFPropertyListRef; // deprecated 74 | 75 | /* Exporting a Property List */ 76 | pub fn CFPropertyListCreateData( 77 | allocator: CFAllocatorRef, 78 | propertyList: CFPropertyListRef, 79 | format: CFPropertyListFormat, 80 | options: CFOptionFlags, 81 | error: *mut CFErrorRef, 82 | ) -> CFDataRef; 83 | pub fn CFPropertyListWrite( 84 | propertyList: CFPropertyListRef, 85 | stream: CFWriteStreamRef, 86 | format: CFPropertyListFormat, 87 | options: CFOptionFlags, 88 | error: *mut CFErrorRef, 89 | ) -> CFIndex; 90 | pub fn CFPropertyListCreateXMLData( 91 | allocator: CFAllocatorRef, 92 | propertyList: CFPropertyListRef, 93 | ) -> CFDataRef; // deprecated 94 | pub fn CFPropertyListWriteToStream( 95 | propertyList: CFPropertyListRef, 96 | stream: CFWriteStreamRef, 97 | format: CFPropertyListFormat, 98 | errorString: *mut CFStringRef, 99 | ) -> CFIndex; 100 | 101 | /* Validating a Property List */ 102 | pub fn CFPropertyListIsValid(plist: CFPropertyListRef, format: CFPropertyListFormat) 103 | -> Boolean; 104 | } 105 | -------------------------------------------------------------------------------- /core-foundation-sys/src/plugin.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 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 core::ffi::c_void; 11 | 12 | use crate::array::CFArrayRef; 13 | use crate::base::{Boolean, CFAllocatorRef, CFIndex, CFTypeID}; 14 | use crate::bundle::{CFBundleRef, CFPlugInRef}; 15 | use crate::string::CFStringRef; 16 | use crate::url::CFURLRef; 17 | use crate::uuid::CFUUIDRef; 18 | 19 | #[repr(C)] 20 | pub struct __CFPlugInInstance(c_void); 21 | pub type CFPlugInInstanceRef = *mut __CFPlugInInstance; 22 | 23 | pub type CFPlugInDynamicRegisterFunction = extern "C" fn(plugIn: CFPlugInRef); 24 | pub type CFPlugInUnloadFunction = extern "C" fn(plugIn: CFPlugInRef); 25 | pub type CFPlugInFactoryFunction = 26 | extern "C" fn(allocator: CFAllocatorRef, typeUUID: CFUUIDRef) -> *mut c_void; 27 | 28 | pub type CFPlugInInstanceGetInterfaceFunction = extern "C" fn( 29 | instance: CFPlugInInstanceRef, 30 | interfaceName: CFStringRef, 31 | ftbl: *mut *mut c_void, 32 | ) -> Boolean; 33 | pub type CFPlugInInstanceDeallocateInstanceDataFunction = extern "C" fn(instanceData: *mut c_void); 34 | 35 | extern "C" { 36 | /* 37 | * CFPlugIn.h 38 | */ 39 | 40 | /* CFPlugIn */ 41 | /* Information Property List Keys */ 42 | pub static kCFPlugInDynamicRegistrationKey: CFStringRef; 43 | pub static kCFPlugInDynamicRegisterFunctionKey: CFStringRef; 44 | pub static kCFPlugInUnloadFunctionKey: CFStringRef; 45 | pub static kCFPlugInFactoriesKey: CFStringRef; 46 | pub static kCFPlugInTypesKey: CFStringRef; 47 | 48 | /* Creating Plug-ins */ 49 | pub fn CFPlugInCreate(allocator: CFAllocatorRef, plugInURL: CFURLRef) -> CFPlugInRef; 50 | pub fn CFPlugInInstanceCreate( 51 | allocator: CFAllocatorRef, 52 | factoryUUID: CFUUIDRef, 53 | typeUUID: CFUUIDRef, 54 | ) -> *mut c_void; 55 | 56 | /* Registration */ 57 | pub fn CFPlugInRegisterFactoryFunction( 58 | factoryUUID: CFUUIDRef, 59 | func: CFPlugInFactoryFunction, 60 | ) -> Boolean; 61 | pub fn CFPlugInRegisterFactoryFunctionByName( 62 | CfactoryUUID: CFUUIDRef, 63 | plugIn: CFPlugInRef, 64 | functionName: CFStringRef, 65 | ) -> Boolean; 66 | pub fn CFPlugInRegisterPlugInType(factoryUUID: CFUUIDRef, typeUUID: CFUUIDRef) -> Boolean; 67 | pub fn CFPlugInUnregisterFactory(factoryUUID: CFUUIDRef) -> Boolean; 68 | pub fn CFPlugInUnregisterPlugInType(factoryUUID: CFUUIDRef, typeUUID: CFUUIDRef) -> Boolean; 69 | 70 | /* CFPlugIn Miscellaneous Functions */ 71 | pub fn CFPlugInAddInstanceForFactory(factoryID: CFUUIDRef); 72 | pub fn CFPlugInFindFactoriesForPlugInType(typeUUID: CFUUIDRef) -> CFArrayRef; 73 | pub fn CFPlugInFindFactoriesForPlugInTypeInPlugIn( 74 | typeUUID: CFUUIDRef, 75 | plugIn: CFPlugInRef, 76 | ) -> CFArrayRef; 77 | pub fn CFPlugInGetBundle(plugIn: CFPlugInRef) -> CFBundleRef; 78 | pub fn CFPlugInGetTypeID() -> CFTypeID; 79 | pub fn CFPlugInIsLoadOnDemand(plugIn: CFPlugInRef) -> Boolean; 80 | pub fn CFPlugInRemoveInstanceForFactory(factoryID: CFUUIDRef); 81 | pub fn CFPlugInSetLoadOnDemand(plugIn: CFPlugInRef, flag: Boolean); 82 | 83 | /* CFPlugInInstance: deprecated */ 84 | pub fn CFPlugInInstanceCreateWithInstanceDataSize( 85 | allocator: CFAllocatorRef, 86 | instanceDataSize: CFIndex, 87 | deallocateInstanceFunction: CFPlugInInstanceDeallocateInstanceDataFunction, 88 | factoryName: CFStringRef, 89 | getInterfaceFunction: CFPlugInInstanceGetInterfaceFunction, 90 | ) -> CFPlugInInstanceRef; 91 | pub fn CFPlugInInstanceGetFactoryName(instance: CFPlugInInstanceRef) -> CFStringRef; 92 | pub fn CFPlugInInstanceGetInstanceData(instance: CFPlugInInstanceRef) -> *mut c_void; 93 | pub fn CFPlugInInstanceGetInterfaceFunctionTable( 94 | instance: CFPlugInInstanceRef, 95 | interfaceName: CFStringRef, 96 | ftbl: *mut *mut c_void, 97 | ) -> Boolean; 98 | pub fn CFPlugInInstanceGetTypeID() -> CFTypeID; 99 | } 100 | -------------------------------------------------------------------------------- /core-text/src/line.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 crate::run::CTRun; 11 | use core_foundation::array::{CFArray, CFArrayRef}; 12 | use core_foundation::attributed_string::CFAttributedStringRef; 13 | use core_foundation::base::{CFIndex, CFRange, CFTypeID, TCFType}; 14 | use core_foundation::{declare_TCFType, impl_CFTypeDescription, impl_TCFType}; 15 | use core_graphics::base::CGFloat; 16 | use core_graphics::context::CGContext; 17 | use core_graphics::geometry::{CGPoint, CGRect}; 18 | use foreign_types::ForeignType; 19 | 20 | #[repr(C)] 21 | pub struct __CTLine(core::ffi::c_void); 22 | 23 | pub type CTLineRef = *const __CTLine; 24 | 25 | declare_TCFType! { 26 | CTLine, CTLineRef 27 | } 28 | impl_TCFType!(CTLine, CTLineRef, CTLineGetTypeID); 29 | impl_CFTypeDescription!(CTLine); 30 | 31 | /// Metrics for a given line. 32 | pub struct TypographicBounds { 33 | pub width: CGFloat, 34 | pub ascent: CGFloat, 35 | pub descent: CGFloat, 36 | pub leading: CGFloat, 37 | } 38 | 39 | impl CTLine { 40 | pub fn new_with_attributed_string(string: CFAttributedStringRef) -> Self { 41 | unsafe { 42 | let ptr = CTLineCreateWithAttributedString(string); 43 | CTLine::wrap_under_create_rule(ptr) 44 | } 45 | } 46 | 47 | pub fn glyph_runs(&self) -> CFArray { 48 | unsafe { TCFType::wrap_under_get_rule(CTLineGetGlyphRuns(self.0)) } 49 | } 50 | 51 | pub fn get_string_range(&self) -> CFRange { 52 | unsafe { CTLineGetStringRange(self.as_concrete_TypeRef()) } 53 | } 54 | 55 | pub fn draw(&self, context: &CGContext) { 56 | unsafe { CTLineDraw(self.as_concrete_TypeRef(), context.as_ptr()) } 57 | } 58 | 59 | pub fn get_image_bounds(&self, context: &CGContext) -> CGRect { 60 | unsafe { CTLineGetImageBounds(self.as_concrete_TypeRef(), context.as_ptr()) } 61 | } 62 | 63 | pub fn get_typographic_bounds(&self) -> TypographicBounds { 64 | let mut ascent = 0.0; 65 | let mut descent = 0.0; 66 | let mut leading = 0.0; 67 | unsafe { 68 | let width = CTLineGetTypographicBounds( 69 | self.as_concrete_TypeRef(), 70 | &mut ascent, 71 | &mut descent, 72 | &mut leading, 73 | ); 74 | TypographicBounds { 75 | width, 76 | ascent, 77 | descent, 78 | leading, 79 | } 80 | } 81 | } 82 | 83 | pub fn get_string_index_for_position(&self, position: CGPoint) -> CFIndex { 84 | unsafe { CTLineGetStringIndexForPosition(self.as_concrete_TypeRef(), position) } 85 | } 86 | 87 | pub fn get_string_offset_for_string_index(&self, charIndex: CFIndex) -> CGFloat { 88 | unsafe { 89 | CTLineGetOffsetForStringIndex(self.as_concrete_TypeRef(), charIndex, std::ptr::null()) 90 | } 91 | } 92 | } 93 | 94 | #[cfg_attr(feature = "link", link(name = "CoreText", kind = "framework"))] 95 | extern "C" { 96 | fn CTLineGetTypeID() -> CFTypeID; 97 | fn CTLineGetGlyphRuns(line: CTLineRef) -> CFArrayRef; 98 | fn CTLineGetStringRange(line: CTLineRef) -> CFRange; 99 | 100 | // Creating Lines 101 | fn CTLineCreateWithAttributedString(string: CFAttributedStringRef) -> CTLineRef; 102 | 103 | // Drawing the Line 104 | fn CTLineDraw(line: CTLineRef, context: *const core_graphics::sys::CGContext); 105 | 106 | // Measuring Lines 107 | fn CTLineGetImageBounds( 108 | line: CTLineRef, 109 | context: *const core_graphics::sys::CGContext, 110 | ) -> CGRect; 111 | fn CTLineGetTypographicBounds( 112 | line: CTLineRef, 113 | ascent: *mut CGFloat, 114 | descent: *mut CGFloat, 115 | leading: *mut CGFloat, 116 | ) -> CGFloat; 117 | 118 | // Getting Line Positioning 119 | fn CTLineGetStringIndexForPosition(line: CTLineRef, position: CGPoint) -> CFIndex; 120 | fn CTLineGetOffsetForStringIndex( 121 | line: CTLineRef, 122 | charIndex: CFIndex, 123 | secondaryOffset: *const CGFloat, 124 | ) -> CGFloat; 125 | } 126 | -------------------------------------------------------------------------------- /core-foundation/src/number.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 | //! Immutable numbers. 11 | 12 | use core::ffi::c_void; 13 | use core_foundation_sys::base::kCFAllocatorDefault; 14 | pub use core_foundation_sys::number::*; 15 | 16 | use crate::base::TCFType; 17 | 18 | declare_TCFType! { 19 | /// An immutable numeric value. 20 | CFNumber, CFNumberRef 21 | } 22 | impl_TCFType!(CFNumber, CFNumberRef, CFNumberGetTypeID); 23 | impl_CFTypeDescription!(CFNumber); 24 | impl_CFComparison!(CFNumber, CFNumberCompare); 25 | 26 | impl CFNumber { 27 | #[inline] 28 | pub fn to_i32(&self) -> Option { 29 | unsafe { 30 | let mut value: i32 = 0; 31 | let ok = CFNumberGetValue( 32 | self.0, 33 | kCFNumberSInt32Type, 34 | &mut value as *mut i32 as *mut c_void, 35 | ); 36 | if ok { 37 | Some(value) 38 | } else { 39 | None 40 | } 41 | } 42 | } 43 | 44 | #[inline] 45 | pub fn to_i64(&self) -> Option { 46 | unsafe { 47 | let mut value: i64 = 0; 48 | let ok = CFNumberGetValue( 49 | self.0, 50 | kCFNumberSInt64Type, 51 | &mut value as *mut i64 as *mut c_void, 52 | ); 53 | if ok { 54 | Some(value) 55 | } else { 56 | None 57 | } 58 | } 59 | } 60 | 61 | #[inline] 62 | pub fn to_f32(&self) -> Option { 63 | unsafe { 64 | let mut value: f32 = 0.0; 65 | let ok = CFNumberGetValue( 66 | self.0, 67 | kCFNumberFloat32Type, 68 | &mut value as *mut f32 as *mut c_void, 69 | ); 70 | if ok { 71 | Some(value) 72 | } else { 73 | None 74 | } 75 | } 76 | } 77 | 78 | #[inline] 79 | pub fn to_f64(&self) -> Option { 80 | unsafe { 81 | let mut value: f64 = 0.0; 82 | let ok = CFNumberGetValue( 83 | self.0, 84 | kCFNumberFloat64Type, 85 | &mut value as *mut f64 as *mut c_void, 86 | ); 87 | if ok { 88 | Some(value) 89 | } else { 90 | None 91 | } 92 | } 93 | } 94 | } 95 | 96 | impl From for CFNumber { 97 | #[inline] 98 | fn from(value: i32) -> Self { 99 | unsafe { 100 | let number_ref = CFNumberCreate( 101 | kCFAllocatorDefault, 102 | kCFNumberSInt32Type, 103 | &value as *const i32 as *const c_void, 104 | ); 105 | TCFType::wrap_under_create_rule(number_ref) 106 | } 107 | } 108 | } 109 | 110 | impl From for CFNumber { 111 | #[inline] 112 | fn from(value: i64) -> Self { 113 | unsafe { 114 | let number_ref = CFNumberCreate( 115 | kCFAllocatorDefault, 116 | kCFNumberSInt64Type, 117 | &value as *const i64 as *const c_void, 118 | ); 119 | TCFType::wrap_under_create_rule(number_ref) 120 | } 121 | } 122 | } 123 | 124 | impl From for CFNumber { 125 | #[inline] 126 | fn from(value: f32) -> Self { 127 | unsafe { 128 | let number_ref = CFNumberCreate( 129 | kCFAllocatorDefault, 130 | kCFNumberFloat32Type, 131 | &value as *const f32 as *const c_void, 132 | ); 133 | TCFType::wrap_under_create_rule(number_ref) 134 | } 135 | } 136 | } 137 | 138 | impl From for CFNumber { 139 | #[inline] 140 | fn from(value: f64) -> Self { 141 | unsafe { 142 | let number_ref = CFNumberCreate( 143 | kCFAllocatorDefault, 144 | kCFNumberFloat64Type, 145 | &value as *const f64 as *const c_void, 146 | ); 147 | TCFType::wrap_under_create_rule(number_ref) 148 | } 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /core-graphics/src/path.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 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 | pub use crate::sys::CGPathRef as SysCGPathRef; 11 | 12 | use crate::geometry::{CGAffineTransform, CGPoint, CGRect}; 13 | use core::ffi::c_void; 14 | use core_foundation::base::{CFRelease, CFRetain, CFTypeID}; 15 | use foreign_types::{foreign_type, ForeignType}; 16 | use std::fmt::{self, Debug, Formatter}; 17 | use std::marker::PhantomData; 18 | use std::ops::Deref; 19 | use std::ptr; 20 | use std::slice; 21 | 22 | foreign_type! { 23 | #[doc(hidden)] 24 | pub unsafe type CGPath { 25 | type CType = crate::sys::CGPath; 26 | fn drop = |p| CFRelease(p as *mut _); 27 | fn clone = |p| CFRetain(p as *const _) as *mut _; 28 | } 29 | } 30 | 31 | impl CGPath { 32 | pub fn from_rect(rect: CGRect, transform: Option<&CGAffineTransform>) -> CGPath { 33 | unsafe { 34 | let transform = match transform { 35 | None => ptr::null(), 36 | Some(transform) => transform as *const CGAffineTransform, 37 | }; 38 | CGPath::from_ptr(CGPathCreateWithRect(rect, transform)) 39 | } 40 | } 41 | 42 | pub fn type_id() -> CFTypeID { 43 | unsafe { CGPathGetTypeID() } 44 | } 45 | 46 | pub fn apply<'a, F>(&'a self, mut closure: &'a F) 47 | where 48 | F: FnMut(CGPathElementRef<'a>), 49 | { 50 | unsafe { 51 | CGPathApply( 52 | self.as_ptr(), 53 | &mut closure as *mut _ as *mut c_void, 54 | do_apply::, 55 | ); 56 | } 57 | 58 | unsafe extern "C" fn do_apply<'a, F>(info: *mut c_void, element: *const CGPathElement) 59 | where 60 | F: FnMut(CGPathElementRef<'a>), 61 | { 62 | let closure = info as *mut *mut F; 63 | (**closure)(CGPathElementRef::new(element)) 64 | } 65 | } 66 | } 67 | 68 | #[repr(i32)] 69 | #[derive(Clone, Copy, Debug, PartialEq)] 70 | pub enum CGPathElementType { 71 | MoveToPoint = 0, 72 | AddLineToPoint = 1, 73 | AddQuadCurveToPoint = 2, 74 | AddCurveToPoint = 3, 75 | CloseSubpath = 4, 76 | } 77 | 78 | pub struct CGPathElementRef<'a> { 79 | element: *const CGPathElement, 80 | phantom: PhantomData<&'a CGPathElement>, 81 | } 82 | 83 | impl CGPathElementRef<'_> { 84 | fn new<'b>(element: *const CGPathElement) -> CGPathElementRef<'b> { 85 | CGPathElementRef { 86 | element, 87 | phantom: PhantomData, 88 | } 89 | } 90 | } 91 | 92 | impl Deref for CGPathElementRef<'_> { 93 | type Target = CGPathElement; 94 | fn deref(&self) -> &CGPathElement { 95 | unsafe { &*self.element } 96 | } 97 | } 98 | 99 | #[repr(C)] 100 | pub struct CGPathElement { 101 | pub element_type: CGPathElementType, 102 | points: *mut CGPoint, 103 | } 104 | 105 | impl Debug for CGPathElement { 106 | fn fmt(&self, formatter: &mut Formatter) -> Result<(), fmt::Error> { 107 | write!(formatter, "{:?}: {:?}", self.element_type, self.points()) 108 | } 109 | } 110 | 111 | impl CGPathElement { 112 | pub fn points(&self) -> &[CGPoint] { 113 | unsafe { 114 | match self.element_type { 115 | CGPathElementType::CloseSubpath => &[], 116 | CGPathElementType::MoveToPoint | CGPathElementType::AddLineToPoint => { 117 | slice::from_raw_parts(self.points, 1) 118 | } 119 | CGPathElementType::AddQuadCurveToPoint => slice::from_raw_parts(self.points, 2), 120 | CGPathElementType::AddCurveToPoint => slice::from_raw_parts(self.points, 3), 121 | } 122 | } 123 | } 124 | } 125 | 126 | type CGPathApplierFunction = unsafe extern "C" fn(info: *mut c_void, element: *const CGPathElement); 127 | 128 | #[cfg_attr(feature = "link", link(name = "CoreGraphics", kind = "framework"))] 129 | extern "C" { 130 | fn CGPathCreateWithRect( 131 | rect: CGRect, 132 | transform: *const CGAffineTransform, 133 | ) -> crate::sys::CGPathRef; 134 | fn CGPathApply(path: crate::sys::CGPathRef, info: *mut c_void, function: CGPathApplierFunction); 135 | fn CGPathGetTypeID() -> CFTypeID; 136 | } 137 | -------------------------------------------------------------------------------- /core-foundation-sys/src/attributed_string.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 crate::base::{Boolean, CFAllocatorRef, CFIndex, CFRange, CFTypeID, CFTypeRef}; 11 | use crate::dictionary::CFDictionaryRef; 12 | use crate::string::CFMutableStringRef; 13 | use crate::string::CFStringRef; 14 | use core::ffi::c_void; 15 | 16 | #[repr(C)] 17 | pub struct __CFAttributedString(c_void); 18 | 19 | pub type CFAttributedStringRef = *const __CFAttributedString; 20 | pub type CFMutableAttributedStringRef = *mut __CFAttributedString; 21 | 22 | extern "C" { 23 | /* 24 | * CFAttributedString.h 25 | */ 26 | 27 | /* CFAttributedString */ 28 | /* Creating a CFAttributedString */ 29 | pub fn CFAttributedStringCreate( 30 | allocator: CFAllocatorRef, 31 | str: CFStringRef, 32 | attributes: CFDictionaryRef, 33 | ) -> CFAttributedStringRef; 34 | pub fn CFAttributedStringCreateCopy( 35 | alloc: CFAllocatorRef, 36 | aStr: CFAttributedStringRef, 37 | ) -> CFAttributedStringRef; 38 | pub fn CFAttributedStringCreateWithSubstring( 39 | alloc: CFAllocatorRef, 40 | aStr: CFAttributedStringRef, 41 | range: CFRange, 42 | ) -> CFAttributedStringRef; 43 | pub fn CFAttributedStringGetLength(astr: CFAttributedStringRef) -> CFIndex; 44 | pub fn CFAttributedStringGetString(aStr: CFAttributedStringRef) -> CFStringRef; 45 | 46 | /* Accessing Attributes */ 47 | pub fn CFAttributedStringGetAttribute( 48 | aStr: CFAttributedStringRef, 49 | loc: CFIndex, 50 | attrName: CFStringRef, 51 | effectiveRange: *mut CFRange, 52 | ) -> CFTypeRef; 53 | pub fn CFAttributedStringGetAttributes( 54 | aStr: CFAttributedStringRef, 55 | loc: CFIndex, 56 | effectiveRange: *mut CFRange, 57 | ) -> CFDictionaryRef; 58 | pub fn CFAttributedStringGetAttributeAndLongestEffectiveRange( 59 | aStr: CFAttributedStringRef, 60 | loc: CFIndex, 61 | attrName: CFStringRef, 62 | inRange: CFRange, 63 | longestEffectiveRange: *mut CFRange, 64 | ) -> CFTypeRef; 65 | pub fn CFAttributedStringGetAttributesAndLongestEffectiveRange( 66 | aStr: CFAttributedStringRef, 67 | loc: CFIndex, 68 | inRange: CFRange, 69 | longestEffectiveRange: *mut CFRange, 70 | ) -> CFDictionaryRef; 71 | 72 | /* Getting Attributed String Properties */ 73 | pub fn CFAttributedStringGetTypeID() -> CFTypeID; 74 | 75 | /* CFMutableAttributedString */ 76 | /* Creating a CFMutableAttributedString */ 77 | pub fn CFAttributedStringCreateMutable( 78 | allocator: CFAllocatorRef, 79 | max_length: CFIndex, 80 | ) -> CFMutableAttributedStringRef; 81 | pub fn CFAttributedStringCreateMutableCopy( 82 | allocator: CFAllocatorRef, 83 | max_length: CFIndex, 84 | astr: CFAttributedStringRef, 85 | ) -> CFMutableAttributedStringRef; 86 | 87 | /* Modifying a CFMutableAttributedString */ 88 | pub fn CFAttributedStringBeginEditing(aStr: CFMutableAttributedStringRef); 89 | pub fn CFAttributedStringEndEditing(aStr: CFMutableAttributedStringRef); 90 | pub fn CFAttributedStringGetMutableString( 91 | aStr: CFMutableAttributedStringRef, 92 | ) -> CFMutableStringRef; 93 | pub fn CFAttributedStringRemoveAttribute( 94 | aStr: CFMutableAttributedStringRef, 95 | range: CFRange, 96 | attrName: CFStringRef, 97 | ); 98 | pub fn CFAttributedStringReplaceString( 99 | aStr: CFMutableAttributedStringRef, 100 | range: CFRange, 101 | replacement: CFStringRef, 102 | ); 103 | pub fn CFAttributedStringReplaceAttributedString( 104 | aStr: CFMutableAttributedStringRef, 105 | range: CFRange, 106 | replacement: CFAttributedStringRef, 107 | ); 108 | pub fn CFAttributedStringSetAttribute( 109 | aStr: CFMutableAttributedStringRef, 110 | range: CFRange, 111 | attrName: CFStringRef, 112 | value: CFTypeRef, 113 | ); 114 | pub fn CFAttributedStringSetAttributes( 115 | aStr: CFMutableAttributedStringRef, 116 | range: CFRange, 117 | replacement: CFDictionaryRef, 118 | clearOtherAttributes: Boolean, 119 | ); 120 | } 121 | -------------------------------------------------------------------------------- /cocoa/examples/fullscreen.rs: -------------------------------------------------------------------------------- 1 | #![allow(deprecated)] // the cocoa crate is deprecated 2 | use cocoa::appkit::{ 3 | NSApp, NSApplication, NSApplicationActivateIgnoringOtherApps, 4 | NSApplicationActivationPolicyRegular, NSApplicationPresentationOptions, NSBackingStoreBuffered, 5 | NSMenu, NSMenuItem, NSRunningApplication, NSWindow, NSWindowCollectionBehavior, 6 | NSWindowStyleMask, 7 | }; 8 | use cocoa::base::{id, nil, selector, NO}; 9 | use cocoa::foundation::{ 10 | NSAutoreleasePool, NSPoint, NSProcessInfo, NSRect, NSSize, NSString, NSUInteger, 11 | }; 12 | 13 | use core_graphics::display::CGDisplay; 14 | 15 | use objc::declare::ClassDecl; 16 | use objc::runtime::{Object, Sel}; 17 | use objc::{class, msg_send, sel, sel_impl}; 18 | 19 | fn main() { 20 | unsafe { 21 | let _pool = NSAutoreleasePool::new(nil); 22 | 23 | let app = NSApp(); 24 | app.setActivationPolicy_(NSApplicationActivationPolicyRegular); 25 | 26 | // create Menu Bar 27 | let menubar = NSMenu::new(nil).autorelease(); 28 | let app_menu_item = NSMenuItem::new(nil).autorelease(); 29 | menubar.addItem_(app_menu_item); 30 | app.setMainMenu_(menubar); 31 | 32 | // create Application menu 33 | let app_menu = NSMenu::new(nil).autorelease(); 34 | let quit_prefix = NSString::alloc(nil).init_str("Quit "); 35 | let quit_title = 36 | quit_prefix.stringByAppendingString_(NSProcessInfo::processInfo(nil).processName()); 37 | let quit_action = selector("terminate:"); 38 | let quit_key = NSString::alloc(nil).init_str("q"); 39 | let quit_item = NSMenuItem::alloc(nil) 40 | .initWithTitle_action_keyEquivalent_(quit_title, quit_action, quit_key) 41 | .autorelease(); 42 | app_menu.addItem_(quit_item); 43 | app_menu_item.setSubmenu_(app_menu); 44 | 45 | // Create NSWindowDelegate 46 | let superclass = class!(NSObject); 47 | let mut decl = ClassDecl::new("MyWindowDelegate", superclass).unwrap(); 48 | 49 | extern "C" fn will_use_fillscreen_presentation_options( 50 | _: &Object, 51 | _: Sel, 52 | _: id, 53 | _: NSUInteger, 54 | ) -> NSUInteger { 55 | // Set initial presentation options for fullscreen 56 | let options = NSApplicationPresentationOptions::NSApplicationPresentationFullScreen 57 | | NSApplicationPresentationOptions::NSApplicationPresentationHideDock 58 | | NSApplicationPresentationOptions::NSApplicationPresentationHideMenuBar 59 | | NSApplicationPresentationOptions::NSApplicationPresentationDisableProcessSwitching; 60 | options.bits() 61 | } 62 | 63 | extern "C" fn window_entering_fullscreen(_: &Object, _: Sel, _: id) { 64 | // Reset HideDock and HideMenuBar settings during/after we entered fullscreen. 65 | let options = NSApplicationPresentationOptions::NSApplicationPresentationHideDock 66 | | NSApplicationPresentationOptions::NSApplicationPresentationHideMenuBar; 67 | unsafe { 68 | NSApp().setPresentationOptions_(options); 69 | } 70 | } 71 | 72 | decl.add_method( 73 | sel!(window:willUseFullScreenPresentationOptions:), 74 | will_use_fillscreen_presentation_options 75 | as extern "C" fn(&Object, Sel, id, NSUInteger) -> NSUInteger, 76 | ); 77 | decl.add_method( 78 | sel!(windowWillEnterFullScreen:), 79 | window_entering_fullscreen as extern "C" fn(&Object, Sel, id), 80 | ); 81 | decl.add_method( 82 | sel!(windowDidEnterFullScreen:), 83 | window_entering_fullscreen as extern "C" fn(&Object, Sel, id), 84 | ); 85 | 86 | let delegate_class = decl.register(); 87 | let delegate_object = msg_send![delegate_class, new]; 88 | 89 | // create Window 90 | let display = CGDisplay::main(); 91 | let size = NSSize::new(display.pixels_wide() as _, display.pixels_high() as _); 92 | let window = NSWindow::alloc(nil) 93 | .initWithContentRect_styleMask_backing_defer_( 94 | NSRect::new(NSPoint::new(0., 0.), size), 95 | NSWindowStyleMask::NSTitledWindowMask, 96 | NSBackingStoreBuffered, 97 | NO, 98 | ) 99 | .autorelease(); 100 | window.setDelegate_(delegate_object); 101 | let title = NSString::alloc(nil).init_str("Fullscreen!"); 102 | window.setTitle_(title); 103 | window.makeKeyAndOrderFront_(nil); 104 | 105 | let current_app = NSRunningApplication::currentApplication(nil); 106 | current_app.activateWithOptions_(NSApplicationActivateIgnoringOtherApps); 107 | window.setCollectionBehavior_( 108 | NSWindowCollectionBehavior::NSWindowCollectionBehaviorFullScreenPrimary, 109 | ); 110 | window.toggleFullScreen_(nil); 111 | app.run(); 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /core-foundation/src/data.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 | //! Core Foundation byte buffers. 11 | 12 | use core_foundation_sys::base::kCFAllocatorDefault; 13 | use core_foundation_sys::base::CFIndex; 14 | pub use core_foundation_sys::data::*; 15 | use std::ops::Deref; 16 | use std::slice; 17 | use std::sync::Arc; 18 | 19 | use crate::base::{CFIndexConvertible, TCFType}; 20 | 21 | declare_TCFType! { 22 | /// A byte buffer. 23 | CFData, CFDataRef 24 | } 25 | impl_TCFType!(CFData, CFDataRef, CFDataGetTypeID); 26 | impl_CFTypeDescription!(CFData); 27 | 28 | impl CFData { 29 | /// Creates a [`CFData`] around a copy `buffer` 30 | pub fn from_buffer(buffer: &[u8]) -> CFData { 31 | unsafe { 32 | let data_ref = CFDataCreate( 33 | kCFAllocatorDefault, 34 | buffer.as_ptr(), 35 | buffer.len().to_CFIndex(), 36 | ); 37 | TCFType::wrap_under_create_rule(data_ref) 38 | } 39 | } 40 | 41 | /// Creates a [`CFData`] referencing `buffer` without creating a copy 42 | pub fn from_arc + Sync + Send>(buffer: Arc) -> Self { 43 | use crate::base::{CFAllocator, CFAllocatorContext}; 44 | use core::ffi::c_void; 45 | 46 | unsafe { 47 | let ptr = (*buffer).as_ref().as_ptr() as *const _; 48 | let len = (*buffer).as_ref().len().to_CFIndex(); 49 | let info = Arc::into_raw(buffer) as *mut c_void; 50 | 51 | extern "C" fn deallocate(_: *mut c_void, info: *mut c_void) { 52 | unsafe { 53 | drop(Arc::from_raw(info as *mut T)); 54 | } 55 | } 56 | 57 | // Use a separate allocator for each allocation because 58 | // we need `info` to do the deallocation vs. `ptr` 59 | let allocator = CFAllocator::new(CFAllocatorContext { 60 | info, 61 | version: 0, 62 | retain: None, 63 | reallocate: None, 64 | release: None, 65 | copyDescription: None, 66 | allocate: None, 67 | deallocate: Some(deallocate::), 68 | preferredSize: None, 69 | }); 70 | let data_ref = CFDataCreateWithBytesNoCopy( 71 | kCFAllocatorDefault, 72 | ptr, 73 | len, 74 | allocator.as_CFTypeRef(), 75 | ); 76 | TCFType::wrap_under_create_rule(data_ref) 77 | } 78 | } 79 | 80 | /// Returns a pointer to the underlying bytes in this data. Note that this byte buffer is 81 | /// read-only. 82 | #[inline] 83 | pub fn bytes(&self) -> &[u8] { 84 | unsafe { 85 | let ptr = CFDataGetBytePtr(self.0); 86 | // Rust slice must never have a NULL pointer 87 | if ptr.is_null() { 88 | return &[]; 89 | } 90 | slice::from_raw_parts(ptr, self.len() as usize) 91 | } 92 | } 93 | 94 | /// Returns the length of this byte buffer. 95 | #[inline] 96 | pub fn len(&self) -> CFIndex { 97 | unsafe { CFDataGetLength(self.0) } 98 | } 99 | 100 | /// Returns `true` if this byte buffer is empty. 101 | #[inline] 102 | pub fn is_empty(&self) -> bool { 103 | self.len() == 0 104 | } 105 | } 106 | 107 | impl Deref for CFData { 108 | type Target = [u8]; 109 | 110 | #[inline] 111 | fn deref(&self) -> &[u8] { 112 | self.bytes() 113 | } 114 | } 115 | 116 | #[cfg(test)] 117 | mod test { 118 | use super::CFData; 119 | use std::sync::Arc; 120 | 121 | #[test] 122 | fn test_data_provider() { 123 | let l = vec![5]; 124 | CFData::from_arc(Arc::new(l)); 125 | 126 | let l = vec![5]; 127 | CFData::from_arc(Arc::new(l.into_boxed_slice())); 128 | 129 | // Make sure the buffer is actually dropped 130 | use std::sync::atomic::{AtomicBool, Ordering::SeqCst}; 131 | struct VecWrapper { 132 | inner: Vec, 133 | dropped: Arc, 134 | } 135 | 136 | impl Drop for VecWrapper { 137 | fn drop(&mut self) { 138 | self.dropped.store(true, SeqCst) 139 | } 140 | } 141 | 142 | impl std::convert::AsRef<[u8]> for VecWrapper { 143 | fn as_ref(&self) -> &[u8] { 144 | &self.inner 145 | } 146 | } 147 | 148 | let dropped = Arc::new(AtomicBool::default()); 149 | let l = Arc::new(VecWrapper { 150 | inner: vec![5], 151 | dropped: dropped.clone(), 152 | }); 153 | let m = l.clone(); 154 | let dp = CFData::from_arc(l); 155 | drop(m); 156 | assert!(!dropped.load(SeqCst)); 157 | drop(dp); 158 | assert!(dropped.load(SeqCst)) 159 | } 160 | } 161 | -------------------------------------------------------------------------------- /core-foundation-sys/src/array.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2013-2015 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 core::ffi::c_void; 11 | 12 | use crate::base::{Boolean, CFAllocatorRef, CFComparatorFunction, CFIndex, CFRange, CFTypeID}; 13 | use crate::string::CFStringRef; 14 | 15 | pub type CFArrayRetainCallBack = 16 | extern "C" fn(allocator: CFAllocatorRef, value: *const c_void) -> *const c_void; 17 | pub type CFArrayReleaseCallBack = extern "C" fn(allocator: CFAllocatorRef, value: *const c_void); 18 | pub type CFArrayCopyDescriptionCallBack = extern "C" fn(value: *const c_void) -> CFStringRef; 19 | pub type CFArrayEqualCallBack = 20 | extern "C" fn(value1: *const c_void, value2: *const c_void) -> Boolean; 21 | pub type CFArrayApplierFunction = extern "C" fn(value: *const c_void, context: *mut c_void); 22 | 23 | #[repr(C)] 24 | #[derive(Clone, Copy, Debug)] 25 | pub struct CFArrayCallBacks { 26 | pub version: CFIndex, 27 | pub retain: CFArrayRetainCallBack, 28 | pub release: CFArrayReleaseCallBack, 29 | pub copyDescription: CFArrayCopyDescriptionCallBack, 30 | pub equal: CFArrayEqualCallBack, 31 | } 32 | 33 | #[repr(C)] 34 | pub struct __CFArray(c_void); 35 | 36 | pub type CFArrayRef = *const __CFArray; 37 | pub type CFMutableArrayRef = *mut __CFArray; 38 | 39 | extern "C" { 40 | /* 41 | * CFArray.h 42 | */ 43 | 44 | pub static kCFTypeArrayCallBacks: CFArrayCallBacks; 45 | 46 | /* CFArray */ 47 | /* Creating an Array */ 48 | pub fn CFArrayCreate( 49 | allocator: CFAllocatorRef, 50 | values: *const *const c_void, 51 | numValues: CFIndex, 52 | callBacks: *const CFArrayCallBacks, 53 | ) -> CFArrayRef; 54 | pub fn CFArrayCreateCopy(allocator: CFAllocatorRef, theArray: CFArrayRef) -> CFArrayRef; 55 | 56 | /* Examining an Array */ 57 | pub fn CFArrayBSearchValues( 58 | theArray: CFArrayRef, 59 | range: CFRange, 60 | value: *const c_void, 61 | comparator: CFComparatorFunction, 62 | context: *mut c_void, 63 | ) -> CFIndex; 64 | pub fn CFArrayContainsValue( 65 | theArray: CFArrayRef, 66 | range: CFRange, 67 | value: *const c_void, 68 | ) -> Boolean; 69 | pub fn CFArrayGetCount(theArray: CFArrayRef) -> CFIndex; 70 | pub fn CFArrayGetCountOfValue( 71 | theArray: CFArrayRef, 72 | range: CFRange, 73 | value: *const c_void, 74 | ) -> CFIndex; 75 | pub fn CFArrayGetFirstIndexOfValue( 76 | theArray: CFArrayRef, 77 | range: CFRange, 78 | value: *const c_void, 79 | ) -> CFIndex; 80 | pub fn CFArrayGetLastIndexOfValue( 81 | theArray: CFArrayRef, 82 | range: CFRange, 83 | value: *const c_void, 84 | ) -> CFIndex; 85 | pub fn CFArrayGetValues(theArray: CFArrayRef, range: CFRange, values: *mut *const c_void); 86 | pub fn CFArrayGetValueAtIndex(theArray: CFArrayRef, idx: CFIndex) -> *const c_void; 87 | 88 | /* Applying a Function to Elements */ 89 | pub fn CFArrayApplyFunction( 90 | theArray: CFArrayRef, 91 | range: CFRange, 92 | applier: CFArrayApplierFunction, 93 | context: *mut c_void, 94 | ); 95 | 96 | /* Getting the CFArray Type ID */ 97 | pub fn CFArrayGetTypeID() -> CFTypeID; 98 | 99 | /* CFMutableArray */ 100 | /* CFMutableArray Miscellaneous Functions */ 101 | pub fn CFArrayAppendArray( 102 | theArray: CFMutableArrayRef, 103 | otherArray: CFArrayRef, 104 | otherRange: CFRange, 105 | ); 106 | pub fn CFArrayAppendValue(theArray: CFMutableArrayRef, value: *const c_void); 107 | pub fn CFArrayCreateMutable( 108 | allocator: CFAllocatorRef, 109 | capacity: CFIndex, 110 | callBacks: *const CFArrayCallBacks, 111 | ) -> CFMutableArrayRef; 112 | pub fn CFArrayCreateMutableCopy( 113 | allocator: CFAllocatorRef, 114 | capacity: CFIndex, 115 | theArray: CFArrayRef, 116 | ) -> CFMutableArrayRef; 117 | pub fn CFArrayExchangeValuesAtIndices( 118 | theArray: CFMutableArrayRef, 119 | idx1: CFIndex, 120 | idx2: CFIndex, 121 | ); 122 | pub fn CFArrayInsertValueAtIndex( 123 | theArray: CFMutableArrayRef, 124 | idx: CFIndex, 125 | value: *const c_void, 126 | ); 127 | pub fn CFArrayRemoveAllValues(theArray: CFMutableArrayRef); 128 | pub fn CFArrayRemoveValueAtIndex(theArray: CFMutableArrayRef, idx: CFIndex); 129 | pub fn CFArrayReplaceValues( 130 | theArray: CFMutableArrayRef, 131 | range: CFRange, 132 | newValues: *mut *const c_void, 133 | newCount: CFIndex, 134 | ); 135 | pub fn CFArraySetValueAtIndex(theArray: CFMutableArrayRef, idx: CFIndex, value: *const c_void); 136 | pub fn CFArraySortValues( 137 | theArray: CFMutableArrayRef, 138 | range: CFRange, 139 | comparator: CFComparatorFunction, 140 | context: *mut c_void, 141 | ); 142 | } 143 | -------------------------------------------------------------------------------- /core-foundation-sys/src/xml_node.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 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 core::ffi::{c_char, c_void}; 11 | 12 | use crate::array::CFArrayRef; 13 | use crate::base::{Boolean, CFAllocatorRef, CFIndex, CFTypeID}; 14 | use crate::dictionary::CFDictionaryRef; 15 | use crate::string::{CFStringEncoding, CFStringRef}; 16 | use crate::tree::CFTreeRef; 17 | use crate::url::CFURLRef; 18 | 19 | #[repr(C)] 20 | pub struct __CFXMLNode(c_void); 21 | 22 | pub type CFXMLNodeRef = *mut __CFXMLNode; 23 | pub type CFXMLTreeRef = CFTreeRef; 24 | 25 | pub const kCFXMLNodeCurrentVersion: CFIndex = 1; 26 | 27 | pub type CFXMLNodeTypeCode = CFIndex; 28 | pub const kCFXMLNodeTypeDocument: CFXMLNodeTypeCode = 1; 29 | pub const kCFXMLNodeTypeElement: CFXMLNodeTypeCode = 2; 30 | pub const kCFXMLNodeTypeAttribute: CFXMLNodeTypeCode = 3; 31 | pub const kCFXMLNodeTypeProcessingInstruction: CFXMLNodeTypeCode = 4; 32 | pub const kCFXMLNodeTypeComment: CFXMLNodeTypeCode = 5; 33 | pub const kCFXMLNodeTypeText: CFXMLNodeTypeCode = 6; 34 | pub const kCFXMLNodeTypeCDATASection: CFXMLNodeTypeCode = 7; 35 | pub const kCFXMLNodeTypeDocumentFragment: CFXMLNodeTypeCode = 8; 36 | pub const kCFXMLNodeTypeEntity: CFXMLNodeTypeCode = 9; 37 | pub const kCFXMLNodeTypeEntityReference: CFXMLNodeTypeCode = 10; 38 | pub const kCFXMLNodeTypeDocumentType: CFXMLNodeTypeCode = 11; 39 | pub const kCFXMLNodeTypeWhitespace: CFXMLNodeTypeCode = 12; 40 | pub const kCFXMLNodeTypeNotation: CFXMLNodeTypeCode = 13; 41 | pub const kCFXMLNodeTypeElementTypeDeclaration: CFXMLNodeTypeCode = 14; 42 | pub const kCFXMLNodeTypeAttributeListDeclaration: CFXMLNodeTypeCode = 15; 43 | 44 | #[repr(C)] 45 | #[derive(Debug, Clone, Copy)] 46 | pub struct CFXMLElementInfo { 47 | pub attributes: CFDictionaryRef, 48 | pub attributeOrder: CFArrayRef, 49 | pub isEmpty: Boolean, 50 | pub _reserved: [c_char; 3], 51 | } 52 | 53 | #[repr(C)] 54 | #[derive(Debug, Clone, Copy)] 55 | pub struct CFXMLProcessingInstructionInfo { 56 | pub dataString: CFStringRef, 57 | } 58 | 59 | #[repr(C)] 60 | #[derive(Debug, Clone, Copy)] 61 | pub struct CFXMLDocumentInfo { 62 | pub sourceURL: CFURLRef, 63 | pub encoding: CFStringEncoding, 64 | } 65 | 66 | #[repr(C)] 67 | #[derive(Debug, Clone, Copy)] 68 | pub struct CFXMLExternalID { 69 | pub systemID: CFURLRef, 70 | pub publicID: CFStringRef, 71 | } 72 | 73 | #[repr(C)] 74 | #[derive(Debug, Clone, Copy)] 75 | pub struct CFXMLDocumentTypeInfo { 76 | pub externalID: CFXMLExternalID, 77 | } 78 | 79 | #[repr(C)] 80 | #[derive(Debug, Clone, Copy)] 81 | pub struct CFXMLNotationInfo { 82 | pub externalID: CFXMLExternalID, 83 | } 84 | 85 | #[repr(C)] 86 | #[derive(Debug, Clone, Copy)] 87 | pub struct CFXMLElementTypeDeclarationInfo { 88 | pub contentDescription: CFStringRef, 89 | } 90 | 91 | #[repr(C)] 92 | #[derive(Debug, Clone, Copy)] 93 | pub struct CFXMLAttributeDeclarationInfo { 94 | pub attributeName: CFStringRef, 95 | pub typeString: CFStringRef, 96 | pub defaultString: CFStringRef, 97 | } 98 | 99 | #[repr(C)] 100 | #[derive(Debug, Clone, Copy)] 101 | pub struct CFXMLAttributeListDeclarationInfo { 102 | pub numberOfAttributes: CFIndex, 103 | pub attributes: *mut CFXMLAttributeDeclarationInfo, 104 | } 105 | 106 | pub type CFXMLEntityTypeCode = CFIndex; 107 | pub const kCFXMLEntityTypeParameter: CFXMLEntityTypeCode = 0; 108 | pub const kCFXMLEntityTypeParsedInternal: CFXMLEntityTypeCode = 1; 109 | pub const kCFXMLEntityTypeParsedExternal: CFXMLEntityTypeCode = 2; 110 | pub const kCFXMLEntityTypeUnparsed: CFXMLEntityTypeCode = 3; 111 | pub const kCFXMLEntityTypeCharacter: CFXMLEntityTypeCode = 4; 112 | 113 | #[repr(C)] 114 | #[derive(Debug, Clone, Copy)] 115 | pub struct CFXMLEntityInfo { 116 | pub entityType: CFXMLEntityTypeCode, 117 | pub replacementText: CFStringRef, 118 | pub entityID: CFXMLExternalID, 119 | pub notationName: CFStringRef, 120 | } 121 | 122 | #[repr(C)] 123 | #[derive(Debug, Clone, Copy)] 124 | pub struct CFXMLEntityReferenceInfo { 125 | pub entityType: CFXMLEntityTypeCode, 126 | } 127 | 128 | extern "C" { 129 | /* 130 | * CFXMLNode.h 131 | */ 132 | pub fn CFXMLNodeGetTypeID() -> CFTypeID; 133 | pub fn CFXMLNodeCreate( 134 | alloc: CFAllocatorRef, 135 | xmlType: CFXMLNodeTypeCode, 136 | dataString: CFStringRef, 137 | additionalInfoPtr: *const c_void, 138 | version: CFIndex, 139 | ) -> CFXMLNodeRef; 140 | pub fn CFXMLNodeCreateCopy(alloc: CFAllocatorRef, origNode: CFXMLNodeRef) -> CFXMLNodeRef; 141 | pub fn CFXMLNodeGetTypeCode(node: CFXMLNodeRef) -> CFXMLNodeTypeCode; 142 | pub fn CFXMLNodeGetString(node: CFXMLNodeRef) -> CFStringRef; 143 | pub fn CFXMLNodeGetInfoPtr(node: CFXMLNodeRef) -> *const c_void; 144 | pub fn CFXMLNodeGetVersion(node: CFXMLNodeRef) -> CFIndex; 145 | pub fn CFXMLTreeCreateWithNode(alloc: CFAllocatorRef, node: CFXMLNodeRef) -> CFXMLTreeRef; 146 | pub fn CFXMLTreeGetNode(xmlTree: CFXMLTreeRef) -> CFXMLNodeRef; 147 | } 148 | -------------------------------------------------------------------------------- /core-foundation-sys/src/characterset.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2019 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 crate::base::{Boolean, CFAllocatorRef, CFIndex, CFRange, CFTypeID, UTF32Char}; 11 | use crate::data::CFDataRef; 12 | use crate::string::{CFStringRef, UniChar}; 13 | use core::ffi::c_void; 14 | 15 | pub type CFCharacterSetPredefinedSet = CFIndex; 16 | 17 | // Members of CFCharacterSetPredefinedSet enum 18 | pub static kCFCharacterSetControl: CFCharacterSetPredefinedSet = 1; 19 | pub static kCFCharacterSetWhitespace: CFCharacterSetPredefinedSet = 2; 20 | pub static kCFCharacterSetWhitespaceAndNewline: CFCharacterSetPredefinedSet = 3; 21 | pub static kCFCharacterSetDecimalDigit: CFCharacterSetPredefinedSet = 4; 22 | pub static kCFCharacterSetLetter: CFCharacterSetPredefinedSet = 5; 23 | pub static kCFCharacterSetLowercaseLetter: CFCharacterSetPredefinedSet = 6; 24 | pub static kCFCharacterSetUppercaseLetter: CFCharacterSetPredefinedSet = 7; 25 | pub static kCFCharacterSetNonBase: CFCharacterSetPredefinedSet = 8; 26 | pub static kCFCharacterSetDecomposable: CFCharacterSetPredefinedSet = 9; 27 | pub static kCFCharacterSetAlphaNumeric: CFCharacterSetPredefinedSet = 10; 28 | pub static kCFCharacterSetPunctuation: CFCharacterSetPredefinedSet = 11; 29 | pub static kCFCharacterSetIllegal: CFCharacterSetPredefinedSet = 12; 30 | pub static kCFCharacterSetCapitalizedLetter: CFCharacterSetPredefinedSet = 13; 31 | pub static kCFCharacterSetSymbol: CFCharacterSetPredefinedSet = 14; 32 | pub static kCFCharacterSetNewline: CFCharacterSetPredefinedSet = 15; 33 | 34 | #[repr(C)] 35 | pub struct __CFCharacterSet(c_void); 36 | 37 | pub type CFCharacterSetRef = *const __CFCharacterSet; 38 | pub type CFMutableCharacterSetRef = *mut __CFCharacterSet; 39 | 40 | extern "C" { 41 | /* 42 | * CFCharacterSet.h 43 | */ 44 | 45 | /* CFCharacterSet */ 46 | /* Creating Character Sets */ 47 | pub fn CFCharacterSetCreateCopy( 48 | alloc: CFAllocatorRef, 49 | theSet: CFCharacterSetRef, 50 | ) -> CFCharacterSetRef; 51 | pub fn CFCharacterSetCreateInvertedSet( 52 | alloc: CFAllocatorRef, 53 | theSet: CFCharacterSetRef, 54 | ) -> CFCharacterSetRef; 55 | pub fn CFCharacterSetCreateWithCharactersInRange( 56 | alloc: CFAllocatorRef, 57 | theRange: CFRange, 58 | ) -> CFCharacterSetRef; 59 | pub fn CFCharacterSetCreateWithCharactersInString( 60 | alloc: CFAllocatorRef, 61 | theString: CFStringRef, 62 | ) -> CFCharacterSetRef; 63 | pub fn CFCharacterSetCreateWithBitmapRepresentation( 64 | alloc: CFAllocatorRef, 65 | theData: CFDataRef, 66 | ) -> CFCharacterSetRef; 67 | 68 | /* Getting Predefined Character Sets */ 69 | pub fn CFCharacterSetGetPredefined( 70 | theSetIdentifier: CFCharacterSetPredefinedSet, 71 | ) -> CFCharacterSetRef; 72 | 73 | /* Querying Character Sets */ 74 | pub fn CFCharacterSetCreateBitmapRepresentation( 75 | alloc: CFAllocatorRef, 76 | theSet: CFCharacterSetRef, 77 | ) -> CFDataRef; 78 | pub fn CFCharacterSetHasMemberInPlane(theSet: CFCharacterSetRef, thePlane: CFIndex) -> Boolean; 79 | pub fn CFCharacterSetIsCharacterMember(theSet: CFCharacterSetRef, theChar: UniChar) -> Boolean; 80 | pub fn CFCharacterSetIsLongCharacterMember( 81 | theSet: CFCharacterSetRef, 82 | theChar: UTF32Char, 83 | ) -> Boolean; 84 | pub fn CFCharacterSetIsSupersetOfSet( 85 | theSet: CFCharacterSetRef, 86 | theOtherset: CFCharacterSetRef, 87 | ) -> Boolean; 88 | 89 | /* Getting the Character Set Type Identifier */ 90 | pub fn CFCharacterSetGetTypeID() -> CFTypeID; 91 | 92 | /* CFMutableCharacterSet */ 93 | /* Creating a Mutable Character Set */ 94 | pub fn CFCharacterSetCreateMutable(alloc: CFAllocatorRef) -> CFMutableCharacterSetRef; 95 | pub fn CFCharacterSetCreateMutableCopy( 96 | alloc: CFAllocatorRef, 97 | theSet: CFCharacterSetRef, 98 | ) -> CFMutableCharacterSetRef; 99 | 100 | /* Adding Characters */ 101 | pub fn CFCharacterSetAddCharactersInRange(theSet: CFMutableCharacterSetRef, theRange: CFRange); 102 | pub fn CFCharacterSetAddCharactersInString( 103 | theSet: CFMutableCharacterSetRef, 104 | theString: CFStringRef, 105 | ); 106 | 107 | /* Removing Characters */ 108 | pub fn CFCharacterSetRemoveCharactersInRange( 109 | theSet: CFMutableCharacterSetRef, 110 | theRange: CFRange, 111 | ); 112 | pub fn CFCharacterSetRemoveCharactersInString( 113 | theSet: CFMutableCharacterSetRef, 114 | theString: CFStringRef, 115 | ); 116 | 117 | /* Logical Operations */ 118 | pub fn CFCharacterSetIntersect( 119 | theSet: CFMutableCharacterSetRef, 120 | theOtherSet: CFCharacterSetRef, 121 | ); 122 | pub fn CFCharacterSetInvert(theSet: CFMutableCharacterSetRef); 123 | pub fn CFCharacterSetUnion(theSet: CFMutableCharacterSetRef, theOtherSet: CFCharacterSetRef); 124 | } 125 | -------------------------------------------------------------------------------- /core-foundation-sys/src/calendar.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 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 core::ffi::{c_char, c_void}; 11 | 12 | use crate::base::{Boolean, CFAllocatorRef, CFIndex, CFOptionFlags, CFRange, CFTypeID}; 13 | use crate::date::{CFAbsoluteTime, CFTimeInterval}; 14 | use crate::locale::{CFCalendarIdentifier, CFLocaleRef}; 15 | use crate::timezone::CFTimeZoneRef; 16 | 17 | #[repr(C)] 18 | pub struct __CFCalendar(c_void); 19 | pub type CFCalendarRef = *mut __CFCalendar; 20 | 21 | pub type CFCalendarUnit = CFOptionFlags; 22 | pub const kCFCalendarUnitEra: CFCalendarUnit = 1 << 1; 23 | pub const kCFCalendarUnitYear: CFCalendarUnit = 1 << 2; 24 | pub const kCFCalendarUnitMonth: CFCalendarUnit = 1 << 3; 25 | pub const kCFCalendarUnitDay: CFCalendarUnit = 1 << 4; 26 | pub const kCFCalendarUnitHour: CFCalendarUnit = 1 << 5; 27 | pub const kCFCalendarUnitMinute: CFCalendarUnit = 1 << 6; 28 | pub const kCFCalendarUnitSecond: CFCalendarUnit = 1 << 7; 29 | pub const kCFCalendarUnitWeek: CFCalendarUnit = 1 << 8; // deprecated since macos 10.10 30 | pub const kCFCalendarUnitWeekday: CFCalendarUnit = 1 << 9; 31 | pub const kCFCalendarUnitWeekdayOrdinal: CFCalendarUnit = 1 << 10; 32 | pub const kCFCalendarUnitQuarter: CFCalendarUnit = 1 << 11; 33 | pub const kCFCalendarUnitWeekOfMonth: CFCalendarUnit = 1 << 12; 34 | pub const kCFCalendarUnitWeekOfYear: CFCalendarUnit = 1 << 13; 35 | pub const kCFCalendarUnitYearForWeekOfYear: CFCalendarUnit = 1 << 14; 36 | 37 | pub const kCFCalendarComponentsWrap: CFOptionFlags = 1 << 0; 38 | 39 | extern "C" { 40 | /* 41 | * CFCalendar.h 42 | */ 43 | 44 | /* Creating a Calendar */ 45 | pub fn CFCalendarCopyCurrent() -> CFCalendarRef; 46 | pub fn CFCalendarCreateWithIdentifier( 47 | allocator: CFAllocatorRef, 48 | identifier: CFCalendarIdentifier, 49 | ) -> CFCalendarRef; 50 | 51 | /* Calendrical Calculations */ 52 | pub fn CFCalendarAddComponents( 53 | identifier: CFCalendarIdentifier, 54 | /* inout */ at: *mut CFAbsoluteTime, 55 | options: CFOptionFlags, 56 | componentDesc: *const char, 57 | ... 58 | ) -> Boolean; 59 | pub fn CFCalendarComposeAbsoluteTime( 60 | identifier: CFCalendarIdentifier, 61 | /* out */ at: *mut CFAbsoluteTime, 62 | componentDesc: *const c_char, 63 | ... 64 | ) -> Boolean; 65 | pub fn CFCalendarDecomposeAbsoluteTime( 66 | identifier: CFCalendarIdentifier, 67 | at: CFAbsoluteTime, 68 | componentDesc: *const c_char, 69 | ... 70 | ) -> Boolean; 71 | pub fn CFCalendarGetComponentDifference( 72 | identifier: CFCalendarIdentifier, 73 | startingAT: CFAbsoluteTime, 74 | resultAT: CFAbsoluteTime, 75 | options: CFOptionFlags, 76 | componentDesc: *const c_char, 77 | ... 78 | ) -> Boolean; 79 | 80 | /* Getting Ranges of Units */ 81 | pub fn CFCalendarGetRangeOfUnit( 82 | identifier: CFCalendarIdentifier, 83 | smallerUnit: CFCalendarUnit, 84 | biggerUnit: CFCalendarUnit, 85 | at: CFAbsoluteTime, 86 | ) -> CFRange; 87 | pub fn CFCalendarGetOrdinalityOfUnit( 88 | identifier: CFCalendarIdentifier, 89 | smallerUnit: CFCalendarUnit, 90 | biggerUnit: CFCalendarUnit, 91 | at: CFAbsoluteTime, 92 | ) -> CFIndex; 93 | pub fn CFCalendarGetTimeRangeOfUnit( 94 | identifier: CFCalendarIdentifier, 95 | unit: CFCalendarUnit, 96 | at: CFAbsoluteTime, 97 | startp: *mut CFAbsoluteTime, 98 | tip: *mut CFTimeInterval, 99 | ) -> Boolean; 100 | pub fn CFCalendarGetMaximumRangeOfUnit( 101 | identifier: CFCalendarIdentifier, 102 | unit: CFCalendarUnit, 103 | ) -> CFRange; 104 | pub fn CFCalendarGetMinimumRangeOfUnit( 105 | identifier: CFCalendarIdentifier, 106 | unit: CFCalendarUnit, 107 | ) -> CFRange; 108 | 109 | /* Getting and Setting the Time Zone */ 110 | pub fn CFCalendarCopyTimeZone(identifier: CFCalendarIdentifier) -> CFTimeZoneRef; 111 | pub fn CFCalendarSetTimeZone(identifier: CFCalendarIdentifier, tz: CFTimeZoneRef); 112 | 113 | /* Getting the Identifier */ 114 | pub fn CFCalendarGetIdentifier(identifier: CFCalendarIdentifier) -> CFCalendarIdentifier; 115 | 116 | /* Getting and Setting the Locale */ 117 | pub fn CFCalendarCopyLocale(identifier: CFCalendarIdentifier) -> CFLocaleRef; 118 | pub fn CFCalendarSetLocale(identifier: CFCalendarIdentifier, locale: CFLocaleRef); 119 | 120 | /* Getting and Setting Day Information */ 121 | pub fn CFCalendarGetFirstWeekday(identifier: CFCalendarIdentifier) -> CFIndex; 122 | pub fn CFCalendarSetFirstWeekday(identifier: CFCalendarIdentifier, wkdy: CFIndex); 123 | pub fn CFCalendarGetMinimumDaysInFirstWeek(identifier: CFCalendarIdentifier) -> CFIndex; 124 | pub fn CFCalendarSetMinimumDaysInFirstWeek(identifier: CFCalendarIdentifier, mwd: CFIndex); 125 | 126 | /* Getting the Type ID */ 127 | pub fn CFCalendarGetTypeID() -> CFTypeID; 128 | } 129 | -------------------------------------------------------------------------------- /core-graphics/src/color_space.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 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 core_foundation::base::{CFRelease, CFRetain, CFTypeID}; 11 | use core_foundation::string::CFStringRef; 12 | use foreign_types::{foreign_type, ForeignType}; 13 | 14 | foreign_type! { 15 | #[doc(hidden)] 16 | pub unsafe type CGColorSpace { 17 | type CType = crate::sys::CGColorSpace; 18 | fn drop = |p| CFRelease(p as *mut _); 19 | fn clone = |p| CFRetain(p as *const _) as *mut _; 20 | } 21 | } 22 | 23 | impl CGColorSpace { 24 | pub fn type_id() -> CFTypeID { 25 | unsafe { CGColorSpaceGetTypeID() } 26 | } 27 | 28 | pub fn create_with_name(name: CFStringRef) -> Option { 29 | unsafe { 30 | let p = CGColorSpaceCreateWithName(name); 31 | if !p.is_null() { 32 | Some(CGColorSpace::from_ptr(p)) 33 | } else { 34 | None 35 | } 36 | } 37 | } 38 | 39 | #[inline] 40 | pub fn create_device_rgb() -> CGColorSpace { 41 | unsafe { 42 | let result = CGColorSpaceCreateDeviceRGB(); 43 | CGColorSpace::from_ptr(result) 44 | } 45 | } 46 | 47 | #[inline] 48 | pub fn create_device_gray() -> CGColorSpace { 49 | unsafe { 50 | let result = CGColorSpaceCreateDeviceGray(); 51 | CGColorSpace::from_ptr(result) 52 | } 53 | } 54 | } 55 | 56 | #[cfg_attr(feature = "link", link(name = "CoreGraphics", kind = "framework"))] 57 | extern "C" { 58 | /// The Display P3 color space, created by Apple. 59 | pub static kCGColorSpaceDisplayP3: CFStringRef; 60 | /// The Display P3 color space, using the HLG transfer function. 61 | pub static kCGColorSpaceDisplayP3_HLG: CFStringRef; 62 | /// The Display P3 color space with a linear transfer function 63 | /// and extended-range values. 64 | pub static kCGColorSpaceExtendedLinearDisplayP3: CFStringRef; 65 | /// The standard Red Green Blue (sRGB) color space. 66 | pub static kCGColorSpaceSRGB: CFStringRef; 67 | /// The sRGB color space with a linear transfer function. 68 | pub static kCGColorSpaceLinearSRGB: CFStringRef; 69 | /// The extended sRGB color space. 70 | pub static kCGColorSpaceExtendedSRGB: CFStringRef; 71 | /// The sRGB color space with a linear transfer function and 72 | /// extended-range values. 73 | pub static kCGColorSpaceExtendedLinearSRGB: CFStringRef; 74 | /// The generic gray color space that has an exponential transfer 75 | /// function with a power of 2.2. 76 | pub static kCGColorSpaceGenericGrayGamma2_2: CFStringRef; 77 | /// The gray color space using a linear transfer function. 78 | pub static kCGColorSpaceLinearGray: CFStringRef; 79 | /// The extended gray color space. 80 | pub static kCGColorSpaceExtendedGray: CFStringRef; 81 | /// The extended gray color space with a linear transfer function. 82 | pub static kCGColorSpaceExtendedLinearGray: CFStringRef; 83 | /// The generic RGB color space with a linear transfer function. 84 | pub static kCGColorSpaceGenericRGBLinear: CFStringRef; 85 | /// The generic CMYK color space. 86 | pub static kCGColorSpaceGenericCMYK: CFStringRef; 87 | /// The XYZ color space, as defined by the CIE 1931 standard. 88 | pub static kCGColorSpaceGenericXYZ: CFStringRef; 89 | /// The generic LAB color space. 90 | pub static kCGColorSpaceGenericLab: CFStringRef; 91 | /// The ACEScg color space. 92 | pub static kCGColorSpaceACESCGLinear: CFStringRef; 93 | /// The Adobe RGB (1998) color space. 94 | pub static kCGColorSpaceAdobeRGB1998: CFStringRef; 95 | /// The DCI P3 color space, which is the digital cinema standard. 96 | pub static kCGColorSpaceDCIP3: CFStringRef; 97 | /// The recommendation of the International Telecommunication Union 98 | /// (ITU) Radiocommunication sector for the BT.709 color space. 99 | pub static kCGColorSpaceITUR_709: CFStringRef; 100 | /// The Reference Output Medium Metric (ROMM) RGB color space. 101 | pub static kCGColorSpaceROMMRGB: CFStringRef; 102 | /// The recommendation of the International Telecommunication Union 103 | /// (ITU) Radiocommunication sector for the BT.2020 color space. 104 | pub static kCGColorSpaceITUR_2020: CFStringRef; 105 | /// The recommendation of the International Telecommunication Union 106 | /// (ITU) Radiocommunication sector for the BT.2020 color space, with 107 | /// a linear transfer function and extended range values. 108 | pub static kCGColorSpaceExtendedLinearITUR_2020: CFStringRef; 109 | /// The name of the generic RGB color space. 110 | pub static kCGColorSpaceGenericRGB: CFStringRef; 111 | /// The name of the generic gray color space. 112 | pub static kCGColorSpaceGenericGray: CFStringRef; 113 | 114 | fn CGColorSpaceCreateDeviceRGB() -> crate::sys::CGColorSpaceRef; 115 | fn CGColorSpaceCreateDeviceGray() -> crate::sys::CGColorSpaceRef; 116 | fn CGColorSpaceCreateWithName(name: CFStringRef) -> crate::sys::CGColorSpaceRef; 117 | fn CGColorSpaceGetTypeID() -> CFTypeID; 118 | } 119 | -------------------------------------------------------------------------------- /core-foundation-sys/src/dictionary.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2013-2015 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 core::ffi::c_void; 11 | 12 | use crate::base::{Boolean, CFAllocatorRef, CFHashCode, CFIndex, CFTypeID}; 13 | use crate::string::CFStringRef; 14 | 15 | pub type CFDictionaryApplierFunction = 16 | extern "C" fn(key: *const c_void, value: *const c_void, context: *mut c_void); 17 | 18 | pub type CFDictionaryRetainCallBack = 19 | extern "C" fn(allocator: CFAllocatorRef, value: *const c_void) -> *const c_void; 20 | pub type CFDictionaryReleaseCallBack = 21 | extern "C" fn(allocator: CFAllocatorRef, value: *const c_void); 22 | pub type CFDictionaryCopyDescriptionCallBack = extern "C" fn(value: *const c_void) -> CFStringRef; 23 | pub type CFDictionaryEqualCallBack = 24 | extern "C" fn(value1: *const c_void, value2: *const c_void) -> Boolean; 25 | pub type CFDictionaryHashCallBack = extern "C" fn(value: *const c_void) -> CFHashCode; 26 | 27 | #[repr(C)] 28 | #[derive(Clone, Copy)] 29 | pub struct CFDictionaryKeyCallBacks { 30 | pub version: CFIndex, 31 | pub retain: CFDictionaryRetainCallBack, 32 | pub release: CFDictionaryReleaseCallBack, 33 | pub copyDescription: CFDictionaryCopyDescriptionCallBack, 34 | pub equal: CFDictionaryEqualCallBack, 35 | pub hash: CFDictionaryHashCallBack, 36 | } 37 | 38 | #[repr(C)] 39 | #[derive(Clone, Copy)] 40 | pub struct CFDictionaryValueCallBacks { 41 | pub version: CFIndex, 42 | pub retain: CFDictionaryRetainCallBack, 43 | pub release: CFDictionaryReleaseCallBack, 44 | pub copyDescription: CFDictionaryCopyDescriptionCallBack, 45 | pub equal: CFDictionaryEqualCallBack, 46 | } 47 | 48 | #[repr(C)] 49 | pub struct __CFDictionary(c_void); 50 | 51 | pub type CFDictionaryRef = *const __CFDictionary; 52 | pub type CFMutableDictionaryRef = *mut __CFDictionary; 53 | 54 | extern "C" { 55 | /* 56 | * CFDictionary.h 57 | */ 58 | 59 | pub static kCFTypeDictionaryKeyCallBacks: CFDictionaryKeyCallBacks; 60 | pub static kCFCopyStringDictionaryKeyCallBacks: CFDictionaryKeyCallBacks; 61 | pub static kCFTypeDictionaryValueCallBacks: CFDictionaryValueCallBacks; 62 | 63 | /* CFDictionary */ 64 | /* Creating a dictionary */ 65 | pub fn CFDictionaryCreate( 66 | allocator: CFAllocatorRef, 67 | keys: *const *const c_void, 68 | values: *const *const c_void, 69 | numValues: CFIndex, 70 | keyCallBacks: *const CFDictionaryKeyCallBacks, 71 | valueCallBacks: *const CFDictionaryValueCallBacks, 72 | ) -> CFDictionaryRef; 73 | pub fn CFDictionaryCreateCopy( 74 | allocator: CFAllocatorRef, 75 | theDict: CFDictionaryRef, 76 | ) -> CFDictionaryRef; 77 | 78 | /* Examining a dictionary */ 79 | pub fn CFDictionaryContainsKey(theDict: CFDictionaryRef, key: *const c_void) -> Boolean; 80 | pub fn CFDictionaryContainsValue(theDict: CFDictionaryRef, value: *const c_void) -> Boolean; 81 | pub fn CFDictionaryGetCount(theDict: CFDictionaryRef) -> CFIndex; 82 | pub fn CFDictionaryGetCountOfKey(theDict: CFDictionaryRef, key: *const c_void) -> CFIndex; 83 | pub fn CFDictionaryGetCountOfValue(heDict: CFDictionaryRef, value: *const c_void) -> CFIndex; 84 | pub fn CFDictionaryGetKeysAndValues( 85 | theDict: CFDictionaryRef, 86 | keys: *mut *const c_void, 87 | values: *mut *const c_void, 88 | ); 89 | pub fn CFDictionaryGetValue(theDict: CFDictionaryRef, key: *const c_void) -> *const c_void; 90 | pub fn CFDictionaryGetValueIfPresent( 91 | theDict: CFDictionaryRef, 92 | key: *const c_void, 93 | value: *mut *const c_void, 94 | ) -> Boolean; 95 | 96 | /* Applying a function to a dictionary */ 97 | pub fn CFDictionaryApplyFunction( 98 | theDict: CFDictionaryRef, 99 | applier: CFDictionaryApplierFunction, 100 | context: *mut c_void, 101 | ); 102 | 103 | /* Getting the CFDictionary type ID */ 104 | pub fn CFDictionaryGetTypeID() -> CFTypeID; 105 | 106 | /* CFMutableDictionary */ 107 | /* Creating a Mutable Dictionary */ 108 | pub fn CFDictionaryCreateMutable( 109 | allocator: CFAllocatorRef, 110 | capacity: CFIndex, 111 | keyCallbacks: *const CFDictionaryKeyCallBacks, 112 | valueCallbacks: *const CFDictionaryValueCallBacks, 113 | ) -> CFMutableDictionaryRef; 114 | pub fn CFDictionaryCreateMutableCopy( 115 | allocator: CFAllocatorRef, 116 | capacity: CFIndex, 117 | theDict: CFDictionaryRef, 118 | ) -> CFMutableDictionaryRef; 119 | 120 | /* Modifying a Dictionary */ 121 | pub fn CFDictionaryAddValue( 122 | theDict: CFMutableDictionaryRef, 123 | key: *const c_void, 124 | value: *const c_void, 125 | ); 126 | pub fn CFDictionaryRemoveAllValues(theDict: CFMutableDictionaryRef); 127 | pub fn CFDictionaryRemoveValue(theDict: CFMutableDictionaryRef, key: *const c_void); 128 | pub fn CFDictionaryReplaceValue( 129 | theDict: CFMutableDictionaryRef, 130 | key: *const c_void, 131 | value: *const c_void, 132 | ); 133 | pub fn CFDictionarySetValue( 134 | theDict: CFMutableDictionaryRef, 135 | key: *const c_void, 136 | value: *const c_void, 137 | ); 138 | 139 | } 140 | --------------------------------------------------------------------------------