Class: TSubMenuItem

Declaration: MenuControls.h

Taxonomy Categories:

Member Functions:


Interface Category:

API.

Inherits From:

TMomentaryMenuItem

Inherited By:

TPopUpSubMenuItem

Purpose:

TSubMenuItem derives from TMomentaryMenuItem and implements a special menu item that pops open a submenu when the user clicks on it. This class wraps a submenu so that a hierarchy of menus can be assembled. When the user selects a submenu item, the menu that the item represents is automatically displayed on the screen. In this way, the user can traverse down into submenus in a single mouse gesture. When the submenus are displayed, they are positioned to fit entirely within a screen. If the menu is too large for the screen, it is clipped and autoscrolling is enabled. TSubMenuItem inherits from TMomentaryMenuItem just in case a client wants to adopt a momentary control state into it. This control state can be used to lazy construct the items in the submenu. The control state can get the submenu by calling GetControlView and then dynamically casting the result to a TMenu. The control state can populate the submenu when SetPressed(true) is called. It can also delete all the items when SetPressed(false) is called because TSubMenuItem guarantees to only call these member functions when the menu is shown and hidden. Deleting the items is only recommended if the enabled state of the items and of the submenu item itself is always true and if constructing the items is relatively cheap or if you need the memory for something else. By doing this, constructing the initial set of menus is cheaper and faster.

Instantiation:

Usually allocated on the heap so that it can be adopted into a menu.

Deriving Classes:

It is unlikely that you will need to derive from this. One possibility is that you might want to add a new menu item subpart or rearrange the existing parts by overriding GetNumberOfParts, GetLabelPartIndex, GetPreferredPartSize, SetPartBounds, and DrawParts or you might want to change the behavior of the interactor by overriding CreateInteractor to return your own interactor.

Concurrency:

Not multithread safe.

Resource Use:

No special requirements.

Member Function: TSubMenuItem::TSubMenuItem

  1. TSubMenuItem ()
  2. TSubMenuItem (TLabel * label)
  3. TSubMenuItem (TMenu * submenu, TLabel * label =NIL)
  4. TSubMenuItem (const TSubMenuItem &)

Interface Category:

API.

Purpose:

  1. Default constructor.
  2. Creates a menu item with the specified label.
  3. Creates a menu item with the specified label and submenu.
  4. Copy constructor. Clones the entire menu hierarchy within the specified menu that is adopted into the submenu item.

Calling Context:

  1. Called by the stream-in operators and derived classes.
  2. Call this function directly.
  3. Call this function directly.
  4. Called to copy an object.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TSubMenuItem::~TSubMenuItem

virtual ~ TSubMenuItem ()

Interface Category:

API.

Purpose:

Destructor.

Calling Context:

Called to destroy an object.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TSubMenuItem::operator=

TSubMenuItem & operator =(const TSubMenuItem &)

Interface Category:

API.

Purpose:

Assignment operator. This function deletes its adopted submenu and clones the submenu in the specified menu item and adopts the clone. Cloning the menu also clones all its submenus.

Calling Context:

Call this function by using the operator in an assignment statement.

Parameters:

Return Value:

Returns a const reference to the left-hand side object.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TSubMenuItem::operator>>=

virtual TStream & operator >>=(TStream &) const

Interface Category:

API.

Purpose:

Stream-out operator. Flattens the adopted submenu.

Calling Context:

Called to stream out data.

Parameters:

Return Value:

Returns a reference to the stream the object streams itself out to.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TSubMenuItem::operator<<=

virtual TStream & operator <<= (TStream &)

Interface Category:

API.

Purpose:

Stream-in operator.

Calling Context:

Called to stream in data.

Parameters:

Return Value:

Returns a reference to the stream the object streams itself in from.

Exceptions:

Throws TInvalidVersionError if the object has detected an unsupportable version during the stream-in process.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TSubMenuItem::AdoptSubMenu

virtual void AdoptSubMenu (TMenu * menu)

Interface Category:

API.

Purpose:

Adopts the specified menu. This menu is popped up when the submenu item is selected by the user. A submenu item can only represent a single submenu, so this function deletes any existing submenu.

Calling Context:

Call this function directly.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TSubMenuItem::OrphanSubMenu

virtual TMenu * OrphanSubMenu ()

Interface Category:

API.

Purpose:

Orphans this menu item's submenu. The caller is responsible for deleting the orphaned submenu. A submenu item with no submenu is disabled.

Calling Context:

Call this function directly.

Parameters:

Return Value:

Returns the orphaned submenu.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TSubMenuItem::GetSubMenu

virtual TMenu * GetSubMenu () const

Interface Category:

API.

Purpose:

Returns a pointer to the submenu currently adopted into this menu item.

Calling Context:

Called during menu initialization and user interaction. You can also call this function directly.

Parameters:

Return Value:

Returns the currently adopted menu, or NIL if no menu is adopted.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TSubMenuItem::GetNumberOfParts

virtual unsigned long GetNumberOfParts () const

Interface Category:

API.

Purpose:

Returns the number of parts in this menu item. This function adds one to the number of subparts returned from MMenuItem. The additional part is for the submenu arrow.

Calling Context:

Called by the owning menu during layout negotiations.

Parameters:

Return Value:

Returns the number of parts.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

Overrides the inherited MMenuItem function.

Member Function: TSubMenuItem::GetLabelPartIndex

virtual unsigned long GetLabelPartIndex () const

Interface Category:

API.

Purpose:

Returns the index of the main label for this menu item. The index indicates the position of the main label relative to the beginning edge of the menu item. Indexes begin at 0. This class returns the same label part index returned from MMenuItem. The submenu arrow comes after the MMenuItem label, so there is no need to change the label index.

Calling Context:

Called during menu layout. You can also call this function directly.

Parameters:

Return Value:

Returns the label part index.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

Overrides the inherited MMenuItem function.

Member Function: TSubMenuItem::GetPreferredPartSize

virtual TGPoint GetPreferredPartSize (unsigned long part) const

Interface Category:

API.

Purpose:

Determines the preferred size of the specified subpart. If the part index is for the submenu arrow, this function returns the preferred size of the submenu arrow graphic. If the part index is not for the submenu arrow, then it returns the preferred size from MMenuItem (being careful to adjust the part number so that it matches what MMenuItem expects to get).

Calling Context:

Called during menu layout. You can also call this function directly.

Parameters:

Return Value:

Returns the preferred size of the specified subpart.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

Overrides the inherited MMenuItem function.

Member Function: TSubMenuItem::SetPartBounds

virtual void SetPartBounds (unsigned long part, TGRect & bounds)

Interface Category:

API.

Purpose:

Sets the bounds of the specified subpart. If the part index is for the submenu arrow, this function stores the new bounds for the submenu arrow. Otherwise, this function adjusts the part index and passes the bounds to MMenuItem.

Calling Context:

Called during menu layout. Do not call this function directly unless it is from an override of this member function in a derived class.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

Overrides the inherited MMenuItem function.

Member Function: TSubMenuItem::SetArrowVisible

virtual void SetArrowVisible (bool visible =true)

Interface Category:

API.

Purpose:

Sets whether a submenu arrow graphic is displayed on this menu item. Normally, the arrow is visible if the layout of the items in the owning menu is perpendicular to the layout of the subparts of the items. For example, if the menu items are laid out from top to bottom and the item's subparts are laid out from left to right, an arrow is visible. Whereas, if the item subparts are also laid out from left to right, no arrow is visible. SetArrowVisible can be called to override this default algorithm.

Calling Context:

Call this function directly.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TSubMenuItem::IsArrowVisible

virtual bool IsArrowVisible () const

Interface Category:

API.

Purpose:

Determines if the submenu arrow is (or is going to be) visible. If the visibility was not explicitly set via SetArrowVisible, then the arrow is visible if the layout of the items in the owning menu is perpendicular to the layout of the subparts of the items. For example, if the menu items are laid out from top to bottom and the item's subparts are laid out from left to right, an arrow is visible. Whereas, if the item subparts are also laid out from left to right, no arrow is visible.

Calling Context:

Called during drawing of the menu item. You can also call this function directly.

Parameters:

Return Value:

Returns true if the arrow is visible; false otherwise.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TSubMenuItem::DrawParts

virtual void DrawParts (TGrafPort & port) const

Interface Category:

API.

Purpose:

Draws this menu item's subparts to the specified port. This function draws the submenu arrow, and then delegates to MMenuItem to draw the item label.

Calling Context:

Called during a menu draw operation. You can also call this function directly.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

Overrides the inherited MMenuItem function.

Member Function: TSubMenuItem::CreateInteractor

virtual TInteractor * CreateInteractor (const TGPoint & pt)

Interface Category:

API.

Purpose:

Creates an interactor used to interpret user gestures on this menu item. This is an MControl override that is used by the menu owning this menu item to interact with the menu item. The interactor returned from this function must know how to translate user input, in the context of menu interaction, into state changes on the menu item. For this class, the interactor calls SetPressed(true) when the mouse moves into the item, which results in popping open the submenu. The interactor does not call SetPressed(false) when the mouse moves out of the item, because the user might be interacting with the submenu.

Calling Context:

Called during user interaction. You can also call this function directly.

Parameters:

Return Value:

Returns the newly created interactor.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

Overrides the inherited MControl function.

Member Function: TSubMenuItem::GetPopUpBounds

virtual TGRect GetPopUpBounds () const

Interface Category:

API.

Purpose:

Determines where the submenu should be popped open. The location of the pop-up menu depends on the layout of the menu that owns this item, the bounds of the screen, the preferred size of the submenu and whether the popup is reversed. This function can also decide to reverse the pop-up direction if it fits better on the other side of the item. The pop-up bounds are returned in global coordinates.

Calling Context:

Called when the user selects this submenu item. You can also call this function directly.

Parameters:

Return Value:

Returns the bounds indicating where the submenu should be popped up.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TSubMenuItem::GetBestDeviceBounds

virtual void GetBestDeviceBounds (const TGRect & bounds, TGRect & bestDeviceBounds) const

Interface Category:

API.

Purpose:

Scans the graf device chain for the device that contains the largest intersection of the given rectangle and returns the bounds of the found device. All bounds are in global coordinates.

Calling Context:

Called when the user selects the submenu item. This member function can only return the correct result when a TGrafPort is available from the menu that owns this item. You can also call this function directly.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TSubMenuItem::SetPopUpReversed

virtual void SetPopUpReversed (bool reversed)

Interface Category:

API.

Purpose:

Sets whether the submenu associated with this menu item is popped up on the opposite side from its natural side. When a submenu is popped open, the submenu item can decide to place the pop up menu on the opposite side of the item than that indicated by the item's arrow. This happens if the menu would not fit on the correct side of the item. This function is called by this item if this item decides to reverse, or if any submenu item in any of the parent menus decides to reverse. This means that when a submenu item decides to reverse, all the submenu items in the pop-up menu are also reversed. This also causes the arrow to be rotated 180 degrees.

Calling Context:

Called during user interaction on the menu item. You should not call this function directly.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TSubMenuItem::IsPopUpReversed

virtual bool IsPopUpReversed () const

Interface Category:

API.

Purpose:

Determines if this item or any of the parent submenu items have reversed the pop-up direction.

Calling Context:

Called during drawing to get the submenu arrow correct. You can also call this function directly.

Parameters:

Return Value:

Returns true if the submenu item's pop-up menu is reversed; false otherwise.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TSubMenuItem::SetEnabled

virtual void SetEnabled (bool enabled)

Interface Category:

API.

Purpose:

Enables or disables the submenu according to the specified flag. This results in calling SetEnabled on all the items in the submenu.

Calling Context:

Called when owning menu's enabled state is changed. You can also call this function directly.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

Overrides the inherited MMenuItem function.

Member Function: TSubMenuItem::IsEnabled

virtual bool IsEnabled () const

Interface Category:

API.

Purpose:

Called by owning menu to determine if user interaction is allowed on the item. You can also call this function directly.

Calling Context:

Call this function directly.

Parameters:

Return Value:

Returns true if at least one item in the submenu (or any of its submenus) is enabled; false otherwise.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

Overrides the inherited MDelegatingMomentaryControl function.

Member Function: TSubMenuItem::SetPressed

virtual void SetPressed (bool pressed)

Interface Category:

API.

Purpose:

Presses or unpresses this menu item according to the specified flag. This function pops up the submenu and then delegates to MMenuItem, which highlights the item.

Calling Context:

Called during user interaction on the menu and also when item is orphaned from a menu. You can also call this function directly, although Animate is probably more useful.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

Overrides the inherited MMenuItem function.

Member Function: TSubMenuItem::GetArrowAngle

virtual GDegrees GetArrowAngle () const

Interface Category:

API.

Purpose:

Calculates the angle by which the default submenu down arrow needs to be rotated. This depends on the layout of the submenu arrow, and whether the pop-up direction has been reversed. For example, a left-to-right item with no pop-up reversal uses a right arrow, which is a down arrow rotated 270 degrees. If it is a right-to-left item, with no reversal, the angle is 90 degrees.

Calling Context:

Called during drawing of the menu item.

Parameters:

Return Value:

The angle.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TSubMenuItem::SetKeyboardEquivalent

virtual void SetKeyboardEquivalent (const TVirtualKeyCode :: EVirtualKey keycode, const TModifierKeys & modifiers)

Interface Category:

API.

Purpose:

This member function is protected because it doesn't make sense to have a command key equivalent for a submenu item.

Calling Context:

Do not call this member function.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

Overrides the inherited MMenuItem function.

Member Function: TSubMenuItem::HandleActivationChanged

virtual void HandleActivationChanged (bool active)

Interface Category:

API.

Purpose:

Handles the situation where the activation state of this menu item has changed. This member function simply passes on the new activation state to the adopted submenu by calling SetActive on the submenu.

Calling Context:

Called by the owning menu when the menu activation is changed or when the menu items are adopted or orphaned. Derived classes can also call this if new situations arise where you want the activation state to be reexamined.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

Overrides the inherited MMenuItem function.

Member Function: TSubMenuItem::HandleAttributesChanged

virtual void HandleAttributesChanged ()

Interface Category:

API.

Purpose:

Handles the situation where the submenu item's GUI attributes have changed. Calls the submenu's HandleAttributesChanged.

Calling Context:

Called when attributes (such as colors) have changed. Derived classes can also call this if new situations arise where you want the attributes to be reexamined.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

Overrides the inherited MMenuItem function.

Member Function: TSubMenuItem::OrphanLabel

virtual TLabel * OrphanLabel ()

Interface Category:

API.

Purpose:

Orphans the label from this menu item, and from the title bar in the submenu. The caller is responsible for destroying the orphaned label. This function delegates to MMenuItem to orphan the menu item label. It then deletes and removes the label from the submenu title bar.

Calling Context:

Call this function directly.

Parameters:

Return Value:

Returns the orphaned label. This function returns NIL if this menu item has no label.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

Overrides the inherited MMenuItem function.

Member Function: TSubMenuItem::AdoptLabel

virtual void AdoptLabel (TLabel * label)

Interface Category:

API.

Purpose:

Adopts the specified label as this menu item's label, and as the label used in the title bar in the submenu. This function delegates to MMenuItem to delete any previously adopted menu item label and adopt the new label. It then clones the new label and adopts the result into the submenu title bar.

Calling Context:

Call this function directly.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

Overrides the inherited MMenuItem function.

Member Function: TSubMenuItem::CloseSubMenu

virtual void CloseSubMenu ()

Interface Category:

API.

Purpose:

Closes the submenu if it is open or torn off.

Calling Context:

Called by the submenu item interactor when the submenu is closed. You should not call this function, but use SetPressed(false) instead.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TSubMenuItem::IsSticky

virtual bool IsSticky ()

Interface Category:

API.

Purpose:

Determines whether the submenu item is sticky. A sticky menu is one that is open and attached to a parent menu. Moving the parent moves its sticky submenus. A menu can be closed, open in sticky mode, or torn off.

Calling Context:

Called during user interaction. You can also call this function directly.

Parameters:

Return Value:

Returns true if it's sticky, false if it's not.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TSubMenuItem::SetSticky

virtual bool SetSticky ()

Interface Category:

API.

Purpose:

Makes the submenu sticky, that is, it makes it stick around after the mouse up that follows the mouse down that opens the submenu.

Calling Context:

Called during user interaction. You should not call this member function directly, instead use SetPressed(true).

Parameters:

Return Value:

Returns true if successful.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TSubMenuItem::IsTornOff

virtual bool IsTornOff () const

Interface Category:

API.

Purpose:

Determines whether the submenu item is torn off. After a submenu is opened, it can be torn off to a different location, making it a separate independent window.

Calling Context:

Called during user interaction. You can also call this function directly.

Parameters:

Return Value:

Returns true if it's torn off, false if it's not.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TSubMenuItem::TearOffTo

virtual void TearOffTo (const TGPoint & pt)

Interface Category:

API.

Purpose:

Moves the open submenu to the specified location, making it a separate independent window if it isn't already.

Calling Context:

Called during user interaction. You can also call this function directly.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TSubMenuItem::SnapBack

virtual void SnapBack ()

Interface Category:

API.

Purpose:

Snaps a torn off submenu back to its previous position or closes a sticky menu. If a menu is torn off, and the user clicks on it's parent submenu item again, the menu jumps back over to where the submenu item is and is positioned as if the menu was just opened for the first time. When the user clicks on the submenu item again to close the submenu, this member function is called to snap the submenu back to the original torn off position.

Calling Context:

Called during user interaction. You should not call this function directly.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TSubMenuItem::Animate

virtual void Animate ()

Interface Category:

API.

Purpose:

Briefly highlights the menu item programmatically. This does not have the same effect as if the user selected the item with a mouse. For example, it does not open the submenu.

Calling Context:

Called while handling a command key equivalent for a menu item that belongs to a submenu of this submenu item to give feedback to the user. This only gets called if the submenu is closed. You can also call this function directly.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

Overrides the inherited MMenuItem function.

Member Function: TSubMenuItem::GetArrowGraphic

virtual TGPolygon * GetArrowGraphic () const

Interface Category:

API.

Purpose:

This member function is obsolete.

Calling Context:

Do not call this member function.

Parameters:

Return Value:

Always returns NIL.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TSubMenuItem::SetOwner

virtual void SetOwner (TMenu * menu)

Interface Category:

API.

Purpose:

Notifies this menu item that it has been added to a menu. Menu items require a pointer to the owning menu so that the item can call back to the menu when it needs to redraw itself. This function delegates to MMenuItem, and activates or deactivates the submenu, based on whether the owning menu is active or inactive.

Calling Context:

Called during initialization and destruction of a menu and sometimes during user interaction. You should not call this function directly.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

Overrides the inherited MMenuItem function.
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.