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