/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGrid.cs
C# | 3462 lines | 2716 code | 617 blank | 129 comment | 564 complexity | 6adc470b264352468b991579f8b9903b MD5 | raw file
Possible License(s): Unlicense, Apache-2.0, LGPL-2.0, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, GPL-2.0
Large files files are truncated, but you can click here to view the full file
- // Permission is hereby granted, free of charge, to any person obtaining
- // a copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to
- // permit persons to whom the Software is furnished to do so, subject to
- // the following conditions:
- //
- // The above copyright notice and this permission notice shall be
- // included in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
- // Copyright (c) 2005,2006 Novell, Inc. (http://www.novell.com)
- //
- // Authors:
- // Jordi Mas i Hernandez <jordi@ximian.com>
- // Chris Toshok <toshok@ximian.com>
- //
- //
- using System;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Runtime.InteropServices;
- using System.Collections;
- using System.Text;
- namespace System.Windows.Forms
- {
- internal class DataGridRelationshipRow {
- DataGrid owner;
- public DataGridRelationshipRow (DataGrid owner)
- {
- this.owner = owner;
- IsSelected = false;
- IsExpanded = false;
- height = 0;
- VerticalOffset = 0;
- RelationHeight = 0;
- relation_area = Rectangle.Empty;
- }
- public int height;
- /* this needs to be a property so that the Autosize
- * example from the Windows.Forms FAQ will work */
- public int Height {
- get { return height; }
- set {
- if (height != value) {
- height = value;
- owner.UpdateRowsFrom (this);
- }
- }
- }
- public bool IsSelected;
- public bool IsExpanded;
- public int VerticalOffset;
- public int RelationHeight;
- public Rectangle relation_area; /* the Y coordinate of this rectangle is updated as needed */
- }
- internal class DataGridDataSource
- {
- public DataGrid owner;
- public CurrencyManager list_manager;
- public object view;
- public string data_member;
- public object data_source;
- public DataGridCell current;
- public DataGridDataSource (DataGrid owner, CurrencyManager list_manager, object data_source, string data_member, object view_data, DataGridCell current)
- {
- this.owner = owner;
- this.list_manager = list_manager;
- this.view = view_data;
- this.data_source = data_source;
- this.data_member = data_member;
- this.current = current;
- }
- DataGridRelationshipRow[] rows;
- public DataGridRelationshipRow[] Rows {
- get { return rows; }
- set { rows = value; }
- }
- Hashtable selected_rows;
- public Hashtable SelectedRows {
- get { return selected_rows; }
- set { selected_rows = value; }
- }
- int selection_start;
- public int SelectionStart {
- get { return selection_start; }
- set { selection_start = value; }
- }
- }
- [DefaultEvent("Navigate")]
- [DefaultProperty("DataSource")]
- [Designer("System.Windows.Forms.Design.DataGridDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
- [ComplexBindingProperties ("DataSource", "DataMember")]
- [ClassInterface (ClassInterfaceType.AutoDispatch)]
- [ComVisible (true)]
- public class DataGrid : Control, ISupportInitialize, IDataGridEditingService
- {
- [Flags]
- public enum HitTestType
- {
- None = 0,
- Cell = 1,
- ColumnHeader = 2,
- RowHeader = 4,
- ColumnResize = 8,
- RowResize = 16,
- Caption = 32,
- ParentRows = 64
- }
- public sealed class HitTestInfo
- {
- public static readonly HitTestInfo Nowhere = null;
- int row;
- int column;
- DataGrid.HitTestType type;
- #region Private Constructors
- internal HitTestInfo () : this (-1, -1, HitTestType.None)
- {
- }
- internal HitTestInfo (int row, int column, DataGrid.HitTestType type)
- {
- this.row = row;
- this.column = column;
- this.type = type;
- }
- #endregion
- #region Public Instance Properties
- public int Column {
- get { return column; }
- }
- public int Row {
- get { return row; }
- }
- public DataGrid.HitTestType Type {
- get { return type; }
- }
- #endregion //Public Instance Properties
- public override bool Equals (object value)
- {
- if (!(value is HitTestInfo))
- return false;
- HitTestInfo obj = (HitTestInfo) value;
- return (obj.Column == column && obj.Row == row && obj.Type ==type);
- }
- public override int GetHashCode ()
- {
- return row ^ column;
- }
- public override string ToString ()
- {
- return "{ " + type + "," + row + "," + column + "}";
- }
- }
- #region Local Variables
- /* cached theme defaults */
- static readonly Color def_background_color = ThemeEngine.Current.DataGridBackgroundColor;
- static readonly Color def_caption_backcolor = ThemeEngine.Current.DataGridCaptionBackColor;
- static readonly Color def_caption_forecolor = ThemeEngine.Current.DataGridCaptionForeColor;
- static readonly Color def_parent_rows_backcolor = ThemeEngine.Current.DataGridParentRowsBackColor;
- static readonly Color def_parent_rows_forecolor = ThemeEngine.Current.DataGridParentRowsForeColor;
- /* colors */
- // XXX this needs addressing. Control.background_color should not be internal.
- new Color background_color;
- Color caption_backcolor;
- Color caption_forecolor;
- Color parent_rows_backcolor;
- Color parent_rows_forecolor;
- /* flags to determine which areas of the datagrid are shown */
- bool caption_visible;
- bool parent_rows_visible;
- GridTableStylesCollection styles_collection;
- DataGridParentRowsLabelStyle parent_rows_label_style;
- DataGridTableStyle default_style;
- DataGridTableStyle grid_style;
- DataGridTableStyle current_style;
- /* selection */
- DataGridCell current_cell;
- Hashtable selected_rows;
- int selection_start; // used for range selection
- /* layout/rendering */
- bool allow_navigation;
- int first_visible_row;
- int first_visible_column;
- int visible_row_count;
- int visible_column_count;
- Font caption_font;
- string caption_text;
- bool flatmode;
- HScrollBar horiz_scrollbar;
- VScrollBar vert_scrollbar;
- int horiz_pixeloffset;
- internal Bitmap back_button_image;
- internal Rectangle back_button_rect;
- internal bool back_button_mouseover;
- internal bool back_button_active;
- internal Bitmap parent_rows_button_image;
- internal Rectangle parent_rows_button_rect;
- internal bool parent_rows_button_mouseover;
- internal bool parent_rows_button_active;
- /* databinding */
- object datasource;
- string datamember;
- CurrencyManager list_manager;
- bool refetch_list_manager = true;
- bool _readonly;
- DataGridRelationshipRow[] rows;
- /* column resize fields */
- bool column_resize_active;
- int resize_column_x;
- int resize_column_width_delta;
- int resize_column;
-
- /* row resize fields */
- bool row_resize_active;
- int resize_row_y;
- int resize_row_height_delta;
- int resize_row;
- /* used to make sure we don't endlessly recurse calling set_CurrentCell and OnListManagerPositionChanged */
- bool from_positionchanged_handler;
- /* editing state */
- bool cursor_in_add_row;
- bool add_row_changed;
- internal bool is_editing; // Current cell is edit mode
- bool is_changing;
- bool commit_row_changes = true; // Whether to commit current edit or cancel it
- bool adding_new_row; // Used to temporary ignore the new row added by CurrencyManager.AddNew in CurrentCell
- internal Stack data_source_stack;
- internal Stack data_grid_table_style_stack;
- internal Stack grid_style_stack;
- #endregion // Local Variables
- #region Public Constructors
- public DataGrid ()
- {
- allow_navigation = true;
- background_color = def_background_color;
- border_style = BorderStyle.Fixed3D;
- caption_backcolor = def_caption_backcolor;
- caption_forecolor = def_caption_forecolor;
- caption_text = string.Empty;
- caption_visible = true;
- datamember = string.Empty;
- parent_rows_backcolor = def_parent_rows_backcolor;
- parent_rows_forecolor = def_parent_rows_forecolor;
- parent_rows_visible = true;
- current_cell = new DataGridCell ();
- parent_rows_label_style = DataGridParentRowsLabelStyle.Both;
- selected_rows = new Hashtable ();
- selection_start = -1;
- rows = new DataGridRelationshipRow [0];
- grid_style_stack = new Stack ();
- data_grid_table_style_stack = new Stack ();
- default_style = new DataGridTableStyle (true);
- grid_style = new DataGridTableStyle ();
- styles_collection = new GridTableStylesCollection (this);
- styles_collection.CollectionChanged += new CollectionChangeEventHandler (OnTableStylesCollectionChanged);
- CurrentTableStyle = grid_style;
- horiz_scrollbar = new ImplicitHScrollBar ();
- horiz_scrollbar.Scroll += new ScrollEventHandler (GridHScrolled);
- vert_scrollbar = new ImplicitVScrollBar ();
- vert_scrollbar.Scroll += new ScrollEventHandler (GridVScrolled);
- SetStyle (ControlStyles.UserMouse, true);
- data_source_stack = new Stack ();
- back_button_image = ResourceImageLoader.Get ("go-previous.png");
- back_button_image.MakeTransparent (Color.Transparent);
- parent_rows_button_image = ResourceImageLoader.Get ("go-top.png");
- parent_rows_button_image.MakeTransparent (Color.Transparent);
- }
- #endregion // Public Constructor
- #region Public Instance Properties
- [DefaultValue(true)]
- public bool AllowNavigation {
- get { return allow_navigation; }
- set {
- if (allow_navigation != value) {
- allow_navigation = value;
- OnAllowNavigationChanged (EventArgs.Empty);
- }
- }
- }
- [DefaultValue(true)]
- public bool AllowSorting {
- get { return grid_style.AllowSorting; }
- set { grid_style.AllowSorting = value; }
- }
- public Color AlternatingBackColor {
- get { return grid_style.AlternatingBackColor; }
- set { grid_style.AlternatingBackColor = value; }
- }
- public override Color BackColor {
- get { return grid_style.BackColor; }
- set { grid_style.BackColor = value; }
- }
- public Color BackgroundColor {
- get { return background_color; }
- set {
- if (background_color != value) {
- background_color = value;
- OnBackgroundColorChanged (EventArgs.Empty);
- Invalidate ();
- }
- }
- }
- [Browsable(false)]
- [EditorBrowsable(EditorBrowsableState.Never)]
- public override Image BackgroundImage {
- get { return base.BackgroundImage; }
- set {
- if (base.BackgroundImage == value)
- return;
- base.BackgroundImage = value;
- Invalidate ();
- }
- }
- [Browsable (false)]
- [EditorBrowsable (EditorBrowsableState.Never)]
- public override ImageLayout BackgroundImageLayout {
- get { return base.BackgroundImageLayout; }
- set { base.BackgroundImageLayout = value; }
- }
- [DispId(-504)]
- [DefaultValue(BorderStyle.Fixed3D)]
- public BorderStyle BorderStyle {
- get { return InternalBorderStyle; }
- set {
- InternalBorderStyle = value;
- CalcAreasAndInvalidate ();
- OnBorderStyleChanged (EventArgs.Empty);
- }
- }
- public Color CaptionBackColor {
- get { return caption_backcolor; }
- set {
- if (caption_backcolor != value) {
- caption_backcolor = value;
- InvalidateCaption ();
- }
- }
- }
- [Localizable(true)]
- [AmbientValue(null)]
- public Font CaptionFont {
- get {
- if (caption_font == null)
- return new Font (Font, FontStyle.Bold);
- return caption_font;
- }
- set {
- if (caption_font != null && caption_font.Equals (value))
- return;
- caption_font = value;
- CalcAreasAndInvalidate ();
- }
- }
- public Color CaptionForeColor {
- get { return caption_forecolor; }
- set {
- if (caption_forecolor != value) {
- caption_forecolor = value;
- InvalidateCaption ();
- }
- }
- }
- [Localizable(true)]
- [DefaultValue("")]
- public string CaptionText {
- get { return caption_text; }
- set {
- if (caption_text != value) {
- caption_text = value;
- InvalidateCaption ();
- }
- }
- }
- [DefaultValue(true)]
- public bool CaptionVisible {
- get { return caption_visible; }
- set {
- if (caption_visible != value) {
- EndEdit ();
- caption_visible = value;
- CalcAreasAndInvalidate ();
- OnCaptionVisibleChanged (EventArgs.Empty);
- }
- }
- }
- [DefaultValue(true)]
- public bool ColumnHeadersVisible {
- get { return grid_style.ColumnHeadersVisible; }
- set {
- if (grid_style.ColumnHeadersVisible != value) {
- grid_style.ColumnHeadersVisible = value;
- // UIA Framework: To keep track of header
- OnUIAColumnHeadersVisibleChanged ();
- }
- }
- }
- bool setting_current_cell;
- [Browsable(false)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- public DataGridCell CurrentCell {
- get { return current_cell; }
- set {
- if (setting_current_cell)
- return;
- setting_current_cell = true;
- if (!IsHandleCreated) {
- setting_current_cell = false;
- throw new Exception ("CurrentCell cannot be set at this time.");
- }
- /* Even if we are on the same cell, we could need to actually start edition */
- if (current_cell.Equals (value) && is_editing) {
- setting_current_cell = false;
- return;
- }
- /* make sure the new cell fits in the correct bounds for [row,column] */
- if (ReadOnly && value.RowNumber > RowsCount - 1)
- value.RowNumber = RowsCount - 1;
- else if (value.RowNumber > RowsCount)
- value.RowNumber = RowsCount;
- if (value.ColumnNumber >= CurrentTableStyle.GridColumnStyles.Count)
- value.ColumnNumber = CurrentTableStyle.GridColumnStyles.Count == 0 ? 0 : CurrentTableStyle.GridColumnStyles.Count - 1;
- /* now make sure we don't go negative */
- if (value.RowNumber < 0) value.RowNumber = 0;
- if (value.ColumnNumber < 0) value.ColumnNumber = 0;
- bool was_changing = is_changing;
- add_row_changed = add_row_changed || was_changing;
- EndEdit ();
- if (value.RowNumber != current_cell.RowNumber) {
- if (!from_positionchanged_handler) {
- try {
- if (commit_row_changes)
- ListManager.EndCurrentEdit ();
- else
- ListManager.CancelCurrentEdit ();
- }
- catch (Exception e) {
- DialogResult r = MessageBox.Show (String.Format ("{0} Do you wish to correct the value?", e.Message),
- "Error when committing the row to the original data source",
- MessageBoxButtons.YesNo);
- if (r == DialogResult.Yes) {
- InvalidateRowHeader (value.RowNumber);
- InvalidateRowHeader (current_cell.RowNumber);
- setting_current_cell = false;
- Edit ();
- return;
- }
- else
- ListManager.CancelCurrentEdit ();
- }
- }
- if (value.RowNumber == RowsCount && !ListManager.AllowNew)
- value.RowNumber --;
- }
- int old_row = current_cell.RowNumber;
- current_cell = value;
- EnsureCellVisibility (value);
- // by default, edition in existing rows is commited, and for new ones is discarded, unless
- // we receive actual input data from the user
- if (CurrentRow == RowsCount && ListManager.AllowNew) {
- commit_row_changes = false;
- cursor_in_add_row = true;
- add_row_changed = false;
- adding_new_row = true;
- AddNewRow ();
- adding_new_row = false;
- }
- else {
- cursor_in_add_row = false;
- commit_row_changes = true;
- }
- InvalidateRowHeader (old_row);
- InvalidateRowHeader (current_cell.RowNumber);
- list_manager.Position = current_cell.RowNumber;
- OnCurrentCellChanged (EventArgs.Empty);
- if (!from_positionchanged_handler)
- Edit ();
- setting_current_cell = false;
- }
- }
- internal void EditRowChanged (DataGridColumnStyle column_style)
- {
- if (cursor_in_add_row) {
- if (!commit_row_changes) { // first change in add row, time to show another row in the ui
- commit_row_changes = true;
- RecreateDataGridRows (true);
- }
- }
- }
- int CurrentRow {
- get { return current_cell.RowNumber; }
- set { CurrentCell = new DataGridCell (value, current_cell.ColumnNumber); }
- }
- int CurrentColumn {
- get { return current_cell.ColumnNumber; }
- set { CurrentCell = new DataGridCell (current_cell.RowNumber, value); }
- }
- [Browsable(false)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- public int CurrentRowIndex {
- get {
- if (ListManager == null)
- return -1;
-
- return CurrentRow;
- }
- set { CurrentRow = value; }
- }
- [Browsable(false)]
- [EditorBrowsable(EditorBrowsableState.Never)]
- public override Cursor Cursor {
- get { return base.Cursor; }
- set { base.Cursor = value; }
- }
- [DefaultValue(null)]
- [Editor ("System.Windows.Forms.Design.DataMemberListEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
- public string DataMember {
- get { return datamember; }
- set {
- if (BindingContext != null) {
- SetDataSource (datasource, value);
- }
- else {
- if (list_manager != null)
- list_manager = null;
- datamember = value;
- refetch_list_manager = true;
- }
- }
- }
- [DefaultValue(null)]
- [RefreshProperties(RefreshProperties.Repaint)]
- [AttributeProvider (typeof (IListSource))]
- public object DataSource {
- get { return datasource; }
- set {
- if (BindingContext != null) {
- SetDataSource (value, ListManager == null ? datamember : string.Empty);
- }
- else {
- datasource = value;
- if (list_manager != null)
- datamember = string.Empty;
- if (list_manager != null)
- list_manager = null;
- refetch_list_manager = true;
- }
- }
- }
- protected override Size DefaultSize {
- get { return new Size (130, 80); }
- }
- [Browsable(false)]
- public int FirstVisibleColumn {
- get { return first_visible_column; }
- }
- [DefaultValue(false)]
- public bool FlatMode {
- get { return flatmode; }
- set {
- if (flatmode != value) {
- flatmode = value;
- OnFlatModeChanged (EventArgs.Empty);
- Refresh ();
- }
- }
- }
- public override Color ForeColor {
- get { return grid_style.ForeColor; }
- set { grid_style.ForeColor = value; }
- }
- public Color GridLineColor {
- get { return grid_style.GridLineColor; }
- set {
- if (value == Color.Empty)
- throw new ArgumentException ("Color.Empty value is invalid.");
- grid_style.GridLineColor = value;
- }
- }
- [DefaultValue(DataGridLineStyle.Solid)]
- public DataGridLineStyle GridLineStyle {
- get { return grid_style.GridLineStyle; }
- set { grid_style.GridLineStyle = value; }
- }
- public Color HeaderBackColor {
- get { return grid_style.HeaderBackColor; }
- set {
- if (value == Color.Empty)
- throw new ArgumentException ("Color.Empty value is invalid.");
- grid_style.HeaderBackColor = value;
- }
- }
- public Font HeaderFont {
- get { return grid_style.HeaderFont; }
- set { grid_style.HeaderFont = value; }
- }
- public Color HeaderForeColor {
- get { return grid_style.HeaderForeColor; }
- set { grid_style.HeaderForeColor = value; }
- }
- protected ScrollBar HorizScrollBar {
- get { return horiz_scrollbar; }
- }
- internal ScrollBar HScrollBar {
- get { return horiz_scrollbar; }
- }
- internal int HorizPixelOffset {
- get { return horiz_pixeloffset; }
- }
- internal bool IsChanging {
- get { return is_changing; }
- }
- public object this [DataGridCell cell] {
- get { return this [cell.RowNumber, cell.ColumnNumber]; }
- set { this [cell.RowNumber, cell.ColumnNumber] = value; }
- }
- public object this [int rowIndex, int columnIndex] {
- get { return CurrentTableStyle.GridColumnStyles[columnIndex].GetColumnValueAtRow (ListManager,
- rowIndex); }
- set {
- CurrentTableStyle.GridColumnStyles[columnIndex].SetColumnValueAtRow (ListManager,
- rowIndex, value);
- // UIA Framework: Raising changes in datasource.
- OnUIAGridCellChanged (new CollectionChangeEventArgs (CollectionChangeAction.Refresh,
- new DataGridCell (rowIndex,
- columnIndex)));
- }
- }
- public Color LinkColor {
- get { return grid_style.LinkColor; }
- set { grid_style.LinkColor = value; }
- }
- internal Font LinkFont {
- get { return new Font (Font, FontStyle.Underline); }
- }
- [Browsable(false)]
- [EditorBrowsable(EditorBrowsableState.Never)]
- public Color LinkHoverColor {
- get { return grid_style.LinkHoverColor; }
- set { grid_style.LinkHoverColor = value; }
- }
- [Browsable(false)]
- [EditorBrowsable(EditorBrowsableState.Advanced)]
- protected internal CurrencyManager ListManager {
- get {
- if (list_manager == null && refetch_list_manager) {
- SetDataSource (datasource, datamember);
- refetch_list_manager = false;
- }
- return list_manager;
- }
- set { throw new NotSupportedException ("Operation is not supported."); }
- }
- public Color ParentRowsBackColor {
- get { return parent_rows_backcolor; }
- set {
- if (parent_rows_backcolor != value) {
- parent_rows_backcolor = value;
- if (parent_rows_visible) {
- Refresh ();
- }
- }
- }
- }
- public Color ParentRowsForeColor {
- get { return parent_rows_forecolor; }
- set {
- if (parent_rows_forecolor != value) {
- parent_rows_forecolor = value;
- if (parent_rows_visible) {
- Refresh ();
- }
- }
- }
- }
- [DefaultValue(DataGridParentRowsLabelStyle.Both)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- public DataGridParentRowsLabelStyle ParentRowsLabelStyle {
- get { return parent_rows_label_style; }
- set {
- if (parent_rows_label_style != value) {
- parent_rows_label_style = value;
- if (parent_rows_visible) {
- Refresh ();
- }
- OnParentRowsLabelStyleChanged (EventArgs.Empty);
- }
- }
- }
- [DefaultValue(true)]
- public bool ParentRowsVisible {
- get { return parent_rows_visible; }
- set {
- if (parent_rows_visible != value) {
- parent_rows_visible = value;
- CalcAreasAndInvalidate ();
- OnParentRowsVisibleChanged (EventArgs.Empty);
- }
- }
- }
- // Settting this property seems to have no effect.
- [DefaultValue(75)]
- [TypeConverter(typeof(DataGridPreferredColumnWidthTypeConverter))]
- public int PreferredColumnWidth {
- get { return grid_style.PreferredColumnWidth; }
- set { grid_style.PreferredColumnWidth = value; }
- }
- public int PreferredRowHeight {
- get { return grid_style.PreferredRowHeight; }
- set { grid_style.PreferredRowHeight = value; }
- }
- [DefaultValue(false)]
- public bool ReadOnly {
- get { return _readonly; }
- set {
- if (_readonly != value) {
- _readonly = value;
- OnReadOnlyChanged (EventArgs.Empty);
- CalcAreasAndInvalidate ();
- }
- }
- }
- [DefaultValue(true)]
- public bool RowHeadersVisible {
- get { return grid_style.RowHeadersVisible; }
- set { grid_style.RowHeadersVisible = value; }
- }
- [DefaultValue(35)]
- public int RowHeaderWidth {
- get { return grid_style.RowHeaderWidth; }
- set { grid_style.RowHeaderWidth = value; }
- }
- internal DataGridRelationshipRow[] DataGridRows {
- get { return rows; }
- }
- public Color SelectionBackColor {
- get { return grid_style.SelectionBackColor; }
- set { grid_style.SelectionBackColor = value; }
- }
- public Color SelectionForeColor {
- get { return grid_style.SelectionForeColor; }
- set { grid_style.SelectionForeColor = value; }
- }
- public override ISite Site {
- get { return base.Site; }
- set { base.Site = value; }
- }
- [Localizable(true)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
- public GridTableStylesCollection TableStyles {
- get { return styles_collection; }
- }
- [Bindable(false)]
- [Browsable(false)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- [EditorBrowsable(EditorBrowsableState.Never)]
- public override string Text {
- get { return base.Text; }
- set { base.Text = value; }
- }
- [Browsable(false)]
- [EditorBrowsable(EditorBrowsableState.Advanced)]
- protected ScrollBar VertScrollBar {
- get { return vert_scrollbar; }
- }
- internal ScrollBar VScrollBar {
- get { return vert_scrollbar; }
- }
- [Browsable(false)]
- public int VisibleColumnCount {
- get { return visible_column_count; }
- }
- [Browsable(false)]
- public int VisibleRowCount {
- get { return visible_row_count; }
- }
- #endregion // Public Instance Properties
- #region Private Instance Properties
- internal DataGridTableStyle CurrentTableStyle {
- get { return current_style; }
- set {
- if (current_style != value) {
- if (current_style != null)
- DisconnectTableStyleEvents ();
- current_style = value;
- if (current_style != null) {
- current_style.DataGrid = this;
- ConnectTableStyleEvents ();
- }
- CalcAreasAndInvalidate ();
- }
- }
- }
- internal int FirstVisibleRow {
- get { return first_visible_row; }
- }
- // As opposed to VisibleRowCount, this value is the maximum
- // *possible* number of visible rows given our area.
- internal int MaxVisibleRowCount {
- get {
- return cells_area.Height / RowHeight;
- }
- }
-
- internal int RowsCount {
- get { return ListManager != null ? ListManager.Count : 0; }
- }
- internal int RowHeight {
- get {
- if (CurrentTableStyle.CurrentPreferredRowHeight > Font.Height + 3 + 1 /* line */)
- return CurrentTableStyle.CurrentPreferredRowHeight;
- else
- return Font.Height + 3 + 1 /* line */;
- }
- }
-
- internal override bool ScaleChildrenInternal {
- get { return false; }
- }
- internal bool ShowEditRow {
- get {
- if (ListManager != null && !ListManager.AllowNew)
- return false;
- return !_readonly;
- }
- }
-
- internal bool ShowParentRows {
- get { return ParentRowsVisible && data_source_stack.Count > 0; }
- }
-
- #endregion Private Instance Properties
- #region Public Instance Methods
- void AbortEditing ()
- {
- if (is_changing) {
- CurrentTableStyle.GridColumnStyles[current_cell.ColumnNumber].Abort (current_cell.RowNumber);
- is_changing = false;
- InvalidateRowHeader (current_cell.RowNumber);
- }
- }
- public bool BeginEdit (DataGridColumnStyle gridColumn, int rowNumber)
- {
- if (is_changing)
- return false;
- int column = CurrentTableStyle.GridColumnStyles.IndexOf (gridColumn);
- if (column < 0)
- return false;
- CurrentCell = new DataGridCell (rowNumber, column);
- /* force editing of CurrentCell if we aren't already editing */
- Edit ();
- return true;
- }
- public void BeginInit ()
- {
- }
- protected virtual void CancelEditing ()
- {
- if (CurrentTableStyle.GridColumnStyles.Count == 0)
- return;
- CurrentTableStyle.GridColumnStyles[current_cell.ColumnNumber].ConcedeFocus ();
- if (is_changing) {
- if (current_cell.ColumnNumber < CurrentTableStyle.GridColumnStyles.Count)
- CurrentTableStyle.GridColumnStyles[current_cell.ColumnNumber].Abort (current_cell.RowNumber);
- InvalidateRowHeader (current_cell.RowNumber);
- }
- if (cursor_in_add_row && !is_changing) {
- ListManager.CancelCurrentEdit ();
- }
- is_changing = false;
- is_editing = false;
- }
- public void Collapse (int row)
- {
- if (!rows[row].IsExpanded)
- return;
- SuspendLayout ();
- rows[row].IsExpanded = false;
- for (int i = 1; i < rows.Length - row; i ++)
- rows[row + i].VerticalOffset -= rows[row].RelationHeight;
- rows[row].height -= rows[row].RelationHeight;
- rows[row].RelationHeight = 0;
- ResumeLayout (false);
- /* XX need to redraw from @row down */
- CalcAreasAndInvalidate ();
- }
- protected internal virtual void ColumnStartedEditing (Control editingControl)
- {
- ColumnStartedEditing (editingControl.Bounds);
- }
- protected internal virtual void ColumnStartedEditing (Rectangle bounds)
- {
- bool need_invalidate = is_changing == false;
- // XXX calculate the row header to invalidate
- // instead of using CurrentRow
- is_changing = true;
- if (cursor_in_add_row && need_invalidate)
- RecreateDataGridRows (true);
- if (need_invalidate)
- InvalidateRowHeader (CurrentRow);
- }
- protected override AccessibleObject CreateAccessibilityInstance ()
- {
- return base.CreateAccessibilityInstance ();
- }
- protected virtual DataGridColumnStyle CreateGridColumn (PropertyDescriptor prop)
- {
- return CreateGridColumn (prop, false);
- }
- [MonoTODO ("Not implemented, will throw NotImplementedException")]
- protected virtual DataGridColumnStyle CreateGridColumn (PropertyDescriptor prop, bool isDefault)
- {
- throw new NotImplementedException();
- }
- protected override void Dispose (bool disposing)
- {
- base.Dispose (disposing);
- }
- public bool EndEdit (DataGridColumnStyle gridColumn, int rowNumber, bool shouldAbort)
- {
- if (shouldAbort || (_readonly || gridColumn.TableStyleReadOnly || gridColumn.ReadOnly))
- gridColumn.Abort (rowNumber);
- else {
- gridColumn.Commit (ListManager, rowNumber);
- gridColumn.ConcedeFocus ();
- }
- if (is_editing || is_changing) {
- is_editing = false;
- is_changing = false;
- InvalidateRowHeader (rowNumber);
- }
- return true;
- }
- public void EndInit ()
- {
- if (grid_style != null)
- grid_style.DataGrid = this;
- }
- public void Expand (int row)
- {
- if (rows[row].IsExpanded)
- return;
- rows[row].IsExpanded = true;
- int i;
- string[] relations = CurrentTableStyle.Relations;
- StringBuilder relation_builder = new StringBuilder ("");
- for (i = 0; i < relations.Length; i ++) {
- if (i > 0)
- relation_builder.Append ("\n");
- relation_builder.Append (relations[i]);
- }
- string relation_text = relation_builder.ToString ();
- SizeF measured_area = TextRenderer.MeasureString (relation_text, LinkFont);
- rows[row].relation_area = new Rectangle (cells_area.X + 1,
- 0, /* updated as needed at the usage sites for relation_area */
- (int)measured_area.Width + 4,
- Font.Height * relations.Length);
- for (i = 1; i < rows.Length - row; i ++)
- rows[row + i].VerticalOffset += rows[row].relation_area.Height;
- rows[row].height += rows[row].relation_area.Height;
- rows[row].RelationHeight = rows[row].relation_area.Height;
- /* XX need to redraw from @row down */
- CalcAreasAndInvalidate ();
- }
- public Rectangle GetCellBounds (DataGridCell dgc)
- {
- return GetCellBounds (dgc.RowNumber, dgc.ColumnNumber);
- }
- public Rectangle GetCellBounds (int row, int col)
- {
- Rectangle bounds = new Rectangle ();
- int col_pixel;
- bounds.Width = CurrentTableStyle.GridColumnStyles[col].Width;
- bounds.Height = rows[row].Height - rows[row].RelationHeight;
- bounds.Y = cells_area.Y + rows[row].VerticalOffset - rows[FirstVisibleRow].VerticalOffset;
- col_pixel = GetColumnStartingPixel (col);
- bounds.X = cells_area.X + col_pixel - horiz_pixeloffset;
- return bounds;
- }
- public Rectangle GetCurrentCellBounds ()
- {
- return GetCellBounds (current_cell.RowNumber, current_cell.ColumnNumber);
- }
- protected virtual string GetOutputTextDelimiter ()
- {
- return string.Empty;
- }
- protected virtual void GridHScrolled (object sender, ScrollEventArgs se)
- {
- if (se.NewValue == horiz_pixeloffset ||
- se.Type == ScrollEventType.EndScroll) {
- return;
- }
- ScrollToColumnInPixels (se.NewValue);
- }
- protected virtual void GridVScrolled (object sender, ScrollEventArgs se)
- {
- int old_first_visible_row = first_visible_row;
- first_visible_row = se.NewValue;
- if (first_visible_row == old_first_visible_row)
- return;
- UpdateVisibleRowCount ();
- if (first_visible_row == old_first_visible_row)
- return;
-
- ScrollToRow (old_first_visible_row, first_visible_row);
- }
- public HitTestInfo HitTest (Point position)
- {
- return HitTest (position.X, position.Y);
- }
- const int RESIZE_HANDLE_HORIZ_SIZE = 5;
- const int RESIZE_HANDLE_VERT_SIZE = 3;
- // From Point to Cell
- public HitTestInfo HitTest (int x, int y)
- {
- if (column_headers_area.Contains (x, y)) {
- int offset_x = x + horiz_pixeloffset;
- int column_x;
- int column_under_mouse = FromPixelToColumn (offset_x, out column_x);
- if (column_under_mouse == -1)
- return new HitTestInfo (-1, -1, HitTestType.None);
- if ((column_x + CurrentTableStyle.GridColumnStyles[column_under_mouse].Width - offset_x < RESIZE_HANDLE_HORIZ_SIZE)
- && column_under_mouse < CurrentTableStyle.GridColumnStyles.Count) {
- return new HitTestInfo (-1, column_under_mouse, HitTestType.ColumnResize);
- }
- else {
- return new HitTestInfo (-1, column_under_mouse, HitTestType.ColumnHeader);
- }
- }
- if (row_headers_area.Contains (x, y)) {
- int posy;
- int rcnt = FirstVisibleRow + VisibleRowCount;
- for (int r = FirstVisibleRow; r < rcnt; r++) {
- posy = cells_area.Y + rows[r].VerticalOffset - rows[FirstVisibleRow].VerticalOffset;
- if (y <= posy + rows[r].Height) {
- if ((posy + rows[r].Height) - y < RESIZE_HANDLE_VERT_SIZE) {
- return new HitTestInfo (r, -1, HitTestType.RowResize);
- }
- else {
- return new HitTestInfo (r, -1, HitTestType.RowHeader);
- }
- }
- }
- }
- if (caption_area.Contains (x, y)) {
- return new HitTestInfo (-1, -1, HitTestType.Caption);
- }
- if (parent_rows.Contains (x, y)) {
- return new HitTestInfo (-1, -1, HitTestType.ParentRows);
- }
- int pos_y, pos_x, width;
- int rowcnt = FirstVisibleRow + VisibleRowCount;
- for (int row = FirstVisibleRow; row < rowcnt; row++) {
- pos_y = cells_area.Y + rows[row].VerticalOffset - rows[FirstVisibleRow].VerticalOffset;
- if (y <= pos_y + rows[row].Height) {
- int col_pixel;
- int column_cnt = first_visible_column + visible_column_count;
- if (column_cnt > 0) {
- for (int column = first_visible_column; column < column_cnt; column++) {
- if (CurrentTableStyle.GridColumnStyles[column].bound == false)
- continue;
- col_pixel = GetColumnStartingPixel (column);
- pos_x = cells_area.X + col_pixel - horiz_pixeloffset;
- width = CurrentTableStyle.GridColumnStyles[column].Width;
- if (x <= pos_x + width) { // Column found
- return new HitTestInfo (row, column, HitTestType.Cell);
- }
- }
- }
- else if (CurrentTableStyle.HasRelations) {
- /* XXX this needs checking against MS somehow... */
- if (x < rows[row].relation_area.X + rows[row].relation_area.Width)
- return new HitTestInfo (row, 0/*XXX?*/, HitTestType.Cell);
- }
- break;
- }
- }
- return new HitTestInfo ();
- }
- public bool IsExpanded (int rowNumber)
- {
- return (rows[rowNumber].IsExpanded);
- }
- public bool IsSelected (int row)
- {
- return rows[row].IsSelected;
- }
- public void NavigateBack ()
- {
- if (data_source_stack.Count == 0)
- return;
-
- EndEdit ();
- DataGridDataSource source = (DataGridDataSource)data_source_stack.Pop ();
- CurrentTableStyle= (DataGridTableStyle)data_grid_table_style_stack.Pop ();
- grid_style = (DataGridTableStyle) grid_style_stack.Pop ();
- list_manager = source.list_manager;
- rows = source.Rows;
- selected_rows = source.SelectedRows;
- selection_start = source.SelectionStart;
- SetDataSource (source.data_source, source.data_member);
- CurrentCell = source.current;
- }
- public void NavigateTo (int rowNumber, string relationName)
- {
- if (allow_navigation == false)
- return;
- EndEdit ();
- DataGridDataSource previous_source = new DataGridDataSource (this, list_manager, datasource, datamember, list_manager.Current, CurrentCell);
- previous_source.Rows = rows;
- previous_source.SelectedRows = selected_rows;
- previous_source.SelectionStart = selection_start;
- data_source_stack.Push (previous_source);
-
- data_grid_table_style_stack.Push (CurrentTableStyle);
- grid_style_stack.Push (grid_style);
- grid_style = new DataGridTableStyle ();
- CurrentTableStyle = grid_style;
- rows = null;
- selected_rows = new Hashtable ();
- selection_start = -1;
- DataMember = String.Format ("{0}.{1}", DataMember, relationName);
- OnDataSourceChanged (EventArgs.Empty);
- }
- protected virtual void OnAllowNavigationChanged (EventArgs e)
- {
- EventHandler eh = (EventHandler)(Events [AllowNavigationChangedEvent]);
- if (eh != null)
- eh (this, e);
- }
- protected void OnBackButtonClicked (object sender, EventArgs e)
- {
- EventHandler eh = (EventHandler)(Events [BackButtonClickEvent]);
- if (eh != null)
- eh (this, e);
- }
- protected override void OnBackColorChanged (EventArgs e)
- {
- base.OnBackColorChanged (e);
- }
- protected virtual void OnBackgroundColorChanged (EventArgs e)
- {
- EventHandler eh = (EventHandler)(Events [BackgroundColorChangedEvent]);
- if (eh != null)
- eh (this, e);
- }
- protected override void OnBindingContextChanged (EventArgs e)
- {
- base.OnBindingContextChanged (e);
- SetDataSource (datasource, datamember);
- }
- protected virtual void OnBorderStyleChanged (EventArgs e)
- {
- EventHandler eh = (EventHandler)(Events [BorderStyleChangedEvent]);
- if (eh != null)
- eh (this, e);
- }
- protected virtual void OnCaptionVisibleChanged (EventArgs e)
- {
- EventHandler eh = (EventHandler)(Events [CaptionVisibleChangedEvent]);
- if (eh != null)
- eh (this, e);
- }
- protected virtual void OnCurrentCellChanged (EventArgs e)
- {
- EventHandler eh = (EventHandler)(Events [CurrentCellChangedEvent]);
- if (eh != null)
- eh (this, e);
- }
- protected virtual void OnDataSourceChanged (EventArgs e)
- {
- EventHandler eh = (EventHandler)(Events [DataSourceChangedEvent]);
- if (eh != null)
- eh (this, e);
- }
- protected override void OnEnter (EventArgs e)
- {
- base.OnEnter (e);
- Edit ();
- }
- protected virtual void OnFlatModeChanged (EventArgs e)
- {
- EventHandler eh = (EventHandler)(Events [FlatModeChangedEvent]);
- if (eh != null)
- eh (this, e);
- }
- protected override void OnFontChanged (EventArgs e)
- {
- CalcGridAreas ();
- base.OnFontChanged (e);
- }
- protected override void OnForeColorChanged (EventArgs e)
- {
- base.OnForeColorChanged (e);
- }
- protected override void OnHandleCreated (EventArgs e)
- {
- base.OnHandleCreated (e);
- SetDataSource (datasource, datamember);
- }
- protected override void OnHandleDestroyed (EventArgs e)
- {
- base.OnHandleDestroyed (e);
- }
- // It seems we have repeated code with ProcessKeyPreview, specifically
- // the call to ProcessGridKey. In practice it seems this event is *never* fired
- // since the key events are handled by the current column's textbox.
- // We are keeping commented anyway, in case we need to actually call it.
- protected override void OnKeyDown (KeyEventArgs ke)
- {
- base.OnKeyDown (ke);
-
- /*if (ProcessGridKey (ke) == true)
- ke.Handled = true;
- // TODO: we probably don't need this check,
- // since current_cell wouldn't have been set
- // to something invalid
- if (CurrentTableStyle.GridColumnStyles.Count > 0) {
- CurrentTableStyle.GridColumnStyles[current_cell.ColumnNumber].OnKeyDown
- (ke, current_cell.RowNumber, current_cell.ColumnNumber);
- }*/
- }
- protected override void OnKeyPress (KeyPressEventArgs kpe)
- {
- base.OnKeyPress (kpe);
- }
- protected override void OnLayout (LayoutEventArgs levent)
- {
- base.OnLayout (levent);
- CalcAreasAndInvalidate ();
- }
- protected override void OnLeave (EventArgs e)
- {
- base.OnLeave (e);
- EndEdit ();
- if (commit_row_changes)
- ListManager.EndCurrentEdit ();
- else
- ListManager.CancelCurrentEdit ();
- }
- protected override void OnMouseDown (MouseEventArgs e)
- {
- base.OnMouseDown (e);
- bool ctrl_pressed = ((Control.ModifierKeys & Keys.Control) != 0);
- bool shift_pressed = ((Control.ModifierKeys & Keys.Shift) != 0);
- HitTestInfo testinfo;
- testinfo = HitTest (e.X, e.Y);
- switch (testinfo.Type) {
- case HitTestType.Cell:
- if (testinfo.Row < 0 || testinfo.Column < 0)
- break;
- if (rows[testinfo.Row].IsExpanded) {
- Rectangle relation_area = rows[testinfo.Row].relation_area;
- relation_area.Y = rows[testinfo.Row].VerticalOffset + cells_area.Y + rows[testinfo.Row].Height - rows[testinfo.Row].RelationHeight;
- if (relation_area.Contains (e.X, e.Y)) {
- /* the click happened in the relation area, navigate to the new table */
- int relative = e.Y - relation_area.Y;
- NavigateTo (testinfo.Row, CurrentTableStyle.Relations[relative / LinkFont.Height]);
- return;
- }
- }
- DataGridCell new_cell = new DataGridCell (testinfo.Row, testinfo.Column);
- if ((new_cell.Equals (current_cell) == false) || (!is_editing)) {
- ResetSelection ();
- CurrentCell = new_cell;
- Edit ();
- } else {
- CurrentTableStyle.GridColumnStyles[testinfo.Column].OnMouseDown (e, testinfo.Row, testinfo.Column);
- }
- break;
- case HitTestType.RowHeader:
- bool expansion_click = false;
- if (CurrentTableStyle.HasRelations) {
- if (e.X > row_headers_area.X + row_headers_area.Width / 2) {
- /* it's in the +/- space */
- if (IsExpanded (testinfo.Row))
- Collapse (testinfo.Row);
- else
- Expand (testinfo.Row);
- expansion_click = true;
- }
- }
- CancelEditing ();
- CurrentRow = testinfo.Row;
- if (!ctrl_pressed && !shift_pressed && !expansion_click) {
- ResetSelection (); // Invalidates selected rows
- }
- if ((shift_pressed || expansion_click) && selection_start != -1) {
- ShiftSelection (testinfo.Row);
- } else { // ctrl_pressed or single item
- selection_start = testinfo.Row;
- Select (testinfo.Row);
- }
- OnRowHeaderClick (EventArgs.Empty);
- break;
- case HitTestType.ColumnHeader:
- if (CurrentTableStyle.GridColumnStyles.Count == 0)
- break;
- if (AllowSorting == false)
- break;
- if (ListManager.List is IBindingList == false)
- break;
- // Don't do any sort if we are empty, as .net does
- if (ListManager.Count == 0)
- return;
-
- ListSortDirection direction = ListSortDirection.Ascending;
- PropertyDescriptor prop = CurrentTableStyle.GridColumnStyles[testinfo.Column].PropertyDescriptor;
- IBindingList list = (IBindingList) ListManager.List;
- if (list.SortProperty != null) {
- CurrentTableStyle.GridColumnStyles[list.SortProperty].ArrowDrawingMode
- = DataGridColumnStyle.ArrowDrawing.No;
- }
- if (prop == list.SortProperty && list.SortDirection == ListSortDirection.Ascending) {
- direction = ListSortDirection.Descending;
- }
-
- CurrentTableStyle.GridColumnStyles[testinfo.Column].ArrowDrawingMode =
- direction == ListSortDirection.Ascending ?
- DataGridColumnStyle.ArrowDrawing.Ascending : DataGridColumnStyle.ArrowDrawing.Descending;
-
- list.ApplySort (prop, direction);
- Refresh ();
- if (this.is_editing)
- //CurrentTableStyle.GridColumnStyles[CurrentColumn].UpdateUI ();
- this.InvalidateColumn (CurrentTableStyle.GridColumnStyles[CurrentColumn]);
- break;
- case HitTestType.ColumnResize:
- if (e.Clicks == 2) {
- EndEdit ();
- ColumnResize (testinfo.Column);
- } else {
- resize_column = testinfo.Column;
- column_resize_active = true;
- resize_column_x = e.X;
- resize_column_width_delta = 0;
- EndEdit ();
- DrawResizeLineVert (resize_column_x);
- }
- break;
- case HitTestType.RowResize:
- if (e.Clicks == 2) {
- EndEdit ();
- RowResize (testinfo.Row);
- } else {
- resize_row = testinfo.Row;
- row_resize_active = true;
- resize_row_y = e.Y;
- resize_row_height_delta = 0;
- EndEdit ();
- DrawResizeLineHoriz (resize_row_y);
- }
- break;
- case HitTestType.Caption:
- if (back_button_rect.Contains (e.X, e.Y)) {
- back_button_active = true;
- Invalidate (back_button_rect);
- }
- if (parent_rows_button_rect.Contains (e.X, e.Y)) {
- parent_rows_button_active = true;
- Invalidate (parent_rows_button_rect);
- }
- break;
- default:
- break;
- }
- }
- protected override void OnMouseLeave (EventArgs e)
- {
- base.OnMouseLeave (e);
- }
- protected override void OnMouseMove (MouseEventArgs e)
- {
- base.OnMouseMove (e);
- if (column_resize_active) {
- /* erase the old line */
- DrawResizeLineVert (resize_column_x + resize_column_width_delta);
- resize_column_width_delta = e.X - resize_column_x;
- /* draw the new line */
- DrawResizeLineVert (resize_column_x + resize_column_width_delta);
- return;
- }
- else if (row_resize_active) {
- /* erase the old line */
- DrawResizeLineHoriz (resize_row_y + resize_row_height_delta);
- resize_row_height_delta = e.Y - resize_row_y;
- /* draw the new line */
- DrawResizeLineHoriz (resize_row_y + resize_row_height_delta);
- return;
- }
- else {
- /* determine the cursor to use */
- HitTestInfo testinfo;
- testinfo = HitTest (e.X, e.Y);
- switch (testinfo.Type) {
- case HitTestType.ColumnResize:
- Cursor = Cursors.VSplit;
- break;
- case HitTestType.RowResize:
- Cursor = Cursors.HSplit;
- break;
- case HitTestType.Caption:
- Cursor = Cursors.Default;
- if (back_button_rect.Contains (e.X, e.Y)) {
- if (!back_button_mouseover)
- Invalidate (back_button_rect);
- back_button_mouseover = true;
- } else if (back_button_mouseover) {
- Invalidate (back_button_rect);
- back_button_mouseover = false;
- }
- if (parent_rows_button_rect.Contains (e.X, e.Y)) {
- if (parent_rows_button_mouseover)
- Invalidate (parent_rows_button_rect);
- parent_rows_button_mouseover = true;
- } else if (parent_rows_button_mouseover) {
- Invalidate (parent_rows_button_rect);
- parent_rows_button_mouseover = false;
- }
- break;
- case HitTestType.Cell:
- if (rows[testinfo.Row].IsExpanded) {
- Rectangle relation_area = rows[testinfo.Row].relation_area;
- relation_area.Y = rows[testinfo.Row].VerticalOffset + cells_area.Y + rows[testinfo.Row].Height - rows[testinfo.Row].RelationHeight;
- if (relation_area.Contains (e.X, e.Y)) {
- Cursor = Cursors.Hand;
- break;
- }
- }
- Cursor = Cursors.Default;
- break;
- case HitTestType.RowHeader:
- if (e.Button == MouseButtons.Left)
- ShiftSelection (testinfo.Row);
- Cursor = Cursors.Default;
- break;
- default:
- Cursor = Cursors.Default;
- break;
- }
- }
- }
- protected override void OnMouseUp (MouseEventArgs e)
- {
- base.OnMouseUp (e);
- if (column_resize_active) {
- column_resize_active = false;
- if (resize_column_width_delta + CurrentTableStyle.GridColumnStyles[resize_column].Width < 0)
- resize_column_width_delta = -CurrentTableStyle.GridColumnStyles[resize_column].Width;
- CurrentTableStyle.GridColumnStyles[resize_column].Width += resize_column_width_delta;
- width_of_all_columns += resize_column_width_delta;
- Edit ();
- Invalidate ();
- } else if (row_resize_active) {
- row_resize_active = false;
- if (resize_row_height_delta + rows[resize_row].Height < 0)
- resize_row_height_delta = -rows[resize_row].Height;
- rows[resize_row].height = rows[resize_row].Height + resize_row_height_delta;
- for (int i = resize_row + 1; i < rows.Length; i ++)
- rows[i].VerticalOffset += resize_row_height_delta;
- Edit ();
- CalcAreasAndInvalidate ();
- } else if (back_button_active) {
- if (back_button_rect.Contains (e.X, e.Y)) {
- Invalidate (back_button_rect);
- NavigateBack ();
- OnBackButtonClicked (this, EventArgs.Empty);
- }
- back_button_active = false;
- } else if (parent_rows_button_active) {
- if (parent_rows_button_rect.Contains (e.X, e.Y)) {
- Invalidate (parent_rows_button_rect);
- ParentRowsVisible = !ParentRowsVisible;
- OnShowParentDetailsButtonClicked (this, EventArgs.Empty);
- }
- parent_rows_button_active = false;
- }
- }
- protected override void OnMouseWheel (MouseEventArgs e)
- {
- base.OnMouseWheel (e);
- bool ctrl_pressed = ((Control.ModifierKeys & Keys.Control) != 0);
- int pixels;
- if (ctrl_pressed) { // scroll horizontally
- if (!horiz_scrollbar.Visible)
- return;
- if (e.Delta > 0) {
- /* left */
- pixels = Math.Max (horiz_scrollbar.Minimum,
- horiz_scrollbar.Value - horiz_scrollbar.LargeChange);
- } else {
- /* right */
- pixels = Math.Min (horiz_scrollbar.Maximum - horiz_scrollbar.LargeChange + 1,
- horiz_scrollbar.Value + horiz_scrollbar.LargeChange);
- }
- GridHScrolled (this, new ScrollEventArgs (ScrollEventType.ThumbPosition, pixels));
- horiz_scrollbar.Value = pixels;
- } else {
- if (!vert_scrollbar.Visible)
- return;
- if (e.Delta > 0) {
- /* up */
- pixels = Math.Max (vert_scrollbar.Minimum,
- vert_scrollbar.Value - vert_scrollbar.LargeChange);
- } else {
- /* down */
- pixels = Math.Min (vert_scrollbar.Maximum - vert_scrollbar.LargeChange + 1,
- vert_scrollbar.Value + vert_scrollbar.LargeChange);
- }
- GridVScrolled (this, new ScrollEventArgs (ScrollEventType.ThumbPosition, pixels));
- vert_scrollbar.Value = pixels;
- }
- }
- protected void OnNavigate (NavigateEventArgs e)
- {
- EventHandler eh = (EventHandler)(Events [NavigateEvent]);
- if (eh != null)
- eh (this, e);
- }
- protected override void OnPaint (PaintEventArgs pe)
- {
- ThemeEngine.Current.DataGridPaint (pe, this);
- }
- protected override void OnPaintBackground (PaintEventArgs ebe)
- {
- }
- protected virtual void OnParentRowsLabelStyleChanged (EventArgs e)
- {
- EventHandler eh = (EventHandler)(Events [ParentRowsLabelStyleChangedEvent]);
- if (eh != null)
- eh (this, e);
- }
- protected virtual void OnParentRowsVisibleChanged (EventArgs e)
- {
- EventHandler eh = (EventHandler)(Events [ParentRowsVisibleChangedEvent]);
- if (eh != null)
- eh (this, e);
- }
- protected virtual void OnReadOnlyChanged (EventArgs e)
- {
- EventHandler eh = (EventHandler)(Events [ReadOnlyChangedEve…
Large files files are truncated, but you can click here to view the full file