Completed alert panel functions

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@3453 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1998-12-14 08:58:53 +00:00
parent 286bae6e74
commit 3bdb18f536
3 changed files with 259 additions and 37 deletions

View file

@ -1,3 +1,8 @@
Mon Dec 14 9:10:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* NSPanel.m: Implemented all the alert panel functions
* NSPanel.h: Added prototypes for MacOS-X alert panel functions.
Sat Dec 12 10:10:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk> Sat Dec 12 10:10:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* NSView.m: Fixed bug and added comment about the (deliberately) * NSView.m: Fixed bug and added comment about the (deliberately)

View file

@ -87,6 +87,20 @@ id NSGetAlertPanel(NSString *title,
NSString *alternateButton, NSString *alternateButton,
NSString *otherButton, ...); NSString *otherButton, ...);
#ifndef STRICT_OPENSTEP
id NSGetCriticalAlertPanel(NSString *title,
NSString *msg,
NSString *defaultButton,
NSString *alternateButton,
NSString *otherButton, ...);
id NSGetInformationalAlertPanel(NSString *title,
NSString *msg,
NSString *defaultButton,
NSString *alternateButton,
NSString *otherButton, ...);
#endif
// //
// Create and Run an Attention Panel // Create and Run an Attention Panel
// //
@ -95,12 +109,29 @@ int NSRunAlertPanel(NSString *title,
NSString *defaultButton, NSString *defaultButton,
NSString *alternateButton, NSString *alternateButton,
NSString *otherButton, ...); NSString *otherButton, ...);
#ifndef STRICT_OPENSTEP
int NSRunCriticalAlertPanel(NSString *title,
NSString *msg,
NSString *defaultButton,
NSString *alternateButton,
NSString *otherButton, ...);
int NSRunInformationalAlertPanel(NSString *title,
NSString *msg,
NSString *defaultButton,
NSString *alternateButton,
NSString *otherButton, ...);
#endif
#ifndef STRICT_MACOS_X
int NSRunLocalizedAlertPanel(NSString *table, int NSRunLocalizedAlertPanel(NSString *table,
NSString *title, NSString *title,
NSString *msg, NSString *msg,
NSString *defaultButton, NSString *defaultButton,
NSString *alternateButton, NSString *alternateButton,
NSString *otherButton, ...); NSString *otherButton, ...);
#endif
// //
// Release an Attention Panel // Release an Attention Panel

View file

@ -33,6 +33,8 @@
#include <gnustep/gui/config.h> #include <gnustep/gui/config.h>
#include <Foundation/NSBundle.h>
#include <Foundation/NSCoder.h>
#include <AppKit/NSPanel.h> #include <AppKit/NSPanel.h>
#include <AppKit/NSApplication.h> #include <AppKit/NSApplication.h>
#include <AppKit/NSButton.h> #include <AppKit/NSButton.h>
@ -43,6 +45,7 @@
#include <AppKit/NSImage.h> #include <AppKit/NSImage.h>
#include <AppKit/NSScreen.h> #include <AppKit/NSScreen.h>
#include <AppKit/IMLoading.h> #include <AppKit/IMLoading.h>
#include <AppKit/GMAppKit.h>
#include <extensions/GMArchiver.h> #include <extensions/GMArchiver.h>
@ -83,13 +86,32 @@
// //
// Determining the Panel's Behavior // Determining the Panel's Behavior
// //
- (BOOL)isFloatingPanel { return _isFloatingPanel; } - (BOOL) isFloatingPanel
- (void)setFloatingPanel:(BOOL)flag { _isFloatingPanel = flag; } {
- (BOOL)worksWhenModal { return _worksWhenModal; } return _isFloatingPanel;
- (void)setWorksWhenModal:(BOOL)flag { _worksWhenModal = flag; } }
- (BOOL)becomesKeyOnlyIfNeeded { return _becomesKeyOnlyIfNeeded; }
- (void)setBecomesKeyOnlyIfNeeded:(BOOL)flag - (void) setFloatingPanel: (BOOL)flag
{
_isFloatingPanel = flag;
}
- (BOOL) worksWhenModal
{
return _worksWhenModal;
}
- (void) setWorksWhenModal: (BOOL)flag
{
_worksWhenModal = flag;
}
- (BOOL) becomesKeyOnlyIfNeeded
{
return _becomesKeyOnlyIfNeeded;
}
- (void)setBecomesKeyOnlyIfNeeded: (BOOL)flag
{ {
_becomesKeyOnlyIfNeeded = flag; _becomesKeyOnlyIfNeeded = flag;
} }
@ -97,16 +119,16 @@
// //
// NSCoding protocol // NSCoding protocol
// //
- (void)encodeWithCoder:aCoder - (void) encodeWithCoder: (NSCoder*)aCoder
{ {
[super encodeWithCoder:aCoder]; [super encodeWithCoder:aCoder];
} }
- initWithCoder:aDecoder - initWithCoder: (NSCoder*)aDecoder
{ {
[super initWithCoder:aDecoder]; [super initWithCoder:aDecoder];
return self; return self;
} }
@end /* NSPanel */ @end /* NSPanel */
@ -123,7 +145,9 @@
@class GSAlertPanel; @class GSAlertPanel;
static GSAlertPanel *standardAlertPanel = nil; static GSAlertPanel *standardAlertPanel = nil;
static GSAlertPanel *reusableAlertPanel = nil; static GSAlertPanel *informationalAlertPanel = nil;
static GSAlertPanel *criticalAlertPanel = nil;
static GSAlertPanel *gmodelAlertPanel = nil;
@interface GSAlertPanel : NSPanel @interface GSAlertPanel : NSPanel
{ {
@ -136,7 +160,7 @@ static GSAlertPanel *reusableAlertPanel = nil;
int result; int result;
BOOL active; BOOL active;
} }
- (void) buttonAction: (id)sender; - (void) buttonAction: (id) sender;
- (int) result; - (int) result;
- (int) runModal; - (int) runModal;
- (void) setTitle: (NSString*)title - (void) setTitle: (NSString*)title
@ -159,6 +183,20 @@ static GSAlertPanel *reusableAlertPanel = nil;
} }
} }
+ (id) createObjectForModelUnarchiver: (GMUnarchiver*)unarchiver
{
unsigned backingType = [unarchiver decodeUnsignedIntWithName:
@"backingType"];
unsigned styleMask = [unarchiver decodeUnsignedIntWithName:@"styleMask"];
NSRect aRect = [unarchiver decodeRectWithName:@"frame"];
NSPanel* panel = [[[GSAlertPanel allocWithZone:[unarchiver objectZone]]
initWithContentRect:aRect
styleMask:styleMask backing:backingType defer:YES]
autorelease];
return panel;
}
- (void) buttonAction: (id)sender - (void) buttonAction: (id)sender
{ {
if (active == NO) if (active == NO)
@ -190,6 +228,12 @@ static GSAlertPanel *reusableAlertPanel = nil;
- (void) dealloc - (void) dealloc
{ {
if (self == standardAlertPanel)
standardAlertPanel = nil;
if (self == informationalAlertPanel)
informationalAlertPanel = nil;
if (self == criticalAlertPanel)
criticalAlertPanel = nil;
[defButton release]; [defButton release];
[altButton release]; [altButton release];
[othButton release]; [othButton release];
@ -201,8 +245,13 @@ static GSAlertPanel *reusableAlertPanel = nil;
- (void) encodeWithModelArchiver: (GMArchiver *)archiver - (void) encodeWithModelArchiver: (GMArchiver *)archiver
{ {
if (standardAlertPanel) [super encodeWithModelArchiver: archiver];
[archiver encodeObject: standardAlertPanel withName: @"AlertPanel"]; [archiver encodeObject: defButton withName: @"DefaultButton"];
[archiver encodeObject: altButton withName: @"AlternateButton"];
[archiver encodeObject: othButton withName: @"OtherButton"];
[archiver encodeObject: icoButton withName: @"IconButton"];
[archiver encodeObject: messageField withName: @"MessageField"];
[archiver encodeObject: titleField withName: @"TitleField"];
} }
- (id) initWithContentRect: (NSRect)r - (id) initWithContentRect: (NSRect)r
@ -322,10 +371,15 @@ static GSAlertPanel *reusableAlertPanel = nil;
- (id) initWithModelUnarchiver: (GMUnarchiver*)unarchiver - (id) initWithModelUnarchiver: (GMUnarchiver*)unarchiver
{ {
if (!standardAlertPanel) self = [super initWithModelUnarchiver: unarchiver];
standardAlertPanel = [unarchiver decodeObjectWithName: @"AlertPanel"]; defButton = [[unarchiver decodeObjectWithName: @"DefaultButton"] retain];
[self release]; altButton = [[unarchiver decodeObjectWithName: @"AlternateButton"] retain];
return standardAlertPanel; othButton = [[unarchiver decodeObjectWithName: @"OtherButton"] retain];
icoButton = [[unarchiver decodeObjectWithName: @"IconButton"] retain];
messageField = [[unarchiver decodeObjectWithName: @"MessageField"] retain];
titleField = [[unarchiver decodeObjectWithName: @"TitleField"] retain];
gmodelAlertPanel = self;
return gmodelAlertPanel;
} }
- (int) result - (int) result
@ -483,16 +537,31 @@ NSGetCriticalAlertPanel(NSString *title,
NSString *otherButton, ...) NSString *otherButton, ...)
{ {
va_list ap; va_list ap;
NSPanel *panel; NSString *message;
GSAlertPanel *panel;
if (title == nil) if (title == nil)
title = @"Warning"; title = @"Warning";
va_start (ap, otherButton); va_start (ap, otherButton);
panel = NSGetAlertPanel(title, msg, defaultButton, message = [NSString stringWithFormat: msg arguments: ap];
alternateButton, otherButton, ap);
va_end (ap); va_end (ap);
return [panel retain]; if (criticalAlertPanel == nil)
{
panel = NSGetAlertPanel(title, msg, defaultButton,
alternateButton, otherButton, ap);
criticalAlertPanel = panel;
}
else
panel = criticalAlertPanel;
[panel setTitle: @"Critical"];
[panel setTitle: title
message: message
def: defaultButton
alt: alternateButton
other: otherButton];
return panel;
} }
id id
@ -503,22 +572,40 @@ NSGetInformationalAlertPanel(NSString *title,
NSString *otherButton, ...) NSString *otherButton, ...)
{ {
va_list ap; va_list ap;
NSPanel *panel; NSString *message;
GSAlertPanel *panel;
if (title == nil) if (title == nil)
title = @"Information"; title = @"Information";
va_start (ap, otherButton); va_start (ap, otherButton);
panel = NSGetAlertPanel(title, msg, defaultButton, message = [NSString stringWithFormat: msg arguments: ap];
alternateButton, otherButton, ap);
va_end (ap); va_end (ap);
return [panel retain]; if (informationalAlertPanel == nil)
{
panel = NSGetAlertPanel(title, msg, defaultButton,
alternateButton, otherButton, ap);
informationalAlertPanel = panel;
}
else
panel = informationalAlertPanel;
[panel setTitle: @"Information"];
[panel setTitle: title
message: message
def: defaultButton
alt: alternateButton
other: otherButton];
return panel;
} }
void void
NSReleaseAlertPanel(id alertPanel) NSReleaseAlertPanel(id alertPanel)
{ {
[alertPanel release]; if (alertPanel != standardAlertPanel &&
alertPanel != informationalAlertPanel &&
alertPanel != criticalAlertPanel)
[alertPanel release];
} }
int int
@ -542,10 +629,9 @@ NSRunAlertPanel(NSString *title,
message = [NSString stringWithFormat: msg arguments: ap]; message = [NSString stringWithFormat: msg arguments: ap];
va_end (ap); va_end (ap);
if (reusableAlertPanel) if (standardAlertPanel)
{ {
panel = reusableAlertPanel; panel = standardAlertPanel;
reusableAlertPanel = nil;
[panel setTitle: title [panel setTitle: title
message: message message: message
def: defaultButton def: defaultButton
@ -556,15 +642,115 @@ NSRunAlertPanel(NSString *title,
{ {
panel = NSGetAlertPanel(title, message, defaultButton, panel = NSGetAlertPanel(title, message, defaultButton,
alternateButton, otherButton, ap); alternateButton, otherButton, ap);
standardAlertPanel = panel;
} }
result = [panel runModal]; result = [panel runModal];
NSReleaseAlertPanel(panel);
if (reusableAlertPanel == nil) return result;
reusableAlertPanel = panel; }
else
NSReleaseAlertPanel(panel); int
NSRunCriticalAlertPanel(NSString *title,
NSString *msg,
NSString *defaultButton,
NSString *alternateButton,
NSString *otherButton, ...)
{
va_list ap;
GSAlertPanel *panel;
int result;
va_start (ap, otherButton);
panel = NSGetCriticalAlertPanel(title, msg,
defaultButton, alternateButton, otherButton, ap);
va_end (ap);
result = [panel runModal];
NSReleaseAlertPanel(panel);
return result;
}
int
NSRunInformationalAlertPanel(NSString *title,
NSString *msg,
NSString *defaultButton,
NSString *alternateButton,
NSString *otherButton, ...)
{
va_list ap;
GSAlertPanel *panel;
int result;
va_start (ap, otherButton);
panel = NSGetInformationalAlertPanel(title, msg,
defaultButton, alternateButton, otherButton, ap);
va_end (ap);
result = [panel runModal];
NSReleaseAlertPanel(panel);
return result;
}
int
NSRunLocalizedAlertPanel(NSString *table,
NSString *title,
NSString *msg,
NSString *defaultButton,
NSString *alternateButton,
NSString *otherButton, ...)
{
va_list ap;
GSAlertPanel *panel;
NSString *message;
int result;
NSBundle *bundle = [NSBundle mainBundle];
if (title == nil)
title = @"Alert";
title = [bundle localizedStringForKey: title
value: title
table: table];
if (defaultButton)
defaultButton = [bundle localizedStringForKey: defaultButton
value: defaultButton
table: table];
if (alternateButton)
alternateButton = [bundle localizedStringForKey: alternateButton
value: alternateButton
table: table];
if (otherButton)
otherButton = [bundle localizedStringForKey: otherButton
value: otherButton
table: table];
if (msg)
msg = [bundle localizedStringForKey: msg
value: msg
table: table];
va_start (ap, otherButton);
message = [NSString stringWithFormat: msg arguments: ap];
va_end (ap);
if (standardAlertPanel)
{
panel = standardAlertPanel;
[panel setTitle: title
message: message
def: defaultButton
alt: alternateButton
other: otherButton];
}
else
{
panel = NSGetAlertPanel(title, message, defaultButton,
alternateButton, otherButton, ap);
standardAlertPanel = panel;
}
result = [panel runModal];
NSReleaseAlertPanel(panel);
return result; return result;
} }