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