1 | /* $Id: pager.cpp,v 1.2 2000-03-17 17:13:23 cbratschi 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 "ccbase.h"
|
---|
21 | #include "pager.h"
|
---|
22 |
|
---|
23 | #define PAGER_GetInfoPtr(hwnd) ((PAGER_INFO*)getInfoPtr(hwnd))
|
---|
24 |
|
---|
25 | static LRESULT
|
---|
26 | PAGER_ForwardMouse (HWND hwnd, WPARAM wParam)
|
---|
27 | {
|
---|
28 | PAGER_INFO *infoPtr = PAGER_GetInfoPtr (hwnd);
|
---|
29 |
|
---|
30 | infoPtr->bForward = (BOOL)wParam;
|
---|
31 |
|
---|
32 | return 0;
|
---|
33 | }
|
---|
34 |
|
---|
35 |
|
---|
36 | static LRESULT
|
---|
37 | PAGER_GetBkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
38 | {
|
---|
39 | PAGER_INFO *infoPtr = PAGER_GetInfoPtr (hwnd);
|
---|
40 |
|
---|
41 | return (LRESULT)infoPtr->clrBk;
|
---|
42 | }
|
---|
43 |
|
---|
44 |
|
---|
45 | static LRESULT
|
---|
46 | PAGER_GetBorder (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
47 | {
|
---|
48 | PAGER_INFO *infoPtr = PAGER_GetInfoPtr (hwnd);
|
---|
49 |
|
---|
50 | return (LRESULT)infoPtr->nBorder;
|
---|
51 | }
|
---|
52 |
|
---|
53 |
|
---|
54 | static LRESULT
|
---|
55 | PAGER_GetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
56 | {
|
---|
57 | PAGER_INFO *infoPtr = PAGER_GetInfoPtr (hwnd);
|
---|
58 |
|
---|
59 | return (LRESULT)infoPtr->nButtonSize;
|
---|
60 | }
|
---|
61 |
|
---|
62 |
|
---|
63 | static LRESULT
|
---|
64 | PAGER_GetButtonState (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
65 | {
|
---|
66 | /* PAGER_INFO *infoPtr = PAGER_GetInfoPtr (hwnd); */
|
---|
67 |
|
---|
68 | // FIXME (pager, "empty stub!\n");
|
---|
69 |
|
---|
70 | return PGF_INVISIBLE;
|
---|
71 | }
|
---|
72 |
|
---|
73 |
|
---|
74 | /* << PAGER_GetDropTarget >> */
|
---|
75 |
|
---|
76 |
|
---|
77 | static LRESULT
|
---|
78 | PAGER_GetPos (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
79 | {
|
---|
80 | PAGER_INFO *infoPtr = PAGER_GetInfoPtr (hwnd);
|
---|
81 |
|
---|
82 | return infoPtr->nPos;
|
---|
83 | }
|
---|
84 |
|
---|
85 |
|
---|
86 | static LRESULT
|
---|
87 | PAGER_RecalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
88 | {
|
---|
89 | PAGER_INFO *infoPtr = PAGER_GetInfoPtr (hwnd);
|
---|
90 | DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
|
---|
91 | NMPGCALCSIZE nmpgcs;
|
---|
92 |
|
---|
93 | if (infoPtr->hwndChild) {
|
---|
94 | ZeroMemory (&nmpgcs, sizeof (NMPGCALCSIZE));
|
---|
95 | nmpgcs.dwFlag = (dwStyle & PGS_HORZ) ? PGF_CALCWIDTH : PGF_CALCHEIGHT;
|
---|
96 | sendNotify(hwnd,PGN_CALCSIZE,&nmpgcs.hdr);
|
---|
97 |
|
---|
98 | infoPtr->nChildSize = (dwStyle & PGS_HORZ) ? nmpgcs.iWidth : nmpgcs.iHeight;
|
---|
99 |
|
---|
100 |
|
---|
101 | // FIXME (pager, "Child size %d\n", infoPtr->nChildSize);
|
---|
102 |
|
---|
103 |
|
---|
104 | }
|
---|
105 |
|
---|
106 | return 0;
|
---|
107 | }
|
---|
108 |
|
---|
109 |
|
---|
110 | static LRESULT
|
---|
111 | PAGER_SetBkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
112 | {
|
---|
113 | PAGER_INFO *infoPtr = PAGER_GetInfoPtr (hwnd);
|
---|
114 | COLORREF clrTemp = infoPtr->clrBk;
|
---|
115 |
|
---|
116 | infoPtr->clrBk = (COLORREF)lParam;
|
---|
117 |
|
---|
118 | /* FIXME: redraw */
|
---|
119 |
|
---|
120 | return (LRESULT)clrTemp;
|
---|
121 | }
|
---|
122 |
|
---|
123 |
|
---|
124 | static LRESULT
|
---|
125 | PAGER_SetBorder (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
126 | {
|
---|
127 | PAGER_INFO *infoPtr = PAGER_GetInfoPtr (hwnd);
|
---|
128 | INT nTemp = infoPtr->nBorder;
|
---|
129 |
|
---|
130 | infoPtr->nBorder = (INT)lParam;
|
---|
131 |
|
---|
132 | /* FIXME: redraw */
|
---|
133 |
|
---|
134 | return (LRESULT)nTemp;
|
---|
135 | }
|
---|
136 |
|
---|
137 |
|
---|
138 | static LRESULT
|
---|
139 | PAGER_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
140 | {
|
---|
141 | PAGER_INFO *infoPtr = PAGER_GetInfoPtr (hwnd);
|
---|
142 | INT nTemp = infoPtr->nButtonSize;
|
---|
143 |
|
---|
144 | infoPtr->nButtonSize = (INT)lParam;
|
---|
145 |
|
---|
146 | // FIXME (pager, "size=%d\n", infoPtr->nButtonSize);
|
---|
147 |
|
---|
148 | /* FIXME: redraw */
|
---|
149 |
|
---|
150 | return (LRESULT)nTemp;
|
---|
151 | }
|
---|
152 |
|
---|
153 |
|
---|
154 | static LRESULT
|
---|
155 | PAGER_SetChild (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
156 | {
|
---|
157 | PAGER_INFO *infoPtr = PAGER_GetInfoPtr (hwnd);
|
---|
158 |
|
---|
159 | infoPtr->hwndChild = IsWindow ((HWND)lParam) ? (HWND)lParam : 0;
|
---|
160 |
|
---|
161 | // FIXME (pager, "hwnd=%x\n", infoPtr->hwndChild);
|
---|
162 |
|
---|
163 | /* FIXME: redraw */
|
---|
164 | if (infoPtr->hwndChild) {
|
---|
165 | RECT rect;
|
---|
166 |
|
---|
167 | GetClientRect(hwnd,&rect);
|
---|
168 | SetParent (infoPtr->hwndChild, hwnd);
|
---|
169 | SetWindowPos (infoPtr->hwndChild, HWND_TOP,
|
---|
170 | 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE);
|
---|
171 |
|
---|
172 | MoveWindow (infoPtr->hwndChild, 0, 0, rect.right, rect.bottom, TRUE);
|
---|
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*)initControl(hwnd,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 | /* free pager info data */
|
---|
223 | doneControl(hwnd);
|
---|
224 |
|
---|
225 | return 0;
|
---|
226 | }
|
---|
227 |
|
---|
228 |
|
---|
229 | static LRESULT
|
---|
230 | PAGER_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
231 | {
|
---|
232 | PAGER_INFO *infoPtr = PAGER_GetInfoPtr (hwnd);
|
---|
233 | HBRUSH hBrush = CreateSolidBrush (infoPtr->clrBk);
|
---|
234 | RECT rect;
|
---|
235 |
|
---|
236 | GetClientRect (hwnd, &rect);
|
---|
237 | FillRect ((HDC)wParam, &rect, hBrush);
|
---|
238 | DeleteObject (hBrush);
|
---|
239 |
|
---|
240 | /* return TRUE; */
|
---|
241 | return FALSE;
|
---|
242 | }
|
---|
243 |
|
---|
244 |
|
---|
245 | static LRESULT
|
---|
246 | PAGER_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
247 | {
|
---|
248 | /* PAGER_INFO *infoPtr = PAGER_GetInfoPtr (hwnd); */
|
---|
249 |
|
---|
250 | // TRACE (pager, "stub!\n");
|
---|
251 |
|
---|
252 | return 0;
|
---|
253 | }
|
---|
254 |
|
---|
255 |
|
---|
256 | /* << PAGER_Paint >> */
|
---|
257 |
|
---|
258 |
|
---|
259 | static LRESULT
|
---|
260 | PAGER_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
261 | {
|
---|
262 | PAGER_INFO *infoPtr = PAGER_GetInfoPtr (hwnd);
|
---|
263 | RECT rect;
|
---|
264 |
|
---|
265 | GetClientRect (hwnd, &rect);
|
---|
266 | if (infoPtr->hwndChild) {
|
---|
267 | SetWindowPos (infoPtr->hwndChild, HWND_TOP, rect.left, rect.top,
|
---|
268 | rect.right - rect.left, rect.bottom - rect.top,
|
---|
269 | SWP_SHOWWINDOW);
|
---|
270 | /* MoveWindow (infoPtr->hwndChild, 1, 1, rect.right - 2, rect.bottom-2, TRUE); */
|
---|
271 | /* UpdateWindow (infoPtr->hwndChild); */
|
---|
272 |
|
---|
273 | }
|
---|
274 | /* FillRect ((HDC)wParam, &rect, hBrush); */
|
---|
275 | /* DeleteObject (hBrush); */
|
---|
276 | return TRUE;
|
---|
277 | }
|
---|
278 |
|
---|
279 |
|
---|
280 |
|
---|
281 | static LRESULT WINAPI
|
---|
282 | PAGER_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
---|
283 | {
|
---|
284 | switch (uMsg)
|
---|
285 | {
|
---|
286 | case PGM_FORWARDMOUSE:
|
---|
287 | return PAGER_ForwardMouse (hwnd, wParam);
|
---|
288 |
|
---|
289 | case PGM_GETBKCOLOR:
|
---|
290 | return PAGER_GetBkColor (hwnd, wParam, lParam);
|
---|
291 |
|
---|
292 | case PGM_GETBORDER:
|
---|
293 | return PAGER_GetBorder (hwnd, wParam, lParam);
|
---|
294 |
|
---|
295 | case PGM_GETBUTTONSIZE:
|
---|
296 | return PAGER_GetButtonSize (hwnd, wParam, lParam);
|
---|
297 |
|
---|
298 | case PGM_GETBUTTONSTATE:
|
---|
299 | return PAGER_GetButtonState (hwnd, wParam, lParam);
|
---|
300 |
|
---|
301 | /* case PGM_GETDROPTARGET: */
|
---|
302 |
|
---|
303 | case PGM_GETPOS:
|
---|
304 | return PAGER_SetPos (hwnd, wParam, lParam);
|
---|
305 |
|
---|
306 | case PGM_RECALCSIZE:
|
---|
307 | return PAGER_RecalcSize (hwnd, wParam, lParam);
|
---|
308 |
|
---|
309 | case PGM_SETBKCOLOR:
|
---|
310 | return PAGER_SetBkColor (hwnd, wParam, lParam);
|
---|
311 |
|
---|
312 | case PGM_SETBORDER:
|
---|
313 | return PAGER_SetBorder (hwnd, wParam, lParam);
|
---|
314 |
|
---|
315 | case PGM_SETBUTTONSIZE:
|
---|
316 | return PAGER_SetButtonSize (hwnd, wParam, lParam);
|
---|
317 |
|
---|
318 | case PGM_SETCHILD:
|
---|
319 | return PAGER_SetChild (hwnd, wParam, lParam);
|
---|
320 |
|
---|
321 | case PGM_SETPOS:
|
---|
322 | return PAGER_SetPos (hwnd, wParam, lParam);
|
---|
323 |
|
---|
324 | case WM_CREATE:
|
---|
325 | return PAGER_Create (hwnd, wParam, lParam);
|
---|
326 |
|
---|
327 | case WM_DESTROY:
|
---|
328 | return PAGER_Destroy (hwnd, wParam, lParam);
|
---|
329 |
|
---|
330 | case WM_ERASEBKGND:
|
---|
331 | return PAGER_EraseBackground (hwnd, wParam, lParam);
|
---|
332 |
|
---|
333 | case WM_MOUSEMOVE:
|
---|
334 | return PAGER_MouseMove (hwnd, wParam, lParam);
|
---|
335 |
|
---|
336 | case WM_NOTIFY:
|
---|
337 | case WM_COMMAND:
|
---|
338 | return SendMessageA (GetParent (hwnd), uMsg, wParam, lParam);
|
---|
339 |
|
---|
340 | /* case WM_PAINT: */
|
---|
341 | /* return PAGER_Paint (hwnd, wParam); */
|
---|
342 |
|
---|
343 | case WM_SIZE:
|
---|
344 | return PAGER_Size (hwnd, wParam, lParam);
|
---|
345 |
|
---|
346 | default:
|
---|
347 | // if (uMsg >= WM_USER)
|
---|
348 | // ERR (pager, "unknown msg %04x wp=%08x lp=%08lx\n",
|
---|
349 | // uMsg, wParam, lParam);
|
---|
350 | return defComCtl32ProcA (hwnd, uMsg, wParam, lParam);
|
---|
351 | }
|
---|
352 | return 0;
|
---|
353 | }
|
---|
354 |
|
---|
355 |
|
---|
356 | VOID
|
---|
357 | PAGER_Register (VOID)
|
---|
358 | {
|
---|
359 | WNDCLASSA wndClass;
|
---|
360 |
|
---|
361 | ZeroMemory (&wndClass, sizeof(WNDCLASSA));
|
---|
362 | wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_SAVEBITS;
|
---|
363 | wndClass.lpfnWndProc = (WNDPROC)PAGER_WindowProc;
|
---|
364 | wndClass.cbClsExtra = 0;
|
---|
365 | wndClass.cbWndExtra = sizeof(PAGER_INFO *);
|
---|
366 | wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
|
---|
367 | wndClass.hbrBackground = 0;
|
---|
368 | wndClass.lpszClassName = WC_PAGESCROLLERA;
|
---|
369 |
|
---|
370 | RegisterClassA (&wndClass);
|
---|
371 | }
|
---|
372 |
|
---|
373 |
|
---|
374 | VOID
|
---|
375 | PAGER_Unregister (VOID)
|
---|
376 | {
|
---|
377 | UnregisterClassA (WC_PAGESCROLLERA, (HINSTANCE)NULL);
|
---|
378 | }
|
---|
379 |
|
---|