wined3d: Add basic support for rendering to 3D textures.
[wine.git] / dlls / comctl32 / pager.c
bloba10d3bb30fe5e95a977405b118a6619133a88e5d
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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
37 * Messages:
38 * WM_PRINT and/or WM_PRINTCLIENT
40 * TESTING:
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>
55 #include <stdarg.h>
56 #include <string.h>
57 #include "windef.h"
58 #include "winbase.h"
59 #include "wingdi.h"
60 #include "winuser.h"
61 #include "winnls.h"
62 #include "commctrl.h"
63 #include "comctl32.h"
64 #include "wine/debug.h"
66 WINE_DEFAULT_DEBUG_CHANNEL(pager);
68 typedef struct
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) */
85 } PAGER_INFO;
87 #define TIMERID1 1
88 #define TIMERID2 2
89 #define INITIAL_DELAY 500
90 #define REPEAT_DELAY 50
92 static void
93 PAGER_GetButtonRects(const PAGER_INFO* infoPtr, RECT* prcTopLeft, RECT* prcBottomRight, BOOL bClientCoords)
95 RECT rcWindow;
96 GetWindowRect (infoPtr->hwndSelf, &rcWindow);
98 if (bClientCoords)
99 MapWindowPoints( 0, infoPtr->hwndSelf, (POINT *)&rcWindow, 2 );
100 else
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;
109 else
111 prcTopLeft->bottom = prcTopLeft->top + infoPtr->nButtonSize;
112 prcBottomRight->top = prcBottomRight->bottom - infoPtr->nButtonSize;
116 static void
117 PAGER_DrawButton(HDC hdc, COLORREF clrBk, RECT rc,
118 BOOL horz, BOOL topLeft, INT btnState)
120 UINT flags;
122 TRACE("rc = %s, btnState = %d\n", wine_dbgstr_rect(&rc), btnState);
124 if (btnState == PGF_INVISIBLE)
125 return;
127 if ((rc.right - rc.left <= 0) || (rc.bottom - rc.top <= 0))
128 return;
130 if (horz)
131 flags = topLeft ? DFCS_SCROLLLEFT : DFCS_SCROLLRIGHT;
132 else
133 flags = topLeft ? DFCS_SCROLLUP : DFCS_SCROLLDOWN;
135 switch (btnState)
137 case PGF_HOT:
138 break;
139 case PGF_NORMAL:
140 flags |= DFCS_FLAT;
141 break;
142 case PGF_DEPRESSED:
143 flags |= DFCS_PUSHED;
144 break;
145 case PGF_GRAYED:
146 flags |= DFCS_INACTIVE | DFCS_FLAT;
147 break;
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;
161 return 0;
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;
175 return btnState;
179 static inline INT
180 PAGER_GetPos(const PAGER_INFO *infoPtr)
182 TRACE("[%p] returns %d\n", infoPtr->hwndSelf, infoPtr->nPos);
183 return infoPtr->nPos;
186 static inline INT
187 PAGER_GetButtonSize(const PAGER_INFO *infoPtr)
189 TRACE("[%p] returns %d\n", infoPtr->hwndSelf, infoPtr->nButtonSize);
190 return infoPtr->nButtonSize;
193 static inline INT
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;
207 static void
208 PAGER_CalcSize( PAGER_INFO *infoPtr )
210 NMPGCALCSIZE nmpgcs;
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;
222 else
223 infoPtr->nHeight = nmpgcs.iHeight;
225 TRACE("[%p] PGN_CALCSIZE returns %dx%d\n", infoPtr->hwndSelf, nmpgcs.iWidth, nmpgcs.iHeight );
228 static void
229 PAGER_PositionChildWnd(PAGER_INFO* infoPtr)
231 if (infoPtr->hwndChild)
233 RECT rcClient;
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,
250 -nPos, 0);
251 SetWindowPos(infoPtr->hwndChild, 0,
252 -nPos, 0,
253 infoPtr->nWidth, infoPtr->nHeight,
254 SWP_NOZORDER);
256 else
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,
264 0, -nPos);
265 SetWindowPos(infoPtr->hwndChild, 0,
266 0, -nPos,
267 infoPtr->nWidth, infoPtr->nHeight,
268 SWP_NOZORDER);
271 InvalidateRect(infoPtr->hwndChild, NULL, TRUE);
275 static INT
276 PAGER_GetScrollRange(PAGER_INFO* infoPtr)
278 INT scrollRange = 0;
280 if (infoPtr->hwndChild)
282 INT wndSize, childSize;
283 RECT wndRect;
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;
292 else
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);
304 return scrollRange;
307 static void
308 PAGER_UpdateBtns(PAGER_INFO *infoPtr, INT scrollRange, BOOL hideGrayBtns)
310 BOOL resizeClient;
311 BOOL repaintBtns;
312 INT oldTLbtnState = infoPtr->TLbtnState;
313 INT oldBRbtnState = infoPtr->BRbtnState;
314 POINT pt;
315 RECT rcTopLeft, rcBottomRight;
317 /* get button rects */
318 PAGER_GetButtonRects(infoPtr, &rcTopLeft, &rcBottomRight, TRUE);
320 GetCursorPos(&pt);
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;
331 else
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;
346 else
347 infoPtr->BRbtnState = PGF_INVISIBLE;
349 /* only need to resize when entering or leaving PGF_INVISIBLE state */
350 resizeClient =
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 */
354 if (resizeClient)
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);
362 if (repaintBtns)
363 SendMessageW(infoPtr->hwndSelf, WM_NCPAINT, 0, 0);
366 static LRESULT
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))
373 infoPtr->nPos = 0;
374 else if (newPos > scrollRange)
375 infoPtr->nPos = scrollRange;
376 else
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);
388 return 0;
391 /******************************************************************
392 * For the PGM_RECALCSIZE message (but not the other uses in *
393 * this module), the native control does only the following: *
395 * if (some condition) *
396 * PostMessageW(hwnd, EM_FMTLINES, 0, 0); *
397 * return DefWindowProcW(hwnd, PGM_RECALCSIZE, 0, 0); *
399 * When we figure out what the "some condition" is we will *
400 * implement that for the message processing. *
401 ******************************************************************/
403 static LRESULT
404 PAGER_RecalcSize(PAGER_INFO *infoPtr)
406 TRACE("[%p]\n", infoPtr->hwndSelf);
408 if (infoPtr->hwndChild)
410 INT scrollRange = PAGER_GetScrollRange(infoPtr);
412 if (scrollRange <= 0)
414 infoPtr->nPos = -1;
415 PAGER_SetPos(infoPtr, 0, FALSE);
417 else
418 PAGER_PositionChildWnd(infoPtr);
421 return 1;
425 static COLORREF
426 PAGER_SetBkColor (PAGER_INFO* infoPtr, COLORREF clrBk)
428 COLORREF clrTemp = infoPtr->clrBk;
430 infoPtr->clrBk = clrBk;
431 TRACE("[%p] %06x\n", infoPtr->hwndSelf, infoPtr->clrBk);
433 /* the native control seems to do things this way */
434 SetWindowPos(infoPtr->hwndSelf, 0, 0, 0, 0, 0,
435 SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE |
436 SWP_NOZORDER | SWP_NOACTIVATE);
438 RedrawWindow(infoPtr->hwndSelf, 0, 0, RDW_ERASE | RDW_INVALIDATE);
440 return clrTemp;
444 static INT
445 PAGER_SetBorder (PAGER_INFO* infoPtr, INT iBorder)
447 INT nTemp = infoPtr->nBorder;
449 infoPtr->nBorder = iBorder;
450 TRACE("[%p] %d\n", infoPtr->hwndSelf, infoPtr->nBorder);
452 PAGER_RecalcSize(infoPtr);
454 return nTemp;
458 static INT
459 PAGER_SetButtonSize (PAGER_INFO* infoPtr, INT iButtonSize)
461 INT nTemp = infoPtr->nButtonSize;
463 infoPtr->nButtonSize = iButtonSize;
464 TRACE("[%p] %d\n", infoPtr->hwndSelf, infoPtr->nButtonSize);
466 PAGER_RecalcSize(infoPtr);
468 return nTemp;
472 static LRESULT
473 PAGER_SetChild (PAGER_INFO* infoPtr, HWND hwndChild)
475 infoPtr->hwndChild = IsWindow (hwndChild) ? hwndChild : 0;
477 if (infoPtr->hwndChild)
479 TRACE("[%p] hwndChild=%p\n", infoPtr->hwndSelf, infoPtr->hwndChild);
481 SetWindowPos(infoPtr->hwndSelf, 0, 0, 0, 0, 0,
482 SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE);
484 /* position child within the page scroller */
485 SetWindowPos(infoPtr->hwndChild, HWND_TOP,
486 0,0,0,0,
487 SWP_SHOWWINDOW | SWP_NOSIZE); /* native is 0 */
489 infoPtr->nPos = -1;
490 PAGER_SetPos(infoPtr, 0, FALSE);
493 return 0;
496 static void
497 PAGER_Scroll(PAGER_INFO* infoPtr, INT dir)
499 NMPGSCROLL nmpgScroll;
500 RECT rcWnd;
502 if (infoPtr->hwndChild)
504 ZeroMemory (&nmpgScroll, sizeof (NMPGSCROLL));
505 nmpgScroll.hdr.hwndFrom = infoPtr->hwndSelf;
506 nmpgScroll.hdr.idFrom = GetWindowLongPtrW (infoPtr->hwndSelf, GWLP_ID);
507 nmpgScroll.hdr.code = PGN_SCROLL;
509 GetWindowRect(infoPtr->hwndSelf, &rcWnd);
510 GetClientRect(infoPtr->hwndSelf, &nmpgScroll.rcParent);
511 nmpgScroll.iXpos = nmpgScroll.iYpos = 0;
512 nmpgScroll.iDir = dir;
514 if (infoPtr->dwStyle & PGS_HORZ)
516 nmpgScroll.iScroll = rcWnd.right - rcWnd.left;
517 nmpgScroll.iXpos = infoPtr->nPos;
519 else
521 nmpgScroll.iScroll = rcWnd.bottom - rcWnd.top;
522 nmpgScroll.iYpos = infoPtr->nPos;
524 nmpgScroll.iScroll -= 2*infoPtr->nButtonSize;
526 SendMessageW (infoPtr->hwndNotify, WM_NOTIFY, nmpgScroll.hdr.idFrom, (LPARAM)&nmpgScroll);
528 TRACE("[%p] PGN_SCROLL returns iScroll=%d\n", infoPtr->hwndSelf, nmpgScroll.iScroll);
530 if (nmpgScroll.iScroll > 0)
532 infoPtr->direction = dir;
534 if (dir == PGF_SCROLLLEFT || dir == PGF_SCROLLUP)
535 PAGER_SetPos(infoPtr, infoPtr->nPos - nmpgScroll.iScroll, TRUE);
536 else
537 PAGER_SetPos(infoPtr, infoPtr->nPos + nmpgScroll.iScroll, TRUE);
539 else
540 infoPtr->direction = -1;
544 static LRESULT
545 PAGER_FmtLines(const PAGER_INFO *infoPtr)
547 /* initiate NCCalcSize to resize client wnd and get size */
548 SetWindowPos(infoPtr->hwndSelf, 0, 0, 0, 0, 0,
549 SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE |
550 SWP_NOZORDER | SWP_NOACTIVATE);
552 SetWindowPos(infoPtr->hwndChild, 0,
553 0,0,infoPtr->nWidth,infoPtr->nHeight,
556 return DefWindowProcW (infoPtr->hwndSelf, EM_FMTLINES, 0, 0);
559 static LRESULT
560 PAGER_Create (HWND hwnd, const CREATESTRUCTW *lpcs)
562 PAGER_INFO *infoPtr;
564 /* allocate memory for info structure */
565 infoPtr = Alloc (sizeof(PAGER_INFO));
566 if (!infoPtr) return -1;
567 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
569 /* set default settings */
570 infoPtr->hwndSelf = hwnd;
571 infoPtr->hwndChild = NULL;
572 infoPtr->hwndNotify = lpcs->hwndParent;
573 infoPtr->dwStyle = lpcs->style;
574 infoPtr->clrBk = GetSysColor(COLOR_BTNFACE);
575 infoPtr->nBorder = 0;
576 infoPtr->nButtonSize = 12;
577 infoPtr->nPos = 0;
578 infoPtr->nWidth = 0;
579 infoPtr->nHeight = 0;
580 infoPtr->bForward = FALSE;
581 infoPtr->bCapture = FALSE;
582 infoPtr->TLbtnState = PGF_INVISIBLE;
583 infoPtr->BRbtnState = PGF_INVISIBLE;
584 infoPtr->direction = -1;
586 if (infoPtr->dwStyle & PGS_DRAGNDROP)
587 FIXME("[%p] Drag and Drop style is not implemented yet.\n", infoPtr->hwndSelf);
589 return 0;
593 static LRESULT
594 PAGER_Destroy (PAGER_INFO *infoPtr)
596 SetWindowLongPtrW (infoPtr->hwndSelf, 0, 0);
597 Free (infoPtr); /* free pager info data */
598 return 0;
601 static LRESULT
602 PAGER_NCCalcSize(PAGER_INFO* infoPtr, WPARAM wParam, LPRECT lpRect)
604 RECT rcChild, rcWindow;
607 * lpRect points to a RECT struct. On entry, the struct
608 * contains the proposed wnd rectangle for the window.
609 * On exit, the struct should contain the screen
610 * coordinates of the corresponding window's client area.
613 DefWindowProcW (infoPtr->hwndSelf, WM_NCCALCSIZE, wParam, (LPARAM)lpRect);
615 TRACE("orig rect=%s\n", wine_dbgstr_rect(lpRect));
617 GetWindowRect (infoPtr->hwndChild, &rcChild);
618 MapWindowPoints (0, infoPtr->hwndSelf, (LPPOINT)&rcChild, 2); /* FIXME: RECT != 2 POINTS */
619 GetWindowRect (infoPtr->hwndSelf, &rcWindow);
621 infoPtr->nWidth = lpRect->right - lpRect->left;
622 infoPtr->nHeight = lpRect->bottom - lpRect->top;
623 PAGER_CalcSize( infoPtr );
625 if (infoPtr->dwStyle & PGS_HORZ)
627 if (infoPtr->TLbtnState && (lpRect->left + infoPtr->nButtonSize < lpRect->right))
628 lpRect->left += infoPtr->nButtonSize;
629 if (infoPtr->BRbtnState && (lpRect->right - infoPtr->nButtonSize > lpRect->left))
630 lpRect->right -= infoPtr->nButtonSize;
632 else
634 if (infoPtr->TLbtnState && (lpRect->top + infoPtr->nButtonSize < lpRect->bottom))
635 lpRect->top += infoPtr->nButtonSize;
636 if (infoPtr->BRbtnState && (lpRect->bottom - infoPtr->nButtonSize > lpRect->top))
637 lpRect->bottom -= infoPtr->nButtonSize;
640 TRACE("nPos=%d, nHeight=%d, window=%s\n", infoPtr->nPos, infoPtr->nHeight, wine_dbgstr_rect(&rcWindow));
641 TRACE("[%p] client rect set to %s BtnState[%d,%d]\n", infoPtr->hwndSelf, wine_dbgstr_rect(lpRect),
642 infoPtr->TLbtnState, infoPtr->BRbtnState);
644 return 0;
647 static LRESULT
648 PAGER_NCPaint (const PAGER_INFO* infoPtr, HRGN hRgn)
650 RECT rcBottomRight, rcTopLeft;
651 HDC hdc;
653 if (infoPtr->dwStyle & WS_MINIMIZE)
654 return 0;
656 DefWindowProcW (infoPtr->hwndSelf, WM_NCPAINT, (WPARAM)hRgn, 0);
658 if (!(hdc = GetDCEx (infoPtr->hwndSelf, 0, DCX_USESTYLE | DCX_WINDOW)))
659 return 0;
661 PAGER_GetButtonRects(infoPtr, &rcTopLeft, &rcBottomRight, FALSE);
663 PAGER_DrawButton(hdc, infoPtr->clrBk, rcTopLeft,
664 infoPtr->dwStyle & PGS_HORZ, TRUE, infoPtr->TLbtnState);
665 PAGER_DrawButton(hdc, infoPtr->clrBk, rcBottomRight,
666 infoPtr->dwStyle & PGS_HORZ, FALSE, infoPtr->BRbtnState);
668 ReleaseDC( infoPtr->hwndSelf, hdc );
669 return 0;
672 static INT
673 PAGER_HitTest (const PAGER_INFO* infoPtr, const POINT * pt)
675 RECT clientRect, rcTopLeft, rcBottomRight;
676 POINT ptWindow;
678 GetClientRect (infoPtr->hwndSelf, &clientRect);
680 if (PtInRect(&clientRect, *pt))
682 TRACE("child\n");
683 return -1;
686 ptWindow = *pt;
687 PAGER_GetButtonRects(infoPtr, &rcTopLeft, &rcBottomRight, TRUE);
689 if ((infoPtr->TLbtnState != PGF_INVISIBLE) && PtInRect(&rcTopLeft, ptWindow))
691 TRACE("PGB_TOPORLEFT\n");
692 return PGB_TOPORLEFT;
694 else if ((infoPtr->BRbtnState != PGF_INVISIBLE) && PtInRect(&rcBottomRight, ptWindow))
696 TRACE("PGB_BOTTOMORRIGHT\n");
697 return PGB_BOTTOMORRIGHT;
700 TRACE("nowhere\n");
701 return -1;
704 static LRESULT
705 PAGER_NCHitTest (const PAGER_INFO* infoPtr, INT x, INT y)
707 POINT pt;
708 INT nHit;
710 pt.x = x;
711 pt.y = y;
713 ScreenToClient (infoPtr->hwndSelf, &pt);
714 nHit = PAGER_HitTest(infoPtr, &pt);
716 return (nHit < 0) ? HTTRANSPARENT : HTCLIENT;
719 static LRESULT
720 PAGER_MouseMove (PAGER_INFO* infoPtr, INT keys, INT x, INT y)
722 POINT clpt, pt;
723 RECT wnrect;
724 BOOL topLeft = FALSE;
725 INT btnstate = 0;
726 INT hit;
727 HDC hdc;
729 pt.x = x;
730 pt.y = y;
732 TRACE("[%p] to (%d,%d)\n", infoPtr->hwndSelf, x, y);
733 ClientToScreen(infoPtr->hwndSelf, &pt);
734 GetWindowRect(infoPtr->hwndSelf, &wnrect);
735 if (PtInRect(&wnrect, pt)) {
736 RECT topleft, bottomright, *rect = NULL;
738 PAGER_GetButtonRects(infoPtr, &topleft, &bottomright, FALSE);
740 clpt = pt;
741 MapWindowPoints(0, infoPtr->hwndSelf, &clpt, 1);
742 hit = PAGER_HitTest(infoPtr, &clpt);
743 if ((hit == PGB_TOPORLEFT) && (infoPtr->TLbtnState == PGF_NORMAL))
745 topLeft = TRUE;
746 rect = &topleft;
747 infoPtr->TLbtnState = PGF_HOT;
748 btnstate = infoPtr->TLbtnState;
750 else if ((hit == PGB_BOTTOMORRIGHT) && (infoPtr->BRbtnState == PGF_NORMAL))
752 topLeft = FALSE;
753 rect = &bottomright;
754 infoPtr->BRbtnState = PGF_HOT;
755 btnstate = infoPtr->BRbtnState;
758 /* If in one of the buttons the capture and draw buttons */
759 if (rect)
761 TRACE("[%p] draw btn (%s), Capture %s, style %08x\n",
762 infoPtr->hwndSelf, wine_dbgstr_rect(rect),
763 (infoPtr->bCapture) ? "TRUE" : "FALSE",
764 infoPtr->dwStyle);
765 if (!infoPtr->bCapture)
767 TRACE("[%p] SetCapture\n", infoPtr->hwndSelf);
768 SetCapture(infoPtr->hwndSelf);
769 infoPtr->bCapture = TRUE;
771 if (infoPtr->dwStyle & PGS_AUTOSCROLL)
772 SetTimer(infoPtr->hwndSelf, TIMERID1, 0x3e, 0);
773 hdc = GetWindowDC(infoPtr->hwndSelf);
774 /* OffsetRect(wnrect, 0 | 1, 0 | 1) */
775 PAGER_DrawButton(hdc, infoPtr->clrBk, *rect,
776 infoPtr->dwStyle & PGS_HORZ, topLeft, btnstate);
777 ReleaseDC(infoPtr->hwndSelf, hdc);
778 return 0;
782 /* If we think we are captured, then do release */
783 if (infoPtr->bCapture && (WindowFromPoint(pt) != infoPtr->hwndSelf))
785 NMHDR nmhdr;
787 infoPtr->bCapture = FALSE;
789 if (GetCapture() == infoPtr->hwndSelf)
791 ReleaseCapture();
793 if (infoPtr->TLbtnState == PGF_GRAYED)
795 infoPtr->TLbtnState = PGF_INVISIBLE;
796 SetWindowPos(infoPtr->hwndSelf, 0, 0, 0, 0, 0,
797 SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE |
798 SWP_NOZORDER | SWP_NOACTIVATE);
800 else if (infoPtr->TLbtnState == PGF_HOT)
802 infoPtr->TLbtnState = PGF_NORMAL;
803 /* FIXME: just invalidate button rect */
804 RedrawWindow(infoPtr->hwndSelf, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
807 if (infoPtr->BRbtnState == PGF_GRAYED)
809 infoPtr->BRbtnState = PGF_INVISIBLE;
810 SetWindowPos(infoPtr->hwndSelf, 0, 0, 0, 0, 0,
811 SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE |
812 SWP_NOZORDER | SWP_NOACTIVATE);
814 else if (infoPtr->BRbtnState == PGF_HOT)
816 infoPtr->BRbtnState = PGF_NORMAL;
817 /* FIXME: just invalidate button rect */
818 RedrawWindow(infoPtr->hwndSelf, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
821 /* Notify parent of released mouse capture */
822 memset(&nmhdr, 0, sizeof(NMHDR));
823 nmhdr.hwndFrom = infoPtr->hwndSelf;
824 nmhdr.idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
825 nmhdr.code = NM_RELEASEDCAPTURE;
826 SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, nmhdr.idFrom, (LPARAM)&nmhdr);
828 if (IsWindow(infoPtr->hwndSelf))
829 KillTimer(infoPtr->hwndSelf, TIMERID1);
831 return 0;
834 static LRESULT
835 PAGER_LButtonDown (PAGER_INFO* infoPtr, INT keys, INT x, INT y)
837 BOOL repaintBtns = FALSE;
838 POINT pt;
839 INT hit;
841 pt.x = x;
842 pt.y = y;
844 TRACE("[%p] at (%d,%d)\n", infoPtr->hwndSelf, x, y);
846 hit = PAGER_HitTest(infoPtr, &pt);
848 /* put btn in DEPRESSED state */
849 if (hit == PGB_TOPORLEFT)
851 repaintBtns = infoPtr->TLbtnState != PGF_DEPRESSED;
852 infoPtr->TLbtnState = PGF_DEPRESSED;
853 SetTimer(infoPtr->hwndSelf, TIMERID1, INITIAL_DELAY, 0);
855 else if (hit == PGB_BOTTOMORRIGHT)
857 repaintBtns = infoPtr->BRbtnState != PGF_DEPRESSED;
858 infoPtr->BRbtnState = PGF_DEPRESSED;
859 SetTimer(infoPtr->hwndSelf, TIMERID1, INITIAL_DELAY, 0);
862 if (repaintBtns)
863 SendMessageW(infoPtr->hwndSelf, WM_NCPAINT, 0, 0);
865 switch(hit)
867 case PGB_TOPORLEFT:
868 if (infoPtr->dwStyle & PGS_HORZ)
870 TRACE("[%p] PGF_SCROLLLEFT\n", infoPtr->hwndSelf);
871 PAGER_Scroll(infoPtr, PGF_SCROLLLEFT);
873 else
875 TRACE("[%p] PGF_SCROLLUP\n", infoPtr->hwndSelf);
876 PAGER_Scroll(infoPtr, PGF_SCROLLUP);
878 break;
879 case PGB_BOTTOMORRIGHT:
880 if (infoPtr->dwStyle & PGS_HORZ)
882 TRACE("[%p] PGF_SCROLLRIGHT\n", infoPtr->hwndSelf);
883 PAGER_Scroll(infoPtr, PGF_SCROLLRIGHT);
885 else
887 TRACE("[%p] PGF_SCROLLDOWN\n", infoPtr->hwndSelf);
888 PAGER_Scroll(infoPtr, PGF_SCROLLDOWN);
890 break;
891 default:
892 break;
895 return 0;
898 static LRESULT
899 PAGER_LButtonUp (PAGER_INFO* infoPtr, INT keys, INT x, INT y)
901 TRACE("[%p]\n", infoPtr->hwndSelf);
903 KillTimer (infoPtr->hwndSelf, TIMERID1);
904 KillTimer (infoPtr->hwndSelf, TIMERID2);
906 /* make PRESSED btns NORMAL but don't hide gray btns */
907 if (infoPtr->TLbtnState & (PGF_HOT | PGF_DEPRESSED))
908 infoPtr->TLbtnState = PGF_NORMAL;
909 if (infoPtr->BRbtnState & (PGF_HOT | PGF_DEPRESSED))
910 infoPtr->BRbtnState = PGF_NORMAL;
912 return 0;
915 static LRESULT
916 PAGER_Timer (PAGER_INFO* infoPtr, INT nTimerId)
918 INT dir;
920 /* if initial timer, kill it and start the repeat timer */
921 if (nTimerId == TIMERID1) {
922 if (infoPtr->TLbtnState == PGF_HOT)
923 dir = (infoPtr->dwStyle & PGS_HORZ) ?
924 PGF_SCROLLLEFT : PGF_SCROLLUP;
925 else
926 dir = (infoPtr->dwStyle & PGS_HORZ) ?
927 PGF_SCROLLRIGHT : PGF_SCROLLDOWN;
928 TRACE("[%p] TIMERID1: style=%08x, dir=%d\n",
929 infoPtr->hwndSelf, infoPtr->dwStyle, dir);
930 KillTimer(infoPtr->hwndSelf, TIMERID1);
931 SetTimer(infoPtr->hwndSelf, TIMERID1, REPEAT_DELAY, 0);
932 if (infoPtr->dwStyle & PGS_AUTOSCROLL) {
933 PAGER_Scroll(infoPtr, dir);
934 SetWindowPos(infoPtr->hwndSelf, 0, 0, 0, 0, 0,
935 SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE |
936 SWP_NOZORDER | SWP_NOACTIVATE);
938 return 0;
942 TRACE("[%p] TIMERID2: dir=%d\n", infoPtr->hwndSelf, infoPtr->direction);
943 KillTimer(infoPtr->hwndSelf, TIMERID2);
944 if (infoPtr->direction > 0) {
945 PAGER_Scroll(infoPtr, infoPtr->direction);
946 SetTimer(infoPtr->hwndSelf, TIMERID2, REPEAT_DELAY, 0);
948 return 0;
951 static LRESULT
952 PAGER_EraseBackground (const PAGER_INFO* infoPtr, HDC hdc)
954 POINT pt, ptorig;
955 HWND parent;
956 LRESULT ret;
958 pt.x = 0;
959 pt.y = 0;
960 parent = GetParent(infoPtr->hwndSelf);
961 MapWindowPoints(infoPtr->hwndSelf, parent, &pt, 1);
962 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
963 ret = SendMessageW (parent, WM_ERASEBKGND, (WPARAM)hdc, 0);
964 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
966 return ret;
970 static LRESULT
971 PAGER_Size (PAGER_INFO* infoPtr, INT type, INT x, INT y)
973 /* note that WM_SIZE is sent whenever NCCalcSize resizes the client wnd */
975 TRACE("[%p] %d,%d\n", infoPtr->hwndSelf, x, y);
977 if (infoPtr->dwStyle & PGS_HORZ)
978 infoPtr->nHeight = y;
979 else
980 infoPtr->nWidth = x;
982 return PAGER_RecalcSize(infoPtr);
986 static LRESULT
987 PAGER_StyleChanged(PAGER_INFO *infoPtr, WPARAM wStyleType, const STYLESTRUCT *lpss)
989 DWORD oldStyle = infoPtr->dwStyle;
991 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
992 wStyleType, lpss->styleOld, lpss->styleNew);
994 if (wStyleType != GWL_STYLE) return 0;
996 infoPtr->dwStyle = lpss->styleNew;
998 if ((oldStyle ^ lpss->styleNew) & (PGS_HORZ | PGS_VERT))
1000 PAGER_RecalcSize(infoPtr);
1003 return 0;
1006 static LRESULT WINAPI
1007 PAGER_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1009 PAGER_INFO *infoPtr = (PAGER_INFO *)GetWindowLongPtrW(hwnd, 0);
1011 TRACE("(%p, %#x, %#lx, %#lx)\n", hwnd, uMsg, wParam, lParam);
1013 if (!infoPtr && (uMsg != WM_CREATE))
1014 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
1016 switch (uMsg)
1018 case EM_FMTLINES:
1019 return PAGER_FmtLines(infoPtr);
1021 case PGM_FORWARDMOUSE:
1022 return PAGER_ForwardMouse (infoPtr, (BOOL)wParam);
1024 case PGM_GETBKCOLOR:
1025 return PAGER_GetBkColor(infoPtr);
1027 case PGM_GETBORDER:
1028 return PAGER_GetBorder(infoPtr);
1030 case PGM_GETBUTTONSIZE:
1031 return PAGER_GetButtonSize(infoPtr);
1033 case PGM_GETPOS:
1034 return PAGER_GetPos(infoPtr);
1036 case PGM_GETBUTTONSTATE:
1037 return PAGER_GetButtonState (infoPtr, (INT)lParam);
1039 /* case PGM_GETDROPTARGET: */
1041 case PGM_RECALCSIZE:
1042 return PAGER_RecalcSize(infoPtr);
1044 case PGM_SETBKCOLOR:
1045 return PAGER_SetBkColor (infoPtr, (COLORREF)lParam);
1047 case PGM_SETBORDER:
1048 return PAGER_SetBorder (infoPtr, (INT)lParam);
1050 case PGM_SETBUTTONSIZE:
1051 return PAGER_SetButtonSize (infoPtr, (INT)lParam);
1053 case PGM_SETCHILD:
1054 return PAGER_SetChild (infoPtr, (HWND)lParam);
1056 case PGM_SETPOS:
1057 return PAGER_SetPos(infoPtr, (INT)lParam, FALSE);
1059 case WM_CREATE:
1060 return PAGER_Create (hwnd, (LPCREATESTRUCTW)lParam);
1062 case WM_DESTROY:
1063 return PAGER_Destroy (infoPtr);
1065 case WM_SIZE:
1066 return PAGER_Size (infoPtr, (INT)wParam, (short)LOWORD(lParam), (short)HIWORD(lParam));
1068 case WM_NCPAINT:
1069 return PAGER_NCPaint (infoPtr, (HRGN)wParam);
1071 case WM_STYLECHANGED:
1072 return PAGER_StyleChanged(infoPtr, wParam, (LPSTYLESTRUCT)lParam);
1074 case WM_NCCALCSIZE:
1075 return PAGER_NCCalcSize (infoPtr, wParam, (LPRECT)lParam);
1077 case WM_NCHITTEST:
1078 return PAGER_NCHitTest (infoPtr, (short)LOWORD(lParam), (short)HIWORD(lParam));
1080 case WM_MOUSEMOVE:
1081 if (infoPtr->bForward && infoPtr->hwndChild)
1082 PostMessageW(infoPtr->hwndChild, WM_MOUSEMOVE, wParam, lParam);
1083 return PAGER_MouseMove (infoPtr, (INT)wParam, (short)LOWORD(lParam), (short)HIWORD(lParam));
1085 case WM_LBUTTONDOWN:
1086 return PAGER_LButtonDown (infoPtr, (INT)wParam, (short)LOWORD(lParam), (short)HIWORD(lParam));
1088 case WM_LBUTTONUP:
1089 return PAGER_LButtonUp (infoPtr, (INT)wParam, (short)LOWORD(lParam), (short)HIWORD(lParam));
1091 case WM_ERASEBKGND:
1092 return PAGER_EraseBackground (infoPtr, (HDC)wParam);
1094 case WM_TIMER:
1095 return PAGER_Timer (infoPtr, (INT)wParam);
1097 case WM_NOTIFY:
1098 case WM_COMMAND:
1099 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
1101 default:
1102 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
1107 VOID
1108 PAGER_Register (void)
1110 WNDCLASSW wndClass;
1112 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
1113 wndClass.style = CS_GLOBALCLASS;
1114 wndClass.lpfnWndProc = PAGER_WindowProc;
1115 wndClass.cbClsExtra = 0;
1116 wndClass.cbWndExtra = sizeof(PAGER_INFO *);
1117 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1118 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
1119 wndClass.lpszClassName = WC_PAGESCROLLERW;
1121 RegisterClassW (&wndClass);
1125 VOID
1126 PAGER_Unregister (void)
1128 UnregisterClassW (WC_PAGESCROLLERW, NULL);