| | 3 | |
| | 4 | @interface MyDelegate : NSObject |
| | 5 | { |
| | 6 | NSWindow *myWindow; |
| | 7 | } |
| | 8 | - (void) createMenu; |
| | 9 | - (void) createWindow; |
| | 10 | - (void) applicationWillFinishLaunching: (NSNotification *)not; |
| | 11 | - (void) applicationDidFinishLaunching: (NSNotification *)not; |
| | 12 | @end |
| | 13 | |
| | 14 | @implementation MyDelegate : NSObject |
| | 15 | - (void) dealloc |
| | 16 | { |
| | 17 | RELEASE (myWindow); |
| | 18 | } |
| | 19 | |
| | 20 | - (void) createMenu |
| | 21 | { |
| | 22 | NSMenu *menu; |
| | 23 | |
| | 24 | menu = AUTORELEASE ([NSMenu new]); |
| | 25 | |
| | 26 | [menu addItemWithTitle: @"Quit" |
| | 27 | action: @selector (terminate:) |
| | 28 | keyEquivalent: @"q"]; |
| | 29 | |
| | 30 | [NSApp setMainMenu: menu]; |
| | 31 | } |
| | 32 | |
| | 33 | - (void) createWindow |
| | 34 | { |
| | 35 | NSRect rect = NSMakeRect (100, 100, 200, 200); |
| | 36 | unsigned int styleMask = NSTitledWindowMask |
| | 37 | | NSMiniaturizableWindowMask; |
| | 38 | |
| | 39 | |
| | 40 | myWindow = [NSWindow alloc]; |
| | 41 | myWindow = [myWindow initWithContentRect: rect |
| | 42 | styleMask: styleMask |
| | 43 | backing: NSBackingStoreBuffered |
| | 44 | defer: NO]; |
| | 45 | [myWindow setTitle: @"This is a test window"]; |
| | 46 | } |
| | 47 | |
| | 48 | - (void) applicationWillFinishLaunching: (NSNotification *)not |
| | 49 | { |
| | 50 | [self createMenu]; |
| | 51 | [self createWindow]; |
| | 52 | } |
| | 53 | |
| | 54 | - (void) applicationDidFinishLaunching: (NSNotification *)not; |
| | 55 | { |
| | 56 | [myWindow makeKeyAndOrderFront: nil]; |
| | 57 | } |
| | 58 | @end |
| 9 | | void alert(string message) |
| 10 | | { |
| | 67 | exit_status init_gui_global_data(int argc, const char** argv) |
| | 68 | { |
| | 69 | using namespace std; |
| | 70 | #ifdef MOL_OS_UNIX |
| | 71 | if (setlocale(LC_ALL, "") != NULL) |
| | 72 | { |
| | 73 | bindtextdomain(PACKAGE_NAME, LOCALEDIR); |
| | 74 | textdomain(PACKAGE_NAME); |
| | 75 | bind_textdomain_codeset(PACKAGE_NAME, COCOA_CODESET); |
| | 76 | } |
| | 77 | #else |
| | 78 | init_windows_gettext(); |
| | 79 | #endif |
| | 80 | |
| | 81 | [NSApplication sharedApplication]; |
| | 82 | [NSApp setDelegate: [MyDelegate new]]; |
| | 83 | |
| | 84 | return 0; |
| | 85 | } |
| 13 | | exit_status init_gui_global_data(int& argc,char**& argv) |
| 14 | | { |
| 15 | | using namespace std; |
| 16 | | #ifdef MOL_OS_UNIX |
| 17 | | if (setlocale(LC_ALL, "") != NULL) |
| 18 | | { |
| 19 | | bindtextdomain(PACKAGE_NAME, LOCALEDIR); |
| 20 | | textdomain(PACKAGE_NAME); |
| 21 | | bind_textdomain_codeset(PACKAGE_NAME, COCOA_CODESET); |
| 22 | | } |
| 23 | | #else |
| 24 | | init_windows_gettext(); |
| 25 | | #endif |
| 26 | | QApplication app(argc, argv); |
| 27 | | QString qs = _("Hello, world!"); |
| 28 | | QLabel* label(new QLabel(qs)); |
| 29 | | label->show(); |
| 30 | | int r = app.exec(); |
| 31 | | return 0; |
| 32 | | } |
| 33 | | } |
| 34 | | |