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