~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/dlls/comctl32/pager.c

Version: ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~ [ wine-1.0-rc5 ] ~ [ wine-1.0-rc4 ] ~ [ wine-1.0-rc3 ] ~ [ wine-1.0-rc2 ] ~ [ wine-1.0-rc1 ] ~ [ wine-0.9.61 ] ~ [ wine-0.9.60 ] ~ [ wine-0.9.59 ] ~ [ wine-0.9.58 ] ~ [ wine-0.9.57 ] ~ [ wine-0.9.56 ] ~ [ wine-0.9.55 ] ~ [ wine-0.9.54 ] ~ [ wine-0.9.53 ] ~ [ wine-0.9.52 ] ~ [ wine-0.9.51 ] ~ [ wine-0.9.50 ] ~ [ wine-0.9.49 ] ~ [ wine-0.9.48 ] ~ [ wine-0.9.47 ] ~ [ wine-0.9.46 ] ~ [ wine-0.9.45 ] ~ [ wine-0.9.44 ] ~ [ wine-0.9.43 ] ~ [ wine-0.9.42 ] ~ [ wine-0.9.41 ] ~ [ wine-0.9.40 ] ~ [ wine-0.9.39 ] ~ [ wine-0.9.38 ] ~ [ wine-0.9.37 ] ~ [ wine-0.9.36 ] ~ [ wine-0.9.35 ] ~ [ wine-0.9.34 ] ~ [ wine-0.9.33 ] ~ [ wine-0.9.32 ] ~ [ wine-0.9.31 ] ~ [ wine-0.9.30 ] ~ [ wine-0.9.29 ] ~ [ wine-0.9.28 ] ~ [ wine-0.9.27 ] ~ [ wine-0.9.26 ] ~ [ wine-0.9.25 ] ~ [ wine-0.9.24 ] ~ [ wine-0.9.23 ] ~ [ wine-0.9.22 ] ~ [ wine-0.9.21 ] ~ [ wine-0.9.20 ] ~ [ wine-0.9.19 ] ~ [ wine-0.9.18 ] ~ [ wine-0.9.17 ] ~ [ wine-0.9.16 ] ~ [ wine-0.9.15 ] ~ [ wine-0.9.14 ] ~ [ wine-0.9.13 ] ~ [ wine-0.9.12 ] ~ [ wine-0.9.11 ] ~ [ wine-0.9.10 ] ~ [ wine-0.9.9 ] ~ [ wine-0.9.8 ] ~ [ wine-0.9.7 ] ~ [ wine-0.9.6 ] ~ [ wine-0.9.5 ] ~ [ wine-0.9.4 ] ~ [ wine-0.9.3 ] ~ [ wine-0.9.2 ] ~ [ wine-0.9.1 ] ~ [ wine-0.9 ] ~ [ wine20050930 ] ~ [ wine20050830 ] ~ [ wine20050725 ] ~ [ wine20050628 ] ~ [ wine20050524 ] ~ [ wine20050419 ] ~ [ wine20050310 ] ~ [ wine20050211 ] ~ [ wine20050111 ] ~ [ wine20041201 ] ~ [ wine20041019 ] ~ [ wine20040914 ] ~ [ wine20040813 ] ~ [ wine20040716 ] ~ [ wine20040615 ] ~ [ wine20040505 ] ~ [ wine20040408 ] ~ [ wine20040309 ] ~ [ wine20040213 ] ~ [ wine20040121 ] ~ [ wine20031212 ] ~ [ wine20031118 ] ~ [ wine20031016 ] ~ [ wine20030911 ] ~ [ wine20030813 ] ~ [ wine20030709 ] ~ [ wine20030618 ] ~ [ wine20030508 ] ~ [ wine20030408 ] ~ [ wine20030318 ] ~ [ wine20030219 ] ~ [ wine20030115 ] ~ [ wine20021219 ] ~ [ wine20021125 ] ~ [ wine20021031 ] ~ [ wine20021007 ] ~ [ wine20020904 ] ~ [ wine20020804 ] ~ [ wine20020710 ] ~ [ wine20020605 ] ~ [ wine20020509 ] ~ [ wine20020411 ] ~ [ wine20020310 ] ~ [ wine20020228 ] ~ [ wine20011226 ] ~ [ wine20011108 ] ~ [ wine20011004 ] ~ [ wine20010824 ] ~ [ wine20010731 ] ~ [ wine20010629 ] ~ [ wine20010510 ] ~ [ wine20010418 ] ~ [ wine20010326 ] ~ [ wine20010305 ] ~ [ wine20010216 ] ~ [ wine20010112 ] ~ [ wine20001222 ] ~ [ wine20001202 ] ~ [ wine20001026 ] ~ [ wine20001002 ] ~ [ wine20000909 ] ~ [ wine20000821 ] ~ [ wine20000801 ] ~ [ wine20000716 ] ~ [ wine20000326 ] ~ [ wine20000227 ] ~ [ wine20000130 ] ~ [ wine20000109 ] ~

  1 /*
  2  * Pager control
  3  *
  4  * Copyright 1998, 1999 Eric Kohl
  5  *
  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.
 10  *
 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.
 15  *
 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
 19  *
 20  * NOTES
 21  *
 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.
 24  * 
 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.
 28  *
 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
 39  *
 40  * TESTING:
 41  *    Tested primarily with the controlspy Pager application.
 42  *       Susan Farley (susan@codeweavers.com)
 43  *
 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>
 53  */
 54 
 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"
 65 
 66 WINE_DEFAULT_DEBUG_CHANNEL(pager);
 67 
 68 typedef struct
 69 {
 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;
 86 
 87 #define MIN_ARROW_WIDTH  8
 88 #define MIN_ARROW_HEIGHT 5
 89 
 90 #define TIMERID1         1
 91 #define TIMERID2         2
 92 #define INITIAL_DELAY    500
 93 #define REPEAT_DELAY     50
 94 
 95 static void
 96 PAGER_GetButtonRects(const PAGER_INFO* infoPtr, RECT* prcTopLeft, RECT* prcBottomRight, BOOL bClientCoords)
 97 {
 98     RECT rcWindow;
 99     GetWindowRect (infoPtr->hwndSelf, &rcWindow);
100 
101     if (bClientCoords)
102     {
103         POINT pt = {rcWindow.left, rcWindow.top};
104         ScreenToClient(infoPtr->hwndSelf, &pt);
105         OffsetRect(&rcWindow, -(rcWindow.left-pt.x), -(rcWindow.top-pt.y));
106     }
107     else
108         OffsetRect(&rcWindow, -rcWindow.left, -rcWindow.top);
109 
110     *prcTopLeft = *prcBottomRight = rcWindow;
111     if (infoPtr->dwStyle & PGS_HORZ)
112     {
113         prcTopLeft->right = prcTopLeft->left + infoPtr->nButtonSize;
114         prcBottomRight->left = prcBottomRight->right - infoPtr->nButtonSize;
115     }
116     else
117     {
118         prcTopLeft->bottom = prcTopLeft->top + infoPtr->nButtonSize;
119         prcBottomRight->top = prcBottomRight->bottom - infoPtr->nButtonSize;
120     }
121 }
122 
123 /* the horizontal arrows are:
124  *
125  * 01234    01234
126  * 1  *      *
127  * 2 **      **
128  * 3***      ***
129  * 4***      ***
130  * 5 **      **
131  * 6  *      *
132  * 7
133  *
134  */
135 static void
136 PAGER_DrawHorzArrow (HDC hdc, RECT r, INT colorRef, BOOL left)
137 {
138     INT x, y, w, h;
139     HPEN hPen, hOldPen;
140 
141     w = r.right - r.left + 1;
142     h = r.bottom - r.top + 1;
143     if ((h < MIN_ARROW_WIDTH) || (w < MIN_ARROW_HEIGHT))
144         return;  /* refuse to draw partial arrow */
145 
146     if (!(hPen = CreatePen( PS_SOLID, 1, GetSysColor( colorRef )))) return;
147     hOldPen = SelectObject ( hdc, hPen );
148     if (left)
149     {
150         x = r.left + ((w - MIN_ARROW_HEIGHT) / 2) + 3;
151         y = r.top + ((h - MIN_ARROW_WIDTH) / 2) + 1;
152         MoveToEx (hdc, x, y, NULL);
153         LineTo (hdc, x--, y+5); y++;
154         MoveToEx (hdc, x, y, NULL);
155         LineTo (hdc, x--, y+3); y++;
156         MoveToEx (hdc, x, y, NULL);
157         LineTo (hdc, x, y+1);
158     }
159     else
160     {
161         x = r.left + ((w - MIN_ARROW_HEIGHT) / 2) + 1;
162         y = r.top + ((h - MIN_ARROW_WIDTH) / 2) + 1;
163         MoveToEx (hdc, x, y, NULL);
164         LineTo (hdc, x++, y+5); y++;
165         MoveToEx (hdc, x, y, NULL);
166         LineTo (hdc, x++, y+3); y++;
167         MoveToEx (hdc, x, y, NULL);
168         LineTo (hdc, x, y+1);
169     }
170 
171     SelectObject( hdc, hOldPen );
172     DeleteObject( hPen );
173 }
174 
175 /* the vertical arrows are:
176  *
177  * 01234567    01234567
178  * 1******        **
179  * 2 ****        ****
180  * 3  **        ******
181  * 4
182  *
183  */
184 static void
185 PAGER_DrawVertArrow (HDC hdc, RECT r, INT colorRef, BOOL up)
186 {
187     INT x, y, w, h;
188     HPEN hPen, hOldPen;
189 
190     w = r.right - r.left + 1;
191     h = r.bottom - r.top + 1;
192     if ((h < MIN_ARROW_WIDTH) || (w < MIN_ARROW_HEIGHT))
193         return;  /* refuse to draw partial arrow */
194 
195     if (!(hPen = CreatePen( PS_SOLID, 1, GetSysColor( colorRef )))) return;
196     hOldPen = SelectObject ( hdc, hPen );
197     if (up)
198     {
199         x = r.left + ((w - MIN_ARROW_HEIGHT) / 2) + 1;
200         y = r.top + ((h - MIN_ARROW_WIDTH) / 2) + 3;
201         MoveToEx (hdc, x, y, NULL);
202         LineTo (hdc, x+5, y--); x++;
203         MoveToEx (hdc, x, y, NULL);
204         LineTo (hdc, x+3, y--); x++;
205         MoveToEx (hdc, x, y, NULL);
206         LineTo (hdc, x+1, y);
207     }
208     else
209     {
210         x = r.left + ((w - MIN_ARROW_HEIGHT) / 2) + 1;
211         y = r.top + ((h - MIN_ARROW_WIDTH) / 2) + 1;
212         MoveToEx (hdc, x, y, NULL);
213         LineTo (hdc, x+5, y++); x++;
214         MoveToEx (hdc, x, y, NULL);
215         LineTo (hdc, x+3, y++); x++;
216         MoveToEx (hdc, x, y, NULL);
217         LineTo (hdc, x+1, y);
218     }
219 
220     SelectObject( hdc, hOldPen );
221     DeleteObject( hPen );
222 }
223 
224 static void
225 PAGER_DrawButton(HDC hdc, COLORREF clrBk, RECT arrowRect,
226                  BOOL horz, BOOL topLeft, INT btnState)
227 {
228     HBRUSH   hBrush, hOldBrush;
229     RECT     rc = arrowRect;
230 
231     TRACE("arrowRect = %s, btnState = %d\n", wine_dbgstr_rect(&arrowRect), btnState);
232 
233     if (btnState == PGF_INVISIBLE)
234         return;
235 
236     if ((rc.right - rc.left <= 0) || (rc.bottom - rc.top <= 0))
237         return;
238 
239     hBrush = CreateSolidBrush(clrBk);
240     hOldBrush = (HBRUSH)SelectObject(hdc, hBrush);
241 
242     FillRect(hdc, &rc, hBrush);
243 
244     if (btnState == PGF_HOT)
245     {
246        DrawEdge( hdc, &rc, BDR_RAISEDINNER, BF_RECT);
247        if (horz)
248            PAGER_DrawHorzArrow(hdc, rc, COLOR_WINDOWFRAME, topLeft);
249        else
250            PAGER_DrawVertArrow(hdc, rc, COLOR_WINDOWFRAME, topLeft);
251     }
252     else if (btnState == PGF_NORMAL)
253     {
254        DrawEdge (hdc, &rc, BDR_OUTER, BF_FLAT);
255        if (horz)
256            PAGER_DrawHorzArrow(hdc, rc, COLOR_WINDOWFRAME, topLeft);
257        else
258            PAGER_DrawVertArrow(hdc, rc, COLOR_WINDOWFRAME, topLeft);
259     }
260     else if (btnState == PGF_DEPRESSED)
261     {
262        DrawEdge( hdc, &rc, BDR_SUNKENOUTER, BF_RECT);
263        if (horz)
264            PAGER_DrawHorzArrow(hdc, rc, COLOR_WINDOWFRAME, topLeft);
265        else
266            PAGER_DrawVertArrow(hdc, rc, COLOR_WINDOWFRAME, topLeft);
267     }
268     else if (btnState == PGF_GRAYED)
269     {
270        DrawEdge (hdc, &rc, BDR_OUTER, BF_FLAT);
271        if (horz)
272        {
273            PAGER_DrawHorzArrow(hdc, rc, COLOR_3DHIGHLIGHT, topLeft);
274            rc.left++, rc.top++; rc.right++, rc.bottom++;
275            PAGER_DrawHorzArrow(hdc, rc, COLOR_3DSHADOW, topLeft);
276        }
277        else
278        {
279            PAGER_DrawVertArrow(hdc, rc, COLOR_3DHIGHLIGHT, topLeft);
280            rc.left++, rc.top++; rc.right++, rc.bottom++;
281            PAGER_DrawVertArrow(hdc, rc, COLOR_3DSHADOW, topLeft);
282        }
283     }
284 
285     SelectObject( hdc, hOldBrush );
286     DeleteObject(hBrush);
287 }
288 
289 /* << PAGER_GetDropTarget >> */
290 
291 static inline LRESULT
292 PAGER_ForwardMouse (PAGER_INFO* infoPtr, BOOL bFwd)
293 {
294     TRACE("[%p]\n", infoPtr->hwndSelf);
295 
296     infoPtr->bForward = bFwd;
297 
298     return 0;
299 }
300 
301 static inline LRESULT
302 PAGER_GetButtonState (const PAGER_INFO* infoPtr, INT btn)
303 {
304     LRESULT btnState = PGF_INVISIBLE;
305     TRACE("[%p]\n", infoPtr->hwndSelf);
306 
307     if (btn == PGB_TOPORLEFT)
308         btnState = infoPtr->TLbtnState;
309     else if (btn == PGB_BOTTOMORRIGHT)
310         btnState = infoPtr->BRbtnState;
311 
312     return btnState;
313 }
314 
315 
316 static inline INT
317 PAGER_GetPos(const PAGER_INFO *infoPtr)
318 {
319     TRACE("[%p] returns %d\n", infoPtr->hwndSelf, infoPtr->nPos);
320     return infoPtr->nPos;
321 }
322 
323 static inline INT
324 PAGER_GetButtonSize(const PAGER_INFO *infoPtr)
325 {
326     TRACE("[%p] returns %d\n", infoPtr->hwndSelf, infoPtr->nButtonSize);
327     return infoPtr->nButtonSize;
328 }
329 
330 static inline INT
331 PAGER_GetBorder(const PAGER_INFO *infoPtr)
332 {
333     TRACE("[%p] returns %d\n", infoPtr->hwndSelf, infoPtr->nBorder);
334     return infoPtr->nBorder;
335 }
336 
337 static inline COLORREF
338 PAGER_GetBkColor(const PAGER_INFO *infoPtr)
339 {
340     TRACE("[%p] returns %06x\n", infoPtr->hwndSelf, infoPtr->clrBk);
341     return infoPtr->clrBk;
342 }
343 
344 static void
345 PAGER_CalcSize (const PAGER_INFO *infoPtr, INT* size, BOOL getWidth)
346 {
347     NMPGCALCSIZE nmpgcs;
348     ZeroMemory (&nmpgcs, sizeof (NMPGCALCSIZE));
349     nmpgcs.hdr.hwndFrom = infoPtr->hwndSelf;
350     nmpgcs.hdr.idFrom   = GetWindowLongPtrW (infoPtr->hwndSelf, GWLP_ID);
351     nmpgcs.hdr.code = PGN_CALCSIZE;
352     nmpgcs.dwFlag = getWidth ? PGF_CALCWIDTH : PGF_CALCHEIGHT;
353     nmpgcs.iWidth = getWidth ? *size : 0;
354     nmpgcs.iHeight = getWidth ? 0 : *size;
355     SendMessageW (infoPtr->hwndNotify, WM_NOTIFY, nmpgcs.hdr.idFrom, (LPARAM)&nmpgcs);
356 
357     *size = getWidth ? nmpgcs.iWidth : nmpgcs.iHeight;
358 
359     TRACE("[%p] PGN_CALCSIZE returns %s=%d\n", infoPtr->hwndSelf,
360                   getWidth ? "width" : "height", *size);
361 }
362 
363 static void
364 PAGER_PositionChildWnd(PAGER_INFO* infoPtr)
365 {
366     if (infoPtr->hwndChild)
367     {
368         RECT rcClient;
369         int nPos = infoPtr->nPos;
370 
371         /* compensate for a grayed btn, which will soon become invisible */
372         if (infoPtr->TLbtnState == PGF_GRAYED)
373             nPos += infoPtr->nButtonSize;
374 
375         GetClientRect(infoPtr->hwndSelf, &rcClient);
376 
377         if (infoPtr->dwStyle & PGS_HORZ)
378         {
379             int wndSize = max(0, rcClient.right - rcClient.left);
380             if (infoPtr->nWidth < wndSize)
381                 infoPtr->nWidth = wndSize;
382 
383             TRACE("[%p] SWP %dx%d at (%d,%d)\n", infoPtr->hwndSelf,
384                          infoPtr->nWidth, infoPtr->nHeight,
385                          -nPos, 0);
386             SetWindowPos(infoPtr->hwndChild, 0,
387                          -nPos, 0,
388                          infoPtr->nWidth, infoPtr->nHeight,
389                          SWP_NOZORDER);
390         }
391         else
392         {
393             int wndSize = max(0, rcClient.bottom - rcClient.top);
394             if (infoPtr->nHeight < wndSize)
395                 infoPtr->nHeight = wndSize;
396 
397             TRACE("[%p] SWP %dx%d at (%d,%d)\n", infoPtr->hwndSelf,
398                          infoPtr->nWidth, infoPtr->nHeight,
399                          0, -nPos);
400             SetWindowPos(infoPtr->hwndChild, 0,
401                          0, -nPos,
402                          infoPtr->nWidth, infoPtr->nHeight,
403                          SWP_NOZORDER);
404         }
405 
406         InvalidateRect(infoPtr->hwndChild, NULL, TRUE);
407     }
408 }
409 
410 static INT
411 PAGER_GetScrollRange(PAGER_INFO* infoPtr)
412 {
413     INT scrollRange = 0;
414 
415     if (infoPtr->hwndChild)
416     {
417         INT wndSize, childSize;
418         RECT wndRect;
419         GetWindowRect(infoPtr->hwndSelf, &wndRect);
420 
421         if (infoPtr->dwStyle & PGS_HORZ)
422         {
423             wndSize = wndRect.right - wndRect.left;
424             PAGER_CalcSize(infoPtr, &infoPtr->nWidth, TRUE);
425             childSize = infoPtr->nWidth;
426         }
427         else
428         {
429             wndSize = wndRect.bottom - wndRect.top;
430             PAGER_CalcSize(infoPtr, &infoPtr->nHeight, FALSE);
431             childSize = infoPtr->nHeight;
432         }
433 
434         TRACE("childSize = %d,  wndSize = %d\n", childSize, wndSize);
435         if (childSize > wndSize)
436             scrollRange = childSize - wndSize + infoPtr->nButtonSize;
437     }
438 
439     TRACE("[%p] returns %d\n", infoPtr->hwndSelf, scrollRange);
440     return scrollRange;
441 }
442 
443 static void
444 PAGER_UpdateBtns(PAGER_INFO *infoPtr, INT scrollRange, BOOL hideGrayBtns)
445 {
446     BOOL resizeClient;
447     BOOL repaintBtns;
448     INT oldTLbtnState = infoPtr->TLbtnState;
449     INT oldBRbtnState = infoPtr->BRbtnState;
450     POINT pt;
451     RECT rcTopLeft, rcBottomRight;
452 
453     /* get button rects */
454     PAGER_GetButtonRects(infoPtr, &rcTopLeft, &rcBottomRight, FALSE);
455 
456     GetCursorPos(&pt);
457 
458     /* update states based on scroll position */
459     if (infoPtr->nPos > 0)
460     {
461         if (infoPtr->TLbtnState == PGF_INVISIBLE || infoPtr->TLbtnState == PGF_GRAYED)
462             infoPtr->TLbtnState = PGF_NORMAL;
463     }
464     else if (PtInRect(&rcTopLeft, pt))
465         infoPtr->TLbtnState = PGF_GRAYED;
466     else
467         infoPtr->TLbtnState = PGF_INVISIBLE;
468 
469     if (scrollRange <= 0)
470     {
471         infoPtr->TLbtnState = PGF_INVISIBLE;
472         infoPtr->BRbtnState = PGF_INVISIBLE;
473     }
474     else if (infoPtr->nPos < scrollRange)
475     {
476         if (infoPtr->BRbtnState == PGF_INVISIBLE || infoPtr->BRbtnState == PGF_GRAYED)
477             infoPtr->BRbtnState = PGF_NORMAL;
478     }
479     else if (PtInRect(&rcBottomRight, pt))
480         infoPtr->BRbtnState = PGF_GRAYED;
481     else
482         infoPtr->BRbtnState = PGF_INVISIBLE;
483 
484     /* only need to resize when entering or leaving PGF_INVISIBLE state */
485     resizeClient =
486         ((oldTLbtnState == PGF_INVISIBLE) != (infoPtr->TLbtnState == PGF_INVISIBLE)) ||
487         ((oldBRbtnState == PGF_INVISIBLE) != (infoPtr->BRbtnState == PGF_INVISIBLE));
488     /* initiate NCCalcSize to resize client wnd if necessary */
489     if (resizeClient)
490         SetWindowPos(infoPtr->hwndSelf, 0, 0, 0, 0, 0,
491                      SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE |
492                      SWP_NOZORDER | SWP_NOACTIVATE);
493 
494     /* repaint when changing any state */
495     repaintBtns = (oldTLbtnState != infoPtr->TLbtnState) || 
496                   (oldBRbtnState != infoPtr->BRbtnState);
497     if (repaintBtns)
498         SendMessageW(infoPtr->hwndSelf, WM_NCPAINT, 0, 0);
499 }
500 
501 static LRESULT
502 PAGER_SetPos(PAGER_INFO* infoPtr, INT newPos, BOOL fromBtnPress)
503 {
504     INT scrollRange = PAGER_GetScrollRange(infoPtr);
505     INT oldPos = infoPtr->nPos;
506 
507     if ((scrollRange <= 0) || (newPos < 0))
508         infoPtr->nPos = 0;
509     else if (newPos > scrollRange)
510         infoPtr->nPos = scrollRange;
511     else
512         infoPtr->nPos = newPos;
513 
514     TRACE("[%p] pos=%d, oldpos=%d\n", infoPtr->hwndSelf, infoPtr->nPos, oldPos);
515 
516     if (infoPtr->nPos != oldPos)
517     {
518         /* gray and restore btns, and if from WM_SETPOS, hide the gray btns */
519         PAGER_UpdateBtns(infoPtr, scrollRange, !fromBtnPress);
520         PAGER_PositionChildWnd(infoPtr);
521     }
522 
523     return 0;
524 }
525 
526 static LRESULT
527 PAGER_WindowPosChanging(PAGER_INFO* infoPtr, WINDOWPOS *winpos)
528 {
529     if ((infoPtr->dwStyle & CCS_NORESIZE) && !(winpos->flags & SWP_NOSIZE))
530     {
531         /* don't let the app resize the nonscrollable dimension of a control
532          * that was created with CCS_NORESIZE style
533          * (i.e. height for a horizontal pager, or width for a vertical one) */
534 
535         /* except if the current dimension is 0 and app is setting for
536          * first time, then save amount as dimension. - GA 8/01 */
537 
538         if (infoPtr->dwStyle & PGS_HORZ)
539             if (!infoPtr->nHeight && winpos->cy)
540                 infoPtr->nHeight = winpos->cy;
541             else
542                 winpos->cy = infoPtr->nHeight;
543         else
544             if (!infoPtr->nWidth && winpos->cx)
545                 infoPtr->nWidth = winpos->cx;
546             else
547                 winpos->cx = infoPtr->nWidth;
548         return 0;
549     }
550 
551     return DefWindowProcW (infoPtr->hwndSelf, WM_WINDOWPOSCHANGING, 0, (LPARAM)winpos);
552 }
553 
554 static INT
555 PAGER_SetFixedWidth(PAGER_INFO* infoPtr)
556 {
557   /* Must set the non-scrollable dimension to be less than the full height/width
558    * so that NCCalcSize is called.  The Microsoft docs mention 3/4 factor for button
559    * size, and experimentation shows that the effect is almost right. */
560 
561     RECT wndRect;
562     INT delta, h;
563     GetWindowRect(infoPtr->hwndSelf, &wndRect);
564 
565     /* see what the app says for btn width */
566     PAGER_CalcSize(infoPtr, &infoPtr->nWidth, TRUE);
567 
568     if (infoPtr->dwStyle & CCS_NORESIZE)
569     {
570         delta = wndRect.right - wndRect.left - infoPtr->nWidth;
571         if (delta > infoPtr->nButtonSize)
572             infoPtr->nWidth += 4 * infoPtr->nButtonSize / 3;
573         else if (delta > 0)
574             infoPtr->nWidth +=  infoPtr->nButtonSize / 3;
575     }
576 
577     h = wndRect.bottom - wndRect.top + infoPtr->nButtonSize;
578 
579     TRACE("[%p] infoPtr->nWidth set to %d\n",
580                infoPtr->hwndSelf, infoPtr->nWidth);
581 
582     return h;
583 }
584 
585 static INT
586 PAGER_SetFixedHeight(PAGER_INFO* infoPtr)
587 {
588   /* Must set the non-scrollable dimension to be less than the full height/width
589    * so that NCCalcSize is called.  The Microsoft docs mention 3/4 factor for button
590    * size, and experimentation shows that the effect is almost right. */
591 
592     RECT wndRect;
593     INT delta, w;
594     GetWindowRect(infoPtr->hwndSelf, &wndRect);
595 
596     /* see what the app says for btn height */
597     PAGER_CalcSize(infoPtr, &infoPtr->nHeight, FALSE);
598 
599     if (infoPtr->dwStyle & CCS_NORESIZE)
600     {
601         delta = wndRect.bottom - wndRect.top - infoPtr->nHeight;
602         if (delta > infoPtr->nButtonSize)
603             infoPtr->nHeight += infoPtr->nButtonSize;
604         else if (delta > 0)
605             infoPtr->nHeight +=  infoPtr->nButtonSize / 3;
606     }
607 
608     w = wndRect.right - wndRect.left + infoPtr->nButtonSize;
609 
610     TRACE("[%p] infoPtr->nHeight set to %d\n",
611                infoPtr->hwndSelf, infoPtr->nHeight);
612 
613     return w;
614 }
615 
616 /******************************************************************
617  * For the PGM_RECALCSIZE message (but not the other uses in      *
618  * this module), the native control does only the following:      *
619  *                                                                *
620  *    if (some condition)                                         *
621  *          PostMessageW(hwnd, EM_FMTLINES, 0, 0);                *
622  *    return DefWindowProcW(hwnd, PGM_RECALCSIZE, 0, 0);          *
623  *                                                                *
624  * When we figure out what the "some condition" is we will        *
625  * implement that for the message processing.                     *
626  ******************************************************************/
627 
628 static LRESULT
629 PAGER_RecalcSize(PAGER_INFO *infoPtr)
630 {
631     TRACE("[%p]\n", infoPtr->hwndSelf);
632 
633     if (infoPtr->hwndChild)
634     {
635         INT scrollRange = PAGER_GetScrollRange(infoPtr);
636 
637         if (scrollRange <= 0)
638         {
639             infoPtr->nPos = -1;
640             PAGER_SetPos(infoPtr, 0, FALSE);
641         }
642         else
643             PAGER_PositionChildWnd(infoPtr);
644     }
645 
646     return 1;
647 }
648 
649 
650 static COLORREF
651 PAGER_SetBkColor (PAGER_INFO* infoPtr, COLORREF clrBk)
652 {
653     COLORREF clrTemp = infoPtr->clrBk;
654 
655     infoPtr->clrBk = clrBk;
656     TRACE("[%p] %06x\n", infoPtr->hwndSelf, infoPtr->clrBk);
657 
658     /* the native control seems to do things this way */
659     SetWindowPos(infoPtr->hwndSelf, 0, 0, 0, 0, 0,
660                  SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE |
661                  SWP_NOZORDER | SWP_NOACTIVATE);
662 
663     RedrawWindow(infoPtr->hwndSelf, 0, 0, RDW_ERASE | RDW_INVALIDATE);
664 
665     return clrTemp;
666 }
667 
668 
669 static INT
670 PAGER_SetBorder (PAGER_INFO* infoPtr, INT iBorder)
671 {
672     INT nTemp = infoPtr->nBorder;
673 
674     infoPtr->nBorder = iBorder;
675     TRACE("[%p] %d\n", infoPtr->hwndSelf, infoPtr->nBorder);
676 
677     PAGER_RecalcSize(infoPtr);
678 
679     return nTemp;
680 }
681 
682 
683 static INT
684 PAGER_SetButtonSize (PAGER_INFO* infoPtr, INT iButtonSize)
685 {
686     INT nTemp = infoPtr->nButtonSize;
687 
688     infoPtr->nButtonSize = iButtonSize;
689     TRACE("[%p] %d\n", infoPtr->hwndSelf, infoPtr->nButtonSize);
690 
691     PAGER_RecalcSize(infoPtr);
692 
693     return nTemp;
694 }
695 
696 
697 static LRESULT
698 PAGER_SetChild (PAGER_INFO* infoPtr, HWND hwndChild)
699 {
700     INT hw;
701 
702     infoPtr->hwndChild = IsWindow (hwndChild) ? hwndChild : 0;
703 
704     if (infoPtr->hwndChild)
705     {
706         TRACE("[%p] hwndChild=%p\n", infoPtr->hwndSelf, infoPtr->hwndChild);
707 
708         if (infoPtr->dwStyle & PGS_HORZ) {
709             hw = PAGER_SetFixedHeight(infoPtr);
710             /* adjust non-scrollable dimension to fit the child */
711             SetWindowPos(infoPtr->hwndSelf, 0, 0, 0, hw, infoPtr->nHeight,
712                          SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOZORDER |
713                          SWP_NOSIZE | SWP_NOACTIVATE);
714         }
715         else {
716             hw = PAGER_SetFixedWidth(infoPtr);
717             /* adjust non-scrollable dimension to fit the child */
718             SetWindowPos(infoPtr->hwndSelf, 0, 0, 0, infoPtr->nWidth, hw,
719                          SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOZORDER |
720                          SWP_NOSIZE | SWP_NOACTIVATE);
721         }
722 
723         /* position child within the page scroller */
724         SetWindowPos(infoPtr->hwndChild, HWND_TOP,
725                      0,0,0,0,
726                      SWP_SHOWWINDOW | SWP_NOSIZE);  /* native is 0 */
727 
728         infoPtr->nPos = -1;
729         PAGER_SetPos(infoPtr, 0, FALSE);
730     }
731 
732     return 0;
733 }
734 
735 static void
736 PAGER_Scroll(PAGER_INFO* infoPtr, INT dir)
737 {
738     NMPGSCROLL nmpgScroll;
739     RECT rcWnd;
740 
741     if (infoPtr->hwndChild)
742     {
743         ZeroMemory (&nmpgScroll, sizeof (NMPGSCROLL));
744         nmpgScroll.hdr.hwndFrom = infoPtr->hwndSelf;
745         nmpgScroll.hdr.idFrom   = GetWindowLongPtrW (infoPtr->hwndSelf, GWLP_ID);
746         nmpgScroll.hdr.code = PGN_SCROLL;
747 
748         GetWindowRect(infoPtr->hwndSelf, &rcWnd);
749         GetClientRect(infoPtr->hwndSelf, &nmpgScroll.rcParent);
750         nmpgScroll.iXpos = nmpgScroll.iYpos = 0;
751         nmpgScroll.iDir = dir;
752 
753         if (infoPtr->dwStyle & PGS_HORZ)
754         {
755             nmpgScroll.iScroll = rcWnd.right - rcWnd.left;
756             nmpgScroll.iXpos = infoPtr->nPos;
757         }
758         else
759         {
760             nmpgScroll.iScroll = rcWnd.bottom - rcWnd.top;
761             nmpgScroll.iYpos = infoPtr->nPos;
762         }
763         nmpgScroll.iScroll -= 2*infoPtr->nButtonSize;
764 
765         SendMessageW (infoPtr->hwndNotify, WM_NOTIFY, nmpgScroll.hdr.idFrom, (LPARAM)&nmpgScroll);
766 
767         TRACE("[%p] PGN_SCROLL returns iScroll=%d\n", infoPtr->hwndSelf, nmpgScroll.iScroll);
768 
769         if (nmpgScroll.iScroll > 0)
770         {
771             infoPtr->direction = dir;
772 
773             if (dir == PGF_SCROLLLEFT || dir == PGF_SCROLLUP)
774                 PAGER_SetPos(infoPtr, infoPtr->nPos - nmpgScroll.iScroll, TRUE);
775             else
776                 PAGER_SetPos(infoPtr, infoPtr->nPos + nmpgScroll.iScroll, TRUE);
777         }
778         else
779             infoPtr->direction = -1;
780     }
781 }
782 
783 static LRESULT
784 PAGER_FmtLines(const PAGER_INFO *infoPtr)
785 {
786     /* initiate NCCalcSize to resize client wnd and get size */
787     SetWindowPos(infoPtr->hwndSelf, 0, 0, 0, 0, 0,
788                  SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE |
789                  SWP_NOZORDER | SWP_NOACTIVATE);
790 
791     SetWindowPos(infoPtr->hwndChild, 0,
792                  0,0,infoPtr->nWidth,infoPtr->nHeight,
793                  0);
794 
795     return DefWindowProcW (infoPtr->hwndSelf, EM_FMTLINES, 0, 0);
796 }
797 
798 static LRESULT
799 PAGER_Create (HWND hwnd, const CREATESTRUCTW *lpcs)
800 {
801     PAGER_INFO *infoPtr;
802 
803     /* allocate memory for info structure */
804     infoPtr = (PAGER_INFO *)Alloc (sizeof(PAGER_INFO));
805     if (!infoPtr) return -1;
806     SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
807 
808     /* set default settings */
809     infoPtr->hwndSelf = hwnd;
810     infoPtr->hwndChild = NULL;
811     infoPtr->hwndNotify = lpcs->hwndParent;
812     infoPtr->dwStyle = lpcs->style;
813     infoPtr->clrBk = GetSysColor(COLOR_BTNFACE);
814     infoPtr->nBorder = 0;
815     infoPtr->nButtonSize = 12;
816     infoPtr->nPos = 0;
817     infoPtr->nWidth = 0;
818     infoPtr->nHeight = 0;
819     infoPtr->bForward = FALSE;
820     infoPtr->bCapture = FALSE;
821     infoPtr->TLbtnState = PGF_INVISIBLE;
822     infoPtr->BRbtnState = PGF_INVISIBLE;
823     infoPtr->direction = -1;
824 
825     if (infoPtr->dwStyle & PGS_DRAGNDROP)
826         FIXME("[%p] Drag and Drop style is not implemented yet.\n", infoPtr->hwndSelf);
827 
828     return 0;
829 }
830 
831 
832 static LRESULT
833 PAGER_Destroy (PAGER_INFO *infoPtr)
834 {
835     SetWindowLongPtrW (infoPtr->hwndSelf, 0, 0);
836     Free (infoPtr);  /* free pager info data */
837     return 0;
838 }
839 
840 static LRESULT
841 PAGER_NCCalcSize(PAGER_INFO* infoPtr, WPARAM wParam, LPRECT lpRect)
842 {
843     RECT rcChild, rcWindow;
844     INT scrollRange;
845 
846     /*
847      * lpRect points to a RECT struct.  On entry, the struct
848      * contains the proposed wnd rectangle for the window.
849      * On exit, the struct should contain the screen
850      * coordinates of the corresponding window's client area.
851      */
852 
853     DefWindowProcW (infoPtr->hwndSelf, WM_NCCALCSIZE, wParam, (LPARAM)lpRect);
854 
855     TRACE("orig rect=%s\n", wine_dbgstr_rect(lpRect));
856 
857     GetWindowRect (infoPtr->hwndChild, &rcChild);
858     MapWindowPoints (0, infoPtr->hwndSelf, (LPPOINT)&rcChild, 2); /* FIXME: RECT != 2 POINTS */
859     GetWindowRect (infoPtr->hwndSelf, &rcWindow);
860 
861     if (infoPtr->dwStyle & PGS_HORZ)
862     {
863         infoPtr->nWidth = lpRect->right - lpRect->left;
864         PAGER_CalcSize (infoPtr, &infoPtr->nWidth, TRUE);
865 
866         scrollRange = infoPtr->nWidth - (rcWindow.right - rcWindow.left);
867 
868         if (infoPtr->TLbtnState && (lpRect->left + infoPtr->nButtonSize < lpRect->right))
869             lpRect->left += infoPtr->nButtonSize;
870         if (infoPtr->BRbtnState && (lpRect->right - infoPtr->nButtonSize > lpRect->left))
871             lpRect->right -= infoPtr->nButtonSize;
872     }
873     else
874     {
875         infoPtr->nHeight = lpRect->bottom - lpRect->top;
876         PAGER_CalcSize (infoPtr, &infoPtr->nHeight, FALSE);
877 
878         scrollRange = infoPtr->nHeight - (rcWindow.bottom - rcWindow.top);
879 
880         if (infoPtr->TLbtnState && (lpRect->top + infoPtr->nButtonSize < lpRect->bottom))
881             lpRect->top += infoPtr->nButtonSize;
882         if (infoPtr->BRbtnState && (lpRect->bottom - infoPtr->nButtonSize > lpRect->top))
883             lpRect->bottom -= infoPtr->nButtonSize;
884     }
885 
886     TRACE("nPos=%d, nHeight=%d, window=%s\n",
887           infoPtr->nPos, infoPtr->nHeight,
888           wine_dbgstr_rect(&rcWindow));
889 
890     TRACE("[%p] client rect set to %dx%d at (%d,%d) BtnState[%d,%d]\n",
891           infoPtr->hwndSelf, lpRect->right-lpRect->left, lpRect->bottom-lpRect->top,
892           lpRect->left, lpRect->top,
893           infoPtr->TLbtnState, infoPtr->BRbtnState);
894 
895     return 0;
896 }
897 
898 static LRESULT
899 PAGER_NCPaint (const PAGER_INFO* infoPtr, HRGN hRgn)
900 {
901     RECT rcBottomRight, rcTopLeft;
902     HDC hdc;
903 
904     if (infoPtr->dwStyle & WS_MINIMIZE)
905         return 0;
906 
907     DefWindowProcW (infoPtr->hwndSelf, WM_NCPAINT, (WPARAM)hRgn, 0);
908 
909     if (!(hdc = GetDCEx (infoPtr->hwndSelf, 0, DCX_USESTYLE | DCX_WINDOW)))
910         return 0;
911 
912     PAGER_GetButtonRects(infoPtr, &rcTopLeft, &rcBottomRight, FALSE);
913 
914     PAGER_DrawButton(hdc, infoPtr->clrBk, rcTopLeft,
915                      infoPtr->dwStyle & PGS_HORZ, TRUE, infoPtr->TLbtnState);
916     PAGER_DrawButton(hdc, infoPtr->clrBk, rcBottomRight,
917                      infoPtr->dwStyle & PGS_HORZ, FALSE, infoPtr->BRbtnState);
918 
919     ReleaseDC( infoPtr->hwndSelf, hdc );
920     return 0;
921 }
922 
923 static INT
924 PAGER_HitTest (const PAGER_INFO* infoPtr, const POINT * pt)
925 {
926     RECT clientRect, rcTopLeft, rcBottomRight;
927     POINT ptWindow;
928 
929     GetClientRect (infoPtr->hwndSelf, &clientRect);
930 
931     if (PtInRect(&clientRect, *pt))
932     {
933         TRACE("child\n");
934         return -1;
935     }
936 
937     ptWindow = *pt;
938     PAGER_GetButtonRects(infoPtr, &rcTopLeft, &rcBottomRight, TRUE);
939 
940     if ((infoPtr->TLbtnState != PGF_INVISIBLE) && PtInRect(&rcTopLeft, ptWindow))
941     {
942         TRACE("PGB_TOPORLEFT\n");
943         return PGB_TOPORLEFT;
944     }
945     else if ((infoPtr->BRbtnState != PGF_INVISIBLE) && PtInRect(&rcBottomRight, ptWindow))
946     {
947         TRACE("PGB_BOTTOMORRIGHT\n");
948         return PGB_BOTTOMORRIGHT;
949     }
950 
951     TRACE("nowhere\n");
952     return -1;
953 }
954 
955 static LRESULT
956 PAGER_NCHitTest (const PAGER_INFO* infoPtr, INT x, INT y)
957 {
958     POINT pt;
959     INT nHit;
960 
961     pt.x = x;
962     pt.y = y;
963 
964     ScreenToClient (infoPtr->hwndSelf, &pt);
965     nHit = PAGER_HitTest(infoPtr, &pt);
966 
967     return (nHit < 0) ? HTTRANSPARENT : HTCLIENT;
968 }
969 
970 static LRESULT
971 PAGER_MouseMove (PAGER_INFO* infoPtr, INT keys, INT x, INT y)
972 {
973     POINT clpt, pt;
974     RECT wnrect, *btnrect = NULL;
975     BOOL topLeft = FALSE;
976     INT btnstate = 0;
977     INT hit;
978     HDC hdc;
979 
980     pt.x = x;
981     pt.y = y;
982 
983     TRACE("[%p] to (%d,%d)\n", infoPtr->hwndSelf, x, y);
984     ClientToScreen(infoPtr->hwndSelf, &pt);
985     GetWindowRect(infoPtr->hwndSelf, &wnrect);
986     if (PtInRect(&wnrect, pt)) {
987         RECT TLbtnrect, BRbtnrect;
988         PAGER_GetButtonRects(infoPtr, &TLbtnrect, &BRbtnrect, FALSE);
989 
990         clpt = pt;
991         MapWindowPoints(0, infoPtr->hwndSelf, &clpt, 1);
992         hit = PAGER_HitTest(infoPtr, &clpt);
993         if ((hit == PGB_TOPORLEFT) && (infoPtr->TLbtnState == PGF_NORMAL))
994         {
995             topLeft = TRUE;
996             btnrect = &TLbtnrect;
997             infoPtr->TLbtnState = PGF_HOT;
998             btnstate = infoPtr->TLbtnState;
999         }
1000         else if ((hit == PGB_BOTTOMORRIGHT) && (infoPtr->BRbtnState == PGF_NORMAL))
1001         {
1002             topLeft = FALSE;
1003             btnrect = &BRbtnrect;
1004             infoPtr->BRbtnState = PGF_HOT;
1005