Code:
/ DotNET / DotNET / 8.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
- MouseButtonEventArgs.cs
- TextRangeProviderWrapper.cs
- NavigationProgressEventArgs.cs
- SimpleTextLine.cs
- TypeResolver.cs
- WmlLabelAdapter.cs
- RemoteWebConfigurationHost.cs
- IgnoreFileBuildProvider.cs
- PageThemeCodeDomTreeGenerator.cs
- printdlgexmarshaler.cs
- HealthMonitoringSectionHelper.cs
- XPathDocumentNavigator.cs
- BindToObject.cs
- SqlDataSourceConfigureSelectPanel.cs
- XsdBuildProvider.cs
- PeerNameResolver.cs
- SecurityUtils.cs
- SslStream.cs
- Semaphore.cs
- LoginCancelEventArgs.cs
- PathSegmentCollection.cs
- Utils.cs
- SoapDocumentServiceAttribute.cs
- QilName.cs
- SqlVisitor.cs
- TextRangeEditTables.cs
- DataGridViewRowsRemovedEventArgs.cs
- ConfigXmlElement.cs
- XmlValidatingReader.cs
- AutoCompleteStringCollection.cs
- NavigationPropertySingletonExpression.cs
- StateInitialization.cs
- XmlArrayAttribute.cs
- MenuItem.cs
- TextTrailingCharacterEllipsis.cs
- RSACryptoServiceProvider.cs
- HttpListenerContext.cs
- CryptoKeySecurity.cs
- SqlDataSourceFilteringEventArgs.cs
- SmiEventSink_DeferedProcessing.cs
- StylusShape.cs
- ByteStorage.cs
- IDQuery.cs
- FrameworkContentElement.cs
- EtwTrace.cs
- FamilyCollection.cs
- _FtpDataStream.cs
- SettingsPropertyWrongTypeException.cs
- InputReportEventArgs.cs
- XsdBuilder.cs
- ValueQuery.cs
- PartialCachingAttribute.cs
- SqlUserDefinedAggregateAttribute.cs
- iisPickupDirectory.cs
- ControlIdConverter.cs
- TaskFormBase.cs
- NameValuePermission.cs
- CookieParameter.cs
- RequestStatusBarUpdateEventArgs.cs
- DispatcherSynchronizationContext.cs
- SelectingProviderEventArgs.cs
- HtmlMeta.cs
- ListView.cs
- RSAOAEPKeyExchangeDeformatter.cs
- PassportIdentity.cs
- ResourceReader.cs
- DataBindingCollection.cs
- CodeAttributeDeclarationCollection.cs
- AliasExpr.cs
- FieldNameLookup.cs
- DeadCharTextComposition.cs
- AxHost.cs
- ResourcePool.cs
- StrokeNodeOperations2.cs
- PagesSection.cs
- BindableAttribute.cs
- PageContentAsyncResult.cs
- TextEditorTyping.cs
- SmiEventSink.cs
- CultureTableRecord.cs
- CodeDelegateInvokeExpression.cs
- RequestCacheValidator.cs
- SqlRowUpdatingEvent.cs
- DecimalStorage.cs
- LeaseManager.cs
- WorkflowRuntimeSection.cs
- MenuItemBindingCollection.cs
- CompositeControl.cs
- ShimAsPublicXamlType.cs
- ListenerHandler.cs
- PolyBezierSegmentFigureLogic.cs
- SingleAnimation.cs
- KeyPullup.cs
- WaitHandle.cs
- ThreadInterruptedException.cs
- TabRenderer.cs
- AttributeTable.cs
- TextSelectionHelper.cs
- UnsettableComboBox.cs
- EncoderReplacementFallback.cs