From 031c67e38d3af33334be2201fc0164d8e837fce0 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Wed, 19 Nov 2014 22:33:18 -0500 Subject: [PATCH] Split the code to turn x/y LPARAM into a row/column number to its own function. The mouse tracking code will need it. --- wintable/main.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/wintable/main.c b/wintable/main.c index d9cffa6..e1fe9d1 100644 --- a/wintable/main.c +++ b/wintable/main.c @@ -205,6 +205,26 @@ static intptr_t hitTestColumn(struct table *t, int x) return -1; } +static void lParamToRowColumn(struct table *t, LPARAM lParam, intptr_t *row, intptr_t *column) +{ + int x, y; + LONG h; + + x = GET_X_LPARAM(lParam); + y = GET_Y_LPARAM(lParam); + h = rowHeight(t); + y += t->firstVisible * h; + y -= t->headerHeight; + y /= h; + if (row != NULL) { + *row = y; + if (*row >= t->count) + *row = -1; + } + if (column != NULL) + *column = hitTestColumn(t, x); +} + static void retrack(struct table *t) { TRACKMOUSEEVENT tm; @@ -523,21 +543,10 @@ static void keySelect(struct table *t, WPARAM wParam, LPARAM lParam) static void selectItem(struct table *t, WPARAM wParam, LPARAM lParam) { - int x, y; - LONG h; intptr_t prev; prev = t->selected; - x = GET_X_LPARAM(lParam); - y = GET_Y_LPARAM(lParam); - h = rowHeight(t); - y += t->firstVisible * h; - y -= t->headerHeight; - y /= h; - t->selected = y; - if (t->selected >= t->count) - t->selected = -1; - t->focusedColumn = hitTestColumn(t, x); + lParamToRowColumn(t, lParam, &(t->selected), &(t->focusedColumn)); // TODO only if inside a checkbox t->mouseDown = TRUE; t->mouseDownRow = t->selected;