Mercurial > hg > ucis.core
comparison FBGUI/FBGUI.cs @ 32:ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Fri, 19 Apr 2013 16:54:51 +0200 |
parents | af27992b5972 |
children | e9b704f193df |
comparison
equal
deleted
inserted
replaced
31:af27992b5972 | 32:ff1bc8445743 |
---|---|
10 using System.Windows.Forms; | 10 using System.Windows.Forms; |
11 using UCIS.VNCServer; | 11 using UCIS.VNCServer; |
12 using ThreadingTimer = System.Threading.Timer; | 12 using ThreadingTimer = System.Threading.Timer; |
13 | 13 |
14 namespace UCIS.FBGUI { | 14 namespace UCIS.FBGUI { |
15 public abstract class FBGEvent { | |
16 } | |
17 public enum FBGPointingEventType { | |
18 Move, | |
19 ButtonDown, | |
20 ButtonUp | |
21 } | |
22 public class FBGPointingEvent : FBGEvent { | |
23 private Point position; | |
24 public Point Position { get { return position; } set { position = value; } } | |
25 public int X { get { return position.X; } set { position.X = value; } } | |
26 public int Y { get { return position.Y; } set { position.Y = value; } } | |
27 public MouseButtons Buttons { get; private set; } | |
28 public FBGPointingEventType Type { get; private set; } | |
29 public FBGCursor Cursor { get; set; } | |
30 public FBGPointingEvent(Point position, MouseButtons buttons, FBGPointingEventType type) { | |
31 this.Position = position; | |
32 this.Buttons = buttons; | |
33 this.Type = type; | |
34 } | |
35 } | |
36 public class FBGKeyboardEvent : FBGEvent { | |
37 public Keys KeyData { get; private set; } | |
38 public Keys KeyCode { get { return KeyData & Keys.KeyCode; } } | |
39 public Keys Modifiers { get { return KeyData & Keys.Modifiers; } } | |
40 public Boolean Shift { get { return (KeyData & Keys.Shift) != 0; } } | |
41 public Boolean Control { get { return (KeyData & Keys.Control) != 0; } } | |
42 public Boolean Alt { get { return (KeyData & Keys.Alt) != 0; } } | |
43 public Boolean IsDown { get; private set; } | |
44 public Char KeyChar { get; private set; } | |
45 public FBGKeyboardEvent(Keys keyData, Char keyChar, Boolean isDown) { | |
46 this.KeyData = keyData; | |
47 this.KeyChar = keyChar; | |
48 this.IsDown = isDown; | |
49 } | |
50 } | |
51 public class FBGPaintEvent : FBGEvent { | |
52 public Graphics Canvas { get; private set; } | |
53 public FBGPaintEvent(Graphics canvas) { | |
54 this.Canvas = canvas; | |
55 } | |
56 } | |
57 public class FBGKeyboardCaptureEvent : FBGEvent { | |
58 public Boolean Capture { get; set; } | |
59 public FBGKeyboardCaptureEvent(Boolean capture) { | |
60 this.Capture = capture; | |
61 } | |
62 } | |
63 public abstract class FBGMessage { | |
64 public IFBGControl Source { get; private set; } | |
65 protected FBGMessage(IFBGControl source) { | |
66 this.Source = source; | |
67 } | |
68 } | |
69 public class FBGInvalidateMessage : FBGMessage { | |
70 public Rectangle Area { get; set; } | |
71 public FBGInvalidateMessage(IFBGControl source, Rectangle area) : base(source) { | |
72 this.Area = area; | |
73 } | |
74 } | |
75 public class FBGPointingCaptureMessage : FBGMessage { | |
76 public Boolean Capture { get; set; } | |
77 public FBGPointingCaptureMessage(IFBGControl source, Boolean capture) : base(source) { | |
78 this.Capture = capture; | |
79 } | |
80 } | |
81 public class FBGKeyboardCaptureMessage : FBGMessage { | |
82 public Boolean Capture { get; set; } | |
83 public FBGKeyboardCaptureMessage(IFBGControl source, Boolean capture) : base(source) { | |
84 this.Capture = capture; | |
85 } | |
86 } | |
87 | |
15 public interface IFBGControl { | 88 public interface IFBGControl { |
16 Rectangle Bounds { get; set; } | 89 Rectangle Bounds { get; set; } |
17 Boolean Visible { get; set; } | 90 Boolean Visible { get; set; } |
18 FBGCursor Cursor { get; } | 91 void HandleEvent(FBGEvent e); |
19 void Paint(Graphics g); | |
20 void MouseMove(Point position, MouseButtons buttons); | |
21 void MouseDown(Point position, MouseButtons buttons); | |
22 void MouseUp(Point position, MouseButtons buttons); | |
23 void KeyDown(Keys key); | |
24 void KeyPress(Char keyChar); | |
25 void KeyUp(Keys key); | |
26 void LostKeyboardCapture(); | |
27 void Orphaned(); | 92 void Orphaned(); |
28 } | 93 } |
29 public interface IFBGContainerControl { | 94 public interface IFBGContainerControl { |
30 void Invalidate(IFBGControl control, Rectangle rect); | |
31 void AddControl(IFBGControl control); | 95 void AddControl(IFBGControl control); |
32 void RemoveControl(IFBGControl control); | 96 void RemoveControl(IFBGControl control); |
33 Boolean CaptureMouse(IFBGControl control, Boolean capture); | 97 void HandleMessage(IFBGControl sender, FBGMessage e); |
34 Boolean CaptureKeyboard(IFBGControl control, Boolean capture); | 98 } |
35 } | 99 |
36 public class FBGControl : IFBGControl { | 100 public class FBGControl : IFBGControl { |
37 private Rectangle bounds = new Rectangle(0, 0, 100, 100); | 101 private Rectangle bounds = new Rectangle(0, 0, 100, 100); |
38 private Color backColor = Color.Transparent; | 102 private Color backColor = Color.Transparent; |
39 private Boolean visible = true; | 103 private Boolean visible = true; |
40 protected FBGCursor CurrentCursor = null; | |
41 public virtual IFBGContainerControl Parent { get; private set; } | 104 public virtual IFBGContainerControl Parent { get; private set; } |
42 public event MouseEventHandler OnMouseDown; | 105 public event MouseEventHandler OnMouseDown; |
43 public event MouseEventHandler OnMouseMove; | 106 public event MouseEventHandler OnMouseMove; |
44 public event MouseEventHandler OnMouseUp; | 107 public event MouseEventHandler OnMouseUp; |
45 public event PaintEventHandler OnPaint; | 108 public event PaintEventHandler OnPaint; |
53 get { return bounds; } | 116 get { return bounds; } |
54 set { | 117 set { |
55 if (bounds == value) return; | 118 if (bounds == value) return; |
56 Rectangle old = bounds; | 119 Rectangle old = bounds; |
57 bounds = value; | 120 bounds = value; |
58 Parent.Invalidate(this, Rectangle.Union(new Rectangle(Point.Empty, value.Size), new Rectangle(old.X - value.X, old.Y - value.Y, old.Width, old.Height))); | 121 Invalidate(Rectangle.Union(new Rectangle(Point.Empty, value.Size), new Rectangle(old.X - value.X, old.Y - value.Y, old.Width, old.Height))); |
59 if (value.Location != old.Location) RaiseEvent(OnMove); | 122 if (value.Location != old.Location) RaiseEvent(OnMove); |
60 if (value.Size != old.Size) RaiseEvent(OnResize); | 123 if (value.Size != old.Size) RaiseEvent(OnResize); |
61 } | 124 } |
62 } | 125 } |
63 public virtual Boolean Visible { | 126 public virtual Boolean Visible { |
65 set { | 128 set { |
66 visible = value; | 129 visible = value; |
67 Invalidate(); | 130 Invalidate(); |
68 } | 131 } |
69 } | 132 } |
70 FBGCursor IFBGControl.Cursor { get { return CurrentCursor; } } | 133 public virtual FBGCursor Cursor { get; set; } |
71 public virtual FBGCursor Cursor { get { return CurrentCursor; } set { CurrentCursor = value; } } | |
72 public Size Size { get { return Bounds.Size; } set { Rectangle r = Bounds; r.Size = value; Bounds = r; } } | 134 public Size Size { get { return Bounds.Size; } set { Rectangle r = Bounds; r.Size = value; Bounds = r; } } |
73 public Point Location { get { return Bounds.Location; } set { Rectangle r = Bounds; r.Location = value; Bounds = r; } } | 135 public Point Location { get { return Bounds.Location; } set { Rectangle r = Bounds; r.Location = value; Bounds = r; } } |
74 public int Left { get { return Bounds.Left; } set { Rectangle r = Bounds; r.X = value; Bounds = r; } } | 136 public int Left { get { return Bounds.Left; } set { Rectangle r = Bounds; r.X = value; Bounds = r; } } |
75 public int Top { get { return Bounds.Top; } set { Rectangle r = Bounds; r.Y = value; Bounds = r; } } | 137 public int Top { get { return Bounds.Top; } set { Rectangle r = Bounds; r.Y = value; Bounds = r; } } |
76 public int Width { get { return Bounds.Width; } set { Rectangle r = Bounds; r.Width = value; Bounds = r; } } | 138 public int Width { get { return Bounds.Width; } set { Rectangle r = Bounds; r.Width = value; Bounds = r; } } |
78 public virtual Color BackColor { get { return backColor; } set { if (backColor == value) return; backColor = value; Invalidate(); } } | 140 public virtual Color BackColor { get { return backColor; } set { if (backColor == value) return; backColor = value; Invalidate(); } } |
79 public virtual void Invalidate() { | 141 public virtual void Invalidate() { |
80 Invalidate(new Rectangle(Point.Empty, Bounds.Size)); | 142 Invalidate(new Rectangle(Point.Empty, Bounds.Size)); |
81 } | 143 } |
82 public virtual void Invalidate(Rectangle rect) { | 144 public virtual void Invalidate(Rectangle rect) { |
83 Parent.Invalidate(this, rect); | 145 Parent.HandleMessage(this, new FBGInvalidateMessage(this, rect)); |
84 } | 146 } |
85 void IFBGControl.Paint(Graphics g) { Paint(g); } | 147 void IFBGControl.HandleEvent(FBGEvent e) { |
86 void IFBGControl.MouseMove(Point position, MouseButtons buttons) { MouseMove(position, buttons); } | 148 HandleEvent(e); |
87 void IFBGControl.MouseDown(Point position, MouseButtons buttons) { MouseDown(position, buttons); } | 149 } |
88 void IFBGControl.MouseUp(Point position, MouseButtons buttons) { MouseUp(position, buttons); } | 150 protected virtual void HandleEvent(FBGEvent e) { |
89 void IFBGControl.KeyDown(Keys g) { KeyDown(g); } | 151 if (e is FBGPaintEvent) HandlePaintEvent((FBGPaintEvent)e); |
90 void IFBGControl.KeyPress(Char g) { KeyPress(g); } | 152 else if (e is FBGPointingEvent) HandlePointingEvent((FBGPointingEvent)e); |
91 void IFBGControl.KeyUp(Keys g) { KeyUp(g); } | 153 else if (e is FBGKeyboardEvent) HandleKeyboardEvent((FBGKeyboardEvent)e); |
92 void IFBGControl.LostKeyboardCapture() { LostKeyboardCapture(); } | 154 else if (e is FBGKeyboardCaptureEvent) HandleKeyboardCaptureEvent((FBGKeyboardCaptureEvent)e); |
155 } | |
156 protected virtual void HandlePaintEvent(FBGPaintEvent e) { | |
157 Paint(e.Canvas); | |
158 } | |
159 protected virtual void HandlePointingEvent(FBGPointingEvent e) { | |
160 if (Cursor != null) e.Cursor = Cursor; | |
161 switch (e.Type) { | |
162 case FBGPointingEventType.Move: MouseMove(e.Position, e.Buttons); break; | |
163 case FBGPointingEventType.ButtonDown: MouseDown(e.Position, e.Buttons); break; | |
164 case FBGPointingEventType.ButtonUp: MouseUp(e.Position, e.Buttons); break; | |
165 } | |
166 } | |
167 protected virtual void HandleKeyboardEvent(FBGKeyboardEvent e) { | |
168 if (e.IsDown) { | |
169 if (e.KeyData != Keys.None) KeyDown(e.KeyData); | |
170 if (e.KeyChar != Char.MinValue) KeyPress(e.KeyChar); | |
171 } else { | |
172 if (e.KeyData != Keys.None) KeyUp(e.KeyData); | |
173 } | |
174 } | |
175 protected virtual void HandleKeyboardCaptureEvent(FBGKeyboardCaptureEvent e) { | |
176 if (!e.Capture) LostKeyboardCapture(); | |
177 } | |
93 void IFBGControl.Orphaned() { Orphaned(); } | 178 void IFBGControl.Orphaned() { Orphaned(); } |
94 protected virtual void Paint(Graphics g) { | 179 protected virtual void Paint(Graphics g) { |
95 if (!visible) return; | 180 if (!visible) return; |
96 if (backColor.A == 0xff) g.Clear(backColor); | 181 if (backColor.A == 0xff) g.Clear(backColor); |
97 else if (backColor.A != 0) using (Brush brush = new SolidBrush(backColor)) g.FillRectangle(brush, g.ClipBounds); | 182 else if (backColor.A != 0) using (Brush brush = new SolidBrush(backColor)) g.FillRectangle(brush, g.ClipBounds); |
99 } | 184 } |
100 protected virtual void MouseMove(Point position, MouseButtons buttons) { RaiseEvent(OnMouseMove, new MouseEventArgs(buttons, 0, position.X, position.Y, 0)); } | 185 protected virtual void MouseMove(Point position, MouseButtons buttons) { RaiseEvent(OnMouseMove, new MouseEventArgs(buttons, 0, position.X, position.Y, 0)); } |
101 protected virtual void MouseDown(Point position, MouseButtons buttons) { RaiseEvent(OnMouseDown, new MouseEventArgs(buttons, 1, position.X, position.Y, 0)); } | 186 protected virtual void MouseDown(Point position, MouseButtons buttons) { RaiseEvent(OnMouseDown, new MouseEventArgs(buttons, 1, position.X, position.Y, 0)); } |
102 protected virtual void MouseUp(Point position, MouseButtons buttons) { RaiseEvent(OnMouseUp, new MouseEventArgs(buttons, 1, position.X, position.Y, 0)); } | 187 protected virtual void MouseUp(Point position, MouseButtons buttons) { RaiseEvent(OnMouseUp, new MouseEventArgs(buttons, 1, position.X, position.Y, 0)); } |
103 protected virtual Boolean CaptureMouse(Boolean capture) { | 188 protected virtual Boolean CaptureMouse(Boolean capture) { |
104 return Parent.CaptureMouse(this, capture); | 189 FBGPointingCaptureMessage m = new FBGPointingCaptureMessage(this, capture); |
190 Parent.HandleMessage(this, m); | |
191 return capture == m.Capture; | |
105 } | 192 } |
106 protected virtual void KeyDown(Keys key) { } | 193 protected virtual void KeyDown(Keys key) { } |
107 protected virtual void KeyPress(Char keyChar) { } | 194 protected virtual void KeyPress(Char keyChar) { } |
108 protected virtual void KeyUp(Keys key) { } | 195 protected virtual void KeyUp(Keys key) { } |
109 protected virtual Boolean CaptureKeyboard(Boolean capture) { | 196 protected virtual Boolean CaptureKeyboard(Boolean capture) { |
110 return Parent.CaptureKeyboard(this, capture); | 197 FBGKeyboardCaptureMessage m = new FBGKeyboardCaptureMessage(this, capture); |
198 Parent.HandleMessage(this, m); | |
199 return capture == m.Capture; | |
111 } | 200 } |
112 protected virtual void LostKeyboardCapture() { } | 201 protected virtual void LostKeyboardCapture() { } |
113 protected virtual void Orphaned() { | 202 protected virtual void Orphaned() { |
114 //IDisposable disp = this as IDisposable; | 203 //IDisposable disp = this as IDisposable; |
115 //if (!ReferenceEquals(disp, null)) disp.Dispose(); | 204 //if (!ReferenceEquals(disp, null)) disp.Dispose(); |
125 public class FBGContainerControl : FBGControl, IFBGContainerControl { | 214 public class FBGContainerControl : FBGControl, IFBGContainerControl { |
126 protected List<IFBGControl> controls = new List<IFBGControl>(); | 215 protected List<IFBGControl> controls = new List<IFBGControl>(); |
127 protected IFBGControl mouseCaptureControl = null; | 216 protected IFBGControl mouseCaptureControl = null; |
128 protected IFBGControl keyboardCaptureControl = null; | 217 protected IFBGControl keyboardCaptureControl = null; |
129 private Rectangle childarea = Rectangle.Empty; | 218 private Rectangle childarea = Rectangle.Empty; |
130 protected FBGCursor DefaultCursor = null; | |
131 public Rectangle ClientRectangle { get { return childarea; } protected set { childarea = value; Invalidate(); } } | 219 public Rectangle ClientRectangle { get { return childarea; } protected set { childarea = value; Invalidate(); } } |
132 public Size ClientSize { get { return childarea.Size; } set { Bounds = new Rectangle(Bounds.Location, Bounds.Size - childarea.Size + value); } } | 220 public Size ClientSize { get { return childarea.Size; } set { Bounds = new Rectangle(Bounds.Location, Bounds.Size - childarea.Size + value); } } |
133 public override FBGCursor Cursor { get { return DefaultCursor; } set { DefaultCursor = value; } } | |
134 public FBGContainerControl(IFBGContainerControl parent) : base(parent) { } | 221 public FBGContainerControl(IFBGContainerControl parent) : base(parent) { } |
135 void IFBGContainerControl.AddControl(IFBGControl control) { AddControl(control); } | 222 void IFBGContainerControl.AddControl(IFBGControl control) { AddControl(control); } |
136 protected virtual void AddControl(IFBGControl control) { | 223 protected virtual void AddControl(IFBGControl control) { |
137 controls.Add(control); | 224 controls.Add(control); |
138 if (control.Visible) Invalidate(control); | 225 if (control.Visible) Invalidate(control); |
139 } | 226 } |
140 public virtual void RemoveControl(IFBGControl control) { | 227 public virtual void RemoveControl(IFBGControl control) { |
141 if (controls.Remove(control)) { | 228 if (controls.Remove(control)) { |
142 if (control.Visible) Invalidate(control); | 229 if (control.Visible) Invalidate(control); |
143 CaptureMouse(control, false); | 230 HandleMessage(control, new FBGPointingCaptureMessage(control, false)); |
144 CaptureKeyboard(control, false); | 231 HandleMessage(control, new FBGKeyboardCaptureMessage(control, false)); |
145 control.Orphaned(); | 232 control.Orphaned(); |
146 } | 233 } |
147 } | 234 } |
148 public virtual Point PointToChild(IFBGControl child, Point point) { | 235 public virtual Point PointToChild(IFBGControl child, Point point) { |
149 return point - (Size)child.Bounds.Location - (Size)ClientRectangle.Location; | 236 return point - (Size)child.Bounds.Location - (Size)ClientRectangle.Location; |
162 Invalidate(new Rectangle(PointFromChild(control, Point.Empty), control.Bounds.Size)); | 249 Invalidate(new Rectangle(PointFromChild(control, Point.Empty), control.Bounds.Size)); |
163 } | 250 } |
164 public virtual void Invalidate(IFBGControl control, Rectangle rect) { | 251 public virtual void Invalidate(IFBGControl control, Rectangle rect) { |
165 Invalidate(new Rectangle(PointFromChild(control, rect.Location), rect.Size)); | 252 Invalidate(new Rectangle(PointFromChild(control, rect.Location), rect.Size)); |
166 } | 253 } |
167 protected override void Paint(Graphics g) { | 254 protected override void HandlePaintEvent(FBGPaintEvent e) { |
168 base.Paint(g); | 255 base.HandlePaintEvent(e); |
169 if (controls == null) return; | 256 if (controls == null) return; |
170 GraphicsState state2 = null; | 257 GraphicsState state2 = null; |
258 Graphics g = e.Canvas; | |
171 if (!childarea.IsEmpty) { | 259 if (!childarea.IsEmpty) { |
172 state2 = g.Save(); | 260 state2 = g.Save(); |
173 g.TranslateTransform(childarea.X, childarea.Y, MatrixOrder.Append); | 261 g.TranslateTransform(childarea.X, childarea.Y, MatrixOrder.Append); |
174 g.IntersectClip(new Rectangle(Point.Empty, childarea.Size)); | 262 g.IntersectClip(new Rectangle(Point.Empty, childarea.Size)); |
175 } | 263 } |
178 if (control.Bounds.Width <= 0 || control.Bounds.Height <= 0) continue; | 266 if (control.Bounds.Width <= 0 || control.Bounds.Height <= 0) continue; |
179 if (!g.ClipBounds.IntersectsWith((RectangleF)control.Bounds)) continue; | 267 if (!g.ClipBounds.IntersectsWith((RectangleF)control.Bounds)) continue; |
180 GraphicsState state = g.Save(); | 268 GraphicsState state = g.Save(); |
181 g.TranslateTransform(control.Bounds.X, control.Bounds.Y, MatrixOrder.Append); | 269 g.TranslateTransform(control.Bounds.X, control.Bounds.Y, MatrixOrder.Append); |
182 g.IntersectClip(new Rectangle(Point.Empty, control.Bounds.Size)); | 270 g.IntersectClip(new Rectangle(Point.Empty, control.Bounds.Size)); |
183 control.Paint(g); | 271 control.HandleEvent(e); |
184 g.Restore(state); | 272 g.Restore(state); |
185 } | 273 } |
186 if (state2 != null) g.Restore(state2); | 274 if (state2 != null) g.Restore(state2); |
187 } | 275 } |
188 public IFBGControl FindControlAtPosition(Point p) { | 276 public IFBGControl FindControlAtPosition(Point p) { |
189 if (!childarea.IsEmpty && !childarea.Contains(p)) return null; | 277 if (!childarea.IsEmpty && !childarea.Contains(p)) return null; |
190 p.Offset(-childarea.X, -childarea.Y); | 278 p.Offset(-childarea.X, -childarea.Y); |
191 return ((List<IFBGControl>)controls).FindLast(delegate(IFBGControl control) { return control.Visible && control.Bounds.Contains(p); }); | 279 return ((List<IFBGControl>)controls).FindLast(delegate(IFBGControl control) { return control.Visible && control.Bounds.Contains(p); }); |
192 } | 280 } |
193 protected override void MouseMove(Point position, MouseButtons buttons) { | 281 protected override void HandlePointingEvent(FBGPointingEvent e) { |
194 IFBGControl control = mouseCaptureControl != null ? mouseCaptureControl : FindControlAtPosition(position); | 282 IFBGControl control = mouseCaptureControl != null ? mouseCaptureControl : FindControlAtPosition(e.Position); |
195 if (control == null) { | 283 if (control == null) { |
196 base.MouseMove(position, buttons); | 284 base.HandlePointingEvent(e); |
197 } else { | 285 } else { |
198 control.MouseMove(PointToChild(control, position), buttons); | 286 if (Cursor != null) e.Cursor = Cursor; |
199 } | 287 e.Position = PointToChild(control, e.Position); |
200 CurrentCursor = control == null || control.Cursor == null ? DefaultCursor : control.Cursor; | 288 control.HandleEvent(e); |
201 } | 289 } |
202 protected override void MouseDown(Point position, MouseButtons buttons) { | 290 } |
203 IFBGControl control = mouseCaptureControl != null ? mouseCaptureControl : FindControlAtPosition(position); | 291 void IFBGContainerControl.HandleMessage(IFBGControl sender, FBGMessage e) { |
204 if (control == null) { | 292 HandleMessage(sender, e); |
205 base.MouseDown(position, buttons); | 293 } |
206 } else { | 294 protected virtual void HandleMessage(IFBGControl sender, FBGMessage e) { |
207 control.MouseDown(PointToChild(control, position), buttons); | 295 if (e is FBGPointingCaptureMessage) HandlePointingCaptureMessage(sender, (FBGPointingCaptureMessage)e); |
208 } | 296 else if (e is FBGKeyboardCaptureMessage) HandleKeyboardCaptureMessage(sender, (FBGKeyboardCaptureMessage)e); |
209 CurrentCursor = control == null || control.Cursor == null ? DefaultCursor : control.Cursor; | 297 else if (e is FBGInvalidateMessage) HandleInvalidateMessage(sender, (FBGInvalidateMessage)e); |
210 } | 298 } |
211 protected override void MouseUp(Point position, MouseButtons buttons) { | 299 protected virtual void HandleInvalidateMessage(IFBGControl sender, FBGInvalidateMessage e) { |
212 IFBGControl control = mouseCaptureControl != null ? mouseCaptureControl : FindControlAtPosition(position); | 300 e.Area = new Rectangle(PointFromChild(sender, e.Area.Location), e.Area.Size); |
213 if (control == null) { | 301 Parent.HandleMessage(this, e); |
214 base.MouseUp(position, buttons); | 302 } |
215 } else { | 303 protected virtual void HandlePointingCaptureMessage(IFBGControl sender, FBGPointingCaptureMessage e) { |
216 control.MouseUp(PointToChild(control, position), buttons); | 304 if (e.Capture && !(ReferenceEquals(mouseCaptureControl, null) || ReferenceEquals(mouseCaptureControl, sender))) e.Capture = false; |
217 } | 305 else if (!e.Capture && !ReferenceEquals(mouseCaptureControl, sender)) e.Capture = false; |
218 CurrentCursor = control == null || control.Cursor == null ? DefaultCursor : control.Cursor; | 306 else { |
219 } | 307 Parent.HandleMessage(this, e); |
220 Boolean IFBGContainerControl.CaptureMouse(IFBGControl control, Boolean capture) { return CaptureMouse(control, capture); } | 308 mouseCaptureControl = e.Capture ? sender : null; |
221 protected Boolean CaptureMouse(IFBGControl control, Boolean capture) { | 309 } |
222 if (capture && !ReferenceEquals(mouseCaptureControl, null)) return false; | 310 } |
223 if (!capture && !ReferenceEquals(mouseCaptureControl, control)) return false; | 311 protected override void HandleKeyboardEvent(FBGKeyboardEvent e) { |
224 if (!CaptureMouse(capture)) return false; | 312 if (ReferenceEquals(keyboardCaptureControl, null)) base.HandleKeyboardEvent(e); |
225 mouseCaptureControl = capture ? control : null; | 313 else keyboardCaptureControl.HandleEvent(e); |
226 return true; | 314 } |
227 } | 315 protected virtual void HandleKeyboardCaptureMessage(IFBGControl sender, FBGKeyboardCaptureMessage e) { |
228 protected override void KeyDown(Keys key) { | 316 if (!e.Capture && !(ReferenceEquals(mouseCaptureControl, null) || ReferenceEquals(mouseCaptureControl, sender))) e.Capture = false; |
229 if (ReferenceEquals(keyboardCaptureControl, null)) base.KeyDown(key); | 317 else { |
230 else keyboardCaptureControl.KeyDown(key); | 318 Parent.HandleMessage(this, e); |
231 } | 319 IFBGControl prev = keyboardCaptureControl; |
232 protected override void KeyPress(Char keyChar) { | 320 keyboardCaptureControl = e.Capture ? sender : null; |
233 if (ReferenceEquals(keyboardCaptureControl, null)) base.KeyPress(keyChar); | 321 if (prev != null && prev != sender) prev.HandleEvent(new FBGKeyboardCaptureEvent(false)); |
234 else keyboardCaptureControl.KeyPress(keyChar); | 322 } |
235 } | 323 } |
236 protected override void KeyUp(Keys key) { | 324 protected override void HandleKeyboardCaptureEvent(FBGKeyboardCaptureEvent e) { |
237 if (ReferenceEquals(keyboardCaptureControl, null)) base.KeyUp(key); | 325 if (keyboardCaptureControl != null) keyboardCaptureControl.HandleEvent(new FBGKeyboardCaptureEvent(false)); |
238 else keyboardCaptureControl.KeyUp(key); | 326 base.HandleKeyboardCaptureEvent(e); |
239 } | |
240 Boolean IFBGContainerControl.CaptureKeyboard(IFBGControl control, Boolean capture) { return CaptureKeyboard(control, capture); } | |
241 protected Boolean CaptureKeyboard(IFBGControl control, Boolean capture) { | |
242 if (!capture && !ReferenceEquals(keyboardCaptureControl, control)) return false; | |
243 if (!CaptureKeyboard(capture)) return false; | |
244 IFBGControl prev = keyboardCaptureControl; | |
245 keyboardCaptureControl = capture ? control : null; | |
246 if (prev != null) LostKeyboardCapture(); | |
247 return true; | |
248 } | |
249 protected override void LostKeyboardCapture() { | |
250 base.LostKeyboardCapture(); | |
251 if (keyboardCaptureControl != null) keyboardCaptureControl.LostKeyboardCapture(); | |
252 } | 327 } |
253 protected override void Orphaned() { | 328 protected override void Orphaned() { |
254 base.Orphaned(); | 329 base.Orphaned(); |
255 IFBGControl[] c = controls.ToArray(); | 330 IFBGControl[] c = controls.ToArray(); |
256 controls.Clear(); | 331 controls.Clear(); |
420 } | 495 } |
421 public virtual Point PointFromChild(IFBGControl child, Point point) { | 496 public virtual Point PointFromChild(IFBGControl child, Point point) { |
422 return point + (Size)child.Bounds.Location; | 497 return point + (Size)child.Bounds.Location; |
423 } | 498 } |
424 | 499 |
425 void IFBGContainerControl.Invalidate(IFBGControl control, Rectangle rect) { | |
426 Invalidate(new Rectangle(PointFromChild(control, rect.Location), rect.Size)); | |
427 } | |
428 void IFBGContainerControl.AddControl(IFBGControl control) { | 500 void IFBGContainerControl.AddControl(IFBGControl control) { |
429 if (!ReferenceEquals(childControl, null)) throw new InvalidOperationException("This container can have only one child control"); | 501 if (!ReferenceEquals(childControl, null)) throw new InvalidOperationException("This container can have only one child control"); |
430 childControl = control; | 502 childControl = control; |
431 control.Bounds = new Rectangle(Point.Empty, ClientSize); | 503 control.Bounds = new Rectangle(Point.Empty, ClientSize); |
432 Invalidate(control.Bounds); | 504 Invalidate(control.Bounds); |
437 Invalidate(control.Bounds); | 509 Invalidate(control.Bounds); |
438 if (mouseCaptureControl == control) mouseCaptureControl = null; | 510 if (mouseCaptureControl == control) mouseCaptureControl = null; |
439 if (keyboardCaptureControl == control) control = null; | 511 if (keyboardCaptureControl == control) control = null; |
440 control.Orphaned(); | 512 control.Orphaned(); |
441 } | 513 } |
442 Boolean IFBGContainerControl.CaptureMouse(IFBGControl control, Boolean capture) { | 514 void IFBGContainerControl.HandleMessage(IFBGControl sender, FBGMessage e) { |
443 if (capture && !ReferenceEquals(mouseCaptureControl, null)) return false; | 515 if (e is FBGInvalidateMessage) { |
444 if (!capture && !ReferenceEquals(mouseCaptureControl, control)) return false; | 516 FBGInvalidateMessage p = (FBGInvalidateMessage)e; |
445 mouseCaptureControl = capture ? control : null; | 517 Invalidate(new Rectangle(PointFromChild(sender, p.Area.Location), p.Area.Size)); |
446 return true; | 518 } else if (e is FBGPointingCaptureMessage) { |
447 } | 519 FBGPointingCaptureMessage p = (FBGPointingCaptureMessage)e; |
448 Boolean IFBGContainerControl.CaptureKeyboard(IFBGControl control, Boolean capture) { | 520 if (p.Capture && !(ReferenceEquals(mouseCaptureControl, null) || ReferenceEquals(mouseCaptureControl, sender))) p.Capture = false; |
449 if (!capture && !ReferenceEquals(keyboardCaptureControl, control)) return false; | 521 else if (!p.Capture && !ReferenceEquals(mouseCaptureControl, sender)) p.Capture = false; |
450 keyboardCaptureControl = capture ? control : null; | 522 else mouseCaptureControl = p.Capture ? sender : null; |
451 return true; | 523 } else if (e is FBGKeyboardCaptureMessage) { |
524 FBGKeyboardCaptureMessage p = (FBGKeyboardCaptureMessage)e; | |
525 if (!p.Capture && !ReferenceEquals(keyboardCaptureControl, sender)) p.Capture = false; | |
526 else keyboardCaptureControl = p.Capture ? sender : null; | |
527 } | |
452 } | 528 } |
453 | 529 |
454 protected override void OnPaint(PaintEventArgs e) { | 530 protected override void OnPaint(PaintEventArgs e) { |
455 base.OnPaint(e); | 531 base.OnPaint(e); |
456 Graphics g = e.Graphics; | 532 Graphics g = e.Graphics; |
459 if (ReferenceEquals(childControl, null)) return; | 535 if (ReferenceEquals(childControl, null)) return; |
460 if (childControl.Bounds.Width <= 0 || childControl.Bounds.Height <= 0) return; | 536 if (childControl.Bounds.Width <= 0 || childControl.Bounds.Height <= 0) return; |
461 if (!g.ClipBounds.IntersectsWith((RectangleF)childControl.Bounds)) return; | 537 if (!g.ClipBounds.IntersectsWith((RectangleF)childControl.Bounds)) return; |
462 g.TranslateTransform(childControl.Bounds.X, childControl.Bounds.Y, MatrixOrder.Append); | 538 g.TranslateTransform(childControl.Bounds.X, childControl.Bounds.Y, MatrixOrder.Append); |
463 g.IntersectClip(new Rectangle(Point.Empty, childControl.Bounds.Size)); | 539 g.IntersectClip(new Rectangle(Point.Empty, childControl.Bounds.Size)); |
464 childControl.Paint(g); | 540 childControl.HandleEvent(new FBGPaintEvent(g)); |
465 g.Restore(state); | 541 g.Restore(state); |
466 } | 542 } |
467 protected override void OnResize(EventArgs e) { | 543 protected override void OnResize(EventArgs e) { |
468 if (!ReferenceEquals(childControl, null)) childControl.Bounds = new Rectangle(Point.Empty, ClientSize); | 544 if (!ReferenceEquals(childControl, null)) childControl.Bounds = new Rectangle(Point.Empty, ClientSize); |
469 base.OnResize(e); | 545 base.OnResize(e); |
470 } | 546 } |
547 void DispatchMouseEvent(MouseEventArgs e, FBGPointingEventType type) { | |
548 IFBGControl control = mouseCaptureControl != null ? mouseCaptureControl : childControl; | |
549 if (control != null) control.HandleEvent(new FBGPointingEvent(e.Location, e.Button, type)); | |
550 } | |
471 protected override void OnMouseDown(MouseEventArgs e) { | 551 protected override void OnMouseDown(MouseEventArgs e) { |
472 base.OnMouseDown(e); | 552 base.OnMouseDown(e); |
473 IFBGControl control = mouseCaptureControl != null ? mouseCaptureControl : childControl; | 553 DispatchMouseEvent(e, FBGPointingEventType.ButtonDown); |
474 if (control != null) control.MouseDown(PointToChild(control, e.Location), e.Button); | |
475 } | 554 } |
476 protected override void OnMouseUp(MouseEventArgs e) { | 555 protected override void OnMouseUp(MouseEventArgs e) { |
477 base.OnMouseUp(e); | 556 base.OnMouseUp(e); |
478 IFBGControl control = mouseCaptureControl != null ? mouseCaptureControl : childControl; | 557 DispatchMouseEvent(e, FBGPointingEventType.ButtonUp); |
479 if (control != null) control.MouseUp(PointToChild(control, e.Location), e.Button); | |
480 } | 558 } |
481 protected override void OnMouseMove(MouseEventArgs e) { | 559 protected override void OnMouseMove(MouseEventArgs e) { |
482 IFBGControl control = mouseCaptureControl != null ? mouseCaptureControl : childControl; | 560 DispatchMouseEvent(e, FBGPointingEventType.Move); |
483 if (control != null) control.MouseMove(PointToChild(control, e.Location), e.Button); | |
484 } | 561 } |
485 protected override bool IsInputChar(char charCode) { | 562 protected override bool IsInputChar(char charCode) { |
486 return true; | 563 return true; |
487 } | 564 } |
488 protected override bool IsInputKey(Keys keyData) { | 565 protected override bool IsInputKey(Keys keyData) { |
489 return true; | 566 return true; |
490 } | 567 } |
491 protected override void OnKeyDown(KeyEventArgs e) { | 568 protected override void OnKeyDown(KeyEventArgs e) { |
492 //base.OnKeyDown(e); | 569 //base.OnKeyDown(e); |
493 if (!ReferenceEquals(keyboardCaptureControl, null)) keyboardCaptureControl.KeyDown(e.KeyData); | 570 if (!ReferenceEquals(keyboardCaptureControl, null)) keyboardCaptureControl.HandleEvent(new FBGKeyboardEvent(e.KeyData, Char.MinValue, true)); |
494 } | 571 } |
495 protected override void OnKeyPress(KeyPressEventArgs e) { | 572 protected override void OnKeyPress(KeyPressEventArgs e) { |
496 //base.OnKeyPress(e); | 573 //base.OnKeyPress(e); |
497 if (!ReferenceEquals(keyboardCaptureControl, null)) keyboardCaptureControl.KeyPress(e.KeyChar); | 574 if (!ReferenceEquals(keyboardCaptureControl, null)) keyboardCaptureControl.HandleEvent(new FBGKeyboardEvent(Keys.None, e.KeyChar, true)); |
498 } | 575 } |
499 protected override void OnKeyUp(KeyEventArgs e) { | 576 protected override void OnKeyUp(KeyEventArgs e) { |
500 //base.OnKeyUp(e); | 577 //base.OnKeyUp(e); |
501 if (!ReferenceEquals(keyboardCaptureControl, null)) keyboardCaptureControl.KeyUp(e.KeyData); | 578 if (!ReferenceEquals(keyboardCaptureControl, null)) keyboardCaptureControl.HandleEvent(new FBGKeyboardEvent(e.KeyData, Char.MinValue, false)); |
502 } | 579 } |
503 protected override void OnHandleDestroyed(EventArgs e) { | 580 protected override void OnHandleDestroyed(EventArgs e) { |
504 if (!ReferenceEquals(childControl, null)) childControl.Orphaned(); | 581 if (!ReferenceEquals(childControl, null)) childControl.Orphaned(); |
505 base.OnHandleDestroyed(e); | 582 base.OnHandleDestroyed(e); |
506 } | 583 } |
629 size = Frontbuffer.Size; | 706 size = Frontbuffer.Size; |
630 } | 707 } |
631 protected FBGRenderer() : base(null) { | 708 protected FBGRenderer() : base(null) { |
632 BackColor = SystemColors.Control; | 709 BackColor = SystemColors.Control; |
633 } | 710 } |
711 protected override void HandleInvalidateMessage(IFBGControl sender, FBGInvalidateMessage e) { | |
712 e.Area = new Rectangle(PointFromChild(sender, e.Area.Location), e.Area.Size); | |
713 Invalidate(e.Area); | |
714 } | |
634 public override void Invalidate(Rectangle rect) { | 715 public override void Invalidate(Rectangle rect) { |
635 if (rect.Width == 0 || rect.Height == 0) return; | 716 if (rect.Width == 0 || rect.Height == 0) return; |
636 lock (RenderLock) { | 717 lock (RenderLock) { |
637 if (SuspendDrawing || PaintTimer != null) { | 718 if (SuspendDrawing || PaintTimer != null) { |
638 DirtyRectangle = DirtyRectangle.IsEmpty ? rect : Rectangle.Union(DirtyRectangle, rect); | 719 DirtyRectangle = DirtyRectangle.IsEmpty ? rect : Rectangle.Union(DirtyRectangle, rect); |
669 if (Framebuffer != null) Framebuffer.DrawImage(Frontbuffer, rect, rect.Location); | 750 if (Framebuffer != null) Framebuffer.DrawImage(Frontbuffer, rect, rect.Location); |
670 } | 751 } |
671 RaiseEvent(Painted, new InvalidateEventArgs(rect)); | 752 RaiseEvent(Painted, new InvalidateEventArgs(rect)); |
672 } | 753 } |
673 } | 754 } |
674 protected override void Paint(Graphics g) { | 755 public virtual new void Paint(Graphics g) { |
675 base.Paint(g); | 756 HandleEvent(new FBGPaintEvent(g)); |
676 if (cursor != null) { | 757 if (cursor != null) { |
677 Point r = CursorPosition; | 758 Point r = CursorPosition; |
678 r.Offset(-cursor.Hotspot.X, -cursor.Hotspot.Y); | 759 r.Offset(-cursor.Hotspot.X, -cursor.Hotspot.Y); |
679 g.DrawImage(cursor.Image, new Rectangle(r, cursor.Size)); | 760 g.DrawImage(cursor.Image, new Rectangle(r, cursor.Size)); |
680 } | 761 } |
681 } | 762 } |
763 protected override void HandlePointingCaptureMessage(IFBGControl sender, FBGPointingCaptureMessage e) { | |
764 if (e.Capture && !(ReferenceEquals(mouseCaptureControl, null) || ReferenceEquals(mouseCaptureControl, sender))) e.Capture = false; | |
765 else if (!e.Capture && !ReferenceEquals(mouseCaptureControl, sender)) e.Capture = false; | |
766 else mouseCaptureControl = e.Capture ? sender : null; | |
767 } | |
768 protected override void HandleKeyboardCaptureMessage(IFBGControl sender, FBGKeyboardCaptureMessage e) { | |
769 if (!e.Capture && !ReferenceEquals(keyboardCaptureControl, sender)) e.Capture = false; | |
770 else { | |
771 IFBGControl prev = keyboardCaptureControl; | |
772 keyboardCaptureControl = e.Capture ? sender : null; | |
773 if (prev != null && prev != sender) prev.HandleEvent(new FBGKeyboardCaptureEvent(false)); | |
774 } | |
775 } | |
776 | |
682 protected override Boolean CaptureMouse(Boolean capture) { | 777 protected override Boolean CaptureMouse(Boolean capture) { |
683 return true; | 778 return true; |
684 } | 779 } |
685 protected override Boolean CaptureKeyboard(bool capture) { | 780 protected override Boolean CaptureKeyboard(bool capture) { |
686 return true; | 781 return true; |
698 return Frontbuffer; | 793 return Frontbuffer; |
699 } | 794 } |
700 public void UnlockBitmapBuffer() { | 795 public void UnlockBitmapBuffer() { |
701 Monitor.Exit(RenderLock); | 796 Monitor.Exit(RenderLock); |
702 } | 797 } |
703 public new void MouseMove(Point position, MouseButtons buttons) { base.MouseMove(position, buttons); UpdateCursor(cursorposition, CurrentCursor); } | 798 void DispatchPointingEvent(Point position, MouseButtons buttons, FBGPointingEventType type) { |
704 public new void MouseDown(Point position, MouseButtons buttons) { base.MouseDown(position, buttons); UpdateCursor(cursorposition, CurrentCursor); } | 799 FBGPointingEvent e = new FBGPointingEvent(position, buttons, type); |
705 public new void MouseUp(Point position, MouseButtons buttons) { base.MouseUp(position, buttons); UpdateCursor(cursorposition, CurrentCursor); } | 800 HandleEvent(e); |
706 public new void KeyDown(Keys key) { base.KeyDown(key); } | 801 UpdateCursor(cursorposition, e.Cursor); |
707 public new void KeyPress(Char key) { base.KeyPress(key); } | 802 } |
708 public new void KeyUp(Keys key) { base.KeyUp(key); } | 803 public new void MouseMove(Point position, MouseButtons buttons) { DispatchPointingEvent(position, buttons, FBGPointingEventType.Move); } |
804 public new void MouseDown(Point position, MouseButtons buttons) { DispatchPointingEvent(position, buttons, FBGPointingEventType.ButtonDown); } | |
805 public new void MouseUp(Point position, MouseButtons buttons) { DispatchPointingEvent(position, buttons, FBGPointingEventType.ButtonUp); } | |
806 public new void KeyDown(Keys key) { KeyDown(key, Char.MinValue); } | |
807 public new void KeyPress(Char key) { KeyDown(Keys.None, key); } | |
808 public new void KeyUp(Keys key) { KeyUp(key, Char.MinValue); } | |
809 public void KeyDown(Keys key, Char keyChar) { HandleEvent(new FBGKeyboardEvent(key, keyChar, true)); } | |
810 public void KeyUp(Keys key, Char keyChar) { HandleEvent(new FBGKeyboardEvent(key, keyChar, false)); } | |
709 } | 811 } |
710 public class FBGForm : FBGDockContainer { | 812 public class FBGForm : FBGDockContainer { |
711 private Point prevPosition = Point.Empty; | 813 private Point prevPosition = Point.Empty; |
712 private NonClientOps moveresize = 0; | 814 private NonClientOps moveresize = 0; |
713 private String text = String.Empty; | 815 private String text = String.Empty; |
754 if (p.Y >= Bounds.Height - 4) mr |= NonClientOps.ResizeBottom; | 856 if (p.Y >= Bounds.Height - 4) mr |= NonClientOps.ResizeBottom; |
755 } | 857 } |
756 if (mr == 0 && Movable && p.Y < 20) mr = NonClientOps.Move; | 858 if (mr == 0 && Movable && p.Y < 20) mr = NonClientOps.Move; |
757 return mr; | 859 return mr; |
758 } | 860 } |
759 private void SetCursorForNonClientOperation(NonClientOps op) { | 861 private void SetCursorForNonClientOperation(NonClientOps op, FBGPointingEvent e) { |
760 switch (op & NonClientOps.MoveResize) { | 862 switch (op & NonClientOps.MoveResize) { |
761 case NonClientOps.Move: CurrentCursor = FBGCursor.Move; break; | 863 case NonClientOps.Move: e.Cursor = FBGCursor.Move; break; |
762 case NonClientOps.ResizeLeft: CurrentCursor = FBGCursor.SizeLeft; break; | 864 case NonClientOps.ResizeLeft: e.Cursor = FBGCursor.SizeLeft; break; |
763 case NonClientOps.ResizeRight: CurrentCursor = FBGCursor.SizeRight; break; | 865 case NonClientOps.ResizeRight: e.Cursor = FBGCursor.SizeRight; break; |
764 case NonClientOps.ResizeBottom: CurrentCursor = FBGCursor.SizeBottom; break; | 866 case NonClientOps.ResizeBottom: e.Cursor = FBGCursor.SizeBottom; break; |
765 case NonClientOps.ResizeTop: CurrentCursor = FBGCursor.SizeTop; break; | 867 case NonClientOps.ResizeTop: e.Cursor = FBGCursor.SizeTop; break; |
766 case NonClientOps.ResizeTop | NonClientOps.ResizeLeft: CurrentCursor = FBGCursor.SizeTopLeft; break; | 868 case NonClientOps.ResizeTop | NonClientOps.ResizeLeft: e.Cursor = FBGCursor.SizeTopLeft; break; |
767 case NonClientOps.ResizeTop | NonClientOps.ResizeRight: CurrentCursor = FBGCursor.SizeTopRight; break; | 869 case NonClientOps.ResizeTop | NonClientOps.ResizeRight: e.Cursor = FBGCursor.SizeTopRight; break; |
768 case NonClientOps.ResizeBottom | NonClientOps.ResizeLeft: CurrentCursor = FBGCursor.SizeBottomLeft; break; | 870 case NonClientOps.ResizeBottom | NonClientOps.ResizeLeft: e.Cursor = FBGCursor.SizeBottomLeft; break; |
769 case NonClientOps.ResizeBottom | NonClientOps.ResizeRight: CurrentCursor = FBGCursor.SizeBottomRight; break; | 871 case NonClientOps.ResizeBottom | NonClientOps.ResizeRight: e.Cursor = FBGCursor.SizeBottomRight; break; |
770 default: CurrentCursor = DefaultCursor; break; | 872 } |
771 } | 873 } |
772 } | 874 protected override void HandlePointingEvent(FBGPointingEvent e) { |
773 protected override void MouseDown(Point p, MouseButtons buttons) { | 875 e.Cursor = Cursor; |
876 if (HandlePointingEventA(e)) base.HandlePointingEvent(e); | |
877 } | |
878 Boolean HandlePointingEventA(FBGPointingEvent e) { | |
879 e.Cursor = Cursor; | |
880 switch (e.Type) { | |
881 case FBGPointingEventType.Move: return MouseMove(e.Position, e.Buttons, e); | |
882 case FBGPointingEventType.ButtonDown: return MouseDown(e.Position, e.Buttons, e); | |
883 case FBGPointingEventType.ButtonUp: return MouseUp(e.Position, e.Buttons, e); | |
884 default: return true; | |
885 } | |
886 } | |
887 Boolean MouseDown(Point p, MouseButtons buttons, FBGPointingEvent e) { | |
774 NonClientOps mr = 0; | 888 NonClientOps mr = 0; |
775 if ((buttons & MouseButtons.Left) != 0) mr = GetNonClientOperation(p); | 889 if ((buttons & MouseButtons.Left) != 0) mr = GetNonClientOperation(p); |
776 if (mr != 0) { | 890 if (mr != 0) { |
777 moveresize = mr; | 891 moveresize = mr; |
778 prevPosition = p; | 892 prevPosition = p; |
893 SetCursorForNonClientOperation(moveresize, e); | |
779 CaptureMouse(true); | 894 CaptureMouse(true); |
895 return false; | |
780 } else { | 896 } else { |
781 base.MouseDown(p, buttons); | 897 return true; |
782 } | 898 } |
783 } | 899 } |
784 protected override void MouseMove(Point position, MouseButtons buttons) { | 900 Boolean MouseMove(Point position, MouseButtons buttons, FBGPointingEvent e) { |
785 if (moveresize == 0) { | 901 SetCursorForNonClientOperation(moveresize == 0 ? GetNonClientOperation(position) : moveresize, e); |
786 base.MouseMove(position, buttons); | 902 if (moveresize == 0) return true; |
787 } else if ((moveresize & NonClientOps.MoveResize) != 0) { | 903 if ((moveresize & NonClientOps.MoveResize) != 0) { |
788 Rectangle b = Bounds; | 904 Rectangle b = Bounds; |
789 int dx = position.X - prevPosition.X; | 905 int dx = position.X - prevPosition.X; |
790 int dy = position.Y - prevPosition.Y; | 906 int dy = position.Y - prevPosition.Y; |
791 if (moveresize == NonClientOps.Move) { | 907 if (moveresize == NonClientOps.Move) { |
792 b.Offset(dx, dy); | 908 b.Offset(dx, dy); |
807 } | 923 } |
808 if (b.Width < 55) b.Width = 55; | 924 if (b.Width < 55) b.Width = 55; |
809 if (b.Height < 25) b.Height = 25; | 925 if (b.Height < 25) b.Height = 25; |
810 Bounds = b; | 926 Bounds = b; |
811 } | 927 } |
812 SetCursorForNonClientOperation(moveresize == 0 ? GetNonClientOperation(position) : moveresize); | 928 return false; |
813 } | 929 } |
814 protected override void MouseUp(Point position, MouseButtons buttons) { | 930 Boolean MouseUp(Point position, MouseButtons buttons, FBGPointingEvent e) { |
815 if (moveresize == 0) { | 931 if (moveresize == 0) { |
816 base.MouseUp(position, buttons); | 932 SetCursorForNonClientOperation(GetNonClientOperation(position), e); |
933 return true; | |
817 } else if ((buttons & MouseButtons.Left) != 0) { | 934 } else if ((buttons & MouseButtons.Left) != 0) { |
818 MouseMove(position, buttons); | 935 MouseMove(position, buttons); |
819 CaptureMouse(false); | 936 CaptureMouse(false); |
820 if (moveresize == NonClientOps.ButtonClose && (new Rectangle(Bounds.Width - 5 - 14, 4, 14, 14)).Contains(position) && Closable) Close(); | 937 if (moveresize == NonClientOps.ButtonClose && (new Rectangle(Bounds.Width - 5 - 14, 4, 14, 14)).Contains(position) && Closable) Close(); |
821 moveresize = 0; | 938 moveresize = 0; |
822 } | 939 SetCursorForNonClientOperation(GetNonClientOperation(position), e); |
823 SetCursorForNonClientOperation(moveresize == 0 ? GetNonClientOperation(position) : moveresize); | 940 } |
941 return false; | |
824 } | 942 } |
825 protected override void Paint(Graphics g) { | 943 protected override void Paint(Graphics g) { |
826 base.Paint(g); | 944 base.Paint(g); |
827 g.DrawRectangle(Pens.Gray, 0, 0, Bounds.Width - 1, Bounds.Height - 1); | 945 g.DrawRectangle(Pens.Gray, 0, 0, Bounds.Width - 1, Bounds.Height - 1); |
828 g.DrawRectangle(Pens.LightGray, 1, 1, Bounds.Width - 3, Bounds.Height - 3); | 946 g.DrawRectangle(Pens.LightGray, 1, 1, Bounds.Width - 3, Bounds.Height - 3); |