From 88c9a6b8775b5c97d21811b7f48a92eeeb5906c2 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 26 Sep 2023 21:52:38 +0200 Subject: Document: Initial attempt to cascade new document windows When creating a new document with Apple-N, try to cascade the new window so that it opens a bit below and to the right of the previous window. Store the previous window origin in a static variable for a relative reference point. Currently this seems to cascade, but not by a full titlebar height and corresponding horizontal position. Needs some adjustment. --- src/Document.m | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Document.m b/src/Document.m index e50737d..609f0a6 100644 --- a/src/Document.m +++ b/src/Document.m @@ -1,11 +1,21 @@ #import "Document.h" +static NSPoint *cascade_offset; + @implementation Document - (id)init { self = [super init]; if (self) { + NSLog(@"Checking cascade_offset"); + if (!cascade_offset) { + NSLog(@"Setting cascade_offset"); + NSPoint p = NSMakePoint(100, 100); + cascade_offset = &p; + NSLog(@"Has set cascade_offset"); + } + _label = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 180, 20)]; [_label setStringValue:@"Your document contents here"]; @@ -31,7 +41,7 @@ // DocumentWindowController *controller = [[DocumentWindowController alloc] init]; NSWindow *window = [[NSWindow alloc] - initWithContentRect:NSMakeRect(0, 0, 600, 500) + initWithContentRect:NSMakeRect(100, 50, 600, 500) styleMask: NSWindowStyleMaskTitled | NSWindowStyleMaskClosable @@ -63,7 +73,14 @@ | NSViewMaxYMargin]; // TODO: Cascade, store previous top-left position. - // [window cascadeTopLeftFromPoint:NSMakePoint(100, 100)]; + if (cascade_offset) { + // cascade_offset = NSMakePoint(100, 100); + NSLog(@"Yes"); + } + + *cascade_offset = [window cascadeTopLeftFromPoint:*cascade_offset]; + + // cascade_offset = [window frame].origin; NSWindowController *window_controller = [[NSWindowController alloc] initWithWindow:window]; -- cgit v1.2.3