1/* Example for use of GNU gettext. 2 Copyright (C) 2003 Free Software Foundation, Inc. 3 This file is in the public domain. 4 5 Source code of the Hello class. */ 6 7#include <unistd.h> 8#include "Hello.h" 9#include <GNUstepGUI/GSHbox.h> 10#include <GNUstepGUI/GSVbox.h> 11 12@implementation Hello 13 14- (id)init 15{ 16 if ((self = [super init])) 17 [self createUI]; 18 return self; 19} 20 21- (void)dealloc 22{ 23 RELEASE (window); 24 [super dealloc]; 25} 26 27- (void)makeKeyAndOrderFront 28{ 29 if (![window isVisible]) 30 [window center]; 31 [window makeKeyAndOrderFront:self]; 32} 33 34- (void)done 35{ 36 [window close]; 37} 38 39@end 40 41@implementation Hello (UIBuilder) 42 43- (void)createUI 44{ 45 GSVbox *cview; 46 GSHbox *buttonbar; 47 int i; 48 49 label1 = [NSTextField new]; 50 [label1 setStringValue: _(@"Hello, world!")]; 51 [label1 setAlignment: NSLeftTextAlignment]; 52 [label1 setBordered: NO]; 53 [label1 setEditable: NO]; 54 [label1 setBezeled: NO]; 55 [label1 setDrawsBackground: NO]; 56 [label1 sizeToFit]; 57 58 label2 = [NSTextField new]; 59 [label2 setStringValue: [NSString stringWithFormat: _(@"This program is running as process number %d."), [[NSProcessInfo processInfo] processIdentifier]]]; 60 [label2 setAlignment: NSLeftTextAlignment]; 61 [label2 setBordered: NO]; 62 [label2 setEditable: NO]; 63 [label2 setBezeled: NO]; 64 [label2 setDrawsBackground: NO]; 65 [label2 sizeToFit]; 66 67 okButton = [NSButton new]; 68 [okButton setTitle: @"OK"]; 69 [okButton setTarget: self]; 70 [okButton setAction: @selector(done)]; 71 [okButton setFrameSize: NSMakeSize(60,22)]; 72 [okButton setAutoresizingMask: 7]; 73 74 buttonbar = [GSHbox new]; 75 [buttonbar setAutoresizingMask: NSViewMinXMargin]; 76 [buttonbar addView: okButton]; 77 AUTORELEASE (okButton); 78 79 cview = [GSVbox new]; 80 // GSVbox is flawed: We have to add the controls bottom-up, and mark the 81 // last one (= the topmost one) as non-resizable in Y direction, so that the 82 // Y space becomes equally distributed _between_ (not above) the subviews. 83 [cview addView: buttonbar]; 84 AUTORELEASE (buttonbar); 85 [cview addView: label2]; 86 AUTORELEASE (label2); 87 [cview addView: label1 enablingYResizing: NO]; 88 AUTORELEASE (label1); 89 90 window = [[NSWindow alloc] initWithContentRect: NSMakeRect(0,0, [cview frame].size.width, [cview frame].size.height) 91 styleMask: (NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask) 92 backing: NSBackingStoreBuffered 93 defer: NO]; 94 [window setDelegate: self]; 95 [window setTitle: @"Hello example"]; 96 [window setReleasedWhenClosed: NO]; 97 [window setContentView: cview]; 98} 99 100@end 101