Mercurial > hg > ucis.core
annotate FBGUI/FBGUI.cs @ 73:6aca18ee4ec6
NaCl: improved ed25519 implementation, added simple API for ed25519 and sha512
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Sat, 02 Nov 2013 16:01:09 +0100 |
parents | 82290dc1403c |
children | 8f31b164ce7e 1a10ca0f662e |
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); |
40 | 630 public static readonly FBGCursor Hand = LoadFromResource("cursor_hand", 5, 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
|
631 public static FBGCursor ArrowCursor { get { return Arrow; } } |
23 | 632 } |
633 public class FBGRenderer : FBGContainerControl, IDisposable { | |
634 private FBGCursor cursor = null; | |
635 private Point cursorposition = Point.Empty; | |
636 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
|
637 private Bitmap Frontbuffer = null; |
7f0b7a53a000
FBGUI: Allow derived classes to access some internals
Ivo Smits <Ivo@UCIS.nl>
parents:
23
diff
changeset
|
638 protected Object RenderLock = new object(); |
23 | 639 public event EventHandler<InvalidateEventArgs> Painted; |
26
7f0b7a53a000
FBGUI: Allow derived classes to access some internals
Ivo Smits <Ivo@UCIS.nl>
parents:
23
diff
changeset
|
640 protected Size size = Size.Empty; |
23 | 641 private ThreadingTimer PaintTimer = null; |
642 private Boolean PaintScheduled = false; | |
643 private int PaintDelay = 0; | |
644 public Boolean SuspendDrawing { | |
645 get { return suspenddrawing; } | |
646 set { | |
647 lock (RenderLock) { | |
648 suspenddrawing = value; | |
649 if (!value) { | |
650 Refresh(DirtyRectangle); | |
651 DirtyRectangle = Rectangle.Empty; | |
652 } | |
653 } | |
654 } | |
655 } | |
656 public int RedrawDelay { | |
657 get { return PaintDelay; } | |
658 set { | |
659 lock (RenderLock) { | |
660 if (value < 0) throw new ArgumentOutOfRangeException("value"); | |
661 PaintDelay = value; | |
662 if (PaintDelay == 0) { | |
663 if (PaintTimer != null) PaintTimer.Dispose(); | |
664 PaintTimer = null; | |
665 if (PaintScheduled) PaintTimerCallback(null); | |
666 } else { | |
667 PaintTimer = new ThreadingTimer(PaintTimerCallback); | |
668 } | |
669 } | |
670 } | |
671 } | |
672 private Boolean suspenddrawing = false; | |
673 private Rectangle DirtyRectangle; | |
674 | |
675 public Point CursorPosition { | |
676 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
|
677 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
|
678 } |
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 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
|
680 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
|
681 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
|
682 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
|
683 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
|
684 r1.Offset(cursorposition); |
23 | 685 } |
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
|
686 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
|
687 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
|
688 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
|
689 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
|
690 } |
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 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
|
692 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
|
693 Invalidate(r1); |
23 | 694 } |
695 public override Rectangle Bounds { | |
696 get { return new Rectangle(Point.Empty, size); } | |
697 set { throw new NotSupportedException("Can not change the top control bounds"); } | |
698 } | |
699 public FBGRenderer(IFramebuffer fb) : this(fb.Width, fb.Height) { | |
700 Framebuffer = fb; | |
701 } | |
702 public FBGRenderer(Size fbsize) : this(fbsize.Width, fbsize.Height) { } | |
703 public FBGRenderer(int width, int height) : this(new Bitmap(width, height, PixelFormat.Format32bppRgb)) { } | |
704 public FBGRenderer(Bitmap bmp) : base(null) { | |
705 Frontbuffer = bmp; | |
706 BackColor = SystemColors.Control; | |
707 size = Frontbuffer.Size; | |
708 } | |
26
7f0b7a53a000
FBGUI: Allow derived classes to access some internals
Ivo Smits <Ivo@UCIS.nl>
parents:
23
diff
changeset
|
709 protected FBGRenderer() : base(null) { |
7f0b7a53a000
FBGUI: Allow derived classes to access some internals
Ivo Smits <Ivo@UCIS.nl>
parents:
23
diff
changeset
|
710 BackColor = SystemColors.Control; |
7f0b7a53a000
FBGUI: Allow derived classes to access some internals
Ivo Smits <Ivo@UCIS.nl>
parents:
23
diff
changeset
|
711 } |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
712 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
|
713 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
|
714 Invalidate(e.Area); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
715 } |
23 | 716 public override void Invalidate(Rectangle rect) { |
717 if (rect.Width == 0 || rect.Height == 0) return; | |
718 lock (RenderLock) { | |
719 if (SuspendDrawing || PaintTimer != null) { | |
720 DirtyRectangle = DirtyRectangle.IsEmpty ? rect : Rectangle.Union(DirtyRectangle, rect); | |
721 if (!SuspendDrawing && !PaintScheduled) { | |
722 PaintScheduled = true; | |
723 PaintTimer.Change(PaintDelay, Timeout.Infinite); | |
724 } | |
725 } else { | |
726 Refresh(rect); | |
727 } | |
728 } | |
729 } | |
730 private void PaintTimerCallback(Object state) { | |
731 try { | |
732 lock (RenderLock) { | |
733 PaintScheduled = false; | |
734 Refresh(DirtyRectangle); | |
735 DirtyRectangle = Rectangle.Empty; | |
736 } | |
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
|
737 } 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
|
738 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
|
739 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
|
740 } |
23 | 741 } |
26
7f0b7a53a000
FBGUI: Allow derived classes to access some internals
Ivo Smits <Ivo@UCIS.nl>
parents:
23
diff
changeset
|
742 protected virtual void Refresh(Rectangle rect) { |
23 | 743 lock (RenderLock) { |
744 rect.Intersect(Bounds); | |
745 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
|
746 if (Frontbuffer != null) { |
7f0b7a53a000
FBGUI: Allow derived classes to access some internals
Ivo Smits <Ivo@UCIS.nl>
parents:
23
diff
changeset
|
747 using (Graphics g = Graphics.FromImage(Frontbuffer)) { |
7f0b7a53a000
FBGUI: Allow derived classes to access some internals
Ivo Smits <Ivo@UCIS.nl>
parents:
23
diff
changeset
|
748 g.SetClip(rect); |
7f0b7a53a000
FBGUI: Allow derived classes to access some internals
Ivo Smits <Ivo@UCIS.nl>
parents:
23
diff
changeset
|
749 Paint(g); |
7f0b7a53a000
FBGUI: Allow derived classes to access some internals
Ivo Smits <Ivo@UCIS.nl>
parents:
23
diff
changeset
|
750 } |
7f0b7a53a000
FBGUI: Allow derived classes to access some internals
Ivo Smits <Ivo@UCIS.nl>
parents:
23
diff
changeset
|
751 if (Framebuffer != null) Framebuffer.DrawImage(Frontbuffer, rect, rect.Location); |
23 | 752 } |
753 RaiseEvent(Painted, new InvalidateEventArgs(rect)); | |
754 } | |
755 } | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
756 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
|
757 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
|
758 if (cursor != null) { |
42 | 759 Rectangle r = cursor.Area; |
760 r.Offset(cursorposition); | |
761 g.DrawImage(cursor.Image, r); | |
23 | 762 } |
763 } | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
764 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
|
765 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
|
766 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
|
767 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
|
768 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
769 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
|
770 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
|
771 else { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
772 IFBGControl prev = keyboardCaptureControl; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
773 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
|
774 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
|
775 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
776 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
777 |
23 | 778 protected override Boolean CaptureMouse(Boolean capture) { |
779 return true; | |
780 } | |
781 protected override Boolean CaptureKeyboard(bool capture) { | |
782 return true; | |
783 } | |
26
7f0b7a53a000
FBGUI: Allow derived classes to access some internals
Ivo Smits <Ivo@UCIS.nl>
parents:
23
diff
changeset
|
784 public virtual void Dispose() { |
23 | 785 lock (RenderLock) { |
786 if (PaintTimer != null) PaintTimer.Dispose(); | |
787 PaintTimer = null; | |
788 } | |
789 Orphaned(); | |
69
82290dc1403c
Fix crash in FBGUI renderer shutdown
Ivo Smits <Ivo@UCIS.nl>
parents:
42
diff
changeset
|
790 lock (RenderLock) { |
82290dc1403c
Fix crash in FBGUI renderer shutdown
Ivo Smits <Ivo@UCIS.nl>
parents:
42
diff
changeset
|
791 if (Frontbuffer != null) Frontbuffer.Dispose(); |
82290dc1403c
Fix crash in FBGUI renderer shutdown
Ivo Smits <Ivo@UCIS.nl>
parents:
42
diff
changeset
|
792 Frontbuffer = null; |
82290dc1403c
Fix crash in FBGUI renderer shutdown
Ivo Smits <Ivo@UCIS.nl>
parents:
42
diff
changeset
|
793 } |
23 | 794 } |
795 public Bitmap LockBitmapBuffer() { | |
796 Monitor.Enter(RenderLock); | |
797 return Frontbuffer; | |
798 } | |
799 public void UnlockBitmapBuffer() { | |
800 Monitor.Exit(RenderLock); | |
801 } | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
802 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
|
803 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
|
804 HandleEvent(e); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
805 UpdateCursor(cursorposition, e.Cursor); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
806 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
807 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
|
808 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
|
809 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
|
810 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
|
811 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
|
812 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
|
813 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
|
814 public void KeyUp(Keys key, Char keyChar) { HandleEvent(new FBGKeyboardEvent(key, keyChar, false)); } |
23 | 815 } |
816 public class FBGForm : FBGDockContainer { | |
817 private Point prevPosition = Point.Empty; | |
818 private NonClientOps moveresize = 0; | |
819 private String text = String.Empty; | |
820 public event EventHandler TextChanged; | |
31 | 821 public event EventHandler Closed; |
23 | 822 public Boolean Sizable { get; set; } |
823 public Boolean Movable { get; set; } | |
824 public Boolean Closable { get; set; } | |
825 [Flags] | |
826 private enum NonClientOps : int { | |
827 None = 0, | |
828 Move = 1, | |
829 ResizeLeft = 2, | |
830 ResizeRight = 4, | |
831 ResizeTop = 8, | |
832 ResizeBottom = 16, | |
833 ButtonClose = 32, | |
834 MoveResize = ResizeLeft | ResizeRight | ResizeBottom | ResizeTop | Move, | |
835 } | |
836 public FBGForm(IFBGContainerControl parent) : base(parent) { | |
837 BackColor = SystemColors.Control; | |
838 ClientRectangle = new Rectangle(4, 22, Bounds.Width - 8, Bounds.Height - 26); | |
839 Sizable = true; | |
840 Movable = true; | |
841 Closable = false; | |
842 } | |
843 public override Rectangle Bounds { | |
844 get { return base.Bounds; } | |
845 set { | |
846 ClientRectangle = new Rectangle(4, 22, value.Width - 8, value.Height - 26); | |
847 base.Bounds = value; | |
848 } | |
849 } | |
850 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
|
851 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
|
852 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
|
853 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
|
854 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
|
855 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
|
856 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
|
857 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
|
858 } |
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 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
|
860 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
|
861 } |
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 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
|
863 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
|
864 } |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
865 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
|
866 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
|
867 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
|
868 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
|
869 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
|
870 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
|
871 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
|
872 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
|
873 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
|
874 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
|
875 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
|
876 } |
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
|
877 } |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
878 protected override void HandlePointingEvent(FBGPointingEvent e) { |
39
41b2d01ae458
FBGUI: Fixed cursor handling in forms
Ivo Smits <Ivo@UCIS.nl>
parents:
34
diff
changeset
|
879 if (Cursor != null) e.Cursor = Cursor; |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
880 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
|
881 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
882 Boolean HandlePointingEventA(FBGPointingEvent e) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
883 switch (e.Type) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
884 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
|
885 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
|
886 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
|
887 default: return true; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
888 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
889 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
890 Boolean MouseDown(Point p, MouseButtons buttons, FBGPointingEvent e) { |
23 | 891 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
|
892 if ((buttons & MouseButtons.Left) != 0) mr = GetNonClientOperation(p); |
23 | 893 if (mr != 0) { |
894 moveresize = mr; | |
895 prevPosition = p; | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
896 SetCursorForNonClientOperation(moveresize, e); |
23 | 897 CaptureMouse(true); |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
898 return false; |
23 | 899 } else { |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
900 return true; |
23 | 901 } |
902 } | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
903 Boolean MouseMove(Point position, MouseButtons buttons, FBGPointingEvent e) { |
39
41b2d01ae458
FBGUI: Fixed cursor handling in forms
Ivo Smits <Ivo@UCIS.nl>
parents:
34
diff
changeset
|
904 NonClientOps mr = moveresize; |
41b2d01ae458
FBGUI: Fixed cursor handling in forms
Ivo Smits <Ivo@UCIS.nl>
parents:
34
diff
changeset
|
905 if (mr == 0) mr = GetNonClientOperation(position); |
41b2d01ae458
FBGUI: Fixed cursor handling in forms
Ivo Smits <Ivo@UCIS.nl>
parents:
34
diff
changeset
|
906 if (mr == 0) return true; |
41b2d01ae458
FBGUI: Fixed cursor handling in forms
Ivo Smits <Ivo@UCIS.nl>
parents:
34
diff
changeset
|
907 SetCursorForNonClientOperation(mr, e); |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
908 if ((moveresize & NonClientOps.MoveResize) != 0) { |
23 | 909 Rectangle b = Bounds; |
910 int dx = position.X - prevPosition.X; | |
911 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
|
912 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
|
913 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
|
914 } |
23 | 915 if ((moveresize & NonClientOps.ResizeLeft) != 0) { |
916 b.X += dx; | |
917 b.Width -= dx; | |
918 } else if ((moveresize & NonClientOps.ResizeRight) != 0) { | |
919 b.Width += dx; | |
920 prevPosition.X = position.X; | |
921 } | |
922 if ((moveresize & NonClientOps.ResizeTop) != 0) { | |
923 b.Y += dy; | |
924 b.Height -= dy; | |
925 } else if ((moveresize & NonClientOps.ResizeBottom) != 0) { | |
926 b.Height += dy; | |
927 prevPosition.Y = position.Y; | |
928 } | |
929 if (b.Width < 55) b.Width = 55; | |
930 if (b.Height < 25) b.Height = 25; | |
931 Bounds = b; | |
932 } | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
933 return false; |
23 | 934 } |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
935 Boolean MouseUp(Point position, MouseButtons buttons, FBGPointingEvent e) { |
23 | 936 if (moveresize == 0) { |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
937 SetCursorForNonClientOperation(GetNonClientOperation(position), e); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
938 return true; |
23 | 939 } else if ((buttons & MouseButtons.Left) != 0) { |
940 MouseMove(position, buttons); | |
941 CaptureMouse(false); | |
942 if (moveresize == NonClientOps.ButtonClose && (new Rectangle(Bounds.Width - 5 - 14, 4, 14, 14)).Contains(position) && Closable) Close(); | |
943 moveresize = 0; | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
944 SetCursorForNonClientOperation(GetNonClientOperation(position), e); |
23 | 945 } |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
946 return false; |
23 | 947 } |
948 protected override void Paint(Graphics g) { | |
949 base.Paint(g); | |
950 g.DrawRectangle(Pens.Gray, 0, 0, Bounds.Width - 1, Bounds.Height - 1); | |
951 g.DrawRectangle(Pens.LightGray, 1, 1, Bounds.Width - 3, Bounds.Height - 3); | |
952 g.DrawRectangle(Pens.DarkGray, 2, 20, Bounds.Width - 5, Bounds.Height - 23); | |
953 g.DrawRectangle(Pens.Gray, 3, 21, Bounds.Width - 7, Bounds.Height - 25); | |
954 using (Brush b = new LinearGradientBrush(new Rectangle(0, 1, 1, 18), Color.Gray, Color.LightGray, LinearGradientMode.Vertical)) | |
955 g.FillRectangle(b, 2, 2, Bounds.Width - 4, 18); | |
956 | |
957 g.DrawString(Text, SystemFonts.CaptionFont, Brushes.Black, 4, 1); | |
958 | |
959 g.DrawRectangle(Pens.Gray, Bounds.Width - 5 - 14, 4, 14, 14); | |
960 g.DrawRectangle(Pens.Gray, Bounds.Width - 5 - 14 - 16, 4, 14, 14); | |
961 g.DrawRectangle(Pens.Gray, Bounds.Width - 5 - 14 - 32, 4, 14, 14); | |
962 using (Brush b = new LinearGradientBrush(new Rectangle(0, 5, 1, 13), Color.LightGray, Color.DarkGray, LinearGradientMode.Vertical)) { | |
963 g.FillRectangle(b, Bounds.Width - 5 - 14 + 1, 5, 13, 13); | |
964 g.FillRectangle(b, Bounds.Width - 5 - 14 + 1 - 16, 5, 13, 13); | |
965 g.FillRectangle(b, Bounds.Width - 5 - 14 + 1 - 32, 5, 13, 13); | |
966 } | |
967 if (Closable) { | |
968 g.DrawLine(Pens.Black, Bounds.Width - 5 - 14 + 3, 4 + 3, Bounds.Width - 5 - 14 + 14 - 3, 4 + 14 - 3); | |
969 g.DrawLine(Pens.Black, Bounds.Width - 5 - 14 + 3, 4 + 14 - 3, Bounds.Width - 5 - 14 + 14 - 3, 4 + 3); | |
970 } | |
971 } | |
972 public void Close() { | |
973 Parent.RemoveControl(this); | |
31 | 974 RaiseEvent(Closed); |
23 | 975 } |
976 } | |
977 public class FBGDesktop : FBGContainerControl { | |
978 FBGContainerControl windowcontainer; | |
979 FBGContainerControl menucontainer; | |
980 Boolean startup = true; | |
981 class FBGWindowState { | |
982 public IFBGControl Control; | |
983 public FBGButton MenuButton; | |
984 public Boolean Visible; | |
985 public Rectangle OldBounds; | |
986 public FBGWindowState(IFBGControl cntrl, FBGButton btn) { | |
987 Control = cntrl; | |
988 MenuButton = btn; | |
989 Visible = true; | |
990 } | |
991 } | |
992 Dictionary<IFBGControl, FBGWindowState> windowstates = new Dictionary<IFBGControl, FBGWindowState>(); | |
993 public FBGDesktop(IFBGContainerControl parent) : base(parent) { | |
994 menucontainer = new FBGContainerControl(this); | |
995 menucontainer.Bounds = new Rectangle(0, Bounds.Height - 25, Bounds.Width, 25); | |
996 windowcontainer = new FBGContainerControl(this); | |
997 windowcontainer.Bounds = new Rectangle(0, 0, Bounds.Width, Bounds.Height - 25); | |
998 startup = false; | |
999 } | |
1000 public override Rectangle Bounds { | |
1001 get { return base.Bounds; } | |
1002 set { | |
1003 if (Bounds == value) return; | |
1004 base.Bounds = value; | |
1005 if (startup) return; | |
1006 menucontainer.Bounds = new Rectangle(0, value.Height - 25, value.Width, 25); | |
1007 windowcontainer.Bounds = new Rectangle(0, 0, value.Width, value.Height - 25); | |
1008 ScaleMenuButtons(); | |
1009 } | |
1010 } | |
1011 protected override void AddControl(IFBGControl control) { | |
1012 if (startup) { | |
1013 base.AddControl(control); | |
1014 return; | |
1015 } | |
1016 ((IFBGContainerControl)windowcontainer).AddControl(control); | |
1017 FBGButton btn = new FBGButton(menucontainer); | |
1018 FBGForm formcontrol = control as FBGForm; | |
1019 if (formcontrol == null) { | |
1020 btn.Text = "Untitled"; | |
1021 } else { | |
1022 formcontrol.TextChanged += delegate(Object sender, EventArgs e) { | |
1023 btn.Text = formcontrol.Text; | |
1024 }; | |
1025 btn.Text = formcontrol.Text; | |
1026 } | |
1027 FBGWindowState ws = new FBGWindowState(control, btn); | |
1028 windowstates.Add(control, ws); | |
1029 ScaleMenuButtons(); | |
1030 btn.Click += delegate(Object sender, EventArgs e) { | |
1031 if (ws.Visible) { | |
1032 if (ws.MenuButton.BackColor == Color.DarkGray) { | |
1033 ws.OldBounds = ws.Control.Bounds; | |
1034 ws.Visible = false; | |
1035 ws.Control.Bounds = Rectangle.Empty; | |
1036 } else { | |
1037 windowcontainer.BringControlToFront(ws.Control); | |
1038 foreach (FBGWindowState wsa in windowstates.Values) if (!ReferenceEquals(ws, wsa)) wsa.MenuButton.BackColor = SystemColors.ButtonFace; | |
1039 ws.MenuButton.BackColor = Color.DarkGray; | |
1040 } | |
1041 } else { | |
1042 ws.Control.Bounds = ws.OldBounds; | |
1043 ws.Visible = true; | |
1044 windowcontainer.BringControlToFront(ws.Control); | |
1045 foreach (FBGWindowState wsa in windowstates.Values) if (!ReferenceEquals(ws, wsa)) wsa.MenuButton.BackColor = SystemColors.ButtonFace; | |
1046 ws.MenuButton.BackColor = Color.DarkGray; | |
1047 } | |
1048 }; | |
1049 } | |
1050 public override void RemoveControl(IFBGControl control) { | |
1051 windowcontainer.RemoveControl(control); | |
1052 windowstates.Remove(control); | |
1053 ScaleMenuButtons(); | |
1054 } | |
1055 private void ScaleMenuButtons() { | |
1056 int bcount = windowstates.Count; | |
1057 int bwidth = 200; | |
1058 int twidth = bwidth * bcount; | |
1059 if (twidth > Bounds.Width) bwidth = menucontainer.Bounds.Width / bcount; | |
1060 int i = 0; | |
1061 foreach (FBGWindowState ws in windowstates.Values) { | |
1062 ws.MenuButton.Bounds = new Rectangle(i * bwidth, 0, bwidth, 25); | |
1063 i++; | |
1064 } | |
1065 } | |
1066 protected override void Paint(Graphics g) { | |
1067 base.Paint(g); | |
1068 g.DrawLine(Pens.Black, 0, Bounds.Height - 25, Bounds.Width, Bounds.Height - 25); | |
1069 } | |
1070 protected override void MouseDown(Point position, MouseButtons buttons) { | |
1071 IFBGControl control = FindControlAtPosition(position); | |
1072 if (ReferenceEquals(control, windowcontainer)) { | |
1073 control = windowcontainer.FindControlAtPosition(PointToChild(windowcontainer, position)); | |
1074 if (!ReferenceEquals(control, null)) { | |
1075 windowcontainer.BringControlToFront(control); | |
1076 foreach (FBGWindowState ws in windowstates.Values) | |
1077 ws.MenuButton.BackColor = ReferenceEquals(ws.Control, control) ? Color.DarkGray : SystemColors.ButtonFace; | |
1078 } | |
1079 } | |
1080 base.MouseDown(position, buttons); | |
1081 } | |
1082 } | |
1083 | |
1084 public class FBGLabel : FBGControl, IDisposable { | |
1085 public FBGLabel(IFBGContainerControl parent) : base(parent) { | |
1086 Size = new Size(200, 16); | |
1087 } | |
1088 private String text = String.Empty; | |
1089 private Font font = SystemFonts.DefaultFont; | |
1090 private Brush brush = SystemBrushes.ControlText; | |
1091 private StringFormat stringformat = new StringFormat(); | |
1092 public String Text { get { return text; } set { text = value; Invalidate(); } } | |
1093 public Font Font { get { return font; } set { font = value; Invalidate(); } } | |
1094 public Brush Brush { get { return brush; } set { brush = value; Invalidate(); } } | |
1095 public Color Color { set { Brush = new SolidBrush(value); } } | |
1096 public StringAlignment Alignment { get { return stringformat.Alignment; } set { stringformat.Alignment = value; Invalidate(); } } | |
1097 public StringFormatFlags FormatFlags { get { return stringformat.FormatFlags; } set { stringformat.FormatFlags = value; Invalidate(); } } | |
1098 public StringAlignment LineAlignment { get { return stringformat.LineAlignment; } set { stringformat.LineAlignment = value; Invalidate(); } } | |
1099 public StringTrimming Trimming { get { return stringformat.Trimming; } set { stringformat.Trimming = value; Invalidate(); } } | |
1100 protected override void Paint(Graphics g) { | |
1101 base.Paint(g); | |
1102 g.DrawString(text, font, brush, new Rectangle(Point.Empty, Bounds.Size), stringformat); | |
1103 } | |
1104 public void Dispose() { | |
1105 stringformat.Dispose(); | |
1106 } | |
1107 protected override void Orphaned() { | |
1108 base.Orphaned(); | |
1109 Dispose(); | |
1110 } | |
1111 } | |
1112 public class FBGTextBox : FBGControl { | |
1113 public FBGTextBox(IFBGContainerControl parent) : base(parent) { | |
1114 BackColor = Color.White; | |
1115 Size = new Size(200, 20); | |
1116 } | |
1117 private String text = String.Empty; | |
1118 private Char passwordChar = (Char)0; | |
1119 private Font font = new Font(FontFamily.GenericMonospace, 10); | |
1120 private Brush brush = SystemBrushes.ControlText; | |
1121 private Boolean hasKeyboardFocus = false; | |
1122 public String Text { get { return text; } set { text = value; if (CaretPosition > text.Length) CaretPosition = text.Length; Invalidate(); RaiseEvent(TextChanged); } } | |
1123 public Font Font { get { return font; } set { font = value; Invalidate(); } } | |
1124 public Brush Brush { get { return brush; } set { brush = value; Invalidate(); } } | |
1125 public Color Color { set { Brush = new SolidBrush(value); } } | |
1126 public Int32 CaretPosition { get; private set; } | |
1127 public Char PasswordChar { get { return passwordChar; } set { passwordChar = value; Invalidate(); } } | |
1128 public event EventHandler TextChanged; | |
1129 public event KeyPressEventHandler OnKeyPress; | |
1130 protected override void Paint(Graphics g) { | |
1131 base.Paint(g); | |
1132 g.DrawRectangle(Pens.Gray, 0, 0, Bounds.Width - 1, Bounds.Height - 1); | |
1133 using (StringFormat sf_nonprinting = new StringFormat(StringFormat.GenericTypographic)) { | |
1134 sf_nonprinting.Trimming = StringTrimming.None; | |
1135 sf_nonprinting.FormatFlags = StringFormatFlags.DisplayFormatControl | StringFormatFlags.MeasureTrailingSpaces; | |
1136 sf_nonprinting.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.None; | |
1137 | |
1138 float x = 1; | |
1139 float y = 1; | |
1140 float w = Width - 2; | |
1141 if (hasKeyboardFocus && CaretPosition == 0) { | |
1142 g.DrawLine(Pens.Black, x + 2, 2, x + 2, Height - 4); | |
1143 } | |
1144 String c = passwordChar == 0 ? null : new String(passwordChar, 1); | |
1145 for (int i = 0; i < text.Length; i++) { | |
1146 if (passwordChar == 0) c = text.Substring(i, 1); | |
1147 SizeF s = g.MeasureString(c, font, (int)Math.Ceiling(w), sf_nonprinting); | |
1148 g.DrawString(c, font, brush, x, y); | |
1149 x += (float)Math.Ceiling(s.Width); | |
1150 w -= (float)Math.Ceiling(s.Width); | |
1151 | |
1152 if (hasKeyboardFocus && i == CaretPosition - 1) { | |
1153 g.DrawLine(Pens.Black, x + 2, 2, x + 2, Height - 4); | |
1154 } | |
1155 } | |
1156 } | |
1157 } | |
1158 protected override void MouseDown(Point position, MouseButtons buttons) { | |
1159 hasKeyboardFocus = CaptureKeyboard(true); | |
1160 CaretPosition = text.Length; | |
1161 float x = 1; | |
1162 String c = passwordChar == 0 ? null : new String(passwordChar, 1); | |
1163 for (int i = 0; i < text.Length; i++) { | |
1164 if (passwordChar == 0) c = text.Substring(i, 1); | |
1165 Size s; | |
1166 try { | |
1167 s = TextRenderer.MeasureText(c, font, Size.Empty, TextFormatFlags.NoPadding | TextFormatFlags.NoPrefix); | |
1168 } catch (Exception) { | |
1169 break; | |
1170 } | |
1171 x += s.Width; | |
1172 if (position.X < x) { | |
1173 CaretPosition = i; | |
1174 break; | |
1175 } | |
1176 } | |
1177 Invalidate(); | |
1178 } | |
1179 protected override void KeyDown(Keys key) { | |
1180 if ((key & Keys.KeyCode) == Keys.Left) { | |
1181 CaretPosition--; | |
1182 if (CaretPosition < 0) CaretPosition = 0; | |
1183 Invalidate(); | |
1184 } else if ((key & Keys.KeyCode) == Keys.Right) { | |
1185 CaretPosition++; | |
1186 if (CaretPosition > text.Length) CaretPosition = text.Length; | |
1187 Invalidate(); | |
1188 } else if ((key & Keys.KeyCode) == Keys.Home) { | |
1189 CaretPosition = 0; | |
1190 Invalidate(); | |
1191 } else if ((key & Keys.KeyCode) == Keys.End) { | |
1192 CaretPosition = text.Length; | |
1193 Invalidate(); | |
1194 } else if ((key & Keys.Control) != 0 && (key & Keys.KeyCode) == Keys.V) { | |
1195 String cbtext = Clipboard.GetText(TextDataFormat.UnicodeText); | |
1196 CaretPosition += cbtext.Length; | |
1197 Text = Text.Insert(CaretPosition - cbtext.Length, cbtext); | |
1198 } | |
1199 } | |
1200 protected override void KeyPress(char keyChar) { | |
1201 KeyPressEventArgs e = new KeyPressEventArgs(keyChar); | |
1202 RaiseEvent(OnKeyPress, e); | |
1203 if (e.Handled) return; | |
1204 hasKeyboardFocus = true; | |
1205 if (keyChar == 8) { | |
1206 if (CaretPosition > 0) { | |
1207 CaretPosition--; | |
1208 Text = Text.Remove(CaretPosition, 1); | |
1209 } | |
1210 } else if (keyChar == 127) { | |
1211 if (CaretPosition < Text.Length) { | |
1212 Text = Text.Remove(CaretPosition, 1); | |
1213 } | |
1214 } else if (keyChar < 32) { | |
1215 } else { | |
1216 CaretPosition++; | |
1217 Text = Text.Insert(CaretPosition - 1, new String(keyChar, 1)); | |
1218 } | |
1219 } | |
1220 public void Focus() { | |
1221 hasKeyboardFocus = CaptureKeyboard(true); | |
1222 } | |
1223 protected override void LostKeyboardCapture() { | |
1224 base.LostKeyboardCapture(); | |
1225 hasKeyboardFocus = false; | |
1226 Invalidate(); | |
1227 } | |
1228 } | |
1229 public class FBGButton : FBGControl { | |
1230 public FBGButton(IFBGContainerControl parent) : base(parent) { | |
1231 BackColor = SystemColors.ButtonFace; | |
1232 } | |
1233 private String text = String.Empty; | |
1234 private Font font = SystemFonts.DefaultFont; | |
1235 private Color color = SystemColors.ControlText; | |
1236 private Boolean pressed = false; | |
1237 private Boolean enabled = true; | |
1238 public String Text { get { return text; } set { text = value; Invalidate(); } } | |
1239 public Font Font { get { return font; } set { font = value; Invalidate(); } } | |
1240 public Color Color { get { return color; } set { color = value; Invalidate(); } } | |
1241 public Boolean Enabled { get { return enabled; } set { enabled = value; Invalidate(); } } | |
1242 public event EventHandler Click; | |
1243 protected override void Paint(Graphics g) { | |
1244 base.Paint(g); | |
1245 if (Bounds.Width == 0 || Bounds.Height == 0) return; | |
1246 if (BackColor == SystemColors.ButtonFace) { | |
1247 ControlPaint.DrawButton(g, new Rectangle(0, 0, Bounds.Width, Bounds.Height), enabled ? (pressed ? ButtonState.Pushed : ButtonState.Normal) : ButtonState.Inactive); | |
1248 } else { | |
1249 //Hackish and not completely right... | |
1250 //Todo: borrowed from mono... possible licencing issues!? | |
1251 g.DrawLine(new Pen(ControlPaint.LightLight(BackColor)), 0, 0, Bounds.Width, 0); | |
1252 g.DrawLine(new Pen(ControlPaint.LightLight(BackColor)), 0, 0, 0, Bounds.Height); | |
1253 g.DrawLine(new Pen(ControlPaint.Dark(BackColor)), 1, Bounds.Height - 2, Bounds.Width - 1, Bounds.Height - 2); | |
1254 g.DrawLine(new Pen(ControlPaint.Dark(BackColor)), Bounds.Width - 2, 1, Bounds.Width - 2, Bounds.Height - 2); | |
1255 g.DrawLine(new Pen(ControlPaint.DarkDark(BackColor)), 0, Bounds.Height - 1, Bounds.Width, Bounds.Height - 1); | |
1256 g.DrawLine(new Pen(ControlPaint.DarkDark(BackColor)), Bounds.Width - 1, 1, Bounds.Width - 1, Bounds.Height - 1); | |
1257 Graphics dc = g; | |
1258 Rectangle rectangle = new Rectangle(0, 0, Bounds.Width - 1, Bounds.Height - 1); | |
1259 Color ColorControl = BackColor; | |
1260 Color ColorControlLight = ControlPaint.Light(ColorControl); | |
1261 ButtonState state = pressed ? ButtonState.Pushed : ButtonState.Normal; | |
1262 using (Pen NormalPen = new Pen(BackColor), LightPen = new Pen(ControlPaint.Light(BackColor)), DarkPen = new Pen(ControlPaint.Dark(BackColor))) { | |
1263 // sadly enough, the rectangle gets always filled with a hatchbrush | |
1264 using (HatchBrush hb = new HatchBrush(HatchStyle.Percent50, Color.FromArgb(Math.Min(255, ColorControl.R + 3), ColorControl.G, ColorControl.B), ColorControl)) { | |
1265 dc.FillRectangle(hb, rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2); | |
1266 } | |
1267 if ((state & ButtonState.All) == ButtonState.All || ((state & ButtonState.Checked) == ButtonState.Checked && (state & ButtonState.Flat) == ButtonState.Flat)) { | |
1268 using (HatchBrush hb = new HatchBrush(HatchStyle.Percent50, ColorControlLight, ColorControl)) { | |
1269 dc.FillRectangle(hb, rectangle.X + 2, rectangle.Y + 2, rectangle.Width - 4, rectangle.Height - 4); | |
1270 } | |
1271 dc.DrawRectangle(SystemPens.ControlDark, rectangle.X, rectangle.Y, rectangle.Width - 1, rectangle.Height - 1); | |
1272 } else if ((state & ButtonState.Flat) == ButtonState.Flat) { | |
1273 dc.DrawRectangle(SystemPens.ControlDark, rectangle.X, rectangle.Y, rectangle.Width - 1, rectangle.Height - 1); | |
1274 } else if ((state & ButtonState.Checked) == ButtonState.Checked) { | |
1275 using (HatchBrush hb = new HatchBrush(HatchStyle.Percent50, ColorControlLight, ColorControl)) { | |
1276 dc.FillRectangle(hb, rectangle.X + 2, rectangle.Y + 2, rectangle.Width - 4, rectangle.Height - 4); | |
1277 } | |
1278 Pen pen = DarkPen; | |
1279 dc.DrawLine(pen, rectangle.X, rectangle.Y, rectangle.X, rectangle.Bottom - 2); | |
1280 dc.DrawLine(pen, rectangle.X + 1, rectangle.Y, rectangle.Right - 2, rectangle.Y); | |
1281 | |
1282 pen = NormalPen; | |
1283 dc.DrawLine(pen, rectangle.X + 1, rectangle.Y + 1, rectangle.X + 1, rectangle.Bottom - 3); | |
1284 dc.DrawLine(pen, rectangle.X + 2, rectangle.Y + 1, rectangle.Right - 3, rectangle.Y + 1); | |
1285 | |
1286 pen = LightPen; | |
1287 dc.DrawLine(pen, rectangle.X, rectangle.Bottom - 1, rectangle.Right - 2, rectangle.Bottom - 1); | |
1288 dc.DrawLine(pen, rectangle.Right - 1, rectangle.Y, rectangle.Right - 1, rectangle.Bottom - 1); | |
1289 } else if (((state & ButtonState.Pushed) == ButtonState.Pushed) && ((state & ButtonState.Normal) == ButtonState.Normal)) { | |
1290 Pen pen = DarkPen; | |
1291 dc.DrawLine(pen, rectangle.X, rectangle.Y, rectangle.X, rectangle.Bottom - 2); | |
1292 dc.DrawLine(pen, rectangle.X + 1, rectangle.Y, rectangle.Right - 2, rectangle.Y); | |
1293 | |
1294 pen = NormalPen; | |
1295 dc.DrawLine(pen, rectangle.X + 1, rectangle.Y + 1, rectangle.X + 1, rectangle.Bottom - 3); | |
1296 dc.DrawLine(pen, rectangle.X + 2, rectangle.Y + 1, rectangle.Right - 3, rectangle.Y + 1); | |
1297 | |
1298 pen = LightPen; | |
1299 dc.DrawLine(pen, rectangle.X, rectangle.Bottom - 1, rectangle.Right - 2, rectangle.Bottom - 1); | |
1300 dc.DrawLine(pen, rectangle.Right - 1, rectangle.Y, rectangle.Right - 1, rectangle.Bottom - 1); | |
1301 } else if (((state & ButtonState.Inactive) == ButtonState.Inactive) || ((state & ButtonState.Normal) == ButtonState.Normal)) { | |
1302 Pen pen = LightPen; | |
1303 dc.DrawLine(pen, rectangle.X, rectangle.Y, rectangle.Right - 2, rectangle.Y); | |
1304 dc.DrawLine(pen, rectangle.X, rectangle.Y, rectangle.X, rectangle.Bottom - 2); | |
1305 | |
1306 pen = NormalPen; | |
1307 dc.DrawLine(pen, rectangle.X + 1, rectangle.Bottom - 2, rectangle.Right - 2, rectangle.Bottom - 2); | |
1308 dc.DrawLine(pen, rectangle.Right - 2, rectangle.Y + 1, rectangle.Right - 2, rectangle.Bottom - 3); | |
1309 | |
1310 pen = DarkPen; | |
1311 dc.DrawLine(pen, rectangle.X, rectangle.Bottom - 1, rectangle.Right - 1, rectangle.Bottom - 1); | |
1312 dc.DrawLine(pen, rectangle.Right - 1, rectangle.Y, rectangle.Right - 1, rectangle.Bottom - 2); | |
1313 } | |
1314 } | |
1315 } | |
1316 Rectangle frect = new Rectangle(Point.Empty, Bounds.Size); | |
1317 SizeF textsize = g.MeasureString(Text, Font); | |
1318 using (Brush b = new SolidBrush(enabled ? Color : Color.DarkGray)) { | |
1319 g.DrawString(Text, Font, b, new PointF(Bounds.Width / 2.0f - textsize.Width / 2.0f, Bounds.Height / 2.0f - textsize.Height / 2.0f)); | |
1320 } | |
1321 } | |
1322 protected override void MouseDown(Point position, MouseButtons buttons) { | |
1323 pressed = true; | |
1324 Invalidate(); | |
1325 CaptureMouse(true); | |
1326 base.MouseDown(position, buttons); | |
1327 } | |
1328 protected override void MouseUp(Point position, MouseButtons buttons) { | |
1329 pressed = false; | |
1330 Invalidate(); | |
1331 CaptureMouse(false); | |
1332 if (position.X >= 0 && position.X <= Bounds.Width && position.Y >= 0 && position.Y <= Bounds.Height && enabled) RaiseEvent(Click); | |
1333 base.MouseUp(position, buttons); | |
1334 } | |
1335 protected override void KeyDown(Keys key) { | |
1336 if (key == Keys.Return || key == Keys.Space) { | |
1337 pressed = true; | |
1338 Invalidate(); | |
1339 } | |
1340 base.KeyDown(key); | |
1341 } | |
1342 protected override void KeyUp(Keys key) { | |
1343 if (key == Keys.Return || key == Keys.Space) { | |
1344 if (pressed) RaiseEvent(Click); | |
1345 pressed = false; | |
1346 Invalidate(); | |
1347 } | |
1348 base.KeyUp(key); | |
1349 } | |
1350 public void Focus() { | |
1351 CaptureKeyboard(true); | |
1352 } | |
1353 } | |
1354 public class FBGCheckBox : FBGControl { | |
1355 public FBGCheckBox(IFBGContainerControl parent) : base(parent) { } | |
1356 private String text = String.Empty; | |
1357 private Font font = SystemFonts.DefaultFont; | |
1358 private Color color = SystemColors.ControlText; | |
1359 private Boolean _checked = false; | |
1360 public String Text { get { return text; } set { text = value; Invalidate(); } } | |
1361 public Font Font { get { return font; } set { font = value; Invalidate(); } } | |
1362 public Color Color { get { return color; } set { color = value; Invalidate(); } } | |
1363 public Boolean Checked { get { return _checked; } set { _checked = value; Invalidate(); } } | |
1364 public event EventHandler CheckedChanged; | |
1365 protected override void Paint(Graphics g) { | |
1366 base.Paint(g); | |
1367 ControlPaint.DrawCheckBox(g, 0, 0, 13, 13, _checked ? ButtonState.Checked : ButtonState.Normal); | |
1368 g.DrawString(Text, Font, new SolidBrush(Color), 15, 0); | |
1369 } | |
1370 protected override void MouseDown(Point position, MouseButtons buttons) { | |
1371 Checked = !Checked; | |
1372 RaiseEvent(CheckedChanged); | |
1373 base.MouseDown(position, buttons); | |
1374 } | |
1375 } | |
1376 public class FBGImageBox : FBGControl { | |
1377 Image image = null; | |
33 | 1378 Image scaledImage = null; |
1379 Size imageSize; | |
1380 Boolean ownsImage = false; | |
34
70bde4fa6a2f
FBGUI: Fixed image scaling in FBGImageBox
Ivo Smits <Ivo@UCIS.nl>
parents:
33
diff
changeset
|
1381 Boolean shouldScaleImage = false; |
23 | 1382 PictureBoxSizeMode sizeMode = PictureBoxSizeMode.Normal; |
1383 Rectangle imageRect; | |
33 | 1384 public Image Image { get { return image; } set { SetImage(value, false); } } |
1385 public Boolean PreScaleImage { get; set; } | |
1386 public void SetOwnedImage(Image img) { SetImage(img, true); } | |
1387 private void SetImage(Image img, Boolean owned) { | |
1388 image = img; | |
1389 imageSize = img == null ? Size.Empty : img.Size; | |
1390 ownsImage = owned; | |
1391 UpdateImageRect(Size.Empty); | |
1392 } | |
23 | 1393 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
|
1394 public PictureBoxSizeMode SizeMode { get { return sizeMode; } set { sizeMode = value; UpdateImageRect(Size.Empty); } } |
23 | 1395 public override Rectangle Bounds { |
1396 get { | |
1397 return base.Bounds; | |
1398 } | |
1399 set { | |
33 | 1400 if (Bounds.Size != value.Size) UpdateImageRect(value.Size); |
23 | 1401 base.Bounds = value; |
1402 } | |
1403 } | |
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 private void UpdateImageRect(Size csize) { |
34
70bde4fa6a2f
FBGUI: Fixed image scaling in FBGImageBox
Ivo Smits <Ivo@UCIS.nl>
parents:
33
diff
changeset
|
1405 shouldScaleImage = false; |
70bde4fa6a2f
FBGUI: Fixed image scaling in FBGImageBox
Ivo Smits <Ivo@UCIS.nl>
parents:
33
diff
changeset
|
1406 if (scaledImage != null) scaledImage.Dispose(); |
33 | 1407 scaledImage = null; |
23 | 1408 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
|
1409 Boolean boundsset = !csize.IsEmpty; |
23 | 1410 if (!boundsset && sizeMode == PictureBoxSizeMode.AutoSize) { |
33 | 1411 Size = imageSize; |
23 | 1412 return; |
1413 } | |
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
|
1414 if (!boundsset) csize = Bounds.Size; |
23 | 1415 switch (sizeMode) { |
1416 case PictureBoxSizeMode.AutoSize: | |
1417 case PictureBoxSizeMode.Normal: | |
33 | 1418 imageRect = new Rectangle(Point.Empty, imageSize); |
23 | 1419 break; |
1420 case PictureBoxSizeMode.CenterImage: | |
33 | 1421 imageRect = new Rectangle(csize.Width / 2 - imageSize.Width / 2, csize.Height / 2 - imageSize.Height / 2, imageSize.Width, imageSize.Height); |
23 | 1422 break; |
1423 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
|
1424 imageRect = new Rectangle(Point.Empty, csize); |
23 | 1425 break; |
1426 case PictureBoxSizeMode.Zoom: | |
33 | 1427 float xrat = (float)csize.Width / (float)imageSize.Width; |
1428 float yrat = (float)csize.Height / (float)imageSize.Height; | |
23 | 1429 float rat = Math.Min(xrat, yrat); |
33 | 1430 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
|
1431 imageRect = Rectangle.Round(new RectangleF(csize.Width / 2f - dispsize.Width / 2f, csize.Height / 2f - dispsize.Height / 2f, dispsize.Width, dispsize.Height)); |
23 | 1432 break; |
1433 } | |
34
70bde4fa6a2f
FBGUI: Fixed image scaling in FBGImageBox
Ivo Smits <Ivo@UCIS.nl>
parents:
33
diff
changeset
|
1434 shouldScaleImage = imageRect.Size != imageSize; |
23 | 1435 if (!boundsset) Invalidate(); |
1436 } | |
1437 protected override void Paint(Graphics g) { | |
1438 if (!Visible) return; | |
1439 base.Paint(g); | |
34
70bde4fa6a2f
FBGUI: Fixed image scaling in FBGImageBox
Ivo Smits <Ivo@UCIS.nl>
parents:
33
diff
changeset
|
1440 if (shouldScaleImage && PreScaleImage && image != null) { |
70bde4fa6a2f
FBGUI: Fixed image scaling in FBGImageBox
Ivo Smits <Ivo@UCIS.nl>
parents:
33
diff
changeset
|
1441 scaledImage = new Bitmap(image, imageRect.Size); |
70bde4fa6a2f
FBGUI: Fixed image scaling in FBGImageBox
Ivo Smits <Ivo@UCIS.nl>
parents:
33
diff
changeset
|
1442 shouldScaleImage = false; |
70bde4fa6a2f
FBGUI: Fixed image scaling in FBGImageBox
Ivo Smits <Ivo@UCIS.nl>
parents:
33
diff
changeset
|
1443 } |
70bde4fa6a2f
FBGUI: Fixed image scaling in FBGImageBox
Ivo Smits <Ivo@UCIS.nl>
parents:
33
diff
changeset
|
1444 if (scaledImage != null) g.DrawImage(scaledImage, imageRect); |
70bde4fa6a2f
FBGUI: Fixed image scaling in FBGImageBox
Ivo Smits <Ivo@UCIS.nl>
parents:
33
diff
changeset
|
1445 else if (image != null) g.DrawImage(image, imageRect); |
23 | 1446 } |
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
|
1447 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
|
1448 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
|
1449 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
|
1450 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
|
1451 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
|
1452 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
|
1453 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
|
1454 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
|
1455 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
|
1456 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
|
1457 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
|
1458 default: |
33 | 1459 point.X = (point.X - imageRect.X) * imageSize.Width / imageRect.Width; |
1460 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
|
1461 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
|
1462 } |
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
|
1463 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
|
1464 } |
33 | 1465 protected override void Orphaned() { |
1466 base.Orphaned(); | |
1467 if (scaledImage != null && scaledImage != image) scaledImage.Dispose(); | |
1468 scaledImage = null; | |
1469 if (ownsImage) { | |
1470 image.Dispose(); | |
1471 image = null; | |
1472 } | |
1473 } | |
23 | 1474 } |
1475 public class FBGListBox : FBGControl { | |
1476 private List<Object> items = new List<object>(); | |
1477 private Object selected = null; | |
1478 private Object highlighted = null; | |
1479 private Boolean hasScrollBar = false; | |
1480 private Boolean hitScrollBar = false; | |
1481 private int offset = 0; | |
1482 private ButtonState buttonUpState = ButtonState.Normal; | |
1483 private ButtonState buttonDownState = ButtonState.Normal; | |
1484 private Converter<Object, String> itemFormatter = null; | |
1485 public Converter<Object, String> ItemFormatter { get { return itemFormatter; } set { itemFormatter = value; Invalidate(); } } | |
1486 public FBGListBox(IFBGContainerControl parent) | |
1487 : base(parent) { | |
1488 BackColor = Color.White; | |
1489 } | |
1490 public void AddItem(Object item) { | |
1491 items.Add(item); | |
1492 Invalidate(); | |
1493 } | |
1494 protected override void Paint(Graphics g) { | |
1495 base.Paint(g); | |
1496 g.DrawRectangle(Pens.DarkBlue, 0, 0, Bounds.Width - 1, Bounds.Height - 1); | |
1497 int lh = (int)Math.Ceiling(SystemFonts.DefaultFont.GetHeight()); | |
1498 int th = lh * items.Count; | |
1499 int y = 2; | |
1500 using (Pen dottedpen = new Pen(Brushes.Black)) { | |
1501 dottedpen.DashStyle = DashStyle.Dot; | |
1502 using (StringFormat sf = new StringFormat(StringFormatFlags.NoWrap)) { | |
1503 for (int i = offset; i < items.Count; i++) { | |
1504 Object item = items[i]; | |
1505 String text = itemFormatter == null ? (item == null ? String.Empty : item.ToString()) : itemFormatter(item); | |
1506 if (item == selected) g.FillRectangle(Brushes.DarkGray, 2, y, Bounds.Width - 4, lh); | |
1507 if (item == highlighted) g.DrawRectangle(dottedpen, 2, y, Bounds.Width - 5, lh - 1); | |
1508 g.DrawString(text, SystemFonts.DefaultFont, SystemBrushes.WindowText, new Rectangle(3, y, Bounds.Width - 6, lh), sf); | |
1509 y += lh; | |
1510 if (y + lh + 2 >= Bounds.Height) break; | |
1511 } | |
1512 } | |
1513 } | |
1514 if (y < th) hasScrollBar = true; | |
1515 if (hasScrollBar) { | |
1516 int xoff = Bounds.Width - 17; | |
1517 using (Brush b = new LinearGradientBrush(new Rectangle(xoff, 0, 17, 1), Color.LightGray, Color.White, LinearGradientMode.Horizontal)) | |
1518 g.FillRectangle(b, xoff, 17, 16, Bounds.Height - 17 - 17); | |
1519 ControlPaint.DrawScrollButton(g, xoff, 1, 16, 16, ScrollButton.Up, buttonUpState); | |
1520 ControlPaint.DrawScrollButton(g, xoff, Bounds.Height - 17, 16, 16, ScrollButton.Down, buttonDownState); | |
1521 g.DrawRectangle(Pens.Black, new Rectangle(xoff, 17 + offset * (Bounds.Height - 17 - 17 - 20) / (items.Count - 1), 15, 20)); | |
1522 } | |
1523 } | |
1524 protected override void MouseDown(Point position, MouseButtons buttons) { | |
1525 if ((buttons & MouseButtons.Left) != 0) { | |
1526 CaptureMouse(true); | |
1527 if (hasScrollBar && position.X > Bounds.Width - 17) { | |
1528 hitScrollBar = true; | |
1529 if (position.Y < 17) { | |
1530 offset--; | |
1531 buttonUpState = ButtonState.Pushed; | |
1532 } else if (position.Y > Bounds.Height - 17) { | |
1533 offset++; | |
1534 buttonDownState = ButtonState.Pushed; | |
1535 } else { | |
1536 offset = (int)Math.Round((position.Y - 17) * (items.Count - 1) / (double)(Bounds.Height - 17 - 17 - 10)); | |
1537 } | |
1538 if (offset < 0) offset = 0; | |
1539 if (offset >= items.Count) offset = items.Count - 1; | |
1540 Invalidate(); | |
1541 } else { | |
1542 MouseHandler(position, buttons); | |
1543 } | |
1544 } | |
1545 } | |
1546 protected override void MouseMove(Point position, MouseButtons buttons) { | |
1547 if (hitScrollBar) { | |
1548 if (position.Y < 17) { | |
1549 } else if (position.Y > Bounds.Height - 17) { | |
1550 } else { | |
1551 offset = (int)Math.Round((position.Y - 17) * (items.Count - 1) / (double)(Bounds.Height - 17 - 17 - 10)); | |
1552 if (offset < 0) offset = 0; | |
1553 if (offset >= items.Count) offset = items.Count - 1; | |
1554 Invalidate(); | |
1555 } | |
1556 return; | |
1557 } | |
1558 MouseHandler(position, buttons); | |
1559 } | |
1560 protected override void MouseUp(Point position, MouseButtons buttons) { | |
1561 if ((buttons & MouseButtons.Left) != 0) { | |
1562 CaptureMouse(false); | |
1563 buttonUpState = buttonDownState = ButtonState.Normal; | |
1564 Invalidate(); | |
1565 if (hitScrollBar) { | |
1566 hitScrollBar = false; | |
1567 return; | |
1568 } | |
1569 } | |
1570 if (hitScrollBar) return; | |
1571 MouseHandler(position, buttons); | |
1572 } | |
1573 private void MouseHandler(Point position, MouseButtons buttons) { | |
1574 if ((buttons & MouseButtons.Left) != 0) { | |
1575 int lh = (int)Math.Ceiling(SystemFonts.DefaultFont.GetHeight()); | |
1576 int i = (position.Y - 2) / lh + offset; | |
1577 if (i < 0) i = 0; | |
1578 if (i >= items.Count) i = items.Count - 1; | |
1579 Boolean changed = false; | |
1580 Object current = items[i]; | |
1581 if (!ReferenceEquals(highlighted, current)) changed = true; | |
1582 highlighted = current; | |
1583 if ((new Rectangle(Point.Empty, Bounds.Size)).Contains(position)) { | |
1584 if (!ReferenceEquals(selected, current)) changed = true; | |
1585 selected = current; | |
1586 } | |
1587 if (changed) Invalidate(); | |
1588 } | |
1589 } | |
1590 } | |
27
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1591 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
|
1592 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
|
1593 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
|
1594 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
|
1595 BackColor = Color.White; |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1596 Height = 25; |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1597 } |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1598 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
|
1599 base.Paint(g); |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1600 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
|
1601 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
|
1602 String text = SelectedText; |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1603 if (text == null) { |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1604 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
|
1605 } else { |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1606 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
|
1607 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
|
1608 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
|
1609 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
|
1610 } |
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 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
|
1613 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
|
1614 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
|
1615 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
|
1616 } |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1617 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
|
1618 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
|
1619 CaptureKeyboard(true); |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1620 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
|
1621 CaptureMouse(true); |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1622 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
|
1623 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
|
1624 buttonUpState = ButtonState.Pushed; |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1625 ButtonPressUp(); |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1626 } else { |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1627 buttonDownState = ButtonState.Pushed; |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1628 ButtonPressDown(); |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1629 } |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1630 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
|
1631 } |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1632 } |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1633 } |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1634 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
|
1635 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
|
1636 CaptureMouse(false); |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1637 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
|
1638 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
|
1639 } |
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 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
|
1642 base.KeyDown(key); |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1643 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
|
1644 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
|
1645 } |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1646 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
|
1647 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
|
1648 } |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1649 public class FBGDomainUpDown : FBGUpDownControlBase { |
23 | 1650 private List<Object> items = new List<object>(); |
1651 private int selectedIndex = -1; | |
1652 private Converter<Object, String> itemFormatter = null; | |
1653 public Boolean AllowSelectEmpty { get; set; } | |
1654 public Converter<Object, String> ItemFormatter { get { return itemFormatter; } set { itemFormatter = value; Invalidate(); } } | |
1655 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
|
1656 public FBGDomainUpDown(IFBGContainerControl parent) : base(parent) { } |
23 | 1657 public void AddItem(Object item) { |
1658 items.Add(item); | |
1659 Invalidate(); | |
1660 } | |
1661 public void RemoveItem(Object item) { | |
1662 items.Remove(item); | |
1663 FixSelectedIndex(0); | |
1664 } | |
1665 public void RemoveItem(int index) { | |
1666 items.RemoveAt(index); | |
1667 FixSelectedIndex(0); | |
1668 } | |
1669 public int SelectedIndex { | |
1670 get { return selectedIndex; } | |
1671 set { | |
1672 if (value < -2 || value >= items.Count) throw new ArgumentOutOfRangeException("value", "Value must be between -1 and the number of items minus one"); | |
1673 if (selectedIndex == value) return; | |
1674 selectedIndex = value; | |
1675 Invalidate(); | |
1676 RaiseEvent(SelectedIndexChanged); | |
1677 } | |
1678 } | |
1679 public Object SelectedItem { | |
1680 get { return selectedIndex == -1 ? null : items[selectedIndex]; } | |
1681 set { | |
1682 if (value == null) { | |
1683 SelectedIndex = -1; | |
1684 } else { | |
1685 for (int i = 0; i < items.Count; i++) { | |
1686 if (items[i] == value) { | |
1687 SelectedIndex = i; | |
1688 break; | |
1689 } | |
1690 } | |
1691 } | |
1692 } | |
1693 } | |
27
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1694 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
|
1695 get { |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1696 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
|
1697 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
|
1698 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
|
1699 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
|
1700 return item.ToString(); |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1701 } |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1702 } |
23 | 1703 private void FixSelectedIndex(int change) { |
1704 int value = selectedIndex; | |
1705 if (value == 0 && change == -1 && !AllowSelectEmpty) change = 0; | |
1706 value += change; | |
1707 if (value < -1) value = -1; | |
1708 if (value >= items.Count) value = items.Count - 1; | |
1709 SelectedIndex = value; | |
1710 } | |
27
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1711 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
|
1712 FixSelectedIndex(1); |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1713 } |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1714 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
|
1715 FixSelectedIndex(-1); |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1716 } |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1717 } |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1718 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
|
1719 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
|
1720 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
|
1721 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
|
1722 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
|
1723 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
|
1724 public int Value { |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1725 get { return value; } |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1726 set { if (this.value == value) return; this.value = value; Invalidate(); RaiseEvent(SelectedValueChanged); } |
23 | 1727 } |
27
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1728 public int Minimum { |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1729 get { return minimum; } |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1730 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
|
1731 } |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1732 public int Maximum { |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1733 get { return maximum; } |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1734 set { maximum = value; if (this.value > maximum) this.Value = maximum; } |
23 | 1735 } |
27
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1736 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
|
1737 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
|
1738 get { return value.ToString(); } |
23 | 1739 } |
27
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1740 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
|
1741 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
|
1742 } |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
1743 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
|
1744 Value = Math.Min(maximum, value + Step); |
23 | 1745 } |
1746 } | |
1747 public interface IFBGTreeParent { | |
1748 FBGTreeView TreeView { get; } | |
1749 int Depth { get; } | |
1750 void AddChild(FBGTreeNode node); | |
1751 void RemoveChild(FBGTreeNode node); | |
1752 } | |
1753 public class FBGTreeNode : IFBGTreeParent { | |
1754 private List<FBGTreeNode> children = new List<FBGTreeNode>(); | |
1755 private Boolean expanded = true; | |
1756 private Boolean hasCheckBox = false; | |
1757 private Boolean isChecked = false; | |
1758 private Object item; | |
1759 | |
1760 public FBGTreeView TreeView { get; private set; } | |
1761 public int Depth { get; private set; } | |
1762 public Object Tag { get; set; } | |
1763 public IFBGTreeParent Parent { get; private set; } | |
1764 | |
1765 public IList<FBGTreeNode> Children { get { return children.AsReadOnly(); } } | |
1766 | |
1767 public Object Item { | |
1768 get { return item; } | |
1769 set { | |
1770 item = value; | |
1771 Invalidate(); | |
1772 } | |
1773 } | |
1774 public Boolean Expanded { | |
1775 get { return expanded; } | |
1776 set { | |
1777 if (expanded == value) return; | |
1778 expanded = value; | |
1779 UpdateTree(); | |
1780 } | |
1781 } | |
1782 public Boolean HasCheckBox { | |
1783 get { return hasCheckBox; } | |
1784 set { | |
1785 if (hasCheckBox == value) return; | |
1786 hasCheckBox = value; | |
1787 Invalidate(); | |
1788 } | |
1789 } | |
1790 public Boolean Checked { | |
1791 get { return isChecked; } | |
1792 set { | |
1793 if (isChecked == value) return; | |
1794 isChecked = value; | |
1795 Invalidate(); | |
1796 if (TreeView != null) TreeView.RaiseNodeCheckedChanged(this); | |
1797 } | |
1798 } | |
1799 | |
1800 public FBGTreeNode(IFBGTreeParent parent, Object item) { | |
1801 this.TreeView = parent.TreeView; | |
1802 this.Depth = parent.Depth + 1; | |
1803 this.Parent = parent; | |
1804 this.item = item; | |
1805 parent.AddChild(this); | |
1806 } | |
1807 | |
1808 public void Remove() { | |
1809 Parent.RemoveChild(this); | |
1810 } | |
1811 void IFBGTreeParent.AddChild(FBGTreeNode node) { | |
1812 children.Add(node); | |
1813 if (Expanded) UpdateTree(); | |
1814 else Invalidate(); | |
1815 } | |
1816 void IFBGTreeParent.RemoveChild(FBGTreeNode node) { | |
1817 children.Remove(node); | |
1818 TreeView.ReleaseNodeFromTree(node); | |
1819 if (Expanded) UpdateTree(); | |
1820 else Invalidate(); | |
1821 } | |
1822 public void Invalidate() { | |
1823 if (TreeView != null) TreeView.Invalidate(this); | |
1824 } | |
1825 private void UpdateTree() { | |
1826 if (TreeView != null) TreeView.UpdateView(); | |
1827 } | |
1828 public FBGTreeNode AddNode(Object item) { | |
1829 return new FBGTreeNode(this, item); | |
1830 } | |
1831 } | |
1832 public class FBGTreeView : FBGControl, IFBGTreeParent { | |
1833 private List<FBGTreeNode> items = new List<FBGTreeNode>(); | |
1834 private List<FBGTreeNode> itemsView = new List<FBGTreeNode>(); | |
1835 private FBGTreeNode selected = null; | |
1836 private FBGTreeNode highlighted = null; | |
1837 private Boolean hasScrollBar = false; | |
1838 private Boolean hitScrollBar = false; | |
1839 private int offset = 0; | |
1840 private ButtonState buttonUpState = ButtonState.Normal; | |
1841 private ButtonState buttonDownState = ButtonState.Normal; | |
1842 private Converter<Object, String> itemFormatter = null; | |
1843 | |
1844 public Converter<Object, String> ItemFormatter { get { return itemFormatter; } set { itemFormatter = value; Invalidate(); } } | |
1845 public FBGTreeNode SelectedNode { get { return selected; } set { if (selected != value) { selected = value; Invalidate(); RaiseEvent(SelectedNodeChanged); } } } | |
1846 public IList<FBGTreeNode> Nodes { get { return items.AsReadOnly(); } } | |
1847 | |
1848 public event EventHandler SelectedNodeChanged; | |
1849 public event EventHandler NodeCheckedChanged; | |
1850 | |
1851 public FBGTreeView(IFBGContainerControl parent) : base(parent) { | |
1852 BackColor = Color.White; | |
1853 } | |
1854 FBGTreeView IFBGTreeParent.TreeView { get { return this; } } | |
1855 int IFBGTreeParent.Depth { get { return -1; } } | |
1856 void IFBGTreeParent.AddChild(FBGTreeNode node) { | |
1857 items.Add(node); | |
1858 UpdateView(); | |
1859 } | |
1860 void IFBGTreeParent.RemoveChild(FBGTreeNode node) { | |
1861 items.Remove(node); | |
1862 ReleaseNodeFromTree(node); | |
1863 UpdateView(); | |
1864 } | |
1865 public FBGTreeNode AddNode(Object item) { return new FBGTreeNode(this, item); } | |
1866 internal void ReleaseNodeFromTree(FBGTreeNode node) { | |
1867 if (highlighted == node) highlighted = null; | |
1868 if (selected == node) SelectedNode = null; | |
1869 } | |
1870 internal void RaiseNodeCheckedChanged(FBGTreeNode node) { | |
1871 RaiseEvent(NodeCheckedChanged); | |
1872 } | |
1873 internal void UpdateView() { | |
1874 List<FBGTreeNode> newView = new List<FBGTreeNode>(); | |
1875 Stack<Queue<FBGTreeNode>> stack = new Stack<Queue<FBGTreeNode>>(); | |
1876 stack.Push(new Queue<FBGTreeNode>(items)); | |
1877 while (stack.Count > 0) { | |
1878 Queue<FBGTreeNode> list = stack.Peek(); | |
1879 if (list.Count == 0) { | |
1880 stack.Pop(); | |
1881 continue; | |
1882 } | |
1883 FBGTreeNode item = list.Dequeue(); | |
1884 newView.Add(item); | |
1885 if (item.Expanded) stack.Push(new Queue<FBGTreeNode>(item.Children)); | |
1886 } | |
1887 itemsView = newView; | |
1888 Invalidate(); | |
1889 } | |
1890 internal void Invalidate(FBGTreeNode node) { | |
1891 int i = itemsView.IndexOf(node); | |
1892 if (i == -1) return; | |
1893 int lh = (int)Math.Ceiling(SystemFonts.DefaultFont.GetHeight() / 2.0) * 2; | |
1894 Invalidate(new Rectangle(1, i * lh, Bounds.Width - 1, lh)); | |
1895 } | |
1896 protected override void Paint(Graphics g) { | |
1897 base.Paint(g); | |
1898 | |
1899 int lh = (int)Math.Ceiling(SystemFonts.DefaultFont.GetHeight() / 2.0) * 2; | |
1900 int th = lh * itemsView.Count; | |
1901 hasScrollBar = offset > 0 || th + 2 > Bounds.Height; | |
1902 int y = 2; | |
1903 using (Pen dottedpen = new Pen(Brushes.Black)) { | |
1904 dottedpen.DashStyle = DashStyle.Dot; | |
1905 using (StringFormat sf = new StringFormat(StringFormatFlags.NoWrap)) { | |
1906 int lw = Bounds.Width - 2; | |
1907 if (hasScrollBar) lw -= 17; | |
1908 for (int i = offset; i < itemsView.Count; i++) { | |
1909 FBGTreeNode item = itemsView[i]; | |
1910 if (y + 2 < Bounds.Height) { | |
1911 Object obj = item.Item; | |
1912 String text = itemFormatter == null ? (obj == null ? String.Empty : obj.ToString()) : itemFormatter(obj); | |
1913 if (item == selected) g.FillRectangle(Brushes.DarkGray, 2, y, lw - 2, lh); | |
1914 if (item == highlighted) g.DrawRectangle(dottedpen, 2, y, lw - 3, lh - 1); | |
1915 int x = 3 + 19 * item.Depth + 14; | |
1916 if (item.HasCheckBox) { | |
1917 x += 2; | |
1918 ControlPaint.DrawCheckBox(g, x, y, lh, lh, item.Checked ? ButtonState.Checked : ButtonState.Normal); | |
1919 x += lh + 1; | |
1920 } | |
1921 g.DrawString(text, SystemFonts.DefaultFont, SystemBrushes.WindowText, new Rectangle(x, y, lw - x, lh), sf); | |
1922 } | |
1923 int upto = y + 2 + 4 - 8; | |
1924 for (int j = i - 1; j >= 0; j--) { | |
1925 if (itemsView[j].Depth < item.Depth) { | |
1926 break; | |
1927 } | |
1928 if (itemsView[j].Depth == item.Depth) { | |
1929 if (itemsView[j].Children.Count > 0) { | |
1930 upto = 2 + lh * (j - offset) + 10; | |
1931 } else { | |
1932 upto = 2 + lh * (j - offset) + 6; | |
1933 } | |
1934 break; | |
1935 } | |
1936 if (j <= offset) { | |
1937 upto = 2 + 2 + 4 - 8; | |
1938 break; | |
1939 } | |
1940 } | |
1941 if (item.Children.Count > 0) { | |
1942 g.DrawRectangle(Pens.Black, 3 + 19 * item.Depth, y + 2, 8, 8); | |
1943 g.DrawLine(Pens.Black, 3 + 19 * item.Depth + 2, y + 2 + 4, 3 + 19 * item.Depth + 6, y + 2 + 4); | |
1944 if (!item.Expanded) g.DrawLine(Pens.Black, 3 + 19 * item.Depth + 4, y + 4, 3 + 19 * item.Depth + 4, y + 2 + 6); | |
1945 | |
1946 g.DrawLine(dottedpen, 3 + 19 * item.Depth + 8, y + 2 + 4, 3 + 19 * item.Depth + 14, y + 2 + 4); | |
1947 g.DrawLine(dottedpen, 3 + 19 * item.Depth + 4, y + 2 + 4 - 6, 3 + 19 * item.Depth + 4, upto); | |
1948 } else { | |
1949 g.DrawLine(dottedpen, 3 + 19 * item.Depth + 4, y + 2 + 4, 3 + 19 * item.Depth + 14, y + 2 + 4); | |
1950 g.DrawLine(dottedpen, 3 + 19 * item.Depth + 4, y + 2 + 4 - 2, 3 + 19 * item.Depth + 4, upto); | |
1951 } | |
1952 y += lh; | |
1953 //if (y + lh + 2 >= Bounds.Height && item.Depth == 0) break; | |
1954 if (y + 2 >= Bounds.Height && item.Depth == 0) break; | |
1955 } | |
1956 } | |
1957 } | |
1958 //if (y < th) hasScrollBar = true; | |
1959 //hasScrollBar = true; | |
1960 if (hasScrollBar) { | |
1961 int xoff = Bounds.Width - 17; | |
1962 using (Brush b = new LinearGradientBrush(new Rectangle(xoff, 0, 17, 1), Color.LightGray, Color.White, LinearGradientMode.Horizontal)) | |
1963 g.FillRectangle(b, xoff, 17, 16, Bounds.Height - 17 - 17); | |
1964 ControlPaint.DrawScrollButton(g, xoff, 1, 16, 16, ScrollButton.Up, buttonUpState); | |
1965 ControlPaint.DrawScrollButton(g, xoff, Bounds.Height - 17, 16, 16, ScrollButton.Down, buttonDownState); | |
1966 g.DrawRectangle(Pens.Black, new Rectangle(xoff, 17 + offset * (Bounds.Height - 17 - 17 - 20) / (itemsView.Count - 1), 15, 20)); | |
1967 } | |
1968 | |
1969 g.DrawRectangle(Pens.DarkBlue, 0, 0, Bounds.Width - 1, Bounds.Height - 1); | |
1970 } | |
1971 protected override void MouseDown(Point position, MouseButtons buttons) { | |
1972 CaptureKeyboard(true); | |
1973 if ((buttons & MouseButtons.Left) != 0) { | |
1974 CaptureMouse(true); | |
1975 if (hasScrollBar && position.X > Bounds.Width - 17) { | |
1976 hitScrollBar = true; | |
1977 if (position.Y < 17) { | |
1978 offset--; | |
1979 buttonUpState = ButtonState.Pushed; | |
1980 } else if (position.Y > Bounds.Height - 17) { | |
1981 offset++; | |
1982 buttonDownState = ButtonState.Pushed; | |
1983 } else { | |
1984 offset = (int)Math.Round((position.Y - 17) * (itemsView.Count - 1) / (double)(Bounds.Height - 17 - 17 - 10)); | |
1985 } | |
1986 if (offset < 0) offset = 0; | |
1987 if (offset >= itemsView.Count) offset = itemsView.Count - 1; | |
1988 Invalidate(); | |
1989 } else { | |
1990 MouseHandler(position, buttons, true); | |
1991 } | |
1992 } | |
1993 } | |
1994 protected override void MouseMove(Point position, MouseButtons buttons) { | |
1995 if (hitScrollBar) { | |
1996 if (position.Y < 17) { | |
1997 } else if (position.Y > Bounds.Height - 17) { | |
1998 } else { | |
1999 offset = (int)Math.Round((position.Y - 17) * (itemsView.Count - 1) / (double)(Bounds.Height - 17 - 17 - 10)); | |
2000 if (offset < 0) offset = 0; | |
2001 if (offset >= itemsView.Count) offset = itemsView.Count - 1; | |
2002 Invalidate(); | |
2003 } | |
2004 return; | |
2005 } | |
2006 MouseHandler(position, buttons, false); | |
2007 } | |
2008 protected override void MouseUp(Point position, MouseButtons buttons) { | |
2009 if ((buttons & MouseButtons.Left) != 0) { | |
2010 CaptureMouse(false); | |
2011 buttonUpState = buttonDownState = ButtonState.Normal; | |
2012 Invalidate(); | |
2013 if (hitScrollBar) { | |
2014 hitScrollBar = false; | |
2015 return; | |
2016 } | |
2017 } | |
2018 if (hitScrollBar) return; | |
2019 MouseHandler(position, buttons, false); | |
2020 } | |
2021 private void MouseHandler(Point position, MouseButtons buttons, Boolean down) { | |
2022 if ((buttons & MouseButtons.Left) != 0 && itemsView.Count > 0) { | |
2023 int lh = (int)Math.Ceiling(SystemFonts.DefaultFont.GetHeight() / 2.0) * 2; | |
2024 int i = (position.Y - 2) / lh + offset; | |
2025 if (i < 0) i = 0; | |
2026 if (i >= itemsView.Count) i = itemsView.Count - 1; | |
2027 Boolean changed = false; | |
2028 FBGTreeNode current = itemsView[i]; | |
2029 if (!ReferenceEquals(highlighted, current)) changed = true; | |
2030 highlighted = current; | |
2031 if (current.Children.Count > 0 && (new Rectangle(3 + 19 * current.Depth, 2 + lh * (i - offset) + 2, 8, 8)).Contains(position)) { | |
2032 if (down) current.Expanded = !current.Expanded; | |
2033 } else if (current.HasCheckBox && (new Rectangle(3 + 19 * current.Depth + 14 + 2, 2 + lh * (i - offset), lh, lh)).Contains(position)) { | |
2034 if (down) current.Checked = !current.Checked; | |
2035 } else if ((new Rectangle(Point.Empty, Bounds.Size)).Contains(position)) { | |
2036 SelectedNode = current; | |
2037 changed = false; | |
2038 } | |
2039 if (changed) Invalidate(); | |
2040 } | |
2041 } | |
2042 protected override void KeyDown(Keys key) { | |
2043 base.KeyDown(key); | |
2044 if (key == Keys.Up) { | |
2045 int i = itemsView.IndexOf(selected); | |
2046 i--; | |
2047 if (i >= 0) SelectAndScrollIntoView(itemsView[i]); | |
2048 } else if (key == Keys.Down) { | |
2049 int i = itemsView.IndexOf(selected); | |
2050 i++; | |
2051 if (i < itemsView.Count) SelectAndScrollIntoView(itemsView[i]); | |
2052 } else if (key == Keys.Left && selected != null) { | |
2053 if (selected.Expanded && selected.Children.Count > 0) { | |
2054 selected.Expanded = false; | |
2055 } else { | |
2056 FBGTreeNode tn = selected.Parent as FBGTreeNode; | |
2057 if (tn != null) SelectAndScrollIntoView(tn); | |
2058 } | |
2059 } else if (key == Keys.Right && selected != null) { | |
2060 if (!selected.Expanded && selected.Children.Count > 0) { | |
2061 selected.Expanded = true; | |
2062 } else if (selected.Children.Count > 0) { | |
2063 SelectAndScrollIntoView(selected.Children[0]); | |
2064 } | |
2065 } else if (key == Keys.Space && selected != null) { | |
2066 if (selected.HasCheckBox) selected.Checked = !selected.Checked; | |
2067 } | |
2068 } | |
2069 private void SelectAndScrollIntoView(FBGTreeNode tn) { | |
2070 int i = itemsView.IndexOf(tn); | |
2071 if (i == -1) { | |
2072 for (FBGTreeNode tp = tn.Parent as FBGTreeNode; tp != null; tp = tp.Parent as FBGTreeNode) if (!tp.Expanded) tp.Expanded = true; | |
2073 i = itemsView.IndexOf(tn); | |
2074 } | |
2075 if (i != -1) { | |
2076 int lh = (int)Math.Ceiling(SystemFonts.DefaultFont.GetHeight() / 2.0) * 2; | |
2077 if (i < offset) offset = i; | |
2078 offset = Math.Max(offset, i - Bounds.Height / lh + 1); | |
2079 } | |
2080 highlighted = tn; | |
2081 SelectedNode = tn; | |
2082 } | |
2083 } | |
2084 } |