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