1 | ///
|
---|
2 | /// This file is part of ILNumerics Community Edition.
|
---|
3 | ///
|
---|
4 | /// ILNumerics Community Edition - high performance computing for applications.
|
---|
5 | /// Copyright (C) 2006 - 2012 Haymo Kutschbach, http://ilnumerics.net
|
---|
6 | ///
|
---|
7 | /// ILNumerics Community Edition is free software: you can redistribute it and/or modify
|
---|
8 | /// it under the terms of the GNU General Public License version 3 as published by
|
---|
9 | /// the Free Software Foundation.
|
---|
10 | ///
|
---|
11 | /// ILNumerics Community Edition is distributed in the hope that it will be useful,
|
---|
12 | /// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
14 | /// GNU General Public License for more details.
|
---|
15 | ///
|
---|
16 | /// You should have received a copy of the GNU General Public License
|
---|
17 | /// along with ILNumerics Community Edition. See the file License.txt in the root
|
---|
18 | /// of your distribution package. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | ///
|
---|
20 | /// In addition this software uses the following components and/or licenses:
|
---|
21 | ///
|
---|
22 | /// =================================================================================
|
---|
23 | /// The Open Toolkit Library License
|
---|
24 | ///
|
---|
25 | /// Copyright (c) 2006 - 2009 the Open Toolkit library.
|
---|
26 | ///
|
---|
27 | /// Permission is hereby granted, free of charge, to any person obtaining a copy
|
---|
28 | /// of this software and associated documentation files (the "Software"), to deal
|
---|
29 | /// in the Software without restriction, including without limitation the rights to
|
---|
30 | /// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
---|
31 | /// the Software, and to permit persons to whom the Software is furnished to do
|
---|
32 | /// so, subject to the following conditions:
|
---|
33 | ///
|
---|
34 | /// The above copyright notice and this permission notice shall be included in all
|
---|
35 | /// copies or substantial portions of the Software.
|
---|
36 | ///
|
---|
37 | /// =================================================================================
|
---|
38 | ///
|
---|
39 |
|
---|
40 | using System;
|
---|
41 | using System.Collections.Generic;
|
---|
42 | using System.Text;
|
---|
43 | using System.Windows.Forms;
|
---|
44 | using System.Drawing;
|
---|
45 |
|
---|
46 | namespace ILNumerics.Drawing {
|
---|
47 |
|
---|
48 | /// <summary>
|
---|
49 | /// Label with flexible configurable orientation of it's text
|
---|
50 | /// </summary>
|
---|
51 | public class ILMovingDockPanel : Panel {
|
---|
52 | private DockStyle m_dockStyle;
|
---|
53 | private TextOrientation m_standardOrientation = TextOrientation.Horizontal;
|
---|
54 | private BorderStyle m_borderStyle;
|
---|
55 | private bool m_isMoving;
|
---|
56 | private Size m_oldSize;
|
---|
57 | private System.Drawing.Point m_moveStart;
|
---|
58 | private float m_bgGradientDeg = 0.0f;
|
---|
59 | private byte m_bgGradientStrength = 30;
|
---|
60 | protected Color m_backColor = SystemColors.Info;
|
---|
61 | private Button m_buttonClose;
|
---|
62 |
|
---|
63 | /// <summary>
|
---|
64 | /// Intensity of lighting / darkner effect for background color
|
---|
65 | /// </summary>
|
---|
66 | public byte BackgroundGradientStrength {
|
---|
67 | get { return m_bgGradientStrength; }
|
---|
68 | set {
|
---|
69 | m_bgGradientStrength = value;
|
---|
70 | Invalidate();
|
---|
71 | }
|
---|
72 | }
|
---|
73 | /// <summary>
|
---|
74 | /// orientation for background gradient effect
|
---|
75 | /// </summary>
|
---|
76 | public float BackgroundGradientDeg {
|
---|
77 | get { return m_bgGradientDeg; }
|
---|
78 | set {
|
---|
79 | m_bgGradientDeg = value;
|
---|
80 | Invalidate();
|
---|
81 | }
|
---|
82 | }
|
---|
83 |
|
---|
84 |
|
---|
85 | protected TextOrientation m_orientation = TextOrientation.Horizontal;
|
---|
86 | /// <summary>
|
---|
87 | /// set the orientation of text (Horizontal/Vertical)
|
---|
88 | /// </summary>
|
---|
89 | public TextOrientation Orientation {
|
---|
90 | get {
|
---|
91 | return m_orientation;
|
---|
92 | }
|
---|
93 | set {
|
---|
94 | m_orientation = value;
|
---|
95 | }
|
---|
96 | }
|
---|
97 | /// <summary>
|
---|
98 | /// The type of orientation (hor./ vert) if the control is not docked
|
---|
99 | /// </summary>
|
---|
100 | /// <remarks>Setting this value will not alter the way the display is
|
---|
101 | /// currently drawn until the control returns from a docked state the next time.</remarks>
|
---|
102 | public TextOrientation StandardOrientation {
|
---|
103 | get {
|
---|
104 | return m_standardOrientation;
|
---|
105 | }
|
---|
106 | set {
|
---|
107 | m_standardOrientation = value;
|
---|
108 | OnOrientationChanged();
|
---|
109 | }
|
---|
110 | }
|
---|
111 |
|
---|
112 | public new BorderStyle BorderStyle {
|
---|
113 | get {
|
---|
114 | return m_borderStyle;
|
---|
115 | }
|
---|
116 | set {
|
---|
117 | m_borderStyle = value;
|
---|
118 | }
|
---|
119 | }
|
---|
120 |
|
---|
121 | public System.Drawing.Point LocationMoveStart {
|
---|
122 | get {
|
---|
123 | return m_moveStart;
|
---|
124 | }
|
---|
125 | set {
|
---|
126 | m_moveStart = value;
|
---|
127 | }
|
---|
128 | }
|
---|
129 | /// <summary>
|
---|
130 | /// True, if the control is currently moved around by the user
|
---|
131 | /// </summary>
|
---|
132 | public bool IsMoving {
|
---|
133 | get {
|
---|
134 | return m_isMoving;
|
---|
135 | }
|
---|
136 | set {
|
---|
137 | m_isMoving = value;
|
---|
138 | }
|
---|
139 | }
|
---|
140 |
|
---|
141 | protected override void OnPaint(PaintEventArgs e) {
|
---|
142 | base.OnPaint(e);
|
---|
143 | Pen pen = new Pen(new SolidBrush(ForeColor),1.0f);
|
---|
144 | if (BorderStyle == BorderStyle.FixedSingle) {
|
---|
145 | Rectangle rect = ClientRectangle;
|
---|
146 | rect.Width -= 1;
|
---|
147 | rect.Height -= 1;
|
---|
148 | e.Graphics.DrawRectangle( pen,rect);
|
---|
149 | }
|
---|
150 | }
|
---|
151 |
|
---|
152 | public ILMovingDockPanel() {
|
---|
153 | m_dockStyle = DockStyle.None;
|
---|
154 | m_borderStyle = BorderStyle.None;
|
---|
155 | this.Padding = new Padding(2);
|
---|
156 | this.MouseDoubleClick += new MouseEventHandler(ILMovingDockPanel_MouseDoubleClick);
|
---|
157 | this.MouseDown += new MouseEventHandler(ILMovingDockPanel_MouseDown);
|
---|
158 | this.MouseUp += new MouseEventHandler(ILMovingDockPanel_MouseUp);
|
---|
159 | this.MouseMove += new MouseEventHandler(ILMovingDockPanel_MouseMove);
|
---|
160 | Cursor = Cursors.SizeAll;
|
---|
161 | BackColor = SystemColors.Info;
|
---|
162 | // create close button
|
---|
163 | m_buttonClose = new Button();
|
---|
164 | Bitmap bmpClose = Resources.Images.close;
|
---|
165 | m_buttonClose.BackgroundImage = bmpClose;
|
---|
166 | m_buttonClose.Height = bmpClose.Height;
|
---|
167 | m_buttonClose.Width = bmpClose.Width;
|
---|
168 | Controls.Add(m_buttonClose);
|
---|
169 | m_buttonClose.FlatAppearance.BorderSize = 2;
|
---|
170 | m_buttonClose.Cursor = Cursors.Default;
|
---|
171 | m_buttonClose.Visible = false;
|
---|
172 | m_buttonClose.Click += new EventHandler(m_buttonClose_Click);
|
---|
173 | positionButtonClose();
|
---|
174 | }
|
---|
175 |
|
---|
176 | #region handle close button
|
---|
177 | void m_buttonClose_Click(object sender, EventArgs e) {
|
---|
178 | this.Visible = false;
|
---|
179 | }
|
---|
180 |
|
---|
181 | private void positionButtonClose() {
|
---|
182 | if (m_orientation == TextOrientation.Horizontal) {
|
---|
183 |
|
---|
184 | } else {
|
---|
185 |
|
---|
186 | }
|
---|
187 | m_buttonClose.Left = 2;
|
---|
188 | m_buttonClose.Top = 2;
|
---|
189 | }
|
---|
190 |
|
---|
191 | protected override void OnMouseEnter(EventArgs e) {
|
---|
192 | base.OnMouseEnter(e);
|
---|
193 | m_buttonClose.Visible = true;
|
---|
194 | }
|
---|
195 |
|
---|
196 | protected override void OnMouseLeave(EventArgs e) {
|
---|
197 | base.OnMouseLeave(e);
|
---|
198 | Point p = this.PointToClient(MousePosition);
|
---|
199 | if (p.X < 0 || p.Y < 0 || p.Y > ClientSize.Height || p.X > ClientSize.Width)
|
---|
200 | m_buttonClose.Visible = false;
|
---|
201 | }
|
---|
202 |
|
---|
203 |
|
---|
204 | #endregion
|
---|
205 |
|
---|
206 | void ILMovingDockPanel_MouseMove(object sender, MouseEventArgs e) {
|
---|
207 | if (e.Button != MouseButtons.Left)
|
---|
208 | return;
|
---|
209 | if (!m_isMoving && (Math.Abs(e.X - m_moveStart.X) > 2 || Math.Abs(e.Y - m_moveStart.Y) > 2)) {
|
---|
210 | m_isMoving = true;
|
---|
211 | this.BorderStyle = BorderStyle.FixedSingle;
|
---|
212 | }
|
---|
213 | }
|
---|
214 | protected override void OnPaintBackground(PaintEventArgs e) {
|
---|
215 | //System.Diagnostic.Debug.WriteLine("ILBordFtLbl: paintbg");
|
---|
216 | base.OnPaintBackground(e);
|
---|
217 | Color c1 = BackColor;
|
---|
218 | int c1r = Math.Max(Math.Max(c1.R,c1.G),c1.B);
|
---|
219 | c1r = Math.Min(255-c1r,m_bgGradientStrength);
|
---|
220 | c1 = Color.FromArgb(100,c1.R+c1r,c1.G+c1r,c1.B+c1r);
|
---|
221 | Color c2 = BackColor;
|
---|
222 | c1r = Math.Min(Math.Min(c2.R,c2.G),c2.B);
|
---|
223 | if (c1r > m_bgGradientStrength) c1r = m_bgGradientStrength;
|
---|
224 | c2 = Color.FromArgb(200,c2.R-c1r,c2.G-c1r,c2.B-c1r);
|
---|
225 | Point p = new Point(ClientRectangle.Size.Width / 2, ClientRectangle.Height / 2);
|
---|
226 | System.Drawing.Drawing2D.LinearGradientBrush br =
|
---|
227 | new System.Drawing.Drawing2D.LinearGradientBrush(ClientRectangle,c1,c2,m_bgGradientDeg);
|
---|
228 | e.Graphics.FillRegion(br,new Region(ClientRectangle));
|
---|
229 | }
|
---|
230 |
|
---|
231 | void ILMovingDockPanel_MouseUp(object sender, MouseEventArgs e) {
|
---|
232 | m_isMoving = false;
|
---|
233 | }
|
---|
234 |
|
---|
235 | void ILMovingDockPanel_MouseDown(object sender, MouseEventArgs e) {
|
---|
236 | if (e.Button == MouseButtons.Left) {
|
---|
237 | m_moveStart = e.Location;
|
---|
238 | }
|
---|
239 | }
|
---|
240 |
|
---|
241 | void ILMovingDockPanel_MouseDoubleClick(object sender, MouseEventArgs e) {
|
---|
242 | if (e.Button == MouseButtons.Left) {
|
---|
243 | System.Array ds = Enum.GetValues(typeof(DockStyle));
|
---|
244 | int cds = (int)Dock;
|
---|
245 | DockStyle dos = (DockStyle)((cds + 1) % ds.Length);
|
---|
246 | while (dos == DockStyle.Fill) {
|
---|
247 | cds++;
|
---|
248 | dos = (DockStyle)((cds + 1) % ds.Length);
|
---|
249 | }
|
---|
250 | SuspendLayout();
|
---|
251 | Dock = dos;
|
---|
252 | ResumeLayout();
|
---|
253 | }
|
---|
254 | }
|
---|
255 |
|
---|
256 | public override DockStyle Dock {
|
---|
257 | get {
|
---|
258 | return m_dockStyle;
|
---|
259 | }
|
---|
260 | set {
|
---|
261 | if (m_dockStyle == value) return;
|
---|
262 | if (m_dockStyle == DockStyle.None) {
|
---|
263 | m_oldSize = this.Size;
|
---|
264 | }
|
---|
265 | this.BorderStyle = BorderStyle.None;
|
---|
266 | switch (value) {
|
---|
267 | case DockStyle.Left:
|
---|
268 | m_orientation = TextOrientation.Vertical;
|
---|
269 | break;
|
---|
270 | case DockStyle.Right:
|
---|
271 | m_orientation = TextOrientation.Vertical;
|
---|
272 | break;
|
---|
273 | case DockStyle.Top:
|
---|
274 | m_orientation = TextOrientation.Horizontal;
|
---|
275 | break;
|
---|
276 | case DockStyle.Bottom:
|
---|
277 | m_orientation = TextOrientation.Horizontal;
|
---|
278 | break;
|
---|
279 | case DockStyle.Fill:
|
---|
280 | m_orientation = m_standardOrientation;
|
---|
281 | break;
|
---|
282 | case DockStyle.None:
|
---|
283 | this.BorderStyle = BorderStyle.FixedSingle;
|
---|
284 | m_orientation = m_standardOrientation;
|
---|
285 | break;
|
---|
286 | default:
|
---|
287 | m_orientation = m_standardOrientation;
|
---|
288 | break;
|
---|
289 | }
|
---|
290 | m_dockStyle = value;
|
---|
291 | if (m_dockStyle == DockStyle.None && m_oldSize.Width > 0 && m_oldSize.Height > 0) {
|
---|
292 | this.Size = m_oldSize;
|
---|
293 | }
|
---|
294 | if (Parent != null && Parent is ILSubfigure)
|
---|
295 | ((ILSubfigure)Parent).PerformLayout();
|
---|
296 | }
|
---|
297 | }
|
---|
298 |
|
---|
299 | protected virtual void OnOrientationChanged () {
|
---|
300 |
|
---|
301 | }
|
---|
302 | }
|
---|
303 | }
|
---|