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