gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSWindow and delegate methods


From: Fred Kiefer
Subject: Re: NSWindow and delegate methods
Date: Thu, 19 Sep 2013 23:53:00 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130801 Thunderbird/17.0.8

It looks like I added the check for these methods being send to self
about ten years ago. But I don't have any recollection of this. So the
best I can do is look up the Apple documentation for zoom:. There it says:

"Invokes the windowWillUseStandardFrame:defaultFrame: method, if the
delegate or the window class implements it, to obtain a “best fit” frame
for the window. If neither the delegate nor the window class implements
the method, uses a default frame that nearly fills the current screen,
which is defined to be the screen containing the largest part of the
window’s current frame."


I am now a bit unsure what is meant by "the window class". When
implementing the code I thought the method should be called on the
window itself, but it might as well be the class of the window. Later on
for windowShouldZoom:toFrame: the documentation is more clear.
This means that removing this call is not a valid option. Moving away
from defined behaviour, just because the code gives warnings on some
overambitious compiler isn't enough reason.

I would also think that Greg's fix is not correct, as it removed the
method from the delegate protocol. It looks like in the case of an
optional protocol we need to duplicate the definitions, once in the
protocol and again in an NSObject extension.

Fred


On 18.09.2013 01:21, Ivan Vučica wrote:
> Hello all,
> 
> Gregory has added NSWindowDelegate as a formal protocol. That's great.
> 
> Unfortunately, it did break the build for me on Clang for a while. We
> talked about it over XMPP, we noticed that there are some message sends for
> phantom methods, and we decided to check to the mailing list about a
> possible permanent fix.
> 
> Here's an example of the error:
> NSWindow.m:5098:23: warning: instance method
>       '-windowWillUseStandardFrame:defaultFrame:' not found (return type
>       defaults to 'id') [-Wobjc-method-access]
>       maxRect = [self windowWillUseStandardFrame: self defaultFrame:
> maxRect];
>                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ../Headers/AppKit/NSWindow.h:164:12: note: receiver is instance of class
>       declared here
> @interface NSWindow : NSResponder <NSCoding>
>            ^
> NSWindow.m:5098:15: error: assigning to 'NSRect' (aka 'struct _NSRect') from
>       incompatible type 'id'
>       maxRect = [self windowWillUseStandardFrame: self defaultFrame:
> maxRect];
>               ^
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> Here's some context:
>   if ([_delegate respondsToSelector:
> @selector(windowWillUseStandardFrame:defaultFrame:)])
>     {
>       maxRect = [_delegate windowWillUseStandardFrame: self defaultFrame:
> maxRect];
>     }
>   else if ([self respondsToSelector:
> @selector(windowWillUseStandardFrame:defaultFrame:)])
>     {
>       maxRect = [self windowWillUseStandardFrame: self defaultFrame:
> maxRect];
>     }
> 
> There is no implementation of -windowWillUseStandardFrame:defaultFrame: in
> NSWindow. I can also find no confirmation online that a subclass can
> implement it. I'm not under OS X right now, so I cannot check, but it seems
> to me that even if it's a valid thing to do, noone is doing it.
> 
> So what I would suggest we do is: we rip out the message send to 'self' for
> these several relevant methods.
> 
> Greg's current fix is to add these declarations back to NSObject...
> @interface NSObject (NSWindowDelegateAdditions) <NSWindowDelegate>
> ...but that is kind-of wrong, as we're back where we started; the @protocol
> could have been defined empty and everything could have remained in the
> informal protocol.
> 
> Anyway -- since someone may depend on this behavior. Is there someone
> depending on NSWindow's subclasses being able to implement
> -windowWillUseStandardFrame:defaultFrame:, -windowShouldZoom:toFrame:,
> -windowWillResize:toSize: and -windowShouldClose:?
> 
> (These are the methods that broke for me when they were moved to the formal
> protocol.)
> 
> Thanks!




reply via email to

[Prev in Thread] Current Thread [Next in Thread]