- New implementation of SendMessage, ReceiveMessage, ReplyMessage functions
[wine] / dlls / comctl32 / pager.c
1 /*
2  * Pager control
3  *
4  * Copyright 1998 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 "commctrl.h"
17 #include "pager.h"
18 #include "win.h"
19 #include "debug.h"
20
21
22 #define PAGER_GetInfoPtr(wndPtr) ((PAGER_INFO *)wndPtr->wExtra[0])
23
24
25 static __inline__ LRESULT
26 PAGER_ForwardMouse (WND *wndPtr, WPARAM32 wParam)
27 {
28     PAGER_INFO *infoPtr = PAGER_GetInfoPtr(wndPtr);
29
30     infoPtr->bForward = (BOOL32)wParam;
31
32     return 0;
33 }
34
35
36 static __inline__ LRESULT
37 PAGER_GetBkColor (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
38 {
39     PAGER_INFO *infoPtr = PAGER_GetInfoPtr(wndPtr);
40
41     return (LRESULT)infoPtr->clrBk;
42 }
43
44
45 static __inline__ LRESULT
46 PAGER_GetBorder (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
47 {
48     PAGER_INFO *infoPtr = PAGER_GetInfoPtr(wndPtr);
49
50     return (LRESULT)infoPtr->nBorder;
51 }
52
53
54 static __inline__ LRESULT
55 PAGER_GetButtonSize (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
56 {
57     PAGER_INFO *infoPtr = PAGER_GetInfoPtr(wndPtr);
58
59     return (LRESULT)infoPtr->nButtonSize;
60 }
61
62
63 static LRESULT
64 PAGER_GetButtonState (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
65 {
66     /* PAGER_INFO *infoPtr = PAGER_GetInfoPtr(wndPtr); */
67
68     FIXME (pager, "empty stub!\n");
69
70     return PGF_INVISIBLE;
71 }
72
73
74 /* << PAGER_GetDropTarget >> */
75
76
77 static __inline__ LRESULT
78 PAGER_GetPos (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
79 {
80     PAGER_INFO *infoPtr = PAGER_GetInfoPtr(wndPtr);
81
82     return infoPtr->nPos;
83 }
84
85
86 static LRESULT
87 PAGER_RecalcSize (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
88 {
89     PAGER_INFO *infoPtr = PAGER_GetInfoPtr(wndPtr);
90     NMPGCALCSIZE nmpgcs;
91
92     if (infoPtr->hwndChild) {
93         ZeroMemory (&nmpgcs, sizeof (NMPGCALCSIZE));
94         nmpgcs.hdr.hwndFrom = wndPtr->hwndSelf;
95         nmpgcs.hdr.idFrom = wndPtr->wIDmenu;
96         nmpgcs.hdr.code = PGN_CALCSIZE;
97         nmpgcs.dwFlag =
98              (wndPtr->dwStyle & PGS_HORZ) ? PGF_CALCWIDTH : PGF_CALCHEIGHT;
99         SendMessage32A (GetParent32 (wndPtr->hwndSelf), WM_NOTIFY,
100                         (WPARAM32)wndPtr->wIDmenu, (LPARAM)&nmpgcs);
101
102         infoPtr->nChildSize =
103              (wndPtr->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 __inline__ LRESULT
116 PAGER_SetBkColor (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
117 {
118     PAGER_INFO *infoPtr = PAGER_GetInfoPtr(wndPtr);
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 __inline__ LRESULT
130 PAGER_SetBorder (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
131 {
132     PAGER_INFO *infoPtr = PAGER_GetInfoPtr(wndPtr);
133     INT32 nTemp = infoPtr->nBorder;
134
135     infoPtr->nBorder = (INT32)lParam;
136
137     /* FIXME: redraw */
138
139     return (LRESULT)nTemp;
140 }
141
142
143 static __inline__ LRESULT
144 PAGER_SetButtonSize (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
145 {
146     PAGER_INFO *infoPtr = PAGER_GetInfoPtr(wndPtr);
147     INT32 nTemp = infoPtr->nButtonSize;
148
149     infoPtr->nButtonSize = (INT32)lParam;
150
151     FIXME (pager, "size=%d\n", infoPtr->nButtonSize);
152
153     /* FIXME: redraw */
154
155     return (LRESULT)nTemp;
156 }
157
158
159 static __inline__ LRESULT
160 PAGER_SetChild (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
161 {
162     PAGER_INFO *infoPtr = PAGER_GetInfoPtr(wndPtr);
163
164     infoPtr->hwndChild = IsWindow32 ((HWND32)lParam) ? (HWND32)lParam : 0;
165
166     FIXME (pager, "hwnd=%x\n", infoPtr->hwndChild);
167
168     /* FIXME: redraw */
169     if (infoPtr->hwndChild) {
170         SetParent32 (infoPtr->hwndChild, wndPtr->hwndSelf);
171         SetWindowPos32 (infoPtr->hwndChild, HWND_TOP,
172                         0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE);
173     }
174
175     return 0;
176 }
177
178
179 static __inline__ LRESULT
180 PAGER_SetPos (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
181 {
182     PAGER_INFO *infoPtr = PAGER_GetInfoPtr(wndPtr);
183
184     infoPtr->nPos = (INT32)lParam;
185
186     FIXME (pager, "pos=%d\n", infoPtr->nPos);
187
188     /* FIXME: redraw */
189     SetWindowPos32 (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 (WND *wndPtr, WPARAM32 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     wndPtr->wExtra[0] = (DWORD)infoPtr;
204
205     if (infoPtr == NULL) {
206         ERR (pager, "could not allocate info memory!\n");
207         return 0;
208     }
209
210     if ((PAGER_INFO*)wndPtr->wExtra[0] != infoPtr) {
211         ERR (pager, "pointer assignment error!\n");
212         return 0;
213     }
214
215     /* set default settings */
216     infoPtr->hwndChild = (HWND32)NULL;
217     infoPtr->clrBk = GetSysColor32 (COLOR_BTNFACE);
218     infoPtr->nBorder = 0;
219     infoPtr->nButtonSize = 0;
220     infoPtr->nPos = 0;
221
222
223     return 0;
224 }
225
226
227 static LRESULT
228 PAGER_Destroy (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
229 {
230     PAGER_INFO *infoPtr = PAGER_GetInfoPtr(wndPtr);
231
232
233
234
235     /* free pager info data */
236     COMCTL32_Free (infoPtr);
237
238     return 0;
239 }
240
241
242 static LRESULT
243 PAGER_EraseBackground (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
244 {
245     PAGER_INFO *infoPtr = PAGER_GetInfoPtr(wndPtr);
246     HBRUSH32 hBrush = CreateSolidBrush32 (infoPtr->clrBk);
247     RECT32 rect;
248
249     GetClientRect32 (wndPtr->hwndSelf, &rect);
250     FillRect32 ((HDC32)wParam, &rect, hBrush);
251     DeleteObject32 (hBrush);
252
253 /*    return TRUE; */
254     return FALSE;
255 }
256
257
258 static LRESULT
259 PAGER_MouseMove (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
260 {
261     /* PAGER_INFO *infoPtr = PAGER_GetInfoPtr(wndPtr); */
262
263     TRACE (pager, "stub!\n");
264
265     return 0;
266 }
267
268
269 /* << PAGER_Paint >> */
270
271
272 static LRESULT
273 PAGER_Size (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
274 {
275     PAGER_INFO *infoPtr = PAGER_GetInfoPtr(wndPtr);
276     RECT32 rect;
277
278     GetClientRect32 (wndPtr->hwndSelf, &rect);
279     if (infoPtr->hwndChild) {
280         SetWindowPos32 (infoPtr->hwndChild, HWND_TOP, rect.left, rect.top,
281                         rect.right - rect.left, rect.bottom - rect.top,
282                         SWP_SHOWWINDOW);
283 /*      MoveWindow32 (infoPtr->hwndChild, 1, 1, rect.right - 2, rect.bottom-2, TRUE); */
284 /*      UpdateWindow32 (infoPtr->hwndChild); */
285
286     }
287 /*    FillRect32 ((HDC32)wParam, &rect, hBrush); */
288 /*    DeleteObject32 (hBrush); */
289     return TRUE;
290 }
291
292
293
294 LRESULT WINAPI
295 PAGER_WindowProc (HWND32 hwnd, UINT32 uMsg, WPARAM32 wParam, LPARAM lParam)
296 {
297     WND *wndPtr = WIN_FindWndPtr(hwnd);
298
299     switch (uMsg)
300     {
301         case PGM_FORWARDMOUSE:
302             return PAGER_ForwardMouse (wndPtr, wParam);
303
304         case PGM_GETBKCOLOR:
305             return PAGER_GetBkColor (wndPtr, wParam, lParam);
306
307         case PGM_GETBORDER:
308             return PAGER_GetBorder (wndPtr, wParam, lParam);
309
310         case PGM_GETBUTTONSIZE:
311             return PAGER_GetButtonSize (wndPtr, wParam, lParam);
312
313         case PGM_GETBUTTONSTATE:
314             return PAGER_GetButtonState (wndPtr, wParam, lParam);
315
316 /*      case PGM_GETDROPTARGET: */
317
318         case PGM_GETPOS:
319             return PAGER_SetPos (wndPtr, wParam, lParam);
320
321         case PGM_RECALCSIZE:
322             return PAGER_RecalcSize (wndPtr, wParam, lParam);
323
324         case PGM_SETBKCOLOR:
325             return PAGER_SetBkColor (wndPtr, wParam, lParam);
326
327         case PGM_SETBORDER:
328             return PAGER_SetBorder (wndPtr, wParam, lParam);
329
330         case PGM_SETBUTTONSIZE:
331             return PAGER_SetButtonSize (wndPtr, wParam, lParam);
332
333         case PGM_SETCHILD:
334             return PAGER_SetChild (wndPtr, wParam, lParam);
335
336         case PGM_SETPOS:
337             return PAGER_SetPos (wndPtr, wParam, lParam);
338
339         case WM_CREATE:
340             return PAGER_Create (wndPtr, wParam, lParam);
341
342         case WM_DESTROY:
343             return PAGER_Destroy (wndPtr, wParam, lParam);
344
345         case WM_ERASEBKGND:
346             return PAGER_EraseBackground (wndPtr, wParam, lParam);
347
348         case WM_MOUSEMOVE:
349             return PAGER_MouseMove (wndPtr, wParam, lParam);
350
351         case WM_NOTIFY:
352         case WM_COMMAND:
353             return SendMessage32A (wndPtr->parent->hwndSelf, uMsg, wParam, lParam);
354
355 /*      case WM_PAINT: */
356 /*          return PAGER_Paint (wndPtr, wParam); */
357
358         case WM_SIZE:
359             return PAGER_Size (wndPtr, wParam, lParam);
360
361         default:
362             if (uMsg >= WM_USER)
363                 ERR (pager, "unknown msg %04x wp=%08x lp=%08lx\n",
364                      uMsg, wParam, lParam);
365             return DefWindowProc32A (hwnd, uMsg, wParam, lParam);
366     }
367     return 0;
368 }
369
370
371 VOID
372 PAGER_Register (VOID)
373 {
374     WNDCLASS32A wndClass;
375
376     if (GlobalFindAtom32A (WC_PAGESCROLLER32A)) return;
377
378     ZeroMemory (&wndClass, sizeof(WNDCLASS32A));
379     wndClass.style         = CS_GLOBALCLASS | CS_DBLCLKS | CS_SAVEBITS;
380     wndClass.lpfnWndProc   = (WNDPROC32)PAGER_WindowProc;
381     wndClass.cbClsExtra    = 0;
382     wndClass.cbWndExtra    = sizeof(PAGER_INFO *);
383     wndClass.hCursor       = LoadCursor32A (0, IDC_ARROW32A);
384     wndClass.hbrBackground = 0;
385     wndClass.lpszClassName = WC_PAGESCROLLER32A;
386  
387     RegisterClass32A (&wndClass);
388 }
389
390
391 VOID
392 PAGER_Unregister (VOID)
393 {
394     if (GlobalFindAtom32A (WC_PAGESCROLLER32A))
395         UnregisterClass32A (WC_PAGESCROLLER32A, (HINSTANCE32)NULL);
396 }
397