root/lang/objective-cplusplus/i3/trunk/tmp/nsw.m

Revision 37878, 1.6 kB (checked in by saturday06, 4 years ago)

na

Line 
1// -*- coding: utf-8-dos -*-
2
3#import <Foundation/Foundation.h>
4#import <AppKit/AppKit.h>
5
6@interface MyWindow : NSWindow
7{
8}
9-(BOOL)windowShouldClose:(id)sender;
10-(void)windowWillClose:(NSNotification*)aNotification;
11@end
12
13@implementation MyWindow
14-(void)windowWillClose:(NSNotification*)aNotification {
15    NSLog(@"windowWillClose");
16    [NSApp terminate:self];
17}
18
19-(BOOL)windowShouldClose:(id)sender {
20    NSLog(@"windowShouldClose");
21    [NSApp terminate:self];
22    return 0;
23}
24@end
25
26int main() {
27    NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
28
29    NS_DURING
30    {
31        [NSApplication sharedApplication];
32
33        MyWindow* window = [MyWindow alloc];
34        [window initWithContentRect: NSMakeRect(100, 100, 200, 200)
35                          styleMask: NSTitledWindowMask | NSMiniaturizableWindowMask | NSClosableWindowMask
36                            backing: NSBackingStoreBuffered
37                              defer: NO];
38        [window retain];
39        [window setTitle: @"Hello, Input"];
40        [window makeKeyAndOrderFront: nil];
41
42        // [NSException raise:@"Application_will_terminate" format:@"Someone requested to terminate application"];
43        //[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:10]];
44        [NSApp run];
45    }
46    NS_HANDLER
47    {
48        NSLog(@"Objective-C exception name=[%s] reason=[%s]\n",
49              [[localException name] UTF8String],
50              [[localException reason] UTF8String]);
51    }
52    NS_ENDHANDLER;
53     
54    [pool release];
55   
56    return 0;
57}
58
59
60
Note: See TracBrowser for help on using the browser.