Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / CompMod / System / ComponentModel / Design / MenuCommand.cs / 1 / MenuCommand.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
/*
*/
namespace System.ComponentModel.Design {
using Microsoft.Win32;
using System;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics;
using System.Security.Permissions;
///
///
/// Represents a Windows
/// menu or toolbar item.
///
///
[HostProtection(SharedState = true)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.InheritanceDemand, Name="FullTrust")]
[System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.LinkDemand, Name="FullTrust")]
public class MenuCommand {
// Events that we suface or call on
//
private EventHandler execHandler;
private EventHandler statusHandler;
private CommandID commandID;
private int status;
private IDictionary properties;
///
/// Indicates that the given command is enabled. An enabled command may
/// be selected by the user (it's not greyed out).
///
private const int ENABLED = 0x02; //tagOLECMDF.OLECMDF_ENABLED;
///
/// Indicates that the given command is not visible on the command bar.
///
private const int INVISIBLE = 0x10;
///
/// Indicates that the given command is checked in the "on" state.
///
private const int CHECKED = 0x04; // tagOLECMDF.OLECMDF_LATCHED;
///
/// Indicates that the given command is supported. Marking a command
/// as supported indicates that the shell will not look any further up
/// the command target chain.
///
private const int SUPPORTED = 0x01; // tagOLECMDF.OLECMDF_SUPPORTED
///
///
/// Initializes a new instance of .
///
///
public MenuCommand(EventHandler handler, CommandID command) {
this.execHandler = handler;
this.commandID = command;
this.status = SUPPORTED | ENABLED;
}
///
/// Gets or sets a value indicating whether this menu item is checked.
///
public virtual bool Checked {
get {
return (status & CHECKED) != 0;
}
set {
SetStatus(CHECKED, value);
}
}
///
/// Gets or
/// sets a value indicating whether this menu item is available.
///
public virtual bool Enabled {
get{
return (status & ENABLED) != 0;
}
set {
SetStatus(ENABLED, value);
}
}
private void SetStatus(int mask, bool value){
int newStatus = status;
if (value) {
newStatus |= mask;
}
else {
newStatus &= ~mask;
}
if (newStatus != status) {
status = newStatus;
OnCommandChanged(EventArgs.Empty);
}
}
///
///
public virtual IDictionary Properties
{
get {
if (properties == null) {
properties = new HybridDictionary();
}
return properties;
}
}
///
/// Gets or sets a value
/// indicating whether this menu item is supported.
///
public virtual bool Supported {
get{
return (status & SUPPORTED) != 0;
}
set{
SetStatus(SUPPORTED, value);
}
}
///
/// Gets or sets a value
/// indicating if this menu item is visible.
///
public virtual bool Visible {
get {
return (status & INVISIBLE) == 0;
}
set {
SetStatus(INVISIBLE, !value);
}
}
///
///
/// Occurs when the menu command changes.
///
///
public event EventHandler CommandChanged {
add {
statusHandler += value;
}
remove {
statusHandler -= value;
}
}
///
/// Gets the associated with this menu command.
///
public virtual CommandID CommandID {
get {
return commandID;
}
}
///
///
/// Invokes a menu item.
///
///
public virtual void Invoke() {
if (execHandler != null){
try {
execHandler(this, EventArgs.Empty);
}
catch (CheckoutException cxe) {
if (cxe == CheckoutException.Canceled)
return;
throw;
}
}
}
///
///
/// Invokes a menu item. The default implementation of this method ignores
/// the argument, but deriving classes may override this method.
///
///
public virtual void Invoke(object arg) {
Invoke();
}
///
///
/// Gets the OLE command status code for this menu item.
///
///
public virtual int OleStatus {
get {
return status;
}
}
///
/// Provides notification and is called in response to
/// a event.
///
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2109:ReviewVisibleEventHandlers")] // Safe: FullTrust LinkDemand to instantiate an object of this class.
protected virtual void OnCommandChanged(EventArgs e) {
if (statusHandler != null) {
statusHandler(this, e);
}
}
///
/// Overrides object's ToString().
///
public override string ToString() {
string str = commandID.ToString() + " : ";
if ((status & SUPPORTED) != 0) {
str += "Supported";
}
if ((status & ENABLED) != 0) {
str += "|Enabled";
}
if ((status & INVISIBLE) == 0) {
str += "|Visible";
}
if ((status & CHECKED) != 0) {
str += "|Checked";
}
return str;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
/*
*/
namespace System.ComponentModel.Design {
using Microsoft.Win32;
using System;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics;
using System.Security.Permissions;
///
///
/// Represents a Windows
/// menu or toolbar item.
///
///
[HostProtection(SharedState = true)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.InheritanceDemand, Name="FullTrust")]
[System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.LinkDemand, Name="FullTrust")]
public class MenuCommand {
// Events that we suface or call on
//
private EventHandler execHandler;
private EventHandler statusHandler;
private CommandID commandID;
private int status;
private IDictionary properties;
///
/// Indicates that the given command is enabled. An enabled command may
/// be selected by the user (it's not greyed out).
///
private const int ENABLED = 0x02; //tagOLECMDF.OLECMDF_ENABLED;
///
/// Indicates that the given command is not visible on the command bar.
///
private const int INVISIBLE = 0x10;
///
/// Indicates that the given command is checked in the "on" state.
///
private const int CHECKED = 0x04; // tagOLECMDF.OLECMDF_LATCHED;
///
/// Indicates that the given command is supported. Marking a command
/// as supported indicates that the shell will not look any further up
/// the command target chain.
///
private const int SUPPORTED = 0x01; // tagOLECMDF.OLECMDF_SUPPORTED
///
///
/// Initializes a new instance of .
///
///
public MenuCommand(EventHandler handler, CommandID command) {
this.execHandler = handler;
this.commandID = command;
this.status = SUPPORTED | ENABLED;
}
///
/// Gets or sets a value indicating whether this menu item is checked.
///
public virtual bool Checked {
get {
return (status & CHECKED) != 0;
}
set {
SetStatus(CHECKED, value);
}
}
///
/// Gets or
/// sets a value indicating whether this menu item is available.
///
public virtual bool Enabled {
get{
return (status & ENABLED) != 0;
}
set {
SetStatus(ENABLED, value);
}
}
private void SetStatus(int mask, bool value){
int newStatus = status;
if (value) {
newStatus |= mask;
}
else {
newStatus &= ~mask;
}
if (newStatus != status) {
status = newStatus;
OnCommandChanged(EventArgs.Empty);
}
}
///
///
public virtual IDictionary Properties
{
get {
if (properties == null) {
properties = new HybridDictionary();
}
return properties;
}
}
///
/// Gets or sets a value
/// indicating whether this menu item is supported.
///
public virtual bool Supported {
get{
return (status & SUPPORTED) != 0;
}
set{
SetStatus(SUPPORTED, value);
}
}
///
/// Gets or sets a value
/// indicating if this menu item is visible.
///
public virtual bool Visible {
get {
return (status & INVISIBLE) == 0;
}
set {
SetStatus(INVISIBLE, !value);
}
}
///
///
/// Occurs when the menu command changes.
///
///
public event EventHandler CommandChanged {
add {
statusHandler += value;
}
remove {
statusHandler -= value;
}
}
///
/// Gets the associated with this menu command.
///
public virtual CommandID CommandID {
get {
return commandID;
}
}
///
///
/// Invokes a menu item.
///
///
public virtual void Invoke() {
if (execHandler != null){
try {
execHandler(this, EventArgs.Empty);
}
catch (CheckoutException cxe) {
if (cxe == CheckoutException.Canceled)
return;
throw;
}
}
}
///
///
/// Invokes a menu item. The default implementation of this method ignores
/// the argument, but deriving classes may override this method.
///
///
public virtual void Invoke(object arg) {
Invoke();
}
///
///
/// Gets the OLE command status code for this menu item.
///
///
public virtual int OleStatus {
get {
return status;
}
}
///
/// Provides notification and is called in response to
/// a event.
///
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2109:ReviewVisibleEventHandlers")] // Safe: FullTrust LinkDemand to instantiate an object of this class.
protected virtual void OnCommandChanged(EventArgs e) {
if (statusHandler != null) {
statusHandler(this, e);
}
}
///
/// Overrides object's ToString().
///
public override string ToString() {
string str = commandID.ToString() + " : ";
if ((status & SUPPORTED) != 0) {
str += "Supported";
}
if ((status & ENABLED) != 0) {
str += "|Enabled";
}
if ((status & INVISIBLE) == 0) {
str += "|Visible";
}
if ((status & CHECKED) != 0) {
str += "|Checked";
}
return str;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- IndexedSelectQueryOperator.cs
- Condition.cs
- ScalarConstant.cs
- FontUnit.cs
- StandardBindingOptionalReliableSessionElement.cs
- RequiredFieldValidator.cs
- RoleManagerModule.cs
- DataPagerField.cs
- CachedRequestParams.cs
- ConnectionStringSettingsCollection.cs
- PerformanceCounterCategory.cs
- HostingEnvironmentWrapper.cs
- WorkflowOperationFault.cs
- OdbcConnectionOpen.cs
- DataGridHelper.cs
- DrawListViewColumnHeaderEventArgs.cs
- XmlObjectSerializerReadContext.cs
- TextBoxDesigner.cs
- XPathParser.cs
- HScrollBar.cs
- DataGridViewColumnDesigner.cs
- Point.cs
- EntryPointNotFoundException.cs
- ReaderWriterLock.cs
- XmlFormatMapping.cs
- CompiledAction.cs
- EditorZone.cs
- FieldAccessException.cs
- DbParameterCollectionHelper.cs
- MarshalByValueComponent.cs
- FileAuthorizationModule.cs
- KernelTypeValidation.cs
- WebPartConnectionsEventArgs.cs
- DataGridViewSelectedCellsAccessibleObject.cs
- RpcAsyncResult.cs
- MultiBinding.cs
- EventLogPermissionEntry.cs
- InlineCollection.cs
- DurableInstanceProvider.cs
- RuntimeArgumentHandle.cs
- TypeDescriptionProviderAttribute.cs
- StringValidatorAttribute.cs
- SiteOfOriginPart.cs
- DataGridViewElement.cs
- TextRunTypographyProperties.cs
- XmlHierarchicalDataSourceView.cs
- WindowsListViewGroup.cs
- RegexTree.cs
- AuthenticationModuleElement.cs
- NumericPagerField.cs
- NamespaceCollection.cs
- OracleParameter.cs
- WebServiceEnumData.cs
- DefaultTextStore.cs
- Root.cs
- WindowsEditBoxRange.cs
- VoiceObjectToken.cs
- ParameterBuilder.cs
- TypeDescriptorContext.cs
- BatchWriter.cs
- BaseDataListActionList.cs
- securitycriticaldata.cs
- GregorianCalendarHelper.cs
- Math.cs
- ClientFormsAuthenticationCredentials.cs
- ReceiveCompletedEventArgs.cs
- RequestUriProcessor.cs
- ExtractCollection.cs
- CodeGotoStatement.cs
- EncryptedKeyHashIdentifierClause.cs
- SchemaManager.cs
- PolicyLevel.cs
- SqlConnectionString.cs
- SiteMapNodeCollection.cs
- DropShadowEffect.cs
- ValueTypeIndexerReference.cs
- ProgressBar.cs
- XmlUtf8RawTextWriter.cs
- Pen.cs
- ProviderSettings.cs
- ImageBrush.cs
- WSSecureConversationDec2005.cs
- ProfessionalColorTable.cs
- CodeSnippetCompileUnit.cs
- DurableInstanceProvider.cs
- PlainXmlSerializer.cs
- ContentIterators.cs
- EntityProviderServices.cs
- TextElementEnumerator.cs
- WebPartConnection.cs
- ExtensibleClassFactory.cs
- WSUtilitySpecificationVersion.cs
- OdbcErrorCollection.cs
- DragStartedEventArgs.cs
- ResourcesBuildProvider.cs
- SqlReferenceCollection.cs
- FontFaceLayoutInfo.cs
- CompletionCallbackWrapper.cs
- AppDomainUnloadedException.cs
- MbpInfo.cs