On 22.08.2016 at 17:55 Ken Thomases wrote:

>>> Is this in the same app from your other thread
>>> where you're trying to shoehorn Cocoa into a C-based program?  Can
>>> you reproduce the problem in a new, standard Cocoa app project?

>> Yup, see above ;)

> This is ambiguous.  Was the "yup" to my first or second question? 

Oops, sorry, the "yup" addressed your first question.

> If to the second, then what you wrote above is definitely not a
> standard Cocoa app.  I'm trying to help you determine the specific
> factor that's causing the problem.  The question is whether the
> games you're playing with the app loop are responsible.  So, does
> the problem happen in an app where you don't play those games?

I think it's obvious that this must be related to the app loop "games"
because I think we can rule out the possibility that such a fundamental
functionality like "runModal" is broken completely in 10.6 for NSAlert,
NSOpenPanel, NSSavePanel... I'm pretty certain that it will work
correctly when doing things the proper way using NSApplicationMain().

Still, it must be possible to get these to work correctly when setting
up the NSApp in a custom way.

Hence, I've now prepared an absolutely minimal test program that
reproduces the issue, it's only 50 lines so it should be really
self-explaining. The NSAlert code in this test program is a direct
copy&paste from Apple's site.

Here we go:

---------------------------------------------------------------------------
#include <stdio.h>
#include <ctype.h>

#include <Cocoa/Cocoa.h>
        
@interface MyApplication : NSApplication
@end

@implementation MyApplication
@end

@interface MyApplicationDelegate : NSObject
@end

@implementation MyApplicationDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)notification
{
        [NSApp stop:nil];

        NSEvent *event = [NSEvent otherEventWithType:NSApplicationDefined 
location:NSMakePoint(0, 0) modifierFlags:0 timestamp:0 windowNumber:0 
context:nil subtype:0 data1:0 data2:0];

        [NSApp postEvent:event atStart:YES];
}
@end

int main(int argc, char *argv[])
{
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
        
        [MyApplication sharedApplication];

        [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];

        id appDelegate = [[MyApplicationDelegate alloc] init];

        [NSApp setDelegate:appDelegate];

        [NSApp run];

        NSAlert *alert = [[NSAlert alloc] init];
        [alert addButtonWithTitle:@"OK"];
        [alert addButtonWithTitle:@"Cancel"];
        [alert setMessageText:@"Delete the record?"];
        [alert setInformativeText:@"Deleted records cannot be restored."];
        [alert setAlertStyle:NSWarningAlertStyle];

        [alert runModal];
        [alert release];
        
        [pool release];
                        
        return 0;
}
---------------------------------------------------------------------------
        
Works correctly on 10.11, but doesn't work on 10.6.

-- 
Best regards,
 Andreas Falkenhahn                            mailto:andr...@falkenhahn.com


_______________________________________________

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