There is a possible bug that I found in "GetTableCellFromPoint" when used with large tables on CVI 8.1 under XP Pro SP2.
Create a table in a UIR panel, populate it with lots of empty row and columns with both scroll bars activated. Use enough rows and columns to go force the table to turn on the scrol bars. Add a callback function to the table. In that callback, add the event that captures the mouse cursor movement. Add a custom function to that particular event branch that reports back the row index and column index. That would look something like this.
int __cdecl TableCCB (int panel, int control, int event, void *callbackData, int eventData1, int eventData2)
{
int rowIndex;
int colIndex;
switch (event) {
case EVENT_MOUSE_POINTER_MOVE:
MouseOverGetsTableCell (panel, control, eventData2, eventData1, &rowIndex, &colIndex);
break;
}
return 0;
}
Your custom function would be like this (the print statement was temporarily added for text reporting from this function):
static int __stdcall MouseOverGetsTableCell (int pnl, int ctrl, int msX, int msY, int *row, int *col)
{
Rect gridCoords;
Point hoverCell;
/*----------------------------------------------------------------------*/
GetTableCellRangeRect (pnl, ctrl, VAL_TABLE_ENTIRE_RANGE, &gridCoords);
GetTableCellFromPoint (pnl, ctrl, MakePoint (msX, msY), &hoverCell);
printf ("Row = %4d, Col = %4d.\n", hoverCell.y, hoverCell.x);
*row = hoverCell.y;
*col = hoverCell.x;
return 0;
}
You will notice that when you hover over the row labels and the column labels, it will report erroneous cell values.
I already got a fix for this for my use, using a technique from one of the CVI samples.
Insert the following where the "/*----*/" comment is located and add the appropriate Rect and int variables:
GetTableCellRangeRect (pnl, ctrl, VAL_TABLE_ENTIRE_RANGE, &labelCoords);
GetCtrlAttribute (pnl, ctrl, ATTR_ROW_LABELS_WIDTH, &labelCoords.width);
GetCtrlAttribute (pnl, ctrl, ATTR_GRID_AREA_LEFT, &gridLeft);
GetCtrlAttribute (pnl, ctrl, ATTR_LEFT, &tableLeft);
labelCoords.left = tableLeft + gridLeft - labelCoords.width;
if (RectContainsPoint (labelCoords, MakePoint (msX, msY))) {
*row = 0;
*col = 0;
printf ("Mouse is over row label area.\n");
return 0;
}
GetTableCellRangeRect (pnl, ctrl, VAL_TABLE_ENTIRE_RANGE, &labelCoords);
GetCtrlAttribute (pnl, ctrl, ATTR_COLUMN_LABELS_HEIGHT, &labelCoords.height);
GetCtrlAttribute (pnl, ctrl, ATTR_GRID_AREA_TOP, &gridTop);
GetCtrlAttribute (pnl, ctrl, ATTR_TOP, &tableTop);
labelCoords.top = tableTop + gridTop - labelCoords.height;
if (RectContainsPoint (labelCoords, MakePoint (msX, msY))) {
*row = 0;
*col = 0;
printf ("Mouse is over col label area.\n");
return 0;
}
Does anyone have any comments on whether this is a CVI bug or not?
I don't recall that behavior before, and I think I was using tables ever since they first appeared...
JB
--
To whom it may concern: My alias is also my nickname, I've had it since I was a (very) skinny basketball-playing teen. OK, so I've got a 38 inch waist now, but my hometown friends haven't shaken that appellation for me. I trust that you will someday be OK with that alias, as I have been with that nickname.