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 nsMenuBarX_h_ michael@0: #define nsMenuBarX_h_ michael@0: michael@0: #import michael@0: michael@0: #include "nsMenuBaseX.h" michael@0: #include "nsMenuGroupOwnerX.h" michael@0: #include "nsChangeObserver.h" michael@0: #include "nsINativeMenuService.h" michael@0: #include "nsAutoPtr.h" michael@0: #include "nsString.h" michael@0: michael@0: class nsMenuX; michael@0: class nsMenuBarX; michael@0: class nsMenuItemX; michael@0: class nsIWidget; michael@0: class nsIContent; michael@0: michael@0: // The native menu service for creating native menu bars. michael@0: class nsNativeMenuServiceX : public nsINativeMenuService michael@0: { michael@0: public: michael@0: NS_DECL_ISUPPORTS michael@0: michael@0: nsNativeMenuServiceX() {} michael@0: virtual ~nsNativeMenuServiceX() {} michael@0: michael@0: NS_IMETHOD CreateNativeMenuBar(nsIWidget* aParent, nsIContent* aMenuBarNode); michael@0: }; michael@0: michael@0: @interface NSMenu (Undocumented) michael@0: // Undocumented method, present unchanged since OS X 10.6, used to temporarily michael@0: // highlight a top-level menu item when an appropriate Cmd+key combination is michael@0: // pressed. michael@0: - (void)_performActionWithHighlightingForItemAtIndex:(NSInteger)index; michael@0: @end michael@0: michael@0: // Objective-C class used to allow us to intervene with keyboard event handling. michael@0: // We allow mouse actions to work normally. michael@0: @interface GeckoNSMenu : NSMenu michael@0: { michael@0: @private michael@0: nsMenuBarX *mMenuBarOwner; // Weak -- if non-null it owns us michael@0: bool mDelayResignMainMenu; michael@0: } michael@0: - (id)initWithTitle:(NSString *)aTitle andMenuBarOwner:(nsMenuBarX *)aMenuBarOwner; michael@0: - (void)resetMenuBarOwner; michael@0: - (bool)delayResignMainMenu; michael@0: - (void)setDelayResignMainMenu:(bool)aShouldDelay; michael@0: - (void)delayedPaintMenuBar:(id)unused; michael@0: @end michael@0: michael@0: // Objective-C class used as action target for menu items michael@0: @interface NativeMenuItemTarget : NSObject michael@0: { michael@0: } michael@0: -(IBAction)menuItemHit:(id)sender; michael@0: @end michael@0: michael@0: // Objective-C class used for menu items on the Services menu to allow Gecko michael@0: // to override their standard behavior in order to stop key equivalents from michael@0: // firing in certain instances. michael@0: @interface GeckoServicesNSMenuItem : NSMenuItem michael@0: { michael@0: } michael@0: - (id) target; michael@0: - (SEL) action; michael@0: - (void) _doNothing:(id)sender; michael@0: @end michael@0: michael@0: // Objective-C class used as the Services menu so that Gecko can override the michael@0: // standard behavior of the Services menu in order to stop key equivalents michael@0: // from firing in certain instances. michael@0: @interface GeckoServicesNSMenu : NSMenu michael@0: { michael@0: } michael@0: - (void)addItem:(NSMenuItem *)newItem; michael@0: - (NSMenuItem *)addItemWithTitle:(NSString *)aString action:(SEL)aSelector keyEquivalent:(NSString *)keyEquiv; michael@0: - (void)insertItem:(NSMenuItem *)newItem atIndex:(NSInteger)index; michael@0: - (NSMenuItem *)insertItemWithTitle:(NSString *)aString action:(SEL)aSelector keyEquivalent:(NSString *)keyEquiv atIndex:(NSInteger)index; michael@0: - (void) _overrideClassOfMenuItem:(NSMenuItem *)menuItem; 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 nsMenuBarX : public nsMenuGroupOwnerX, public nsChangeObserver michael@0: { michael@0: public: michael@0: nsMenuBarX(); michael@0: virtual ~nsMenuBarX(); michael@0: michael@0: static NativeMenuItemTarget* sNativeEventTarget; michael@0: static nsMenuBarX* sLastGeckoMenuBarPainted; michael@0: static nsMenuBarX* sCurrentPaintDelayedMenuBar; michael@0: michael@0: // The following content nodes have been removed from the menu system. michael@0: // We save them here for use in command handling. michael@0: nsCOMPtr mAboutItemContent; michael@0: nsCOMPtr mUpdateItemContent; michael@0: nsCOMPtr mPrefItemContent; michael@0: nsCOMPtr mQuitItemContent; michael@0: michael@0: // nsChangeObserver michael@0: NS_DECL_CHANGEOBSERVER michael@0: michael@0: // nsMenuObjectX michael@0: void* NativeData() {return (void*)mNativeMenu;} michael@0: nsMenuObjectTypeX MenuObjectType() {return eMenuBarObjectType;} michael@0: michael@0: // nsMenuBarX michael@0: nsresult Create(nsIWidget* aParent, nsIContent* aContent); michael@0: void SetParent(nsIWidget* aParent); michael@0: uint32_t GetMenuCount(); michael@0: bool MenuContainsAppMenu(); michael@0: nsMenuX* GetMenuAt(uint32_t aIndex); michael@0: nsMenuX* GetXULHelpMenu(); michael@0: void SetSystemHelpMenu(); michael@0: nsresult Paint(bool aDelayed = false); michael@0: void PaintMenuBarAfterDelay(); michael@0: void ResetAwaitingDelayedPaint() { mAwaitingDelayedPaint = false; } michael@0: void ForceUpdateNativeMenuAt(const nsAString& indexString); michael@0: void ForceNativeMenuReload(); // used for testing michael@0: static char GetLocalizedAccelKey(const char *shortcutID); michael@0: michael@0: protected: michael@0: void ConstructNativeMenus(); michael@0: nsresult InsertMenuAtIndex(nsMenuX* aMenu, uint32_t aIndex); michael@0: void RemoveMenuAtIndex(uint32_t aIndex); michael@0: void HideItem(nsIDOMDocument* inDoc, const nsAString & inID, nsIContent** outHiddenNode); michael@0: void AquifyMenuBar(); michael@0: NSMenuItem* CreateNativeAppMenuItem(nsMenuX* inMenu, const nsAString& nodeID, SEL action, michael@0: int tag, NativeMenuItemTarget* target); michael@0: nsresult CreateApplicationMenu(nsMenuX* inMenu); michael@0: michael@0: nsTArray< nsAutoPtr > mMenuArray; michael@0: nsIWidget* mParentWindow; // [weak] michael@0: GeckoNSMenu* mNativeMenu; // root menu, representing entire menu bar michael@0: michael@0: bool mAwaitingDelayedPaint; michael@0: }; michael@0: michael@0: #endif // nsMenuBarX_h_