comparison UI/StatColumnStyle.cs @ 64:e04bea5b7b3d WarFoundry_v0.1beta3_Winforms

Fixes #157: Stats show object class name when selected * Do the column style properly and re-implement the parent's abstract methods from scratch rather than from the "textbox" version (as per MSDN page: http://msdn.microsoft.com/en-us/library/ms996453.aspx#datagridcolumnstyle2_topic5)
author IBBoard <dev@ibboard.co.uk>
date Tue, 22 Sep 2009 19:24:00 +0000
parents 740350673006
children e749b748e7ea
comparison
equal deleted inserted replaced
63:4db2c1086a85 64:e04bea5b7b3d
8 using System.Windows.Forms; 8 using System.Windows.Forms;
9 using IBBoard.WarFoundry.API.Objects; 9 using IBBoard.WarFoundry.API.Objects;
10 10
11 namespace IBBoard.WarFoundry.GUI.WinForms.UI 11 namespace IBBoard.WarFoundry.GUI.WinForms.UI
12 { 12 {
13 class StatColumnStyle : DataGridTextBoxColumn 13 class StatColumnStyle : DataGridColumnStyle
14 { 14 {
15 protected override void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, Brush backBrush, Brush foreBrush, bool alignToRight) 15 protected override void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, Brush backBrush, Brush foreBrush, bool alignToRight)
16 { 16 {
17 Object obj = GetColumnValueAtRow(source, rowNum); 17 Object obj = GetColumnValueAtRow(source, rowNum);
18 Rectangle rect = bounds; 18 Rectangle rect = bounds;
19 g.FillRectangle(backBrush, rect); 19 g.FillRectangle(backBrush, rect);
20 rect.Offset(0, 2);
21 rect.Height -= 2;
22 20
23 if (obj is Stat) 21 if (obj is Stat)
24 { 22 {
25 Stat stat = (Stat) obj; 23 Stat stat = (Stat) obj;
26 StringFormat stringFormat = new StringFormat(); 24 StringFormat stringFormat = new StringFormat();
27 stringFormat.Alignment = (stat.ParentSlotName == "Name" ? StringAlignment.Near : StringAlignment.Center); 25 stringFormat.Alignment = (stat.ParentSlotName == "Name" ? StringAlignment.Near : StringAlignment.Center);
28 g.DrawString(stat.SlotValueString, this.DataGridTableStyle.DataGrid.Font, foreBrush, rect, stringFormat); 26 g.DrawString(stat.SlotValueString, GetFont(), foreBrush, rect, stringFormat);
29 } 27 }
30 else 28 else
31 { 29 {
32 g.DrawString(NullText, this.DataGridTableStyle.DataGrid.Font, foreBrush, rect); 30 g.DrawString(NullText, GetFont(), foreBrush, rect);
33 } 31 }
32 }
33
34 private Font GetFont()
35 {
36 return DataGridTableStyle.DataGrid.Font;
37 }
38
39 protected override void Abort(int rowNum)
40 {
41 // Do nothing - we don't allow editing
42 }
43
44 protected override bool Commit(CurrencyManager dataSource, int rowNum)
45 {
46 // Do nothing - we don't allow editing - but pretend we did
47 return true;
48 }
49
50 protected override void Edit(CurrencyManager source, int rowNum, Rectangle bounds, bool readOnly, string displayText, bool cellIsVisible)
51 {
52 // Do nothing - we don't allow editing
53 }
54
55 protected override int GetMinimumHeight()
56 {
57 return GetFont().Height;
58 }
59
60 protected override int GetPreferredHeight(Graphics g, object value)
61 {
62 return GetFont().Height;
63 }
64
65 protected override Size GetPreferredSize(Graphics g, object value)
66 {
67 Size size = new Size();
68
69 if (value is Stat)
70 {
71 SizeF stringSize = g.MeasureString(((Stat) value).SlotValueString, GetFont());
72 size.Height = (int) Math.Ceiling(stringSize.Height);
73 size.Width = (int) Math.Ceiling(stringSize.Width);
74 }
75
76 return size;
77 }
78
79 protected override void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum)
80 {
81 Paint(g, bounds, source, rowNum, false);
82 }
83
84 protected override void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, bool alignToRight)
85 {
86 Paint(g, bounds, source, rowNum, SystemBrushes.Window, SystemBrushes.WindowText, alignToRight);
34 } 87 }
35 } 88 }
36 } 89 }