summaryrefslogtreecommitdiff
path: root/wintable
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-11-19 22:33:18 -0500
committerPietro Gagliardi <[email protected]>2014-11-19 22:33:18 -0500
commit031c67e38d3af33334be2201fc0164d8e837fce0 (patch)
tree492e54db4e14508a41bb39dc477d6f4d5c169824 /wintable
parentd75795f968dedb0e544d6701e8e2b2fdc11b08f9 (diff)
Split the code to turn x/y LPARAM into a row/column number to its own function. The mouse tracking code will need it.
Diffstat (limited to 'wintable')
-rw-r--r--wintable/main.c33
1 files 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;