2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifndef nsMenuItemX_h_
|
|
|
|
#define nsMenuItemX_h_
|
|
|
|
|
2008-06-28 00:55:30 -07:00
|
|
|
#include "nsMenuBaseX.h"
|
2010-01-26 22:14:40 -08:00
|
|
|
#include "nsMenuGroupOwnerX.h"
|
2008-01-22 20:04:15 -08:00
|
|
|
#include "nsChangeObserver.h"
|
2007-04-21 18:42:17 -07:00
|
|
|
#include "nsAutoPtr.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#import <Cocoa/Cocoa.h>
|
|
|
|
|
2008-06-28 00:55:30 -07:00
|
|
|
class nsString;
|
2007-04-21 18:42:17 -07:00
|
|
|
class nsMenuItemIconX;
|
2008-06-28 00:55:30 -07:00
|
|
|
class nsMenuX;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-06-28 00:55:30 -07:00
|
|
|
enum {
|
|
|
|
knsMenuItemNoModifier = 0,
|
|
|
|
knsMenuItemShiftModifier = (1 << 0),
|
|
|
|
knsMenuItemAltModifier = (1 << 1),
|
|
|
|
knsMenuItemControlModifier = (1 << 2),
|
|
|
|
knsMenuItemCommandModifier = (1 << 3)
|
|
|
|
};
|
|
|
|
|
|
|
|
enum EMenuItemType {
|
|
|
|
eRegularMenuItemType = 0,
|
|
|
|
eCheckboxMenuItemType,
|
|
|
|
eRadioMenuItemType,
|
|
|
|
eSeparatorMenuItemType
|
|
|
|
};
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-06-28 00:55:30 -07:00
|
|
|
|
|
|
|
// Once instantiated, this object lives until its DOM node or its parent window is destroyed.
|
|
|
|
// Do not hold references to this, they can become invalid any time the DOM node can be destroyed.
|
|
|
|
class nsMenuItemX : public nsMenuObjectX,
|
2008-01-22 20:04:15 -08:00
|
|
|
public nsChangeObserver
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsMenuItemX();
|
|
|
|
virtual ~nsMenuItemX();
|
|
|
|
|
2008-01-22 20:04:15 -08:00
|
|
|
NS_DECL_CHANGEOBSERVER
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-06-28 00:55:30 -07:00
|
|
|
// nsMenuObjectX
|
|
|
|
void* NativeData() {return (void*)mNativeMenuItem;}
|
|
|
|
nsMenuObjectTypeX MenuObjectType() {return eMenuItemObjectType;}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-06-28 00:55:30 -07:00
|
|
|
// nsMenuItemX
|
|
|
|
nsresult Create(nsMenuX* aParent, const nsString& aLabel, EMenuItemType aItemType,
|
2010-01-26 22:14:40 -08:00
|
|
|
nsMenuGroupOwnerX* aMenuGroupOwner, nsIContent* aNode);
|
2011-09-28 23:19:26 -07:00
|
|
|
nsresult SetChecked(bool aIsChecked);
|
2008-06-28 00:55:30 -07:00
|
|
|
EMenuItemType GetMenuItemType();
|
|
|
|
void DoCommand();
|
2011-09-28 23:19:26 -07:00
|
|
|
nsresult DispatchDOMEvent(const nsString &eventName, bool* preventDefaultCalled);
|
2008-06-28 00:55:30 -07:00
|
|
|
void SetupIcon();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static uint32_t ConvertGeckoToMacKeyCode(nsAString& aKeyCodeName);
|
2010-01-22 11:24:00 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
protected:
|
2007-08-31 01:08:03 -07:00
|
|
|
void UncheckRadioSiblings(nsIContent* inCheckedElement);
|
2011-02-13 04:28:00 -08:00
|
|
|
void SetKeyEquiv();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-06-28 00:55:30 -07:00
|
|
|
EMenuItemType mType;
|
2009-02-20 13:55:25 -08:00
|
|
|
// nsMenuItemX objects should always have a valid native menu item.
|
2008-06-28 00:55:30 -07:00
|
|
|
NSMenuItem* mNativeMenuItem; // [strong]
|
|
|
|
nsMenuX* mMenuParent; // [weak]
|
2010-01-26 22:14:40 -08:00
|
|
|
nsMenuGroupOwnerX* mMenuGroupOwner; // [weak]
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIContent> mCommandContent;
|
2009-02-20 13:55:25 -08:00
|
|
|
// The icon object should never outlive its creating nsMenuItemX object.
|
2007-04-21 18:42:17 -07:00
|
|
|
nsRefPtr<nsMenuItemIconX> mIcon;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mIsChecked;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsMenuItemX_h_
|