1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
9 #import <Cocoa/Cocoa.h>
11 #include "nsMenuBaseX.h"
12 #include "nsMenuBarX.h"
13 #include "nsMenuGroupOwnerX.h"
15 #include "nsChangeObserver.h"
16 #include "nsAutoPtr.h"
19 class nsMenuItemIconX
;
23 // MenuDelegate is used to receive Cocoa notifications for setting
24 // up carbon events. Protocol is defined as of 10.6 SDK.
25 #if defined(MAC_OS_X_VERSION_10_6) && (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6)
26 @interface MenuDelegate
: NSObject
< NSMenuDelegate
>
28 @interface MenuDelegate
: NSObject
31 nsMenuX
* mGeckoMenu
; // weak ref
33 - (id
)initWithGeckoMenu
:(nsMenuX
*)geckoMenu
;
36 // Once instantiated, this object lives until its DOM node or its parent window is destroyed.
37 // Do not hold references to this, they can become invalid any time the DOM node can be destroyed.
38 class nsMenuX
: public nsMenuObjectX
,
39 public nsChangeObserver
45 // If > 0, the OS is indexing all the app's menus (triggered by opening
46 // Help menu on Leopard and higher). There are some things that are
47 // unsafe to do while this is happening.
48 static int32_t sIndexingMenuLevel
;
50 NS_DECL_CHANGEOBSERVER
53 void* NativeData() {return (void*)mNativeMenu
;}
54 nsMenuObjectTypeX
MenuObjectType() {return eSubmenuObjectType
;}
57 nsresult
Create(nsMenuObjectX
* aParent
, nsMenuGroupOwnerX
* aMenuGroupOwner
, nsIContent
* aNode
);
58 uint32_t GetItemCount();
59 nsMenuObjectX
* GetItemAt(uint32_t aPos
);
60 nsresult
GetVisibleItemCount(uint32_t &aCount
);
61 nsMenuObjectX
* GetVisibleItemAt(uint32_t aPos
);
62 nsEventStatus
MenuOpened();
64 void SetRebuild(bool aMenuEvent
);
65 NSMenuItem
* NativeMenuItem();
67 static bool IsXULHelpMenu(nsIContent
* aMenuContent
);
72 nsresult
SetEnabled(bool aIsEnabled
);
73 nsresult
GetEnabled(bool* aIsEnabled
);
75 void GetMenuPopupContent(nsIContent
** aResult
);
78 nsresult
AddMenuItem(nsMenuItemX
* aMenuItem
);
79 nsresult
AddMenu(nsMenuX
* aMenu
);
80 void LoadMenuItem(nsIContent
* inMenuItemContent
);
81 void LoadSubMenu(nsIContent
* inMenuContent
);
82 GeckoNSMenu
* CreateMenuWithGeckoString(nsString
& menuTitle
);
84 nsTArray
< nsAutoPtr
<nsMenuObjectX
> > mMenuObjectsArray
;
86 uint32_t mVisibleItemsCount
; // cache
87 nsMenuObjectX
* mParent
; // [weak]
88 nsMenuGroupOwnerX
* mMenuGroupOwner
; // [weak]
89 // The icon object should never outlive its creating nsMenuX object.
90 nsRefPtr
<nsMenuItemIconX
> mIcon
;
91 GeckoNSMenu
* mNativeMenu
; // [strong]
92 MenuDelegate
* mMenuDelegate
; // [strong]
93 // nsMenuX objects should always have a valid native menu item.
94 NSMenuItem
* mNativeMenuItem
; // [strong]
96 bool mDestroyHandlerCalled
;