Ejemplo n.º 1
0
        private IHTMLElement GetTargetCell(Point clientPoint)
        {
            // maximum amount of scanning buffer is based on cell spacing
            int maxScanningRange = Math.Max(TableHelper.GetAttributeAsInteger(_table.cellSpacing), 2);

            // copy client point so we can modify the x-coordinate while scanning
            Point targetPoint = new Point(clientPoint.X, clientPoint.Y);

            // if we go past the end of the table allow the cell closest to the cursor
            // to become the target cell (necessary for sizing the table larger)
            Point          xTargetPoint = new Point(targetPoint.X, targetPoint.Y);
            IHTMLTableCell targetCell   = null;

            while (targetCell == null && xTargetPoint.X >= (targetPoint.X - maxScanningRange))   // 0 )
            {
                // determine the cell we are over
                targetCell = _editorContext.ElementFromClientPoint(xTargetPoint) as IHTMLTableCell;

                // screen cells that don't belong to us
                if (!HTMLElementHelper.ElementsAreEqual(_table as IHTMLElement, TableHelper.GetContainingTableElement(targetCell as IHTMLElement) as IHTMLElement))
                {
                    targetCell = null;
                }

                xTargetPoint.X--;
            }


            // if we got a target cell then ensure that the point is over the document area
            if (targetCell != null)
            {
                if (_editorContext.PointIsOverDocumentArea(clientPoint))
                {
                    return(targetCell as IHTMLElement);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 2
0
        private void HandleMouseMove(TableColumnMouseEventArgs ea)
        {
            // cell element we are over
            IHTMLElement targetCell = GetTargetCell(ea.ClientPoint);

            // if there is no element then we are done
            if (targetCell == null)
            {
                // reset state
                _sizingOperation.EndSizing();
                return;
            }

            // get the cell and row
            IHTMLTableCell cell = targetCell as IHTMLTableCell;
            IHTMLTableRow  row  = TableHelper.GetContainingRowElement(cell);

            // convert the client point to cell-local coordinates & calcualte our comparison x values
            TableCellEditingElementBehavior cellBehavior = _tableEditingContext.GetCellBehavior(targetCell);

            if (cellBehavior == null)
            {
                _sizingOperation.ClearPending();
                return;
            }

            Point cellLocalMousePt  = cellBehavior.TransformGlobalToLocal(ea.ClientPoint);
            int   cellSpacing       = TableHelper.GetAttributeAsInteger(_table.cellSpacing);
            int   cellSpacingOffset = cellSpacing / 2;
            int   compareX          = cellLocalMousePt.X;
            int   cellStartX        = 0 - cellSpacingOffset;
            int   cellEndX          = targetCell.offsetWidth + cellSpacingOffset;

            // if the mouse is near the edge of the cell then update the pending sizing action
            // (unless the mouse is near the edge of the first cell where no sizing is supported)
            if (MouseNearCellEdge(compareX, cellStartX, cellSpacing) || MouseNearCellEdge(compareX, cellEndX, cellSpacing))
            {
                if (MouseNearCellEdge(compareX, cellStartX, cellSpacing))
                {
                    if (cell.cellIndex > 0)
                    {
                        int leftIndex  = cell.cellIndex - 1;
                        int rightIndex = cell.cellIndex;
                        _sizingOperation.TrackPending(ea.ClientPoint.X, leftIndex, rightIndex);
                        ea.Handled = true;
                    }
                    else
                    {
                        _sizingOperation.ClearPending();
                    }
                }
                else if (MouseNearCellEdge(compareX, cellEndX, cellSpacing))
                {
                    int leftIndex  = cell.cellIndex;
                    int rightIndex = cell.cellIndex < (row.cells.length - 1) ? cell.cellIndex + 1 : -1;

                    _sizingOperation.TrackPending(ea.ClientPoint.X, leftIndex, rightIndex);
                    ea.Handled = true;
                }
            }
            else // mouse is not near the edge of the cell, reset pending action
            {
                _sizingOperation.ClearPending();
            }
        }