diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index 766677bb..e68bc142 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -189,10 +189,13 @@ impl View { /// so on. It returns a generic `View`, which the caller can then customize as needed. pub(crate) fn init(view: id) -> View { unsafe { - let _: () = msg_send![view, setTranslatesAutoresizingMaskIntoConstraints:NO]; + let _: () = msg_send![ + view, + setTranslatesAutoresizingMaskIntoConstraints: false, + ]; #[cfg(target_os = "macos")] - let _: () = msg_send![view, setWantsLayer:YES]; + let _: () = msg_send![view, setWantsLayer: true]; } View { diff --git a/src/appkit/app/mod.rs b/src/appkit/app/mod.rs index a266d925..ea058d3e 100644 --- a/src/appkit/app/mod.rs +++ b/src/appkit/app/mod.rs @@ -44,7 +44,7 @@ use objc::runtime::Object; use objc::{class, msg_send, msg_send_id, sel}; use crate::appkit::menu::Menu; -use crate::foundation::{id, nil, AutoReleasePool, NSUInteger, NO, YES}; +use crate::foundation::{id, nil, AutoReleasePool, NSUInteger}; use crate::invoker::TargetActionHandler; use crate::notification_center::Dispatcher; use crate::utils::activate_cocoa_multithreading; @@ -246,10 +246,7 @@ impl App { /// from your trait implementation of `should_terminate()`. pub fn reply_to_termination_request(should_terminate: bool) { shared_application(|app| unsafe { - let _: () = msg_send![app, replyToApplicationShouldTerminate:match should_terminate { - true => YES, - false => NO - }]; + let _: () = msg_send![app, replyToApplicationShouldTerminate: should_terminate]; }); } diff --git a/src/appkit/cursor.rs b/src/appkit/cursor.rs index 2a161f30..ba966a1d 100644 --- a/src/appkit/cursor.rs +++ b/src/appkit/cursor.rs @@ -1,6 +1,6 @@ use objc::{class, msg_send, sel}; -use crate::foundation::{id, NO, YES}; +use crate::foundation::id; /// Represents a type of cursor that you can associate with mouse movement. /// @TODO: Loading? @@ -163,10 +163,7 @@ impl Cursor { /// Trying to invert this with `unhide` will result in undefined system behavior. pub fn set_hidden_until_mouse_moves(status: bool) { unsafe { - let _: () = msg_send![class!(NSCursor), setHiddenUntilMouseMoves:match status { - true => YES, - false => NO - }]; + let _: () = msg_send![class!(NSCursor), setHiddenUntilMouseMoves: status]; } } } diff --git a/src/appkit/segmentedcontrol.rs b/src/appkit/segmentedcontrol.rs index 4b3488c6..c729a80e 100644 --- a/src/appkit/segmentedcontrol.rs +++ b/src/appkit/segmentedcontrol.rs @@ -8,12 +8,12 @@ use std::rc::Rc; use objc::declare::ClassDecl; use objc::rc::{Id, Shared}; -use objc::runtime::{Class, Object, Sel}; +use objc::runtime::{Bool, Class, Object, Sel}; use objc::{class, msg_send, msg_send_id, sel}; use crate::color::Color; use crate::control::Control; -use crate::foundation::{id, nil, NSArray, NSString, NSUInteger, BOOL, NO, YES}; +use crate::foundation::{id, nil, NSArray, NSString, NSUInteger}; use crate::image::Image; use crate::invoker::TargetActionHandler; use crate::keys::Key; @@ -120,10 +120,10 @@ impl SegmentedControl { action:nil ]; - let _: () = msg_send![control, setWantsLayer: YES]; + let _: () = msg_send![control, setWantsLayer: true]; #[cfg(feature = "autolayout")] - let _: () = msg_send![control, setTranslatesAutoresizingMaskIntoConstraints: NO]; + let _: () = msg_send![control, setTranslatesAutoresizingMaskIntoConstraints: false]; control }; @@ -253,10 +253,7 @@ impl SegmentedControl { #[cfg(feature = "appkit")] pub fn set_bordered(&self, is_bordered: bool) { self.objc.with_mut(|obj| unsafe { - let _: () = msg_send![obj, setBordered:match is_bordered { - true => YES, - false => NO - }]; + let _: () = msg_send![obj, setBordered: is_bordered]; }); } @@ -284,10 +281,7 @@ impl SegmentedControl { /// Toggles the highlighted status of the button. pub fn set_highlighted(&self, highlight: bool) { self.objc.with_mut(|obj| unsafe { - let _: () = msg_send![obj, highlight:match highlight { - true => YES, - false => NO - }]; + let _: () = msg_send![obj, highlight: highlight]; }); } } diff --git a/src/appkit/toolbar/item.rs b/src/appkit/toolbar/item.rs index 80498977..96b547ab 100644 --- a/src/appkit/toolbar/item.rs +++ b/src/appkit/toolbar/item.rs @@ -12,7 +12,7 @@ use objc::{class, msg_send, msg_send_id, sel}; use crate::appkit::segmentedcontrol::SegmentedControl; use crate::button::{BezelStyle, Button}; -use crate::foundation::{id, NSString, NO, YES}; +use crate::foundation::{id, NSString}; use crate::image::Image; use crate::invoker::TargetActionHandler; @@ -110,10 +110,7 @@ impl ToolbarItem { pub fn set_bordered(&self, bordered: bool) { unsafe { - let _: () = msg_send![&*self.objc, setBordered:match bordered { - true => YES, - false => NO - }]; + let _: () = msg_send![&*self.objc, setBordered: bordered]; } } } diff --git a/src/appkit/toolbar/mod.rs b/src/appkit/toolbar/mod.rs index ada8614a..2d85225b 100644 --- a/src/appkit/toolbar/mod.rs +++ b/src/appkit/toolbar/mod.rs @@ -9,7 +9,7 @@ use objc::rc::{Id, Owned, Shared}; use objc::runtime::Object; use objc::{class, msg_send, msg_send_id, sel}; -use crate::foundation::{id, nil, NSString, NSUInteger, NO, YES}; +use crate::foundation::{id, nil, NSString, NSUInteger}; mod class; use class::register_toolbar_class; @@ -88,10 +88,7 @@ impl Toolbar { /// contents. pub fn set_shows_baseline_separator(&self, shows: bool) { unsafe { - let _: () = msg_send![&*self.objc, setShowsBaselineSeparator:match shows { - true => YES, - false => NO - }]; + let _: () = msg_send![&*self.objc, setShowsBaselineSeparator: shows]; } } @@ -116,10 +113,7 @@ impl Toolbar { /// Set whether the toolbar is visible or not. pub fn set_visible(&self, visibility: bool) { unsafe { - let _: () = msg_send![&*self.objc, setVisible:match visibility { - true => YES, - false => NO - }]; + let _: () = msg_send![&*self.objc, setVisible: visibility]; } } diff --git a/src/appkit/window/mod.rs b/src/appkit/window/mod.rs index b71274ad..45d1f396 100644 --- a/src/appkit/window/mod.rs +++ b/src/appkit/window/mod.rs @@ -17,7 +17,7 @@ use objc::{class, msg_send, msg_send_id, sel}; use crate::appkit::toolbar::{Toolbar, ToolbarDelegate}; use crate::color::Color; -use crate::foundation::{id, nil, to_bool, NSInteger, NSString, NSUInteger, NO, YES}; +use crate::foundation::{id, nil, NSInteger, NSString, NSUInteger}; use crate::layout::Layout; use crate::objc_access::ObjcAccess; use crate::utils::{os, Controller}; @@ -66,9 +66,9 @@ impl Window { /// after we initialize the backing `NSWindow`. pub fn new(config: WindowConfig) -> Window { let objc = unsafe { - // This behavior might make sense to keep as default (YES), but I think the majority of + // This behavior might make sense to keep as default (true), but I think the majority of // apps that would use this toolkit wouldn't be tab-oriented... - let _: () = msg_send![class!(NSWindow), setAllowsAutomaticWindowTabbing: NO]; + let _: () = msg_send![class!(NSWindow), setAllowsAutomaticWindowTabbing: false]; // Other types of backing (Retained/NonRetained) are archaic, dating back to the // NeXTSTEP era, and are outright deprecated... so we don't allow setting them. @@ -79,19 +79,16 @@ impl Window { initWithContentRect: dimensions, styleMask: config.style, backing: buffered, - defer: match config.defer { - true => YES, - false => NO - }, + defer: config.defer, ]; // This is very important! NSWindow is an old class and has some behavior that we need // to disable, like... this. If we don't set this, we'll segfault entirely because the // Objective-C runtime gets out of sync by releasing the window out from underneath of // us. - let _: () = msg_send![&*window, setReleasedWhenClosed: NO]; + let _: () = msg_send![&*window, setReleasedWhenClosed: false]; - let _: () = msg_send![&*window, setRestorable: NO]; + let _: () = msg_send![&*window, setRestorable: false]; // This doesn't exist prior to Big Sur, but is important to support for Big Sur. // @@ -131,9 +128,9 @@ where let mut delegate = Box::new(delegate); let objc: Id = unsafe { - // This behavior might make sense to keep as default (YES), but I think the majority of + // This behavior might make sense to keep as default (true), but I think the majority of // apps that would use this toolkit wouldn't be tab-oriented... - let _: () = msg_send![class!(NSWindow), setAllowsAutomaticWindowTabbing: NO]; + let _: () = msg_send![class!(NSWindow), setAllowsAutomaticWindowTabbing: false]; // Other types of backing (Retained/NonRetained) are archaic, dating back to the // NeXTSTEP era, and are outright deprecated... so we don't allow setting them. @@ -144,10 +141,7 @@ where initWithContentRect: dimensions, styleMask: config.style, backing: buffered, - defer: match config.defer { - true => YES, - false => NO - }, + defer: config.defer, ]; let delegate_ptr: *const T = &*delegate; @@ -157,12 +151,12 @@ where // to disable, like... this. If we don't set this, we'll segfault entirely because the // Objective-C runtime gets out of sync by releasing the window out from underneath of // us. - let _: () = msg_send![&*window, setReleasedWhenClosed: NO]; + let _: () = msg_send![&*window, setReleasedWhenClosed: false]; // We set the window to be its own delegate - this is cleaned up inside `Drop`. let _: () = msg_send![&*window, setDelegate: &*window]; - let _: () = msg_send![&*window, setRestorable: NO]; + let _: () = msg_send![&*window, setRestorable: false]; // This doesn't exist prior to Big Sur, but is important to support for Big Sur. // @@ -225,20 +219,14 @@ impl Window { /// Used for configuring whether the window is movable via the background. pub fn set_movable_by_background(&self, movable: bool) { unsafe { - let _: () = msg_send![&*self.objc, setMovableByWindowBackground:match movable { - true => YES, - false => NO - }]; + let _: () = msg_send![&*self.objc, setMovableByWindowBackground: movable]; } } /// Used for setting whether this titlebar appears transparent. pub fn set_titlebar_appears_transparent(&self, transparent: bool) { unsafe { - let _: () = msg_send![&*self.objc, setTitlebarAppearsTransparent:match transparent { - true => YES, - false => NO - }]; + let _: () = msg_send![&*self.objc, setTitlebarAppearsTransparent: transparent]; } } @@ -314,10 +302,7 @@ impl Window { /// window. pub fn set_shows_toolbar_button(&self, shows: bool) { unsafe { - let _: () = msg_send![&*self.objc, setShowsToolbarButton:match shows { - true => YES, - false => NO - }]; + let _: () = msg_send![&*self.objc, setShowsToolbarButton: shows]; } } @@ -377,12 +362,12 @@ impl Window { /// Returns whether this window is opaque or not. pub fn is_opaque(&self) -> bool { - to_bool(unsafe { msg_send![&*self.objc, isOpaque] }) + unsafe { msg_send![&*self.objc, isOpaque] } } /// Returns whether this window is miniaturized or not. pub fn is_miniaturized(&self) -> bool { - to_bool(unsafe { msg_send![&*self.objc, isMiniaturized] }) + unsafe { msg_send![&*self.objc, isMiniaturized] } } /// Miniaturize this window. @@ -411,27 +396,27 @@ impl Window { /// /// From Apple's documentation: /// - /// _The value of this property is YES if the window is on the currently active space; otherwise, NO. + /// _The value of this property is `true` if the window is on the currently active space; otherwise, `false`. /// For visible windows, this property indicates whether the window is currently visible on the active /// space. For nonvisible windows, it indicates whether ordering the window onscreen would cause it to /// be on the active space._ pub fn is_on_active_space(&self) -> bool { - to_bool(unsafe { msg_send![&*self.objc, isOnActiveSpace] }) + unsafe { msg_send![&*self.objc, isOnActiveSpace] } } /// Returns whether this window is visible or not. pub fn is_visible(&self) -> bool { - to_bool(unsafe { msg_send![&*self.objc, isVisible] }) + unsafe { msg_send![&*self.objc, isVisible] } } /// Returns whether this window is the key or not. pub fn is_key(&self) -> bool { - to_bool(unsafe { msg_send![&*self.objc, isKeyWindow] }) + unsafe { msg_send![&*self.objc, isKeyWindow] } } /// Returns whether this window can become the key window. pub fn can_become_key(&self) -> bool { - to_bool(unsafe { msg_send![&*self.objc, canBecomeKeyWindow] }) + unsafe { msg_send![&*self.objc, canBecomeKeyWindow] } } /// Make this window the key window. @@ -451,21 +436,18 @@ impl Window { /// Returns if this is the main window or not. pub fn is_main_window(&self) -> bool { - to_bool(unsafe { msg_send![&*self.objc, isMainWindow] }) + unsafe { msg_send![&*self.objc, isMainWindow] } } /// Returns if this can become the main window. pub fn can_become_main_window(&self) -> bool { - to_bool(unsafe { msg_send![&*self.objc, canBecomeMainWindow] }) + unsafe { msg_send![&*self.objc, canBecomeMainWindow] } } /// Set whether this window should be excluded from the top-level "Windows" menu. pub fn set_excluded_from_windows_menu(&self, excluded: bool) { unsafe { - let _: () = msg_send![&*self.objc, setExcludedFromWindowsMenu:match excluded { - true => YES, - false => NO - }]; + let _: () = msg_send![&*self.objc, setExcludedFromWindowsMenu: excluded]; } } diff --git a/src/bundle.rs b/src/bundle.rs index 78bac9e5..ca8cc8f8 100644 --- a/src/bundle.rs +++ b/src/bundle.rs @@ -15,7 +15,7 @@ use objc::ffi; use objc::runtime::{Class, Imp, Object, Sel}; use objc::{class, msg_send, sel, Encode, EncodeArguments, Encoding, Message}; -use crate::foundation::{id, nil, BOOL, YES, NSString}; +use crate::foundation::{id, nil, NSString}; /// Types that can be used as the implementation of an Objective-C method. pub trait MethodImplementation { @@ -56,8 +56,8 @@ extern "C" fn get_bundle_id(this: &Object, s: Sel, v: id) -> id { unsafe { let bundle = class!(NSBundle); let main_bundle: id = msg_send![bundle, mainBundle]; - let e: BOOL = msg_send![this, isEqual:main_bundle]; - if e == YES { + let e = msg_send![this, isEqual:main_bundle]; + if e { let url: id = msg_send![main_bundle, bundleURL]; let x: id = msg_send![url, absoluteString]; println!("Got here? {:?}", x); diff --git a/src/button/mod.rs b/src/button/mod.rs index 1c3bd434..792b3002 100644 --- a/src/button/mod.rs +++ b/src/button/mod.rs @@ -31,7 +31,7 @@ pub use enums::*; use crate::appkit::FocusRingType; use crate::color::Color; use crate::control::Control; -use crate::foundation::{id, load_or_register_class, nil, NSString, NSUInteger, NO, YES}; +use crate::foundation::{id, load_or_register_class, nil, NSString, NSUInteger}; use crate::image::Image; use crate::invoker::TargetActionHandler; use crate::keys::Key; @@ -129,10 +129,10 @@ impl Button { action:nil ]; - let _: () = msg_send![button, setWantsLayer: YES]; + let _: () = msg_send![button, setWantsLayer: true]; #[cfg(feature = "autolayout")] - let _: () = msg_send![button, setTranslatesAutoresizingMaskIntoConstraints: NO]; + let _: () = msg_send![button, setTranslatesAutoresizingMaskIntoConstraints: false]; button }; @@ -271,10 +271,7 @@ impl Button { #[cfg(feature = "appkit")] pub fn set_bordered(&self, is_bordered: bool) { self.objc.with_mut(|obj| unsafe { - let _: () = msg_send![obj, setBordered:match is_bordered { - true => YES, - false => NO - }]; + let _: () = msg_send![obj, setBordered: is_bordered]; }); } @@ -302,10 +299,7 @@ impl Button { /// Toggles the highlighted status of the button. pub fn set_highlighted(&self, highlight: bool) { self.objc.with_mut(|obj| unsafe { - let _: () = msg_send![obj, highlight:match highlight { - true => YES, - false => NO - }]; + let _: () = msg_send![obj, highlight: highlight]; }); } } diff --git a/src/control/mod.rs b/src/control/mod.rs index 8691011c..c9c941a7 100644 --- a/src/control/mod.rs +++ b/src/control/mod.rs @@ -1,7 +1,7 @@ use objc::runtime::Object; use objc::{class, msg_send, sel}; -use crate::foundation::{id, NSUInteger, NO, YES}; +use crate::foundation::{id, NSUInteger}; use crate::objc_access::ObjcAccess; /// Use this enum for specifying NSControl size types. @@ -28,10 +28,7 @@ pub trait Control: ObjcAccess { /// Whether this control is enabled or not. fn set_enabled(&self, is_enabled: bool) { self.with_backing_obj_mut(|obj| unsafe { - let _: () = msg_send![obj, setEnabled:match is_enabled { - true => YES, - false => NO - }]; + let _: () = msg_send![obj, setEnabled: is_enabled]; }); } diff --git a/src/defaults/mod.rs b/src/defaults/mod.rs index e8fee70c..1d2fe59b 100644 --- a/src/defaults/mod.rs +++ b/src/defaults/mod.rs @@ -38,7 +38,7 @@ use objc::rc::{Id, Owned}; use objc::runtime::Object; use objc::{class, msg_send, msg_send_id, sel}; -use crate::foundation::{id, nil, to_bool, NSData, NSMutableDictionary, NSNumber, NSString, BOOL, NO, YES}; +use crate::foundation::{id, nil, NSData, NSMutableDictionary, NSNumber, NSString}; mod value; pub use value::Value; @@ -195,7 +195,7 @@ impl UserDefaults { // `NSInteger` (platform specific) and `double` (f64) respectively, but conceivably we // might need others. // - // BOOL returns as "c", which... something makes me feel weird there, but testing it seems + // Bool returns as "c", which... something makes me feel weird there, but testing it seems // reliable. // // For context: https://nshipster.com/type-encodings/ @@ -236,12 +236,10 @@ impl UserDefaults { /// assert_eq!(value, false); /// ``` pub fn is_forced_for_key>(&self, key: K) -> bool { - let result: BOOL = unsafe { + unsafe { let key = NSString::new(key.as_ref()); msg_send![&*self.0, objectIsForcedForKey:&*key] - }; - - to_bool(result) + } } /// Blocks for any asynchronous updates to the defaults database and returns. diff --git a/src/filesystem/manager.rs b/src/filesystem/manager.rs index e5e5893f..f11b5b8f 100644 --- a/src/filesystem/manager.rs +++ b/src/filesystem/manager.rs @@ -5,13 +5,13 @@ use std::error::Error; use std::sync::{Arc, RwLock}; use objc::rc::{Id, Owned}; -use objc::runtime::{Object, BOOL}; +use objc::runtime::Object; use objc::{class, msg_send, msg_send_id, sel}; use url::Url; use crate::error::Error as AppKitError; use crate::filesystem::enums::{SearchPathDirectory, SearchPathDomainMask}; -use crate::foundation::{id, nil, NSString, NSUInteger, NO}; +use crate::foundation::{id, nil, NSString, NSUInteger}; /// A FileManager can be used for file operations (moving files, etc). /// @@ -47,11 +47,14 @@ impl FileManager { let directory = unsafe { let manager = self.0.read().unwrap(); - let dir: id = msg_send![&**manager, URLForDirectory:dir - inDomain:mask - appropriateForURL:nil - create:NO - error:nil]; + let dir: id = msg_send![ + &**manager, + URLForDirectory: dir, + inDomain: mask, + appropriateForURL: nil, + create: false, + error: nil, + ]; NSString::retain(msg_send![dir, absoluteString]) }; @@ -75,8 +78,8 @@ impl FileManager { let manager = self.0.read().unwrap(); let error: id = nil; - let result: BOOL = msg_send![&**manager, moveItemAtURL:from_url toURL:to_url error:&error]; - if result == NO { + let result = msg_send![&**manager, moveItemAtURL:from_url toURL:to_url error:&error]; + if result { return Err(AppKitError::new(error).into()); } } diff --git a/src/filesystem/save.rs b/src/filesystem/save.rs index 869e59b7..e2a52c71 100644 --- a/src/filesystem/save.rs +++ b/src/filesystem/save.rs @@ -8,7 +8,7 @@ use objc::rc::{Id, Shared}; use objc::runtime::Object; use objc::{class, msg_send, msg_send_id, sel}; -use crate::foundation::{id, nil, NSInteger, NSString, NO, YES}; +use crate::foundation::{id, nil, NSInteger, NSString}; #[derive(Debug)] pub struct FileSavePanel { @@ -67,10 +67,7 @@ impl FileSavePanel { /// Sets whether directories can be created by the user. pub fn set_can_create_directories(&mut self, can_create: bool) { unsafe { - let _: () = msg_send![&*self.panel, setCanCreateDirectories:match can_create { - true => YES, - false => NO - }]; + let _: () = msg_send![&*self.panel, setCanCreateDirectories: can_create]; } self.can_create_directories = can_create; diff --git a/src/filesystem/select.rs b/src/filesystem/select.rs index b30fc51c..3fef7f71 100644 --- a/src/filesystem/select.rs +++ b/src/filesystem/select.rs @@ -11,7 +11,7 @@ use objc::runtime::Object; use objc::{class, msg_send, msg_send_id, sel}; use crate::filesystem::enums::ModalResponse; -use crate::foundation::{id, nil, NSInteger, NSString, NO, NSURL, YES}; +use crate::foundation::{id, nil, NSInteger, NSString, NSURL}; #[cfg(feature = "appkit")] use crate::appkit::window::{Window, WindowDelegate}; @@ -71,10 +71,7 @@ impl FileSelectPanel { /// Sets whether files can be chosen by the user. pub fn set_can_choose_files(&mut self, can_choose: bool) { unsafe { - let _: () = msg_send![&*self.panel, setCanChooseFiles:match can_choose { - true => YES, - false => NO - }]; + let _: () = msg_send![&*self.panel, setCanChooseFiles: can_choose]; } self.can_choose_files = can_choose; @@ -91,10 +88,7 @@ impl FileSelectPanel { /// Sets whether the user can choose directories. pub fn set_can_choose_directories(&mut self, can_choose: bool) { unsafe { - let _: () = msg_send![&*self.panel, setCanChooseDirectories:match can_choose { - true => YES, - false => NO - }]; + let _: () = msg_send![&*self.panel, setCanChooseDirectories: can_choose]; } self.can_choose_directories = can_choose; @@ -103,10 +97,7 @@ impl FileSelectPanel { /// Sets whether the panel resolves aliases. pub fn set_resolves_aliases(&mut self, resolves: bool) { unsafe { - let _: () = msg_send![&*self.panel, setResolvesAliases:match resolves { - true => YES, - false => NO - }]; + let _: () = msg_send![&*self.panel, setResolvesAliases: resolves]; } self.resolves_aliases = resolves; @@ -115,10 +106,7 @@ impl FileSelectPanel { /// Sets whether the panel allows multiple selections. pub fn set_allows_multiple_selection(&mut self, allows: bool) { unsafe { - let _: () = msg_send![&*self.panel, setAllowsMultipleSelection:match allows { - true => YES, - false => NO - }]; + let _: () = msg_send![&*self.panel, setAllowsMultipleSelection: allows]; } self.allows_multiple_selection = allows; diff --git a/src/foundation/data.rs b/src/foundation/data.rs index 48bd145b..55e7637b 100644 --- a/src/foundation/data.rs +++ b/src/foundation/data.rs @@ -9,7 +9,7 @@ use objc::rc::{Id, Owned}; use objc::runtime::Object; use objc::{class, msg_send, msg_send_id, sel}; -use crate::foundation::{id, to_bool, NSUInteger, BOOL, NO, YES}; +use crate::foundation::{id, NSUInteger}; /// Wrapper for a retained `NSData` object. /// @@ -79,9 +79,7 @@ impl NSData { /// A helper method for determining if a given `NSObject` is an `NSData`. pub fn is(obj: id) -> bool { - let result: BOOL = unsafe { msg_send![obj, isKindOfClass: class!(NSData)] }; - - to_bool(result) + unsafe { msg_send![obj, isKindOfClass: class!(NSData)] } } /// Returns the length of the underlying `NSData` bytes. diff --git a/src/foundation/mod.rs b/src/foundation/mod.rs index e1012551..8459cfdc 100644 --- a/src/foundation/mod.rs +++ b/src/foundation/mod.rs @@ -19,7 +19,6 @@ #![allow(non_upper_case_globals)] use objc::runtime; -pub use objc::runtime::{BOOL, NO, YES}; mod autoreleasepool; pub use autoreleasepool::AutoReleasePool; @@ -47,22 +46,6 @@ pub use string::NSString; mod urls; pub use urls::{NSURLBookmarkCreationOption, NSURLBookmarkResolutionOption, NSURL}; -/// Bool mapping types differ between ARM and x64. There's a number of places that we need to check -/// against BOOL results throughout the framework, and this just simplifies some mismatches. -#[inline(always)] -pub fn to_bool(result: BOOL) -> bool { - match result { - YES => true, - NO => false, - - //#[cfg(target_arch = "aarch64")] - #[cfg(not(target_arch = "aarch64"))] - _ => { - std::unreachable!(); - } - } -} - /// More or less maps over to Objective-C's `id` type, which... can really be anything. #[allow(non_camel_case_types)] pub type id = *mut runtime::Object; diff --git a/src/foundation/number.rs b/src/foundation/number.rs index ce980395..45cd861d 100644 --- a/src/foundation/number.rs +++ b/src/foundation/number.rs @@ -5,7 +5,7 @@ use objc::rc::{Id, Owned}; use objc::runtime::Object; use objc::{class, msg_send, msg_send_id, sel}; -use crate::foundation::{id, to_bool, NSInteger, BOOL, NO, YES}; +use crate::foundation::{id, NSInteger}; /// Wrapper for a `NSNumber` object. /// @@ -23,12 +23,7 @@ impl NSNumber { /// Constructs a `numberWithBool` instance of `NSNumber` and retains it. pub fn bool(value: bool) -> Self { - NSNumber(unsafe { - msg_send_id![class!(NSNumber), numberWithBool:match value { - true => YES, - false => NO - }] - }) + NSNumber(unsafe { msg_send_id![class!(NSNumber), numberWithBool: value] }) } /// Constructs a `numberWithInteger` instance of `NSNumber` and retains it. @@ -73,20 +68,16 @@ impl NSNumber { unsafe { msg_send![&*self.0, doubleValue] } } - /// Pulls the underlying `BOOL` value out and passes it back as a `bool`. + /// Pulls the underlying `Bool` value out and passes it back as a `bool`. /// /// Note that this _does not check_ if the underlying type is actually this. You are /// responsible for doing so via the `objc_type()` method. pub fn as_bool(&self) -> bool { - let result: BOOL = unsafe { msg_send![&*self.0, boolValue] }; - - to_bool(result) + unsafe { msg_send![&*self.0, boolValue] } } /// A helper method for determining if a given `NSObject` is an `NSNumber`. pub fn is(obj: id) -> bool { - let result: BOOL = unsafe { msg_send![obj, isKindOfClass: class!(NSNumber)] }; - - to_bool(result) + unsafe { msg_send![obj, isKindOfClass: class!(NSNumber)] } } } diff --git a/src/foundation/string.rs b/src/foundation/string.rs index d6adbbe8..f1113b60 100644 --- a/src/foundation/string.rs +++ b/src/foundation/string.rs @@ -7,7 +7,7 @@ use objc::rc::{Id, Owned}; use objc::runtime::Object; use objc::{class, msg_send, msg_send_id, sel}; -use crate::foundation::{id, to_bool, BOOL, NO, YES}; +use crate::foundation::id; const UTF8_ENCODING: usize = 4; @@ -49,7 +49,7 @@ impl<'a> NSString<'a> { initWithBytesNoCopy: s.as_ptr(), length: s.len(), encoding: UTF8_ENCODING, - freeWhenDone: NO, + freeWhenDone: false, ] }, @@ -75,8 +75,7 @@ impl<'a> NSString<'a> { /// Utility method for checking whether an `NSObject` is an `NSString`. pub fn is(obj: id) -> bool { - let result: BOOL = unsafe { msg_send![obj, isKindOfClass: class!(NSString)] }; - to_bool(result) + unsafe { msg_send![obj, isKindOfClass: class!(NSString)] } } /// Helper method for returning the UTF8 bytes for this `NSString`. diff --git a/src/image/mod.rs b/src/image/mod.rs index 1ef6db54..a2d9b406 100644 --- a/src/image/mod.rs +++ b/src/image/mod.rs @@ -3,7 +3,7 @@ use objc::runtime::{Class, Object}; use objc::{msg_send, msg_send_id, sel}; use crate::color::Color; -use crate::foundation::{id, nil, NSArray, NSString, NO, YES}; +use crate::foundation::{id, nil, NSArray, NSString}; use crate::layout::Layout; use crate::objc_access::ObjcAccess; use crate::utils::properties::ObjcProperty; @@ -38,10 +38,10 @@ fn allocate_view(registration_fn: fn() -> &'static Class) -> id { let view: id = msg_send![registration_fn(), new]; #[cfg(feature = "autolayout")] - let _: () = msg_send![view, setTranslatesAutoresizingMaskIntoConstraints: NO]; + let _: () = msg_send![view, setTranslatesAutoresizingMaskIntoConstraints: false]; #[cfg(feature = "appkit")] - let _: () = msg_send![view, setWantsLayer: YES]; + let _: () = msg_send![view, setWantsLayer: true]; view } diff --git a/src/input/mod.rs b/src/input/mod.rs index 1e1bf911..848bf705 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -49,7 +49,7 @@ use objc::{class, msg_send, sel}; use crate::color::Color; use crate::control::Control; -use crate::foundation::{id, nil, NSArray, NSInteger, NSString, NO, YES}; +use crate::foundation::{id, nil, NSArray, NSInteger, NSString}; use crate::layout::Layout; use crate::objc_access::ObjcAccess; use crate::text::{Font, TextAlign}; @@ -81,10 +81,10 @@ fn common_init(class: &Class) -> id { let view: id = msg_send![class, new]; #[cfg(feature = "autolayout")] - let _: () = msg_send![view, setTranslatesAutoresizingMaskIntoConstraints: NO]; + let _: () = msg_send![view, setTranslatesAutoresizingMaskIntoConstraints: false]; #[cfg(feature = "appkit")] - let _: () = msg_send![view, setWantsLayer: YES]; + let _: () = msg_send![view, setWantsLayer: true]; view } @@ -351,10 +351,7 @@ impl TextField { pub fn set_uses_single_line(&self, uses_single_line: bool) { self.objc.with_mut(|obj| unsafe { let cell: id = msg_send![obj, cell]; - let _: () = msg_send![cell, setUsesSingleLineMode:match uses_single_line { - true => YES, - false => NO - }]; + let _: () = msg_send![cell, setUsesSingleLineMode: uses_single_line]; }); } @@ -362,10 +359,7 @@ impl TextField { pub fn set_wraps(&self, uses_single_line: bool) { self.objc.with_mut(|obj| unsafe { let cell: id = msg_send![obj, cell]; - let _: () = msg_send![cell, setWraps:match uses_single_line { - true => YES, - false => NO - }]; + let _: () = msg_send![cell, setWraps: uses_single_line]; }); } diff --git a/src/layout/constraint.rs b/src/layout/constraint.rs index 10459fc3..1660522f 100644 --- a/src/layout/constraint.rs +++ b/src/layout/constraint.rs @@ -7,7 +7,7 @@ use objc::rc::{Id, Shared}; use objc::runtime::Object; use objc::{class, msg_send, sel}; -use crate::foundation::{id, NO, YES}; +use crate::foundation::id; #[cfg(all(feature = "appkit", target_os = "macos"))] use super::LayoutConstraintAnimatorProxy; @@ -83,10 +83,7 @@ impl LayoutConstraint { /// `LayoutConstraint::deactivate()`. pub fn set_active(&self, active: bool) { unsafe { - let _: () = msg_send![&*self.constraint, setActive:match active { - true => YES, - false => NO - }]; + let _: () = msg_send![&*self.constraint, setActive: active]; } } diff --git a/src/layout/traits.rs b/src/layout/traits.rs index 4fd1ffab..ead2f58e 100644 --- a/src/layout/traits.rs +++ b/src/layout/traits.rs @@ -6,7 +6,7 @@ use objc::rc::{Id, Shared}; use objc::runtime::Object; use objc::{msg_send, sel}; -use crate::foundation::{id, nil, to_bool, NSArray, NSString, NO, YES}; +use crate::foundation::{id, nil, NSArray, NSString}; use crate::geometry::Rect; use crate::objc_access::ObjcAccess; @@ -23,10 +23,7 @@ pub trait Layout: ObjcAccess { /// `false`. fn set_needs_display(&self, needs_display: bool) { self.with_backing_obj_mut(|obj| unsafe { - let _: () = msg_send![obj, setNeedsDisplay:match needs_display { - true => YES, - false => NO - }]; + let _: () = msg_send![obj, setNeedsDisplay: needs_display]; }); } @@ -67,10 +64,7 @@ pub trait Layout: ObjcAccess { #[cfg(feature = "autolayout")] fn set_translates_autoresizing_mask_into_constraints(&self, translates: bool) { self.with_backing_obj_mut(|backing_node| unsafe { - let _: () = msg_send![backing_node, setTranslatesAutoresizingMaskIntoConstraints:match translates { - true => YES, - false => NO - }]; + let _: () = msg_send![backing_node, setTranslatesAutoresizingMaskIntoConstraints: translates]; }); } @@ -79,10 +73,7 @@ pub trait Layout: ObjcAccess { /// When hidden, widgets don't receive events and is not visible. fn set_hidden(&self, hide: bool) { self.with_backing_obj_mut(|obj| unsafe { - let _: () = msg_send![obj, setHidden:match hide { - true => YES, - false => NO - }]; + let _: () = msg_send![obj, setHidden: hide]; }); } @@ -91,13 +82,13 @@ pub trait Layout: ObjcAccess { /// Note that this can report `false` if an ancestor widget is hidden, thus hiding this - to check in /// that case, you may want `is_hidden_or_ancestor_is_hidden()`. fn is_hidden(&self) -> bool { - self.get_from_backing_obj(|obj| to_bool(unsafe { msg_send![obj, isHidden] })) + self.get_from_backing_obj(|obj| unsafe { msg_send![obj, isHidden] }) } /// Returns whether this is hidden, *or* whether an ancestor view is hidden. #[cfg(feature = "appkit")] fn is_hidden_or_ancestor_is_hidden(&self) -> bool { - self.get_from_backing_obj(|obj| to_bool(unsafe { msg_send![obj, isHiddenOrHasHiddenAncestor] })) + self.get_from_backing_obj(|obj| unsafe { msg_send![obj, isHiddenOrHasHiddenAncestor] }) } /// Register this view for drag and drop operations. @@ -139,10 +130,7 @@ pub trait Layout: ObjcAccess { #[cfg(feature = "appkit")] fn set_posts_frame_change_notifications(&self, posts: bool) { self.with_backing_obj_mut(|obj| unsafe { - let _: () = msg_send![obj, setPostsFrameChangedNotifications:match posts { - true => YES, - false => NO - }]; + let _: () = msg_send![obj, setPostsFrameChangedNotifications: posts]; }); } @@ -153,10 +141,7 @@ pub trait Layout: ObjcAccess { #[cfg(feature = "appkit")] fn set_posts_bounds_change_notifications(&self, posts: bool) { self.with_backing_obj_mut(|obj| unsafe { - let _: () = msg_send![obj, setPostsBoundsChangedNotifications:match posts { - true => YES, - false => NO - }]; + let _: () = msg_send![obj, setPostsBoundsChangedNotifications: posts]; }); } diff --git a/src/listview/mod.rs b/src/listview/mod.rs index 34d257b9..7eee449a 100644 --- a/src/listview/mod.rs +++ b/src/listview/mod.rs @@ -50,7 +50,7 @@ use objc::runtime::{Class, Object}; use objc::{class, msg_send, msg_send_id, sel}; use crate::color::Color; -use crate::foundation::{id, nil, NSArray, NSInteger, NSString, NSUInteger, NO, YES}; +use crate::foundation::{id, nil, NSArray, NSInteger, NSString, NSUInteger}; use crate::layout::Layout; #[cfg(feature = "autolayout")] @@ -112,13 +112,13 @@ fn common_init(class: &Class) -> id { let _: () = msg_send![menu, setDelegate: tableview]; let _: () = msg_send![tableview, setMenu: menu]; - let _: () = msg_send![tableview, setWantsLayer: YES]; - let _: () = msg_send![tableview, setUsesAutomaticRowHeights: YES]; - let _: () = msg_send![tableview, setFloatsGroupRows: YES]; + let _: () = msg_send![tableview, setWantsLayer: true]; + let _: () = msg_send![tableview, setUsesAutomaticRowHeights: true]; + let _: () = msg_send![tableview, setFloatsGroupRows: true]; //let _: () = msg_send![tableview, setIntercellSpacing: NSSize::new(0., 0.)]; let _: () = msg_send![tableview, setColumnAutoresizingStyle:1]; //msg_send![tableview, setSelectionHighlightStyle:-1]; - //let _: () = msg_send![tableview, setAllowsMultipleSelection:NO]; + //let _: () = msg_send![tableview, setAllowsMultipleSelection: false]; let _: () = msg_send![tableview, setHeaderView: nil]; // NSTableView requires at least one column to be manually added if doing so by code. @@ -467,10 +467,7 @@ impl ListView { #[cfg(feature = "appkit")] pub fn set_allows_empty_selection(&self, allows: bool) { self.objc.with_mut(|obj| unsafe { - let _: () = msg_send![obj, setAllowsEmptySelection:match allows { - true => YES, - false => NO - }]; + let _: () = msg_send![obj, setAllowsEmptySelection: allows]; }); } @@ -491,10 +488,7 @@ impl ListView { } self.objc.with_mut(|obj| { - let _: () = msg_send![obj, selectRowIndexes: &*index_set, byExtendingSelection: match extends_existing { - true => YES, - false => NO - }]; + let _: () = msg_send![obj, selectRowIndexes: &*index_set, byExtendingSelection: extends_existing]; }); } } @@ -656,10 +650,7 @@ impl ListView { pub fn set_uses_automatic_row_heights(&self, uses: bool) { #[cfg(feature = "appkit")] self.objc.with_mut(|obj| unsafe { - let _: () = msg_send![obj, setUsesAutomaticRowHeights:match uses { - true => YES, - false => NO - }]; + let _: () = msg_send![obj, setUsesAutomaticRowHeights: uses]; }); } @@ -669,10 +660,7 @@ impl ListView { pub fn set_uses_alternating_backgrounds(&self, uses: bool) { #[cfg(feature = "appkit")] self.objc.with_mut(|obj| unsafe { - let _: () = msg_send![obj, setUsesAlternatingRowBackgroundColors:match uses { - true => YES, - false => NO - }]; + let _: () = msg_send![obj, setUsesAlternatingRowBackgroundColors: uses]; }); } @@ -680,10 +668,7 @@ impl ListView { pub fn set_row_actions_visible(&self, visible: bool) { #[cfg(feature = "appkit")] self.objc.with_mut(|obj| unsafe { - let _: () = msg_send![obj, setRowActionsVisible:match visible { - true => YES, - false => NO - }]; + let _: () = msg_send![obj, setRowActionsVisible: visible]; }); } diff --git a/src/listview/row/appkit.rs b/src/listview/row/appkit.rs index d7ed7356..76f97fb3 100644 --- a/src/listview/row/appkit.rs +++ b/src/listview/row/appkit.rs @@ -18,7 +18,7 @@ use crate::utils::load; /// Enforces normalcy, or: a needlessly cruel method in terms of the name. You get the idea though. extern "C" fn enforce_normalcy(_: &Object, _: Sel) -> Bool { - return Bool::YES; + Bool::YES } /// Called when a drag/drop operation has entered this view. diff --git a/src/listview/row/mod.rs b/src/listview/row/mod.rs index ef6342d8..88210e64 100644 --- a/src/listview/row/mod.rs +++ b/src/listview/row/mod.rs @@ -50,7 +50,7 @@ use objc::runtime::{Class, Object}; use objc::{class, msg_send, sel}; use crate::color::Color; -use crate::foundation::{id, nil, NSArray, NSString, NO, YES}; +use crate::foundation::{id, nil, NSArray, NSString}; use crate::layer::Layer; use crate::layout::Layout; use crate::objc_access::ObjcAccess; @@ -82,10 +82,10 @@ fn allocate_view(registration_fn: fn() -> &'static Class) -> id { let view: id = msg_send![registration_fn(), new]; #[cfg(feature = "autolayout")] - let _: () = msg_send![view, setTranslatesAutoresizingMaskIntoConstraints: NO]; + let _: () = msg_send![view, setTranslatesAutoresizingMaskIntoConstraints: false]; #[cfg(feature = "appkit")] - let _: () = msg_send![view, setWantsLayer: YES]; + let _: () = msg_send![view, setWantsLayer: true]; view } diff --git a/src/listview/row/uikit.rs b/src/listview/row/uikit.rs index 72fcd4ec..276f8960 100644 --- a/src/listview/row/uikit.rs +++ b/src/listview/row/uikit.rs @@ -1,10 +1,10 @@ use objc::declare::ClassDecl; -use objc::runtime::{Class, Object, Sel, BOOL}; +use objc::runtime::{Class, Object, Sel}; use objc::{class, sel}; use objc::rc::{Id, Owned}; use crate::dragdrop::DragInfo; -use crate::foundation::{id, NSUInteger, NO, YES}; +use crate::foundation::{id, NSUInteger}; use crate::utils::load; use crate::view::{ViewDelegate, VIEW_DELEGATE_PTR}; diff --git a/src/progress/mod.rs b/src/progress/mod.rs index e4eb9ec8..802a8492 100644 --- a/src/progress/mod.rs +++ b/src/progress/mod.rs @@ -21,7 +21,7 @@ use objc::runtime::{Class, Object}; use objc::{class, msg_send, sel}; use crate::color::Color; -use crate::foundation::{id, nil, NSUInteger, NO, YES}; +use crate::foundation::{id, nil, NSUInteger}; use crate::layout::Layout; use crate::objc_access::ObjcAccess; use crate::utils::properties::ObjcProperty; @@ -94,10 +94,10 @@ impl ProgressIndicator { let view: id = msg_send![class!(NSProgressIndicator), new]; #[cfg(feature = "autolayout")] - let _: () = msg_send![view, setTranslatesAutoresizingMaskIntoConstraints: NO]; + let _: () = msg_send![view, setTranslatesAutoresizingMaskIntoConstraints: false]; #[cfg(feature = "appkit")] - let _: () = msg_send![view, setWantsLayer: YES]; + let _: () = msg_send![view, setWantsLayer: true]; view }; @@ -176,10 +176,7 @@ impl ProgressIndicator { /// Invert this to go back to a bar appearance. pub fn set_indeterminate(&self, is_indeterminate: bool) { self.objc.with_mut(|obj| unsafe { - let _: () = msg_send![obj, setIndeterminate:match is_indeterminate { - true => YES, - false => NO - }]; + let _: () = msg_send![obj, setIndeterminate: is_indeterminate]; }); } @@ -197,10 +194,7 @@ impl ProgressIndicator { /// Set whether this control is hidden or not. pub fn set_hidden(&self, hidden: bool) { self.objc.with_mut(|obj| unsafe { - let _: () = msg_send![obj, setHidden:match hidden { - true => YES, - false => NO - }]; + let _: () = msg_send![obj, setHidden: hidden]; }); } } diff --git a/src/quicklook/config.rs b/src/quicklook/config.rs index 81ba859e..19f10e1e 100644 --- a/src/quicklook/config.rs +++ b/src/quicklook/config.rs @@ -5,7 +5,7 @@ use objc::rc::{Id, Shared}; use objc::runtime::Object; use objc::{class, msg_send, sel}; -use crate::foundation::{id, NSString, NSUInteger, YES}; +use crate::foundation::{id, NSString, NSUInteger}; /// Describes the quality of the thumbnail you expect back from the /// generator service. @@ -117,7 +117,7 @@ impl ThumbnailConfig { representationTypes:types]; if self.icon_mode { - let _: () = msg_send![request, setIconMode: YES]; + let _: () = msg_send![request, setIconMode: true]; } if self.minimum_dimension != 0. { diff --git a/src/scrollview/appkit.rs b/src/scrollview/appkit.rs index 4360ff82..8c4a201a 100644 --- a/src/scrollview/appkit.rs +++ b/src/scrollview/appkit.rs @@ -18,7 +18,7 @@ use crate::utils::load; /// Enforces normalcy, or: a needlessly cruel method in terms of the name. You get the idea though. extern "C" fn enforce_normalcy(_: &Object, _: Sel) -> Bool { - return Bool::YES; + Bool::YES } /// Called when a drag/drop operation has entered this view. diff --git a/src/scrollview/mod.rs b/src/scrollview/mod.rs index 6fb612c0..783c5550 100644 --- a/src/scrollview/mod.rs +++ b/src/scrollview/mod.rs @@ -47,7 +47,7 @@ use objc::runtime::{Class, Object}; use objc::{msg_send, sel}; use crate::color::Color; -use crate::foundation::{id, nil, NSArray, NSString, NO, YES}; +use crate::foundation::{id, nil, NSArray, NSString}; use crate::layout::Layout; use crate::objc_access::ObjcAccess; use crate::utils::properties::ObjcProperty; @@ -78,15 +78,15 @@ fn allocate_view(registration_fn: fn() -> &'static Class) -> id { let view: id = msg_send![registration_fn(), new]; #[cfg(feature = "autolayout")] - let _: () = msg_send![view, setTranslatesAutoresizingMaskIntoConstraints: NO]; + let _: () = msg_send![view, setTranslatesAutoresizingMaskIntoConstraints: false]; #[cfg(feature = "appkit")] { - let _: () = msg_send![view, setDrawsBackground: NO]; - let _: () = msg_send![view, setWantsLayer: YES]; + let _: () = msg_send![view, setDrawsBackground: false]; + let _: () = msg_send![view, setWantsLayer: true]; let _: () = msg_send![view, setBorderType:0]; let _: () = msg_send![view, setHorizontalScrollElasticity:1]; - let _: () = msg_send![view, setHasVerticalScroller: YES]; + let _: () = msg_send![view, setHasVerticalScroller: true]; } view diff --git a/src/select/mod.rs b/src/select/mod.rs index 3f99b52a..49bf1102 100644 --- a/src/select/mod.rs +++ b/src/select/mod.rs @@ -6,7 +6,7 @@ use objc::runtime::{Class, Object}; use objc::{msg_send, msg_send_id, sel}; use crate::control::Control; -use crate::foundation::{id, load_or_register_class, nil, NSInteger, NSString, NO, YES}; +use crate::foundation::{id, load_or_register_class, nil, NSInteger, NSString}; use crate::geometry::Rect; use crate::invoker::TargetActionHandler; use crate::layout::Layout; @@ -89,10 +89,10 @@ impl Select { let view: id = unsafe { let alloc: id = msg_send![register_class(), alloc]; - let select: id = msg_send![alloc, initWithFrame:zero pullsDown:NO]; + let select: id = msg_send![alloc, initWithFrame:zero, pullsDown: false]; #[cfg(feature = "autolayout")] - let _: () = msg_send![select, setTranslatesAutoresizingMaskIntoConstraints: NO]; + let _: () = msg_send![select, setTranslatesAutoresizingMaskIntoConstraints: false]; select }; @@ -150,10 +150,7 @@ impl Select { /// Sets whether this pulls down (dropdown) or pops up. pub fn set_pulls_down(&self, pulls_down: bool) { self.objc.with_mut(|obj| unsafe { - let _: () = msg_send![obj, setPullsDown:match pulls_down { - true => YES, - false => NO - }]; + let _: () = msg_send![obj, setPullsDown: pulls_down]; }); } diff --git a/src/switch.rs b/src/switch.rs index 601ac901..7111eed0 100644 --- a/src/switch.rs +++ b/src/switch.rs @@ -5,7 +5,7 @@ use objc::rc::{Id, Shared}; use objc::runtime::{Class, Object}; use objc::{msg_send, msg_send_id, sel}; -use crate::foundation::{id, load_or_register_class, nil, NSString, NO}; +use crate::foundation::{id, load_or_register_class, nil, NSString}; use crate::invoker::TargetActionHandler; use crate::layout::Layout; #[cfg(feature = "autolayout")] @@ -72,7 +72,7 @@ impl Switch { let button: id = msg_send![register_class(), buttonWithTitle: &*title, target: nil, action: nil]; #[cfg(feature = "autolayout")] - let _: () = msg_send![button, setTranslatesAutoresizingMaskIntoConstraints: NO]; + let _: () = msg_send![button, setTranslatesAutoresizingMaskIntoConstraints: false]; #[cfg(feature = "appkit")] let _: () = msg_send![button, setButtonType:3]; diff --git a/src/text/font.rs b/src/text/font.rs index c81c0dd5..2c0072ce 100644 --- a/src/text/font.rs +++ b/src/text/font.rs @@ -7,7 +7,7 @@ use objc::rc::{Id, Shared}; use objc::runtime::{Class, Object}; use objc::{class, msg_send, msg_send_id, sel}; -use crate::foundation::{id, nil, NSArray, NSString, NO, YES}; +use crate::foundation::{id, nil, NSArray, NSString}; use crate::utils::os; /// A `Font` can be constructed and applied to supported controls to control things like text diff --git a/src/text/label/mod.rs b/src/text/label/mod.rs index 918a6913..1d490d94 100644 --- a/src/text/label/mod.rs +++ b/src/text/label/mod.rs @@ -48,7 +48,7 @@ use objc::runtime::{Class, Object}; use objc::{msg_send, msg_send_id, sel}; use crate::color::Color; -use crate::foundation::{id, nil, NSArray, NSInteger, NSString, NSUInteger, NO, YES}; +use crate::foundation::{id, nil, NSArray, NSInteger, NSString, NSUInteger}; use crate::layer::Layer; use crate::layout::Layout; use crate::objc_access::ObjcAccess; @@ -85,7 +85,7 @@ fn allocate_view(registration_fn: fn() -> &'static Class) -> id { let label: id = msg_send![registration_fn(), wrappingLabelWithString:&*blank]; // We sub this in to get the general expected behavior for 202*. - let _: () = msg_send![label, setSelectable: NO]; + let _: () = msg_send![label, setSelectable: false]; label }; @@ -94,10 +94,10 @@ fn allocate_view(registration_fn: fn() -> &'static Class) -> id { let view: id = msg_send![registration_fn(), new]; #[cfg(feature = "autolayout")] - let _: () = msg_send![view, setTranslatesAutoresizingMaskIntoConstraints: NO]; + let _: () = msg_send![view, setTranslatesAutoresizingMaskIntoConstraints: false]; #[cfg(feature = "appkit")] - let _: () = msg_send![view, setWantsLayer: YES]; + let _: () = msg_send![view, setWantsLayer: true]; view } @@ -407,10 +407,7 @@ impl Label { /// Set whether this is hidden or not. pub fn set_hidden(&self, hidden: bool) { self.objc.with_mut(|obj| unsafe { - let _: () = msg_send![obj, setHidden:match hidden { - true => YES, - false => NO - }]; + let _: () = msg_send![obj, setHidden: hidden]; }); } @@ -430,7 +427,7 @@ impl Label { self.objc.with_mut(|obj| unsafe { let cell: id = msg_send![obj, cell]; let mode = mode as NSUInteger; - let _: () = msg_send![cell, setTruncatesLastVisibleLine: YES]; + let _: () = msg_send![cell, setTruncatesLastVisibleLine: true]; let _: () = msg_send![cell, setLineBreakMode: mode]; }); } diff --git a/src/text/label/uikit.rs b/src/text/label/uikit.rs index d7e0e9a1..f194dda6 100644 --- a/src/text/label/uikit.rs +++ b/src/text/label/uikit.rs @@ -1,10 +1,10 @@ use std::sync::Once; use objc::declare::ClassDecl; -use objc::runtime::{Class, Object, Sel, BOOL}; +use objc::runtime::{Class, Object, Sel}; use objc::{class, sel}; -use crate::foundation::{id, NSUInteger, NO, YES}; +use crate::foundation::{id, NSUInteger}; use crate::text::label::{LabelDelegate, LABEL_DELEGATE_PTR}; /// Injects an `UILabel` subclass. This is used for the default views that don't use delegates - we diff --git a/src/uikit/app/mod.rs b/src/uikit/app/mod.rs index eb9367ed..00907639 100644 --- a/src/uikit/app/mod.rs +++ b/src/uikit/app/mod.rs @@ -40,7 +40,7 @@ use std::ffi::CString; use objc::runtime::Object; use objc::{class, msg_send, sel}; -use crate::foundation::{id, nil, AutoReleasePool, NSString, NSUInteger, NO, YES}; +use crate::foundation::{id, nil, AutoReleasePool, NSString, NSUInteger}; use crate::notification_center::Dispatcher; use crate::uikit::scene::{register_window_scene_delegate_class, WindowSceneDelegate}; use crate::utils::activate_cocoa_multithreading; diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 187b5362..e962e9c1 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -7,7 +7,7 @@ use objc::runtime::Object; use objc::{class, msg_send, sel}; use objc::{Encode, Encoding}; -use crate::foundation::{id, BOOL, NO, YES}; +use crate::foundation::id; mod cell_factory; pub use cell_factory::CellFactory; diff --git a/src/view/appkit.rs b/src/view/appkit.rs index 309a31ca..294aa324 100644 --- a/src/view/appkit.rs +++ b/src/view/appkit.rs @@ -19,7 +19,7 @@ use crate::view::{ViewDelegate, BACKGROUND_COLOR, VIEW_DELEGATE_PTR}; /// Enforces normalcy, or: a needlessly cruel method in terms of the name. You get the idea though. extern "C" fn enforce_normalcy(_: &Object, _: Sel) -> Bool { - return Bool::YES; + Bool::YES } /// Called when a drag/drop operation has entered this view. diff --git a/src/view/mod.rs b/src/view/mod.rs index c0e1a334..64aec95e 100644 --- a/src/view/mod.rs +++ b/src/view/mod.rs @@ -46,7 +46,7 @@ use objc::runtime::{Class, Object}; use objc::{msg_send, msg_send_id, sel}; use crate::color::Color; -use crate::foundation::{id, nil, NSArray, NSInteger, NSString, NO, YES}; +use crate::foundation::{id, nil, NSArray, NSInteger, NSString}; use crate::layer::Layer; use crate::layout::Layout; use crate::objc_access::ObjcAccess; @@ -174,10 +174,10 @@ impl View { pub(crate) fn init(view: id) -> View { unsafe { #[cfg(feature = "autolayout")] - let _: () = msg_send![view, setTranslatesAutoresizingMaskIntoConstraints: NO]; + let _: () = msg_send![view, setTranslatesAutoresizingMaskIntoConstraints: false]; #[cfg(feature = "appkit")] - let _: () = msg_send![view, setWantsLayer: YES]; + let _: () = msg_send![view, setWantsLayer: true]; } View { @@ -341,10 +341,7 @@ impl View { #[cfg(feature = "appkit")] pub fn set_can_draw_subviews_into_layer(&self, can: bool) { self.objc.with_mut(|obj| unsafe { - let _: () = msg_send![&*obj, setCanDrawSubviewsIntoLayer:match can { - true => YES, - false => NO - }]; + let _: () = msg_send![&*obj, setCanDrawSubviewsIntoLayer: can]; }); } } diff --git a/src/view/uikit.rs b/src/view/uikit.rs index 06ddc9e9..b944dcb0 100644 --- a/src/view/uikit.rs +++ b/src/view/uikit.rs @@ -1,10 +1,10 @@ use objc::declare::ClassDecl; use objc::rc::{Id, Owned}; -use objc::runtime::{Class, Object, Sel, BOOL}; +use objc::runtime::{Class, Object, Sel}; use objc::{class, sel}; use crate::foundation::load_or_register_class; -use crate::foundation::{id, NSUInteger, NO, YES}; +use crate::foundation::{id, NSUInteger}; use crate::utils::load; use crate::view::{ViewDelegate, VIEW_DELEGATE_PTR}; diff --git a/src/webview/actions.rs b/src/webview/actions.rs index d6e1f27b..b9ff2267 100644 --- a/src/webview/actions.rs +++ b/src/webview/actions.rs @@ -2,7 +2,7 @@ use objc::{msg_send, sel}; -use crate::foundation::{id, NSInteger, BOOL, NO, YES}; +use crate::foundation::{id, NSInteger}; use crate::networking::URLRequest; use crate::webview::enums::NavigationType; @@ -33,14 +33,7 @@ pub struct NavigationResponse { impl NavigationResponse { pub fn new(response: id) -> Self { NavigationResponse { - can_show_mime_type: unsafe { - let can_show: BOOL = msg_send![response, canShowMIMEType]; - if can_show == YES { - true - } else { - false - } - } + can_show_mime_type: unsafe { msg_send![response, canShowMIMEType] } } } } @@ -54,29 +47,9 @@ pub struct OpenPanelParameters { impl From for OpenPanelParameters { fn from(params: id) -> Self { OpenPanelParameters { - allows_directories: unsafe { - match msg_send![params, allowsDirectories] { - YES => true, - NO => false, + allows_directories: unsafe { msg_send![params, allowsDirectories] }, - #[cfg(not(target_arch = "aarch64"))] - _ => { - panic!("Invalid value from WKOpenPanelParameters:allowsDirectories"); - } - } - }, - - allows_multiple_selection: unsafe { - match msg_send![params, allowsMultipleSelection] { - YES => true, - NO => false, - - #[cfg(not(target_arch = "aarch64"))] - _ => { - panic!("Invalid value from WKOpenPanelParameters:allowsMultipleSelection"); - } - } - } + allows_multiple_selection: unsafe { msg_send![params, allowsMultipleSelection] } } } } diff --git a/src/webview/class.rs b/src/webview/class.rs index e14dbd3e..f5ada8cc 100644 --- a/src/webview/class.rs +++ b/src/webview/class.rs @@ -151,7 +151,7 @@ extern "C" fn run_open_panel(this: &Object, _: Sel, _: id, p extern "C" fn handle_download(this: &Object, _: Sel, download: id, suggested_filename: id, handler: usize) { let delegate = load::(this, WEBVIEW_DELEGATE_PTR); - let handler = handler as *const Block<(objc::runtime::Bool, id), ()>; + let handler = handler as *const Block<(Bool, id), ()>; let filename = NSString::retain(suggested_filename); delegate.run_save_panel(filename.to_str(), move |can_overwrite, path| unsafe { diff --git a/src/webview/config.rs b/src/webview/config.rs index 95ab0315..afec7d3e 100644 --- a/src/webview/config.rs +++ b/src/webview/config.rs @@ -5,7 +5,7 @@ use objc::rc::{Id, Owned}; use objc::runtime::Object; use objc::{class, msg_send, msg_send_id, sel}; -use crate::foundation::{id, NSInteger, NSString, NO, YES}; +use crate::foundation::{id, NSInteger, NSString}; use crate::webview::enums::InjectAt; /// A wrapper for `WKWebViewConfiguration`. Holds (retains) pointers for the Objective-C runtime @@ -48,10 +48,7 @@ impl WebViewConfig { alloc, initWithSource: &*source, injectionTime: at, - forMainFrameOnly: match main_frame_only { - true => YES, - false => NO - }, + forMainFrameOnly: main_frame_only, ]; let content_controller: id = msg_send![&*self.objc, userContentController]; @@ -70,7 +67,7 @@ impl WebViewConfig { let key = NSString::new("developerExtrasEnabled"); unsafe { - let yes: id = msg_send![class!(NSNumber), numberWithBool: YES]; + let yes: id = msg_send![class!(NSNumber), numberWithBool: true]; let preferences: id = msg_send![&*self.objc, preferences]; let _: () = msg_send![preferences, setValue: yes, forKey: &*key]; } diff --git a/src/webview/mod.rs b/src/webview/mod.rs index 110a67a6..11cf391c 100644 --- a/src/webview/mod.rs +++ b/src/webview/mod.rs @@ -18,7 +18,7 @@ use objc::rc::{Id, Owned, Shared}; use objc::runtime::Object; use objc::{class, msg_send, msg_send_id, sel}; -use crate::foundation::{id, nil, NSString, NO, YES}; +use crate::foundation::{id, nil, NSString}; use crate::geometry::Rect; use crate::layer::Layer; use crate::layout::Layout; @@ -79,10 +79,10 @@ fn allocate_webview(mut config: WebViewConfig, objc_delegate: Option<&Object>) - let webview: id = msg_send![webview_alloc, initWithFrame:zero configuration: &*config.objc]; #[cfg(feature = "appkit")] - let _: () = msg_send![webview, setWantsLayer: YES]; + let _: () = msg_send![webview, setWantsLayer: true]; #[cfg(feature = "autolayout")] - let _: () = msg_send![webview, setTranslatesAutoresizingMaskIntoConstraints: NO]; + let _: () = msg_send![webview, setTranslatesAutoresizingMaskIntoConstraints: false]; if let Some(delegate) = &objc_delegate { let _: () = msg_send![webview, setNavigationDelegate:*delegate]; @@ -167,10 +167,10 @@ impl WebView { /// so on. It returns a generic `WebView`, which the caller can then customize as needed. pub(crate) fn init(view: id) -> WebView { unsafe { - let _: () = msg_send![view, setTranslatesAutoresizingMaskIntoConstraints: NO]; + let _: () = msg_send![view, setTranslatesAutoresizingMaskIntoConstraints: false]; #[cfg(feature = "appkit")] - let _: () = msg_send![view, setWantsLayer: YES]; + let _: () = msg_send![view, setWantsLayer: true]; } WebView { diff --git a/src/webview/process_pool.rs b/src/webview/process_pool.rs index 84e5ac02..cecc27d2 100644 --- a/src/webview/process_pool.rs +++ b/src/webview/process_pool.rs @@ -7,10 +7,10 @@ use block::Block; use cocoa::foundation::{NSArray, NSInteger, NSPoint, NSRect, NSSize, NSString}; use objc::declare::ClassDecl; -use objc::runtime::{Class, Object, Sel, BOOL}; +use objc::runtime::{Class, Object, Sel}; use objc::{class, msg_send, sel}; -use crate::foundation::{id, nil, NO, YES}; +use crate::foundation::{id, nil}; use crate::webview::traits::WebViewController; extern "C" fn download_delegate(this: &Object, _: Sel) -> id {