Changeset 4068 for trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.WinFormsUI/2.3.1/WinFormsUI-2.3.1/Docking/VS2005AutoHideStrip.cs
- Timestamp:
- 07/22/10 00:44:01 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.WinFormsUI/2.3.1/WinFormsUI-2.3.1/Docking/VS2005AutoHideStrip.cs
r2645 r4068 1 1 using System; 2 2 using System.Drawing; 3 using System.Drawing.Drawing2D; 3 4 using System.Windows.Forms; 4 using System.Drawing.Drawing2D; 5 using System.ComponentModel; 6 7 namespace WeifenLuo.WinFormsUI.Docking 8 { 9 internal class VS2005AutoHideStrip : AutoHideStripBase 10 { 11 private class TabVS2005 : Tab 12 { 13 internal TabVS2005(IDockContent content) 14 : base(content) 15 { 16 } 17 18 private int m_tabX = 0; 19 public int TabX 20 { 21 get { return m_tabX; } 22 set { m_tabX = value; } 23 } 24 25 private int m_tabWidth = 0; 26 public int TabWidth 27 { 28 get { return m_tabWidth; } 29 set { m_tabWidth = value; } 30 } 31 5 6 namespace WeifenLuo.WinFormsUI.Docking { 7 internal class VS2005AutoHideStrip : AutoHideStripBase { 8 private class TabVS2005 : Tab { 9 internal TabVS2005(IDockContent content) 10 : base(content) { 11 } 12 13 private int m_tabX = 0; 14 public int TabX { 15 get { return m_tabX; } 16 set { m_tabX = value; } 17 } 18 19 private int m_tabWidth = 0; 20 public int TabWidth { 21 get { return m_tabWidth; } 22 set { m_tabWidth = value; } 23 } 24 25 } 26 27 private const int _ImageHeight = 16; 28 private const int _ImageWidth = 16; 29 private const int _ImageGapTop = 2; 30 private const int _ImageGapLeft = 4; 31 private const int _ImageGapRight = 2; 32 private const int _ImageGapBottom = 2; 33 private const int _TextGapLeft = 0; 34 private const int _TextGapRight = 0; 35 private const int _TabGapTop = 3; 36 private const int _TabGapLeft = 4; 37 private const int _TabGapBetween = 10; 38 39 #region Customizable Properties 40 private static Font TextFont { 41 get { return SystemInformation.MenuFont; } 42 } 43 44 private static StringFormat _stringFormatTabHorizontal; 45 private StringFormat StringFormatTabHorizontal { 46 get { 47 if (_stringFormatTabHorizontal == null) { 48 _stringFormatTabHorizontal = new StringFormat(); 49 _stringFormatTabHorizontal.Alignment = StringAlignment.Near; 50 _stringFormatTabHorizontal.LineAlignment = StringAlignment.Center; 51 _stringFormatTabHorizontal.FormatFlags = StringFormatFlags.NoWrap; 52 _stringFormatTabHorizontal.Trimming = StringTrimming.None; 32 53 } 33 54 34 private const int _ImageHeight = 16; 35 private const int _ImageWidth = 16; 36 private const int _ImageGapTop = 2; 37 private const int _ImageGapLeft = 4; 38 private const int _ImageGapRight = 2; 39 private const int _ImageGapBottom = 2; 40 private const int _TextGapLeft = 0; 41 private const int _TextGapRight = 0; 42 private const int _TabGapTop = 3; 43 private const int _TabGapLeft = 4; 44 private const int _TabGapBetween = 10; 45 46 #region Customizable Properties 47 private static Font TextFont 48 { 49 get { return SystemInformation.MenuFont; } 55 if (RightToLeft == RightToLeft.Yes) 56 _stringFormatTabHorizontal.FormatFlags |= StringFormatFlags.DirectionRightToLeft; 57 else 58 _stringFormatTabHorizontal.FormatFlags &= ~StringFormatFlags.DirectionRightToLeft; 59 60 return _stringFormatTabHorizontal; 61 } 62 } 63 64 private static StringFormat _stringFormatTabVertical; 65 private StringFormat StringFormatTabVertical { 66 get { 67 if (_stringFormatTabVertical == null) { 68 _stringFormatTabVertical = new StringFormat(); 69 _stringFormatTabVertical.Alignment = StringAlignment.Near; 70 _stringFormatTabVertical.LineAlignment = StringAlignment.Center; 71 _stringFormatTabVertical.FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.DirectionVertical; 72 _stringFormatTabVertical.Trimming = StringTrimming.None; 50 73 } 51 52 private static StringFormat _stringFormatTabHorizontal; 53 private StringFormat StringFormatTabHorizontal 54 { 55 get 56 { 57 if (_stringFormatTabHorizontal == null) 58 { 59 _stringFormatTabHorizontal = new StringFormat(); 60 _stringFormatTabHorizontal.Alignment = StringAlignment.Near; 61 _stringFormatTabHorizontal.LineAlignment = StringAlignment.Center; 62 _stringFormatTabHorizontal.FormatFlags = StringFormatFlags.NoWrap; 63 _stringFormatTabHorizontal.Trimming = StringTrimming.None; 64 } 65 66 if (RightToLeft == RightToLeft.Yes) 67 _stringFormatTabHorizontal.FormatFlags |= StringFormatFlags.DirectionRightToLeft; 68 else 69 _stringFormatTabHorizontal.FormatFlags &= ~StringFormatFlags.DirectionRightToLeft; 70 71 return _stringFormatTabHorizontal; 72 } 73 } 74 75 private static StringFormat _stringFormatTabVertical; 76 private StringFormat StringFormatTabVertical 77 { 78 get 79 { 80 if (_stringFormatTabVertical == null) 81 { 82 _stringFormatTabVertical = new StringFormat(); 83 _stringFormatTabVertical.Alignment = StringAlignment.Near; 84 _stringFormatTabVertical.LineAlignment = StringAlignment.Center; 85 _stringFormatTabVertical.FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.DirectionVertical; 86 _stringFormatTabVertical.Trimming = StringTrimming.None; 87 } 88 if (RightToLeft == RightToLeft.Yes) 89 _stringFormatTabVertical.FormatFlags |= StringFormatFlags.DirectionRightToLeft; 90 else 91 _stringFormatTabVertical.FormatFlags &= ~StringFormatFlags.DirectionRightToLeft; 92 93 return _stringFormatTabVertical; 94 } 95 } 96 97 private static int ImageHeight 98 { 99 get { return _ImageHeight; } 100 } 101 102 private static int ImageWidth 103 { 104 get { return _ImageWidth; } 105 } 106 107 private static int ImageGapTop 108 { 109 get { return _ImageGapTop; } 110 } 111 112 private static int ImageGapLeft 113 { 114 get { return _ImageGapLeft; } 115 } 116 117 private static int ImageGapRight 118 { 119 get { return _ImageGapRight; } 120 } 121 122 private static int ImageGapBottom 123 { 124 get { return _ImageGapBottom; } 125 } 126 127 private static int TextGapLeft 128 { 129 get { return _TextGapLeft; } 130 } 131 132 private static int TextGapRight 133 { 134 get { return _TextGapRight; } 135 } 136 137 private static int TabGapTop 138 { 139 get { return _TabGapTop; } 140 } 141 142 private static int TabGapLeft 143 { 144 get { return _TabGapLeft; } 145 } 146 147 private static int TabGapBetween 148 { 149 get { return _TabGapBetween; } 150 } 151 152 private static Pen PenTabBorder 153 { 154 get { return SystemPens.GrayText; } 155 } 156 #endregion 157 158 private static Matrix _matrixIdentity = new Matrix(); 159 private static Matrix MatrixIdentity 160 { 161 get { return _matrixIdentity; } 162 } 163 164 private static DockState[] _dockStates; 165 private static DockState[] DockStates 166 { 167 get 168 { 169 if (_dockStates == null) 170 { 171 _dockStates = new DockState[4]; 172 _dockStates[0] = DockState.DockLeftAutoHide; 173 _dockStates[1] = DockState.DockRightAutoHide; 174 _dockStates[2] = DockState.DockTopAutoHide; 175 _dockStates[3] = DockState.DockBottomAutoHide; 176 } 177 return _dockStates; 178 } 179 } 180 181 private static GraphicsPath _graphicsPath; 182 internal static GraphicsPath GraphicsPath 183 { 184 get 185 { 186 if (_graphicsPath == null) 187 _graphicsPath = new GraphicsPath(); 188 189 return _graphicsPath; 190 } 74 if (RightToLeft == RightToLeft.Yes) 75 _stringFormatTabVertical.FormatFlags |= StringFormatFlags.DirectionRightToLeft; 76 else 77 _stringFormatTabVertical.FormatFlags &= ~StringFormatFlags.DirectionRightToLeft; 78 79 return _stringFormatTabVertical; 80 } 81 } 82 83 private static int ImageHeight { 84 get { return _ImageHeight; } 85 } 86 87 private static int ImageWidth { 88 get { return _ImageWidth; } 89 } 90 91 private static int ImageGapTop { 92 get { return _ImageGapTop; } 93 } 94 95 private static int ImageGapLeft { 96 get { return _ImageGapLeft; } 97 } 98 99 private static int ImageGapRight { 100 get { return _ImageGapRight; } 101 } 102 103 private static int ImageGapBottom { 104 get { return _ImageGapBottom; } 105 } 106 107 private static int TextGapLeft { 108 get { return _TextGapLeft; } 109 } 110 111 private static int TextGapRight { 112 get { return _TextGapRight; } 113 } 114 115 private static int TabGapTop { 116 get { return _TabGapTop; } 117 } 118 119 private static int TabGapLeft { 120 get { return _TabGapLeft; } 121 } 122 123 private static int TabGapBetween { 124 get { return _TabGapBetween; } 125 } 126 127 private static Pen PenTabBorder { 128 get { return SystemPens.GrayText; } 129 } 130 #endregion 131 132 private static Matrix _matrixIdentity = new Matrix(); 133 private static Matrix MatrixIdentity { 134 get { return _matrixIdentity; } 135 } 136 137 private static DockState[] _dockStates; 138 private static DockState[] DockStates { 139 get { 140 if (_dockStates == null) { 141 _dockStates = new DockState[4]; 142 _dockStates[0] = DockState.DockLeftAutoHide; 143 _dockStates[1] = DockState.DockRightAutoHide; 144 _dockStates[2] = DockState.DockTopAutoHide; 145 _dockStates[3] = DockState.DockBottomAutoHide; 191 146 } 192 193 public VS2005AutoHideStrip(DockPanel panel) : base(panel) 194 { 195 SetStyle(ControlStyles.ResizeRedraw | 147 return _dockStates; 148 } 149 } 150 151 private static GraphicsPath _graphicsPath; 152 internal static GraphicsPath GraphicsPath { 153 get { 154 if (_graphicsPath == null) 155 _graphicsPath = new GraphicsPath(); 156 157 return _graphicsPath; 158 } 159 } 160 161 public VS2005AutoHideStrip(DockPanel panel) 162 : base(panel) { 163 SetStyle(ControlStyles.ResizeRedraw | 196 164 ControlStyles.UserPaint | 197 165 ControlStyles.AllPaintingInWmPaint | 198 166 ControlStyles.OptimizedDoubleBuffer, true); 199 BackColor = SystemColors.ControlLight; 200 } 201 202 protected override void OnPaint(PaintEventArgs e) 203 { 204 Graphics g = e.Graphics; 205 206 Color startColor = DockPanel.Skin.AutoHideStripSkin.DockStripGradient.StartColor; 207 Color endColor = DockPanel.Skin.AutoHideStripSkin.DockStripGradient.EndColor; 208 LinearGradientMode gradientMode = DockPanel.Skin.AutoHideStripSkin.DockStripGradient.LinearGradientMode; 209 using (LinearGradientBrush brush = new LinearGradientBrush(ClientRectangle, startColor, endColor, gradientMode)) 210 { 211 g.FillRectangle(brush, ClientRectangle); 212 } 213 214 DrawTabStrip(g); 215 } 216 217 protected override void OnLayout(LayoutEventArgs levent) 218 { 219 CalculateTabs(); 220 base.OnLayout (levent); 221 } 222 223 private void DrawTabStrip(Graphics g) 224 { 225 DrawTabStrip(g, DockState.DockTopAutoHide); 226 DrawTabStrip(g, DockState.DockBottomAutoHide); 227 DrawTabStrip(g, DockState.DockLeftAutoHide); 228 DrawTabStrip(g, DockState.DockRightAutoHide); 229 } 230 231 private void DrawTabStrip(Graphics g, DockState dockState) 232 { 233 Rectangle rectTabStrip = GetLogicalTabStripRectangle(dockState); 234 235 if (rectTabStrip.IsEmpty) 236 return; 237 238 Matrix matrixIdentity = g.Transform; 239 if (dockState == DockState.DockLeftAutoHide || dockState == DockState.DockRightAutoHide) 240 { 241 Matrix matrixRotated = new Matrix(); 242 matrixRotated.RotateAt(90, new PointF((float)rectTabStrip.X + (float)rectTabStrip.Height / 2, 243 (float)rectTabStrip.Y + (float)rectTabStrip.Height / 2)); 244 g.Transform = matrixRotated; 245 } 246 247 foreach (Pane pane in GetPanes(dockState)) 248 { 249 foreach (TabVS2005 tab in pane.AutoHideTabs) 250 DrawTab(g, tab); 251 } 252 g.Transform = matrixIdentity; 253 } 254 255 private void CalculateTabs() 256 { 257 CalculateTabs(DockState.DockTopAutoHide); 258 CalculateTabs(DockState.DockBottomAutoHide); 259 CalculateTabs(DockState.DockLeftAutoHide); 260 CalculateTabs(DockState.DockRightAutoHide); 261 } 262 263 private void CalculateTabs(DockState dockState) 264 { 265 Rectangle rectTabStrip = GetLogicalTabStripRectangle(dockState); 266 267 int imageHeight = rectTabStrip.Height - ImageGapTop - ImageGapBottom; 268 int imageWidth = ImageWidth; 269 if (imageHeight > ImageHeight) 270 imageWidth = ImageWidth * (imageHeight / ImageHeight); 271 272 int x = TabGapLeft + rectTabStrip.X; 273 foreach (Pane pane in GetPanes(dockState)) 274 { 275 foreach (TabVS2005 tab in pane.AutoHideTabs) 276 { 277 int width = imageWidth + ImageGapLeft + ImageGapRight + 278 TextRenderer.MeasureText(tab.Content.DockHandler.TabText, TextFont).Width + 279 TextGapLeft + TextGapRight; 280 tab.TabX = x; 281 tab.TabWidth = width; 282 x += width; 283 } 284 285 x += TabGapBetween; 286 } 167 BackColor = SystemColors.ControlLight; 168 } 169 170 protected override void OnPaint(PaintEventArgs e) { 171 Graphics g = e.Graphics; 172 173 Color startColor = DockPanel.Skin.AutoHideStripSkin.DockStripGradient.StartColor; 174 Color endColor = DockPanel.Skin.AutoHideStripSkin.DockStripGradient.EndColor; 175 LinearGradientMode gradientMode = DockPanel.Skin.AutoHideStripSkin.DockStripGradient.LinearGradientMode; 176 using (LinearGradientBrush brush = new LinearGradientBrush(ClientRectangle, startColor, endColor, gradientMode)) { 177 g.FillRectangle(brush, ClientRectangle); 178 } 179 180 DrawTabStrip(g); 181 } 182 183 protected override void OnLayout(LayoutEventArgs levent) { 184 CalculateTabs(); 185 base.OnLayout(levent); 186 } 187 188 private void DrawTabStrip(Graphics g) { 189 DrawTabStrip(g, DockState.DockTopAutoHide); 190 DrawTabStrip(g, DockState.DockBottomAutoHide); 191 DrawTabStrip(g, DockState.DockLeftAutoHide); 192 DrawTabStrip(g, DockState.DockRightAutoHide); 193 } 194 195 private void DrawTabStrip(Graphics g, DockState dockState) { 196 Rectangle rectTabStrip = GetLogicalTabStripRectangle(dockState); 197 198 if (rectTabStrip.IsEmpty) 199 return; 200 201 Matrix matrixIdentity = g.Transform; 202 if (dockState == DockState.DockLeftAutoHide || dockState == DockState.DockRightAutoHide) { 203 Matrix matrixRotated = new Matrix(); 204 matrixRotated.RotateAt(90, new PointF((float)rectTabStrip.X + (float)rectTabStrip.Height / 2, 205 (float)rectTabStrip.Y + (float)rectTabStrip.Height / 2)); 206 g.Transform = matrixRotated; 207 } 208 209 foreach (Pane pane in GetPanes(dockState)) { 210 foreach (TabVS2005 tab in pane.AutoHideTabs) 211 DrawTab(g, tab); 212 } 213 g.Transform = matrixIdentity; 214 } 215 216 private void CalculateTabs() { 217 CalculateTabs(DockState.DockTopAutoHide); 218 CalculateTabs(DockState.DockBottomAutoHide); 219 CalculateTabs(DockState.DockLeftAutoHide); 220 CalculateTabs(DockState.DockRightAutoHide); 221 } 222 223 private void CalculateTabs(DockState dockState) { 224 Rectangle rectTabStrip = GetLogicalTabStripRectangle(dockState); 225 226 int imageHeight = rectTabStrip.Height - ImageGapTop - ImageGapBottom; 227 int imageWidth = ImageWidth; 228 if (imageHeight > ImageHeight) 229 imageWidth = ImageWidth * (imageHeight / ImageHeight); 230 231 int x = TabGapLeft + rectTabStrip.X; 232 foreach (Pane pane in GetPanes(dockState)) { 233 foreach (TabVS2005 tab in pane.AutoHideTabs) { 234 int width = imageWidth + ImageGapLeft + ImageGapRight + 235 TextRenderer.MeasureText(tab.Content.DockHandler.TabText, TextFont).Width + 236 TextGapLeft + TextGapRight; 237 tab.TabX = x; 238 tab.TabWidth = width; 239 x += width; 287 240 } 288 241 289 private Rectangle RtlTransform(Rectangle rect, DockState dockState) 290 { 291 Rectangle rectTransformed; 292 if (dockState == DockState.DockLeftAutoHide || dockState == DockState.DockRightAutoHide) 293 rectTransformed = rect; 294 else 295 rectTransformed = DrawHelper.RtlTransform(this, rect); 296 297 return rectTransformed; 242 x += TabGapBetween; 243 } 244 } 245 246 private Rectangle RtlTransform(Rectangle rect, DockState dockState) { 247 Rectangle rectTransformed; 248 if (dockState == DockState.DockLeftAutoHide || dockState == DockState.DockRightAutoHide) 249 rectTransformed = rect; 250 else 251 rectTransformed = DrawHelper.RtlTransform(this, rect); 252 253 return rectTransformed; 254 } 255 256 private GraphicsPath GetTabOutline(TabVS2005 tab, bool transformed, bool rtlTransform) { 257 DockState dockState = tab.Content.DockHandler.DockState; 258 Rectangle rectTab = GetTabRectangle(tab, transformed); 259 if (rtlTransform) 260 rectTab = RtlTransform(rectTab, dockState); 261 bool upTab = (dockState == DockState.DockLeftAutoHide || dockState == DockState.DockBottomAutoHide); 262 DrawHelper.GetRoundedCornerTab(GraphicsPath, rectTab, upTab); 263 264 return GraphicsPath; 265 } 266 267 private void DrawTab(Graphics g, TabVS2005 tab) { 268 Rectangle rectTabOrigin = GetTabRectangle(tab); 269 if (rectTabOrigin.IsEmpty) 270 return; 271 272 DockState dockState = tab.Content.DockHandler.DockState; 273 IDockContent content = tab.Content; 274 275 GraphicsPath path = GetTabOutline(tab, false, true); 276 277 Color startColor = DockPanel.Skin.AutoHideStripSkin.TabGradient.StartColor; 278 Color endColor = DockPanel.Skin.AutoHideStripSkin.TabGradient.EndColor; 279 LinearGradientMode gradientMode = DockPanel.Skin.AutoHideStripSkin.TabGradient.LinearGradientMode; 280 g.FillPath(new LinearGradientBrush(rectTabOrigin, startColor, endColor, gradientMode), path); 281 g.DrawPath(PenTabBorder, path); 282 283 // Set no rotate for drawing icon and text 284 Matrix matrixRotate = g.Transform; 285 g.Transform = MatrixIdentity; 286 287 // Draw the icon 288 Rectangle rectImage = rectTabOrigin; 289 rectImage.X += ImageGapLeft; 290 rectImage.Y += ImageGapTop; 291 int imageHeight = rectTabOrigin.Height - ImageGapTop - ImageGapBottom; 292 int imageWidth = ImageWidth; 293 if (imageHeight > ImageHeight) 294 imageWidth = ImageWidth * (imageHeight / ImageHeight); 295 rectImage.Height = imageHeight; 296 rectImage.Width = imageWidth; 297 rectImage = GetTransformedRectangle(dockState, rectImage); 298 g.DrawIcon(((Form)content).Icon, RtlTransform(rectImage, dockState)); 299 300 // Draw the text 301 Rectangle rectText = rectTabOrigin; 302 rectText.X += ImageGapLeft + imageWidth + ImageGapRight + TextGapLeft; 303 rectText.Width -= ImageGapLeft + imageWidth + ImageGapRight + TextGapLeft; 304 rectText = RtlTransform(GetTransformedRectangle(dockState, rectText), dockState); 305 306 Color textColor = DockPanel.Skin.AutoHideStripSkin.TabGradient.TextColor; 307 308 if (dockState == DockState.DockLeftAutoHide || dockState == DockState.DockRightAutoHide) 309 g.DrawString(content.DockHandler.TabText, TextFont, new SolidBrush(textColor), rectText, StringFormatTabVertical); 310 else 311 g.DrawString(content.DockHandler.TabText, TextFont, new SolidBrush(textColor), rectText, StringFormatTabHorizontal); 312 313 // Set rotate back 314 g.Transform = matrixRotate; 315 } 316 317 private Rectangle GetLogicalTabStripRectangle(DockState dockState) { 318 return GetLogicalTabStripRectangle(dockState, false); 319 } 320 321 private Rectangle GetLogicalTabStripRectangle(DockState dockState, bool transformed) { 322 if (!DockHelper.IsDockStateAutoHide(dockState)) 323 return Rectangle.Empty; 324 325 int leftPanes = GetPanes(DockState.DockLeftAutoHide).Count; 326 int rightPanes = GetPanes(DockState.DockRightAutoHide).Count; 327 int topPanes = GetPanes(DockState.DockTopAutoHide).Count; 328 int bottomPanes = GetPanes(DockState.DockBottomAutoHide).Count; 329 330 int x, y, width, height; 331 332 height = MeasureHeight(); 333 if (dockState == DockState.DockLeftAutoHide && leftPanes > 0) { 334 x = 0; 335 y = (topPanes == 0) ? 0 : height; 336 width = Height - (topPanes == 0 ? 0 : height) - (bottomPanes == 0 ? 0 : height); 337 } else if (dockState == DockState.DockRightAutoHide && rightPanes > 0) { 338 x = Width - height; 339 if (leftPanes != 0 && x < height) 340 x = height; 341 y = (topPanes == 0) ? 0 : height; 342 width = Height - (topPanes == 0 ? 0 : height) - (bottomPanes == 0 ? 0 : height); 343 } else if (dockState == DockState.DockTopAutoHide && topPanes > 0) { 344 x = leftPanes == 0 ? 0 : height; 345 y = 0; 346 width = Width - (leftPanes == 0 ? 0 : height) - (rightPanes == 0 ? 0 : height); 347 } else if (dockState == DockState.DockBottomAutoHide && bottomPanes > 0) { 348 x = leftPanes == 0 ? 0 : height; 349 y = Height - height; 350 if (topPanes != 0 && y < height) 351 y = height; 352 width = Width - (leftPanes == 0 ? 0 : height) - (rightPanes == 0 ? 0 : height); 353 } else 354 return Rectangle.Empty; 355 356 if (!transformed) 357 return new Rectangle(x, y, width, height); 358 else 359 return GetTransformedRectangle(dockState, new Rectangle(x, y, width, height)); 360 } 361 362 private Rectangle GetTabRectangle(TabVS2005 tab) { 363 return GetTabRectangle(tab, false); 364 } 365 366 private Rectangle GetTabRectangle(TabVS2005 tab, bool transformed) { 367 DockState dockState = tab.Content.DockHandler.DockState; 368 Rectangle rectTabStrip = GetLogicalTabStripRectangle(dockState); 369 370 if (rectTabStrip.IsEmpty) 371 return Rectangle.Empty; 372 373 int x = tab.TabX; 374 int y = rectTabStrip.Y + 375 (dockState == DockState.DockTopAutoHide || dockState == DockState.DockRightAutoHide ? 376 0 : TabGapTop); 377 int width = tab.TabWidth; 378 int height = rectTabStrip.Height - TabGapTop; 379 380 if (!transformed) 381 return new Rectangle(x, y, width, height); 382 else 383 return GetTransformedRectangle(dockState, new Rectangle(x, y, width, height)); 384 } 385 386 private Rectangle GetTransformedRectangle(DockState dockState, Rectangle rect) { 387 if (dockState != DockState.DockLeftAutoHide && dockState != DockState.DockRightAutoHide) 388 return rect; 389 390 PointF[] pts = new PointF[1]; 391 // the center of the rectangle 392 pts[0].X = (float)rect.X + (float)rect.Width / 2; 393 pts[0].Y = (float)rect.Y + (float)rect.Height / 2; 394 Rectangle rectTabStrip = GetLogicalTabStripRectangle(dockState); 395 Matrix matrix = new Matrix(); 396 matrix.RotateAt(90, new PointF((float)rectTabStrip.X + (float)rectTabStrip.Height / 2, 397 (float)rectTabStrip.Y + (float)rectTabStrip.Height / 2)); 398 matrix.TransformPoints(pts); 399 400 return new Rectangle((int)(pts[0].X - (float)rect.Height / 2 + .5F), 401 (int)(pts[0].Y - (float)rect.Width / 2 + .5F), 402 rect.Height, rect.Width); 403 } 404 405 protected override IDockContent HitTest(Point ptMouse) { 406 foreach (DockState state in DockStates) { 407 Rectangle rectTabStrip = GetLogicalTabStripRectangle(state, true); 408 if (!rectTabStrip.Contains(ptMouse)) 409 continue; 410 411 foreach (Pane pane in GetPanes(state)) { 412 DockState dockState = pane.DockPane.DockState; 413 foreach (TabVS2005 tab in pane.AutoHideTabs) { 414 GraphicsPath path = GetTabOutline(tab, true, true); 415 if (path.IsVisible(ptMouse)) 416 return tab.Content; 417 } 298 418 } 299 300 private GraphicsPath GetTabOutline(TabVS2005 tab, bool transformed, bool rtlTransform) 301 { 302 DockState dockState = tab.Content.DockHandler.DockState; 303 Rectangle rectTab = GetTabRectangle(tab, transformed); 304 if (rtlTransform) 305 rectTab = RtlTransform(rectTab, dockState); 306 bool upTab = (dockState == DockState.DockLeftAutoHide || dockState == DockState.DockBottomAutoHide); 307 DrawHelper.GetRoundedCornerTab(GraphicsPath, rectTab, upTab); 308 309 return GraphicsPath; 310 } 311 312 private void DrawTab(Graphics g, TabVS2005 tab) 313 { 314 Rectangle rectTabOrigin = GetTabRectangle(tab); 315 if (rectTabOrigin.IsEmpty) 316 return; 317 318 DockState dockState = tab.Content.DockHandler.DockState; 319 IDockContent content = tab.Content; 320 321 GraphicsPath path = GetTabOutline(tab, false, true); 322 323 Color startColor = DockPanel.Skin.AutoHideStripSkin.TabGradient.StartColor; 324 Color endColor = DockPanel.Skin.AutoHideStripSkin.TabGradient.EndColor; 325 LinearGradientMode gradientMode = DockPanel.Skin.AutoHideStripSkin.TabGradient.LinearGradientMode; 326 g.FillPath(new LinearGradientBrush(rectTabOrigin, startColor, endColor, gradientMode), path); 327 g.DrawPath(PenTabBorder, path); 328 329 // Set no rotate for drawing icon and text 330 Matrix matrixRotate = g.Transform; 331 g.Transform = MatrixIdentity; 332 333 // Draw the icon 334 Rectangle rectImage = rectTabOrigin; 335 rectImage.X += ImageGapLeft; 336 rectImage.Y += ImageGapTop; 337 int imageHeight = rectTabOrigin.Height - ImageGapTop - ImageGapBottom; 338 int imageWidth = ImageWidth; 339 if (imageHeight > ImageHeight) 340 imageWidth = ImageWidth * (imageHeight/ImageHeight); 341 rectImage.Height = imageHeight; 342 rectImage.Width = imageWidth; 343 rectImage = GetTransformedRectangle(dockState, rectImage); 344 g.DrawIcon(((Form)content).Icon, RtlTransform(rectImage, dockState)); 345 346 // Draw the text 347 Rectangle rectText = rectTabOrigin; 348 rectText.X += ImageGapLeft + imageWidth + ImageGapRight + TextGapLeft; 349 rectText.Width -= ImageGapLeft + imageWidth + ImageGapRight + TextGapLeft; 350 rectText = RtlTransform(GetTransformedRectangle(dockState, rectText), dockState); 351 352 Color textColor = DockPanel.Skin.AutoHideStripSkin.TabGradient.TextColor; 353 354 if (dockState == DockState.DockLeftAutoHide || dockState == DockState.DockRightAutoHide) 355 g.DrawString(content.DockHandler.TabText, TextFont, new SolidBrush(textColor), rectText, StringFormatTabVertical); 356 else 357 g.DrawString(content.DockHandler.TabText, TextFont, new SolidBrush(textColor), rectText, StringFormatTabHorizontal); 358 359 // Set rotate back 360 g.Transform = matrixRotate; 361 } 362 363 private Rectangle GetLogicalTabStripRectangle(DockState dockState) 364 { 365 return GetLogicalTabStripRectangle(dockState, false); 366 } 367 368 private Rectangle GetLogicalTabStripRectangle(DockState dockState, bool transformed) 369 { 370 if (!DockHelper.IsDockStateAutoHide(dockState)) 371 return Rectangle.Empty; 372 373 int leftPanes = GetPanes(DockState.DockLeftAutoHide).Count; 374 int rightPanes = GetPanes(DockState.DockRightAutoHide).Count; 375 int topPanes = GetPanes(DockState.DockTopAutoHide).Count; 376 int bottomPanes = GetPanes(DockState.DockBottomAutoHide).Count; 377 378 int x, y, width, height; 379 380 height = MeasureHeight(); 381 if (dockState == DockState.DockLeftAutoHide && leftPanes > 0) 382 { 383 x = 0; 384 y = (topPanes == 0) ? 0 : height; 385 width = Height - (topPanes == 0 ? 0 : height) - (bottomPanes == 0 ? 0 :height); 386 } 387 else if (dockState == DockState.DockRightAutoHide && rightPanes > 0) 388 { 389 x = Width - height; 390 if (leftPanes != 0 && x < height) 391 x = height; 392 y = (topPanes == 0) ? 0 : height; 393 width = Height - (topPanes == 0 ? 0 : height) - (bottomPanes == 0 ? 0 :height); 394 } 395 else if (dockState == DockState.DockTopAutoHide && topPanes > 0) 396 { 397 x = leftPanes == 0 ? 0 : height; 398 y = 0; 399 width = Width - (leftPanes == 0 ? 0 : height) - (rightPanes == 0 ? 0 : height); 400 } 401 else if (dockState == DockState.DockBottomAutoHide && bottomPanes > 0) 402 { 403 x = leftPanes == 0 ? 0 : height; 404 y = Height - height; 405 if (topPanes != 0 && y < height) 406 y = height; 407 width = Width - (leftPanes == 0 ? 0 : height) - (rightPanes == 0 ? 0 : height); 408 } 409 else 410 return Rectangle.Empty; 411 412 if (!transformed) 413 return new Rectangle(x, y, width, height); 414 else 415 return GetTransformedRectangle(dockState, new Rectangle(x, y, width, height)); 416 } 417 418 private Rectangle GetTabRectangle(TabVS2005 tab) 419 { 420 return GetTabRectangle(tab, false); 421 } 422 423 private Rectangle GetTabRectangle(TabVS2005 tab, bool transformed) 424 { 425 DockState dockState = tab.Content.DockHandler.DockState; 426 Rectangle rectTabStrip = GetLogicalTabStripRectangle(dockState); 427 428 if (rectTabStrip.IsEmpty) 429 return Rectangle.Empty; 430 431 int x = tab.TabX; 432 int y = rectTabStrip.Y + 433 (dockState == DockState.DockTopAutoHide || dockState == DockState.DockRightAutoHide ? 434 0 : TabGapTop); 435 int width = tab.TabWidth; 436 int height = rectTabStrip.Height - TabGapTop; 437 438 if (!transformed) 439 return new Rectangle(x, y, width, height); 440 else 441 return GetTransformedRectangle(dockState, new Rectangle(x, y, width, height)); 442 } 443 444 private Rectangle GetTransformedRectangle(DockState dockState, Rectangle rect) 445 { 446 if (dockState != DockState.DockLeftAutoHide && dockState != DockState.DockRightAutoHide) 447 return rect; 448 449 PointF[] pts = new PointF[1]; 450 // the center of the rectangle 451 pts[0].X = (float)rect.X + (float)rect.Width / 2; 452 pts[0].Y = (float)rect.Y + (float)rect.Height / 2; 453 Rectangle rectTabStrip = GetLogicalTabStripRectangle(dockState); 454 Matrix matrix = new Matrix(); 455 matrix.RotateAt(90, new PointF((float)rectTabStrip.X + (float)rectTabStrip.Height / 2, 456 (float)rectTabStrip.Y + (float)rectTabStrip.Height / 2)); 457 matrix.TransformPoints(pts); 458 459 return new Rectangle((int)(pts[0].X - (float)rect.Height / 2 + .5F), 460 (int)(pts[0].Y - (float)rect.Width / 2 + .5F), 461 rect.Height, rect.Width); 462 } 463 464 protected override IDockContent HitTest(Point ptMouse) 465 { 466 foreach(DockState state in DockStates) 467 { 468 Rectangle rectTabStrip = GetLogicalTabStripRectangle(state, true); 469 if (!rectTabStrip.Contains(ptMouse)) 470 continue; 471 472 foreach(Pane pane in GetPanes(state)) 473 { 474 DockState dockState = pane.DockPane.DockState; 475 foreach(TabVS2005 tab in pane.AutoHideTabs) 476 { 477 GraphicsPath path = GetTabOutline(tab, true, true); 478 if (path.IsVisible(ptMouse)) 479 return tab.Content; 480 } 481 } 482 } 483 484 return null; 485 } 486 487 protected internal override int MeasureHeight() 488 { 489 return Math.Max(ImageGapBottom + 490 ImageGapTop + ImageHeight, 491 TextFont.Height) + TabGapTop; 492 } 493 494 protected override void OnRefreshChanges() 495 { 496 CalculateTabs(); 497 Invalidate(); 498 } 499 500 protected override AutoHideStripBase.Tab CreateTab(IDockContent content) 501 { 502 return new TabVS2005(content); 503 } 504 } 419 } 420 421 return null; 422 } 423 424 protected internal override int MeasureHeight() { 425 return Math.Max(ImageGapBottom + 426 ImageGapTop + ImageHeight, 427 TextFont.Height) + TabGapTop; 428 } 429 430 protected override void OnRefreshChanges() { 431 CalculateTabs(); 432 Invalidate(); 433 } 434 435 protected override AutoHideStripBase.Tab CreateTab(IDockContent content) { 436 return new TabVS2005(content); 437 } 438 } 505 439 }
Note: See TracChangeset
for help on using the changeset viewer.