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