Skip to content

Commit

Permalink
Fix add_method calls
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Sep 5, 2023
1 parent b4719f7 commit 86d3eeb
Show file tree
Hide file tree
Showing 23 changed files with 192 additions and 286 deletions.
6 changes: 3 additions & 3 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ pub(crate) fn register_view_class() -> *const Class {
let superclass = class!(NSView);
let mut decl = ClassDecl::new("RSTView", superclass).unwrap();

decl.add_method(sel!(isFlipped), enforce_normalcy as extern "C" fn(&Object, _) -> BOOL);
decl.add_method(sel!(isFlipped), enforce_normalcy as extern "C" fn(_, _) -> _);

decl.add_ivar::<id>(BACKGROUND_COLOR);

Expand All @@ -384,12 +384,12 @@ pub(crate) fn register_view_class_with_delegate<T: ViewDelegate>(instance: &T) -

decl.add_method(
sel!(isFlipped),
enforce_normalcy as extern "C" fn(&Object, _) -> BOOL
enforce_normalcy as extern "C" fn(_, _) -> _,
);

decl.add_method(
sel!(draggingEntered:),
dragging_entered::<T> as extern "C" fn (&mut Object, _, _) -> NSUInteger
dragging_entered::<T> as extern "C" fn (_, _, _) -> _,
);
})
}
Expand Down
81 changes: 36 additions & 45 deletions src/appkit/app/delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,150 +298,141 @@ pub(crate) fn register_app_delegate_class<T: AppDelegate + AppDelegate>() -> *co
// Launching Applications
decl.add_method(
sel!(applicationWillFinishLaunching:),
will_finish_launching::<T> as extern "C" fn(&Object, _, _)
will_finish_launching::<T> as extern "C" fn(_, _, _)
);
decl.add_method(
sel!(applicationDidFinishLaunching:),
did_finish_launching::<T> as extern "C" fn(&Object, _, _)
did_finish_launching::<T> as extern "C" fn(_, _, _)
);

// Managing Active Status
decl.add_method(
sel!(applicationWillBecomeActive:),
will_become_active::<T> as extern "C" fn(&Object, _, _)
will_become_active::<T> as extern "C" fn(_, _, _)
);
decl.add_method(
sel!(applicationDidBecomeActive:),
did_become_active::<T> as extern "C" fn(&Object, _, _)
did_become_active::<T> as extern "C" fn(_, _, _)
);
decl.add_method(
sel!(applicationWillResignActive:),
will_resign_active::<T> as extern "C" fn(&Object, _, _)
will_resign_active::<T> as extern "C" fn(_, _, _)
);
decl.add_method(
sel!(applicationDidResignActive:),
did_resign_active::<T> as extern "C" fn(&Object, _, _)
did_resign_active::<T> as extern "C" fn(_, _, _)
);

// Terminating Applications
decl.add_method(
sel!(applicationShouldTerminate:),
should_terminate::<T> as extern "C" fn(&Object, _, _) -> NSUInteger
);
decl.add_method(
sel!(applicationWillTerminate:),
will_terminate::<T> as extern "C" fn(&Object, _, _)
should_terminate::<T> as extern "C" fn(_, _, _) -> _
);
decl.add_method(sel!(applicationWillTerminate:), will_terminate::<T> as extern "C" fn(_, _, _));
decl.add_method(
sel!(applicationShouldTerminateAfterLastWindowClosed:),
should_terminate_after_last_window_closed::<T> as extern "C" fn(&Object, _, _) -> BOOL
should_terminate_after_last_window_closed::<T> as extern "C" fn(_, _, _) -> _
);

// Hiding Applications
decl.add_method(sel!(applicationWillHide:), will_hide::<T> as extern "C" fn(&Object, _, _));
decl.add_method(sel!(applicationDidHide:), did_hide::<T> as extern "C" fn(&Object, _, _));
decl.add_method(sel!(applicationWillUnhide:), will_unhide::<T> as extern "C" fn(&Object, _, _));
decl.add_method(sel!(applicationDidUnhide:), did_unhide::<T> as extern "C" fn(&Object, _, _));
decl.add_method(sel!(applicationWillHide:), will_hide::<T> as extern "C" fn(_, _, _));
decl.add_method(sel!(applicationDidHide:), did_hide::<T> as extern "C" fn(_, _, _));
decl.add_method(sel!(applicationWillUnhide:), will_unhide::<T> as extern "C" fn(_, _, _));
decl.add_method(sel!(applicationDidUnhide:), did_unhide::<T> as extern "C" fn(_, _, _));

// Managing Windows
decl.add_method(sel!(applicationWillUpdate:), will_update::<T> as extern "C" fn(&Object, _, _));
decl.add_method(sel!(applicationDidUpdate:), did_update::<T> as extern "C" fn(&Object, _, _));
decl.add_method(sel!(applicationWillUpdate:), will_update::<T> as extern "C" fn(_, _, _));
decl.add_method(sel!(applicationDidUpdate:), did_update::<T> as extern "C" fn(_, _, _));
decl.add_method(
sel!(applicationShouldHandleReopen:hasVisibleWindows:),
should_handle_reopen::<T> as extern "C" fn(&Object, _, _, BOOL) -> BOOL
should_handle_reopen::<T> as extern "C" fn(_, _, _, _) -> _
);

// Dock Menu
decl.add_method(
sel!(applicationDockMenu:),
dock_menu::<T> as extern "C" fn(&Object, _, _) -> id
);
decl.add_method(sel!(applicationDockMenu:), dock_menu::<T> as extern "C" fn(_, _, _) -> _);

// Displaying Errors
decl.add_method(
sel!(application:willPresentError:),
will_present_error::<T> as extern "C" fn(&Object, _, _, id) -> id
will_present_error::<T> as extern "C" fn(_, _, _, _) -> _
);

// Managing the Screen
decl.add_method(
sel!(applicationDidChangeScreenParameters:),
did_change_screen_parameters::<T> as extern "C" fn(&Object, _, _)
did_change_screen_parameters::<T> as extern "C" fn(_, _, _)
);
decl.add_method(
sel!(applicationDidChangeOcclusionState:),
did_change_occlusion_state::<T> as extern "C" fn(&Object, _, _)
did_change_occlusion_state::<T> as extern "C" fn(_, _, _)
);

// User Activities
decl.add_method(
sel!(application:willContinueUserActivityWithType:),
will_continue_user_activity_with_type::<T> as extern "C" fn(&Object, _, _, id) -> BOOL
will_continue_user_activity_with_type::<T> as extern "C" fn(_, _, _, _) -> _
);
decl.add_method(
sel!(application:continueUserActivity:restorationHandler:),
continue_user_activity::<T> as extern "C" fn(&Object, _, _, id, id) -> BOOL
continue_user_activity::<T> as extern "C" fn(_, _, _, _, _) -> _
);
decl.add_method(
sel!(application:didFailToContinueUserActivityWithType:error:),
failed_to_continue_user_activity::<T> as extern "C" fn(&Object, _, _, id, id)
failed_to_continue_user_activity::<T> as extern "C" fn(_, _, _, _, _)
);
decl.add_method(
sel!(application:didUpdateUserActivity:),
did_update_user_activity::<T> as extern "C" fn(&Object, _, _, id)
did_update_user_activity::<T> as extern "C" fn(_, _, _, _)
);

// Handling push notifications
decl.add_method(
sel!(application:didRegisterForRemoteNotificationsWithDeviceToken:),
registered_for_remote_notifications::<T> as extern "C" fn(&Object, _, _, id)
registered_for_remote_notifications::<T> as extern "C" fn(_, _, _, _)
);
decl.add_method(
sel!(application:didFailToRegisterForRemoteNotificationsWithError:),
failed_to_register_for_remote_notifications::<T> as extern "C" fn(&Object, _, _, id)
failed_to_register_for_remote_notifications::<T> as extern "C" fn(_, _, _, _)
);
decl.add_method(
sel!(application:didReceiveRemoteNotification:),
did_receive_remote_notification::<T> as extern "C" fn(&Object, _, _, id)
did_receive_remote_notification::<T> as extern "C" fn(_, _, _, _)
);

// CloudKit
#[cfg(feature = "cloudkit")]
decl.add_method(
sel!(application:userDidAcceptCloudKitShareWithMetadata:),
accepted_cloudkit_share::<T> as extern "C" fn(&Object, _, _, id)
accepted_cloudkit_share::<T> as extern "C" fn(_, _, _, _)
);

// Opening Files
decl.add_method(
sel!(application:openURLs:),
open_urls::<T> as extern "C" fn(&Object, _, _, id)
);
decl.add_method(sel!(application:openURLs:), open_urls::<T> as extern "C" fn(_, _, _, _));
decl.add_method(
sel!(application:openFileWithoutUI:),
open_file_without_ui::<T> as extern "C" fn(&Object, _, _, id) -> BOOL
open_file_without_ui::<T> as extern "C" fn(_, _, _, _) -> _
);
decl.add_method(
sel!(applicationShouldOpenUntitledFile:),
should_open_untitled_file::<T> as extern "C" fn(&Object, _, _) -> BOOL
should_open_untitled_file::<T> as extern "C" fn(_, _, _) -> _
);
decl.add_method(
sel!(applicationOpenUntitledFile:),
open_untitled_file::<T> as extern "C" fn(&Object, _, _) -> BOOL
open_untitled_file::<T> as extern "C" fn(_, _, _) -> _
);
decl.add_method(
sel!(application:openTempFile:),
open_temp_file::<T> as extern "C" fn(&Object, _, _, id) -> BOOL
open_temp_file::<T> as extern "C" fn(_, _, _, _) -> _
);

// Printing
decl.add_method(
sel!(application:printFile:),
print_file::<T> as extern "C" fn(&Object, _, _, id) -> BOOL
print_file::<T> as extern "C" fn(_, _, _, _) -> _
);
decl.add_method(
sel!(application:printFiles:withSettings:showPrintPanels:),
print_files::<T> as extern "C" fn(&Object, _, id, id, id, BOOL) -> NSUInteger
print_files::<T> as extern "C" fn(_, _, _, _, _, _) -> _
);

// @TODO: Restoring Application State
Expand All @@ -450,7 +441,7 @@ pub(crate) fn register_app_delegate_class<T: AppDelegate + AppDelegate>() -> *co
// Scripting
decl.add_method(
sel!(application:delegateHandlesKey:),
delegate_handles_key::<T> as extern "C" fn(&Object, _, _, id) -> BOOL
delegate_handles_key::<T> as extern "C" fn(_, _, _, _) -> _
);
})
}
4 changes: 2 additions & 2 deletions src/appkit/menu/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ pub(crate) fn register_menu_item_class() -> *const Class {
load_or_register_class("NSMenuItem", "CacaoMenuItem", |decl| unsafe {
decl.add_ivar::<usize>(BLOCK_PTR);

decl.add_method(sel!(dealloc), dealloc_cacao_menuitem as extern "C" fn(&Object, _));
decl.add_method(sel!(fireBlockAction:), fire_block_action as extern "C" fn(&Object, _, id));
decl.add_method(sel!(dealloc), dealloc_cacao_menuitem as extern "C" fn(_, _));
decl.add_method(sel!(fireBlockAction:), fire_block_action as extern "C" fn(_, _, _));
})
}
8 changes: 4 additions & 4 deletions src/appkit/toolbar/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,19 @@ pub(crate) fn register_toolbar_class<T: ToolbarDelegate>(instance: &T) -> *const
// Add callback methods
decl.add_method(
sel!(toolbarAllowedItemIdentifiers:),
allowed_item_identifiers::<T> as extern "C" fn(&Object, _, _) -> id
allowed_item_identifiers::<T> as extern "C" fn(_, _, _) -> _
);
decl.add_method(
sel!(toolbarDefaultItemIdentifiers:),
default_item_identifiers::<T> as extern "C" fn(&Object, _, _) -> id
default_item_identifiers::<T> as extern "C" fn(_, _, _) -> _
);
decl.add_method(
sel!(toolbarSelectableItemIdentifiers:),
selectable_item_identifiers::<T> as extern "C" fn(&Object, _, _) -> id
selectable_item_identifiers::<T> as extern "C" fn(_, _, _) -> _
);
decl.add_method(
sel!(toolbar:itemForItemIdentifier:willBeInsertedIntoToolbar:),
item_for_identifier::<T> as extern "C" fn(&Object, _, _, _, _) -> id
item_for_identifier::<T> as extern "C" fn(_, _, _, _, _) -> _
);
})
}
78 changes: 30 additions & 48 deletions src/appkit/window/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,112 +232,94 @@ pub(crate) fn register_window_class_with_delegate<T: WindowDelegate>(instance: &
decl.add_ivar::<usize>(WINDOW_DELEGATE_PTR);

// NSWindowDelegate methods
decl.add_method(
sel!(windowShouldClose:),
should_close::<T> as extern "C" fn(&Object, _, _) -> BOOL
);
decl.add_method(sel!(windowWillClose:), will_close::<T> as extern "C" fn(&Object, _, _));
decl.add_method(sel!(windowShouldClose:), should_close::<T> as extern "C" fn(_, _, _) -> _);
decl.add_method(sel!(windowWillClose:), will_close::<T> as extern "C" fn(_, _, _));

// Sizing
decl.add_method(
sel!(windowWillResize:toSize:),
will_resize::<T> as extern "C" fn(&Object, _, _, CGSize) -> CGSize
will_resize::<T> as extern "C" fn(_, _, _, _) -> _
);
decl.add_method(sel!(windowDidResize:), did_resize::<T> as extern "C" fn(&Object, _, _));
decl.add_method(sel!(windowDidResize:), did_resize::<T> as extern "C" fn(_, _, _));
decl.add_method(
sel!(windowWillStartLiveResize:),
will_start_live_resize::<T> as extern "C" fn(&Object, _, _)
will_start_live_resize::<T> as extern "C" fn(_, _, _)
);
decl.add_method(
sel!(windowDidEndLiveResize:),
did_end_live_resize::<T> as extern "C" fn(&Object, _, _)
did_end_live_resize::<T> as extern "C" fn(_, _, _)
);

// Minimizing
decl.add_method(
sel!(windowWillMiniaturize:),
will_miniaturize::<T> as extern "C" fn(&Object, _, _)
);
decl.add_method(
sel!(windowDidMiniaturize:),
did_miniaturize::<T> as extern "C" fn(&Object, _, _)
);
decl.add_method(sel!(windowWillMiniaturize:), will_miniaturize::<T> as extern "C" fn(_, _, _));
decl.add_method(sel!(windowDidMiniaturize:), did_miniaturize::<T> as extern "C" fn(_, _, _));
decl.add_method(
sel!(windowDidDeminiaturize:),
did_deminiaturize::<T> as extern "C" fn(&Object, _, _)
did_deminiaturize::<T> as extern "C" fn(_, _, _)
);

// Full Screen
decl.add_method(
sel!(window:willUseFullScreenContentSize:),
content_size_for_full_screen::<T> as extern "C" fn(&Object, _, _, CGSize) -> CGSize
content_size_for_full_screen::<T> as extern "C" fn(_, _, _, _) -> _
);
decl.add_method(
sel!(window:willUseFullScreenPresentationOptions:),
options_for_full_screen::<T> as extern "C" fn(&Object, _, _, NSUInteger) -> NSUInteger
options_for_full_screen::<T> as extern "C" fn(_, _, _, _) -> _
);
decl.add_method(
sel!(windowWillEnterFullScreen:),
will_enter_full_screen::<T> as extern "C" fn(&Object, _, _)
will_enter_full_screen::<T> as extern "C" fn(_, _, _)
);
decl.add_method(
sel!(windowDidEnterFullScreen:),
did_enter_full_screen::<T> as extern "C" fn(&Object, _, _)
did_enter_full_screen::<T> as extern "C" fn(_, _, _)
);
decl.add_method(
sel!(windowWillExitFullScreen:),
will_exit_full_screen::<T> as extern "C" fn(&Object, _, _)
will_exit_full_screen::<T> as extern "C" fn(_, _, _)
);
decl.add_method(
sel!(windowDidExitFullScreen:),
did_exit_full_screen::<T> as extern "C" fn(&Object, _, _)
did_exit_full_screen::<T> as extern "C" fn(_, _, _)
);
decl.add_method(
sel!(windowDidFailToEnterFullScreen:),
did_fail_to_enter_full_screen::<T> as extern "C" fn(&Object, _, _)
did_fail_to_enter_full_screen::<T> as extern "C" fn(_, _, _)
);
decl.add_method(
sel!(windowDidFailToExitFullScreen:),
did_fail_to_exit_full_screen::<T> as extern "C" fn(&Object, _, _)
did_fail_to_exit_full_screen::<T> as extern "C" fn(_, _, _)
);

// Key status
decl.add_method(sel!(windowDidBecomeKey:), did_become_key::<T> as extern "C" fn(&Object, _, _));
decl.add_method(sel!(windowDidResignKey:), did_resign_key::<T> as extern "C" fn(&Object, _, _));
decl.add_method(sel!(windowDidBecomeKey:), did_become_key::<T> as extern "C" fn(_, _, _));
decl.add_method(sel!(windowDidResignKey:), did_resign_key::<T> as extern "C" fn(_, _, _));

// Main status
decl.add_method(
sel!(windowDidBecomeMain:),
did_become_main::<T> as extern "C" fn(&Object, _, _)
);
decl.add_method(
sel!(windowDidResignMain:),
did_resign_main::<T> as extern "C" fn(&Object, _, _)
);
decl.add_method(sel!(windowDidBecomeMain:), did_become_main::<T> as extern "C" fn(_, _, _));
decl.add_method(sel!(windowDidResignMain:), did_resign_main::<T> as extern "C" fn(_, _, _));

// Moving Windows
decl.add_method(sel!(windowWillMove:), will_move::<T> as extern "C" fn(&Object, _, _));
decl.add_method(sel!(windowDidMove:), did_move::<T> as extern "C" fn(&Object, _, _));
decl.add_method(
sel!(windowDidChangeScreen:),
did_change_screen::<T> as extern "C" fn(&Object, _, _)
);
decl.add_method(sel!(windowWillMove:), will_move::<T> as extern "C" fn(_, _, _));
decl.add_method(sel!(windowDidMove:), did_move::<T> as extern "C" fn(_, _, _));
decl.add_method(sel!(windowDidChangeScreen:), did_change_screen::<T> as extern "C" fn(_, _, _));
decl.add_method(
sel!(windowDidChangeScreenProfile:),
did_change_screen_profile::<T> as extern "C" fn(&Object, _, _)
did_change_screen_profile::<T> as extern "C" fn(_, _, _)
);
decl.add_method(
sel!(windowDidChangeBackingProperties:),
did_change_backing_properties::<T> as extern "C" fn(&Object, _, _)
did_change_backing_properties::<T> as extern "C" fn(_, _, _)
);

// Random
decl.add_method(
sel!(windowDidChangeOcclusionState:),
did_change_occlusion_state::<T> as extern "C" fn(&Object, _, _)
did_change_occlusion_state::<T> as extern "C" fn(_, _, _)
);
decl.add_method(sel!(windowDidExpose:), did_expose::<T> as extern "C" fn(&Object, _, _));
decl.add_method(sel!(windowDidUpdate:), did_update::<T> as extern "C" fn(&Object, _, _));
decl.add_method(sel!(cancelOperation:), cancel::<T> as extern "C" fn(&Object, _, _));
decl.add_method(sel!(windowDidExpose:), did_expose::<T> as extern "C" fn(_, _, _));
decl.add_method(sel!(windowDidUpdate:), did_update::<T> as extern "C" fn(_, _, _));
decl.add_method(sel!(cancelOperation:), cancel::<T> as extern "C" fn(_, _, _));
})
}
Loading

0 comments on commit 86d3eeb

Please sign in to comment.