Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Tweaking a window size



On Tue, Dec 30, 2008 at 1:48 AM, Graham Cox <email@hidden> wrote:
> One of my windows has a delegate implementing the -windowWillResize:toSize:
> method. This forces the window size to be certain whole multiples of rows in
> a matrix of icons, the idea being to prevent the user from sizing the window
> so that only a partial row is visible, which is ugly. It works as I wish.
>
> The user can also select whether they want small, medium or large icons in
> this matrix, so the row height changes as a result. When this happens I'd
> like to be able to tweak the window height as minimally as necessary to
> conform to the "whole rows" requirement.
>
> Since the delegate method already does all the needed calculation, I figured
> I could just do something that would cause it to get triggered just as if
> the user had dragged the resize widget. Unfortunately, -setFrame:display: is
> explicitly excluded in the docs - it doesn't call the delegate method - , so
> that's out. So I tried getting the saved frame string then setting the frame
> using the string, but while that should call the delegate, it appears not to
> if the size is the same as the window's current size.
>
> Any ideas how I can force the window to act as if it were being resized?

I think you're approaching this backwards. It's generally wrong to try
to tweak the guts of your app to trigger this sort of fixup response.
These delegate methods are intended to be in response to user actions.
For programmatic changes, it's assumed that your code knows what's
going on.

What you really want to do is to invoke your delegate method. So call
it! Delegate methods are not special. Something like this will do:

if([[window delegate] respondsToSelector:@selector(windowWillResize:toSize:)]) {
   NSRect frame = [window frame];
   frame.size = [[window delegate] windowWillResize:window toSize:frame.size];
   [window setFrame:frame display:YES];
}

Or better yet, have a separate method which generates the needed size,
and then call that method both from here and the -windowWillResize:
implementation.

Mike
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden

References: 
 >Tweaking a window size (From: Graham Cox <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.