OS X: sort out window visibility and focus.

This commit is contained in:
whitequark 2016-06-13 01:35:43 +04:00
parent dce906465d
commit c25e4c8973

View File

@ -400,7 +400,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];
@ -1030,6 +1030,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]];
@ -1047,9 +1052,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) {
@ -1140,6 +1145,8 @@ std::vector<std::string> SolveSpace::GetFontFiles() {
- (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
@ -1160,6 +1167,18 @@ std::vector<std::string> SolveSpace::GetFontFiles() {
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]);
} }
@ -1187,7 +1206,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();