12 #import "WKWizardPanel.h"
14 #import <Foundation/NSString.h>
15 #import <Foundation/NSBundle.h>
16 #import <Foundation/NSArray.h>
17 #import <Foundation/NSDictionary.h>
18 #import <Foundation/NSException.h>
19 #import <Foundation/NSNotification.h>
20 #import <Foundation/NSCoder.h>
22 #import <AppKit/NSApplication.h>
29 NSString *
const WKWizardPanelDidChangeCurrentStageNotification
30 =
@"WKWizardPanelDidChangeCurrentStageNotification";
32 @interface WKWizardPanel (Private)
34 - (void) setupForStage: (NSString *) aStage;
82 - (void) setStages: (NSArray *) someStages
86 [NSException raise: NSInternalInconsistencyException
87 format: _(@"-[WKWizardPanel setStages:]: panel already "
88 @"active - stages must be set before activating the panel.")];
91 ASSIGNCOPY(
stages, someStages);
115 - (void) setRunsInModalSession: (BOOL) flag
119 [NSException raise: NSInternalInconsistencyException
120 format: _(@"-[WKWizardPanel setRunsInModalSession:] "
121 @"panel already active - modality must be set before activating "
146 - (void) setInitialStage: (NSString *) aStageName
148 if (aStageName != nil && [
stages containsObject: aStageName] == NO)
150 [NSException raise: NSInvalidArgumentException
151 format: _(@"-[WKWizardPanel setInitialStage:]: "
152 @"invalid stage name passed. Stage \"%@\" not in stages list: %@."),
177 - (void) setCentersBeforeActivating: (BOOL) flag
205 - (void) setCurrentStage: (NSString *) aStageName
210 [NSException raise: NSInvalidArgumentException
211 format: _(@"-[WKWizardPanel setCurrentStage:]: "
212 @"invalid stage name passed. Stage \"%@\" not in stages list: %@."),
216 [
self setupForStage: aStageName];
218 [[NSNotificationCenter defaultCenter]
219 postNotificationName: WKWizardPanelDidChangeCurrentStageNotification
221 userInfo: [NSDictionary dictionaryWithObject: aStageName
234 return [stages objectAtIndex: currentStage];
243 - (void) nextStage: (
id) sender
247 [
self setCurrentStage: [stages objectAtIndex: currentStage + 1]];
257 - (void) previousStage: (
id) sender
261 [
self setCurrentStage: [stages objectAtIndex: currentStage - 1]];
281 - (int) activate: (
id) sender
285 [NSException raise: NSInternalInconsistencyException
286 format: _(@"-[WKWizardPanel activate:]: panel "
287 @"already active.")];
292 [NSException raise: NSInternalInconsistencyException
293 format: _(@"-[WKWizardPanel activate:]: no stages "
294 @"set. You must set the panel's stages before activating it.")];
301 [
self setCurrentStage: initialStage];
305 [
self setCurrentStage: [stages objectAtIndex: 0]];
317 code = [NSApp runModalForWindow: self];
325 [
self makeKeyAndOrderFront: nil];
327 return NSRunStoppedResponse;
342 - (void) deactivate: (
id) sender
346 [NSException raise: NSInternalInconsistencyException
347 format: _(@"-[WKWizardPanel deactivate:]: panel "
372 - (void) deactivateWithCode: (
int) code
376 [NSException raise: NSInternalInconsistencyException
377 format: _(@"-[WKWizardPanel deactivateWithCode:]: "
378 @"panel not active.")];
383 [NSException raise: NSInternalInconsistencyException
384 format: _(@"-[WKWizardPanel deactivateWithCode]: "
385 @"panel was not run in modal session. Use \"-deactivate:\" to "
386 @"deactivate a non-modal panel instead.")];
391 [NSApp stopModalWithCode: code];
406 - (void) encodeWithCoder: (NSCoder*) aCoder
408 [
super encodeWithCoder: aCoder];
410 if ([aCoder allowsKeyedCoding])
412 [aCoder encodeBool: runsInModalSession
413 forKey: @"WKRunsInModalSessionFlag"];
414 [aCoder encodeBool: runsInModalSession
415 forKey: @"WKCentersBeforeActivatingFlag"];
417 [aCoder encodeObject: stages forKey: @"WKStages"];
418 [aCoder encodeObject: initialStage forKey: @"WKInitialStage"];
422 [aCoder encodeValueOfObjCType: @encode(BOOL)
423 at: &runsInModalSession];
424 [aCoder encodeValueOfObjCType: @encode(BOOL)
425 at: ¢ersBeforeActivating];
427 [aCoder encodeObject: stages];
428 [aCoder encodeObject: initialStage];
432 - (id) initWithCoder: (NSCoder*) aDecoder
434 if ((
self = [super initWithCoder: aDecoder]) != nil)
436 if ([aDecoder allowsKeyedCoding])
439 @"WKRunsInModalSessionFlag"];
441 @"WKCentersBeforeActivatingFlag"];
443 ASSIGN(
stages, [aDecoder decodeObjectForKey:
@"WKStages"]);
445 decodeObjectForKey:
@"WKInitialStage"]);
449 [aDecoder decodeValueOfObjCType: @encode(BOOL)
450 at: &runsInModalSession];
451 [aDecoder decodeValueOfObjCType: @encode(BOOL)
452 at: ¢ersBeforeActivating];
454 ASSIGN(
stages, [aDecoder decodeObject]);
469 @implementation WKWizardPanel (Private)
476 - (void) setupForStage: (NSString *) aStage
478 [
self setContentView: [[
self delegate] wizardPanel: self
479 viewForStage: aStage]];
480 [
self setInitialFirstResponder: [[
self delegate] wizardPanel: self
481 initialFirstResponderForStage: aStage]];
507 viewForStage: (NSString *) aStageName
509 [NSException raise: NSInternalInconsistencyException
510 format: _(@"Wizard delegate %@ didn't override %@."),
511 [
self className], NSStringFromSelector(_cmd)];
526 initialFirstResponderForStage: (NSString *) aStageName
This informal protocol defines what methods the delegate of a wizard panel may or must implement to c...
NSString * initialStage
Returns the receiver's initial stage.
unsigned int currentStage
Returns the current stage which the receiver displays.
BOOL isActive
Returns whether the receiver is active or not.
NSArray * stages
Returns a list of stages of the receiver.
BOOL centersBeforeActivating
Returns whether the receiver centers itself before activating.
BOOL runsInModalSession
Returns whether the receiver activates itself in a modal session.