1 | /*
|
---|
2 | * Pager control
|
---|
3 | *
|
---|
4 | * Copyright 1998, 1999 Eric Kohl
|
---|
5 | *
|
---|
6 | * NOTES
|
---|
7 | * This is just a dummy control. An author is needed! Any volunteers?
|
---|
8 | * I will only improve this control once in a while.
|
---|
9 | * Eric <ekohl@abo.rhein-zeitung.de>
|
---|
10 | *
|
---|
11 | * TODO:
|
---|
12 | * - All messages.
|
---|
13 | * - All notifications.
|
---|
14 | */
|
---|
15 |
|
---|
16 | #include "winbase.h"
|
---|
17 | #include "commctrl.h"
|
---|
18 | #include "pager.h"
|
---|
19 |
|
---|
20 |
|
---|
21 | #define PAGER_GetInfoPtr(hwnd) ((PAGER_INFO *)GetWindowLongA(hwnd, 0))
|
---|
22 |
|
---|
23 |
|
---|
24 | static LRESULT
|
---|
25 | PAGER_ForwardMouse (HWND hwnd, WPARAM wParam)
|
---|
26 | {
|
---|
27 | PAGER_INFO *infoPtr = PAGER_GetInfoPtr (hwnd);
|
---|
28 |
|
---|
29 | infoPtr->bForward = (BOOL)wParam;
|
---|
30 |
|
---|
31 | return 0;
|
---|
32 | }
|
---|
33 |
|
---|
34 |
|
---|
35 | static LRESULT
|
---|
36 | PAGER_GetBkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
37 | {
|
---|
38 | PAGER_INFO *infoPtr = PAGER_GetInfoPtr (hwnd);
|
---|
39 |
|
---|
40 | return (LRESULT)infoPtr->clrBk;
|
---|
41 | }
|
---|
42 |
|
---|
43 |
|
---|
44 | static LRESULT
|
---|
45 | PAGER_GetBorder (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
46 | {
|
---|
47 | PAGER_INFO *infoPtr = PAGER_GetInfoPtr (hwnd);
|
---|
48 |
|
---|
49 | return (LRESULT)infoPtr->nBorder;
|
---|
50 | }
|
---|
51 |
|
---|
52 |
|
---|
53 | static LRESULT
|
---|
54 | PAGER_GetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
55 | {
|
---|
56 | PAGER_INFO *infoPtr = PAGER_GetInfoPtr (hwnd);
|
---|
57 |
|
---|
58 | return (LRESULT)infoPtr->nButtonSize;
|
---|
59 | }
|
---|
60 |
|
---|
61 |
|
---|
62 | static LRESULT
|
---|
63 | PAGER_GetButtonState (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
64 | {
|
---|
65 | /* PAGER_INFO *infoPtr = PAGER_GetInfoPtr (hwnd); */
|
---|
66 |
|
---|
67 | // FIXME (pager, "empty stub!\n");
|
---|
68 |
|
---|
69 | return PGF_INVISIBLE;
|
---|
70 | }
|
---|
71 |
|
---|
72 |
|
---|
73 | /* << PAGER_GetDropTarget >> */
|
---|
74 |
|
---|
75 |
|
---|
76 | static LRESULT
|
---|
77 | PAGER_GetPos (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
78 | {
|
---|
79 | PAGER_INFO *infoPtr = PAGER_GetInfoPtr (hwnd);
|
---|
80 |
|
---|
81 | return infoPtr->nPos;
|
---|
82 | }
|
---|
83 |
|
---|
84 |
|
---|
85 | static LRESULT
|
---|
86 | PAGER_RecalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
87 | {
|
---|
88 | PAGER_INFO *infoPtr = PAGER_GetInfoPtr (hwnd);
|
---|
89 | DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
|
---|
90 | NMPGCALCSIZE nmpgcs;
|
---|
91 |
|
---|
92 | if (infoPtr->hwndChild) {
|
---|
93 | ZeroMemory (&nmpgcs, sizeof (NMPGCALCSIZE));
|
---|
94 | nmpgcs.hdr.hwndFrom = hwnd;
|
---|
95 | nmpgcs.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
|
---|
96 | nmpgcs.hdr.code = PGN_CALCSIZE;
|
---|
97 | nmpgcs.dwFlag = (dwStyle & PGS_HORZ) ? PGF_CALCWIDTH : PGF_CALCHEIGHT;
|
---|
98 | SendMessageA (GetParent (hwnd), WM_NOTIFY,
|
---|
99 | (WPARAM)nmpgcs.hdr.idFrom, (LPARAM)&nmpgcs);
|
---|
100 |
|
---|
101 | infoPtr->nChildSize = (dwStyle & PGS_HORZ) ? nmpgcs.iWidth : nmpgcs.iHeight;
|
---|
102 |
|
---|
103 |
|
---|
104 | // FIXME (pager, "Child size %d\n", infoPtr->nChildSize);
|
---|
105 |
|
---|
106 |
|
---|
107 | }
|
---|
108 |
|
---|
109 | return 0;
|
---|
110 | }
|
---|
111 |
|
---|
112 |
|
---|
113 | static LRESULT
|
---|
114 | PAGER_SetBkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
115 | {
|
---|
116 | PAGER_INFO *infoPtr = PAGER_GetInfoPtr (hwnd);
|
---|
117 | COLORREF clrTemp = infoPtr->clrBk;
|
---|
118 |
|
---|
119 | infoPtr->clrBk = (COLORREF)lParam;
|
---|
120 |
|
---|
121 | /* FIXME: redraw */
|
---|
122 |
|
---|
123 | return (LRESULT)clrTemp;
|
---|
124 | }
|
---|
125 |
|
---|
126 |
|
---|
127 | static LRESULT
|
---|
128 | PAGER_SetBorder (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
129 | {
|
---|
130 | PAGER_INFO *infoPtr = PAGER_GetInfoPtr (hwnd);
|
---|
131 | INT nTemp = infoPtr->nBorder;
|
---|
132 |
|
---|
133 | infoPtr->nBorder = (INT)lParam;
|
---|
134 |
|
---|
135 | /* FIXME: redraw */
|
---|
136 |
|
---|
137 | return (LRESULT)nTemp;
|
---|
138 | }
|
---|
139 |
|
---|
140 |
|
---|
141 | static LRESULT
|
---|
142 | PAGER_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
143 | {
|
---|
144 | PAGER_INFO *infoPtr = PAGER_GetInfoPtr (hwnd);
|
---|
145 | INT nTemp = infoPtr->nButtonSize;
|
---|
146 |
|
---|
147 | infoPtr->nButtonSize = (INT)lParam;
|
---|
148 |
|
---|
149 | // FIXME (pager, "size=%d\n", infoPtr->nButtonSize);
|
---|
150 |
|
---|
151 | /* FIXME: redraw */
|
---|
152 |
|
---|
153 | return (LRESULT)nTemp;
|
---|
154 | }
|
---|
155 |
|
---|
156 |
|
---|
157 | static LRESULT
|
---|
158 | PAGER_SetChild (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
159 | {
|
---|
160 | PAGER_INFO *infoPtr = PAGER_GetInfoPtr (hwnd);
|
---|
161 |
|
---|
162 | infoPtr->hwndChild = IsWindow ((HWND)lParam) ? (HWND)lParam : 0;
|
---|
163 |
|
---|
164 | // FIXME (pager, "hwnd=%x\n", infoPtr->hwndChild);
|
---|
165 |
|
---|
166 | /* FIXME: redraw */
|
---|
167 | if (infoPtr->hwndChild) {
|
---|
168 | SetParent (infoPtr->hwndChild, hwnd);
|
---|
169 | SetWindowPos (infoPtr->hwndChild, HWND_TOP,
|
---|
170 | 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE);
|
---|
171 | }
|
---|
172 |
|
---|
173 | return 0;
|
---|
174 | }
|
---|
175 |
|
---|
176 |
|
---|
177 | static LRESULT
|
---|
178 | PAGER_SetPos (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
179 | {
|
---|
180 | PAGER_INFO *infoPtr = PAGER_GetInfoPtr (hwnd);
|
---|
181 |
|
---|
182 | infoPtr->nPos = (INT)lParam;
|
---|
183 |
|
---|
184 | // FIXME (pager, "pos=%d\n", infoPtr->nPos);
|
---|
185 |
|
---|
186 | /* FIXME: redraw */
|
---|
187 | SetWindowPos (infoPtr->hwndChild, HWND_TOP,
|
---|
188 | 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE);
|
---|
189 |
|
---|
190 | return 0;
|
---|
191 | }
|
---|
192 |
|
---|
193 |
|
---|
194 | static LRESULT
|
---|
195 | PAGER_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
196 | {
|
---|
197 | PAGER_INFO *infoPtr;
|
---|
198 |
|
---|
199 | /* allocate memory for info structure */
|
---|
200 | infoPtr = (PAGER_INFO *)COMCTL32_Alloc (sizeof(PAGER_INFO));
|
---|
201 | SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
|
---|
202 |
|
---|
203 | /* set default settings */
|
---|
204 | infoPtr->hwndChild = (HWND)NULL;
|
---|
205 | infoPtr->clrBk = GetSysColor (COLOR_BTNFACE);
|
---|
206 | infoPtr->nBorder = 0;
|
---|
207 | infoPtr->nButtonSize = 0;
|
---|
208 | infoPtr->nPos = 0;
|
---|
209 |
|
---|
210 |
|
---|
211 | return 0;
|
---|
212 | }
|
---|
213 |
|
---|
214 |
|
---|
215 | static LRESULT
|
---|
216 | PAGER_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
217 | {
|
---|
218 | PAGER_INFO *infoPtr = PAGER_GetInfoPtr (hwnd);
|
---|
219 |
|
---|
220 |
|
---|
221 |
|
---|
222 |
|
---|
223 | /* free pager info data */
|
---|
224 | COMCTL32_Free (infoPtr);
|
---|
225 |
|
---|
226 | return 0;
|
---|
227 | }
|
---|
228 |
|
---|
229 |
|
---|
230 | static LRESULT
|
---|
231 | PAGER_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
232 | {
|
---|
233 | PAGER_INFO *infoPtr = PAGER_GetInfoPtr (hwnd);
|
---|
234 | HBRUSH hBrush = CreateSolidBrush (infoPtr->clrBk);
|
---|
235 | RECT rect;
|
---|
236 |
|
---|
237 | GetClientRect (hwnd, &rect);
|
---|
238 | FillRect ((HDC)wParam, &rect, hBrush);
|
---|
239 | DeleteObject (hBrush);
|
---|
240 |
|
---|
241 | /* return TRUE; */
|
---|
242 | return FALSE;
|
---|
243 | }
|
---|
244 |
|
---|
245 |
|
---|
246 | static LRESULT
|
---|
247 | PAGER_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
248 | {
|
---|
249 | /* PAGER_INFO *infoPtr = PAGER_GetInfoPtr (hwnd); */
|
---|
250 |
|
---|
251 | // TRACE (pager, "stub!\n");
|
---|
252 |
|
---|
253 | return 0;
|
---|
254 | }
|
---|
255 |
|
---|
256 |
|
---|
257 | /* << PAGER_Paint >> */
|
---|
258 |
|
---|
259 |
|
---|
260 | static LRESULT
|
---|
261 | PAGER_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
262 | {
|
---|
263 | PAGER_INFO *infoPtr = PAGER_GetInfoPtr (hwnd);
|
---|
264 | RECT rect;
|
---|
265 |
|
---|
266 | GetClientRect (hwnd, &rect);
|
---|
267 | if (infoPtr->hwndChild) {
|
---|
268 | SetWindowPos (infoPtr->hwndChild, HWND_TOP, rect.left, rect.top,
|
---|
269 | rect.right - rect.left, rect.bottom - rect.top,
|
---|
270 | SWP_SHOWWINDOW);
|
---|
271 | /* MoveWindow32 (infoPtr->hwndChild, 1, 1, rect.right - 2, rect.bottom-2, TRUE); */
|
---|
272 | /* UpdateWindow32 (infoPtr->hwndChild); */
|
---|
273 |
|
---|
274 | }
|
---|
275 | /* FillRect32 ((HDC32)wParam, &rect, hBrush); */
|
---|
276 | /* DeleteObject32 (hBrush); */
|
---|
277 | return TRUE;
|
---|
278 | }
|
---|
279 |
|
---|
280 |
|
---|
281 |
|
---|
282 | LRESULT WINAPI
|
---|
283 | PAGER_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
---|
284 | {
|
---|
285 | switch (uMsg)
|
---|
286 | {
|
---|
287 | case PGM_FORWARDMOUSE:
|
---|
288 | return PAGER_ForwardMouse (hwnd, wParam);
|
---|
289 |
|
---|
290 | case PGM_GETBKCOLOR:
|
---|
291 | return PAGER_GetBkColor (hwnd, wParam, lParam);
|
---|
292 |
|
---|
293 | case PGM_GETBORDER:
|
---|
294 | return PAGER_GetBorder (hwnd, wParam, lParam);
|
---|
295 |
|
---|
296 | case PGM_GETBUTTONSIZE:
|
---|
297 | return PAGER_GetButtonSize (hwnd, wParam, lParam);
|
---|
298 |
|
---|
299 | case PGM_GETBUTTONSTATE:
|
---|
300 | return PAGER_GetButtonState (hwnd, wParam, lParam);
|
---|
301 |
|
---|
302 | /* case PGM_GETDROPTARGET: */
|
---|
303 |
|
---|
304 | case PGM_GETPOS:
|
---|
305 | return PAGER_SetPos (hwnd, wParam, lParam);
|
---|
306 |
|
---|
307 | case PGM_RECALCSIZE:
|
---|
308 | return PAGER_RecalcSize (hwnd, wParam, lParam);
|
---|
309 |
|
---|
310 | case PGM_SETBKCOLOR:
|
---|
311 | return PAGER_SetBkColor (hwnd, wParam, lParam);
|
---|
312 |
|
---|
313 | case PGM_SETBORDER:
|
---|
314 | return PAGER_SetBorder (hwnd, wParam, lParam);
|
---|
315 |
|
---|
316 | case PGM_SETBUTTONSIZE:
|
---|
317 | return PAGER_SetButtonSize (hwnd, wParam, lParam);
|
---|
318 |
|
---|
319 | case PGM_SETCHILD:
|
---|
320 | return PAGER_SetChild (hwnd, wParam, lParam);
|
---|
321 |
|
---|
322 | case PGM_SETPOS:
|
---|
323 | return PAGER_SetPos (hwnd, wParam, lParam);
|
---|
324 |
|
---|
325 | case WM_CREATE:
|
---|
326 | return PAGER_Create (hwnd, wParam, lParam);
|
---|
327 |
|
---|
328 | case WM_DESTROY:
|
---|
329 | return PAGER_Destroy (hwnd, wParam, lParam);
|
---|
330 |
|
---|
331 | case WM_ERASEBKGND:
|
---|
332 | return PAGER_EraseBackground (hwnd, wParam, lParam);
|
---|
333 |
|
---|
334 | case WM_MOUSEMOVE:
|
---|
335 | return PAGER_MouseMove (hwnd, wParam, lParam);
|
---|
336 |
|
---|
337 | case WM_NOTIFY:
|
---|
338 | case WM_COMMAND:
|
---|
339 | return SendMessageA (GetParent (hwnd), uMsg, wParam, lParam);
|
---|
340 |
|
---|
341 | /* case WM_PAINT: */
|
---|
342 | /* return PAGER_Paint (hwnd, wParam); */
|
---|
343 |
|
---|
344 | case WM_SIZE:
|
---|
345 | return PAGER_Size (hwnd, wParam, lParam);
|
---|
346 |
|
---|
347 | default:
|
---|
348 | // if (uMsg >= WM_USER)
|
---|
349 | // ERR (pager, "unknown msg %04x wp=%08x lp=%08lx\n",
|
---|
350 | // uMsg, wParam, lParam);
|
---|
351 | return DefWindowProcA (hwnd, uMsg, wParam, lParam);
|
---|
352 | }
|
---|
353 | return 0;
|
---|
354 | }
|
---|
355 |
|
---|
356 |
|
---|
357 | VOID
|
---|
358 | PAGER_Register (VOID)
|
---|
359 | {
|
---|
360 | WNDCLASSA wndClass;
|
---|
361 |
|
---|
362 | if (GlobalFindAtomA (WC_PAGESCROLLERA)) return;
|
---|
363 |
|
---|
364 | ZeroMemory (&wndClass, sizeof(WNDCLASSA));
|
---|
365 | wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_SAVEBITS;
|
---|
366 | wndClass.lpfnWndProc = (WNDPROC)PAGER_WindowProc;
|
---|
367 | wndClass.cbClsExtra = 0;
|
---|
368 | wndClass.cbWndExtra = sizeof(PAGER_INFO *);
|
---|
369 | wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
|
---|
370 | wndClass.hbrBackground = 0;
|
---|
371 | wndClass.lpszClassName = WC_PAGESCROLLERA;
|
---|
372 |
|
---|
373 | RegisterClassA (&wndClass);
|
---|
374 | }
|
---|
375 |
|
---|
376 |
|
---|
377 | VOID
|
---|
378 | PAGER_Unregister (VOID)
|
---|
379 | {
|
---|
380 | if (GlobalFindAtomA (WC_PAGESCROLLERA))
|
---|
381 | UnregisterClassA (WC_PAGESCROLLERA, (HINSTANCE)NULL);
|
---|
382 | }
|
---|
383 |
|
---|