// NOT COMPLETE
//
+using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
public static DataGridTableStyle DefaultTableStyle = new DataGridTableStyle (true);
#region Local Variables
- private static readonly Color def_alternating_backcolor = SystemColors.Window;
- private static readonly Color def_backcolor = SystemColors.Window;
+ private static readonly Color def_alternating_backcolor = ThemeEngine.Current.DataGridAlternatingBackColor;
+ private static readonly Color def_backcolor = ThemeEngine.Current.DataGridBackColor;
private static readonly Color def_forecolor = SystemColors.WindowText;
- private static readonly Color def_gridline_color = SystemColors.Control;
- private static readonly Color def_header_backcolor = SystemColors.Control;
- private static readonly Font def_header_font = null;
- private static readonly Color def_header_forecolor = SystemColors.ControlText;
- private static readonly Color def_link_color = SystemColors.HotTrack;
- private static readonly Color def_link_hovercolor = SystemColors.HotTrack;
- private static readonly Color def_selection_backcolor = SystemColors.ActiveCaption;
- private static readonly Color def_selection_forecolor = SystemColors.ActiveCaptionText;
+ private static readonly Color def_gridline_color = ThemeEngine.Current.DataGridGridLineColor;
+ private static readonly Color def_header_backcolor = ThemeEngine.Current.DataGridHeaderBackColor;
+ private static readonly Font def_header_font = ThemeEngine.Current.DefaultFont;
+ private static readonly Color def_header_forecolor = ThemeEngine.Current.DataGridHeaderForeColor;
+ private static readonly Color def_link_color = ThemeEngine.Current.DataGridLinkColor;
+ private static readonly Color def_link_hovercolor = ThemeEngine.Current.DataGridLinkHoverColor;
+ private static readonly Color def_selection_backcolor = ThemeEngine.Current.DataGridSelectionBackColor;
+ private static readonly Color def_selection_forecolor = ThemeEngine.Current.DataGridSelectionForeColor;
+ private static readonly int def_preferredrow_height = ThemeEngine.Current.DefaultFont.Height + 3;
private bool allow_sorting;
private DataGrid datagrid;
private Color backcolor;
private Color forecolor;
private bool is_default;
+ internal ArrayList table_relations;
CurrencyManager manager;
#endregion // Local Variables
#region Constructors
public DataGridTableStyle ()
+ : this (false)
{
- CommonConstructor ();
- is_default = false;
}
public DataGridTableStyle (bool isDefaultTableStyle)
{
- CommonConstructor ();
is_default = isDefaultTableStyle;
- }
-
- // TODO: What to do with the CurrencyManager
- public DataGridTableStyle (CurrencyManager listManager)
- {
- CommonConstructor ();
- is_default = false;
- manager = listManager;
- }
-
- private void CommonConstructor ()
- {
allow_sorting = true;
datagrid = null;
header_forecolor = def_header_forecolor;
mapping_name = string.Empty;
+ table_relations = new ArrayList ();
column_styles = new GridColumnStylesCollection (this);
alternating_backcolor = def_alternating_backcolor;
backcolor = def_backcolor;
forecolor = def_forecolor;
}
+
+ public DataGridTableStyle (CurrencyManager listManager)
+ : this (false)
+ {
+ manager = listManager;
+ }
#endregion
#region Public Instance Properties
[DefaultValue(true)]
public bool AllowSorting {
- get {
- return allow_sorting;
- }
-
+ get { return allow_sorting; }
set {
+ if (is_default)
+ throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
+
if (allow_sorting != value) {
allow_sorting = value;
OnAllowSortingChanged (EventArgs.Empty);
}
public Color AlternatingBackColor {
- get {
- return alternating_backcolor;
- }
-
+ get { return alternating_backcolor; }
set {
+ if (is_default)
+ throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
+
if (alternating_backcolor != value) {
alternating_backcolor = value;
OnAlternatingBackColorChanged (EventArgs.Empty);
}
public Color BackColor {
- get {
- return backcolor;
- }
-
+ get { return backcolor; }
set {
+ if (is_default)
+ throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
+
if (backcolor != value) {
backcolor = value;
OnBackColorChanged (EventArgs.Empty);
[Browsable(false)]
public virtual DataGrid DataGrid {
- get {
- return datagrid;
- }
-
+ get { return datagrid; }
set {
if (datagrid != value) {
datagrid = value;
+
+ /* now set the value on all our column styles */
+ for (int i = 0; i < column_styles.Count; i ++) {
+ column_styles[i].SetDataGridInternal (datagrid);
+ }
}
}
}
public Color ForeColor {
- get {
- return forecolor;
- }
-
+ get { return forecolor; }
set {
+ if (is_default)
+ throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
+
if (forecolor != value) {
forecolor = value;
OnForeColorChanged (EventArgs.Empty);
}
public Color GridLineColor {
- get {
- return gridline_color;
- }
-
+ get { return gridline_color; }
set {
+ if (is_default)
+ throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
+
if (gridline_color != value) {
gridline_color = value;
OnGridLineColorChanged (EventArgs.Empty);
[DefaultValue(DataGridLineStyle.Solid)]
public DataGridLineStyle GridLineStyle {
- get {
- return gridline_style;
- }
-
+ get { return gridline_style; }
set {
+ if (is_default)
+ throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
+
if (gridline_style != value) {
gridline_style = value;
OnGridLineStyleChanged (EventArgs.Empty);
}
public Color HeaderBackColor {
- get {
- return header_backcolor;
- }
-
+ get { return header_backcolor; }
set {
+ if (is_default)
+ throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
+
if (value == Color.Empty) {
throw new ArgumentNullException ("Color.Empty value is invalid.");
}
[AmbientValue(null)]
[Localizable(true)]
public Font HeaderFont {
- get {
- if (header_font != null)
- return header_font;
-
- if (datagrid != null)
- return datagrid.HeaderFont;
+ get { return header_font; }
+ set {
+ if (is_default)
+ throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
- return ThemeEngine.Current.DefaultFont;
- }
+ if (value == null)
+ value = def_header_font;
- set {
if (header_font != value) {
header_font = value;
OnHeaderFontChanged (EventArgs.Empty);
}
public Color HeaderForeColor {
- get {
- return header_forecolor;
- }
-
+ get { return header_forecolor; }
set {
+ if (is_default)
+ throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
if (header_forecolor != value) {
header_forecolor = value;
}
public Color LinkColor {
- get {
- return link_color;
- }
-
+ get { return link_color; }
set {
+ if (is_default)
+ throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
+
if (link_color != value) {
link_color = value;
[EditorBrowsable(EditorBrowsableState.Never)]
[Browsable(false)]
public Color LinkHoverColor {
- get {
- return link_hovercolor;
- }
-
+ get { return link_hovercolor; }
set {
if (link_hovercolor != value) {
link_hovercolor = value;
[Editor("System.Windows.Forms.Design.DataGridTableStyleMappingNameEditor, " + Consts.AssemblySystem_Design, typeof(System.Drawing.Design.UITypeEditor))]
public string MappingName {
- get {
- return mapping_name;
- }
-
+ get { return mapping_name; }
set {
+ if (value == null)
+ value = "";
+
if (mapping_name != value) {
mapping_name = value;
OnMappingNameChanged (EventArgs.Empty);
[TypeConverter(typeof(DataGridPreferredColumnWidthTypeConverter))]
[Localizable(true)]
public int PreferredColumnWidth {
- get {
- return preferredcolumn_width;
- }
-
+ get { return preferredcolumn_width; }
set {
+ if (is_default)
+ throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
+
if (value < 0) {
throw new ArgumentException ("PreferredColumnWidth is less than 0");
}
[Localizable(true)]
public int PreferredRowHeight {
- get {
- return preferredrow_height;
- }
-
+ get { return preferredrow_height; }
set {
+ if (is_default)
+ throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
+
if (preferredrow_height != value) {
preferredrow_height = value;
OnPreferredRowHeightChanged (EventArgs.Empty);
}
[DefaultValue(false)]
- public bool ReadOnly {
- get {
- return _readonly;
- }
-
+ public virtual bool ReadOnly {
+ get { return _readonly; }
set {
if (_readonly != value) {
_readonly = value;
[DefaultValue(true)]
public bool RowHeadersVisible {
- get {
- return rowheaders_visible;
- }
-
+ get { return rowheaders_visible; }
set {
if (rowheaders_visible != value) {
rowheaders_visible = value;
[DefaultValue(35)]
[Localizable(true)]
public int RowHeaderWidth {
- get {
- return rowheaders_width;
- }
-
+ get { return rowheaders_width; }
set {
if (rowheaders_width != value) {
rowheaders_width = value;
}
public Color SelectionBackColor {
- get {
- return selection_backcolor;
- }
-
+ get { return selection_backcolor; }
set {
+ if (is_default)
+ throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
+
if (selection_backcolor != value) {
selection_backcolor = value;
OnSelectionBackColorChanged (EventArgs.Empty);
[Description("The foreground color for the current data grid row")]
public Color SelectionForeColor {
- get {
- return selection_forecolor;
- }
-
+ get { return selection_forecolor; }
set {
+ if (is_default)
+ throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
+
if (selection_forecolor != value) {
selection_forecolor = value;
OnSelectionForeColorChanged (EventArgs.Empty);
}
}
+ internal bool HasRelations {
+ get { return table_relations.Count > 0; }
+ }
+
+ internal string[] Relations {
+ get {
+ string[] rel = new string[table_relations.Count];
+ table_relations.CopyTo (rel, 0);
+ return rel;
+ }
+ }
#endregion Private Instance Properties
#region Public Instance Methods
[MonoTODO]
- public virtual bool BeginEdit (DataGridColumnStyle gridColumn, int rowNumber)
+ public bool BeginEdit (DataGridColumnStyle gridColumn, int rowNumber)
{
throw new NotImplementedException ();
}
protected internal virtual DataGridColumnStyle CreateGridColumn (PropertyDescriptor prop, bool isDefault)
{
- if (DataGridBoolColumn.CanRenderType (prop.PropertyType)) {
+ if (prop.PropertyType == typeof (bool))
return new DataGridBoolColumn (prop, isDefault);
- }
-
- if (DataGridTextBoxColumn.CanRenderType (prop.PropertyType)) {
-
+ else {
// At least to special cases with formats
if (prop.PropertyType.Equals (typeof (DateTime))) {
return new DataGridTextBoxColumn (prop, "d", isDefault);
return new DataGridTextBoxColumn (prop, isDefault);
}
-
- throw new NotImplementedException ();
}
protected override void Dispose (bool disposing)
}
[MonoTODO]
- public virtual bool EndEdit ( DataGridColumnStyle gridColumn, int rowNumber, bool shouldAbort)
+ public bool EndEdit ( DataGridColumnStyle gridColumn, int rowNumber, bool shouldAbort)
{
throw new NotImplementedException ();
}
protected bool ShouldSerializePreferredRowHeight ()
{
- return (preferredrow_height != datagrid.def_preferredrow_height);
+ return (preferredrow_height != def_preferredrow_height);
}
protected bool ShouldSerializeSelectionBackColor ()
// Create column styles for this TableStyle
internal void CreateColumnsForTable (bool onlyBind)
{
- CurrencyManager mgr = null;
- mgr = datagrid.ListManager;
+ CurrencyManager mgr = manager;
+ DataGridColumnStyle st;
if (mgr == null) {
- return;
+ mgr = datagrid.ListManager;
+
+ if (mgr == null)
+ return;
}
+ table_relations.Clear ();
PropertyDescriptorCollection propcol = mgr.GetItemProperties ();
for (int i = 0; i < propcol.Count; i++)
{
// The column style is already provided by the user
- if (column_styles[propcol[i].Name] != null &&
- column_styles[propcol[i].Name].IsDefault == false) {
- column_styles[propcol[i].Name].table_style = this;
- column_styles[propcol[i].Name].SetDataGridInternal (datagrid);
+ st = column_styles[propcol[i].Name];
+ if (st != null) {
+ if (st.Width == -1)
+ st.Width = CurrentPreferredColumnWidth;
+
+ st.PropertyDescriptor = propcol[i];
+
continue;
}
continue;
}
-
- // TODO: What to do with relations?
- if (propcol[i].ComponentType.ToString () == "System.Data.DataTablePropertyDescriptor") {
- Console.WriteLine ("CreateColumnsForTable::System.Data.DataTablePropertyDescriptor");
-
+ if (typeof (IBindingList).IsAssignableFrom (propcol[i].PropertyType)) {
+ table_relations.Add (propcol[i].Name);
} else {
- DataGridColumnStyle st = CreateGridColumn (propcol[i], true);
+ st = CreateGridColumn (propcol[i], true);
st.grid = datagrid;
st.MappingName = propcol[i].Name;
st.HeaderText = propcol[i].Name;