Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Member Functions | Protected Attributes
nsMenuX Class Reference

#include <nsMenuX.h>

Inheritance diagram for nsMenuX:
Inheritance graph
[legend]
Collaboration diagram for nsMenuX:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsMenuX ()
virtual ~nsMenuX ()
NS_DECL_ISUPPORTS
NS_DECL_NSICHANGEOBSERVER
nsEventStatus 
MenuItemSelected (const nsMenuEvent &aMenuEvent)
 Processes a menu item selected event.
nsEventStatus MenuSelected (const nsMenuEvent &aMenuEvent)
 Processes a menu selected event.
nsEventStatus MenuDeselected (const nsMenuEvent &aMenuEvent)
 Processes a menu deselect event.
nsEventStatus MenuConstruct (const nsMenuEvent &aMenuEvent, nsIWidget *aParentWindow, void *menuNode, void *aDocShell)
nsEventStatus MenuDestruct (const nsMenuEvent &aMenuEvent)
nsEventStatus CheckRebuild (PRBool &aMenuEvent)
nsEventStatus SetRebuild (PRBool aMenuEvent)
NS_IMETHOD Create (nsISupports *aParent, const nsAString &aLabel, const nsAString &aAccessKey, nsIChangeManager *aManager, nsIDocShell *aShell, nsIContent *aNode)
 Creates the Menu.
NS_IMETHOD GetParent (nsISupports *&aParent)
 Get the Menu's Parent.
NS_IMETHOD GetLabel (nsString &aText)
 Get the Menu label.
NS_IMETHOD SetLabel (const nsAString &aText)
 Set the Menu label.
NS_IMETHOD GetAccessKey (nsString &aText)
 Get the Menu Access Key.
NS_IMETHOD SetAccessKey (const nsAString &aText)
 Set the Menu Access Key.
NS_IMETHOD AddItem (nsISupports *aText)
 Adds a Menu Item.
NS_IMETHOD AddSeparator ()
 Adds a separator.
NS_IMETHOD GetItemCount (PRUint32 &aCount)
 Returns the number of menu items This does count separators as items.
NS_IMETHOD GetItemAt (const PRUint32 aPos, nsISupports *&aMenuItem)
 Returns a Menu or Menu Item at a specified Index.
NS_IMETHOD InsertItemAt (const PRUint32 aPos, nsISupports *aMenuItem)
 Inserts a Menu Item at a specified Index.
NS_IMETHOD RemoveItem (const PRUint32 aPos)
 Removes an Menu Item from a specified Index.
NS_IMETHOD RemoveAll ()
 Removes all the Menu Items.
NS_IMETHOD GetNativeData (void **aData)
 Gets Native MenuHandle.
NS_IMETHOD SetNativeData (void *aData)
 Sets Native MenuHandle.
NS_IMETHOD AddMenuListener (nsIMenuListener *aMenuListener)
 Adds menu listener for dynamic construction.
NS_IMETHOD RemoveMenuListener (nsIMenuListener *aMenuListener)
 Removes menu listener for dynamic construction.
NS_IMETHOD GetMenuContent (nsIContent **aMenuNode)
 Get GetMenuContent.
NS_IMETHOD SetEnabled (PRBool aIsEnabled)
 Set enabled state.
NS_IMETHOD GetEnabled (PRBool *aIsEnabled)
 Get enabled state.
NS_IMETHOD IsHelpMenu (PRBool *aIsEnabled)
 Query if this is the help menu.
NS_IMETHOD AddMenuItem (nsIMenuItem *aMenuItem)
NS_IMETHOD AddMenu (nsIMenu *aMenu)
 nsMenuX ()
virtual ~nsMenuX ()
NS_DECL_ISUPPORTS
NS_DECL_NSICHANGEOBSERVER
nsEventStatus 
MenuItemSelected (const nsMenuEvent &aMenuEvent)
 Processes a menu item selected event.
nsEventStatus MenuSelected (const nsMenuEvent &aMenuEvent)
 Processes a menu selected event.
nsEventStatus MenuDeselected (const nsMenuEvent &aMenuEvent)
 Processes a menu deselect event.
nsEventStatus MenuConstruct (const nsMenuEvent &aMenuEvent, nsIWidget *aParentWindow, void *menuNode, void *aDocShell)
nsEventStatus MenuDestruct (const nsMenuEvent &aMenuEvent)
nsEventStatus CheckRebuild (PRBool &aMenuEvent)
nsEventStatus SetRebuild (PRBool aMenuEvent)
NS_IMETHOD Create (nsISupports *aParent, const nsAString &aLabel, const nsAString &aAccessKey, nsIChangeManager *aManager, nsIDocShell *aShell, nsIContent *aNode)
 Creates the Menu.
NS_IMETHOD GetParent (nsISupports *&aParent)
 Get the Menu's Parent.
NS_IMETHOD GetLabel (nsString &aText)
 Get the Menu label.
NS_IMETHOD SetLabel (const nsAString &aText)
 Set the Menu label.
NS_IMETHOD GetAccessKey (nsString &aText)
 Get the Menu Access Key.
NS_IMETHOD SetAccessKey (const nsAString &aText)
 Set the Menu Access Key.
NS_IMETHOD AddItem (nsISupports *aText)
 Adds a Menu Item.
NS_IMETHOD AddSeparator ()
 Adds a separator.
NS_IMETHOD GetItemCount (PRUint32 &aCount)
 Returns the number of menu items This does count separators as items.
NS_IMETHOD GetItemAt (const PRUint32 aPos, nsISupports *&aMenuItem)
 Returns a Menu or Menu Item at a specified Index.
NS_IMETHOD InsertItemAt (const PRUint32 aPos, nsISupports *aMenuItem)
 Inserts a Menu Item at a specified Index.
NS_IMETHOD RemoveItem (const PRUint32 aPos)
 Removes an Menu Item from a specified Index.
NS_IMETHOD RemoveAll ()
 Removes all the Menu Items.
NS_IMETHOD GetNativeData (void **aData)
 Gets Native MenuHandle.
NS_IMETHOD SetNativeData (void *aData)
 Sets Native MenuHandle.
NS_IMETHOD AddMenuListener (nsIMenuListener *aMenuListener)
 Adds menu listener for dynamic construction.
NS_IMETHOD RemoveMenuListener (nsIMenuListener *aMenuListener)
 Removes menu listener for dynamic construction.
NS_IMETHOD GetMenuContent (nsIContent **aMenuNode)
 Get GetMenuContent.
NS_IMETHOD SetEnabled (PRBool aIsEnabled)
 Set the Menu enabled state.
NS_IMETHOD GetEnabled (PRBool *aIsEnabled)
 Get the Menu enabled state.
NS_IMETHOD IsHelpMenu (PRBool *aIsEnabled)
 Query if this is the help menu.
NS_IMETHOD AddMenuItem (nsIMenuItem *aMenuItem)
NS_IMETHOD AddMenu (nsIMenu *aMenu)
NS_IMETHOD ChangeNativeEnabledStatusForMenuItem (nsIMenuItem *aMenuItem, PRBool aEnabled)
 Enable/disable native widget for a particular nsIMenuItem.
NS_IMETHOD GetMenuRefAndItemIndexForMenuItem (nsISupports *aMenuItem, void **aMenuRef, PRUint16 *aMenuItemIndex)
 Retrieve the native menu and the index of the item within that menu.
NS_IMETHOD SetupIcon ()
 Sets an appropriate icon for the menu.
void AttributeChanged (in nsIDocument aDocument, in long aNameSpaceID, in nsIAtom aAttribute)
void AttributeChanged (in nsIDocument aDocument, in long aNameSpaceID, in nsIContent aContent, in nsIAtom aAttribute)
void ContentRemoved (in nsIDocument aDocument, in nsIContent aChild, in long aIndexInContainer)
void ContentRemoved (in nsIDocument aDocument, in nsIContent aChild, in long aIndexInContainer)
void ContentInserted (in nsIDocument aDocument, in nsIContent aChild, in long aIndexInContainer)
void ContentInserted (in nsIDocument aDocument, in nsIContent aChild, in long aIndexInContainer)

Protected Member Functions

nsresult CountVisibleBefore (PRUint32 *outVisibleBefore)
void GetMenuPopupContent (nsIContent **aResult)
void InsertMenuItemWithTruncation (nsAutoString &inItemLabel, PRUint32 inItemIndex)
PRBool OnDestroy ()
PRBool OnCreate ()
PRBool OnDestroyed ()
PRBool OnCreated ()
void LoadMenuItem (nsIMenu *pParentMenu, nsIContent *menuitemContent)
void LoadSubMenu (nsIMenu *pParentMenu, nsIContent *menuitemContent)
void LoadSeparator (nsIContent *menuitemContent)
MenuHandle NSStringNewMenu (short menuID, nsString &menuTitle)
nsresult CountVisibleBefore (PRUint32 *outVisibleBefore)
void GetMenuPopupContent (nsIContent **aResult)
void InsertMenuItemWithTruncation (nsAutoString &inItemLabel, PRUint32 inItemIndex)
PRBool OnDestroy ()
PRBool OnCreate ()
PRBool OnDestroyed ()
PRBool OnCreated ()
void LoadMenuItem (nsIMenu *pParentMenu, nsIContent *menuitemContent)
void LoadSubMenu (nsIMenu *pParentMenu, nsIContent *menuitemContent)
void LoadSeparator (nsIContent *menuitemContent)
MenuHandle NSStringNewMenu (short menuID, nsString &menuTitle)

Protected Attributes

nsString mLabel
PRUint32 mNumMenuItems
nsSupportsArray mMenuItemsArray
nsISupports * mParent
nsIChangeManagermManager
nsWeakPtr mDocShellWeakRef
nsCOMPtr< nsIContentmMenuContent
nsCOMPtr< nsIMenuListenermListener
PRInt16 mMacMenuID
MenuHandle mMacMenuHandle
PRPackedBool mIsEnabled
PRPackedBool mDestroyHandlerCalled
PRPackedBool mNeedsRebuild
PRPackedBool mConstructed
PRPackedBool mVisible
EventHandlerRef mHandler
nsRefPtr< nsMenuItemIconmIcon

Detailed Description

Definition at line 61 of file nsMenuX.h.


Constructor & Destructor Documentation

nsMenuX::~nsMenuX ( ) [virtual]

Definition at line 127 of file nsMenuX.cpp.

{
  RemoveAll();

  if ( mMacMenuHandle ) {
    if ( mHandler )
      ::RemoveEventHandler(mHandler);
    ::ReleaseMenu(mMacMenuHandle);
  }
  
  // alert the change notifier we don't care no more
  mManager->Unregister(mMenuContent);

#if DEBUG
  //--gMenuCounterX;
#endif
}

Here is the call graph for this function:

virtual nsMenuX::~nsMenuX ( ) [virtual]

Member Function Documentation

NS_METHOD nsMenuX::AddItem ( nsISupports *  aItem) [virtual]

Adds a Menu Item.

 

Implements nsIMenu.

Definition at line 229 of file nsMenuX.cpp.

{
    nsresult rv = NS_ERROR_FAILURE;
    if (aItem) {
        // Figure out what we're adding
        nsCOMPtr<nsIMenuItem> menuItem(do_QueryInterface(aItem));
        if (menuItem) {
            rv = AddMenuItem(menuItem);
        } else {
            nsCOMPtr<nsIMenu> menu(do_QueryInterface(aItem));
            if (menu)
                rv = AddMenu(menu);
        }
    }
    return rv;
}

Here is the call graph for this function:

NS_IMETHOD nsMenuX::AddItem ( nsISupports *  aItem) [virtual]

Adds a Menu Item.

 

Implements nsIMenu.

Definition at line 317 of file nsMenuX.cpp.

{
  // Add a submenu
  if (!aMenu) return NS_ERROR_NULL_POINTER;

  nsCOMPtr<nsISupports>  supports = do_QueryInterface(aMenu);
  if (!supports) return NS_ERROR_NO_INTERFACE;

  mMenuItemsArray.AppendElement(supports);   // owning ref
  PRUint32 currItemIndex;
  mMenuItemsArray.Count(&currItemIndex);

  mNumMenuItems++;

  // We have to add it as a menu item and then associate it with the item
  nsAutoString label;
  aMenu->GetLabel(label);
  InsertMenuItemWithTruncation ( label, currItemIndex );

  PRBool isEnabled;
  aMenu->GetEnabled(&isEnabled);
  if (isEnabled)
    ::EnableMenuItem(mMacMenuHandle, currItemIndex);
  else
    ::DisableMenuItem(mMacMenuHandle, currItemIndex);       

  MenuHandle childMenu;
  if (aMenu->GetNativeData((void**)&childMenu) == NS_OK)
    ::SetMenuItemHierarchicalMenu((MenuHandle) mMacMenuHandle, currItemIndex, childMenu);
  
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 247 of file nsMenuX.cpp.

{
  if(!aMenuItem) return NS_ERROR_NULL_POINTER;

  mMenuItemsArray.AppendElement(aMenuItem);    // owning ref
  PRUint32 currItemIndex;
  mMenuItemsArray.Count(&currItemIndex);

  mNumMenuItems++;

  nsAutoString label;
  aMenuItem->GetLabel(label);
  InsertMenuItemWithTruncation ( label, currItemIndex );
  
  // I want to be internationalized too!
  nsAutoString keyEquivalent(NS_LITERAL_STRING(" "));
  aMenuItem->GetShortcutChar(keyEquivalent);
  if (!keyEquivalent.EqualsLiteral(" ")) {
    ToUpperCase(keyEquivalent);
    char keyStr[2];
    keyEquivalent.ToCString(keyStr, sizeof(keyStr));
    short inKey = keyStr[0];
    ::SetItemCmd(mMacMenuHandle, currItemIndex, inKey);
    //::SetMenuItemKeyGlyph(mMacMenuHandle, mNumMenuItems, 0x61);
  }

  PRUint8 modifiers;
  aMenuItem->GetModifiers(&modifiers);
  PRUint8 macModifiers = kMenuNoModifiers;
  if (knsMenuItemShiftModifier & modifiers)
    macModifiers |= kMenuShiftModifier;

  if (knsMenuItemAltModifier & modifiers)
    macModifiers |= kMenuOptionModifier;

  if (knsMenuItemControlModifier & modifiers)
    macModifiers |= kMenuControlModifier;

  if (!(knsMenuItemCommandModifier & modifiers))
    macModifiers |= kMenuNoCommandModifier;

  ::SetMenuItemModifiers(mMacMenuHandle, currItemIndex, macModifiers);

  // set its command. we get the unique command id from the menubar
  nsCOMPtr<nsIMenuCommandDispatcher> dispatcher ( do_QueryInterface(mManager) );
  if ( dispatcher ) {
    PRUint32 commandID = 0L;
    dispatcher->Register(aMenuItem, &commandID);
    if ( commandID )
      ::SetMenuItemCommandID(mMacMenuHandle, currItemIndex, commandID);
  }
  
  PRBool isEnabled;
  aMenuItem->GetEnabled(&isEnabled);
  if(isEnabled)
    ::EnableMenuItem(mMacMenuHandle, currItemIndex);
  else
    ::DisableMenuItem(mMacMenuHandle, currItemIndex);

  PRBool isChecked;
  aMenuItem->GetChecked(&isChecked);
  if(isChecked)
    ::CheckMenuItem(mMacMenuHandle, currItemIndex, true);
  else
    ::CheckMenuItem(mMacMenuHandle, currItemIndex, false);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_METHOD nsMenuX::AddMenuListener ( nsIMenuListener aMenuListener) [virtual]

Adds menu listener for dynamic construction.

 

Implements nsIMenu.

Definition at line 451 of file nsMenuX.cpp.

{
  mListener = aMenuListener;    // strong ref
  return NS_OK;
}
NS_IMETHOD nsMenuX::AddMenuListener ( nsIMenuListener aMenuListener) [virtual]

Adds menu listener for dynamic construction.

 

Implements nsIMenu.

Adds a separator.

 

Implements nsIMenu.

Definition at line 376 of file nsMenuX.cpp.

{
  // HACK - We're not really appending an nsMenuItem but it 
  // needs to be here to make sure that event dispatching isn't off by one.
  mMenuItemsArray.AppendElement(&gDummyMenuItemX);   // owning ref
  PRUint32  numItems;
  mMenuItemsArray.Count(&numItems);
  ::InsertMenuItem(mMacMenuHandle, "\p(-", numItems);
  mNumMenuItems++;
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Adds a separator.

 

Implements nsIMenu.

void nsIChangeObserver::AttributeChanged ( in nsIDocument  aDocument,
in long  aNameSpaceID,
in nsIAtom  aAttribute 
) [inherited]
void nsIChangeObserver::AttributeChanged ( in nsIDocument  aDocument,
in long  aNameSpaceID,
in nsIContent  aContent,
in nsIAtom  aAttribute 
) [inherited]

Enable/disable native widget for a particular nsIMenuItem.

 

Implements nsIMenu_MOZILLA_1_8_BRANCH.

Definition at line 1264 of file nsMenuX.cpp.

{
  MenuRef menuRef;
  PRUint16 menuItemIndex;
  nsresult rv = GetMenuRefAndItemIndexForMenuItem(aMenuItem,
                                                  (void**)&menuRef,
                                                  &menuItemIndex);
  if (NS_FAILED(rv)) return rv;

  if (aEnabled)
    ::EnableMenuItem(menuRef, menuItemIndex);
  else
    ::DisableMenuItem(menuRef, menuItemIndex);

  return NS_OK;
}

Here is the call graph for this function:

nsEventStatus nsMenuX::CheckRebuild ( PRBool aMenuEvent) [virtual]

Implements nsIMenuListener.

Definition at line 612 of file nsMenuX.cpp.

{
  aNeedsRebuild = PR_TRUE;
  return nsEventStatus_eIgnore;
}
nsEventStatus nsMenuX::CheckRebuild ( PRBool aMenuEvent) [virtual]

Implements nsIMenuListener.

void nsIChangeObserver::ContentInserted ( in nsIDocument  aDocument,
in nsIContent  aChild,
in long  aIndexInContainer 
) [inherited]
void nsIChangeObserver::ContentInserted ( in nsIDocument  aDocument,
in nsIContent  aChild,
in long  aIndexInContainer 
) [inherited]
void nsIChangeObserver::ContentRemoved ( in nsIDocument  aDocument,
in nsIContent  aChild,
in long  aIndexInContainer 
) [inherited]
void nsIChangeObserver::ContentRemoved ( in nsIDocument  aDocument,
in nsIContent  aChild,
in long  aIndexInContainer 
) [inherited]
nsresult nsMenuX::CountVisibleBefore ( PRUint32 outVisibleBefore) [protected]

Definition at line 1141 of file nsMenuX.cpp.

{
  NS_ASSERTION ( outVisibleBefore, "bad index param" );
  
  nsCOMPtr<nsIMenuBar> menubarParent = do_QueryInterface(mParent);
  if (!menubarParent) return NS_ERROR_FAILURE;

  PRUint32 numMenus = 0;
  menubarParent->GetMenuCount(numMenus);
  
  // Find this menu among the children of my parent menubar
  PRBool gotThisMenu = PR_FALSE;
  *outVisibleBefore = 1;                            // start at 1, the apple menu will always be there
  for ( PRUint32 i = 0; i < numMenus; ++i ) {
    nsCOMPtr<nsIMenu> currMenu;
    menubarParent->GetMenuAt(i, *getter_AddRefs(currMenu));
    
    // we found ourselves, break out
    if ( currMenu == NS_STATIC_CAST(nsIMenu*, this) ) {
      gotThisMenu = PR_TRUE;
      break;
    }
      
    // check the current menu to see if it is visible (not hidden, not collapsed). If
    // it is, count it.
    if (currMenu) {
      nsCOMPtr<nsIContent> menuContent;
      currMenu->GetMenuContent(getter_AddRefs(menuContent));
      if ( menuContent ) {
        nsAutoString hiddenValue, collapsedValue;
        menuContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::hidden, hiddenValue);
        menuContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::collapsed, collapsedValue);
        if ( !hiddenValue.EqualsLiteral("true") && !collapsedValue.EqualsLiteral("true"))
          ++(*outVisibleBefore);
      }
    }
    
  } // for each menu

  return gotThisMenu ? NS_OK : NS_ERROR_FAILURE;

} // CountVisibleBefore

Here is the call graph for this function:

nsresult nsMenuX::CountVisibleBefore ( PRUint32 outVisibleBefore) [protected]
NS_METHOD nsMenuX::Create ( nsISupports *  aParent,
const nsAString &  aLabel,
const nsAString &  aAccessKey,
nsIChangeManager aManager,
nsIDocShell aShell,
nsIContent aNode 
) [virtual]

Creates the Menu.

 

Implements nsIMenu.

Definition at line 150 of file nsMenuX.cpp.

{
  mDocShellWeakRef = do_GetWeakReference(aShell);
  mMenuContent = aNode;

  // register this menu to be notified when changes are made to our content object
  mManager = aManager;                    // weak ref
  nsCOMPtr<nsIChangeObserver> changeObs ( do_QueryInterface(NS_STATIC_CAST(nsIChangeObserver*, this)) );
  mManager->Register(mMenuContent, changeObs);

  NS_ASSERTION ( mMenuContent, "Menu not given a dom node at creation time" );
  NS_ASSERTION ( mManager, "No change manager given, can't tell content model updates" );

  mParent = aParent;
  // our parent could be either a menu bar (if we're toplevel) or a menu (if we're a submenu)
  PRBool isValidParent = PR_FALSE;
  if (aParent) {
    nsCOMPtr<nsIMenuBar> menubar = do_QueryInterface(aParent);
    nsCOMPtr<nsIMenu> menu = do_QueryInterface(aParent);
    isValidParent = (menubar || menu);
  }
  NS_ASSERTION(isValidParent, "Menu parent not a menu bar or menu!" );

  SetLabel(aLabel);
  SetAccessKey(aAccessKey);

  nsAutoString hiddenValue, collapsedValue;
  mMenuContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::hidden, hiddenValue);
  mMenuContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::collapsed, collapsedValue);
  if ( hiddenValue.EqualsLiteral("true") || collapsedValue.EqualsLiteral("true") )
    mVisible = PR_FALSE;

  return NS_OK;
}

Here is the call graph for this function:

NS_IMETHOD nsMenuX::Create ( nsISupports *  aParent,
const nsAString &  aLabel,
const nsAString &  aAccessKey,
nsIChangeManager aManager,
nsIDocShell aShell,
nsIContent aNode 
) [virtual]

Creates the Menu.

 

Implements nsIMenu.

NS_METHOD nsMenuX::GetAccessKey ( nsString aText) [virtual]

Get the Menu Access Key.

 

Implements nsIMenu.

Definition at line 217 of file nsMenuX.cpp.

{
  return NS_OK;
}
NS_IMETHOD nsMenuX::GetAccessKey ( nsString aText) [virtual]

Get the Menu Access Key.

 

Implements nsIMenu.

NS_METHOD nsMenuX::GetEnabled ( PRBool aIsEnabled) [virtual]

Get enabled state.

Implements nsIMenu.

Definition at line 648 of file nsMenuX.cpp.

{
  NS_ENSURE_ARG_POINTER(aIsEnabled);
  *aIsEnabled = mIsEnabled;
  return NS_OK;
}
NS_IMETHOD nsMenuX::GetEnabled ( PRBool aIsEnabled) [virtual]

Get the Menu enabled state.

 

Implements nsIMenu.

NS_METHOD nsMenuX::GetItemAt ( const PRUint32  aPos,
nsISupports *&  aMenuItem 
) [virtual]

Returns a Menu or Menu Item at a specified Index.

 

Implements nsIMenu.

Definition at line 395 of file nsMenuX.cpp.

{
  mMenuItemsArray.GetElementAt(aPos, &aMenuItem);
  return NS_OK;
}
NS_IMETHOD nsMenuX::GetItemAt ( const PRUint32  aPos,
nsISupports *&  aMenuItem 
) [virtual]

Returns a Menu or Menu Item at a specified Index.

 

Implements nsIMenu.

NS_METHOD nsMenuX::GetItemCount ( PRUint32 aCount) [virtual]

Returns the number of menu items This does count separators as items.

Implements nsIMenu.

Definition at line 389 of file nsMenuX.cpp.

{
  return mMenuItemsArray.Count(&aCount);
}
NS_IMETHOD nsMenuX::GetItemCount ( PRUint32 aCount) [virtual]

Returns the number of menu items This does count separators as items.

Implements nsIMenu.

NS_METHOD nsMenuX::GetLabel ( nsString aText) [virtual]

Get the Menu label.

 

Implements nsIMenu.

Definition at line 195 of file nsMenuX.cpp.

{
  aText = mLabel;
  return NS_OK;
}
NS_IMETHOD nsMenuX::GetLabel ( nsString aText) [virtual]

Get the Menu label.

 

Implements nsIMenu.

NS_METHOD nsMenuX::GetMenuContent ( nsIContent **  aMenuContent) [virtual]

Get GetMenuContent.

Implements nsIMenu.

Definition at line 671 of file nsMenuX.cpp.

{
  NS_ENSURE_ARG_POINTER(aMenuContent);
  NS_IF_ADDREF(*aMenuContent = mMenuContent);
       return NS_OK;
}
NS_IMETHOD nsMenuX::GetMenuContent ( nsIContent **  aMenuContent) [virtual]

Get GetMenuContent.

 

Implements nsIMenu.

void nsMenuX::GetMenuPopupContent ( nsIContent **  aResult) [protected]

Definition at line 1105 of file nsMenuX.cpp.

{
  if (!aResult )
    return;
  *aResult = nsnull;
  
  nsresult rv;
  nsCOMPtr<nsIXBLService> xblService = 
           do_GetService("@mozilla.org/xbl;1", &rv);
  if ( !xblService )
    return;
  
  PRUint32 count = mMenuContent->GetChildCount();
  for (PRUint32 i = 0; i < count; i++) {
    PRInt32 dummy;
    nsIContent *child = mMenuContent->GetChildAt(i);
    nsCOMPtr<nsIAtom> tag;
    xblService->ResolveTag(child, &dummy, getter_AddRefs(tag));
    if (tag == nsWidgetAtoms::menupopup) {
      *aResult = child;
      NS_ADDREF(*aResult);
      return;
    }
  }

} // GetMenuPopupContent

Here is the call graph for this function:

Here is the caller graph for this function:

void nsMenuX::GetMenuPopupContent ( nsIContent **  aResult) [protected]
NS_IMETHODIMP nsMenuX::GetMenuRefAndItemIndexForMenuItem ( nsISupports *  aMenuItem,
void **  aMenuRef,
PRUint16 aMenuItemIndex 
) [virtual]

Retrieve the native menu and the index of the item within that menu.

Implements nsIMenu_MOZILLA_1_8_BRANCH.

Definition at line 1284 of file nsMenuX.cpp.

{
  // look for the menu item given
  PRUint32 menuItemCount;
  mMenuItemsArray.Count(&menuItemCount);

  for (PRUint32 i = 0; i < menuItemCount; i++) {
    nsCOMPtr<nsISupports> currItem; 
    mMenuItemsArray.GetElementAt(i, getter_AddRefs(currItem));
    if (currItem == aMenuItem) {
      *aMenuRef = (void*)mMacMenuHandle;
      *aMenuItemIndex = i + 1;
      return NS_OK;
    }
  }

  return NS_ERROR_FAILURE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_METHOD nsMenuX::GetNativeData ( void **  aData) [virtual]

Gets Native MenuHandle.

 

Implements nsIMenu.

Definition at line 437 of file nsMenuX.cpp.

{
  *aData = mMacMenuHandle;
  return NS_OK;
}
NS_IMETHOD nsMenuX::GetNativeData ( void **  aData) [virtual]

Gets Native MenuHandle.

 

Implements nsIMenu.

NS_METHOD nsMenuX::GetParent ( nsISupports *&  aParent) [virtual]

Get the Menu's Parent.

 

Implements nsIMenu.

Definition at line 187 of file nsMenuX.cpp.

{
  aParent = mParent;
  NS_IF_ADDREF(aParent);
  return NS_OK;
}
NS_IMETHOD nsMenuX::GetParent ( nsISupports *&  aParent) [virtual]

Get the Menu's Parent.

 

Implements nsIMenu.

NS_METHOD nsMenuX::InsertItemAt ( const PRUint32  aPos,
nsISupports *  aMenuItem 
) [virtual]

Inserts a Menu Item at a specified Index.

 

Implements nsIMenu.

Definition at line 402 of file nsMenuX.cpp.

{
  NS_ASSERTION(0, "Not implemented");
  return NS_OK;
}
NS_IMETHOD nsMenuX::InsertItemAt ( const PRUint32  aPos,
nsISupports *  aMenuItem 
) [virtual]

Inserts a Menu Item at a specified Index.

 

Implements nsIMenu.

void nsMenuX::InsertMenuItemWithTruncation ( nsAutoString inItemLabel,
PRUint32  inItemIndex 
) [protected]

Definition at line 358 of file nsMenuX.cpp.

{
  // ::TruncateThemeText() doesn't take the number of characters to truncate to, it takes a pixel with
  // to fit the string in. Ugh. I talked it over with sfraser and we couldn't come up with an 
  // easy way to compute what this should be given the system font, etc, so we're just going
  // to hard code it to something reasonable and bigger fonts will just have to deal.
  const short kMaxItemPixelWidth = 300;

  CFMutableStringRef labelRef = ::CFStringCreateMutable ( kCFAllocatorDefault, inItemLabel.Length() );
  ::CFStringAppendCharacters ( labelRef, (UniChar*)inItemLabel.get(), inItemLabel.Length() );
  ::TruncateThemeText(labelRef, kThemeMenuItemFont, kThemeStateActive, kMaxItemPixelWidth, truncMiddle, NULL);
  ::InsertMenuItemTextWithCFString(mMacMenuHandle, labelRef, inItemIndex, 0, 0);
  ::CFRelease(labelRef);

} // InsertMenuItemWithTruncation

Here is the call graph for this function:

Here is the caller graph for this function:

void nsMenuX::InsertMenuItemWithTruncation ( nsAutoString inItemLabel,
PRUint32  inItemIndex 
) [protected]
NS_METHOD nsMenuX::IsHelpMenu ( PRBool aIsHelpMenu) [virtual]

Query if this is the help menu.

Implements nsIMenu.

Definition at line 660 of file nsMenuX.cpp.

NS_IMETHOD nsMenuX::IsHelpMenu ( PRBool aIsHelpMenu) [virtual]

Query if this is the help menu.

Mostly for MacOS voodoo.

Implements nsIMenu.

void nsMenuX::LoadMenuItem ( nsIMenu pParentMenu,
nsIContent menuitemContent 
) [protected]

Definition at line 755 of file nsMenuX.cpp.

{
  if ( !inMenuItemContent )
    return;

  // if menu should be hidden, bail
  nsAutoString hidden;
  inMenuItemContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::hidden, hidden);
  if ( hidden.EqualsLiteral("true") )
    return;

  // Create nsMenuItem
  nsCOMPtr<nsIMenuItem> pnsMenuItem = do_CreateInstance ( kMenuItemCID ) ;
  if ( pnsMenuItem ) {
    nsAutoString disabled;
    nsAutoString checked;
    nsAutoString type;
    nsAutoString menuitemName;
    nsAutoString menuitemCmd;
    
    inMenuItemContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::disabled, disabled);
    inMenuItemContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::checked, checked);
    inMenuItemContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::type, type);
    inMenuItemContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::label, menuitemName);
    inMenuItemContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::command, menuitemCmd);

    //printf("menuitem %s \n", NS_LossyConvertUCS2toASCII(menuitemName).get());
              
    PRBool enabled = ! (disabled.EqualsLiteral("true"));
    
    nsIMenuItem::EMenuItemType itemType = nsIMenuItem::eRegular;
    if ( type.EqualsLiteral("checkbox") )
      itemType = nsIMenuItem::eCheckbox;
    else if ( type.EqualsLiteral("radio") )
      itemType = nsIMenuItem::eRadio;
      
    nsCOMPtr<nsIDocShell>  docShell = do_QueryReferent(mDocShellWeakRef);
    if (!docShell)
      return;

    // Create the item.
    pnsMenuItem->Create(inParentMenu, menuitemName, PR_FALSE, itemType, 
                          enabled, mManager, docShell, inMenuItemContent);   

    //
    // Set key shortcut and modifiers
    //
    
    nsAutoString keyValue;
    inMenuItemContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::key, keyValue);

    // Try to find the key node. Get the document so we can do |GetElementByID|
    nsCOMPtr<nsIDOMDocument> domDocument =
      do_QueryInterface(inMenuItemContent->GetDocument());
    if ( !domDocument )
      return;
  
    nsCOMPtr<nsIDOMElement> keyElement;
    if (!keyValue.IsEmpty())
      domDocument->GetElementById(keyValue, getter_AddRefs(keyElement));
    if ( keyElement ) {
      nsCOMPtr<nsIContent> keyContent ( do_QueryInterface(keyElement) );
      nsAutoString keyChar(NS_LITERAL_STRING(" "));
      keyContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::key, keyChar);
           if(!keyChar.EqualsLiteral(" ")) 
        pnsMenuItem->SetShortcutChar(keyChar);
        
      PRUint8 modifiers = knsMenuItemNoModifier;
           nsAutoString modifiersStr;
      keyContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::modifiers, modifiersStr);
                char* str = ToNewCString(modifiersStr);
                char* newStr;
                char* token = nsCRT::strtok( str, ", ", &newStr );
                while( token != NULL ) {
                  if (PL_strcmp(token, "shift") == 0)
                    modifiers |= knsMenuItemShiftModifier;
                  else if (PL_strcmp(token, "alt") == 0) 
                    modifiers |= knsMenuItemAltModifier;
                  else if (PL_strcmp(token, "control") == 0) 
                    modifiers |= knsMenuItemControlModifier;
                  else if ((PL_strcmp(token, "accel") == 0) ||
                           (PL_strcmp(token, "meta") == 0)) {
          modifiers |= knsMenuItemCommandModifier;
                  }
                  
                  token = nsCRT::strtok( newStr, ", ", &newStr );
                }
                nsMemory::Free(str);

           pnsMenuItem->SetModifiers ( modifiers );
    }

    if ( checked.EqualsLiteral("true") )
      pnsMenuItem->SetChecked(PR_TRUE);
    else
      pnsMenuItem->SetChecked(PR_FALSE);
      
    nsCOMPtr<nsISupports> supports ( do_QueryInterface(pnsMenuItem) );
    inParentMenu->AddItem(supports);         // Parent now owns menu item
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsMenuX::LoadMenuItem ( nsIMenu pParentMenu,
nsIContent menuitemContent 
) [protected]
void nsMenuX::LoadSeparator ( nsIContent menuitemContent) [protected]

Definition at line 897 of file nsMenuX.cpp.

{
  // if item should be hidden, bail
  nsAutoString hidden;
  inMenuItemContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::hidden, hidden);
  if ( hidden.EqualsLiteral("true") )
    return;

  AddSeparator();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsMenuX::LoadSeparator ( nsIContent menuitemContent) [protected]
void nsMenuX::LoadSubMenu ( nsIMenu pParentMenu,
nsIContent menuitemContent 
) [protected]

Definition at line 859 of file nsMenuX.cpp.

{
  // if menu should be hidden, bail
  nsAutoString hidden; 
  inMenuItemContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::hidden, hidden);
  if ( hidden.EqualsLiteral("true") )
    return;
  
  nsAutoString menuName; 
  inMenuItemContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::label, menuName);
  //printf("Creating Menu [%s] \n", NS_LossyConvertUCS2toASCII(menuName).get());

  // Create nsMenu
  nsCOMPtr<nsIMenu> pnsMenu ( do_CreateInstance(kMenuCID) );
  if (pnsMenu) {
    // Call Create
    nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mDocShellWeakRef);
    if (!docShell)
        return;
    nsCOMPtr<nsISupports> supports(do_QueryInterface(pParentMenu));
    pnsMenu->Create(supports, menuName, EmptyString(), mManager, docShell, inMenuItemContent);

    // set if it's enabled or disabled
    nsAutoString disabled;
    inMenuItemContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::disabled, disabled);
    if ( disabled.EqualsLiteral("true") )
      pnsMenu->SetEnabled ( PR_FALSE );
    else
      pnsMenu->SetEnabled ( PR_TRUE );

    // Make nsMenu a child of parent nsMenu. The parent takes ownership
    nsCOMPtr<nsISupports> supports2 ( do_QueryInterface(pnsMenu) );
         pParentMenu->AddItem(supports2);
  }     
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsMenuX::LoadSubMenu ( nsIMenu pParentMenu,
nsIContent menuitemContent 
) [protected]
nsEventStatus nsMenuX::MenuConstruct ( const nsMenuEvent aMenuEvent,
nsIWidget aParentWindow,
void menuNode,
void aDocShell 
) [virtual]

Implements nsIMenuListener.

Definition at line 545 of file nsMenuX.cpp.

{
  mConstructed = false;
  gConstructingMenu = PR_TRUE;
  
  // reset destroy handler flag so that we'll know to fire it next time this menu goes away.
  mDestroyHandlerCalled = PR_FALSE;
  
  //printf("nsMenuX::MenuConstruct called for %s = %d \n", NS_LossyConvertUCS2toASCII(mLabel).get(), mMacMenuHandle);
  // Begin menuitem inner loop
  
  // Retrieve our menupopup.
  nsCOMPtr<nsIContent> menuPopup;
  GetMenuPopupContent(getter_AddRefs(menuPopup));
  if (!menuPopup)
    return nsEventStatus_eIgnore;
      
  // Iterate over the kids
  PRUint32 count = menuPopup->GetChildCount();
  for ( PRUint32 i = 0; i < count; ++i ) {
    nsIContent *child = menuPopup->GetChildAt(i);
    if ( child ) {
      // depending on the type, create a menu item, separator, or submenu
      nsIAtom *tag = child->Tag();
      if ( tag == nsWidgetAtoms::menuitem )
        LoadMenuItem(this, child);
      else if ( tag == nsWidgetAtoms::menuseparator )
        LoadSeparator(child);
      else if ( tag == nsWidgetAtoms::menu )
        LoadSubMenu(this, child);
    }
  } // for each menu item
  
  gConstructingMenu = PR_FALSE;
  mNeedsRebuild = PR_FALSE;
  //printf("  Done building, mMenuItemVoidArray.Count() = %d \n", mMenuItemVoidArray.Count());
  
  return nsEventStatus_eIgnore;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsEventStatus nsMenuX::MenuConstruct ( const nsMenuEvent aMenuEvent,
nsIWidget aParentWindow,
void menuNode,
void aDocShell 
) [virtual]

Implements nsIMenuListener.

Processes a menu deselect event.

Parameters:
aMenuEventSee nsGUIEvent.h
Returns:
whether the event was consumed or ignored. See nsEventStatus

Implements nsIMenuListener.

Definition at line 534 of file nsMenuX.cpp.

{
  // Destroy the menu
  if (mConstructed) {
    MenuDestruct(aMenuEvent);
    mConstructed = false;
  }
  return nsEventStatus_eIgnore;
}

Here is the call graph for this function:

Processes a menu deselect event.

Parameters:
aMenuEventSee nsGUIEvent.h
Returns:
whether the event was consumed or ignored. See nsEventStatus

Implements nsIMenuListener.

Implements nsIMenuListener.

Definition at line 591 of file nsMenuX.cpp.

{
  //printf("nsMenuX::MenuDestruct() called for %s \n", NS_LossyConvertUCS2toASCII(mLabel).get());
  
  // Fire our ondestroy handler. If we're told to stop, don't destroy the menu
  PRBool keepProcessing = OnDestroy();
  if ( keepProcessing ) {
    if(mNeedsRebuild) {
        mConstructed = false;
        //printf("  mMenuItemVoidArray.Count() = %d \n", mMenuItemVoidArray.Count());
    } 
    // Close the node.
    mMenuContent->UnsetAttr(kNameSpaceID_None, nsWidgetAtoms::open, PR_TRUE);

    OnDestroyed();
  }
  
  return nsEventStatus_eIgnore;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Implements nsIMenuListener.

Processes a menu item selected event.

Parameters:
aMenuEventSee nsGUIEvent.h
Returns:
whether the event was consumed or ignored. See nsEventStatus

Implements nsIMenuListener.

Definition at line 471 of file nsMenuX.cpp.

{
  // all this is now handled by Carbon Events.
  return nsEventStatus_eConsumeNoDefault;
}
NS_DECL_ISUPPORTS NS_DECL_NSICHANGEOBSERVER nsEventStatus nsMenuX::MenuItemSelected ( const nsMenuEvent aMenuEvent) [virtual]

Processes a menu item selected event.

Parameters:
aMenuEventSee nsGUIEvent.h
Returns:
whether the event was consumed or ignored. See nsEventStatus

Implements nsIMenuListener.

Processes a menu selected event.

Parameters:
aMenuEventSee nsGUIEvent.h
Returns:
whether the event was consumed or ignored. See nsEventStatus

Implements nsIMenuListener.

Definition at line 478 of file nsMenuX.cpp.

{
  //printf("MenuSelected called for %s \n", NS_LossyConvertUCS2toASCII(mLabel).get());
  nsEventStatus eventStatus = nsEventStatus_eIgnore;

  // Determine if this is the correct menu to handle the event
  MenuHandle selectedMenuHandle = (MenuHandle) aMenuEvent.mCommand;

  if (mMacMenuHandle == selectedMenuHandle) {
    // Open the node.
    mMenuContent->SetAttr(kNameSpaceID_None, nsWidgetAtoms::open, NS_LITERAL_STRING("true"), PR_TRUE);
  

    // Fire our oncreate handler. If we're told to stop, don't build the menu at all
    PRBool keepProcessing = OnCreate();

    if (!mNeedsRebuild || !keepProcessing)
      return nsEventStatus_eConsumeNoDefault;

    if(!mConstructed || mNeedsRebuild) {
      if (mNeedsRebuild)
        RemoveAll();

      nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mDocShellWeakRef);
      if (!docShell) {
        NS_ERROR("No doc shell");
        return nsEventStatus_eConsumeNoDefault;
      }
      MenuConstruct(aMenuEvent, nsnull /* mParentWindow */, nsnull, docShell);
      mConstructed = true;
    } 

    OnCreated();  // Now that it's built, fire the popupShown event.

    eventStatus = nsEventStatus_eConsumeNoDefault;  
  } 
  else {
    // Make sure none of our submenus are the ones that should be handling this
    PRUint32    numItems;
    mMenuItemsArray.Count(&numItems);
    for (PRUint32 i = numItems; i > 0; i--) {
      nsCOMPtr<nsISupports>     menuSupports = getter_AddRefs(mMenuItemsArray.ElementAt(i - 1));    
      nsCOMPtr<nsIMenu>         submenu = do_QueryInterface(menuSupports);
      nsCOMPtr<nsIMenuListener> menuListener = do_QueryInterface(submenu);
      if (menuListener) {
        eventStatus = menuListener->MenuSelected(aMenuEvent);
        if (nsEventStatus_eIgnore != eventStatus)
          return eventStatus;
      }  
    }
  }

  return eventStatus;
}

Here is the call graph for this function:

Processes a menu selected event.

Parameters:
aMenuEventSee nsGUIEvent.h
Returns:
whether the event was consumed or ignored. See nsEventStatus

Implements nsIMenuListener.

MenuHandle nsMenuX::NSStringNewMenu ( short  menuID,
nsString menuTitle 
) [protected]

Definition at line 735 of file nsMenuX.cpp.

{
  MenuRef menuRef;
  OSStatus status = ::CreateNewMenu(menuID, 0, &menuRef);
  NS_ASSERTION(status == noErr,"nsMenuX::NSStringNewMenu: NewMenu failed.");
  CFStringRef titleRef = ::CFStringCreateWithCharacters(kCFAllocatorDefault, (UniChar*)menuTitle.get(), menuTitle.Length());
  NS_ASSERTION(titleRef,"nsMenuX::NSStringNewMenu: CFStringCreateWithCharacters failed.");
  if (titleRef) {
    ::SetMenuTitleWithCFString(menuRef, titleRef);
    ::CFRelease(titleRef);
  }
  
  status = InstallMyMenuEventHandler(menuRef, this, &mHandler);
  NS_ASSERTION(status == noErr,"nsMenuX::NSStringNewMenu: InstallMyMenuEventHandler failed.");

  return menuRef;
}

Here is the call graph for this function:

Here is the caller graph for this function:

MenuHandle nsMenuX::NSStringNewMenu ( short  menuID,
nsString menuTitle 
) [protected]
PRBool nsMenuX::OnCreate ( ) [protected]

Definition at line 917 of file nsMenuX.cpp.

{
  nsEventStatus status = nsEventStatus_eIgnore;
  nsMouseEvent event(PR_TRUE, NS_XUL_POPUP_SHOWING, nsnull,
                     nsMouseEvent::eReal);

  nsCOMPtr<nsIContent> popupContent;
  GetMenuPopupContent(getter_AddRefs(popupContent));

  nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mDocShellWeakRef);
  if (!docShell) {
    NS_ERROR("No doc shell");
    return PR_FALSE;
  }
  nsCOMPtr<nsPresContext> presContext;
  MenuHelpersX::DocShellToPresContext(docShell, getter_AddRefs(presContext) );
  if ( presContext ) {
    nsresult rv = NS_OK;
    nsIContent* dispatchTo = popupContent ? popupContent : mMenuContent;
    rv = dispatchTo->HandleDOMEvent(presContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
    if ( NS_FAILED(rv) || status == nsEventStatus_eConsumeNoDefault )
      return PR_FALSE;
 }

  // the menu is going to show and the oncreate handler has executed. We
  // now need to walk our menu items, checking to see if any of them have
  // a command attribute. If so, several apptributes must potentially
  // be updated.
  if (popupContent) {
    nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(popupContent->GetDocument()));

    PRUint32 count = popupContent->GetChildCount();
    for (PRUint32 i = 0; i < count; i++) {
      nsIContent *grandChild = popupContent->GetChildAt(i);
      nsIAtom *tag = grandChild->Tag();
      if (tag == nsWidgetAtoms::menuitem) {
        // See if we have a command attribute.
        nsAutoString command;
        grandChild->GetAttr(kNameSpaceID_None, nsWidgetAtoms::command, command);
        if (!command.IsEmpty()) {
          // We do! Look it up in our document
          nsCOMPtr<nsIDOMElement> commandElt;
          domDoc->GetElementById(command, getter_AddRefs(commandElt));
          nsCOMPtr<nsIContent> commandContent(do_QueryInterface(commandElt));

          if ( commandContent ) {
            nsAutoString commandDisabled, menuDisabled;
            commandContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::disabled, commandDisabled);
            grandChild->GetAttr(kNameSpaceID_None, nsWidgetAtoms::disabled, menuDisabled);
            if (!commandDisabled.Equals(menuDisabled)) {
              // The menu's disabled state needs to be updated to match the command.
              if (commandDisabled.IsEmpty()) 
                grandChild->UnsetAttr(kNameSpaceID_None, nsWidgetAtoms::disabled, PR_TRUE);
              else grandChild->SetAttr(kNameSpaceID_None, nsWidgetAtoms::disabled, commandDisabled, PR_TRUE);
            }

            // The menu's value and checked states need to be updated to match the command.
            // Note that (unlike the disabled state) if the command has *no* value for either, we
            // assume the menu is supplying its own.
            nsAutoString commandChecked, menuChecked;
            commandContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::checked, commandChecked);
            grandChild->GetAttr(kNameSpaceID_None, nsWidgetAtoms::checked, menuChecked);
            if (!commandChecked.Equals(menuChecked)) {
              if (!commandChecked.IsEmpty()) 
                grandChild->SetAttr(kNameSpaceID_None, nsWidgetAtoms::checked, commandChecked, PR_TRUE);
            }

            nsAutoString commandValue, menuValue;
            commandContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::label, commandValue);
            grandChild->GetAttr(kNameSpaceID_None, nsWidgetAtoms::label, menuValue);
            if (!commandValue.Equals(menuValue)) {
              if (!commandValue.IsEmpty()) 
                grandChild->SetAttr(kNameSpaceID_None, nsWidgetAtoms::label, commandValue, PR_TRUE);
            }
          }
        }
      }
    }
  }
  
  return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsMenuX::OnCreate ( ) [protected]
PRBool nsMenuX::OnCreated ( ) [protected]

Definition at line 1001 of file nsMenuX.cpp.

{
  nsEventStatus status = nsEventStatus_eIgnore;
  nsMouseEvent event(PR_TRUE, NS_XUL_POPUP_SHOWN, nsnull, nsMouseEvent::eReal);
  
  nsCOMPtr<nsIContent> popupContent;
  GetMenuPopupContent(getter_AddRefs(popupContent));

  nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mDocShellWeakRef);
  if (!docShell) {
    NS_ERROR("No doc shell");
    return PR_FALSE;
  }
  nsCOMPtr<nsPresContext> presContext;
  MenuHelpersX::DocShellToPresContext(docShell, getter_AddRefs(presContext) );
  if ( presContext ) {
    nsresult rv = NS_OK;
    nsIContent* dispatchTo = popupContent ? popupContent : mMenuContent;
    rv = dispatchTo->HandleDOMEvent(presContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
    if ( NS_FAILED(rv) || status == nsEventStatus_eConsumeNoDefault )
      return PR_FALSE;
 }
  
  return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsMenuX::OnCreated ( ) [protected]
PRBool nsMenuX::OnDestroy ( void  ) [protected]

Definition at line 1034 of file nsMenuX.cpp.

{
  if ( mDestroyHandlerCalled )
    return PR_TRUE;

  nsEventStatus status = nsEventStatus_eIgnore;
  nsMouseEvent event(PR_TRUE, NS_XUL_POPUP_HIDING, nsnull,
                     nsMouseEvent::eReal);
  
  nsCOMPtr<nsIDocShell>  docShell = do_QueryReferent(mDocShellWeakRef);
  if (!docShell) {
    NS_WARNING("No doc shell so can't run the OnDestroy");
    return PR_FALSE;
  }

  nsCOMPtr<nsIContent> popupContent;
  GetMenuPopupContent(getter_AddRefs(popupContent));

  nsCOMPtr<nsPresContext> presContext;
  MenuHelpersX::DocShellToPresContext (docShell, getter_AddRefs(presContext) );
  if (presContext )  {
    nsresult rv = NS_OK;
    nsIContent* dispatchTo = popupContent ? popupContent : mMenuContent;
    rv = dispatchTo->HandleDOMEvent(presContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);

    mDestroyHandlerCalled = PR_TRUE;
    
    if ( NS_FAILED(rv) || status == nsEventStatus_eConsumeNoDefault )
      return PR_FALSE;
  }
  return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsMenuX::OnDestroy ( ) [protected]
PRBool nsMenuX::OnDestroyed ( ) [protected]

Definition at line 1068 of file nsMenuX.cpp.

{
  nsEventStatus status = nsEventStatus_eIgnore;
  nsMouseEvent event(PR_TRUE, NS_XUL_POPUP_HIDDEN, nsnull,
                     nsMouseEvent::eReal);
  
  nsCOMPtr<nsIDocShell>  docShell = do_QueryReferent(mDocShellWeakRef);
  if (!docShell) {
    NS_WARNING("No doc shell so can't run the OnDestroy");
    return PR_FALSE;
  }

  nsCOMPtr<nsIContent> popupContent;
  GetMenuPopupContent(getter_AddRefs(popupContent));

  nsCOMPtr<nsPresContext> presContext;
  MenuHelpersX::DocShellToPresContext (docShell, getter_AddRefs(presContext) );
  if (presContext )  {
    nsresult rv = NS_OK;
    nsIContent* dispatchTo = popupContent ? popupContent : mMenuContent;
    rv = dispatchTo->HandleDOMEvent(presContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);

    mDestroyHandlerCalled = PR_TRUE;
    
    if ( NS_FAILED(rv) || status == nsEventStatus_eConsumeNoDefault )
      return PR_FALSE;
  }
  return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsMenuX::OnDestroyed ( ) [protected]

Removes all the Menu Items.

 

Implements nsIMenu.

Definition at line 416 of file nsMenuX.cpp.

{
  if (mMacMenuHandle != NULL) {    
    // clear command id's
    nsCOMPtr<nsIMenuCommandDispatcher> dispatcher ( do_QueryInterface(mManager) );
    if ( dispatcher ) {
      for ( int i = 1; i <= mNumMenuItems; ++i ) {
        PRUint32 commandID = 0L;
        OSErr err = ::GetMenuItemCommandID(mMacMenuHandle, i, (unsigned long*)&commandID);
        if ( !err )
          dispatcher->Unregister(commandID);
      }
    }
    ::DeleteMenuItems(mMacMenuHandle, 1, ::CountMenuItems(mMacMenuHandle));
  }
  
  mMenuItemsArray.Clear();    // remove all items
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Removes all the Menu Items.

 

Implements nsIMenu.

Removes an Menu Item from a specified Index.

 

Implements nsIMenu.

Definition at line 409 of file nsMenuX.cpp.

{
  NS_WARNING("Not implemented");
  return NS_OK;
}

Removes an Menu Item from a specified Index.

 

Implements nsIMenu.

NS_METHOD nsMenuX::RemoveMenuListener ( nsIMenuListener aMenuListener) [virtual]

Removes menu listener for dynamic construction.

 

Implements nsIMenu.

Definition at line 458 of file nsMenuX.cpp.

{
  if (aMenuListener == mListener)
    mListener = nsnull;
  return NS_OK;
}
NS_IMETHOD nsMenuX::RemoveMenuListener ( nsIMenuListener aMenuListener) [virtual]

Removes menu listener for dynamic construction.

 

Implements nsIMenu.

NS_METHOD nsMenuX::SetAccessKey ( const nsAString &  aText) [virtual]

Set the Menu Access Key.

 

Implements nsIMenu.

Definition at line 223 of file nsMenuX.cpp.

{
  return NS_OK;
}

Here is the caller graph for this function:

NS_IMETHOD nsMenuX::SetAccessKey ( const nsAString &  aText) [virtual]

Set the Menu Access Key.

 

Implements nsIMenu.

NS_METHOD nsMenuX::SetEnabled ( PRBool  aIsEnabled) [virtual]

Set enabled state.

Implements nsIMenu.

Definition at line 631 of file nsMenuX.cpp.

{
  mIsEnabled = aIsEnabled;

  if ( aIsEnabled )
    ::EnableMenuItem(mMacMenuHandle, 0);
  else
    ::DisableMenuItem(mMacMenuHandle, 0);

  return NS_OK;
}
NS_IMETHOD nsMenuX::SetEnabled ( PRBool  aIsEnabled) [virtual]

Set the Menu enabled state.

 

Implements nsIMenu.

NS_METHOD nsMenuX::SetLabel ( const nsAString &  aText) [virtual]

Set the Menu label.

 

Implements nsIMenu.

Definition at line 203 of file nsMenuX.cpp.

{
  mLabel = aText;

  // first time? create the menu handle, attach event handler to it.
  if (mMacMenuHandle == nsnull) {
    mMacMenuID = gMacMenuIDCountX++;
    mMacMenuHandle = NSStringNewMenu(mMacMenuID, mLabel);
  }
  
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHOD nsMenuX::SetLabel ( const nsAString &  aText) [virtual]

Set the Menu label.

 

Implements nsIMenu.

NS_METHOD nsMenuX::SetNativeData ( void aData) [virtual]

Sets Native MenuHandle.

 

Implements nsIMenu.

Definition at line 444 of file nsMenuX.cpp.

{
  mMacMenuHandle = (MenuHandle) aData;
  return NS_OK;
}
NS_IMETHOD nsMenuX::SetNativeData ( void aData) [virtual]

Sets Native MenuHandle.

 

Implements nsIMenu.

nsEventStatus nsMenuX::SetRebuild ( PRBool  aMenuEvent) [virtual]

Implements nsIMenuListener.

Definition at line 619 of file nsMenuX.cpp.

{
  if(!gConstructingMenu)
    mNeedsRebuild = aNeedsRebuild;
  return nsEventStatus_eIgnore;
}
nsEventStatus nsMenuX::SetRebuild ( PRBool  aMenuEvent) [virtual]

Implements nsIMenuListener.

Sets an appropriate icon for the menu.

Implements nsIMenu_MOZILLA_1_8_BRANCH.

Definition at line 1460 of file nsMenuX.cpp.

{
  // In addition to out-of-memory, menus that are children of the menu bar
  // will not have mIcon set.

  if (!mIcon) return NS_ERROR_OUT_OF_MEMORY;

  return mIcon->SetupIcon();
}

Member Data Documentation

Definition at line 153 of file nsMenuX.h.

Definition at line 151 of file nsMenuX.h.

Definition at line 143 of file nsMenuX.h.

EventHandlerRef nsMenuX::mHandler [protected]

Definition at line 156 of file nsMenuX.h.

Definition at line 188 of file nsMenuX.h.

Definition at line 150 of file nsMenuX.h.

Definition at line 137 of file nsMenuX.h.

Definition at line 145 of file nsMenuX.h.

MenuHandle nsMenuX::mMacMenuHandle [protected]

Definition at line 149 of file nsMenuX.h.

Definition at line 148 of file nsMenuX.h.

Definition at line 142 of file nsMenuX.h.

Definition at line 144 of file nsMenuX.h.

nsSupportsArray nsMenuX::mMenuItemsArray [protected]

Definition at line 139 of file nsMenuX.h.

Definition at line 152 of file nsMenuX.h.

Definition at line 138 of file nsMenuX.h.

nsISupports * nsMenuX::mParent [protected]

Definition at line 141 of file nsMenuX.h.

Definition at line 154 of file nsMenuX.h.


The documentation for this class was generated from the following files: