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
, 0,
253 infoPtr
->nWidth
, infoPtr
->nHeight
,
258 int wndSize
= max(0, rcClient
.bottom
- rcClient
.top
);
259 if (infoPtr
->nHeight
< wndSize
)
260 infoPtr
->nHeight
= wndSize
;
262 TRACE("[%p] SWP %dx%d at (%d,%d)\n", infoPtr
->hwndSelf
,
263 infoPtr
->nWidth
, infoPtr
->nHeight
,
265 SetWindowPos(infoPtr
->hwndChild
, 0,
267 infoPtr
->nWidth
, infoPtr
->nHeight
,
271 InvalidateRect(infoPtr
->hwndChild
, NULL
, TRUE
);
276 PAGER_GetScrollRange(PAGER_INFO
* infoPtr
)
280 if (infoPtr
->hwndChild
)
282 INT wndSize
, childSize
;
284 GetWindowRect(infoPtr
->hwndSelf
, &wndRect
);
286 PAGER_CalcSize(infoPtr
);
287 if (infoPtr
->dwStyle
& PGS_HORZ
)
289 wndSize
= wndRect
.right
- wndRect
.left
;
290 childSize
= infoPtr
->nWidth
;
294 wndSize
= wndRect
.bottom
- wndRect
.top
;
295 childSize
= infoPtr
->nHeight
;
298 TRACE("childSize = %d, wndSize = %d\n", childSize
, wndSize
);
299 if (childSize
> wndSize
)
300 scrollRange
= childSize
- wndSize
+ infoPtr
->nButtonSize
;
303 TRACE("[%p] returns %d\n", infoPtr
->hwndSelf
, scrollRange
);
308 PAGER_UpdateBtns(PAGER_INFO
*infoPtr
, INT scrollRange
, BOOL hideGrayBtns
)
312 INT oldTLbtnState
= infoPtr
->TLbtnState
;
313 INT oldBRbtnState
= infoPtr
->BRbtnState
;
315 RECT rcTopLeft
, rcBottomRight
;
317 /* get button rects */
318 PAGER_GetButtonRects(infoPtr
, &rcTopLeft
, &rcBottomRight
, TRUE
);
321 ScreenToClient( infoPtr
->hwndSelf
, &pt
);
323 /* update states based on scroll position */
324 if (infoPtr
->nPos
> 0)
326 if (infoPtr
->TLbtnState
== PGF_INVISIBLE
|| infoPtr
->TLbtnState
== PGF_GRAYED
)
327 infoPtr
->TLbtnState
= PGF_NORMAL
;
329 else if (!hideGrayBtns
&& PtInRect(&rcTopLeft
, pt
))
330 infoPtr
->TLbtnState
= PGF_GRAYED
;
332 infoPtr
->TLbtnState
= PGF_INVISIBLE
;
334 if (scrollRange
<= 0)
336 infoPtr
->TLbtnState
= PGF_INVISIBLE
;
337 infoPtr
->BRbtnState
= PGF_INVISIBLE
;
339 else if (infoPtr
->nPos
< scrollRange
)
341 if (infoPtr
->BRbtnState
== PGF_INVISIBLE
|| infoPtr
->BRbtnState
== PGF_GRAYED
)
342 infoPtr
->BRbtnState
= PGF_NORMAL
;
344 else if (!hideGrayBtns
&& PtInRect(&rcBottomRight
, pt
))
345 infoPtr
->BRbtnState
= PGF_GRAYED
;
347 infoPtr
->BRbtnState
= PGF_INVISIBLE
;
349 /* only need to resize when entering or leaving PGF_INVISIBLE state */
351 ((oldTLbtnState
== PGF_INVISIBLE
) != (infoPtr
->TLbtnState
== PGF_INVISIBLE
)) ||
352 ((oldBRbtnState
== PGF_INVISIBLE
) != (infoPtr
->BRbtnState
== PGF_INVISIBLE
));
353 /* initiate NCCalcSize to resize client wnd if necessary */
355 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, 0, 0,
356 SWP_FRAMECHANGED
| SWP_NOSIZE
| SWP_NOMOVE
|
357 SWP_NOZORDER
| SWP_NOACTIVATE
);
359 /* repaint when changing any state */
360 repaintBtns
= (oldTLbtnState
!= infoPtr
->TLbtnState
) ||
361 (oldBRbtnState
!= infoPtr
->BRbtnState
);
363 SendMessageW(infoPtr
->hwndSelf
, WM_NCPAINT
, 0, 0);
367 PAGER_SetPos(PAGER_INFO
* infoPtr
, INT newPos
, BOOL fromBtnPress
)
369 INT scrollRange
= PAGER_GetScrollRange(infoPtr
);
370 INT oldPos
= infoPtr
->nPos
;
372 if ((scrollRange
<= 0) || (newPos
< 0))
374 else if (newPos
> scrollRange
)
375 infoPtr
->nPos
= scrollRange
;
377 infoPtr
->nPos
= newPos
;
379 TRACE("[%p] pos=%d, oldpos=%d\n", infoPtr
->hwndSelf
, infoPtr
->nPos
, oldPos
);
381 if (infoPtr
->nPos
!= oldPos
)
383 /* gray and restore btns, and if from WM_SETPOS, hide the gray btns */
384 PAGER_UpdateBtns(infoPtr
, scrollRange
, !fromBtnPress
);
385 PAGER_PositionChildWnd(infoPtr
);
392 PAGER_WindowPosChanging(PAGER_INFO
* infoPtr
, WINDOWPOS
*winpos
)
394 if ((infoPtr
->dwStyle
& CCS_NORESIZE
) && !(winpos
->flags
& SWP_NOSIZE
))
396 /* don't let the app resize the nonscrollable dimension of a control
397 * that was created with CCS_NORESIZE style
398 * (i.e. height for a horizontal pager, or width for a vertical one) */
400 /* except if the current dimension is 0 and app is setting for
401 * first time, then save amount as dimension. - GA 8/01 */
403 if (infoPtr
->dwStyle
& PGS_HORZ
)
404 if (!infoPtr
->nHeight
&& winpos
->cy
)
405 infoPtr
->nHeight
= winpos
->cy
;
407 winpos
->cy
= infoPtr
->nHeight
;
409 if (!infoPtr
->nWidth
&& winpos
->cx
)
410 infoPtr
->nWidth
= winpos
->cx
;
412 winpos
->cx
= infoPtr
->nWidth
;
416 return DefWindowProcW (infoPtr
->hwndSelf
, WM_WINDOWPOSCHANGING
, 0, (LPARAM
)winpos
);
419 /******************************************************************
420 * For the PGM_RECALCSIZE message (but not the other uses in *
421 * this module), the native control does only the following: *
423 * if (some condition) *
424 * PostMessageW(hwnd, EM_FMTLINES, 0, 0); *
425 * return DefWindowProcW(hwnd, PGM_RECALCSIZE, 0, 0); *
427 * When we figure out what the "some condition" is we will *
428 * implement that for the message processing. *
429 ******************************************************************/
432 PAGER_RecalcSize(PAGER_INFO
*infoPtr
)
434 TRACE("[%p]\n", infoPtr
->hwndSelf
);
436 if (infoPtr
->hwndChild
)
438 INT scrollRange
= PAGER_GetScrollRange(infoPtr
);
440 if (scrollRange
<= 0)
443 PAGER_SetPos(infoPtr
, 0, FALSE
);
446 PAGER_PositionChildWnd(infoPtr
);
454 PAGER_SetBkColor (PAGER_INFO
* infoPtr
, COLORREF clrBk
)
456 COLORREF clrTemp
= infoPtr
->clrBk
;
458 infoPtr
->clrBk
= clrBk
;
459 TRACE("[%p] %06x\n", infoPtr
->hwndSelf
, infoPtr
->clrBk
);
461 /* the native control seems to do things this way */
462 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, 0, 0,
463 SWP_FRAMECHANGED
| SWP_NOSIZE
| SWP_NOMOVE
|
464 SWP_NOZORDER
| SWP_NOACTIVATE
);
466 RedrawWindow(infoPtr
->hwndSelf
, 0, 0, RDW_ERASE
| RDW_INVALIDATE
);
473 PAGER_SetBorder (PAGER_INFO
* infoPtr
, INT iBorder
)
475 INT nTemp
= infoPtr
->nBorder
;
477 infoPtr
->nBorder
= iBorder
;
478 TRACE("[%p] %d\n", infoPtr
->hwndSelf
, infoPtr
->nBorder
);
480 PAGER_RecalcSize(infoPtr
);
487 PAGER_SetButtonSize (PAGER_INFO
* infoPtr
, INT iButtonSize
)
489 INT nTemp
= infoPtr
->nButtonSize
;
491 infoPtr
->nButtonSize
= iButtonSize
;
492 TRACE("[%p] %d\n", infoPtr
->hwndSelf
, infoPtr
->nButtonSize
);
494 PAGER_RecalcSize(infoPtr
);
501 PAGER_SetChild (PAGER_INFO
* infoPtr
, HWND hwndChild
)
503 infoPtr
->hwndChild
= IsWindow (hwndChild
) ? hwndChild
: 0;
505 if (infoPtr
->hwndChild
)
507 TRACE("[%p] hwndChild=%p\n", infoPtr
->hwndSelf
, infoPtr
->hwndChild
);
509 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, 0, 0,
510 SWP_FRAMECHANGED
| SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOACTIVATE
);
512 /* position child within the page scroller */
513 SetWindowPos(infoPtr
->hwndChild
, HWND_TOP
,
515 SWP_SHOWWINDOW
| SWP_NOSIZE
); /* native is 0 */
518 PAGER_SetPos(infoPtr
, 0, FALSE
);
525 PAGER_Scroll(PAGER_INFO
* infoPtr
, INT dir
)
527 NMPGSCROLL nmpgScroll
;
530 if (infoPtr
->hwndChild
)
532 ZeroMemory (&nmpgScroll
, sizeof (NMPGSCROLL
));
533 nmpgScroll
.hdr
.hwndFrom
= infoPtr
->hwndSelf
;
534 nmpgScroll
.hdr
.idFrom
= GetWindowLongPtrW (infoPtr
->hwndSelf
, GWLP_ID
);
535 nmpgScroll
.hdr
.code
= PGN_SCROLL
;
537 GetWindowRect(infoPtr
->hwndSelf
, &rcWnd
);
538 GetClientRect(infoPtr
->hwndSelf
, &nmpgScroll
.rcParent
);
539 nmpgScroll
.iXpos
= nmpgScroll
.iYpos
= 0;
540 nmpgScroll
.iDir
= dir
;
542 if (infoPtr
->dwStyle
& PGS_HORZ
)
544 nmpgScroll
.iScroll
= rcWnd
.right
- rcWnd
.left
;
545 nmpgScroll
.iXpos
= infoPtr
->nPos
;
549 nmpgScroll
.iScroll
= rcWnd
.bottom
- rcWnd
.top
;
550 nmpgScroll
.iYpos
= infoPtr
->nPos
;
552 nmpgScroll
.iScroll
-= 2*infoPtr
->nButtonSize
;
554 SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFY
, nmpgScroll
.hdr
.idFrom
, (LPARAM
)&nmpgScroll
);
556 TRACE("[%p] PGN_SCROLL returns iScroll=%d\n", infoPtr
->hwndSelf
, nmpgScroll
.iScroll
);
558 if (nmpgScroll
.iScroll
> 0)
560 infoPtr
->direction
= dir
;
562 if (dir
== PGF_SCROLLLEFT
|| dir
== PGF_SCROLLUP
)
563 PAGER_SetPos(infoPtr
, infoPtr
->nPos
- nmpgScroll
.iScroll
, TRUE
);
565 PAGER_SetPos(infoPtr
, infoPtr
->nPos
+ nmpgScroll
.iScroll
, TRUE
);
568 infoPtr
->direction
= -1;
573 PAGER_FmtLines(const PAGER_INFO
*infoPtr
)
575 /* initiate NCCalcSize to resize client wnd and get size */
576 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, 0, 0,
577 SWP_FRAMECHANGED
| SWP_NOSIZE
| SWP_NOMOVE
|
578 SWP_NOZORDER
| SWP_NOACTIVATE
);
580 SetWindowPos(infoPtr
->hwndChild
, 0,
581 0,0,infoPtr
->nWidth
,infoPtr
->nHeight
,
584 return DefWindowProcW (infoPtr
->hwndSelf
, EM_FMTLINES
, 0, 0);
588 PAGER_Create (HWND hwnd
, const CREATESTRUCTW
*lpcs
)
592 /* allocate memory for info structure */
593 infoPtr
= Alloc (sizeof(PAGER_INFO
));
594 if (!infoPtr
) return -1;
595 SetWindowLongPtrW (hwnd
, 0, (DWORD_PTR
)infoPtr
);
597 /* set default settings */
598 infoPtr
->hwndSelf
= hwnd
;
599 infoPtr
->hwndChild
= NULL
;
600 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
601 infoPtr
->dwStyle
= lpcs
->style
;
602 infoPtr
->clrBk
= GetSysColor(COLOR_BTNFACE
);
603 infoPtr
->nBorder
= 0;
604 infoPtr
->nButtonSize
= 12;
607 infoPtr
->nHeight
= 0;
608 infoPtr
->bForward
= FALSE
;
609 infoPtr
->bCapture
= FALSE
;
610 infoPtr
->TLbtnState
= PGF_INVISIBLE
;
611 infoPtr
->BRbtnState
= PGF_INVISIBLE
;
612 infoPtr
->direction
= -1;
614 if (infoPtr
->dwStyle
& PGS_DRAGNDROP
)
615 FIXME("[%p] Drag and Drop style is not implemented yet.\n", infoPtr
->hwndSelf
);
622 PAGER_Destroy (PAGER_INFO
*infoPtr
)
624 SetWindowLongPtrW (infoPtr
->hwndSelf
, 0, 0);
625 Free (infoPtr
); /* free pager info data */
630 PAGER_NCCalcSize(PAGER_INFO
* infoPtr
, WPARAM wParam
, LPRECT lpRect
)
632 RECT rcChild
, rcWindow
;
635 * lpRect points to a RECT struct. On entry, the struct
636 * contains the proposed wnd rectangle for the window.
637 * On exit, the struct should contain the screen
638 * coordinates of the corresponding window's client area.
641 DefWindowProcW (infoPtr
->hwndSelf
, WM_NCCALCSIZE
, wParam
, (LPARAM
)lpRect
);
643 TRACE("orig rect=%s\n", wine_dbgstr_rect(lpRect
));
645 GetWindowRect (infoPtr
->hwndChild
, &rcChild
);
646 MapWindowPoints (0, infoPtr
->hwndSelf
, (LPPOINT
)&rcChild
, 2); /* FIXME: RECT != 2 POINTS */
647 GetWindowRect (infoPtr
->hwndSelf
, &rcWindow
);
649 infoPtr
->nWidth
= lpRect
->right
- lpRect
->left
;
650 infoPtr
->nHeight
= lpRect
->bottom
- lpRect
->top
;
651 PAGER_CalcSize( infoPtr
);
653 if (infoPtr
->dwStyle
& PGS_HORZ
)
655 if (infoPtr
->TLbtnState
&& (lpRect
->left
+ infoPtr
->nButtonSize
< lpRect
->right
))
656 lpRect
->left
+= infoPtr
->nButtonSize
;
657 if (infoPtr
->BRbtnState
&& (lpRect
->right
- infoPtr
->nButtonSize
> lpRect
->left
))
658 lpRect
->right
-= infoPtr
->nButtonSize
;
662 if (infoPtr
->TLbtnState
&& (lpRect
->top
+ infoPtr
->nButtonSize
< lpRect
->bottom
))
663 lpRect
->top
+= infoPtr
->nButtonSize
;
664 if (infoPtr
->BRbtnState
&& (lpRect
->bottom
- infoPtr
->nButtonSize
> lpRect
->top
))
665 lpRect
->bottom
-= infoPtr
->nButtonSize
;
668 TRACE("nPos=%d, nHeight=%d, window=%s\n", infoPtr
->nPos
, infoPtr
->nHeight
, wine_dbgstr_rect(&rcWindow
));
669 TRACE("[%p] client rect set to %s BtnState[%d,%d]\n", infoPtr
->hwndSelf
, wine_dbgstr_rect(lpRect
),
670 infoPtr
->TLbtnState
, infoPtr
->BRbtnState
);
676 PAGER_NCPaint (const PAGER_INFO
* infoPtr
, HRGN hRgn
)
678 RECT rcBottomRight
, rcTopLeft
;
681 if (infoPtr
->dwStyle
& WS_MINIMIZE
)
684 DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)hRgn
, 0);
686 if (!(hdc
= GetDCEx (infoPtr
->hwndSelf
, 0, DCX_USESTYLE
| DCX_WINDOW
)))
689 PAGER_GetButtonRects(infoPtr
, &rcTopLeft
, &rcBottomRight
, FALSE
);
691 PAGER_DrawButton(hdc
, infoPtr
->clrBk
, rcTopLeft
,
692 infoPtr
->dwStyle
& PGS_HORZ
, TRUE
, infoPtr
->TLbtnState
);
693 PAGER_DrawButton(hdc
, infoPtr
->clrBk
, rcBottomRight
,
694 infoPtr
->dwStyle
& PGS_HORZ
, FALSE
, infoPtr
->BRbtnState
);
696 ReleaseDC( infoPtr
->hwndSelf
, hdc
);
701 PAGER_HitTest (const PAGER_INFO
* infoPtr
, const POINT
* pt
)
703 RECT clientRect
, rcTopLeft
, rcBottomRight
;
706 GetClientRect (infoPtr
->hwndSelf
, &clientRect
);
708 if (PtInRect(&clientRect
, *pt
))
715 PAGER_GetButtonRects(infoPtr
, &rcTopLeft
, &rcBottomRight
, TRUE
);
717 if ((infoPtr
->TLbtnState
!= PGF_INVISIBLE
) && PtInRect(&rcTopLeft
, ptWindow
))
719 TRACE("PGB_TOPORLEFT\n");
720 return PGB_TOPORLEFT
;
722 else if ((infoPtr
->BRbtnState
!= PGF_INVISIBLE
) && PtInRect(&rcBottomRight
, ptWindow
))
724 TRACE("PGB_BOTTOMORRIGHT\n");
725 return PGB_BOTTOMORRIGHT
;
733 PAGER_NCHitTest (const PAGER_INFO
* infoPtr
, INT x
, INT y
)
741 ScreenToClient (infoPtr
->hwndSelf
, &pt
);
742 nHit
= PAGER_HitTest(infoPtr
, &pt
);
744 return (nHit
< 0) ? HTTRANSPARENT
: HTCLIENT
;
748 PAGER_MouseMove (PAGER_INFO
* infoPtr
, INT keys
, INT x
, INT y
)
752 BOOL topLeft
= FALSE
;
760 TRACE("[%p] to (%d,%d)\n", infoPtr
->hwndSelf
, x
, y
);
761 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
762 GetWindowRect(infoPtr
->hwndSelf
, &wnrect
);
763 if (PtInRect(&wnrect
, pt
)) {
764 RECT topleft
, bottomright
, *rect
= NULL
;
766 PAGER_GetButtonRects(infoPtr
, &topleft
, &bottomright
, FALSE
);
769 MapWindowPoints(0, infoPtr
->hwndSelf
, &clpt
, 1);
770 hit
= PAGER_HitTest(infoPtr
, &clpt
);
771 if ((hit
== PGB_TOPORLEFT
) && (infoPtr
->TLbtnState
== PGF_NORMAL
))
775 infoPtr
->TLbtnState
= PGF_HOT
;
776 btnstate
= infoPtr
->TLbtnState
;
778 else if ((hit
== PGB_BOTTOMORRIGHT
) && (infoPtr
->BRbtnState
== PGF_NORMAL
))
782 infoPtr
->BRbtnState
= PGF_HOT
;
783 btnstate
= infoPtr
->BRbtnState
;
786 /* If in one of the buttons the capture and draw buttons */
789 TRACE("[%p] draw btn (%s), Capture %s, style %08x\n",
790 infoPtr
->hwndSelf
, wine_dbgstr_rect(rect
),
791 (infoPtr
->bCapture
) ? "TRUE" : "FALSE",
793 if (!infoPtr
->bCapture
)
795 TRACE("[%p] SetCapture\n", infoPtr
->hwndSelf
);
796 SetCapture(infoPtr
->hwndSelf
);
797 infoPtr
->bCapture
= TRUE
;
799 if (infoPtr
->dwStyle
& PGS_AUTOSCROLL
)
800 SetTimer(infoPtr
->hwndSelf
, TIMERID1
, 0x3e, 0);
801 hdc
= GetWindowDC(infoPtr
->hwndSelf
);
802 /* OffsetRect(wnrect, 0 | 1, 0 | 1) */
803 PAGER_DrawButton(hdc
, infoPtr
->clrBk
, *rect
,
804 infoPtr
->dwStyle
& PGS_HORZ
, topLeft
, btnstate
);
805 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
810 /* If we think we are captured, then do release */
811 if (infoPtr
->bCapture
&& (WindowFromPoint(pt
) != infoPtr
->hwndSelf
))
815 infoPtr
->bCapture
= FALSE
;
817 if (GetCapture() == infoPtr
->hwndSelf
)
821 if (infoPtr
->TLbtnState
== PGF_GRAYED
)
823 infoPtr
->TLbtnState
= PGF_INVISIBLE
;
824 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, 0, 0,
825 SWP_FRAMECHANGED
| SWP_NOSIZE
| SWP_NOMOVE
|
826 SWP_NOZORDER
| SWP_NOACTIVATE
);
828 else if (infoPtr
->TLbtnState
== PGF_HOT
)
830 infoPtr
->TLbtnState
= PGF_NORMAL
;
831 /* FIXME: just invalidate button rect */
832 RedrawWindow(infoPtr
->hwndSelf
, NULL
, NULL
, RDW_FRAME
| RDW_INVALIDATE
);
835 if (infoPtr
->BRbtnState
== PGF_GRAYED
)
837 infoPtr
->BRbtnState
= PGF_INVISIBLE
;
838 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, 0, 0,
839 SWP_FRAMECHANGED
| SWP_NOSIZE
| SWP_NOMOVE
|
840 SWP_NOZORDER
| SWP_NOACTIVATE
);
842 else if (infoPtr
->BRbtnState
== PGF_HOT
)
844 infoPtr
->BRbtnState
= PGF_NORMAL
;
845 /* FIXME: just invalidate button rect */
846 RedrawWindow(infoPtr
->hwndSelf
, NULL
, NULL
, RDW_FRAME
| RDW_INVALIDATE
);
849 /* Notify parent of released mouse capture */
850 memset(&nmhdr
, 0, sizeof(NMHDR
));
851 nmhdr
.hwndFrom
= infoPtr
->hwndSelf
;
852 nmhdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
853 nmhdr
.code
= NM_RELEASEDCAPTURE
;
854 SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, nmhdr
.idFrom
, (LPARAM
)&nmhdr
);
856 if (IsWindow(infoPtr
->hwndSelf
))
857 KillTimer(infoPtr
->hwndSelf
, TIMERID1
);
863 PAGER_LButtonDown (PAGER_INFO
* infoPtr
, INT keys
, INT x
, INT y
)
865 BOOL repaintBtns
= FALSE
;
872 TRACE("[%p] at (%d,%d)\n", infoPtr
->hwndSelf
, x
, y
);
874 hit
= PAGER_HitTest(infoPtr
, &pt
);
876 /* put btn in DEPRESSED state */
877 if (hit
== PGB_TOPORLEFT
)
879 repaintBtns
= infoPtr
->TLbtnState
!= PGF_DEPRESSED
;
880 infoPtr
->TLbtnState
= PGF_DEPRESSED
;
881 SetTimer(infoPtr
->hwndSelf
, TIMERID1
, INITIAL_DELAY
, 0);
883 else if (hit
== PGB_BOTTOMORRIGHT
)
885 repaintBtns
= infoPtr
->BRbtnState
!= PGF_DEPRESSED
;
886 infoPtr
->BRbtnState
= PGF_DEPRESSED
;
887 SetTimer(infoPtr
->hwndSelf
, TIMERID1
, INITIAL_DELAY
, 0);
891 SendMessageW(infoPtr
->hwndSelf
, WM_NCPAINT
, 0, 0);
896 if (infoPtr
->dwStyle
& PGS_HORZ
)
898 TRACE("[%p] PGF_SCROLLLEFT\n", infoPtr
->hwndSelf
);
899 PAGER_Scroll(infoPtr
, PGF_SCROLLLEFT
);
903 TRACE("[%p] PGF_SCROLLUP\n", infoPtr
->hwndSelf
);
904 PAGER_Scroll(infoPtr
, PGF_SCROLLUP
);
907 case PGB_BOTTOMORRIGHT
:
908 if (infoPtr
->dwStyle
& PGS_HORZ
)
910 TRACE("[%p] PGF_SCROLLRIGHT\n", infoPtr
->hwndSelf
);
911 PAGER_Scroll(infoPtr
, PGF_SCROLLRIGHT
);
915 TRACE("[%p] PGF_SCROLLDOWN\n", infoPtr
->hwndSelf
);
916 PAGER_Scroll(infoPtr
, PGF_SCROLLDOWN
);
927 PAGER_LButtonUp (PAGER_INFO
* infoPtr
, INT keys
, INT x
, INT y
)
929 TRACE("[%p]\n", infoPtr
->hwndSelf
);
931 KillTimer (infoPtr
->hwndSelf
, TIMERID1
);
932 KillTimer (infoPtr
->hwndSelf
, TIMERID2
);
934 /* make PRESSED btns NORMAL but don't hide gray btns */
935 if (infoPtr
->TLbtnState
& (PGF_HOT
| PGF_DEPRESSED
))
936 infoPtr
->TLbtnState
= PGF_NORMAL
;
937 if (infoPtr
->BRbtnState
& (PGF_HOT
| PGF_DEPRESSED
))
938 infoPtr
->BRbtnState
= PGF_NORMAL
;
944 PAGER_Timer (PAGER_INFO
* infoPtr
, INT nTimerId
)
948 /* if initial timer, kill it and start the repeat timer */
949 if (nTimerId
== TIMERID1
) {
950 if (infoPtr
->TLbtnState
== PGF_HOT
)
951 dir
= (infoPtr
->dwStyle
& PGS_HORZ
) ?
952 PGF_SCROLLLEFT
: PGF_SCROLLUP
;
954 dir
= (infoPtr
->dwStyle
& PGS_HORZ
) ?
955 PGF_SCROLLRIGHT
: PGF_SCROLLDOWN
;
956 TRACE("[%p] TIMERID1: style=%08x, dir=%d\n",
957 infoPtr
->hwndSelf
, infoPtr
->dwStyle
, dir
);
958 KillTimer(infoPtr
->hwndSelf
, TIMERID1
);
959 SetTimer(infoPtr
->hwndSelf
, TIMERID1
, REPEAT_DELAY
, 0);
960 if (infoPtr
->dwStyle
& PGS_AUTOSCROLL
) {
961 PAGER_Scroll(infoPtr
, dir
);
962 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, 0, 0,
963 SWP_FRAMECHANGED
| SWP_NOSIZE
| SWP_NOMOVE
|
964 SWP_NOZORDER
| SWP_NOACTIVATE
);
970 TRACE("[%p] TIMERID2: dir=%d\n", infoPtr
->hwndSelf
, infoPtr
->direction
);
971 KillTimer(infoPtr
->hwndSelf
, TIMERID2
);
972 if (infoPtr
->direction
> 0) {
973 PAGER_Scroll(infoPtr
, infoPtr
->direction
);
974 SetTimer(infoPtr
->hwndSelf
, TIMERID2
, REPEAT_DELAY
, 0);
980 PAGER_EraseBackground (const PAGER_INFO
* infoPtr
, HDC hdc
)
988 parent
= GetParent(infoPtr
->hwndSelf
);
989 MapWindowPoints(infoPtr
->hwndSelf
, parent
, &pt
, 1);
990 OffsetWindowOrgEx (hdc
, pt
.x
, pt
.y
, &ptorig
);
991 ret
= SendMessageW (parent
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
992 SetWindowOrgEx (hdc
, ptorig
.x
, ptorig
.y
, 0);
999 PAGER_Size (PAGER_INFO
* infoPtr
, INT type
, INT x
, INT y
)
1001 /* note that WM_SIZE is sent whenever NCCalcSize resizes the client wnd */
1003 TRACE("[%p] %d,%d\n", infoPtr
->hwndSelf
, x
, y
);
1005 if (infoPtr
->dwStyle
& PGS_HORZ
)
1006 infoPtr
->nHeight
= y
;
1008 infoPtr
->nWidth
= x
;
1010 return PAGER_RecalcSize(infoPtr
);
1015 PAGER_StyleChanged(PAGER_INFO
*infoPtr
, WPARAM wStyleType
, const STYLESTRUCT
*lpss
)
1017 DWORD oldStyle
= infoPtr
->dwStyle
;
1019 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
1020 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
1022 if (wStyleType
!= GWL_STYLE
) return 0;
1024 infoPtr
->dwStyle
= lpss
->styleNew
;
1026 if ((oldStyle
^ lpss
->styleNew
) & (PGS_HORZ
| PGS_VERT
))
1028 PAGER_RecalcSize(infoPtr
);
1034 static LRESULT WINAPI
1035 PAGER_WindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1037 PAGER_INFO
*infoPtr
= (PAGER_INFO
*)GetWindowLongPtrW(hwnd
, 0);
1039 if (!infoPtr
&& (uMsg
!= WM_CREATE
))
1040 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
1045 return PAGER_FmtLines(infoPtr
);
1047 case PGM_FORWARDMOUSE
:
1048 return PAGER_ForwardMouse (infoPtr
, (BOOL
)wParam
);
1050 case PGM_GETBKCOLOR
:
1051 return PAGER_GetBkColor(infoPtr
);
1054 return PAGER_GetBorder(infoPtr
);
1056 case PGM_GETBUTTONSIZE
:
1057 return PAGER_GetButtonSize(infoPtr
);
1060 return PAGER_GetPos(infoPtr
);
1062 case PGM_GETBUTTONSTATE
:
1063 return PAGER_GetButtonState (infoPtr
, (INT
)lParam
);
1065 /* case PGM_GETDROPTARGET: */
1067 case PGM_RECALCSIZE
:
1068 return PAGER_RecalcSize(infoPtr
);
1070 case PGM_SETBKCOLOR
:
1071 return PAGER_SetBkColor (infoPtr
, (COLORREF
)lParam
);
1074 return PAGER_SetBorder (infoPtr
, (INT
)lParam
);
1076 case PGM_SETBUTTONSIZE
:
1077 return PAGER_SetButtonSize (infoPtr
, (INT
)lParam
);
1080 return PAGER_SetChild (infoPtr
, (HWND
)lParam
);
1083 return PAGER_SetPos(infoPtr
, (INT
)lParam
, FALSE
);
1086 return PAGER_Create (hwnd
, (LPCREATESTRUCTW
)lParam
);
1089 return PAGER_Destroy (infoPtr
);
1092 return PAGER_Size (infoPtr
, (INT
)wParam
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
1095 return PAGER_NCPaint (infoPtr
, (HRGN
)wParam
);
1097 case WM_WINDOWPOSCHANGING
:
1098 return PAGER_WindowPosChanging (infoPtr
, (WINDOWPOS
*)lParam
);
1100 case WM_STYLECHANGED
:
1101 return PAGER_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
1104 return PAGER_NCCalcSize (infoPtr
, wParam
, (LPRECT
)lParam
);
1107 return PAGER_NCHitTest (infoPtr
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
1110 if (infoPtr
->bForward
&& infoPtr
->hwndChild
)
1111 PostMessageW(infoPtr
->hwndChild
, WM_MOUSEMOVE
, wParam
, lParam
);
1112 return PAGER_MouseMove (infoPtr
, (INT
)wParam
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
1114 case WM_LBUTTONDOWN
:
1115 return PAGER_LButtonDown (infoPtr
, (INT
)wParam
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
1118 return PAGER_LButtonUp (infoPtr
, (INT
)wParam
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
1121 return PAGER_EraseBackground (infoPtr
, (HDC
)wParam
);
1124 return PAGER_Timer (infoPtr
, (INT
)wParam
);
1128 return SendMessageW (infoPtr
->hwndNotify
, uMsg
, wParam
, lParam
);
1131 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
1137 PAGER_Register (void)
1141 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
1142 wndClass
.style
= CS_GLOBALCLASS
;
1143 wndClass
.lpfnWndProc
= PAGER_WindowProc
;
1144 wndClass
.cbClsExtra
= 0;
1145 wndClass
.cbWndExtra
= sizeof(PAGER_INFO
*);
1146 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
1147 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+1);
1148 wndClass
.lpszClassName
= WC_PAGESCROLLERW
;
1150 RegisterClassW (&wndClass
);
1155 PAGER_Unregister (void)
1157 UnregisterClassW (WC_PAGESCROLLERW
, NULL
);