summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-12-14 11:09:59 -0500
committerPietro Gagliardi <[email protected]>2014-12-14 11:09:59 -0500
commitf56ae488f0c9cf073f9b7ba2b4bde616ea702e59 (patch)
tree600e90534109caa51f6d044e7d0995149c227400
parentcb7404cf8bc1b435fb54c27a5693d4d6e56cdff9 (diff)
Implemented vertical scrolling on selection changes.
-rw-r--r--wintable/new/main.c4
-rw-r--r--wintable/new/select.h26
2 files changed, 25 insertions, 5 deletions
diff --git a/wintable/new/main.c b/wintable/new/main.c
index 9d92c6e..7d04efa 100644
--- a/wintable/new/main.c
+++ b/wintable/new/main.c
@@ -71,11 +71,11 @@ struct table {
#include "util.h"
#include "coord.h"
-#include "select.h"
-#include "events.h"
#include "scroll.h"
#include "hscroll.h"
#include "vscroll.h"
+#include "select.h"
+#include "events.h"
#include "header.h"
#include "children.h"
#include "resize.h"
diff --git a/wintable/new/select.h b/wintable/new/select.h
index 68e2eb6..299b382 100644
--- a/wintable/new/select.h
+++ b/wintable/new/select.h
@@ -6,18 +6,38 @@ static void doselect(struct table *t, intptr_t row, intptr_t column)
RECT r, client;
intptr_t oldrow;
LONG height;
+ struct rowcol rc;
+ BOOL dovscroll;
oldrow = t->selectedRow;
t->selectedRow = row;
t->selectedColumn = column;
- // TODO scroll to ensure the full cell is visible
-
- // now redraw the old and new /rows/
if (GetClientRect(t->hwnd, &client) == 0)
panic("error getting Table client rect in doselect()");
client.top += t->headerHeight;
height = rowht(t);
+
+ // first vertically scroll to the new row to make it fully visible (or as visible as possible)
+ if (t->selectedRow < t->vscrollpos)
+ vscrollto(t, t->selectedRow);
+ else {
+ rc.row = t->selectedRow;
+ rc.column = t->selectedColumn;
+ // first assume entirely outside the client area
+ dovscroll = TRUE;
+ if (rowColumnToClientRect(t, rc, &r))
+ // partially outside the client area?
+ if (r.bottom <= client.bottom) // <= here since we are comparing bottoms (which are the first pixels outside the rectangle)
+ dovscroll = FALSE;
+ if (dovscroll)
+ vscrollto(t, t->selectedRow - t->vpagesize + 1); // + 1 because apparently just t->selectedRow - t->vpagesize results in no scrolling (t->selectedRow - t->vpagesize == t->vscrollpos)...
+ }
+
+ // TODO horizontal scroll
+
+ // now redraw the old and new /rows/
+ // we do this after scrolling so the rectangles to be invalidated make sense
r.left = client.left;
r.right = client.right;
if (oldrow != -1 && oldrow >= t->vscrollpos) {