On Mar 14, 2013, at 8:13 AM, Steve Mills wrote:

> On Mar 13, 2013, at 17:29:11, Seth Willits <sli...@araelium.com> wrote:
> 
>> On Mar 13, 2013, at 2:38 PM, Steve Mills wrote:
>> 
>>> That's an idea. I was hoping there was some way to say "this is the frame 
>>> for the first new window, but all others should respect it AND then go 
>>> ahead and cascade down from there," because I'd still like to cascade the 
>>> windows from that calculated position but hopefully without having to write 
>>> all the code that Apple already wrote to cascade windows and ensure that 
>>> they's still 100% onscreen in the first place.
>> 
>> The exact behavior you describe is the behavior I see when simply setting 
>> the window frame in windowDidLoad.
> 
> It's hard to say "exact" without seeing each other's app. So #1 gets put into 
> the location I calculate. #2 cascades down from that. Fine. But #3 cascades 
> down from that, and since the bottom is now outside the bottom of the screen, 
> the entire window gets moved up, completely ignoring where I moved it to in 
> windowDidLoad, so it ends up being too high and under my palettes. I don't 
> know why Apple doesn't have a method to get the preferred rect that it will 
> respect when cascading, much like it knows how to get the visibleRect from 
> the NSScreen and still respects that.

Ahhhh. Didn't consider the wrap around. Here:


- (NSRect)allowedRect;
{
        return NSMakeRect(100, 200, 1500, 650);
}


- (NSPoint)cascadeTopLeftFromPoint:(NSPoint)topLeft
{
        NSSize cascadeOffset = NSMakeSize(21, -23);
        
        
        // This window's top left
        if (NSEqualPoints(NSZeroPoint, topLeft)) {
                topLeft = NSMakePoint(NSMinX(self.allowedRect), 
NSMaxY(self.allowedRect));
        }
        
        CGFloat proposedRight  = topLeft.x + self.frame.size.width;
        CGFloat proposedBottom = topLeft.y - self.frame.size.height;
        
        if (proposedRight > NSMaxX(self.allowedRect)) {
                topLeft.x = NSMinY(self.allowedRect);
        }
        
        if (proposedBottom < NSMinY(self.allowedRect)) {
                topLeft.y = NSMaxY(self.allowedRect);
        }
        
        self.frameTopLeftPoint = topLeft;
        
        
        // Next window's top left
        return NSMakePoint(topLeft.x + cascadeOffset.width, topLeft.y + 
cascadeOffset.height);
}



If you never ever ever want a window to be able to be positioned under a 
palette (even if the user moves it there) then you additionally need to 
customize the constrain method. Something along the lines of:

- (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen;
{
        // Move Right
        frameRect.origin.x = MAX(frameRect.origin.x, NSMinX(self.allowedRect));
        
        // Move Left
        frameRect.origin.x = MIN(frameRect.origin.x, NSMinX(self.allowedRect));
        
        // Move upward
        frameRect.origin.y = MAX(frameRect.origin.y, NSMinY(self.allowedRect));
        
        // Move downward
        frameRect.origin.y = MIN(frameRect.origin.y, NSMaxY(self.allowedRect) - 
frameRect.size.height);
        
        return [super constrainFrameRect:frameRect toScreen:screen];
}





--
Seth Willits

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to