2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Josh Aas <josh@mozilla.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#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
|
|
|
|
2010-01-22 11:24:00 -08:00
|
|
|
static PRUint32 ConvertGeckoToMacKeyCode(nsAString& aKeyCodeName);
|
|
|
|
|
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_
|