include: Use the hard-float calling convention for Windows APIs on ARM
[wine.git] / dlls / comctl32 / pager.c
blobe9bcbe8c0612502183f97c69276e85760e308f48
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, HWND_TOP,
252 -nPos, 0,
253 infoPtr->nWidth, infoPtr->nHeight, 0);
255 else
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,
263 0, -nPos);
264 SetWindowPos(infoPtr->hwndChild, HWND_TOP,
265 0, -nPos,
266 infoPtr->nWidth, infoPtr->nHeight, 0);
269 InvalidateRect(infoPtr->hwndChild, NULL, TRUE);
273 static INT
274 PAGER_GetScrollRange(PAGER_INFO* infoPtr, BOOL calc_size)
276 INT scrollRange = 0;
278 if (infoPtr->hwndChild)
280 INT wndSize, childSize;
281 RECT wndRect;
282 GetWindowRect(infoPtr->hwndSelf, &wndRect);
284 if (calc_size)
285 PAGER_CalcSize(infoPtr);
286 if (infoPtr->dwStyle & PGS_HORZ)
288 wndSize = wndRect.right - wndRect.left;
289 childSize = infoPtr->nWidth;
291 else
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);
303 return scrollRange;
306 static void
307 PAGER_UpdateBtns(PAGER_INFO *infoPtr, INT scrollRange, BOOL hideGrayBtns)
309 BOOL resizeClient;
310 BOOL repaintBtns;
311 INT oldTLbtnState = infoPtr->TLbtnState;
312 INT oldBRbtnState = infoPtr->BRbtnState;
313 POINT pt;
314 RECT rcTopLeft, rcBottomRight;
316 /* get button rects */
317 PAGER_GetButtonRects(infoPtr, &rcTopLeft, &rcBottomRight, TRUE);
319 GetCursorPos(&pt);
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;
330 else
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;
345 else
346 infoPtr->BRbtnState = PGF_INVISIBLE;
348 /* only need to resize when entering or leaving PGF_INVISIBLE state */
349 resizeClient =
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 */
353 if (resizeClient)
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);
361 if (repaintBtns)
362 SendMessageW(infoPtr->hwndSelf, WM_NCPAINT, 0, 0);
365 static LRESULT
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))
372 infoPtr->nPos = 0;
373 else if (newPos > scrollRange)
374 infoPtr->nPos = scrollRange;
375 else
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);
387 return 0;
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 ******************************************************************/
402 static LRESULT
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)
413 infoPtr->nPos = -1;
414 PAGER_SetPos(infoPtr, 0, FALSE, TRUE);
416 else
417 PAGER_PositionChildWnd(infoPtr);
420 return 1;
424 static COLORREF
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);
439 return clrTemp;
443 static INT
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);
453 return nTemp;
457 static INT
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);
467 return nTemp;
471 static LRESULT
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);
483 infoPtr->nPos = -1;
484 PAGER_SetPos(infoPtr, 0, FALSE, FALSE);
487 return 0;
490 static void
491 PAGER_Scroll(PAGER_INFO* infoPtr, INT dir)
493 NMPGSCROLL nmpgScroll;
494 RECT rcWnd;
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;
513 else
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);
530 else
531 PAGER_SetPos(infoPtr, infoPtr->nPos + nmpgScroll.iScroll, TRUE, TRUE);
533 else
534 infoPtr->direction = -1;
538 static LRESULT
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);
553 static LRESULT
554 PAGER_Create (HWND hwnd, const CREATESTRUCTW *lpcs)
556 PAGER_INFO *infoPtr;
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;
571 infoPtr->nPos = 0;
572 infoPtr->nWidth = 0;
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);
583 return 0;
587 static LRESULT
588 PAGER_Destroy (PAGER_INFO *infoPtr)
590 SetWindowLongPtrW (infoPtr->hwndSelf, 0, 0);
591 Free (infoPtr); /* free pager info data */
592 return 0;
595 static LRESULT
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;
626 else
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);
638 return 0;
641 static LRESULT
642 PAGER_NCPaint (const PAGER_INFO* infoPtr, HRGN hRgn)
644 RECT rcBottomRight, rcTopLeft;
645 HDC hdc;
647 if (infoPtr->dwStyle & WS_MINIMIZE)
648 return 0;
650 DefWindowProcW (infoPtr->hwndSelf, WM_NCPAINT, (WPARAM)hRgn, 0);
652 if (!(hdc = GetDCEx (infoPtr->hwndSelf, 0, DCX_USESTYLE | DCX_WINDOW)))
653 return 0;
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 );
663 return 0;
666 static INT
667 PAGER_HitTest (const PAGER_INFO* infoPtr, const POINT * pt)
669 RECT clientRect, rcTopLeft, rcBottomRight;
670 POINT ptWindow;
672 GetClientRect (infoPtr->hwndSelf, &clientRect);
674 if (PtInRect(&clientRect, *pt))
676 TRACE("child\n");
677 return -1;
680 ptWindow = *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;
694 TRACE("nowhere\n");
695 return -1;
698 static LRESULT
699 PAGER_NCHitTest (const PAGER_INFO* infoPtr, INT x, INT y)
701 POINT pt;
702 INT nHit;
704 pt.x = x;
705 pt.y = y;
707 ScreenToClient (infoPtr->hwndSelf, &pt);
708 nHit = PAGER_HitTest(infoPtr, &pt);
710 return (nHit < 0) ? HTTRANSPARENT : HTCLIENT;
713 static LRESULT
714 PAGER_MouseMove (PAGER_INFO* infoPtr, INT keys, INT x, INT y)
716 POINT clpt, pt;
717 RECT wnrect;
718 BOOL topLeft = FALSE;
719 INT btnstate = 0;
720 INT hit;
721 HDC hdc;
723 pt.x = x;
724 pt.y = y;
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);
734 clpt = pt;
735 MapWindowPoints(0, infoPtr->hwndSelf, &clpt, 1);
736 hit = PAGER_HitTest(infoPtr, &clpt);
737 if ((hit == PGB_TOPORLEFT) && (infoPtr->TLbtnState == PGF_NORMAL))
739 topLeft = TRUE;
740 rect = &topleft;
741 infoPtr->TLbtnState = PGF_HOT;
742 btnstate = infoPtr->TLbtnState;
744 else if ((hit == PGB_BOTTOMORRIGHT) && (infoPtr->BRbtnState == PGF_NORMAL))
746 topLeft = FALSE;
747 rect = &bottomright;
748 infoPtr->BRbtnState = PGF_HOT;
749 btnstate = infoPtr->BRbtnState;
752 /* If in one of the buttons the capture and draw buttons */
753 if (rect)
755 TRACE("[%p] draw btn (%s), Capture %s, style %08x\n",
756 infoPtr->hwndSelf, wine_dbgstr_rect(rect),
757 (infoPtr->bCapture) ? "TRUE" : "FALSE",
758 infoPtr->dwStyle);
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);
772 return 0;
776 /* If we think we are captured, then do release */
777 if (infoPtr->bCapture && (WindowFromPoint(pt) != infoPtr->hwndSelf))
779 NMHDR nmhdr;
781 infoPtr->bCapture = FALSE;
783 if (GetCapture() == infoPtr->hwndSelf)
785 ReleaseCapture();
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);
825 return 0;
828 static LRESULT
829 PAGER_LButtonDown (PAGER_INFO* infoPtr, INT keys, INT x, INT y)
831 BOOL repaintBtns = FALSE;
832 POINT pt;
833 INT hit;
835 pt.x = x;
836 pt.y = y;
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);
856 if (repaintBtns)
857 SendMessageW(infoPtr->hwndSelf, WM_NCPAINT, 0, 0);
859 switch(hit)
861 case PGB_TOPORLEFT:
862 if (infoPtr->dwStyle & PGS_HORZ)
864 TRACE("[%p] PGF_SCROLLLEFT\n", infoPtr->hwndSelf);
865 PAGER_Scroll(infoPtr, PGF_SCROLLLEFT);
867 else
869 TRACE("[%p] PGF_SCROLLUP\n", infoPtr->hwndSelf);
870 PAGER_Scroll(infoPtr, PGF_SCROLLUP);
872 break;
873 case PGB_BOTTOMORRIGHT:
874 if (infoPtr->dwStyle & PGS_HORZ)
876 TRACE("[%p] PGF_SCROLLRIGHT\n", infoPtr->hwndSelf);
877 PAGER_Scroll(infoPtr, PGF_SCROLLRIGHT);
879 else
881 TRACE("[%p] PGF_SCROLLDOWN\n", infoPtr->hwndSelf);
882 PAGER_Scroll(infoPtr, PGF_SCROLLDOWN);
884 break;
885 default:
886 break;
889 return 0;
892 static LRESULT
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;
906 return 0;
909 static LRESULT
910 PAGER_Timer (PAGER_INFO* infoPtr, INT nTimerId)
912 INT dir;
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;
919 else
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);
932 return 0;
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);
942 return 0;
945 static LRESULT
946 PAGER_EraseBackground (const PAGER_INFO* infoPtr, HDC hdc)
948 POINT pt, ptorig;
949 HWND parent;
950 LRESULT ret;
952 pt.x = 0;
953 pt.y = 0;
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);
960 return ret;
964 static LRESULT
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;
973 else
974 infoPtr->nWidth = x;
976 return PAGER_RecalcSize(infoPtr);
980 static LRESULT
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);
997 return 0;
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);
1010 switch (uMsg)
1012 case EM_FMTLINES:
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);
1021 case PGM_GETBORDER:
1022 return PAGER_GetBorder(infoPtr);
1024 case PGM_GETBUTTONSIZE:
1025 return PAGER_GetButtonSize(infoPtr);
1027 case PGM_GETPOS:
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);
1041 case PGM_SETBORDER:
1042 return PAGER_SetBorder (infoPtr, (INT)lParam);
1044 case PGM_SETBUTTONSIZE:
1045 return PAGER_SetButtonSize (infoPtr, (INT)lParam);
1047 case PGM_SETCHILD:
1048 return PAGER_SetChild (infoPtr, (HWND)lParam);
1050 case PGM_SETPOS:
1051 return PAGER_SetPos(infoPtr, (INT)lParam, FALSE, TRUE);
1053 case WM_CREATE:
1054 return PAGER_Create (hwnd, (LPCREATESTRUCTW)lParam);
1056 case WM_DESTROY:
1057 return PAGER_Destroy (infoPtr);
1059 case WM_SIZE:
1060 return PAGER_Size (infoPtr, (INT)wParam, (short)LOWORD(lParam), (short)HIWORD(lParam));
1062 case WM_NCPAINT:
1063 return PAGER_NCPaint (infoPtr, (HRGN)wParam);
1065 case WM_STYLECHANGED:
1066 return PAGER_StyleChanged(infoPtr, wParam, (LPSTYLESTRUCT)lParam);
1068 case WM_NCCALCSIZE:
1069 return PAGER_NCCalcSize (infoPtr, wParam, (LPRECT)lParam);
1071 case WM_NCHITTEST:
1072 return PAGER_NCHitTest (infoPtr, (short)LOWORD(lParam), (short)HIWORD(lParam));
1074 case WM_MOUSEMOVE:
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));
1082 case WM_LBUTTONUP:
1083 return PAGER_LButtonUp (infoPtr, (INT)wParam, (short)LOWORD(lParam), (short)HIWORD(lParam));
1085 case WM_ERASEBKGND:
1086 return PAGER_EraseBackground (infoPtr, (HDC)wParam);
1088 case WM_TIMER:
1089 return PAGER_Timer (infoPtr, (INT)wParam);
1091 case WM_NOTIFY:
1092 case WM_COMMAND:
1093 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
1095 default:
1096 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
1101 VOID
1102 PAGER_Register (void)
1104 WNDCLASSW wndClass;
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);
1119 VOID
1120 PAGER_Unregister (void)
1122 UnregisterClassW (WC_PAGESCROLLERW, NULL);