summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2015-01-07 21:34:12 -0500
committerPietro Gagliardi <[email protected]>2015-01-07 21:34:12 -0500
commit7eaadad25ca26c254139e3cdeb31d4cb9eb67f46 (patch)
tree3dd08bbc3bf2d4e99755d96f09713ffd5670dfbf
parent10cee922233d33df57e5f6195cb685b59d2bccaa (diff)
Implemented checkbox notifications.
-rw-r--r--wintable/checkboxes.h6
-rw-r--r--wintable/draw.h38
-rw-r--r--wintable/main.h2
-rw-r--r--wintable/test.c11
4 files changed, 32 insertions, 25 deletions
diff --git a/wintable/checkboxes.h b/wintable/checkboxes.h
index 67bc745..6e62621 100644
--- a/wintable/checkboxes.h
+++ b/wintable/checkboxes.h
@@ -199,9 +199,6 @@ HANDLER(checkboxMouseDownHandler)
return TRUE;
}
-// TODO get rid of this
-struct rowcol lastCheckbox;
-
HANDLER(checkboxMouseUpHandler)
{
struct rowcol rc;
@@ -225,8 +222,7 @@ HANDLER(checkboxMouseUpHandler)
pt.y = GET_Y_LPARAM(lParam);
if (PtInRect(&r, pt) == 0)
goto wrongUp;
- // TODO send toggle event
-lastCheckbox = rc;
+ notify(t, tableNotificationCellCheckboxToggled, rc.row, rc.column, 0);
t->checkboxMouseDown = FALSE;
// TODO redraw the whole cell?
if (InvalidateRect(t->hwnd, &r, TRUE) == 0)
diff --git a/wintable/draw.h b/wintable/draw.h
index a34ed4a..98c1402 100644
--- a/wintable/draw.h
+++ b/wintable/draw.h
@@ -67,13 +67,32 @@ static void drawImageCell(struct table *t, HDC dc, struct drawCellParams *p, REC
notify(t, tableNotificationFinishedWithCellData, p->row, p->column, (uintptr_t) bitmap);
}
+static void drawCheckboxCell(struct table *t, HDC dc, struct drawCellParams *p, RECT *r)
+{
+ POINT pt;
+ int cbState;
+
+ toCheckboxRect(t, r, p->xoff);
+ cbState = 0;
+ if (notify(t, tableNotificationGetCellData, p->row, p->column, 0) != 0)
+ cbState |= checkboxStateChecked;
+ if (t->checkboxMouseDown)
+ if (p->row == t->checkboxMouseDownRow && p->column == t->checkboxMouseDownColumn)
+ cbState |= checkboxStatePushed;
+ if (t->checkboxMouseOverLast) {
+ pt.x = GET_X_LPARAM(t->checkboxMouseOverLastPoint);
+ pt.y = GET_Y_LPARAM(t->checkboxMouseOverLastPoint);
+ if (PtInRect(r, pt) != 0)
+ cbState |= checkboxStateHot;
+ }
+ drawCheckbox(t, dc, r, cbState);
+}
+
static void drawCell(struct table *t, HDC dc, struct drawCellParams *p)
{
RECT r;
HBRUSH background;
int textColor;
- POINT pt;
- int cbState;
RECT cellrect;
// TODO verify these two
@@ -107,20 +126,7 @@ static void drawCell(struct table *t, HDC dc, struct drawCellParams *p)
drawImageCell(t, dc, p, &r);
break;
case tableColumnCheckbox:
- toCheckboxRect(t, &r, p->xoff);
- cbState = 0;
- if (p->row == lastCheckbox.row && p->column == lastCheckbox.column)
- cbState |= checkboxStateChecked;
- if (t->checkboxMouseDown)
- if (p->row == t->checkboxMouseDownRow && p->column == t->checkboxMouseDownColumn)
- cbState |= checkboxStatePushed;
- if (t->checkboxMouseOverLast) {
- pt.x = GET_X_LPARAM(t->checkboxMouseOverLastPoint);
- pt.y = GET_Y_LPARAM(t->checkboxMouseOverLastPoint);
- if (PtInRect(&r, pt) != 0)
- cbState |= checkboxStateHot;
- }
- drawCheckbox(t, dc, &r, cbState);
+ drawCheckboxCell(t, dc, p, &r);
break;
}
diff --git a/wintable/main.h b/wintable/main.h
index 50e8bff..d17f5d8 100644
--- a/wintable/main.h
+++ b/wintable/main.h
@@ -45,7 +45,7 @@ enum {
tableNotificationFinishedWithCellData,
// data is zero
// no return
- tableNotificationToggleCellCheckbox,
+ tableNotificationCellCheckboxToggled,
};
typedef struct tableNM tableNM;
diff --git a/wintable/test.c b/wintable/test.c
index f09d609..f58a92e 100644
--- a/wintable/test.c
+++ b/wintable/test.c
@@ -51,6 +51,8 @@ void mainwinResize(HWND hwnd, UINT state, int cx, int cy)
MoveWindow(tablehwnd, 0, 0, cx, cy, TRUE);
}
+BOOL checkboxstates[100];
+
LRESULT CALLBACK mainwndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
NMHDR *nmhdr = (NMHDR *) lParam;
@@ -58,6 +60,8 @@ LRESULT CALLBACK mainwndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
WCHAR *text;
int n;
+ if (uMsg == WM_CREATE)
+ ZeroMemory(checkboxstates, 100 * sizeof (BOOL));
switch (uMsg) {
HANDLE_MSG(hwnd, WM_CREATE, mainwinCreate);
HANDLE_MSG(hwnd, WM_SIZE, mainwinResize);
@@ -78,7 +82,7 @@ LRESULT CALLBACK mainwndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
case tableColumnImage:
return (LRESULT) mkbitmap();
case tableColumnCheckbox:
- ; // TODO
+ return (LRESULT) (checkboxstates[nm->row]);
}
panic("(test program) unreachable");
case tableNotificationFinishedWithCellData:
@@ -92,8 +96,9 @@ LRESULT CALLBACK mainwndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
break;
}
return 0;
- case tableNotificationToggleCellCheckbox:
- ; // TODO
+ case tableNotificationCellCheckboxToggled:
+ checkboxstates[nm->row] = !checkboxstates[nm->row];
+ return 0;
}
break;
}