| 1 | /* $Id: pager.cpp,v 1.3 2000-03-21 17:30:44 cbratschi 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 "ccbase.h"
|
|---|
| 21 | #include "pager.h"
|
|---|
| 22 |
|
|---|
| 23 | #define PAGER_GetInfoPtr(hwnd) ((PAGER_INFO*)getInfoPtr(hwnd))
|
|---|
| 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.dwFlag = (dwStyle & PGS_HORZ) ? PGF_CALCWIDTH : PGF_CALCHEIGHT;
|
|---|
| 96 | sendNotify(hwnd,PGN_CALCSIZE,&nmpgcs.hdr);
|
|---|
| 97 |
|
|---|
| 98 | infoPtr->nChildSize = (dwStyle & PGS_HORZ) ? nmpgcs.iWidth : nmpgcs.iHeight;
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 | // FIXME (pager, "Child size %d\n", infoPtr->nChildSize);
|
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | return 0;
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 | static LRESULT
|
|---|
| 111 | PAGER_SetBkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 112 | {
|
|---|
| 113 | PAGER_INFO *infoPtr = PAGER_GetInfoPtr (hwnd);
|
|---|
| 114 | COLORREF clrTemp = infoPtr->clrBk;
|
|---|
| 115 |
|
|---|
| 116 | infoPtr->clrBk = (COLORREF)lParam;
|
|---|
| 117 |
|
|---|
| 118 | /* FIXME: redraw */
|
|---|
| 119 |
|
|---|
| 120 | return (LRESULT)clrTemp;
|
|---|
| 121 | }
|
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 | static LRESULT
|
|---|
| 125 | PAGER_SetBorder (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 126 | {
|
|---|
| 127 | PAGER_INFO *infoPtr = PAGER_GetInfoPtr (hwnd);
|
|---|
| 128 | INT nTemp = infoPtr->nBorder;
|
|---|
| 129 |
|
|---|
| 130 | infoPtr->nBorder = (INT)lParam;
|
|---|
| 131 |
|
|---|
| 132 | /* FIXME: redraw */
|
|---|
| 133 |
|
|---|
| 134 | return (LRESULT)nTemp;
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 | static LRESULT
|
|---|
| 139 | PAGER_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 140 | {
|
|---|
| 141 | PAGER_INFO *infoPtr = PAGER_GetInfoPtr (hwnd);
|
|---|
| 142 | INT nTemp = infoPtr->nButtonSize;
|
|---|
| 143 |
|
|---|
| 144 | infoPtr->nButtonSize = (INT)lParam;
|
|---|
| 145 |
|
|---|
| 146 | // FIXME (pager, "size=%d\n", infoPtr->nButtonSize);
|
|---|
| 147 |
|
|---|
| 148 | /* FIXME: redraw */
|
|---|
| 149 |
|
|---|
| 150 | return (LRESULT)nTemp;
|
|---|
| 151 | }
|
|---|
| 152 |
|
|---|
| 153 |
|
|---|
| 154 | static LRESULT
|
|---|
| 155 | PAGER_SetChild (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 156 | {
|
|---|
| 157 | PAGER_INFO *infoPtr = PAGER_GetInfoPtr (hwnd);
|
|---|
| 158 |
|
|---|
| 159 | infoPtr->hwndChild = IsWindow ((HWND)lParam) ? (HWND)lParam : 0;
|
|---|
| 160 |
|
|---|
| 161 | // FIXME (pager, "hwnd=%x\n", infoPtr->hwndChild);
|
|---|
| 162 |
|
|---|
| 163 | /* FIXME: redraw */
|
|---|
| 164 | if (infoPtr->hwndChild) {
|
|---|
| 165 | RECT rect;
|
|---|
| 166 |
|
|---|
| 167 | GetClientRect(hwnd,&rect);
|
|---|
| 168 | SetParent (infoPtr->hwndChild, hwnd);
|
|---|
| 169 | SetWindowPos (infoPtr->hwndChild, HWND_TOP,
|
|---|
| 170 | 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE);
|
|---|
| 171 |
|
|---|
| 172 | MoveWindow (infoPtr->hwndChild, 0, 0, rect.right, rect.bottom, TRUE);
|
|---|
| 173 | }
|
|---|
| 174 |
|
|---|
| 175 | return 0;
|
|---|
| 176 | }
|
|---|
| 177 |
|
|---|
| 178 |
|
|---|
| 179 | static LRESULT
|
|---|
| 180 | PAGER_SetPos (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 181 | {
|
|---|
| 182 | PAGER_INFO *infoPtr = PAGER_GetInfoPtr (hwnd);
|
|---|
| 183 |
|
|---|
| 184 | infoPtr->nPos = (INT)lParam;
|
|---|
| 185 |
|
|---|
| 186 | // FIXME (pager, "pos=%d\n", infoPtr->nPos);
|
|---|
| 187 |
|
|---|
| 188 | /* FIXME: redraw */
|
|---|
| 189 | SetWindowPos (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 (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 198 | {
|
|---|
| 199 | PAGER_INFO *infoPtr;
|
|---|
| 200 |
|
|---|
| 201 | /* allocate memory for info structure */
|
|---|
| 202 | infoPtr = (PAGER_INFO*)initControl(hwnd,sizeof(PAGER_INFO));
|
|---|
| 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 | /* free pager info data */
|
|---|
| 222 | doneControl(hwnd);
|
|---|
| 223 |
|
|---|
| 224 | return 0;
|
|---|
| 225 | }
|
|---|
| 226 |
|
|---|
| 227 |
|
|---|
| 228 | static LRESULT
|
|---|
| 229 | PAGER_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 230 | {
|
|---|
| 231 | PAGER_INFO *infoPtr = PAGER_GetInfoPtr (hwnd);
|
|---|
| 232 | HBRUSH hBrush = CreateSolidBrush (infoPtr->clrBk);
|
|---|
| 233 | RECT rect;
|
|---|
| 234 |
|
|---|
| 235 | GetClientRect (hwnd, &rect);
|
|---|
| 236 | FillRect ((HDC)wParam, &rect, hBrush);
|
|---|
| 237 | DeleteObject (hBrush);
|
|---|
| 238 |
|
|---|
| 239 | /* return TRUE; */
|
|---|
| 240 | return FALSE;
|
|---|
| 241 | }
|
|---|
| 242 |
|
|---|
| 243 |
|
|---|
| 244 | static LRESULT
|
|---|
| 245 | PAGER_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 246 | {
|
|---|
| 247 | /* PAGER_INFO *infoPtr = PAGER_GetInfoPtr (hwnd); */
|
|---|
| 248 |
|
|---|
| 249 | // TRACE (pager, "stub!\n");
|
|---|
| 250 |
|
|---|
| 251 | return 0;
|
|---|
| 252 | }
|
|---|
| 253 |
|
|---|
| 254 |
|
|---|
| 255 | /* << PAGER_Paint >> */
|
|---|
| 256 |
|
|---|
| 257 |
|
|---|
| 258 | static LRESULT
|
|---|
| 259 | PAGER_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 260 | {
|
|---|
| 261 | PAGER_INFO *infoPtr = PAGER_GetInfoPtr (hwnd);
|
|---|
| 262 | RECT rect;
|
|---|
| 263 |
|
|---|
| 264 | GetClientRect (hwnd, &rect);
|
|---|
| 265 | if (infoPtr->hwndChild) {
|
|---|
| 266 | SetWindowPos (infoPtr->hwndChild, HWND_TOP, rect.left, rect.top,
|
|---|
| 267 | rect.right - rect.left, rect.bottom - rect.top,
|
|---|
| 268 | SWP_SHOWWINDOW);
|
|---|
| 269 | /* MoveWindow (infoPtr->hwndChild, 1, 1, rect.right - 2, rect.bottom-2, TRUE); */
|
|---|
| 270 | /* UpdateWindow (infoPtr->hwndChild); */
|
|---|
| 271 |
|
|---|
| 272 | }
|
|---|
| 273 | /* FillRect ((HDC)wParam, &rect, hBrush); */
|
|---|
| 274 | /* DeleteObject (hBrush); */
|
|---|
| 275 | return TRUE;
|
|---|
| 276 | }
|
|---|
| 277 |
|
|---|
| 278 | static VOID PAGER_Draw(HWND hwnd,HDC hdc,RECT *updateRect)
|
|---|
| 279 | {
|
|---|
| 280 | drawStubControl(hwnd,hdc);
|
|---|
| 281 | }
|
|---|
| 282 |
|
|---|
| 283 | static LRESULT PAGER_Paint(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 284 | {
|
|---|
| 285 | HDC hdc = (HDC)wParam;
|
|---|
| 286 |
|
|---|
| 287 | if (!hdc)
|
|---|
| 288 | {
|
|---|
| 289 | PAINTSTRUCT ps;
|
|---|
| 290 |
|
|---|
| 291 | hdc = BeginPaint(hwnd,&ps);
|
|---|
| 292 | PAGER_Draw(hwnd, hdc,&ps.rcPaint);
|
|---|
| 293 | EndPaint(hwnd,&ps);
|
|---|
| 294 | } else
|
|---|
| 295 | PAGER_Draw(hwnd,hdc,NULL);
|
|---|
| 296 |
|
|---|
| 297 | return 0;
|
|---|
| 298 | }
|
|---|
| 299 |
|
|---|
| 300 | static LRESULT WINAPI
|
|---|
| 301 | PAGER_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|---|
| 302 | {
|
|---|
| 303 | switch (uMsg)
|
|---|
| 304 | {
|
|---|
| 305 | case PGM_FORWARDMOUSE:
|
|---|
| 306 | return PAGER_ForwardMouse (hwnd, wParam);
|
|---|
| 307 |
|
|---|
| 308 | case PGM_GETBKCOLOR:
|
|---|
| 309 | return PAGER_GetBkColor (hwnd, wParam, lParam);
|
|---|
| 310 |
|
|---|
| 311 | case PGM_GETBORDER:
|
|---|
| 312 | return PAGER_GetBorder (hwnd, wParam, lParam);
|
|---|
| 313 |
|
|---|
| 314 | case PGM_GETBUTTONSIZE:
|
|---|
| 315 | return PAGER_GetButtonSize (hwnd, wParam, lParam);
|
|---|
| 316 |
|
|---|
| 317 | case PGM_GETBUTTONSTATE:
|
|---|
| 318 | return PAGER_GetButtonState (hwnd, wParam, lParam);
|
|---|
| 319 |
|
|---|
| 320 | /* case PGM_GETDROPTARGET: */
|
|---|
| 321 |
|
|---|
| 322 | case PGM_GETPOS:
|
|---|
| 323 | return PAGER_SetPos (hwnd, wParam, lParam);
|
|---|
| 324 |
|
|---|
| 325 | case PGM_RECALCSIZE:
|
|---|
| 326 | return PAGER_RecalcSize (hwnd, wParam, lParam);
|
|---|
| 327 |
|
|---|
| 328 | case PGM_SETBKCOLOR:
|
|---|
| 329 | return PAGER_SetBkColor (hwnd, wParam, lParam);
|
|---|
| 330 |
|
|---|
| 331 | case PGM_SETBORDER:
|
|---|
| 332 | return PAGER_SetBorder (hwnd, wParam, lParam);
|
|---|
| 333 |
|
|---|
| 334 | case PGM_SETBUTTONSIZE:
|
|---|
| 335 | return PAGER_SetButtonSize (hwnd, wParam, lParam);
|
|---|
| 336 |
|
|---|
| 337 | case PGM_SETCHILD:
|
|---|
| 338 | return PAGER_SetChild (hwnd, wParam, lParam);
|
|---|
| 339 |
|
|---|
| 340 | case PGM_SETPOS:
|
|---|
| 341 | return PAGER_SetPos (hwnd, wParam, lParam);
|
|---|
| 342 |
|
|---|
| 343 | case WM_CREATE:
|
|---|
| 344 | return PAGER_Create (hwnd, wParam, lParam);
|
|---|
| 345 |
|
|---|
| 346 | case WM_DESTROY:
|
|---|
| 347 | return PAGER_Destroy (hwnd, wParam, lParam);
|
|---|
| 348 |
|
|---|
| 349 | case WM_ERASEBKGND:
|
|---|
| 350 | return PAGER_EraseBackground (hwnd, wParam, lParam);
|
|---|
| 351 |
|
|---|
| 352 | case WM_MOUSEMOVE:
|
|---|
| 353 | return PAGER_MouseMove (hwnd, wParam, lParam);
|
|---|
| 354 |
|
|---|
| 355 | case WM_NOTIFY:
|
|---|
| 356 | case WM_COMMAND:
|
|---|
| 357 | return SendMessageA (GetParent (hwnd), uMsg, wParam, lParam);
|
|---|
| 358 |
|
|---|
| 359 | case WM_PAINT:
|
|---|
| 360 | return PAGER_Paint(hwnd,wParam,lParam);
|
|---|
| 361 |
|
|---|
| 362 | case WM_SIZE:
|
|---|
| 363 | return PAGER_Size (hwnd, wParam, lParam);
|
|---|
| 364 |
|
|---|
| 365 | default:
|
|---|
| 366 | //if (uMsg >= WM_USER)
|
|---|
| 367 | // ERR (pager, "unknown msg %04x wp=%08x lp=%08lx\n",
|
|---|
| 368 | // uMsg, wParam, lParam);
|
|---|
| 369 | return defComCtl32ProcA (hwnd, uMsg, wParam, lParam);
|
|---|
| 370 | }
|
|---|
| 371 | return 0;
|
|---|
| 372 | }
|
|---|
| 373 |
|
|---|
| 374 |
|
|---|
| 375 | VOID
|
|---|
| 376 | PAGER_Register (VOID)
|
|---|
| 377 | {
|
|---|
| 378 | WNDCLASSA wndClass;
|
|---|
| 379 |
|
|---|
| 380 | ZeroMemory (&wndClass, sizeof(WNDCLASSA));
|
|---|
| 381 | wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_SAVEBITS;
|
|---|
| 382 | wndClass.lpfnWndProc = (WNDPROC)PAGER_WindowProc;
|
|---|
| 383 | wndClass.cbClsExtra = 0;
|
|---|
| 384 | wndClass.cbWndExtra = sizeof(PAGER_INFO *);
|
|---|
| 385 | wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
|
|---|
| 386 | wndClass.hbrBackground = 0;
|
|---|
| 387 | wndClass.lpszClassName = WC_PAGESCROLLERA;
|
|---|
| 388 |
|
|---|
| 389 | RegisterClassA (&wndClass);
|
|---|
| 390 | }
|
|---|
| 391 |
|
|---|
| 392 |
|
|---|
| 393 | VOID
|
|---|
| 394 | PAGER_Unregister (VOID)
|
|---|
| 395 | {
|
|---|
| 396 | UnregisterClassA (WC_PAGESCROLLERA, (HINSTANCE)NULL);
|
|---|
| 397 | }
|
|---|
| 398 |
|
|---|