-
Notifications
You must be signed in to change notification settings - Fork 71
/
TitleBarTab.cs
201 lines (174 loc) · 5.49 KB
/
TitleBarTab.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
using Microsoft.WindowsAPICodePack.Taskbar;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace EasyTabs
{
/// <summary>Wraps a <see cref="Form" /> instance (<see cref="_content" />), that represents the content that should be displayed within a tab instance.</summary>
public class TitleBarTab
{
/// <summary>Flag indicating whether or not this tab is active.</summary>
protected bool _active;
/// <summary>Content that should be displayed within the tab.</summary>
protected Form _content;
/// <summary>Parent window that contains this tab.</summary>
protected TitleBarTabs _parent;
/// <summary>Default constructor that initializes the various properties.</summary>
/// <param name="parent">Parent window that contains this tab.</param>
public TitleBarTab(TitleBarTabs parent)
{
ShowCloseButton = true;
Parent = parent;
}
/// <summary>Parent window that contains this tab.</summary>
public TitleBarTabs Parent
{
get
{
return _parent;
}
internal set
{
_parent = value;
if (_content != null)
{
_content.Parent = _parent;
}
}
}
/// <summary>Flag indicating whether or not we should display the close button for this tab.</summary>
public bool ShowCloseButton
{
get;
set;
}
/// <summary>The caption that's displayed in the tab's title (simply uses the <see cref="Form.Text" /> of
/// <see cref="Content" />).</summary>
public string Caption
{
get
{
return Content.Text;
}
set
{
Content.Text = value;
}
}
/// <summary>Flag indicating whether or not this tab is active.</summary>
public bool Active
{
get
{
return _active;
}
internal set
{
// When the status of the tab changes, we null out the TabImage property so that it's recreated in the next rendering pass
_active = value;
TabImage = null;
Content.Visible = value;
}
}
/// <summary>The icon that's displayed in the tab's title (simply uses the <see cref="Form.Icon" /> of <see cref="Content" />).</summary>
public Icon Icon
{
get
{
return Content.Icon;
}
set
{
Content.Icon = value;
}
}
/// <summary>The area in which the tab is rendered in the client window.</summary>
internal Rectangle Area
{
get;
set;
}
/// <summary>The area of the close button for this tab in the client window.</summary>
internal Rectangle CloseButtonArea
{
get;
set;
}
/// <summary>Pre-rendered image of the tab's background.</summary>
internal Bitmap TabImage
{
get;
set;
}
/// <summary>The content that should be displayed for this tab.</summary>
public Form Content
{
get
{
return _content;
}
set
{
if (_content != null)
{
_content.FormClosing -= Content_Closing;
_content.TextChanged -= Content_TextChanged;
}
_content = value;
// We set the content form to a non-top-level child of the parent form.
Content.FormBorderStyle = FormBorderStyle.None;
Content.TopLevel = false;
Content.Parent = Parent;
Content.FormClosing += Content_Closing;
Content.TextChanged += Content_TextChanged;
}
}
/// <summary>
/// Called from <see cref="TornTabForm" /> when we need to generate a thumbnail for a tab when it is torn out of its parent window. We simply call
/// <see cref="Graphics.CopyFromScreen(System.Drawing.Point,System.Drawing.Point,System.Drawing.Size)" /> to copy the screen contents to a
/// <see cref="Bitmap" />.
/// </summary>
/// <returns>An image of the tab's contents.</returns>
public virtual Bitmap GetImage()
{
return TabbedThumbnailScreenCapture.GrabWindowBitmap(Content.Handle, Content.Size);
}
/// <summary>Event that is fired when <see cref="Content" />'s <see cref="Form.Closing" /> event is fired.</summary>
public event CancelEventHandler Closing;
/// <summary>Event that is fired when <see cref="Content" />'s <see cref="Control.TextChanged" /> event is fired.</summary>
public event EventHandler TextChanged;
/// <summary>
/// Event handler that is invoked when <see cref="Content" />'s <see cref="Control.TextChanged" /> event is fired, which in turn fires this class'
/// <see cref="TextChanged" /> event.
/// </summary>
/// <param name="sender">Object from which this event originated (<see cref="Content" /> in this case).</param>
/// <param name="e">Arguments associated with the event.</param>
private void Content_TextChanged(object sender, EventArgs e)
{
if (TextChanged != null)
{
TextChanged(this, e);
}
}
/// <summary>
/// Event handler that is invoked when <see cref="Content" />'s <see cref="Form.Closing" /> event is fired, which in turn fires this class'
/// <see cref="Closing" /> event.
/// </summary>
/// <param name="sender">Object from which this event originated (<see cref="Content" /> in this case).</param>
/// <param name="e">Arguments associated with the event.</param>
protected void Content_Closing(object sender, CancelEventArgs e)
{
if (Closing != null)
{
Closing(this, e);
}
}
/// <summary>Unsubscribes the tab from any event handlers that may have been attached to its <see cref="Closing" /> or <see cref="TextChanged" /> events.</summary>
public void ClearSubscriptions()
{
Closing = null;
TextChanged = null;
}
}
}