Release 3.0, Copyright ©1998 by Sean Luke.  All Rights Reserved.



ModuleMenuNode





Subclass Of: NSObject

Declared In: ModuleMenuNode.h




Class Description

This object stores menu information to be passed to Resound from modules.  Future versions will eliminate this node (I hope), when IB is able to generate menus without an application (or I learn to).

The Module Menu Node is a tree node.  The root (top) node of the tree should be set with a blank name.  This node contains all the menu items to be added directly to Resound's Modules menu. Children nodes have names, and the menu items they contain are for custom submenus off of the Modules Menu.

Let's say you want to make two menu options in the Modules menu.  One is just a standard menu option, called "Tweak".  The other displays a submenu, called "Twist", with submenu items "Bend", "Break", and "Bust".  You'd generate a tree like this:

(Root Node)
Name (not set, defaults to @"")  (empty string)
Receiver (not set) (indicates this node has submenus)
Message (not set)
Length 2 (for Tweak and Twist)
Submenu[0] points to the node Tweak
Submenu[1] points to the node Twist

Tweak
Name "Tweak"
Receiver object that will receive the Tweak message
Message selector of message sent to Tweak's receiver
Length 0
Submenu... (not set)

Twist
Name "Twist"
Receiver (not set) (indicates this node has submenus)
Message (not set)
Length 3 (for Bend, Break, and Bust)
Submenu[0] points to the node Bend
Submenu[1] points to the node Break
Submenu[2] points to the node Bust

Bend
Name "Bend"
Receiver object that will receive the Bend message
Message selector of message sent to Bend's receiver
Length 0
Submenu... (not set)

Break
Name "Break"
Receiver object that will receive the Break message
Message selector of message sent to Break's receiver
Length 0
Submenu... (not set)

Bust
Name "Bust"
Receiver object that will receive the Bust message
Message selector of message sent to Bust's receiver
Length 0
Submenu... (not set)

To do this, you might  write write the init method of your module to look like:

- init
{
id returnVal=[super init];
// ABSOLUTELY CALL [super init] FIRST!!!

ModuleMenuNode* tweak= [[ModuleMenuNode alloc]
initLeafNode:@"Tweak":self:@selector(tweakMe:)];
ModuleMenuNode* twist= [[ModuleMenuNode alloc]
initNonleafNode:@"Twist"];

ModuleMenuNode* bend= [[ModuleMenuNode alloc]
initLeafNode:@"Bend":self:@selector(bendMe:)];
ModuleMenuNode* break= [[ModuleMenuNode alloc]
initLeafNode:@"Break":self:@selector(breakMe:)];
ModuleMenuNode* bust= [[ModuleMenuNode alloc]
initLeafNode:@"Bust":self:@selector(bustMe:)];

[TheModuleMenuNode addSubmenu: tweak];
[TheModuleMenuNode addSubmenu: twist];

[twist addSubmenu: bend];
[twist addSubmenu: break];
[twist addSubmenu: bust];

[tweak release]; [twist release];
[bend release]; [break release]; [bust release];

return returnVal;
}

As a result, Resound would create menus in its Modules menu as such:

Resound attaches the appropriate receiver to as the target of Tweak, Bend, Break, and Bust, and sets them to call the appropriate message.  In the example above, the receivers of all menus have been set to your own module, and the modules will call, respectively, tweakMe:, bendMe:, breakMe:, or bustMe:.

Instance Variables
NSString*  name;
id receiver;
id message;
int length;
NSMutableArray* submenu;

name  The name to put in the menu.

receiver  The target of the method sent when the menu is selected.

message  The selector for the method sent when the menu is selected.

length  The number of items in the submenu. This is no longer used in the API, but is here for backward-compatibility only

submenu  The array of submenu ModuleMenuNodes.



Method Types

Object Maintenance - initLeafNode:::
- initNonleafNode:
- dealloc

Data Retrieval - getNameAsString
- getReceiver
- getMessage
- getSubmenu:
- numSubmenus
- isLeafNode



Setting Data - setNameToString:
- setReceiver:
- setMessage:
- addSubmenu:

Backward-Compatibility - init
- getName
- setName:
- setLength:
- getLength
- setSubmenu::






Instance Methods

addSubmenu:
addSubmenu: (ModuleMenuNode*) this_node

Sets this_node as the next node in the ModuleMenuNode's submenu array.

dealloc
- (void) dealloc

Frees the ModuleMenuNode.

getLength
-  (int) getLength

Returns the length of the ModuleMenuNode's submenu array.   Only for backward-compatibility.  You should use numSubmenus instead (more robust).

getMessage
-  (SEL) getMessage

Returns the ModuleMenuNode's receiving message.

getName
- (char*) getName

Returns the ModuleMenuNode's name.   You should not expect this name to be around for long (even a second call to getName: will change it). For backward-compatibility.  You should now use getNameAsString:.

getNameAsString
- (NSString*) getNameAsString

Returns the ModuleMenuNode's name.

getReceiver
getReceiver

Returns the ModuleMenuNode's receiver (target).

getSubmenu:
getSubmenu:(int)this_index

Returns the subsidiary ModuleMenuNode that is at this_index position of the parent ModuleMenuNode's submenu array .

init
- init

Initializes the ModuleMenuNode.  Only for backward-compatibility.

initLeafNode:::
- initLeafNode:(NSString*) this_name:(NSObject*) this_receiver:(SEL)this_message

Initializes the ModuleMenuNode to be a leaf node, that is, one which doesn't just pop up a submenu.

initNonleafNode:::
- initNonleafNode:(NSString*) this_name

Initializes the ModuleMenuNode to be a nonleaf node, that is, one which pops up a submenu.

isLeafNode
-  (BOOL)isLeafNode

Returns YES if this was initialized as a leaf node, NO if it was initialized as a nonleaf node. This is the defining method for whether or not a node is a leaf node.

numSubmenus
-  (int)numSubmenus

Returns the number of submenus currently stored in this node.

setLength:
setLength:(int)this_length

Sets the length of the ModuleMenuNode's submenu array to this_length.   Only for backward-compatibility.

setMessage:
setMessage:(SEL)this_message

Sets the ModuleMenuNode's receiving message to this_message, which should be a selector for a method of one id argument (which will be the menu whose menu item had been selected).  For backward compatibility, when this method is called, the node then "becomes" a leaf node.

setName:
- setName:(char*)this_name

Sets the ModuleMenuNode's name to this_name. For backward-compatibility only.  You should now use setNameToString:.

setNameToString:
- setNameToString:(NSString*)this_name

Sets the ModuleMenuNode's name to this_name.

setReceiver:
setReceiver:this_receiver

Sets the ModuleMenuNode's receiver (target). This will be the object sent the message defined in setMessage when the ModuleMenuNode's menu item is selected by the user.  For backward compatibility, when this method is called, the node then "becomes" a leaf node.

setSubmenu::
setSubmenu:(int)this_index : this_node

Sets (as this_node) the subsidiary ModuleMenuNode that is at this_index position of the parent ModuleMenuNode's submenu array.   Only for backward-compatibility.  Note that this will now only work if you set the menus in order (0, 1, 2, 3... etc.).  Otherwise your old code may break.