Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / CompMod / System / ComponentModel / Design / MenuCommand.cs / 1305376 / 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; ////// [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; ////// Represents a Windows /// menu or toolbar item. /// ////// 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 ////// public MenuCommand(EventHandler handler, CommandID command) { this.execHandler = handler; this.commandID = command; this.status = SUPPORTED | ENABLED; } ////// Initializes a new instance of ///. /// /// public virtual bool Checked { get { return (status & CHECKED) != 0; } set { SetStatus(CHECKED, value); } } ///Gets or sets a value indicating whether this menu item is checked. ////// 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); } } ///Gets or /// sets a value indicating whether this menu item is available. ////// public virtual IDictionary Properties { get { if (properties == null) { properties = new HybridDictionary(); } return properties; } } ////// public virtual bool Supported { get{ return (status & SUPPORTED) != 0; } set{ SetStatus(SUPPORTED, value); } } ///Gets or sets a value /// indicating whether this menu item is supported. ////// public virtual bool Visible { get { return (status & INVISIBLE) == 0; } set { SetStatus(INVISIBLE, !value); } } ///Gets or sets a value /// indicating if this menu item is visible. ////// public event EventHandler CommandChanged { add { statusHandler += value; } remove { statusHandler -= value; } } ////// Occurs when the menu command changes. /// ////// public virtual CommandID CommandID { get { return commandID; } } ///Gets the ///associated with this menu command. /// 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. /// ////// public virtual void Invoke(object arg) { Invoke(); } ////// Invokes a menu item. The default implementation of this method ignores /// the argument, but deriving classes may override this method. /// ////// public virtual int OleStatus { get { return status; } } ////// Gets the OLE command status code for this menu item. /// ////// [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); } } ///Provides notification and is called in response to /// a ///event. /// 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
- DataControlHelper.cs
- CustomWebEventKey.cs
- PropertySourceInfo.cs
- TextDecorationCollectionConverter.cs
- ComponentManagerBroker.cs
- ThreadExceptionDialog.cs
- CharAnimationUsingKeyFrames.cs
- Cloud.cs
- ConnectionPointCookie.cs
- DataMemberAttribute.cs
- BitmapFrameEncode.cs
- HtmlInputReset.cs
- LayoutSettings.cs
- OleAutBinder.cs
- SpecialNameAttribute.cs
- TextEditorSelection.cs
- TextBox.cs
- AnnotationMap.cs
- ToolStripDropDown.cs
- GlobalizationAssembly.cs
- TransportBindingElement.cs
- TranslateTransform3D.cs
- ControlBuilderAttribute.cs
- StateMachineSubscriptionManager.cs
- DesignTimeTemplateParser.cs
- ReadOnlyDictionary.cs
- CharacterString.cs
- TextBoxBase.cs
- PageWrapper.cs
- HierarchicalDataSourceIDConverter.cs
- FloaterBaseParagraph.cs
- TextCompositionManager.cs
- KeyInstance.cs
- Propagator.JoinPropagator.cs
- NamedObject.cs
- StickyNoteHelper.cs
- DataKey.cs
- Logging.cs
- ScriptServiceAttribute.cs
- TextWriterEngine.cs
- C14NUtil.cs
- SurrogateSelector.cs
- Bitmap.cs
- SchemaImporterExtensionElementCollection.cs
- RichTextBoxConstants.cs
- SourceChangedEventArgs.cs
- TableColumn.cs
- ServiceEndpoint.cs
- ObservableCollectionDefaultValueFactory.cs
- GeometryDrawing.cs
- EventEntry.cs
- RoleManagerEventArgs.cs
- Header.cs
- _SafeNetHandles.cs
- SerTrace.cs
- ConditionalBranch.cs
- FormViewRow.cs
- SecureConversationSecurityTokenParameters.cs
- JournalNavigationScope.cs
- KnownTypesProvider.cs
- Variant.cs
- FixedDocument.cs
- StateMachineExecutionState.cs
- CTreeGenerator.cs
- WebPartCancelEventArgs.cs
- HighlightVisual.cs
- XPathParser.cs
- BitmapScalingModeValidation.cs
- _RequestCacheProtocol.cs
- BitArray.cs
- ConnectivityStatus.cs
- XsltException.cs
- ListBindableAttribute.cs
- MsmqHostedTransportConfiguration.cs
- Parser.cs
- ContextDataSource.cs
- MediaSystem.cs
- ComContractElementCollection.cs
- AssertSection.cs
- ViewEventArgs.cs
- ComponentEditorForm.cs
- RoleGroup.cs
- WindowsTitleBar.cs
- WorkflowTransactionOptions.cs
- CookieParameter.cs
- VScrollProperties.cs
- SqlConnectionStringBuilder.cs
- ChangeBlockUndoRecord.cs
- ControlBuilderAttribute.cs
- MessageQueueException.cs
- BooleanToSelectiveScrollingOrientationConverter.cs
- NavigatingCancelEventArgs.cs
- Message.cs
- DataControlFieldCell.cs
- Closure.cs
- PrinterUnitConvert.cs
- SecureEnvironment.cs
- FlowDocumentScrollViewerAutomationPeer.cs
- _FtpDataStream.cs
- IFlowDocumentViewer.cs