1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2004-2005 Novell, Inc.
23 // Jackson Harper (jackson@ximian.com)
28 using System.ComponentModel;
29 using System.ComponentModel.Design;
33 namespace System.Windows.Forms {
34 [DefaultEvent("SplitterMoved")]
35 [Designer("System.Windows.Forms.Design.SplitterDesigner, " + Consts.AssemblySystem_Design)]
36 [DefaultProperty("Dock")]
37 public class Splitter : Control, IMessageFilter {
39 private int min_extra;
41 private int move_start_x;
42 private int move_start_y;
44 private int thickness;
48 private SplitterEventHandler on_splitter_moved;
49 private SplitterEventHandler on_splitter_moving;
51 private Control adjacent;
54 #region Public Constructors
57 SetStyle (ControlStyles.UserPaint, true);
58 SetStyle (ControlStyles.StandardClick, true);
59 SetStyle (ControlStyles.StandardDoubleClick, true);
60 SetStyle (ControlStyles.AllPaintingInWmPaint, true);
61 SetStyle (ControlStyles.Selectable, false);
63 Dock = DockStyle.Left;
69 #endregion // Public Constructors
71 #region Public Instance Properties
72 [DefaultValue(DockStyle.Left)]
74 public override DockStyle Dock {
75 get { return base.Dock; }
77 if (value == base.Dock)
81 case DockStyle.Bottom:
90 throw new ArgumentException ("A splitter control must be docked left, right, top, or bottom.");
99 get { return min_extra; }
121 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
122 public int SplitPosition {
124 Control adjacent = FindAdjacentControl ();
125 if (adjacent == null)
129 return adjacent.Width;
130 return adjacent.Height;
133 adjacent = FindAdjacentControl ();
134 if (adjacent == null)
138 if (adjacent.Height == value)
140 OnSplitterMoved (new SplitterEventArgs (Left, Top, Left, value));
143 if (adjacent.Width == value)
145 OnSplitterMoved (new SplitterEventArgs (adjacent.Width / 2, adjacent.Height / 2, value, Top));
150 #endregion // Public Instance Properties
152 #region Protected Instance Properties
153 protected override CreateParams CreateParams {
\r
155 return base.CreateParams;
\r
159 protected override ImeMode DefaultImeMode {
\r
161 return base.DefaultImeMode;
\r
165 protected override Size DefaultSize {
167 return new Size (3, 3);
171 #endregion // Protected Instance Properties
173 #region Public Instance Methods
175 public bool PreFilterMessage(ref Message m) {
178 #endregion // Public Instance Methods
180 #region Protected Instance Methods
181 protected override void OnMouseDown (MouseEventArgs e)
183 base.OnMouseDown (e);
185 if (!moving && e.Button == MouseButtons.Left) {
186 adjacent = FindAdjacentControl ();
196 protected override void OnMouseMove (MouseEventArgs e)
199 base.OnMouseMove (e);
201 int x_move = e.X - move_start_x;
202 int y_move = e.Y - move_start_y;
210 Left = Left + x_move;
213 OnSplitterMoving (new SplitterEventArgs (e.X, e.Y, Left, Top));
217 protected override void OnMouseUp (MouseEventArgs e)
219 base.OnMouseDown (e);
225 protected virtual void OnSplitterMoved (SplitterEventArgs e) {
226 if (on_splitter_moved != null)
227 on_splitter_moved (this, e);
228 Move (e.SplitX, e.SplitY);
231 protected virtual void OnSplitterMoving (SplitterEventArgs e) {
232 if (on_splitter_moving != null)
233 on_splitter_moving (this, e);
234 Move (e.SplitX, e.SplitY);
237 protected override void SetBoundsCore (int x, int y, int width, int height, BoundsSpecified specified)
251 base.SetBoundsCore (x, y, width, height, specified);
254 #endregion // Protected Instance Methods
256 #region Internal & Private Methods
257 private void Draw () {
258 using (Graphics pdc = Parent.CreateGraphics ()) {
259 pdc.FillRectangle (new SolidBrush (Color.Red), ClientRectangle);
263 private void Move (int x, int y) {
264 if (adjacent == null)
268 if (adjacent.Height == y)
274 if (adjacent.Width == x)
282 private Control FindAdjacentControl () {
286 foreach (Control sibling in Parent.Controls) {
288 if (!sibling.Visible)
294 if (sibling.Right == Left)
298 case DockStyle.Right:
299 if (sibling.Left == Right)
304 if (sibling.Bottom == Top)
308 case DockStyle.Bottom:
309 if (sibling.Top == Bottom)
317 #endregion // Internal & Private Methods
322 [EditorBrowsable(EditorBrowsableState.Never)]
323 public new event EventHandler BackgroundImageChanged {
324 add { base.BackgroundImageChanged += value; }
325 remove { base.BackgroundImageChanged -= value; }
329 [EditorBrowsable(EditorBrowsableState.Never)]
330 public new event EventHandler Enter {
331 add { base.Enter += value; }
332 remove { base.Enter -= value; }
336 [EditorBrowsable(EditorBrowsableState.Never)]
337 public new event EventHandler FontChanged {
338 add { base.FontChanged += value; }
339 remove { base.FontChanged -= value; }
343 [EditorBrowsable(EditorBrowsableState.Never)]
344 public new event EventHandler ForeColorChanged {
345 add { base.ForeColorChanged += value; }
346 remove { base.ForeColorChanged -= value; }
350 [EditorBrowsable(EditorBrowsableState.Never)]
351 public new event EventHandler ImeModeChanged {
352 add { base.ImeModeChanged += value; }
353 remove { base.ImeModeChanged -= value; }
357 [EditorBrowsable(EditorBrowsableState.Never)]
358 public new event KeyEventHandler KeyDown {
359 add { base.KeyDown += value; }
360 remove { base.KeyDown -= value; }
364 [EditorBrowsable(EditorBrowsableState.Never)]
365 public new event KeyPressEventHandler KeyPress {
366 add { base.KeyPress += value; }
367 remove { base.KeyPress -= value; }
371 [EditorBrowsable(EditorBrowsableState.Never)]
372 public new event KeyEventHandler KeyUp {
373 add { base.KeyUp += value; }
374 remove { base.KeyUp -= value; }
378 [EditorBrowsable(EditorBrowsableState.Never)]
379 public new event EventHandler Leave {
380 add { base.Leave += value; }
381 remove { base.Leave -= value; }
385 [EditorBrowsable(EditorBrowsableState.Never)]
386 public new event EventHandler TabStopChanged {
387 add { base.TabStopChanged += value; }
388 remove { base.TabStopChanged -= value; }
392 [EditorBrowsable(EditorBrowsableState.Never)]
393 public new event EventHandler TextChanged {
394 add { base.TextChanged += value; }
395 remove { base.TextChanged -= value; }
398 public event SplitterEventHandler SplitterMoved {
399 add { on_splitter_moved += value; }
400 remove { on_splitter_moved -= value; }
403 public event SplitterEventHandler SplitterMoving {
404 add { on_splitter_moving += value; }
405 remove { on_splitter_moving -= value; }