Add beginSheet:completionHandler:-related methods:

-[NSWindow beginSheet:completionHandler:]
-[NSAlert beginSheetModalForWindow:completionHandler:]
This commit is contained in:
ethanc8 2023-01-03 19:56:16 -06:00 committed by ethanc8
parent 969fe4c870
commit ea6c43911f
5 changed files with 56 additions and 4 deletions

View file

@ -55,6 +55,11 @@ enum {
NSAlertThirdButtonReturn = 1002
};
#if OS_API_VERSION(MAC_OS_X_VERSION_10_9, GS_API_LATEST)
typedef NSInteger NSModalResponse;
DEFINE_BLOCK_TYPE(GSNSWindowDidEndSheetCallbackBlock, void, NSModalResponse returnCode);
#endif
APPKIT_EXPORT_CLASS
@interface NSAlert : NSObject
{
@ -106,6 +111,11 @@ APPKIT_EXPORT_CLASS
- (BOOL) showsHelp;
- (id) window;
#if OS_API_VERSION(MAC_OS_X_VERSION_10_9, GS_API_LATEST)
- (void) beginSheetModalForWindow:(NSWindow *)sheetWindow
completionHandler:(GSNSWindowDidEndSheetCallbackBlock)handler;
#endif
@end

View file

@ -74,6 +74,10 @@ enum {
NSRunContinuesResponse = (-1002)
};
#if OS_API_VERSION(MAC_OS_X_VERSION_10_9, GS_API_LATEST)
typedef NSInteger NSModalResponse;
#endif
#if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST)
#define NSUpdateWindowsRunLoopOrdering 600000

View file

@ -90,10 +90,12 @@ enum {
};
#if OS_API_VERSION(MAC_OS_X_VERSION_10_9, GS_API_LATEST)
enum {
NSModalResponseOK = 1,
NSModalResponseCancel = 0
};
typedef NSInteger NSModalResponse;
enum {
NSModalResponseOK = 1,
NSModalResponseCancel = 0
};
DEFINE_BLOCK_TYPE(GSNSWindowDidEndSheetCallbackBlock, void, NSModalResponse returnCode);
#endif
enum {
@ -862,6 +864,9 @@ PACKAGE_SCOPE
#else
- (NSWindow *) sheetParent;
#endif
- (void)beginSheet:(NSWindow *)sheet
completionHandler:(GSNSWindowDidEndSheetCallbackBlock)handler;
#endif
#if OS_API_VERSION(MAC_OS_X_VERSION_10_7, GS_API_LATEST)

View file

@ -2049,6 +2049,15 @@ void NSBeginInformationalAlertSheet(NSString *title,
DESTROY(_window);
}
- (void) beginSheetModalForWindow:(NSWindow *)sheet
completionHandler:(GSNSWindowDidEndSheetCallbackBlock)handler
{
[self _setupPanel];
[sheet beginSheet: _window
completionHandler: handler];
DESTROY(_window);
}
- (void) _alertDidEnd: (NSWindow *)sheet
returnCode: (NSInteger)returnCode
contextInfo: (void *)contextInfo

View file

@ -5952,6 +5952,30 @@ current key view.<br />
return nil;
}
- (void)beginSheet:(NSWindow *)sheet
completionHandler:(GSNSWindowDidEndSheetCallbackBlock)handler {
// FIXME
NSInteger ret;
[sheet setParentWindow: self];
self->_attachedSheet = sheet;
[[NSNotificationCenter defaultCenter]
postNotificationName: NSWindowWillBeginSheetNotification
object: self];
ret = [NSApp runModalForWindow: sheet
relativeToWindow: self];
CALL_BLOCK(handler, ret);
[sheet close];
self->_attachedSheet = nil;
[sheet setParentWindow: nil];
[[NSNotificationCenter defaultCenter]
postNotificationName: NSWindowDidEndSheetNotification
object: self];
}
- (CGFloat) backingScaleFactor
{
return 1.0;