Removed a few inter-dll dependencies.
[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         RECT rect;
172
173         GetClientRect (hwnd, &rect);
174         SetParent (infoPtr->hwndChild, hwnd);
175         SetWindowPos (infoPtr->hwndChild, HWND_TOP,
176                         0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE);
177
178         MoveWindow (infoPtr->hwndChild, 0, 0, rect.right, rect.bottom, TRUE);
179     }
180
181     return 0;
182 }
183
184
185 static inline LRESULT
186 PAGER_SetPos (HWND hwnd, WPARAM wParam, LPARAM lParam)
187 {
188     PAGER_INFO *infoPtr = PAGER_GetInfoPtr (hwnd);
189
190     infoPtr->nPos = (INT)lParam;
191
192     FIXME("pos=%d\n", infoPtr->nPos);
193
194     /* FIXME: redraw */
195     SetWindowPos (infoPtr->hwndChild, HWND_TOP,
196                     0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE);
197
198     return 0;
199 }
200
201
202 static LRESULT
203 PAGER_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
204 {
205     PAGER_INFO *infoPtr;
206
207     /* allocate memory for info structure */
208     infoPtr = (PAGER_INFO *)COMCTL32_Alloc (sizeof(PAGER_INFO));
209     SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
210
211     /* set default settings */
212     infoPtr->hwndChild = (HWND)NULL;
213     infoPtr->clrBk = GetSysColor (COLOR_BTNFACE);
214     infoPtr->nBorder = 0;
215     infoPtr->nButtonSize = 0;
216     infoPtr->nPos = 0;
217
218
219     return 0;
220 }
221
222
223 static LRESULT
224 PAGER_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
225 {
226     PAGER_INFO *infoPtr = PAGER_GetInfoPtr (hwnd);
227
228
229
230
231     /* free pager info data */
232     COMCTL32_Free (infoPtr);
233
234     return 0;
235 }
236
237
238 static LRESULT
239 PAGER_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
240 {
241     PAGER_INFO *infoPtr = PAGER_GetInfoPtr (hwnd);
242     HBRUSH hBrush = CreateSolidBrush (infoPtr->clrBk);
243     RECT rect;
244
245     GetClientRect (hwnd, &rect);
246     FillRect ((HDC)wParam, &rect, hBrush);
247     DeleteObject (hBrush);
248
249 /*    return TRUE; */
250     return FALSE;
251 }
252
253
254 static LRESULT
255 PAGER_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
256 {
257     /* PAGER_INFO *infoPtr = PAGER_GetInfoPtr (hwnd); */
258
259     TRACE("stub!\n");
260
261     return 0;
262 }
263
264
265 /* << PAGER_Paint >> */
266
267
268 static LRESULT
269 PAGER_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
270 {
271     PAGER_INFO *infoPtr = PAGER_GetInfoPtr (hwnd);
272     RECT rect;
273
274     GetClientRect (hwnd, &rect);
275     if (infoPtr->hwndChild) {
276         SetWindowPos (infoPtr->hwndChild, HWND_TOP, rect.left, rect.top,
277                         rect.right - rect.left, rect.bottom - rect.top,
278                         SWP_SHOWWINDOW);
279 /*      MoveWindow (infoPtr->hwndChild, 1, 1, rect.right - 2, rect.bottom-2, TRUE); */
280 /*      UpdateWindow (infoPtr->hwndChild); */
281
282     }
283 /*    FillRect ((HDC)wParam, &rect, hBrush); */
284 /*    DeleteObject (hBrush); */
285     return TRUE;
286 }
287
288
289
290 static LRESULT WINAPI
291 PAGER_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
292 {
293     switch (uMsg)
294     {
295         case PGM_FORWARDMOUSE:
296             return PAGER_ForwardMouse (hwnd, wParam);
297
298         case PGM_GETBKCOLOR:
299             return PAGER_GetBkColor (hwnd, wParam, lParam);
300
301         case PGM_GETBORDER:
302             return PAGER_GetBorder (hwnd, wParam, lParam);
303
304         case PGM_GETBUTTONSIZE:
305             return PAGER_GetButtonSize (hwnd, wParam, lParam);
306
307         case PGM_GETBUTTONSTATE:
308             return PAGER_GetButtonState (hwnd, wParam, lParam);
309
310 /*      case PGM_GETDROPTARGET: */
311
312         case PGM_GETPOS:
313             return PAGER_SetPos (hwnd, wParam, lParam);
314
315         case PGM_RECALCSIZE:
316             return PAGER_RecalcSize (hwnd, wParam, lParam);
317
318         case PGM_SETBKCOLOR:
319             return PAGER_SetBkColor (hwnd, wParam, lParam);
320
321         case PGM_SETBORDER:
322             return PAGER_SetBorder (hwnd, wParam, lParam);
323
324         case PGM_SETBUTTONSIZE:
325             return PAGER_SetButtonSize (hwnd, wParam, lParam);
326
327         case PGM_SETCHILD:
328             return PAGER_SetChild (hwnd, wParam, lParam);
329
330         case PGM_SETPOS:
331             return PAGER_SetPos (hwnd, wParam, lParam);
332
333         case WM_CREATE:
334             return PAGER_Create (hwnd, wParam, lParam);
335
336         case WM_DESTROY:
337             return PAGER_Destroy (hwnd, wParam, lParam);
338
339         case WM_ERASEBKGND:
340             return PAGER_EraseBackground (hwnd, wParam, lParam);
341
342         case WM_MOUSEMOVE:
343             return PAGER_MouseMove (hwnd, wParam, lParam);
344
345         case WM_NOTIFY:
346         case WM_COMMAND:
347             return SendMessageA (GetParent (hwnd), uMsg, wParam, lParam);
348
349 /*      case WM_PAINT: */
350 /*          return PAGER_Paint (hwnd, wParam); */
351
352         case WM_SIZE:
353             return PAGER_Size (hwnd, wParam, lParam);
354
355         default:
356             if (uMsg >= WM_USER)
357                 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
358                      uMsg, wParam, lParam);
359             return DefWindowProcA (hwnd, uMsg, wParam, lParam);
360     }
361     return 0;
362 }
363
364
365 VOID
366 PAGER_Register (void)
367 {
368     WNDCLASSA wndClass;
369
370     ZeroMemory (&wndClass, sizeof(WNDCLASSA));
371     wndClass.style         = CS_GLOBALCLASS | CS_DBLCLKS | CS_SAVEBITS;
372     wndClass.lpfnWndProc   = (WNDPROC)PAGER_WindowProc;
373     wndClass.cbClsExtra    = 0;
374     wndClass.cbWndExtra    = sizeof(PAGER_INFO *);
375     wndClass.hCursor       = LoadCursorA (0, IDC_ARROWA);
376     wndClass.hbrBackground = 0;
377     wndClass.lpszClassName = WC_PAGESCROLLERA;
378  
379     RegisterClassA (&wndClass);
380 }
381
382
383 VOID
384 PAGER_Unregister (void)
385 {
386     UnregisterClassA (WC_PAGESCROLLERA, (HINSTANCE)NULL);
387 }
388