This is AlertPanel.m in view mode; [Download] [Up]
/* AlertPanel class
*
* Copyright (C) 1994 The Board of Trustees of
* The Leland Stanford Junior University. All Rights Reserved.
*
* Author: Michael Gravina
*
* This file is part of an Objective-C class library for a window system
*
*/
#include "Panel.h"
#include "Application.h"
#include "Button.h"
#include "TextField.h"
#include <stdarg.h>
@interface AlertPanel : Panel
- init :(const char *)title :(const char *)msg :(const char *)defaultText
:(const char *)alternateText :(const char *)otherText;
- default:sender;
- alternate:sender;
- other:sender;
@end
extern int
NXRunAlertPanel(const char *title, const char *msg, const char *defaultText,
const char *alternateText, const char *otherText, ...)
{
id alertPanel;
int irc;
char msgString[200];
va_list ap;
va_start (ap, otherText);
vsprintf (msgString, msg, ap);
va_end (ap);
alertPanel = [AlertPanel alloc];
[alertPanel init :title :msgString :defaultText :alternateText :otherText];
[alertPanel makeKeyAndOrderFront:alertPanel];
irc = [NXApp runModalFor:alertPanel];
[alertPanel close];
return irc;
}
@implementation AlertPanel
- init :(const char *)myTitle :(const char *)msg :(const char *)defaultText
:(const char *)alternateText :(const char *)otherText
{
id defaultButton;
id alternateButton;
id otherButton;
id myText1;
id myText2;
NXRect myFrame;
NXRect contentFrame;
myFrame.size.width = 400;
myFrame.size.height = 164;
myFrame.origin.x = 349;
myFrame.origin.y = 422;
[super initContent:&myFrame style:0 backing:0 buttonMask:0
defer:YES];
[contentView getFrame:&contentFrame];
[self setTitle:"Alert Panel"];
defaultButton = [[Button alloc] init];
myFrame.size.width = 72;
myFrame.size.height = 24;
myFrame.origin.x = 280;
myFrame.origin.y = 8;
[defaultButton setFrame:&myFrame];
if (defaultText == NULL) [defaultButton setTitle:"OK"];
else [defaultButton setTitle:defaultText];
[defaultButton setTarget:self];
[defaultButton setAction:@selector(default:)];
[contentView addSubview:defaultButton];
if (alternateText != NULL) {
alternateButton = [[Button alloc] init];
myFrame.origin.x = 199;
[alternateButton setFrame:&myFrame];
[alternateButton setTitle:alternateText];
[alternateButton setTarget:self];
[alternateButton setAction:@selector(alternate:)];
[contentView addSubview:alternateButton];
}
if (otherText != NULL) {
otherButton = [[Button alloc] init];
myFrame.origin.x = 120;
if (alternateText == NULL) myFrame.origin.x = 199;
[otherButton setFrame:&myFrame];
[otherButton setTitle:otherText];
[otherButton setTarget:self];
[otherButton setAction:@selector(other:)];
[contentView addSubview:otherButton];
}
myText1 = [[TextField alloc] _initAsLabel];
myFrame.size.width = 289;
myFrame.size.height = 21;
myFrame.origin.x = 64;
myFrame.origin.y = 120;
[myText1 setFrame:&myFrame];
if (myTitle == NULL) [myText1 setStringValue:"ALERT"];
else [myText1 setStringValue:myTitle];
[contentView addSubview:myText1];
if (msg != NULL) {
myText2 = [[TextField alloc] _initAsLabel];
myFrame.size.width = 395;
myFrame.size.height = 36;
myFrame.origin.x = 8;
myFrame.origin.y = 45;
[myText2 setFrame:&myFrame];
[myText2 setStringValue:msg];
[contentView addSubview:myText2];
}
return self;
}
- default:sender
{
[NXApp stopModal:1];
return self;
}
- alternate:sender
{
[NXApp stopModal:0];
return self;
}
- other:sender
{
[NXApp stopModal:-1];
return self;
}
@end
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.