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