Skip to content

Commit ee57388

Browse files
committed
Replace BOOL with Bool when declaring delegates
This makes cacao compile on Aarch64 again
1 parent 2c402a3 commit ee57388

File tree

16 files changed

+132
-216
lines changed

16 files changed

+132
-216
lines changed

ARCHITECTURE.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -401,12 +401,12 @@ to the Rust `ViewDelegate` implementation.
401401
The methods we're setting up can range from simple to complex - take `isFlipped`:
402402

403403
``` rust
404-
extern "C" fn is_flipped(_: &Object, _: Sel) -> BOOL {
405-
return YES;
404+
extern "C" fn is_flipped(_: &Object, _: Sel) -> Bool {
405+
return Bool::YES;
406406
}
407407
```
408408

409-
Here, we just want to tell `NSView` to use top,left as the origin point, so we need to respond `YES` in this subclass method.
409+
Here, we just want to tell `NSView` to use top,left as the origin point, so we need to respond `Bool::YES` in this subclass method.
410410

411411
``` rust
412412
extern "C" fn dragging_entered<T: ViewDelegate>(this: &mut Object, _: Sel, info: id) -> NSUInteger {

src/appkit/app/delegate.rs

+27-55
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use std::ffi::c_void;
66

77
use block::Block;
8-
use objc::runtime::{Class, Object, Sel};
8+
use objc::runtime::{Bool, Class, Object, Sel};
99
use objc::{msg_send, sel};
1010
use url::Url;
1111

@@ -14,7 +14,7 @@ use crate::appkit::printing::PrintSettings;
1414
#[cfg(feature = "cloudkit")]
1515
use crate::cloudkit::share::CKShareMetaData;
1616
use crate::error::Error;
17-
use crate::foundation::{id, load_or_register_class, nil, to_bool, NSArray, NSString, NSUInteger, BOOL, NO, YES};
17+
use crate::foundation::{id, load_or_register_class, nil, NSArray, NSString, NSUInteger};
1818
use crate::user_activity::UserActivity;
1919

2020
/// A handy method for grabbing our `AppDelegate` from the pointer. This is different from our
@@ -99,11 +99,8 @@ extern "C" fn did_update<T: AppDelegate>(this: &Object, _: Sel, _: id) {
9999

100100
/// Fires when the Application Delegate receives a
101101
/// `applicationShouldHandleReopen:hasVisibleWindows:` notification.
102-
extern "C" fn should_handle_reopen<T: AppDelegate>(this: &Object, _: Sel, _: id, has_visible_windows: BOOL) -> BOOL {
103-
match app::<T>(this).should_handle_reopen(to_bool(has_visible_windows)) {
104-
true => YES,
105-
false => NO
106-
}
102+
extern "C" fn should_handle_reopen<T: AppDelegate>(this: &Object, _: Sel, _: id, has_visible_windows: Bool) -> Bool {
103+
Bool::new(app::<T>(this).should_handle_reopen(has_visible_windows.as_bool()))
107104
}
108105

109106
/// Fires when the application delegate receives a `applicationDockMenu:` request.
@@ -128,29 +125,23 @@ extern "C" fn did_change_screen_parameters<T: AppDelegate>(this: &Object, _: Sel
128125

129126
/// Fires when the application receives a `application:willContinueUserActivityWithType:`
130127
/// notification.
131-
extern "C" fn will_continue_user_activity_with_type<T: AppDelegate>(this: &Object, _: Sel, _: id, activity_type: id) -> BOOL {
128+
extern "C" fn will_continue_user_activity_with_type<T: AppDelegate>(this: &Object, _: Sel, _: id, activity_type: id) -> Bool {
132129
let activity = NSString::retain(activity_type);
133130

134-
match app::<T>(this).will_continue_user_activity(activity.to_str()) {
135-
true => YES,
136-
false => NO
137-
}
131+
Bool::new(app::<T>(this).will_continue_user_activity(activity.to_str()))
138132
}
139133

140134
/// Fires when the application receives a `application:continueUserActivity:restorationHandler:` notification.
141-
extern "C" fn continue_user_activity<T: AppDelegate>(this: &Object, _: Sel, _: id, activity: id, handler: id) -> BOOL {
135+
extern "C" fn continue_user_activity<T: AppDelegate>(this: &Object, _: Sel, _: id, activity: id, handler: id) -> Bool {
142136
// @TODO: This needs to support restorable objects, but it involves a larger question about how
143137
// much `NSObject` retainping we want to do here. For now, pass the handler for whenever it's
144138
// useful.
145139
let activity = UserActivity::with_inner(activity);
146140

147-
match app::<T>(this).continue_user_activity(activity, || unsafe {
141+
Bool::new(app::<T>(this).continue_user_activity(activity, || unsafe {
148142
let handler = handler as *const Block<(id,), ()>;
149143
(*handler).call((nil,));
150-
}) {
151-
true => YES,
152-
false => NO
153-
}
144+
}))
154145
}
155146

156147
/// Fires when the application receives a
@@ -199,57 +190,39 @@ extern "C" fn open_urls<T: AppDelegate>(this: &Object, _: Sel, _: id, file_urls:
199190
}
200191

201192
/// Fires when the application receives an `application:openFileWithoutUI:` message.
202-
extern "C" fn open_file_without_ui<T: AppDelegate>(this: &Object, _: Sel, _: id, file: id) -> BOOL {
193+
extern "C" fn open_file_without_ui<T: AppDelegate>(this: &Object, _: Sel, _: id, file: id) -> Bool {
203194
let filename = NSString::retain(file);
204195

205-
match app::<T>(this).open_file_without_ui(filename.to_str()) {
206-
true => YES,
207-
false => NO
208-
}
196+
Bool::new(app::<T>(this).open_file_without_ui(filename.to_str()))
209197
}
210198

211199
/// Fired when the application receives an `applicationShouldOpenUntitledFile:` message.
212-
extern "C" fn should_open_untitled_file<T: AppDelegate>(this: &Object, _: Sel, _: id) -> BOOL {
213-
match app::<T>(this).should_open_untitled_file() {
214-
true => YES,
215-
false => NO
216-
}
200+
extern "C" fn should_open_untitled_file<T: AppDelegate>(this: &Object, _: Sel, _: id) -> Bool {
201+
Bool::new(app::<T>(this).should_open_untitled_file())
217202
}
218203

219204
/// Fired when the application receives an `applicationShouldTerminateAfterLastWindowClosed:` message.
220-
extern "C" fn should_terminate_after_last_window_closed<T: AppDelegate>(this: &Object, _: Sel, _: id) -> BOOL {
221-
match app::<T>(this).should_terminate_after_last_window_closed() {
222-
true => YES,
223-
false => NO
224-
}
205+
extern "C" fn should_terminate_after_last_window_closed<T: AppDelegate>(this: &Object, _: Sel, _: id) -> Bool {
206+
Bool::new(app::<T>(this).should_terminate_after_last_window_closed())
225207
}
226208

227209
/// Fired when the application receives an `applicationOpenUntitledFile:` message.
228-
extern "C" fn open_untitled_file<T: AppDelegate>(this: &Object, _: Sel, _: id) -> BOOL {
229-
match app::<T>(this).open_untitled_file() {
230-
true => YES,
231-
false => NO
232-
}
210+
extern "C" fn open_untitled_file<T: AppDelegate>(this: &Object, _: Sel, _: id) -> Bool {
211+
Bool::new(app::<T>(this).open_untitled_file())
233212
}
234213

235214
/// Fired when the application receives an `application:openTempFile:` message.
236-
extern "C" fn open_temp_file<T: AppDelegate>(this: &Object, _: Sel, _: id, filename: id) -> BOOL {
215+
extern "C" fn open_temp_file<T: AppDelegate>(this: &Object, _: Sel, _: id, filename: id) -> Bool {
237216
let filename = NSString::retain(filename);
238217

239-
match app::<T>(this).open_temp_file(filename.to_str()) {
240-
true => YES,
241-
false => NO
242-
}
218+
Bool::new(app::<T>(this).open_temp_file(filename.to_str()))
243219
}
244220

245221
/// Fired when the application receives an `application:printFile:` message.
246-
extern "C" fn print_file<T: AppDelegate>(this: &Object, _: Sel, _: id, file: id) -> BOOL {
222+
extern "C" fn print_file<T: AppDelegate>(this: &Object, _: Sel, _: id, file: id) -> Bool {
247223
let filename = NSString::retain(file);
248224

249-
match app::<T>(this).print_file(filename.to_str()) {
250-
true => YES,
251-
false => NO
252-
}
225+
Bool::new(app::<T>(this).print_file(filename.to_str()))
253226
}
254227

255228
/// Fired when the application receives an `application:printFiles:withSettings:showPrintPanels:`
@@ -260,7 +233,7 @@ extern "C" fn print_files<T: AppDelegate>(
260233
_: id,
261234
files: id,
262235
settings: id,
263-
show_print_panels: BOOL
236+
show_print_panels: Bool
264237
) -> NSUInteger {
265238
let files = NSArray::retain(files)
266239
.iter()
@@ -269,7 +242,9 @@ extern "C" fn print_files<T: AppDelegate>(
269242

270243
let settings = PrintSettings::with_inner(settings);
271244

272-
app::<T>(this).print_files(files, settings, to_bool(show_print_panels)).into()
245+
app::<T>(this)
246+
.print_files(files, settings, show_print_panels.as_bool())
247+
.into()
273248
}
274249

275250
/// Called when the application's occlusion state has changed.
@@ -280,13 +255,10 @@ extern "C" fn did_change_occlusion_state<T: AppDelegate>(this: &Object, _: Sel,
280255
/// Called when the application receives an `application:delegateHandlesKey:` message.
281256
/// Note: this may not fire in sandboxed applications. Apple's documentation is unclear on the
282257
/// matter.
283-
extern "C" fn delegate_handles_key<T: AppDelegate>(this: &Object, _: Sel, _: id, key: id) -> BOOL {
258+
extern "C" fn delegate_handles_key<T: AppDelegate>(this: &Object, _: Sel, _: id, key: id) -> Bool {
284259
let key = NSString::retain(key);
285260

286-
match app::<T>(this).delegate_handles_key(key.to_str()) {
287-
true => YES,
288-
false => NO
289-
}
261+
Bool::new(app::<T>(this).delegate_handles_key(key.to_str()))
290262
}
291263

292264
/// Registers an `NSObject` application delegate, and configures it for the various callbacks and

src/appkit/toolbar/class.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
use std::sync::Once;
44

55
use objc::declare::ClassDecl;
6-
use objc::runtime::{Class, Object, Sel};
6+
use objc::runtime::{Bool, Class, Object, Sel};
77
use objc::{class, msg_send, sel};
88

99
use crate::appkit::toolbar::{ToolbarDelegate, TOOLBAR_PTR};
10-
use crate::foundation::{id, load_or_register_class, NSArray, NSString, BOOL};
10+
use crate::foundation::{id, load_or_register_class, NSArray, NSString};
1111
use crate::utils::load;
1212

1313
/// Retrieves and passes the allowed item identifiers for this toolbar.
@@ -54,7 +54,7 @@ extern "C" fn selectable_item_identifiers<T: ToolbarDelegate>(this: &Object, _:
5454

5555
/// Loads the controller, grabs whatever item is for this identifier, and returns what the
5656
/// Objective-C runtime needs.
57-
extern "C" fn item_for_identifier<T: ToolbarDelegate>(this: &Object, _: Sel, _: id, identifier: id, _: BOOL) -> id {
57+
extern "C" fn item_for_identifier<T: ToolbarDelegate>(this: &Object, _: Sel, _: id, identifier: id, _: Bool) -> id {
5858
let toolbar = load::<T>(this, TOOLBAR_PTR);
5959
let identifier = NSString::from_retained(identifier);
6060

src/appkit/window/class.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,19 @@ use std::sync::Once;
66
use core_graphics::base::CGFloat;
77

88
use objc::declare::ClassDecl;
9-
use objc::runtime::{Class, Object, Sel};
9+
use objc::runtime::{Bool, Class, Object, Sel};
1010
use objc::{class, sel};
1111

1212
use crate::appkit::window::{WindowDelegate, WINDOW_DELEGATE_PTR};
13-
use crate::foundation::{id, load_or_register_class, NSUInteger, BOOL, NO, YES};
13+
use crate::foundation::{id, load_or_register_class, NSUInteger};
1414
use crate::utils::{load, CGSize};
1515

1616
/// Called when an `NSWindowDelegate` receives a `windowWillClose:` event.
1717
/// Good place to clean up memory and what not.
18-
extern "C" fn should_close<T: WindowDelegate>(this: &Object, _: Sel, _: id) -> BOOL {
18+
extern "C" fn should_close<T: WindowDelegate>(this: &Object, _: Sel, _: id) -> Bool {
1919
let window = load::<T>(this, WINDOW_DELEGATE_PTR);
2020

21-
match window.should_close() {
22-
true => YES,
23-
false => NO
24-
}
21+
Bool::new(window.should_close())
2522
}
2623

2724
/// Called when an `NSWindowDelegate` receives a `windowWillClose:` event.

src/image/image.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use objc::rc::{Id, Shared};
2-
use objc::runtime::{Class, Object};
2+
use objc::runtime::{Bool, Class, Object};
33

44
use objc::{class, msg_send, msg_send_id, sel};
55

@@ -12,7 +12,7 @@ use core_graphics::{
1212
};
1313

1414
use super::icons::*;
15-
use crate::foundation::{id, NSData, NSString, NO, NSURL, YES};
15+
use crate::foundation::{id, NSData, NSString, NSURL};
1616
use crate::utils::os;
1717

1818
/// Specifies resizing behavior for image drawing.
@@ -280,10 +280,7 @@ impl Image {
280280

281281
let _: () = msg_send![class!(NSGraphicsContext), restoreGraphicsState];
282282

283-
match result {
284-
true => YES,
285-
false => NO
286-
}
283+
Bool::new(result)
287284
});
288285
let block = block.copy();
289286

src/input/appkit.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use objc::rc::{Id, Owned};
2-
use objc::runtime::{Class, Object, Sel, BOOL};
2+
use objc::runtime::{Bool, Class, Object, Sel};
33
use objc::{msg_send, sel};
44

5-
use crate::foundation::{id, load_or_register_class, NSString, NO, YES};
5+
use crate::foundation::{id, load_or_register_class, NSString};
66
use crate::input::{TextFieldDelegate, TEXTFIELD_DELEGATE_PTR};
77
use crate::utils::load;
88

@@ -25,23 +25,17 @@ extern "C" fn text_did_change<T: TextFieldDelegate>(this: &Object, _: Sel, _info
2525
view.text_did_change(s.to_str());
2626
}
2727

28-
extern "C" fn text_should_begin_editing<T: TextFieldDelegate>(this: &Object, _: Sel, _info: id) -> BOOL {
28+
extern "C" fn text_should_begin_editing<T: TextFieldDelegate>(this: &Object, _: Sel, _info: id) -> Bool {
2929
let view = load::<T>(this, TEXTFIELD_DELEGATE_PTR);
3030
let s = NSString::retain(unsafe { msg_send![this, stringValue] });
3131

32-
match view.text_should_begin_editing(s.to_str()) {
33-
true => YES,
34-
false => NO
35-
}
32+
Bool::new(view.text_should_begin_editing(s.to_str()))
3633
}
3734

38-
extern "C" fn text_should_end_editing<T: TextFieldDelegate>(this: &Object, _: Sel, _info: id) -> BOOL {
35+
extern "C" fn text_should_end_editing<T: TextFieldDelegate>(this: &Object, _: Sel, _info: id) -> Bool {
3936
let view = load::<T>(this, TEXTFIELD_DELEGATE_PTR);
4037
let s = NSString::retain(unsafe { msg_send![this, stringValue] });
41-
match view.text_should_end_editing(s.to_str()) {
42-
true => YES,
43-
false => NO
44-
}
38+
Bool::new(view.text_should_end_editing(s.to_str()))
4539
}
4640

4741
/// Injects an `NSTextField` subclass. This is used for the default views that don't use delegates - we

src/input/uikit.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use std::sync::Once;
22

33
use objc::declare::ClassDecl;
4-
use objc::runtime::{Class, Object, Sel, BOOL};
4+
use objc::runtime::{Bool, Class, Object, Sel};
55
use objc::{class, msg_send, sel};
66

7-
use crate::foundation::{id, load_or_register_class, NSString, NSUInteger, NO, YES};
7+
use crate::foundation::{id, load_or_register_class, NSString, NSUInteger};
88
use crate::input::{TextFieldDelegate, TEXTFIELD_DELEGATE_PTR};
99
use crate::utils::load;
1010

@@ -27,23 +27,17 @@ extern "C" fn text_did_change<T: TextFieldDelegate>(this: &Object, _: Sel, _info
2727
view.text_did_change(s.to_str());
2828
}
2929

30-
extern "C" fn text_should_begin_editing<T: TextFieldDelegate>(this: &Object, _: Sel, _info: id) -> BOOL {
30+
extern "C" fn text_should_begin_editing<T: TextFieldDelegate>(this: &Object, _: Sel, _info: id) -> Bool {
3131
let view = load::<T>(this, TEXTFIELD_DELEGATE_PTR);
3232
let s = NSString::retain(unsafe { msg_send![this, text] });
3333

34-
match view.text_should_begin_editing(s.to_str()) {
35-
true => YES,
36-
false => NO
37-
}
34+
Bool::new(view.text_should_begin_editing(s.to_str()))
3835
}
3936

40-
extern "C" fn text_should_end_editing<T: TextFieldDelegate>(this: &Object, _: Sel, _info: id) -> BOOL {
37+
extern "C" fn text_should_end_editing<T: TextFieldDelegate>(this: &Object, _: Sel, _info: id) -> Bool {
4138
let view = load::<T>(this, TEXTFIELD_DELEGATE_PTR);
4239
let s = NSString::retain(unsafe { msg_send![this, text] });
43-
match view.text_should_end_editing(s.to_str()) {
44-
true => YES,
45-
false => NO
46-
}
40+
Bool::new(view.text_should_end_editing(s.to_str()))
4741
}
4842

4943
/// Injects an `UITextField` subclass. This is used for the default views that don't use delegates - we

0 commit comments

Comments
 (0)