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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
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.
30 * Implement repetitive button press.
31 * Adjust arrow size relative to size of button.
32 * Allow border size changes.
38 * WM_PRINT and/or WM_PRINTCLIENT
41 * Tested primarily with the controlspy Pager application.
42 * Susan Farley (susan@codeweavers.com)
44 * IMPLEMENTATION NOTES:
45 * This control uses WM_NCPAINT instead of WM_PAINT to paint itself
46 * as we need to scroll a child window. In order to do this we move
47 * the child window in the control's client area, using the clipping
48 * region that is automatically set around the client area. As the
49 * entire client area now consists of the child window, we must
50 * allocate space (WM_NCCALCSIZE) for the buttons and draw them as
51 * a non-client area (WM_NCPAINT).
52 * Robert Shearman <rob@codeweavers.com>
64 #include "wine/debug.h"
66 WINE_DEFAULT_DEBUG_CHANNEL(pager);
70 HWND hwndSelf; /* handle of the control wnd */
71 HWND hwndChild; /* handle of the contained wnd */
72 HWND hwndNotify; /* handle of the parent wnd */
73 DWORD dwStyle; /* styles for this control */
74 COLORREF clrBk; /* background color */
75 INT nBorder; /* border size for the control */
76 INT nButtonSize;/* size of the pager btns */
77 INT nPos; /* scroll position */
78 INT nWidth; /* from child wnd's response to PGN_CALCSIZE */
79 INT nHeight; /* from child wnd's response to PGN_CALCSIZE */
80 BOOL bForward; /* forward WM_MOUSEMOVE msgs to the contained wnd */
81 BOOL bCapture; /* we have captured the mouse */
82 INT TLbtnState; /* state of top or left btn */
83 INT BRbtnState; /* state of bottom or right btn */
84 INT direction; /* direction of the scroll, (e.g. PGF_SCROLLUP) */
87 #define MIN_ARROW_WIDTH 8
88 #define MIN_ARROW_HEIGHT 5
92 #define INITIAL_DELAY 500
93 #define REPEAT_DELAY 50
96 PAGER_GetButtonRects(PAGER_INFO* infoPtr, RECT* prcTopLeft, RECT* prcBottomRight, BOOL bClientCoords)
99 GetWindowRect (infoPtr->hwndSelf, &rcWindow);
103 POINT pt = {rcWindow.left, rcWindow.top};
104 ScreenToClient(infoPtr->hwndSelf, &pt);
105 OffsetRect(&rcWindow, -(rcWindow.left-pt.x), -(rcWindow.top-pt.y));
108 OffsetRect(&rcWindow, -rcWindow.left, -rcWindow.top);
110 *prcTopLeft = *prcBottomRight = rcWindow;
111 if (infoPtr->dwStyle & PGS_HORZ)
113 prcTopLeft->right = prcTopLeft->left + infoPtr->nButtonSize;
114 prcBottomRight->left = prcBottomRight->right - infoPtr->nButtonSize;
118 prcTopLeft->bottom = prcTopLeft->top + infoPtr->nButtonSize;
119 prcBottomRight->top = prcBottomRight->bottom - infoPtr->nButtonSize;
123 /* the horizontal arrows are:
136 PAGER_DrawHorzArrow (HDC hdc, RECT r, INT colorRef, BOOL left)
141 w = r.right - r.left + 1;
142 h = r.bottom - r.top + 1;
143 if ((h < MIN_ARROW_WIDTH) || (w < MIN_ARROW_HEIGHT))
144 return; /* refuse to draw partial arrow */
146 if (!(hPen = CreatePen( PS_SOLID, 1, GetSysColor( colorRef )))) return;
147 hOldPen = SelectObject ( hdc, hPen );
150 x = r.left + ((w - MIN_ARROW_HEIGHT) / 2) + 3;
151 y = r.top + ((h - MIN_ARROW_WIDTH) / 2) + 1;
152 MoveToEx (hdc, x, y, NULL);
153 LineTo (hdc, x--, y+5); y++;
154 MoveToEx (hdc, x, y, NULL);
155 LineTo (hdc, x--, y+3); y++;
156 MoveToEx (hdc, x, y, NULL);
157 LineTo (hdc, x, y+1);
161 x = r.left + ((w - MIN_ARROW_HEIGHT) / 2) + 1;
162 y = r.top + ((h - MIN_ARROW_WIDTH) / 2) + 1;
163 MoveToEx (hdc, x, y, NULL);
164 LineTo (hdc, x++, y+5); y++;
165 MoveToEx (hdc, x, y, NULL);
166 LineTo (hdc, x++, y+3); y++;
167 MoveToEx (hdc, x, y, NULL);
168 LineTo (hdc, x, y+1);
171 SelectObject( hdc, hOldPen );
172 DeleteObject( hPen );
175 /* the vertical arrows are:
185 PAGER_DrawVertArrow (HDC hdc, RECT r, INT colorRef, BOOL up)
190 w = r.right - r.left + 1;
191 h = r.bottom - r.top + 1;
192 if ((h < MIN_ARROW_WIDTH) || (w < MIN_ARROW_HEIGHT))
193 return; /* refuse to draw partial arrow */
195 if (!(hPen = CreatePen( PS_SOLID, 1, GetSysColor( colorRef )))) return;
196 hOldPen = SelectObject ( hdc, hPen );
199 x = r.left + ((w - MIN_ARROW_HEIGHT) / 2) + 1;
200 y = r.top + ((h - MIN_ARROW_WIDTH) / 2) + 3;
201 MoveToEx (hdc, x, y, NULL);
202 LineTo (hdc, x+5, y--); x++;
203 MoveToEx (hdc, x, y, NULL);
204 LineTo (hdc, x+3, y--); x++;
205 MoveToEx (hdc, x, y, NULL);
206 LineTo (hdc, x+1, y);
210 x = r.left + ((w - MIN_ARROW_HEIGHT) / 2) + 1;
211 y = r.top + ((h - MIN_ARROW_WIDTH) / 2) + 1;
212 MoveToEx (hdc, x, y, NULL);
213 LineTo (hdc, x+5, y++); x++;
214 MoveToEx (hdc, x, y, NULL);
215 LineTo (hdc, x+3, y++); x++;
216 MoveToEx (hdc, x, y, NULL);
217 LineTo (hdc, x+1, y);
220 SelectObject( hdc, hOldPen );
221 DeleteObject( hPen );
225 PAGER_DrawButton(HDC hdc, COLORREF clrBk, RECT arrowRect,
226 BOOL horz, BOOL topLeft, INT btnState)
228 HBRUSH hBrush, hOldBrush;
231 TRACE("arrowRect = %s, btnState = %d\n", wine_dbgstr_rect(&arrowRect), btnState);
233 if (btnState == PGF_INVISIBLE)
236 if ((rc.right - rc.left <= 0) || (rc.bottom - rc.top <= 0))
239 hBrush = CreateSolidBrush(clrBk);
240 hOldBrush = (HBRUSH)SelectObject(hdc, hBrush);
242 FillRect(hdc, &rc, hBrush);
244 if (btnState == PGF_HOT)
246 DrawEdge( hdc, &rc, BDR_RAISEDINNER, BF_RECT);
248 PAGER_DrawHorzArrow(hdc, rc, COLOR_WINDOWFRAME, topLeft);
250 PAGER_DrawVertArrow(hdc, rc, COLOR_WINDOWFRAME, topLeft);
252 else if (btnState == PGF_NORMAL)
254 DrawEdge (hdc, &rc, BDR_OUTER, BF_FLAT);
256 PAGER_DrawHorzArrow(hdc, rc, COLOR_WINDOWFRAME, topLeft);
258 PAGER_DrawVertArrow(hdc, rc, COLOR_WINDOWFRAME, topLeft);
260 else if (btnState == PGF_DEPRESSED)
262 DrawEdge( hdc, &rc, BDR_SUNKENOUTER, BF_RECT);
264 PAGER_DrawHorzArrow(hdc, rc, COLOR_WINDOWFRAME, topLeft);
266 PAGER_DrawVertArrow(hdc, rc, COLOR_WINDOWFRAME, topLeft);
268 else if (btnState == PGF_GRAYED)
270 DrawEdge (hdc, &rc, BDR_OUTER, BF_FLAT);
273 PAGER_DrawHorzArrow(hdc, rc, COLOR_3DHIGHLIGHT, topLeft);
274 rc.left++, rc.top++; rc.right++, rc.bottom++;
275 PAGER_DrawHorzArrow(hdc, rc, COLOR_3DSHADOW, topLeft);
279 PAGER_DrawVertArrow(hdc, rc, COLOR_3DHIGHLIGHT, topLeft);
280 rc.left++, rc.top++; rc.right++, rc.bottom++;
281 PAGER_DrawVertArrow(hdc, rc, COLOR_3DSHADOW, topLeft);
285 SelectObject( hdc, hOldBrush );
286 DeleteObject(hBrush);
289 /* << PAGER_GetDropTarget >> */
291 static inline LRESULT
292 PAGER_ForwardMouse (PAGER_INFO* infoPtr, BOOL bFwd)
294 TRACE("[%p]\n", infoPtr->hwndSelf);
296 infoPtr->bForward = bFwd;
301 static inline LRESULT
302 PAGER_GetButtonState (PAGER_INFO* infoPtr, INT btn)
304 LRESULT btnState = PGF_INVISIBLE;
305 TRACE("[%p]\n", infoPtr->hwndSelf);
307 if (btn == PGB_TOPORLEFT)
308 btnState = infoPtr->TLbtnState;
309 else if (btn == PGB_BOTTOMORRIGHT)
310 btnState = infoPtr->BRbtnState;
317 PAGER_GetPos(PAGER_INFO *infoPtr)
319 TRACE("[%p] returns %d\n", infoPtr->hwndSelf, infoPtr->nPos);
320 return infoPtr->nPos;
324 PAGER_GetButtonSize(PAGER_INFO *infoPtr)
326 TRACE("[%p] returns %d\n", infoPtr->hwndSelf, infoPtr->nButtonSize);
327 return infoPtr->nButtonSize;
331 PAGER_GetBorder(PAGER_INFO *infoPtr)
333 TRACE("[%p] returns %d\n", infoPtr->hwndSelf, infoPtr->nBorder);
334 return infoPtr->nBorder;
337 static inline COLORREF
338 PAGER_GetBkColor(PAGER_INFO *infoPtr)
340 TRACE("[%p] returns %06x\n", infoPtr->hwndSelf, infoPtr->clrBk);
341 return infoPtr->clrBk;
345 PAGER_CalcSize (PAGER_INFO *infoPtr, INT* size, BOOL getWidth)
348 ZeroMemory (&nmpgcs, sizeof (NMPGCALCSIZE));
349 nmpgcs.hdr.hwndFrom = infoPtr->hwndSelf;
350 nmpgcs.hdr.idFrom = GetWindowLongPtrW (infoPtr->hwndSelf, GWLP_ID);
351 nmpgcs.hdr.code = PGN_CALCSIZE;
352 nmpgcs.dwFlag = getWidth ? PGF_CALCWIDTH : PGF_CALCHEIGHT;
353 nmpgcs.iWidth = getWidth ? *size : 0;
354 nmpgcs.iHeight = getWidth ? 0 : *size;
355 SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
356 (WPARAM)nmpgcs.hdr.idFrom, (LPARAM)&nmpgcs);
358 *size = getWidth ? nmpgcs.iWidth : nmpgcs.iHeight;
360 TRACE("[%p] PGN_CALCSIZE returns %s=%d\n", infoPtr->hwndSelf,
361 getWidth ? "width" : "height", *size);
365 PAGER_PositionChildWnd(PAGER_INFO* infoPtr)
367 if (infoPtr->hwndChild)
370 int nPos = infoPtr->nPos;
372 /* compensate for a grayed btn, which will soon become invisible */
373 if (infoPtr->TLbtnState == PGF_GRAYED)
374 nPos += infoPtr->nButtonSize;
376 GetClientRect(infoPtr->hwndSelf, &rcClient);
378 if (infoPtr->dwStyle & PGS_HORZ)
380 int wndSize = max(0, rcClient.right - rcClient.left);
381 if (infoPtr->nWidth < wndSize)
382 infoPtr->nWidth = wndSize;
384 TRACE("[%p] SWP %dx%d at (%d,%d)\n", infoPtr->hwndSelf,
385 infoPtr->nWidth, infoPtr->nHeight,
387 SetWindowPos(infoPtr->hwndChild, 0,
389 infoPtr->nWidth, infoPtr->nHeight,
394 int wndSize = max(0, rcClient.bottom - rcClient.top);
395 if (infoPtr->nHeight < wndSize)
396 infoPtr->nHeight = wndSize;
398 TRACE("[%p] SWP %dx%d at (%d,%d)\n", infoPtr->hwndSelf,
399 infoPtr->nWidth, infoPtr->nHeight,
401 SetWindowPos(infoPtr->hwndChild, 0,
403 infoPtr->nWidth, infoPtr->nHeight,
407 InvalidateRect(infoPtr->hwndChild, NULL, TRUE);
412 PAGER_GetScrollRange(PAGER_INFO* infoPtr)
416 if (infoPtr->hwndChild)
418 INT wndSize, childSize;
420 GetWindowRect(infoPtr->hwndSelf, &wndRect);
422 if (infoPtr->dwStyle & PGS_HORZ)
424 wndSize = wndRect.right - wndRect.left;
425 PAGER_CalcSize(infoPtr, &infoPtr->nWidth, TRUE);
426 childSize = infoPtr->nWidth;
430 wndSize = wndRect.bottom - wndRect.top;
431 PAGER_CalcSize(infoPtr, &infoPtr->nHeight, FALSE);
432 childSize = infoPtr->nHeight;
435 TRACE("childSize = %d, wndSize = %d\n", childSize, wndSize);
436 if (childSize > wndSize)
437 scrollRange = childSize - wndSize + infoPtr->nButtonSize;
440 TRACE("[%p] returns %d\n", infoPtr->hwndSelf, scrollRange);
445 PAGER_UpdateBtns(PAGER_INFO *infoPtr, INT scrollRange, BOOL hideGrayBtns)
449 INT oldTLbtnState = infoPtr->TLbtnState;
450 INT oldBRbtnState = infoPtr->BRbtnState;
452 RECT rcTopLeft, rcBottomRight;
454 /* get button rects */
455 PAGER_GetButtonRects(infoPtr, &rcTopLeft, &rcBottomRight, FALSE);
459 /* update states based on scroll position */
460 if (infoPtr->nPos > 0)
462 if (infoPtr->TLbtnState == PGF_INVISIBLE || infoPtr->TLbtnState == PGF_GRAYED)
463 infoPtr->TLbtnState = PGF_NORMAL;
465 else if (PtInRect(&rcTopLeft, pt))
466 infoPtr->TLbtnState = PGF_GRAYED;
468 infoPtr->TLbtnState = PGF_INVISIBLE;
470 if (scrollRange <= 0)
472 infoPtr->TLbtnState = PGF_INVISIBLE;
473 infoPtr->BRbtnState = PGF_INVISIBLE;
475 else if (infoPtr->nPos < scrollRange)
477 if (infoPtr->BRbtnState == PGF_INVISIBLE || infoPtr->BRbtnState == PGF_GRAYED)
478 infoPtr->BRbtnState = PGF_NORMAL;
480 else if (PtInRect(&rcBottomRight, pt))
481 infoPtr->BRbtnState = PGF_GRAYED;
483 infoPtr->BRbtnState = PGF_INVISIBLE;
485 /* only need to resize when entering or leaving PGF_INVISIBLE state */
487 ((oldTLbtnState == PGF_INVISIBLE) != (infoPtr->TLbtnState == PGF_INVISIBLE)) ||
488 ((oldBRbtnState == PGF_INVISIBLE) != (infoPtr->BRbtnState == PGF_INVISIBLE));
489 /* initiate NCCalcSize to resize client wnd if necessary */
491 SetWindowPos(infoPtr->hwndSelf, 0, 0, 0, 0, 0,
492 SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE |
493 SWP_NOZORDER | SWP_NOACTIVATE);
495 /* repaint when changing any state */
496 repaintBtns = (oldTLbtnState != infoPtr->TLbtnState) ||
497 (oldBRbtnState != infoPtr->BRbtnState);
499 SendMessageW(infoPtr->hwndSelf, WM_NCPAINT, 0, 0);
503 PAGER_SetPos(PAGER_INFO* infoPtr, INT newPos, BOOL fromBtnPress)
505 INT scrollRange = PAGER_GetScrollRange(infoPtr);
506 INT oldPos = infoPtr->nPos;
508 if ((scrollRange <= 0) || (newPos < 0))
510 else if (newPos > scrollRange)
511 infoPtr->nPos = scrollRange;
513 infoPtr->nPos = newPos;
515 TRACE("[%p] pos=%d, oldpos=%d\n", infoPtr->hwndSelf, infoPtr->nPos, oldPos);
517 if (infoPtr->nPos != oldPos)
519 /* gray and restore btns, and if from WM_SETPOS, hide the gray btns */
520 PAGER_UpdateBtns(infoPtr, scrollRange, !fromBtnPress);
521 PAGER_PositionChildWnd(infoPtr);
528 PAGER_WindowPosChanging(PAGER_INFO* infoPtr, WINDOWPOS *winpos)
530 if ((infoPtr->dwStyle & CCS_NORESIZE) && !(winpos->flags & SWP_NOSIZE))
532 /* don't let the app resize the nonscrollable dimension of a control
533 * that was created with CCS_NORESIZE style
534 * (i.e. height for a horizontal pager, or width for a vertical one) */
536 /* except if the current dimension is 0 and app is setting for
537 * first time, then save amount as dimension. - GA 8/01 */
539 if (infoPtr->dwStyle & PGS_HORZ)
540 if (!infoPtr->nHeight && winpos->cy)
541 infoPtr->nHeight = winpos->cy;
543 winpos->cy = infoPtr->nHeight;
545 if (!infoPtr->nWidth && winpos->cx)
546 infoPtr->nWidth = winpos->cx;
548 winpos->cx = infoPtr->nWidth;
552 return DefWindowProcW (infoPtr->hwndSelf, WM_WINDOWPOSCHANGING, 0, (LPARAM)winpos);
556 PAGER_SetFixedWidth(PAGER_INFO* infoPtr)
558 /* Must set the non-scrollable dimension to be less than the full height/width
559 * so that NCCalcSize is called. The Msoft docs mention 3/4 factor for button
560 * size, and experimentation shows that affect is almost right. */
564 GetWindowRect(infoPtr->hwndSelf, &wndRect);
566 /* see what the app says for btn width */
567 PAGER_CalcSize(infoPtr, &infoPtr->nWidth, TRUE);
569 if (infoPtr->dwStyle & CCS_NORESIZE)
571 delta = wndRect.right - wndRect.left - infoPtr->nWidth;
572 if (delta > infoPtr->nButtonSize)
573 infoPtr->nWidth += 4 * infoPtr->nButtonSize / 3;
575 infoPtr->nWidth += infoPtr->nButtonSize / 3;
578 h = wndRect.bottom - wndRect.top + infoPtr->nButtonSize;
580 TRACE("[%p] infoPtr->nWidth set to %d\n",
581 infoPtr->hwndSelf, infoPtr->nWidth);
587 PAGER_SetFixedHeight(PAGER_INFO* infoPtr)
589 /* Must set the non-scrollable dimension to be less than the full height/width
590 * so that NCCalcSize is called. The Msoft docs mention 3/4 factor for button
591 * size, and experimentation shows that affect is almost right. */
595 GetWindowRect(infoPtr->hwndSelf, &wndRect);
597 /* see what the app says for btn height */
598 PAGER_CalcSize(infoPtr, &infoPtr->nHeight, FALSE);
600 if (infoPtr->dwStyle & CCS_NORESIZE)
602 delta = wndRect.bottom - wndRect.top - infoPtr->nHeight;
603 if (delta > infoPtr->nButtonSize)
604 infoPtr->nHeight += infoPtr->nButtonSize;
606 infoPtr->nHeight += infoPtr->nButtonSize / 3;
609 w = wndRect.right - wndRect.left + infoPtr->nButtonSize;
611 TRACE("[%p] infoPtr->nHeight set to %d\n",
612 infoPtr->hwndSelf, infoPtr->nHeight);
617 /******************************************************************
618 * For the PGM_RECALCSIZE message (but not the other uses in *
619 * this module), the native control does only the following: *
621 * if (some condition) *
622 * PostMessageW(hwnd, EM_FMTLINES, 0, 0); *
623 * return DefWindowProcW(hwnd, PGM_RECALCSIZE, 0, 0); *
625 * When we figure out what the "some condition" is we will *
626 * implement that for the message processing. *
627 ******************************************************************/
630 PAGER_RecalcSize(PAGER_INFO *infoPtr)
632 TRACE("[%p]\n", infoPtr->hwndSelf);
634 if (infoPtr->hwndChild)
636 INT scrollRange = PAGER_GetScrollRange(infoPtr);
638 if (scrollRange <= 0)
641 PAGER_SetPos(infoPtr, 0, FALSE);
644 PAGER_PositionChildWnd(infoPtr);
652 PAGER_SetBkColor (PAGER_INFO* infoPtr, COLORREF clrBk)
654 COLORREF clrTemp = infoPtr->clrBk;
656 infoPtr->clrBk = clrBk;
657 TRACE("[%p] %06x\n", infoPtr->hwndSelf, infoPtr->clrBk);
659 /* the native control seems to do things this way */
660 SetWindowPos(infoPtr->hwndSelf, 0, 0, 0, 0, 0,
661 SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE |
662 SWP_NOZORDER | SWP_NOACTIVATE);
664 RedrawWindow(infoPtr->hwndSelf, 0, 0, RDW_ERASE | RDW_INVALIDATE);
671 PAGER_SetBorder (PAGER_INFO* infoPtr, INT iBorder)
673 INT nTemp = infoPtr->nBorder;
675 infoPtr->nBorder = iBorder;
676 TRACE("[%p] %d\n", infoPtr->hwndSelf, infoPtr->nBorder);
678 PAGER_RecalcSize(infoPtr);
685 PAGER_SetButtonSize (PAGER_INFO* infoPtr, INT iButtonSize)
687 INT nTemp = infoPtr->nButtonSize;
689 infoPtr->nButtonSize = iButtonSize;
690 TRACE("[%p] %d\n", infoPtr->hwndSelf, infoPtr->nButtonSize);
692 PAGER_RecalcSize(infoPtr);
699 PAGER_SetChild (PAGER_INFO* infoPtr, HWND hwndChild)
703 infoPtr->hwndChild = IsWindow (hwndChild) ? hwndChild : 0;
705 if (infoPtr->hwndChild)
707 TRACE("[%p] hwndChild=%p\n", infoPtr->hwndSelf, infoPtr->hwndChild);
709 if (infoPtr->dwStyle & PGS_HORZ) {
710 hw = PAGER_SetFixedHeight(infoPtr);
711 /* adjust non-scrollable dimension to fit the child */
712 SetWindowPos(infoPtr->hwndSelf, 0, 0, 0, hw, infoPtr->nHeight,
713 SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOZORDER |
714 SWP_NOSIZE | SWP_NOACTIVATE);
717 hw = PAGER_SetFixedWidth(infoPtr);
718 /* adjust non-scrollable dimension to fit the child */
719 SetWindowPos(infoPtr->hwndSelf, 0, 0, 0, infoPtr->nWidth, hw,
720 SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOZORDER |
721 SWP_NOSIZE | SWP_NOACTIVATE);
724 /* position child within the page scroller */
725 SetWindowPos(infoPtr->hwndChild, HWND_TOP,
727 SWP_SHOWWINDOW | SWP_NOSIZE); /* native is 0 */
730 PAGER_SetPos(infoPtr, 0, FALSE);
737 PAGER_Scroll(PAGER_INFO* infoPtr, INT dir)
739 NMPGSCROLL nmpgScroll;
742 if (infoPtr->hwndChild)
744 ZeroMemory (&nmpgScroll, sizeof (NMPGSCROLL));
745 nmpgScroll.hdr.hwndFrom = infoPtr->hwndSelf;
746 nmpgScroll.hdr.idFrom = GetWindowLongPtrW (infoPtr->hwndSelf, GWLP_ID);
747 nmpgScroll.hdr.code = PGN_SCROLL;
749 GetWindowRect(infoPtr->hwndSelf, &rcWnd);
750 GetClientRect(infoPtr->hwndSelf, &nmpgScroll.rcParent);
751 nmpgScroll.iXpos = nmpgScroll.iYpos = 0;
752 nmpgScroll.iDir = dir;
754 if (infoPtr->dwStyle & PGS_HORZ)
756 nmpgScroll.iScroll = rcWnd.right - rcWnd.left;
757 nmpgScroll.iXpos = infoPtr->nPos;
761 nmpgScroll.iScroll = rcWnd.bottom - rcWnd.top;
762 nmpgScroll.iYpos = infoPtr->nPos;
764 nmpgScroll.iScroll -= 2*infoPtr->nButtonSize;
766 SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
767 (WPARAM)nmpgScroll.hdr.idFrom, (LPARAM)&nmpgScroll);
769 TRACE("[%p] PGN_SCROLL returns iScroll=%d\n", infoPtr->hwndSelf, nmpgScroll.iScroll);
771 if (nmpgScroll.iScroll > 0)
773 infoPtr->direction = dir;
775 if (dir == PGF_SCROLLLEFT || dir == PGF_SCROLLUP)
776 PAGER_SetPos(infoPtr, infoPtr->nPos - nmpgScroll.iScroll, TRUE);
778 PAGER_SetPos(infoPtr, infoPtr->nPos + nmpgScroll.iScroll, TRUE);
781 infoPtr->direction = -1;
786 PAGER_FmtLines(PAGER_INFO *infoPtr)
788 /* initiate NCCalcSize to resize client wnd and get size */
789 SetWindowPos(infoPtr->hwndSelf, 0, 0, 0, 0, 0,
790 SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE |
791 SWP_NOZORDER | SWP_NOACTIVATE);
793 SetWindowPos(infoPtr->hwndChild, 0,
794 0,0,infoPtr->nWidth,infoPtr->nHeight,
797 return DefWindowProcW (infoPtr->hwndSelf, EM_FMTLINES, 0, 0);
801 PAGER_Create (HWND hwnd, LPCREATESTRUCTW lpcs)
805 /* allocate memory for info structure */
806 infoPtr = (PAGER_INFO *)Alloc (sizeof(PAGER_INFO));
807 if (!infoPtr) return -1;
808 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
810 /* set default settings */
811 infoPtr->hwndSelf = hwnd;
812 infoPtr->hwndChild = NULL;
813 infoPtr->hwndNotify = lpcs->hwndParent;
814 infoPtr->dwStyle = lpcs->style;
815 infoPtr->clrBk = GetSysColor(COLOR_BTNFACE);
816 infoPtr->nBorder = 0;
817 infoPtr->nButtonSize = 12;
820 infoPtr->nHeight = 0;
821 infoPtr->bForward = FALSE;
822 infoPtr->bCapture = FALSE;
823 infoPtr->TLbtnState = PGF_INVISIBLE;
824 infoPtr->BRbtnState = PGF_INVISIBLE;
825 infoPtr->direction = -1;
827 if (infoPtr->dwStyle & PGS_DRAGNDROP)
828 FIXME("[%p] Drag and Drop style is not implemented yet.\n", infoPtr->hwndSelf);
835 PAGER_Destroy (PAGER_INFO *infoPtr)
837 SetWindowLongPtrW (infoPtr->hwndSelf, 0, 0);
838 Free (infoPtr); /* free pager info data */
843 PAGER_NCCalcSize(PAGER_INFO* infoPtr, WPARAM wParam, LPRECT lpRect)
845 RECT rcChild, rcWindow;
849 * lpRect points to a RECT struct. On entry, the struct
850 * contains the proposed wnd rectangle for the window.
851 * On exit, the struct should contain the screen
852 * coordinates of the corresponding window's client area.
855 DefWindowProcW (infoPtr->hwndSelf, WM_NCCALCSIZE, wParam, (LPARAM)lpRect);
857 TRACE("orig rect=%s\n", wine_dbgstr_rect(lpRect));
859 GetWindowRect (infoPtr->hwndChild, &rcChild);
860 MapWindowPoints (0, infoPtr->hwndSelf, (LPPOINT)&rcChild, 2); /* FIXME: RECT != 2 POINTS */
861 GetWindowRect (infoPtr->hwndSelf, &rcWindow);
863 if (infoPtr->dwStyle & PGS_HORZ)
865 infoPtr->nWidth = lpRect->right - lpRect->left;
866 PAGER_CalcSize (infoPtr, &infoPtr->nWidth, TRUE);
868 scrollRange = infoPtr->nWidth - (rcWindow.right - rcWindow.left);
870 if (infoPtr->TLbtnState && (lpRect->left + infoPtr->nButtonSize < lpRect->right))
871 lpRect->left += infoPtr->nButtonSize;
872 if (infoPtr->BRbtnState && (lpRect->right - infoPtr->nButtonSize > lpRect->left))
873 lpRect->right -= infoPtr->nButtonSize;
877 infoPtr->nHeight = lpRect->bottom - lpRect->top;
878 PAGER_CalcSize (infoPtr, &infoPtr->nHeight, FALSE);
880 scrollRange = infoPtr->nHeight - (rcWindow.bottom - rcWindow.top);
882 if (infoPtr->TLbtnState && (lpRect->top + infoPtr->nButtonSize < lpRect->bottom))
883 lpRect->top += infoPtr->nButtonSize;
884 if (infoPtr->BRbtnState && (lpRect->bottom - infoPtr->nButtonSize > lpRect->top))
885 lpRect->bottom -= infoPtr->nButtonSize;
888 TRACE("nPos=%d, nHeight=%d, window=%s\n",
889 infoPtr->nPos, infoPtr->nHeight,
890 wine_dbgstr_rect(&rcWindow));
892 TRACE("[%p] client rect set to %dx%d at (%d,%d) BtnState[%d,%d]\n",
893 infoPtr->hwndSelf, lpRect->right-lpRect->left, lpRect->bottom-lpRect->top,
894 lpRect->left, lpRect->top,
895 infoPtr->TLbtnState, infoPtr->BRbtnState);
901 PAGER_NCPaint (PAGER_INFO* infoPtr, HRGN hRgn)
903 RECT rcBottomRight, rcTopLeft;
906 if (infoPtr->dwStyle & WS_MINIMIZE)
909 DefWindowProcW (infoPtr->hwndSelf, WM_NCPAINT, (WPARAM)hRgn, 0);
911 if (!(hdc = GetDCEx (infoPtr->hwndSelf, 0, DCX_USESTYLE | DCX_WINDOW)))
914 PAGER_GetButtonRects(infoPtr, &rcTopLeft, &rcBottomRight, FALSE);
916 PAGER_DrawButton(hdc, infoPtr->clrBk, rcTopLeft,
917 infoPtr->dwStyle & PGS_HORZ, TRUE, infoPtr->TLbtnState);
918 PAGER_DrawButton(hdc, infoPtr->clrBk, rcBottomRight,
919 infoPtr->dwStyle & PGS_HORZ, FALSE, infoPtr->BRbtnState);
921 ReleaseDC( infoPtr->hwndSelf, hdc );
926 PAGER_HitTest (PAGER_INFO* infoPtr, const POINT * pt)
928 RECT clientRect, rcTopLeft, rcBottomRight;
931 GetClientRect (infoPtr->hwndSelf, &clientRect);
933 if (PtInRect(&clientRect, *pt))
940 PAGER_GetButtonRects(infoPtr, &rcTopLeft, &rcBottomRight, TRUE);
942 if ((infoPtr->TLbtnState != PGF_INVISIBLE) && PtInRect(&rcTopLeft, ptWindow))
944 TRACE("PGB_TOPORLEFT\n");
945 return PGB_TOPORLEFT;
947 else if ((infoPtr->BRbtnState != PGF_INVISIBLE) && PtInRect(&rcBottomRight, ptWindow))
949 TRACE("PGB_BOTTOMORRIGHT\n");
950 return PGB_BOTTOMORRIGHT;
958 PAGER_NCHitTest (PAGER_INFO* infoPtr, INT x, INT y)
966 ScreenToClient (infoPtr->hwndSelf, &pt);
967 nHit = PAGER_HitTest(infoPtr, &pt);
969 return (nHit < 0) ? HTTRANSPARENT : HTCLIENT;
973 PAGER_MouseMove (PAGER_INFO* infoPtr, INT keys, INT x, INT y)
976 RECT wnrect, *btnrect = NULL;
977 BOOL topLeft = FALSE;
985 TRACE("[%p] to (%d,%d)\n", infoPtr->hwndSelf, x, y);
986 ClientToScreen(infoPtr->hwndSelf, &pt);
987 GetWindowRect(infoPtr->hwndSelf, &wnrect);
988 if (PtInRect(&wnrect, pt)) {
989 RECT TLbtnrect, BRbtnrect;
990 PAGER_GetButtonRects(infoPtr, &TLbtnrect, &BRbtnrect, FALSE);
993 MapWindowPoints(0, infoPtr->hwndSelf, &clpt, 1);
994 hit = PAGER_HitTest(infoPtr, &clpt);
995 if ((hit == PGB_TOPORLEFT) && (infoPtr->TLbtnState == PGF_NORMAL))
998 btnrect = &TLbtnrect;
999 infoPtr->TLbtnState = PGF_HOT;
1000 btnstate = infoPtr->TLbtnState;
1002 else if ((hit == PGB_BOTTOMORRIGHT) && (infoPtr->BRbtnState == PGF_NORMAL))
1005 btnrect = &BRbtnrect;
1006 infoPtr->BRbtnState = PGF_HOT;
1007 btnstate = infoPtr->BRbtnState;
1010 /* If in one of the buttons the capture and draw buttons */
1013 TRACE("[%p] draw btn (%d,%d)-(%d,%d), Capture %s, style %08x\n",
1014 infoPtr->hwndSelf, btnrect->left, btnrect->top,
1015 btnrect->right, btnrect->bottom,
1016 (infoPtr->bCapture) ? "TRUE" : "FALSE",
1018 if (!infoPtr->bCapture)
1020 TRACE("[%p] SetCapture\n", infoPtr->hwndSelf);
1021 SetCapture(infoPtr->hwndSelf);
1022 infoPtr->bCapture = TRUE;
1024 if (infoPtr->dwStyle & PGS_AUTOSCROLL)
1025 SetTimer(infoPtr->hwndSelf, TIMERID1, 0x3e, 0);
1026 hdc = GetWindowDC(infoPtr->hwndSelf);
1027 /* OffsetRect(wnrect, 0 | 1, 0 | 1) */
1028 PAGER_DrawButton(hdc, infoPtr->clrBk, *btnrect,
1029 infoPtr->dwStyle & PGS_HORZ, topLeft, btnstate);
1030 ReleaseDC(infoPtr->hwndSelf, hdc);
1035 /* If we think we are captured, then do release */
1036 if (infoPtr->bCapture && (WindowFromPoint(pt) != infoPtr->hwndSelf))
1040 infoPtr->bCapture = FALSE;
1042 if (GetCapture() == infoPtr->hwndSelf)
1046 if (infoPtr->TLbtnState == PGF_GRAYED)
1048 infoPtr->TLbtnState = PGF_INVISIBLE;
1049 SetWindowPos(infoPtr->hwndSelf, 0, 0, 0, 0, 0,
1050 SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE |
1051 SWP_NOZORDER | SWP_NOACTIVATE);
1053 else if (infoPtr->TLbtnState == PGF_HOT)
1055 infoPtr->TLbtnState = PGF_NORMAL;
1056 /* FIXME: just invalidate button rect */
1057 RedrawWindow(infoPtr->hwndSelf, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
1060 if (infoPtr->BRbtnState == PGF_GRAYED)
1062 infoPtr->BRbtnState = PGF_INVISIBLE;
1063 SetWindowPos(infoPtr->hwndSelf, 0, 0, 0, 0, 0,
1064 SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE |
1065 SWP_NOZORDER | SWP_NOACTIVATE);
1067 else if (infoPtr->BRbtnState == PGF_HOT)
1069 infoPtr->BRbtnState = PGF_NORMAL;
1070 /* FIXME: just invalidate button rect */
1071 RedrawWindow(infoPtr->hwndSelf, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
1074 /* Notify parent of released mouse capture */
1075 memset(&nmhdr, 0, sizeof(NMHDR));
1076 nmhdr.hwndFrom = infoPtr->hwndSelf;
1077 nmhdr.idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
1078 nmhdr.code = NM_RELEASEDCAPTURE;
1079 SendMessageW(infoPtr->hwndNotify, WM_NOTIFY,
1080 (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
1082 if (IsWindow(infoPtr->hwndSelf))
1083 KillTimer(infoPtr->hwndSelf, TIMERID1);
1089 PAGER_LButtonDown (PAGER_INFO* infoPtr, INT keys, INT x, INT y)
1091 BOOL repaintBtns = FALSE;
1098 TRACE("[%p] at (%d,%d)\n", infoPtr->hwndSelf, x, y);
1100 hit = PAGER_HitTest(infoPtr, &pt);
1102 /* put btn in DEPRESSED state */
1103 if (hit == PGB_TOPORLEFT)
1105 repaintBtns = infoPtr->TLbtnState != PGF_DEPRESSED;
1106 infoPtr->TLbtnState = PGF_DEPRESSED;
1107 SetTimer(infoPtr->hwndSelf, TIMERID1, INITIAL_DELAY, 0);
1109 else if (hit == PGB_BOTTOMORRIGHT)
1111 repaintBtns = infoPtr->BRbtnState != PGF_DEPRESSED;
1112 infoPtr->BRbtnState = PGF_DEPRESSED;
1113 SetTimer(infoPtr->hwndSelf, TIMERID1, INITIAL_DELAY, 0);
1117 SendMessageW(infoPtr->hwndSelf, WM_NCPAINT, 0, 0);
1122 if (infoPtr->dwStyle & PGS_HORZ)
1124 TRACE("[%p] PGF_SCROLLLEFT\n", infoPtr->hwndSelf);
1125 PAGER_Scroll(infoPtr, PGF_SCROLLLEFT);
1129 TRACE("[%p] PGF_SCROLLUP\n", infoPtr->hwndSelf);
1130 PAGER_Scroll(infoPtr, PGF_SCROLLUP);
1133 case PGB_BOTTOMORRIGHT:
1134 if (infoPtr->dwStyle & PGS_HORZ)
1136 TRACE("[%p] PGF_SCROLLRIGHT\n", infoPtr->hwndSelf);
1137 PAGER_Scroll(infoPtr, PGF_SCROLLRIGHT);
1141 TRACE("[%p] PGF_SCROLLDOWN\n", infoPtr->hwndSelf);
1142 PAGER_Scroll(infoPtr, PGF_SCROLLDOWN);
1153 PAGER_LButtonUp (PAGER_INFO* infoPtr, INT keys, INT x, INT y)
1155 TRACE("[%p]\n", infoPtr->hwndSelf);
1157 KillTimer (infoPtr->hwndSelf, TIMERID1);
1158 KillTimer (infoPtr->hwndSelf, TIMERID2);
1160 /* make PRESSED btns NORMAL but don't hide gray btns */
1161 if (infoPtr->TLbtnState & (PGF_HOT | PGF_DEPRESSED))
1162 infoPtr->TLbtnState = PGF_NORMAL;
1163 if (infoPtr->BRbtnState & (PGF_HOT | PGF_DEPRESSED))
1164 infoPtr->BRbtnState = PGF_NORMAL;
1170 PAGER_Timer (PAGER_INFO* infoPtr, INT nTimerId)
1174 /* if initial timer, kill it and start the repeat timer */
1175 if (nTimerId == TIMERID1) {
1176 if (infoPtr->TLbtnState == PGF_HOT)
1177 dir = (infoPtr->dwStyle & PGS_HORZ) ?
1178 PGF_SCROLLLEFT : PGF_SCROLLUP;
1180 dir = (infoPtr->dwStyle & PGS_HORZ) ?
1181 PGF_SCROLLRIGHT : PGF_SCROLLDOWN;
1182 TRACE("[%p] TIMERID1: style=%08x, dir=%d\n",
1183 infoPtr->hwndSelf, infoPtr->dwStyle, dir);
1184 KillTimer(infoPtr->hwndSelf, TIMERID1);
1185 SetTimer(infoPtr->hwndSelf, TIMERID1, REPEAT_DELAY, 0);
1186 if (infoPtr->dwStyle & PGS_AUTOSCROLL) {
1187 PAGER_Scroll(infoPtr, dir);
1188 SetWindowPos(infoPtr->hwndSelf, 0, 0, 0, 0, 0,
1189 SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE |
1190 SWP_NOZORDER | SWP_NOACTIVATE);
1196 TRACE("[%p] TIMERID2: dir=%d\n", infoPtr->hwndSelf, infoPtr->direction);
1197 KillTimer(infoPtr->hwndSelf, TIMERID2);
1198 if (infoPtr->direction > 0) {
1199 PAGER_Scroll(infoPtr, infoPtr->direction);
1200 SetTimer(infoPtr->hwndSelf, TIMERID2, REPEAT_DELAY, 0);
1206 PAGER_EraseBackground (PAGER_INFO* infoPtr, HDC hdc)
1213 parent = GetParent(infoPtr->hwndSelf);
1214 MapWindowPoints(infoPtr->hwndSelf, parent, &pt, 1);
1215 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
1216 SendMessageW (parent, WM_ERASEBKGND, (WPARAM)hdc, 0);
1217 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
1224 PAGER_Size (PAGER_INFO* infoPtr, INT type, INT x, INT y)
1226 /* note that WM_SIZE is sent whenever NCCalcSize resizes the client wnd */
1228 TRACE("[%p] %d,%d\n", infoPtr->hwndSelf, x, y);
1230 if (infoPtr->dwStyle & PGS_HORZ)
1231 infoPtr->nHeight = y;
1233 infoPtr->nWidth = x;
1235 return PAGER_RecalcSize(infoPtr);
1240 PAGER_StyleChanged(PAGER_INFO *infoPtr, WPARAM wStyleType, LPSTYLESTRUCT lpss)
1242 DWORD oldStyle = infoPtr->dwStyle;
1244 TRACE("(styletype=%x, styleOld=0x%08x, styleNew=0x%08x)\n",
1245 wStyleType, lpss->styleOld, lpss->styleNew);
1247 if (wStyleType != GWL_STYLE) return 0;
1249 infoPtr->dwStyle = lpss->styleNew;
1251 if ((oldStyle ^ lpss->styleNew) & (PGS_HORZ | PGS_VERT))
1253 PAGER_RecalcSize(infoPtr);
1259 static LRESULT WINAPI
1260 PAGER_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1262 PAGER_INFO *infoPtr = (PAGER_INFO *)GetWindowLongPtrW(hwnd, 0);
1264 if (!infoPtr && (uMsg != WM_CREATE))
1265 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
1270 return PAGER_FmtLines(infoPtr);
1272 case PGM_FORWARDMOUSE:
1273 return PAGER_ForwardMouse (infoPtr, (BOOL)wParam);
1275 case PGM_GETBKCOLOR:
1276 return PAGER_GetBkColor(infoPtr);
1279 return PAGER_GetBorder(infoPtr);
1281 case PGM_GETBUTTONSIZE:
1282 return PAGER_GetButtonSize(infoPtr);
1285 return PAGER_GetPos(infoPtr);
1287 case PGM_GETBUTTONSTATE:
1288 return PAGER_GetButtonState (infoPtr, (INT)lParam);
1290 /* case PGM_GETDROPTARGET: */
1292 case PGM_RECALCSIZE:
1293 return PAGER_RecalcSize(infoPtr);
1295 case PGM_SETBKCOLOR:
1296 return PAGER_SetBkColor (infoPtr, (COLORREF)lParam);
1299 return PAGER_SetBorder (infoPtr, (INT)lParam);
1301 case PGM_SETBUTTONSIZE:
1302 return PAGER_SetButtonSize (infoPtr, (INT)lParam);
1305 return PAGER_SetChild (infoPtr, (HWND)lParam);
1308 return PAGER_SetPos(infoPtr, (INT)lParam, FALSE);
1311 return PAGER_Create (hwnd, (LPCREATESTRUCTW)lParam);
1314 return PAGER_Destroy (infoPtr);
1317 return PAGER_Size (infoPtr, (INT)wParam, (short)LOWORD(lParam), (short)HIWORD(lParam));
1320 return PAGER_NCPaint (infoPtr, (HRGN)wParam);
1322 case WM_WINDOWPOSCHANGING:
1323 return PAGER_WindowPosChanging (infoPtr, (WINDOWPOS*)lParam);
1325 case WM_STYLECHANGED:
1326 return PAGER_StyleChanged(infoPtr, wParam, (LPSTYLESTRUCT)lParam);
1329 return PAGER_NCCalcSize (infoPtr, wParam, (LPRECT)lParam);
1332 return PAGER_NCHitTest (infoPtr, (short)LOWORD(lParam), (short)HIWORD(lParam));
1335 if (infoPtr->bForward && infoPtr->hwndChild)
1336 PostMessageW(infoPtr->hwndChild, WM_MOUSEMOVE, wParam, lParam);
1337 return PAGER_MouseMove (infoPtr, (INT)wParam, (short)LOWORD(lParam), (short)HIWORD(lParam));
1339 case WM_LBUTTONDOWN:
1340 return PAGER_LButtonDown (infoPtr, (INT)wParam, (short)LOWORD(lParam), (short)HIWORD(lParam));
1343 return PAGER_LButtonUp (infoPtr, (INT)wParam, (short)LOWORD(lParam), (short)HIWORD(lParam));
1346 return PAGER_EraseBackground (infoPtr, (HDC)wParam);
1349 return PAGER_Timer (infoPtr, (INT)wParam);
1353 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
1356 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
1362 PAGER_Register (void)
1366 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
1367 wndClass.style = CS_GLOBALCLASS;
1368 wndClass.lpfnWndProc = PAGER_WindowProc;
1369 wndClass.cbClsExtra = 0;
1370 wndClass.cbWndExtra = sizeof(PAGER_INFO *);
1371 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1372 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
1373 wndClass.lpszClassName = WC_PAGESCROLLERW;
1375 RegisterClassW (&wndClass);
1380 PAGER_Unregister (void)
1382 UnregisterClassW (WC_PAGESCROLLERW, NULL);