OS X: sort out window visibility and focus.

This commit is contained in:
whitequark 2016-06-13 01:35:43 +04:00
parent afafa5ec2e
commit 1dba594949

View File

@ -402,7 +402,7 @@ CONVERT(Rect)
.x = xy.x + size.width / 2, .x = xy.x + size.width / 2,
.y = xy.y - size.height / 2 .y = xy.y - size.height / 2
}; };
[[self window] becomeKeyWindow]; [[self window] makeKeyWindow];
[super startEditing:text at:[self convertPointFromBacking:point] [super startEditing:text at:[self convertPointFromBacking:point]
withHeight:fontHeight usingMonospace:FALSE]; withHeight:fontHeight usingMonospace:FALSE];
[self prepareEditorWithMinWidthInChars:minWidthChars]; [self prepareEditorWithMinWidthInChars:minWidthChars];
@ -1035,6 +1035,11 @@ void InitTextWindow() {
[TW setBecomesKeyOnlyIfNeeded:YES]; [TW setBecomesKeyOnlyIfNeeded:YES];
[GW addChildWindow:TW ordered:NSWindowAbove]; [GW addChildWindow:TW ordered:NSWindowAbove];
// Without this, graphics window is also hidden when the text window is shown
// (and is its child window). We replicate the standard behavior manually, in
// the application delegate;
[TW setHidesOnDeactivate:NO];
NSScrollView *scrollView = [[NSScrollView alloc] init]; NSScrollView *scrollView = [[NSScrollView alloc] init];
[TW setContentView:scrollView]; [TW setContentView:scrollView];
[scrollView setBackgroundColor:[NSColor blackColor]]; [scrollView setBackgroundColor:[NSColor blackColor]];
@ -1052,9 +1057,9 @@ void InitTextWindow() {
void ShowTextWindow(bool visible) { void ShowTextWindow(bool visible) {
if(visible) if(visible)
[TW orderFront:nil]; [GW addChildWindow:TW ordered:NSWindowAbove];
else else
[TW close]; [TW orderOut:GW];
} }
void GetTextWindowSize(int *w, int *h) { void GetTextWindowSize(int *w, int *h) {
@ -1165,6 +1170,8 @@ const void *SolveSpace::LoadResource(const std::string &name, size_t *size) {
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication; - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication;
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender; - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender;
- (void)applicationWillTerminate:(NSNotification *)aNotification; - (void)applicationWillTerminate:(NSNotification *)aNotification;
- (void)applicationWillBecomeActive:(NSNotification *)aNotification;
- (void)applicationWillResignActive:(NSNotification *)aNotification;
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename; - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename;
- (IBAction)preferences:(id)sender; - (IBAction)preferences:(id)sender;
@end @end
@ -1185,6 +1192,18 @@ const void *SolveSpace::LoadResource(const std::string &name, size_t *size) {
SolveSpace::SS.Exit(); SolveSpace::SS.Exit();
} }
- (void)applicationWillBecomeActive:(NSNotification *)aNotification {
if(SolveSpace::SS.GW.showTextWindow) {
[GW addChildWindow:TW ordered:NSWindowAbove];
}
}
- (void)applicationWillResignActive:(NSNotification *)aNotification {
[TW setAnimationBehavior:NSWindowAnimationBehaviorNone];
[TW orderOut:nil];
[TW setAnimationBehavior:NSWindowAnimationBehaviorDefault];
}
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename { - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename {
return SolveSpace::SS.OpenFile([filename UTF8String]); return SolveSpace::SS.OpenFile([filename UTF8String]);
} }
@ -1212,7 +1231,6 @@ int main(int argc, const char *argv[]) {
SolveSpace::SS.Init(); SolveSpace::SS.Init();
[GW makeKeyAndOrderFront:nil]; [GW makeKeyAndOrderFront:nil];
[NSApp activateIgnoringOtherApps:YES];
[NSApp run]; [NSApp run];
SolveSpace::SK.Clear(); SolveSpace::SK.Clear();