|
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/. */ |
|
5 |
|
6 #ifndef nsMenuX_h_ |
|
7 #define nsMenuX_h_ |
|
8 |
|
9 #import <Cocoa/Cocoa.h> |
|
10 |
|
11 #include "nsMenuBaseX.h" |
|
12 #include "nsMenuBarX.h" |
|
13 #include "nsMenuGroupOwnerX.h" |
|
14 #include "nsCOMPtr.h" |
|
15 #include "nsChangeObserver.h" |
|
16 #include "nsAutoPtr.h" |
|
17 |
|
18 class nsMenuX; |
|
19 class nsMenuItemIconX; |
|
20 class nsMenuItemX; |
|
21 class nsIWidget; |
|
22 |
|
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 > |
|
27 #else |
|
28 @interface MenuDelegate : NSObject |
|
29 #endif |
|
30 { |
|
31 nsMenuX* mGeckoMenu; // weak ref |
|
32 } |
|
33 - (id)initWithGeckoMenu:(nsMenuX*)geckoMenu; |
|
34 @end |
|
35 |
|
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 |
|
40 { |
|
41 public: |
|
42 nsMenuX(); |
|
43 virtual ~nsMenuX(); |
|
44 |
|
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; |
|
49 |
|
50 NS_DECL_CHANGEOBSERVER |
|
51 |
|
52 // nsMenuObjectX |
|
53 void* NativeData() {return (void*)mNativeMenu;} |
|
54 nsMenuObjectTypeX MenuObjectType() {return eSubmenuObjectType;} |
|
55 |
|
56 // nsMenuX |
|
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(); |
|
63 void MenuClosed(); |
|
64 void SetRebuild(bool aMenuEvent); |
|
65 NSMenuItem* NativeMenuItem(); |
|
66 |
|
67 static bool IsXULHelpMenu(nsIContent* aMenuContent); |
|
68 |
|
69 protected: |
|
70 void MenuConstruct(); |
|
71 nsresult RemoveAll(); |
|
72 nsresult SetEnabled(bool aIsEnabled); |
|
73 nsresult GetEnabled(bool* aIsEnabled); |
|
74 nsresult SetupIcon(); |
|
75 void GetMenuPopupContent(nsIContent** aResult); |
|
76 bool OnOpen(); |
|
77 bool OnClose(); |
|
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); |
|
83 |
|
84 nsTArray< nsAutoPtr<nsMenuObjectX> > mMenuObjectsArray; |
|
85 nsString mLabel; |
|
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] |
|
95 bool mIsEnabled; |
|
96 bool mDestroyHandlerCalled; |
|
97 bool mNeedsRebuild; |
|
98 bool mConstructed; |
|
99 bool mVisible; |
|
100 bool mXBLAttached; |
|
101 }; |
|
102 |
|
103 #endif // nsMenuX_h_ |