]>
Commit | Line | Data |
---|---|---|
d4e26d1d JF |
1 | #import <Foundation/Foundation.h> |
2 | #import <UIKit/UIKit.h> | |
3 | ||
a60b86de | 4 | #include <unistd.h> |
d4e26d1d | 5 | #include <cstdlib> |
a60b86de JF |
6 | |
7 | int argc_; | |
8 | char **argv_; | |
9 | ||
e8653a29 JF |
10 | @interface AlertSheet : UIApplication |
11 | #ifdef __OBJC2__ | |
12 | <UIModalViewDelegate> | |
13 | #endif | |
14 | { | |
a60b86de JF |
15 | } |
16 | ||
e8653a29 JF |
17 | #ifdef __OBJC2__ |
18 | - (void) modalView:(UIModalView *)modalView didDismissWithButtonIndex:(NSInteger)buttonIndex; | |
19 | #else | |
a60b86de | 20 | - (void) alertSheet:(UIAlertSheet *)sheet buttonClicked:(int)button; |
e8653a29 JF |
21 | #endif |
22 | ||
a60b86de JF |
23 | - (void) applicationDidFinishLaunching:(id)unused; |
24 | @end | |
25 | ||
26 | @implementation AlertSheet | |
27 | ||
e8653a29 JF |
28 | #ifdef __OBJC2__ |
29 | - (void) modalView:(UIModalView *)modalView didDismissWithButtonIndex:(NSInteger)buttonIndex { | |
30 | exit(buttonIndex); | |
31 | } | |
32 | #else | |
33 | - (void) alertSheet:(UIAlertSheet *)alertSheet buttonClicked:(int)button { | |
34 | [alertSheet dismiss]; | |
a60b86de JF |
35 | exit(button); |
36 | } | |
e8653a29 | 37 | #endif |
a60b86de JF |
38 | |
39 | - (void) applicationDidFinishLaunching:(id)unused { | |
40 | NSMutableArray *buttons = [NSMutableArray arrayWithCapacity:(argc_ - 3)]; | |
41 | for (size_t i(0); i != argc_ - 3; ++i) | |
42 | [buttons addObject:[NSString stringWithCString:argv_[i + 3]]]; | |
43 | ||
e8653a29 JF |
44 | #ifdef __OBJC2__ |
45 | UIAlertView *alert = [[[UIAlertView alloc] | |
46 | initWithTitle:[NSString stringWithCString:argv_[1]] | |
47 | message:[NSString stringWithCString:argv_[2]] | |
48 | delegate:self | |
49 | cancelButtonTitle:nil | |
50 | otherButtonTitles:nil | |
51 | ] autorelease]; | |
52 | ||
53 | [alert show]; | |
54 | #else | |
a60b86de JF |
55 | UIAlertSheet *sheet = [[[UIAlertSheet alloc] |
56 | initWithTitle:[NSString stringWithCString:argv_[1]] | |
57 | buttons:buttons | |
58 | defaultButtonIndex:0 | |
59 | delegate:self | |
60 | context:self | |
61 | ] autorelease]; | |
62 | ||
63 | [sheet setBodyText:[NSString stringWithCString:argv_[2]]]; | |
64 | ||
65 | [sheet setShowsOverSpringBoardAlerts:YES]; | |
66 | [sheet popupAlertAnimated:YES]; | |
e8653a29 | 67 | #endif |
a60b86de JF |
68 | } |
69 | ||
70 | @end | |
71 | ||
72 | int main(int argc, char *argv[]) { | |
73 | argc_ = argc; | |
74 | argv_ = argv; | |
75 | ||
76 | char *args[] = { | |
d4e26d1d | 77 | (char *) "AlertSheet", NULL |
a60b86de JF |
78 | }; |
79 | ||
80 | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | |
e8653a29 JF |
81 | #ifdef __OBJC2__ |
82 | UIApplicationMain(1, args, nil, @"AlertSheet"); | |
83 | #else | |
a60b86de | 84 | UIApplicationMain(1, args, [AlertSheet class]); |
e8653a29 | 85 | #endif |
a60b86de JF |
86 | [pool release]; |
87 | return 0; | |
88 | } |