changeset 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 4db2c1086a85
children c4181adba7df
files UI/StatColumnStyle.cs
diffstat 1 files changed, 58 insertions(+), 5 deletions(-) [+]
line diff
     1.1 --- a/UI/StatColumnStyle.cs	Mon Sep 21 19:31:24 2009 +0000
     1.2 +++ b/UI/StatColumnStyle.cs	Tue Sep 22 19:24:00 2009 +0000
     1.3 @@ -10,27 +10,80 @@
     1.4  
     1.5  namespace IBBoard.WarFoundry.GUI.WinForms.UI
     1.6  {
     1.7 -	class StatColumnStyle : DataGridTextBoxColumn
     1.8 +	class StatColumnStyle : DataGridColumnStyle
     1.9  	{
    1.10  		protected override void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, Brush backBrush, Brush foreBrush, bool alignToRight)
    1.11  		{
    1.12  			Object obj = GetColumnValueAtRow(source, rowNum);
    1.13  			Rectangle rect = bounds;
    1.14  			g.FillRectangle(backBrush, rect);
    1.15 -			rect.Offset(0, 2);
    1.16 -			rect.Height -= 2;
    1.17  
    1.18  			if (obj is Stat)
    1.19  			{
    1.20  				Stat stat = (Stat) obj;
    1.21  				StringFormat stringFormat = new StringFormat();
    1.22  				stringFormat.Alignment = (stat.ParentSlotName == "Name" ? StringAlignment.Near : StringAlignment.Center);
    1.23 -				g.DrawString(stat.SlotValueString, this.DataGridTableStyle.DataGrid.Font, foreBrush, rect, stringFormat);
    1.24 +				g.DrawString(stat.SlotValueString, GetFont(), foreBrush, rect, stringFormat);
    1.25  			}
    1.26  			else
    1.27  			{
    1.28 -				g.DrawString(NullText, this.DataGridTableStyle.DataGrid.Font, foreBrush, rect);
    1.29 +				g.DrawString(NullText, GetFont(), foreBrush, rect);
    1.30  			}
    1.31  		}
    1.32 +
    1.33 +		private Font GetFont()
    1.34 +		{
    1.35 +			return DataGridTableStyle.DataGrid.Font;
    1.36 +		}
    1.37 +
    1.38 +		protected override void Abort(int rowNum)
    1.39 +		{
    1.40 +			// Do nothing - we don't allow editing
    1.41 +		}
    1.42 +
    1.43 +		protected override bool Commit(CurrencyManager dataSource, int rowNum)
    1.44 +		{
    1.45 +			// Do nothing - we don't allow editing - but pretend we did
    1.46 +			return true;
    1.47 +		}
    1.48 +
    1.49 +		protected override void Edit(CurrencyManager source, int rowNum, Rectangle bounds, bool readOnly, string displayText, bool cellIsVisible)
    1.50 +		{
    1.51 +			// Do nothing - we don't allow editing
    1.52 +		}
    1.53 +
    1.54 +		protected override int GetMinimumHeight()
    1.55 +		{
    1.56 +			return GetFont().Height;
    1.57 +		}
    1.58 +
    1.59 +		protected override int GetPreferredHeight(Graphics g, object value)
    1.60 +		{
    1.61 +			return GetFont().Height;
    1.62 +		}
    1.63 +
    1.64 +		protected override Size GetPreferredSize(Graphics g, object value)
    1.65 +		{
    1.66 +			Size size = new Size();
    1.67 +
    1.68 +			if (value is Stat)
    1.69 +			{
    1.70 +				SizeF stringSize = g.MeasureString(((Stat) value).SlotValueString, GetFont());
    1.71 +				size.Height = (int) Math.Ceiling(stringSize.Height);
    1.72 +				size.Width = (int) Math.Ceiling(stringSize.Width);
    1.73 +			}
    1.74 +
    1.75 +			return size;
    1.76 +		}
    1.77 +
    1.78 +		protected override void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum)
    1.79 +		{
    1.80 +			Paint(g, bounds, source, rowNum, false);
    1.81 +		}
    1.82 +
    1.83 +		protected override void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, bool alignToRight)
    1.84 +		{
    1.85 +			Paint(g, bounds, source, rowNum, SystemBrushes.Window, SystemBrushes.WindowText, alignToRight);
    1.86 +		}
    1.87  	}
    1.88  }