/// <include file='doc\ScrollableControlDesigner.uex' path='docs/doc[@for="ScrollableControlDesigner.WndProc"]/*' />
        /// <devdoc>
        ///     We override our base class's WndProc to monitor certain messages.
        /// </devdoc>
        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);

            switch (m.Msg)
            {
            case NativeMethods.WM_HSCROLL:
            case NativeMethods.WM_VSCROLL:

                // When we scroll, we reposition a control without causing a
                // property change event.  Therefore, we must tell the
                // selection UI service to sync itself.
                //
                if (selectionUISvc == null)
                {
                    selectionUISvc = (ISelectionUIService)GetService(typeof(ISelectionUIService));
                }

                if (selectionUISvc != null)
                {
                    selectionUISvc.SyncSelection();
                }

                // Now we must paint our adornments, since the scroll does not
                // trigger a paint event
                //
                Control.Invalidate();
                Control.Update();
                break;
            }
        }
        /// <include file='doc\TextBoxBaseDesigner.uex' path='docs/doc[@for="TextBoxBaseDesigner.OnControlPropertyChanged"]/*' />
        /// <devdoc>
        ///      For controls, we sync their property changed event so our component can track their location.
        /// </devdoc>
        private void OnControlPropertyChanged(object sender, EventArgs e)
        {
            ISelectionUIService selectionUISvc = (ISelectionUIService)GetService(typeof(ISelectionUIService));

            if (selectionUISvc != null)
            {
                selectionUISvc.SyncComponent((IComponent)sender);
            }
        }
Пример #3
0
        void SyncDesignerUI()
        {
            Size selectionSize      = new Size(0, 0);
            ISelectionUIService uis = (ISelectionUIService)designerSite.GetService(typeof(ISelectionUIService));

            if (uis != null)
            {
                selectionSize = uis.GetAdornmentDimensions(AdornmentType.Maximum);
            }

            designerRegion.AutoScrollMargin = selectionSize;
            designer.Location = new Point(selectionSize.Width, selectionSize.Height);

            if (uis != null)
            {
                uis.SyncSelection();
            }
        }
Пример #4
0
        /// <include file='doc\FormDocumentDesigner.uex' path='docs/doc[@for="FormDocumentDesigner.OnLoadComplete"]/*' />
        /// <devdoc>
        ///      Called when our code loads.  Here we connect us as the selection
        ///      UI handler for ourselves.  This is a special case because for
        ///      the top level document, we are our own selection UI handler.
        /// </devdoc>
        private void OnLoadComplete(object source, EventArgs evevent)
        {
            ApplyAutoScaling(autoScaleBaseSize, (Form)Control);
            ISelectionUIService svc = (ISelectionUIService)GetService(typeof(ISelectionUIService));

            if (svc != null)
            {
                svc.SyncSelection();
            }

            // if there is a menu and we need to update our height because of it,
            // do it now.
            //
            if (heightDelta != 0)
            {
                ((Form)Control).Height += heightDelta;
                heightDelta             = 0;
            }
        }
Пример #5
0
            /// <devdoc>
            ///     Need to know when child windows are created so we can properly set the Z-order
            /// </devdoc>
            protected override void WndProc(ref Message m)
            {
                base.WndProc(ref m);

                if (m.Msg == NativeMethods.WM_PARENTNOTIFY && NativeMethods.Util.LOWORD((int)m.WParam) == (short)NativeMethods.WM_CREATE)
                {
                    if (overlayList != null)
                    {
                        bool ourWindow = false;
                        foreach (Control c in overlayList)
                        {
                            if (c.IsHandleCreated && m.LParam == c.Handle)
                            {
                                ourWindow = true;
                                break;
                            }
                        }

                        if (!ourWindow)
                        {
                            foreach (Control c in overlayList)
                            {
                                SafeNativeMethods.SetWindowPos(c.Handle, (IntPtr)NativeMethods.HWND_TOP, 0, 0, 0, 0,
                                                               NativeMethods.SWP_NOSIZE | NativeMethods.SWP_NOMOVE);
                            }
                        }
                    }
                }
                else if ((m.Msg == NativeMethods.WM_VSCROLL || m.Msg == NativeMethods.WM_HSCROLL) && provider != null)
                {
                    ISelectionUIService selUISvc = (ISelectionUIService)provider.GetService(typeof(ISelectionUIService));
                    if (selUISvc != null)
                    {
                        selUISvc.SyncComponent(null);
                    }
                }
            }
Пример #6
0
            /// <include file='doc\DesignerFrame.uex' path='docs/doc[@for="DesignerFrame.OverlayControl.OnCreateControl"]/*' />
            /// <devdoc>
            ///     At handle creation time we request the designer's handle and
            ///     parent it.
            /// </devdoc>
            protected override void OnCreateControl()
            {
                base.OnCreateControl();

                // Loop through all of the overlays, create them, and hook them up
                //
                if (overlayList != null)
                {
                    foreach (Control c in overlayList)
                    {
                        ParentOverlay(c);
                    }
                }

                // We've reparented everything, which means that our selection UI is probably
                // out of sync.  Ask it to sync.
                //
                ISelectionUIService selUISvc = (ISelectionUIService)provider.GetService(typeof(ISelectionUIService));

                if (selUISvc != null)
                {
                    selUISvc.SyncSelection();
                }
            }
Пример #7
0
        public void DoOleDragDrop(DragEventArgs de)
        {
            // ASURT 43757: By the time we come here, it means that the user completed the drag-drop and
            // we compute the new location/size of the controls if needed and set the property values.
            // We have to stop freezePainting right here, so that controls can get a chance to validate
            // their new rects.
            //
            freezePainting = false;

            if (selectionHandler == null)
            {
                Debug.Fail("selectionHandler should not be null");
                de.Effect = DragDropEffects.None;
                return;
            }

            // make sure we've actually moved
            if ((localDrag && de.X == dragBase.X && de.Y == dragBase.Y) ||
                de.AllowedEffect == DragDropEffects.None ||
                (!localDrag && !dragOk))
            {
                de.Effect = DragDropEffects.None;
                return;
            }

            bool localMoveOnly = ((int)de.AllowedEffect & AllowLocalMoveOnly) != 0 && localDragInside;

            // if we are dragging inside the local dropsource/target, and and AllowLocalMoveOnly flag is set,
            // we just consider this a normal move.
            //
            bool moveAllowed = (de.AllowedEffect & DragDropEffects.Move) != DragDropEffects.None || localMoveOnly;
            bool copyAllowed = (de.AllowedEffect & DragDropEffects.Copy) != DragDropEffects.None;

            if ((de.Effect & DragDropEffects.Move) != 0 && !moveAllowed)
            {
                // Try copy instead?
                de.Effect = DragDropEffects.Copy;
            }

            // make sure the copy is allowed
            if ((de.Effect & DragDropEffects.Copy) != 0 && !copyAllowed)
            {
                // if copy isn't allowed, don't do anything

                de.Effect = DragDropEffects.None;
                return;
            }

            if (localMoveOnly && (de.Effect & DragDropEffects.Move) != 0)
            {
                de.Effect |= (DragDropEffects)AllowLocalMoveOnly | DragDropEffects.Move;
            }
            else if ((de.Effect & DragDropEffects.Copy) != 0)
            {
                de.Effect = DragDropEffects.Copy;
            }

            if (forceDrawFrames || localDragInside)
            {
                // undraw the drag rect
                localDragOffset = DrawDragFrames(dragComps, localDragOffset, localDragEffect,
                                                 Point.Empty, DragDropEffects.None, forceDrawFrames);
                forceDrawFrames = false;
            }

            Cursor oldCursor = Cursor.Current;

            try
            {
                Cursor.Current = Cursors.WaitCursor;

                if (dragOk || (localDragInside && de.Effect == DragDropEffects.Copy))
                {
                    // add em to this parent.
                    IDesignerHost host      = (IDesignerHost)GetService(typeof(IDesignerHost));
                    IContainer    container = host.RootComponent.Site.Container;

                    object[]    components;
                    IDataObject dataObj        = de.Data;
                    bool        updateLocation = false;

                    if (dataObj is ComponentDataObjectWrapper)
                    {
                        dataObj = ((ComponentDataObjectWrapper)dataObj).InnerData;
                        ComponentDataObject cdo = (ComponentDataObject)dataObj;

                        // if we're moving ot a different container, do a full serialization
                        // to make sure we pick up design time props, etc.
                        //
                        IComponent dragOwner        = GetDragOwnerComponent(de.Data);
                        bool       newContainer     = dragOwner == null || client.Component == null || dragOwner.Site.Container != client.Component.Site.Container;
                        bool       collapseChildren = false;
                        if (de.Effect == DragDropEffects.Copy || newContainer)
                        {
                            // this causes new elements to be created
                            //
                            cdo.Deserialize(serviceProvider, (de.Effect & DragDropEffects.Copy) == 0);
                        }
                        else
                        {
                            collapseChildren = true;
                        }

                        updateLocation = true;
                        components     = cdo.Components;

                        if (collapseChildren)
                        {
                            components = GetTopLevelComponents(components);
                        }
                    }
                    else
                    {
                        object serializationData = dataObj.GetData(DataFormat, true);

                        if (serializationData == null)
                        {
                            Debug.Fail("data object didn't return any data, so how did we allow the drop?");
                            components = Array.Empty <IComponent>();
                        }
                        else
                        {
                            dataObj        = new ComponentDataObject(client, serviceProvider, serializationData);
                            components     = ((ComponentDataObject)dataObj).Components;
                            updateLocation = true;
                        }
                    }

                    // now we need to offset the components locations from the drop mouse
                    // point to the parent, since their current locations are relative
                    // the the mouse pointer
                    if (components != null && components.Length > 0)
                    {
                        Debug.Assert(container != null, "Didn't get a container from the site!");
                        string     name;
                        IComponent comp = null;

                        DesignerTransaction trans = null;

                        try
                        {
                            trans = host.CreateTransaction(SR.DragDropDropComponents);
                            if (!localDrag)
                            {
                                host.Activate();
                            }

                            ArrayList selectComps = new ArrayList();

                            for (int i = 0; i < components.Length; i++)
                            {
                                comp = components[i] as IComponent;

                                if (comp == null)
                                {
                                    comp = null;
                                    continue;
                                }

                                try
                                {
                                    name = null;
                                    if (comp.Site != null)
                                    {
                                        name = comp.Site.Name;
                                    }

                                    Control oldDesignerControl = null;
                                    if (updateLocation)
                                    {
                                        oldDesignerControl = client.GetDesignerControl();
                                        User32.SendMessageW(oldDesignerControl.Handle, User32.WM.SETREDRAW);
                                    }

                                    Point dropPt = client.GetDesignerControl().PointToClient(new Point(de.X, de.Y));

                                    // First check if the component we are dropping have a TrayLocation, and if so, use it
                                    PropertyDescriptor loc = TypeDescriptor.GetProperties(comp)["TrayLocation"];
                                    if (loc == null)
                                    {
                                        // it didn't, so let's check for the regular Location
                                        loc = TypeDescriptor.GetProperties(comp)["Location"];
                                    }

                                    if (loc != null && !loc.IsReadOnly)
                                    {
                                        Rectangle bounds = new Rectangle();
                                        Point     pt     = (Point)loc.GetValue(comp);
                                        bounds.X = dropPt.X + pt.X;
                                        bounds.Y = dropPt.Y + pt.Y;
                                        bounds   = selectionHandler.GetUpdatedRect(Rectangle.Empty, bounds, false);
                                    }

                                    if (!client.AddComponent(comp, name, false))
                                    {
                                        // this means that we just moved the control
                                        // around in the same designer.

                                        de.Effect = DragDropEffects.None;
                                    }
                                    else
                                    {
                                        // make sure the component was added to this client
                                        if (client.GetControlForComponent(comp) == null)
                                        {
                                            updateLocation = false;
                                        }
                                    }

                                    if (updateLocation)
                                    {
                                        ParentControlDesigner parentDesigner = client as ParentControlDesigner;
                                        if (parentDesigner != null)
                                        {
                                            Control c = client.GetControlForComponent(comp);
                                            dropPt     = parentDesigner.GetSnappedPoint(c.Location);
                                            c.Location = dropPt;
                                        }
                                    }

                                    if (oldDesignerControl != null)
                                    {
                                        //((ComponentDataObject)dataObj).ShowControls();
                                        User32.SendMessageW(oldDesignerControl.Handle, User32.WM.SETREDRAW, (IntPtr)1);
                                        oldDesignerControl.Invalidate(true);
                                    }

                                    if (TypeDescriptor.GetAttributes(comp).Contains(DesignTimeVisibleAttribute.Yes))
                                    {
                                        selectComps.Add(comp);
                                    }
                                }
                                catch (CheckoutException ceex)
                                {
                                    if (ceex == CheckoutException.Canceled)
                                    {
                                        break;
                                    }

                                    throw;
                                }
                            }

                            if (host != null)
                            {
                                host.Activate();
                            }

                            // select the newly added components
                            ISelectionService selService = (ISelectionService)GetService(typeof(ISelectionService));

                            selService.SetSelectedComponents((object[])selectComps.ToArray(typeof(IComponent)), SelectionTypes.Replace);
                            localDragInside = false;
                        }
                        finally
                        {
                            if (trans != null)
                            {
                                trans.Commit();
                            }
                        }
                    }
                }

                if (localDragInside)
                {
                    ISelectionUIService selectionUISvc = (ISelectionUIService)GetService(typeof(ISelectionUIService));
                    Debug.Assert(selectionUISvc != null, "Unable to get selection ui service when adding child control");

                    if (selectionUISvc != null)
                    {
                        // We must check to ensure that UI service is still in drag mode.  It is
                        // possible that the user hit escape, which will cancel drag mode.
                        //
                        if (selectionUISvc.Dragging && moveAllowed)
                        {
                            Rectangle offset = new Rectangle(de.X - dragBase.X, de.Y - dragBase.Y, 0, 0);
                            selectionUISvc.DragMoved(offset);
                        }
                    }
                }

                dragOk = false;
            }
            finally
            {
                Cursor.Current = oldCursor;
            }
        }
Пример #8
0
        public bool DoBeginDrag(object[] components, SelectionRules rules, int initialX, int initialY)
        {
            // if we're in a sizing operation, or the mouse isn't down, don't do this!
            if ((rules & SelectionRules.AllSizeable) != SelectionRules.None || Control.MouseButtons == MouseButtons.None)
            {
                return(true);
            }

            Control c = client.GetDesignerControl();

            localDrag       = true;
            localDragInside = false;

            dragComps       = components;
            dragBase        = new Point(initialX, initialY);
            localDragOffset = Point.Empty;
            c.PointToClient(new Point(initialX, initialY));

            DragDropEffects allowedEffects = DragDropEffects.Copy | DragDropEffects.None | DragDropEffects.Move;

            // check to see if any of the components are inherhited. if so, don't allow them to be moved.
            // We replace DragDropEffects.Move with a local bit called AllowLocalMoveOnly which means it
            // can be moved around on the current dropsource/target, but not to another target.  Since only
            // we understand this bit, other drop targets will not allow the move to occur
            //
            for (int i = 0; i < components.Length; i++)
            {
                InheritanceAttribute attr = (InheritanceAttribute)TypeDescriptor.GetAttributes(components[i])[typeof(InheritanceAttribute)];

                if (!attr.Equals(InheritanceAttribute.NotInherited) && !attr.Equals(InheritanceAttribute.InheritedReadOnly))
                {
                    allowedEffects &= ~DragDropEffects.Move;
                    allowedEffects |= (DragDropEffects)AllowLocalMoveOnly;
                }
            }

            DataObject data = new ComponentDataObjectWrapper(new ComponentDataObject(client, serviceProvider, components, initialX, initialY));

            // We make sure we're painted before we start the drag.  Then, we disable window painting to
            // ensure that the drag can proceed without leaving artifacts lying around.  We should be caling LockWindowUpdate,
            // but that causes a horrible flashing because GDI+ uses direct draw.
            //
            User32.MSG msg = default;
            while (User32.PeekMessageW(ref msg, IntPtr.Zero, User32.WM.PAINT, User32.WM.PAINT, User32.PM.REMOVE).IsTrue())
            {
                User32.TranslateMessage(ref msg);
                User32.DispatchMessageW(ref msg);
            }

            // don't do any new painting...
            bool oldFreezePainting = freezePainting;

            // asurt 90345 -- this causes some subtle bugs, so i'm turning it off to see if we really need it, and if we do
            // if we can find a better way.
            //
            //freezePainting = true;

            AddCurrentDrag(data, client.Component);

            // Walk through all the children recursively and disable drag-drop
            // for each of them. This way, we will not accidentally try to drop
            // ourselves into our own children.
            //
            ArrayList allowDropChanged = new ArrayList();

            foreach (object comp in components)
            {
                Control ctl = comp as Control;
                if (ctl != null && ctl.HasChildren)
                {
                    DisableDragDropChildren(ctl.Controls, allowDropChanged);
                }
            }

            DragDropEffects     effect = DragDropEffects.None;
            IDesignerHost       host   = GetService(typeof(IDesignerHost)) as IDesignerHost;
            DesignerTransaction trans  = null;

            if (host != null)
            {
                trans = host.CreateTransaction(string.Format(SR.DragDropDragComponents, components.Length));
            }

            try
            {
                effect = c.DoDragDrop(data, allowedEffects);
                if (trans != null)
                {
                    trans.Commit();
                }
            }
            finally
            {
                RemoveCurrentDrag(data);

                // Reset the AllowDrop for the components being dragged.
                //
                foreach (Control ctl in allowDropChanged)
                {
                    ctl.AllowDrop = true;
                }

                freezePainting = oldFreezePainting;

                if (trans != null)
                {
                    ((IDisposable)trans).Dispose();
                }
            }

            bool isMove = (effect & DragDropEffects.Move) != 0 || ((int)effect & AllowLocalMoveOnly) != 0;

            // since the EndDrag will clear this
            bool isLocalMove = isMove && localDragInside;

            ISelectionUIService selectionUISvc = (ISelectionUIService)GetService(typeof(ISelectionUIService));

            Debug.Assert(selectionUISvc != null, "Unable to get selection ui service when adding child control");

            if (selectionUISvc != null)
            {
                // We must check to ensure that UI service is still in drag mode.  It is
                // possible that the user hit escape, which will cancel drag mode.
                //
                if (selectionUISvc.Dragging)
                {
                    // cancel the drag if we aren't doing a local move
                    selectionUISvc.EndDrag(!isLocalMove);
                }
            }

            if (!localDragOffset.IsEmpty && effect != DragDropEffects.None)
            {
                DrawDragFrames(dragComps, localDragOffset, localDragEffect,
                               Point.Empty, DragDropEffects.None, false);
            }

            localDragOffset = Point.Empty;
            dragComps       = null;
            localDrag       = localDragInside = false;
            dragBase        = Point.Empty;

            /*if (!isLocalMove && isMove){
             *  IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost));
             *  IUndoService  undoService = (IUndoService)GetService(typeof(IUndoService));
             *  IActionUnit unit = null;
             *
             *  if (host != null) {
             *      DesignerTransaction trans = host.CreateTransaction("Drag/drop");
             *      try{
             *          // delete the components
             *          try{
             *              for (int i = 0; i < components.Length; i++){
             *                 if (components[i] is IComponent){
             *                    if (undoService != null){
             *                        unit = new CreateControlActionUnit(host, (IComponent)components[i], true);
             *                    }
             *                    host.DestroyComponent((IComponent)components[i]);
             *                    if (undoService != null){
             *                         undoService.AddAction(unit, false);
             *                    }
             *                 }
             *              }
             *          }catch(CheckoutException ex){
             *              if (ex != CheckoutException.Canceled){
             *                  throw ex;
             *              }
             *          }
             *      }
             *      finally{
             *          trans.Commit();
             *      }
             *  }
             * }*/

            return(false);
        }
 protected virtual void OnMouseDragEnd(bool cancel)
 {
     this.mouseDragLast = InvalidPoint;
     this.Control.Capture = false;
     if (!this.mouseDragMoved)
     {
         if (!cancel)
         {
             ISelectionService service = (ISelectionService) this.GetService(typeof(ISelectionService));
             if (((System.Windows.Forms.Control.ModifierKeys & Keys.Shift) == Keys.None) && (this.ctrlSelect || ((service != null) && !service.GetComponentSelected(base.Component))))
             {
                 if (service != null)
                 {
                     service.SetSelectedComponents(new object[] { base.Component }, SelectionTypes.Click);
                 }
                 this.ctrlSelect = false;
             }
         }
     }
     else
     {
         this.mouseDragMoved = false;
         this.ctrlSelect = false;
         if (((this.BehaviorService != null) && this.BehaviorService.Dragging) && cancel)
         {
             this.BehaviorService.CancelDrag = true;
         }
         if (this.selectionUISvc == null)
         {
             this.selectionUISvc = (ISelectionUIService) this.GetService(typeof(ISelectionUIService));
         }
         if ((this.selectionUISvc != null) && this.selectionUISvc.Dragging)
         {
             this.selectionUISvc.EndDrag(cancel);
         }
     }
 }
Пример #10
0
        /// <include file='doc\TabOrder.uex' path='docs/doc[@for="TabOrder.TabOrder"]/*' />
        /// <devdoc>
        ///     Creates a new tab order control that displays the tab order
        ///     UI for a form.
        /// </devdoc>
        public TabOrder(IDesignerHost host)
        {
            this.host = host;

            // Determine a font for us to use.
            //
            IUIService uisvc = (IUIService)host.GetService(typeof(IUIService));

            if (uisvc != null)
            {
                tabFont = (Font)uisvc.Styles["DialogFont"];
            }
            else
            {
                tabFont = Control.DefaultFont;
            }
            tabFont = new Font(tabFont, FontStyle.Bold);

            // And compute the proper highlight dimensions.
            //
            ISelectionUIService seluisvc = (ISelectionUIService)host.GetService(typeof(ISelectionUIService));

            if (seluisvc != null)
            {
                selSize          = seluisvc.GetAdornmentDimensions(AdornmentType.GrabHandle).Width;
                seluisvc.Visible = false;
            }
            else
            {
                selSize = 7;
            }

            // Colors and brushes...
            //
            drawString         = new StringBuilder(12);
            highlightTextBrush = new SolidBrush(SystemColors.HighlightText);
            highlightPen       = new Pen(SystemColors.Highlight);

            // The decimal separator
            //
            NumberFormatInfo formatInfo = (NumberFormatInfo)CultureInfo.CurrentCulture.GetFormat(typeof(NumberFormatInfo));

            if (formatInfo != null)
            {
                decimalSep = formatInfo.NumberDecimalSeparator;
            }
            else
            {
                decimalSep = ".";
            }


            tabProperties = new Hashtable();

            // Set up a NULL brush so we never try to invalidate the control.  This is
            // more efficient for what we're doing
            //
            SetStyle(ControlStyles.Opaque, true);

            // We're an overlay on top of the form
            //
            IOverlayService os = (IOverlayService)host.GetService(typeof(IOverlayService));

            Debug.Assert(os != null, "No overlay service -- tab order UI cannot be shown");
            if (os != null)
            {
                os.PushOverlay(this);
            }

            // Push a help keyword so the help system knows we're in place.
            //
            IHelpService hs = (IHelpService)host.GetService(typeof(IHelpService));

            if (hs != null)
            {
                hs.AddContextAttribute("Keyword", "TabOrderView", HelpKeywordType.FilterKeyword);
            }

            commands = new MenuCommand[] {
                new MenuCommand(new EventHandler(OnKeyCancel),
                                MenuCommands.KeyCancel),

                new MenuCommand(new EventHandler(OnKeyDefault),
                                MenuCommands.KeyDefaultAction),

                new MenuCommand(new EventHandler(OnKeyPrevious),
                                MenuCommands.KeyMoveUp),

                new MenuCommand(new EventHandler(OnKeyNext),
                                MenuCommands.KeyMoveDown),

                new MenuCommand(new EventHandler(OnKeyPrevious),
                                MenuCommands.KeyMoveLeft),

                new MenuCommand(new EventHandler(OnKeyNext),
                                MenuCommands.KeyMoveRight),

                new MenuCommand(new EventHandler(OnKeyNext),
                                MenuCommands.KeySelectNext),

                new MenuCommand(new EventHandler(OnKeyPrevious),
                                MenuCommands.KeySelectPrevious),
            };

            newCommands = new MenuCommand[] {
                new MenuCommand(new EventHandler(OnKeyDefault),
                                MenuCommands.KeyTabOrderSelect),
            };

            IMenuCommandService mcs = (IMenuCommandService)host.GetService(typeof(IMenuCommandService));

            if (mcs != null)
            {
                foreach (MenuCommand mc in newCommands)
                {
                    mcs.AddCommand(mc);
                }
            }

            // We also override keyboard, menu and mouse handlers.  Our override relies on the
            // above array of menu commands, so this must come after we initialize the array.
            //
            IEventHandlerService ehs = (IEventHandlerService)host.GetService(typeof(IEventHandlerService));

            if (ehs != null)
            {
                ehs.PushHandler(this);
            }

            // We sync add, remove and change events so we remain in sync with any nastiness that the
            // form may pull on us.
            //
            IComponentChangeService cs = (IComponentChangeService)host.GetService(typeof(IComponentChangeService));

            if (cs != null)
            {
                cs.ComponentAdded   += new ComponentEventHandler(this.OnComponentAddRemove);
                cs.ComponentRemoved += new ComponentEventHandler(this.OnComponentAddRemove);
                cs.ComponentChanged += new ComponentChangedEventHandler(this.OnComponentChanged);
            }
        }
Пример #11
0
        /// <include file='doc\TabOrder.uex' path='docs/doc[@for="TabOrder.Dispose"]/*' />
        /// <devdoc>
        ///     Called when it is time for the tab order UI to go away.
        /// </devdoc>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (region != null)
                {
                    region.Dispose();
                    region = null;
                }

                if (host != null)
                {
                    IOverlayService os = (IOverlayService)host.GetService(typeof(IOverlayService));
                    if (os != null)
                    {
                        os.RemoveOverlay(this);
                    }

                    IEventHandlerService ehs = (IEventHandlerService)host.GetService(typeof(IEventHandlerService));
                    if (ehs != null)
                    {
                        ehs.PopHandler(this);
                    }

                    IMenuCommandService mcs = (IMenuCommandService)host.GetService(typeof(IMenuCommandService));
                    if (mcs != null)
                    {
                        foreach (MenuCommand mc in newCommands)
                        {
                            mcs.RemoveCommand(mc);
                        }
                    }

                    ISelectionUIService seluisvc = (ISelectionUIService)host.GetService(typeof(ISelectionUIService));
                    if (seluisvc != null)
                    {
                        seluisvc.Visible = true;
                    }

                    // We sync add, remove and change events so we remain in sync with any nastiness that the
                    // form may pull on us.
                    //
                    IComponentChangeService cs = (IComponentChangeService)host.GetService(typeof(IComponentChangeService));
                    if (cs != null)
                    {
                        cs.ComponentAdded   -= new ComponentEventHandler(this.OnComponentAddRemove);
                        cs.ComponentRemoved -= new ComponentEventHandler(this.OnComponentAddRemove);
                        cs.ComponentChanged -= new ComponentChangedEventHandler(this.OnComponentChanged);
                    }

                    IHelpService hs = (IHelpService)host.GetService(typeof(IHelpService));
                    if (hs != null)
                    {
                        hs.RemoveContextAttribute("Keyword", "TabOrderView");
                    }

                    host = null;
                }
            }
            base.Dispose(disposing);
        }
Пример #12
0
        /// <include file='doc\ControlCommandSet.uex' path='docs/doc[@for="ControlCommandSet.OnKeySize"]/*' />
        /// <devdoc>
        ///     Called for the various sizing commands we support.
        /// </devdoc>
        protected void OnKeySize(object sender, EventArgs e)
        {
            // Arrow keys.  Begin a drag if the selection isn't locked.
            //
            ISelectionService   selSvc = SelectionService;
            ISelectionUIService uiSvc  = SelectionUIService;

            if (uiSvc != null && selSvc != null)
            {
                //added to remove the selection rectangle: bug(54692)
                //
                uiSvc.Visible = false;
                object comp = selSvc.PrimarySelection;
                if (comp != null && comp is IComponent)
                {
                    PropertyDescriptor lockedProp = TypeDescriptor.GetProperties(comp)["Locked"];
                    if (lockedProp == null || (lockedProp.PropertyType == typeof(bool) && ((bool)lockedProp.GetValue(comp))) == false)
                    {
                        SelectionRules rules       = SelectionRules.Visible;
                        CommandID      cmd         = ((MenuCommand)sender).CommandID;
                        bool           invertSnap  = false;
                        int            moveOffsetX = 0;
                        int            moveOffsetY = 0;

                        if (cmd.Equals(MenuCommands.KeySizeHeightDecrease))
                        {
                            moveOffsetY = -1;
                            rules      |= SelectionRules.BottomSizeable;
                        }
                        else if (cmd.Equals(MenuCommands.KeySizeHeightIncrease))
                        {
                            moveOffsetY = 1;
                            rules      |= SelectionRules.BottomSizeable;
                        }
                        else if (cmd.Equals(MenuCommands.KeySizeWidthDecrease))
                        {
                            moveOffsetX = -1;
                            rules      |= SelectionRules.RightSizeable;
                        }
                        else if (cmd.Equals(MenuCommands.KeySizeWidthIncrease))
                        {
                            moveOffsetX = 1;
                            rules      |= SelectionRules.RightSizeable;
                        }
                        else if (cmd.Equals(MenuCommands.KeyNudgeHeightDecrease))
                        {
                            moveOffsetY = -1;
                            invertSnap  = true;
                            rules      |= SelectionRules.BottomSizeable;
                        }
                        else if (cmd.Equals(MenuCommands.KeyNudgeHeightIncrease))
                        {
                            moveOffsetY = 1;
                            invertSnap  = true;
                            rules      |= SelectionRules.BottomSizeable;
                        }
                        else if (cmd.Equals(MenuCommands.KeyNudgeWidthDecrease))
                        {
                            moveOffsetX = -1;
                            invertSnap  = true;
                            rules      |= SelectionRules.RightSizeable;
                        }
                        else if (cmd.Equals(MenuCommands.KeyNudgeWidthIncrease))
                        {
                            moveOffsetX = 1;
                            invertSnap  = true;
                            rules      |= SelectionRules.RightSizeable;
                        }
                        else
                        {
                            Debug.Fail("Unknown command mapped to OnKeySize: " + cmd.ToString());
                        }

                        if (uiSvc.BeginDrag(rules, 0, 0))
                        {
                            bool               snapOn        = false;
                            Size               snapSize      = Size.Empty;
                            IComponent         snapComponent = null;
                            PropertyDescriptor snapProperty  = null;

                            // Gets the needed snap information
                            //
                            IDesignerHost       host  = (IDesignerHost)GetService(typeof(IDesignerHost));
                            DesignerTransaction trans = null;

                            try {
                                if (host != null)
                                {
                                    GetSnapInformation(host, (IComponent)comp, out snapSize, out snapComponent, out snapProperty);

                                    if (selSvc.SelectionCount > 1)
                                    {
                                        trans = host.CreateTransaction(SR.GetString(SR.DragDropSizeComponents, selSvc.SelectionCount));
                                    }
                                    else
                                    {
                                        trans = host.CreateTransaction(SR.GetString(SR.DragDropSizeComponent, ((IComponent)comp).Site.Name));
                                    }

                                    if (snapProperty != null)
                                    {
                                        snapOn = (bool)snapProperty.GetValue(snapComponent);

                                        if (invertSnap)
                                        {
                                            snapOn = !snapOn;
                                            snapProperty.SetValue(snapComponent, snapOn);
                                        }
                                    }
                                }

                                if (snapOn && !snapSize.IsEmpty)
                                {
                                    moveOffsetX *= snapSize.Width;
                                    moveOffsetY *= snapSize.Height;
                                }


                                // Now move the controls the correct # of pixels.
                                //
                                uiSvc.DragMoved(new Rectangle(0, 0, moveOffsetX, moveOffsetY));
                                uiSvc.EndDrag(false);

                                if (host != null)
                                {
                                    if (invertSnap && snapProperty != null)
                                    {
                                        snapOn = !snapOn;
                                        snapProperty.SetValue(snapComponent, snapOn);
                                    }
                                }
                            }
                            finally {
                                if (trans != null)
                                {
                                    trans.Commit();
                                    uiSvc.Visible = true;
                                }
                            }
                        }
                    }
                }

                uiSvc.Visible = true;
            }
        }
 protected override void Dispose(bool disposing)
 {
     if (disposing && (this.controls != null))
     {
         IExtenderProviderService service = (IExtenderProviderService) this.GetService(typeof(IExtenderProviderService));
         bool enabled = System.ComponentModel.CompModSwitches.CommonDesignerServices.Enabled;
         if (service != null)
         {
             service.RemoveExtenderProvider(this);
         }
         IDesignerHost host = (IDesignerHost) this.GetService(typeof(IDesignerHost));
         if ((this.eventHandlerService != null) && (host != null))
         {
             host.RemoveService(typeof(IEventHandlerService));
             this.eventHandlerService = null;
         }
         IComponentChangeService service2 = (IComponentChangeService) this.GetService(typeof(IComponentChangeService));
         if (service2 != null)
         {
             service2.ComponentRemoved -= new ComponentEventHandler(this.OnComponentRemoved);
         }
         TypeDescriptor.Refreshed -= new RefreshEventHandler(this.OnComponentRefresh);
         SystemEvents.DisplaySettingsChanged -= new EventHandler(this.OnSystemSettingChanged);
         SystemEvents.InstalledFontsChanged -= new EventHandler(this.OnSystemSettingChanged);
         SystemEvents.UserPreferenceChanged -= new UserPreferenceChangedEventHandler(this.OnUserPreferenceChanged);
         IMenuCommandService menuService = this.MenuService;
         if (menuService != null)
         {
             menuService.RemoveCommand(this.menucmdArrangeIcons);
             menuService.RemoveCommand(this.menucmdLineupIcons);
             menuService.RemoveCommand(this.menucmdLargeIcons);
         }
         if (this.privateCommandSet != null)
         {
             this.privateCommandSet.Dispose();
             if (host != null)
             {
                 host.RemoveService(typeof(ISelectionUIService));
             }
         }
         this.selectionUISvc = null;
         if (this.inheritanceUI != null)
         {
             this.inheritanceUI.Dispose();
             this.inheritanceUI = null;
         }
         this.serviceProvider = null;
         this.controls.Clear();
         this.controls = null;
         if (this.glyphManager != null)
         {
             this.glyphManager.Dispose();
             this.glyphManager = null;
         }
     }
     base.Dispose(disposing);
 }
 public virtual void AddComponent(IComponent component)
 {
     IDesignerHost service = (IDesignerHost) this.GetService(typeof(IDesignerHost));
     if (this.CanDisplayComponent(component))
     {
         if (this.selectionUISvc == null)
         {
             this.selectionUISvc = (ISelectionUIService) this.GetService(typeof(ISelectionUIService));
             if (this.selectionUISvc == null)
             {
                 this.selectionUISvc = new SelectionUIService(service);
                 service.AddService(typeof(ISelectionUIService), this.selectionUISvc);
             }
             this.grabHandle = this.selectionUISvc.GetAdornmentDimensions(AdornmentType.GrabHandle);
         }
         TrayControl control = new TrayControl(this, component);
         base.SuspendLayout();
         try
         {
             base.Controls.Add(control);
             this.controls.Add(control);
             TypeDescriptor.Refresh(component);
             if ((service != null) && !service.Loading)
             {
                 this.PositionControl(control);
             }
             if (this.selectionUISvc != null)
             {
                 this.selectionUISvc.AssignSelectionUIHandler(component, this);
             }
             InheritanceAttribute inheritanceAttribute = control.InheritanceAttribute;
             if (inheritanceAttribute.InheritanceLevel != InheritanceLevel.NotInherited)
             {
                 System.Windows.Forms.Design.InheritanceUI inheritanceUI = this.InheritanceUI;
                 if (inheritanceUI != null)
                 {
                     inheritanceUI.AddInheritedControl(control, inheritanceAttribute.InheritanceLevel);
                 }
             }
         }
         finally
         {
             base.ResumeLayout();
         }
         if ((service != null) && !service.Loading)
         {
             base.ScrollControlIntoView(control);
         }
     }
 }