Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / WinForms / System / WinForms / Design / ToolStripAdornerWindowService.cs / 1 / ToolStripAdornerWindowService.cs
namespace System.Windows.Forms.Design { using System; using System.Collections; using System.ComponentModel; using System.ComponentModel.Design; using System.Design; using System.Diagnostics; using System.Drawing; using System.Drawing.Design; using System.Security; using System.Security.Permissions; using System.Diagnostics.CodeAnalysis; using System.Windows.Forms.Design; using System.Runtime.InteropServices; using System.Windows.Forms.Design.Behavior; ////// /// Transparent Window to parent the DropDowns. /// internal sealed class ToolStripAdornerWindowService : IDisposable { private IServiceProvider serviceProvider; //standard service provider private ToolStripAdornerWindow toolStripAdornerWindow; //the transparent window all glyphs are drawn to private BehaviorService bs; private Adorner dropDownAdorner; private ArrayList dropDownCollection; private IOverlayService os; ////// This constructor is called from DocumentDesigner's Initialize method. /// internal ToolStripAdornerWindowService(IServiceProvider serviceProvider, Control windowFrame) { this.serviceProvider = serviceProvider; //create the AdornerWindow toolStripAdornerWindow = new ToolStripAdornerWindow(windowFrame); bs = (BehaviorService)serviceProvider.GetService(typeof(BehaviorService)); int indexToInsert = bs.AdornerWindowIndex; //use the adornerWindow as an overlay os = (IOverlayService)serviceProvider.GetService(typeof(IOverlayService)); if (os != null) { os.InsertOverlay(toolStripAdornerWindow, indexToInsert); } dropDownAdorner = new Adorner(); int count = bs.Adorners.Count; // Why this is NEEDED ? // To Add the Adorner at proper index in the AdornerCollection for the BehaviorService // So that the DesignerActionGlyph always stays on the Top. if (count > 1) { bs.Adorners.Insert(count - 1, dropDownAdorner); } } ////// Returns the actual Control that represents the transparent AdornerWindow. /// internal Control ToolStripAdornerWindowControl { get { return toolStripAdornerWindow; } } ////// /// Creates and returns a Graphics object for the AdornerWindow /// public Graphics ToolStripAdornerWindowGraphics { get { return toolStripAdornerWindow.CreateGraphics(); } } internal Adorner DropDownAdorner { get { return dropDownAdorner; } } ////// /// Disposes the behavior service. /// [SuppressMessage("Microsoft.Usage", "CA2213:DisposableFieldsShouldBeDisposed")] public void Dispose() { if (os != null) { os.RemoveOverlay(toolStripAdornerWindow); } toolStripAdornerWindow.Dispose(); if (bs != null) { bs.Adorners.Remove(dropDownAdorner); bs = null; } if (dropDownAdorner != null) { dropDownAdorner.Glyphs.Clear(); dropDownAdorner = null; } } ////// /// Translates a point in the AdornerWindow to screen coords. /// public Point AdornerWindowPointToScreen(Point p) { NativeMethods.POINT offset = new NativeMethods.POINT(p.X, p.Y); NativeMethods.MapWindowPoints(toolStripAdornerWindow.Handle, IntPtr.Zero, offset, 1); return new Point(offset.x, offset.y); } ////// /// Gets the location (upper-left corner) of the AdornerWindow in screen coords. /// public Point AdornerWindowToScreen() { Point origin = new Point(0, 0); return AdornerWindowPointToScreen(origin); } ////// /// Returns the location of a Control translated to AdornerWidnow coords. /// public Point ControlToAdornerWindow(Control c) { if (c.Parent == null) { return Point.Empty; } NativeMethods.POINT pt = new NativeMethods.POINT(); pt.x = c.Left; pt.y = c.Top; NativeMethods.MapWindowPoints(c.Parent.Handle, toolStripAdornerWindow.Handle, pt, 1); return new Point(pt.x, pt.y); } ////// /// Invalidates the BehaviorService's AdornerWindow. This will force a refesh of all Adorners /// and, in turn, all Glyphs. /// public void Invalidate() { toolStripAdornerWindow.InvalidateAdornerWindow(); } ////// /// Invalidates the BehaviorService's AdornerWindow. This will force a refesh of all Adorners /// and, in turn, all Glyphs. /// public void Invalidate(Rectangle rect) { toolStripAdornerWindow.InvalidateAdornerWindow(rect); } ////// /// Invalidates the BehaviorService's AdornerWindow. This will force a refesh of all Adorners /// and, in turn, all Glyphs. /// public void Invalidate(Region r) { toolStripAdornerWindow.InvalidateAdornerWindow(r); } internal ArrayList DropDowns { get { return dropDownCollection; } set { if (dropDownCollection == null) { dropDownCollection = new ArrayList(); } } } ////// ControlDesigner calls this internal method in response to a WmPaint. /// We need to know when a ControlDesigner paints - 'cause we will need /// to re-paint any glyphs above of this Control. /// internal void ProcessPaintMessage(Rectangle paintRect) { //Note, we don't call BehSvc.Invalidate because //this will just cause the messages to recurse. //Instead, invalidating this adornerWindow will //just cause a "propagatePaint" and draw the glyphs. toolStripAdornerWindow.Invalidate(paintRect); } ////// The AdornerWindow is a transparent window that resides ontop of the /// Designer's Frame. This window is used by the ToolStripAdornerWindowService to /// parent the MenuItem DropDowns. /// private class ToolStripAdornerWindow : Control { private Control designerFrame;//the designer's frame ////// Constructor that parents itself to the Designer Frame and hooks all /// necessary events. /// [SuppressMessage("Microsoft.Globalization", "CA1303:DoNotPassLiteralsAsLocalizedParameters")] internal ToolStripAdornerWindow(Control designerFrame) { this.designerFrame = designerFrame; this.Dock = DockStyle.Fill; this.AllowDrop = true; this.Text = "ToolStripAdornerWindow"; SetStyle(ControlStyles.Opaque,true); } ////// The key here is to set the appropriate TransparetWindow style. /// protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; cp.Style &= ~(NativeMethods.WS_CLIPCHILDREN | NativeMethods.WS_CLIPSIBLINGS); cp.ExStyle |= 0x00000020/*WS_EX_TRANSPARENT*/; return cp; } } ////// We'll use CreateHandle as our notification for creating // our mouse hooker. /// protected override void OnHandleCreated(EventArgs e) { base.OnHandleCreated(e); } ////// Unhook and null out our mouseHook. /// protected override void OnHandleDestroyed(EventArgs e) { base.OnHandleDestroyed(e); } ////// Null out our mouseHook and unhook any events. /// protected override void Dispose(bool disposing) { if (disposing) { if (designerFrame != null) { designerFrame = null; } } base.Dispose(disposing); } ////// Returns true if the DesignerFrame is created & not being disposed. /// private bool DesignerFrameValid { get { if (designerFrame == null || designerFrame.IsDisposed || !designerFrame.IsHandleCreated) { return false; } return true; } } ////// Invalidates the transparent AdornerWindow by asking /// the Designer Frame beneath it to invalidate. Note the /// they use of the .Update() call for perf. purposes. /// internal void InvalidateAdornerWindow() { if (DesignerFrameValid) { designerFrame.Invalidate(true); designerFrame.Update(); } } ////// Invalidates the transparent AdornerWindow by asking /// the Designer Frame beneath it to invalidate. Note the /// they use of the .Update() call for perf. purposes. /// internal void InvalidateAdornerWindow(Region region) { if (DesignerFrameValid) { designerFrame.Invalidate(region, true); designerFrame.Update(); } } ////// Invalidates the transparent AdornerWindow by asking /// the Designer Frame beneath it to invalidate. Note the /// they use of the .Update() call for perf. purposes. /// internal void InvalidateAdornerWindow(Rectangle rectangle) { if (DesignerFrameValid) { designerFrame.Invalidate(rectangle, true); designerFrame.Update(); } } ////// The AdornerWindow intercepts all designer-related messages and forwards them /// to the BehaviorService for appropriate actions. Note that Paint and HitTest /// messages are correctly parsed and translated to AdornerWindow coords. /// protected override void WndProc(ref Message m) { switch(m.Msg) { case NativeMethods.WM_NCHITTEST: m.Result = (IntPtr)(NativeMethods.HTTRANSPARENT); break; default: base.WndProc(ref m); break; } } } } } // 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
- PtsContext.cs
- NumberFunctions.cs
- MimeXmlImporter.cs
- HelpKeywordAttribute.cs
- OleDbReferenceCollection.cs
- AssemblyCollection.cs
- WebServiceFaultDesigner.cs
- MetadataArtifactLoaderXmlReaderWrapper.cs
- XmlSerializationWriter.cs
- CollectionTypeElement.cs
- SoapAttributeAttribute.cs
- KeySpline.cs
- CssTextWriter.cs
- DelayedRegex.cs
- LoadWorkflowByKeyAsyncResult.cs
- Interlocked.cs
- ProvidersHelper.cs
- CryptoKeySecurity.cs
- CommandConverter.cs
- DefaultAssemblyResolver.cs
- PeerTransportSecuritySettings.cs
- RelationHandler.cs
- MenuDesigner.cs
- GeometryHitTestResult.cs
- AssociationTypeEmitter.cs
- HideDisabledControlAdapter.cs
- Calendar.cs
- RequestResizeEvent.cs
- MoveSizeWinEventHandler.cs
- DataTemplateSelector.cs
- ClaimTypeElement.cs
- PipeStream.cs
- GradientBrush.cs
- GeneralTransform3DGroup.cs
- RelationalExpressions.cs
- XmlTypeAttribute.cs
- Slider.cs
- SByte.cs
- RequestBringIntoViewEventArgs.cs
- MorphHelper.cs
- PeerTransportSecurityElement.cs
- control.ime.cs
- SqlGatherProducedAliases.cs
- SqlOuterApplyReducer.cs
- DataGridDesigner.cs
- SerializationFieldInfo.cs
- MimeFormImporter.cs
- PixelShader.cs
- ThreadStartException.cs
- Color.cs
- PropertyValue.cs
- Attribute.cs
- OpenFileDialog.cs
- MimeWriter.cs
- AuthenticationModuleElement.cs
- CryptoConfig.cs
- ObjectDataSourceView.cs
- SiteIdentityPermission.cs
- COM2PropertyBuilderUITypeEditor.cs
- ScriptControl.cs
- _WebProxyDataBuilder.cs
- _LazyAsyncResult.cs
- DataContractSerializerElement.cs
- RedirectionProxy.cs
- Int64Converter.cs
- SimpleTextLine.cs
- AllMembershipCondition.cs
- LambdaCompiler.Unary.cs
- XmlBindingWorker.cs
- TempFiles.cs
- PropagatorResult.cs
- SchemaCollectionCompiler.cs
- __TransparentProxy.cs
- infer.cs
- ClientConfigPaths.cs
- MatrixIndependentAnimationStorage.cs
- ClientData.cs
- QueryableDataSource.cs
- XmlMessageFormatter.cs
- ObjectDataSource.cs
- ZipIOExtraFieldElement.cs
- SignedInfo.cs
- WeakReferenceEnumerator.cs
- WindowAutomationPeer.cs
- PropertyGridEditorPart.cs
- NullableFloatAverageAggregationOperator.cs
- PocoEntityKeyStrategy.cs
- Token.cs
- TimeoutException.cs
- MetadataPropertyAttribute.cs
- ProfileGroupSettings.cs
- InstanceNameConverter.cs
- MenuTracker.cs
- XmlSchemaComplexContent.cs
- EntityDataSourceReferenceGroup.cs
- DeflateStream.cs
- SqlGatherProducedAliases.cs
- DateTimeStorage.cs
- TripleDESCryptoServiceProvider.cs
- PropertyChangeTracker.cs