Mercurial > hg > ucis.core
annotate FBGUI/FBGUI.cs @ 35:6fcedb1030bf
USBLib: Added support for USBIO driver
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Sun, 21 Apr 2013 18:32:04 +0200 |
parents | 70bde4fa6a2f |
children | 41b2d01ae458 |
rev | line source |
---|---|
23 | 1 ???using System; |
2 using System.Collections.Generic; | |
30
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
3 using System.Diagnostics; |
23 | 4 using System.Drawing; |
5 using System.Drawing.Drawing2D; | |
6 using System.Drawing.Imaging; | |
7 using System.IO; | |
30
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
8 using System.Reflection; |
23 | 9 using System.Threading; |
10 using System.Windows.Forms; | |
11 using UCIS.VNCServer; | |
12 using ThreadingTimer = System.Threading.Timer; | |
13 | |
14 namespace UCIS.FBGUI { | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
15 public abstract class FBGEvent { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
16 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
17 public enum FBGPointingEventType { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
18 Move, |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
19 ButtonDown, |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
20 ButtonUp |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
21 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
22 public class FBGPointingEvent : FBGEvent { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
23 private Point position; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
24 public Point Position { get { return position; } set { position = value; } } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
25 public int X { get { return position.X; } set { position.X = value; } } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
26 public int Y { get { return position.Y; } set { position.Y = value; } } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
27 public MouseButtons Buttons { get; private set; } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
28 public FBGPointingEventType Type { get; private set; } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
29 public FBGCursor Cursor { get; set; } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
30 public FBGPointingEvent(Point position, MouseButtons buttons, FBGPointingEventType type) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
31 this.Position = position; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
32 this.Buttons = buttons; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
33 this.Type = type; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
34 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
35 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
36 public class FBGKeyboardEvent : FBGEvent { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
37 public Keys KeyData { get; private set; } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
38 public Keys KeyCode { get { return KeyData & Keys.KeyCode; } } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
39 public Keys Modifiers { get { return KeyData & Keys.Modifiers; } } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
40 public Boolean Shift { get { return (KeyData & Keys.Shift) != 0; } } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
41 public Boolean Control { get { return (KeyData & Keys.Control) != 0; } } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
42 public Boolean Alt { get { return (KeyData & Keys.Alt) != 0; } } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
43 public Boolean IsDown { get; private set; } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
44 public Char KeyChar { get; private set; } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
45 public FBGKeyboardEvent(Keys keyData, Char keyChar, Boolean isDown) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
46 this.KeyData = keyData; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
47 this.KeyChar = keyChar; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
48 this.IsDown = isDown; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
49 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
50 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
51 public class FBGPaintEvent : FBGEvent { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
52 public Graphics Canvas { get; private set; } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
53 public FBGPaintEvent(Graphics canvas) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
54 this.Canvas = canvas; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
55 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
56 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
57 public class FBGKeyboardCaptureEvent : FBGEvent { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
58 public Boolean Capture { get; set; } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
59 public FBGKeyboardCaptureEvent(Boolean capture) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
60 this.Capture = capture; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
61 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
62 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
63 public abstract class FBGMessage { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
64 public IFBGControl Source { get; private set; } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
65 protected FBGMessage(IFBGControl source) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
66 this.Source = source; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
67 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
68 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
69 public class FBGInvalidateMessage : FBGMessage { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
70 public Rectangle Area { get; set; } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
71 public FBGInvalidateMessage(IFBGControl source, Rectangle area) : base(source) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
72 this.Area = area; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
73 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
74 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
75 public class FBGPointingCaptureMessage : FBGMessage { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
76 public Boolean Capture { get; set; } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
77 public FBGPointingCaptureMessage(IFBGControl source, Boolean capture) : base(source) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
78 this.Capture = capture; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
79 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
80 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
81 public class FBGKeyboardCaptureMessage : FBGMessage { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
82 public Boolean Capture { get; set; } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
83 public FBGKeyboardCaptureMessage(IFBGControl source, Boolean capture) : base(source) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
84 this.Capture = capture; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
85 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
86 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
87 |
23 | 88 public interface IFBGControl { |
89 Rectangle Bounds { get; set; } | |
90 Boolean Visible { get; set; } | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
91 void HandleEvent(FBGEvent e); |
23 | 92 void Orphaned(); |
93 } | |
94 public interface IFBGContainerControl { | |
95 void AddControl(IFBGControl control); | |
96 void RemoveControl(IFBGControl control); | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
97 void HandleMessage(IFBGControl sender, FBGMessage e); |
23 | 98 } |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
99 |
23 | 100 public class FBGControl : IFBGControl { |
101 private Rectangle bounds = new Rectangle(0, 0, 100, 100); | |
102 private Color backColor = Color.Transparent; | |
103 private Boolean visible = true; | |
104 public virtual IFBGContainerControl Parent { get; private set; } | |
105 public event MouseEventHandler OnMouseDown; | |
106 public event MouseEventHandler OnMouseMove; | |
107 public event MouseEventHandler OnMouseUp; | |
108 public event PaintEventHandler OnPaint; | |
109 public event EventHandler OnResize; | |
110 public event EventHandler OnMove; | |
111 public FBGControl(IFBGContainerControl parent) { | |
112 this.Parent = parent; | |
113 if (Parent != null) Parent.AddControl(this); | |
114 } | |
115 public virtual Rectangle Bounds { | |
116 get { return bounds; } | |
117 set { | |
118 if (bounds == value) return; | |
119 Rectangle old = bounds; | |
120 bounds = value; | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
121 Invalidate(Rectangle.Union(new Rectangle(Point.Empty, value.Size), new Rectangle(old.X - value.X, old.Y - value.Y, old.Width, old.Height))); |
23 | 122 if (value.Location != old.Location) RaiseEvent(OnMove); |
123 if (value.Size != old.Size) RaiseEvent(OnResize); | |
124 } | |
125 } | |
126 public virtual Boolean Visible { | |
127 get { return visible; } | |
128 set { | |
129 visible = value; | |
130 Invalidate(); | |
131 } | |
132 } | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
133 public virtual FBGCursor Cursor { get; set; } |
23 | 134 public Size Size { get { return Bounds.Size; } set { Rectangle r = Bounds; r.Size = value; Bounds = r; } } |
135 public Point Location { get { return Bounds.Location; } set { Rectangle r = Bounds; r.Location = value; Bounds = r; } } | |
136 public int Left { get { return Bounds.Left; } set { Rectangle r = Bounds; r.X = value; Bounds = r; } } | |
137 public int Top { get { return Bounds.Top; } set { Rectangle r = Bounds; r.Y = value; Bounds = r; } } | |
138 public int Width { get { return Bounds.Width; } set { Rectangle r = Bounds; r.Width = value; Bounds = r; } } | |
139 public int Height { get { return Bounds.Height; } set { Rectangle r = Bounds; r.Height = value; Bounds = r; } } | |
140 public virtual Color BackColor { get { return backColor; } set { if (backColor == value) return; backColor = value; Invalidate(); } } | |
141 public virtual void Invalidate() { | |
142 Invalidate(new Rectangle(Point.Empty, Bounds.Size)); | |
143 } | |
144 public virtual void Invalidate(Rectangle rect) { | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
145 Parent.HandleMessage(this, new FBGInvalidateMessage(this, rect)); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
146 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
147 void IFBGControl.HandleEvent(FBGEvent e) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
148 HandleEvent(e); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
149 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
150 protected virtual void HandleEvent(FBGEvent e) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
151 if (e is FBGPaintEvent) HandlePaintEvent((FBGPaintEvent)e); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
152 else if (e is FBGPointingEvent) HandlePointingEvent((FBGPointingEvent)e); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
153 else if (e is FBGKeyboardEvent) HandleKeyboardEvent((FBGKeyboardEvent)e); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
154 else if (e is FBGKeyboardCaptureEvent) HandleKeyboardCaptureEvent((FBGKeyboardCaptureEvent)e); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
155 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
156 protected virtual void HandlePaintEvent(FBGPaintEvent e) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
157 Paint(e.Canvas); |
23 | 158 } |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
159 protected virtual void HandlePointingEvent(FBGPointingEvent e) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
160 if (Cursor != null) e.Cursor = Cursor; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
161 switch (e.Type) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
162 case FBGPointingEventType.Move: MouseMove(e.Position, e.Buttons); break; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
163 case FBGPointingEventType.ButtonDown: MouseDown(e.Position, e.Buttons); break; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
164 case FBGPointingEventType.ButtonUp: MouseUp(e.Position, e.Buttons); break; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
165 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
166 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
167 protected virtual void HandleKeyboardEvent(FBGKeyboardEvent e) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
168 if (e.IsDown) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
169 if (e.KeyData != Keys.None) KeyDown(e.KeyData); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
170 if (e.KeyChar != Char.MinValue) KeyPress(e.KeyChar); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
171 } else { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
172 if (e.KeyData != Keys.None) KeyUp(e.KeyData); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
173 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
174 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
175 protected virtual void HandleKeyboardCaptureEvent(FBGKeyboardCaptureEvent e) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
176 if (!e.Capture) LostKeyboardCapture(); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
177 } |
23 | 178 void IFBGControl.Orphaned() { Orphaned(); } |
179 protected virtual void Paint(Graphics g) { | |
180 if (!visible) return; | |
27
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
181 if (backColor.A == 0xff) g.Clear(backColor); |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
182 else if (backColor.A != 0) using (Brush brush = new SolidBrush(backColor)) g.FillRectangle(brush, g.ClipBounds); |
23 | 183 RaiseEvent(OnPaint, new PaintEventArgs(g, Rectangle.Round(g.ClipBounds))); |
184 } | |
185 protected virtual void MouseMove(Point position, MouseButtons buttons) { RaiseEvent(OnMouseMove, new MouseEventArgs(buttons, 0, 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)); } | |
187 protected virtual void MouseUp(Point position, MouseButtons buttons) { RaiseEvent(OnMouseUp, new MouseEventArgs(buttons, 1, position.X, position.Y, 0)); } | |
188 protected virtual Boolean CaptureMouse(Boolean capture) { | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
189 FBGPointingCaptureMessage m = new FBGPointingCaptureMessage(this, capture); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
190 Parent.HandleMessage(this, m); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
191 return capture == m.Capture; |
23 | 192 } |
193 protected virtual void KeyDown(Keys key) { } | |
194 protected virtual void KeyPress(Char keyChar) { } | |
195 protected virtual void KeyUp(Keys key) { } | |
196 protected virtual Boolean CaptureKeyboard(Boolean capture) { | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
197 FBGKeyboardCaptureMessage m = new FBGKeyboardCaptureMessage(this, capture); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
198 Parent.HandleMessage(this, m); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
199 return capture == m.Capture; |
23 | 200 } |
201 protected virtual void LostKeyboardCapture() { } | |
202 protected virtual void Orphaned() { | |
203 //IDisposable disp = this as IDisposable; | |
204 //if (!ReferenceEquals(disp, null)) disp.Dispose(); | |
205 } | |
206 protected void RaiseEvent(KeyEventHandler eh, KeyEventArgs ea) { if (eh != null) eh(this, ea); } | |
207 protected void RaiseEvent(KeyPressEventHandler eh, KeyPressEventArgs ea) { if (eh != null) eh(this, ea); } | |
208 protected void RaiseEvent(MouseEventHandler eh, MouseEventArgs ea) { if (eh != null) eh(this, ea); } | |
209 protected void RaiseEvent(PaintEventHandler eh, PaintEventArgs ea) { if (eh != null) eh(this, ea); } | |
210 protected void RaiseEvent<T>(EventHandler<T> eh, T ea) where T : EventArgs { if (eh != null) eh(this, ea); } | |
211 protected void RaiseEvent(EventHandler eh, EventArgs ea) { if (eh != null) eh(this, ea); } | |
212 protected void RaiseEvent(EventHandler eh) { if (eh != null) eh(this, new EventArgs()); } | |
213 } | |
214 public class FBGContainerControl : FBGControl, IFBGContainerControl { | |
215 protected List<IFBGControl> controls = new List<IFBGControl>(); | |
26
7f0b7a53a000
FBGUI: Allow derived classes to access some internals
Ivo Smits <Ivo@UCIS.nl>
parents:
23
diff
changeset
|
216 protected IFBGControl mouseCaptureControl = null; |
7f0b7a53a000
FBGUI: Allow derived classes to access some internals
Ivo Smits <Ivo@UCIS.nl>
parents:
23
diff
changeset
|
217 protected IFBGControl keyboardCaptureControl = null; |
23 | 218 private Rectangle childarea = Rectangle.Empty; |
219 public Rectangle ClientRectangle { get { return childarea; } protected set { childarea = value; Invalidate(); } } | |
30
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
220 public Size ClientSize { get { return childarea.Size; } set { Bounds = new Rectangle(Bounds.Location, Bounds.Size - childarea.Size + value); } } |
23 | 221 public FBGContainerControl(IFBGContainerControl parent) : base(parent) { } |
222 void IFBGContainerControl.AddControl(IFBGControl control) { AddControl(control); } | |
223 protected virtual void AddControl(IFBGControl control) { | |
224 controls.Add(control); | |
225 if (control.Visible) Invalidate(control); | |
226 } | |
227 public virtual void RemoveControl(IFBGControl control) { | |
228 if (controls.Remove(control)) { | |
229 if (control.Visible) Invalidate(control); | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
230 HandleMessage(control, new FBGPointingCaptureMessage(control, false)); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
231 HandleMessage(control, new FBGKeyboardCaptureMessage(control, false)); |
23 | 232 control.Orphaned(); |
233 } | |
234 } | |
235 public virtual Point PointToChild(IFBGControl child, Point point) { | |
236 return point - (Size)child.Bounds.Location - (Size)ClientRectangle.Location; | |
237 } | |
238 public virtual Point PointFromChild(IFBGControl child, Point point) { | |
239 return point + (Size)child.Bounds.Location + (Size)ClientRectangle.Location; | |
240 } | |
241 public virtual void BringControlToFront(IFBGControl control) { | |
242 if (controls.Count == 0) return; | |
243 if (ReferenceEquals(controls[controls.Count - 1], control)) return; | |
244 if (!controls.Remove(control)) return; | |
245 controls.Add(control); | |
246 if (control.Visible) Invalidate(control); | |
247 } | |
248 public virtual void Invalidate(IFBGControl control) { | |
249 Invalidate(new Rectangle(PointFromChild(control, Point.Empty), control.Bounds.Size)); | |
250 } | |
251 public virtual void Invalidate(IFBGControl control, Rectangle rect) { | |
252 Invalidate(new Rectangle(PointFromChild(control, rect.Location), rect.Size)); | |
253 } | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
254 protected override void HandlePaintEvent(FBGPaintEvent e) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
255 base.HandlePaintEvent(e); |
23 | 256 if (controls == null) return; |
257 GraphicsState state2 = null; | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
258 Graphics g = e.Canvas; |
23 | 259 if (!childarea.IsEmpty) { |
260 state2 = g.Save(); | |
261 g.TranslateTransform(childarea.X, childarea.Y, MatrixOrder.Append); | |
262 g.IntersectClip(new Rectangle(Point.Empty, childarea.Size)); | |
263 } | |
264 foreach (IFBGControl control in controls) { | |
265 if (!control.Visible) continue; | |
266 if (control.Bounds.Width <= 0 || control.Bounds.Height <= 0) continue; | |
267 if (!g.ClipBounds.IntersectsWith((RectangleF)control.Bounds)) continue; | |
268 GraphicsState state = g.Save(); | |
269 g.TranslateTransform(control.Bounds.X, control.Bounds.Y, MatrixOrder.Append); | |
270 g.IntersectClip(new Rectangle(Point.Empty, control.Bounds.Size)); | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
271 control.HandleEvent(e); |
23 | 272 g.Restore(state); |
273 } | |
274 if (state2 != null) g.Restore(state2); | |
275 } | |
276 public IFBGControl FindControlAtPosition(Point p) { | |
277 if (!childarea.IsEmpty && !childarea.Contains(p)) return null; | |
278 p.Offset(-childarea.X, -childarea.Y); | |
279 return ((List<IFBGControl>)controls).FindLast(delegate(IFBGControl control) { return control.Visible && control.Bounds.Contains(p); }); | |
280 } | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
281 protected override void HandlePointingEvent(FBGPointingEvent e) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
282 IFBGControl control = mouseCaptureControl != null ? mouseCaptureControl : FindControlAtPosition(e.Position); |
23 | 283 if (control == null) { |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
284 base.HandlePointingEvent(e); |
23 | 285 } else { |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
286 if (Cursor != null) e.Cursor = Cursor; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
287 e.Position = PointToChild(control, e.Position); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
288 control.HandleEvent(e); |
23 | 289 } |
290 } | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
291 void IFBGContainerControl.HandleMessage(IFBGControl sender, FBGMessage e) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
292 HandleMessage(sender, e); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
293 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
294 protected virtual void HandleMessage(IFBGControl sender, FBGMessage e) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
295 if (e is FBGPointingCaptureMessage) HandlePointingCaptureMessage(sender, (FBGPointingCaptureMessage)e); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
296 else if (e is FBGKeyboardCaptureMessage) HandleKeyboardCaptureMessage(sender, (FBGKeyboardCaptureMessage)e); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
297 else if (e is FBGInvalidateMessage) HandleInvalidateMessage(sender, (FBGInvalidateMessage)e); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
298 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
299 protected virtual void HandleInvalidateMessage(IFBGControl sender, FBGInvalidateMessage e) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
300 e.Area = new Rectangle(PointFromChild(sender, e.Area.Location), e.Area.Size); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
301 Parent.HandleMessage(this, e); |
23 | 302 } |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
303 protected virtual void HandlePointingCaptureMessage(IFBGControl sender, FBGPointingCaptureMessage e) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
304 if (e.Capture && !(ReferenceEquals(mouseCaptureControl, null) || ReferenceEquals(mouseCaptureControl, sender))) e.Capture = false; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
305 else if (!e.Capture && !ReferenceEquals(mouseCaptureControl, sender)) e.Capture = false; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
306 else { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
307 Parent.HandleMessage(this, e); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
308 mouseCaptureControl = e.Capture ? sender : null; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
309 } |
23 | 310 } |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
311 protected override void HandleKeyboardEvent(FBGKeyboardEvent e) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
312 if (ReferenceEquals(keyboardCaptureControl, null)) base.HandleKeyboardEvent(e); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
313 else keyboardCaptureControl.HandleEvent(e); |
23 | 314 } |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
315 protected virtual void HandleKeyboardCaptureMessage(IFBGControl sender, FBGKeyboardCaptureMessage e) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
316 if (!e.Capture && !(ReferenceEquals(mouseCaptureControl, null) || ReferenceEquals(mouseCaptureControl, sender))) e.Capture = false; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
317 else { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
318 Parent.HandleMessage(this, e); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
319 IFBGControl prev = keyboardCaptureControl; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
320 keyboardCaptureControl = e.Capture ? sender : null; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
321 if (prev != null && prev != sender) prev.HandleEvent(new FBGKeyboardCaptureEvent(false)); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
322 } |
23 | 323 } |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
324 protected override void HandleKeyboardCaptureEvent(FBGKeyboardCaptureEvent e) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
325 if (keyboardCaptureControl != null) keyboardCaptureControl.HandleEvent(new FBGKeyboardCaptureEvent(false)); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
326 base.HandleKeyboardCaptureEvent(e); |
23 | 327 } |
328 protected override void Orphaned() { | |
329 base.Orphaned(); | |
330 IFBGControl[] c = controls.ToArray(); | |
331 controls.Clear(); | |
332 foreach (IFBGControl control in c) control.Orphaned(); | |
333 mouseCaptureControl = null; | |
334 keyboardCaptureControl = null; | |
335 } | |
336 } | |
337 public class FBGDockContainer : FBGContainerControl { | |
338 private Dictionary<IFBGControl, DockStyle> dockStyles = new Dictionary<IFBGControl, DockStyle>(); | |
339 private Dictionary<IFBGControl, AnchorStyles> anchorStyles = new Dictionary<IFBGControl, AnchorStyles>(); | |
340 private Rectangle oldBounds; | |
341 public FBGDockContainer(IFBGContainerControl parent) | |
342 : base(parent) { | |
343 oldBounds = ClientRectangle.IsEmpty ? Bounds : new Rectangle(Bounds.Location + (Size)ClientRectangle.Location, ClientRectangle.Size); | |
344 } | |
345 protected override void AddControl(IFBGControl control) { | |
346 base.AddControl(control); | |
347 } | |
348 public override void BringControlToFront(IFBGControl control) { | |
349 base.BringControlToFront(control); | |
350 if (dockStyles.ContainsKey(control)) DoLayout(); | |
351 } | |
352 public override void RemoveControl(IFBGControl control) { | |
353 base.RemoveControl(control); | |
354 if (dockStyles.Remove(control)) DoLayout(); | |
355 } | |
356 public override Rectangle Bounds { | |
357 get { return base.Bounds; } | |
358 set { | |
359 base.Bounds = value; | |
360 DoLayout(); | |
361 Rectangle newBounds = ClientRectangle.IsEmpty ? Bounds : new Rectangle(Bounds.Location + (Size)ClientRectangle.Location, ClientRectangle.Size); | |
362 foreach (KeyValuePair<IFBGControl, AnchorStyles> c in anchorStyles) { | |
363 Rectangle b = c.Key.Bounds; | |
364 if ((c.Value & AnchorStyles.Right) != 0) { | |
365 if ((c.Value & AnchorStyles.Left) == 0) b.X += newBounds.Width - oldBounds.Width; | |
366 else b.Width += newBounds.Width - oldBounds.Width; | |
367 } else if ((c.Value & AnchorStyles.Left) == 0) b.X += newBounds.X - oldBounds.X; | |
368 if ((c.Value & AnchorStyles.Bottom) != 0) { | |
369 if ((c.Value & AnchorStyles.Top) == 0) b.Y += newBounds.Height - oldBounds.Height; | |
370 else b.Height += newBounds.Height - oldBounds.Height; | |
371 } else if ((c.Value & AnchorStyles.Top) == 0) b.Y += newBounds.Y - oldBounds.Y; | |
372 c.Key.Bounds = b; | |
373 } | |
374 oldBounds = newBounds; | |
375 } | |
376 } | |
377 public DockStyle GetDockStyle(IFBGControl control) { | |
378 DockStyle ds; | |
379 if (!dockStyles.TryGetValue(control, out ds)) ds = DockStyle.None; | |
380 return ds; | |
381 } | |
382 public void SetDockStyle(IFBGControl control, DockStyle style) { | |
383 if (style == DockStyle.None) { | |
384 if (dockStyles.Remove(control)) DoLayout(); | |
385 } else if (controls.Contains(control)) { | |
386 anchorStyles.Remove(control); | |
387 dockStyles[control] = style; | |
388 DoLayout(); | |
389 } | |
390 } | |
391 public AnchorStyles GetAnchorStyle(IFBGControl control) { | |
392 AnchorStyles ds; | |
393 if (!anchorStyles.TryGetValue(control, out ds)) ds = AnchorStyles.Left | AnchorStyles.Top; | |
394 return ds; | |
395 } | |
396 public void SetAnchorStyle(IFBGControl control, AnchorStyles style) { | |
397 if (style == (AnchorStyles.Left | AnchorStyles.Top)) { | |
398 anchorStyles.Remove(control); | |
399 } else if (controls.Contains(control)) { | |
400 dockStyles.Remove(control); | |
401 anchorStyles[control] = style; | |
402 } | |
403 } | |
404 public void SetAnchor(IFBGControl control, AnchorStyles style, int value) { | |
405 if (controls.Contains(control)) { | |
406 AnchorStyles oldstyle; | |
407 if (!anchorStyles.TryGetValue(control, out oldstyle)) oldstyle = AnchorStyles.Left | AnchorStyles.Top; | |
408 Rectangle b = control.Bounds; | |
409 switch (style) { | |
410 case AnchorStyles.None: throw new ArgumentException("style", "Anchor style can not be None"); | |
411 case AnchorStyles.Left: b.X = value; break; | |
412 case AnchorStyles.Top: b.Y = value; break; | |
413 case AnchorStyles.Right: | |
414 if ((oldstyle & AnchorStyles.Left) == 0) b.X = ClientRectangle.Width - b.Width - value; | |
415 else b.Width = ClientRectangle.Width - b.X - value; | |
416 break; | |
417 case AnchorStyles.Bottom: | |
418 if ((oldstyle & AnchorStyles.Top) == 0) b.Y = ClientRectangle.Height - b.Height - value; | |
419 else b.Height = ClientRectangle.Height - b.Y - value; | |
420 break; | |
421 default: throw new ArgumentOutOfRangeException("style", "The value vor the style argument is invalid"); | |
422 } | |
423 control.Bounds = b; | |
424 dockStyles.Remove(control); | |
425 anchorStyles[control] = oldstyle | style; | |
426 } | |
427 } | |
428 private void DoLayout() { | |
429 Rectangle a = new Rectangle(Point.Empty, ClientRectangle.IsEmpty ? Bounds.Size : ClientRectangle.Size); | |
430 foreach (KeyValuePair<IFBGControl, DockStyle> c in dockStyles) { | |
431 Rectangle b = c.Key.Bounds; | |
432 if (c.Value == DockStyle.Left) { | |
433 b.Location = a.Location; | |
434 b.Height = a.Height; | |
435 a.X += b.Width; | |
436 a.Width -= b.Width; | |
437 } else if (c.Value == DockStyle.Top) { | |
438 b.Location = a.Location; | |
439 b.Width = a.Width; | |
440 a.Y += b.Height; | |
441 a.Height -= b.Height; | |
442 } else if (c.Value == DockStyle.Right) { | |
443 b.X = a.X + a.Width - b.Width; | |
444 b.Y = a.Y; | |
445 b.Height = a.Height; | |
446 a.Width -= b.Width; | |
447 } else if (c.Value == DockStyle.Bottom) { | |
448 b.X = a.X; | |
449 b.Y = a.Y + a.Height - b.Height; | |
450 b.Width = a.Width; | |
451 a.Height -= b.Height; | |
452 } else if (c.Value == DockStyle.Fill) { | |
453 b = a; | |
454 } | |
455 c.Key.Bounds = b; | |
456 if (a.Width < 0) a.Width = 0; | |
457 if (a.Height < 0) a.Height = 0; | |
458 } | |
459 } | |
460 } | |
461 public class FBGGroupBox : FBGDockContainer { | |
462 private String text = String.Empty; | |
463 public FBGGroupBox(IFBGContainerControl parent) | |
464 : base(parent) { | |
465 ClientRectangle = new Rectangle(1, 15, Bounds.Width - 2, Bounds.Height - 17); | |
466 } | |
467 public override Rectangle Bounds { | |
468 get { return base.Bounds; } | |
469 set { | |
470 ClientRectangle = new Rectangle(1, 15, value.Width - 2, value.Height - 17); | |
471 base.Bounds = value; | |
472 } | |
473 } | |
474 public String Text { get { return text; } set { if (text == value) return; text = value; Invalidate(new Rectangle(0, 0, Bounds.Width, 15)); } } | |
475 protected override void Paint(Graphics g) { | |
476 base.Paint(g); | |
477 g.DrawRectangle(Pens.Gray, 0, 6, Bounds.Width - 1, Bounds.Height - 7); | |
478 SizeF ss = g.MeasureString(Text, SystemFonts.DefaultFont, new Size(Bounds.Width - 10 - 9, 15)); | |
479 g.FillRectangle(SystemBrushes.Control, 9, 0, ss.Width, ss.Height); | |
480 g.DrawString(Text, SystemFonts.DefaultFont, Brushes.DarkBlue, new Rectangle(9, 0, Bounds.Width - 10 - 9, 15)); | |
481 } | |
482 } | |
483 public class WinFormsFBGHost : Control, IFBGContainerControl { | |
484 private IFBGControl childControl = null; | |
485 private IFBGControl mouseCaptureControl = null; | |
486 private IFBGControl keyboardCaptureControl = null; | |
487 public IFBGControl ChildControl { get { return childControl; } } | |
488 | |
489 public WinFormsFBGHost() { | |
490 DoubleBuffered = true; | |
491 } | |
492 | |
493 public virtual Point PointToChild(IFBGControl child, Point point) { | |
494 return point - (Size)child.Bounds.Location; | |
495 } | |
496 public virtual Point PointFromChild(IFBGControl child, Point point) { | |
497 return point + (Size)child.Bounds.Location; | |
498 } | |
499 | |
500 void IFBGContainerControl.AddControl(IFBGControl control) { | |
501 if (!ReferenceEquals(childControl, null)) throw new InvalidOperationException("This container can have only one child control"); | |
502 childControl = control; | |
503 control.Bounds = new Rectangle(Point.Empty, ClientSize); | |
504 Invalidate(control.Bounds); | |
505 } | |
506 void IFBGContainerControl.RemoveControl(IFBGControl control) { | |
507 if (!ReferenceEquals(childControl, control)) return; | |
508 childControl = null; | |
509 Invalidate(control.Bounds); | |
510 if (mouseCaptureControl == control) mouseCaptureControl = null; | |
511 if (keyboardCaptureControl == control) control = null; | |
512 control.Orphaned(); | |
513 } | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
514 void IFBGContainerControl.HandleMessage(IFBGControl sender, FBGMessage e) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
515 if (e is FBGInvalidateMessage) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
516 FBGInvalidateMessage p = (FBGInvalidateMessage)e; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
517 Invalidate(new Rectangle(PointFromChild(sender, p.Area.Location), p.Area.Size)); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
518 } else if (e is FBGPointingCaptureMessage) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
519 FBGPointingCaptureMessage p = (FBGPointingCaptureMessage)e; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
520 if (p.Capture && !(ReferenceEquals(mouseCaptureControl, null) || ReferenceEquals(mouseCaptureControl, sender))) p.Capture = false; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
521 else if (!p.Capture && !ReferenceEquals(mouseCaptureControl, sender)) p.Capture = false; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
522 else mouseCaptureControl = p.Capture ? sender : null; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
523 } else if (e is FBGKeyboardCaptureMessage) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
524 FBGKeyboardCaptureMessage p = (FBGKeyboardCaptureMessage)e; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
525 if (!p.Capture && !ReferenceEquals(keyboardCaptureControl, sender)) p.Capture = false; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
526 else keyboardCaptureControl = p.Capture ? sender : null; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
527 } |
23 | 528 } |
529 | |
530 protected override void OnPaint(PaintEventArgs e) { | |
531 base.OnPaint(e); | |
532 Graphics g = e.Graphics; | |
533 GraphicsState state = g.Save(); | |
534 g.SetClip(e.ClipRectangle); | |
535 if (ReferenceEquals(childControl, null)) return; | |
536 if (childControl.Bounds.Width <= 0 || childControl.Bounds.Height <= 0) return; | |
537 if (!g.ClipBounds.IntersectsWith((RectangleF)childControl.Bounds)) return; | |
538 g.TranslateTransform(childControl.Bounds.X, childControl.Bounds.Y, MatrixOrder.Append); | |
539 g.IntersectClip(new Rectangle(Point.Empty, childControl.Bounds.Size)); | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
540 childControl.HandleEvent(new FBGPaintEvent(g)); |
23 | 541 g.Restore(state); |
542 } | |
543 protected override void OnResize(EventArgs e) { | |
544 if (!ReferenceEquals(childControl, null)) childControl.Bounds = new Rectangle(Point.Empty, ClientSize); | |
545 base.OnResize(e); | |
546 } | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
547 void DispatchMouseEvent(MouseEventArgs e, FBGPointingEventType type) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
548 IFBGControl control = mouseCaptureControl != null ? mouseCaptureControl : childControl; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
549 if (control != null) control.HandleEvent(new FBGPointingEvent(e.Location, e.Button, type)); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
550 } |
23 | 551 protected override void OnMouseDown(MouseEventArgs e) { |
552 base.OnMouseDown(e); | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
553 DispatchMouseEvent(e, FBGPointingEventType.ButtonDown); |
23 | 554 } |
555 protected override void OnMouseUp(MouseEventArgs e) { | |
556 base.OnMouseUp(e); | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
557 DispatchMouseEvent(e, FBGPointingEventType.ButtonUp); |
23 | 558 } |
559 protected override void OnMouseMove(MouseEventArgs e) { | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
560 DispatchMouseEvent(e, FBGPointingEventType.Move); |
23 | 561 } |
562 protected override bool IsInputChar(char charCode) { | |
563 return true; | |
564 } | |
565 protected override bool IsInputKey(Keys keyData) { | |
566 return true; | |
567 } | |
568 protected override void OnKeyDown(KeyEventArgs e) { | |
569 //base.OnKeyDown(e); | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
570 if (!ReferenceEquals(keyboardCaptureControl, null)) keyboardCaptureControl.HandleEvent(new FBGKeyboardEvent(e.KeyData, Char.MinValue, true)); |
23 | 571 } |
572 protected override void OnKeyPress(KeyPressEventArgs e) { | |
573 //base.OnKeyPress(e); | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
574 if (!ReferenceEquals(keyboardCaptureControl, null)) keyboardCaptureControl.HandleEvent(new FBGKeyboardEvent(Keys.None, e.KeyChar, true)); |
23 | 575 } |
576 protected override void OnKeyUp(KeyEventArgs e) { | |
577 //base.OnKeyUp(e); | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
578 if (!ReferenceEquals(keyboardCaptureControl, null)) keyboardCaptureControl.HandleEvent(new FBGKeyboardEvent(e.KeyData, Char.MinValue, false)); |
23 | 579 } |
580 protected override void OnHandleDestroyed(EventArgs e) { | |
581 if (!ReferenceEquals(childControl, null)) childControl.Orphaned(); | |
582 base.OnHandleDestroyed(e); | |
583 } | |
584 } | |
585 public class FBGCursor { | |
586 public Image Image { get; private set; } | |
587 public Point Hotspot { get; private set; } | |
588 public Size Size { get; private set; } | |
589 public FBGCursor(Image image, Point hotspot) { | |
590 this.Image = image; | |
591 this.Hotspot = hotspot; | |
592 this.Size = image.Size; | |
593 } | |
30
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
594 public Rectangle Area { get { return new Rectangle(-Hotspot.X, -Hotspot.Y, Size.Width, Size.Height); } } |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
595 public FBGCursor RotateFlip(RotateFlipType type) { |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
596 Image img = new Bitmap(Image); |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
597 img.RotateFlip(type); |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
598 Point hs = Hotspot; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
599 switch (type) { |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
600 case RotateFlipType.RotateNoneFlipNone: break; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
601 case RotateFlipType.Rotate90FlipNone: hs = new Point(img.Width - hs.Y, hs.X); break; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
602 case RotateFlipType.Rotate180FlipNone: hs = new Point(img.Width - hs.X, img.Height - hs.Y); break; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
603 case RotateFlipType.Rotate270FlipNone: hs = new Point(hs.Y, img.Height - hs.X); break; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
604 case RotateFlipType.RotateNoneFlipX: hs.X = img.Width - hs.X; break; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
605 case RotateFlipType.Rotate90FlipX: hs = new Point(hs.Y, hs.X); break; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
606 case RotateFlipType.RotateNoneFlipY: hs.Y = img.Height - hs.Y; break; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
607 case RotateFlipType.Rotate90FlipY: hs = new Point(img.Width - hs.Y, img.Height - hs.X); break; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
608 } |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
609 return new FBGCursor(img, hs); |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
610 } |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
611 public static FBGCursor FromBase64Image(String data, Point hotspot) { |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
612 return new FBGCursor(Image.FromStream(new MemoryStream(Convert.FromBase64String(data))), hotspot); |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
613 } |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
614 private static FBGCursor LoadFromResource(String name, int hotX, int hotY) { |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
615 using (Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream("UCIS.FBGUI." + name + ".png")) { |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
616 return new FBGCursor(Image.FromStream(s), new Point(hotX, hotY)); |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
617 } |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
618 } |
23 | 619 |
30
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
620 public static readonly FBGCursor Arrow = LoadFromResource("cursor_arrow", 0, 0); |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
621 public static readonly FBGCursor Move = LoadFromResource("cursor_move", 8, 8); |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
622 public static readonly FBGCursor SizeLeft = LoadFromResource("cursor_left", 1, 10); |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
623 public static readonly FBGCursor SizeRight = SizeLeft.RotateFlip(RotateFlipType.RotateNoneFlipX); |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
624 public static readonly FBGCursor SizeTop = SizeLeft.RotateFlip(RotateFlipType.Rotate90FlipNone); |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
625 public static readonly FBGCursor SizeBottom = SizeLeft.RotateFlip(RotateFlipType.Rotate90FlipY); |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
626 public static readonly FBGCursor SizeTopLeft = LoadFromResource("cursor_topleft", 1, 1); |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
627 public static readonly FBGCursor SizeTopRight = SizeTopLeft.RotateFlip(RotateFlipType.RotateNoneFlipX); |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
628 public static readonly FBGCursor SizeBottomLeft = SizeTopLeft.RotateFlip(RotateFlipType.RotateNoneFlipY); |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
629 public static readonly FBGCursor SizeBottomRight = SizeTopLeft.RotateFlip(RotateFlipType.RotateNoneFlipXY); |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
630 public static FBGCursor ArrowCursor { get { return Arrow; } } |
23 | 631 } |
632 public class FBGRenderer : FBGContainerControl, IDisposable { | |
633 private FBGCursor cursor = null; | |
634 private Point cursorposition = Point.Empty; | |
635 public IFramebuffer Framebuffer { get; private set; } | |
26
7f0b7a53a000
FBGUI: Allow derived classes to access some internals
Ivo Smits <Ivo@UCIS.nl>
parents:
23
diff
changeset
|
636 private Bitmap Frontbuffer = null; |
7f0b7a53a000
FBGUI: Allow derived classes to access some internals
Ivo Smits <Ivo@UCIS.nl>
parents:
23
diff
changeset
|
637 protected Object RenderLock = new object(); |
23 | 638 public event EventHandler<InvalidateEventArgs> Painted; |
26
7f0b7a53a000
FBGUI: Allow derived classes to access some internals
Ivo Smits <Ivo@UCIS.nl>
parents:
23
diff
changeset
|
639 protected Size size = Size.Empty; |
23 | 640 private ThreadingTimer PaintTimer = null; |
641 private Boolean PaintScheduled = false; | |
642 private int PaintDelay = 0; | |
643 public Boolean SuspendDrawing { | |
644 get { return suspenddrawing; } | |
645 set { | |
646 lock (RenderLock) { | |
647 suspenddrawing = value; | |
648 if (!value) { | |
649 Refresh(DirtyRectangle); | |
650 DirtyRectangle = Rectangle.Empty; | |
651 } | |
652 } | |
653 } | |
654 } | |
655 public int RedrawDelay { | |
656 get { return PaintDelay; } | |
657 set { | |
658 lock (RenderLock) { | |
659 if (value < 0) throw new ArgumentOutOfRangeException("value"); | |
660 PaintDelay = value; | |
661 if (PaintDelay == 0) { | |
662 if (PaintTimer != null) PaintTimer.Dispose(); | |
663 PaintTimer = null; | |
664 if (PaintScheduled) PaintTimerCallback(null); | |
665 } else { | |
666 PaintTimer = new ThreadingTimer(PaintTimerCallback); | |
667 } | |
668 } | |
669 } | |
670 } | |
671 private Boolean suspenddrawing = false; | |
672 private Rectangle DirtyRectangle; | |
673 | |
674 public Point CursorPosition { | |
675 get { return cursorposition; } | |
30
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
676 set { UpdateCursor(value, cursor); } |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
677 } |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
678 protected void UpdateCursor(Point position, FBGCursor cursor) { |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
679 if (cursorposition == position && cursor == this.cursor) return; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
680 Rectangle r1 = Rectangle.Empty; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
681 if (this.cursor != null) { |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
682 r1 = this.cursor.Area; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
683 r1.Offset(cursorposition); |
23 | 684 } |
30
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
685 if (cursor != null) { |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
686 Rectangle r2 = cursor.Area; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
687 r2.Offset(position); |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
688 r1 = r1.IsEmpty ? r2 : Rectangle.Union(r1, r2); |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
689 } |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
690 this.cursor = cursor; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
691 cursorposition = position; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
692 Invalidate(r1); |
23 | 693 } |
694 public override Rectangle Bounds { | |
695 get { return new Rectangle(Point.Empty, size); } | |
696 set { throw new NotSupportedException("Can not change the top control bounds"); } | |
697 } | |
698 public FBGRenderer(IFramebuffer fb) : this(fb.Width, fb.Height) { | |
699 Framebuffer = fb; | |
700 } | |
701 public FBGRenderer(Size fbsize) : this(fbsize.Width, fbsize.Height) { } | |
702 public FBGRenderer(int width, int height) : this(new Bitmap(width, height, PixelFormat.Format32bppRgb)) { } | |
703 public FBGRenderer(Bitmap bmp) : base(null) { | |
704 Frontbuffer = bmp; | |
705 BackColor = SystemColors.Control; | |
706 size = Frontbuffer.Size; | |
707 } | |
26
7f0b7a53a000
FBGUI: Allow derived classes to access some internals
Ivo Smits <Ivo@UCIS.nl>
parents:
23
diff
changeset
|
708 protected FBGRenderer() : base(null) { |
7f0b7a53a000
FBGUI: Allow derived classes to access some internals
Ivo Smits <Ivo@UCIS.nl>
parents:
23
diff
changeset
|
709 BackColor = SystemColors.Control; |
7f0b7a53a000
FBGUI: Allow derived classes to access some internals
Ivo Smits <Ivo@UCIS.nl>
parents:
23
diff
changeset
|
710 } |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
711 protected override void HandleInvalidateMessage(IFBGControl sender, FBGInvalidateMessage e) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
712 e.Area = new Rectangle(PointFromChild(sender, e.Area.Location), e.Area.Size); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
713 Invalidate(e.Area); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
714 } |
23 | 715 public override void Invalidate(Rectangle rect) { |
716 if (rect.Width == 0 || rect.Height == 0) return; | |
717 lock (RenderLock) { | |
718 if (SuspendDrawing || PaintTimer != null) { | |
719 DirtyRectangle = DirtyRectangle.IsEmpty ? rect : Rectangle.Union(DirtyRectangle, rect); | |
720 if (!SuspendDrawing && !PaintScheduled) { | |
721 PaintScheduled = true; | |
722 PaintTimer.Change(PaintDelay, Timeout.Infinite); | |
723 } | |
724 } else { | |
725 Refresh(rect); | |
726 } | |
727 } | |
728 } | |
729 private void PaintTimerCallback(Object state) { | |
730 try { | |
731 lock (RenderLock) { | |
732 PaintScheduled = false; | |
733 Refresh(DirtyRectangle); | |
734 DirtyRectangle = Rectangle.Empty; | |
735 } | |
30
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
736 } catch (Exception ex) { |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
737 Debug.WriteLine(ex); |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
738 Console.Error.WriteLine(ex); |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
739 } |
23 | 740 } |
26
7f0b7a53a000
FBGUI: Allow derived classes to access some internals
Ivo Smits <Ivo@UCIS.nl>
parents:
23
diff
changeset
|
741 protected virtual void Refresh(Rectangle rect) { |
23 | 742 lock (RenderLock) { |
743 rect.Intersect(Bounds); | |
744 if (rect.Width == 0 || rect.Height == 0) return; | |
26
7f0b7a53a000
FBGUI: Allow derived classes to access some internals
Ivo Smits <Ivo@UCIS.nl>
parents:
23
diff
changeset
|
745 if (Frontbuffer != null) { |
7f0b7a53a000
FBGUI: Allow derived classes to access some internals
Ivo Smits <Ivo@UCIS.nl>
parents:
23
diff
changeset
|
746 using (Graphics g = Graphics.FromImage(Frontbuffer)) { |
7f0b7a53a000
FBGUI: Allow derived classes to access some internals
Ivo Smits <Ivo@UCIS.nl>
parents:
23
diff
changeset
|
747 g.SetClip(rect); |
7f0b7a53a000
FBGUI: Allow derived classes to access some internals
Ivo Smits <Ivo@UCIS.nl>
parents:
23
diff
changeset
|
748 Paint(g); |
7f0b7a53a000
FBGUI: Allow derived classes to access some internals
Ivo Smits <Ivo@UCIS.nl>
parents:
23
diff
changeset
|
749 } |
7f0b7a53a000
FBGUI: Allow derived classes to access some internals
Ivo Smits <Ivo@UCIS.nl>
parents:
23
diff
changeset
|
750 if (Framebuffer != null) Framebuffer.DrawImage(Frontbuffer, rect, rect.Location); |
23 | 751 } |
752 RaiseEvent(Painted, new InvalidateEventArgs(rect)); | |
753 } | |
754 } | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
755 public virtual new void Paint(Graphics g) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
756 HandleEvent(new FBGPaintEvent(g)); |
30
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
757 if (cursor != null) { |
23 | 758 Point r = CursorPosition; |
759 r.Offset(-cursor.Hotspot.X, -cursor.Hotspot.Y); | |
30
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
760 g.DrawImage(cursor.Image, new Rectangle(r, cursor.Size)); |
23 | 761 } |
762 } | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
763 protected override void HandlePointingCaptureMessage(IFBGControl sender, FBGPointingCaptureMessage e) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
764 if (e.Capture && !(ReferenceEquals(mouseCaptureControl, null) || ReferenceEquals(mouseCaptureControl, sender))) e.Capture = false; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
765 else if (!e.Capture && !ReferenceEquals(mouseCaptureControl, sender)) e.Capture = false; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
766 else mouseCaptureControl = e.Capture ? sender : null; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
767 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
768 protected override void HandleKeyboardCaptureMessage(IFBGControl sender, FBGKeyboardCaptureMessage e) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
769 if (!e.Capture && !ReferenceEquals(keyboardCaptureControl, sender)) e.Capture = false; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
770 else { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
771 IFBGControl prev = keyboardCaptureControl; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
772 keyboardCaptureControl = e.Capture ? sender : null; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
773 if (prev != null && prev != sender) prev.HandleEvent(new FBGKeyboardCaptureEvent(false)); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
774 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
775 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
776 |
23 | 777 protected override Boolean CaptureMouse(Boolean capture) { |
778 return true; | |
779 } | |
780 protected override Boolean CaptureKeyboard(bool capture) { | |
781 return true; | |
782 } | |
26
7f0b7a53a000
FBGUI: Allow derived classes to access some internals
Ivo Smits <Ivo@UCIS.nl>
parents:
23
diff
changeset
|
783 public virtual void Dispose() { |
23 | 784 lock (RenderLock) { |
785 if (PaintTimer != null) PaintTimer.Dispose(); | |
786 PaintTimer = null; | |
787 } | |
788 Orphaned(); | |
789 if (Frontbuffer != null) Frontbuffer.Dispose(); | |
790 } | |
791 public Bitmap LockBitmapBuffer() { | |
792 Monitor.Enter(RenderLock); | |
793 return Frontbuffer; | |
794 } | |
795 public void UnlockBitmapBuffer() { | |
796 Monitor.Exit(RenderLock); | |
797 } | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
798 void DispatchPointingEvent(Point position, MouseButtons buttons, FBGPointingEventType type) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
799 FBGPointingEvent e = new FBGPointingEvent(position, buttons, type); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
800 HandleEvent(e); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
801 UpdateCursor(cursorposition, e.Cursor); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
802 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
803 public new void MouseMove(Point position, MouseButtons buttons) { DispatchPointingEvent(position, buttons, FBGPointingEventType.Move); } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
804 public new void MouseDown(Point position, MouseButtons buttons) { DispatchPointingEvent(position, buttons, FBGPointingEventType.ButtonDown); } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
805 public new void MouseUp(Point position, MouseButtons buttons) { DispatchPointingEvent(position, buttons, FBGPointingEventType.ButtonUp); } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
806 public new void KeyDown(Keys key) { KeyDown(key, Char.MinValue); } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
807 public new void KeyPress(Char key) { KeyDown(Keys.None, key); } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
808 public new void KeyUp(Keys key) { KeyUp(key, Char.MinValue); } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
809 public void KeyDown(Keys key, Char keyChar) { HandleEvent(new FBGKeyboardEvent(key, keyChar, true)); } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
810 public void KeyUp(Keys key, Char keyChar) { HandleEvent(new FBGKeyboardEvent(key, keyChar, false)); } |
23 | 811 } |
812 public class FBGForm : FBGDockContainer { | |
813 private Point prevPosition = Point.Empty; | |
814 private NonClientOps moveresize = 0; | |
815 private String text = String.Empty; | |
816 public event EventHandler TextChanged; | |
31 | 817 public event EventHandler Closed; |
23 | 818 public Boolean Sizable { get; set; } |
819 public Boolean Movable { get; set; } | |
820 public Boolean Closable { get; set; } | |
821 [Flags] | |
822 private enum NonClientOps : int { | |
823 None = 0, | |
824 Move = 1, | |
825 ResizeLeft = 2, | |
826 ResizeRight = 4, | |
827 ResizeTop = 8, | |
828 ResizeBottom = 16, | |
829 ButtonClose = 32, | |
830 MoveResize = ResizeLeft | ResizeRight | ResizeBottom | ResizeTop | Move, | |
831 } | |
832 public FBGForm(IFBGContainerControl parent) : base(parent) { | |
833 BackColor = SystemColors.Control; | |
834 ClientRectangle = new Rectangle(4, 22, Bounds.Width - 8, Bounds.Height - 26); | |
835 Sizable = true; | |
836 Movable = true; | |
837 Closable = false; | |
838 } | |
839 public override Rectangle Bounds { | |
840 get { return base.Bounds; } | |
841 set { | |
842 ClientRectangle = new Rectangle(4, 22, value.Width - 8, value.Height - 26); | |
843 base.Bounds = value; | |
844 } | |
845 } | |
846 public String Text { get { return text; } set { if (text == value) return; text = value; Invalidate(new Rectangle(0, 0, Bounds.Width, 20)); RaiseEvent(TextChanged); } } | |
30
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
847 private NonClientOps GetNonClientOperation(Point p) { |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
848 if ((new Rectangle(Bounds.Width - 5 - 14, 4, 14, 14)).Contains(p)) return NonClientOps.ButtonClose; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
849 NonClientOps mr = 0; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
850 if (Sizable) { |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
851 if (Movable) { |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
852 if (p.X < 4) mr |= NonClientOps.ResizeLeft; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
853 if (p.Y < 4) mr |= NonClientOps.ResizeTop; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
854 } |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
855 if (p.X >= Bounds.Width - 4) mr |= NonClientOps.ResizeRight; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
856 if (p.Y >= Bounds.Height - 4) mr |= NonClientOps.ResizeBottom; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
857 } |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
858 if (mr == 0 && Movable && p.Y < 20) mr = NonClientOps.Move; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
859 return mr; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
860 } |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
861 private void SetCursorForNonClientOperation(NonClientOps op, FBGPointingEvent e) { |
30
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
862 switch (op & NonClientOps.MoveResize) { |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
863 case NonClientOps.Move: e.Cursor = FBGCursor.Move; break; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
864 case NonClientOps.ResizeLeft: e.Cursor = FBGCursor.SizeLeft; break; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
865 case NonClientOps.ResizeRight: e.Cursor = FBGCursor.SizeRight; break; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
866 case NonClientOps.ResizeBottom: e.Cursor = FBGCursor.SizeBottom; break; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
867 case NonClientOps.ResizeTop: e.Cursor = FBGCursor.SizeTop; break; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
868 case NonClientOps.ResizeTop | NonClientOps.ResizeLeft: e.Cursor = FBGCursor.SizeTopLeft; break; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
869 case NonClientOps.ResizeTop | NonClientOps.ResizeRight: e.Cursor = FBGCursor.SizeTopRight; break; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
870 case NonClientOps.ResizeBottom | NonClientOps.ResizeLeft: e.Cursor = FBGCursor.SizeBottomLeft; break; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
871 case NonClientOps.ResizeBottom | NonClientOps.ResizeRight: e.Cursor = FBGCursor.SizeBottomRight; break; |
30
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
872 } |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
873 } |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
874 protected override void HandlePointingEvent(FBGPointingEvent e) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
875 e.Cursor = Cursor; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
876 if (HandlePointingEventA(e)) base.HandlePointingEvent(e); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
877 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
878 Boolean HandlePointingEventA(FBGPointingEvent e) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
879 e.Cursor = Cursor; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
880 switch (e.Type) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
881 case FBGPointingEventType.Move: return MouseMove(e.Position, e.Buttons, e); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
882 case FBGPointingEventType.ButtonDown: return MouseDown(e.Position, e.Buttons, e); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
883 case FBGPointingEventType.ButtonUp: return MouseUp(e.Position, e.Buttons, e); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
884 default: return true; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
885 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
886 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
887 Boolean MouseDown(Point p, MouseButtons buttons, FBGPointingEvent e) { |
23 | 888 NonClientOps mr = 0; |
30
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
889 if ((buttons & MouseButtons.Left) != 0) mr = GetNonClientOperation(p); |
23 | 890 if (mr != 0) { |
891 moveresize = mr; | |
892 prevPosition = p; | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
893 SetCursorForNonClientOperation(moveresize, e); |
23 | 894 CaptureMouse(true); |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
895 return false; |
23 | 896 } else { |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
897 return true; |
23 | 898 } |
899 } | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
900 Boolean MouseMove(Point position, MouseButtons buttons, FBGPointingEvent e) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
901 SetCursorForNonClientOperation(moveresize == 0 ? GetNonClientOperation(position) : moveresize, e); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
902 if (moveresize == 0) return true; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
903 if ((moveresize & NonClientOps.MoveResize) != 0) { |
23 | 904 Rectangle b = Bounds; |
905 int dx = position.X - prevPosition.X; | |
906 int dy = position.Y - prevPosition.Y; | |
30
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
907 if (moveresize == NonClientOps.Move) { |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
908 b.Offset(dx, dy); |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
909 } |
23 | 910 if ((moveresize & NonClientOps.ResizeLeft) != 0) { |
911 b.X += dx; | |
912 b.Width -= dx; | |
913 } else if ((moveresize & NonClientOps.ResizeRight) != 0) { | |
914 b.Width += dx; | |
915 prevPosition.X = position.X; | |
916 } | |
917 if ((moveresize & NonClientOps.ResizeTop) != 0) { | |
918 b.Y += dy; | |
919 b.Height -= dy; | |
920 } else if ((moveresize & NonClientOps.ResizeBottom) != 0) { | |
921 b.Height += dy; | |
922 prevPosition.Y = position.Y; | |
923 } | |
924 if (b.Width < 55) b.Width = 55; | |
925 if (b.Height < 25) b.Height = 25; | |
926 Bounds = b; | |
927 } | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
928 return false; |
23 | 929 } |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
930 Boolean MouseUp(Point position, MouseButtons buttons, FBGPointingEvent e) { |
23 | 931 if (moveresize == 0) { |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
932 SetCursorForNonClientOperation(GetNonClientOperation(position), e); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
933 return true; |
23 | 934 } else if ((buttons & MouseButtons.Left) != 0) { |
935 MouseMove(position, buttons); | |
936 CaptureMouse(false); | |
937 if (moveresize == NonClientOps.ButtonClose && (new Rectangle(Bounds.Width - 5 - 14, 4, 14, 14)).Contains(position) && Closable) Close(); | |
938 moveresize = 0; | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
939 SetCursorForNonClientOperation(GetNonClientOperation(position), e); |
23 | 940 } |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
941 return false; |
23 | 942 } |
943 protected override void Paint(Graphics g) { | |
944 base.Paint(g); | |
945 g.DrawRectangle(Pens.Gray, 0, 0, Bounds.Width - 1, Bounds.Height - 1); | |
946 g.DrawRectangle(Pens.LightGray, 1, 1, Bounds.Width - 3, Bounds.Height - 3); | |
947 g.DrawRectangle(Pens.DarkGray, 2, 20, Bounds.Width - 5, Bounds.Height - 23); | |
948 g.DrawRectangle(Pens.Gray, 3, 21, Bounds.Width - 7, Bounds.Height - 25); | |
949 using (Brush b = new LinearGradientBrush(new Rectangle(0, 1, 1, 18), Color.Gray, Color.LightGray, LinearGradientMode.Vertical)) | |
950 g.FillRectangle(b, 2, 2, Bounds.Width - 4, 18); | |
951 | |
952 g.DrawString(Text, SystemFonts.CaptionFont, Brushes.Black, 4, 1); | |
953 | |
954 g.DrawRectangle(Pens.Gray, Bounds.Width - 5 - 14, 4, 14, 14); | |
955 g.DrawRectangle(Pens.Gray, Bounds.Width - 5 - 14 - 16, 4, 14, 14); | |
956 g.DrawRectangle(Pens.Gray, Bounds.Width - 5 - 14 - 32, 4, 14, 14); | |
957 using (Brush b = new LinearGradientBrush(new Rectangle(0, 5, 1, 13), Color.LightGray, Color.DarkGray, LinearGradientMode.Vertical)) { | |
958 g.FillRectangle(b, Bounds.Width - 5 - 14 + 1, 5, 13, 13); | |
959 g.FillRectangle(b, Bounds.Width - 5 - 14 + 1 - 16, 5, 13, 13); | |
960 g.FillRectangle(b, Bounds.Width - 5 - 14 + 1 - 32, 5, 13, 13); | |
961 } | |
962 if (Closable) { | |
963 g.DrawLine(Pens.Black, Bounds.Width - 5 - 14 + 3, 4 + 3, Bounds.Width - 5 - 14 + 14 - 3, 4 + 14 - 3); | |
964 g.DrawLine(Pens.Black, Bounds.Width - 5 - 14 + 3, 4 + 14 - 3, Bounds.Width - 5 - 14 + 14 - 3, 4 + 3); | |
965 } | |
966 } | |
967 public void Close() { | |
968 Parent.RemoveControl(this); | |
31 | 969 RaiseEvent(Closed); |
23 | 970 } |
971 } | |
972 public class FBGDesktop : FBGContainerControl { | |
973 FBGContainerControl windowcontainer; | |
974 FBGContainerControl menucontainer; | |
975 Boolean startup = true; | |
976 class FBGWindowState { | |
977 public IFBGControl Control; | |
978 public FBGButton MenuButton; | |
979 public Boolean Visible; | |
980 public Rectangle OldBounds; | |
981 public FBGWindowState(IFBGControl cntrl, FBGButton btn) { | |
982 Control = cntrl; | |
983 MenuButton = btn; | |
984 Visible = true; | |
985 } | |
986 } | |
987 Dictionary<IFBGControl, FBGWindowState> windowstates = new Dictionary<IFBGControl, FBGWindowState>(); | |
988 public FBGDesktop(IFBGContainerControl parent) : base(parent) { | |
989 menucontainer = new FBGContainerControl(this); | |
990 menucontainer.Bounds = new Rectangle(0, Bounds.Height - 25, Bounds.Width, 25); | |
991 windowcontainer = new FBGContainerControl(this); | |
992 windowcontainer.Bounds = new Rectangle(0, 0, Bounds.Width, Bounds.Height - 25); | |
993 startup = false; | |
994 } | |
995 public override Rectangle Bounds { | |
996 get { return base.Bounds; } | |
997 set { | |
998 if (Bounds == value) return; | |
999 base.Bounds = value; | |
1000 if (startup) return; | |
1001 menucontainer.Bounds = new Rectangle(0, value.Height - 25, value.Width, 25); | |
1002 windowcontainer.Bounds = new Rectangle(0, 0, value.Width, value.Height - 25); | |
1003 ScaleMenuButtons(); | |
1004 } | |
1005 } | |
1006 protected override void AddControl(IFBGControl control) { | |
1007 if (startup) { | |
1008 base.AddControl(control); | |
1009 return; | |
1010 } | |
1011 ((IFBGContainerControl)windowcontainer).AddControl(control); | |
1012 FBGButton btn = new FBGButton(menucontainer); | |
1013 FBGForm formcontrol = control as FBGForm; | |
1014 if (formcontrol == null) { | |
1015 btn.Text = "Untitled"; | |
1016 } else { | |
1017 formcontrol.TextChanged += delegate(Object sender, EventArgs e) { | |
1018 btn.Text = formcontrol.Text; | |
1019 }; | |
1020 btn.Text = formcontrol.Text; | |
1021 } | |
1022 FBGWindowState ws = new FBGWindowState(control, btn); | |
1023 windowstates.Add(control, ws); | |
1024 ScaleMenuButtons(); | |
1025 btn.Click += delegate(Object sender, EventArgs e) { | |
1026 if (ws.Visible) { | |
1027 if (ws.MenuButton.BackColor == Color.DarkGray) { | |
1028 ws.OldBounds = ws.Control.Bounds; | |
1029 ws.Visible = false; | |
1030 ws.Control.Bounds = Rectangle.Empty; | |
1031 } else { | |
1032 windowcontainer.BringControlToFront(ws.Control); | |
1033 foreach (FBGWindowState wsa in windowstates.Values) if (!ReferenceEquals(ws, wsa)) wsa.MenuButton.BackColor = SystemColors.ButtonFace; | |
1034 ws.MenuButton.BackColor = Color.DarkGray; | |
1035 } | |
1036 } else { | |
1037 ws.Control.Bounds = ws.OldBounds; | |
1038 ws.Visible = true; | |
1039 windowcontainer.BringControlToFront(ws.Control); | |
1040 foreach (FBGWindowState wsa in windowstates.Values) if (!ReferenceEquals(ws, wsa)) wsa.MenuButton.BackColor = SystemColors.ButtonFace; | |
1041 ws.MenuButton.BackColor = Color.DarkGray; | |
1042 } | |
1043 }; | |
1044 } | |
1045 public override void RemoveControl(IFBGControl control) { | |
1046 windowcontainer.RemoveControl(control); | |
1047 windowstates.Remove(control); | |
1048 ScaleMenuButtons(); | |
1049 } | |
1050 private void ScaleMenuButtons() { | |
1051 int bcount = windowstates.Count; | |
1052 int bwidth = 200; | |
1053 int twidth = bwidth * bcount; | |
1054 if (twidth > Bounds.Width) bwidth = menucontainer.Bounds.Width / bcount; | |
1055 int i = 0; | |
1056 foreach (FBGWindowState ws in windowstates.Values) { | |
1057 ws.MenuButton.Bounds = new Rectangle(i * bwidth, 0, bwidth, 25); | |
1058 i++; | |
1059 } | |
1060 } | |
1061 protected override void Paint(Graphics g) { | |
1062 base.Paint(g); | |
1063 g.DrawLine(Pens.Black, 0, Bounds.Height - 25, Bounds.Width, Bounds.Height - 25); | |
1064 } | |
1065 protected override void MouseDown(Point position, MouseButtons buttons) { | |
1066 IFBGControl control = FindControlAtPosition(position); | |
1067 if (ReferenceEquals(control, windowcontainer)) { | |
1068 control = windowcontainer.FindControlAtPosition(PointToChild(windowcontainer, position)); | |
1069 if (!ReferenceEquals(control, null)) { | |
1070 windowcontainer.BringControlToFront(control); | |
1071 foreach (FBGWindowState ws in windowstates.Values) | |
1072 ws.MenuButton.BackColor = ReferenceEquals(ws.Control, control) ? Color.DarkGray : SystemColors.ButtonFace; | |
1073 } | |
1074 } | |
1075 base.MouseDown(position, buttons); | |
1076 } | |
1077 } | |
1078 | |
1079 public class FBGLabel : FBGControl, IDisposable { | |
1080 public FBGLabel(IFBGContainerControl parent) : base(parent) { | |
1081 Size = new Size(200, 16); | |
1082 } | |
1083 private String text = String.Empty; | |
1084 private Font font = SystemFonts.DefaultFont; | |
1085 private Brush brush = SystemBrushes.ControlText; | |
1086 private StringFormat stringformat = new StringFormat(); | |
1087 public String Text { get { return text; } set { text = value; Invalidate(); } } | |
1088 public Font Font { get { return font; } set { font = value; Invalidate(); } } | |
1089 public Brush Brush { get { return brush; } set { brush = value; Invalidate(); } } | |
1090 public Color Color { set { Brush = new SolidBrush(value); } } | |
1091 public StringAlignment Alignment { get { return stringformat.Alignment; } set { stringformat.Alignment = value; Invalidate(); } } | |
1092 public StringFormatFlags FormatFlags { get { return stringformat.FormatFlags; } set { stringformat.FormatFlags = value; Invalidate(); } } | |
1093 public StringAlignment LineAlignment { get { return stringformat.LineAlignment; } set { stringformat.LineAlignment = value; Invalidate(); } } | |
1094 public StringTrimming Trimming { get { return stringformat.Trimming; } set { stringformat.Trimming = value; Invalidate(); } } | |
1095 protected override void Paint(Graphics g) { | |
1096 base.Paint(g); | |
1097 g.DrawString(text, font, brush, new Rectangle(Point.Empty, Bounds.Size), stringformat); | |
1098 } | |
1099 public void Dispose() { | |
1100 stringformat.Dispose(); | |
1101 } | |
1102 protected override void Orphaned() { | |
1103 base.Orphaned(); | |
1104 Dispose(); | |
1105 } | |
1106 } | |
1107 public class FBGTextBox : FBGControl { | |
1108 public FBGTextBox(IFBGContainerControl parent) : base(parent) { | |
1109 BackColor = Color.White; | |
1110 Size = new Size(200, 20); | |
1111 } | |
1112 private String text = String.Empty; | |
1113 private Char passwordChar = (Char)0; | |
1114 private Font font = new Font(FontFamily.GenericMonospace, 10); | |
1115 private Brush brush = SystemBrushes.ControlText; | |
1116 private Boolean hasKeyboardFocus = false; | |
1117 public String Text { get { return text; } set { text = value; if (CaretPosition > text.Length) CaretPosition = text.Length; Invalidate(); RaiseEvent(TextChanged); } } | |
1118 public Font Font { get { return font; } set { font = value; Invalidate(); } } | |
1119 public Brush Brush { get { return brush; } set { brush = value; Invalidate(); } } | |
1120 public Color Color { set { Brush = new SolidBrush(value); } } | |
1121 public Int32 CaretPosition { get; private set; } | |
1122 public Char PasswordChar { get { return passwordChar; } set { passwordChar = value; Invalidate(); } } | |
1123 public event EventHandler TextChanged; | |
1124 public event KeyPressEventHandler OnKeyPress; | |
1125 protected override void Paint(Graphics g) { | |
1126 base.Paint(g); | |
1127 g.DrawRectangle(Pens.Gray, 0, 0, Bounds.Width - 1, Bounds.Height - 1); | |
1128 using (StringFormat sf_nonprinting = new StringFormat(StringFormat.GenericTypographic)) { | |
1129 sf_nonprinting.Trimming = StringTrimming.None; | |
1130 sf_nonprinting.FormatFlags = StringFormatFlags.DisplayFormatControl | StringFormatFlags.MeasureTrailingSpaces; | |
1131 sf_nonprinting.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.None; | |
1132 | |
1133 float x = 1; | |
1134 float y = 1; | |
1135 float w = Width - 2; | |
1136 if (hasKeyboardFocus && CaretPosition == 0) { | |
1137 g.DrawLine(Pens.Black, x + 2, 2, x + 2, Height - 4); | |
1138 } | |
1139 String c = passwordChar == 0 ? null : new String(passwordChar, 1); | |
1140 for (int i = 0; i < text.Length; i++) { | |
1141 if (passwordChar == 0) c = text.Substring(i, 1); | |
1142 SizeF s = g.MeasureString(c, font, (int)Math.Ceiling(w), sf_nonprinting); | |
1143 g.DrawString(c, font, brush, x, y); | |
1144 x += (float)Math.Ceiling(s.Width); | |
1145 w -= (float)Math.Ceiling(s.Width); | |
1146 | |
1147 if (hasKeyboardFocus && i == CaretPosition - 1) { | |
1148 g.DrawLine(Pens.Black, x + 2, 2, x + 2, Height - 4); | |
1149 } | |
1150 } | |
1151 } | |
1152 } | |
1153 protected override void MouseDown(Point position, MouseButtons buttons) { | |
1154 hasKeyboardFocus = CaptureKeyboard(true); | |
1155 CaretPosition = text.Length; | |
1156 float x = 1; | |
1157 String c = passwordChar == 0 ? null : new String(passwordChar, 1); | |
1158 for (int i = 0; i < text.Length; i++) { | |
1159 if (passwordChar == 0) c = text.Substring(i, 1); | |
1160 Size s; | |
1161 try { | |
1162 s = TextRenderer.MeasureText(c, font, Size.Empty, TextFormatFlags.NoPadding | TextFormatFlags.NoPrefix); | |
1163 } catch (Exception) { | |
1164 break; | |
1165 } | |
1166 x += s.Width; | |
1167 if (position.X < x) { | |
1168 CaretPosition = i; | |
1169 break; | |
1170 } | |
1171 } | |
1172 Invalidate(); | |
1173 } | |
1174 protected override void KeyDown(Keys key) { | |
1175 if ((key & Keys.KeyCode) == Keys.Left) { | |
1176 CaretPosition--; | |
1177 if (CaretPosition < 0) CaretPosition = 0; | |
1178 Invalidate(); | |
1179 } else if ((key & Keys.KeyCode) == Keys.Right) { | |
1180 CaretPosition++; | |
1181 if (CaretPosition > text.Length) CaretPosition = text.Length; | |
1182 Invalidate(); | |
1183 } else if ((key & Keys.KeyCode) == Keys.Home) { | |
1184 CaretPosition = 0; | |
1185 Invalidate(); | |
1186 } else if ((key & Keys.KeyCode) == Keys.End) { | |
1187 CaretPosition = text.Length; | |
1188 Invalidate(); | |
1189 } else if ((key & Keys.Control) != 0 && (key & Keys.KeyCode) == Keys.V) { | |
1190 String cbtext = Clipboard.GetText(TextDataFormat.UnicodeText); | |
1191 CaretPosition += cbtext.Length; | |
1192 Text = Text.Insert(CaretPosition - cbtext.Length, cbtext); | |
1193 } | |
1194 } | |
1195 protected override void KeyPress(char keyChar) { | |
1196 KeyPressEventArgs e = new KeyPressEventArgs(keyChar); | |
1197 RaiseEvent(OnKeyPress, e); | |
1198 if (e.Handled) return; | |
1199 hasKeyboardFocus = true; | |
1200 if (keyChar == 8) { | |
1201 if (CaretPosition > 0) { | |
1202 CaretPosition--; | |
1203 Text = Text.Remove(CaretPosition, 1); | |
1204 } | |
1205 } else if (keyChar == 127) { | |
1206 if (CaretPosition < Text.Length) { | |
1207 Text = Text.Remove(CaretPosition, 1); | |
1208 } | |
1209 } else if (keyChar < 32) { | |
1210 } else { | |
1211 CaretPosition++; | |
1212 Text = Text.Insert(CaretPosition - 1, new String(keyChar, 1)); | |
1213 } | |
1214 } | |
1215 public void Focus() { | |
1216 hasKeyboardFocus = CaptureKeyboard(true); | |
1217 } | |
1218 protected override void LostKeyboardCapture() { | |
1219 base.LostKeyboardCapture(); | |
1220 hasKeyboardFocus = false; | |
1221 Invalidate(); | |
1222 } | |
1223 } | |
1224 public class FBGButton : FBGControl { | |
1225 public FBGButton(IFBGContainerControl parent) : base(parent) { | |
1226 BackColor = SystemColors.ButtonFace; | |
1227 } | |
1228 private String text = String.Empty; | |
1229 private Font font = SystemFonts.DefaultFont; | |
1230 private Color color = SystemColors.ControlText; | |
1231 private Boolean pressed = false; | |
1232 private Boolean enabled = true; | |
1233 public String Text { get { return text; } set { text = value; Invalidate(); } } | |
1234 public Font Font { get { return font; } set { font = value; Invalidate(); } } | |
1235 public Color Color { get { return color; } set { color = value; Invalidate(); } } | |
1236 public Boolean Enabled { get { return enabled; } set { enabled = value; Invalidate(); } } | |
1237 public event EventHandler Click; | |
1238 protected override void Paint(Graphics g) { | |
1239 base.Paint(g); | |
1240 if (Bounds.Width == 0 || Bounds.Height == 0) return; | |
1241 if (BackColor == SystemColors.ButtonFace) { | |
1242 ControlPaint.DrawButton(g, new Rectangle(0, 0, Bounds.Width, Bounds.Height), enabled ? (pressed ? ButtonState.Pushed : ButtonState.Normal) : ButtonState.Inactive); | |
1243 } else { | |
1244 //Hackish and not completely right... | |
1245 //Todo: borrowed from mono... possible licencing issues!? | |
1246 g.DrawLine(new Pen(ControlPaint.LightLight(BackColor)), 0, 0, Bounds.Width, 0); | |
1247 g.DrawLine(new Pen(ControlPaint.LightLight(BackColor)), 0, 0, 0, Bounds.Height); | |
1248 g.DrawLine(new Pen(ControlPaint.Dark(BackColor)), 1, Bounds.Height - 2, Bounds.Width - 1, Bounds.Height - 2); | |
1249 g.DrawLine(new Pen(ControlPaint.Dark(BackColor)), Bounds.Width - 2, 1, Bounds.Width - 2, Bounds.Height - 2); | |
1250 g.DrawLine(new Pen(ControlPaint.DarkDark(BackColor)), 0, Bounds.Height - 1, Bounds.Width, Bounds.Height - 1); | |
1251 g.DrawLine(new Pen(ControlPaint.DarkDark(BackColor)), Bounds.Width - 1, 1, Bounds.Width - 1, Bounds.Height - 1); | |
1252 Graphics dc = g; | |
1253 Rectangle rectangle = new Rectangle(0, 0, Bounds.Width - 1, Bounds.Height - 1); | |
1254 Color ColorControl = BackColor; | |
1255 Color ColorControlLight = ControlPaint.Light(ColorControl); | |
1256 ButtonState state = pressed ? ButtonState.Pushed : ButtonState.Normal; | |
1257 using (Pen NormalPen = new Pen(BackColor), LightPen = new Pen(ControlPaint.Light(BackColor)), DarkPen = new Pen(ControlPaint.Dark(BackColor))) { | |
1258 // sadly enough, the rectangle gets always filled with a hatchbrush | |
1259 using (HatchBrush hb = new HatchBrush(HatchStyle.Percent50, Color.FromArgb(Math.Min(255, ColorControl.R + 3), ColorControl.G, ColorControl.B), ColorControl)) { | |
1260 dc.FillRectangle(hb, rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2); | |
1261 } | |
1262 if ((state & ButtonState.All) == ButtonState.All || ((state & ButtonState.Checked) == ButtonState.Checked && (state & ButtonState.Flat) == ButtonState.Flat)) { | |
1263 using (HatchBrush hb = new HatchBrush(HatchStyle.Percent50, ColorControlLight, ColorControl)) { | |
1264 dc.FillRectangle(hb, rectangle.X + 2, rectangle.Y + 2, rectangle.Width - 4, rectangle.Height - 4); | |
1265 } | |
1266 dc.DrawRectangle(SystemPens.ControlDark, rectangle.X, rectangle.Y, rectangle.Width - 1, rectangle.Height - 1); | |
1267 } else if ((state & ButtonState.Flat) == ButtonState.Flat) { | |
1268 dc.DrawRectangle(SystemPens.ControlDark, rectangle.X, rectangle.Y, rectangle.Width - 1, rectangle.Height - 1); | |
1269 } else if ((state & ButtonState.Checked) == ButtonState.Checked) { | |
1270 using (HatchBrush hb = new HatchBrush(HatchStyle.Percent50, ColorControlLight, ColorControl)) { | |
1271 dc.FillRectangle(hb, rectangle.X + 2, rectangle.Y + 2, rectangle.Width - 4, rectangle.Height - 4); | |
1272 } | |
1273 Pen pen = DarkPen; | |
1274 dc.DrawLine(pen, rectangle.X, rectangle.Y, rectangle.X, rectangle.Bottom - 2); | |
1275 dc.DrawLine(pen, rectangle.X + 1, rectangle.Y, rectangle.Right - 2, rectangle.Y); | |
1276 | |
1277 pen = NormalPen; | |
1278 dc.DrawLine(pen, rectangle.X + 1, rectangle.Y + 1, rectangle.X + 1, rectangle.Bottom - 3); | |
1279 dc.DrawLine(pen, rectangle.X + 2, rectangle.Y + 1, rectangle.Right - 3, rectangle.Y + 1); | |
1280 | |
1281 pen = LightPen; | |
1282 dc.DrawLine(pen, rectangle.X, rectangle.Bottom - 1, rectangle.Right - 2, rectangle.Bottom - 1); | |
1283 dc.DrawLine(pen, rectangle.Right - 1, rectangle.Y, rectangle.Right - 1, rectangle.Bottom - 1); | |
1284 } else if (((state & ButtonState.Pushed) == ButtonState.Pushed) && ((state & ButtonState.Normal) == ButtonState.Normal)) { | |
1285 Pen pen = DarkPen; | |
1286 dc.DrawLine(pen, rectangle.X, rectangle.Y, rectangle.X, rectangle.Bottom - 2); | |
1287 dc.DrawLine(pen, rectangle.X + 1, rectangle.Y, rectangle.Right - 2, rectangle.Y); | |
1288 | |
1289 pen = NormalPen; | |
1290 dc.DrawLine(pen, rectangle.X + 1, rectangle.Y + 1, rectangle.X + 1, rectangle.Bottom - 3); | |
1291 dc.DrawLine(pen, rectangle.X + 2, rectangle.Y + 1, rectangle.Right - 3, rectangle.Y + 1); | |
1292 | |
1293 pen = LightPen; | |
1294 dc.DrawLine(pen, rectangle.X, rectangle.Bottom - 1, rectangle.Right - 2, rectangle.Bottom - 1); | |
1295 dc.DrawLine(pen, rectangle.Right - 1, rectangle.Y, rectangle.Right - 1, rectangle.Bottom - 1); | |
1296 } else if (((state & ButtonState.Inactive) == ButtonState.Inactive) || ((state & ButtonState.Normal) == ButtonState.Normal)) { | |
1297 Pen pen = LightPen; | |
1298 dc.DrawLine(pen, rectangle.X, rectangle.Y, rectangle.Right - 2, rectangle.Y); | |
1299 dc.DrawLine(pen, rectangle.X, rectangle.Y, rectangle.X, rectangle.Bottom - 2); | |
1300 | |
1301 pen = NormalPen; | |
1302 dc.DrawLine(pen, rectangle.X + 1, rectangle.Bottom - 2, rectangle.Right - 2, rectangle.Bottom - 2); | |
1303 dc.DrawLine(pen, rectangle.Right - 2, rectangle.Y + 1, rectangle.Right - 2, rectangle.Bottom - 3); | |
1304 | |
1305 pen = DarkPen; | |
1306 dc.DrawLine(pen, rectangle.X, rectangle.Bottom - 1, rectangle.Right - 1, rectangle.Bottom - 1); | |
1307 dc.DrawLine(pen, rectangle.Right - 1, rectangle.Y, rectangle.Right - 1, rectangle.Bottom - 2); | |
1308 } | |
1309 } | |
1310 } | |
1311 Rectangle frect = new Rectangle(Point.Empty, Bounds.Size); | |
1312 SizeF textsize = g.MeasureString(Text, Font); | |
1313 using (Brush b = new SolidBrush(enabled ? Color : Color.DarkGray)) { | |
1314 g.DrawString(Text, Font, b, new PointF(Bounds.Width / 2.0f - textsize.Width / 2.0f, Bounds.Height / 2.0f - textsize.Height / 2.0f)); | |
1315 } | |
1316 } | |
1317 protected override void MouseDown(Point position, MouseButtons buttons) { | |
1318 pressed = true; | |
1319 Invalidate(); | |
1320 CaptureMouse(true); | |
1321 base.MouseDown(position, buttons); | |
1322 } | |
1323 protected override void MouseUp(Point position, MouseButtons buttons) { | |
1324 pressed = false; | |
1325 Invalidate(); | |
1326 CaptureMouse(false); | |
1327 if (position.X >= 0 && position.X <= Bounds.Width && position.Y >= 0 && position.Y <= Bounds.Height && enabled) RaiseEvent(Click); | |
1328 base.MouseUp(position, buttons); | |
1329 } | |
1330 protected override void KeyDown(Keys key) { | |
1331 if (key == Keys.Return || key == Keys.Space) { | |
1332 pressed = true; | |
1333 Invalidate(); | |
1334 } | |
1335 base.KeyDown(key); | |
1336 } | |
1337 protected override void KeyUp(Keys key) { | |
1338 if (key == Keys.Return || key == Keys.Space) { | |
1339 if (pressed) RaiseEvent(Click); | |
1340 pressed = false; | |
1341 Invalidate(); | |
1342 } | |
1343 base.KeyUp(key); | |
1344 } | |
1345 public void Focus() { | |
1346 CaptureKeyboard(true); | |
1347 } | |
1348 } | |
1349 public class FBGCheckBox : FBGControl { | |
1350 public FBGCheckBox(IFBGContainerControl parent) : base(parent) { } | |
1351 private String text = String.Empty; | |
1352 private Font font = SystemFonts.DefaultFont; | |
1353 private Color color = SystemColors.ControlText; | |
1354 private Boolean _checked = false; | |
1355 public String Text { get { return text; } set { text = value; Invalidate(); } } | |
1356 public Font Font { get { return font; } set { font = value; Invalidate(); } } | |
1357 public Color Color { get { return color; } set { color = value; Invalidate(); } } | |
1358 public Boolean Checked { get { return _checked; } set { _checked = value; Invalidate(); } } | |
1359 public event EventHandler CheckedChanged; | |
1360 protected override void Paint(Graphics g) { | |
1361 base.Paint(g); | |
1362 ControlPaint.DrawCheckBox(g, 0, 0, 13, 13, _checked ? ButtonState.Checked : ButtonState.Normal); | |
1363 g.DrawString(Text, Font, new SolidBrush(Color), 15, 0); | |
1364 } | |
1365 protected override void MouseDown(Point position, MouseButtons buttons) { | |
1366 Checked = !Checked; | |
1367 RaiseEvent(CheckedChanged); | |
1368 base.MouseDown(position, buttons); | |
1369 } | |
1370 } | |
1371 public class FBGImageBox : FBGControl { | |
1372 Image image = null; | |
33 | 1373 Image scaledImage = null; |
1374 Size imageSize; | |
1375 Boolean ownsImage = false; | |
34
70bde4fa6a2f
FBGUI: Fixed image scaling in FBGImageBox
Ivo Smits <Ivo@UCIS.nl>
parents:
33
diff
changeset
|
1376 Boolean shouldScaleImage = false; |
23 | 1377 PictureBoxSizeMode sizeMode = PictureBoxSizeMode.Normal; |
1378 Rectangle imageRect; | |
33 | 1379 public Image Image { get { return image; } set { SetImage(value, false); } } |
1380 public Boolean PreScaleImage { get; set; } | |
1381 public void SetOwnedImage(Image img) { SetImage(img, true); } | |
1382 private void SetImage(Image img, Boolean owned) { | |
1383 image = img; | |
1384 imageSize = img == null ? Size.Empty : img.Size; | |
1385 ownsImage = owned; | |
1386 UpdateImageRect(Size.Empty); | |
1387 } | |
23 | 1388 public FBGImageBox(IFBGContainerControl parent) : base(parent) { } |
30
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
1389 public PictureBoxSizeMode SizeMode { get { return sizeMode; } set { sizeMode = value; UpdateImageRect(Size.Empty); } } |
23 | 1390 public override Rectangle Bounds { |
1391 get { | |
1392 return base.Bounds; | |
1393 } | |
1394 set { | |
33 | 1395 if (Bounds.Size != value.Size) UpdateImageRect(value.Size); |
23 | 1396 base.Bounds = value; |
1397 } | |
1398 } | |
30
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
1399 private void UpdateImageRect(Size csize) { |
34
70bde4fa6a2f
FBGUI: Fixed image scaling in FBGImageBox
Ivo Smits <Ivo@UCIS.nl>
parents:
33
diff
changeset
|
1400 shouldScaleImage = false; |
70bde4fa6a2f
FBGUI: Fixed image scaling in FBGImageBox
Ivo Smits <Ivo@UCIS.nl>
parents:
33
diff
changeset
|
1401 if (scaledImage != null) scaledImage.Dispose(); |
33 | 1402 scaledImage = null; |
23 | 1403 if (image == null) return; |
30
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
1404 Boolean boundsset = !csize.IsEmpty; |
23 | 1405 if (!boundsset && sizeMode == PictureBoxSizeMode.AutoSize) { |
33 | 1406 Size = imageSize; |
23 | 1407 return; |
1408 } | |
30
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
1409 if (!boundsset) csize = Bounds.Size; |
23 | 1410 switch (sizeMode) { |
1411 case PictureBoxSizeMode.AutoSize: | |
1412 case PictureBoxSizeMode.Normal: | |
33 | 1413 imageRect = new Rectangle(Point.Empty, imageSize); |
23 | 1414 break; |
1415 case PictureBoxSizeMode.CenterImage: | |
33 | 1416 imageRect = new Rectangle(csize.Width / 2 - imageSize.Width / 2, csize.Height / 2 - imageSize.Height / 2, imageSize.Width, imageSize.Height); |
23 | 1417 break; |
1418 case PictureBoxSizeMode.StretchImage: | |
30
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
1419 imageRect = new Rectangle(Point.Empty, csize); |
23 | 1420 break; |
1421 case PictureBoxSizeMode.Zoom: | |
33 | 1422 float xrat = (float)csize.Width / (float)imageSize.Width; |
1423 float yrat = (float)csize.Height / (float)imageSize.Height; | |
23 | 1424 float rat = Math.Min(xrat, yrat); |
33 | 1425 SizeF dispsize = new SizeF(imageSize.Width * rat, imageSize.Height * rat); |
30
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
1426 imageRect = Rectangle.Round(new RectangleF(csize.Width / 2f - dispsize.Width / 2f, csize.Height / 2f - dispsize.Height / 2f, dispsize.Width, dispsize.Height)); |
23 | 1427 break; |
1428 } | |
34
70bde4fa6a2f
FBGUI: Fixed image scaling in FBGImageBox
Ivo Smits <Ivo@UCIS.nl>
parents:
33
diff
changeset
|
1429 shouldScaleImage = imageRect.Size != imageSize; |
23 | 1430 if (!boundsset) Invalidate(); |
1431 } | |
1432 protected override void Paint(Graphics g) { | |
1433 if (!Visible) return; | |
1434 base.Paint(g); | |
34
70bde4fa6a2f
FBGUI: Fixed image scaling in FBGImageBox
Ivo Smits <Ivo@UCIS.nl>
parents:
33
diff
changeset
|
1435 if (shouldScaleImage && PreScaleImage && image != null) { |
70bde4fa6a2f
FBGUI: Fixed image scaling in FBGImageBox
Ivo Smits <Ivo@UCIS.nl>
parents:
33
diff
changeset
|
1436 scaledImage = new Bitmap(image, imageRect.Size); |
70bde4fa6a2f
FBGUI: Fixed image scaling in FBGImageBox
Ivo Smits <Ivo@UCIS.nl>
parents:
33
diff
changeset
|
1437 shouldScaleImage = false; |
70bde4fa6a2f
FBGUI: Fixed image scaling in FBGImageBox
Ivo Smits <Ivo@UCIS.nl>
parents:
33
diff
changeset
|
1438 } |
70bde4fa6a2f
FBGUI: Fixed image scaling in FBGImageBox
Ivo Smits <Ivo@UCIS.nl>
parents:
33
diff
changeset
|
1439 if (scaledImage != null) g.DrawImage(scaledImage, imageRect); |
70bde4fa6a2f
FBGUI: Fixed image scaling in FBGImageBox
Ivo Smits <Ivo@UCIS.nl>
parents:
33
diff
changeset
|
1440 else if (image != null) g.DrawImage(image, imageRect); |
23 | 1441 } |
30
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
1442 public Point PointToImage(Point point) { |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
1443 switch (sizeMode) { |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
1444 case PictureBoxSizeMode.AutoSize: |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
1445 case PictureBoxSizeMode.Normal: |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
1446 break; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
1447 case PictureBoxSizeMode.CenterImage: |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
1448 point.X -= imageRect.X; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
1449 point.Y -= imageRect.Y; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
1450 break; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
1451 case PictureBoxSizeMode.StretchImage: |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
1452 case PictureBoxSizeMode.Zoom: |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
1453 default: |
33 | 1454 point.X = (point.X - imageRect.X) * imageSize.Width / imageRect.Width; |
1455 point.Y = (point.Y - imageRect.Y) * imageSize.Height / imageRect.Height; | |
30
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
1456 break; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
1457 } |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
1458 return point; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
1459 } |
33 | 1460 protected override void Orphaned() { |
1461 base.Orphaned(); | |
1462 if (scaledImage != null && scaledImage != image) scaledImage.Dispose(); | |
1463 scaledImage = null; | |
1464 if (ownsImage) { | |
1465 image.Dispose(); | |
1466 image = null; | |
1467 } | |
1468 } | |
23 | 1469 } |
1470 public class FBGListBox : FBGControl { | |
1471 private List<Object> items = new List<object>(); | |
1472 private Object selected = null; | |
1473 private Object highlighted = null; | |
1474 private Boolean hasScrollBar = false; | |
1475 private Boolean hitScrollBar = false; | |
1476 private int offset = 0; | |
1477 private ButtonState buttonUpState = ButtonState.Normal; | |
1478 private ButtonState buttonDownState = ButtonState.Normal; | |
1479 private Converter<Object, String> itemFormatter = null; | |
1480 public Converter<Object, String> ItemFormatter { get { return itemFormatter; } set { itemFormatter = value; Invalidate(); } } | |
1481 public FBGListBox(IFBGContainerControl parent) | |
1482 : base(parent) { | |
1483 BackColor = Color.White; | |
1484 } | |
1485 public void AddItem(Object item) { | |
1486 items.Add(item); | |
1487 Invalidate(); | |
1488 } | |
1489 protected override void Paint(Graphics g) { | |
1490 base.Paint(g); | |
1491 g.DrawRectangle(Pens.DarkBlue, 0, 0, Bounds.Width - 1, Bounds.Height - 1); | |
1492 int lh = (int)Math.Ceiling(SystemFonts.DefaultFont.GetHeight()); | |
1493 int th = lh * items.Count; | |
1494 int y = 2; | |
1495 using (Pen dottedpen = new Pen(Brushes.Black)) { | |
1496 dottedpen.DashStyle = DashStyle.Dot; | |
1497 using (StringFormat sf = new StringFormat(StringFormatFlags.NoWrap)) { | |
1498 for (int i = offset; i < items.Count; i++) { | |
1499 Object item = items[i]; | |
1500 String text = itemFormatter == null ? (item == null ? String.Empty : item.ToString()) : itemFormatter(item); | |
1501 if (item == selected) g.FillRectangle(Brushes.DarkGray, 2, y, Bounds.Width - 4, lh); | |
1502 if (item == highlighted) g.DrawRectangle(dottedpen, 2, y, Bounds.Width - 5, lh - 1); | |
1503 g.DrawString(text, SystemFonts.DefaultFont, SystemBrushes.WindowText, new Rectangle(3, y, Bounds.Width - 6, lh), sf); | |
1504 y += lh; | |
1505 if (y + lh + 2 >= Bounds.Height) break; | |
1506 } | |
1507 } | |
1508 } | |
1509 if (y < th) hasScrollBar = true; | |
1510 if (hasScrollBar) { | |
1511 int xoff = Bounds.Width - 17; | |
1512 using (Brush b = new LinearGradientBrush(new Rectangle(xoff, 0, 17, 1), Color.LightGray, Color.White, LinearGradientMode.Horizontal)) | |
1513 g.FillRectangle(b, xoff, 17, 16, Bounds.Height - 17 - 17); | |
1514 ControlPaint.DrawScrollButton(g, xoff, 1, 16, 16, ScrollButton.Up, buttonUpState); | |
1515 ControlPaint.DrawScrollButton(g, xoff, Bounds.Height - 17, 16, 16, ScrollButton.Down, buttonDownState); | |
1516 g.DrawRectangle(Pens.Black, new Rectangle(xoff, 17 + offset * (Bounds.Height - 17 - 17 - 20) / (items.Count - 1), 15, 20)); | |
1517 } | |
1518 } | |
1519 protected override void MouseDown(Point position, MouseButtons buttons) { | |
1520 if ((buttons & MouseButtons.Left) != 0) { | |
1521 CaptureMouse(true); | |
1522 if (hasScrollBar && position.X > Bounds.Width - 17) { | |
1523 hitScrollBar = true; | |
1524 if (position.Y < 17) { | |
1525 offset--; | |
1526 buttonUpState = ButtonState.Pushed; | |
1527 } else if (position.Y > Bounds.Height - 17) { | |
1528 offset++; | |
1529 buttonDownState = ButtonState.Pushed; | |
1530 } else { | |
1531 offset = (int)Math.Round((position.Y - 17) * (items.Count - 1) / (double)(Bounds.Height - 17 - 17 - 10)); | |
1532 } | |
1533 if (offset < 0) offset = 0; | |
1534 if (offset >= items.Count) offset = items.Count - 1; | |
1535 Invalidate(); | |
1536 } else { | |
1537 MouseHandler(position, buttons); | |
1538 } | |
1539 } | |
1540 } | |
1541 protected override void MouseMove(Point position, MouseButtons buttons) { | |
1542 if (hitScrollBar) { | |
1543 if (position.Y < 17) { | |
1544 } else if (position.Y > Bounds.Height - 17) { | |
1545 } else { | |
1546 offset = (int)Math.Round((position.Y - 17) * (items.Count - 1) / (double)(Bounds.Height - 17 - 17 - 10)); | |
1547 if (offset < 0) offset = 0; | |
1548 if (offset >= items.Count) offset = items.Count - 1; | |
1549 Invalidate(); | |
1550 } | |
1551 return; | |
1552 } | |
1553 MouseHandler(position, buttons); | |
1554 } | |
1555 protected override void MouseUp(Point position, MouseButtons buttons) { | |
1556 if ((buttons & MouseButtons.Left) != 0) { | |
1557 CaptureMouse(false); | |
1558 buttonUpState = buttonDownState = ButtonState.Normal; | |
1559 Invalidate(); | |
1560 if (hitScrollBar) { | |
1561 hitScrollBar = false; | |
1562 return; | |
1563 } | |
1564 } | |
1565 if (hitScrollBar) return; | |
1566 MouseHandler(position, buttons); | |
1567 } | |
1568 private void MouseHandler(Point position, MouseButtons buttons) { | |
1569 if ((buttons & MouseButtons.Left) != 0) { | |
1570 int lh = (int)Math.Ceiling(SystemFonts.DefaultFont.GetHeight()); | |
1571 int i = (position.Y - 2) / lh + offset; | |
1572 if (i < 0) i = 0; | |
1573 if (i >= items.Count) i = items.Count - 1; | |
1574 Boolean changed = false; | |
1575 Object current = items[i]; | |
1576 if (!ReferenceEquals(highlighted, current)) changed = true; | |
1577 highlighted = current; | |
1578 if ((new Rectangle(Point.Empty, Bounds.Size)).Contains(position)) { | |
1579 if (!ReferenceEquals(selected, current)) changed = true; | |
1580 selected = current; | |
1581 } | |
1582 if (changed) Invalidate(); | |
1583 } | |
1584 } | |
1585 } | |
27
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1586 public abstract class FBGUpDownControlBase : FBGControl { |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1587 private ButtonState buttonUpState = ButtonState.Normal; |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1588 private ButtonState buttonDownState = ButtonState.Normal; |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1589 public FBGUpDownControlBase(IFBGContainerControl parent) : base(parent) { |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1590 BackColor = Color.White; |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1591 Height = 25; |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1592 } |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1593 protected override void Paint(Graphics g) { |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1594 base.Paint(g); |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1595 g.DrawRectangle(Pens.DarkBlue, 0, 0, Bounds.Width - 1, Bounds.Height - 1); |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1596 int lh = (int)Math.Ceiling(SystemFonts.DefaultFont.GetHeight()); |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1597 String text = SelectedText; |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1598 if (text == null) { |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1599 g.FillRectangle(Brushes.DarkGray, 2, 2, Bounds.Width - 4 - 16, Bounds.Height - 4); |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1600 } else { |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1601 using (StringFormat sf = new StringFormat(StringFormatFlags.NoWrap)) { |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1602 sf.LineAlignment = StringAlignment.Center; |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1603 g.FillRectangle(Brushes.LightGray, 2, 2, Bounds.Width - 4 - 16, Bounds.Height - 4); |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1604 g.DrawString(text, SystemFonts.DefaultFont, SystemBrushes.WindowText, new Rectangle(3, 2, Bounds.Width - 6 - 16, Bounds.Height - 4), sf); |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1605 } |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1606 } |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1607 int xoff = Bounds.Width - 17; |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1608 int he = (Bounds.Height - 2) / 2; |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1609 ControlPaint.DrawScrollButton(g, xoff, 1, 16, he, ScrollButton.Up, buttonUpState); |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1610 ControlPaint.DrawScrollButton(g, xoff, Bounds.Height - he - 1, 16, he, ScrollButton.Down, buttonDownState); |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1611 } |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1612 protected abstract String SelectedText { get; } |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1613 protected override void MouseDown(Point position, MouseButtons buttons) { |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1614 CaptureKeyboard(true); |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1615 if ((buttons & MouseButtons.Left) != 0) { |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1616 CaptureMouse(true); |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1617 if (position.X > Bounds.Width - 17) { |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1618 if (position.Y < Bounds.Height / 2) { |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1619 buttonUpState = ButtonState.Pushed; |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1620 ButtonPressUp(); |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1621 } else { |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1622 buttonDownState = ButtonState.Pushed; |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1623 ButtonPressDown(); |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1624 } |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1625 Invalidate(new Rectangle(Bounds.Width - 16, 0, 16, Bounds.Height)); |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1626 } |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1627 } |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1628 } |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1629 protected override void MouseUp(Point position, MouseButtons buttons) { |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1630 if ((buttons & MouseButtons.Left) != 0) { |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1631 CaptureMouse(false); |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1632 buttonUpState = buttonDownState = ButtonState.Normal; |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1633 Invalidate(new Rectangle(Bounds.Width - 16, 0, 16, Bounds.Height)); |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1634 } |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1635 } |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1636 protected override void KeyDown(Keys key) { |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1637 base.KeyDown(key); |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1638 if (key == Keys.Down) ButtonPressDown(); |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1639 else if (key == Keys.Up) ButtonPressUp(); |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1640 } |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1641 protected abstract void ButtonPressUp(); |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1642 protected abstract void ButtonPressDown(); |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1643 } |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1644 public class FBGDomainUpDown : FBGUpDownControlBase { |
23 | 1645 private List<Object> items = new List<object>(); |
1646 private int selectedIndex = -1; | |
1647 private Converter<Object, String> itemFormatter = null; | |
1648 public Boolean AllowSelectEmpty { get; set; } | |
1649 public Converter<Object, String> ItemFormatter { get { return itemFormatter; } set { itemFormatter = value; Invalidate(); } } | |
1650 public event EventHandler SelectedIndexChanged; | |
27
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1651 public FBGDomainUpDown(IFBGContainerControl parent) : base(parent) { } |
23 | 1652 public void AddItem(Object item) { |
1653 items.Add(item); | |
1654 Invalidate(); | |
1655 } | |
1656 public void RemoveItem(Object item) { | |
1657 items.Remove(item); | |
1658 FixSelectedIndex(0); | |
1659 } | |
1660 public void RemoveItem(int index) { | |
1661 items.RemoveAt(index); | |
1662 FixSelectedIndex(0); | |
1663 } | |
1664 public int SelectedIndex { | |
1665 get { return selectedIndex; } | |
1666 set { | |
1667 if (value < -2 || value >= items.Count) throw new ArgumentOutOfRangeException("value", "Value must be between -1 and the number of items minus one"); | |
1668 if (selectedIndex == value) return; | |
1669 selectedIndex = value; | |
1670 Invalidate(); | |
1671 RaiseEvent(SelectedIndexChanged); | |
1672 } | |
1673 } | |
1674 public Object SelectedItem { | |
1675 get { return selectedIndex == -1 ? null : items[selectedIndex]; } | |
1676 set { | |
1677 if (value == null) { | |
1678 SelectedIndex = -1; | |
1679 } else { | |
1680 for (int i = 0; i < items.Count; i++) { | |
1681 if (items[i] == value) { | |
1682 SelectedIndex = i; | |
1683 break; | |
1684 } | |
1685 } | |
1686 } | |
1687 } | |
1688 } | |
27
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1689 protected override string SelectedText { |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1690 get { |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1691 if (selectedIndex == -1) return null; |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1692 Object item = items[selectedIndex]; |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1693 if (itemFormatter != null) return itemFormatter(item); |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1694 if (item == null) return null; |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1695 return item.ToString(); |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1696 } |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1697 } |
23 | 1698 private void FixSelectedIndex(int change) { |
1699 int value = selectedIndex; | |
1700 if (value == 0 && change == -1 && !AllowSelectEmpty) change = 0; | |
1701 value += change; | |
1702 if (value < -1) value = -1; | |
1703 if (value >= items.Count) value = items.Count - 1; | |
1704 SelectedIndex = value; | |
1705 } | |
27
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1706 protected override void ButtonPressDown() { |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1707 FixSelectedIndex(1); |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1708 } |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1709 protected override void ButtonPressUp() { |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1710 FixSelectedIndex(-1); |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1711 } |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1712 } |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1713 public class FBGNumericUpDown : FBGUpDownControlBase { |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1714 private int minimum = 0; |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1715 private int maximum = 0; |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1716 private int value = 0; |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1717 public event EventHandler SelectedValueChanged; |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1718 public FBGNumericUpDown(IFBGContainerControl parent) : base(parent) { } |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1719 public int Value { |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1720 get { return value; } |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1721 set { if (this.value == value) return; this.value = value; Invalidate(); RaiseEvent(SelectedValueChanged); } |
23 | 1722 } |
27
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1723 public int Minimum { |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1724 get { return minimum; } |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1725 set { minimum = value; if (this.value < minimum) this.Value = minimum; } |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1726 } |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1727 public int Maximum { |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1728 get { return maximum; } |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1729 set { maximum = value; if (this.value > maximum) this.Value = maximum; } |
23 | 1730 } |
27
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1731 public int Step { get; set; } |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1732 protected override string SelectedText { |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1733 get { return value.ToString(); } |
23 | 1734 } |
27
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1735 protected override void ButtonPressDown() { |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1736 Value = Math.Max(minimum, value - Step); |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1737 } |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1738 protected override void ButtonPressUp() { |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1739 Value = Math.Min(maximum, value + Step); |
23 | 1740 } |
1741 } | |
1742 public interface IFBGTreeParent { | |
1743 FBGTreeView TreeView { get; } | |
1744 int Depth { get; } | |
1745 void AddChild(FBGTreeNode node); | |
1746 void RemoveChild(FBGTreeNode node); | |
1747 } | |
1748 public class FBGTreeNode : IFBGTreeParent { | |
1749 private List<FBGTreeNode> children = new List<FBGTreeNode>(); | |
1750 private Boolean expanded = true; | |
1751 private Boolean hasCheckBox = false; | |
1752 private Boolean isChecked = false; | |
1753 private Object item; | |
1754 | |
1755 public FBGTreeView TreeView { get; private set; } | |
1756 public int Depth { get; private set; } | |
1757 public Object Tag { get; set; } | |
1758 public IFBGTreeParent Parent { get; private set; } | |
1759 | |
1760 public IList<FBGTreeNode> Children { get { return children.AsReadOnly(); } } | |
1761 | |
1762 public Object Item { | |
1763 get { return item; } | |
1764 set { | |
1765 item = value; | |
1766 Invalidate(); | |
1767 } | |
1768 } | |
1769 public Boolean Expanded { | |
1770 get { return expanded; } | |
1771 set { | |
1772 if (expanded == value) return; | |
1773 expanded = value; | |
1774 UpdateTree(); | |
1775 } | |
1776 } | |
1777 public Boolean HasCheckBox { | |
1778 get { return hasCheckBox; } | |
1779 set { | |
1780 if (hasCheckBox == value) return; | |
1781 hasCheckBox = value; | |
1782 Invalidate(); | |
1783 } | |
1784 } | |
1785 public Boolean Checked { | |
1786 get { return isChecked; } | |
1787 set { | |
1788 if (isChecked == value) return; | |
1789 isChecked = value; | |
1790 Invalidate(); | |
1791 if (TreeView != null) TreeView.RaiseNodeCheckedChanged(this); | |
1792 } | |
1793 } | |
1794 | |
1795 public FBGTreeNode(IFBGTreeParent parent, Object item) { | |
1796 this.TreeView = parent.TreeView; | |
1797 this.Depth = parent.Depth + 1; | |
1798 this.Parent = parent; | |
1799 this.item = item; | |
1800 parent.AddChild(this); | |
1801 } | |
1802 | |
1803 public void Remove() { | |
1804 Parent.RemoveChild(this); | |
1805 } | |
1806 void IFBGTreeParent.AddChild(FBGTreeNode node) { | |
1807 children.Add(node); | |
1808 if (Expanded) UpdateTree(); | |
1809 else Invalidate(); | |
1810 } | |
1811 void IFBGTreeParent.RemoveChild(FBGTreeNode node) { | |
1812 children.Remove(node); | |
1813 TreeView.ReleaseNodeFromTree(node); | |
1814 if (Expanded) UpdateTree(); | |
1815 else Invalidate(); | |
1816 } | |
1817 public void Invalidate() { | |
1818 if (TreeView != null) TreeView.Invalidate(this); | |
1819 } | |
1820 private void UpdateTree() { | |
1821 if (TreeView != null) TreeView.UpdateView(); | |
1822 } | |
1823 public FBGTreeNode AddNode(Object item) { | |
1824 return new FBGTreeNode(this, item); | |
1825 } | |
1826 } | |
1827 public class FBGTreeView : FBGControl, IFBGTreeParent { | |
1828 private List<FBGTreeNode> items = new List<FBGTreeNode>(); | |
1829 private List<FBGTreeNode> itemsView = new List<FBGTreeNode>(); | |
1830 private FBGTreeNode selected = null; | |
1831 private FBGTreeNode highlighted = null; | |
1832 private Boolean hasScrollBar = false; | |
1833 private Boolean hitScrollBar = false; | |
1834 private int offset = 0; | |
1835 private ButtonState buttonUpState = ButtonState.Normal; | |
1836 private ButtonState buttonDownState = ButtonState.Normal; | |
1837 private Converter<Object, String> itemFormatter = null; | |
1838 | |
1839 public Converter<Object, String> ItemFormatter { get { return itemFormatter; } set { itemFormatter = value; Invalidate(); } } | |
1840 public FBGTreeNode SelectedNode { get { return selected; } set { if (selected != value) { selected = value; Invalidate(); RaiseEvent(SelectedNodeChanged); } } } | |
1841 public IList<FBGTreeNode> Nodes { get { return items.AsReadOnly(); } } | |
1842 | |
1843 public event EventHandler SelectedNodeChanged; | |
1844 public event EventHandler NodeCheckedChanged; | |
1845 | |
1846 public FBGTreeView(IFBGContainerControl parent) : base(parent) { | |
1847 BackColor = Color.White; | |
1848 } | |
1849 FBGTreeView IFBGTreeParent.TreeView { get { return this; } } | |
1850 int IFBGTreeParent.Depth { get { return -1; } } | |
1851 void IFBGTreeParent.AddChild(FBGTreeNode node) { | |
1852 items.Add(node); | |
1853 UpdateView(); | |
1854 } | |
1855 void IFBGTreeParent.RemoveChild(FBGTreeNode node) { | |
1856 items.Remove(node); | |
1857 ReleaseNodeFromTree(node); | |
1858 UpdateView(); | |
1859 } | |
1860 public FBGTreeNode AddNode(Object item) { return new FBGTreeNode(this, item); } | |
1861 internal void ReleaseNodeFromTree(FBGTreeNode node) { | |
1862 if (highlighted == node) highlighted = null; | |
1863 if (selected == node) SelectedNode = null; | |
1864 } | |
1865 internal void RaiseNodeCheckedChanged(FBGTreeNode node) { | |
1866 RaiseEvent(NodeCheckedChanged); | |
1867 } | |
1868 internal void UpdateView() { | |
1869 List<FBGTreeNode> newView = new List<FBGTreeNode>(); | |
1870 Stack<Queue<FBGTreeNode>> stack = new Stack<Queue<FBGTreeNode>>(); | |
1871 stack.Push(new Queue<FBGTreeNode>(items)); | |
1872 while (stack.Count > 0) { | |
1873 Queue<FBGTreeNode> list = stack.Peek(); | |
1874 if (list.Count == 0) { | |
1875 stack.Pop(); | |
1876 continue; | |
1877 } | |
1878 FBGTreeNode item = list.Dequeue(); | |
1879 newView.Add(item); | |
1880 if (item.Expanded) stack.Push(new Queue<FBGTreeNode>(item.Children)); | |
1881 } | |
1882 itemsView = newView; | |
1883 Invalidate(); | |
1884 } | |
1885 internal void Invalidate(FBGTreeNode node) { | |
1886 int i = itemsView.IndexOf(node); | |
1887 if (i == -1) return; | |
1888 int lh = (int)Math.Ceiling(SystemFonts.DefaultFont.GetHeight() / 2.0) * 2; | |
1889 Invalidate(new Rectangle(1, i * lh, Bounds.Width - 1, lh)); | |
1890 } | |
1891 protected override void Paint(Graphics g) { | |
1892 base.Paint(g); | |
1893 | |
1894 int lh = (int)Math.Ceiling(SystemFonts.DefaultFont.GetHeight() / 2.0) * 2; | |
1895 int th = lh * itemsView.Count; | |
1896 hasScrollBar = offset > 0 || th + 2 > Bounds.Height; | |
1897 int y = 2; | |
1898 using (Pen dottedpen = new Pen(Brushes.Black)) { | |
1899 dottedpen.DashStyle = DashStyle.Dot; | |
1900 using (StringFormat sf = new StringFormat(StringFormatFlags.NoWrap)) { | |
1901 int lw = Bounds.Width - 2; | |
1902 if (hasScrollBar) lw -= 17; | |
1903 for (int i = offset; i < itemsView.Count; i++) { | |
1904 FBGTreeNode item = itemsView[i]; | |
1905 if (y + 2 < Bounds.Height) { | |
1906 Object obj = item.Item; | |
1907 String text = itemFormatter == null ? (obj == null ? String.Empty : obj.ToString()) : itemFormatter(obj); | |
1908 if (item == selected) g.FillRectangle(Brushes.DarkGray, 2, y, lw - 2, lh); | |
1909 if (item == highlighted) g.DrawRectangle(dottedpen, 2, y, lw - 3, lh - 1); | |
1910 int x = 3 + 19 * item.Depth + 14; | |
1911 if (item.HasCheckBox) { | |
1912 x += 2; | |
1913 ControlPaint.DrawCheckBox(g, x, y, lh, lh, item.Checked ? ButtonState.Checked : ButtonState.Normal); | |
1914 x += lh + 1; | |
1915 } | |
1916 g.DrawString(text, SystemFonts.DefaultFont, SystemBrushes.WindowText, new Rectangle(x, y, lw - x, lh), sf); | |
1917 } | |
1918 int upto = y + 2 + 4 - 8; | |
1919 for (int j = i - 1; j >= 0; j--) { | |
1920 if (itemsView[j].Depth < item.Depth) { | |
1921 break; | |
1922 } | |
1923 if (itemsView[j].Depth == item.Depth) { | |
1924 if (itemsView[j].Children.Count > 0) { | |
1925 upto = 2 + lh * (j - offset) + 10; | |
1926 } else { | |
1927 upto = 2 + lh * (j - offset) + 6; | |
1928 } | |
1929 break; | |
1930 } | |
1931 if (j <= offset) { | |
1932 upto = 2 + 2 + 4 - 8; | |
1933 break; | |
1934 } | |
1935 } | |
1936 if (item.Children.Count > 0) { | |
1937 g.DrawRectangle(Pens.Black, 3 + 19 * item.Depth, y + 2, 8, 8); | |
1938 g.DrawLine(Pens.Black, 3 + 19 * item.Depth + 2, y + 2 + 4, 3 + 19 * item.Depth + 6, y + 2 + 4); | |
1939 if (!item.Expanded) g.DrawLine(Pens.Black, 3 + 19 * item.Depth + 4, y + 4, 3 + 19 * item.Depth + 4, y + 2 + 6); | |
1940 | |
1941 g.DrawLine(dottedpen, 3 + 19 * item.Depth + 8, y + 2 + 4, 3 + 19 * item.Depth + 14, y + 2 + 4); | |
1942 g.DrawLine(dottedpen, 3 + 19 * item.Depth + 4, y + 2 + 4 - 6, 3 + 19 * item.Depth + 4, upto); | |
1943 } else { | |
1944 g.DrawLine(dottedpen, 3 + 19 * item.Depth + 4, y + 2 + 4, 3 + 19 * item.Depth + 14, y + 2 + 4); | |
1945 g.DrawLine(dottedpen, 3 + 19 * item.Depth + 4, y + 2 + 4 - 2, 3 + 19 * item.Depth + 4, upto); | |
1946 } | |
1947 y += lh; | |
1948 //if (y + lh + 2 >= Bounds.Height && item.Depth == 0) break; | |
1949 if (y + 2 >= Bounds.Height && item.Depth == 0) break; | |
1950 } | |
1951 } | |
1952 } | |
1953 //if (y < th) hasScrollBar = true; | |
1954 //hasScrollBar = true; | |
1955 if (hasScrollBar) { | |
1956 int xoff = Bounds.Width - 17; | |
1957 using (Brush b = new LinearGradientBrush(new Rectangle(xoff, 0, 17, 1), Color.LightGray, Color.White, LinearGradientMode.Horizontal)) | |
1958 g.FillRectangle(b, xoff, 17, 16, Bounds.Height - 17 - 17); | |
1959 ControlPaint.DrawScrollButton(g, xoff, 1, 16, 16, ScrollButton.Up, buttonUpState); | |
1960 ControlPaint.DrawScrollButton(g, xoff, Bounds.Height - 17, 16, 16, ScrollButton.Down, buttonDownState); | |
1961 g.DrawRectangle(Pens.Black, new Rectangle(xoff, 17 + offset * (Bounds.Height - 17 - 17 - 20) / (itemsView.Count - 1), 15, 20)); | |
1962 } | |
1963 | |
1964 g.DrawRectangle(Pens.DarkBlue, 0, 0, Bounds.Width - 1, Bounds.Height - 1); | |
1965 } | |
1966 protected override void MouseDown(Point position, MouseButtons buttons) { | |
1967 CaptureKeyboard(true); | |
1968 if ((buttons & MouseButtons.Left) != 0) { | |
1969 CaptureMouse(true); | |
1970 if (hasScrollBar && position.X > Bounds.Width - 17) { | |
1971 hitScrollBar = true; | |
1972 if (position.Y < 17) { | |
1973 offset--; | |
1974 buttonUpState = ButtonState.Pushed; | |
1975 } else if (position.Y > Bounds.Height - 17) { | |
1976 offset++; | |
1977 buttonDownState = ButtonState.Pushed; | |
1978 } else { | |
1979 offset = (int)Math.Round((position.Y - 17) * (itemsView.Count - 1) / (double)(Bounds.Height - 17 - 17 - 10)); | |
1980 } | |
1981 if (offset < 0) offset = 0; | |
1982 if (offset >= itemsView.Count) offset = itemsView.Count - 1; | |
1983 Invalidate(); | |
1984 } else { | |
1985 MouseHandler(position, buttons, true); | |
1986 } | |
1987 } | |
1988 } | |
1989 protected override void MouseMove(Point position, MouseButtons buttons) { | |
1990 if (hitScrollBar) { | |
1991 if (position.Y < 17) { | |
1992 } else if (position.Y > Bounds.Height - 17) { | |
1993 } else { | |
1994 offset = (int)Math.Round((position.Y - 17) * (itemsView.Count - 1) / (double)(Bounds.Height - 17 - 17 - 10)); | |
1995 if (offset < 0) offset = 0; | |
1996 if (offset >= itemsView.Count) offset = itemsView.Count - 1; | |
1997 Invalidate(); | |
1998 } | |
1999 return; | |
2000 } | |
2001 MouseHandler(position, buttons, false); | |
2002 } | |
2003 protected override void MouseUp(Point position, MouseButtons buttons) { | |
2004 if ((buttons & MouseButtons.Left) != 0) { | |
2005 CaptureMouse(false); | |
2006 buttonUpState = buttonDownState = ButtonState.Normal; | |
2007 Invalidate(); | |
2008 if (hitScrollBar) { | |
2009 hitScrollBar = false; | |
2010 return; | |
2011 } | |
2012 } | |
2013 if (hitScrollBar) return; | |
2014 MouseHandler(position, buttons, false); | |
2015 } | |
2016 private void MouseHandler(Point position, MouseButtons buttons, Boolean down) { | |
2017 if ((buttons & MouseButtons.Left) != 0 && itemsView.Count > 0) { | |
2018 int lh = (int)Math.Ceiling(SystemFonts.DefaultFont.GetHeight() / 2.0) * 2; | |
2019 int i = (position.Y - 2) / lh + offset; | |
2020 if (i < 0) i = 0; | |
2021 if (i >= itemsView.Count) i = itemsView.Count - 1; | |
2022 Boolean changed = false; | |
2023 FBGTreeNode current = itemsView[i]; | |
2024 if (!ReferenceEquals(highlighted, current)) changed = true; | |
2025 highlighted = current; | |
2026 if (current.Children.Count > 0 && (new Rectangle(3 + 19 * current.Depth, 2 + lh * (i - offset) + 2, 8, 8)).Contains(position)) { | |
2027 if (down) current.Expanded = !current.Expanded; | |
2028 } else if (current.HasCheckBox && (new Rectangle(3 + 19 * current.Depth + 14 + 2, 2 + lh * (i - offset), lh, lh)).Contains(position)) { | |
2029 if (down) current.Checked = !current.Checked; | |
2030 } else if ((new Rectangle(Point.Empty, Bounds.Size)).Contains(position)) { | |
2031 SelectedNode = current; | |
2032 changed = false; | |
2033 } | |
2034 if (changed) Invalidate(); | |
2035 } | |
2036 } | |
2037 protected override void KeyDown(Keys key) { | |
2038 base.KeyDown(key); | |
2039 if (key == Keys.Up) { | |
2040 int i = itemsView.IndexOf(selected); | |
2041 i--; | |
2042 if (i >= 0) SelectAndScrollIntoView(itemsView[i]); | |
2043 } else if (key == Keys.Down) { | |
2044 int i = itemsView.IndexOf(selected); | |
2045 i++; | |
2046 if (i < itemsView.Count) SelectAndScrollIntoView(itemsView[i]); | |
2047 } else if (key == Keys.Left && selected != null) { | |
2048 if (selected.Expanded && selected.Children.Count > 0) { | |
2049 selected.Expanded = false; | |
2050 } else { | |
2051 FBGTreeNode tn = selected.Parent as FBGTreeNode; | |
2052 if (tn != null) SelectAndScrollIntoView(tn); | |
2053 } | |
2054 } else if (key == Keys.Right && selected != null) { | |
2055 if (!selected.Expanded && selected.Children.Count > 0) { | |
2056 selected.Expanded = true; | |
2057 } else if (selected.Children.Count > 0) { | |
2058 SelectAndScrollIntoView(selected.Children[0]); | |
2059 } | |
2060 } else if (key == Keys.Space && selected != null) { | |
2061 if (selected.HasCheckBox) selected.Checked = !selected.Checked; | |
2062 } | |
2063 } | |
2064 private void SelectAndScrollIntoView(FBGTreeNode tn) { | |
2065 int i = itemsView.IndexOf(tn); | |
2066 if (i == -1) { | |
2067 for (FBGTreeNode tp = tn.Parent as FBGTreeNode; tp != null; tp = tp.Parent as FBGTreeNode) if (!tp.Expanded) tp.Expanded = true; | |
2068 i = itemsView.IndexOf(tn); | |
2069 } | |
2070 if (i != -1) { | |
2071 int lh = (int)Math.Ceiling(SystemFonts.DefaultFont.GetHeight() / 2.0) * 2; | |
2072 if (i < offset) offset = i; | |
2073 offset = Math.Max(offset, i - Bounds.Height / lh + 1); | |
2074 } | |
2075 highlighted = tn; | |
2076 SelectedNode = tn; | |
2077 } | |
2078 } | |
2079 } |