widget/cocoa/nsMenuItemX.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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/. */
     6 #ifndef nsMenuItemX_h_
     7 #define nsMenuItemX_h_
     9 #include "nsMenuBaseX.h"
    10 #include "nsMenuGroupOwnerX.h"
    11 #include "nsChangeObserver.h"
    12 #include "nsAutoPtr.h"
    14 #import <Cocoa/Cocoa.h>
    16 class nsString;
    17 class nsMenuItemIconX;
    18 class nsMenuX;
    20 enum {
    21   knsMenuItemNoModifier      = 0,
    22   knsMenuItemShiftModifier   = (1 << 0),
    23   knsMenuItemAltModifier     = (1 << 1),
    24   knsMenuItemControlModifier = (1 << 2),
    25   knsMenuItemCommandModifier = (1 << 3)
    26 };
    28 enum EMenuItemType {
    29   eRegularMenuItemType = 0,
    30   eCheckboxMenuItemType,
    31   eRadioMenuItemType,
    32   eSeparatorMenuItemType
    33 };
    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();
    45   NS_DECL_CHANGEOBSERVER
    47   // nsMenuObjectX
    48   void*             NativeData()     {return (void*)mNativeMenuItem;}
    49   nsMenuObjectTypeX MenuObjectType() {return eMenuItemObjectType;}
    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();
    60 protected:
    61   void UncheckRadioSiblings(nsIContent* inCheckedElement);
    62   void SetKeyEquiv();
    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 };
    75 #endif // nsMenuItemX_h_

mercurial