]>
Commit | Line | Data |
---|---|---|
1 | #import <Foundation/Foundation.h> | |
2 | #import <UIKit/UIKit.h> | |
3 | ||
4 | #include <unistd.h> | |
5 | #include <cstdlib> | |
6 | ||
7 | int argc_; | |
8 | char **argv_; | |
9 | ||
10 | @interface AlertSheet : UIApplication | |
11 | #ifdef __OBJC2__ | |
12 | <UIModalViewDelegate> | |
13 | #endif | |
14 | { | |
15 | } | |
16 | ||
17 | #ifdef __OBJC2__ | |
18 | - (void) modalView:(UIModalView *)modalView didDismissWithButtonIndex:(NSInteger)buttonIndex; | |
19 | #else | |
20 | - (void) alertSheet:(UIAlertSheet *)sheet buttonClicked:(int)button; | |
21 | #endif | |
22 | ||
23 | - (void) applicationDidFinishLaunching:(id)unused; | |
24 | @end | |
25 | ||
26 | @implementation AlertSheet | |
27 | ||
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]; | |
35 | exit(button); | |
36 | } | |
37 | #endif | |
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 | ||
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 | |
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]; | |
67 | #endif | |
68 | } | |
69 | ||
70 | @end | |
71 | ||
72 | int main(int argc, char *argv[]) { | |
73 | argc_ = argc; | |
74 | argv_ = argv; | |
75 | ||
76 | char *args[] = { | |
77 | (char *) "AlertSheet", NULL | |
78 | }; | |
79 | ||
80 | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | |
81 | #ifdef __OBJC2__ | |
82 | UIApplicationMain(1, args, nil, @"AlertSheet"); | |
83 | #else | |
84 | UIApplicationMain(1, args, [AlertSheet class]); | |
85 | #endif | |
86 | [pool release]; | |
87 | return 0; | |
88 | } |