]> git.saurik.com Git - uikittools.git/blob - uialert.mm
Port to Xcode 4.6.3: newer versions of Xcode fail.
[uikittools.git] / uialert.mm
1 /* UIKit Tools - command-line utilities for UIKit
2 * Copyright (C) 2008-2012 Jay Freeman (saurik)
3 */
4
5 /* Modified BSD License {{{ */
6 /*
7 * Redistribution and use in source and binary
8 * forms, with or without modification, are permitted
9 * provided that the following conditions are met:
10 *
11 * 1. Redistributions of source code must retain the
12 * above copyright notice, this list of conditions
13 * and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the
15 * above copyright notice, this list of conditions
16 * and the following disclaimer in the documentation
17 * and/or other materials provided with the
18 * distribution.
19 * 3. The name of the author may not be used to endorse
20 * or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS''
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
25 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
34 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
36 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 */
38 /* }}} */
39
40 #import <Foundation/Foundation.h>
41 #import <UIKit/UIKit.h>
42
43 #include <unistd.h>
44 #include <cstdlib>
45
46 int argc_;
47 char **argv_;
48
49 @interface AlertSheet : UIApplication
50 #ifdef __OBJC2__
51 <UIModalViewDelegate>
52 #endif
53 {
54 }
55
56 #ifdef __OBJC2__
57 - (void) modalView:(UIModalView *)modalView didDismissWithButtonIndex:(NSInteger)buttonIndex;
58 #else
59 - (void) alertSheet:(UIAlertSheet *)sheet buttonClicked:(int)button;
60 #endif
61
62 - (void) applicationDidFinishLaunching:(id)unused;
63 @end
64
65 @implementation AlertSheet
66
67 #ifdef __OBJC2__
68 - (void) modalView:(UIModalView *)modalView didDismissWithButtonIndex:(NSInteger)buttonIndex {
69 exit(buttonIndex);
70 }
71 #else
72 - (void) alertSheet:(UIAlertSheet *)alertSheet buttonClicked:(int)button {
73 [alertSheet dismiss];
74 exit(button);
75 }
76 #endif
77
78 - (void) applicationDidFinishLaunching:(id)unused {
79 NSMutableArray *buttons = [NSMutableArray arrayWithCapacity:(argc_ - 3)];
80 for (size_t i(0); i != argc_ - 3; ++i)
81 [buttons addObject:[NSString stringWithCString:argv_[i + 3]]];
82
83 #ifdef __OBJC2__
84 UIAlertView *alert = [[[UIAlertView alloc]
85 initWithTitle:[NSString stringWithCString:argv_[1]]
86 message:[NSString stringWithCString:argv_[2]]
87 delegate:self
88 cancelButtonTitle:nil
89 otherButtonTitles:nil
90 ] autorelease];
91
92 [alert show];
93 #else
94 UIAlertSheet *sheet = [[[UIAlertSheet alloc]
95 initWithTitle:[NSString stringWithCString:argv_[1]]
96 buttons:buttons
97 defaultButtonIndex:0
98 delegate:self
99 context:self
100 ] autorelease];
101
102 [sheet setBodyText:[NSString stringWithCString:argv_[2]]];
103
104 [sheet setShowsOverSpringBoardAlerts:YES];
105 [sheet popupAlertAnimated:YES];
106 #endif
107 }
108
109 @end
110
111 int main(int argc, char *argv[]) {
112 argc_ = argc;
113 argv_ = argv;
114
115 char *args[] = {
116 (char *) "AlertSheet", NULL
117 };
118
119 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
120 #ifdef __OBJC2__
121 UIApplicationMain(1, args, nil, @"AlertSheet");
122 #else
123 UIApplicationMain(1, args, [AlertSheet class]);
124 #endif
125 [pool release];
126 return 0;
127 }