Ejemplo n.º 1
0
 /// <summary>
 /// Raises the RubberbandClear event.
 /// </summary>
 /// <param name="e">Standard MWRubberbandPaintEventArgs object.</param>
 public void OnRubberbandClear(MWRubberbandClearEventArgs e)
 {
     if(RubberbandClear != null)
     {
         RubberbandClear(this, e);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Standard OnMouseMove EventHandler.
        /// </summary>
        /// <param name="e">Standard MouseEventArgs object.</param>
        protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e)
        {
            if(this.MultiSelect != TreeViewMultiSelect.Classic)
            {
                if(this.ExtendedTemporaryMarking && !bTNDone && tnTNDown != null && !IsTreeNodeSelected(tnTNDown))
                {
                    bTNDone = true;
                    tnTNDown.BackColor = cBackColorTNDown;
                    tnTNDown.ForeColor = cForeColorTNDown;
                }

                int iMouseDownTreeNodeLevel = GetTreeNodeLevel(this.TreeNodeMouseDownInt);
                TreeNode tnMouseDownGrandParent = GetTreeNodeGrandParent(this.TreeNodeMouseDownInt);

                bool bStartRubberbandPainting = Math.Abs(ptMouseDown.Y - e.Y) > this.ItemHeight;

                if(bStartRubberbandPainting)
                {
                    if(this.UseRubberbandUpdateTimer)
                    {
                        tRubberbandUpdate.Start();
                    }

                    bRubberbandIsOnScreen = true;
                }

                TreeNode tn = this.GetNodeAt(e.X, e.Y);

                if(this.HotTracking)
                {
                    if(IsTreeNodeSelected(tn) && IsPointOnTreeNode(tn, new Point(e.X, e.Y)))
                    {
                        bPaintFocusRectAndHottracking = true;
                        this.SelectedNode = tn;
                        bPaintFocusRectAndHottracking = false;
                    }
                    else
                    {
                        this.SelectedNode = null;
                    }
                }

                if(	((this.AllowOutOfFocusRubberbandSelection && !bActive) || bActive) &&
                    RubberbandSelection != RubberbandSelectionMode.None)
                {
                    if(	e.Button == MouseButtons.Left &&
                        this.MultiSelect != TreeViewMultiSelect.NoMulti &&
                        (bStartRubberbandPainting || bRubberbandHasBeenPainted || (tn != this.TreeNodeMouseDownInt && tn != null)) &&
                        !bExpandInProgress &&
                        !bCollapseInProgress &&
                        IsMouseMoveSelect)
                    {
                        if(!(ptMouseDownScreen == this.PointToScreen(ptMouseDown) &&
                            ptMouseMoveScreen == this.PointToScreen(new Point(e.X, e.Y))) ||
                            bUpdated || bRubberbandStartMoved)
                        {

                            #region OnMouseMove Selection

                            if(this.TreeNodeMouseDownInt != null && tn != null)
                            {
                                TreeNode tnTemp = this.TreeNodeMouseDownInt;

                                if(tnTemp != tn)
                                {
                                    bool bPrevious = false;

                                    while(tnTemp != null && tnTemp.PrevVisibleNode != null && tnTemp != tn)
                                    {
                                        if(tnTemp.PrevVisibleNode == tn)
                                        {
                                            bPrevious = true;
                                            break;
                                        }

                                        tnTemp = tnTemp.PrevVisibleNode;
                                    }

                                    tnTemp = this.TreeNodeMouseDownInt;

                                    if(!MouseModKeyControl)
                                    {
                                        if(bPrevious)
                                        {
                                            this.ClearSelNodes(tn, this.TreeNodeMouseDownInt);
                                        }
                                        else
                                        {
                                            this.ClearSelNodes(this.TreeNodeMouseDownInt, tn);
                                        }
                                    }

                                    if(	MouseModKeyAlt &&
                                        this.MultiSelect != TreeViewMultiSelect.MultiSameLevel &&
                                        this.MultiSelect != TreeViewMultiSelect.MultiPathToParent &&
                                        this.MultiSelect != TreeViewMultiSelect.MultiPathToParents &&
                                        this.MultiSelect != TreeViewMultiSelect.SinglePathToParent &&
                                        this.MultiSelect != TreeViewMultiSelect.SinglePathToParents &&
                                        this.MultiSelect != TreeViewMultiSelect.MultiAllDescendants)
                                    {
                                        SelectBranch(this.TreeNodeMouseDownInt, true, true, false);
                                    }
                                    else if(this.MultiSelect == TreeViewMultiSelect.MultiAllDescendants)
                                    {
                                        SelectBranch(this.TreeNodeMouseDownInt, true, true, false);
                                    }
                                    else
                                    {
                                        SelectNode(this.TreeNodeMouseDownInt, false);
                                    }

                                    if(bPrevious)
                                    {
                                        while(tnTemp.PrevVisibleNode != null && tnTemp != tn)
                                        {
                                            if(	this.ConstrainedRubberbandSelection &&
                                                this.MultiSelect == TreeViewMultiSelect.MultiSameLevel)
                                            {
                                                if(iMouseDownTreeNodeLevel == GetTreeNodeLevel(tnTemp.PrevVisibleNode))
                                                {
                                                    SelectNode(tnTemp.PrevVisibleNode, false);
                                                }
                                            }
                                            else if(this.ConstrainedRubberbandSelection &&
                                                this.MultiSelect == TreeViewMultiSelect.MultiSameBranch)
                                            {
                                                if(tnMouseDownGrandParent == GetTreeNodeGrandParent(tnTemp.PrevVisibleNode))
                                                {
                                                    SelectNode(tnTemp.PrevVisibleNode, false);
                                                }
                                            }
                                            else if(this.ConstrainedRubberbandSelection &&
                                                this.MultiSelect == TreeViewMultiSelect.MultiSameBranchAndLevel)
                                            {
                                                if(	iMouseDownTreeNodeLevel == GetTreeNodeLevel(tnTemp.PrevVisibleNode) &&
                                                    tnMouseDownGrandParent == GetTreeNodeGrandParent(tnTemp.PrevVisibleNode))
                                                {
                                                    SelectNode(tnTemp.PrevVisibleNode, false);
                                                }
                                            }
                                            else if(this.MultiSelect == TreeViewMultiSelect.MultiPathToParent ||
                                                this.MultiSelect == TreeViewMultiSelect.MultiPathToParents ||
                                                this.MultiSelect == TreeViewMultiSelect.SinglePathToParent ||
                                                this.MultiSelect == TreeViewMultiSelect.SinglePathToParents)
                                            {
                                                SelectNode(tnTemp.PrevVisibleNode, false);
                                            }
                                            else if(this.MultiSelect == TreeViewMultiSelect.MultiAllDescendants)
                                            {
                                                if(MouseModKeyAlt)
                                                {
                                                    SelectNode(tnTemp.PrevVisibleNode, false);
                                                }
                                                else
                                                {
                                                    SelectBranch(tnTemp.PrevVisibleNode, true, false, false);
                                                }
                                            }
                                            else
                                            {
                                                if(MouseModKeyAlt)
                                                {
                                                    SelectBranch(tnTemp.PrevVisibleNode, true, false, false);
                                                }
                                                else
                                                {
                                                    SelectNode(tnTemp.PrevVisibleNode, false);
                                                }
                                            }

                                            tnTemp = tnTemp.PrevVisibleNode;
                                        }
                                    }
                                    else
                                    {
                                        while(tnTemp.NextVisibleNode != null && tnTemp != tn)
                                        {
                                            if(	this.ConstrainedRubberbandSelection &&
                                                this.MultiSelect == TreeViewMultiSelect.MultiSameLevel)
                                            {
                                                if(iMouseDownTreeNodeLevel == GetTreeNodeLevel(tnTemp.NextVisibleNode))
                                                {
                                                    SelectNode(tnTemp.NextVisibleNode, false);
                                                }
                                            }
                                            else if(this.ConstrainedRubberbandSelection &&
                                                this.MultiSelect == TreeViewMultiSelect.MultiSameBranch)
                                            {
                                                if(tnMouseDownGrandParent == GetTreeNodeGrandParent(tnTemp.NextVisibleNode))
                                                {
                                                    SelectNode(tnTemp.NextVisibleNode, false);
                                                }
                                            }
                                            else if(this.ConstrainedRubberbandSelection &&
                                                this.MultiSelect == TreeViewMultiSelect.MultiSameBranchAndLevel)
                                            {
                                                if(	iMouseDownTreeNodeLevel == GetTreeNodeLevel(tnTemp.NextVisibleNode) &&
                                                    tnMouseDownGrandParent == GetTreeNodeGrandParent(tnTemp.NextVisibleNode))
                                                {
                                                    SelectNode(tnTemp.NextVisibleNode, false);
                                                }
                                            }
                                            else if(this.MultiSelect == TreeViewMultiSelect.MultiPathToParent ||
                                                this.MultiSelect == TreeViewMultiSelect.MultiPathToParents ||
                                                this.MultiSelect == TreeViewMultiSelect.SinglePathToParent ||
                                                this.MultiSelect == TreeViewMultiSelect.SinglePathToParents)
                                            {
                                                SelectNode(tnTemp.NextVisibleNode, false);
                                            }
                                            else if(this.MultiSelect == TreeViewMultiSelect.MultiAllDescendants)
                                            {
                                                if(MouseModKeyAlt)
                                                {
                                                    SelectNode(tnTemp.NextVisibleNode, false);
                                                }
                                                else
                                                {
                                                    SelectBranch(tnTemp.NextVisibleNode, true, true, false);
                                                }
                                            }
                                            else
                                            {
                                                if(MouseModKeyAlt)
                                                {
                                                    SelectBranch(tnTemp.NextVisibleNode, true, true, false);
                                                }
                                                else
                                                {
                                                    SelectNode(tnTemp.NextVisibleNode, false);
                                                }
                                            }

                                            tnTemp = tnTemp.NextVisibleNode;
                                        }
                                    }
                                }
                                else
                                {
                                    if(!MouseModKeyControl)
                                    {
                                        ClearSelNodes(tn);
                                    }
                                }

                                if(	this.ConstrainedRubberbandSelection &&
                                    this.MultiSelect == TreeViewMultiSelect.MultiSameLevel)
                                {
                                    if(iMouseDownTreeNodeLevel == GetTreeNodeLevel(tn))
                                    {
                                        SelectNode(tn, false);
                                    }
                                }
                                else if(this.ConstrainedRubberbandSelection &&
                                    this.MultiSelect == TreeViewMultiSelect.MultiSameBranch)
                                {
                                    if(tnMouseDownGrandParent == GetTreeNodeGrandParent(tn))
                                    {
                                        SelectNode(tn, false);
                                    }
                                }
                                else if(this.ConstrainedRubberbandSelection &&
                                    this.MultiSelect == TreeViewMultiSelect.MultiSameBranchAndLevel)
                                {
                                    if(	iMouseDownTreeNodeLevel == GetTreeNodeLevel(tn) &&
                                        tnMouseDownGrandParent == GetTreeNodeGrandParent(tn))
                                    {
                                        SelectNode(tn, false);
                                    }
                                }
                                else if(this.MultiSelect == TreeViewMultiSelect.MultiPathToParent ||
                                    this.MultiSelect == TreeViewMultiSelect.MultiPathToParents ||
                                    this.MultiSelect == TreeViewMultiSelect.SinglePathToParent ||
                                    this.MultiSelect == TreeViewMultiSelect.SinglePathToParents)
                                {
                                    SelectNode(tn, false);
                                }
                                else if(this.MultiSelect == TreeViewMultiSelect.MultiAllDescendants)
                                {
                                    if(MouseModKeyAlt)
                                    {
                                        SelectNode(tn, false);
                                    }
                                    else
                                    {
                                        SelectBranch(tn, true, true, false);
                                    }
                                }
                                else
                                {
                                    if(MouseModKeyAlt)
                                    {
                                        SelectBranch(tn, true, true, false);
                                    }
                                    else
                                    {
                                        SelectNode(tn, false);
                                    }
                                }
                            }

                            #endregion OnMouseMove Selection

                            MoveRubberbandStart();

                            Point ptMouseMoveClientInt = this.PointToClient(ptMouseMoveScreen);

                            //The next line is not used because if the Control is scrolled horizontally while the rubberband is painted it is not cleared properly.
                            //Rectangle rctInvalidate1 = new Rectangle(ptMouseDown.X, ptMouseDown.Y, ptMouseMoveClientInt.X - ptMouseDown.X, ptMouseMoveClientInt.Y - ptMouseDown.Y);
                            Rectangle rctInvalidate1 = new Rectangle(this.ClientRectangle.Left, ptMouseDown.Y, this.ClientRectangle.Width, ptMouseMoveClientInt.Y - ptMouseDown.Y);

                            //Since calling ControlPaint.DrawReversibleFrame with FrameStyle.Thick seems to 'bleed' over the top edge by one
                            //	pixel the following is necessary.
                            if(this.RubberbandSelection == RubberbandSelectionMode.RubberbandSolid)
                            {
                                rctInvalidate1 = GetPositiveRectangle(rctInvalidate1);
                                rctInvalidate1 = new Rectangle(rctInvalidate1.X, rctInvalidate1.Y - 1, rctInvalidate1.Width, rctInvalidate1.Height + 1);
                            }

                            ptMouseDownScreen = this.PointToScreen(ptMouseDown);
                            ptMouseMoveScreen = this.PointToScreen(new Point(e.X, e.Y));
                            ptMouseDownClient = ptMouseDown;
                            ptMouseMoveClient = new Point(e.X, e.Y);

                            Rectangle rctSelection = new Rectangle(ptMouseDownScreen.X, ptMouseDownScreen.Y, ptMouseMoveScreen.X - ptMouseDownScreen.X, ptMouseMoveScreen.Y - ptMouseDownScreen.Y);
                            Rectangle rctSelectionClient = new Rectangle(ptMouseDownClient.X, ptMouseDownClient.Y, ptMouseMoveClient.X - ptMouseDownClient.X, ptMouseMoveClient.Y - ptMouseDownClient.Y);
                            Rectangle rctPositiveSelectionClient = GetPositiveRectangle(rctSelectionClient);
                            Rectangle rctPositiveSelectionClientFrame = GetPositiveRectangleSmaller(rctSelectionClient, this.RubberbandBorderThickness);
                            Rectangle rctPositiveSelectionClientInside = GetPositiveRectangleInside(rctPositiveSelectionClient, this.RubberbandBorderThickness);

                            //This is used in OnMouseUp, OnMouseMove, OnMouseLeave to give more accurate feedback to the OnRubberbandClear EventHandler.
                            rctRubberbandArea = rctPositiveSelectionClient;

                            //The next line is not used because if the Control is scrolled horizontally while the rubberband is painted it is not cleared properly.
                            //Rectangle rctInvalidate2 = new Rectangle(ptMouseDown.X, ptMouseDown.Y, e.X - ptMouseDown.X, e.Y - ptMouseDown.Y);
                            Rectangle rctInvalidate2 = new Rectangle(this.ClientRectangle.Left, ptMouseDown.Y, this.ClientRectangle.Width, e.Y - ptMouseDown.Y);

                            //Invalidate is now done further down.
                            //Two Rectangles need to be Invalidated because the new Rectangle could be bigger than the old one or smaller.
                            //this.Invalidate(GetPositiveRectangle(rctInvalidate1), false);
                            //this.Invalidate(GetPositiveRectangle(rctInvalidate2), false);

                            //Update is now done in the switch-statement below so that the RubberbandSelectionModes that invalidate more
                            //	than rctInvalidate1 and rctInvalidate2 do not cause Update to be called twice.
                            //this.Update(false);

                            #region RubberbandSelection Painting

                            Graphics g = this.CreateGraphics();

                            //When Rectangle is zero-width or zero-height it cannot be painted (that is why there are try-catch-statements below).
                            switch(this.RubberbandSelection)
                            {

                                    #region RubberbandDashed

                                case RubberbandSelectionMode.RubberbandDashed:
                                    this.Invalidate(GetPositiveRectangle(rctInvalidate1), false);
                                    this.Invalidate(GetPositiveRectangle(rctInvalidate2), false);
                                    this.Update(false);

                                    ControlPaint.DrawReversibleFrame(rctSelection, this.BackColor, FrameStyle.Dashed);

                                    break;
                                    #endregion RubberbandDashed

                                    #region RubberbandSolid

                                case RubberbandSelectionMode.RubberbandSolid:
                                    this.Invalidate(GetPositiveRectangle(rctInvalidate1), false);
                                    this.Invalidate(GetPositiveRectangle(rctInvalidate2), false);
                                    this.Update(false);

                                    ControlPaint.DrawReversibleFrame(rctSelection, this.BackColor, FrameStyle.Thick);

                                    break;

                                    #endregion RubberbandSolid

                                    #region SelectionFrame

                                case RubberbandSelectionMode.SelectionFrame:
                                    this.Invalidate(GetPositiveRectangle(rctInvalidate1), false);
                                    this.Invalidate(GetPositiveRectangle(rctInvalidate2), false);
                                    this.Invalidate(rctPositiveSelectionClient, false);
                                    this.Update(false);

                                    try
                                    {
                                        Rectangle rctPositiveSelectionClientInsideTemp = rctPositiveSelectionClientInside;

                                        //Make sure the RubberbandBorderThickness property is used as thickness and not just to not draw in a Rectangle.
                                        if(	rctPositiveSelectionClient.Width - 2 * this.RubberbandBorderThickness < 0 ||
                                            rctPositiveSelectionClient.Height - 2 * this.RubberbandBorderThickness < 0)
                                        {
                                            rctPositiveSelectionClientInsideTemp = new Rectangle(0, 0, 0, 0);
                                        }

                                        ControlPaint.DrawSelectionFrame(g, this.RubberbandSelectionFrameActive, rctPositiveSelectionClient, rctPositiveSelectionClientInsideTemp, this.BackColor);
                                    }
                                    catch
                                    {
                                    }

                                    break;

                                    #endregion SelectionFrame

                                    #region Frame

                                case RubberbandSelectionMode.Frame:
                                    this.Invalidate(GetPositiveRectangle(rctInvalidate1), false);
                                    this.Invalidate(GetPositiveRectangle(rctInvalidate2), false);
                                    this.Invalidate(rctPositiveSelectionClient, false);
                                    this.Update(false);

                                    try
                                    {
                                        g.DrawRectangle(new Pen(this.RubberbandBorderColor, (int)this.RubberbandBorderThickness), rctPositiveSelectionClientFrame);
                                    }
                                    catch
                                    {
                                    }

                                    break;

                                    #endregion Frame

                                    #region Fill

                                case RubberbandSelectionMode.Fill:
                                    this.Invalidate(GetPositiveRectangle(rctInvalidate1), false);
                                    this.Invalidate(GetPositiveRectangle(rctInvalidate2), false);
                                    this.Invalidate(rctPositiveSelectionClient, false);
                                    this.Update(false);

                                    try
                                    {
                                        if(this.UseRubberbandBorder)
                                        {
                                            g.DrawRectangle(new Pen(this.RubberbandBorderColor, (int)this.RubberbandBorderThickness), rctPositiveSelectionClientFrame);
                                        }
                                    }
                                    catch
                                    {
                                    }

                                    try
                                    {
                                        if(this.UseRubberbandBorder)
                                        {
                                            g.FillRectangle(new SolidBrush(this.RubberbandFillColor), rctPositiveSelectionClientInside);
                                        }
                                        else
                                        {
                                            g.FillRectangle(new SolidBrush(this.RubberbandFillColor), rctPositiveSelectionClient);
                                        }
                                    }
                                    catch
                                    {
                                    }

                                    break;

                                    #endregion Fill

                                    #region Hatch

                                case RubberbandSelectionMode.Hatch:
                                    this.Invalidate(GetPositiveRectangle(rctInvalidate1), false);
                                    this.Invalidate(GetPositiveRectangle(rctInvalidate2), false);
                                    this.Invalidate(rctPositiveSelectionClient, false);
                                    this.Update(false);

                                    try
                                    {
                                        if(this.UseRubberbandBorder)
                                        {
                                            g.DrawRectangle(new Pen(this.RubberbandBorderColor, (int)this.RubberbandBorderThickness), rctPositiveSelectionClientFrame);
                                        }
                                    }
                                    catch
                                    {
                                    }

                                    try
                                    {
                                        if(this.UseRubberbandBorder)
                                        {
                                            g.FillRectangle(new HatchBrush(this.RubberbandHatchStyle, this.RubberbandHatchForeColor, this.RubberbandHatchBackColor), rctPositiveSelectionClientInside);
                                        }
                                        else
                                        {
                                            g.FillRectangle(new HatchBrush(this.RubberbandHatchStyle, this.RubberbandHatchForeColor, this.RubberbandHatchBackColor), rctPositiveSelectionClient);
                                        }
                                    }
                                    catch
                                    {
                                    }

                                    //Here is an example of painting everything to an image and then updating and displaying the image.
                                    //	I experienced no speed increase what-so-ever using this method.
                                    //
                                    //Rectangle rctPositiveSelectionClientInsideOrigo = new Rectangle(Point.Empty, rctPositiveSelectionClientInside.Size - new Size(2, 2));
                                    //Rectangle rctPositiveSelectionClientFrameOrigo = new Rectangle(Point.Empty, rctPositiveSelectionClientFrame.Size - new Size(2, 2));
                                    //
                                    //try
                                    //{
                                    //	Bitmap bmp = new Bitmap(rctPositiveSelectionClientInside.Width, rctPositiveSelectionClientInside.Height);
                                    //	Image img = (Image)bmp;
                                    //	Graphics gnew = Graphics.FromImage(img);
                                    //	gnew.DrawRectangle(new Pen(this.RubberbandBorderColor, (int)this.RubberbandBorderThickness), rctPositiveSelectionClientFrameOrigo);
                                    //	gnew.FillRectangle(new HatchBrush(this.RubberbandHatchStyle, this.RubberbandHatchForeColor, this.RubberbandHatchBackColor), rctPositiveSelectionClientInsideOrigo);
                                    //	gnew.Dispose();
                                    //
                                    //	this.Invalidate(GetPositiveRectangle(rctInvalidate1), false);
                                    //	this.Invalidate(GetPositiveRectangle(rctInvalidate2), false);
                                    //	this.Invalidate(rctPositiveSelectionClient, false);
                                    //	this.Update(false);
                                    //
                                    //	g.DrawImage(img, rctPositiveSelectionClient, 0, 0, img.Width, img.Height, GraphicsUnit.Pixel);
                                    //}
                                    //catch(Exception ex)
                                    //{
                                    //	int a = 0;
                                    //}

                                    break;

                                    #endregion Hatch

                                    #region Texture

                                    //case RubberbandSelectionMode.Texture:
                                    //	this.Invalidate(GetPositiveRectangle(rctInvalidate1), false);
                                    //	this.Invalidate(GetPositiveRectangle(rctInvalidate2), false);
                                    //	this.Invalidate(rctPositiveSelectionClient, false);
                                    //	this.Update(false);
                                    //	//NOT IMPLEMENTED YET.
                                    //
                                    //	try
                                    //	{
                                    //		if(this.UseRubberbandBorder)
                                    //		{
                                    //			g.DrawRectangle(new Pen(this.RubberbandBorderColor, (int)this.RubberbandBorderThickness), rctPositiveSelectionClientFrame);
                                    //		}
                                    //	}
                                    //	catch
                                    //	{
                                    //	}
                                    //
                                    //	try
                                    //	{
                                    //		//DRAW USING TEXTURE BRUSH.
                                    //
                                    //		Image imgTexture = Image.FromFile("background.jpg");
                                    //		//Image imgTexture = Image.FromFile("test_001a.png");
                                    //		//Image imgTexture = Image.FromFile("background_32x32.png");
                                    //
                                    //		//g.FillRectangle(new TextureBrush(img, rct, ImageAttributes), rct);
                                    //		//g.FillRectangle(new TextureBrush(img, rct), rct);
                                    //		//g.FillRectangle(new TextureBrush(img, WrapMode, rct), rct);
                                    //		//g.FillRectangle(new TextureBrush(img, WrapMode), rct);
                                    //		//g.FillRectangle(new TextureBrush(img), rct);
                                    //
                                    //		ImageAttributes iaTexture = new ImageAttributes();
                                    //		ColorMatrix cm = new ColorMatrix();
                                    //		cm.Matrix00 = 1.0f;
                                    //		cm.Matrix01 = 0.0f;
                                    //		cm.Matrix02 = 0.0f;
                                    //		cm.Matrix03 = 0.0f;
                                    //		cm.Matrix04 = 0.0f;
                                    //		cm.Matrix10 = 0.0f;
                                    //		cm.Matrix11 = 1.0f;
                                    //		cm.Matrix12 = 0.0f;
                                    //		cm.Matrix13 = 0.0f;
                                    //		cm.Matrix14 = 0.0f;
                                    //		cm.Matrix20 = 0.0f;
                                    //		cm.Matrix21 = 0.0f;
                                    //		cm.Matrix22 = 1.0f;
                                    //		cm.Matrix23 = 0.0f;
                                    //		cm.Matrix24 = 0.0f;
                                    //		cm.Matrix30 = 0.0f;
                                    //		cm.Matrix31 = 0.0f;
                                    //		cm.Matrix32 = 0.0f;
                                    //		cm.Matrix33 = 0.5f;
                                    //		cm.Matrix34 = 0.0f;
                                    //		cm.Matrix40 = 0.0f;
                                    //		cm.Matrix41 = 0.0f;
                                    //		cm.Matrix42 = 0.0f;
                                    //		cm.Matrix43 = 0.0f;
                                    //		cm.Matrix44 = 1.0f;
                                    //		iaTexture.SetColorMatrix(cm);
                                    //
                                    //		//Convert to grayscale:
                                    //		//cm = new ColorMatrix(new float[][]{	new float[]{0.3f,0.3f,0.3f,0,0},
                                    //		//										new float[]{0.59f,0.59f,0.59f,0,0},
                                    //		//										new float[]{0.11f,0.11f,0.11f,0,0},
                                    //		//										new float[]{0,0,0,1,0,0},
                                    //		//										new float[]{0,0,0,0,1,0},
                                    //		//										new float[]{0,0,0,0,0,1}});
                                    //		//iaTexture.SetColorMatrix(cm);
                                    //
                                    //		//iaTexture.SetWrapMode(WrapMode.Tile);
                                    //		g.FillRectangle(new TextureBrush(imgTexture, rctPositiveSelectionClientInside, iaTexture), rctPositiveSelectionClientInside);
                                    //		//g.DrawImage(imgTexture, rctPositiveSelectionClientInside, 0, 0, imgTexture.Width, imgTexture.Height, GraphicsUnit.Pixel, iaTexture);
                                    //		//g.FillRectangle(new TextureBrush(imgTexture), rctPositiveSelectionClientInside);
                                    //	}
                                    //	catch(Exception ex)
                                    //	{
                                    //		//Out of memory.
                                    //		int a = 0;
                                    //	}
                                    //
                                    //	break;

                                    #endregion Texture

                                    #region Gradient

                                case RubberbandSelectionMode.Gradient:
                                    try
                                    {
                                        LinearGradientBrush lgb = null;
                                        Rectangle rctGradient = Rectangle.Empty;

                                        if(this.RubberbandGradientPaintMode == GradientPaintMode.MousePoints)
                                        {
                                            if(this.UseRubberbandBorder)
                                            {
                                                lgb = new LinearGradientBrush(new Point(ptMouseDown.X - this.RubberbandBorderThickness, ptMouseDown.Y - this.RubberbandBorderThickness), new Point(e.X - this.RubberbandBorderThickness, e.Y - this.RubberbandBorderThickness), this.RubberbandGradientColor1, this.RubberbandGradientColor2);
                                                rctGradient = rctPositiveSelectionClientInside;
                                            }
                                            else
                                            {
                                                lgb = new LinearGradientBrush(ptMouseDown, new Point(e.X, e.Y), this.RubberbandGradientColor1, this.RubberbandGradientColor2);
                                                rctGradient = rctPositiveSelectionClient;
                                            }
                                        }
                                        else if(this.RubberbandGradientPaintMode == GradientPaintMode.Angle)
                                        {
                                            if(this.UseRubberbandBorder)
                                            {
                                                lgb = new LinearGradientBrush(rctPositiveSelectionClientInside, this.RubberbandGradientColor1, this.RubberbandGradientColor2, this.RubberbandGradientAngle, true);
                                                rctGradient = rctPositiveSelectionClientInside;
                                            }
                                            else
                                            {
                                                lgb = new LinearGradientBrush(rctPositiveSelectionClient, this.RubberbandGradientColor1, this.RubberbandGradientColor2, this.RubberbandGradientAngle, true);
                                                rctGradient = rctPositiveSelectionClient;
                                            }
                                        }
                                        else if(this.RubberbandGradientPaintMode == GradientPaintMode.LinearGradientMode)
                                        {
                                            if(this.UseRubberbandBorder)
                                            {
                                                lgb = new LinearGradientBrush(rctPositiveSelectionClientInside, this.RubberbandGradientColor1, this.RubberbandGradientColor2, this.RubberbandGradientLinearGradientMode);
                                                rctGradient = rctPositiveSelectionClientInside;
                                            }
                                            else
                                            {
                                                lgb = new LinearGradientBrush(rctPositiveSelectionClient, this.RubberbandGradientColor1, this.RubberbandGradientColor2, this.RubberbandGradientLinearGradientMode);
                                                rctGradient = rctPositiveSelectionClient;
                                            }
                                        }

                                        if(this.RubberbandGradientShape == GradientShape.Triangular)
                                        {
                                            lgb.SetBlendTriangularShape(this.RubberbandGradientShapeFocus, this.RubberbandGradientShapeScale);
                                        }
                                        else if(this.RubberbandGradientShape == GradientShape.SigmaBell)
                                        {
                                            lgb.SetSigmaBellShape(this.RubberbandGradientShapeFocus, this.RubberbandGradientShapeScale);
                                        }
                                        else if(this.RubberbandGradientShape == GradientShape.Blend && this.RubberbandGradientBlend.Length > 0)
                                        {
                                            Blend bl = new Blend(this.RubberbandGradientBlend.Length);

                                            bl.Factors = MWRubberbandGradientBlend.GetFactorArray(this.RubberbandGradientBlend);
                                            bl.Positions = MWRubberbandGradientBlend.GetPositionArray(this.RubberbandGradientBlend);

                                            lgb.Blend = bl;
                                        }
                                        else if(this.RubberbandGradientShape == GradientShape.ColorBlend && this.RubberbandGradientColorBlend.Length > 0)
                                        {
                                            ColorBlend cbl = new ColorBlend(this.RubberbandGradientColorBlend.Length);

                                            cbl.Colors = MWRubberbandGradientColorBlend.GetColorArray(this.RubberbandGradientColorBlend);
                                            cbl.Positions = MWRubberbandGradientColorBlend.GetPositionArray(this.RubberbandGradientColorBlend);

                                            lgb.InterpolationColors = cbl;
                                        }

                                        this.Invalidate(GetPositiveRectangle(rctInvalidate1), false);
                                        this.Invalidate(GetPositiveRectangle(rctInvalidate2), false);
                                        this.Invalidate(rctPositiveSelectionClient, false);
                                        this.Update(false);

                                        try
                                        {
                                            if(this.UseRubberbandBorder)
                                            {
                                                g.DrawRectangle(new Pen(this.RubberbandBorderColor, (int)this.RubberbandBorderThickness), rctPositiveSelectionClientFrame);
                                            }
                                        }
                                        catch
                                        {
                                        }

                                        g.FillRectangle(lgb, rctGradient);

                                        lgb.Dispose();
                                    }
                                    catch
                                    {
                                    }

                                    break;

                                    #endregion Gradient

                                    #region PathGradient

                                    //case RubberbandSelectionMode.PathGradient:
                                    //	this.Invalidate(GetPositiveRectangle(rctInvalidate1), false);
                                    //	this.Invalidate(GetPositiveRectangle(rctInvalidate2), false);
                                    //	this.Invalidate(rctPositiveSelectionClient, false);
                                    //	this.Update(false);
                                    //	//NOT IMPLEMENTED YET.
                                    //
                                    //	try
                                    //	{
                                    //		if(this.UseRubberbandBorder)
                                    //		{
                                    //			g.DrawRectangle(new Pen(this.RubberbandBorderColor, (int)this.RubberbandBorderThickness), rctPositiveSelectionClientFrame);
                                    //		}
                                    //	}
                                    //	catch
                                    //	{
                                    //	}
                                    //
                                    //	//DRAW USING PATH GRADIENT BRUSH.
                                    //
                                    //	break;

                                    #endregion PathGradient

                                    #region Custom

                                case RubberbandSelectionMode.Custom:

                                    //Clearing.
                                    Rectangle rctClearArea = Rectangle.Union(GetPositiveRectangle(rctInvalidate1), GetPositiveRectangle(rctInvalidate2));
                                    rctClearArea = Rectangle.Union(rctClearArea, rctPositiveSelectionClient);

                                    MWRubberbandClearEventArgs ce = new MWRubberbandClearEventArgs(rctClearArea, rctPositiveSelectionClient);

                                    try
                                    {
                                        OnRubberbandClear(ce);

                                        this.Invalidate(ce.ClearArea, false);
                                        this.Update();
                                    }
                                    catch
                                    {
                                        this.Invalidate(rctClearArea, false);
                                        this.Update();
                                    }

                                    //Painting.
                                    MWRubberbandPaintEventArgs pe = new MWRubberbandPaintEventArgs(g, rctPositiveSelectionClientInside, rctPositiveSelectionClient, ptMouseDownClient, ptMouseMoveClient, this.UseRubberbandBorder);

                                    try
                                    {
                                        OnRubberbandPaint(pe);
                                    }
                                    catch
                                    {
                                    }

                                    //Note that the border is painted last since there is the option of overriding the border painting through
                                    //	the EventHandler.
                                    if(pe.MWTreeViewPaintBorder)
                                    {
                                        try
                                        {
                                            g.DrawRectangle(new Pen(this.RubberbandBorderColor, (int)this.RubberbandBorderThickness), rctPositiveSelectionClientFrame);
                                        }
                                        catch
                                        {
                                        }
                                    }

                                    break;

                                    #endregion Custom

                                    #region Image

                                case RubberbandSelectionMode.Image:

                                    Rectangle rctImageSource = Rectangle.Empty;

                                    ImageAttributes iaImage = new ImageAttributes();

                                    try
                                    {
                                        if(this.RubberbandImageScaleCorrection)
                                        {
                                            rctImageSource = new Rectangle(0, 0, this.RubberbandImage.Size.Width - 1, this.RubberbandImage.Size.Height - 1);
                                        }
                                        else
                                        {
                                            rctImageSource = new Rectangle(Point.Empty, this.RubberbandImage.Size);
                                        }

                                        if(this.RubberbandImageTransparency != 1.0f)
                                        {
                                            ColorMatrix cmImage = new ColorMatrix();
                                            //cmImage.Matrix00 = 1.0f;	//Red (already set to 1.0f, so no need to change)
                                            //cmImage.Matrix11 = 1.0f;	//Green (already set to 1.0f, so no need to change)
                                            //cmImage.Matrix22 = 1.0f;	//Blue (already set to 1.0f, so no need to change)
                                            cmImage.Matrix33 = this.RubberbandImageTransparency;	//Transparency
                                            iaImage.SetColorMatrix(cmImage, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
                                        }
                                    }
                                    catch
                                    {
                                    }

                                    //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
                                    //ImageAttributes ia = new ImageAttributes();
                                    //ia.SetGamma(fGamma);
                                    //ia.SetColorMatrix(cm);
                                    //g.InterpolationMode = InterpolationMode.Default;
                                    //g.SmoothingMode = SmoothingMode.Default;
                                    //g.Transform = new Matrix();

                                    this.Invalidate(GetPositiveRectangle(rctInvalidate1), false);
                                    this.Invalidate(GetPositiveRectangle(rctInvalidate2), false);
                                    this.Invalidate(rctPositiveSelectionClient, false);
                                    this.Update(false);

                                    try
                                    {
                                        if(this.UseRubberbandBorder)
                                        {
                                            g.DrawRectangle(new Pen(this.RubberbandBorderColor, (int)this.RubberbandBorderThickness), rctPositiveSelectionClientFrame);
                                        }
                                    }
                                    catch
                                    {
                                    }

                                    try
                                    {
                                        if(this.UseRubberbandBorder)
                                        {
                                            if(this.RubberbandImageTransparency != 1.0f)
                                            {
                                                g.DrawImage(this.RubberbandImage, rctPositiveSelectionClientInside, 0, 0, rctImageSource.Width, rctImageSource.Height, GraphicsUnit.Pixel, iaImage);
                                            }
                                            else
                                            {
                                                g.DrawImage(this.RubberbandImage, rctPositiveSelectionClientInside, 0, 0, rctImageSource.Width, rctImageSource.Height, GraphicsUnit.Pixel);
                                            }
                                        }
                                        else
                                        {
                                            if(this.RubberbandImageTransparency != 1.0f)
                                            {
                                                g.DrawImage(this.RubberbandImage, rctPositiveSelectionClient, 0, 0, rctImageSource.Width, rctImageSource.Height, GraphicsUnit.Pixel, iaImage);
                                            }
                                            else
                                            {
                                                g.DrawImage(this.RubberbandImage, rctPositiveSelectionClient, 0, 0, rctImageSource.Width, rctImageSource.Height, GraphicsUnit.Pixel);
                                            }
                                        }
                                    }
                                    catch
                                    {
                                    }

                                    break;

                                    #endregion Image

                                default:
                                    this.Update(false);
                                    //Should never end up here.
                                    break;
                            }

                            //Testing.
                            //g.DrawString(rctPositiveSelectionClient.ToString(), new Font("Arial", 12), new SolidBrush(Color.Black), rctPositiveSelectionClient);

                            #endregion RubberbandSelection Painting

                            bUpdated = false;

                        }
                        else if(!(ptMouseDownScreen == this.PointToScreen(ptMouseDown) &&
                            ptMouseMoveScreen == this.PointToScreen(new Point(e.X, e.Y))) ||
                            bRubberbandStartMoved)
                        {
                            //End up here if wheel scrolled away and then back to the same position.
                            //This will make it update the rubberband to the current position.

                            bRubberbandStartMoved = false;
                            bUpdated = true;
                        }
                        else if(this.GetNodeAt(ptMouseDownOrig) != null &&
                            this.TreeNodeMouseDownInt != null &&
                            this.GetNodeAt(e.X, e.Y) != null &&
                            this.GetNodeAt(ptMouseDownOrig) != this.TreeNodeMouseDownInt)
                        {
                            //End up here if wheel scrolled away.
                            //This will make it update the rubberband to the current position.

                            bRubberbandStartMoved = false;
                            bUpdated = true;
                        }

                        bRubberbandHasBeenPainted = true;
                    }

                        #region Selection

                    else if(e.Button == MouseButtons.Left && this.FullRowSelect && tn != null)
                    {
                        if(!bExpandInProgress && !bCollapseInProgress)
                        {
                            if(!MouseModKeyControl)
                            {
                                this.ClearSelNodes(this.TreeNodeMouseDownInt);
                            }

                            if(	this.ConstrainedRubberbandSelection &&
                                this.MultiSelect == TreeViewMultiSelect.MultiSameLevel)
                            {
                                if(iMouseDownTreeNodeLevel == GetTreeNodeLevel(this.TreeNodeMouseDownInt))
                                {
                                    SelectNode(this.TreeNodeMouseDownInt, false);
                                }
                            }
                            else if(this.ConstrainedRubberbandSelection &&
                                this.MultiSelect == TreeViewMultiSelect.MultiSameBranch)
                            {
                                if(tnMouseDownGrandParent == GetTreeNodeGrandParent(this.TreeNodeMouseDownInt))
                                {
                                    SelectNode(this.TreeNodeMouseDownInt, false);
                                }
                            }
                            else if(this.ConstrainedRubberbandSelection &&
                                this.MultiSelect == TreeViewMultiSelect.MultiSameBranchAndLevel)
                            {
                                if(	iMouseDownTreeNodeLevel == GetTreeNodeLevel(this.TreeNodeMouseDownInt) &&
                                    tnMouseDownGrandParent == GetTreeNodeGrandParent(this.TreeNodeMouseDownInt))
                                {
                                    SelectNode(this.TreeNodeMouseDownInt, false);
                                }
                            }
                            else if(this.MultiSelect == TreeViewMultiSelect.MultiPathToParent ||
                                this.MultiSelect == TreeViewMultiSelect.MultiPathToParents ||
                                this.MultiSelect == TreeViewMultiSelect.SinglePathToParent ||
                                this.MultiSelect == TreeViewMultiSelect.SinglePathToParents)
                            {
                                SelectNode(this.TreeNodeMouseDownInt, false);
                            }
                            else if(this.MultiSelect == TreeViewMultiSelect.MultiAllDescendants)
                            {
                                if(MouseModKeyAlt)
                                {
                                    SelectNode(this.TreeNodeMouseDownInt, false);
                                }
                                else
                                {
                                    SelectBranch(this.TreeNodeMouseDownInt, true, true, false);
                                }
                            }
                            else
                            {
                                if(MouseModKeyAlt)
                                {
                                    SelectBranch(this.TreeNodeMouseDownInt, true, true, false);
                                }
                                else
                                {
                                    SelectNode(this.TreeNodeMouseDownInt, false);
                                }
                            }
                        }
                    }

                        #endregion Selection

                    else if(bRubberbandHasBeenPainted)
                    {
                        switch(this.RubberbandSelection)
                        {
                            case RubberbandSelectionMode.RubberbandDashed:
                                ControlPaint.DrawReversibleFrame(new Rectangle(ptMouseDownScreen.X, ptMouseDownScreen.Y, ptMouseMoveScreen.X - ptMouseDownScreen.X, ptMouseMoveScreen.Y - ptMouseDownScreen.Y), this.BackColor, FrameStyle.Dashed);
                                break;

                            case RubberbandSelectionMode.RubberbandSolid:
                                ControlPaint.DrawReversibleFrame(new Rectangle(ptMouseDownScreen.X, ptMouseDownScreen.Y, ptMouseMoveScreen.X - ptMouseDownScreen.X, ptMouseMoveScreen.Y - ptMouseDownScreen.Y), this.BackColor, FrameStyle.Thick);
                                break;

                            case RubberbandSelectionMode.SelectionFrame:
                            case RubberbandSelectionMode.Frame:
                            case RubberbandSelectionMode.Fill:
                            case RubberbandSelectionMode.Hatch:
                                //case RubberbandSelectionMode.Texture:
                            case RubberbandSelectionMode.Gradient:
                                //case RubberbandSelectionMode.PathGradient:
                            case RubberbandSelectionMode.Image:
                                this.Invalidate(new Rectangle(ptMouseDownClient.X, ptMouseDownClient.Y, ptMouseMoveClient.X - ptMouseDownClient.X, ptMouseMoveClient.Y - ptMouseDownClient.Y), false);
                                this.Update(false);
                                break;

                            case RubberbandSelectionMode.Custom:
                                MWRubberbandClearEventArgs ce = new MWRubberbandClearEventArgs(GetPositiveRectangle(new Rectangle(ptMouseDownClient.X, ptMouseDownClient.Y, ptMouseMoveClient.X - ptMouseDownClient.X, ptMouseMoveClient.Y - ptMouseDownClient.Y)), rctRubberbandArea);

                                try
                                {
                                    OnRubberbandClear(ce);

                                    this.Invalidate(ce.ClearArea, false);
                                    this.Update();
                                }
                                catch
                                {
                                    this.Invalidate(new Rectangle(ptMouseDownClient.X, ptMouseDownClient.Y, ptMouseMoveClient.X - ptMouseDownClient.X, ptMouseMoveClient.Y - ptMouseDownClient.Y), false);
                                    this.Update();
                                }

                                break;

                            default:
                                //RubberbandSelectionMode.None ends up here
                                break;
                        }

                        bRubberbandHasBeenPainted = false;
                    }
                }
                else if(bRubberbandHasBeenPainted)
                {
                    switch(this.RubberbandSelection)
                    {
                        case RubberbandSelectionMode.RubberbandDashed:
                            ControlPaint.DrawReversibleFrame(new Rectangle(ptMouseDownScreen.X, ptMouseDownScreen.Y, ptMouseMoveScreen.X - ptMouseDownScreen.X, ptMouseMoveScreen.Y - ptMouseDownScreen.Y), this.BackColor, FrameStyle.Dashed);
                            break;

                        case RubberbandSelectionMode.RubberbandSolid:
                            ControlPaint.DrawReversibleFrame(new Rectangle(ptMouseDownScreen.X, ptMouseDownScreen.Y, ptMouseMoveScreen.X - ptMouseDownScreen.X, ptMouseMoveScreen.Y - ptMouseDownScreen.Y), this.BackColor, FrameStyle.Thick);
                            break;

                        case RubberbandSelectionMode.SelectionFrame:
                        case RubberbandSelectionMode.Frame:
                        case RubberbandSelectionMode.Fill:
                        case RubberbandSelectionMode.Hatch:
                            //case RubberbandSelectionMode.Texture:
                        case RubberbandSelectionMode.Gradient:
                            //case RubberbandSelectionMode.PathGradient:
                        case RubberbandSelectionMode.Image:
                            this.Invalidate(new Rectangle(ptMouseDownClient.X, ptMouseDownClient.Y, ptMouseMoveClient.X - ptMouseDownClient.X, ptMouseMoveClient.Y - ptMouseDownClient.Y), false);
                            this.Update(false);
                            break;

                        case RubberbandSelectionMode.Custom:
                            MWRubberbandClearEventArgs ce = new MWRubberbandClearEventArgs(GetPositiveRectangle(new Rectangle(ptMouseDownClient.X, ptMouseDownClient.Y, ptMouseMoveClient.X - ptMouseDownClient.X, ptMouseMoveClient.Y - ptMouseDownClient.Y)), rctRubberbandArea);

                            try
                            {
                                OnRubberbandClear(ce);

                                this.Invalidate(ce.ClearArea, false);
                                this.Update();
                            }
                            catch
                            {
                                this.Invalidate(new Rectangle(ptMouseDownClient.X, ptMouseDownClient.Y, ptMouseMoveClient.X - ptMouseDownClient.X, ptMouseMoveClient.Y - ptMouseDownClient.Y), false);
                                this.Update();
                            }

                            break;

                        default:
                            //RubberbandSelectionMode.None ends up here
                            break;
                    }

                    bRubberbandHasBeenPainted = false;
                }
            }

            base.OnMouseMove(e);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Standard OnMouseUp EventHandler.
        /// </summary>
        /// <param name="e">Standard MouseEventArgs object.</param>
        protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e)
        {
            //Nice little way of finding out exactly where the mouse was released.
            //TreeNode tnDebug = this.GetNodeAt(e.X, e.Y);
            //if(tnDebug != null)
            //{
            //	Debug.WriteLine("------------------------------- " + tnDebug.Text);
            //	Debug.WriteLine("IsPointOnTreeNode             : " + IsPointOnTreeNode(tnDebug, ptMouseDown));
            //	Debug.WriteLine("IsPointOnTreeNodeText         : " + IsPointOnTreeNodeText(tnDebug, ptMouseDown));
            //	Debug.WriteLine("IsPointOnTreeNodeTextExact    : " + IsPointOnTreeNodeTextExact(tnDebug, ptMouseDown));
            //	Debug.WriteLine("IsPointOnTreeNodeRow          : " + IsPointOnTreeNodeRow(tnDebug, ptMouseDown));
            //	Debug.WriteLine("IsPointOnTreeNodeImage        : " + IsPointOnTreeNodeImage(tnDebug, ptMouseDown));
            //	Debug.WriteLine("IsPointOnTreeNodeImageExact   : " + IsPointOnTreeNodeImageExact(tnDebug, ptMouseDown));
            //	Debug.WriteLine("IsPointOnTreeNodeCheckBox     : " + IsPointOnTreeNodeCheckBox(tnDebug, ptMouseDown));
            //	Debug.WriteLine("IsPointOnTreeNodeCheckBoxExact: " + IsPointOnTreeNodeCheckBoxExact(tnDebug, ptMouseDown));
            //	Debug.WriteLine("IsPointLeftOfTreeNode         : " + IsPointLeftOfTreeNode(tnDebug, ptMouseDown));
            //	Debug.WriteLine("IsPointRightOfTreeNode        : " + IsPointRightOfTreeNode(tnDebug, ptMouseDown));
            //	Debug.WriteLine("-------------------------------------");
            //}
            //else
            //{
            //	Debug.WriteLine("TreeNode is NULL");
            //}

            if(this.MultiSelect != TreeViewMultiSelect.Classic)
            {
                if(this.ExtendedTemporaryMarking && !bTNDone && tnTNDown != null && !IsTreeNodeSelected(tnTNDown))
                {
                    bTNDone = true;
                    tnTNDown.BackColor = cBackColorTNDown;
                    tnTNDown.ForeColor = cForeColorTNDown;
                }

                TreeNode tn = this.GetNodeAt(e.X, e.Y);

                if(	this.ConstrainedRubberbandSelection &&
                    (
                    this.MultiSelect == TreeViewMultiSelect.MultiSameLevel ||
                    this.MultiSelect == TreeViewMultiSelect.MultiSameBranch ||
                    this.MultiSelect == TreeViewMultiSelect.MultiSameBranchAndLevel
                    ) &&
                    tn != null &&
                    tn != tnMouseDown &&
                    !IsTreeNodeSelected(tn))
                {
                    TreeNode tnTemp = tnMouseDown;

                    bool bPrevious = false;

                    while(tnTemp != null && tnTemp.PrevVisibleNode != null && tnTemp != tn)
                    {
                        if(tnTemp.PrevVisibleNode == tn)
                        {
                            bPrevious = true;
                            break;
                        }

                        tnTemp = tnTemp.PrevVisibleNode;
                    }

                    if(bPrevious)
                    {
                        tnTemp = tn;

                        while(!IsTreeNodeSelected(tnTemp))
                        {
                            if(tnTemp.NextVisibleNode != null)
                            {
                                tnTemp = tnTemp.NextVisibleNode;
                            }
                            else
                            {
                                break;
                            }
                        }

                        tn = tnTemp;
                    }
                    else
                    {
                        tnTemp = tn;

                        while(!IsTreeNodeSelected(tnTemp))
                        {
                            if(tnTemp.PrevVisibleNode != null)
                            {
                                tnTemp = tnTemp.PrevVisibleNode;
                            }
                            else
                            {
                                break;
                            }
                        }

                        tn = tnTemp;
                    }
                }

                if(bRubberbandIsOnScreen && bRubberbandHasBeenPainted)
                {
                    switch(this.RubberbandSelection)
                    {
                        case RubberbandSelectionMode.RubberbandDashed:
                            ControlPaint.DrawReversibleFrame(new Rectangle(ptMouseDownScreen.X, ptMouseDownScreen.Y, ptMouseMoveScreen.X - ptMouseDownScreen.X, ptMouseMoveScreen.Y - ptMouseDownScreen.Y), this.BackColor, FrameStyle.Dashed);
                            break;

                        case RubberbandSelectionMode.RubberbandSolid:
                            ControlPaint.DrawReversibleFrame(new Rectangle(ptMouseDownScreen.X, ptMouseDownScreen.Y, ptMouseMoveScreen.X - ptMouseDownScreen.X, ptMouseMoveScreen.Y - ptMouseDownScreen.Y), this.BackColor, FrameStyle.Thick);
                            break;

                        case RubberbandSelectionMode.SelectionFrame:
                        case RubberbandSelectionMode.Frame:
                        case RubberbandSelectionMode.Fill:
                        case RubberbandSelectionMode.Hatch:
                            //case RubberbandSelectionMode.Texture:
                        case RubberbandSelectionMode.Gradient:
                            //case RubberbandSelectionMode.PathGradient:
                        case RubberbandSelectionMode.Image:
                            this.Invalidate(new Rectangle(ptMouseDownClient.X, ptMouseDownClient.Y, ptMouseMoveClient.X - ptMouseDownClient.X, ptMouseMoveClient.Y - ptMouseDownClient.Y), false);
                            this.Update();
                            break;

                        case RubberbandSelectionMode.Custom:
                            MWRubberbandClearEventArgs ce = new MWRubberbandClearEventArgs(GetPositiveRectangle(new Rectangle(ptMouseDownClient.X, ptMouseDownClient.Y, ptMouseMoveClient.X - ptMouseDownClient.X, ptMouseMoveClient.Y - ptMouseDownClient.Y)), rctRubberbandArea);

                            try
                            {
                                OnRubberbandClear(ce);

                                this.Invalidate(ce.ClearArea, false);
                                this.Update();
                            }
                            catch
                            {
                                this.Invalidate(new Rectangle(ptMouseDownClient.X, ptMouseDownClient.Y, ptMouseMoveClient.X - ptMouseDownClient.X, ptMouseMoveClient.Y - ptMouseDownClient.Y), false);
                                this.Update();
                            }

                            break;

                        default:
                            //RubberbandSelectionMode.None ends up here
                            break;
                    }

                    tRubberbandUpdate.Stop();

                    SelectNode(tn, true);

                    BeginAllowLabelEditing();
                }
                else
                {
                    if(tnFullRowSelect != null)
                    {
                        if(	this.FullRowSelect &&
                            bFullRowSelectNodeSelected == IsTreeNodeSelected(tnFullRowSelect) &&
                            bFullRowSelectNodeChecked == tnFullRowSelect.Checked &&
                            bFullRowSelectNodeExpanded == tnFullRowSelect.IsExpanded &&
                            !bExpandInProgress && !bCollapseInProgress)
                        {
                            BeforeSelectMethod(tnFullRowSelect);
                        }
                    }
                }

                if(	e.Button == MouseButtons.Left &&
                    !MouseModKeyAlt &&
                    !MouseModKeyControl &&
                    !MouseModKeyShift &&
                    AllowMouseClearSelNodes(tn, new Point(e.X, e.Y)))
                {
                    if(	(bRubberbandIsOnScreen && bRubberbandHasBeenPainted && tnMouseDown == null) ||
                        (!(bRubberbandIsOnScreen && bRubberbandHasBeenPainted)))
                    {
                        if(this.AllowNoSelNode)
                        {
                            this.SelNodeInt = null;
                            this.ClearSelNodes();
                        }
                        else
                        {
                            this.ClearSelNodes(this.SelNode);
                        }
                    }
                }

                tnFullRowSelect = null;

                bRubberbandIsOnScreen = false;
                bRubberbandHasBeenPainted = false;
            }

            base.OnMouseUp(e);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Standard OnMouseLeave EventHandler.
        /// </summary>
        /// <param name="e">Standard EventArgs object.</param>
        protected override void OnMouseLeave(System.EventArgs e)
        {
            if(this.MultiSelect != TreeViewMultiSelect.Classic)
            {
                if(bRubberbandHasBeenPainted)
                {
                    switch(this.RubberbandSelection)
                    {
                        case RubberbandSelectionMode.RubberbandDashed:
                            ControlPaint.DrawReversibleFrame(new Rectangle(ptMouseDownScreen.X, ptMouseDownScreen.Y, ptMouseMoveScreen.X - ptMouseDownScreen.X, ptMouseMoveScreen.Y - ptMouseDownScreen.Y), this.BackColor, FrameStyle.Dashed);
                            break;

                        case RubberbandSelectionMode.RubberbandSolid:
                            ControlPaint.DrawReversibleFrame(new Rectangle(ptMouseDownScreen.X, ptMouseDownScreen.Y, ptMouseMoveScreen.X - ptMouseDownScreen.X, ptMouseMoveScreen.Y - ptMouseDownScreen.Y), this.BackColor, FrameStyle.Thick);
                            break;

                        case RubberbandSelectionMode.SelectionFrame:
                        case RubberbandSelectionMode.Frame:
                        case RubberbandSelectionMode.Fill:
                        case RubberbandSelectionMode.Hatch:
                            //case RubberbandSelectionMode.Texture:
                        case RubberbandSelectionMode.Gradient:
                            //case RubberbandSelectionMode.PathGradient:
                        case RubberbandSelectionMode.Image:
                            this.Invalidate(new Rectangle(ptMouseDownClient.X, ptMouseDownClient.Y, ptMouseMoveClient.X - ptMouseDownClient.X, ptMouseMoveClient.Y - ptMouseDownClient.Y), false);
                            this.Update();
                            break;

                        case RubberbandSelectionMode.Custom:
                            MWRubberbandClearEventArgs ce = new MWRubberbandClearEventArgs(GetPositiveRectangle(new Rectangle(ptMouseDownClient.X, ptMouseDownClient.Y, ptMouseMoveClient.X - ptMouseDownClient.X, ptMouseMoveClient.Y - ptMouseDownClient.Y)), rctRubberbandArea);

                            try
                            {
                                OnRubberbandClear(ce);

                                this.Invalidate(ce.ClearArea, false);
                                this.Update();
                            }
                            catch
                            {
                                this.Invalidate(new Rectangle(ptMouseDownClient.X, ptMouseDownClient.Y, ptMouseMoveClient.X - ptMouseDownClient.X, ptMouseMoveClient.Y - ptMouseDownClient.Y), false);
                                this.Update();
                            }

                            break;

                        default:
                            //RubberbandSelectionMode.None ends up here
                            break;
                    }

                    if(!this.AllowOutOfFocusRubberbandSelection)
                    {
                        tRubberbandUpdate.Stop();
                    }

                    bRubberbandHasBeenPainted = false;

                    //Make sure that the SelNode gets set when the mouse leaves the MWTreeView, if there are any selected TreeNodes that is.
                    TreeNode tn = GetNodeAt(ptMouseMoveClient);

                    if(this.SelNodes.Count > 0 && tn != null)
                    {
                        if(IsTreeNodeSelected(tn))
                        {
                            this.SelNodeInt = tn;
                        }
                        else if(this.SelNodes.Count > 0)
                        {
                            tn = this.TopNode;

                            //Look for the last visible TreeNode
                            while(tn != tn.NextVisibleNode && tn.NextVisibleNode != null)
                            {
                                tn = tn.NextVisibleNode;
                            }

                            //Iterate from the bottom and up and set the the SelNode property to the first selected TreeNode encountered.
                            while(tn != tn.PrevVisibleNode && tn.PrevVisibleNode != null)
                            {
                                if(IsTreeNodeSelected(tn))
                                {
                                    break;
                                }
                                else
                                {
                                    tn = tn.PrevVisibleNode;
                                }
                            }

                            if(tn != null)
                            {
                                this.SelNodeInt = tn;
                            }
                        }
                    }
                }
            }

            base.OnMouseLeave(e);
        }