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