Beispiel #1
0
        /// <summary>
        /// Returns the row number of the clicked cell.
        /// </summary>
        /// <param name="dg">The parent WorksheetController.</param>
        /// <param name="mouseCoord">The mouse coordinates of the click.</param>
        /// <param name="cellRect">Returns the bounding rectangle of the clicked cell.</param>
        /// <param name="bPropertyCol">True if clicked on either the property column header or a property column, else false.</param>
        /// <returns>The row number of the clicked cell, or -1 if clicked on the column header.</returns>
        /// <remarks>If clicked onto a property cell, the function returns the property column number.</remarks>
        public static int GetRowNumber(WinFormsWorksheetController dg, Point mouseCoord, ref Rectangle cellRect, out bool bPropertyCol)
        {
            int firstVisibleColumn = dg.FirstVisibleColumn;
            int actualColumnRight  = dg.WorksheetLayout.RowHeaderStyle.Width;
            int columnCount        = dg.DataTable.DataColumns.ColumnCount;

            if (mouseCoord.Y < dg.WorksheetLayout.ColumnHeaderStyle.Height)
            {
                cellRect.Y   = 0; cellRect.Height = dg.WorksheetLayout.ColumnHeaderStyle.Height;
                bPropertyCol = false;
                return(-1);
            }

            if (mouseCoord.Y < dg.VerticalPositionOfFirstVisibleDataRow && dg.VisiblePropertyColumns > 0)
            {
                // calculate the raw row number
                int rawrow = (int)Math.Floor((mouseCoord.Y - dg.WorksheetLayout.ColumnHeaderStyle.Height) / (double)dg.WorksheetLayout.PropertyColumnHeaderStyle.Height);

                cellRect.Y      = dg.WorksheetLayout.ColumnHeaderStyle.Height + rawrow * dg.WorksheetLayout.PropertyColumnHeaderStyle.Height;
                cellRect.Height = dg.WorksheetLayout.PropertyColumnHeaderStyle.Height;

                bPropertyCol = true;
                return(dg.FirstVisiblePropertyColumn + rawrow);
            }
            else
            {
                int rawrow = (int)Math.Floor((mouseCoord.Y - dg.VerticalPositionOfFirstVisibleDataRow) / (double)dg.WorksheetLayout.RowHeaderStyle.Height);

                cellRect.Y      = dg.VerticalPositionOfFirstVisibleDataRow + rawrow * dg.WorksheetLayout.RowHeaderStyle.Height;
                cellRect.Height = dg.WorksheetLayout.RowHeaderStyle.Height;
                bPropertyCol    = false;
                return(dg.FirstVisibleTableRow + rawrow);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Retrieves the column number clicked onto
        /// </summary>
        /// <param name="dg">The parent data grid</param>
        /// <param name="mouseCoord">The coordinates of the mouse click.</param>
        /// <param name="cellRect">The function sets the x-properties (X and Width) of the cell rectangle.</param>
        /// <returns>Either -1 when clicked on the row header area, column number when clicked in the column range, or int.MinValue when clicked outside of all.</returns>
        public static int GetColumnNumber(WinFormsWorksheetController dg, Point mouseCoord, ref Rectangle cellRect)
        {
            int firstVisibleColumn = dg.FirstVisibleColumn;
            int actualColumnRight  = dg.WorksheetLayout.RowHeaderStyle.Width;
            int columnCount        = dg.DataTable.DataColumns.ColumnCount;

            if (mouseCoord.X < actualColumnRight)
            {
                cellRect.X = 0; cellRect.Width = actualColumnRight;
                return(-1);
            }

            for (int i = firstVisibleColumn; i < columnCount; i++)
            {
                cellRect.X = actualColumnRight;
                Altaxo.Worksheet.ColumnStyle cs = dg.GetDataColumnStyle(i);
                actualColumnRight += cs.Width;
                if (actualColumnRight > mouseCoord.X)
                {
                    cellRect.Width = cs.Width;
                    return(i);
                }
            } // end for
            return(int.MinValue);
        }
Beispiel #3
0
        /// <summary>
        /// Creates the ClickedCellInfo from the data grid and the mouse coordinates of the click.
        /// </summary>
        /// <param name="dg">The data grid.</param>
        /// <param name="mouseCoord">The mouse coordinates of the click.</param>
        public void MouseClick(WinFormsWorksheetController dg, Point mouseCoord)
        {
            bool bIsPropertyColumn = false;

            _clickedCellRectangle = new Rectangle(0, 0, 0, 0);
            _clickedColumn        = GetColumnNumber(dg, mouseCoord, ref _clickedCellRectangle);
            _clickedRow           = GetRowNumber(dg, mouseCoord, ref _clickedCellRectangle, out bIsPropertyColumn);

            if (bIsPropertyColumn)
            {
                if (_clickedColumn == -1)
                {
                    _clickedAreaType = AreaType.PropertyColumnHeader;
                }
                else if (_clickedColumn >= 0)
                {
                    _clickedAreaType = AreaType.PropertyCell;
                }
                else
                {
                    _clickedAreaType = AreaType.OutsideAll;
                }

                int h = _clickedColumn; _clickedColumn = _clickedRow; _clickedRow = h; // Swap columns and rows since it is a property column
            }
            else // it is not a property related cell
            {
                if (_clickedRow == -1 && _clickedColumn == -1)
                {
                    _clickedAreaType = AreaType.TableHeader;
                }
                else if (_clickedRow == -1 && _clickedColumn >= 0)
                {
                    _clickedAreaType = AreaType.DataColumnHeader;
                }
                else if (_clickedRow >= 0 && _clickedColumn == -1)
                {
                    _clickedAreaType = AreaType.DataRowHeader;
                }
                else if (_clickedRow >= 0 && _clickedColumn >= 0)
                {
                    _clickedAreaType = AreaType.DataCell;
                }
                else
                {
                    _clickedAreaType = AreaType.OutsideAll;
                }
            }
        }
Beispiel #4
0
    /// <summary>
    /// Creates the ClickedCellInfo from the data grid and the mouse coordinates of the click.
    /// </summary>
    /// <param name="dg">The data grid.</param>
    /// <param name="mouseCoord">The mouse coordinates of the click.</param>
    public void MouseClick(WinFormsWorksheetController dg, Point mouseCoord)
    {

      bool bIsPropertyColumn=false;
      _clickedCellRectangle = new Rectangle(0,0,0,0);
      _clickedColumn = GetColumnNumber(dg,mouseCoord, ref _clickedCellRectangle);
      _clickedRow    = GetRowNumber(dg,mouseCoord,ref _clickedCellRectangle, out bIsPropertyColumn);

      if(bIsPropertyColumn)
      {
        if(_clickedColumn==-1)
          _clickedAreaType = AreaType.PropertyColumnHeader;
        else if(_clickedColumn>=0)
          _clickedAreaType = AreaType.PropertyCell;
        else
          _clickedAreaType = AreaType.OutsideAll;

        int h=_clickedColumn; _clickedColumn = _clickedRow; _clickedRow = h; // Swap columns and rows since it is a property column
      }
      else // it is not a property related cell
      {
        if(_clickedRow==-1 && _clickedColumn==-1)
          _clickedAreaType = AreaType.TableHeader;
        else if(_clickedRow==-1 && _clickedColumn>=0)
          _clickedAreaType = AreaType.DataColumnHeader;
        else if(_clickedRow>=0 && _clickedColumn==-1)
          _clickedAreaType = AreaType.DataRowHeader;
        else if(_clickedRow>=0 && _clickedColumn>=0)
          _clickedAreaType = AreaType.DataCell;
        else
          _clickedAreaType = AreaType.OutsideAll;
      }
    }
Beispiel #5
0
    /// <summary>
    /// Returns the row number of the clicked cell.
    /// </summary>
    /// <param name="dg">The parent WorksheetController.</param>
    /// <param name="mouseCoord">The mouse coordinates of the click.</param>
    /// <param name="cellRect">Returns the bounding rectangle of the clicked cell.</param>
    /// <param name="bPropertyCol">True if clicked on either the property column header or a property column, else false.</param>
    /// <returns>The row number of the clicked cell, or -1 if clicked on the column header.</returns>
    /// <remarks>If clicked onto a property cell, the function returns the property column number.</remarks>
    public static int GetRowNumber(WinFormsWorksheetController dg, Point mouseCoord, ref Rectangle cellRect, out bool bPropertyCol)
    {
      int firstVisibleColumn = dg.FirstVisibleColumn;
      int actualColumnRight = dg.WorksheetLayout.RowHeaderStyle.Width;
      int columnCount = dg.DataTable.DataColumns.ColumnCount;

      if(mouseCoord.Y<dg.WorksheetLayout.ColumnHeaderStyle.Height)
      {
        cellRect.Y=0; cellRect.Height=dg.WorksheetLayout.ColumnHeaderStyle.Height;
        bPropertyCol=false;
        return -1;
      }

      if(mouseCoord.Y<dg.VerticalPositionOfFirstVisibleDataRow && dg.VisiblePropertyColumns>0)
      {
        // calculate the raw row number
        int rawrow = (int)Math.Floor((mouseCoord.Y-dg.WorksheetLayout.ColumnHeaderStyle.Height)/(double)dg.WorksheetLayout.PropertyColumnHeaderStyle.Height);

        cellRect.Y= dg.WorksheetLayout.ColumnHeaderStyle.Height + rawrow * dg.WorksheetLayout.PropertyColumnHeaderStyle.Height;
        cellRect.Height = dg.WorksheetLayout.PropertyColumnHeaderStyle.Height;

        bPropertyCol=true;
        return dg.FirstVisiblePropertyColumn+rawrow;
      }
      else
      {
        int rawrow = (int)Math.Floor((mouseCoord.Y-dg.VerticalPositionOfFirstVisibleDataRow)/(double)dg.WorksheetLayout.RowHeaderStyle.Height);

        cellRect.Y= dg.VerticalPositionOfFirstVisibleDataRow + rawrow * dg.WorksheetLayout.RowHeaderStyle.Height;
        cellRect.Height = dg.WorksheetLayout.RowHeaderStyle.Height;
        bPropertyCol=false;
        return dg.FirstVisibleTableRow + rawrow;
      }
    }
Beispiel #6
0
    /// <summary>
    /// Retrieves the column number clicked onto 
    /// </summary>
    /// <param name="dg">The parent data grid</param>
    /// <param name="mouseCoord">The coordinates of the mouse click.</param>
    /// <param name="cellRect">The function sets the x-properties (X and Width) of the cell rectangle.</param>
    /// <returns>Either -1 when clicked on the row header area, column number when clicked in the column range, or int.MinValue when clicked outside of all.</returns>
    public static int GetColumnNumber(WinFormsWorksheetController dg, Point mouseCoord, ref Rectangle cellRect)
    {
      int firstVisibleColumn = dg.FirstVisibleColumn;
      int actualColumnRight = dg.WorksheetLayout.RowHeaderStyle.Width;
      int columnCount = dg.DataTable.DataColumns.ColumnCount;

      if(mouseCoord.X<actualColumnRight)
      {
        cellRect.X=0; cellRect.Width=actualColumnRight;
        return -1;
      }

      for(int i=firstVisibleColumn;i<columnCount;i++)
      {
        cellRect.X=actualColumnRight;
        Altaxo.Worksheet.ColumnStyle cs = dg.GetDataColumnStyle(i);
        actualColumnRight += cs.Width;
        if(actualColumnRight>mouseCoord.X)
        {
          cellRect.Width = cs.Width;
          return i;
        }
      } // end for
      return int.MinValue;
    }