michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsMenuX_h_ michael@0: #define nsMenuX_h_ michael@0: michael@0: #import michael@0: michael@0: #include "nsMenuBaseX.h" michael@0: #include "nsMenuBarX.h" michael@0: #include "nsMenuGroupOwnerX.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsChangeObserver.h" michael@0: #include "nsAutoPtr.h" michael@0: michael@0: class nsMenuX; michael@0: class nsMenuItemIconX; michael@0: class nsMenuItemX; michael@0: class nsIWidget; michael@0: michael@0: // MenuDelegate is used to receive Cocoa notifications for setting michael@0: // up carbon events. Protocol is defined as of 10.6 SDK. michael@0: #if defined(MAC_OS_X_VERSION_10_6) && (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6) michael@0: @interface MenuDelegate : NSObject < NSMenuDelegate > michael@0: #else michael@0: @interface MenuDelegate : NSObject michael@0: #endif michael@0: { michael@0: nsMenuX* mGeckoMenu; // weak ref michael@0: } michael@0: - (id)initWithGeckoMenu:(nsMenuX*)geckoMenu; michael@0: @end michael@0: michael@0: // Once instantiated, this object lives until its DOM node or its parent window is destroyed. michael@0: // Do not hold references to this, they can become invalid any time the DOM node can be destroyed. michael@0: class nsMenuX : public nsMenuObjectX, michael@0: public nsChangeObserver michael@0: { michael@0: public: michael@0: nsMenuX(); michael@0: virtual ~nsMenuX(); michael@0: michael@0: // If > 0, the OS is indexing all the app's menus (triggered by opening michael@0: // Help menu on Leopard and higher). There are some things that are michael@0: // unsafe to do while this is happening. michael@0: static int32_t sIndexingMenuLevel; michael@0: michael@0: NS_DECL_CHANGEOBSERVER michael@0: michael@0: // nsMenuObjectX michael@0: void* NativeData() {return (void*)mNativeMenu;} michael@0: nsMenuObjectTypeX MenuObjectType() {return eSubmenuObjectType;} michael@0: michael@0: // nsMenuX michael@0: nsresult Create(nsMenuObjectX* aParent, nsMenuGroupOwnerX* aMenuGroupOwner, nsIContent* aNode); michael@0: uint32_t GetItemCount(); michael@0: nsMenuObjectX* GetItemAt(uint32_t aPos); michael@0: nsresult GetVisibleItemCount(uint32_t &aCount); michael@0: nsMenuObjectX* GetVisibleItemAt(uint32_t aPos); michael@0: nsEventStatus MenuOpened(); michael@0: void MenuClosed(); michael@0: void SetRebuild(bool aMenuEvent); michael@0: NSMenuItem* NativeMenuItem(); michael@0: michael@0: static bool IsXULHelpMenu(nsIContent* aMenuContent); michael@0: michael@0: protected: michael@0: void MenuConstruct(); michael@0: nsresult RemoveAll(); michael@0: nsresult SetEnabled(bool aIsEnabled); michael@0: nsresult GetEnabled(bool* aIsEnabled); michael@0: nsresult SetupIcon(); michael@0: void GetMenuPopupContent(nsIContent** aResult); michael@0: bool OnOpen(); michael@0: bool OnClose(); michael@0: nsresult AddMenuItem(nsMenuItemX* aMenuItem); michael@0: nsresult AddMenu(nsMenuX* aMenu); michael@0: void LoadMenuItem(nsIContent* inMenuItemContent); michael@0: void LoadSubMenu(nsIContent* inMenuContent); michael@0: GeckoNSMenu* CreateMenuWithGeckoString(nsString& menuTitle); michael@0: michael@0: nsTArray< nsAutoPtr > mMenuObjectsArray; michael@0: nsString mLabel; michael@0: uint32_t mVisibleItemsCount; // cache michael@0: nsMenuObjectX* mParent; // [weak] michael@0: nsMenuGroupOwnerX* mMenuGroupOwner; // [weak] michael@0: // The icon object should never outlive its creating nsMenuX object. michael@0: nsRefPtr mIcon; michael@0: GeckoNSMenu* mNativeMenu; // [strong] michael@0: MenuDelegate* mMenuDelegate; // [strong] michael@0: // nsMenuX objects should always have a valid native menu item. michael@0: NSMenuItem* mNativeMenuItem; // [strong] michael@0: bool mIsEnabled; michael@0: bool mDestroyHandlerCalled; michael@0: bool mNeedsRebuild; michael@0: bool mConstructed; michael@0: bool mVisible; michael@0: bool mXBLAttached; michael@0: }; michael@0: michael@0: #endif // nsMenuX_h_