Mercurial > hg > ucis.core
annotate FBGUI/FBGUI.cs @ 79:4e4c600031e2
Merge FBGUI updates
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Sun, 16 Feb 2014 15:02:36 +0100 |
parents | 1a10ca0f662e 8f31b164ce7e |
children | 3352f89cf6f5 0d389692be32 |
rev | line source |
---|---|
23 | 1 ???using System; |
2 using System.Collections.Generic; | |
30
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
3 using System.Diagnostics; |
23 | 4 using System.Drawing; |
5 using System.Drawing.Drawing2D; | |
6 using System.Drawing.Imaging; | |
7 using System.IO; | |
30
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
8 using System.Reflection; |
23 | 9 using System.Threading; |
10 using System.Windows.Forms; | |
11 using UCIS.VNCServer; | |
12 using ThreadingTimer = System.Threading.Timer; | |
13 | |
14 namespace UCIS.FBGUI { | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
15 public abstract class FBGEvent { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
16 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
17 public enum FBGPointingEventType { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
18 Move, |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
19 ButtonDown, |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
20 ButtonUp |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
21 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
22 public class FBGPointingEvent : FBGEvent { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
23 private Point position; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
24 public Point Position { get { return position; } set { position = value; } } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
25 public int X { get { return position.X; } set { position.X = value; } } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
26 public int Y { get { return position.Y; } set { position.Y = value; } } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
27 public MouseButtons Buttons { get; private set; } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
28 public FBGPointingEventType Type { get; private set; } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
29 public FBGCursor Cursor { get; set; } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
30 public FBGPointingEvent(Point position, MouseButtons buttons, FBGPointingEventType type) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
31 this.Position = position; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
32 this.Buttons = buttons; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
33 this.Type = type; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
34 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
35 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
36 public class FBGKeyboardEvent : FBGEvent { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
37 public Keys KeyData { get; private set; } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
38 public Keys KeyCode { get { return KeyData & Keys.KeyCode; } } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
39 public Keys Modifiers { get { return KeyData & Keys.Modifiers; } } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
40 public Boolean Shift { get { return (KeyData & Keys.Shift) != 0; } } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
41 public Boolean Control { get { return (KeyData & Keys.Control) != 0; } } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
42 public Boolean Alt { get { return (KeyData & Keys.Alt) != 0; } } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
43 public Boolean IsDown { get; private set; } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
44 public Char KeyChar { get; private set; } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
45 public FBGKeyboardEvent(Keys keyData, Char keyChar, Boolean isDown) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
46 this.KeyData = keyData; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
47 this.KeyChar = keyChar; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
48 this.IsDown = isDown; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
49 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
50 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
51 public class FBGPaintEvent : FBGEvent { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
52 public Graphics Canvas { get; private set; } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
53 public FBGPaintEvent(Graphics canvas) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
54 this.Canvas = canvas; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
55 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
56 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
57 public class FBGKeyboardCaptureEvent : FBGEvent { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
58 public Boolean Capture { get; set; } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
59 public FBGKeyboardCaptureEvent(Boolean capture) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
60 this.Capture = capture; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
61 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
62 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
63 public abstract class FBGMessage { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
64 public IFBGControl Source { get; private set; } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
65 protected FBGMessage(IFBGControl source) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
66 this.Source = source; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
67 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
68 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
69 public class FBGInvalidateMessage : FBGMessage { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
70 public Rectangle Area { get; set; } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
71 public FBGInvalidateMessage(IFBGControl source, Rectangle area) : base(source) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
72 this.Area = area; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
73 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
74 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
75 public class FBGPointingCaptureMessage : FBGMessage { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
76 public Boolean Capture { get; set; } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
77 public FBGPointingCaptureMessage(IFBGControl source, Boolean capture) : base(source) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
78 this.Capture = capture; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
79 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
80 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
81 public class FBGKeyboardCaptureMessage : FBGMessage { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
82 public Boolean Capture { get; set; } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
83 public FBGKeyboardCaptureMessage(IFBGControl source, Boolean capture) : base(source) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
84 this.Capture = capture; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
85 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
86 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
87 |
23 | 88 public interface IFBGControl { |
89 Rectangle Bounds { get; set; } | |
90 Boolean Visible { get; set; } | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
91 void HandleEvent(FBGEvent e); |
23 | 92 void Orphaned(); |
93 } | |
94 public interface IFBGContainerControl { | |
95 void AddControl(IFBGControl control); | |
96 void RemoveControl(IFBGControl control); | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
97 void HandleMessage(IFBGControl sender, FBGMessage e); |
78 | 98 Size ClientSize { get; } |
23 | 99 } |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
100 |
23 | 101 public class FBGControl : IFBGControl { |
102 private Rectangle bounds = new Rectangle(0, 0, 100, 100); | |
103 private Color backColor = Color.Transparent; | |
104 private Boolean visible = true; | |
105 public virtual IFBGContainerControl Parent { get; private set; } | |
106 public event MouseEventHandler OnMouseDown; | |
107 public event MouseEventHandler OnMouseMove; | |
108 public event MouseEventHandler OnMouseUp; | |
109 public event PaintEventHandler OnPaint; | |
110 public event EventHandler OnResize; | |
111 public event EventHandler OnMove; | |
112 public FBGControl(IFBGContainerControl parent) { | |
113 this.Parent = parent; | |
114 if (Parent != null) Parent.AddControl(this); | |
115 } | |
116 public virtual Rectangle Bounds { | |
117 get { return bounds; } | |
118 set { | |
119 if (bounds == value) return; | |
120 Rectangle old = bounds; | |
121 bounds = value; | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
122 Invalidate(Rectangle.Union(new Rectangle(Point.Empty, value.Size), new Rectangle(old.X - value.X, old.Y - value.Y, old.Width, old.Height))); |
23 | 123 if (value.Location != old.Location) RaiseEvent(OnMove); |
124 if (value.Size != old.Size) RaiseEvent(OnResize); | |
125 } | |
126 } | |
127 public virtual Boolean Visible { | |
128 get { return visible; } | |
129 set { | |
130 visible = value; | |
131 Invalidate(); | |
132 } | |
133 } | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
134 public virtual FBGCursor Cursor { get; set; } |
23 | 135 public Size Size { get { return Bounds.Size; } set { Rectangle r = Bounds; r.Size = value; Bounds = r; } } |
136 public Point Location { get { return Bounds.Location; } set { Rectangle r = Bounds; r.Location = value; Bounds = r; } } | |
137 public int Left { get { return Bounds.Left; } set { Rectangle r = Bounds; r.X = value; Bounds = r; } } | |
138 public int Top { get { return Bounds.Top; } set { Rectangle r = Bounds; r.Y = value; Bounds = r; } } | |
139 public int Width { get { return Bounds.Width; } set { Rectangle r = Bounds; r.Width = value; Bounds = r; } } | |
140 public int Height { get { return Bounds.Height; } set { Rectangle r = Bounds; r.Height = value; Bounds = r; } } | |
141 public virtual Color BackColor { get { return backColor; } set { if (backColor == value) return; backColor = value; Invalidate(); } } | |
142 public virtual void Invalidate() { | |
143 Invalidate(new Rectangle(Point.Empty, Bounds.Size)); | |
144 } | |
145 public virtual void Invalidate(Rectangle rect) { | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
146 Parent.HandleMessage(this, new FBGInvalidateMessage(this, rect)); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
147 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
148 void IFBGControl.HandleEvent(FBGEvent e) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
149 HandleEvent(e); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
150 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
151 protected virtual void HandleEvent(FBGEvent e) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
152 if (e is FBGPaintEvent) HandlePaintEvent((FBGPaintEvent)e); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
153 else if (e is FBGPointingEvent) HandlePointingEvent((FBGPointingEvent)e); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
154 else if (e is FBGKeyboardEvent) HandleKeyboardEvent((FBGKeyboardEvent)e); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
155 else if (e is FBGKeyboardCaptureEvent) HandleKeyboardCaptureEvent((FBGKeyboardCaptureEvent)e); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
156 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
157 protected virtual void HandlePaintEvent(FBGPaintEvent e) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
158 Paint(e.Canvas); |
23 | 159 } |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
160 protected virtual void HandlePointingEvent(FBGPointingEvent e) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
161 if (Cursor != null) e.Cursor = Cursor; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
162 switch (e.Type) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
163 case FBGPointingEventType.Move: MouseMove(e.Position, e.Buttons); break; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
164 case FBGPointingEventType.ButtonDown: MouseDown(e.Position, e.Buttons); break; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
165 case FBGPointingEventType.ButtonUp: MouseUp(e.Position, e.Buttons); break; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
166 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
167 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
168 protected virtual void HandleKeyboardEvent(FBGKeyboardEvent e) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
169 if (e.IsDown) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
170 if (e.KeyData != Keys.None) KeyDown(e.KeyData); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
171 if (e.KeyChar != Char.MinValue) KeyPress(e.KeyChar); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
172 } else { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
173 if (e.KeyData != Keys.None) KeyUp(e.KeyData); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
174 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
175 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
176 protected virtual void HandleKeyboardCaptureEvent(FBGKeyboardCaptureEvent e) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
177 if (!e.Capture) LostKeyboardCapture(); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
178 } |
23 | 179 void IFBGControl.Orphaned() { Orphaned(); } |
180 protected virtual void Paint(Graphics g) { | |
181 if (!visible) return; | |
27
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
182 if (backColor.A == 0xff) g.Clear(backColor); |
5bfc6c68591e
FBGUI: Added numeric up/down control, fix for transparent control background
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
183 else if (backColor.A != 0) using (Brush brush = new SolidBrush(backColor)) g.FillRectangle(brush, g.ClipBounds); |
23 | 184 RaiseEvent(OnPaint, new PaintEventArgs(g, Rectangle.Round(g.ClipBounds))); |
185 } | |
186 protected virtual void MouseMove(Point position, MouseButtons buttons) { RaiseEvent(OnMouseMove, new MouseEventArgs(buttons, 0, position.X, position.Y, 0)); } | |
187 protected virtual void MouseDown(Point position, MouseButtons buttons) { RaiseEvent(OnMouseDown, new MouseEventArgs(buttons, 1, position.X, position.Y, 0)); } | |
188 protected virtual void MouseUp(Point position, MouseButtons buttons) { RaiseEvent(OnMouseUp, new MouseEventArgs(buttons, 1, position.X, position.Y, 0)); } | |
189 protected virtual Boolean CaptureMouse(Boolean capture) { | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
190 FBGPointingCaptureMessage m = new FBGPointingCaptureMessage(this, capture); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
191 Parent.HandleMessage(this, m); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
192 return capture == m.Capture; |
23 | 193 } |
194 protected virtual void KeyDown(Keys key) { } | |
195 protected virtual void KeyPress(Char keyChar) { } | |
196 protected virtual void KeyUp(Keys key) { } | |
197 protected virtual Boolean CaptureKeyboard(Boolean capture) { | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
198 FBGKeyboardCaptureMessage m = new FBGKeyboardCaptureMessage(this, capture); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
199 Parent.HandleMessage(this, m); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
200 return capture == m.Capture; |
23 | 201 } |
202 protected virtual void LostKeyboardCapture() { } | |
203 protected virtual void Orphaned() { | |
204 //IDisposable disp = this as IDisposable; | |
205 //if (!ReferenceEquals(disp, null)) disp.Dispose(); | |
206 } | |
207 protected void RaiseEvent(KeyEventHandler eh, KeyEventArgs ea) { if (eh != null) eh(this, ea); } | |
208 protected void RaiseEvent(KeyPressEventHandler eh, KeyPressEventArgs ea) { if (eh != null) eh(this, ea); } | |
209 protected void RaiseEvent(MouseEventHandler eh, MouseEventArgs ea) { if (eh != null) eh(this, ea); } | |
210 protected void RaiseEvent(PaintEventHandler eh, PaintEventArgs ea) { if (eh != null) eh(this, ea); } | |
211 protected void RaiseEvent<T>(EventHandler<T> eh, T ea) where T : EventArgs { if (eh != null) eh(this, ea); } | |
212 protected void RaiseEvent(EventHandler eh, EventArgs ea) { if (eh != null) eh(this, ea); } | |
213 protected void RaiseEvent(EventHandler eh) { if (eh != null) eh(this, new EventArgs()); } | |
214 } | |
215 public class FBGContainerControl : FBGControl, IFBGContainerControl { | |
216 protected List<IFBGControl> controls = new List<IFBGControl>(); | |
26
7f0b7a53a000
FBGUI: Allow derived classes to access some internals
Ivo Smits <Ivo@UCIS.nl>
parents:
23
diff
changeset
|
217 protected IFBGControl mouseCaptureControl = null; |
7f0b7a53a000
FBGUI: Allow derived classes to access some internals
Ivo Smits <Ivo@UCIS.nl>
parents:
23
diff
changeset
|
218 protected IFBGControl keyboardCaptureControl = null; |
78 | 219 public virtual Rectangle ClientRectangle { get { return Bounds; } } |
220 public virtual Size ClientSize { get { return ClientRectangle.Size; } set { Bounds = new Rectangle(Bounds.Location, Bounds.Size - ClientRectangle.Size + value); } } | |
23 | 221 public FBGContainerControl(IFBGContainerControl parent) : base(parent) { } |
222 void IFBGContainerControl.AddControl(IFBGControl control) { AddControl(control); } | |
223 protected virtual void AddControl(IFBGControl control) { | |
224 controls.Add(control); | |
225 if (control.Visible) Invalidate(control); | |
226 } | |
227 public virtual void RemoveControl(IFBGControl control) { | |
228 if (controls.Remove(control)) { | |
229 if (control.Visible) Invalidate(control); | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
230 HandleMessage(control, new FBGPointingCaptureMessage(control, false)); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
231 HandleMessage(control, new FBGKeyboardCaptureMessage(control, false)); |
23 | 232 control.Orphaned(); |
233 } | |
234 } | |
235 public virtual Point PointToChild(IFBGControl child, Point point) { | |
236 return point - (Size)child.Bounds.Location - (Size)ClientRectangle.Location; | |
237 } | |
238 public virtual Point PointFromChild(IFBGControl child, Point point) { | |
239 return point + (Size)child.Bounds.Location + (Size)ClientRectangle.Location; | |
240 } | |
241 public virtual void BringControlToFront(IFBGControl control) { | |
242 if (controls.Count == 0) return; | |
243 if (ReferenceEquals(controls[controls.Count - 1], control)) return; | |
244 if (!controls.Remove(control)) return; | |
245 controls.Add(control); | |
246 if (control.Visible) Invalidate(control); | |
247 } | |
248 public virtual void Invalidate(IFBGControl control) { | |
249 Invalidate(new Rectangle(PointFromChild(control, Point.Empty), control.Bounds.Size)); | |
250 } | |
251 public virtual void Invalidate(IFBGControl control, Rectangle rect) { | |
252 Invalidate(new Rectangle(PointFromChild(control, rect.Location), rect.Size)); | |
253 } | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
254 protected override void HandlePaintEvent(FBGPaintEvent e) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
255 base.HandlePaintEvent(e); |
23 | 256 GraphicsState state2 = null; |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
257 Graphics g = e.Canvas; |
78 | 258 Rectangle childarea = ClientRectangle; |
259 if (childarea.X != 0 || childarea.Y != 0 || childarea.Width != Bounds.Width || childarea.Height != Bounds.Height) { | |
23 | 260 state2 = g.Save(); |
261 g.TranslateTransform(childarea.X, childarea.Y, MatrixOrder.Append); | |
262 g.IntersectClip(new Rectangle(Point.Empty, childarea.Size)); | |
263 } | |
264 foreach (IFBGControl control in controls) { | |
265 if (!control.Visible) continue; | |
266 if (control.Bounds.Width <= 0 || control.Bounds.Height <= 0) continue; | |
267 if (!g.ClipBounds.IntersectsWith((RectangleF)control.Bounds)) continue; | |
268 GraphicsState state = g.Save(); | |
269 g.TranslateTransform(control.Bounds.X, control.Bounds.Y, MatrixOrder.Append); | |
270 g.IntersectClip(new Rectangle(Point.Empty, control.Bounds.Size)); | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
271 control.HandleEvent(e); |
23 | 272 g.Restore(state); |
273 } | |
274 if (state2 != null) g.Restore(state2); | |
275 } | |
276 public IFBGControl FindControlAtPosition(Point p) { | |
78 | 277 Rectangle childarea = ClientRectangle; |
278 if (!childarea.Contains(p)) return null; | |
23 | 279 p.Offset(-childarea.X, -childarea.Y); |
280 return ((List<IFBGControl>)controls).FindLast(delegate(IFBGControl control) { return control.Visible && control.Bounds.Contains(p); }); | |
281 } | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
282 protected override void HandlePointingEvent(FBGPointingEvent e) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
283 IFBGControl control = mouseCaptureControl != null ? mouseCaptureControl : FindControlAtPosition(e.Position); |
23 | 284 if (control == null) { |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
285 base.HandlePointingEvent(e); |
23 | 286 } else { |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
287 if (Cursor != null) e.Cursor = Cursor; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
288 e.Position = PointToChild(control, e.Position); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
289 control.HandleEvent(e); |
23 | 290 } |
291 } | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
292 void IFBGContainerControl.HandleMessage(IFBGControl sender, FBGMessage e) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
293 HandleMessage(sender, e); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
294 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
295 protected virtual void HandleMessage(IFBGControl sender, FBGMessage e) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
296 if (e is FBGPointingCaptureMessage) HandlePointingCaptureMessage(sender, (FBGPointingCaptureMessage)e); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
297 else if (e is FBGKeyboardCaptureMessage) HandleKeyboardCaptureMessage(sender, (FBGKeyboardCaptureMessage)e); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
298 else if (e is FBGInvalidateMessage) HandleInvalidateMessage(sender, (FBGInvalidateMessage)e); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
299 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
300 protected virtual void HandleInvalidateMessage(IFBGControl sender, FBGInvalidateMessage e) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
301 e.Area = new Rectangle(PointFromChild(sender, e.Area.Location), e.Area.Size); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
302 Parent.HandleMessage(this, e); |
23 | 303 } |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
304 protected virtual void HandlePointingCaptureMessage(IFBGControl sender, FBGPointingCaptureMessage e) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
305 if (e.Capture && !(ReferenceEquals(mouseCaptureControl, null) || ReferenceEquals(mouseCaptureControl, sender))) e.Capture = false; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
306 else if (!e.Capture && !ReferenceEquals(mouseCaptureControl, sender)) e.Capture = false; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
307 else { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
308 Parent.HandleMessage(this, e); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
309 mouseCaptureControl = e.Capture ? sender : null; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
310 } |
23 | 311 } |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
312 protected override void HandleKeyboardEvent(FBGKeyboardEvent e) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
313 if (ReferenceEquals(keyboardCaptureControl, null)) base.HandleKeyboardEvent(e); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
314 else keyboardCaptureControl.HandleEvent(e); |
23 | 315 } |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
316 protected virtual void HandleKeyboardCaptureMessage(IFBGControl sender, FBGKeyboardCaptureMessage e) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
317 if (!e.Capture && !(ReferenceEquals(mouseCaptureControl, null) || ReferenceEquals(mouseCaptureControl, sender))) e.Capture = false; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
318 else { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
319 Parent.HandleMessage(this, e); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
320 IFBGControl prev = keyboardCaptureControl; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
321 keyboardCaptureControl = e.Capture ? sender : null; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
322 if (prev != null && prev != sender) prev.HandleEvent(new FBGKeyboardCaptureEvent(false)); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
323 } |
23 | 324 } |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
325 protected override void HandleKeyboardCaptureEvent(FBGKeyboardCaptureEvent e) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
326 if (keyboardCaptureControl != null) keyboardCaptureControl.HandleEvent(new FBGKeyboardCaptureEvent(false)); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
327 base.HandleKeyboardCaptureEvent(e); |
23 | 328 } |
329 protected override void Orphaned() { | |
330 base.Orphaned(); | |
331 IFBGControl[] c = controls.ToArray(); | |
332 controls.Clear(); | |
333 foreach (IFBGControl control in c) control.Orphaned(); | |
334 mouseCaptureControl = null; | |
335 keyboardCaptureControl = null; | |
336 } | |
337 } | |
338 public class FBGDockContainer : FBGContainerControl { | |
339 private Dictionary<IFBGControl, DockStyle> dockStyles = new Dictionary<IFBGControl, DockStyle>(); | |
340 private Dictionary<IFBGControl, AnchorStyles> anchorStyles = new Dictionary<IFBGControl, AnchorStyles>(); | |
341 private Rectangle oldBounds; | |
342 public FBGDockContainer(IFBGContainerControl parent) | |
343 : base(parent) { | |
344 oldBounds = ClientRectangle.IsEmpty ? Bounds : new Rectangle(Bounds.Location + (Size)ClientRectangle.Location, ClientRectangle.Size); | |
345 } | |
346 protected override void AddControl(IFBGControl control) { | |
347 base.AddControl(control); | |
348 } | |
349 public override void BringControlToFront(IFBGControl control) { | |
350 base.BringControlToFront(control); | |
351 if (dockStyles.ContainsKey(control)) DoLayout(); | |
352 } | |
353 public override void RemoveControl(IFBGControl control) { | |
354 base.RemoveControl(control); | |
355 if (dockStyles.Remove(control)) DoLayout(); | |
356 } | |
357 public override Rectangle Bounds { | |
358 get { return base.Bounds; } | |
359 set { | |
360 base.Bounds = value; | |
361 DoLayout(); | |
362 Rectangle newBounds = ClientRectangle.IsEmpty ? Bounds : new Rectangle(Bounds.Location + (Size)ClientRectangle.Location, ClientRectangle.Size); | |
363 foreach (KeyValuePair<IFBGControl, AnchorStyles> c in anchorStyles) { | |
364 Rectangle b = c.Key.Bounds; | |
365 if ((c.Value & AnchorStyles.Right) != 0) { | |
366 if ((c.Value & AnchorStyles.Left) == 0) b.X += newBounds.Width - oldBounds.Width; | |
367 else b.Width += newBounds.Width - oldBounds.Width; | |
368 } else if ((c.Value & AnchorStyles.Left) == 0) b.X += newBounds.X - oldBounds.X; | |
369 if ((c.Value & AnchorStyles.Bottom) != 0) { | |
370 if ((c.Value & AnchorStyles.Top) == 0) b.Y += newBounds.Height - oldBounds.Height; | |
371 else b.Height += newBounds.Height - oldBounds.Height; | |
372 } else if ((c.Value & AnchorStyles.Top) == 0) b.Y += newBounds.Y - oldBounds.Y; | |
373 c.Key.Bounds = b; | |
374 } | |
375 oldBounds = newBounds; | |
376 } | |
377 } | |
378 public DockStyle GetDockStyle(IFBGControl control) { | |
379 DockStyle ds; | |
380 if (!dockStyles.TryGetValue(control, out ds)) ds = DockStyle.None; | |
381 return ds; | |
382 } | |
383 public void SetDockStyle(IFBGControl control, DockStyle style) { | |
384 if (style == DockStyle.None) { | |
385 if (dockStyles.Remove(control)) DoLayout(); | |
386 } else if (controls.Contains(control)) { | |
387 anchorStyles.Remove(control); | |
388 dockStyles[control] = style; | |
389 DoLayout(); | |
390 } | |
391 } | |
392 public AnchorStyles GetAnchorStyle(IFBGControl control) { | |
393 AnchorStyles ds; | |
394 if (!anchorStyles.TryGetValue(control, out ds)) ds = AnchorStyles.Left | AnchorStyles.Top; | |
395 return ds; | |
396 } | |
397 public void SetAnchorStyle(IFBGControl control, AnchorStyles style) { | |
398 if (style == (AnchorStyles.Left | AnchorStyles.Top)) { | |
399 anchorStyles.Remove(control); | |
400 } else if (controls.Contains(control)) { | |
401 dockStyles.Remove(control); | |
402 anchorStyles[control] = style; | |
403 } | |
404 } | |
405 public void SetAnchor(IFBGControl control, AnchorStyles style, int value) { | |
406 if (controls.Contains(control)) { | |
407 AnchorStyles oldstyle; | |
408 if (!anchorStyles.TryGetValue(control, out oldstyle)) oldstyle = AnchorStyles.Left | AnchorStyles.Top; | |
409 Rectangle b = control.Bounds; | |
410 switch (style) { | |
411 case AnchorStyles.None: throw new ArgumentException("style", "Anchor style can not be None"); | |
412 case AnchorStyles.Left: b.X = value; break; | |
413 case AnchorStyles.Top: b.Y = value; break; | |
414 case AnchorStyles.Right: | |
415 if ((oldstyle & AnchorStyles.Left) == 0) b.X = ClientRectangle.Width - b.Width - value; | |
416 else b.Width = ClientRectangle.Width - b.X - value; | |
417 break; | |
418 case AnchorStyles.Bottom: | |
419 if ((oldstyle & AnchorStyles.Top) == 0) b.Y = ClientRectangle.Height - b.Height - value; | |
420 else b.Height = ClientRectangle.Height - b.Y - value; | |
421 break; | |
422 default: throw new ArgumentOutOfRangeException("style", "The value vor the style argument is invalid"); | |
423 } | |
424 control.Bounds = b; | |
425 dockStyles.Remove(control); | |
426 anchorStyles[control] = oldstyle | style; | |
427 } | |
428 } | |
429 private void DoLayout() { | |
430 Rectangle a = new Rectangle(Point.Empty, ClientRectangle.IsEmpty ? Bounds.Size : ClientRectangle.Size); | |
431 foreach (KeyValuePair<IFBGControl, DockStyle> c in dockStyles) { | |
432 Rectangle b = c.Key.Bounds; | |
433 if (c.Value == DockStyle.Left) { | |
434 b.Location = a.Location; | |
435 b.Height = a.Height; | |
436 a.X += b.Width; | |
437 a.Width -= b.Width; | |
438 } else if (c.Value == DockStyle.Top) { | |
439 b.Location = a.Location; | |
440 b.Width = a.Width; | |
441 a.Y += b.Height; | |
442 a.Height -= b.Height; | |
443 } else if (c.Value == DockStyle.Right) { | |
444 b.X = a.X + a.Width - b.Width; | |
445 b.Y = a.Y; | |
446 b.Height = a.Height; | |
447 a.Width -= b.Width; | |
448 } else if (c.Value == DockStyle.Bottom) { | |
449 b.X = a.X; | |
450 b.Y = a.Y + a.Height - b.Height; | |
451 b.Width = a.Width; | |
452 a.Height -= b.Height; | |
453 } else if (c.Value == DockStyle.Fill) { | |
454 b = a; | |
455 } | |
456 c.Key.Bounds = b; | |
457 if (a.Width < 0) a.Width = 0; | |
458 if (a.Height < 0) a.Height = 0; | |
459 } | |
460 } | |
461 } | |
462 public class FBGGroupBox : FBGDockContainer { | |
463 private String text = String.Empty; | |
78 | 464 public override Rectangle ClientRectangle { get { return new Rectangle(1, 15, Bounds.Width - 2, Bounds.Height - 17); } } |
465 public FBGGroupBox(IFBGContainerControl parent) : base(parent) { } | |
23 | 466 public String Text { get { return text; } set { if (text == value) return; text = value; Invalidate(new Rectangle(0, 0, Bounds.Width, 15)); } } |
467 protected override void Paint(Graphics g) { | |
468 base.Paint(g); | |
469 SizeF ss = g.MeasureString(Text, SystemFonts.DefaultFont, new Size(Bounds.Width - 10 - 9, 15)); | |
78 | 470 g.DrawLines(Pens.Gray, new PointF[] { new PointF(8 + ss.Width + 4, 6), new Point(Bounds.Width - 1, 6), new Point(Bounds.Width - 1, Bounds.Height - 1), new Point(0, Bounds.Height - 1), new Point(0, 6), new Point(8, 6) }); |
23 | 471 g.DrawString(Text, SystemFonts.DefaultFont, Brushes.DarkBlue, new Rectangle(9, 0, Bounds.Width - 10 - 9, 15)); |
472 } | |
473 } | |
78 | 474 [System.ComponentModel.DesignerCategory("")] |
23 | 475 public class WinFormsFBGHost : Control, IFBGContainerControl { |
476 private IFBGControl childControl = null; | |
477 private IFBGControl mouseCaptureControl = null; | |
478 private IFBGControl keyboardCaptureControl = null; | |
479 public IFBGControl ChildControl { get { return childControl; } } | |
480 | |
481 public WinFormsFBGHost() { | |
482 DoubleBuffered = true; | |
483 } | |
484 | |
485 public virtual Point PointToChild(IFBGControl child, Point point) { | |
486 return point - (Size)child.Bounds.Location; | |
487 } | |
488 public virtual Point PointFromChild(IFBGControl child, Point point) { | |
489 return point + (Size)child.Bounds.Location; | |
490 } | |
491 | |
492 void IFBGContainerControl.AddControl(IFBGControl control) { | |
493 if (!ReferenceEquals(childControl, null)) throw new InvalidOperationException("This container can have only one child control"); | |
494 childControl = control; | |
495 control.Bounds = new Rectangle(Point.Empty, ClientSize); | |
496 Invalidate(control.Bounds); | |
497 } | |
498 void IFBGContainerControl.RemoveControl(IFBGControl control) { | |
499 if (!ReferenceEquals(childControl, control)) return; | |
500 childControl = null; | |
501 Invalidate(control.Bounds); | |
502 if (mouseCaptureControl == control) mouseCaptureControl = null; | |
503 if (keyboardCaptureControl == control) control = null; | |
504 control.Orphaned(); | |
505 } | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
506 void IFBGContainerControl.HandleMessage(IFBGControl sender, FBGMessage e) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
507 if (e is FBGInvalidateMessage) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
508 FBGInvalidateMessage p = (FBGInvalidateMessage)e; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
509 Invalidate(new Rectangle(PointFromChild(sender, p.Area.Location), p.Area.Size)); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
510 } else if (e is FBGPointingCaptureMessage) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
511 FBGPointingCaptureMessage p = (FBGPointingCaptureMessage)e; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
512 if (p.Capture && !(ReferenceEquals(mouseCaptureControl, null) || ReferenceEquals(mouseCaptureControl, sender))) p.Capture = false; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
513 else if (!p.Capture && !ReferenceEquals(mouseCaptureControl, sender)) p.Capture = false; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
514 else mouseCaptureControl = p.Capture ? sender : null; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
515 } else if (e is FBGKeyboardCaptureMessage) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
516 FBGKeyboardCaptureMessage p = (FBGKeyboardCaptureMessage)e; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
517 if (!p.Capture && !ReferenceEquals(keyboardCaptureControl, sender)) p.Capture = false; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
518 else keyboardCaptureControl = p.Capture ? sender : null; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
519 } |
23 | 520 } |
521 | |
522 protected override void OnPaint(PaintEventArgs e) { | |
523 base.OnPaint(e); | |
524 Graphics g = e.Graphics; | |
525 GraphicsState state = g.Save(); | |
526 g.SetClip(e.ClipRectangle); | |
527 if (ReferenceEquals(childControl, null)) return; | |
528 if (childControl.Bounds.Width <= 0 || childControl.Bounds.Height <= 0) return; | |
529 if (!g.ClipBounds.IntersectsWith((RectangleF)childControl.Bounds)) return; | |
530 g.TranslateTransform(childControl.Bounds.X, childControl.Bounds.Y, MatrixOrder.Append); | |
531 g.IntersectClip(new Rectangle(Point.Empty, childControl.Bounds.Size)); | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
532 childControl.HandleEvent(new FBGPaintEvent(g)); |
23 | 533 g.Restore(state); |
534 } | |
535 protected override void OnResize(EventArgs e) { | |
536 if (!ReferenceEquals(childControl, null)) childControl.Bounds = new Rectangle(Point.Empty, ClientSize); | |
537 base.OnResize(e); | |
538 } | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
539 void DispatchMouseEvent(MouseEventArgs e, FBGPointingEventType type) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
540 IFBGControl control = mouseCaptureControl != null ? mouseCaptureControl : childControl; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
541 if (control != null) control.HandleEvent(new FBGPointingEvent(e.Location, e.Button, type)); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
542 } |
23 | 543 protected override void OnMouseDown(MouseEventArgs e) { |
544 base.OnMouseDown(e); | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
545 DispatchMouseEvent(e, FBGPointingEventType.ButtonDown); |
23 | 546 } |
547 protected override void OnMouseUp(MouseEventArgs e) { | |
548 base.OnMouseUp(e); | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
549 DispatchMouseEvent(e, FBGPointingEventType.ButtonUp); |
23 | 550 } |
551 protected override void OnMouseMove(MouseEventArgs e) { | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
552 DispatchMouseEvent(e, FBGPointingEventType.Move); |
23 | 553 } |
554 protected override bool IsInputChar(char charCode) { | |
555 return true; | |
556 } | |
557 protected override bool IsInputKey(Keys keyData) { | |
558 return true; | |
559 } | |
560 protected override void OnKeyDown(KeyEventArgs e) { | |
561 //base.OnKeyDown(e); | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
562 if (!ReferenceEquals(keyboardCaptureControl, null)) keyboardCaptureControl.HandleEvent(new FBGKeyboardEvent(e.KeyData, Char.MinValue, true)); |
23 | 563 } |
564 protected override void OnKeyPress(KeyPressEventArgs e) { | |
565 //base.OnKeyPress(e); | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
566 if (!ReferenceEquals(keyboardCaptureControl, null)) keyboardCaptureControl.HandleEvent(new FBGKeyboardEvent(Keys.None, e.KeyChar, true)); |
23 | 567 } |
568 protected override void OnKeyUp(KeyEventArgs e) { | |
569 //base.OnKeyUp(e); | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
570 if (!ReferenceEquals(keyboardCaptureControl, null)) keyboardCaptureControl.HandleEvent(new FBGKeyboardEvent(e.KeyData, Char.MinValue, false)); |
23 | 571 } |
572 protected override void OnHandleDestroyed(EventArgs e) { | |
573 if (!ReferenceEquals(childControl, null)) childControl.Orphaned(); | |
574 base.OnHandleDestroyed(e); | |
575 } | |
576 } | |
577 public class FBGCursor { | |
578 public Image Image { get; private set; } | |
579 public Point Hotspot { get; private set; } | |
580 public Size Size { get; private set; } | |
581 public FBGCursor(Image image, Point hotspot) { | |
582 this.Image = image; | |
583 this.Hotspot = hotspot; | |
74
8f31b164ce7e
FBGUI: Added invisible cursor support
Ivo Smits <Ivo@UCIS.nl>
parents:
69
diff
changeset
|
584 this.Size = image == null ? Size.Empty : image.Size; |
23 | 585 } |
30
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
586 public Rectangle Area { get { return new Rectangle(-Hotspot.X, -Hotspot.Y, Size.Width, Size.Height); } } |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
587 public FBGCursor RotateFlip(RotateFlipType type) { |
74
8f31b164ce7e
FBGUI: Added invisible cursor support
Ivo Smits <Ivo@UCIS.nl>
parents:
69
diff
changeset
|
588 if (Image == null) return this; |
30
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
589 Image img = new Bitmap(Image); |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
590 img.RotateFlip(type); |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
591 Point hs = Hotspot; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
592 switch (type) { |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
593 case RotateFlipType.RotateNoneFlipNone: break; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
594 case RotateFlipType.Rotate90FlipNone: hs = new Point(img.Width - hs.Y, hs.X); break; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
595 case RotateFlipType.Rotate180FlipNone: hs = new Point(img.Width - hs.X, img.Height - hs.Y); break; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
596 case RotateFlipType.Rotate270FlipNone: hs = new Point(hs.Y, img.Height - hs.X); break; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
597 case RotateFlipType.RotateNoneFlipX: hs.X = img.Width - hs.X; break; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
598 case RotateFlipType.Rotate90FlipX: hs = new Point(hs.Y, hs.X); break; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
599 case RotateFlipType.RotateNoneFlipY: hs.Y = img.Height - hs.Y; break; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
600 case RotateFlipType.Rotate90FlipY: hs = new Point(img.Width - hs.Y, img.Height - hs.X); break; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
601 } |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
602 return new FBGCursor(img, hs); |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
603 } |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
604 public static FBGCursor FromBase64Image(String data, Point hotspot) { |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
605 return new FBGCursor(Image.FromStream(new MemoryStream(Convert.FromBase64String(data))), hotspot); |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
606 } |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
607 private static FBGCursor LoadFromResource(String name, int hotX, int hotY) { |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
608 using (Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream("UCIS.FBGUI." + name + ".png")) { |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
609 return new FBGCursor(Image.FromStream(s), new Point(hotX, hotY)); |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
610 } |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
611 } |
23 | 612 |
74
8f31b164ce7e
FBGUI: Added invisible cursor support
Ivo Smits <Ivo@UCIS.nl>
parents:
69
diff
changeset
|
613 public static readonly FBGCursor None = new FBGCursor(null, Point.Empty); |
30
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
614 public static readonly FBGCursor Arrow = LoadFromResource("cursor_arrow", 0, 0); |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
615 public static readonly FBGCursor Move = LoadFromResource("cursor_move", 8, 8); |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
616 public static readonly FBGCursor SizeLeft = LoadFromResource("cursor_left", 1, 10); |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
617 public static readonly FBGCursor SizeRight = SizeLeft.RotateFlip(RotateFlipType.RotateNoneFlipX); |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
618 public static readonly FBGCursor SizeTop = SizeLeft.RotateFlip(RotateFlipType.Rotate90FlipNone); |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
619 public static readonly FBGCursor SizeBottom = SizeLeft.RotateFlip(RotateFlipType.Rotate90FlipY); |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
620 public static readonly FBGCursor SizeTopLeft = LoadFromResource("cursor_topleft", 1, 1); |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
621 public static readonly FBGCursor SizeTopRight = SizeTopLeft.RotateFlip(RotateFlipType.RotateNoneFlipX); |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
622 public static readonly FBGCursor SizeBottomLeft = SizeTopLeft.RotateFlip(RotateFlipType.RotateNoneFlipY); |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
623 public static readonly FBGCursor SizeBottomRight = SizeTopLeft.RotateFlip(RotateFlipType.RotateNoneFlipXY); |
40 | 624 public static readonly FBGCursor Hand = LoadFromResource("cursor_hand", 5, 0); |
30
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
625 public static FBGCursor ArrowCursor { get { return Arrow; } } |
23 | 626 } |
627 public class FBGRenderer : FBGContainerControl, IDisposable { | |
628 private FBGCursor cursor = null; | |
629 private Point cursorposition = Point.Empty; | |
630 public IFramebuffer Framebuffer { get; private set; } | |
26
7f0b7a53a000
FBGUI: Allow derived classes to access some internals
Ivo Smits <Ivo@UCIS.nl>
parents:
23
diff
changeset
|
631 private Bitmap Frontbuffer = null; |
7f0b7a53a000
FBGUI: Allow derived classes to access some internals
Ivo Smits <Ivo@UCIS.nl>
parents:
23
diff
changeset
|
632 protected Object RenderLock = new object(); |
23 | 633 public event EventHandler<InvalidateEventArgs> Painted; |
26
7f0b7a53a000
FBGUI: Allow derived classes to access some internals
Ivo Smits <Ivo@UCIS.nl>
parents:
23
diff
changeset
|
634 protected Size size = Size.Empty; |
23 | 635 private ThreadingTimer PaintTimer = null; |
636 private Boolean PaintScheduled = false; | |
637 private int PaintDelay = 0; | |
638 public Boolean SuspendDrawing { | |
639 get { return suspenddrawing; } | |
640 set { | |
641 lock (RenderLock) { | |
642 suspenddrawing = value; | |
643 if (!value) { | |
644 Refresh(DirtyRectangle); | |
645 DirtyRectangle = Rectangle.Empty; | |
646 } | |
647 } | |
648 } | |
649 } | |
650 public int RedrawDelay { | |
651 get { return PaintDelay; } | |
652 set { | |
653 lock (RenderLock) { | |
654 if (value < 0) throw new ArgumentOutOfRangeException("value"); | |
655 PaintDelay = value; | |
656 if (PaintDelay == 0) { | |
657 if (PaintTimer != null) PaintTimer.Dispose(); | |
658 PaintTimer = null; | |
659 if (PaintScheduled) PaintTimerCallback(null); | |
660 } else { | |
661 PaintTimer = new ThreadingTimer(PaintTimerCallback); | |
662 } | |
663 } | |
664 } | |
665 } | |
666 private Boolean suspenddrawing = false; | |
667 private Rectangle DirtyRectangle; | |
668 | |
669 public Point CursorPosition { | |
670 get { return cursorposition; } | |
30
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
671 set { UpdateCursor(value, cursor); } |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
672 } |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
673 protected void UpdateCursor(Point position, FBGCursor cursor) { |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
674 if (cursorposition == position && cursor == this.cursor) return; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
675 Rectangle r1 = Rectangle.Empty; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
676 if (this.cursor != null) { |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
677 r1 = this.cursor.Area; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
678 r1.Offset(cursorposition); |
23 | 679 } |
30
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
680 if (cursor != null) { |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
681 Rectangle r2 = cursor.Area; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
682 r2.Offset(position); |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
683 r1 = r1.IsEmpty ? r2 : Rectangle.Union(r1, r2); |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
684 } |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
685 this.cursor = cursor; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
686 cursorposition = position; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
687 Invalidate(r1); |
23 | 688 } |
689 public override Rectangle Bounds { | |
690 get { return new Rectangle(Point.Empty, size); } | |
691 set { throw new NotSupportedException("Can not change the top control bounds"); } | |
692 } | |
693 public FBGRenderer(IFramebuffer fb) : this(fb.Width, fb.Height) { | |
694 Framebuffer = fb; | |
695 } | |
696 public FBGRenderer(Size fbsize) : this(fbsize.Width, fbsize.Height) { } | |
697 public FBGRenderer(int width, int height) : this(new Bitmap(width, height, PixelFormat.Format32bppRgb)) { } | |
698 public FBGRenderer(Bitmap bmp) : base(null) { | |
699 Frontbuffer = bmp; | |
700 BackColor = SystemColors.Control; | |
701 size = Frontbuffer.Size; | |
702 } | |
26
7f0b7a53a000
FBGUI: Allow derived classes to access some internals
Ivo Smits <Ivo@UCIS.nl>
parents:
23
diff
changeset
|
703 protected FBGRenderer() : base(null) { |
7f0b7a53a000
FBGUI: Allow derived classes to access some internals
Ivo Smits <Ivo@UCIS.nl>
parents:
23
diff
changeset
|
704 BackColor = SystemColors.Control; |
7f0b7a53a000
FBGUI: Allow derived classes to access some internals
Ivo Smits <Ivo@UCIS.nl>
parents:
23
diff
changeset
|
705 } |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
706 protected override void HandleInvalidateMessage(IFBGControl sender, FBGInvalidateMessage e) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
707 e.Area = new Rectangle(PointFromChild(sender, e.Area.Location), e.Area.Size); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
708 Invalidate(e.Area); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
709 } |
23 | 710 public override void Invalidate(Rectangle rect) { |
711 if (rect.Width == 0 || rect.Height == 0) return; | |
712 lock (RenderLock) { | |
713 if (SuspendDrawing || PaintTimer != null) { | |
714 DirtyRectangle = DirtyRectangle.IsEmpty ? rect : Rectangle.Union(DirtyRectangle, rect); | |
715 if (!SuspendDrawing && !PaintScheduled) { | |
716 PaintScheduled = true; | |
717 PaintTimer.Change(PaintDelay, Timeout.Infinite); | |
718 } | |
719 } else { | |
720 Refresh(rect); | |
721 } | |
722 } | |
723 } | |
724 private void PaintTimerCallback(Object state) { | |
725 try { | |
726 lock (RenderLock) { | |
727 PaintScheduled = false; | |
728 Refresh(DirtyRectangle); | |
729 DirtyRectangle = Rectangle.Empty; | |
730 } | |
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
|
731 } 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
|
732 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
|
733 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
|
734 } |
23 | 735 } |
26
7f0b7a53a000
FBGUI: Allow derived classes to access some internals
Ivo Smits <Ivo@UCIS.nl>
parents:
23
diff
changeset
|
736 protected virtual void Refresh(Rectangle rect) { |
23 | 737 lock (RenderLock) { |
738 rect.Intersect(Bounds); | |
739 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
|
740 if (Frontbuffer != null) { |
7f0b7a53a000
FBGUI: Allow derived classes to access some internals
Ivo Smits <Ivo@UCIS.nl>
parents:
23
diff
changeset
|
741 using (Graphics g = Graphics.FromImage(Frontbuffer)) { |
7f0b7a53a000
FBGUI: Allow derived classes to access some internals
Ivo Smits <Ivo@UCIS.nl>
parents:
23
diff
changeset
|
742 g.SetClip(rect); |
7f0b7a53a000
FBGUI: Allow derived classes to access some internals
Ivo Smits <Ivo@UCIS.nl>
parents:
23
diff
changeset
|
743 Paint(g); |
7f0b7a53a000
FBGUI: Allow derived classes to access some internals
Ivo Smits <Ivo@UCIS.nl>
parents:
23
diff
changeset
|
744 } |
7f0b7a53a000
FBGUI: Allow derived classes to access some internals
Ivo Smits <Ivo@UCIS.nl>
parents:
23
diff
changeset
|
745 if (Framebuffer != null) Framebuffer.DrawImage(Frontbuffer, rect, rect.Location); |
23 | 746 } |
747 RaiseEvent(Painted, new InvalidateEventArgs(rect)); | |
748 } | |
749 } | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
750 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
|
751 HandleEvent(new FBGPaintEvent(g)); |
74
8f31b164ce7e
FBGUI: Added invisible cursor support
Ivo Smits <Ivo@UCIS.nl>
parents:
69
diff
changeset
|
752 if (cursor != null && cursor.Image != null) { |
42 | 753 Rectangle r = cursor.Area; |
754 r.Offset(cursorposition); | |
755 g.DrawImage(cursor.Image, r); | |
23 | 756 } |
757 } | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
758 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
|
759 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
|
760 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
|
761 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
|
762 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
763 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
|
764 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
|
765 else { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
766 IFBGControl prev = keyboardCaptureControl; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
767 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
|
768 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
|
769 } |
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 |
23 | 772 protected override Boolean CaptureMouse(Boolean capture) { |
773 return true; | |
774 } | |
775 protected override Boolean CaptureKeyboard(bool capture) { | |
776 return true; | |
777 } | |
26
7f0b7a53a000
FBGUI: Allow derived classes to access some internals
Ivo Smits <Ivo@UCIS.nl>
parents:
23
diff
changeset
|
778 public virtual void Dispose() { |
23 | 779 lock (RenderLock) { |
780 if (PaintTimer != null) PaintTimer.Dispose(); | |
781 PaintTimer = null; | |
782 } | |
783 Orphaned(); | |
69
82290dc1403c
Fix crash in FBGUI renderer shutdown
Ivo Smits <Ivo@UCIS.nl>
parents:
42
diff
changeset
|
784 lock (RenderLock) { |
82290dc1403c
Fix crash in FBGUI renderer shutdown
Ivo Smits <Ivo@UCIS.nl>
parents:
42
diff
changeset
|
785 if (Frontbuffer != null) Frontbuffer.Dispose(); |
82290dc1403c
Fix crash in FBGUI renderer shutdown
Ivo Smits <Ivo@UCIS.nl>
parents:
42
diff
changeset
|
786 Frontbuffer = null; |
82290dc1403c
Fix crash in FBGUI renderer shutdown
Ivo Smits <Ivo@UCIS.nl>
parents:
42
diff
changeset
|
787 } |
23 | 788 } |
789 public Bitmap LockBitmapBuffer() { | |
790 Monitor.Enter(RenderLock); | |
791 return Frontbuffer; | |
792 } | |
793 public void UnlockBitmapBuffer() { | |
794 Monitor.Exit(RenderLock); | |
795 } | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
796 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
|
797 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
|
798 HandleEvent(e); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
799 UpdateCursor(cursorposition, e.Cursor); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
800 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
801 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
|
802 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
|
803 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
|
804 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
|
805 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
|
806 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
|
807 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
|
808 public void KeyUp(Keys key, Char keyChar) { HandleEvent(new FBGKeyboardEvent(key, keyChar, false)); } |
23 | 809 } |
810 public class FBGForm : FBGDockContainer { | |
811 private Point prevPosition = Point.Empty; | |
812 private NonClientOps moveresize = 0; | |
813 private String text = String.Empty; | |
814 public event EventHandler TextChanged; | |
31 | 815 public event EventHandler Closed; |
23 | 816 public Boolean Sizable { get; set; } |
817 public Boolean Movable { get; set; } | |
818 public Boolean Closable { get; set; } | |
819 [Flags] | |
820 private enum NonClientOps : int { | |
821 None = 0, | |
822 Move = 1, | |
823 ResizeLeft = 2, | |
824 ResizeRight = 4, | |
825 ResizeTop = 8, | |
826 ResizeBottom = 16, | |
827 ButtonClose = 32, | |
828 MoveResize = ResizeLeft | ResizeRight | ResizeBottom | ResizeTop | Move, | |
829 } | |
78 | 830 public override Rectangle ClientRectangle { get { return new Rectangle(4, 22, Bounds.Width - 8, Bounds.Height - 26); } } |
23 | 831 public FBGForm(IFBGContainerControl parent) : base(parent) { |
832 BackColor = SystemColors.Control; | |
833 Sizable = true; | |
834 Movable = true; | |
835 Closable = false; | |
836 } | |
837 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
|
838 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
|
839 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
|
840 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
|
841 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
|
842 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
|
843 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
|
844 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
|
845 } |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
846 if (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
|
847 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
|
848 } |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
849 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
|
850 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
|
851 } |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
852 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
|
853 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
|
854 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
|
855 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
|
856 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
|
857 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
|
858 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
|
859 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
|
860 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
|
861 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
|
862 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
|
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 } |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
865 protected override void HandlePointingEvent(FBGPointingEvent e) { |
39
41b2d01ae458
FBGUI: Fixed cursor handling in forms
Ivo Smits <Ivo@UCIS.nl>
parents:
34
diff
changeset
|
866 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
|
867 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
|
868 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
869 Boolean HandlePointingEventA(FBGPointingEvent e) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
870 switch (e.Type) { |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
871 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
|
872 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
|
873 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
|
874 default: return true; |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
875 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
876 } |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
877 Boolean MouseDown(Point p, MouseButtons buttons, FBGPointingEvent e) { |
23 | 878 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
|
879 if ((buttons & MouseButtons.Left) != 0) mr = GetNonClientOperation(p); |
23 | 880 if (mr != 0) { |
881 moveresize = mr; | |
882 prevPosition = p; | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
883 SetCursorForNonClientOperation(moveresize, e); |
23 | 884 CaptureMouse(true); |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
885 return false; |
23 | 886 } else { |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
887 return true; |
23 | 888 } |
889 } | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
890 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
|
891 NonClientOps mr = moveresize; |
41b2d01ae458
FBGUI: Fixed cursor handling in forms
Ivo Smits <Ivo@UCIS.nl>
parents:
34
diff
changeset
|
892 if (mr == 0) mr = GetNonClientOperation(position); |
41b2d01ae458
FBGUI: Fixed cursor handling in forms
Ivo Smits <Ivo@UCIS.nl>
parents:
34
diff
changeset
|
893 if (mr == 0) return true; |
41b2d01ae458
FBGUI: Fixed cursor handling in forms
Ivo Smits <Ivo@UCIS.nl>
parents:
34
diff
changeset
|
894 SetCursorForNonClientOperation(mr, e); |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
895 if ((moveresize & NonClientOps.MoveResize) != 0) { |
23 | 896 Rectangle b = Bounds; |
897 int dx = position.X - prevPosition.X; | |
898 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
|
899 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
|
900 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
|
901 } |
23 | 902 if ((moveresize & NonClientOps.ResizeLeft) != 0) { |
903 b.X += dx; | |
904 b.Width -= dx; | |
905 } else if ((moveresize & NonClientOps.ResizeRight) != 0) { | |
906 b.Width += dx; | |
907 prevPosition.X = position.X; | |
908 } | |
909 if ((moveresize & NonClientOps.ResizeTop) != 0) { | |
910 b.Y += dy; | |
911 b.Height -= dy; | |
912 } else if ((moveresize & NonClientOps.ResizeBottom) != 0) { | |
913 b.Height += dy; | |
914 prevPosition.Y = position.Y; | |
915 } | |
916 if (b.Width < 55) b.Width = 55; | |
917 if (b.Height < 25) b.Height = 25; | |
918 Bounds = b; | |
919 } | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
920 return false; |
23 | 921 } |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
922 Boolean MouseUp(Point position, MouseButtons buttons, FBGPointingEvent e) { |
23 | 923 if (moveresize == 0) { |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
924 SetCursorForNonClientOperation(GetNonClientOperation(position), e); |
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
925 return true; |
23 | 926 } else if ((buttons & MouseButtons.Left) != 0) { |
927 MouseMove(position, buttons); | |
928 CaptureMouse(false); | |
929 if (moveresize == NonClientOps.ButtonClose && (new Rectangle(Bounds.Width - 5 - 14, 4, 14, 14)).Contains(position) && Closable) Close(); | |
930 moveresize = 0; | |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
931 SetCursorForNonClientOperation(GetNonClientOperation(position), e); |
23 | 932 } |
32
ff1bc8445743
FBGUI: Changed event handling and propagation to be more extensible
Ivo Smits <Ivo@UCIS.nl>
parents:
31
diff
changeset
|
933 return false; |
23 | 934 } |
935 protected override void Paint(Graphics g) { | |
936 base.Paint(g); | |
937 g.DrawRectangle(Pens.Gray, 0, 0, Bounds.Width - 1, Bounds.Height - 1); | |
938 g.DrawRectangle(Pens.LightGray, 1, 1, Bounds.Width - 3, Bounds.Height - 3); | |
939 g.DrawRectangle(Pens.DarkGray, 2, 20, Bounds.Width - 5, Bounds.Height - 23); | |
940 g.DrawRectangle(Pens.Gray, 3, 21, Bounds.Width - 7, Bounds.Height - 25); | |
941 using (Brush b = new LinearGradientBrush(new Rectangle(0, 1, 1, 18), Color.Gray, Color.LightGray, LinearGradientMode.Vertical)) | |
942 g.FillRectangle(b, 2, 2, Bounds.Width - 4, 18); | |
943 | |
944 g.DrawString(Text, SystemFonts.CaptionFont, Brushes.Black, 4, 1); | |
945 | |
946 g.DrawRectangle(Pens.Gray, Bounds.Width - 5 - 14, 4, 14, 14); | |
947 g.DrawRectangle(Pens.Gray, Bounds.Width - 5 - 14 - 16, 4, 14, 14); | |
948 g.DrawRectangle(Pens.Gray, Bounds.Width - 5 - 14 - 32, 4, 14, 14); | |
949 using (Brush b = new LinearGradientBrush(new Rectangle(0, 5, 1, 13), Color.LightGray, Color.DarkGray, LinearGradientMode.Vertical)) { | |
950 g.FillRectangle(b, Bounds.Width - 5 - 14 + 1, 5, 13, 13); | |
951 g.FillRectangle(b, Bounds.Width - 5 - 14 + 1 - 16, 5, 13, 13); | |
952 g.FillRectangle(b, Bounds.Width - 5 - 14 + 1 - 32, 5, 13, 13); | |
953 } | |
954 if (Closable) { | |
955 g.DrawLine(Pens.Black, Bounds.Width - 5 - 14 + 3, 4 + 3, Bounds.Width - 5 - 14 + 14 - 3, 4 + 14 - 3); | |
956 g.DrawLine(Pens.Black, Bounds.Width - 5 - 14 + 3, 4 + 14 - 3, Bounds.Width - 5 - 14 + 14 - 3, 4 + 3); | |
957 } | |
958 } | |
959 public void Close() { | |
960 Parent.RemoveControl(this); | |
31 | 961 RaiseEvent(Closed); |
23 | 962 } |
963 } | |
964 public class FBGDesktop : FBGContainerControl { | |
965 FBGContainerControl windowcontainer; | |
966 FBGContainerControl menucontainer; | |
967 Boolean startup = true; | |
968 class FBGWindowState { | |
969 public IFBGControl Control; | |
970 public FBGButton MenuButton; | |
971 public Boolean Visible; | |
972 public Rectangle OldBounds; | |
973 public FBGWindowState(IFBGControl cntrl, FBGButton btn) { | |
974 Control = cntrl; | |
975 MenuButton = btn; | |
976 Visible = true; | |
977 } | |
978 } | |
979 Dictionary<IFBGControl, FBGWindowState> windowstates = new Dictionary<IFBGControl, FBGWindowState>(); | |
980 public FBGDesktop(IFBGContainerControl parent) : base(parent) { | |
981 menucontainer = new FBGContainerControl(this); | |
982 menucontainer.Bounds = new Rectangle(0, Bounds.Height - 25, Bounds.Width, 25); | |
983 windowcontainer = new FBGContainerControl(this); | |
984 windowcontainer.Bounds = new Rectangle(0, 0, Bounds.Width, Bounds.Height - 25); | |
985 startup = false; | |
986 } | |
987 public override Rectangle Bounds { | |
988 get { return base.Bounds; } | |
989 set { | |
990 if (Bounds == value) return; | |
991 base.Bounds = value; | |
992 if (startup) return; | |
993 menucontainer.Bounds = new Rectangle(0, value.Height - 25, value.Width, 25); | |
994 windowcontainer.Bounds = new Rectangle(0, 0, value.Width, value.Height - 25); | |
995 ScaleMenuButtons(); | |
996 } | |
997 } | |
998 protected override void AddControl(IFBGControl control) { | |
999 if (startup) { | |
1000 base.AddControl(control); | |
1001 return; | |
1002 } | |
1003 ((IFBGContainerControl)windowcontainer).AddControl(control); | |
1004 FBGButton btn = new FBGButton(menucontainer); | |
1005 FBGForm formcontrol = control as FBGForm; | |
1006 if (formcontrol == null) { | |
1007 btn.Text = "Untitled"; | |
1008 } else { | |
1009 formcontrol.TextChanged += delegate(Object sender, EventArgs e) { | |
1010 btn.Text = formcontrol.Text; | |
1011 }; | |
1012 btn.Text = formcontrol.Text; | |
1013 } | |
1014 FBGWindowState ws = new FBGWindowState(control, btn); | |
1015 windowstates.Add(control, ws); | |
1016 ScaleMenuButtons(); | |
1017 btn.Click += delegate(Object sender, EventArgs e) { | |
1018 if (ws.Visible) { | |
1019 if (ws.MenuButton.BackColor == Color.DarkGray) { | |
1020 ws.OldBounds = ws.Control.Bounds; | |
1021 ws.Visible = false; | |
1022 ws.Control.Bounds = Rectangle.Empty; | |
1023 } else { | |
1024 windowcontainer.BringControlToFront(ws.Control); | |
1025 foreach (FBGWindowState wsa in windowstates.Values) if (!ReferenceEquals(ws, wsa)) wsa.MenuButton.BackColor = SystemColors.ButtonFace; | |
1026 ws.MenuButton.BackColor = Color.DarkGray; | |
1027 } | |
1028 } else { | |
1029 ws.Control.Bounds = ws.OldBounds; | |
1030 ws.Visible = true; | |
1031 windowcontainer.BringControlToFront(ws.Control); | |
1032 foreach (FBGWindowState wsa in windowstates.Values) if (!ReferenceEquals(ws, wsa)) wsa.MenuButton.BackColor = SystemColors.ButtonFace; | |
1033 ws.MenuButton.BackColor = Color.DarkGray; | |
1034 } | |
1035 }; | |
1036 } | |
1037 public override void RemoveControl(IFBGControl control) { | |
1038 windowcontainer.RemoveControl(control); | |
1039 windowstates.Remove(control); | |
1040 ScaleMenuButtons(); | |
1041 } | |
1042 private void ScaleMenuButtons() { | |
1043 int bcount = windowstates.Count; | |
1044 int bwidth = 200; | |
1045 int twidth = bwidth * bcount; | |
1046 if (twidth > Bounds.Width) bwidth = menucontainer.Bounds.Width / bcount; | |
1047 int i = 0; | |
1048 foreach (FBGWindowState ws in windowstates.Values) { | |
1049 ws.MenuButton.Bounds = new Rectangle(i * bwidth, 0, bwidth, 25); | |
1050 i++; | |
1051 } | |
1052 } | |
1053 protected override void Paint(Graphics g) { | |
1054 base.Paint(g); | |
1055 g.DrawLine(Pens.Black, 0, Bounds.Height - 25, Bounds.Width, Bounds.Height - 25); | |
1056 } | |
1057 protected override void MouseDown(Point position, MouseButtons buttons) { | |
1058 IFBGControl control = FindControlAtPosition(position); | |
1059 if (ReferenceEquals(control, windowcontainer)) { | |
1060 control = windowcontainer.FindControlAtPosition(PointToChild(windowcontainer, position)); | |
1061 if (!ReferenceEquals(control, null)) { | |
1062 windowcontainer.BringControlToFront(control); | |
1063 foreach (FBGWindowState ws in windowstates.Values) | |
1064 ws.MenuButton.BackColor = ReferenceEquals(ws.Control, control) ? Color.DarkGray : SystemColors.ButtonFace; | |
1065 } | |
1066 } | |
1067 base.MouseDown(position, buttons); | |
1068 } | |
1069 } | |
1070 | |
1071 public class FBGLabel : FBGControl, IDisposable { | |
1072 public FBGLabel(IFBGContainerControl parent) : base(parent) { | |
1073 Size = new Size(200, 16); | |
1074 } | |
1075 private String text = String.Empty; | |
1076 private Font font = SystemFonts.DefaultFont; | |
1077 private Brush brush = SystemBrushes.ControlText; | |
1078 private StringFormat stringformat = new StringFormat(); | |
1079 public String Text { get { return text; } set { text = value; Invalidate(); } } | |
1080 public Font Font { get { return font; } set { font = value; Invalidate(); } } | |
1081 public Brush Brush { get { return brush; } set { brush = value; Invalidate(); } } | |
1082 public Color Color { set { Brush = new SolidBrush(value); } } | |
1083 public StringAlignment Alignment { get { return stringformat.Alignment; } set { stringformat.Alignment = value; Invalidate(); } } | |
1084 public StringFormatFlags FormatFlags { get { return stringformat.FormatFlags; } set { stringformat.FormatFlags = value; Invalidate(); } } | |
1085 public StringAlignment LineAlignment { get { return stringformat.LineAlignment; } set { stringformat.LineAlignment = value; Invalidate(); } } | |
1086 public StringTrimming Trimming { get { return stringformat.Trimming; } set { stringformat.Trimming = value; Invalidate(); } } | |
1087 protected override void Paint(Graphics g) { | |
1088 base.Paint(g); | |
1089 g.DrawString(text, font, brush, new Rectangle(Point.Empty, Bounds.Size), stringformat); | |
1090 } | |
1091 public void Dispose() { | |
1092 stringformat.Dispose(); | |
1093 } | |
1094 protected override void Orphaned() { | |
1095 base.Orphaned(); | |
1096 Dispose(); | |
1097 } | |
1098 } | |
1099 public class FBGTextBox : FBGControl { | |
1100 public FBGTextBox(IFBGContainerControl parent) : base(parent) { | |
1101 BackColor = Color.White; | |
1102 Size = new Size(200, 20); | |
1103 } | |
1104 private String text = String.Empty; | |
1105 private Char passwordChar = (Char)0; | |
1106 private Font font = new Font(FontFamily.GenericMonospace, 10); | |
1107 private Brush brush = SystemBrushes.ControlText; | |
1108 private Boolean hasKeyboardFocus = false; | |
1109 public String Text { get { return text; } set { text = value; if (CaretPosition > text.Length) CaretPosition = text.Length; Invalidate(); RaiseEvent(TextChanged); } } | |
1110 public Font Font { get { return font; } set { font = value; Invalidate(); } } | |
1111 public Brush Brush { get { return brush; } set { brush = value; Invalidate(); } } | |
1112 public Color Color { set { Brush = new SolidBrush(value); } } | |
1113 public Int32 CaretPosition { get; private set; } | |
1114 public Char PasswordChar { get { return passwordChar; } set { passwordChar = value; Invalidate(); } } | |
1115 public event EventHandler TextChanged; | |
1116 public event KeyPressEventHandler OnKeyPress; | |
1117 protected override void Paint(Graphics g) { | |
1118 base.Paint(g); | |
1119 g.DrawRectangle(Pens.Gray, 0, 0, Bounds.Width - 1, Bounds.Height - 1); | |
1120 using (StringFormat sf_nonprinting = new StringFormat(StringFormat.GenericTypographic)) { | |
1121 sf_nonprinting.Trimming = StringTrimming.None; | |
1122 sf_nonprinting.FormatFlags = StringFormatFlags.DisplayFormatControl | StringFormatFlags.MeasureTrailingSpaces; | |
1123 sf_nonprinting.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.None; | |
1124 | |
1125 float x = 1; | |
1126 float y = 1; | |
1127 float w = Width - 2; | |
1128 if (hasKeyboardFocus && CaretPosition == 0) { | |
1129 g.DrawLine(Pens.Black, x + 2, 2, x + 2, Height - 4); | |
1130 } | |
1131 String c = passwordChar == 0 ? null : new String(passwordChar, 1); | |
1132 for (int i = 0; i < text.Length; i++) { | |
1133 if (passwordChar == 0) c = text.Substring(i, 1); | |
1134 SizeF s = g.MeasureString(c, font, (int)Math.Ceiling(w), sf_nonprinting); | |
1135 g.DrawString(c, font, brush, x, y); | |
1136 x += (float)Math.Ceiling(s.Width); | |
1137 w -= (float)Math.Ceiling(s.Width); | |
1138 | |
1139 if (hasKeyboardFocus && i == CaretPosition - 1) { | |
1140 g.DrawLine(Pens.Black, x + 2, 2, x + 2, Height - 4); | |
1141 } | |
1142 } | |
1143 } | |
1144 } | |
1145 protected override void MouseDown(Point position, MouseButtons buttons) { | |
1146 hasKeyboardFocus = CaptureKeyboard(true); | |
1147 CaretPosition = text.Length; | |
1148 float x = 1; | |
1149 String c = passwordChar == 0 ? null : new String(passwordChar, 1); | |
1150 for (int i = 0; i < text.Length; i++) { | |
1151 if (passwordChar == 0) c = text.Substring(i, 1); | |
1152 Size s; | |
1153 try { | |
1154 s = TextRenderer.MeasureText(c, font, Size.Empty, TextFormatFlags.NoPadding | TextFormatFlags.NoPrefix); | |
1155 } catch (Exception) { | |
1156 break; | |
1157 } | |
1158 x += s.Width; | |
1159 if (position.X < x) { | |
1160 CaretPosition = i; | |
1161 break; | |
1162 } | |
1163 } | |
1164 Invalidate(); | |
1165 } | |
1166 protected override void KeyDown(Keys key) { | |
1167 if ((key & Keys.KeyCode) == Keys.Left) { | |
1168 CaretPosition--; | |
1169 if (CaretPosition < 0) CaretPosition = 0; | |
1170 Invalidate(); | |
1171 } else if ((key & Keys.KeyCode) == Keys.Right) { | |
1172 CaretPosition++; | |
1173 if (CaretPosition > text.Length) CaretPosition = text.Length; | |
1174 Invalidate(); | |
1175 } else if ((key & Keys.KeyCode) == Keys.Home) { | |
1176 CaretPosition = 0; | |
1177 Invalidate(); | |
1178 } else if ((key & Keys.KeyCode) == Keys.End) { | |
1179 CaretPosition = text.Length; | |
1180 Invalidate(); | |
1181 } else if ((key & Keys.Control) != 0 && (key & Keys.KeyCode) == Keys.V) { | |
1182 String cbtext = Clipboard.GetText(TextDataFormat.UnicodeText); | |
1183 CaretPosition += cbtext.Length; | |
1184 Text = Text.Insert(CaretPosition - cbtext.Length, cbtext); | |
1185 } | |
1186 } | |
1187 protected override void KeyPress(char keyChar) { | |
1188 KeyPressEventArgs e = new KeyPressEventArgs(keyChar); | |
1189 RaiseEvent(OnKeyPress, e); | |
1190 if (e.Handled) return; | |
1191 hasKeyboardFocus = true; | |
1192 if (keyChar == 8) { | |
1193 if (CaretPosition > 0) { | |
1194 CaretPosition--; | |
1195 Text = Text.Remove(CaretPosition, 1); | |
1196 } | |
1197 } else if (keyChar == 127) { | |
1198 if (CaretPosition < Text.Length) { | |
1199 Text = Text.Remove(CaretPosition, 1); | |
1200 } | |
1201 } else if (keyChar < 32) { | |
1202 } else { | |
1203 CaretPosition++; | |
1204 Text = Text.Insert(CaretPosition - 1, new String(keyChar, 1)); | |
1205 } | |
1206 } | |
1207 public void Focus() { | |
1208 hasKeyboardFocus = CaptureKeyboard(true); | |
1209 } | |
1210 protected override void LostKeyboardCapture() { | |
1211 base.LostKeyboardCapture(); | |
1212 hasKeyboardFocus = false; | |
1213 Invalidate(); | |
1214 } | |
1215 } | |
1216 public class FBGButton : FBGControl { | |
1217 public FBGButton(IFBGContainerControl parent) : base(parent) { | |
1218 BackColor = SystemColors.ButtonFace; | |
1219 } | |
1220 private String text = String.Empty; | |
1221 private Font font = SystemFonts.DefaultFont; | |
1222 private Color color = SystemColors.ControlText; | |
1223 private Boolean pressed = false; | |
1224 private Boolean enabled = true; | |
1225 public String Text { get { return text; } set { text = value; Invalidate(); } } | |
1226 public Font Font { get { return font; } set { font = value; Invalidate(); } } | |
1227 public Color Color { get { return color; } set { color = value; Invalidate(); } } | |
1228 public Boolean Enabled { get { return enabled; } set { enabled = value; Invalidate(); } } | |
1229 public event EventHandler Click; | |
1230 protected override void Paint(Graphics g) { | |
1231 base.Paint(g); | |
1232 if (Bounds.Width == 0 || Bounds.Height == 0) return; | |
1233 if (BackColor == SystemColors.ButtonFace) { | |
1234 ControlPaint.DrawButton(g, new Rectangle(0, 0, Bounds.Width, Bounds.Height), enabled ? (pressed ? ButtonState.Pushed : ButtonState.Normal) : ButtonState.Inactive); | |
1235 } else { | |
1236 //Hackish and not completely right... | |
1237 //Todo: borrowed from mono... possible licencing issues!? | |
1238 g.DrawLine(new Pen(ControlPaint.LightLight(BackColor)), 0, 0, Bounds.Width, 0); | |
1239 g.DrawLine(new Pen(ControlPaint.LightLight(BackColor)), 0, 0, 0, Bounds.Height); | |
1240 g.DrawLine(new Pen(ControlPaint.Dark(BackColor)), 1, Bounds.Height - 2, Bounds.Width - 1, Bounds.Height - 2); | |
1241 g.DrawLine(new Pen(ControlPaint.Dark(BackColor)), Bounds.Width - 2, 1, Bounds.Width - 2, Bounds.Height - 2); | |
1242 g.DrawLine(new Pen(ControlPaint.DarkDark(BackColor)), 0, Bounds.Height - 1, Bounds.Width, Bounds.Height - 1); | |
1243 g.DrawLine(new Pen(ControlPaint.DarkDark(BackColor)), Bounds.Width - 1, 1, Bounds.Width - 1, Bounds.Height - 1); | |
1244 Graphics dc = g; | |
1245 Rectangle rectangle = new Rectangle(0, 0, Bounds.Width - 1, Bounds.Height - 1); | |
1246 Color ColorControl = BackColor; | |
1247 Color ColorControlLight = ControlPaint.Light(ColorControl); | |
1248 ButtonState state = pressed ? ButtonState.Pushed : ButtonState.Normal; | |
1249 using (Pen NormalPen = new Pen(BackColor), LightPen = new Pen(ControlPaint.Light(BackColor)), DarkPen = new Pen(ControlPaint.Dark(BackColor))) { | |
1250 // sadly enough, the rectangle gets always filled with a hatchbrush | |
1251 using (HatchBrush hb = new HatchBrush(HatchStyle.Percent50, Color.FromArgb(Math.Min(255, ColorControl.R + 3), ColorControl.G, ColorControl.B), ColorControl)) { | |
1252 dc.FillRectangle(hb, rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2); | |
1253 } | |
1254 if ((state & ButtonState.All) == ButtonState.All || ((state & ButtonState.Checked) == ButtonState.Checked && (state & ButtonState.Flat) == ButtonState.Flat)) { | |
1255 using (HatchBrush hb = new HatchBrush(HatchStyle.Percent50, ColorControlLight, ColorControl)) { | |
1256 dc.FillRectangle(hb, rectangle.X + 2, rectangle.Y + 2, rectangle.Width - 4, rectangle.Height - 4); | |
1257 } | |
1258 dc.DrawRectangle(SystemPens.ControlDark, rectangle.X, rectangle.Y, rectangle.Width - 1, rectangle.Height - 1); | |
1259 } else if ((state & ButtonState.Flat) == ButtonState.Flat) { | |
1260 dc.DrawRectangle(SystemPens.ControlDark, rectangle.X, rectangle.Y, rectangle.Width - 1, rectangle.Height - 1); | |
1261 } else if ((state & ButtonState.Checked) == ButtonState.Checked) { | |
1262 using (HatchBrush hb = new HatchBrush(HatchStyle.Percent50, ColorControlLight, ColorControl)) { | |
1263 dc.FillRectangle(hb, rectangle.X + 2, rectangle.Y + 2, rectangle.Width - 4, rectangle.Height - 4); | |
1264 } | |
1265 Pen pen = DarkPen; | |
1266 dc.DrawLine(pen, rectangle.X, rectangle.Y, rectangle.X, rectangle.Bottom - 2); | |
1267 dc.DrawLine(pen, rectangle.X + 1, rectangle.Y, rectangle.Right - 2, rectangle.Y); | |
1268 | |
1269 pen = NormalPen; | |
1270 dc.DrawLine(pen, rectangle.X + 1, rectangle.Y + 1, rectangle.X + 1, rectangle.Bottom - 3); | |
1271 dc.DrawLine(pen, rectangle.X + 2, rectangle.Y + 1, rectangle.Right - 3, rectangle.Y + 1); | |
1272 | |
1273 pen = LightPen; | |
1274 dc.DrawLine(pen, rectangle.X, rectangle.Bottom - 1, rectangle.Right - 2, rectangle.Bottom - 1); | |
1275 dc.DrawLine(pen, rectangle.Right - 1, rectangle.Y, rectangle.Right - 1, rectangle.Bottom - 1); | |
1276 } else if (((state & ButtonState.Pushed) == ButtonState.Pushed) && ((state & ButtonState.Normal) == ButtonState.Normal)) { | |
1277 Pen pen = DarkPen; | |
1278 dc.DrawLine(pen, rectangle.X, rectangle.Y, rectangle.X, rectangle.Bottom - 2); | |
1279 dc.DrawLine(pen, rectangle.X + 1, rectangle.Y, rectangle.Right - 2, rectangle.Y); | |
1280 | |
1281 pen = NormalPen; | |
1282 dc.DrawLine(pen, rectangle.X + 1, rectangle.Y + 1, rectangle.X + 1, rectangle.Bottom - 3); | |
1283 dc.DrawLine(pen, rectangle.X + 2, rectangle.Y + 1, rectangle.Right - 3, rectangle.Y + 1); | |
1284 | |
1285 pen = LightPen; | |
1286 dc.DrawLine(pen, rectangle.X, rectangle.Bottom - 1, rectangle.Right - 2, rectangle.Bottom - 1); | |
1287 dc.DrawLine(pen, rectangle.Right - 1, rectangle.Y, rectangle.Right - 1, rectangle.Bottom - 1); | |
1288 } else if (((state & ButtonState.Inactive) == ButtonState.Inactive) || ((state & ButtonState.Normal) == ButtonState.Normal)) { | |
1289 Pen pen = LightPen; | |
1290 dc.DrawLine(pen, rectangle.X, rectangle.Y, rectangle.Right - 2, rectangle.Y); | |
1291 dc.DrawLine(pen, rectangle.X, rectangle.Y, rectangle.X, rectangle.Bottom - 2); | |
1292 | |
1293 pen = NormalPen; | |
1294 dc.DrawLine(pen, rectangle.X + 1, rectangle.Bottom - 2, rectangle.Right - 2, rectangle.Bottom - 2); | |
1295 dc.DrawLine(pen, rectangle.Right - 2, rectangle.Y + 1, rectangle.Right - 2, rectangle.Bottom - 3); | |
1296 | |
1297 pen = DarkPen; | |
1298 dc.DrawLine(pen, rectangle.X, rectangle.Bottom - 1, rectangle.Right - 1, rectangle.Bottom - 1); | |
1299 dc.DrawLine(pen, rectangle.Right - 1, rectangle.Y, rectangle.Right - 1, rectangle.Bottom - 2); | |
1300 } | |
1301 } | |
1302 } | |
1303 Rectangle frect = new Rectangle(Point.Empty, Bounds.Size); | |
1304 SizeF textsize = g.MeasureString(Text, Font); | |
1305 using (Brush b = new SolidBrush(enabled ? Color : Color.DarkGray)) { | |
1306 g.DrawString(Text, Font, b, new PointF(Bounds.Width / 2.0f - textsize.Width / 2.0f, Bounds.Height / 2.0f - textsize.Height / 2.0f)); | |
1307 } | |
1308 } | |
1309 protected override void MouseDown(Point position, MouseButtons buttons) { | |
1310 pressed = true; | |
1311 Invalidate(); | |
1312 CaptureMouse(true); | |
1313 base.MouseDown(position, buttons); | |
1314 } | |
1315 protected override void MouseUp(Point position, MouseButtons buttons) { | |
1316 pressed = false; | |
1317 Invalidate(); | |
1318 CaptureMouse(false); | |
1319 if (position.X >= 0 && position.X <= Bounds.Width && position.Y >= 0 && position.Y <= Bounds.Height && enabled) RaiseEvent(Click); | |
1320 base.MouseUp(position, buttons); | |
1321 } | |
1322 protected override void KeyDown(Keys key) { | |
1323 if (key == Keys.Return || key == Keys.Space) { | |
1324 pressed = true; | |
1325 Invalidate(); | |
1326 } | |
1327 base.KeyDown(key); | |
1328 } | |
1329 protected override void KeyUp(Keys key) { | |
1330 if (key == Keys.Return || key == Keys.Space) { | |
1331 if (pressed) RaiseEvent(Click); | |
1332 pressed = false; | |
1333 Invalidate(); | |
1334 } | |
1335 base.KeyUp(key); | |
1336 } | |
1337 public void Focus() { | |
1338 CaptureKeyboard(true); | |
1339 } | |
1340 } | |
1341 public class FBGCheckBox : FBGControl { | |
1342 public FBGCheckBox(IFBGContainerControl parent) : base(parent) { } | |
1343 private String text = String.Empty; | |
1344 private Font font = SystemFonts.DefaultFont; | |
1345 private Color color = SystemColors.ControlText; | |
1346 private Boolean _checked = false; | |
1347 public String Text { get { return text; } set { text = value; Invalidate(); } } | |
1348 public Font Font { get { return font; } set { font = value; Invalidate(); } } | |
1349 public Color Color { get { return color; } set { color = value; Invalidate(); } } | |
1350 public Boolean Checked { get { return _checked; } set { _checked = value; Invalidate(); } } | |
1351 public event EventHandler CheckedChanged; | |
1352 protected override void Paint(Graphics g) { | |
1353 base.Paint(g); | |
1354 ControlPaint.DrawCheckBox(g, 0, 0, 13, 13, _checked ? ButtonState.Checked : ButtonState.Normal); | |
1355 g.DrawString(Text, Font, new SolidBrush(Color), 15, 0); | |
1356 } | |
1357 protected override void MouseDown(Point position, MouseButtons buttons) { | |
1358 Checked = !Checked; | |
1359 RaiseEvent(CheckedChanged); | |
1360 base.MouseDown(position, buttons); | |
1361 } | |
1362 } | |
1363 public class FBGImageBox : FBGControl { | |
1364 Image image = null; | |
33 | 1365 Image scaledImage = null; |
1366 Size imageSize; | |
1367 Boolean ownsImage = false; | |
34
70bde4fa6a2f
FBGUI: Fixed image scaling in FBGImageBox
Ivo Smits <Ivo@UCIS.nl>
parents:
33
diff
changeset
|
1368 Boolean shouldScaleImage = false; |
23 | 1369 PictureBoxSizeMode sizeMode = PictureBoxSizeMode.Normal; |
1370 Rectangle imageRect; | |
33 | 1371 public Image Image { get { return image; } set { SetImage(value, false); } } |
1372 public Boolean PreScaleImage { get; set; } | |
1373 public void SetOwnedImage(Image img) { SetImage(img, true); } | |
1374 private void SetImage(Image img, Boolean owned) { | |
1375 image = img; | |
1376 imageSize = img == null ? Size.Empty : img.Size; | |
1377 ownsImage = owned; | |
1378 UpdateImageRect(Size.Empty); | |
1379 } | |
23 | 1380 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
|
1381 public PictureBoxSizeMode SizeMode { get { return sizeMode; } set { sizeMode = value; UpdateImageRect(Size.Empty); } } |
23 | 1382 public override Rectangle Bounds { |
1383 get { | |
1384 return base.Bounds; | |
1385 } | |
1386 set { | |
33 | 1387 if (Bounds.Size != value.Size) UpdateImageRect(value.Size); |
23 | 1388 base.Bounds = value; |
1389 } | |
1390 } | |
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
|
1391 private void UpdateImageRect(Size csize) { |
34
70bde4fa6a2f
FBGUI: Fixed image scaling in FBGImageBox
Ivo Smits <Ivo@UCIS.nl>
parents:
33
diff
changeset
|
1392 shouldScaleImage = false; |
70bde4fa6a2f
FBGUI: Fixed image scaling in FBGImageBox
Ivo Smits <Ivo@UCIS.nl>
parents:
33
diff
changeset
|
1393 if (scaledImage != null) scaledImage.Dispose(); |
33 | 1394 scaledImage = null; |
23 | 1395 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
|
1396 Boolean boundsset = !csize.IsEmpty; |
23 | 1397 if (!boundsset && sizeMode == PictureBoxSizeMode.AutoSize) { |
33 | 1398 Size = imageSize; |
23 | 1399 return; |
1400 } | |
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
|
1401 if (!boundsset) csize = Bounds.Size; |
23 | 1402 switch (sizeMode) { |
1403 case PictureBoxSizeMode.AutoSize: | |
1404 case PictureBoxSizeMode.Normal: | |
33 | 1405 imageRect = new Rectangle(Point.Empty, imageSize); |
23 | 1406 break; |
1407 case PictureBoxSizeMode.CenterImage: | |
33 | 1408 imageRect = new Rectangle(csize.Width / 2 - imageSize.Width / 2, csize.Height / 2 - imageSize.Height / 2, imageSize.Width, imageSize.Height); |
23 | 1409 break; |
1410 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
|
1411 imageRect = new Rectangle(Point.Empty, csize); |
23 | 1412 break; |
1413 case PictureBoxSizeMode.Zoom: | |
33 | 1414 float xrat = (float)csize.Width / (float)imageSize.Width; |
1415 float yrat = (float)csize.Height / (float)imageSize.Height; | |
23 | 1416 float rat = Math.Min(xrat, yrat); |
33 | 1417 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
|
1418 imageRect = Rectangle.Round(new RectangleF(csize.Width / 2f - dispsize.Width / 2f, csize.Height / 2f - dispsize.Height / 2f, dispsize.Width, dispsize.Height)); |
23 | 1419 break; |
1420 } | |
34
70bde4fa6a2f
FBGUI: Fixed image scaling in FBGImageBox
Ivo Smits <Ivo@UCIS.nl>
parents:
33
diff
changeset
|
1421 shouldScaleImage = imageRect.Size != imageSize; |
23 | 1422 if (!boundsset) Invalidate(); |
1423 } | |
1424 protected override void Paint(Graphics g) { | |
1425 if (!Visible) return; | |
1426 base.Paint(g); | |
34
70bde4fa6a2f
FBGUI: Fixed image scaling in FBGImageBox
Ivo Smits <Ivo@UCIS.nl>
parents:
33
diff
changeset
|
1427 if (shouldScaleImage && PreScaleImage && image != null) { |
70bde4fa6a2f
FBGUI: Fixed image scaling in FBGImageBox
Ivo Smits <Ivo@UCIS.nl>
parents:
33
diff
changeset
|
1428 scaledImage = new Bitmap(image, imageRect.Size); |
70bde4fa6a2f
FBGUI: Fixed image scaling in FBGImageBox
Ivo Smits <Ivo@UCIS.nl>
parents:
33
diff
changeset
|
1429 shouldScaleImage = false; |
70bde4fa6a2f
FBGUI: Fixed image scaling in FBGImageBox
Ivo Smits <Ivo@UCIS.nl>
parents:
33
diff
changeset
|
1430 } |
70bde4fa6a2f
FBGUI: Fixed image scaling in FBGImageBox
Ivo Smits <Ivo@UCIS.nl>
parents:
33
diff
changeset
|
1431 if (scaledImage != null) g.DrawImage(scaledImage, imageRect); |
70bde4fa6a2f
FBGUI: Fixed image scaling in FBGImageBox
Ivo Smits <Ivo@UCIS.nl>
parents:
33
diff
changeset
|
1432 else if (image != null) g.DrawImage(image, imageRect); |
23 | 1433 } |
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
|
1434 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
|
1435 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
|
1436 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
|
1437 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
|
1438 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
|
1439 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
|
1440 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
|
1441 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
|
1442 break; |
24e918d2ac18
FBGUI: Added per-control Cursor handling, added more cursors for Form operations, fixed ImageBox image sizing
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
1443 case PictureBoxSizeMode.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
|
1444 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
|
1445 default: |
33 | 1446 point.X = (point.X - imageRect.X) * imageSize.Width / imageRect.Width; |
1447 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
|
1448 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
|
1449 } |
24e918d2ac18
FBGUI: 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 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
|
1451 } |
33 | 1452 protected override void Orphaned() { |
1453 base.Orphaned(); | |
1454 if (scaledImage != null && scaledImage != image) scaledImage.Dispose(); | |
1455 scaledImage = null; | |
1456 if (ownsImage) { | |
1457 image.Dispose(); | |
1458 image = null; | |
1459 } | |
1460 } | |
23 | 1461 } |
1462 public class FBGListBox : FBGControl { | |
1463 private List<Object> items = new List<object>(); | |
1464 private Object selected = null; | |
1465 private Object highlighted = null; | |
1466 private Boolean hasScrollBar = false; | |
1467 private Boolean hitScrollBar = false; | |
1468 private int offset = 0; | |
1469 private ButtonState buttonUpState = ButtonState.Normal; | |
1470 private ButtonState buttonDownState = ButtonState.Normal; | |
1471 private Converter<Object, String> itemFormatter = null; | |
1472 public Converter<Object, String> ItemFormatter { get { return itemFormatter; } set { itemFormatter = value; Invalidate(); } } | |
1473 public FBGListBox(IFBGContainerControl parent) | |
1474 : base(parent) { | |
1475 BackColor = Color.White; | |
1476 } | |
78 | 1477 public int AddItem(Object item) { |
1478 int id = ((System.Collections.IList)items).Add(item); | |
1479 Invalidate(); | |
1480 return id; | |
1481 } | |
1482 public void RemoveItem(Object item) { | |
1483 items.Remove(item); | |
1484 if (offset >= items.Count) offset = Math.Max(0, items.Count - 1); | |
23 | 1485 Invalidate(); |
1486 } | |
78 | 1487 public void RemoveItemAt(int index) { |
1488 if (index < 0) index += items.Count; | |
1489 items.RemoveAt(index); | |
1490 if (offset >= index && offset > 0) offset--; | |
1491 Invalidate(); | |
1492 } | |
1493 public void Clear() { | |
1494 items.Clear(); | |
1495 offset = 0; | |
1496 Invalidate(); | |
1497 } | |
1498 public System.Collections.IList Items { get { return items.AsReadOnly(); } } | |
23 | 1499 protected override void Paint(Graphics g) { |
1500 base.Paint(g); | |
1501 g.DrawRectangle(Pens.DarkBlue, 0, 0, Bounds.Width - 1, Bounds.Height - 1); | |
1502 int lh = (int)Math.Ceiling(SystemFonts.DefaultFont.GetHeight()); | |
1503 int y = 2; | |
1504 using (Pen dottedpen = new Pen(Brushes.Black)) { | |
1505 dottedpen.DashStyle = DashStyle.Dot; | |
1506 using (StringFormat sf = new StringFormat(StringFormatFlags.NoWrap)) { | |
1507 for (int i = offset; i < items.Count; i++) { | |
1508 Object item = items[i]; | |
1509 String text = itemFormatter == null ? (item == null ? String.Empty : item.ToString()) : itemFormatter(item); | |
1510 if (item == selected) g.FillRectangle(Brushes.DarkGray, 2, y, Bounds.Width - 4, lh); | |
1511 if (item == highlighted) g.DrawRectangle(dottedpen, 2, y, Bounds.Width - 5, lh - 1); | |
1512 g.DrawString(text, SystemFonts.DefaultFont, SystemBrushes.WindowText, new Rectangle(3, y, Bounds.Width - 6, lh), sf); | |
1513 y += lh; | |
1514 if (y + lh + 2 >= Bounds.Height) break; | |
1515 } | |
1516 } | |
1517 } | |
78 | 1518 hasScrollBar = (y < 2 + lh * items.Count) || (offset != 0); |
23 | 1519 if (hasScrollBar) { |
1520 int xoff = Bounds.Width - 17; | |
1521 using (Brush b = new LinearGradientBrush(new Rectangle(xoff, 0, 17, 1), Color.LightGray, Color.White, LinearGradientMode.Horizontal)) | |
1522 g.FillRectangle(b, xoff, 17, 16, Bounds.Height - 17 - 17); | |
1523 ControlPaint.DrawScrollButton(g, xoff, 1, 16, 16, ScrollButton.Up, buttonUpState); | |
1524 ControlPaint.DrawScrollButton(g, xoff, Bounds.Height - 17, 16, 16, ScrollButton.Down, buttonDownState); | |
78 | 1525 if (items.Count > 1) g.DrawRectangle(Pens.Black, new Rectangle(xoff, 17 + offset * (Bounds.Height - 17 - 17 - 20) / (items.Count - 1), 15, 20)); |
23 | 1526 } |
1527 } | |
1528 protected override void MouseDown(Point position, MouseButtons buttons) { | |
1529 if ((buttons & MouseButtons.Left) != 0) { | |
1530 CaptureMouse(true); | |
1531 if (hasScrollBar && position.X > Bounds.Width - 17) { | |
1532 hitScrollBar = true; | |
78 | 1533 int off = offset; |
23 | 1534 if (position.Y < 17) { |
78 | 1535 off--; |
23 | 1536 buttonUpState = ButtonState.Pushed; |
1537 } else if (position.Y > Bounds.Height - 17) { | |
78 | 1538 off++; |
23 | 1539 buttonDownState = ButtonState.Pushed; |
1540 } else { | |
78 | 1541 off = (int)Math.Round((position.Y - 17) * (items.Count - 1) / (double)(Bounds.Height - 17 - 17 - 10)); |
23 | 1542 } |
78 | 1543 offset = Math.Max(0, Math.Min(items.Count - 1, off)); |
23 | 1544 Invalidate(); |
1545 } else { | |
1546 MouseHandler(position, buttons); | |
1547 } | |
1548 } | |
1549 } | |
1550 protected override void MouseMove(Point position, MouseButtons buttons) { | |
1551 if (hitScrollBar) { | |
1552 if (position.Y < 17) { | |
1553 } else if (position.Y > Bounds.Height - 17) { | |
1554 } else { | |
78 | 1555 offset = Math.Max(0, Math.Min(items.Count - 1, (int)Math.Round((position.Y - 17) * (items.Count - 1) / (double)(Bounds.Height - 17 - 17 - 10)))); |
23 | 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 } |