[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

 

LCommander



Overview:

LCommander is a PowerPlant class that is used for managing the state of menu items while they are the active target or in the active chain of command.

Methods :

The methods in this class are:

 

LCommander()  
~LCommander()  
AddSubCommander()  
AllowSubRemoval()  
AllowTargetSwitch()  
AttemptQuit()  
AttemptQuitSelf()  
BeTarget()  
DontBeTarget()  
FindCommandStatus()  
GetDefaultCommander()  
GetLatentSub()  
GetSuperCommander()  
GetTarget()  
GetTopCommander()  
GetUpdateCommandStatus()  
HandleKeyPress()  
InitCommander()  
IsOnDuty()  
IsSyntheticCommand()  
IsTarget()  
ObeyCommand()  
PostAction()  
PostAnAction()  
ProcessCommand()  
ProcessCommandStatus()  
ProcessKeyPress()  
PutChainOnDuty()  
PutOnDuty()  
RemoveSubCommander()  
RestoreTarget()  
SetDefaultCommander()  
SetLatentSub()  
SetSuperCommander()  
SetTarget()  
SetUpdateCommandStatus()  
SwitchTarget()  
TakeChainOffDuty()  
TakeOffDuty()  
 

Data Members:

The data members in this class are:

 

sTopCommander  
sTarget  
sDefaultCommander  
sUpdateCommandStatus  
mSuperCommander  
mSubCommanders  
mOnDuty  
 

Operation:

A commander may be on or off duty, and has functions to manage the duty state. This is an important concept, because an off-duty commander will not receive or respond to events.

To learn more about Commanders and how to use them with PowerPlant, refer to The PowerPlant Book.

Source files:

(Commander Classes)

LCommander.h

LCommander.cp

Ancestors:

LAttachable

See Also:

LMenu

LMenuBar

LCommander()

Purpose:

The constructor creates objects from the passed-in parameters.

Access:

Public

Prototype:

LCommander();

LCommander( const LCommander &inOriginal );

LCommander( LCommander *inSuper );
Parameters:

The parameters for these constructors are:

 

const   LCommander&  
inOriginal  
The reference to the object to copy.  
LCommander*  
inSuper  
The pointer to the super commander.  

~LCommander()

Purpose:

The destructor destroys the object.

Access:

Virtual, Public

Prototype:

virtual ~LCommander();

AddSubCommander()

Purpose:

Adds a subcommander to the commander object.

Access:

Virtual, Protected

Prototype:

virtual void AddSubCommander( LCommander *inSub );
Parameters:

The parameter for this method is:

 

LCommander*  
inSub  
The pointer to the subcommander.  

Return:

None

AllowSubRemoval()

Purpose:

This method indicates whether removal of subcommanders is allowed.

Access:

Virtual, Public

Prototype:

virtual Boolean AllowSubRemoval(LCommander* 
inSub);
Parameters:

The parameter for this method is:

 

LCommander*  
inSub  
Unused.  

Return:

Boolean indicating whether the removal is allowed.

AllowTargetSwitch()

Purpose:

Grant permission to switch the target to the specified Commander.

Both the current target and inNewTarget must be Subordinates of this Commander.

This method passes the request up the command chain by calling AllowTargetSwitch() for its SuperCommander.

Subclasses should override this function if they wish to disallow a target switch under certain circumstances.

Access:

Virtual, Public

Prototype:

virtual Boolean AllowTargetSwitch(
LCommander *inNewTarget);
Parameters:

The parameter for this method is:

 

LCommander*  
inNewTarget  
The pointer to the new target.  

Return:

A Boolean indicating whether the target switch was allowed.

AttemptQuit()

Purpose:

This method asks all subcommanders if we can quit.

Access:

Virtual, Public

Prototype:

virtual Boolean AttemptQuit(
long inSaveOption);
Parameters:

The parameter for this method is:

 

long  
inSaveOption  
The save option to pass to AttemptQuitSelf().  

Return:

Boolean indicating whether it is valid to quit, false if not.

AttemptQuitSelf()

Purpose:

This is a private method that indicates whether it is valid to quit.

Access:

Virtual, Protected

Prototype:

virtual Boolean AttemptQuitSelf(
SInt32 inSaveOption );
Parameters:

The parameter for this method is:

 

long  
inSaveOption  
Unused.  

Return:

Boolean indicating whether it is valid to quit, false if not.

BeTarget()

Purpose:

This method is called when the Commander is becoming the Target.

Subclasses should override this function if they wish to behave differently when they are and are not the target. At entry, the class variable sTarget points to this command.

Access:

Virtual, Protected

Prototype:

virtual void BeTarget();
Parameters:

None

Return:

None

DontBeTarget()

Purpose:

This method is called when the commander will no longer be the target.

Subclasses should override this function if they wish to behave differently when they are and are not the target. At entry, the class variable sTarget points to this commander. sTarget will be changed soon afterwards to the new target.

Access:

Virtual, Protected

Prototype:

virtual void DontBeTarget()
Parameters:

None

Return:

None

FindCommandStatus()

Purpose:

This method passes back the status of a command.

Subclasses must override to enable/disable and mark commands. PowerPlant uses the enabling and marking information to set the appearance of Menu items.

Access:

Virtual, Public

Prototype:

virtual void FindCommandStatus(
CommandT inCommand,
Boolean &outEnabled,
Boolean &outUsesMark,
UInt16 &outMark,
Str255 outName);
Parameters:

The parameters for this method are:

 

CommandT  
inCommand  
The command passed to this method.  
Boolean&  
outEnabled  
Tells whether the command is enabled.  
Boolean&  
outUsesMark  
Tells whether the command uses a mark.  
UInt16&  
outMark  
The mark information for the command.  
Str255  
outName  
The name string.  

Return:

None

GetDefaultCommander()

Purpose:

This method returns the value of the sDefaultCommander data member.

Access:

Inline, Static, Public

Prototype:

static LCommander* GetDefaultCommander();
Parameters:

None

Return:

Returns the value of sDefaultCommander.

GetLatentSub()

Purpose:

Find the latent subcommander of a Commander. A Commander may have one or no latent subcommander.

Access:

Virtual, Public

Prototype:

virtual LCommander* GetLatentSub();
Parameters:

None

Return:

Returns the latent subcommander in a pointer to an LCommander.

GetSuperCommander()

Purpose:

Return the value of the mSuperCommander data member.

Access:

Inline, Public

Prototype:

LCommander* GetSuperCommander();
Parameters:

None

Return:

Returns the value of mSuperCommander.

GetTarget()

Purpose:

Return the value of the sTarget data member.

Access:

Inline, Static, Public

Prototype:

static LCommander* GetTarget();
Parameters:

None

Return:

Returns the value of sTarget.

GetTopCommander()

Purpose:

Returns the value of sTopCommander data member.

Access:

Inline, Static, Public

Prototype:

static LCommander* GetTopCommander();
Parameters:

None

Return:

Returns the value of sTopCommander.

GetUpdateCommandStatus()

Purpose:

Returns the value of sUpdateCommandStatus data member.

Access:

Inline, Static, Public

Prototype:

static Boolean GetUpdateCommandStatus()
Parameters:

None

Return:

Returns the value of sUpdateCommandStatus.

HandleKeyPress()

Purpose:

This method processes key presses.

Access:

Virtual, Public

Prototype:

virtual Boolean HandleKeyPress(
const EventRecord &inKeyEvent );
Parameters:

This method has the following parameter:

 

const   EventRecord&  
inKeyEvent  
The key press event.  

Return:

Boolean of true if the key press was handled, else false.

InitCommander()

Purpose:

Private function for initializing data members from the constructors.

Access:

Private

Prototype:

void InitCommander( LCommander *inSuper );
Parameters:

This method has the following parameter:

 

LCommander*  
inSuper  
Pointer to the SuperCommander.  

Return:

None

IsOnDuty()

Purpose:

Indicate whether this commander is on duty.

Access:

Public

Prototype:

Boolean IsOnDuty() const;
Parameters:

None

Return:

Boolean of true if the command is on duty, else false.

IsSyntheticCommand()

Purpose:

Indicate whether a command is synthetic. If so, pass back the associated Menu ID and item number. If not synthetic, outMenuID and outMenuItem are undefined.

Access:

Static, Public

Prototype:

static Boolean IsSyntheticCommand(
CommandT inCommand,
ResIDT &outMenuID,
SInt16 &outMenuItem);
Parameters:

This method has the following parameters:

 

CommandT  
inCommand  
Command passed to this method.  
ResIDT&  
outMenuID  
The menu resource ID.  
SInt16&  
outMenuItem  
The menu item number.  

Return:

Boolean of true if the command is synthetic, else false.

Remarks:

A synthetic command number has the Menu ID in the high 16 bits and the item number in the low 16 bits, with the result negatated.

syntheticCmd = - (MenuID << 16) - ItemNumber

A synthetic command is the negative of the value returned by the Toolbox traps MenuSelect() and MenuKey().

The LMenu and LMenuBar classes return synthetic command numbers for menu items whose actual command number is cmd_UseMenuItem. You should use synthetic command numbers when the menu choice depends on the runtime name of the menu item. For example, an item in a Font menu.

IsTarget()

Purpose:

Return whether this Commander is the target

Access:

Public

Prototype:

Boolean IsTarget() const;
Parameters:

None

Return:

Return true if the Commander is the target, else false.

ObeyCommand()

Purpose:

Issue a command to a Commander.

Subclasses must override this method in order to respond to commands.

Access:

Virtual, Public

Prototype:

virtual Boolean ObeyCommand(
CommandT inCommand,
void *ioParam );
Parameters:

This method has the following parameters:

 

CommandT  
inCommand  
Command passed to this method.  
void*  
ioParam  
The data block to accompany the command.  

Return:

Returns whether the command was handled (true) or not (false).

PostAction()

Purpose:

If an attachment doesn't intercept the msg_PostAction, this function will post the action up to the supercommander of this object. The default NULL parameter will effectively clear or "commit" the last semantic action.

If an attachment didn't process the posting and there's no supercommander, this function will attempt to Redo, Finalize, and delete the action.

Access:

Virtual, Public

Prototype:

virtual void PostAction( LAction *inAction );
Parameters:

This method has the following parameter:

 

LAction*  
inAction  
The action to post.  

Return:

None

PostAnAction()

Purpose:

Post the action to the present target. This is a static member function that can be used by anything needing to post an action.

If there is no present target, function will attempt to Redo, Finalize, and delete the action.

Access:

Static, Public

Prototype:

static void PostAnAction( LAction *inAction );
Parameters:

This method has the following parameter:

 

LAction*  
inAction  
The action to post.  

Return:

None

ProcessCommand()

Purpose:

Issue a command to a Commander.

This function lets Attachments handle the Command before calling the normal ObeyCommand() function.

Access:

Virtual, Public

Prototype:

virtual Boolean ProcessCommand(
CommandT inCommand,
void *ioParam );
Parameters:

This method has the following parameters:

 

CommandT  
inCommand  
Command passed to this method.  
void*  
ioParam  
The data block to accompany the command.  

Return:

Returns whether the command was handled (true) or not (false).

ProcessCommandStatus()

Purpose:

Pass back the status of a command. This method lets Attachments set the command status before calling the normal FindCommandStatus() method.

Access:

Virtual, Public

Prototype:

virtual void ProcessCommandStatus(
CommandT inCommand,
Boolean &outEnabled,
Boolean &outUsesMark,
UInt16 &outMark,
Str255 outName );
Parameters:

The parameters for this method are:

 

CommandT  
inCommand  
Command passed to this method.  
Boolean&  
outEnabled  
Tells whether the command is enabled.  
Boolean&  
outUsesMark  
Tells whether the command uses a mark.  
UInt16&  
outMark  
The mark information for the command.  
Str255  
outName  
The name string.  

Return:

None

ProcessKeyPress()

Purpose:

Processes keystrokes.

Access:

Virtual, Public

Prototype:

virtual Boolean ProcessKeyPress(
const EventRecord &inKeyEvent );
Parameters:

This method has the following parameter:

 

const   EventRecord&  
inKeyEvent  
The key press event.  

Return:

Returns true if handled, else false.

PutChainOnDuty()

Purpose:

Put on duty a chain of Commanders. This is a wrapper function that guarantees that a Commander can't be put on duty until all its Superiors are on duty.

Access:

Protected

Prototype:

void PutChainOnDuty();
Parameters:

None

Return:

None

PutOnDuty()

Purpose:

Called when a Commander is going on duty. Subclasses should override this function if they wish to behave differently when on duty than when off duty.

Access:

Virtual, Protected

Prototype:

virtual void PutOnDuty();
Parameters:

None

Return:

None

RemoveSubCommander()

Purpose:

This method removes a Subcommander.

Access:

Virtual, Protected

Prototype:

virtual void RemoveSubCommander(LCommander 
*inSub);
Parameters:

This method has the following parameter:

 

LCommander*  
inSub  
The pointer to the commander to remove.  

Return:

None

RestoreTarget()

Purpose:

Set target to the Commander which was the target when this Commander was last on duty.

Access:

Virtual, Public

Prototype:

virtual void RestoreTarget();
Parameters:

None

Return:

None

SetDefaultCommander()

Purpose:

Sets the value of the sDefaultCommander data member.

Access:

Inline, Static, Public

Prototype:

static void SetDefaultCommander( 
  LCommander *inCommander );
Parameters:

This method has the following parameter:

 

LCommander*  
inCommander  
The pointer to the commander to set.  

Return:

None

SetLatentSub()

Purpose:

Specify the Subcommander that will be put on duty when this Commander is put on duty.

This method does nothing if this Commander is already on duty. inSub may be nil, in which case this Commander will have no Latent Subcommander. This will also be the case if inSub is not a Subordinate of this Commander (which raises a Signal).

Access:

Virtual, Public

Prototype:

virtual void SetLatentSub( LCommander *inSub );
Parameters:

This method has the following parameter:

 

LCommander*  
inSub  
The pointer to the commander to remove.  

Return:

None

SetSuperCommander()

Purpose:

Command chain maintenance method.

Access:

Virtual, Public

Prototype:

virtual void SetSuperCommander(LCommander 
*inSuper);
Parameters:

This method has the following parameter:

 

LCommander*  
inSuper  
The pointer to the Supercommander to set.  

Return:

None

SetTarget()

Purpose:

Set the Target class variable. Called internally.

Access:

Static, Protected

Prototype:

static void SetTarget( LCommander *inNewTarget );
Parameters:

This method has the following parameter:

 

LCommander*  
inNewTarget  
The pointer to the Commander to set as the Target.  

Return:

None

SetUpdateCommandStatus()

Purpose:

This method sets the value of the sUpdateCommandStatus data member.

Access:

Static, Public

Prototype:

static void SetUpdateCommandStatus(
Boolean inDirty );
Parameters:

This method has the following parameter:

 

Boolean  
inDirty  
The value indicating whether to mark as dirty or not.  

Return:

None

SwitchTarget()

Purpose:

Try to change Target and return whether the specified Commander did indeed become the Target.

A Target switch can fail if some superior of the old and new Target disallows the switch. For example, this could happen when performing data entry validation.

Access:

Static, Public

Prototype:

static Boolean SwitchTarget(
LCommander *inNewTarget );
Parameters:

This method has the following parameter:

 

LCommander*  
inNewTarget  
The pointer to the Commander to set as the Target.  

Return:

Boolean indicating whether the switch was allowed (true) or not (false).

TakeChainOffDuty()

Purpose:

Take a chain of Commanders off duty.

This is a wrapper function that traverses a command chain from the Commander that firsts receives this message up to the specified Commander. The inUpToCmdr is not taken off duty.

It is an error if inUpToCmdr is not a Superior of the Commander that first receives this message. Note that this includes the case where inUpToCmdr is the Commander that first receives this message (since a Commander is not a Superior of itself). nil is a valid value for inUpToCmdr, since the Commander at the top of a chain of command has a nil SuperCommander.

Access:

Protected

Prototype:

void TakeChainOffDuty(const LCommander 
*inUpToCmdr);
Parameters:

This method has the following parameter:

 

LCommander*  
inUpToCmdr  
The pointer to the Commander to take off duty.  

Return:

None

TakeOffDuty()

Purpose:

A Commander is going off duty. Subclasses should override this method if they wish to behave differently when on duty than when off duty.

Access:

Protected

Prototype:

virtual void TakeOffDuty();
Parameters:

None

Return:

None

sTopCommander

Purpose:

The top Commander pointer.

Access:

Protected

Prototype:

static LCommander *sTopCommander;

sTarget

Purpose:

The Target pointer.

Access:

Protected

Prototype:

static LCommander *sTarget;

sDefaultCommander

Purpose:

The default Commander pointer.

Access:

Protected

Prototype:

static LCommander *sDefaultCommander;

sUpdateCommandStatus

Purpose:

Indicates whether command status should be updated.

Access:

Protected

Prototype:

static Boolean sUpdateCommandStatus;

mSuperCommander

Purpose:

The pointer to the Supercommander.

Access:

Protected

Prototype:

LCommander *mSuperCommander;

mSubCommanders

Purpose:

An array of pointers to Subcommanders.

Access:

Protected

Prototype:

TArray<LCommander*> mSubCommanders;

mOnDuty

Purpose:

Indicates whether the Commander is on duty or not.

Access:

Protected

Prototype:

ETriState mOnDuty;

 


[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.

Last updated: July 21, 2000