-
Notifications
You must be signed in to change notification settings - Fork 0
/
events.c
162 lines (138 loc) · 4.21 KB
/
events.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// 5 december 2014
#include "tablepriv.h"
// general handlers for mouse events
// these run before the other mouse events, which use their results
// they also handle mouse tracking
// we DON'T go from LPARAM to row/column here because scrolling will change that
// or should we? it'd make some calculations later easier, and we're not going to update the hover state when scrolling anyway (real list view doesn't) TODO
// TODO rename to generalXxx everywhere
static EVENTHANDLER(globalMouseMoveHandler)
{
HRESULT hr;
t->lastMouseMoved = t->mouseMoved;
t->lastMouseMoveLPARAM = t->mouseMoveLPARAM;
t->mouseMoved = TRUE;
t->mouseMoveLPARAM = lParam;
// when we capture the mouse, _TrackMouseEvent() won't work
// (see http://blogs.msdn.com/b/oldnewthing/archive/2010/12/06/10100644.aspx)
// for this case, we have to do the check ourselves
if (lParamInRect(&(m->client), t->mouseMoveLPARAM) == 0)
t->mouseMoved = FALSE;
if (!t->lastMouseMoved) {
TRACKMOUSEEVENT tm;
ZeroMemory(&tm, sizeof (TRACKMOUSEEVENT));
tm.cbSize = sizeof (TRACKMOUSEEVENT);
tm.dwFlags = TME_LEAVE;
tm.hwndTrack = t->hwnd;
if (_TrackMouseEvent(&tm) == 0)
; // TODO
} else {
// redraw the old cell unconditionally
hr = redrawCellAtLPARAM(t, m, t->lastMouseMoveLPARAM);
if (hr != S_OK)
; // TODO
}
// redraw the new cell unconditionally
// TODO optimize the redrawing somehow?
hr = redrawCellAtLPARAM(t, m, t->mouseMoveLPARAM);
if (hr != S_OK)
; // TODO
// TODO really?
return TRUE;
}
static EVENTHANDLER(globalMouseLeaveHandler)
{
t->lastMouseMoved = t->mouseMoved;
t->lastMouseMoveLPARAM = t->mouseMoveLPARAM;
t->mouseMoved = FALSE;
// TODO really?
return TRUE;
}
// and a helper function to go with it
BOOL mouseHovering(struct table *t)
{
// change in movement state counts as not hovering
if (t->lastMouseMoved && !t->mouseMoved)
return FALSE;
if (!t->lastMouseMoved && t->mouseMoved)
return FALSE;
// if we're still not in, we're hovering
// TODO really?
if (!t->lastMouseMoved && !t->mouseMoved)
return TRUE;
// otherwise, make sure we didn't actually move
// TODO use the double-click rect?
return t->lastMouseMoveLPARAM == t->mouseMoveLPARAM;
}
// TODO make these function names consistent
static const eventhandlerfunc keyDownHandlers[] = {
keyDownSelectHandler,
NULL,
};
static const eventhandlerfunc keyUpHandlers[] = {
NULL,
};
static const eventhandlerfunc charHandlers[] = {
NULL,
};
static const eventhandlerfunc mouseMoveHandlers[] = {
globalMouseMoveHandler,
tooltipMouseMoveHandler,
NULL,
};
static const eventhandlerfunc mouseLeaveHandlers[] = {
globalMouseLeaveHandler,
tooltipMouseLeaveHandler,
NULL,
};
static const eventhandlerfunc lbuttonDownHandlers[] = {
mouseDownFocusHandler,
mouseDownSelectHandler,
checkboxMouseDownHandler,
NULL,
};
static const eventhandlerfunc lbuttonUpHandlers[] = {
checkboxMouseUpHandler,
NULL,
};
static const eventhandlerfunc captureChangedHandlers[] = {
checkboxCaptureChangedHandler,
NULL,
};
static const eventhandlerfunc timerHandlers[] = {
tooltipTimerHandler,
NULL,
};
// TODO remove or something? depends on if we implement combobox and how
static const eventhandlerfunc mouseWheelHandlers[] = {
NULL,
};
// TODO WM_MOUSEHOVER, other mouse buttons
// TODO what to do if metrics() fails?
HANDLER(eventHandlers)
{
struct metrics m;
HRESULT hr;
// note that the metrics computing is in each case statement, not here
// this is just in case the message isn't an event message, since we can't send the metrics back out
switch (uMsg) {
#define eventHandler(msg, array, returnWhat) \
case msg: \
hr = metrics(t, &m); \
if (hr != S_OK) \
return FALSE; \
return runEventHandlers(array, t, &m, uMsg, wParam, lParam, lResult, returnWhat);
eventHandler(WM_KEYDOWN, keyDownHandlers, 0)
eventHandler(WM_KEYUP, keyUpHandlers, 0)
eventHandler(WM_CHAR, charHandlers, 0)
eventHandler(WM_MOUSEMOVE, mouseMoveHandlers, 0)
eventHandler(WM_MOUSELEAVE, mouseLeaveHandlers, 0)
eventHandler(WM_LBUTTONDOWN, lbuttonDownHandlers, 0)
eventHandler(WM_LBUTTONUP, lbuttonUpHandlers, 0)
eventHandler(WM_CAPTURECHANGED, captureChangedHandlers, 0)
eventHandler(WM_MOUSEWHEEL, mouseWheelHandlers, 0)
eventHandler(WM_TIMER, timerHandlers, 0)
#undef eventHandler
}
return FALSE;
}