From e31fd24a9912e7adc8289cd1573e752dc7e8ae29 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Tue, 16 Dec 2014 18:46:19 -0500 Subject: [PATCH] Actually return no selection in clientCoordToRowColumn() correctly. Part 2 of previous commit. --- wintable/new/coord.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/wintable/new/coord.h b/wintable/new/coord.h index d42ab67..be0dbd7 100644 --- a/wintable/new/coord.h +++ b/wintable/new/coord.h @@ -39,19 +39,17 @@ static struct rowcol clientCoordToRowColumn(struct table *t, POINT pt) struct rowcol rc; intptr_t i; - // initial values for the PtInRect() check - rc.row = -1; - rc.column = -1; - if (GetClientRect(t->hwnd, &r) == 0) panic("error getting Table client rect in clientCoordToRowColumn()"); r.top += t->headerHeight; if (PtInRect(&r, pt) == 0) - return rc; + goto outside; // the row is easy pt.y -= t->headerHeight; rc.row = (pt.y / rowht(t)) + t->vscrollpos; + if (rc.row >= t->count) + goto outside; // the column... not so much // we scroll p.x, then subtract column widths until we cross the left edge of the control @@ -69,9 +67,15 @@ static struct rowcol clientCoordToRowColumn(struct table *t, POINT pt) break; rc.column++; } - // TODO what happens if the break was never taken? + if (rc.column >= t->nColumns) + goto outside; return rc; + +outside: + rc.row = -1; + rc.column = -1; + return rc; } // same as client coordinates, but stored in a lParam (like the various mouse messages provide)