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