--- trunk/deps/WeifenLuo.WinFormsUI.Docking/WinFormsUI/Docking/VS2005AutoHideStrip.cs 2013/06/08 20:02:11 637 +++ trunk/deps/WeifenLuo.WinFormsUI.Docking/WinFormsUI/Docking/VS2005AutoHideStrip.cs 2013/06/08 20:21:53 638 @@ -202,17 +202,24 @@ namespace WeifenLuo.WinFormsUI.Docking protected override void OnPaint(PaintEventArgs e) { - Graphics g = e.Graphics; + try + { + Graphics g = e.Graphics; - Color startColor = DockPanel.Skin.AutoHideStripSkin.DockStripGradient.StartColor; - Color endColor = DockPanel.Skin.AutoHideStripSkin.DockStripGradient.EndColor; - LinearGradientMode gradientMode = DockPanel.Skin.AutoHideStripSkin.DockStripGradient.LinearGradientMode; - using (LinearGradientBrush brush = new LinearGradientBrush(ClientRectangle, startColor, endColor, gradientMode)) + Color startColor = DockPanel.Skin.AutoHideStripSkin.DockStripGradient.StartColor; + Color endColor = DockPanel.Skin.AutoHideStripSkin.DockStripGradient.EndColor; + LinearGradientMode gradientMode = DockPanel.Skin.AutoHideStripSkin.DockStripGradient.LinearGradientMode; + using (LinearGradientBrush brush = new LinearGradientBrush(ClientRectangle, startColor, endColor, gradientMode)) + { + g.FillRectangle(brush, ClientRectangle); + } + + DrawTabStrip(g); + } + catch (Exception) { - g.FillRectangle(brush, ClientRectangle); + throw; } - - DrawTabStrip(g); } protected override void OnLayout(LayoutEventArgs levent) @@ -231,26 +238,33 @@ namespace WeifenLuo.WinFormsUI.Docking private void DrawTabStrip(Graphics g, DockState dockState) { - Rectangle rectTabStrip = GetLogicalTabStripRectangle(dockState); + try + { + Rectangle rectTabStrip = GetLogicalTabStripRectangle(dockState); - if (rectTabStrip.IsEmpty) - return; + if (rectTabStrip.IsEmpty) + return; - Matrix matrixIdentity = g.Transform; - if (dockState == DockState.DockLeftAutoHide || dockState == DockState.DockRightAutoHide) - { - Matrix matrixRotated = new Matrix(); - matrixRotated.RotateAt(90, new PointF((float)rectTabStrip.X + (float)rectTabStrip.Height / 2, - (float)rectTabStrip.Y + (float)rectTabStrip.Height / 2)); - g.Transform = matrixRotated; - } + Matrix matrixIdentity = g.Transform; + if (dockState == DockState.DockLeftAutoHide || dockState == DockState.DockRightAutoHide) + { + Matrix matrixRotated = new Matrix(); + matrixRotated.RotateAt(90, new PointF((float)rectTabStrip.X + (float)rectTabStrip.Height / 2, + (float)rectTabStrip.Y + (float)rectTabStrip.Height / 2)); + g.Transform = matrixRotated; + } - foreach (Pane pane in GetPanes(dockState)) + foreach (Pane pane in GetPanes(dockState)) + { + foreach (TabVS2005 tab in pane.AutoHideTabs) + DrawTab(g, tab); + } + g.Transform = matrixIdentity; + } + catch (Exception) { - foreach (TabVS2005 tab in pane.AutoHideTabs) - DrawTab(g, tab); + throw; } - g.Transform = matrixIdentity; } private void CalculateTabs() @@ -263,123 +277,151 @@ namespace WeifenLuo.WinFormsUI.Docking private void CalculateTabs(DockState dockState) { - Rectangle rectTabStrip = GetLogicalTabStripRectangle(dockState); + try + { + Rectangle rectTabStrip = GetLogicalTabStripRectangle(dockState); - int imageHeight = rectTabStrip.Height - ImageGapTop - ImageGapBottom; - int imageWidth = ImageWidth; - if (imageHeight > ImageHeight) - imageWidth = ImageWidth * (imageHeight / ImageHeight); + int imageHeight = rectTabStrip.Height - ImageGapTop - ImageGapBottom; + int imageWidth = ImageWidth; + if (imageHeight > ImageHeight) + imageWidth = ImageWidth * (imageHeight / ImageHeight); - int x = TabGapLeft + rectTabStrip.X; - foreach (Pane pane in GetPanes(dockState)) - { - foreach (TabVS2005 tab in pane.AutoHideTabs) + int x = TabGapLeft + rectTabStrip.X; + foreach (Pane pane in GetPanes(dockState)) { - int width = imageWidth + ImageGapLeft + ImageGapRight + - TextRenderer.MeasureText(tab.Content.DockHandler.TabText, TextFont).Width + - TextGapLeft + TextGapRight; - tab.TabX = x; - tab.TabWidth = width; - x += width; - } + foreach (TabVS2005 tab in pane.AutoHideTabs) + { + int width = imageWidth + ImageGapLeft + ImageGapRight + + TextRenderer.MeasureText(tab.Content.DockHandler.TabText, TextFont).Width + + TextGapLeft + TextGapRight; + tab.TabX = x; + tab.TabWidth = width; + x += width; + } - x += TabGapBetween; + x += TabGapBetween; + } + } + catch (Exception) + { + throw; } } private Rectangle RtlTransform(Rectangle rect, DockState dockState) { - Rectangle rectTransformed; - if (dockState == DockState.DockLeftAutoHide || dockState == DockState.DockRightAutoHide) - rectTransformed = rect; - else - rectTransformed = DrawHelper.RtlTransform(this, rect); + try + { + Rectangle rectTransformed; + if (dockState == DockState.DockLeftAutoHide || dockState == DockState.DockRightAutoHide) + rectTransformed = rect; + else + rectTransformed = DrawHelper.RtlTransform(this, rect); - return rectTransformed; + return rectTransformed; + } + catch (Exception) + { + throw; + } } private GraphicsPath GetTabOutline(TabVS2005 tab, bool transformed, bool rtlTransform) { - DockState dockState = tab.Content.DockHandler.DockState; - Rectangle rectTab = GetTabRectangle(tab, transformed); - if (rtlTransform) - rectTab = RtlTransform(rectTab, dockState); - bool upTab = (dockState == DockState.DockLeftAutoHide || dockState == DockState.DockBottomAutoHide); - DrawHelper.GetRoundedCornerTab(GraphicsPath, rectTab, upTab); + try + { + DockState dockState = tab.Content.DockHandler.DockState; + Rectangle rectTab = GetTabRectangle(tab, transformed); + if (rtlTransform) + rectTab = RtlTransform(rectTab, dockState); + bool upTab = (dockState == DockState.DockLeftAutoHide || dockState == DockState.DockBottomAutoHide); + DrawHelper.GetRoundedCornerTab(GraphicsPath, rectTab, upTab); - return GraphicsPath; + return GraphicsPath; + } + catch (Exception) + { + throw; + } } private void DrawTab(Graphics g, TabVS2005 tab) { - Rectangle rectTabOrigin = GetTabRectangle(tab); - if (rectTabOrigin.IsEmpty) - return; - - DockState dockState = tab.Content.DockHandler.DockState; - IDockContent content = tab.Content; - - GraphicsPath path = GetTabOutline(tab, false, true); - - Color startColor = DockPanel.Skin.AutoHideStripSkin.TabGradient.StartColor; - Color endColor = DockPanel.Skin.AutoHideStripSkin.TabGradient.EndColor; - LinearGradientMode gradientMode = DockPanel.Skin.AutoHideStripSkin.TabGradient.LinearGradientMode; - g.FillPath(new LinearGradientBrush(rectTabOrigin, startColor, endColor, gradientMode), path); - g.DrawPath(PenTabBorder, path); - - // Set no rotate for drawing icon and text - Matrix matrixRotate = g.Transform; - g.Transform = MatrixIdentity; - - // Draw the icon - Rectangle rectImage = rectTabOrigin; - rectImage.X += ImageGapLeft; - rectImage.Y += ImageGapTop; - int imageHeight = rectTabOrigin.Height - ImageGapTop - ImageGapBottom; - int imageWidth = ImageWidth; - if (imageHeight > ImageHeight) - imageWidth = ImageWidth * (imageHeight / ImageHeight); - rectImage.Height = imageHeight; - rectImage.Width = imageWidth; - rectImage = GetTransformedRectangle(dockState, rectImage); - - if (dockState == DockState.DockLeftAutoHide || dockState == DockState.DockRightAutoHide) - { - // The DockState is DockLeftAutoHide or DockRightAutoHide, so rotate the image 90 degrees to the right. - Rectangle rectTransform = RtlTransform(rectImage, dockState); - Point[] rotationPoints = + try + { + Rectangle rectTabOrigin = GetTabRectangle(tab); + if (rectTabOrigin.IsEmpty) + return; + + DockState dockState = tab.Content.DockHandler.DockState; + IDockContent content = tab.Content; + + GraphicsPath path = GetTabOutline(tab, false, true); + + Color startColor = DockPanel.Skin.AutoHideStripSkin.TabGradient.StartColor; + Color endColor = DockPanel.Skin.AutoHideStripSkin.TabGradient.EndColor; + LinearGradientMode gradientMode = DockPanel.Skin.AutoHideStripSkin.TabGradient.LinearGradientMode; + g.FillPath(new LinearGradientBrush(rectTabOrigin, startColor, endColor, gradientMode), path); + g.DrawPath(PenTabBorder, path); + + // Set no rotate for drawing icon and text + Matrix matrixRotate = g.Transform; + g.Transform = MatrixIdentity; + + // Draw the icon + Rectangle rectImage = rectTabOrigin; + rectImage.X += ImageGapLeft; + rectImage.Y += ImageGapTop; + int imageHeight = rectTabOrigin.Height - ImageGapTop - ImageGapBottom; + int imageWidth = ImageWidth; + if (imageHeight > ImageHeight) + imageWidth = ImageWidth * (imageHeight / ImageHeight); + rectImage.Height = imageHeight; + rectImage.Width = imageWidth; + rectImage = GetTransformedRectangle(dockState, rectImage); + + if (dockState == DockState.DockLeftAutoHide || dockState == DockState.DockRightAutoHide) + { + // The DockState is DockLeftAutoHide or DockRightAutoHide, so rotate the image 90 degrees to the right. + Rectangle rectTransform = RtlTransform(rectImage, dockState); + Point[] rotationPoints = { new Point(rectTransform.X + rectTransform.Width, rectTransform.Y), new Point(rectTransform.X + rectTransform.Width, rectTransform.Y + rectTransform.Height), new Point(rectTransform.X, rectTransform.Y) }; - using (Icon rotatedIcon = new Icon(((Form)content).Icon, 16, 16)) + using (Icon rotatedIcon = new Icon(((Form)content).Icon, 16, 16)) + { + g.DrawImage(rotatedIcon.ToBitmap(), rotationPoints); + } + } + else { - g.DrawImage(rotatedIcon.ToBitmap(), rotationPoints); + // Draw the icon normally without any rotation. + g.DrawIcon(((Form)content).Icon, RtlTransform(rectImage, dockState)); } - } - else - { - // Draw the icon normally without any rotation. - g.DrawIcon(((Form)content).Icon, RtlTransform(rectImage, dockState)); - } - // Draw the text - Rectangle rectText = rectTabOrigin; - rectText.X += ImageGapLeft + imageWidth + ImageGapRight + TextGapLeft; - rectText.Width -= ImageGapLeft + imageWidth + ImageGapRight + TextGapLeft; - rectText = RtlTransform(GetTransformedRectangle(dockState, rectText), dockState); + // Draw the text + Rectangle rectText = rectTabOrigin; + rectText.X += ImageGapLeft + imageWidth + ImageGapRight + TextGapLeft; + rectText.Width -= ImageGapLeft + imageWidth + ImageGapRight + TextGapLeft; + rectText = RtlTransform(GetTransformedRectangle(dockState, rectText), dockState); - Color textColor = DockPanel.Skin.AutoHideStripSkin.TabGradient.TextColor; + Color textColor = DockPanel.Skin.AutoHideStripSkin.TabGradient.TextColor; - if (dockState == DockState.DockLeftAutoHide || dockState == DockState.DockRightAutoHide) - g.DrawString(content.DockHandler.TabText, TextFont, new SolidBrush(textColor), rectText, StringFormatTabVertical); - else - g.DrawString(content.DockHandler.TabText, TextFont, new SolidBrush(textColor), rectText, StringFormatTabHorizontal); + if (dockState == DockState.DockLeftAutoHide || dockState == DockState.DockRightAutoHide) + g.DrawString(content.DockHandler.TabText, TextFont, new SolidBrush(textColor), rectText, StringFormatTabVertical); + else + g.DrawString(content.DockHandler.TabText, TextFont, new SolidBrush(textColor), rectText, StringFormatTabHorizontal); - // Set rotate back - g.Transform = matrixRotate; + // Set rotate back + g.Transform = matrixRotate; + } + catch (Exception) + { + throw; + } } private Rectangle GetLogicalTabStripRectangle(DockState dockState) @@ -389,52 +431,59 @@ namespace WeifenLuo.WinFormsUI.Docking private Rectangle GetLogicalTabStripRectangle(DockState dockState, bool transformed) { - if (!DockHelper.IsDockStateAutoHide(dockState)) - return Rectangle.Empty; + try + { + if (!DockHelper.IsDockStateAutoHide(dockState)) + return Rectangle.Empty; - int leftPanes = GetPanes(DockState.DockLeftAutoHide).Count; - int rightPanes = GetPanes(DockState.DockRightAutoHide).Count; - int topPanes = GetPanes(DockState.DockTopAutoHide).Count; - int bottomPanes = GetPanes(DockState.DockBottomAutoHide).Count; + int leftPanes = GetPanes(DockState.DockLeftAutoHide).Count; + int rightPanes = GetPanes(DockState.DockRightAutoHide).Count; + int topPanes = GetPanes(DockState.DockTopAutoHide).Count; + int bottomPanes = GetPanes(DockState.DockBottomAutoHide).Count; - int x, y, width, height; + int x, y, width, height; - height = MeasureHeight(); - if (dockState == DockState.DockLeftAutoHide && leftPanes > 0) - { - x = 0; - y = (topPanes == 0) ? 0 : height; - width = Height - (topPanes == 0 ? 0 : height) - (bottomPanes == 0 ? 0 : height); - } - else if (dockState == DockState.DockRightAutoHide && rightPanes > 0) - { - x = Width - height; - if (leftPanes != 0 && x < height) - x = height; - y = (topPanes == 0) ? 0 : height; - width = Height - (topPanes == 0 ? 0 : height) - (bottomPanes == 0 ? 0 : height); - } - else if (dockState == DockState.DockTopAutoHide && topPanes > 0) - { - x = leftPanes == 0 ? 0 : height; - y = 0; - width = Width - (leftPanes == 0 ? 0 : height) - (rightPanes == 0 ? 0 : height); + height = MeasureHeight(); + if (dockState == DockState.DockLeftAutoHide && leftPanes > 0) + { + x = 0; + y = (topPanes == 0) ? 0 : height; + width = Height - (topPanes == 0 ? 0 : height) - (bottomPanes == 0 ? 0 : height); + } + else if (dockState == DockState.DockRightAutoHide && rightPanes > 0) + { + x = Width - height; + if (leftPanes != 0 && x < height) + x = height; + y = (topPanes == 0) ? 0 : height; + width = Height - (topPanes == 0 ? 0 : height) - (bottomPanes == 0 ? 0 : height); + } + else if (dockState == DockState.DockTopAutoHide && topPanes > 0) + { + x = leftPanes == 0 ? 0 : height; + y = 0; + width = Width - (leftPanes == 0 ? 0 : height) - (rightPanes == 0 ? 0 : height); + } + else if (dockState == DockState.DockBottomAutoHide && bottomPanes > 0) + { + x = leftPanes == 0 ? 0 : height; + y = Height - height; + if (topPanes != 0 && y < height) + y = height; + width = Width - (leftPanes == 0 ? 0 : height) - (rightPanes == 0 ? 0 : height); + } + else + return Rectangle.Empty; + + if (!transformed) + return new Rectangle(x, y, width, height); + else + return GetTransformedRectangle(dockState, new Rectangle(x, y, width, height)); } - else if (dockState == DockState.DockBottomAutoHide && bottomPanes > 0) + catch (Exception) { - x = leftPanes == 0 ? 0 : height; - y = Height - height; - if (topPanes != 0 && y < height) - y = height; - width = Width - (leftPanes == 0 ? 0 : height) - (rightPanes == 0 ? 0 : height); + throw; } - else - return Rectangle.Empty; - - if (!transformed) - return new Rectangle(x, y, width, height); - else - return GetTransformedRectangle(dockState, new Rectangle(x, y, width, height)); } private Rectangle GetTabRectangle(TabVS2005 tab) @@ -444,65 +493,86 @@ namespace WeifenLuo.WinFormsUI.Docking private Rectangle GetTabRectangle(TabVS2005 tab, bool transformed) { - DockState dockState = tab.Content.DockHandler.DockState; - Rectangle rectTabStrip = GetLogicalTabStripRectangle(dockState); + try + { + DockState dockState = tab.Content.DockHandler.DockState; + Rectangle rectTabStrip = GetLogicalTabStripRectangle(dockState); + + if (rectTabStrip.IsEmpty) + return Rectangle.Empty; - if (rectTabStrip.IsEmpty) - return Rectangle.Empty; + int x = tab.TabX; + int y = rectTabStrip.Y + + (dockState == DockState.DockTopAutoHide || dockState == DockState.DockRightAutoHide ? + 0 : TabGapTop); + int width = tab.TabWidth; + int height = rectTabStrip.Height - TabGapTop; - int x = tab.TabX; - int y = rectTabStrip.Y + - (dockState == DockState.DockTopAutoHide || dockState == DockState.DockRightAutoHide ? - 0 : TabGapTop); - int width = tab.TabWidth; - int height = rectTabStrip.Height - TabGapTop; - - if (!transformed) - return new Rectangle(x, y, width, height); - else - return GetTransformedRectangle(dockState, new Rectangle(x, y, width, height)); + if (!transformed) + return new Rectangle(x, y, width, height); + else + return GetTransformedRectangle(dockState, new Rectangle(x, y, width, height)); + } + catch (Exception) + { + throw; + } } private Rectangle GetTransformedRectangle(DockState dockState, Rectangle rect) { - if (dockState != DockState.DockLeftAutoHide && dockState != DockState.DockRightAutoHide) - return rect; + try + { + if (dockState != DockState.DockLeftAutoHide && dockState != DockState.DockRightAutoHide) + return rect; - PointF[] pts = new PointF[1]; - // the center of the rectangle - pts[0].X = (float)rect.X + (float)rect.Width / 2; - pts[0].Y = (float)rect.Y + (float)rect.Height / 2; - Rectangle rectTabStrip = GetLogicalTabStripRectangle(dockState); - Matrix matrix = new Matrix(); - matrix.RotateAt(90, new PointF((float)rectTabStrip.X + (float)rectTabStrip.Height / 2, - (float)rectTabStrip.Y + (float)rectTabStrip.Height / 2)); - matrix.TransformPoints(pts); - - return new Rectangle((int)(pts[0].X - (float)rect.Height / 2 + .5F), - (int)(pts[0].Y - (float)rect.Width / 2 + .5F), - rect.Height, rect.Width); + PointF[] pts = new PointF[1]; + // the center of the rectangle + pts[0].X = (float)rect.X + (float)rect.Width / 2; + pts[0].Y = (float)rect.Y + (float)rect.Height / 2; + Rectangle rectTabStrip = GetLogicalTabStripRectangle(dockState); + Matrix matrix = new Matrix(); + matrix.RotateAt(90, new PointF((float)rectTabStrip.X + (float)rectTabStrip.Height / 2, + (float)rectTabStrip.Y + (float)rectTabStrip.Height / 2)); + matrix.TransformPoints(pts); + + return new Rectangle((int)(pts[0].X - (float)rect.Height / 2 + .5F), + (int)(pts[0].Y - (float)rect.Width / 2 + .5F), + rect.Height, rect.Width); + } + catch (Exception) + { + throw; + } } protected override IDockContent HitTest(Point ptMouse) { - foreach (DockState state in DockStates) + try { - Rectangle rectTabStrip = GetLogicalTabStripRectangle(state, true); - if (!rectTabStrip.Contains(ptMouse)) - continue; - - foreach (Pane pane in GetPanes(state)) + foreach (DockState state in DockStates) { - foreach (TabVS2005 tab in pane.AutoHideTabs) + Rectangle rectTabStrip = GetLogicalTabStripRectangle(state, true); + if (!rectTabStrip.Contains(ptMouse)) + continue; + + foreach (Pane pane in GetPanes(state)) { - GraphicsPath path = GetTabOutline(tab, true, true); - if (path.IsVisible(ptMouse)) - return tab.Content; + foreach (TabVS2005 tab in pane.AutoHideTabs) + { + GraphicsPath path = GetTabOutline(tab, true, true); + if (path.IsVisible(ptMouse)) + return tab.Content; + } } } - } - return null; + return null; + } + catch (Exception) + { + throw; + } } protected internal override int MeasureHeight() |