Made other windows get events when a dialog is running on OS X. Of course I only now realize this creates a recursiion problem...

This commit is contained in:
Pietro Gagliardi 2016-05-15 16:26:43 -04:00
parent 2f2db46109
commit 20994639c0
2 changed files with 39 additions and 6 deletions

View File

@ -1,8 +1,6 @@
// 26 june 2015
#import "uipriv_darwin.h"
// TODO while a dialog is running no other window receives events
#define windowWindow(w) ((NSWindow *) uiControlHandle(uiControl(w)))
// source of code modal logic: http://stackoverflow.com/questions/604768/wait-for-nsalert-beginsheetmodalforwindow
@ -20,11 +18,16 @@ static void setupSavePanel(NSSavePanel *s)
static char *runSavePanel(NSWindow *parent, NSSavePanel *s)
{
char *filename;
NSInteger res;
// TODO formalize in headers
[(id)parent setWorksWhenModal:NO];
[s beginSheetModalForWindow:parent completionHandler:^(NSInteger result) {
[realNSApp() stopModalWithCode:result];
}];
if ([realNSApp() runModalForWindow:s] != NSFileHandlingPanelOKButton)
res = [realNSApp() runModalForWindow:s];
[(id)parent setWorksWhenModal:YES];
if (res != NSFileHandlingPanelOKButton)
return NULL;
filename = uiDarwinNSStringToText([[s URL] path]);
return filename;
@ -78,11 +81,17 @@ char *uiSaveFile(uiWindow *parent)
- (NSInteger)run
{
NSInteger res;
// TODO like above
[(id)(self->parent) setWorksWhenModal:NO];
[self->panel beginSheetModalForWindow:self->parent
modalDelegate:self
didEndSelector:@selector(panelEnded:result:data:)
contextInfo:NULL];
return [realNSApp() runModalForWindow:[self->panel window]];
res = [realNSApp() runModalForWindow:[self->panel window]];
[(id)(self->parent) setWorksWhenModal:YES];
return res;
}
- (void)panelEnded:(NSAlert *)panel result:(NSInteger)result data:(void *)data

View File

@ -1,9 +1,16 @@
// 15 august 2015
#import "uipriv_darwin.h"
// don't stop other windows from working when one is modal
@interface modalWindow : NSWindow {
BOOL worksModal;
}
- (BOOL)setWorksWhenModal:(BOOL)wwm;
@end
struct uiWindow {
uiDarwinControl c;
NSWindow *window;
modalWindow *window;
uiControl *child;
int margined;
int (*onClosing)(uiWindow *, void *);
@ -11,6 +18,20 @@ struct uiWindow {
struct singleChildConstraints constraints;
};
@implementation modalWindow
- (BOOL)worksWhenModal
{
return self->worksModal;
}
- (void)setWorksWhenModal:(BOOL)wwm
{
self->worksModal = wwm;
}
@end
@interface windowDelegateClass : NSObject<NSWindowDelegate> {
struct mapTable *windows;
}
@ -242,12 +263,15 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
uiDarwinNewControl(uiWindow, w);
w->window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, (CGFloat) width, (CGFloat) height)
w->window = [[modalWindow alloc] initWithContentRect:NSMakeRect(0, 0, (CGFloat) width, (CGFloat) height)
styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)
backing:NSBackingStoreBuffered
defer:YES];
[w->window setTitle:toNSString(title)];
// default is to work when modal; only the modal owner window should not work when modal
[w->window setWorksWhenModal:YES];
// explicitly release when closed
// the only thing that closes the window is us anyway
[w->window setReleasedWhenClosed:YES];