/[RomCheater]/trunk/deps/WeifenLuo.WinFormsUI.Docking/DockSample/Customization/VS2003DockPaneStrip.cs
ViewVC logotype

Contents of /trunk/deps/WeifenLuo.WinFormsUI.Docking/DockSample/Customization/VS2003DockPaneStrip.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 140 - (show annotations) (download)
Fri May 11 11:29:29 2012 UTC (9 years, 4 months ago) by william
File size: 36555 byte(s)


1 using System;
2 using System.Drawing;
3 using System.Drawing.Drawing2D;
4 using System.Windows.Forms;
5 using System.ComponentModel;
6 using WeifenLuo.WinFormsUI.Docking;
7
8 namespace DockSample.Customization
9 {
10 internal class VS2003DockPaneStrip : DockPaneStripBase
11 {
12 private class TabVS2003 : Tab
13 {
14 internal TabVS2003(IDockContent content)
15 : base(content)
16 {
17 }
18
19 private int m_tabX;
20 protected internal int TabX
21 {
22 get { return m_tabX; }
23 set { m_tabX = value; }
24 }
25
26 private int m_tabWidth;
27 protected internal int TabWidth
28 {
29 get { return m_tabWidth; }
30 set { m_tabWidth = value; }
31 }
32
33 private int m_maxWidth;
34 protected internal int MaxWidth
35 {
36 get { return m_maxWidth; }
37 set { m_maxWidth = value; }
38 }
39
40 private bool m_flag;
41 protected internal bool Flag
42 {
43 get { return m_flag; }
44 set { m_flag = value; }
45 }
46 }
47
48 protected override DockPaneStripBase.Tab CreateTab(IDockContent content)
49 {
50 return new TabVS2003(content);
51 }
52
53 private class DocumentButton : Label
54 {
55 public DocumentButton(Image image)
56 {
57 Image = image;
58 }
59
60
61 }
62
63 #region consts
64 private const int _ToolWindowStripGapLeft = 4;
65 private const int _ToolWindowStripGapRight = 3;
66 private const int _ToolWindowImageHeight = 16;
67 private const int _ToolWindowImageWidth = 16;
68 private const int _ToolWindowImageGapTop = 3;
69 private const int _ToolWindowImageGapBottom = 1;
70 private const int _ToolWindowImageGapLeft = 3;
71 private const int _ToolWindowImageGapRight = 2;
72 private const int _ToolWindowTextGapRight = 1;
73 private const int _ToolWindowTabSeperatorGapTop = 3;
74 private const int _ToolWindowTabSeperatorGapBottom = 3;
75
76 private const int _DocumentTabMaxWidth = 200;
77 private const int _DocumentButtonGapTop = 5;
78 private const int _DocumentButtonGapBottom = 5;
79 private const int _DocumentButtonGapBetween = 0;
80 private const int _DocumentButtonGapRight = 3;
81 private const int _DocumentTabGapTop = 3;
82 private const int _DocumentTabGapLeft = 3;
83 private const int _DocumentTabGapRight = 3;
84 private const int _DocumentIconGapLeft = 6;
85 private const int _DocumentIconHeight = 16;
86 private const int _DocumentIconWidth = 16;
87 #endregion
88
89 private InertButton m_buttonClose, m_buttonScrollLeft, m_buttonScrollRight;
90 private IContainer m_components;
91 private ToolTip m_toolTip;
92
93 /// <exclude/>
94 protected IContainer Components
95 {
96 get { return m_components; }
97 }
98
99 private int m_offsetX = 0;
100 private int OffsetX
101 {
102 get { return m_offsetX; }
103 set
104 {
105 m_offsetX = value;
106 #if DEBUG
107 if (m_offsetX > 0)
108 throw new InvalidOperationException();
109 #endif
110 }
111 }
112
113 #region Customizable Properties
114 /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ToolWindowStripGapLeft"]/*'/>
115 protected virtual int ToolWindowStripGapLeft
116 {
117 get { return _ToolWindowStripGapLeft; }
118 }
119
120 /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ToolWindowStripGapRight"]/*'/>
121 protected virtual int ToolWindowStripGapRight
122 {
123 get { return _ToolWindowStripGapRight; }
124 }
125
126 /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ToolWindowImageHeight"]/*'/>
127 protected virtual int ToolWindowImageHeight
128 {
129 get { return _ToolWindowImageHeight; }
130 }
131
132 /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ToolWindowImageWidth"]/*'/>
133 protected virtual int ToolWindowImageWidth
134 {
135 get { return _ToolWindowImageWidth; }
136 }
137
138 /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ToolWindowImageGapTop"]/*'/>
139 protected virtual int ToolWindowImageGapTop
140 {
141 get { return _ToolWindowImageGapTop; }
142 }
143
144 /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ToolWindowImageGapBottom"]/*'/>
145 protected virtual int ToolWindowImageGapBottom
146 {
147 get { return _ToolWindowImageGapBottom; }
148 }
149
150 /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ToolWindowImageGapLeft"]/*'/>
151 protected virtual int ToolWindowImageGapLeft
152 {
153 get { return _ToolWindowImageGapLeft; }
154 }
155
156 /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ToolWindowImageGapRight"]/*'/>
157 protected virtual int ToolWindowImageGapRight
158 {
159 get { return _ToolWindowImageGapRight; }
160 }
161
162 /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ToolWindowTextGapRight"]/*'/>
163 protected virtual int ToolWindowTextGapRight
164 {
165 get { return _ToolWindowTextGapRight; }
166 }
167
168 /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ToolWindowSeperatorGaptop"]/*'/>
169 protected virtual int ToolWindowTabSeperatorGapTop
170 {
171 get { return _ToolWindowTabSeperatorGapTop; }
172 }
173
174 /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ToolWindowSeperatorGapBottom"]/*'/>
175 protected virtual int ToolWindowTabSeperatorGapBottom
176 {
177 get { return _ToolWindowTabSeperatorGapBottom; }
178 }
179
180 private static Image _imageCloseEnabled = null;
181 /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ImageCloseEnabled"]/*'/>
182 protected virtual Image ImageCloseEnabled
183 {
184 get
185 {
186 if (_imageCloseEnabled == null)
187 _imageCloseEnabled = Resources.DockPaneStrip_CloseEnabled;
188 return _imageCloseEnabled;
189 }
190 }
191
192 private static Image _imageCloseDisabled = null;
193 /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ImageCloseDisabled"]/*'/>
194 protected virtual Image ImageCloseDisabled
195 {
196 get
197 {
198 if (_imageCloseDisabled == null)
199 _imageCloseDisabled = Resources.DockPaneStrip_CloseDisabled;
200 return _imageCloseDisabled;
201 }
202 }
203
204 private static Image _imageScrollLeftEnabled = null;
205 /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ImageScrollLeftEnabled"]/*'/>
206 protected virtual Image ImageScrollLeftEnabled
207 {
208 get
209 {
210 if (_imageScrollLeftEnabled == null)
211 _imageScrollLeftEnabled = Resources.DockPaneStrip_ScrollLeftEnabled;
212 return _imageScrollLeftEnabled;
213 }
214 }
215
216 private static Image _imageScrollLeftDisabled = null;
217 /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ImageScrollLeftDisabled"]/*'/>
218 protected virtual Image ImageScrollLeftDisabled
219 {
220 get
221 {
222 if (_imageScrollLeftDisabled == null)
223 _imageScrollLeftDisabled = Resources.DockPaneStrip_ScrollLeftDisabled;
224 return _imageScrollLeftDisabled;
225 }
226 }
227
228 private static Image _imageScrollRightEnabled = null;
229 /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ImageScrollRightEnabled"]/*'/>
230 protected virtual Image ImageScrollRightEnabled
231 {
232 get
233 {
234 if (_imageScrollRightEnabled == null)
235 _imageScrollRightEnabled = Resources.DockPaneStrip_ScrollRightEnabled;
236 return _imageScrollRightEnabled;
237 }
238 }
239
240 private static Image _imageScrollRightDisabled = null;
241 /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ImageScrollRightDisabled"]/*'/>
242 protected virtual Image ImageScrollRightDisabled
243 {
244 get
245 {
246 if (_imageScrollRightDisabled == null)
247 _imageScrollRightDisabled = Resources.DockPaneStrip_ScrollRightDisabled;
248 return _imageScrollRightDisabled;
249 }
250 }
251
252 private static string _toolTipClose = null;
253 /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ToolTipClose"]/*'/>
254 protected virtual string ToolTipClose
255 {
256 get
257 {
258 if (_toolTipClose == null)
259 _toolTipClose = Strings.DockPaneStrip_ToolTipClose;
260 return _toolTipClose;
261 }
262 }
263
264 private static string _toolTipScrollLeft = null;
265 /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ToolTipScrollLeft"]/*'/>
266 protected virtual string ToolTipScrollLeft
267 {
268 get
269 {
270 if (_toolTipScrollLeft == null)
271 _toolTipScrollLeft = Strings.DockPaneStrip_ToolTipScrollLeft;
272 return _toolTipScrollLeft;
273 }
274 }
275
276 private static string _toolTipScrollRight = null;
277 /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ToolTipScrollRight"]/*'/>
278 protected virtual string ToolTipScrollRight
279 {
280 get
281 {
282 if (_toolTipScrollRight == null)
283 _toolTipScrollRight = Strings.DockPaneStrip_ToolTipScrollRight;
284 return _toolTipScrollRight;
285 }
286 }
287
288 private static TextFormatFlags _toolWindowTextFormat =
289 TextFormatFlags.EndEllipsis |
290 TextFormatFlags.HorizontalCenter |
291 TextFormatFlags.SingleLine |
292 TextFormatFlags.VerticalCenter;
293 /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ToolWindowTextStringFormat"]/*'/>
294 protected virtual TextFormatFlags ToolWindowTextFormat
295 {
296 get { return _toolWindowTextFormat; }
297 }
298
299 private static TextFormatFlags _documentTextFormat =
300 TextFormatFlags.PathEllipsis |
301 TextFormatFlags.SingleLine |
302 TextFormatFlags.VerticalCenter;
303 /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="DocumentTextStringFormat"]/*'/>
304 public static TextFormatFlags DocumentTextFormat
305 {
306 get { return _documentTextFormat; }
307 }
308
309 /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="DocumentTabMaxWidth"]/*'/>
310 protected virtual int DocumentTabMaxWidth
311 {
312 get { return _DocumentTabMaxWidth; }
313 }
314
315 /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="DocumentButtonGapTop"]/*'/>
316 protected virtual int DocumentButtonGapTop
317 {
318 get { return _DocumentButtonGapTop; }
319 }
320
321 /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="DocumentButtonGapBottom"]/*'/>
322 protected virtual int DocumentButtonGapBottom
323 {
324 get { return _DocumentButtonGapBottom; }
325 }
326
327 /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="DocumentButtonGapBetween"]/*'/>
328 protected virtual int DocumentButtonGapBetween
329 {
330 get { return _DocumentButtonGapBetween; }
331 }
332
333 /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="DocumentButtonGapRight"]/*'/>
334 protected virtual int DocumentButtonGapRight
335 {
336 get { return _DocumentButtonGapRight; }
337 }
338
339 /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="DocumentTabGapTop"]/*'/>
340 protected virtual int DocumentTabGapTop
341 {
342 get { return _DocumentTabGapTop; }
343 }
344
345 /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="DocumentTabGapLeft"]/*'/>
346 protected virtual int DocumentTabGapLeft
347 {
348 get { return _DocumentTabGapLeft; }
349 }
350
351 /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="DocumentTabGapRight"]/*'/>
352 protected virtual int DocumentTabGapRight
353 {
354 get { return _DocumentTabGapRight; }
355 }
356
357 /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="DocumentIconGapLeft"]/*'/>
358 protected virtual int DocumentIconGapLeft
359 {
360 get { return _DocumentIconGapLeft; }
361 }
362
363 /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="DocumentIconWidth"]/*'/>
364 protected virtual int DocumentIconWidth
365 {
366 get { return _DocumentIconWidth; }
367 }
368
369 /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="DocumentIconHeight"]/*'/>
370 protected virtual int DocumentIconHeight
371 {
372 get { return _DocumentIconHeight; }
373 }
374
375 /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="OutlineInnerPen"]/*'/>
376 protected virtual Pen OutlineInnerPen
377 {
378 get { return SystemPens.ControlText; }
379 }
380
381 /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="OutlineOuterPen"]/*'/>
382 protected virtual Pen OutlineOuterPen
383 {
384 get { return SystemPens.ActiveCaptionText; }
385 }
386
387 /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ActiveBackBrush"]/*'/>
388 protected virtual Brush ActiveBackBrush
389 {
390 get { return SystemBrushes.Control; }
391 }
392
393 /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ActiveTextBrush"]/*'/>
394 protected virtual Color ActiveTextColor
395 {
396 get { return SystemColors.ControlText; }
397 }
398
399 /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="TabSeperatorPen"]/*'/>
400 protected virtual Pen TabSeperatorPen
401 {
402 get { return SystemPens.GrayText; }
403 }
404
405 /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="InactiveTextBrush"]/*'/>
406 protected virtual Color InactiveTextColor
407 {
408 get { return SystemColors.ControlDarkDark; }
409 }
410 #endregion
411
412 public VS2003DockPaneStrip(DockPane pane) : base(pane)
413 {
414 SetStyle(ControlStyles.ResizeRedraw, true);
415 SetStyle(ControlStyles.UserPaint, true);
416 SetStyle(ControlStyles.AllPaintingInWmPaint, true);
417
418 SuspendLayout();
419
420 Font = SystemInformation.MenuFont;
421 BackColor = Color.WhiteSmoke;
422
423 m_components = new Container();
424 m_toolTip = new ToolTip(Components);
425
426 m_buttonClose = new InertButton(ImageCloseEnabled, ImageCloseDisabled);
427 m_buttonScrollLeft = new InertButton(ImageScrollLeftEnabled, ImageScrollLeftDisabled);
428 m_buttonScrollRight = new InertButton(ImageScrollRightEnabled, ImageScrollRightDisabled);
429
430 m_buttonClose.ToolTipText = ToolTipClose;
431 m_buttonClose.Anchor = AnchorStyles.Top | AnchorStyles.Right;
432 m_buttonClose.Click += new EventHandler(Close_Click);
433
434 m_buttonScrollLeft.Enabled = false;
435 m_buttonScrollLeft.RepeatClick = true;
436 m_buttonScrollLeft.ToolTipText = ToolTipScrollLeft;
437 m_buttonScrollLeft.Anchor = AnchorStyles.Top | AnchorStyles.Right;
438 m_buttonScrollLeft.Click += new EventHandler(ScrollLeft_Click);
439
440 m_buttonScrollRight.Enabled = false;
441 m_buttonScrollRight.RepeatClick = true;
442 m_buttonScrollRight.ToolTipText = ToolTipScrollRight;
443 m_buttonScrollRight.Anchor = AnchorStyles.Top | AnchorStyles.Right;
444 m_buttonScrollRight.Click += new EventHandler(ScrollRight_Click);
445
446 Controls.AddRange(new Control[] { m_buttonClose,
447 m_buttonScrollLeft,
448 m_buttonScrollRight });
449
450 ResumeLayout();
451 }
452
453 protected override void Dispose(bool disposing)
454 {
455 if (disposing)
456 {
457 Components.Dispose();
458 }
459 base.Dispose (disposing);
460 }
461
462 protected override int MeasureHeight()
463 {
464 if (Appearance == DockPane.AppearanceStyle.ToolWindow)
465 return MeasureHeight_ToolWindow();
466 else
467 return MeasureHeight_Document();
468 }
469
470 private int MeasureHeight_ToolWindow()
471 {
472 if (DockPane.IsAutoHide || Tabs.Count <= 1)
473 return 0;
474
475 int height = Math.Max(Font.Height, ToolWindowImageHeight)
476 + ToolWindowImageGapTop + ToolWindowImageGapBottom;
477
478 return height;
479 }
480
481 private int MeasureHeight_Document()
482 {
483 int height = Math.Max(Font.Height + DocumentTabGapTop,
484 ImageCloseEnabled.Height + DocumentButtonGapTop + DocumentButtonGapBottom);
485
486 return height;
487 }
488
489 protected override void OnPaint(PaintEventArgs e)
490 {
491 base.OnPaint (e);
492 CalculateTabs();
493 DrawTabStrip(e.Graphics);
494 }
495
496 protected override void OnRefreshChanges()
497 {
498 CalculateTabs();
499 SetInertButtons();
500 Invalidate();
501 }
502
503 protected override GraphicsPath GetOutline(int index)
504 {
505 Point[] pts = new Point[8];
506
507 if (Appearance == DockPane.AppearanceStyle.Document)
508 {
509 Rectangle rectTab = GetTabRectangle(index);
510 rectTab.Intersect(TabsRectangle);
511 int y = DockPane.PointToClient(PointToScreen(new Point(0, rectTab.Bottom))).Y;
512 Rectangle rectPaneClient = DockPane.ClientRectangle;
513 pts[0] = DockPane.PointToScreen(new Point(rectPaneClient.Left, y));
514 pts[1] = PointToScreen(new Point(rectTab.Left, rectTab.Bottom));
515 pts[2] = PointToScreen(new Point(rectTab.Left, rectTab.Top));
516 pts[3] = PointToScreen(new Point(rectTab.Right, rectTab.Top));
517 pts[4] = PointToScreen(new Point(rectTab.Right, rectTab.Bottom));
518 pts[5] = DockPane.PointToScreen(new Point(rectPaneClient.Right, y));
519 pts[6] = DockPane.PointToScreen(new Point(rectPaneClient.Right, rectPaneClient.Bottom));
520 pts[7] = DockPane.PointToScreen(new Point(rectPaneClient.Left, rectPaneClient.Bottom));
521 }
522 else
523 {
524 Rectangle rectTab = GetTabRectangle(index);
525 rectTab.Intersect(TabsRectangle);
526 int y = DockPane.PointToClient(PointToScreen(new Point(0, rectTab.Top))).Y;
527 Rectangle rectPaneClient = DockPane.ClientRectangle;
528 pts[0] = DockPane.PointToScreen(new Point(rectPaneClient.Left, rectPaneClient.Top));
529 pts[1] = DockPane.PointToScreen(new Point(rectPaneClient.Right, rectPaneClient.Top));
530 pts[2] = DockPane.PointToScreen(new Point(rectPaneClient.Right, y));
531 pts[3] = PointToScreen(new Point(rectTab.Right, rectTab.Top));
532 pts[4] = PointToScreen(new Point(rectTab.Right, rectTab.Bottom));
533 pts[5] = PointToScreen(new Point(rectTab.Left, rectTab.Bottom));
534 pts[6] = PointToScreen(new Point(rectTab.Left, rectTab.Top));
535 pts[7] = DockPane.PointToScreen(new Point(rectPaneClient.Left, y));
536 }
537
538 GraphicsPath path = new GraphicsPath();
539 path.AddLines(pts);
540 return path;
541 }
542
543 private void CalculateTabs()
544 {
545 if (Appearance == DockPane.AppearanceStyle.ToolWindow)
546 CalculateTabs_ToolWindow();
547 else
548 CalculateTabs_Document();
549 }
550
551 private void CalculateTabs_ToolWindow()
552 {
553 if (Tabs.Count <= 1 || DockPane.IsAutoHide)
554 return;
555
556 Rectangle rectTabStrip = ClientRectangle;
557
558 // Calculate tab widths
559 int countTabs = Tabs.Count;
560 foreach (TabVS2003 tab in Tabs)
561 {
562 tab.MaxWidth = GetTabOriginalWidth(Tabs.IndexOf(tab));
563 tab.Flag = false;
564 }
565
566 // Set tab whose max width less than average width
567 bool anyWidthWithinAverage = true;
568 int totalWidth = rectTabStrip.Width - ToolWindowStripGapLeft - ToolWindowStripGapRight;
569 int totalAllocatedWidth = 0;
570 int averageWidth = totalWidth / countTabs;
571 int remainedTabs = countTabs;
572 for (anyWidthWithinAverage=true; anyWidthWithinAverage && remainedTabs>0;)
573 {
574 anyWidthWithinAverage = false;
575 foreach (TabVS2003 tab in Tabs)
576 {
577 if (tab.Flag)
578 continue;
579
580 if (tab.MaxWidth <= averageWidth)
581 {
582 tab.Flag = true;
583 tab.TabWidth = tab.MaxWidth;
584 totalAllocatedWidth += tab.TabWidth;
585 anyWidthWithinAverage = true;
586 remainedTabs--;
587 }
588 }
589 if (remainedTabs != 0)
590 averageWidth = (totalWidth - totalAllocatedWidth) / remainedTabs;
591 }
592
593 // If any tab width not set yet, set it to the average width
594 if (remainedTabs > 0)
595 {
596 int roundUpWidth = (totalWidth - totalAllocatedWidth) - (averageWidth * remainedTabs);
597 foreach (TabVS2003 tab in Tabs)
598 {
599 if (tab.Flag)
600 continue;
601
602 tab.Flag = true;
603 if (roundUpWidth > 0)
604 {
605 tab.TabWidth = averageWidth + 1;
606 roundUpWidth --;
607 }
608 else
609 tab.TabWidth = averageWidth;
610 }
611 }
612
613 // Set the X position of the tabs
614 int x = rectTabStrip.X + ToolWindowStripGapLeft;
615 foreach (TabVS2003 tab in Tabs)
616 {
617 tab.TabX = x;
618 x += tab.TabWidth;
619 }
620 }
621
622 private void CalculateTabs_Document()
623 {
624 Rectangle rectTabStrip = TabsRectangle;
625
626 int totalWidth = 0;
627 foreach (TabVS2003 tab in Tabs)
628 {
629 tab.TabWidth = Math.Min(GetTabOriginalWidth(Tabs.IndexOf(tab)), DocumentTabMaxWidth);
630 totalWidth += tab.TabWidth;
631 }
632
633 if (totalWidth + OffsetX < rectTabStrip.Width && OffsetX < 0)
634 OffsetX = Math.Min(0, rectTabStrip.Width - totalWidth);
635
636 int x = rectTabStrip.X + OffsetX;
637 foreach (TabVS2003 tab in Tabs)
638 {
639 tab.TabX = x;
640 x += tab.TabWidth;
641 }
642 }
643
644 protected override void EnsureTabVisible(IDockContent content)
645 {
646 if (Appearance != DockPane.AppearanceStyle.Document || !Tabs.Contains(content))
647 return;
648
649 Rectangle rectTabStrip = TabsRectangle;
650 Rectangle rectTab = GetTabRectangle(Tabs.IndexOf(content));
651
652 if (rectTab.Right > rectTabStrip.Right)
653 {
654 OffsetX -= rectTab.Right - rectTabStrip.Right;
655 rectTab.X -= rectTab.Right - rectTabStrip.Right;
656 }
657
658 if (rectTab.Left < rectTabStrip.Left)
659 OffsetX += rectTabStrip.Left - rectTab.Left;
660
661 OnRefreshChanges();
662 }
663
664 private int GetTabOriginalWidth(int index)
665 {
666 if (Appearance == DockPane.AppearanceStyle.ToolWindow)
667 return GetTabOriginalWidth_ToolWindow(index);
668 else
669 return GetTabOriginalWidth_Document(index);
670 }
671
672 private int GetTabOriginalWidth_ToolWindow(int index)
673 {
674 IDockContent content = Tabs[index].Content;
675 using (Graphics g = CreateGraphics())
676 {
677 Size sizeString = TextRenderer.MeasureText(g, content.DockHandler.TabText, Font);
678 return ToolWindowImageWidth + sizeString.Width + ToolWindowImageGapLeft
679 + ToolWindowImageGapRight + ToolWindowTextGapRight;
680 }
681 }
682
683 private int GetTabOriginalWidth_Document(int index)
684 {
685 IDockContent content = Tabs[index].Content;
686
687 int height = GetTabRectangle_Document(index).Height;
688
689 using (Graphics g = CreateGraphics())
690 {
691 Size sizeText;
692 if (content == DockPane.ActiveContent && DockPane.IsActiveDocumentPane)
693 {
694 using (Font boldFont = new Font(this.Font, FontStyle.Bold))
695 {
696 sizeText = TextRenderer.MeasureText(g, content.DockHandler.TabText, boldFont, new Size(DocumentTabMaxWidth, height), DocumentTextFormat);
697 }
698 }
699 else
700 sizeText = TextRenderer.MeasureText(content.DockHandler.TabText, Font, new Size(DocumentTabMaxWidth, height), DocumentTextFormat);
701
702 if (DockPane.DockPanel.ShowDocumentIcon)
703 return sizeText.Width + DocumentIconWidth + DocumentIconGapLeft;
704 else
705 return sizeText.Width;
706 }
707 }
708
709 private void DrawTabStrip(Graphics g)
710 {
711 OnBeginDrawTabStrip();
712
713 if (Appearance == DockPane.AppearanceStyle.Document)
714 DrawTabStrip_Document(g);
715 else
716 DrawTabStrip_ToolWindow(g);
717
718 OnEndDrawTabStrip();
719 }
720
721 private void DrawTabStrip_Document(Graphics g)
722 {
723 int count = Tabs.Count;
724 if (count == 0)
725 return;
726
727 Rectangle rectTabStrip = ClientRectangle;
728 g.DrawLine(OutlineOuterPen, rectTabStrip.Left, rectTabStrip.Bottom - 1,
729 rectTabStrip.Right, rectTabStrip.Bottom - 1);
730
731 // Draw the tabs
732 Rectangle rectTabOnly = TabsRectangle;
733 Rectangle rectTab = Rectangle.Empty;
734 g.SetClip(rectTabOnly);
735 for (int i=0; i<count; i++)
736 {
737 rectTab = GetTabRectangle(i);
738 if (rectTab.IntersectsWith(rectTabOnly))
739 DrawTab(g, Tabs[i] as TabVS2003, rectTab);
740 }
741 }
742
743 private void DrawTabStrip_ToolWindow(Graphics g)
744 {
745 Rectangle rectTabStrip = ClientRectangle;
746
747 g.DrawLine(OutlineInnerPen, rectTabStrip.Left, rectTabStrip.Top,
748 rectTabStrip.Right, rectTabStrip.Top);
749
750 for (int i=0; i<Tabs.Count; i++)
751 DrawTab(g, Tabs[i] as TabVS2003, GetTabRectangle(i));
752 }
753
754 private Rectangle GetTabRectangle(int index)
755 {
756 if (Appearance == DockPane.AppearanceStyle.ToolWindow)
757 return GetTabRectangle_ToolWindow(index);
758 else
759 return GetTabRectangle_Document(index);
760 }
761
762 private Rectangle GetTabRectangle_ToolWindow(int index)
763 {
764 Rectangle rectTabStrip = ClientRectangle;
765
766 TabVS2003 tab = (TabVS2003)(Tabs[index]);
767 return new Rectangle(tab.TabX, rectTabStrip.Y, tab.TabWidth, rectTabStrip.Height);
768 }
769
770 private Rectangle GetTabRectangle_Document(int index)
771 {
772 Rectangle rectTabStrip = ClientRectangle;
773 TabVS2003 tab = (TabVS2003)Tabs[index];
774
775 return new Rectangle(tab.TabX, rectTabStrip.Y + DocumentTabGapTop, tab.TabWidth, rectTabStrip.Height - DocumentTabGapTop);
776 }
777
778 private void DrawTab(Graphics g, TabVS2003 tab, Rectangle rect)
779 {
780 OnBeginDrawTab(tab);
781
782 if (Appearance == DockPane.AppearanceStyle.ToolWindow)
783 DrawTab_ToolWindow(g, tab, rect);
784 else
785 DrawTab_Document(g, tab, rect);
786
787 OnEndDrawTab(tab);
788 }
789
790 private void DrawTab_ToolWindow(Graphics g, TabVS2003 tab, Rectangle rect)
791 {
792 Rectangle rectIcon = new Rectangle(
793 rect.X + ToolWindowImageGapLeft,
794 rect.Y + rect.Height - 1 - ToolWindowImageGapBottom - ToolWindowImageHeight,
795 ToolWindowImageWidth, ToolWindowImageHeight);
796 Rectangle rectText = rectIcon;
797 rectText.X += rectIcon.Width + ToolWindowImageGapRight;
798 rectText.Width = rect.Width - rectIcon.Width - ToolWindowImageGapLeft -
799 ToolWindowImageGapRight - ToolWindowTextGapRight;
800
801 if (DockPane.ActiveContent == tab.Content)
802 {
803 g.FillRectangle(ActiveBackBrush, rect);
804 g.DrawLine(OutlineOuterPen,
805 rect.X, rect.Y, rect.X, rect.Y + rect.Height - 1);
806 g.DrawLine(OutlineInnerPen,
807 rect.X, rect.Y + rect.Height - 1, rect.X + rect.Width - 1, rect.Y + rect.Height - 1);
808 g.DrawLine(OutlineInnerPen,
809 rect.X + rect.Width - 1, rect.Y, rect.X + rect.Width - 1, rect.Y + rect.Height - 1);
810 TextRenderer.DrawText(g, tab.Content.DockHandler.TabText, Font, rectText, ActiveTextColor, ToolWindowTextFormat);
811 }
812 else
813 {
814 if (Tabs.IndexOf(DockPane.ActiveContent) != Tabs.IndexOf(tab) + 1)
815 g.DrawLine(TabSeperatorPen,
816 rect.X + rect.Width - 1,
817 rect.Y + ToolWindowTabSeperatorGapTop,
818 rect.X + rect.Width - 1,
819 rect.Y + rect.Height - 1 - ToolWindowTabSeperatorGapBottom);
820 TextRenderer.DrawText(g, tab.Content.DockHandler.TabText, Font, rectText, InactiveTextColor, ToolWindowTextFormat);
821 }
822
823 if (rect.Contains(rectIcon))
824 g.DrawIcon(tab.Content.DockHandler.Icon, rectIcon);
825 }
826
827 private void DrawTab_Document(Graphics g, TabVS2003 tab, Rectangle rect)
828 {
829 Rectangle rectText = rect;
830 if (DockPane.DockPanel.ShowDocumentIcon)
831 {
832 rectText.X += DocumentIconWidth + DocumentIconGapLeft;
833 rectText.Width -= DocumentIconWidth + DocumentIconGapLeft;
834 }
835
836 if (DockPane.ActiveContent == tab.Content)
837 {
838 g.FillRectangle(ActiveBackBrush, rect);
839 g.DrawLine(OutlineOuterPen, rect.X, rect.Y, rect.X, rect.Y + rect.Height);
840 g.DrawLine(OutlineOuterPen, rect.X, rect.Y, rect.X + rect.Width - 1, rect.Y);
841 g.DrawLine(OutlineInnerPen,
842 rect.X + rect.Width - 1, rect.Y,
843 rect.X + rect.Width - 1, rect.Y + rect.Height - 1);
844
845 if (DockPane.DockPanel.ShowDocumentIcon)
846 {
847 Icon icon = (tab.Content as Form).Icon;
848 Rectangle rectIcon = new Rectangle(
849 rect.X + DocumentIconGapLeft,
850 rect.Y + (rect.Height - DocumentIconHeight) / 2,
851 DocumentIconWidth, DocumentIconHeight);
852
853 g.DrawIcon(tab.ContentForm.Icon, rectIcon);
854 }
855
856 if (DockPane.IsActiveDocumentPane)
857 {
858 using (Font boldFont = new Font(this.Font, FontStyle.Bold))
859 {
860 TextRenderer.DrawText(g, tab.Content.DockHandler.TabText, boldFont, rectText, ActiveTextColor, DocumentTextFormat);
861 }
862 }
863 else
864 TextRenderer.DrawText(g, tab.Content.DockHandler.TabText, Font, rectText, InactiveTextColor, DocumentTextFormat);
865 }
866 else
867 {
868 if (Tabs.IndexOf(DockPane.ActiveContent) != Tabs.IndexOf(tab) + 1)
869 g.DrawLine(TabSeperatorPen,
870 rect.X + rect.Width - 1, rect.Y,
871 rect.X + rect.Width - 1, rect.Y + rect.Height - 1 - DocumentTabGapTop);
872
873 if (DockPane.DockPanel.ShowDocumentIcon)
874 {
875 Icon icon = tab.ContentForm.Icon;
876 Rectangle rectIcon = new Rectangle(
877 rect.X + DocumentIconGapLeft,
878 rect.Y + (rect.Height - DocumentIconHeight) / 2,
879 DocumentIconWidth, DocumentIconHeight);
880
881 g.DrawIcon(tab.ContentForm.Icon, rectIcon);
882 }
883
884 TextRenderer.DrawText(g, tab.Content.DockHandler.TabText, Font, rectText, InactiveTextColor, DocumentTextFormat);
885 }
886 }
887
888 private Rectangle TabsRectangle
889 {
890 get
891 {
892 if (Appearance == DockPane.AppearanceStyle.ToolWindow)
893 return ClientRectangle;
894
895 Rectangle rectWindow = ClientRectangle;
896 int x = rectWindow.X;
897 int y = rectWindow.Y;
898 int width = rectWindow.Width;
899 int height = rectWindow.Height;
900
901 x += DocumentTabGapLeft;
902 width -= DocumentTabGapLeft +
903 DocumentTabGapRight +
904 DocumentButtonGapRight +
905 m_buttonClose.Width +
906 m_buttonScrollRight.Width +
907 m_buttonScrollLeft.Width +
908 2 * DocumentButtonGapBetween;
909
910 return new Rectangle(x, y, width, height);
911 }
912 }
913
914 private void ScrollLeft_Click(object sender, EventArgs e)
915 {
916 Rectangle rectTabStrip = TabsRectangle;
917
918 int index;
919 for (index=0; index<Tabs.Count; index++)
920 if (GetTabRectangle(index).IntersectsWith(rectTabStrip))
921 break;
922
923 Rectangle rectTab = GetTabRectangle(index);
924 if (rectTab.Left < rectTabStrip.Left)
925 OffsetX += rectTabStrip.Left - rectTab.Left;
926 else if (index == 0)
927 OffsetX = 0;
928 else
929 OffsetX += rectTabStrip.Left - GetTabRectangle(index - 1).Left;
930
931 OnRefreshChanges();
932 }
933
934 private void ScrollRight_Click(object sender, EventArgs e)
935 {
936 Rectangle rectTabStrip = TabsRectangle;
937
938 int index;
939 int count = Tabs.Count;
940 for (index=0; index<count; index++)
941 if (GetTabRectangle(index).IntersectsWith(rectTabStrip))
942 break;
943
944 if (index + 1 < count)
945 {
946 OffsetX -= GetTabRectangle(index + 1).Left - rectTabStrip.Left;
947 CalculateTabs();
948 }
949
950 Rectangle rectLastTab = GetTabRectangle(count - 1);
951 if (rectLastTab.Right < rectTabStrip.Right)
952 OffsetX += rectTabStrip.Right - rectLastTab.Right;
953
954 OnRefreshChanges();
955 }
956
957 private void SetInertButtons()
958 {
959 // Set the visibility of the inert buttons
960 m_buttonScrollLeft.Visible = m_buttonScrollRight.Visible = m_buttonClose.Visible = (DockPane.DockState == DockState.Document);
961
962 m_buttonClose.ForeColor = m_buttonScrollRight.ForeColor = m_buttonScrollLeft.ForeColor = SystemColors.ControlDarkDark;
963 m_buttonClose.BorderColor = m_buttonScrollRight.BorderColor = m_buttonScrollLeft.BorderColor = SystemColors.ControlDarkDark;
964
965 // Enable/disable scroll buttons
966 int count = Tabs.Count;
967
968 Rectangle rectTabOnly = TabsRectangle;
969 Rectangle rectTab = (count == 0) ? Rectangle.Empty : GetTabRectangle(count - 1);
970 m_buttonScrollLeft.Enabled = (OffsetX < 0);
971 m_buttonScrollRight.Enabled = rectTab.Right > rectTabOnly.Right;
972
973 // show/hide close button
974 if (Appearance == DockPane.AppearanceStyle.ToolWindow)
975 m_buttonClose.Visible = false;
976 else
977 {
978 bool showCloseButton = DockPane.ActiveContent == null ? true : DockPane.ActiveContent.DockHandler.CloseButton;
979 if (m_buttonClose.Visible != showCloseButton)
980 {
981 m_buttonClose.Visible = showCloseButton;
982 PerformLayout();
983 }
984 }
985 }
986
987 /// <exclude/>
988 protected override void OnLayout(LayoutEventArgs levent)
989 {
990 Rectangle rectTabStrip = ClientRectangle;
991
992 // Set position and size of the buttons
993 int buttonWidth = ImageCloseEnabled.Width;
994 int buttonHeight = ImageCloseEnabled.Height;
995 int height = rectTabStrip.Height - DocumentButtonGapTop - DocumentButtonGapBottom;
996 if (buttonHeight < height)
997 {
998 buttonWidth = buttonWidth * (height / buttonHeight);
999 buttonHeight = height;
1000 }
1001 Size buttonSize = new Size(buttonWidth, buttonHeight);
1002 m_buttonClose.Size = m_buttonScrollLeft.Size = m_buttonScrollRight.Size = buttonSize;
1003 int x = rectTabStrip.X + rectTabStrip.Width - DocumentTabGapLeft
1004 - DocumentButtonGapRight - buttonWidth;
1005 int y = rectTabStrip.Y + DocumentButtonGapTop;
1006 m_buttonClose.Location = new Point(x, y);
1007 Point point = m_buttonClose.Location;
1008 bool showCloseButton = DockPane.ActiveContent == null ? true : DockPane.ActiveContent.DockHandler.CloseButton;
1009 if (showCloseButton)
1010 point.Offset(-(DocumentButtonGapBetween + buttonWidth), 0);
1011 m_buttonScrollRight.Location = point;
1012 point.Offset(-(DocumentButtonGapBetween + buttonWidth), 0);
1013 m_buttonScrollLeft.Location = point;
1014
1015 OnRefreshChanges();
1016
1017 base.OnLayout (levent);
1018 }
1019
1020 private void Close_Click(object sender, EventArgs e)
1021 {
1022 DockPane.CloseActiveContent();
1023 }
1024
1025 /// <exclude/>
1026 protected override int HitTest(Point ptMouse)
1027 {
1028 Rectangle rectTabStrip = TabsRectangle;
1029
1030 for (int i=0; i<Tabs.Count; i++)
1031 {
1032 Rectangle rectTab = GetTabRectangle(i);
1033 rectTab.Intersect(rectTabStrip);
1034 if (rectTab.Contains(ptMouse))
1035 return i;
1036 }
1037 return -1;
1038 }
1039
1040 /// <exclude/>
1041 protected override void OnMouseMove(MouseEventArgs e)
1042 {
1043 int index = HitTest(PointToClient(Control.MousePosition));
1044 string toolTip = string.Empty;
1045
1046 base.OnMouseMove(e);
1047
1048 if (index != -1)
1049 {
1050 Rectangle rectTab = GetTabRectangle(index);
1051 if (Tabs[index].Content.DockHandler.ToolTipText != null)
1052 toolTip = Tabs[index].Content.DockHandler.ToolTipText;
1053 else if (rectTab.Width < GetTabOriginalWidth(index))
1054 toolTip = Tabs[index].Content.DockHandler.TabText;
1055 }
1056
1057 if (m_toolTip.GetToolTip(this) != toolTip)
1058 {
1059 m_toolTip.Active = false;
1060 m_toolTip.SetToolTip(this, toolTip);
1061 m_toolTip.Active = true;
1062 }
1063 }
1064
1065 /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Method[@name="OnBeginDrawTabStrip()"]/*'/>
1066 protected virtual void OnBeginDrawTabStrip()
1067 {
1068 }
1069
1070 /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Method[@name="OnEndDrawTabStrip()"]/*'/>
1071 protected virtual void OnEndDrawTabStrip()
1072 {
1073 }
1074
1075 /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Method[@name="OnBeginDrawTab(DockPaneTab)"]/*'/>
1076 protected virtual void OnBeginDrawTab(Tab tab)
1077 {
1078 }
1079
1080 /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Method[@name="OnEndDrawTab(DockPaneTab)"]/*'/>
1081 protected virtual void OnEndDrawTab(Tab tab)
1082 {
1083 }
1084 }
1085 }

  ViewVC Help
Powered by ViewVC 1.1.22