From e77801ccddd77be07fdd3acaf38102af3e6f907a Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Tue, 1 Aug 2023 02:01:20 +0200 Subject: [PATCH] Fix message sends arguments that do not implement `Encode` --- src/appkit/alert.rs | 6 +++--- src/appkit/animation.rs | 9 ++++++--- src/appkit/app/delegate.rs | 2 +- src/appkit/event/mod.rs | 14 ++++++++++---- src/appkit/haptics.rs | 2 +- src/appkit/menu/item.rs | 2 +- src/appkit/toolbar/item.rs | 4 ++-- src/appkit/toolbar/mod.rs | 2 +- src/appkit/window/mod.rs | 8 ++++---- src/color/mod.rs | 8 ++++---- src/defaults/mod.rs | 2 +- src/error.rs | 2 +- src/filesystem/save.rs | 2 +- src/filesystem/select.rs | 8 ++++++-- src/foundation/urls/mod.rs | 20 ++++++++++++-------- src/image/image.rs | 19 ++++++++++++------- src/image/mod.rs | 4 +++- src/input/mod.rs | 4 +++- src/layout/dimension.rs | 12 ++++++------ src/layout/horizontal.rs | 6 +++--- src/layout/vertical.rs | 6 +++--- src/listview/actions.rs | 8 +++++--- src/listview/mod.rs | 4 +++- src/pasteboard/mod.rs | 4 ++-- src/quicklook/mod.rs | 7 +++++-- src/scrollview/mod.rs | 4 +++- src/select/mod.rs | 2 +- src/switch.rs | 2 +- src/text/attributed_string.rs | 21 +++++++++++++-------- src/text/label/mod.rs | 4 +++- src/uikit/scene/config.rs | 2 +- src/uikit/scene/delegate.rs | 4 ++-- src/user_notifications/mod.rs | 16 ++++++++++++---- src/user_notifications/notifications.rs | 4 ++-- src/utils/mod.rs | 21 +++++++++++++++++++++ src/webview/class.rs | 17 +++++++++++------ src/webview/config.rs | 15 ++++++++++----- 37 files changed, 179 insertions(+), 98 deletions(-) diff --git a/src/appkit/alert.rs b/src/appkit/alert.rs index 62d6ddd5..25c48e8f 100644 --- a/src/appkit/alert.rs +++ b/src/appkit/alert.rs @@ -45,9 +45,9 @@ impl Alert { Alert(unsafe { let alert: id = msg_send![class!(NSAlert), new]; - let _: () = msg_send![alert, setMessageText: title]; - let _: () = msg_send![alert, setInformativeText: message]; - let _: () = msg_send![alert, addButtonWithTitle: ok]; + let _: () = msg_send![alert, setMessageText: &*title]; + let _: () = msg_send![alert, setInformativeText: &*message]; + let _: () = msg_send![alert, addButtonWithTitle: &*ok]; Id::from_ptr(alert) }) } diff --git a/src/appkit/animation.rs b/src/appkit/animation.rs index b7750d67..48deb215 100644 --- a/src/appkit/animation.rs +++ b/src/appkit/animation.rs @@ -39,7 +39,7 @@ impl AnimationContext { unsafe { //let context: id = msg_send![class!(NSAnimationContext), currentContext]; - let _: () = msg_send![class!(NSAnimationContext), runAnimationGroup: block]; + let _: () = msg_send![class!(NSAnimationContext), runAnimationGroup: &*block]; } } @@ -66,8 +66,11 @@ impl AnimationContext { unsafe { //let context: id = msg_send![class!(NSAnimationContext), currentContext]; - let _: () = msg_send![class!(NSAnimationContext), runAnimationGroup:block - completionHandler:completion_block]; + let _: () = msg_send![ + class!(NSAnimationContext), + runAnimationGroup: &*block, + completionHandler: &*completion_block, + ]; } } } diff --git a/src/appkit/app/delegate.rs b/src/appkit/app/delegate.rs index f34c32b2..3890291a 100644 --- a/src/appkit/app/delegate.rs +++ b/src/appkit/app/delegate.rs @@ -145,7 +145,7 @@ extern "C" fn continue_user_activity(this: &Object, _: Sel, _: i let activity = UserActivity::with_inner(activity); match app::(this).continue_user_activity(activity, || unsafe { - let handler = handler as *const Block<(id,), c_void>; + let handler = handler as *const Block<(id,), ()>; (*handler).call((nil,)); }) { true => YES, diff --git a/src/appkit/event/mod.rs b/src/appkit/event/mod.rs index 1e21a526..966785f2 100644 --- a/src/appkit/event/mod.rs +++ b/src/appkit/event/mod.rs @@ -137,8 +137,11 @@ impl Event { let block = block.copy(); EventMonitor(unsafe { - msg_send![class!(NSEvent), addLocalMonitorForEventsMatchingMask:mask.bits - handler:block] + Id::from_ptr(msg_send![ + class!(NSEvent), + addLocalMonitorForEventsMatchingMask: mask.bits, + handler: &*block, + ]) }) } @@ -163,8 +166,11 @@ impl Event { let block = block.copy(); EventMonitor(unsafe { - msg_send![class!(NSEvent), addGlobalMonitorForEventsMatchingMask:mask.bits - handler:block] + Id::from_ptr(msg_send![ + class!(NSEvent), + addGlobalMonitorForEventsMatchingMask: mask.bits, + handler: &*block, + ]) }) } } diff --git a/src/appkit/haptics.rs b/src/appkit/haptics.rs index c7772a44..a7185a9e 100644 --- a/src/appkit/haptics.rs +++ b/src/appkit/haptics.rs @@ -11,7 +11,7 @@ pub struct HapticFeedbackPerformer(pub ShareId); impl HapticFeedbackPerformer { pub fn perform(&self, pattern: FeedbackPattern, performance_time: PerformanceTime) { unsafe { - let _: () = msg_send![&*self.0, performFeedbackPattern: pattern performanceTime: performance_time]; + let _: () = msg_send![&*self.0, performFeedbackPattern: pattern as isize performanceTime: performance_time as usize]; } } } diff --git a/src/appkit/menu/item.rs b/src/appkit/menu/item.rs index 57f21f3a..ac75ccee 100644 --- a/src/appkit/menu/item.rs +++ b/src/appkit/menu/item.rs @@ -229,7 +229,7 @@ impl MenuItem { if let MenuItem::Custom(objc) = self { unsafe { let key = NSString::new(key); - let _: () = msg_send![&*objc, setKeyEquivalent: key]; + let _: () = msg_send![&*objc, setKeyEquivalent: &*key]; } return MenuItem::Custom(objc); diff --git a/src/appkit/toolbar/item.rs b/src/appkit/toolbar/item.rs index e6af5a33..649b873c 100644 --- a/src/appkit/toolbar/item.rs +++ b/src/appkit/toolbar/item.rs @@ -34,9 +34,9 @@ impl ToolbarItem { let identifier = identifier.into(); let objc = unsafe { - let identifr = NSString::new(&identifier); + let identifer = NSString::new(&identifier); let alloc: id = msg_send![class!(NSToolbarItem), alloc]; - let item: id = msg_send![alloc, initWithItemIdentifier: identifr]; + let item: id = msg_send![alloc, initWithItemIdentifier: &*identifer]; Id::from_ptr(item) }; diff --git a/src/appkit/toolbar/mod.rs b/src/appkit/toolbar/mod.rs index dfcc287f..da0652c7 100644 --- a/src/appkit/toolbar/mod.rs +++ b/src/appkit/toolbar/mod.rs @@ -55,7 +55,7 @@ where let (objc, objc_delegate) = unsafe { let alloc: id = msg_send![class!(NSToolbar), alloc]; let identifier = NSString::new(&identifier); - let toolbar: id = msg_send![alloc, initWithIdentifier: identifier]; + let toolbar: id = msg_send![alloc, initWithIdentifier: &*identifier]; let objc_delegate: id = msg_send![cls, new]; //WithIdentifier:identifier]; let ptr: *const T = &*delegate; diff --git a/src/appkit/window/mod.rs b/src/appkit/window/mod.rs index 436b3bae..308127ed 100644 --- a/src/appkit/window/mod.rs +++ b/src/appkit/window/mod.rs @@ -201,7 +201,7 @@ impl Window { pub fn set_title(&self, title: &str) { unsafe { let title = NSString::new(title); - let _: () = msg_send![&*self.objc, setTitle: title]; + let _: () = msg_send![&*self.objc, setTitle: &*title]; } } @@ -216,7 +216,7 @@ impl Window { unsafe { let subtitle = NSString::new(subtitle); - let _: () = msg_send![&*self.objc, setSubtitle: subtitle]; + let _: () = msg_send![&*self.objc, setSubtitle: &*subtitle]; } } @@ -252,7 +252,7 @@ impl Window { pub fn set_autosave_name(&self, name: &str) { unsafe { let autosave = NSString::new(name); - let _: () = msg_send![&*self.objc, setFrameAutosaveName: autosave]; + let _: () = msg_send![&*self.objc, setFrameAutosaveName: &*autosave]; } } @@ -514,7 +514,7 @@ impl Window { let block = block.copy(); unsafe { - let _: () = msg_send![&*self.objc, beginSheet:&*window.objc completionHandler:block]; + let _: () = msg_send![&*self.objc, beginSheet: &*window.objc, completionHandler: &*block]; } } diff --git a/src/color/mod.rs b/src/color/mod.rs index d1c45d4c..992faf56 100644 --- a/src/color/mod.rs +++ b/src/color/mod.rs @@ -15,6 +15,7 @@ /// @TODO: bundle iOS/tvOS support. use std::sync::{Arc, RwLock}; +use core_foundation::base::TCFType; use core_graphics::base::CGFloat; use core_graphics::color::CGColor; @@ -247,9 +248,9 @@ impl Color { let b = blue as CGFloat / 255.0; let a = alpha as CGFloat / 255.0; #[cfg(feature = "appkit")] - let ptr = unsafe { Id::from_ptr(msg_send![class!(NSColor), colorWithCalibratedRed:r green:g blue:b alpha:a]) }; + let ptr = unsafe { Id::from_ptr(msg_send![class!(NSColor), colorWithCalibratedRed: r, green: g, blue: b, alpha: a]) }; #[cfg(all(feature = "uikit", not(feature = "appkit")))] - let ptr = unsafe { Id::from_ptr(msg_send![class!(UIColor), colorWithRed:r green:g blue:b alpha:a]) }; + let ptr = unsafe { Id::from_ptr(msg_send![class!(UIColor), colorWithRed: r, green: g, blue: b, alpha: a]) }; Color::Custom(Arc::new(RwLock::new(ptr))) } @@ -398,10 +399,9 @@ impl Color { /// you're not using a cached version of this unless you explicitly want the _same_ color /// in every context it's used in. pub fn cg_color(&self) -> CGColor { - // @TODO: This should probably return a CGColorRef... unsafe { let objc: id = self.into(); - msg_send![objc, CGColor] + CGColor::wrap_under_get_rule(msg_send![objc, CGColor]) } } } diff --git a/src/defaults/mod.rs b/src/defaults/mod.rs index ca95a94d..d8014231 100644 --- a/src/defaults/mod.rs +++ b/src/defaults/mod.rs @@ -133,7 +133,7 @@ impl UserDefaults { let value: id = value.into(); unsafe { - let _: () = msg_send![&*self.0, setObject:value forKey:key]; + let _: () = msg_send![&*self.0, setObject: value, forKey: &*key]; } } diff --git a/src/error.rs b/src/error.rs index e36d19b5..584e708b 100644 --- a/src/error.rs +++ b/src/error.rs @@ -58,7 +58,7 @@ impl Error { unsafe { let domain = NSString::new(&self.domain); let code = self.code as NSInteger; - msg_send![class!(NSError), errorWithDomain:domain code:code userInfo:nil] + msg_send![class!(NSError), errorWithDomain: &*domain, code: code, userInfo: nil] } } } diff --git a/src/filesystem/save.rs b/src/filesystem/save.rs index e95082fc..fdec114c 100644 --- a/src/filesystem/save.rs +++ b/src/filesystem/save.rs @@ -95,7 +95,7 @@ impl FileSavePanel { let _: () = msg_send![&*self.panel, runModal]; completion.call((1,)); //beginWithCompletionHandler:completion.copy()]; - //let _: () = msg_send![&*self.panel, beginWithCompletionHandler:completion.copy()]; + //let _: () = msg_send![&*self.panel, beginWithCompletionHandler: &*completion.copy()]; } } } diff --git a/src/filesystem/select.rs b/src/filesystem/select.rs index 71b6f7d5..40807995 100644 --- a/src/filesystem/select.rs +++ b/src/filesystem/select.rs @@ -148,7 +148,7 @@ impl FileSelectPanel { }); unsafe { - let _: () = msg_send![&*self.panel, beginWithCompletionHandler:completion.copy()]; + let _: () = msg_send![&*self.panel, beginWithCompletionHandler: &*completion.copy()]; } } @@ -184,7 +184,11 @@ impl FileSelectPanel { }); unsafe { - let _: () = msg_send![&*self.panel, beginSheetModalForWindow:&*window.objc completionHandler:completion.copy()]; + let _: () = msg_send![ + &*self.panel, + beginSheetModalForWindow: &*window.objc, + completionHandler: &*completion.copy(), + ]; } } } diff --git a/src/foundation/urls/mod.rs b/src/foundation/urls/mod.rs index 4568a8ab..e4099bec 100644 --- a/src/foundation/urls/mod.rs +++ b/src/foundation/urls/mod.rs @@ -105,18 +105,22 @@ impl<'a> NSURL<'a> { // Mutability woes mean we just go through a match here to satisfy message passing needs. let bookmark_data = NSData::retain(match relative_to_url { Some(relative_url) => unsafe { - msg_send![&*self.objc, bookmarkDataWithOptions:opts - includingResourceValuesForKeys:resource_keys - relativeToURL:relative_url - error:nil + msg_send![ + &*self.objc, + bookmarkDataWithOptions: opts, + includingResourceValuesForKeys: resource_keys, + relativeToURL: &*relative_url, + error: nil, ] }, None => unsafe { - msg_send![&*self.objc, bookmarkDataWithOptions:opts - includingResourceValuesForKeys:resource_keys - relativeToURL:nil - error:nil + msg_send![ + &*self.objc, + bookmarkDataWithOptions: opts, + includingResourceValuesForKeys: resource_keys, + relativeToURL: nil, + error: nil, ] } }); diff --git a/src/image/image.rs b/src/image/image.rs index ea174fad..80cb2826 100644 --- a/src/image/image.rs +++ b/src/image/image.rs @@ -142,7 +142,7 @@ impl Image { Image(unsafe { let alloc: id = msg_send![Self::class(), alloc]; - ShareId::from_ptr(msg_send![alloc, initWithContentsOfFile: file_path]) + ShareId::from_ptr(msg_send![alloc, initWithContentsOfFile: &*file_path]) }) } @@ -161,7 +161,7 @@ impl Image { Image(unsafe { let alloc: id = msg_send![Self::class(), alloc]; - ShareId::from_ptr(msg_send![alloc, initWithData: data]) + ShareId::from_ptr(msg_send![alloc, initWithData: &*data]) }) } @@ -196,8 +196,11 @@ impl Image { true => { let icon = NSString::new(icon.to_sfsymbol_str()); let desc = NSString::new(accessibility_description); - msg_send![Self::class(), imageWithSystemSymbolName:&*icon - accessibilityDescription:&*desc] + msg_send![ + Self::class(), + imageWithSystemSymbolName: &*icon, + accessibilityDescription: &*desc, + ] }, false => { @@ -284,9 +287,11 @@ impl Image { let block = block.copy(); Image(unsafe { - let img: id = msg_send![Self::class(), imageWithSize:target_frame.size - flipped:YES - drawingHandler:block + let img: id = msg_send![ + Self::class(), + imageWithSize: target_frame.size, + flipped: YES, + drawingHandler: &*block, ]; ShareId::from_ptr(img) diff --git a/src/image/mod.rs b/src/image/mod.rs index 0ee6407e..66649c47 100644 --- a/src/image/mod.rs +++ b/src/image/mod.rs @@ -1,3 +1,5 @@ +use core_foundation::base::TCFType; + use crate::id_shim::ShareId; use objc::runtime::{Class, Object}; use objc::{msg_send, sel}; @@ -149,7 +151,7 @@ impl ImageView { /// Call this to set the background color for the backing layer. pub fn set_background_color>(&self, color: C) { self.objc.with_mut(|obj| unsafe { - let cg = color.as_ref().cg_color(); + let cg = color.as_ref().cg_color().as_concrete_TypeRef(); let layer: id = msg_send![obj, layer]; let _: () = msg_send![layer, setBackgroundColor: cg]; }); diff --git a/src/input/mod.rs b/src/input/mod.rs index e71fb9c5..4cdf616b 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -43,6 +43,8 @@ //! //! For more information on Autolayout, view the module or check out the examples folder. +use core_foundation::base::TCFType; + use crate::id_shim::ShareId; use objc::runtime::{Class, Object}; use objc::{class, msg_send, sel}; @@ -306,7 +308,7 @@ impl TextField { /// Call this to set the background color for the backing layer. pub fn set_background_color>(&self, color: C) { self.objc.with_mut(|obj| unsafe { - let cg = color.as_ref().cg_color(); + let cg = color.as_ref().cg_color().as_concrete_TypeRef(); let layer: id = msg_send![obj, layer]; let _: () = msg_send![layer, setBackgroundColor: cg]; }); diff --git a/src/layout/dimension.rs b/src/layout/dimension.rs index afcda720..74759e94 100644 --- a/src/layout/dimension.rs +++ b/src/layout/dimension.rs @@ -51,7 +51,7 @@ impl LayoutAnchorDimension { if let Self::Width(obj) | Self::Height(obj) = self { return LayoutConstraint::new(unsafe { let value = constant as CGFloat; - msg_send![*obj, constraintEqualToConstant: value] + msg_send![obj, constraintEqualToConstant: value] }); } @@ -63,7 +63,7 @@ impl LayoutAnchorDimension { if let Self::Width(obj) | Self::Height(obj) = self { return LayoutConstraint::new(unsafe { let value = constant as CGFloat; - msg_send![*obj, constraintGreaterThanOrEqualToConstant: value] + msg_send![obj, constraintGreaterThanOrEqualToConstant: value] }); } @@ -75,7 +75,7 @@ impl LayoutAnchorDimension { if let Self::Width(obj) | Self::Height(obj) = self { return LayoutConstraint::new(unsafe { let value = constant as CGFloat; - msg_send![*obj, constraintLessThanOrEqualToConstant: value] + msg_send![obj, constraintLessThanOrEqualToConstant: value] }); } @@ -112,21 +112,21 @@ impl LayoutAnchorDimension { /// Return a constraint equal to another dimension anchor. pub fn constraint_equal_to(&self, anchor_to: &LayoutAnchorDimension) -> LayoutConstraint { self.constraint_with(anchor_to, |from, to| unsafe { - msg_send![*from, constraintEqualToAnchor:&**to] + msg_send![from, constraintEqualToAnchor:&**to] }) } /// Return a constraint greater than or equal to another dimension anchor. pub fn constraint_greater_than_or_equal_to(&self, anchor_to: &LayoutAnchorDimension) -> LayoutConstraint { self.constraint_with(anchor_to, |from, to| unsafe { - msg_send![*from, constraintGreaterThanOrEqualToAnchor:&**to] + msg_send![from, constraintGreaterThanOrEqualToAnchor:&**to] }) } /// Return a constraint less than or equal to another dimension anchor. pub fn constraint_less_than_or_equal_to(&self, anchor_to: &LayoutAnchorDimension) -> LayoutConstraint { self.constraint_with(anchor_to, |from, to| unsafe { - msg_send![*from, constraintLessThanOrEqualToAnchor:&**to] + msg_send![from, constraintLessThanOrEqualToAnchor:&**to] }) } } diff --git a/src/layout/horizontal.rs b/src/layout/horizontal.rs index 754efaab..bb828633 100644 --- a/src/layout/horizontal.rs +++ b/src/layout/horizontal.rs @@ -160,21 +160,21 @@ impl LayoutAnchorX { /// Return a constraint equal to another horizontal anchor. pub fn constraint_equal_to(&self, anchor_to: &LayoutAnchorX) -> LayoutConstraint { self.constraint_with(anchor_to, |from, to| unsafe { - msg_send![*from, constraintEqualToAnchor:&**to] + msg_send![from, constraintEqualToAnchor:&**to] }) } /// Return a constraint greater than or equal to another horizontal anchor. pub fn constraint_greater_than_or_equal_to(&self, anchor_to: &LayoutAnchorX) -> LayoutConstraint { self.constraint_with(anchor_to, |from, to| unsafe { - msg_send![*from, constraintGreaterThanOrEqualToAnchor:&**to] + msg_send![from, constraintGreaterThanOrEqualToAnchor:&**to] }) } /// Return a constraint less than or equal to another horizontal anchor. pub fn constraint_less_than_or_equal_to(&self, anchor_to: &LayoutAnchorX) -> LayoutConstraint { self.constraint_with(anchor_to, |from, to| unsafe { - msg_send![*from, constraintLessThanOrEqualToAnchor:&**to] + msg_send![from, constraintLessThanOrEqualToAnchor:&**to] }) } } diff --git a/src/layout/vertical.rs b/src/layout/vertical.rs index db9c49ab..232945a7 100644 --- a/src/layout/vertical.rs +++ b/src/layout/vertical.rs @@ -79,21 +79,21 @@ impl LayoutAnchorY { /// Return a constraint equal to another vertical anchor. pub fn constraint_equal_to(&self, anchor_to: &LayoutAnchorY) -> LayoutConstraint { self.constraint_with(anchor_to, |from, to| unsafe { - msg_send![*from, constraintEqualToAnchor:&**to] + msg_send![from, constraintEqualToAnchor:&**to] }) } /// Return a constraint greater than or equal to another vertical anchor. pub fn constraint_greater_than_or_equal_to(&self, anchor_to: &LayoutAnchorY) -> LayoutConstraint { self.constraint_with(anchor_to, |from, to| unsafe { - msg_send![*from, constraintGreaterThanOrEqualToAnchor:&**to] + msg_send![from, constraintGreaterThanOrEqualToAnchor:&**to] }) } /// Return a constraint less than or equal to another vertical anchor. pub fn constraint_less_than_or_equal_to(&self, anchor_to: &LayoutAnchorY) -> LayoutConstraint { self.constraint_with(anchor_to, |from, to| unsafe { - msg_send![*from, constraintLessThanOrEqualToAnchor:&**to] + msg_send![from, constraintLessThanOrEqualToAnchor:&**to] }) } } diff --git a/src/listview/actions.rs b/src/listview/actions.rs index 7013c8fe..6059d005 100644 --- a/src/listview/actions.rs +++ b/src/listview/actions.rs @@ -65,9 +65,11 @@ impl RowAction { RowAction(unsafe { let cls = class!(NSTableViewRowAction); - Id::from_ptr(msg_send![cls, rowActionWithStyle:style - title:&*title - handler:block + Id::from_ptr(msg_send![ + cls, + rowActionWithStyle: style, + title: &*title, + handler: &*block, ]) }) } diff --git a/src/listview/mod.rs b/src/listview/mod.rs index fe4a0b98..4b924e4e 100644 --- a/src/listview/mod.rs +++ b/src/listview/mod.rs @@ -44,6 +44,8 @@ use std::collections::HashMap; +use core_foundation::base::TCFType; + use crate::id_shim::ShareId; use core_graphics::base::CGFloat; use objc::runtime::{Class, Object}; @@ -439,7 +441,7 @@ impl ListView { pub fn set_background_color>(&self, color: C) { // @TODO: This is wrong. self.objc.with_mut(|obj| unsafe { - let color = color.as_ref().cg_color(); + let color = color.as_ref().cg_color().as_concrete_TypeRef(); let layer: id = msg_send![obj, layer]; let _: () = msg_send![layer, setBackgroundColor: color]; }); diff --git a/src/pasteboard/mod.rs b/src/pasteboard/mod.rs index 68859da9..1db2f872 100644 --- a/src/pasteboard/mod.rs +++ b/src/pasteboard/mod.rs @@ -63,7 +63,7 @@ impl Pasteboard { let ptype: NSString = PasteboardType::String.into(); unsafe { - let _: () = msg_send![&*self.0, setString:&*contents forType:ptype]; + let _: () = msg_send![&*self.0, setString: &*contents, forType: &*ptype]; } } @@ -91,7 +91,7 @@ impl Pasteboard { unsafe { let class: id = msg_send![class!(NSURL), class]; let classes = NSArray::new(&[class]); - let contents: id = msg_send![&*self.0, readObjectsForClasses:classes options:nil]; + let contents: id = msg_send![&*self.0, readObjectsForClasses: &*classes, options: nil]; // This can happen if the Pasteboard server has an error in returning items. // In our case, we'll bubble up an error by checking the pasteboard. diff --git a/src/quicklook/mod.rs b/src/quicklook/mod.rs index 035da652..bca530d0 100644 --- a/src/quicklook/mod.rs +++ b/src/quicklook/mod.rs @@ -48,8 +48,11 @@ impl ThumbnailGenerator { let request = config.to_request(path); unsafe { - let _: () = msg_send![&*self.0, generateRepresentationsForRequest:request - updateHandler:block]; + let _: () = msg_send![ + &*self.0, + generateRepresentationsForRequest: request, + updateHandler: &*block, + ]; } } } diff --git a/src/scrollview/mod.rs b/src/scrollview/mod.rs index 13995ecf..16ee2dfa 100644 --- a/src/scrollview/mod.rs +++ b/src/scrollview/mod.rs @@ -42,6 +42,8 @@ //! //! For more information on Autolayout, view the module or check out the examples folder. +use core_foundation::base::TCFType; + use crate::id_shim::ShareId; use objc::runtime::{Class, Object}; use objc::{msg_send, sel}; @@ -296,7 +298,7 @@ impl ScrollView { pub fn set_background_color>(&self, color: C) { // @TODO: This is wrong. self.objc.with_mut(|obj| unsafe { - let color = color.as_ref().cg_color(); + let color = color.as_ref().cg_color().as_concrete_TypeRef(); let layer: id = msg_send![obj, layer]; let _: () = msg_send![layer, setBackgroundColor: color]; }); diff --git a/src/select/mod.rs b/src/select/mod.rs index d666c52a..ab8bcf3c 100644 --- a/src/select/mod.rs +++ b/src/select/mod.rs @@ -161,7 +161,7 @@ impl Select { pub fn add_item(&self, title: &str) { self.objc.with_mut(|obj| unsafe { let s = NSString::new(title); - let _: () = msg_send![obj, addItemWithTitle: s]; + let _: () = msg_send![obj, addItemWithTitle: &*s]; }); } diff --git a/src/switch.rs b/src/switch.rs index fbf173f1..8bee51c5 100644 --- a/src/switch.rs +++ b/src/switch.rs @@ -69,7 +69,7 @@ impl Switch { let title = NSString::new(text); let view: id = unsafe { - let button: id = msg_send![register_class(), buttonWithTitle:title target:nil action:nil]; + let button: id = msg_send![register_class(), buttonWithTitle: &*title, target: nil, action: nil]; #[cfg(feature = "autolayout")] let _: () = msg_send![button, setTranslatesAutoresizingMaskIntoConstraints: NO]; diff --git a/src/text/attributed_string.rs b/src/text/attributed_string.rs index 9ce1c804..f07cacfd 100644 --- a/src/text/attributed_string.rs +++ b/src/text/attributed_string.rs @@ -3,14 +3,13 @@ use std::ops::{Deref, DerefMut, Range}; use std::os::raw::c_char; use std::{fmt, slice, str}; -use core_foundation::base::CFRange; - use crate::id_shim::Id; use objc::runtime::Object; use objc::{class, msg_send, sel}; use crate::color::Color; use crate::foundation::{id, to_bool, NSString, BOOL, NO, YES}; +use crate::utils::CFRange; use super::Font; @@ -49,19 +48,25 @@ impl AttributedString { let range = CFRange::init(range.start, range.end); unsafe { - let _: () = msg_send![&*self.0, addAttribute:NSForegroundColorAttributeName - value:color - range:range + let _: () = msg_send![ + &*self.0, + addAttribute: NSForegroundColorAttributeName, + value: color, + range: range, ]; } } /// Set the font for the specified range. pub fn set_font(&mut self, font: Font, range: Range) { + let range = CFRange::init(range.start, range.end); + unsafe { - let _: () = msg_send![&*self.0, addAttribute:NSFontAttributeName - value:&*font - range:range + let _: () = msg_send![ + &*self.0, + addAttribute: NSFontAttributeName, + value: &*font, + range: range, ]; } } diff --git a/src/text/label/mod.rs b/src/text/label/mod.rs index 8d2514b6..417d9085 100644 --- a/src/text/label/mod.rs +++ b/src/text/label/mod.rs @@ -43,6 +43,8 @@ //! //! For more information on Autolayout, view the module or check out the examples folder. +use core_foundation::base::TCFType; + use crate::id_shim::ShareId; use objc::runtime::{Class, Object}; use objc::{msg_send, sel}; @@ -324,7 +326,7 @@ impl Label { // @TODO: This is wrong. // Needs to set ivar and such, akin to View. self.objc.with_mut(|obj| unsafe { - let color = color.as_ref().cg_color(); + let color = color.as_ref().cg_color().as_concrete_TypeRef(); let layer: id = msg_send![obj, layer]; let _: () = msg_send![layer, setBackgroundColor: color]; }); diff --git a/src/uikit/scene/config.rs b/src/uikit/scene/config.rs index 4a943d4f..a76d5fe2 100644 --- a/src/uikit/scene/config.rs +++ b/src/uikit/scene/config.rs @@ -24,7 +24,7 @@ impl SceneConfig { let role = NSString::from(role); let cls = class!(UISceneConfiguration); - let config: id = msg_send![cls, configurationWithName:name sessionRole:role]; + let config: id = msg_send![cls, configurationWithName: &*name, sessionRole: &*role]; let _: () = msg_send![config, setSceneClass: class!(UIWindowScene)]; diff --git a/src/uikit/scene/delegate.rs b/src/uikit/scene/delegate.rs index 1b80b409..2673b7c6 100644 --- a/src/uikit/scene/delegate.rs +++ b/src/uikit/scene/delegate.rs @@ -9,9 +9,9 @@ use crate::utils::load; pub(crate) static WINDOW_SCENE_PTR: &str = "rstWindowSceneDelegatePtr"; /// -extern "C" fn init Box>(this: &mut Object, _: Sel) -> id { +extern "C" fn init Box>(mut this: &mut Object, _: Sel) -> id { let x = unsafe { - *this = msg_send![super(this, class!(UIResponder)), init]; + this = msg_send![super(this, class!(UIResponder)), init]; let scene_delegate_vendor = SCENE_DELEGATE_VENDOR as *const F; let factory: &F = &*scene_delegate_vendor; diff --git a/src/user_notifications/mod.rs b/src/user_notifications/mod.rs index 4b7c0adf..f18f827e 100644 --- a/src/user_notifications/mod.rs +++ b/src/user_notifications/mod.rs @@ -27,7 +27,7 @@ impl NotificationCenter { unsafe { // @TODO: Revisit. let block = ConcreteBlock::new(|_: id, error: id| { - let localized_description = NSString::new(msg_send![error, localizedDescription]); + let localized_description = NSString::retain(msg_send![error, localizedDescription]); let e = localized_description.to_str(); if e != "" { println!("{:?}", e); @@ -41,7 +41,11 @@ impl NotificationCenter { } let center: id = msg_send![class!(UNUserNotificationCenter), currentNotificationCenter]; - let _: () = msg_send![center, requestAuthorizationWithOptions:opts completionHandler:block.copy()]; + let _: () = msg_send![ + center, + requestAuthorizationWithOptions:opts, + completionHandler: &*block.copy(), + ]; } } @@ -51,8 +55,12 @@ impl NotificationCenter { unsafe { let identifier = NSString::new(&uuidentifier); - let request: id = - msg_send![class!(UNNotificationRequest), requestWithIdentifier:identifier content:&*notification.0 trigger:nil]; + let request: id = msg_send![ + class!(UNNotificationRequest), + requestWithIdentifier: &*identifier, + content: &*notification.0, + trigger: nil, + ]; let center: id = msg_send![class!(UNUserNotificationCenter), currentNotificationCenter]; let _: () = msg_send![center, addNotificationRequest: request]; } diff --git a/src/user_notifications/notifications.rs b/src/user_notifications/notifications.rs index 2c0cbb24..770e2e01 100644 --- a/src/user_notifications/notifications.rs +++ b/src/user_notifications/notifications.rs @@ -21,8 +21,8 @@ impl Notification { Notification(unsafe { let content: id = msg_send![class!(UNMutableNotificationContent), new]; - let _: () = msg_send![content, setTitle: title]; - let _: () = msg_send![content, setBody: body]; + let _: () = msg_send![content, setTitle: &*title]; + let _: () = msg_send![content, setBody: &*body]; Id::from_ptr(content) }) } diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 9c65ef88..830c9661 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -2,6 +2,7 @@ //! belong to. These are typically internal, and if you rely on them... well, don't be surprised if //! they go away one day. +use core_foundation::base::CFIndex; use core_graphics::base::CGFloat; use objc::{class, msg_send, sel}; @@ -95,6 +96,26 @@ unsafe impl Encode for CGSize { const ENCODING: Encoding<'static> = Encoding::Struct("CGSize", &[CGFloat::ENCODING, CGFloat::ENCODING]); } +#[repr(C)] +#[derive(Clone, Copy, Debug, Default, PartialEq)] +pub struct CFRange { + pub location: CFIndex, + pub length: CFIndex +} + +impl CFRange { + pub fn init(location: CFIndex, length: CFIndex) -> CFRange { + CFRange { + location: location, + length: length + } + } +} + +unsafe impl Encode for CFRange { + const ENCODING: Encoding<'static> = Encoding::Struct("CFRange", &[CFIndex::ENCODING, CFIndex::ENCODING]); +} + /// A helper method for ensuring that Cocoa is running in multi-threaded mode. /// /// Why do we need this? According to Apple, if you're going to make use of standard POSIX threads, diff --git a/src/webview/class.rs b/src/webview/class.rs index ee468ab5..1ca540a3 100644 --- a/src/webview/class.rs +++ b/src/webview/class.rs @@ -68,8 +68,13 @@ extern "C" fn start_url_scheme_task(this: &Object, _: Sel, _ if let Some(content) = delegate.on_custom_protocol_request(uri_str) { let mime = MimeType::parse(&content, uri_str); let nsurlresponse: id = msg_send![class!(NSURLResponse), alloc]; - let response: id = msg_send![nsurlresponse, initWithURL:url MIMEType:NSString::new(&mime) - expectedContentLength:content.len() textEncodingName:null::()]; + let response: id = msg_send![ + nsurlresponse, + initWithURL: url, + MIMEType: &*NSString::new(&mime), + expectedContentLength: content.len(), + textEncodingName: null::(), + ]; let _: () = msg_send![task, didReceiveResponse: response]; // Send data @@ -94,7 +99,7 @@ extern "C" fn decide_policy_for_action(this: &Object, _: Sel let action = NavigationAction::new(action); delegate.policy_for_navigation_action(action, |policy| unsafe { - let handler = handler as *const Block<(NSInteger,), c_void>; + let handler = handler as *const Block<(NSInteger,), ()>; (*handler).call((policy.into(),)); }); } @@ -106,7 +111,7 @@ extern "C" fn decide_policy_for_response(this: &Object, _: S let response = NavigationResponse::new(response); delegate.policy_for_navigation_response(response, |policy| unsafe { - let handler = handler as *const Block<(NSInteger,), c_void>; + let handler = handler as *const Block<(NSInteger,), ()>; (*handler).call((policy.into(),)); }); } @@ -116,7 +121,7 @@ extern "C" fn run_open_panel(this: &Object, _: Sel, _: id, p let delegate = load::(this, WEBVIEW_DELEGATE_PTR); delegate.run_open_panel(params.into(), move |urls| unsafe { - let handler = handler as *const Block<(id,), c_void>; + let handler = handler as *const Block<(id,), ()>; match urls { Some(u) => { @@ -146,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), c_void>; + let handler = handler as *const Block<(objc::runtime::BOOL, id), ()>; let filename = NSString::from_retained(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 e40e909c..6c3fe6b0 100644 --- a/src/webview/config.rs +++ b/src/webview/config.rs @@ -47,10 +47,15 @@ impl WebViewConfig { unsafe { let alloc: id = msg_send![class!(WKUserScript), alloc]; - let user_script: id = msg_send![alloc, initWithSource:source injectionTime:at forMainFrameOnly:match main_frame_only { - true => YES, - false => NO - }]; + let user_script: id = msg_send![ + alloc, + initWithSource: &*source, + injectionTime: at, + forMainFrameOnly: match main_frame_only { + true => YES, + false => NO + }, + ]; let content_controller: id = msg_send![&*self.objc, userContentController]; let _: () = msg_send![content_controller, addUserScript: user_script]; @@ -70,7 +75,7 @@ impl WebViewConfig { unsafe { let yes: id = msg_send![class!(NSNumber), numberWithBool: YES]; let preferences: id = msg_send![&*self.objc, preferences]; - let _: () = msg_send![preferences, setValue:yes forKey:key]; + let _: () = msg_send![preferences, setValue: yes, forKey: &*key]; } }