Sorted some of the structs and made them consistent.
[wine/multimedia.git] / dlls / comctl32 / pager.c
blob7328f6ebb5ac0170198bde137c13e7bb59c9c0f4
1 /*
2 * Pager control
4 * Copyright 1998, 1999 Eric Kohl
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * NOTES
22 * This code was audited for completeness against the documented features
23 * of Comctl32.dll version 6.0 on Sep. 18, 2004, by Robert Shearman.
25 * Unless otherwise noted, we believe this code to be complete, as per
26 * the specification mentioned above.
27 * If you discover missing features or bugs please note them below.
29 * TODO:
30 * Implement repetitive button press.
31 * Adjust arrow size relative to size of button.
32 * Allow border size changes.
33 * Styles:
34 * PGS_DRAGNDROP
35 * Notifications:
36 * PGN_HOTITEMCHANGE
38 * TESTING:
39 * Tested primarily with the controlspy Pager application.
40 * Susan Farley (susan@codeweavers.com)
42 * IMPLEMENTATION NOTES:
43 * This control uses WM_NCPAINT instead of WM_PAINT to paint itself
44 * as we need to scroll a child window. In order to do this we move
45 * the child window in the control's client area, using the clipping
46 * region that is automatically set around the client area. As the
47 * entire client area now consists of the child window, we must
48 * allocate space (WM_NCCALCSIZE) for the buttons and draw them as
49 * a non-client area (WM_NCPAINT).
50 * Robert Shearman <rob@codeweavers.com>
53 #include <stdarg.h>
54 #include <string.h>
55 #include "windef.h"
56 #include "winbase.h"
57 #include "wingdi.h"
58 #include "winuser.h"
59 #include "winnls.h"
60 #include "windowsx.h"
61 #include "commctrl.h"
62 #include "comctl32.h"
63 #include "wine/debug.h"
65 WINE_DEFAULT_DEBUG_CHANNEL(pager);
67 typedef struct
69 HWND hwndSelf; /* handle of the control wnd */
70 HWND hwndChild; /* handle of the contained wnd */
71 HWND hwndNotify; /* handle of the parent wnd */
72 DWORD dwStyle; /* styles for this control */
73 COLORREF clrBk; /* background color */
74 INT nBorder; /* border size for the control */
75 INT nButtonSize;/* size of the pager btns */
76 INT nPos; /* scroll position */
77 INT nWidth; /* from child wnd's response to PGN_CALCSIZE */
78 INT nHeight; /* from child wnd's response to PGN_CALCSIZE */
79 BOOL bForward; /* forward WM_MOUSEMOVE msgs to the contained wnd */
80 BOOL bCapture; /* we have captured the mouse */
81 INT TLbtnState; /* state of top or left btn */
82 INT BRbtnState; /* state of bottom or right btn */
83 INT direction; /* direction of the scroll, (e.g. PGF_SCROLLUP) */
84 } PAGER_INFO;
86 #define MIN_ARROW_WIDTH 8
87 #define MIN_ARROW_HEIGHT 5
89 #define TIMERID1 1
90 #define TIMERID2 2
91 #define INITIAL_DELAY 500
92 #define REPEAT_DELAY 50
94 static void
95 PAGER_GetButtonRects(PAGER_INFO* infoPtr, RECT* prcTopLeft, RECT* prcBottomRight, BOOL bClientCoords)
97 RECT rcWindow;
98 GetWindowRect (infoPtr->hwndSelf, &rcWindow);
100 if (bClientCoords)
102 POINT pt = {rcWindow.left, rcWindow.top};
103 ScreenToClient(infoPtr->hwndSelf, &pt);
104 OffsetRect(&rcWindow, -(rcWindow.left-pt.x), -(rcWindow.top-pt.y));
106 else
107 OffsetRect(&rcWindow, -rcWindow.left, -rcWindow.top);
109 *prcTopLeft = *prcBottomRight = rcWindow;
110 if (infoPtr->dwStyle & PGS_HORZ)
112 prcTopLeft->right = prcTopLeft->left + infoPtr->nButtonSize;
113 prcBottomRight->left = prcBottomRight->right - infoPtr->nButtonSize;
115 else
117 prcTopLeft->bottom = prcTopLeft->top + infoPtr->nButtonSize;
118 prcBottomRight->top = prcBottomRight->bottom - infoPtr->nButtonSize;
122 /* the horizontal arrows are:
124 * 01234 01234
125 * 1 * *
126 * 2 ** **
127 * 3*** ***
128 * 4*** ***
129 * 5 ** **
130 * 6 * *
134 static void
135 PAGER_DrawHorzArrow (HDC hdc, RECT r, INT colorRef, BOOL left)
137 INT x, y, w, h;
138 HPEN hPen, hOldPen;
140 w = r.right - r.left + 1;
141 h = r.bottom - r.top + 1;
142 if ((h < MIN_ARROW_WIDTH) || (w < MIN_ARROW_HEIGHT))
143 return; /* refuse to draw partial arrow */
145 if (!(hPen = CreatePen( PS_SOLID, 1, GetSysColor( colorRef )))) return;
146 hOldPen = SelectObject ( hdc, hPen );
147 if (left)
149 x = r.left + ((w - MIN_ARROW_HEIGHT) / 2) + 3;
150 y = r.top + ((h - MIN_ARROW_WIDTH) / 2) + 1;
151 MoveToEx (hdc, x, y, NULL);
152 LineTo (hdc, x--, y+5); y++;
153 MoveToEx (hdc, x, y, NULL);
154 LineTo (hdc, x--, y+3); y++;
155 MoveToEx (hdc, x, y, NULL);
156 LineTo (hdc, x, y+1);
158 else
160 x = r.left + ((w - MIN_ARROW_HEIGHT) / 2) + 1;
161 y = r.top + ((h - MIN_ARROW_WIDTH) / 2) + 1;
162 MoveToEx (hdc, x, y, NULL);
163 LineTo (hdc, x++, y+5); y++;
164 MoveToEx (hdc, x, y, NULL);
165 LineTo (hdc, x++, y+3); y++;
166 MoveToEx (hdc, x, y, NULL);
167 LineTo (hdc, x, y+1);
170 SelectObject( hdc, hOldPen );
171 DeleteObject( hPen );
174 /* the vertical arrows are:
176 * 01234567 01234567
177 * 1****** **
178 * 2 **** ****
179 * 3 ** ******
183 static void
184 PAGER_DrawVertArrow (HDC hdc, RECT r, INT colorRef, BOOL up)
186 INT x, y, w, h;
187 HPEN hPen, hOldPen;
189 w = r.right - r.left + 1;
190 h = r.bottom - r.top + 1;
191 if ((h < MIN_ARROW_WIDTH) || (w < MIN_ARROW_HEIGHT))
192 return; /* refuse to draw partial arrow */
194 if (!(hPen = CreatePen( PS_SOLID, 1, GetSysColor( colorRef )))) return;
195 hOldPen = SelectObject ( hdc, hPen );
196 if (up)
198 x = r.left + ((w - MIN_ARROW_HEIGHT) / 2) + 1;
199 y = r.top + ((h - MIN_ARROW_WIDTH) / 2) + 3;
200 MoveToEx (hdc, x, y, NULL);
201 LineTo (hdc, x+5, y--); x++;
202 MoveToEx (hdc, x, y, NULL);
203 LineTo (hdc, x+3, y--); x++;
204 MoveToEx (hdc, x, y, NULL);
205 LineTo (hdc, x+1, y);
207 else
209 x = r.left + ((w - MIN_ARROW_HEIGHT) / 2) + 1;
210 y = r.top + ((h - MIN_ARROW_WIDTH) / 2) + 1;
211 MoveToEx (hdc, x, y, NULL);
212 LineTo (hdc, x+5, y++); x++;
213 MoveToEx (hdc, x, y, NULL);
214 LineTo (hdc, x+3, y++); x++;
215 MoveToEx (hdc, x, y, NULL);
216 LineTo (hdc, x+1, y);
219 SelectObject( hdc, hOldPen );
220 DeleteObject( hPen );
223 static void
224 PAGER_DrawButton(HDC hdc, COLORREF clrBk, RECT arrowRect,
225 BOOL horz, BOOL topLeft, INT btnState)
227 HBRUSH hBrush, hOldBrush;
228 RECT rc = arrowRect;
230 TRACE("arrowRect = %s, btnState = %d\n", wine_dbgstr_rect(&arrowRect), btnState);
232 if (btnState == PGF_INVISIBLE)
233 return;
235 if ((rc.right - rc.left <= 0) || (rc.bottom - rc.top <= 0))
236 return;
238 hBrush = CreateSolidBrush(clrBk);
239 hOldBrush = (HBRUSH)SelectObject(hdc, hBrush);
241 FillRect(hdc, &rc, hBrush);
243 if (btnState == PGF_HOT)
245 DrawEdge( hdc, &rc, BDR_RAISEDINNER, BF_RECT);
246 if (horz)
247 PAGER_DrawHorzArrow(hdc, rc, COLOR_WINDOWFRAME, topLeft);
248 else
249 PAGER_DrawVertArrow(hdc, rc, COLOR_WINDOWFRAME, topLeft);
251 else if (btnState == PGF_NORMAL)
253 DrawEdge (hdc, &rc, BDR_OUTER, BF_FLAT);
254 if (horz)
255 PAGER_DrawHorzArrow(hdc, rc, COLOR_WINDOWFRAME, topLeft);
256 else
257 PAGER_DrawVertArrow(hdc, rc, COLOR_WINDOWFRAME, topLeft);
259 else if (btnState == PGF_DEPRESSED)
261 DrawEdge( hdc, &rc, BDR_SUNKENOUTER, BF_RECT);
262 if (horz)
263 PAGER_DrawHorzArrow(hdc, rc, COLOR_WINDOWFRAME, topLeft);
264 else
265 PAGER_DrawVertArrow(hdc, rc, COLOR_WINDOWFRAME, topLeft);
267 else if (btnState == PGF_GRAYED)
269 DrawEdge (hdc, &rc, BDR_OUTER, BF_FLAT);
270 if (horz)
272 PAGER_DrawHorzArrow(hdc, rc, COLOR_3DHIGHLIGHT, topLeft);
273 rc.left++, rc.top++; rc.right++, rc.bottom++;
274 PAGER_DrawHorzArrow(hdc, rc, COLOR_3DSHADOW, topLeft);
276 else
278 PAGER_DrawVertArrow(hdc, rc, COLOR_3DHIGHLIGHT, topLeft);
279 rc.left++, rc.top++; rc.right++, rc.bottom++;
280 PAGER_DrawVertArrow(hdc, rc, COLOR_3DSHADOW, topLeft);
284 SelectObject( hdc, hOldBrush );
285 DeleteObject(hBrush);
288 /* << PAGER_GetDropTarget >> */
290 static inline LRESULT
291 PAGER_ForwardMouse (PAGER_INFO* infoPtr, BOOL bFwd)
293 TRACE("[%p]\n", infoPtr->hwndSelf);
295 infoPtr->bForward = bFwd;
297 return 0;
300 static inline LRESULT
301 PAGER_GetButtonState (PAGER_INFO* infoPtr, INT btn)
303 LRESULT btnState = PGF_INVISIBLE;
304 TRACE("[%p]\n", infoPtr->hwndSelf);
306 if (btn == PGB_TOPORLEFT)
307 btnState = infoPtr->TLbtnState;
308 else if (btn == PGB_BOTTOMORRIGHT)
309 btnState = infoPtr->BRbtnState;
311 return btnState;
315 static inline INT
316 PAGER_GetPos(PAGER_INFO *infoPtr)
318 TRACE("[%p] returns %d\n", infoPtr->hwndSelf, infoPtr->nPos);
319 return infoPtr->nPos;
322 static inline INT
323 PAGER_GetButtonSize(PAGER_INFO *infoPtr)
325 TRACE("[%p] returns %d\n", infoPtr->hwndSelf, infoPtr->nButtonSize);
326 return infoPtr->nButtonSize;
329 static inline INT
330 PAGER_GetBorder(PAGER_INFO *infoPtr)
332 TRACE("[%p] returns %d\n", infoPtr->hwndSelf, infoPtr->nBorder);
333 return infoPtr->nBorder;
336 static inline COLORREF
337 PAGER_GetBkColor(PAGER_INFO *infoPtr)
339 TRACE("[%p] returns %06lx\n", infoPtr->hwndSelf, infoPtr->clrBk);
340 return infoPtr->clrBk;
343 static void
344 PAGER_CalcSize (PAGER_INFO *infoPtr, INT* size, BOOL getWidth)
346 NMPGCALCSIZE nmpgcs;
347 ZeroMemory (&nmpgcs, sizeof (NMPGCALCSIZE));
348 nmpgcs.hdr.hwndFrom = infoPtr->hwndSelf;
349 nmpgcs.hdr.idFrom = GetWindowLongPtrW (infoPtr->hwndSelf, GWLP_ID);
350 nmpgcs.hdr.code = PGN_CALCSIZE;
351 nmpgcs.dwFlag = getWidth ? PGF_CALCWIDTH : PGF_CALCHEIGHT;
352 nmpgcs.iWidth = getWidth ? *size : 0;
353 nmpgcs.iHeight = getWidth ? 0 : *size;
354 SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
355 (WPARAM)nmpgcs.hdr.idFrom, (LPARAM)&nmpgcs);
357 *size = getWidth ? nmpgcs.iWidth : nmpgcs.iHeight;
359 TRACE("[%p] PGN_CALCSIZE returns %s=%d\n", infoPtr->hwndSelf,
360 getWidth ? "width" : "height", *size);
363 static void
364 PAGER_PositionChildWnd(PAGER_INFO* infoPtr)
366 if (infoPtr->hwndChild)
368 RECT rcClient;
369 int nPos = infoPtr->nPos;
371 /* compensate for a grayed btn, which will soon become invisible */
372 if (infoPtr->TLbtnState == PGF_GRAYED)
373 nPos += infoPtr->nButtonSize;
375 GetClientRect(infoPtr->hwndSelf, &rcClient);
377 if (infoPtr->dwStyle & PGS_HORZ)
379 int wndSize = max(0, rcClient.right - rcClient.left);
380 if (infoPtr->nWidth < wndSize)
381 infoPtr->nWidth = wndSize;
383 TRACE("[%p] SWP %dx%d at (%d,%d)\n", infoPtr->hwndSelf,
384 infoPtr->nWidth, infoPtr->nHeight,
385 -nPos, 0);
386 SetWindowPos(infoPtr->hwndChild, 0,
387 -nPos, 0,
388 infoPtr->nWidth, infoPtr->nHeight,
389 SWP_NOZORDER);
391 else
393 int wndSize = max(0, rcClient.bottom - rcClient.top);
394 if (infoPtr->nHeight < wndSize)
395 infoPtr->nHeight = wndSize;
397 TRACE("[%p] SWP %dx%d at (%d,%d)\n", infoPtr->hwndSelf,
398 infoPtr->nWidth, infoPtr->nHeight,
399 0, -nPos);
400 SetWindowPos(infoPtr->hwndChild, 0,
401 0, -nPos,
402 infoPtr->nWidth, infoPtr->nHeight,
403 SWP_NOZORDER);
406 InvalidateRect(infoPtr->hwndChild, NULL, TRUE);
410 static INT
411 PAGER_GetScrollRange(PAGER_INFO* infoPtr)
413 INT scrollRange = 0;
415 if (infoPtr->hwndChild)
417 INT wndSize, childSize;
418 RECT wndRect;
419 GetWindowRect(infoPtr->hwndSelf, &wndRect);
421 if (infoPtr->dwStyle & PGS_HORZ)
423 wndSize = wndRect.right - wndRect.left;
424 PAGER_CalcSize(infoPtr, &infoPtr->nWidth, TRUE);
425 childSize = infoPtr->nWidth;
427 else
429 wndSize = wndRect.bottom - wndRect.top;
430 PAGER_CalcSize(infoPtr, &infoPtr->nHeight, FALSE);
431 childSize = infoPtr->nHeight;
434 TRACE("childSize = %d, wndSize = %d\n", childSize, wndSize);
435 if (childSize > wndSize)
436 scrollRange = childSize - wndSize + infoPtr->nButtonSize;
439 TRACE("[%p] returns %d\n", infoPtr->hwndSelf, scrollRange);
440 return scrollRange;
443 static void
444 PAGER_UpdateBtns(PAGER_INFO *infoPtr, INT scrollRange, BOOL hideGrayBtns)
446 BOOL resizeClient;
447 BOOL repaintBtns;
448 INT oldTLbtnState = infoPtr->TLbtnState;
449 INT oldBRbtnState = infoPtr->BRbtnState;
450 POINT pt;
451 RECT rcTopLeft, rcBottomRight;
453 /* get button rects */
454 PAGER_GetButtonRects(infoPtr, &rcTopLeft, &rcBottomRight, FALSE);
456 GetCursorPos(&pt);
458 /* update states based on scroll position */
459 if (infoPtr->nPos > 0)
461 if (infoPtr->TLbtnState == PGF_INVISIBLE || infoPtr->TLbtnState == PGF_GRAYED)
462 infoPtr->TLbtnState = PGF_NORMAL;
464 else if (PtInRect(&rcTopLeft, pt))
465 infoPtr->TLbtnState = PGF_GRAYED;
466 else
467 infoPtr->TLbtnState = PGF_INVISIBLE;
469 if (scrollRange <= 0)
471 infoPtr->TLbtnState = PGF_INVISIBLE;
472 infoPtr->BRbtnState = PGF_INVISIBLE;
474 else if (infoPtr->nPos < scrollRange)
476 if (infoPtr->BRbtnState == PGF_INVISIBLE || infoPtr->BRbtnState == PGF_GRAYED)
477 infoPtr->BRbtnState = PGF_NORMAL;
479 else if (PtInRect(&rcBottomRight, pt))
480 infoPtr->BRbtnState = PGF_GRAYED;
481 else
482 infoPtr->BRbtnState = PGF_INVISIBLE;
484 /* only need to resize when entering or leaving PGF_INVISIBLE state */
485 resizeClient =
486 ((oldTLbtnState == PGF_INVISIBLE) != (infoPtr->TLbtnState == PGF_INVISIBLE)) ||
487 ((oldBRbtnState == PGF_INVISIBLE) != (infoPtr->BRbtnState == PGF_INVISIBLE));
488 /* initiate NCCalcSize to resize client wnd if necessary */
489 if (resizeClient)
490 SetWindowPos(infoPtr->hwndSelf, 0, 0, 0, 0, 0,
491 SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE |
492 SWP_NOZORDER | SWP_NOACTIVATE);
494 /* repaint when changing any state */
495 repaintBtns = (oldTLbtnState != infoPtr->TLbtnState) ||
496 (oldBRbtnState != infoPtr->BRbtnState);
497 if (repaintBtns)
498 SendMessageW(infoPtr->hwndSelf, WM_NCPAINT, 0, 0);
501 static LRESULT
502 PAGER_SetPos(PAGER_INFO* infoPtr, INT newPos, BOOL fromBtnPress)
504 INT scrollRange = PAGER_GetScrollRange(infoPtr);
505 INT oldPos = infoPtr->nPos;
507 if ((scrollRange <= 0) || (newPos < 0))
508 infoPtr->nPos = 0;
509 else if (newPos > scrollRange)
510 infoPtr->nPos = scrollRange;
511 else
512 infoPtr->nPos = newPos;
514 TRACE("[%p] pos=%d, oldpos=%d\n", infoPtr->hwndSelf, infoPtr->nPos, oldPos);
516 if (infoPtr->nPos != oldPos)
518 /* gray and restore btns, and if from WM_SETPOS, hide the gray btns */
519 PAGER_UpdateBtns(infoPtr, scrollRange, !fromBtnPress);
520 PAGER_PositionChildWnd(infoPtr);
523 return 0;
526 static LRESULT
527 PAGER_WindowPosChanging(PAGER_INFO* infoPtr, WINDOWPOS *winpos)
529 if ((infoPtr->dwStyle & CCS_NORESIZE) && !(winpos->flags & SWP_NOSIZE))
531 /* don't let the app resize the nonscrollable dimension of a control
532 * that was created with CCS_NORESIZE style
533 * (i.e. height for a horizontal pager, or width for a vertical one) */
535 /* except if the current dimension is 0 and app is setting for
536 * first time, then save amount as dimension. - GA 8/01 */
538 if (infoPtr->dwStyle & PGS_HORZ)
539 if (!infoPtr->nHeight && winpos->cy)
540 infoPtr->nHeight = winpos->cy;
541 else
542 winpos->cy = infoPtr->nHeight;
543 else
544 if (!infoPtr->nWidth && winpos->cx)
545 infoPtr->nWidth = winpos->cx;
546 else
547 winpos->cx = infoPtr->nWidth;
548 return 0;
551 return DefWindowProcW (infoPtr->hwndSelf, WM_WINDOWPOSCHANGING, 0, (LPARAM)winpos);
554 static INT
555 PAGER_SetFixedWidth(PAGER_INFO* infoPtr)
557 /* Must set the non-scrollable dimension to be less than the full height/width
558 * so that NCCalcSize is called. The Msoft docs mention 3/4 factor for button
559 * size, and experimentation shows that affect is almost right. */
561 RECT wndRect;
562 INT delta, h;
563 GetWindowRect(infoPtr->hwndSelf, &wndRect);
565 /* see what the app says for btn width */
566 PAGER_CalcSize(infoPtr, &infoPtr->nWidth, TRUE);
568 if (infoPtr->dwStyle & CCS_NORESIZE)
570 delta = wndRect.right - wndRect.left - infoPtr->nWidth;
571 if (delta > infoPtr->nButtonSize)
572 infoPtr->nWidth += 4 * infoPtr->nButtonSize / 3;
573 else if (delta > 0)
574 infoPtr->nWidth += infoPtr->nButtonSize / 3;
577 h = wndRect.bottom - wndRect.top + infoPtr->nButtonSize;
579 TRACE("[%p] infoPtr->nWidth set to %d\n",
580 infoPtr->hwndSelf, infoPtr->nWidth);
582 return h;
585 static INT
586 PAGER_SetFixedHeight(PAGER_INFO* infoPtr)
588 /* Must set the non-scrollable dimension to be less than the full height/width
589 * so that NCCalcSize is called. The Msoft docs mention 3/4 factor for button
590 * size, and experimentation shows that affect is almost right. */
592 RECT wndRect;
593 INT delta, w;
594 GetWindowRect(infoPtr->hwndSelf, &wndRect);
596 /* see what the app says for btn height */
597 PAGER_CalcSize(infoPtr, &infoPtr->nHeight, FALSE);
599 if (infoPtr->dwStyle & CCS_NORESIZE)
601 delta = wndRect.bottom - wndRect.top - infoPtr->nHeight;
602 if (delta > infoPtr->nButtonSize)
603 infoPtr->nHeight += infoPtr->nButtonSize;
604 else if (delta > 0)
605 infoPtr->nHeight += infoPtr->nButtonSize / 3;
608 w = wndRect.right - wndRect.left + infoPtr->nButtonSize;
610 TRACE("[%p] infoPtr->nHeight set to %d\n",
611 infoPtr->hwndSelf, infoPtr->nHeight);
613 return w;
616 /******************************************************************
617 * For the PGM_RECALCSIZE message (but not the other uses in *
618 * this module), the native control does only the following: *
620 * if (some condition) *
621 * PostMessageW(hwnd, EM_FMTLINES, 0, 0); *
622 * return DefWindowProcW(hwnd, PGM_RECALCSIZE, 0, 0); *
624 * When we figure out what the "some condition" is we will *
625 * implement that for the message processing. *
626 ******************************************************************/
628 static LRESULT
629 PAGER_RecalcSize(PAGER_INFO *infoPtr)
631 TRACE("[%p]\n", infoPtr->hwndSelf);
633 if (infoPtr->hwndChild)
635 INT scrollRange = PAGER_GetScrollRange(infoPtr);
637 if (scrollRange <= 0)
639 infoPtr->nPos = -1;
640 PAGER_SetPos(infoPtr, 0, FALSE);
642 else
643 PAGER_PositionChildWnd(infoPtr);
646 return 1;
650 static COLORREF
651 PAGER_SetBkColor (PAGER_INFO* infoPtr, COLORREF clrBk)
653 COLORREF clrTemp = infoPtr->clrBk;
655 infoPtr->clrBk = clrBk;
656 TRACE("[%p] %06lx\n", infoPtr->hwndSelf, infoPtr->clrBk);
658 /* the native control seems to do things this way */
659 SetWindowPos(infoPtr->hwndSelf, 0, 0, 0, 0, 0,
660 SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE |
661 SWP_NOZORDER | SWP_NOACTIVATE);
663 RedrawWindow(infoPtr->hwndSelf, 0, 0, RDW_ERASE | RDW_INVALIDATE);
665 return clrTemp;
669 static INT
670 PAGER_SetBorder (PAGER_INFO* infoPtr, INT iBorder)
672 INT nTemp = infoPtr->nBorder;
674 infoPtr->nBorder = iBorder;
675 TRACE("[%p] %d\n", infoPtr->hwndSelf, infoPtr->nBorder);
677 PAGER_RecalcSize(infoPtr);
679 return nTemp;
683 static INT
684 PAGER_SetButtonSize (PAGER_INFO* infoPtr, INT iButtonSize)
686 INT nTemp = infoPtr->nButtonSize;
688 infoPtr->nButtonSize = iButtonSize;
689 TRACE("[%p] %d\n", infoPtr->hwndSelf, infoPtr->nButtonSize);
691 PAGER_RecalcSize(infoPtr);
693 return nTemp;
697 static LRESULT
698 PAGER_SetChild (PAGER_INFO* infoPtr, HWND hwndChild)
700 INT hw;
702 infoPtr->hwndChild = IsWindow (hwndChild) ? hwndChild : 0;
704 if (infoPtr->hwndChild)
706 TRACE("[%p] hwndChild=%p\n", infoPtr->hwndSelf, infoPtr->hwndChild);
708 if (infoPtr->dwStyle & PGS_HORZ) {
709 hw = PAGER_SetFixedHeight(infoPtr);
710 /* adjust non-scrollable dimension to fit the child */
711 SetWindowPos(infoPtr->hwndSelf, 0, 0, 0, hw, infoPtr->nHeight,
712 SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOZORDER |
713 SWP_NOSIZE | SWP_NOACTIVATE);
715 else {
716 hw = PAGER_SetFixedWidth(infoPtr);
717 /* adjust non-scrollable dimension to fit the child */
718 SetWindowPos(infoPtr->hwndSelf, 0, 0, 0, infoPtr->nWidth, hw,
719 SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOZORDER |
720 SWP_NOSIZE | SWP_NOACTIVATE);
723 /* position child within the page scroller */
724 SetWindowPos(infoPtr->hwndChild, HWND_TOP,
725 0,0,0,0,
726 SWP_SHOWWINDOW | SWP_NOSIZE); /* native is 0 */
728 infoPtr->nPos = -1;
729 PAGER_SetPos(infoPtr, 0, FALSE);
732 return 0;
735 static void
736 PAGER_Scroll(PAGER_INFO* infoPtr, INT dir)
738 NMPGSCROLL nmpgScroll;
739 RECT rcWnd;
741 if (infoPtr->hwndChild)
743 ZeroMemory (&nmpgScroll, sizeof (NMPGSCROLL));
744 nmpgScroll.hdr.hwndFrom = infoPtr->hwndSelf;
745 nmpgScroll.hdr.idFrom = GetWindowLongPtrW (infoPtr->hwndSelf, GWLP_ID);
746 nmpgScroll.hdr.code = PGN_SCROLL;
748 GetWindowRect(infoPtr->hwndSelf, &rcWnd);
749 GetClientRect(infoPtr->hwndSelf, &nmpgScroll.rcParent);
750 nmpgScroll.iXpos = nmpgScroll.iYpos = 0;
751 nmpgScroll.iDir = dir;
753 if (infoPtr->dwStyle & PGS_HORZ)
755 nmpgScroll.iScroll = rcWnd.right - rcWnd.left;
756 nmpgScroll.iXpos = infoPtr->nPos;
758 else
760 nmpgScroll.iScroll = rcWnd.bottom - rcWnd.top;
761 nmpgScroll.iYpos = infoPtr->nPos;
763 nmpgScroll.iScroll -= 2*infoPtr->nButtonSize;
765 SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
766 (WPARAM)nmpgScroll.hdr.idFrom, (LPARAM)&nmpgScroll);
768 TRACE("[%p] PGN_SCROLL returns iScroll=%d\n", infoPtr->hwndSelf, nmpgScroll.iScroll);
770 if (nmpgScroll.iScroll > 0)
772 infoPtr->direction = dir;
774 if (dir == PGF_SCROLLLEFT || dir == PGF_SCROLLUP)
775 PAGER_SetPos(infoPtr, infoPtr->nPos - nmpgScroll.iScroll, TRUE);
776 else
777 PAGER_SetPos(infoPtr, infoPtr->nPos + nmpgScroll.iScroll, TRUE);
779 else
780 infoPtr->direction = -1;
784 static LRESULT
785 PAGER_FmtLines(PAGER_INFO *infoPtr)
787 /* initiate NCCalcSize to resize client wnd and get size */
788 SetWindowPos(infoPtr->hwndSelf, 0, 0, 0, 0, 0,
789 SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE |
790 SWP_NOZORDER | SWP_NOACTIVATE);
792 SetWindowPos(infoPtr->hwndChild, 0,
793 0,0,infoPtr->nWidth,infoPtr->nHeight,
796 return DefWindowProcW (infoPtr->hwndSelf, EM_FMTLINES, 0, 0);
799 static LRESULT
800 PAGER_Create (HWND hwnd, LPCREATESTRUCTW lpcs)
802 PAGER_INFO *infoPtr;
804 /* allocate memory for info structure */
805 infoPtr = (PAGER_INFO *)Alloc (sizeof(PAGER_INFO));
806 if (!infoPtr) return -1;
807 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
809 /* set default settings */
810 infoPtr->hwndSelf = hwnd;
811 infoPtr->hwndChild = NULL;
812 infoPtr->hwndNotify = lpcs->hwndParent;
813 infoPtr->dwStyle = lpcs->style;
814 infoPtr->clrBk = GetSysColor(COLOR_BTNFACE);
815 infoPtr->nBorder = 0;
816 infoPtr->nButtonSize = 12;
817 infoPtr->nPos = 0;
818 infoPtr->nWidth = 0;
819 infoPtr->nHeight = 0;
820 infoPtr->bForward = FALSE;
821 infoPtr->bCapture = FALSE;
822 infoPtr->TLbtnState = PGF_INVISIBLE;
823 infoPtr->BRbtnState = PGF_INVISIBLE;
824 infoPtr->direction = -1;
826 if (infoPtr->dwStyle & PGS_DRAGNDROP)
827 FIXME("[%p] Drag and Drop style is not implemented yet.\n", infoPtr->hwndSelf);
829 return 0;
833 static LRESULT
834 PAGER_Destroy (PAGER_INFO *infoPtr)
836 SetWindowLongPtrW (infoPtr->hwndSelf, 0, 0);
837 Free (infoPtr); /* free pager info data */
838 return 0;
841 static LRESULT
842 PAGER_NCCalcSize(PAGER_INFO* infoPtr, WPARAM wParam, LPRECT lpRect)
844 RECT rcChild, rcWindow;
845 INT scrollRange;
848 * lpRect points to a RECT struct. On entry, the struct
849 * contains the proposed wnd rectangle for the window.
850 * On exit, the struct should contain the screen
851 * coordinates of the corresponding window's client area.
854 DefWindowProcW (infoPtr->hwndSelf, WM_NCCALCSIZE, wParam, (LPARAM)lpRect);
856 TRACE("orig rect=%s\n", wine_dbgstr_rect(lpRect));
858 GetWindowRect (infoPtr->hwndChild, &rcChild);
859 MapWindowPoints (0, infoPtr->hwndSelf, (LPPOINT)&rcChild, 2); /* FIXME: RECT != 2 POINTS */
860 GetWindowRect (infoPtr->hwndSelf, &rcWindow);
862 if (infoPtr->dwStyle & PGS_HORZ)
864 infoPtr->nWidth = lpRect->right - lpRect->left;
865 PAGER_CalcSize (infoPtr, &infoPtr->nWidth, TRUE);
867 scrollRange = infoPtr->nWidth - (rcWindow.right - rcWindow.left);
869 if (infoPtr->TLbtnState && (lpRect->left + infoPtr->nButtonSize < lpRect->right))
870 lpRect->left += infoPtr->nButtonSize;
871 if (infoPtr->BRbtnState && (lpRect->right - infoPtr->nButtonSize > lpRect->left))
872 lpRect->right -= infoPtr->nButtonSize;
874 else
876 infoPtr->nHeight = lpRect->bottom - lpRect->top;
877 PAGER_CalcSize (infoPtr, &infoPtr->nHeight, FALSE);
879 scrollRange = infoPtr->nHeight - (rcWindow.bottom - rcWindow.top);
881 if (infoPtr->TLbtnState && (lpRect->top + infoPtr->nButtonSize < lpRect->bottom))
882 lpRect->top += infoPtr->nButtonSize;
883 if (infoPtr->BRbtnState && (lpRect->bottom - infoPtr->nButtonSize > lpRect->top))
884 lpRect->bottom -= infoPtr->nButtonSize;
887 TRACE("nPos=%d, nHeigth=%d, window=%s\n",
888 infoPtr->nPos, infoPtr->nHeight,
889 wine_dbgstr_rect(&rcWindow));
891 TRACE("[%p] client rect set to %ldx%ld at (%ld,%ld) BtnState[%d,%d]\n",
892 infoPtr->hwndSelf, lpRect->right-lpRect->left, lpRect->bottom-lpRect->top,
893 lpRect->left, lpRect->top,
894 infoPtr->TLbtnState, infoPtr->BRbtnState);
896 return 0;
899 static LRESULT
900 PAGER_NCPaint (PAGER_INFO* infoPtr, HRGN hRgn)
902 RECT rcBottomRight, rcTopLeft;
903 HDC hdc;
905 if (infoPtr->dwStyle & WS_MINIMIZE)
906 return 0;
908 DefWindowProcW (infoPtr->hwndSelf, WM_NCPAINT, (WPARAM)hRgn, 0);
910 if (!(hdc = GetDCEx (infoPtr->hwndSelf, 0, DCX_USESTYLE | DCX_WINDOW)))
911 return 0;
913 PAGER_GetButtonRects(infoPtr, &rcTopLeft, &rcBottomRight, FALSE);
915 PAGER_DrawButton(hdc, infoPtr->clrBk, rcTopLeft,
916 infoPtr->dwStyle & PGS_HORZ, TRUE, infoPtr->TLbtnState);
917 PAGER_DrawButton(hdc, infoPtr->clrBk, rcBottomRight,
918 infoPtr->dwStyle & PGS_HORZ, FALSE, infoPtr->BRbtnState);
920 ReleaseDC( infoPtr->hwndSelf, hdc );
921 return 0;
924 static INT
925 PAGER_HitTest (PAGER_INFO* infoPtr, const POINT * pt)
927 RECT clientRect, rcTopLeft, rcBottomRight;
928 POINT ptWindow;
930 GetClientRect (infoPtr->hwndSelf, &clientRect);
932 if (PtInRect(&clientRect, *pt))
934 TRACE("child\n");
935 return -1;
938 ptWindow = *pt;
939 PAGER_GetButtonRects(infoPtr, &rcTopLeft, &rcBottomRight, TRUE);
941 if ((infoPtr->TLbtnState != PGF_INVISIBLE) && PtInRect(&rcTopLeft, ptWindow))
943 TRACE("PGB_TOPORLEFT\n");
944 return PGB_TOPORLEFT;
946 else if ((infoPtr->BRbtnState != PGF_INVISIBLE) && PtInRect(&rcBottomRight, ptWindow))
948 TRACE("PGB_BOTTOMORRIGHT\n");
949 return PGB_BOTTOMORRIGHT;
952 TRACE("nowhere\n");
953 return -1;
956 static LRESULT
957 PAGER_NCHitTest (PAGER_INFO* infoPtr, INT x, INT y)
959 POINT pt;
960 INT nHit;
962 pt.x = x;
963 pt.y = y;
965 ScreenToClient (infoPtr->hwndSelf, &pt);
966 nHit = PAGER_HitTest(infoPtr, &pt);
968 return (nHit < 0) ? HTTRANSPARENT : HTCLIENT;
971 static LRESULT
972 PAGER_MouseMove (PAGER_INFO* infoPtr, INT keys, INT x, INT y)
974 POINT clpt, pt;
975 RECT wnrect, *btnrect = NULL;
976 BOOL topLeft = FALSE;
977 INT btnstate = 0;
978 INT hit;
979 HDC hdc;
981 pt.x = x;
982 pt.y = y;
984 TRACE("[%p] to (%d,%d)\n", infoPtr->hwndSelf, x, y);
985 ClientToScreen(infoPtr->hwndSelf, &pt);
986 GetWindowRect(infoPtr->hwndSelf, &wnrect);
987 if (PtInRect(&wnrect, pt)) {
988 RECT TLbtnrect, BRbtnrect;
989 PAGER_GetButtonRects(infoPtr, &TLbtnrect, &BRbtnrect, FALSE);
991 clpt = pt;
992 MapWindowPoints(0, infoPtr->hwndSelf, &clpt, 1);
993 hit = PAGER_HitTest(infoPtr, &clpt);
994 if ((hit == PGB_TOPORLEFT) && (infoPtr->TLbtnState == PGF_NORMAL))
996 topLeft = TRUE;
997 btnrect = &TLbtnrect;
998 infoPtr->TLbtnState = PGF_HOT;
999 btnstate = infoPtr->TLbtnState;
1001 else if ((hit == PGB_BOTTOMORRIGHT) && (infoPtr->BRbtnState == PGF_NORMAL))
1003 topLeft = FALSE;
1004 btnrect = &BRbtnrect;
1005 infoPtr->BRbtnState = PGF_HOT;
1006 btnstate = infoPtr->BRbtnState;
1009 /* If in one of the buttons the capture and draw buttons */
1010 if (btnrect)
1012 TRACE("[%p] draw btn (%ld,%ld)-(%ld,%ld), Capture %s, style %08lx\n",
1013 infoPtr->hwndSelf, btnrect->left, btnrect->top,
1014 btnrect->right, btnrect->bottom,
1015 (infoPtr->bCapture) ? "TRUE" : "FALSE",
1016 infoPtr->dwStyle);
1017 if (!infoPtr->bCapture)
1019 TRACE("[%p] SetCapture\n", infoPtr->hwndSelf);
1020 SetCapture(infoPtr->hwndSelf);
1021 infoPtr->bCapture = TRUE;
1023 if (infoPtr->dwStyle & PGS_AUTOSCROLL)
1024 SetTimer(infoPtr->hwndSelf, TIMERID1, 0x3e, 0);
1025 hdc = GetWindowDC(infoPtr->hwndSelf);
1026 /* OffsetRect(wnrect, 0 | 1, 0 | 1) */
1027 PAGER_DrawButton(hdc, infoPtr->clrBk, *btnrect,
1028 infoPtr->dwStyle & PGS_HORZ, topLeft, btnstate);
1029 ReleaseDC(infoPtr->hwndSelf, hdc);
1030 return 0;
1034 /* If we think we are captured, then do release */
1035 if (infoPtr->bCapture && (WindowFromPoint(pt) != infoPtr->hwndSelf))
1037 NMHDR nmhdr;
1039 infoPtr->bCapture = FALSE;
1041 if (GetCapture() == infoPtr->hwndSelf)
1043 ReleaseCapture();
1045 if (infoPtr->TLbtnState == PGF_GRAYED)
1047 infoPtr->TLbtnState = PGF_INVISIBLE;
1048 SetWindowPos(infoPtr->hwndSelf, 0, 0, 0, 0, 0,
1049 SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE |
1050 SWP_NOZORDER | SWP_NOACTIVATE);
1052 else if (infoPtr->TLbtnState == PGF_HOT)
1054 infoPtr->TLbtnState = PGF_NORMAL;
1055 /* FIXME: just invalidate button rect */
1056 RedrawWindow(infoPtr->hwndSelf, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
1059 if (infoPtr->BRbtnState == PGF_GRAYED)
1061 infoPtr->BRbtnState = PGF_INVISIBLE;
1062 SetWindowPos(infoPtr->hwndSelf, 0, 0, 0, 0, 0,
1063 SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE |
1064 SWP_NOZORDER | SWP_NOACTIVATE);
1066 else if (infoPtr->BRbtnState == PGF_HOT)
1068 infoPtr->BRbtnState = PGF_NORMAL;
1069 /* FIXME: just invalidate button rect */
1070 RedrawWindow(infoPtr->hwndSelf, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
1073 /* Notify parent of released mouse capture */
1074 memset(&nmhdr, 0, sizeof(NMHDR));
1075 nmhdr.hwndFrom = infoPtr->hwndSelf;
1076 nmhdr.idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
1077 nmhdr.code = NM_RELEASEDCAPTURE;
1078 SendMessageW(infoPtr->hwndNotify, WM_NOTIFY,
1079 (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
1081 if (IsWindow(infoPtr->hwndSelf))
1082 KillTimer(infoPtr->hwndSelf, TIMERID1);
1084 return 0;
1087 static LRESULT
1088 PAGER_LButtonDown (PAGER_INFO* infoPtr, INT keys, INT x, INT y)
1090 BOOL repaintBtns = FALSE;
1091 POINT pt;
1092 INT hit;
1094 pt.x = x;
1095 pt.y = y;
1097 TRACE("[%p] at (%d,%d)\n", infoPtr->hwndSelf, x, y);
1099 hit = PAGER_HitTest(infoPtr, &pt);
1101 /* put btn in DEPRESSED state */
1102 if (hit == PGB_TOPORLEFT)
1104 repaintBtns = infoPtr->TLbtnState != PGF_DEPRESSED;
1105 infoPtr->TLbtnState = PGF_DEPRESSED;
1106 SetTimer(infoPtr->hwndSelf, TIMERID1, INITIAL_DELAY, 0);
1108 else if (hit == PGB_BOTTOMORRIGHT)
1110 repaintBtns = infoPtr->BRbtnState != PGF_DEPRESSED;
1111 infoPtr->BRbtnState = PGF_DEPRESSED;
1112 SetTimer(infoPtr->hwndSelf, TIMERID1, INITIAL_DELAY, 0);
1115 if (repaintBtns)
1116 SendMessageW(infoPtr->hwndSelf, WM_NCPAINT, 0, 0);
1118 switch(hit)
1120 case PGB_TOPORLEFT:
1121 if (infoPtr->dwStyle & PGS_HORZ)
1123 TRACE("[%p] PGF_SCROLLLEFT\n", infoPtr->hwndSelf);
1124 PAGER_Scroll(infoPtr, PGF_SCROLLLEFT);
1126 else
1128 TRACE("[%p] PGF_SCROLLUP\n", infoPtr->hwndSelf);
1129 PAGER_Scroll(infoPtr, PGF_SCROLLUP);
1131 break;
1132 case PGB_BOTTOMORRIGHT:
1133 if (infoPtr->dwStyle & PGS_HORZ)
1135 TRACE("[%p] PGF_SCROLLRIGHT\n", infoPtr->hwndSelf);
1136 PAGER_Scroll(infoPtr, PGF_SCROLLRIGHT);
1138 else
1140 TRACE("[%p] PGF_SCROLLDOWN\n", infoPtr->hwndSelf);
1141 PAGER_Scroll(infoPtr, PGF_SCROLLDOWN);
1143 break;
1144 default:
1145 break;
1148 return 0;
1151 static LRESULT
1152 PAGER_LButtonUp (PAGER_INFO* infoPtr, INT keys, INT x, INT y)
1154 TRACE("[%p]\n", infoPtr->hwndSelf);
1156 KillTimer (infoPtr->hwndSelf, TIMERID1);
1157 KillTimer (infoPtr->hwndSelf, TIMERID2);
1159 /* make PRESSED btns NORMAL but don't hide gray btns */
1160 if (infoPtr->TLbtnState & (PGF_HOT | PGF_DEPRESSED))
1161 infoPtr->TLbtnState = PGF_NORMAL;
1162 if (infoPtr->BRbtnState & (PGF_HOT | PGF_DEPRESSED))
1163 infoPtr->BRbtnState = PGF_NORMAL;
1165 return 0;
1168 static LRESULT
1169 PAGER_Timer (PAGER_INFO* infoPtr, INT nTimerId)
1171 INT dir;
1173 /* if initial timer, kill it and start the repeat timer */
1174 if (nTimerId == TIMERID1) {
1175 if (infoPtr->TLbtnState == PGF_HOT)
1176 dir = (infoPtr->dwStyle & PGS_HORZ) ?
1177 PGF_SCROLLLEFT : PGF_SCROLLUP;
1178 else
1179 dir = (infoPtr->dwStyle & PGS_HORZ) ?
1180 PGF_SCROLLRIGHT : PGF_SCROLLDOWN;
1181 TRACE("[%p] TIMERID1: style=%08lx, dir=%d\n",
1182 infoPtr->hwndSelf, infoPtr->dwStyle, dir);
1183 KillTimer(infoPtr->hwndSelf, TIMERID1);
1184 SetTimer(infoPtr->hwndSelf, TIMERID1, REPEAT_DELAY, 0);
1185 if (infoPtr->dwStyle & PGS_AUTOSCROLL) {
1186 PAGER_Scroll(infoPtr, dir);
1187 SetWindowPos(infoPtr->hwndSelf, 0, 0, 0, 0, 0,
1188 SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE |
1189 SWP_NOZORDER | SWP_NOACTIVATE);
1191 return 0;
1195 TRACE("[%p] TIMERID2: dir=%d\n", infoPtr->hwndSelf, infoPtr->direction);
1196 KillTimer(infoPtr->hwndSelf, TIMERID2);
1197 if (infoPtr->direction > 0) {
1198 PAGER_Scroll(infoPtr, infoPtr->direction);
1199 SetTimer(infoPtr->hwndSelf, TIMERID2, REPEAT_DELAY, 0);
1201 return 0;
1204 static LRESULT
1205 PAGER_EraseBackground (PAGER_INFO* infoPtr, HDC hdc)
1207 POINT pt, ptorig;
1208 HWND parent;
1210 pt.x = 0;
1211 pt.y = 0;
1212 parent = GetParent(infoPtr->hwndSelf);
1213 MapWindowPoints(infoPtr->hwndSelf, parent, &pt, 1);
1214 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
1215 SendMessageW (parent, WM_ERASEBKGND, (WPARAM)hdc, 0);
1216 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
1218 return 0;
1222 static LRESULT
1223 PAGER_Size (PAGER_INFO* infoPtr, INT type, INT x, INT y)
1225 /* note that WM_SIZE is sent whenever NCCalcSize resizes the client wnd */
1227 TRACE("[%p] %d,%d\n", infoPtr->hwndSelf, x, y);
1229 if (infoPtr->dwStyle & PGS_HORZ)
1230 infoPtr->nHeight = x;
1231 else
1232 infoPtr->nWidth = y;
1234 return PAGER_RecalcSize(infoPtr);
1238 static LRESULT
1239 PAGER_StyleChanged(PAGER_INFO *infoPtr, WPARAM wStyleType, LPSTYLESTRUCT lpss)
1241 DWORD oldStyle = infoPtr->dwStyle;
1243 TRACE("(styletype=%x, styleOld=0x%08lx, styleNew=0x%08lx)\n",
1244 wStyleType, lpss->styleOld, lpss->styleNew);
1246 if (wStyleType != GWL_STYLE) return 0;
1248 infoPtr->dwStyle = lpss->styleNew;
1250 if ((oldStyle ^ lpss->styleNew) & (PGS_HORZ | PGS_VERT))
1252 PAGER_RecalcSize(infoPtr);
1255 return 0;
1258 static LRESULT WINAPI
1259 PAGER_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1261 PAGER_INFO *infoPtr = (PAGER_INFO *)GetWindowLongPtrW(hwnd, 0);
1263 if (!infoPtr && (uMsg != WM_CREATE))
1264 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
1266 switch (uMsg)
1268 case EM_FMTLINES:
1269 return PAGER_FmtLines(infoPtr);
1271 case PGM_FORWARDMOUSE:
1272 return PAGER_ForwardMouse (infoPtr, (BOOL)wParam);
1274 case PGM_GETBKCOLOR:
1275 return PAGER_GetBkColor(infoPtr);
1277 case PGM_GETBORDER:
1278 return PAGER_GetBorder(infoPtr);
1280 case PGM_GETBUTTONSIZE:
1281 return PAGER_GetButtonSize(infoPtr);
1283 case PGM_GETPOS:
1284 return PAGER_GetPos(infoPtr);
1286 case PGM_GETBUTTONSTATE:
1287 return PAGER_GetButtonState (infoPtr, (INT)lParam);
1289 /* case PGM_GETDROPTARGET: */
1291 case PGM_RECALCSIZE:
1292 return PAGER_RecalcSize(infoPtr);
1294 case PGM_SETBKCOLOR:
1295 return PAGER_SetBkColor (infoPtr, (COLORREF)lParam);
1297 case PGM_SETBORDER:
1298 return PAGER_SetBorder (infoPtr, (INT)lParam);
1300 case PGM_SETBUTTONSIZE:
1301 return PAGER_SetButtonSize (infoPtr, (INT)lParam);
1303 case PGM_SETCHILD:
1304 return PAGER_SetChild (infoPtr, (HWND)lParam);
1306 case PGM_SETPOS:
1307 return PAGER_SetPos(infoPtr, (INT)lParam, FALSE);
1309 case WM_CREATE:
1310 return PAGER_Create (hwnd, (LPCREATESTRUCTW)lParam);
1312 case WM_DESTROY:
1313 return PAGER_Destroy (infoPtr);
1315 case WM_SIZE:
1316 return PAGER_Size (infoPtr, (INT)wParam, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
1318 case WM_NCPAINT:
1319 return PAGER_NCPaint (infoPtr, (HRGN)wParam);
1321 case WM_WINDOWPOSCHANGING:
1322 return PAGER_WindowPosChanging (infoPtr, (WINDOWPOS*)lParam);
1324 case WM_STYLECHANGED:
1325 return PAGER_StyleChanged(infoPtr, wParam, (LPSTYLESTRUCT)lParam);
1327 case WM_NCCALCSIZE:
1328 return PAGER_NCCalcSize (infoPtr, wParam, (LPRECT)lParam);
1330 case WM_NCHITTEST:
1331 return PAGER_NCHitTest (infoPtr, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
1333 case WM_MOUSEMOVE:
1334 if (infoPtr->bForward && infoPtr->hwndChild)
1335 PostMessageW(infoPtr->hwndChild, WM_MOUSEMOVE, wParam, lParam);
1336 return PAGER_MouseMove (infoPtr, (INT)wParam, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
1338 case WM_LBUTTONDOWN:
1339 return PAGER_LButtonDown (infoPtr, (INT)wParam, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
1341 case WM_LBUTTONUP:
1342 return PAGER_LButtonUp (infoPtr, (INT)wParam, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
1344 case WM_ERASEBKGND:
1345 return PAGER_EraseBackground (infoPtr, (HDC)wParam);
1347 case WM_TIMER:
1348 return PAGER_Timer (infoPtr, (INT)wParam);
1350 case WM_NOTIFY:
1351 case WM_COMMAND:
1352 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
1354 default:
1355 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
1360 VOID
1361 PAGER_Register (void)
1363 WNDCLASSW wndClass;
1365 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
1366 wndClass.style = CS_GLOBALCLASS;
1367 wndClass.lpfnWndProc = PAGER_WindowProc;
1368 wndClass.cbClsExtra = 0;
1369 wndClass.cbWndExtra = sizeof(PAGER_INFO *);
1370 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1371 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
1372 wndClass.lpszClassName = WC_PAGESCROLLERW;
1374 RegisterClassW (&wndClass);
1378 VOID
1379 PAGER_Unregister (void)
1381 UnregisterClassW (WC_PAGESCROLLERW, NULL);