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