• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSWindow resize and zoom
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSWindow resize and zoom


  • Subject: NSWindow resize and zoom
  • From: Daniel Todd Currie <email@hidden>
  • Date: Thu, 13 May 2004 21:56:22 -0700

I have an NSWindow containing an NSTableView that grows as the window is resized. I use NSWindow's -windowWillResize:toSize: and return an adjusted NSSize to make the window resize snap to table row widths so that there is never a half-shown row in the table:

- (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)proposedFrameSize
{
float heightWithEvenTableRows = floor((proposedFrameSize.height - [sender minSize].height) / ([conversionTableView rowHeight] + 2)) * ([conversionTableView rowHeight] + 2) + [sender minSize].height;

return(NSMakeSize(proposedFrameSize.width,
heightWithEvenTableRows));
}

However, when the window's zoom button is pressed, I am unable to control the size of the zoom and it ends up showing half a row of the table. What I would like, is to use NSWindow's windowShouldZoom:toFrame: to do the same thing, but windowShouldZoom:toFrame: only returns a BOOL instead of an NSSize. Why is the API so different for these two methods when they are functionally so similar???

The solution I have come up with is to use windowShouldZoom:toFrame: to get the proposed zoom size, set the window size to an adjusted frame that will have an integer number of table rows visible, and then return NO, so that it will not actually zoom:

- (BOOL)windowShouldZoom:(NSWindow *)sender toFrame:(NSRect)newFrame
{
float heightWithEvenTableRows = floor((newFrame.size.height - [sender minSize].height) / ([conversionTableView rowHeight] + 2)) * ([conversionTableView rowHeight] + 2) + [sender minSize].height;

[sender setFrame:NSMakeRect(newFrame.origin.x,
newFrame.origin.y + (newFrame.size.height - heightWithEvenTableRows),
newFrame.size.width,
heightWithEvenTableRows)
display:YES];

return(NO);
}

This solution will work and isn't really so bad, I just wonder how the Cocoa API could be so incongruous. Any comments?

-- Daniel Currie
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Prev by Date: Re: FTP Framework recommendation
  • Next by Date: Changes..
  • Previous by thread: Re: mouse click events
  • Next by thread: Changes..
  • Index(es):
    • Date
    • Thread