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