widget/cocoa/nsMenuItemX.h

changeset 2
7e26c7da4463
equal deleted inserted replaced
-1:000000000000 0:e5853cc1e1f0
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 nsMenuItemX_h_
7 #define nsMenuItemX_h_
8
9 #include "nsMenuBaseX.h"
10 #include "nsMenuGroupOwnerX.h"
11 #include "nsChangeObserver.h"
12 #include "nsAutoPtr.h"
13
14 #import <Cocoa/Cocoa.h>
15
16 class nsString;
17 class nsMenuItemIconX;
18 class nsMenuX;
19
20 enum {
21 knsMenuItemNoModifier = 0,
22 knsMenuItemShiftModifier = (1 << 0),
23 knsMenuItemAltModifier = (1 << 1),
24 knsMenuItemControlModifier = (1 << 2),
25 knsMenuItemCommandModifier = (1 << 3)
26 };
27
28 enum EMenuItemType {
29 eRegularMenuItemType = 0,
30 eCheckboxMenuItemType,
31 eRadioMenuItemType,
32 eSeparatorMenuItemType
33 };
34
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 nsMenuItemX : public nsMenuObjectX,
39 public nsChangeObserver
40 {
41 public:
42 nsMenuItemX();
43 virtual ~nsMenuItemX();
44
45 NS_DECL_CHANGEOBSERVER
46
47 // nsMenuObjectX
48 void* NativeData() {return (void*)mNativeMenuItem;}
49 nsMenuObjectTypeX MenuObjectType() {return eMenuItemObjectType;}
50
51 // nsMenuItemX
52 nsresult Create(nsMenuX* aParent, const nsString& aLabel, EMenuItemType aItemType,
53 nsMenuGroupOwnerX* aMenuGroupOwner, nsIContent* aNode);
54 nsresult SetChecked(bool aIsChecked);
55 EMenuItemType GetMenuItemType();
56 void DoCommand();
57 nsresult DispatchDOMEvent(const nsString &eventName, bool* preventDefaultCalled);
58 void SetupIcon();
59
60 protected:
61 void UncheckRadioSiblings(nsIContent* inCheckedElement);
62 void SetKeyEquiv();
63
64 EMenuItemType mType;
65 // nsMenuItemX objects should always have a valid native menu item.
66 NSMenuItem* mNativeMenuItem; // [strong]
67 nsMenuX* mMenuParent; // [weak]
68 nsMenuGroupOwnerX* mMenuGroupOwner; // [weak]
69 nsCOMPtr<nsIContent> mCommandContent;
70 // The icon object should never outlive its creating nsMenuItemX object.
71 nsRefPtr<nsMenuItemIconX> mIcon;
72 bool mIsChecked;
73 };
74
75 #endif // nsMenuItemX_h_

mercurial