Mercurial > hg > ucis.core
comparison FBGUI/FBGUI.cs @ 78:1a10ca0f662e
FBGUI updates
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Sun, 16 Feb 2014 14:59:52 +0100 |
parents | 82290dc1403c |
children | 4e4c600031e2 |
comparison
equal
deleted
inserted
replaced
77:b5e27116bd2a | 78:1a10ca0f662e |
---|---|
93 } | 93 } |
94 public interface IFBGContainerControl { | 94 public interface IFBGContainerControl { |
95 void AddControl(IFBGControl control); | 95 void AddControl(IFBGControl control); |
96 void RemoveControl(IFBGControl control); | 96 void RemoveControl(IFBGControl control); |
97 void HandleMessage(IFBGControl sender, FBGMessage e); | 97 void HandleMessage(IFBGControl sender, FBGMessage e); |
98 Size ClientSize { get; } | |
98 } | 99 } |
99 | 100 |
100 public class FBGControl : IFBGControl { | 101 public class FBGControl : IFBGControl { |
101 private Rectangle bounds = new Rectangle(0, 0, 100, 100); | 102 private Rectangle bounds = new Rectangle(0, 0, 100, 100); |
102 private Color backColor = Color.Transparent; | 103 private Color backColor = Color.Transparent; |
213 } | 214 } |
214 public class FBGContainerControl : FBGControl, IFBGContainerControl { | 215 public class FBGContainerControl : FBGControl, IFBGContainerControl { |
215 protected List<IFBGControl> controls = new List<IFBGControl>(); | 216 protected List<IFBGControl> controls = new List<IFBGControl>(); |
216 protected IFBGControl mouseCaptureControl = null; | 217 protected IFBGControl mouseCaptureControl = null; |
217 protected IFBGControl keyboardCaptureControl = null; | 218 protected IFBGControl keyboardCaptureControl = null; |
218 private Rectangle childarea = Rectangle.Empty; | 219 public virtual Rectangle ClientRectangle { get { return Bounds; } } |
219 public Rectangle ClientRectangle { get { return childarea; } protected set { childarea = value; Invalidate(); } } | 220 public virtual Size ClientSize { get { return ClientRectangle.Size; } set { Bounds = new Rectangle(Bounds.Location, Bounds.Size - ClientRectangle.Size + value); } } |
220 public Size ClientSize { get { return childarea.Size; } set { Bounds = new Rectangle(Bounds.Location, Bounds.Size - childarea.Size + value); } } | |
221 public FBGContainerControl(IFBGContainerControl parent) : base(parent) { } | 221 public FBGContainerControl(IFBGContainerControl parent) : base(parent) { } |
222 void IFBGContainerControl.AddControl(IFBGControl control) { AddControl(control); } | 222 void IFBGContainerControl.AddControl(IFBGControl control) { AddControl(control); } |
223 protected virtual void AddControl(IFBGControl control) { | 223 protected virtual void AddControl(IFBGControl control) { |
224 controls.Add(control); | 224 controls.Add(control); |
225 if (control.Visible) Invalidate(control); | 225 if (control.Visible) Invalidate(control); |
251 public virtual void Invalidate(IFBGControl control, Rectangle rect) { | 251 public virtual void Invalidate(IFBGControl control, Rectangle rect) { |
252 Invalidate(new Rectangle(PointFromChild(control, rect.Location), rect.Size)); | 252 Invalidate(new Rectangle(PointFromChild(control, rect.Location), rect.Size)); |
253 } | 253 } |
254 protected override void HandlePaintEvent(FBGPaintEvent e) { | 254 protected override void HandlePaintEvent(FBGPaintEvent e) { |
255 base.HandlePaintEvent(e); | 255 base.HandlePaintEvent(e); |
256 if (controls == null) return; | |
257 GraphicsState state2 = null; | 256 GraphicsState state2 = null; |
258 Graphics g = e.Canvas; | 257 Graphics g = e.Canvas; |
259 if (!childarea.IsEmpty) { | 258 Rectangle childarea = ClientRectangle; |
259 if (childarea.X != 0 || childarea.Y != 0 || childarea.Width != Bounds.Width || childarea.Height != Bounds.Height) { | |
260 state2 = g.Save(); | 260 state2 = g.Save(); |
261 g.TranslateTransform(childarea.X, childarea.Y, MatrixOrder.Append); | 261 g.TranslateTransform(childarea.X, childarea.Y, MatrixOrder.Append); |
262 g.IntersectClip(new Rectangle(Point.Empty, childarea.Size)); | 262 g.IntersectClip(new Rectangle(Point.Empty, childarea.Size)); |
263 } | 263 } |
264 foreach (IFBGControl control in controls) { | 264 foreach (IFBGControl control in controls) { |
272 g.Restore(state); | 272 g.Restore(state); |
273 } | 273 } |
274 if (state2 != null) g.Restore(state2); | 274 if (state2 != null) g.Restore(state2); |
275 } | 275 } |
276 public IFBGControl FindControlAtPosition(Point p) { | 276 public IFBGControl FindControlAtPosition(Point p) { |
277 if (!childarea.IsEmpty && !childarea.Contains(p)) return null; | 277 Rectangle childarea = ClientRectangle; |
278 if (!childarea.Contains(p)) return null; | |
278 p.Offset(-childarea.X, -childarea.Y); | 279 p.Offset(-childarea.X, -childarea.Y); |
279 return ((List<IFBGControl>)controls).FindLast(delegate(IFBGControl control) { return control.Visible && control.Bounds.Contains(p); }); | 280 return ((List<IFBGControl>)controls).FindLast(delegate(IFBGControl control) { return control.Visible && control.Bounds.Contains(p); }); |
280 } | 281 } |
281 protected override void HandlePointingEvent(FBGPointingEvent e) { | 282 protected override void HandlePointingEvent(FBGPointingEvent e) { |
282 IFBGControl control = mouseCaptureControl != null ? mouseCaptureControl : FindControlAtPosition(e.Position); | 283 IFBGControl control = mouseCaptureControl != null ? mouseCaptureControl : FindControlAtPosition(e.Position); |
458 } | 459 } |
459 } | 460 } |
460 } | 461 } |
461 public class FBGGroupBox : FBGDockContainer { | 462 public class FBGGroupBox : FBGDockContainer { |
462 private String text = String.Empty; | 463 private String text = String.Empty; |
463 public FBGGroupBox(IFBGContainerControl parent) | 464 public override Rectangle ClientRectangle { get { return new Rectangle(1, 15, Bounds.Width - 2, Bounds.Height - 17); } } |
464 : base(parent) { | 465 public FBGGroupBox(IFBGContainerControl parent) : base(parent) { } |
465 ClientRectangle = new Rectangle(1, 15, Bounds.Width - 2, Bounds.Height - 17); | |
466 } | |
467 public override Rectangle Bounds { | |
468 get { return base.Bounds; } | |
469 set { | |
470 ClientRectangle = new Rectangle(1, 15, value.Width - 2, value.Height - 17); | |
471 base.Bounds = value; | |
472 } | |
473 } | |
474 public String Text { get { return text; } set { if (text == value) return; text = value; Invalidate(new Rectangle(0, 0, Bounds.Width, 15)); } } | 466 public String Text { get { return text; } set { if (text == value) return; text = value; Invalidate(new Rectangle(0, 0, Bounds.Width, 15)); } } |
475 protected override void Paint(Graphics g) { | 467 protected override void Paint(Graphics g) { |
476 base.Paint(g); | 468 base.Paint(g); |
477 g.DrawRectangle(Pens.Gray, 0, 6, Bounds.Width - 1, Bounds.Height - 7); | |
478 SizeF ss = g.MeasureString(Text, SystemFonts.DefaultFont, new Size(Bounds.Width - 10 - 9, 15)); | 469 SizeF ss = g.MeasureString(Text, SystemFonts.DefaultFont, new Size(Bounds.Width - 10 - 9, 15)); |
479 g.FillRectangle(SystemBrushes.Control, 9, 0, ss.Width, ss.Height); | 470 g.DrawLines(Pens.Gray, new PointF[] { new PointF(8 + ss.Width + 4, 6), new Point(Bounds.Width - 1, 6), new Point(Bounds.Width - 1, Bounds.Height - 1), new Point(0, Bounds.Height - 1), new Point(0, 6), new Point(8, 6) }); |
480 g.DrawString(Text, SystemFonts.DefaultFont, Brushes.DarkBlue, new Rectangle(9, 0, Bounds.Width - 10 - 9, 15)); | 471 g.DrawString(Text, SystemFonts.DefaultFont, Brushes.DarkBlue, new Rectangle(9, 0, Bounds.Width - 10 - 9, 15)); |
481 } | 472 } |
482 } | 473 } |
474 [System.ComponentModel.DesignerCategory("")] | |
483 public class WinFormsFBGHost : Control, IFBGContainerControl { | 475 public class WinFormsFBGHost : Control, IFBGContainerControl { |
484 private IFBGControl childControl = null; | 476 private IFBGControl childControl = null; |
485 private IFBGControl mouseCaptureControl = null; | 477 private IFBGControl mouseCaptureControl = null; |
486 private IFBGControl keyboardCaptureControl = null; | 478 private IFBGControl keyboardCaptureControl = null; |
487 public IFBGControl ChildControl { get { return childControl; } } | 479 public IFBGControl ChildControl { get { return childControl; } } |
831 ResizeTop = 8, | 823 ResizeTop = 8, |
832 ResizeBottom = 16, | 824 ResizeBottom = 16, |
833 ButtonClose = 32, | 825 ButtonClose = 32, |
834 MoveResize = ResizeLeft | ResizeRight | ResizeBottom | ResizeTop | Move, | 826 MoveResize = ResizeLeft | ResizeRight | ResizeBottom | ResizeTop | Move, |
835 } | 827 } |
828 public override Rectangle ClientRectangle { get { return new Rectangle(4, 22, Bounds.Width - 8, Bounds.Height - 26); } } | |
836 public FBGForm(IFBGContainerControl parent) : base(parent) { | 829 public FBGForm(IFBGContainerControl parent) : base(parent) { |
837 BackColor = SystemColors.Control; | 830 BackColor = SystemColors.Control; |
838 ClientRectangle = new Rectangle(4, 22, Bounds.Width - 8, Bounds.Height - 26); | |
839 Sizable = true; | 831 Sizable = true; |
840 Movable = true; | 832 Movable = true; |
841 Closable = false; | 833 Closable = false; |
842 } | |
843 public override Rectangle Bounds { | |
844 get { return base.Bounds; } | |
845 set { | |
846 ClientRectangle = new Rectangle(4, 22, value.Width - 8, value.Height - 26); | |
847 base.Bounds = value; | |
848 } | |
849 } | 834 } |
850 public String Text { get { return text; } set { if (text == value) return; text = value; Invalidate(new Rectangle(0, 0, Bounds.Width, 20)); RaiseEvent(TextChanged); } } | 835 public String Text { get { return text; } set { if (text == value) return; text = value; Invalidate(new Rectangle(0, 0, Bounds.Width, 20)); RaiseEvent(TextChanged); } } |
851 private NonClientOps GetNonClientOperation(Point p) { | 836 private NonClientOps GetNonClientOperation(Point p) { |
852 if ((new Rectangle(Bounds.Width - 5 - 14, 4, 14, 14)).Contains(p)) return NonClientOps.ButtonClose; | 837 if ((new Rectangle(Bounds.Width - 5 - 14, 4, 14, 14)).Contains(p)) return NonClientOps.ButtonClose; |
853 NonClientOps mr = 0; | 838 NonClientOps mr = 0; |
1485 public Converter<Object, String> ItemFormatter { get { return itemFormatter; } set { itemFormatter = value; Invalidate(); } } | 1470 public Converter<Object, String> ItemFormatter { get { return itemFormatter; } set { itemFormatter = value; Invalidate(); } } |
1486 public FBGListBox(IFBGContainerControl parent) | 1471 public FBGListBox(IFBGContainerControl parent) |
1487 : base(parent) { | 1472 : base(parent) { |
1488 BackColor = Color.White; | 1473 BackColor = Color.White; |
1489 } | 1474 } |
1490 public void AddItem(Object item) { | 1475 public int AddItem(Object item) { |
1491 items.Add(item); | 1476 int id = ((System.Collections.IList)items).Add(item); |
1492 Invalidate(); | 1477 Invalidate(); |
1493 } | 1478 return id; |
1479 } | |
1480 public void RemoveItem(Object item) { | |
1481 items.Remove(item); | |
1482 if (offset >= items.Count) offset = Math.Max(0, items.Count - 1); | |
1483 Invalidate(); | |
1484 } | |
1485 public void RemoveItemAt(int index) { | |
1486 if (index < 0) index += items.Count; | |
1487 items.RemoveAt(index); | |
1488 if (offset >= index && offset > 0) offset--; | |
1489 Invalidate(); | |
1490 } | |
1491 public void Clear() { | |
1492 items.Clear(); | |
1493 offset = 0; | |
1494 Invalidate(); | |
1495 } | |
1496 public System.Collections.IList Items { get { return items.AsReadOnly(); } } | |
1494 protected override void Paint(Graphics g) { | 1497 protected override void Paint(Graphics g) { |
1495 base.Paint(g); | 1498 base.Paint(g); |
1496 g.DrawRectangle(Pens.DarkBlue, 0, 0, Bounds.Width - 1, Bounds.Height - 1); | 1499 g.DrawRectangle(Pens.DarkBlue, 0, 0, Bounds.Width - 1, Bounds.Height - 1); |
1497 int lh = (int)Math.Ceiling(SystemFonts.DefaultFont.GetHeight()); | 1500 int lh = (int)Math.Ceiling(SystemFonts.DefaultFont.GetHeight()); |
1498 int th = lh * items.Count; | |
1499 int y = 2; | 1501 int y = 2; |
1500 using (Pen dottedpen = new Pen(Brushes.Black)) { | 1502 using (Pen dottedpen = new Pen(Brushes.Black)) { |
1501 dottedpen.DashStyle = DashStyle.Dot; | 1503 dottedpen.DashStyle = DashStyle.Dot; |
1502 using (StringFormat sf = new StringFormat(StringFormatFlags.NoWrap)) { | 1504 using (StringFormat sf = new StringFormat(StringFormatFlags.NoWrap)) { |
1503 for (int i = offset; i < items.Count; i++) { | 1505 for (int i = offset; i < items.Count; i++) { |
1509 y += lh; | 1511 y += lh; |
1510 if (y + lh + 2 >= Bounds.Height) break; | 1512 if (y + lh + 2 >= Bounds.Height) break; |
1511 } | 1513 } |
1512 } | 1514 } |
1513 } | 1515 } |
1514 if (y < th) hasScrollBar = true; | 1516 hasScrollBar = (y < 2 + lh * items.Count) || (offset != 0); |
1515 if (hasScrollBar) { | 1517 if (hasScrollBar) { |
1516 int xoff = Bounds.Width - 17; | 1518 int xoff = Bounds.Width - 17; |
1517 using (Brush b = new LinearGradientBrush(new Rectangle(xoff, 0, 17, 1), Color.LightGray, Color.White, LinearGradientMode.Horizontal)) | 1519 using (Brush b = new LinearGradientBrush(new Rectangle(xoff, 0, 17, 1), Color.LightGray, Color.White, LinearGradientMode.Horizontal)) |
1518 g.FillRectangle(b, xoff, 17, 16, Bounds.Height - 17 - 17); | 1520 g.FillRectangle(b, xoff, 17, 16, Bounds.Height - 17 - 17); |
1519 ControlPaint.DrawScrollButton(g, xoff, 1, 16, 16, ScrollButton.Up, buttonUpState); | 1521 ControlPaint.DrawScrollButton(g, xoff, 1, 16, 16, ScrollButton.Up, buttonUpState); |
1520 ControlPaint.DrawScrollButton(g, xoff, Bounds.Height - 17, 16, 16, ScrollButton.Down, buttonDownState); | 1522 ControlPaint.DrawScrollButton(g, xoff, Bounds.Height - 17, 16, 16, ScrollButton.Down, buttonDownState); |
1521 g.DrawRectangle(Pens.Black, new Rectangle(xoff, 17 + offset * (Bounds.Height - 17 - 17 - 20) / (items.Count - 1), 15, 20)); | 1523 if (items.Count > 1) g.DrawRectangle(Pens.Black, new Rectangle(xoff, 17 + offset * (Bounds.Height - 17 - 17 - 20) / (items.Count - 1), 15, 20)); |
1522 } | 1524 } |
1523 } | 1525 } |
1524 protected override void MouseDown(Point position, MouseButtons buttons) { | 1526 protected override void MouseDown(Point position, MouseButtons buttons) { |
1525 if ((buttons & MouseButtons.Left) != 0) { | 1527 if ((buttons & MouseButtons.Left) != 0) { |
1526 CaptureMouse(true); | 1528 CaptureMouse(true); |
1527 if (hasScrollBar && position.X > Bounds.Width - 17) { | 1529 if (hasScrollBar && position.X > Bounds.Width - 17) { |
1528 hitScrollBar = true; | 1530 hitScrollBar = true; |
1531 int off = offset; | |
1529 if (position.Y < 17) { | 1532 if (position.Y < 17) { |
1530 offset--; | 1533 off--; |
1531 buttonUpState = ButtonState.Pushed; | 1534 buttonUpState = ButtonState.Pushed; |
1532 } else if (position.Y > Bounds.Height - 17) { | 1535 } else if (position.Y > Bounds.Height - 17) { |
1533 offset++; | 1536 off++; |
1534 buttonDownState = ButtonState.Pushed; | 1537 buttonDownState = ButtonState.Pushed; |
1535 } else { | 1538 } else { |
1536 offset = (int)Math.Round((position.Y - 17) * (items.Count - 1) / (double)(Bounds.Height - 17 - 17 - 10)); | 1539 off = (int)Math.Round((position.Y - 17) * (items.Count - 1) / (double)(Bounds.Height - 17 - 17 - 10)); |
1537 } | 1540 } |
1538 if (offset < 0) offset = 0; | 1541 offset = Math.Max(0, Math.Min(items.Count - 1, off)); |
1539 if (offset >= items.Count) offset = items.Count - 1; | |
1540 Invalidate(); | 1542 Invalidate(); |
1541 } else { | 1543 } else { |
1542 MouseHandler(position, buttons); | 1544 MouseHandler(position, buttons); |
1543 } | 1545 } |
1544 } | 1546 } |
1546 protected override void MouseMove(Point position, MouseButtons buttons) { | 1548 protected override void MouseMove(Point position, MouseButtons buttons) { |
1547 if (hitScrollBar) { | 1549 if (hitScrollBar) { |
1548 if (position.Y < 17) { | 1550 if (position.Y < 17) { |
1549 } else if (position.Y > Bounds.Height - 17) { | 1551 } else if (position.Y > Bounds.Height - 17) { |
1550 } else { | 1552 } else { |
1551 offset = (int)Math.Round((position.Y - 17) * (items.Count - 1) / (double)(Bounds.Height - 17 - 17 - 10)); | 1553 offset = Math.Max(0, Math.Min(items.Count - 1, (int)Math.Round((position.Y - 17) * (items.Count - 1) / (double)(Bounds.Height - 17 - 17 - 10)))); |
1552 if (offset < 0) offset = 0; | |
1553 if (offset >= items.Count) offset = items.Count - 1; | |
1554 Invalidate(); | 1554 Invalidate(); |
1555 } | 1555 } |
1556 return; | 1556 return; |
1557 } | 1557 } |
1558 MouseHandler(position, buttons); | 1558 MouseHandler(position, buttons); |