CLOSED TREE: TraceMonkey merge head. (a=blockers)
[mozilla-central.git] / widget / src / cocoa / nsMenuX.h
blobb0df43026f02ed3d36f924b41a18bbcaf7ed84ea
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Josh Aas <josh@mozilla.com>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #ifndef nsMenuX_h_
40 #define nsMenuX_h_
42 #import <Cocoa/Cocoa.h>
44 #include "nsMenuBaseX.h"
45 #include "nsMenuBarX.h"
46 #include "nsMenuGroupOwnerX.h"
47 #include "nsCOMPtr.h"
48 #include "nsChangeObserver.h"
49 #include "nsAutoPtr.h"
51 class nsMenuX;
52 class nsMenuItemIconX;
53 class nsMenuItemX;
54 class nsIWidget;
56 // MenuDelegate is used to receive Cocoa notifications for setting
57 // up carbon events. Protocol is defined as of 10.6 SDK.
58 #if defined(MAC_OS_X_VERSION_10_6) && (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6)
59 @interface MenuDelegate : NSObject < NSMenuDelegate >
60 #else
61 @interface MenuDelegate : NSObject
62 #endif
64 nsMenuX* mGeckoMenu; // weak ref
66 - (id)initWithGeckoMenu:(nsMenuX*)geckoMenu;
67 @end
69 // Once instantiated, this object lives until its DOM node or its parent window is destroyed.
70 // Do not hold references to this, they can become invalid any time the DOM node can be destroyed.
71 class nsMenuX : public nsMenuObjectX,
72 public nsChangeObserver
74 public:
75 nsMenuX();
76 virtual ~nsMenuX();
78 // If > 0, the OS is indexing all the app's menus (triggered by opening
79 // Help menu on Leopard and higher). There are some things that are
80 // unsafe to do while this is happening.
81 static PRInt32 sIndexingMenuLevel;
83 NS_DECL_CHANGEOBSERVER
85 // nsMenuObjectX
86 void* NativeData() {return (void*)mNativeMenu;}
87 nsMenuObjectTypeX MenuObjectType() {return eSubmenuObjectType;}
89 // nsMenuX
90 nsresult Create(nsMenuObjectX* aParent, nsMenuGroupOwnerX* aMenuGroupOwner, nsIContent* aNode);
91 PRUint32 GetItemCount();
92 nsMenuObjectX* GetItemAt(PRUint32 aPos);
93 nsresult GetVisibleItemCount(PRUint32 &aCount);
94 nsMenuObjectX* GetVisibleItemAt(PRUint32 aPos);
95 nsEventStatus MenuOpened();
96 void MenuClosed();
97 void SetRebuild(PRBool aMenuEvent);
98 NSMenuItem* NativeMenuItem();
100 static PRBool IsXULHelpMenu(nsIContent* aMenuContent);
102 protected:
103 void MenuConstruct();
104 nsresult RemoveAll();
105 nsresult SetEnabled(PRBool aIsEnabled);
106 nsresult GetEnabled(PRBool* aIsEnabled);
107 nsresult SetupIcon();
108 void GetMenuPopupContent(nsIContent** aResult);
109 PRBool OnOpen();
110 PRBool OnClose();
111 nsresult AddMenuItem(nsMenuItemX* aMenuItem);
112 nsresult AddMenu(nsMenuX* aMenu);
113 void LoadMenuItem(nsIContent* inMenuItemContent);
114 void LoadSubMenu(nsIContent* inMenuContent);
115 GeckoNSMenu* CreateMenuWithGeckoString(nsString& menuTitle);
117 nsTArray< nsAutoPtr<nsMenuObjectX> > mMenuObjectsArray;
118 nsString mLabel;
119 PRUint32 mVisibleItemsCount; // cache
120 nsMenuObjectX* mParent; // [weak]
121 nsMenuGroupOwnerX* mMenuGroupOwner; // [weak]
122 // The icon object should never outlive its creating nsMenuX object.
123 nsRefPtr<nsMenuItemIconX> mIcon;
124 GeckoNSMenu* mNativeMenu; // [strong]
125 MenuDelegate* mMenuDelegate; // [strong]
126 // nsMenuX objects should always have a valid native menu item.
127 NSMenuItem* mNativeMenuItem; // [strong]
128 PRPackedBool mIsEnabled;
129 PRPackedBool mDestroyHandlerCalled;
130 PRPackedBool mNeedsRebuild;
131 PRPackedBool mConstructed;
132 PRPackedBool mVisible;
133 PRPackedBool mXBLAttached;
136 #endif // nsMenuX_h_