A
download Splitter.cs
Language: C#
License: GPL
Copyright: (C) 2003 Southern Storm Software, Pty Ltd.
LOC: 641
Project Info
DotGNU Portable.NET(dotgnu-pnet)
Server: Savannah GNU
Type: cvs
...etlib\System.Windows.Forms\
   .cvsignore
   AccessibleEvents.cs
   AccessibleNavigation.cs
   AccessibleObject.cs
   AccessibleRole.cs
   AccessibleSelection.cs
   AccessibleStates.cs
   ActivationGesture.cs
   ActivationState.cs
   AmbientProperties.cs
   AnchorStyles.cs
   Appearance.cs
   Application.cs
   ApplicationContext.cs
   ArrangeDirection.cs
   ArrangeStartingPosition.cs
   BaseCollection.cs
   Binding.cs
   BindingContext.cs
   BindingManagerBase.cs
   BindingMemberInfo.cs
   BindingsCollection.cs
   BootMode.cs
   Border3DSide.cs
   Border3DStyle.cs
   BorderStyle.cs
   BoundsSpecified.cs
   Button.cs
   ButtonBase.cs
   ButtonBorderStyle.cs
   ButtonBoxLayout.cs
   ButtonState.cs
   CancelEventArgs.cs
   CancelEventHandler.cs
   CaptionButton.cs
   CharacterCasing.cs
   CheckBox.cs
   CheckListBox.cs
   CheckState.cs
   Clipboard.cs
   ColorDepth.cs
   ColorDialog.cs
   ColumnClickEventArgs.cs
   ColumnClickEventHandler.cs
   ColumnHeader.cs
   ColumnHeaderStyle.cs
   ComboBox.cs
   ComboBoxStyle.cs
   CommonDialog.cs
   ContainerControl.cs
   ...entsResizedEventArgs.cs
   ...sResizedEventHandler.cs
   ContextMenu.cs
   Control.cs
   ...olBindingsCollection.cs
   ControlEventArgs.cs
   ControlEventHandler.cs
   ControlPaint.cs
   ControlStyles.cs
   ControlToolkitMgr.cs
   ConvertEventArgs.cs
   ConvertEventHandler.cs
   CreateParams.cs
   CurrencyManager.cs
   Cursor.cs
   CursorConverter.cs
   Cursors.cs
   DataFormats.cs
   DataGrid.cs
   DataGridBoolColumn.cs
   DataGridCell.cs
   DataGridColumnStyle.cs
   DataGridLineStyle.cs
   ...ParentRowsLabelStyle.cs
   ...mnWidthTypeConverter.cs
   DataGridTableStyle.cs
   DataGridTextBox.cs
   DataGridTextBoxColumn.cs
   DataObject.cs
   DateBoldEventArgs.cs
   DateBoldEventHandler.cs
   DateRangeEventArgs.cs
   DateRangeEventHandler.cs
   DateTimePickerFormat.cs
   Day.cs
   DialogResult.cs
   DockStyle.cs
   DomainUpDown.cs
   DragAction.cs
   DragDropEffects.cs
   DragEventArgs.cs
   DragEventHandler.cs
   DrawItemEventArgs.cs
   DrawItemEventHandler.cs
   DrawItemState.cs
   DrawMode.cs
   ErrorBlinkStyle.cs
   ErrorIconAlignment.cs
   ErrorProvider.cs
   EventId.cs
   FeatureSupport.cs
   FileDialog.cs
   FlatStyle.cs
   FolderBrowserDialog.cs
   FontDialog.cs
   Form.cs
   FormBorderStyle.cs
   Forms.build
   FormStartPosition.cs
   FormWindowState.cs
   FrameStyle.cs
   GiveFeedbackEventArgs.cs
   ...FeedbackEventHandler.cs
   ...lumnStylesCollection.cs
   GridItem.cs
   GridItemCollection.cs
   GridItemType.cs
   GridLayout.cs
   ...ableStylesCollection.cs
   GroupBox.cs
   HBoxLayout.cs
   Help.cs
   HelpEventArgs.cs
   HelpEventHandler.cs
   HelpNavigator.cs
   HelpProvider.cs
   HorizontalAlignment.cs
   HScrollBar.cs
   IBindableComponent.cs
   IButtonControl.cs
   ICommandExecutor.cs
   ...ponentEditorPageSite.cs
   IContainerControl.cs
   ...gNotificationService.cs
   IDataGridEditingService.cs
   IDataObject.cs
   IDropTarget.cs
   IFeatureSupport.cs
   IFileReaderService.cs
   ImageIndexConverter.cs
   ImageList.cs
   ImageListStreamer.cs
   ImeMode.cs
   IMessageFilter.cs
   InputLanguage.cs
   ...uageChangedEventArgs.cs
   ...eChangedEventHandler.cs
   ...ageChangingEventArgs.cs
   ...ChangingEventHandler.cs
   InvalidateEventArgs.cs
   InvalidateEventHandler.cs
   IRecommendedSize.cs
   ItemActivation.cs
   ItemBoundsPortion.cs
   ItemChangedEventArgs.cs
   ItemChangedEventHandler.cs
   ItemCheckEventArgs.cs
   ItemCheckEventHandler.cs
   ItemDragEventArgs.cs
   ItemDragEventHandler.cs
   IWin32Window.cs
   IWindowTarget.cs
   KeyEventArgs.cs
   KeyEventHandler.cs
   KeyPressEventArgs.cs
   KeyPressEventHandler.cs
   Keys.cs
   Label.cs
   LabelEditEventArgs.cs
   LabelEditEventHandler.cs
   LayoutEventArgs.cs
   LayoutEventHandler.cs
   LeftRightAlignment.cs
   LinkArea.cs
   LinkBehavior.cs
   LinkClickedEventArgs.cs
   LinkClickedEventHandler.cs
   LinkLabel.cs
   ...LinkClickedEventArgs.cs
   ...kClickedEventHandler.cs
   LinkState.cs
   ListBindingConverter.cs
   ListBox.cs
   ListControl.cs
   ListView.cs
   ListViewAlignment.cs
   ListViewItem.cs
   ListViewItemConverter.cs
   ...ViewSubItemConverter.cs
   MainMenu.cs
   Makefile.am
   MdiClient.cs
   MdiLayout.cs
   MeasureItemEventArgs.cs
   MeasureItemEventHandler.cs
   Menu.cs
   MenuGlyph.cs
   MenuItem.cs
   MenuMerge.cs
   Message.cs
   MessageBox.cs
   MessageBoxButtons.cs
   MessageBoxDefaultButton.cs
   MessageBoxIcon.cs
   MessageBoxOptions.cs
   MethodInvoker.cs
   MonthCalendar.cs
   MouseButtons.cs
   MouseEventArgs.cs
   MouseEventHandler.cs
   NativeWindow.cs
   NavigateEventArgs.cs
   NavigateEventHandler.cs
   NodeLabelEditEventArgs.cs
   ...abelEditEventHandler.cs
   NotifyIcon.cs
   NumericUpDown.cs
   OpenFileDialog.cs
   Orientation.cs
   OSFeature.cs
   OwnerDrawPropertyBag.cs
   PaintEventArgs.cs
   PaintEventHandler.cs
   Panel.cs
   PictureBox.cs
   PictureBoxSizeMode.cs
   PopupControl.cs
   PrintDialog.cs
   ProgressBar.cs
   PropertySort.cs
   ...yTabChangedEventArgs.cs
   ...bChangedEventHandler.cs
   ...alueChangedEventArgs.cs
   ...eChangedEventHandler.cs
   ...ccessibilityHelpArgs.cs
   ...lityHelpEventHandler.cs
   ...ontinueDragEventArgs.cs
   ...inueDragEventHandler.cs
   RadioButton.cs
   RichTextBox.cs
   RichTextBoxFinds.cs
   RichTextBoxScrollBars.cs
   ...oxSelectionAttribute.cs
   ...extBoxSelectionTypes.cs
   RichTextBoxStreamType.cs
   ...tBoxWordPunctuations.cs
   RightToLeft.cs
   S.cs
   SaveFileDialog.cs
   Screen.cs
   ScrollableControl.cs
   ScrollBar.cs
   ScrollBars.cs
   ScrollButton.cs
   ScrollEventArgs.cs
   ScrollEventHandler.cs
   ScrollEventType.cs
   SecurityIDType.cs
   ...ItemChangedEventArgs.cs
   ...mChangedEventHandler.cs
   SelectionMode.cs
   Shortcut.cs
   SizeGripStyle.cs
   SortOrder.cs
   Splitter.cs
   SplitterEventArgs.cs
   SplitterEventHandler.cs
   StatusBar.cs
   ...BarDrawItemEventArgs.cs
   ...DrawItemEventHandler.cs
   StatusBarPanel.cs
   StatusBarPanelAutoSize.cs
   ...sBarPanelBorderStyle.cs
   ...rPanelClickEventArgs.cs
   ...nelClickEventHandler.cs
   StatusBarPanelStyle.cs
   StructFormat.cs
   SystemInformation.cs
   TabAlignment.cs
   TabAppearance.cs
   TabControl.cs
   TabDrawMode.cs
   TabPage.cs
   TabSizeMode.cs
   TextBox.cs
   TextBoxBase.cs
   TickStyle.cs
   Timer.cs
   TODOAttribute.cs
   ToolBar.cs
   ToolBarAppearance.cs
   ToolBarButton.cs
   ...ButtonClickEventArgs.cs
   ...tonClickEventHandler.cs
   ToolBarButtonStyle.cs
   ToolBarTextAlign.cs
   ToolTip.cs
   TrackBar.cs
   TreeNode.cs
   TreeNodeCollection.cs
   TreeView.cs
   TreeViewAction.cs
   TreeViewCancelEventArgs.cs
   ...ewCancelEventHandler.cs
   TreeViewEventArgs.cs
   TreeViewEventHandler.cs
   TriangleDirection.cs
   UICues.cs
   UICuesEventArgs.cs
   UICuesEventHandler.cs
   UpDownBase.cs
   UpDownEventArgs.cs
   UpDownEventHandler.cs
   UserControl.cs
   VBoxLayout.cs
   View.cs
   VScrollBar.cs
   Win32Constants.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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
/*
 * Splitter.cs - Implementation of the
 *			"System.Windows.Forms.Splitter" class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Windows.Forms
{

using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Toolkit;
using System.ComponentModel;

#if CONFIG_COMPONENT_MODEL
[DefaultEvent("SplitterMoved")]
[DefaultProperty("Dock")]
[Designer("System.Windows.Forms.Design.SplitterDesigner, System.Design")]
#endif
public class Splitter : Control, IMessageFilter
{
	// Internal state.
	private int minSize;
	private int minExtra;
	private int thickness;
	private bool moving;
	private bool drawn;
	private Brush xorBrush;
	private Rectangle drawnRect;
	private int moveX, moveY;
	private int startMoveX, startMoveY;
	private int startX, startY;
	private int margin1, margin2;

	// Constructor.
	public Splitter()
			{
				minSize = 25;
				minExtra = 25;
				thickness = 3;
				moving = false;
				drawn = false;
				xorBrush = new HatchBrush(HatchStyle.Percent50,
										  Color.White, Color.Black);
				xorBrush = ToolkitManager.CreateXorBrush(xorBrush);
				Dock = DockStyle.Left;
				TabStop = false;
				SetStyle(ControlStyles.Selectable, false);
			}

	// Get or set this control's properties.
	public override bool AllowDrop
			{
				get
				{
					return base.AllowDrop;
				}
				set
				{
					base.AllowDrop = value;
				}
			}
	public override AnchorStyles Anchor
			{
				get
				{
					return AnchorStyles.None;
				}
				set
				{
					// Nothing to do here: anchoring is not supported.
				}
			}
	public override Image BackgroundImage
			{
				get
				{
					return base.BackgroundImage;
				}
				set
				{
					base.BackgroundImage = value;
				}
			}
	public BorderStyle BorderStyle
			{
				get
				{
					return BorderStyleInternal;
				}
				set
				{
					BorderStyleInternal = value;
				}
			}
	protected override CreateParams CreateParams
			{
				get
				{
					return base.CreateParams;
				}
			}
	protected override ImeMode DefaultImeMode
			{
				get
				{
					return ImeMode.Disable;
				}
			}
	protected override Size DefaultSize
			{
				get
				{
					return new Size(3, 3);
				}
			}
	public override Cursor Cursor
		{
			set
			{
				if( value == null ) {
					switch( Dock ) {
						case DockStyle.Left : case DockStyle.Right :
							base.Cursor = Cursors.SizeWE;
							break;
						case DockStyle.Top : case DockStyle.Bottom :
							base.Cursor = Cursors.SizeNS;
							break;
						default:
							base.Cursor = value;
							break;
					}
				}
				else {
					base.Cursor = value;
				}
			}
		}
			
	public override DockStyle Dock
			{
				get
				{
					return base.Dock;
				}
				set
				{
					if(value == DockStyle.Left || value == DockStyle.Right)
					{
						base.Dock = value;
						Width = thickness;
						Cursor = Cursors.SizeWE;
					}
					else if(value == DockStyle.Top || value == DockStyle.Bottom)
					{
						base.Dock = value;
						Height = thickness;
						Cursor = Cursors.SizeNS;
					}
					else
					{
						throw new ArgumentException(S._("SWF_DockStyle"));
					}
				}
			}
	public override Font Font
			{
				get
				{
					return base.Font;
				}
				set
				{
					base.Font = value;
				}
			}
	public override Color ForeColor
			{
				get
				{
					return base.ForeColor;
				}
				set
				{
					base.ForeColor = value;
				}
			}
	public new ImeMode ImeMode
			{
				get
				{
					return base.ImeMode;
				}
				set
				{
					base.ImeMode = value;
				}
			}
	public int MinExtra
			{
				get
				{
					return minExtra;
				}
				set
				{
					if(minExtra != value)
					{
						if(value < 0)
						{
							value = 0;
						}
						minExtra = value;
					}
				}
			}
	public int MinSize
			{
				get
				{
					return minSize;
				}
				set
				{
					if(minSize != value)
					{
						if(value < 0)
						{
							value = 0;
						}
						minSize = value;
					}
				}
			}
	public int SplitPosition
			{
				get
				{
					Control adjusted = GetAdjustedControl();
					if(adjusted != null)
					{
						int size;
						switch(Dock)
						{
							case DockStyle.Left:
							case DockStyle.Right:
							default:
							{
								size = adjusted.Width;
							}
							break;

							case DockStyle.Top:
							case DockStyle.Bottom:
							{
								size = adjusted.Height;
							}
							break;
						}
						if(size < minSize)
						{
							size = minSize;
						}
						return size;
					}
					else
					{
						return -1;
					}
				}
				set
				{
					// Bail out if we are in the middle of a move operation.
					if(moving)
					{
						return;
					}

					// Get the control to be adjusted.
					Control adjusted = GetAdjustedControl();
					if(adjusted == null)
					{
						return;
					}

					// Range-check the size.
					if(value < minSize)
					{
						value = minSize;
					}

					// Adjust the bounds.
					switch(Dock)
					{
						case DockStyle.Left:
						case DockStyle.Right:
						{
							if(adjusted.Width == value)
							{
								return;
							}
							adjusted.Width = value;
						}
						break;

						case DockStyle.Top:
						case DockStyle.Bottom:
						{
							if(adjusted.Height == value)
							{
								return;
							}
							adjusted.Height = value;
						}
						break;
					}

					// Notify event handlers of the move.
					OnSplitterMoved
						(new SplitterEventArgs(Left, Top, Left, Top));
				}
			}
	public new bool TabStop
			{
				get
				{
					return base.TabStop;
				}
				set
				{
					base.TabStop = value;
				}
			}
	public override String Text
			{
				get
				{
					return base.Text;
				}
				set
				{
					base.Text = value;
				}
			}

	// Convert this object into a string.
	public override String ToString()
			{
				return base.ToString() + ", MinExtra=" + MinExtra.ToString() +
					   ", MinSize=" + MinSize.ToString();
			}

	// Filter a message before it is dispatched.
	public bool PreFilterMessage(ref Message m)
			{
				// Not used in this implementation.
				return false;
			}

	// Event that is emitted when the splitter is moved.
	public event SplitterEventHandler SplitterMoved
			{
				add
				{
					AddHandler(EventId.SplitterMoved, value);
				}
				remove
				{
					RemoveHandler(EventId.SplitterMoved, value);
				}
			}

	// Event that is emitted when the splitter is moving.
	public event SplitterEventHandler SplitterMoving
			{
				add
				{
					AddHandler(EventId.SplitterMoving, value);
				}
				remove
				{
					RemoveHandler(EventId.SplitterMoving, value);
				}
			}

	// Draw the splitter at its current move position.
	private void DrawSplitter()
			{
				if(!drawn)
				{
					switch(Dock)
					{
						case DockStyle.Left:
						case DockStyle.Right:
						{
							drawnRect = new Rectangle
								(moveX, Top, thickness, Height);
						}
						break;

						case DockStyle.Top:
						case DockStyle.Bottom:
						{
							drawnRect = new Rectangle
								(Left, moveY, Width, thickness);
						}
						break;
					}
					using(Graphics graphics = Parent.CreateGraphics())
					{
						graphics.FillRectangle(xorBrush, drawnRect);
					}
					drawn = true;
				}
			}

	// Erase the splitter from its current move position.
	private void EraseSplitter()
			{
				if(drawn)
				{
					drawn = false;
					using(Graphics graphics = Parent.CreateGraphics())
					{
						graphics.FillRectangle(xorBrush, drawnRect);
					}
				}
			}

	// End a splitter move operation.
	private void EndMove()
			{
				// Erase the splitter and end the move operation.
				EraseSplitter();
				moving = false;
				Capture = false;

				// Actually move the position.
				switch(Dock)
				{
					case DockStyle.Left:
					{
						SplitPosition = moveX - margin1 + minSize;
					}
					break;

					case DockStyle.Right:
					{
						SplitPosition =
							Parent.ClientSize.Width -
								(moveX + thickness) -
								margin2 + minSize;
					}
					break;

					case DockStyle.Top:
					{
						SplitPosition = moveY - margin1 + minSize;
					}
					break;

					case DockStyle.Bottom:
					{
						SplitPosition =
							Parent.ClientSize.Height -
								(moveY + thickness) -
								margin2 + minSize;
					}
					break;
				}
			}

	// Handle a "KeyDown" event.
	protected override void OnKeyDown(KeyEventArgs e)
			{
				base.OnKeyDown(e);
				if(moving && e.KeyCode == Keys.Escape)
				{
					EndMove();
				}
			}

	// Handle a "MouseDown" event.
	protected override void OnMouseDown(MouseEventArgs e)
			{
				base.OnMouseDown(e);
				if(!moving && e.Button == MouseButtons.Left)
				{
					// Bail out if there is no control to adjust.
					Control adjusted = GetAdjustedControl();
					if(adjusted == null)
					{
						return;
					}

					// Record the starting position so that we know
					// how much to offset by when determining movements.
					startX = e.X;
					startY = e.Y;

					// Set the initial move position.
					moveX = Left;
					moveY = Top;
					startMoveX = moveX;
					startMoveY = moveY;

					// Determine the margins of the splitter move.
					switch(Dock)
					{
						case DockStyle.Left:
						{
							margin1 = adjusted.Left + minSize;
							margin2 = minExtra;
						}
						break;

						case DockStyle.Right:
						{
							margin1 = minExtra;
							margin2 = (Parent.ClientSize.Width -
									   adjusted.Right + minSize);
						}
						break;

						case DockStyle.Top:
						{
							margin1 = adjusted.Top + minSize;
							margin2 = minExtra;
						}
						break;

						case DockStyle.Bottom:
						{
							margin1 = minExtra;
							margin2 = (Parent.ClientSize.Height -
									   adjusted.Bottom + minSize);
						}
						break;
					}

					// Capture the mouse and draw the splitter.
					Capture = true;
					moving = true;
					DrawSplitter();
				}
			}

	// Handle a "MouseMove" event.
	protected override void OnMouseMove(MouseEventArgs e)
			{
				base.OnMouseMove(e);
				if(moving)
				{
					int diffX = e.X - startX;
					int diffY = e.Y - startY;
					int newX = moveX;
					int newY = moveY;
					Size parentSize = Parent.ClientSize;
					switch(Dock)
					{
						case DockStyle.Left:
						case DockStyle.Right:
						{
							newX = startMoveX + diffX;
							if(newX < margin1)
							{
								newX = margin1;
							}
							else if((newX + thickness) >
										(parentSize.Width - margin2))
							{
								newX = parentSize.Width - margin2 - thickness;
							}
						}
						break;

						case DockStyle.Top:
						case DockStyle.Bottom:
						{
							newY = startMoveY + diffY;
							if(newY < margin1)
							{
								newY = margin1;
							}
							else if((newY + thickness) >
										(parentSize.Height - margin2))
							{
								newY = parentSize.Height - margin2 - thickness;
							}
						}
						break;
					}
					if(newX != moveX || newY != moveY)
					{
						// Redraw the splitter in its new position.
						EraseSplitter();
						moveX = newX;
						moveY = newY;
						DrawSplitter();

						// Emit the "SplitterMoving" event.
						OnSplitterMoving
							(new SplitterEventArgs
								(Left + e.X, Top + e.Y, moveX, moveY));
					}
				}
			}

	// Handle a "MouseUp" event.
	protected override void OnMouseUp(MouseEventArgs e)
			{
				base.OnMouseUp(e);
				if(moving && e.Button == MouseButtons.Left)
				{
					EndMove();
				}
			}

	// Emit the "SplitterMoved" event.
	protected virtual void OnSplitterMoved(SplitterEventArgs e)
			{
				SplitterEventHandler handler;
				handler = (SplitterEventHandler)
					(GetHandler(EventId.SplitterMoved));
				if(handler != null)
				{
					handler(this, e);
				}
			}

	// Emit the "SplitterMoving" event.
	protected virtual void OnSplitterMoving(SplitterEventArgs e)
			{
				SplitterEventHandler handler;
				handler = (SplitterEventHandler)
					(GetHandler(EventId.SplitterMoving));
				if(handler != null)
				{
					handler(this, e);
				}
			}

	// Inner core of "SetBounds".
	protected override void SetBoundsCore
				(int x, int y, int width, int height,
				 BoundsSpecified specified)
			{
				// Set the thickness based on the width or height.
				DockStyle dock = Dock;
				if(dock == DockStyle.Left || dock == DockStyle.Right)
				{
					if(width <= 0)
					{
						width = 3;
					}
					thickness = width;
				}
				else
				{
					if(height <= 0)
					{
						height = 3;
					}
					thickness = height;
				}

				// Set the bounds.
				base.SetBoundsCore(x, y, width, height, specified);
			}

	// Get the control that is being adjusted by this splitter.
	// Returns null if we cannot find an appropriate control.
	private Control GetAdjustedControl()
			{
				// No adjusted control if we don't have a parent.
				Control parent = Parent;
				if(parent == null)
				{
					return null;
				}

				// Look for a control that has a side adjoining this one.
				DockStyle dock = Dock;
				foreach(Control control in parent.Controls)
				{
					if(!control.Visible)
					{
						continue;
					}
					switch(dock)
					{
						case DockStyle.Left:
						{
							if(control.Right == Left)
							{
								return control;
							}
						}
						break;

						case DockStyle.Right:
						{
							if(control.Left == Right)
							{
								return control;
							}
						}
						break;

						case DockStyle.Top:
						{
							if(control.Bottom == Top)
							{
								return control;
							}
						}
						break;

						case DockStyle.Bottom:
						{
							if(control.Top == Bottom)
							{
								return control;
							}
						}
						break;
					}
				}

				// We could not find an appropriate control.
				return null;
			}

}; // class Splitter

}; // namespace System.Windows.Forms

About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us