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