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) */
89 #define INITIAL_DELAY 500
90 #define REPEAT_DELAY 50
93 PAGER_GetButtonRects(const PAGER_INFO
* infoPtr
, RECT
* prcTopLeft
, RECT
* prcBottomRight
, BOOL bClientCoords
)
96 GetWindowRect (infoPtr
->hwndSelf
, &rcWindow
);
99 MapWindowPoints( 0, infoPtr
->hwndSelf
, (POINT
*)&rcWindow
, 2 );
101 OffsetRect(&rcWindow
, -rcWindow
.left
, -rcWindow
.top
);
103 *prcTopLeft
= *prcBottomRight
= rcWindow
;
104 if (infoPtr
->dwStyle
& PGS_HORZ
)
106 prcTopLeft
->right
= prcTopLeft
->left
+ infoPtr
->nButtonSize
;
107 prcBottomRight
->left
= prcBottomRight
->right
- infoPtr
->nButtonSize
;
111 prcTopLeft
->bottom
= prcTopLeft
->top
+ infoPtr
->nButtonSize
;
112 prcBottomRight
->top
= prcBottomRight
->bottom
- infoPtr
->nButtonSize
;
117 PAGER_DrawButton(HDC hdc
, COLORREF clrBk
, RECT rc
,
118 BOOL horz
, BOOL topLeft
, INT btnState
)
122 TRACE("rc = %s, btnState = %d\n", wine_dbgstr_rect(&rc
), btnState
);
124 if (btnState
== PGF_INVISIBLE
)
127 if ((rc
.right
- rc
.left
<= 0) || (rc
.bottom
- rc
.top
<= 0))
131 flags
= topLeft
? DFCS_SCROLLLEFT
: DFCS_SCROLLRIGHT
;
133 flags
= topLeft
? DFCS_SCROLLUP
: DFCS_SCROLLDOWN
;
143 flags
|= DFCS_PUSHED
;
146 flags
|= DFCS_INACTIVE
| DFCS_FLAT
;
149 DrawFrameControl( hdc
, &rc
, DFC_SCROLL
, flags
);
152 /* << PAGER_GetDropTarget >> */
154 static inline LRESULT
155 PAGER_ForwardMouse (PAGER_INFO
* infoPtr
, BOOL bFwd
)
157 TRACE("[%p]\n", infoPtr
->hwndSelf
);
159 infoPtr
->bForward
= bFwd
;
164 static inline LRESULT
165 PAGER_GetButtonState (const PAGER_INFO
* infoPtr
, INT btn
)
167 LRESULT btnState
= PGF_INVISIBLE
;
168 TRACE("[%p]\n", infoPtr
->hwndSelf
);
170 if (btn
== PGB_TOPORLEFT
)
171 btnState
= infoPtr
->TLbtnState
;
172 else if (btn
== PGB_BOTTOMORRIGHT
)
173 btnState
= infoPtr
->BRbtnState
;
180 PAGER_GetPos(const PAGER_INFO
*infoPtr
)
182 TRACE("[%p] returns %d\n", infoPtr
->hwndSelf
, infoPtr
->nPos
);
183 return infoPtr
->nPos
;
187 PAGER_GetButtonSize(const PAGER_INFO
*infoPtr
)
189 TRACE("[%p] returns %d\n", infoPtr
->hwndSelf
, infoPtr
->nButtonSize
);
190 return infoPtr
->nButtonSize
;
194 PAGER_GetBorder(const PAGER_INFO
*infoPtr
)
196 TRACE("[%p] returns %d\n", infoPtr
->hwndSelf
, infoPtr
->nBorder
);
197 return infoPtr
->nBorder
;
200 static inline COLORREF
201 PAGER_GetBkColor(const PAGER_INFO
*infoPtr
)
203 TRACE("[%p] returns %06x\n", infoPtr
->hwndSelf
, infoPtr
->clrBk
);
204 return infoPtr
->clrBk
;
208 PAGER_CalcSize( PAGER_INFO
*infoPtr
)
211 ZeroMemory (&nmpgcs
, sizeof (NMPGCALCSIZE
));
212 nmpgcs
.hdr
.hwndFrom
= infoPtr
->hwndSelf
;
213 nmpgcs
.hdr
.idFrom
= GetWindowLongPtrW (infoPtr
->hwndSelf
, GWLP_ID
);
214 nmpgcs
.hdr
.code
= PGN_CALCSIZE
;
215 nmpgcs
.dwFlag
= (infoPtr
->dwStyle
& PGS_HORZ
) ? PGF_CALCWIDTH
: PGF_CALCHEIGHT
;
216 nmpgcs
.iWidth
= infoPtr
->nWidth
;
217 nmpgcs
.iHeight
= infoPtr
->nHeight
;
218 SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFY
, nmpgcs
.hdr
.idFrom
, (LPARAM
)&nmpgcs
);
220 if (infoPtr
->dwStyle
& PGS_HORZ
)
221 infoPtr
->nWidth
= nmpgcs
.iWidth
;
223 infoPtr
->nHeight
= nmpgcs
.iHeight
;
225 TRACE("[%p] PGN_CALCSIZE returns %dx%d\n", infoPtr
->hwndSelf
, nmpgcs
.iWidth
, nmpgcs
.iHeight
);
229 PAGER_PositionChildWnd(PAGER_INFO
* infoPtr
)
231 if (infoPtr
->hwndChild
)
234 int nPos
= infoPtr
->nPos
;
236 /* compensate for a grayed btn, which will soon become invisible */
237 if (infoPtr
->TLbtnState
== PGF_GRAYED
)
238 nPos
+= infoPtr
->nButtonSize
;
240 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
242 if (infoPtr
->dwStyle
& PGS_HORZ
)
244 int wndSize
= max(0, rcClient
.right
- rcClient
.left
);
245 if (infoPtr
->nWidth
< wndSize
)
246 infoPtr
->nWidth
= wndSize
;
248 TRACE("[%p] SWP %dx%d at (%d,%d)\n", infoPtr
->hwndSelf
,
249 infoPtr
->nWidth
, infoPtr
->nHeight
,
251 SetWindowPos(infoPtr
->hwndChild
, HWND_TOP
,
253 infoPtr
->nWidth
, infoPtr
->nHeight
, 0);
257 int wndSize
= max(0, rcClient
.bottom
- rcClient
.top
);
258 if (infoPtr
->nHeight
< wndSize
)
259 infoPtr
->nHeight
= wndSize
;
261 TRACE("[%p] SWP %dx%d at (%d,%d)\n", infoPtr
->hwndSelf
,
262 infoPtr
->nWidth
, infoPtr
->nHeight
,
264 SetWindowPos(infoPtr
->hwndChild
, HWND_TOP
,
266 infoPtr
->nWidth
, infoPtr
->nHeight
, 0);
269 InvalidateRect(infoPtr
->hwndChild
, NULL
, TRUE
);
274 PAGER_GetScrollRange(PAGER_INFO
* infoPtr
, BOOL calc_size
)
278 if (infoPtr
->hwndChild
)
280 INT wndSize
, childSize
;
282 GetWindowRect(infoPtr
->hwndSelf
, &wndRect
);
285 PAGER_CalcSize(infoPtr
);
286 if (infoPtr
->dwStyle
& PGS_HORZ
)
288 wndSize
= wndRect
.right
- wndRect
.left
;
289 childSize
= infoPtr
->nWidth
;
293 wndSize
= wndRect
.bottom
- wndRect
.top
;
294 childSize
= infoPtr
->nHeight
;
297 TRACE("childSize = %d, wndSize = %d\n", childSize
, wndSize
);
298 if (childSize
> wndSize
)
299 scrollRange
= childSize
- wndSize
+ infoPtr
->nButtonSize
;
302 TRACE("[%p] returns %d\n", infoPtr
->hwndSelf
, scrollRange
);
307 PAGER_UpdateBtns(PAGER_INFO
*infoPtr
, INT scrollRange
, BOOL hideGrayBtns
)
311 INT oldTLbtnState
= infoPtr
->TLbtnState
;
312 INT oldBRbtnState
= infoPtr
->BRbtnState
;
314 RECT rcTopLeft
, rcBottomRight
;
316 /* get button rects */
317 PAGER_GetButtonRects(infoPtr
, &rcTopLeft
, &rcBottomRight
, TRUE
);
320 ScreenToClient( infoPtr
->hwndSelf
, &pt
);
322 /* update states based on scroll position */
323 if (infoPtr
->nPos
> 0)
325 if (infoPtr
->TLbtnState
== PGF_INVISIBLE
|| infoPtr
->TLbtnState
== PGF_GRAYED
)
326 infoPtr
->TLbtnState
= PGF_NORMAL
;
328 else if (!hideGrayBtns
&& PtInRect(&rcTopLeft
, pt
))
329 infoPtr
->TLbtnState
= PGF_GRAYED
;
331 infoPtr
->TLbtnState
= PGF_INVISIBLE
;
333 if (scrollRange
<= 0)
335 infoPtr
->TLbtnState
= PGF_INVISIBLE
;
336 infoPtr
->BRbtnState
= PGF_INVISIBLE
;
338 else if (infoPtr
->nPos
< scrollRange
)
340 if (infoPtr
->BRbtnState
== PGF_INVISIBLE
|| infoPtr
->BRbtnState
== PGF_GRAYED
)
341 infoPtr
->BRbtnState
= PGF_NORMAL
;
343 else if (!hideGrayBtns
&& PtInRect(&rcBottomRight
, pt
))
344 infoPtr
->BRbtnState
= PGF_GRAYED
;
346 infoPtr
->BRbtnState
= PGF_INVISIBLE
;
348 /* only need to resize when entering or leaving PGF_INVISIBLE state */
350 ((oldTLbtnState
== PGF_INVISIBLE
) != (infoPtr
->TLbtnState
== PGF_INVISIBLE
)) ||
351 ((oldBRbtnState
== PGF_INVISIBLE
) != (infoPtr
->BRbtnState
== PGF_INVISIBLE
));
352 /* initiate NCCalcSize to resize client wnd if necessary */
354 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, 0, 0,
355 SWP_FRAMECHANGED
| SWP_NOSIZE
| SWP_NOMOVE
|
356 SWP_NOZORDER
| SWP_NOACTIVATE
);
358 /* repaint when changing any state */
359 repaintBtns
= (oldTLbtnState
!= infoPtr
->TLbtnState
) ||
360 (oldBRbtnState
!= infoPtr
->BRbtnState
);
362 SendMessageW(infoPtr
->hwndSelf
, WM_NCPAINT
, 0, 0);
366 PAGER_SetPos(PAGER_INFO
* infoPtr
, INT newPos
, BOOL fromBtnPress
, BOOL calc_size
)
368 INT scrollRange
= PAGER_GetScrollRange(infoPtr
, calc_size
);
369 INT oldPos
= infoPtr
->nPos
;
371 if ((scrollRange
<= 0) || (newPos
< 0))
373 else if (newPos
> scrollRange
)
374 infoPtr
->nPos
= scrollRange
;
376 infoPtr
->nPos
= newPos
;
378 TRACE("[%p] pos=%d, oldpos=%d\n", infoPtr
->hwndSelf
, infoPtr
->nPos
, oldPos
);
380 if (infoPtr
->nPos
!= oldPos
)
382 /* gray and restore btns, and if from WM_SETPOS, hide the gray btns */
383 PAGER_UpdateBtns(infoPtr
, scrollRange
, !fromBtnPress
);
384 PAGER_PositionChildWnd(infoPtr
);
390 /******************************************************************
391 * For the PGM_RECALCSIZE message (but not the other uses in *
392 * this module), the native control does only the following: *
394 * if (some condition) *
395 * PostMessageW(hwnd, EM_FMTLINES, 0, 0); *
396 * return DefWindowProcW(hwnd, PGM_RECALCSIZE, 0, 0); *
398 * When we figure out what the "some condition" is we will *
399 * implement that for the message processing. *
400 ******************************************************************/
403 PAGER_RecalcSize(PAGER_INFO
*infoPtr
)
405 TRACE("[%p]\n", infoPtr
->hwndSelf
);
407 if (infoPtr
->hwndChild
)
409 INT scrollRange
= PAGER_GetScrollRange(infoPtr
, TRUE
);
411 if (scrollRange
<= 0)
414 PAGER_SetPos(infoPtr
, 0, FALSE
, TRUE
);
417 PAGER_PositionChildWnd(infoPtr
);
425 PAGER_SetBkColor (PAGER_INFO
* infoPtr
, COLORREF clrBk
)
427 COLORREF clrTemp
= infoPtr
->clrBk
;
429 infoPtr
->clrBk
= clrBk
;
430 TRACE("[%p] %06x\n", infoPtr
->hwndSelf
, infoPtr
->clrBk
);
432 /* the native control seems to do things this way */
433 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, 0, 0,
434 SWP_FRAMECHANGED
| SWP_NOSIZE
| SWP_NOMOVE
|
435 SWP_NOZORDER
| SWP_NOACTIVATE
);
437 RedrawWindow(infoPtr
->hwndSelf
, 0, 0, RDW_ERASE
| RDW_INVALIDATE
);
444 PAGER_SetBorder (PAGER_INFO
* infoPtr
, INT iBorder
)
446 INT nTemp
= infoPtr
->nBorder
;
448 infoPtr
->nBorder
= iBorder
;
449 TRACE("[%p] %d\n", infoPtr
->hwndSelf
, infoPtr
->nBorder
);
451 PAGER_RecalcSize(infoPtr
);
458 PAGER_SetButtonSize (PAGER_INFO
* infoPtr
, INT iButtonSize
)
460 INT nTemp
= infoPtr
->nButtonSize
;
462 infoPtr
->nButtonSize
= iButtonSize
;
463 TRACE("[%p] %d\n", infoPtr
->hwndSelf
, infoPtr
->nButtonSize
);
465 PAGER_RecalcSize(infoPtr
);
472 PAGER_SetChild (PAGER_INFO
* infoPtr
, HWND hwndChild
)
474 infoPtr
->hwndChild
= IsWindow (hwndChild
) ? hwndChild
: 0;
476 if (infoPtr
->hwndChild
)
478 TRACE("[%p] hwndChild=%p\n", infoPtr
->hwndSelf
, infoPtr
->hwndChild
);
480 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, 0, 0,
481 SWP_FRAMECHANGED
| SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOACTIVATE
);
484 PAGER_SetPos(infoPtr
, 0, FALSE
, FALSE
);
491 PAGER_Scroll(PAGER_INFO
* infoPtr
, INT dir
)
493 NMPGSCROLL nmpgScroll
;
496 if (infoPtr
->hwndChild
)
498 ZeroMemory (&nmpgScroll
, sizeof (NMPGSCROLL
));
499 nmpgScroll
.hdr
.hwndFrom
= infoPtr
->hwndSelf
;
500 nmpgScroll
.hdr
.idFrom
= GetWindowLongPtrW (infoPtr
->hwndSelf
, GWLP_ID
);
501 nmpgScroll
.hdr
.code
= PGN_SCROLL
;
503 GetWindowRect(infoPtr
->hwndSelf
, &rcWnd
);
504 GetClientRect(infoPtr
->hwndSelf
, &nmpgScroll
.rcParent
);
505 nmpgScroll
.iXpos
= nmpgScroll
.iYpos
= 0;
506 nmpgScroll
.iDir
= dir
;
508 if (infoPtr
->dwStyle
& PGS_HORZ
)
510 nmpgScroll
.iScroll
= rcWnd
.right
- rcWnd
.left
;
511 nmpgScroll
.iXpos
= infoPtr
->nPos
;
515 nmpgScroll
.iScroll
= rcWnd
.bottom
- rcWnd
.top
;
516 nmpgScroll
.iYpos
= infoPtr
->nPos
;
518 nmpgScroll
.iScroll
-= 2*infoPtr
->nButtonSize
;
520 SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFY
, nmpgScroll
.hdr
.idFrom
, (LPARAM
)&nmpgScroll
);
522 TRACE("[%p] PGN_SCROLL returns iScroll=%d\n", infoPtr
->hwndSelf
, nmpgScroll
.iScroll
);
524 if (nmpgScroll
.iScroll
> 0)
526 infoPtr
->direction
= dir
;
528 if (dir
== PGF_SCROLLLEFT
|| dir
== PGF_SCROLLUP
)
529 PAGER_SetPos(infoPtr
, infoPtr
->nPos
- nmpgScroll
.iScroll
, TRUE
, TRUE
);
531 PAGER_SetPos(infoPtr
, infoPtr
->nPos
+ nmpgScroll
.iScroll
, TRUE
, TRUE
);
534 infoPtr
->direction
= -1;
539 PAGER_FmtLines(const PAGER_INFO
*infoPtr
)
541 /* initiate NCCalcSize to resize client wnd and get size */
542 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, 0, 0,
543 SWP_FRAMECHANGED
| SWP_NOSIZE
| SWP_NOMOVE
|
544 SWP_NOZORDER
| SWP_NOACTIVATE
);
546 SetWindowPos(infoPtr
->hwndChild
, 0,
547 0,0,infoPtr
->nWidth
,infoPtr
->nHeight
,
550 return DefWindowProcW (infoPtr
->hwndSelf
, EM_FMTLINES
, 0, 0);
554 PAGER_Create (HWND hwnd
, const CREATESTRUCTW
*lpcs
)
558 /* allocate memory for info structure */
559 infoPtr
= Alloc (sizeof(PAGER_INFO
));
560 if (!infoPtr
) return -1;
561 SetWindowLongPtrW (hwnd
, 0, (DWORD_PTR
)infoPtr
);
563 /* set default settings */
564 infoPtr
->hwndSelf
= hwnd
;
565 infoPtr
->hwndChild
= NULL
;
566 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
567 infoPtr
->dwStyle
= lpcs
->style
;
568 infoPtr
->clrBk
= GetSysColor(COLOR_BTNFACE
);
569 infoPtr
->nBorder
= 0;
570 infoPtr
->nButtonSize
= 12;
573 infoPtr
->nHeight
= 0;
574 infoPtr
->bForward
= FALSE
;
575 infoPtr
->bCapture
= FALSE
;
576 infoPtr
->TLbtnState
= PGF_INVISIBLE
;
577 infoPtr
->BRbtnState
= PGF_INVISIBLE
;
578 infoPtr
->direction
= -1;
580 if (infoPtr
->dwStyle
& PGS_DRAGNDROP
)
581 FIXME("[%p] Drag and Drop style is not implemented yet.\n", infoPtr
->hwndSelf
);
588 PAGER_Destroy (PAGER_INFO
*infoPtr
)
590 SetWindowLongPtrW (infoPtr
->hwndSelf
, 0, 0);
591 Free (infoPtr
); /* free pager info data */
596 PAGER_NCCalcSize(PAGER_INFO
* infoPtr
, WPARAM wParam
, LPRECT lpRect
)
598 RECT rcChild
, rcWindow
;
601 * lpRect points to a RECT struct. On entry, the struct
602 * contains the proposed wnd rectangle for the window.
603 * On exit, the struct should contain the screen
604 * coordinates of the corresponding window's client area.
607 DefWindowProcW (infoPtr
->hwndSelf
, WM_NCCALCSIZE
, wParam
, (LPARAM
)lpRect
);
609 TRACE("orig rect=%s\n", wine_dbgstr_rect(lpRect
));
611 GetWindowRect (infoPtr
->hwndChild
, &rcChild
);
612 MapWindowPoints (0, infoPtr
->hwndSelf
, (LPPOINT
)&rcChild
, 2); /* FIXME: RECT != 2 POINTS */
613 GetWindowRect (infoPtr
->hwndSelf
, &rcWindow
);
615 infoPtr
->nWidth
= lpRect
->right
- lpRect
->left
;
616 infoPtr
->nHeight
= lpRect
->bottom
- lpRect
->top
;
617 PAGER_CalcSize( infoPtr
);
619 if (infoPtr
->dwStyle
& PGS_HORZ
)
621 if (infoPtr
->TLbtnState
&& (lpRect
->left
+ infoPtr
->nButtonSize
< lpRect
->right
))
622 lpRect
->left
+= infoPtr
->nButtonSize
;
623 if (infoPtr
->BRbtnState
&& (lpRect
->right
- infoPtr
->nButtonSize
> lpRect
->left
))
624 lpRect
->right
-= infoPtr
->nButtonSize
;
628 if (infoPtr
->TLbtnState
&& (lpRect
->top
+ infoPtr
->nButtonSize
< lpRect
->bottom
))
629 lpRect
->top
+= infoPtr
->nButtonSize
;
630 if (infoPtr
->BRbtnState
&& (lpRect
->bottom
- infoPtr
->nButtonSize
> lpRect
->top
))
631 lpRect
->bottom
-= infoPtr
->nButtonSize
;
634 TRACE("nPos=%d, nHeight=%d, window=%s\n", infoPtr
->nPos
, infoPtr
->nHeight
, wine_dbgstr_rect(&rcWindow
));
635 TRACE("[%p] client rect set to %s BtnState[%d,%d]\n", infoPtr
->hwndSelf
, wine_dbgstr_rect(lpRect
),
636 infoPtr
->TLbtnState
, infoPtr
->BRbtnState
);
642 PAGER_NCPaint (const PAGER_INFO
* infoPtr
, HRGN hRgn
)
644 RECT rcBottomRight
, rcTopLeft
;
647 if (infoPtr
->dwStyle
& WS_MINIMIZE
)
650 DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)hRgn
, 0);
652 if (!(hdc
= GetDCEx (infoPtr
->hwndSelf
, 0, DCX_USESTYLE
| DCX_WINDOW
)))
655 PAGER_GetButtonRects(infoPtr
, &rcTopLeft
, &rcBottomRight
, FALSE
);
657 PAGER_DrawButton(hdc
, infoPtr
->clrBk
, rcTopLeft
,
658 infoPtr
->dwStyle
& PGS_HORZ
, TRUE
, infoPtr
->TLbtnState
);
659 PAGER_DrawButton(hdc
, infoPtr
->clrBk
, rcBottomRight
,
660 infoPtr
->dwStyle
& PGS_HORZ
, FALSE
, infoPtr
->BRbtnState
);
662 ReleaseDC( infoPtr
->hwndSelf
, hdc
);
667 PAGER_HitTest (const PAGER_INFO
* infoPtr
, const POINT
* pt
)
669 RECT clientRect
, rcTopLeft
, rcBottomRight
;
672 GetClientRect (infoPtr
->hwndSelf
, &clientRect
);
674 if (PtInRect(&clientRect
, *pt
))
681 PAGER_GetButtonRects(infoPtr
, &rcTopLeft
, &rcBottomRight
, TRUE
);
683 if ((infoPtr
->TLbtnState
!= PGF_INVISIBLE
) && PtInRect(&rcTopLeft
, ptWindow
))
685 TRACE("PGB_TOPORLEFT\n");
686 return PGB_TOPORLEFT
;
688 else if ((infoPtr
->BRbtnState
!= PGF_INVISIBLE
) && PtInRect(&rcBottomRight
, ptWindow
))
690 TRACE("PGB_BOTTOMORRIGHT\n");
691 return PGB_BOTTOMORRIGHT
;
699 PAGER_NCHitTest (const PAGER_INFO
* infoPtr
, INT x
, INT y
)
707 ScreenToClient (infoPtr
->hwndSelf
, &pt
);
708 nHit
= PAGER_HitTest(infoPtr
, &pt
);
710 return (nHit
< 0) ? HTTRANSPARENT
: HTCLIENT
;
714 PAGER_MouseMove (PAGER_INFO
* infoPtr
, INT keys
, INT x
, INT y
)
718 BOOL topLeft
= FALSE
;
726 TRACE("[%p] to (%d,%d)\n", infoPtr
->hwndSelf
, x
, y
);
727 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
728 GetWindowRect(infoPtr
->hwndSelf
, &wnrect
);
729 if (PtInRect(&wnrect
, pt
)) {
730 RECT topleft
, bottomright
, *rect
= NULL
;
732 PAGER_GetButtonRects(infoPtr
, &topleft
, &bottomright
, FALSE
);
735 MapWindowPoints(0, infoPtr
->hwndSelf
, &clpt
, 1);
736 hit
= PAGER_HitTest(infoPtr
, &clpt
);
737 if ((hit
== PGB_TOPORLEFT
) && (infoPtr
->TLbtnState
== PGF_NORMAL
))
741 infoPtr
->TLbtnState
= PGF_HOT
;
742 btnstate
= infoPtr
->TLbtnState
;
744 else if ((hit
== PGB_BOTTOMORRIGHT
) && (infoPtr
->BRbtnState
== PGF_NORMAL
))
748 infoPtr
->BRbtnState
= PGF_HOT
;
749 btnstate
= infoPtr
->BRbtnState
;
752 /* If in one of the buttons the capture and draw buttons */
755 TRACE("[%p] draw btn (%s), Capture %s, style %08x\n",
756 infoPtr
->hwndSelf
, wine_dbgstr_rect(rect
),
757 (infoPtr
->bCapture
) ? "TRUE" : "FALSE",
759 if (!infoPtr
->bCapture
)
761 TRACE("[%p] SetCapture\n", infoPtr
->hwndSelf
);
762 SetCapture(infoPtr
->hwndSelf
);
763 infoPtr
->bCapture
= TRUE
;
765 if (infoPtr
->dwStyle
& PGS_AUTOSCROLL
)
766 SetTimer(infoPtr
->hwndSelf
, TIMERID1
, 0x3e, 0);
767 hdc
= GetWindowDC(infoPtr
->hwndSelf
);
768 /* OffsetRect(wnrect, 0 | 1, 0 | 1) */
769 PAGER_DrawButton(hdc
, infoPtr
->clrBk
, *rect
,
770 infoPtr
->dwStyle
& PGS_HORZ
, topLeft
, btnstate
);
771 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
776 /* If we think we are captured, then do release */
777 if (infoPtr
->bCapture
&& (WindowFromPoint(pt
) != infoPtr
->hwndSelf
))
781 infoPtr
->bCapture
= FALSE
;
783 if (GetCapture() == infoPtr
->hwndSelf
)
787 if (infoPtr
->TLbtnState
== PGF_GRAYED
)
789 infoPtr
->TLbtnState
= PGF_INVISIBLE
;
790 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, 0, 0,
791 SWP_FRAMECHANGED
| SWP_NOSIZE
| SWP_NOMOVE
|
792 SWP_NOZORDER
| SWP_NOACTIVATE
);
794 else if (infoPtr
->TLbtnState
== PGF_HOT
)
796 infoPtr
->TLbtnState
= PGF_NORMAL
;
797 /* FIXME: just invalidate button rect */
798 RedrawWindow(infoPtr
->hwndSelf
, NULL
, NULL
, RDW_FRAME
| RDW_INVALIDATE
);
801 if (infoPtr
->BRbtnState
== PGF_GRAYED
)
803 infoPtr
->BRbtnState
= PGF_INVISIBLE
;
804 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, 0, 0,
805 SWP_FRAMECHANGED
| SWP_NOSIZE
| SWP_NOMOVE
|
806 SWP_NOZORDER
| SWP_NOACTIVATE
);
808 else if (infoPtr
->BRbtnState
== PGF_HOT
)
810 infoPtr
->BRbtnState
= PGF_NORMAL
;
811 /* FIXME: just invalidate button rect */
812 RedrawWindow(infoPtr
->hwndSelf
, NULL
, NULL
, RDW_FRAME
| RDW_INVALIDATE
);
815 /* Notify parent of released mouse capture */
816 memset(&nmhdr
, 0, sizeof(NMHDR
));
817 nmhdr
.hwndFrom
= infoPtr
->hwndSelf
;
818 nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
819 nmhdr
.code
= NM_RELEASEDCAPTURE
;
820 SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, nmhdr
.idFrom
, (LPARAM
)&nmhdr
);
822 if (IsWindow(infoPtr
->hwndSelf
))
823 KillTimer(infoPtr
->hwndSelf
, TIMERID1
);
829 PAGER_LButtonDown (PAGER_INFO
* infoPtr
, INT keys
, INT x
, INT y
)
831 BOOL repaintBtns
= FALSE
;
838 TRACE("[%p] at (%d,%d)\n", infoPtr
->hwndSelf
, x
, y
);
840 hit
= PAGER_HitTest(infoPtr
, &pt
);
842 /* put btn in DEPRESSED state */
843 if (hit
== PGB_TOPORLEFT
)
845 repaintBtns
= infoPtr
->TLbtnState
!= PGF_DEPRESSED
;
846 infoPtr
->TLbtnState
= PGF_DEPRESSED
;
847 SetTimer(infoPtr
->hwndSelf
, TIMERID1
, INITIAL_DELAY
, 0);
849 else if (hit
== PGB_BOTTOMORRIGHT
)
851 repaintBtns
= infoPtr
->BRbtnState
!= PGF_DEPRESSED
;
852 infoPtr
->BRbtnState
= PGF_DEPRESSED
;
853 SetTimer(infoPtr
->hwndSelf
, TIMERID1
, INITIAL_DELAY
, 0);
857 SendMessageW(infoPtr
->hwndSelf
, WM_NCPAINT
, 0, 0);
862 if (infoPtr
->dwStyle
& PGS_HORZ
)
864 TRACE("[%p] PGF_SCROLLLEFT\n", infoPtr
->hwndSelf
);
865 PAGER_Scroll(infoPtr
, PGF_SCROLLLEFT
);
869 TRACE("[%p] PGF_SCROLLUP\n", infoPtr
->hwndSelf
);
870 PAGER_Scroll(infoPtr
, PGF_SCROLLUP
);
873 case PGB_BOTTOMORRIGHT
:
874 if (infoPtr
->dwStyle
& PGS_HORZ
)
876 TRACE("[%p] PGF_SCROLLRIGHT\n", infoPtr
->hwndSelf
);
877 PAGER_Scroll(infoPtr
, PGF_SCROLLRIGHT
);
881 TRACE("[%p] PGF_SCROLLDOWN\n", infoPtr
->hwndSelf
);
882 PAGER_Scroll(infoPtr
, PGF_SCROLLDOWN
);
893 PAGER_LButtonUp (PAGER_INFO
* infoPtr
, INT keys
, INT x
, INT y
)
895 TRACE("[%p]\n", infoPtr
->hwndSelf
);
897 KillTimer (infoPtr
->hwndSelf
, TIMERID1
);
898 KillTimer (infoPtr
->hwndSelf
, TIMERID2
);
900 /* make PRESSED btns NORMAL but don't hide gray btns */
901 if (infoPtr
->TLbtnState
& (PGF_HOT
| PGF_DEPRESSED
))
902 infoPtr
->TLbtnState
= PGF_NORMAL
;
903 if (infoPtr
->BRbtnState
& (PGF_HOT
| PGF_DEPRESSED
))
904 infoPtr
->BRbtnState
= PGF_NORMAL
;
910 PAGER_Timer (PAGER_INFO
* infoPtr
, INT nTimerId
)
914 /* if initial timer, kill it and start the repeat timer */
915 if (nTimerId
== TIMERID1
) {
916 if (infoPtr
->TLbtnState
== PGF_HOT
)
917 dir
= (infoPtr
->dwStyle
& PGS_HORZ
) ?
918 PGF_SCROLLLEFT
: PGF_SCROLLUP
;
920 dir
= (infoPtr
->dwStyle
& PGS_HORZ
) ?
921 PGF_SCROLLRIGHT
: PGF_SCROLLDOWN
;
922 TRACE("[%p] TIMERID1: style=%08x, dir=%d\n",
923 infoPtr
->hwndSelf
, infoPtr
->dwStyle
, dir
);
924 KillTimer(infoPtr
->hwndSelf
, TIMERID1
);
925 SetTimer(infoPtr
->hwndSelf
, TIMERID1
, REPEAT_DELAY
, 0);
926 if (infoPtr
->dwStyle
& PGS_AUTOSCROLL
) {
927 PAGER_Scroll(infoPtr
, dir
);
928 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, 0, 0,
929 SWP_FRAMECHANGED
| SWP_NOSIZE
| SWP_NOMOVE
|
930 SWP_NOZORDER
| SWP_NOACTIVATE
);
936 TRACE("[%p] TIMERID2: dir=%d\n", infoPtr
->hwndSelf
, infoPtr
->direction
);
937 KillTimer(infoPtr
->hwndSelf
, TIMERID2
);
938 if (infoPtr
->direction
> 0) {
939 PAGER_Scroll(infoPtr
, infoPtr
->direction
);
940 SetTimer(infoPtr
->hwndSelf
, TIMERID2
, REPEAT_DELAY
, 0);
946 PAGER_EraseBackground (const PAGER_INFO
* infoPtr
, HDC hdc
)
954 parent
= GetParent(infoPtr
->hwndSelf
);
955 MapWindowPoints(infoPtr
->hwndSelf
, parent
, &pt
, 1);
956 OffsetWindowOrgEx (hdc
, pt
.x
, pt
.y
, &ptorig
);
957 ret
= SendMessageW (parent
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
958 SetWindowOrgEx (hdc
, ptorig
.x
, ptorig
.y
, 0);
965 PAGER_Size (PAGER_INFO
* infoPtr
, INT type
, INT x
, INT y
)
967 /* note that WM_SIZE is sent whenever NCCalcSize resizes the client wnd */
969 TRACE("[%p] %d,%d\n", infoPtr
->hwndSelf
, x
, y
);
971 if (infoPtr
->dwStyle
& PGS_HORZ
)
972 infoPtr
->nHeight
= y
;
976 return PAGER_RecalcSize(infoPtr
);
981 PAGER_StyleChanged(PAGER_INFO
*infoPtr
, WPARAM wStyleType
, const STYLESTRUCT
*lpss
)
983 DWORD oldStyle
= infoPtr
->dwStyle
;
985 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
986 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
988 if (wStyleType
!= GWL_STYLE
) return 0;
990 infoPtr
->dwStyle
= lpss
->styleNew
;
992 if ((oldStyle
^ lpss
->styleNew
) & (PGS_HORZ
| PGS_VERT
))
994 PAGER_RecalcSize(infoPtr
);
1000 static LRESULT WINAPI
1001 PAGER_WindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1003 PAGER_INFO
*infoPtr
= (PAGER_INFO
*)GetWindowLongPtrW(hwnd
, 0);
1005 TRACE("(%p, %#x, %#lx, %#lx)\n", hwnd
, uMsg
, wParam
, lParam
);
1007 if (!infoPtr
&& (uMsg
!= WM_CREATE
))
1008 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
1013 return PAGER_FmtLines(infoPtr
);
1015 case PGM_FORWARDMOUSE
:
1016 return PAGER_ForwardMouse (infoPtr
, (BOOL
)wParam
);
1018 case PGM_GETBKCOLOR
:
1019 return PAGER_GetBkColor(infoPtr
);
1022 return PAGER_GetBorder(infoPtr
);
1024 case PGM_GETBUTTONSIZE
:
1025 return PAGER_GetButtonSize(infoPtr
);
1028 return PAGER_GetPos(infoPtr
);
1030 case PGM_GETBUTTONSTATE
:
1031 return PAGER_GetButtonState (infoPtr
, (INT
)lParam
);
1033 /* case PGM_GETDROPTARGET: */
1035 case PGM_RECALCSIZE
:
1036 return PAGER_RecalcSize(infoPtr
);
1038 case PGM_SETBKCOLOR
:
1039 return PAGER_SetBkColor (infoPtr
, (COLORREF
)lParam
);
1042 return PAGER_SetBorder (infoPtr
, (INT
)lParam
);
1044 case PGM_SETBUTTONSIZE
:
1045 return PAGER_SetButtonSize (infoPtr
, (INT
)lParam
);
1048 return PAGER_SetChild (infoPtr
, (HWND
)lParam
);
1051 return PAGER_SetPos(infoPtr
, (INT
)lParam
, FALSE
, TRUE
);
1054 return PAGER_Create (hwnd
, (LPCREATESTRUCTW
)lParam
);
1057 return PAGER_Destroy (infoPtr
);
1060 return PAGER_Size (infoPtr
, (INT
)wParam
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
1063 return PAGER_NCPaint (infoPtr
, (HRGN
)wParam
);
1065 case WM_STYLECHANGED
:
1066 return PAGER_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
1069 return PAGER_NCCalcSize (infoPtr
, wParam
, (LPRECT
)lParam
);
1072 return PAGER_NCHitTest (infoPtr
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
1075 if (infoPtr
->bForward
&& infoPtr
->hwndChild
)
1076 PostMessageW(infoPtr
->hwndChild
, WM_MOUSEMOVE
, wParam
, lParam
);
1077 return PAGER_MouseMove (infoPtr
, (INT
)wParam
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
1079 case WM_LBUTTONDOWN
:
1080 return PAGER_LButtonDown (infoPtr
, (INT
)wParam
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
1083 return PAGER_LButtonUp (infoPtr
, (INT
)wParam
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
1086 return PAGER_EraseBackground (infoPtr
, (HDC
)wParam
);
1089 return PAGER_Timer (infoPtr
, (INT
)wParam
);
1093 return SendMessageW (infoPtr
->hwndNotify
, uMsg
, wParam
, lParam
);
1096 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
1102 PAGER_Register (void)
1106 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
1107 wndClass
.style
= CS_GLOBALCLASS
;
1108 wndClass
.lpfnWndProc
= PAGER_WindowProc
;
1109 wndClass
.cbClsExtra
= 0;
1110 wndClass
.cbWndExtra
= sizeof(PAGER_INFO
*);
1111 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
1112 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+1);
1113 wndClass
.lpszClassName
= WC_PAGESCROLLERW
;
1115 RegisterClassW (&wndClass
);
1120 PAGER_Unregister (void)
1122 UnregisterClassW (WC_PAGESCROLLERW
, NULL
);