1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/widget/cocoa/nsMenuItemX.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,75 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef nsMenuItemX_h_ 1.10 +#define nsMenuItemX_h_ 1.11 + 1.12 +#include "nsMenuBaseX.h" 1.13 +#include "nsMenuGroupOwnerX.h" 1.14 +#include "nsChangeObserver.h" 1.15 +#include "nsAutoPtr.h" 1.16 + 1.17 +#import <Cocoa/Cocoa.h> 1.18 + 1.19 +class nsString; 1.20 +class nsMenuItemIconX; 1.21 +class nsMenuX; 1.22 + 1.23 +enum { 1.24 + knsMenuItemNoModifier = 0, 1.25 + knsMenuItemShiftModifier = (1 << 0), 1.26 + knsMenuItemAltModifier = (1 << 1), 1.27 + knsMenuItemControlModifier = (1 << 2), 1.28 + knsMenuItemCommandModifier = (1 << 3) 1.29 +}; 1.30 + 1.31 +enum EMenuItemType { 1.32 + eRegularMenuItemType = 0, 1.33 + eCheckboxMenuItemType, 1.34 + eRadioMenuItemType, 1.35 + eSeparatorMenuItemType 1.36 +}; 1.37 + 1.38 + 1.39 +// Once instantiated, this object lives until its DOM node or its parent window is destroyed. 1.40 +// Do not hold references to this, they can become invalid any time the DOM node can be destroyed. 1.41 +class nsMenuItemX : public nsMenuObjectX, 1.42 + public nsChangeObserver 1.43 +{ 1.44 +public: 1.45 + nsMenuItemX(); 1.46 + virtual ~nsMenuItemX(); 1.47 + 1.48 + NS_DECL_CHANGEOBSERVER 1.49 + 1.50 + // nsMenuObjectX 1.51 + void* NativeData() {return (void*)mNativeMenuItem;} 1.52 + nsMenuObjectTypeX MenuObjectType() {return eMenuItemObjectType;} 1.53 + 1.54 + // nsMenuItemX 1.55 + nsresult Create(nsMenuX* aParent, const nsString& aLabel, EMenuItemType aItemType, 1.56 + nsMenuGroupOwnerX* aMenuGroupOwner, nsIContent* aNode); 1.57 + nsresult SetChecked(bool aIsChecked); 1.58 + EMenuItemType GetMenuItemType(); 1.59 + void DoCommand(); 1.60 + nsresult DispatchDOMEvent(const nsString &eventName, bool* preventDefaultCalled); 1.61 + void SetupIcon(); 1.62 + 1.63 +protected: 1.64 + void UncheckRadioSiblings(nsIContent* inCheckedElement); 1.65 + void SetKeyEquiv(); 1.66 + 1.67 + EMenuItemType mType; 1.68 + // nsMenuItemX objects should always have a valid native menu item. 1.69 + NSMenuItem* mNativeMenuItem; // [strong] 1.70 + nsMenuX* mMenuParent; // [weak] 1.71 + nsMenuGroupOwnerX* mMenuGroupOwner; // [weak] 1.72 + nsCOMPtr<nsIContent> mCommandContent; 1.73 + // The icon object should never outlive its creating nsMenuItemX object. 1.74 + nsRefPtr<nsMenuItemIconX> mIcon; 1.75 + bool mIsChecked; 1.76 +}; 1.77 + 1.78 +#endif // nsMenuItemX_h_