Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions | Variables
nsMenuX.cpp File Reference
#include "nsCOMPtr.h"
#include "nsIDocument.h"
#include "nsIContent.h"
#include "nsIDOMDocument.h"
#include "nsIDocumentViewer.h"
#include "nsIDocumentObserver.h"
#include "nsIComponentManager.h"
#include "nsIDocShell.h"
#include "prinrval.h"
#include "nsIRollupListener.h"
#include "nsMenuX.h"
#include "nsMenuBarX.h"
#include "nsIMenu.h"
#include "nsIMenuBar.h"
#include "nsIMenuItem.h"
#include "nsIMenuListener.h"
#include "nsPresContext.h"
#include "nsIMenuCommandDispatcher.h"
#include "nsMenuItemIcon.h"
#include "nsString.h"
#include "nsReadableUtils.h"
#include "nsUnicharUtils.h"
#include "plstr.h"
#include "nsINameSpaceManager.h"
#include "nsWidgetAtoms.h"
#include "nsIXBLService.h"
#include "nsIServiceManager.h"
#include <Appearance.h>
#include <ToolUtils.h>
#include <UnicodeConverter.h>
#include "nsGUIEvent.h"
#include "nsCRT.h"
#include "nsToolkit.h"
#include "nsWidgetsCID.h"

Go to the source code of this file.


class  nsDummyMenuItemX


static OSStatus InstallMyMenuEventHandler (MenuRef menuRef, void *userData, EventHandlerRef *outHandler)
 NS_IMETHODIMP_ (nsrefcnt) nsDummyMenuItemX
static pascal OSStatus MyMenuEventHandler (EventHandlerCallRef myHandler, EventRef event, void *userData)


static MenuID gCurrentlyTrackedMenuID = 0
const PRInt16 kMacMenuIDX = nsMenuBarX::kAppleMenuID + 1
static PRInt16 gMacMenuIDCountX = kMacMenuIDX
static PRBool gConstructingMenu = PR_FALSE
static nsDummyMenuItemX gDummyMenuItemX

Function Documentation

static OSStatus InstallMyMenuEventHandler ( MenuRef  menuRef,
void userData,
EventHandlerRef *  outHandler 
) [static]

Definition at line 761 of file nsMenuX.cpp.

  // install the event handler for the various carbon menu events.
  static EventTypeSpec eventList[] = {
      { kEventClassMenu, kEventMenuOpening },
      { kEventClassMenu, kEventMenuClosed },
      { kEventClassMenu, kEventMenuTargetItem },
  static EventHandlerUPP gMyMenuEventHandlerUPP = NewEventHandlerUPP(&MyMenuEventHandler);
  return ::InstallMenuEventHandler(menuRef, gMyMenuEventHandlerUPP,
                                   sizeof(eventList) / sizeof(EventTypeSpec), eventList,
                                   userData, outHandler);

Here is the call graph for this function:

static pascal OSStatus MyMenuEventHandler ( EventHandlerCallRef  myHandler,
EventRef  event,
void userData 
) [static]

Definition at line 704 of file nsMenuX.cpp.

  OSStatus result = eventNotHandledErr;

  UInt32 kind = ::GetEventKind(event);
  if (kind == kEventMenuTargetItem) {
    // get the position of the menu item we want
    nsIMenu* targetMenu = reinterpret_cast<nsIMenu*>(userData);
    PRUint16 aPos;
    ::GetEventParameter(event, kEventParamMenuItemIndex, typeMenuItemIndex, NULL, sizeof(MenuItemIndex), NULL, &aPos);
    aPos--; // subtract 1 from aPos because Carbon menu positions start at 1 not 0
    nsISupports* aTargetMenuItem;
    targetMenu->GetItemAt((PRUint32)aPos, aTargetMenuItem);
    // Send DOM event
    // If the QI fails, we're over a submenu and we shouldn't send the event
    nsCOMPtr<nsIMenuItem_MOZILLA_1_8_BRANCH> bTargetMenuItem(do_QueryInterface(aTargetMenuItem));
    if (bTargetMenuItem) {
      PRBool handlerCalledPreventDefault; // but we don't actually care
      bTargetMenuItem->DispatchDOMEvent(NS_LITERAL_STRING("DOMMenuItemActive"), &handlerCalledPreventDefault);
    // remember which menu ID we're over for later
    MenuRef menuRef;
    ::GetEventParameter(event, kEventParamDirectObject, typeMenuRef, NULL, sizeof(menuRef), NULL, &menuRef);
    gCurrentlyTrackedMenuID = ::GetMenuID(menuRef);
  else if (kind == kEventMenuOpening || kind == kEventMenuClosed) {
    if (kind == kEventMenuOpening && gRollupListener != nsnull && gRollupWidget != nsnull) {
      // We can only return userCanceledErr on Tiger or later because it crashes on Panther.
      // See bug 351230.
      if (nsToolkit::OSXVersion() >= MAC_OS_X_VERSION_10_4_HEX)
        return userCanceledErr;

    nsISupports* supports = reinterpret_cast<nsISupports*>(userData);
    nsCOMPtr<nsIMenuListener> listener(do_QueryInterface(supports));
    if (listener) {
      MenuRef menuRef;
      ::GetEventParameter(event, kEventParamDirectObject, typeMenuRef, NULL, sizeof(menuRef), NULL, &menuRef);
      nsMenuEvent menuEvent(PR_TRUE, NS_MENU_SELECTED, nsnull);
      menuEvent.time = PR_IntervalNow();
      menuEvent.mCommand = (PRUint32) menuRef;
      if (kind == kEventMenuOpening) {
        gCurrentlyTrackedMenuID = ::GetMenuID(menuRef);    // remember which menu ID we're over for later
  return result;

Here is the call graph for this function:

Here is the caller graph for this function:

static NS_DEFINE_CID ( kMenuCID  ,
) [static]
static NS_DEFINE_CID ( kMenuItemCID  ,
) [static]

Definition at line 112 of file nsMenuX.cpp.

{ return ++mRefCnt; }

Variable Documentation

Definition at line 91 of file nsMenuX.cpp.

MenuID gCurrentlyTrackedMenuID = 0 [static]

Definition at line 87 of file nsMenuX.cpp.

Definition at line 115 of file nsMenuX.cpp.

Definition at line 90 of file nsMenuX.cpp.

Definition at line 137 of file

Definition at line 138 of file

Definition at line 89 of file nsMenuX.cpp.