Skip to content

Commit

Permalink
Fix message sends arguments that do not implement Encode
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Aug 1, 2023
1 parent 9fa9bd4 commit e77801c
Show file tree
Hide file tree
Showing 37 changed files with 179 additions and 98 deletions.
6 changes: 3 additions & 3 deletions src/appkit/alert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
Expand Down
9 changes: 6 additions & 3 deletions src/appkit/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}

Expand All @@ -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,
];
}
}
}
2 changes: 1 addition & 1 deletion src/appkit/app/delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ extern "C" fn continue_user_activity<T: AppDelegate>(this: &Object, _: Sel, _: i
let activity = UserActivity::with_inner(activity);

match app::<T>(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,
Expand Down
14 changes: 10 additions & 4 deletions src/appkit/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
])
})
}

Expand All @@ -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,
])
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/appkit/haptics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub struct HapticFeedbackPerformer(pub ShareId<Object>);
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];
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/appkit/menu/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/appkit/toolbar/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
};

Expand Down
2 changes: 1 addition & 1 deletion src/appkit/toolbar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/appkit/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ impl<T> Window<T> {
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];
}
}

Expand All @@ -216,7 +216,7 @@ impl<T> Window<T> {

unsafe {
let subtitle = NSString::new(subtitle);
let _: () = msg_send![&*self.objc, setSubtitle: subtitle];
let _: () = msg_send![&*self.objc, setSubtitle: &*subtitle];
}
}

Expand Down Expand Up @@ -252,7 +252,7 @@ impl<T> Window<T> {
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];
}
}

Expand Down Expand Up @@ -514,7 +514,7 @@ impl<T> Window<T> {
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];
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/color/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)))
}
Expand Down Expand Up @@ -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])
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/defaults/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/filesystem/save.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()];
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/filesystem/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl FileSelectPanel {
});

unsafe {
let _: () = msg_send![&*self.panel, beginWithCompletionHandler:completion.copy()];
let _: () = msg_send![&*self.panel, beginWithCompletionHandler: &*completion.copy()];
}
}

Expand Down Expand Up @@ -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(),
];
}
}
}
Expand Down
20 changes: 12 additions & 8 deletions src/foundation/urls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]
}
});
Expand Down
19 changes: 12 additions & 7 deletions src/image/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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])
})
}

Expand All @@ -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])
})
}

Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion src/image/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use core_foundation::base::TCFType;

use crate::id_shim::ShareId;
use objc::runtime::{Class, Object};
use objc::{msg_send, sel};
Expand Down Expand Up @@ -149,7 +151,7 @@ impl ImageView {
/// Call this to set the background color for the backing layer.
pub fn set_background_color<C: AsRef<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];
});
Expand Down
4 changes: 3 additions & 1 deletion src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -306,7 +308,7 @@ impl<T> TextField<T> {
/// Call this to set the background color for the backing layer.
pub fn set_background_color<C: AsRef<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];
});
Expand Down
12 changes: 6 additions & 6 deletions src/layout/dimension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
});
}

Expand All @@ -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]
});
}

Expand All @@ -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]
});
}

Expand Down Expand Up @@ -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]
})
}
}
Loading

0 comments on commit e77801c

Please sign in to comment.