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 nsMenuItemX_h_ michael@0: #define nsMenuItemX_h_ michael@0: michael@0: #include "nsMenuBaseX.h" michael@0: #include "nsMenuGroupOwnerX.h" michael@0: #include "nsChangeObserver.h" michael@0: #include "nsAutoPtr.h" michael@0: michael@0: #import michael@0: michael@0: class nsString; michael@0: class nsMenuItemIconX; michael@0: class nsMenuX; michael@0: michael@0: enum { michael@0: knsMenuItemNoModifier = 0, michael@0: knsMenuItemShiftModifier = (1 << 0), michael@0: knsMenuItemAltModifier = (1 << 1), michael@0: knsMenuItemControlModifier = (1 << 2), michael@0: knsMenuItemCommandModifier = (1 << 3) michael@0: }; michael@0: michael@0: enum EMenuItemType { michael@0: eRegularMenuItemType = 0, michael@0: eCheckboxMenuItemType, michael@0: eRadioMenuItemType, michael@0: eSeparatorMenuItemType michael@0: }; michael@0: 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 nsMenuItemX : public nsMenuObjectX, michael@0: public nsChangeObserver michael@0: { michael@0: public: michael@0: nsMenuItemX(); michael@0: virtual ~nsMenuItemX(); michael@0: michael@0: NS_DECL_CHANGEOBSERVER michael@0: michael@0: // nsMenuObjectX michael@0: void* NativeData() {return (void*)mNativeMenuItem;} michael@0: nsMenuObjectTypeX MenuObjectType() {return eMenuItemObjectType;} michael@0: michael@0: // nsMenuItemX michael@0: nsresult Create(nsMenuX* aParent, const nsString& aLabel, EMenuItemType aItemType, michael@0: nsMenuGroupOwnerX* aMenuGroupOwner, nsIContent* aNode); michael@0: nsresult SetChecked(bool aIsChecked); michael@0: EMenuItemType GetMenuItemType(); michael@0: void DoCommand(); michael@0: nsresult DispatchDOMEvent(const nsString &eventName, bool* preventDefaultCalled); michael@0: void SetupIcon(); michael@0: michael@0: protected: michael@0: void UncheckRadioSiblings(nsIContent* inCheckedElement); michael@0: void SetKeyEquiv(); michael@0: michael@0: EMenuItemType mType; michael@0: // nsMenuItemX objects should always have a valid native menu item. michael@0: NSMenuItem* mNativeMenuItem; // [strong] michael@0: nsMenuX* mMenuParent; // [weak] michael@0: nsMenuGroupOwnerX* mMenuGroupOwner; // [weak] michael@0: nsCOMPtr mCommandContent; michael@0: // The icon object should never outlive its creating nsMenuItemX object. michael@0: nsRefPtr mIcon; michael@0: bool mIsChecked; michael@0: }; michael@0: michael@0: #endif // nsMenuItemX_h_