Changeset 4068 for trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.WinFormsUI/2.3.1/WinFormsUI-2.3.1/Docking/DockPanel.DragHandler.cs
- Timestamp:
- 07/22/10 00:44:01 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.WinFormsUI/2.3.1/WinFormsUI-2.3.1/Docking/DockPanel.DragHandler.cs
r2645 r4068 1 using System; 2 using System.Collections.Generic; 3 using System.Text; 1 using System.Drawing; 4 2 using System.Windows.Forms; 5 using System.Drawing;6 using System.Drawing.Drawing2D;7 using System.ComponentModel;8 3 9 namespace WeifenLuo.WinFormsUI.Docking 10 { 11 partial class DockPanel 12 { 13 /// <summary> 14 /// DragHandlerBase is the base class for drag handlers. The derived class should: 15 /// 1. Define its public method BeginDrag. From within this public BeginDrag method, 16 /// DragHandlerBase.BeginDrag should be called to initialize the mouse capture 17 /// and message filtering. 18 /// 2. Override the OnDragging and OnEndDrag methods. 19 /// </summary> 20 private abstract class DragHandlerBase : NativeWindow, IMessageFilter 21 { 22 protected DragHandlerBase() 23 { 24 } 4 namespace WeifenLuo.WinFormsUI.Docking { 5 partial class DockPanel { 6 /// <summary> 7 /// DragHandlerBase is the base class for drag handlers. The derived class should: 8 /// 1. Define its public method BeginDrag. From within this public BeginDrag method, 9 /// DragHandlerBase.BeginDrag should be called to initialize the mouse capture 10 /// and message filtering. 11 /// 2. Override the OnDragging and OnEndDrag methods. 12 /// </summary> 13 private abstract class DragHandlerBase : NativeWindow, IMessageFilter { 14 protected DragHandlerBase() { 15 } 25 16 26 protected abstract Control DragControl 27 { 28 get; 29 } 17 protected abstract Control DragControl { 18 get; 19 } 30 20 31 private Point m_startMousePosition = Point.Empty; 32 protected Point StartMousePosition 33 { 34 get { return m_startMousePosition; } 35 private set { m_startMousePosition = value; } 36 } 21 private Point m_startMousePosition = Point.Empty; 22 protected Point StartMousePosition { 23 get { return m_startMousePosition; } 24 private set { m_startMousePosition = value; } 25 } 37 26 38 protected bool BeginDrag() 39 { 40 // Avoid re-entrance; 41 lock (this) 42 { 43 if (DragControl == null) 44 return false; 27 protected bool BeginDrag() { 28 // Avoid re-entrance; 29 lock (this) { 30 if (DragControl == null) 31 return false; 45 32 46 33 StartMousePosition = Control.MousePosition; 47 34 48 49 35 if (!NativeMethods.DragDetect(DragControl.Handle, StartMousePosition)) 36 return false; 50 37 51 52 53 54 55 56 38 DragControl.FindForm().Capture = true; 39 AssignHandle(DragControl.FindForm().Handle); 40 Application.AddMessageFilter(this); 41 return true; 42 } 43 } 57 44 58 45 protected abstract void OnDragging(); 59 46 60 47 protected abstract void OnEndDrag(bool abort); 61 48 62 private void EndDrag(bool abort) 63 { 64 ReleaseHandle(); 65 Application.RemoveMessageFilter(this); 66 DragControl.FindForm().Capture = false; 49 private void EndDrag(bool abort) { 50 ReleaseHandle(); 51 Application.RemoveMessageFilter(this); 52 DragControl.FindForm().Capture = false; 67 53 68 69 54 OnEndDrag(abort); 55 } 70 56 71 bool IMessageFilter.PreFilterMessage(ref Message m) 72 { 73 if (m.Msg == (int)Win32.Msgs.WM_MOUSEMOVE) 74 OnDragging(); 75 else if (m.Msg == (int)Win32.Msgs.WM_LBUTTONUP) 76 EndDrag(false); 77 else if (m.Msg == (int)Win32.Msgs.WM_CAPTURECHANGED) 78 EndDrag(true); 79 else if (m.Msg == (int)Win32.Msgs.WM_KEYDOWN && (int)m.WParam == (int)Keys.Escape) 80 EndDrag(true); 57 bool IMessageFilter.PreFilterMessage(ref Message m) { 58 if (m.Msg == (int)Win32.Msgs.WM_MOUSEMOVE) 59 OnDragging(); 60 else if (m.Msg == (int)Win32.Msgs.WM_LBUTTONUP) 61 EndDrag(false); 62 else if (m.Msg == (int)Win32.Msgs.WM_CAPTURECHANGED) 63 EndDrag(true); 64 else if (m.Msg == (int)Win32.Msgs.WM_KEYDOWN && (int)m.WParam == (int)Keys.Escape) 65 EndDrag(true); 81 66 82 83 67 return OnPreFilterMessage(ref m); 68 } 84 69 85 protected virtual bool OnPreFilterMessage(ref Message m) 86 { 87 return false; 88 } 70 protected virtual bool OnPreFilterMessage(ref Message m) { 71 return false; 72 } 89 73 90 protected sealed override void WndProc(ref Message m) 91 { 92 if (m.Msg == (int)Win32.Msgs.WM_CANCELMODE || m.Msg == (int)Win32.Msgs.WM_CAPTURECHANGED) 93 EndDrag(true); 74 protected sealed override void WndProc(ref Message m) { 75 if (m.Msg == (int)Win32.Msgs.WM_CANCELMODE || m.Msg == (int)Win32.Msgs.WM_CAPTURECHANGED) 76 EndDrag(true); 94 77 95 96 97 78 base.WndProc(ref m); 79 } 80 } 98 81 99 private abstract class DragHandler : DragHandlerBase 100 { 101 private DockPanel m_dockPanel; 82 private abstract class DragHandler : DragHandlerBase { 83 private DockPanel m_dockPanel; 102 84 103 protected DragHandler(DockPanel dockPanel) 104 { 105 m_dockPanel = dockPanel; 106 } 85 protected DragHandler(DockPanel dockPanel) { 86 m_dockPanel = dockPanel; 87 } 107 88 108 public DockPanel DockPanel 109 { 110 get { return m_dockPanel; } 111 } 89 public DockPanel DockPanel { 90 get { return m_dockPanel; } 91 } 112 92 113 private IDragSource m_dragSource; 114 protected IDragSource DragSource 115 { 116 get { return m_dragSource; } 117 set { m_dragSource = value; } 118 } 93 private IDragSource m_dragSource; 94 protected IDragSource DragSource { 95 get { return m_dragSource; } 96 set { m_dragSource = value; } 97 } 119 98 120 protected sealed override Control DragControl 121 { 122 get { return DragSource == null ? null : DragSource.DragControl; } 123 } 99 protected sealed override Control DragControl { 100 get { return DragSource == null ? null : DragSource.DragControl; } 101 } 124 102 125 protected sealed override bool OnPreFilterMessage(ref Message m) 126 { 127 if ((m.Msg == (int)Win32.Msgs.WM_KEYDOWN || m.Msg == (int)Win32.Msgs.WM_KEYUP) && 128 ((int)m.WParam == (int)Keys.ControlKey || (int)m.WParam == (int)Keys.ShiftKey)) 129 OnDragging(); 103 protected sealed override bool OnPreFilterMessage(ref Message m) { 104 if ((m.Msg == (int)Win32.Msgs.WM_KEYDOWN || m.Msg == (int)Win32.Msgs.WM_KEYUP) && 105 ((int)m.WParam == (int)Keys.ControlKey || (int)m.WParam == (int)Keys.ShiftKey)) 106 OnDragging(); 130 107 131 return base.OnPreFilterMessage(ref m); 132 } 133 } 108 return base.OnPreFilterMessage(ref m); 109 } 134 110 } 111 } 135 112 }
Note: See TracChangeset
for help on using the changeset viewer.