Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / WinForms / System / WinForms / Design / Behavior / designeractionbehavior.cs / 1 / designeractionbehavior.cs
namespace System.Windows.Forms.Design.Behavior { using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.Design; using System.Design; using System.Diagnostics; using System.Drawing; using System.Windows.Forms.Design; using System.Diagnostics.CodeAnalysis; ////// /// This is the Behavior that represents DesignerActions for a particular /// control. The DesignerActionBehavior is responsible for responding to the /// MouseDown message and either 1) selecting the control and changing the /// DesignerActionGlyph's image or 2) building up a chrome menu /// and requesting it to be shown. /// Also, this Behavior acts as a proxy between "clicked" context menu /// items and the actual DesignerActions that they represent. /// internal sealed class DesignerActionBehavior : Behavior { private IComponent relatedComponent;//The component we are bound to private DesignerActionUI parentUI;//ptr to the parenting UI, used for showing menus and setting selection private DesignerActionListCollection actionLists;//all the shortcuts! private IServiceProvider serviceProvider; // we need to cache the service provider here to be able to create the panel with the proper arguments private bool ignoreNextMouseUp = false; ////// /// Constructor that calls base and caches off the action lists. /// internal DesignerActionBehavior(IServiceProvider serviceProvider, IComponent relatedComponent, DesignerActionListCollection actionLists ,DesignerActionUI parentUI) { this.actionLists = actionLists; this.serviceProvider = serviceProvider; this.relatedComponent = relatedComponent; this.parentUI = parentUI; } ////// /// Returns the collection of DesignerActionLists this Behavior is managing. /// These will be dynamically updated (some can be removed, new ones can be /// added, etc...). /// internal DesignerActionListCollection ActionLists { get { return actionLists; } set { actionLists = value; } } ////// /// Returns the parenting UI (a DesignerActionUI) /// internal DesignerActionUI ParentUI { get { return parentUI; } } ////// /// Returns the Component that this glyph is attached to. /// internal IComponent RelatedComponent { get { return relatedComponent; } } ////// /// Hides the designer action panel UI. /// internal void HideUI() { ParentUI.HideDesignerActionPanel(); } internal DesignerActionPanel CreateDesignerActionPanel(IComponent relatedComponent) { // BUILD AND SHOW THE CHROME UI DesignerActionListCollection lists = new DesignerActionListCollection(); lists.AddRange(ActionLists); DesignerActionPanel dap = new DesignerActionPanel(serviceProvider); dap.UpdateTasks(lists, new DesignerActionListCollection(), SR.GetString(SR.DesignerActionPanel_DefaultPanelTitle, relatedComponent.GetType().Name), null); return dap; } ////// /// Shows the designer action panel UI associated with this glyph. /// internal void ShowUI(Glyph g) { DesignerActionGlyph glyph = g as DesignerActionGlyph; if (glyph == null) { Debug.Fail("Why are we trying to 'showui' on a glyph that's not a DesignerActionGlyph?"); return; } DesignerActionPanel dap = CreateDesignerActionPanel(RelatedComponent); ParentUI.ShowDesignerActionPanel(RelatedComponent, dap, glyph); } internal bool IgnoreNextMouseUp { [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] set { ignoreNextMouseUp = value; } } public override bool OnMouseDoubleClick(Glyph g, MouseButtons button, Point mouseLoc) { ignoreNextMouseUp = true; return true; } public override bool OnMouseDown(Glyph g, MouseButtons button, Point mouseLoc) { // we take the msg return (!ParentUI.IsDesignerActionPanelVisible); } ////// /// In response to a MouseUp, we will either 1) select the Glyph /// and control if not selected, or 2) Build up our context menu /// representing our DesignerActions and show it. /// public override bool OnMouseUp(Glyph g, MouseButtons button) { if (button != MouseButtons.Left || ParentUI == null) { return true; } bool returnValue = true; if(ParentUI.IsDesignerActionPanelVisible) { HideUI(); } else if(!ignoreNextMouseUp) { if(serviceProvider != null) { ISelectionService selectionService = (ISelectionService)serviceProvider.GetService(typeof(ISelectionService)); if(selectionService != null) { if(selectionService.PrimarySelection != RelatedComponent) { ListcomponentList = new List (); componentList.Add(RelatedComponent); selectionService.SetSelectedComponents(componentList, SelectionTypes.Primary); } } } ShowUI(g); } else { returnValue = false; } ignoreNextMouseUp = false; return returnValue; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ListInitExpression.cs
- CompositeDataBoundControl.cs
- BooleanAnimationUsingKeyFrames.cs
- LazyTextWriterCreator.cs
- IdentityManager.cs
- StreamReader.cs
- ImageMap.cs
- InternalPermissions.cs
- PresentationSource.cs
- ColorConvertedBitmapExtension.cs
- EditCommandColumn.cs
- BasePropertyDescriptor.cs
- StylusButtonCollection.cs
- XmlSchemaObject.cs
- TdsParserHelperClasses.cs
- UrlMappingCollection.cs
- XsdBuildProvider.cs
- httpapplicationstate.cs
- CollectionsUtil.cs
- MoveSizeWinEventHandler.cs
- XamlGridLengthSerializer.cs
- DataSourceCache.cs
- StandardTransformFactory.cs
- ResourcePool.cs
- ModuleConfigurationInfo.cs
- SqlDependency.cs
- RichTextBox.cs
- ReachUIElementCollectionSerializer.cs
- _LocalDataStore.cs
- AuthorizationSection.cs
- ChildTable.cs
- InvalidWMPVersionException.cs
- TextContainer.cs
- HttpRawResponse.cs
- RequestCache.cs
- ImportCatalogPart.cs
- VirtualPath.cs
- RotationValidation.cs
- InternalSafeNativeMethods.cs
- UdpRetransmissionSettings.cs
- Transactions.cs
- TreeViewCancelEvent.cs
- XpsFilter.cs
- AsymmetricSignatureDeformatter.cs
- NumericUpDownAcceleration.cs
- autovalidator.cs
- WpfXamlMember.cs
- CheckedListBox.cs
- OleDbParameterCollection.cs
- WindowsGraphicsWrapper.cs
- Metafile.cs
- UniqueConstraint.cs
- StoreContentChangedEventArgs.cs
- RightsManagementPermission.cs
- CodeCommentStatementCollection.cs
- ObjectListFieldsPage.cs
- ListViewGroupConverter.cs
- MsmqReceiveHelper.cs
- UserPrincipalNameElement.cs
- ComPlusInstanceContextInitializer.cs
- AssemblyUtil.cs
- WebColorConverter.cs
- LinkClickEvent.cs
- ModelChangedEventArgsImpl.cs
- HtmlInputFile.cs
- RepeaterItem.cs
- DataGridColumnFloatingHeader.cs
- APCustomTypeDescriptor.cs
- CompleteWizardStep.cs
- TransformerInfoCollection.cs
- DrawListViewSubItemEventArgs.cs
- BitmapEncoder.cs
- EntityDataSourceContextCreatingEventArgs.cs
- MasterPageBuildProvider.cs
- RawStylusSystemGestureInputReport.cs
- ColorDialog.cs
- KeyValuePairs.cs
- VirtualizedCellInfoCollection.cs
- XPathNavigator.cs
- PlatformNotSupportedException.cs
- AttachedPropertyMethodSelector.cs
- GPPOINT.cs
- StickyNoteHelper.cs
- EnumMember.cs
- CachingHintValidation.cs
- TextElementCollectionHelper.cs
- XmlBindingWorker.cs
- SessionMode.cs
- _UriTypeConverter.cs
- UrlSyndicationContent.cs
- XmlBinaryWriterSession.cs
- DelayedRegex.cs
- TileBrush.cs
- CompilationSection.cs
- WebSysDisplayNameAttribute.cs
- PreDigestedSignedInfo.cs
- InputBindingCollection.cs
- FunctionParameter.cs
- CollaborationHelperFunctions.cs
- EnterpriseServicesHelper.cs