Move definition of CPINFO structure from winbase.h to winnls.h
[wine] / controls / scroll.c
1 /*              
2  * Scrollbar control
3  *
4  * Copyright 1993 Martin Ayotte
5  * Copyright 1994, 1996 Alexandre Julliard
6  */
7
8 #include "windef.h"
9 #include "wingdi.h"
10 #include "wine/winuser16.h"
11 #include "scroll.h"
12 #include "heap.h"
13 #include "win.h"
14 #include "debugtools.h"
15 #include "cache.h"
16 #include "tweak.h"
17
18 DEFAULT_DEBUG_CHANNEL(scroll)
19
20
21 static HBITMAP hUpArrow = 0;
22 static HBITMAP hDnArrow = 0;
23 static HBITMAP hLfArrow = 0;
24 static HBITMAP hRgArrow = 0;
25 static HBITMAP hUpArrowD = 0;
26 static HBITMAP hDnArrowD = 0;
27 static HBITMAP hLfArrowD = 0;
28 static HBITMAP hRgArrowD = 0;
29 static HBITMAP hUpArrowI = 0;
30 static HBITMAP hDnArrowI = 0;
31 static HBITMAP hLfArrowI = 0;
32 static HBITMAP hRgArrowI = 0;
33
34 #define TOP_ARROW(flags,pressed) \
35    (((flags)&ESB_DISABLE_UP) ? hUpArrowI : ((pressed) ? hUpArrowD:hUpArrow))
36 #define BOTTOM_ARROW(flags,pressed) \
37    (((flags)&ESB_DISABLE_DOWN) ? hDnArrowI : ((pressed) ? hDnArrowD:hDnArrow))
38 #define LEFT_ARROW(flags,pressed) \
39    (((flags)&ESB_DISABLE_LEFT) ? hLfArrowI : ((pressed) ? hLfArrowD:hLfArrow))
40 #define RIGHT_ARROW(flags,pressed) \
41    (((flags)&ESB_DISABLE_RIGHT) ? hRgArrowI : ((pressed) ? hRgArrowD:hRgArrow))
42
43
44   /* Minimum size of the rectangle between the arrows */
45 #define SCROLL_MIN_RECT  4  
46
47   /* Minimum size of the thumb in pixels */
48 #define SCROLL_MIN_THUMB 6
49
50   /* Overlap between arrows and thumb */
51 #define SCROLL_ARROW_THUMB_OVERLAP ((TWEAK_WineLook == WIN31_LOOK) ? 1 : 0)
52
53   /* Delay (in ms) before first repetition when holding the button down */
54 #define SCROLL_FIRST_DELAY   200
55
56   /* Delay (in ms) between scroll repetitions */
57 #define SCROLL_REPEAT_DELAY  50
58
59   /* Scroll timer id */
60 #define SCROLL_TIMER   0
61
62   /* Scroll-bar hit testing */
63 enum SCROLL_HITTEST
64 {
65     SCROLL_NOWHERE,      /* Outside the scroll bar */
66     SCROLL_TOP_ARROW,    /* Top or left arrow */
67     SCROLL_TOP_RECT,     /* Rectangle between the top arrow and the thumb */
68     SCROLL_THUMB,        /* Thumb rectangle */
69     SCROLL_BOTTOM_RECT,  /* Rectangle between the thumb and the bottom arrow */
70     SCROLL_BOTTOM_ARROW  /* Bottom or right arrow */
71 };
72
73  /* What to do after SCROLL_SetScrollInfo() */
74 #define SA_SSI_HIDE             0x0001
75 #define SA_SSI_SHOW             0x0002
76 #define SA_SSI_REFRESH          0x0004
77 #define SA_SSI_REPAINT_ARROWS   0x0008
78
79  /* Thumb-tracking info */
80 static HWND SCROLL_TrackingWin = 0;
81 static INT  SCROLL_TrackingBar = 0;
82 static INT  SCROLL_TrackingPos = 0;
83 static INT  SCROLL_TrackingVal = 0;
84  /* Hit test code of the last button-down event */
85 static enum SCROLL_HITTEST SCROLL_trackHitTest;
86 static BOOL SCROLL_trackVertical;
87
88  /* Is the moving thumb being displayed? */
89 static BOOL SCROLL_MovingThumb = FALSE;
90
91  /* Local functions */
92 static BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar, 
93                                     BOOL fShowH, BOOL fShowV );
94 static INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar, 
95                                    const SCROLLINFO *info, INT *action );
96 static void SCROLL_DrawInterior_9x( HWND hwnd, HDC hdc, INT nBar, 
97                                     RECT *rect, INT arrowSize,
98                                     INT thumbSize, INT thumbPos,
99                                     UINT flags, BOOL vertical,
100                                     BOOL top_selected, BOOL bottom_selected );
101
102
103 /***********************************************************************
104  *           SCROLL_LoadBitmaps
105  */
106 static void SCROLL_LoadBitmaps(void)
107 {
108     hUpArrow  = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_UPARROW) );
109     hDnArrow  = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_DNARROW) );
110     hLfArrow  = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_LFARROW) );
111     hRgArrow  = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RGARROW) );
112     hUpArrowD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_UPARROWD) );
113     hDnArrowD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_DNARROWD) );
114     hLfArrowD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_LFARROWD) );
115     hRgArrowD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RGARROWD) );
116     hUpArrowI = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_UPARROWI) );
117     hDnArrowI = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_DNARROWI) );
118     hLfArrowI = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_LFARROWI) );
119     hRgArrowI = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RGARROWI) );
120 }
121
122
123 /***********************************************************************
124  *           SCROLL_GetPtrScrollInfo
125  */
126 static SCROLLBAR_INFO *SCROLL_GetPtrScrollInfo( WND* wndPtr, INT nBar )
127 {
128     SCROLLBAR_INFO *infoPtr;
129
130     if (!wndPtr) return NULL;
131     switch(nBar)
132     {
133         case SB_HORZ: infoPtr = (SCROLLBAR_INFO *)wndPtr->pHScroll; break;
134         case SB_VERT: infoPtr = (SCROLLBAR_INFO *)wndPtr->pVScroll; break;
135         case SB_CTL:  infoPtr = (SCROLLBAR_INFO *)wndPtr->wExtra; break;
136         default:      return NULL;
137     }
138
139     if (!infoPtr)  /* Create the info structure if needed */
140     {
141         if ((infoPtr = HeapAlloc( SystemHeap, 0, sizeof(SCROLLBAR_INFO) )))
142         {
143             infoPtr->MinVal = infoPtr->CurVal = infoPtr->Page = 0;
144             infoPtr->MaxVal = 100;
145             infoPtr->flags  = ESB_ENABLE_BOTH;
146             if (nBar == SB_HORZ) wndPtr->pHScroll = infoPtr;
147             else wndPtr->pVScroll = infoPtr;
148         }
149         if (!hUpArrow) SCROLL_LoadBitmaps();
150     }
151     return infoPtr;
152 }
153
154
155 /***********************************************************************
156  *           SCROLL_GetScrollInfo
157  */
158 static SCROLLBAR_INFO *SCROLL_GetScrollInfo( HWND hwnd, INT nBar )
159 {
160    SCROLLBAR_INFO *retvalue;
161    WND *wndPtr = WIN_FindWndPtr( hwnd );
162    retvalue = SCROLL_GetPtrScrollInfo( wndPtr, nBar );
163    WIN_ReleaseWndPtr(wndPtr);
164    return retvalue;
165 }
166
167
168 /***********************************************************************
169  *           SCROLL_GetScrollBarRect
170  *
171  * Compute the scroll bar rectangle, in drawing coordinates (i.e. client
172  * coords for SB_CTL, window coords for SB_VERT and SB_HORZ).
173  * 'arrowSize' returns the width or height of an arrow (depending on
174  * the orientation of the scrollbar), 'thumbSize' returns the size of
175  * the thumb, and 'thumbPos' returns the position of the thumb
176  * relative to the left or to the top.
177  * Return TRUE if the scrollbar is vertical, FALSE if horizontal.
178  */
179 static BOOL SCROLL_GetScrollBarRect( HWND hwnd, INT nBar, RECT *lprect,
180                                        INT *arrowSize, INT *thumbSize,
181                                        INT *thumbPos )
182 {
183     INT pixels;
184     BOOL vertical;
185     WND *wndPtr = WIN_FindWndPtr( hwnd );
186
187     switch(nBar)
188     {
189       case SB_HORZ:
190         lprect->left   = wndPtr->rectClient.left - wndPtr->rectWindow.left;
191         lprect->top    = wndPtr->rectClient.bottom - wndPtr->rectWindow.top;
192         lprect->right  = wndPtr->rectClient.right - wndPtr->rectWindow.left;
193         lprect->bottom = lprect->top + GetSystemMetrics(SM_CYHSCROLL);
194         if(wndPtr->dwStyle & WS_BORDER) {
195           lprect->left--;
196           lprect->right++;
197         } else if(wndPtr->dwStyle & WS_VSCROLL)
198           lprect->right++;
199         vertical = FALSE;
200         break;
201
202       case SB_VERT:
203         lprect->left   = wndPtr->rectClient.right - wndPtr->rectWindow.left;
204         lprect->top    = wndPtr->rectClient.top - wndPtr->rectWindow.top;
205         lprect->right  = lprect->left + GetSystemMetrics(SM_CXVSCROLL);
206         lprect->bottom = wndPtr->rectClient.bottom - wndPtr->rectWindow.top;
207         if(wndPtr->dwStyle & WS_BORDER) {
208           lprect->top--;
209           lprect->bottom++;
210         } else if(wndPtr->dwStyle & WS_HSCROLL)
211           lprect->bottom++;
212         vertical = TRUE;
213         break;
214
215       case SB_CTL:
216         GetClientRect( hwnd, lprect );
217         vertical = ((wndPtr->dwStyle & SBS_VERT) != 0);
218         break;
219
220     default:
221         WIN_ReleaseWndPtr(wndPtr);
222         return FALSE;
223     }
224
225     if (vertical) pixels = lprect->bottom - lprect->top;
226     else pixels = lprect->right - lprect->left;
227
228     if (pixels <= 2*GetSystemMetrics(SM_CXVSCROLL) + SCROLL_MIN_RECT)
229     {
230         if (pixels > SCROLL_MIN_RECT)
231             *arrowSize = (pixels - SCROLL_MIN_RECT) / 2;
232         else
233             *arrowSize = 0;
234         *thumbPos = *thumbSize = 0;
235     }
236     else
237     {
238         SCROLLBAR_INFO *info = SCROLL_GetPtrScrollInfo( wndPtr, nBar );
239
240         *arrowSize = GetSystemMetrics(SM_CXVSCROLL);
241         pixels -= (2 * (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP));
242
243         if (info->Page)
244         {
245             *thumbSize = pixels * info->Page / (info->MaxVal-info->MinVal+1);
246             if (*thumbSize < SCROLL_MIN_THUMB) *thumbSize = SCROLL_MIN_THUMB;
247         }
248         else *thumbSize = GetSystemMetrics(SM_CXVSCROLL);
249
250         if (((pixels -= *thumbSize ) < 0) ||
251             ((info->flags & ESB_DISABLE_BOTH) == ESB_DISABLE_BOTH))
252         {
253             /* Rectangle too small or scrollbar disabled -> no thumb */
254             *thumbPos = *thumbSize = 0;
255         }
256         else
257         {
258             INT max = info->MaxVal - MAX( info->Page-1, 0 );
259             if (info->MinVal >= max)
260                 *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
261             else
262                 *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP
263                  + pixels * (info->CurVal-info->MinVal) / (max - info->MinVal);
264         }
265     }
266     WIN_ReleaseWndPtr(wndPtr);
267     return vertical;
268 }
269
270
271 /***********************************************************************
272  *           SCROLL_GetThumbVal
273  *
274  * Compute the current scroll position based on the thumb position in pixels
275  * from the top of the scroll-bar.
276  */
277 static UINT SCROLL_GetThumbVal( SCROLLBAR_INFO *infoPtr, RECT *rect,
278                                   BOOL vertical, INT pos )
279 {
280     INT thumbSize;
281     INT pixels = vertical ? rect->bottom-rect->top : rect->right-rect->left;
282
283     if ((pixels -= 2*(GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP)) <= 0)
284         return infoPtr->MinVal;
285
286     if (infoPtr->Page)
287     {
288         thumbSize = pixels * infoPtr->Page/(infoPtr->MaxVal-infoPtr->MinVal+1);
289         if (thumbSize < SCROLL_MIN_THUMB) thumbSize = SCROLL_MIN_THUMB;
290     }
291     else thumbSize = GetSystemMetrics(SM_CXVSCROLL);
292
293     if ((pixels -= thumbSize) <= 0) return infoPtr->MinVal;
294
295     pos = MAX( 0, pos - (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP) );
296     if (pos > pixels) pos = pixels;
297
298     if (!infoPtr->Page) pos *= infoPtr->MaxVal - infoPtr->MinVal;
299     else pos *= infoPtr->MaxVal - infoPtr->MinVal - infoPtr->Page + 1;
300     return infoPtr->MinVal + ((pos + pixels / 2) / pixels);
301 }
302
303 /***********************************************************************
304  *           SCROLL_PtInRectEx
305  */
306 static BOOL SCROLL_PtInRectEx( LPRECT lpRect, POINT pt, BOOL vertical )
307 {
308     RECT rect = *lpRect;
309
310     if (vertical)
311     {
312         rect.left -= lpRect->right - lpRect->left;
313         rect.right += lpRect->right - lpRect->left;
314     }
315     else
316     {
317         rect.top -= lpRect->bottom - lpRect->top;
318         rect.bottom += lpRect->bottom - lpRect->top;
319     }
320     return PtInRect( &rect, pt );
321 }
322
323 /***********************************************************************
324  *           SCROLL_ClipPos
325  */
326 static POINT SCROLL_ClipPos( LPRECT lpRect, POINT pt )
327 {
328     if( pt.x < lpRect->left )
329         pt.x = lpRect->left;
330     else
331     if( pt.x > lpRect->right )
332         pt.x = lpRect->right;
333
334     if( pt.y < lpRect->top )
335         pt.y = lpRect->top;
336     else
337     if( pt.y > lpRect->bottom )
338         pt.y = lpRect->bottom;
339
340     return pt;
341 }
342
343
344 /***********************************************************************
345  *           SCROLL_HitTest
346  *
347  * Scroll-bar hit testing (don't confuse this with WM_NCHITTEST!).
348  */
349 static enum SCROLL_HITTEST SCROLL_HitTest( HWND hwnd, INT nBar,
350                                            POINT pt, BOOL bDragging )
351 {
352     INT arrowSize, thumbSize, thumbPos;
353     RECT rect;
354
355     BOOL vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
356                                            &arrowSize, &thumbSize, &thumbPos );
357
358     if ( (bDragging && !SCROLL_PtInRectEx( &rect, pt, vertical )) ||
359          (!PtInRect( &rect, pt )) ) return SCROLL_NOWHERE;
360
361     if (vertical)
362     {
363         if (pt.y < rect.top + arrowSize) return SCROLL_TOP_ARROW;
364         if (pt.y >= rect.bottom - arrowSize) return SCROLL_BOTTOM_ARROW;
365         if (!thumbPos) return SCROLL_TOP_RECT;
366         pt.y -= rect.top;
367         if (pt.y < thumbPos) return SCROLL_TOP_RECT;
368         if (pt.y >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
369     }
370     else  /* horizontal */
371     {
372         if (pt.x < rect.left + arrowSize) return SCROLL_TOP_ARROW;
373         if (pt.x >= rect.right - arrowSize) return SCROLL_BOTTOM_ARROW;
374         if (!thumbPos) return SCROLL_TOP_RECT;
375         pt.x -= rect.left;
376         if (pt.x < thumbPos) return SCROLL_TOP_RECT;
377         if (pt.x >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT;
378     }
379     return SCROLL_THUMB;
380 }
381
382
383 /***********************************************************************
384  *           SCROLL_DrawArrows
385  *
386  * Draw the scroll bar arrows.
387  */
388 static void SCROLL_DrawArrows_9x( HDC hdc, SCROLLBAR_INFO *infoPtr,
389                                   RECT *rect, INT arrowSize, BOOL vertical,
390                                   BOOL top_pressed, BOOL bottom_pressed )
391 {
392   RECT r;
393
394   r = *rect;
395   if( vertical )
396     r.bottom = r.top + arrowSize;
397   else
398     r.right = r.left + arrowSize;
399
400   DrawFrameControl( hdc, &r, DFC_SCROLL,
401                     (vertical ? DFCS_SCROLLUP : DFCS_SCROLLLEFT)
402                     | (top_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0 )
403                     | (infoPtr->flags&ESB_DISABLE_LTUP ? DFCS_INACTIVE : 0 ) );
404
405   r = *rect;
406   if( vertical )
407     r.top = r.bottom-arrowSize;
408   else
409     r.left = r.right-arrowSize;
410
411   DrawFrameControl( hdc, &r, DFC_SCROLL,
412                     (vertical ? DFCS_SCROLLDOWN : DFCS_SCROLLRIGHT)
413                     | (bottom_pressed ? (DFCS_PUSHED | DFCS_FLAT) : 0 )
414                     | (infoPtr->flags&ESB_DISABLE_RTDN ? DFCS_INACTIVE : 0) );
415 }
416
417 static void SCROLL_DrawArrows_31( HDC hdc, SCROLLBAR_INFO *infoPtr,
418                                   RECT *rect, INT arrowSize, BOOL vertical,
419                                   BOOL top_pressed, BOOL bottom_pressed )
420 {
421     HDC hdcMem = CreateCompatibleDC( hdc );
422     HBITMAP hbmpPrev = SelectObject( hdcMem, vertical ?
423                                     TOP_ARROW(infoPtr->flags, top_pressed)
424                                     : LEFT_ARROW(infoPtr->flags, top_pressed));
425
426     SetStretchBltMode( hdc, STRETCH_DELETESCANS );
427     StretchBlt( hdc, rect->left, rect->top,
428                   vertical ? rect->right-rect->left : arrowSize,
429                   vertical ? arrowSize : rect->bottom-rect->top,
430                   hdcMem, 0, 0,
431                   GetSystemMetrics(SM_CXVSCROLL),GetSystemMetrics(SM_CYHSCROLL),
432                   SRCCOPY );
433
434     SelectObject( hdcMem, vertical ?
435                     BOTTOM_ARROW( infoPtr->flags, bottom_pressed )
436                     : RIGHT_ARROW( infoPtr->flags, bottom_pressed ) );
437     if (vertical)
438         StretchBlt( hdc, rect->left, rect->bottom - arrowSize,
439                       rect->right - rect->left, arrowSize,
440                       hdcMem, 0, 0,
441                       GetSystemMetrics(SM_CXVSCROLL),GetSystemMetrics(SM_CYHSCROLL),
442                       SRCCOPY );
443     else
444         StretchBlt( hdc, rect->right - arrowSize, rect->top,
445                       arrowSize, rect->bottom - rect->top,
446                       hdcMem, 0, 0,
447                       GetSystemMetrics(SM_CXVSCROLL), GetSystemMetrics(SM_CYHSCROLL),
448                       SRCCOPY );
449     SelectObject( hdcMem, hbmpPrev );
450     DeleteDC( hdcMem );
451 }
452
453 static void SCROLL_DrawArrows( HDC hdc, SCROLLBAR_INFO *infoPtr,
454                                RECT *rect, INT arrowSize, BOOL vertical,
455                                BOOL top_pressed, BOOL bottom_pressed )
456 {
457   if( TWEAK_WineLook == WIN31_LOOK )
458     SCROLL_DrawArrows_31( hdc, infoPtr, rect, arrowSize,
459                           vertical, top_pressed,bottom_pressed );
460   else
461     SCROLL_DrawArrows_9x( hdc, infoPtr, rect, arrowSize,
462                           vertical, top_pressed,bottom_pressed );
463 }
464
465
466 /***********************************************************************
467  *           SCROLL_DrawMovingThumb
468  *
469  * Draw the moving thumb rectangle.
470  */
471 static void SCROLL_DrawMovingThumb_31( HDC hdc, RECT *rect, BOOL vertical,
472                                        INT arrowSize, INT thumbSize )
473 {
474     RECT r = *rect;
475     if (vertical)
476     {
477         r.top += SCROLL_TrackingPos;
478         if (r.top < rect->top + arrowSize - SCROLL_ARROW_THUMB_OVERLAP)
479             r.top = rect->top + arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
480         if (r.top + thumbSize >
481                        rect->bottom - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP))
482             r.top = rect->bottom - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP)
483                                                                   - thumbSize;
484         r.bottom = r.top + thumbSize;
485     }
486     else
487     {
488         r.left += SCROLL_TrackingPos;
489         if (r.left < rect->left + arrowSize - SCROLL_ARROW_THUMB_OVERLAP)
490             r.left = rect->left + arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
491         if (r.left + thumbSize >
492                        rect->right - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP))
493             r.left = rect->right - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP) 
494                                                                   - thumbSize;
495         r.right = r.left + thumbSize;
496     }
497
498     DrawFocusRect( hdc, &r );
499     SCROLL_MovingThumb = !SCROLL_MovingThumb;
500 }
501
502 static void SCROLL_DrawMovingThumb_9x( HDC hdc, RECT *rect, BOOL vertical,
503                                        INT arrowSize, INT thumbSize )
504 {
505   INT pos = SCROLL_TrackingPos;
506   INT max_size;
507
508   if( vertical )
509     max_size = rect->bottom - rect->top;
510   else
511     max_size = rect->right - rect->left;
512
513   max_size -= (arrowSize-SCROLL_ARROW_THUMB_OVERLAP) + thumbSize;
514
515   if( pos < (arrowSize-SCROLL_ARROW_THUMB_OVERLAP) )
516     pos = (arrowSize-SCROLL_ARROW_THUMB_OVERLAP);
517   else if( pos > max_size )
518     pos = max_size;
519
520   SCROLL_DrawInterior_9x( SCROLL_TrackingWin, hdc, SCROLL_TrackingBar,
521                           rect, arrowSize, thumbSize, pos,
522                           0, vertical, FALSE, FALSE );
523                           
524   SCROLL_MovingThumb = !SCROLL_MovingThumb;
525 }
526
527 static void SCROLL_DrawMovingThumb( HDC hdc, RECT *rect, BOOL vertical,
528                                     INT arrowSize, INT thumbSize )
529 {
530   if( TWEAK_WineLook == WIN31_LOOK )
531     SCROLL_DrawMovingThumb_31( hdc, rect, vertical, arrowSize, thumbSize );
532   else
533     SCROLL_DrawMovingThumb_9x( hdc, rect, vertical, arrowSize, thumbSize );
534 }
535
536 /***********************************************************************
537  *           SCROLL_DrawInterior
538  *
539  * Draw the scroll bar interior (everything except the arrows).
540  */
541 static void SCROLL_DrawInterior_9x( HWND hwnd, HDC hdc, INT nBar, 
542                                     RECT *rect, INT arrowSize,
543                                     INT thumbSize, INT thumbPos,
544                                     UINT flags, BOOL vertical,
545                                     BOOL top_selected, BOOL bottom_selected )
546 {
547     RECT r;
548     HPEN hSavePen;
549     HBRUSH hSaveBrush,hBrush;
550
551     /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
552      * The window-owned scrollbars need to call DEFWND_ControlColor
553      * to correctly setup default scrollbar colors
554      */
555     if (nBar == SB_CTL)
556     {  
557       hBrush = (HBRUSH)SendMessageA( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
558                                      (WPARAM)hdc,(LPARAM)hwnd);
559     }
560     else
561     {
562       hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR );
563     }
564
565     hSavePen = SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) );
566     hSaveBrush = SelectObject( hdc, hBrush );
567
568     /* Calculate the scroll rectangle */
569     r = *rect;
570     if (vertical)
571     {
572         r.top    += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
573         r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
574     }
575     else
576     {
577         r.left  += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
578         r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
579     }
580
581     /* Draw the scroll rectangles and thumb */
582     if (!thumbPos)  /* No thumb to draw */
583     {
584         PatBlt( hdc, r.left, r.top,
585                      r.right - r.left, r.bottom - r.top,
586                      PATCOPY );
587
588         /* cleanup and return */
589         SelectObject( hdc, hSavePen );
590         SelectObject( hdc, hSaveBrush );
591         return;
592     }
593
594     if (vertical)
595     {
596         PatBlt( hdc, r.left, r.top,
597                   r.right - r.left,
598                   thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
599                   top_selected ? 0x0f0000 : PATCOPY );
600         r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
601         PatBlt( hdc, r.left, r.top + thumbSize,
602                   r.right - r.left,
603                   r.bottom - r.top - thumbSize,
604                   bottom_selected ? 0x0f0000 : PATCOPY );
605         r.bottom = r.top + thumbSize;
606     }
607     else  /* horizontal */
608     {
609         PatBlt( hdc, r.left, r.top,
610                   thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
611                   r.bottom - r.top,
612                   top_selected ? 0x0f0000 : PATCOPY );
613         r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
614         PatBlt( hdc, r.left + thumbSize, r.top,
615                   r.right - r.left - thumbSize,
616                   r.bottom - r.top,
617                   bottom_selected ? 0x0f0000 : PATCOPY );
618         r.right = r.left + thumbSize;
619     }
620
621     /* Draw the thumb */
622     DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT | BF_MIDDLE  );
623
624     /* cleanup */
625     SelectObject( hdc, hSavePen );
626     SelectObject( hdc, hSaveBrush );
627 }
628
629
630 static void SCROLL_DrawInterior( HWND hwnd, HDC hdc, INT nBar, 
631                                  RECT *rect, INT arrowSize,
632                                  INT thumbSize, INT thumbPos,
633                                  UINT flags, BOOL vertical,
634                                  BOOL top_selected, BOOL bottom_selected )
635 {
636     RECT r;
637     HPEN hSavePen;
638     HBRUSH hSaveBrush,hBrush;
639     BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
640
641     if (Save_SCROLL_MovingThumb &&
642         (SCROLL_TrackingWin == hwnd) &&
643         (SCROLL_TrackingBar == nBar))
644         SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize );
645
646       /* Select the correct brush and pen */
647
648     if (TWEAK_WineLook == WIN31_LOOK && (flags & ESB_DISABLE_BOTH) == ESB_DISABLE_BOTH)
649     {
650         /* This ought to be the color of the parent window */
651         if (TWEAK_WineLook == WIN31_LOOK) {
652             hBrush = GetSysColorBrush(COLOR_WINDOW);
653         } else { 
654             /* Under Win9x look & feel, scrollbars don't have a solid border.
655              * To make scrollbar's background different from the window 
656              * background, we need to apply a gray 0x55aa pattern brush. 
657              * Otherwise it won't look good.
658              */ 
659             hBrush = CACHE_GetPattern55AABrush();
660        }
661     }
662     else
663     {
664         /* Only scrollbar controls send WM_CTLCOLORSCROLLBAR.
665          * The window-owned scrollbars need to call DEFWND_ControlColor
666          * to correctly setup default scrollbar colors
667          */
668         if (nBar == SB_CTL) {  
669             hBrush = (HBRUSH)SendMessageA( GetParent(hwnd), WM_CTLCOLORSCROLLBAR,
670                                            (WPARAM)hdc,(LPARAM)hwnd);
671         } else {
672             hBrush = DEFWND_ControlColor( hdc, CTLCOLOR_SCROLLBAR ); 
673         }
674     }
675     hSavePen = SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) );
676     hSaveBrush = SelectObject( hdc, hBrush );
677
678       /* Calculate the scroll rectangle */
679
680     r = *rect;
681     if (vertical)
682     {
683         r.top    += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
684         r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
685     }
686     else
687     {
688         r.left  += arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
689         r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
690     }
691
692       /* Draw the scroll bar frame */
693
694         /* Only draw outline if Win 3.1.  Mar 24, 1999 - Ronald B. Cemer */
695     if (TWEAK_WineLook == WIN31_LOOK)
696         Rectangle( hdc, r.left, r.top, r.right, r.bottom );
697
698       /* Draw the scroll rectangles and thumb */
699
700     if (!thumbPos)  /* No thumb to draw */
701     {
702         INT offset = (TWEAK_WineLook > WIN31_LOOK) ? 0 : 1;
703
704         PatBlt( hdc, r.left+offset, r.top+offset,
705                      r.right - r.left - 2*offset, r.bottom - r.top - 2*offset,
706                      PATCOPY );
707
708         /* cleanup and return */
709         SelectObject( hdc, hSavePen );
710         SelectObject( hdc, hSaveBrush );
711         return;
712     }
713
714     if (vertical)
715     {
716         INT offset = (TWEAK_WineLook == WIN31_LOOK) ? 1 : 0;
717
718         PatBlt( hdc, r.left + offset, r.top + offset,
719                   r.right - r.left - offset*2,
720                   thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP) - offset,
721                   top_selected ? 0x0f0000 : PATCOPY );
722         r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
723         PatBlt( hdc, r.left + offset, r.top + thumbSize,
724                   r.right - r.left - offset*2,
725                   r.bottom - r.top - thumbSize - offset,
726                   bottom_selected ? 0x0f0000 : PATCOPY );
727         r.bottom = r.top + thumbSize;
728     }
729     else  /* horizontal */
730     {
731         INT offset = (TWEAK_WineLook == WIN31_LOOK) ? 1 : 0;
732
733         PatBlt( hdc, r.left + offset, r.top + offset,
734                   thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP),
735                   r.bottom - r.top - offset*2,
736                   top_selected ? 0x0f0000 : PATCOPY );
737         r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP);
738         PatBlt( hdc, r.left + thumbSize, r.top + offset,
739                   r.right - r.left - thumbSize - offset,
740                   r.bottom - r.top - offset*2,
741                   bottom_selected ? 0x0f0000 : PATCOPY );
742         r.right = r.left + thumbSize;
743     }
744
745       /* Draw the thumb */
746
747     SelectObject( hdc, GetSysColorBrush(COLOR_BTNFACE) );
748     if (TWEAK_WineLook == WIN31_LOOK)
749     {
750         Rectangle( hdc, r.left, r.top, r.right, r.bottom );
751         r.top++, r.left++;
752     }
753     else
754     {
755         Rectangle( hdc, r.left+1, r.top+1, r.right-1, r.bottom-1 );
756     }
757     DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT );
758
759     if (Save_SCROLL_MovingThumb &&
760         (SCROLL_TrackingWin == hwnd) &&
761         (SCROLL_TrackingBar == nBar))
762         SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize );
763
764     /* cleanup */
765     SelectObject( hdc, hSavePen );
766     SelectObject( hdc, hSaveBrush );
767 }
768
769
770 /***********************************************************************
771  *           SCROLL_DrawScrollBar
772  *
773  * Redraw the whole scrollbar.
774  */
775 void SCROLL_DrawScrollBar( HWND hwnd, HDC hdc, INT nBar, 
776                            BOOL arrows, BOOL interior )
777 {
778     INT arrowSize, thumbSize, thumbPos;
779     RECT rect;
780     BOOL vertical;
781     WND *wndPtr = WIN_FindWndPtr( hwnd );
782     SCROLLBAR_INFO *infoPtr = SCROLL_GetPtrScrollInfo( wndPtr, nBar );
783     BOOL Save_SCROLL_MovingThumb = SCROLL_MovingThumb;
784
785     if (!wndPtr || !infoPtr ||
786         ((nBar == SB_VERT) && !(wndPtr->dwStyle & WS_VSCROLL)) ||
787         ((nBar == SB_HORZ) && !(wndPtr->dwStyle & WS_HSCROLL))) goto END;
788     if (!WIN_IsWindowDrawable( wndPtr, FALSE )) goto END;
789
790     vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
791                                         &arrowSize, &thumbSize, &thumbPos );
792
793     if (Save_SCROLL_MovingThumb &&
794         (SCROLL_TrackingWin == hwnd) &&
795         (SCROLL_TrackingBar == nBar))
796         SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize, thumbSize );
797
798       /* Draw the arrows */
799
800     if (arrows && arrowSize)
801     {
802         if( vertical == SCROLL_trackVertical && GetCapture() == hwnd )
803             SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
804                                (SCROLL_trackHitTest == SCROLL_TOP_ARROW),
805                                (SCROLL_trackHitTest == SCROLL_BOTTOM_ARROW) );
806         else
807             SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical, 
808                                                                FALSE, FALSE );
809     }
810     if( interior )
811         SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
812                          thumbPos, infoPtr->flags, vertical, FALSE, FALSE );
813
814     if (Save_SCROLL_MovingThumb &&
815         (SCROLL_TrackingWin == hwnd) &&
816         (SCROLL_TrackingBar == nBar))
817         SCROLL_DrawMovingThumb( hdc, &rect, vertical, arrowSize, thumbSize );
818
819 END:
820     WIN_ReleaseWndPtr(wndPtr);
821 }
822
823
824 /***********************************************************************
825  *           SCROLL_RefreshScrollBar
826  *
827  * Repaint the scroll bar interior after a SetScrollRange() or
828  * SetScrollPos() call.
829  */
830 static void SCROLL_RefreshScrollBar( HWND hwnd, INT nBar, 
831                                      BOOL arrows, BOOL interior )
832 {
833     HDC hdc = GetDCEx( hwnd, 0,
834                            DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW) );
835     if (!hdc) return;
836
837     SCROLL_DrawScrollBar( hwnd, hdc, nBar, arrows, interior );
838     ReleaseDC( hwnd, hdc );
839 }
840
841
842 /***********************************************************************
843  *           SCROLL_HandleKbdEvent
844  *
845  * Handle a keyboard event (only for SB_CTL scrollbars).
846  */
847 static void SCROLL_HandleKbdEvent( HWND hwnd, WPARAM wParam )
848 {
849     WND *wndPtr = WIN_FindWndPtr( hwnd );
850     WPARAM msg;
851     
852     switch(wParam)
853     {
854     case VK_PRIOR: msg = SB_PAGEUP; break;
855     case VK_NEXT:  msg = SB_PAGEDOWN; break;
856     case VK_HOME:  msg = SB_TOP; break;
857     case VK_END:   msg = SB_BOTTOM; break;
858     case VK_UP:    msg = SB_LINEUP; break;
859     case VK_DOWN:  msg = SB_LINEDOWN; break;
860     default:
861         WIN_ReleaseWndPtr(wndPtr);
862         return;
863     }
864     SendMessageA( GetParent(hwnd),
865                     (wndPtr->dwStyle & SBS_VERT) ? WM_VSCROLL : WM_HSCROLL,
866                     msg, hwnd );
867     WIN_ReleaseWndPtr(wndPtr);
868 }
869
870
871 /***********************************************************************
872  *           SCROLL_HandleScrollEvent
873  *
874  * Handle a mouse or timer event for the scrollbar.
875  * 'pt' is the location of the mouse event in client (for SB_CTL) or
876  * windows coordinates.
877  */
878 void SCROLL_HandleScrollEvent( HWND hwnd, INT nBar, UINT msg, POINT pt)
879 {
880       /* Previous mouse position for timer events */
881     static POINT prevPt;
882       /* Thumb position when tracking started. */
883     static UINT trackThumbPos;
884       /* Position in the scroll-bar of the last button-down event. */
885     static INT lastClickPos;
886       /* Position in the scroll-bar of the last mouse event. */
887     static INT lastMousePos;
888
889     enum SCROLL_HITTEST hittest;
890     HWND hwndOwner, hwndCtl;
891     BOOL vertical;
892     INT arrowSize, thumbSize, thumbPos;
893     RECT rect;
894     HDC hdc;
895
896     SCROLLBAR_INFO *infoPtr = SCROLL_GetScrollInfo( hwnd, nBar );
897     if (!infoPtr) return;
898     if ((SCROLL_trackHitTest == SCROLL_NOWHERE) && (msg != WM_LBUTTONDOWN)) 
899                   return;
900
901     hdc = GetDCEx( hwnd, 0, DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW));
902     vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
903                                         &arrowSize, &thumbSize, &thumbPos );
904     hwndOwner = (nBar == SB_CTL) ? GetParent(hwnd) : hwnd;
905     hwndCtl   = (nBar == SB_CTL) ? hwnd : 0;
906
907     switch(msg)
908     {
909       case WM_LBUTTONDOWN:  /* Initialise mouse tracking */
910           SCROLL_trackVertical = vertical;
911           SCROLL_trackHitTest  = hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
912           lastClickPos  = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
913           lastMousePos  = lastClickPos;
914           trackThumbPos = thumbPos;
915           prevPt = pt;
916           SetCapture( hwnd );
917           if (nBar == SB_CTL) SetFocus( hwnd );
918           break;
919
920       case WM_MOUSEMOVE:
921           hittest = SCROLL_HitTest( hwnd, nBar, pt, TRUE );
922           prevPt = pt;
923           break;
924
925       case WM_LBUTTONUP:
926           hittest = SCROLL_NOWHERE;
927           ReleaseCapture();
928           break;
929
930       case WM_SYSTIMER:
931           pt = prevPt;
932           hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
933           break;
934
935       default:
936           return;  /* Should never happen */
937     }
938
939     TRACE("Event: hwnd=%04x bar=%d msg=%x pt=%ld,%ld hit=%d\n",
940                  hwnd, nBar, msg, pt.x, pt.y, hittest );
941
942     switch(SCROLL_trackHitTest)
943     {
944     case SCROLL_NOWHERE:  /* No tracking in progress */
945         break;
946
947     case SCROLL_TOP_ARROW:
948         SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
949                            (hittest == SCROLL_trackHitTest), FALSE );
950         if (hittest == SCROLL_trackHitTest)
951         {
952             if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
953             {
954                 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
955                                 SB_LINEUP, hwndCtl );
956             }
957              
958             SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
959                             SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
960                             (TIMERPROC)0 );
961         }
962         else KillSystemTimer( hwnd, SCROLL_TIMER );
963         break;
964
965     case SCROLL_TOP_RECT:
966         SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
967                              thumbPos, infoPtr->flags, vertical,
968                              (hittest == SCROLL_trackHitTest), FALSE );
969         if (hittest == SCROLL_trackHitTest)
970         {
971             if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
972             {
973                 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
974                                 SB_PAGEUP, hwndCtl );
975                 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
976                                   SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
977                                   (TIMERPROC)0 );
978             }
979         }
980         else KillSystemTimer( hwnd, SCROLL_TIMER );
981         break;
982
983     case SCROLL_THUMB:
984         if (msg == WM_LBUTTONDOWN)
985         {
986             SCROLL_TrackingWin = hwnd;
987             SCROLL_TrackingBar = nBar;
988             SCROLL_TrackingPos = trackThumbPos + lastMousePos - lastClickPos;
989             if (!SCROLL_MovingThumb)
990                 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
991         }
992         else if (msg == WM_LBUTTONUP)
993         {
994             if (SCROLL_MovingThumb)
995                 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
996             SCROLL_TrackingWin = 0;
997             SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
998                                  thumbPos, infoPtr->flags, vertical,
999                                  FALSE, FALSE );
1000         }
1001         else  /* WM_MOUSEMOVE */
1002         {
1003             UINT pos;
1004
1005             if (!SCROLL_PtInRectEx( &rect, pt, vertical )) pos = lastClickPos;
1006             else
1007             {
1008                 pt = SCROLL_ClipPos( &rect, pt );
1009                 pos = vertical ? (pt.y - rect.top) : (pt.x - rect.left);
1010             }
1011             if ( (pos != lastMousePos) || (!SCROLL_MovingThumb) )
1012             {
1013                 if (SCROLL_MovingThumb)
1014                     SCROLL_DrawMovingThumb( hdc, &rect, vertical,
1015                                         arrowSize, thumbSize );
1016                 lastMousePos = pos;
1017                 SCROLL_TrackingPos = trackThumbPos + pos - lastClickPos;
1018                 SCROLL_TrackingVal = SCROLL_GetThumbVal( infoPtr, &rect,
1019                                                          vertical,
1020                                                          SCROLL_TrackingPos );
1021                 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1022                                 MAKEWPARAM( SB_THUMBTRACK, SCROLL_TrackingVal),
1023                                 hwndCtl );
1024                 if (!SCROLL_MovingThumb)
1025                     SCROLL_DrawMovingThumb( hdc, &rect, vertical,
1026                                         arrowSize, thumbSize );
1027             }
1028         }
1029         break;
1030         
1031     case SCROLL_BOTTOM_RECT:
1032         SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
1033                              thumbPos, infoPtr->flags, vertical,
1034                              FALSE, (hittest == SCROLL_trackHitTest) );
1035         if (hittest == SCROLL_trackHitTest)
1036         {
1037             if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1038             {
1039                 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1040                                 SB_PAGEDOWN, hwndCtl );
1041                 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1042                                   SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
1043                                   (TIMERPROC)0 );
1044             }
1045         }
1046         else KillSystemTimer( hwnd, SCROLL_TIMER );
1047         break;
1048         
1049     case SCROLL_BOTTOM_ARROW:
1050         SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical,
1051                            FALSE, (hittest == SCROLL_trackHitTest) );
1052         if (hittest == SCROLL_trackHitTest)
1053         {
1054             if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
1055             {
1056                 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1057                                 SB_LINEDOWN, hwndCtl );
1058             }
1059
1060             SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1061                             SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
1062                             (TIMERPROC)0 );
1063         }
1064         else KillSystemTimer( hwnd, SCROLL_TIMER );
1065         break;
1066     }
1067
1068     if (msg == WM_LBUTTONUP)
1069     {
1070         hittest = SCROLL_trackHitTest;
1071         SCROLL_trackHitTest = SCROLL_NOWHERE;  /* Terminate tracking */
1072
1073         if (hittest == SCROLL_THUMB)
1074         {
1075             UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
1076                                  trackThumbPos + lastMousePos - lastClickPos );
1077             SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1078                             MAKEWPARAM( SB_THUMBPOSITION, val ), hwndCtl );
1079         }
1080         else
1081             SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
1082                             SB_ENDSCROLL, hwndCtl );
1083     }
1084
1085     ReleaseDC( hwnd, hdc );
1086 }
1087
1088
1089 /***********************************************************************
1090  *           ScrollBarWndProc
1091  */
1092 LRESULT WINAPI ScrollBarWndProc( HWND hwnd, UINT message, WPARAM wParam,
1093                                  LPARAM lParam )
1094 {
1095     switch(message)
1096     {
1097     case WM_CREATE:
1098         {
1099             CREATESTRUCTA *lpCreat = (CREATESTRUCTA *)lParam;
1100             if (lpCreat->style & SBS_SIZEBOX)
1101             {
1102                 FIXME("Unimplemented style SBS_SIZEBOX.\n" );
1103                 return 0;
1104             }
1105             
1106             if (lpCreat->style & SBS_VERT)
1107             {
1108                 if (lpCreat->style & SBS_LEFTALIGN)
1109                     MoveWindow( hwnd, lpCreat->x, lpCreat->y,
1110                                   GetSystemMetrics(SM_CXVSCROLL)+1, lpCreat->cy, FALSE );
1111                 else if (lpCreat->style & SBS_RIGHTALIGN)
1112                     MoveWindow( hwnd, 
1113                                   lpCreat->x+lpCreat->cx-GetSystemMetrics(SM_CXVSCROLL)-1,
1114                                   lpCreat->y,
1115                                   GetSystemMetrics(SM_CXVSCROLL)+1, lpCreat->cy, FALSE );
1116             }
1117             else  /* SBS_HORZ */
1118             {
1119                 if (lpCreat->style & SBS_TOPALIGN)
1120                     MoveWindow( hwnd, lpCreat->x, lpCreat->y,
1121                                   lpCreat->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1122                 else if (lpCreat->style & SBS_BOTTOMALIGN)
1123                     MoveWindow( hwnd, 
1124                                   lpCreat->x,
1125                                   lpCreat->y+lpCreat->cy-GetSystemMetrics(SM_CYHSCROLL)-1,
1126                                   lpCreat->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
1127             }
1128         }
1129         if (!hUpArrow) SCROLL_LoadBitmaps();
1130         TRACE("ScrollBar creation, hwnd=%04x\n", hwnd );
1131         return 0;
1132         
1133     case WM_LBUTTONDOWN:
1134     case WM_LBUTTONUP:
1135     case WM_MOUSEMOVE:
1136     case WM_SYSTIMER:
1137         {
1138             POINT pt;
1139             CONV_POINT16TO32( (POINT16 *)&lParam, &pt );
1140             SCROLL_HandleScrollEvent( hwnd, SB_CTL, message, pt );
1141         }
1142         break;
1143
1144     case WM_KEYDOWN:
1145         SCROLL_HandleKbdEvent( hwnd, wParam );
1146         break;
1147
1148     case WM_ERASEBKGND:
1149          return 1;
1150
1151     case WM_GETDLGCODE:
1152          return DLGC_WANTARROWS; /* Windows returns this value */
1153
1154     case WM_PAINT:
1155         {
1156             PAINTSTRUCT ps;
1157             HDC hdc = BeginPaint( hwnd, &ps );
1158             SCROLL_DrawScrollBar( hwnd, hdc, SB_CTL, TRUE, TRUE );
1159             EndPaint( hwnd, &ps );
1160         }
1161         break;
1162
1163     case SBM_SETPOS16:
1164     case SBM_SETPOS:
1165         return SetScrollPos( hwnd, SB_CTL, wParam, (BOOL)lParam );
1166
1167     case SBM_GETPOS16:
1168     case SBM_GETPOS:
1169         return GetScrollPos( hwnd, SB_CTL );
1170
1171     case SBM_SETRANGE16:
1172         SetScrollRange( hwnd, SB_CTL, LOWORD(lParam), HIWORD(lParam),
1173                           wParam  /* FIXME: Is this correct? */ );
1174         return 0;
1175
1176     case SBM_SETRANGE:
1177         SetScrollRange( hwnd, SB_CTL, wParam, lParam, FALSE );
1178         return 0;  /* FIXME: return previous position */
1179
1180     case SBM_GETRANGE16:
1181         FIXME("don't know how to handle SBM_GETRANGE16 (wp=%04x,lp=%08lx)\n", wParam, lParam );
1182         return 0;
1183
1184     case SBM_GETRANGE:
1185         GetScrollRange( hwnd, SB_CTL, (LPINT)wParam, (LPINT)lParam );
1186         return 0;
1187
1188     case SBM_ENABLE_ARROWS16:
1189     case SBM_ENABLE_ARROWS:
1190         return EnableScrollBar( hwnd, SB_CTL, wParam );
1191
1192     case SBM_SETRANGEREDRAW:
1193         SetScrollRange( hwnd, SB_CTL, wParam, lParam, TRUE );
1194         return 0;  /* FIXME: return previous position */
1195         
1196     case SBM_SETSCROLLINFO:
1197         return SetScrollInfo( hwnd, SB_CTL, (SCROLLINFO *)lParam, wParam );
1198
1199     case SBM_GETSCROLLINFO:
1200         return GetScrollInfo( hwnd, SB_CTL, (SCROLLINFO *)lParam );
1201
1202     case 0x00e5:
1203     case 0x00e7:
1204     case 0x00e8:
1205     case 0x00eb:
1206     case 0x00ec:
1207     case 0x00ed:
1208     case 0x00ee:
1209     case 0x00ef:
1210         ERR("unknown Win32 msg %04x wp=%08x lp=%08lx\n",
1211                     message, wParam, lParam );
1212         break;
1213
1214     default:
1215         if (message >= WM_USER)
1216             WARN("unknown msg %04x wp=%04x lp=%08lx\n",
1217                          message, wParam, lParam );
1218         return DefWindowProcA( hwnd, message, wParam, lParam );
1219     }
1220     return 0;
1221 }
1222
1223
1224 /*************************************************************************
1225  *           SetScrollInfo16   (USER.475)
1226  */
1227 INT16 WINAPI SetScrollInfo16( HWND16 hwnd, INT16 nBar, const SCROLLINFO *info,
1228                               BOOL16 bRedraw )
1229 {
1230     return (INT16)SetScrollInfo( hwnd, nBar, info, bRedraw );
1231 }
1232
1233
1234 /*************************************************************************
1235  *           SetScrollInfo32   (USER32.501)
1236  * SetScrollInfo32 can be used to set the position, upper bound, 
1237  * lower bound, and page size of a scrollbar control.
1238  *
1239  * RETURNS
1240  *    Scrollbar position
1241  *
1242  * NOTE
1243  *    For 100 lines of text to be displayed in a window of 25 lines,
1244  *  one would for instance use info->nMin=0, info->nMax=75
1245  *  (corresponding to the 76 different positions of the window on
1246  *  the text), and info->nPage=25.
1247  */
1248 INT WINAPI SetScrollInfo( 
1249 HWND hwnd /* [I] Handle of window whose scrollbar will be affected */, 
1250 INT nBar /* [I] One of SB_HORZ, SB_VERT, or SB_CTL */, 
1251 const SCROLLINFO *info /* [I] Specifies what to change and new values */,
1252 BOOL bRedraw /* [I] Should scrollbar be redrawn afterwards ? */)
1253 {
1254     INT action;
1255     INT retVal = SCROLL_SetScrollInfo( hwnd, nBar, info, &action );
1256
1257     if( action & SA_SSI_HIDE )
1258         SCROLL_ShowScrollBar( hwnd, nBar, FALSE, FALSE );
1259     else
1260     {
1261         if( action & SA_SSI_SHOW )
1262             if( SCROLL_ShowScrollBar( hwnd, nBar, TRUE, TRUE ) )
1263                 return retVal; /* SetWindowPos() already did the painting */
1264
1265         if( bRedraw && (action & SA_SSI_REFRESH))
1266             SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );
1267         else if( action & SA_SSI_REPAINT_ARROWS )
1268             SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, FALSE );
1269     }
1270     return retVal;
1271 }
1272
1273 INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar, 
1274                             const SCROLLINFO *info, INT *action  )
1275 {
1276     /* Update the scrollbar state and set action flags according to 
1277      * what has to be done graphics wise. */
1278
1279     SCROLLBAR_INFO *infoPtr;
1280     UINT new_flags;
1281
1282    *action = 0;
1283
1284     if (!(infoPtr = SCROLL_GetScrollInfo(hwnd, nBar))) return 0;
1285     if (info->fMask & ~(SIF_ALL | SIF_DISABLENOSCROLL)) return 0;
1286     if ((info->cbSize != sizeof(*info)) &&
1287         (info->cbSize != sizeof(*info)-sizeof(info->nTrackPos))) return 0;
1288
1289     if (TRACE_ON(scroll))
1290     {
1291         DPRINTF( "hwnd=%04x bar=%d", hwnd, nBar);
1292         if (info->fMask & SIF_PAGE) DPRINTF( " page=%d", info->nPage );
1293         if (info->fMask & SIF_POS) DPRINTF( " pos=%d", info->nPos );
1294         if (info->fMask & SIF_RANGE) DPRINTF( " min=%d max=%d", info->nMin, info->nMax );
1295         DPRINTF("\n");
1296     }
1297
1298     /* Set the page size */
1299
1300     if (info->fMask & SIF_PAGE)
1301     {
1302         if( infoPtr->Page != info->nPage )
1303         {
1304             infoPtr->Page = info->nPage;
1305            *action |= SA_SSI_REFRESH;
1306         }
1307     }
1308
1309     /* Set the scroll pos */
1310
1311     if (info->fMask & SIF_POS)
1312     {
1313         if( infoPtr->CurVal != info->nPos )
1314         {
1315             infoPtr->CurVal = info->nPos;
1316            *action |= SA_SSI_REFRESH;
1317         }
1318     }
1319
1320     /* Set the scroll range */
1321
1322     if (info->fMask & SIF_RANGE)
1323     {
1324         /* Invalid range -> range is set to (0,0) */
1325         if ((info->nMin > info->nMax) ||
1326             ((UINT)(info->nMax - info->nMin) >= 0x80000000))
1327         {
1328             infoPtr->MinVal = 0;
1329             infoPtr->MaxVal = 0;
1330         }
1331         else
1332         {
1333             if( infoPtr->MinVal != info->nMin ||
1334                 infoPtr->MaxVal != info->nMax )
1335             {
1336                *action |= SA_SSI_REFRESH;
1337                 infoPtr->MinVal = info->nMin;
1338                 infoPtr->MaxVal = info->nMax;
1339             }
1340         }
1341     }
1342
1343     /* Make sure the page size is valid */
1344
1345     if (infoPtr->Page < 0) infoPtr->Page = 0;
1346     else if (infoPtr->Page > infoPtr->MaxVal - infoPtr->MinVal + 1 )
1347         infoPtr->Page = infoPtr->MaxVal - infoPtr->MinVal + 1;
1348
1349     /* Make sure the pos is inside the range */
1350
1351     if (infoPtr->CurVal < infoPtr->MinVal)
1352         infoPtr->CurVal = infoPtr->MinVal;
1353     else if (infoPtr->CurVal > infoPtr->MaxVal - MAX( infoPtr->Page-1, 0 ))
1354         infoPtr->CurVal = infoPtr->MaxVal - MAX( infoPtr->Page-1, 0 );
1355
1356     TRACE("    new values: page=%d pos=%d min=%d max=%d\n",
1357                  infoPtr->Page, infoPtr->CurVal,
1358                  infoPtr->MinVal, infoPtr->MaxVal );
1359
1360     /* don't change the scrollbar state if SetScrollInfo 
1361      * is just called with SIF_DISABLENOSCROLL
1362      */
1363     if(!(info->fMask & SIF_ALL)) goto done;
1364
1365     /* Check if the scrollbar should be hidden or disabled */
1366
1367     if (info->fMask & (SIF_RANGE | SIF_PAGE | SIF_DISABLENOSCROLL))
1368     {
1369         new_flags = infoPtr->flags;
1370         if (infoPtr->MinVal >= infoPtr->MaxVal - MAX( infoPtr->Page-1, 0 ))
1371         {
1372             /* Hide or disable scroll-bar */
1373             if (info->fMask & SIF_DISABLENOSCROLL)
1374             {
1375                 new_flags = ESB_DISABLE_BOTH;
1376                *action |= SA_SSI_REFRESH;
1377             }
1378             else if (nBar != SB_CTL)
1379             {
1380                 *action = SA_SSI_HIDE;
1381                 goto done;
1382             }
1383         }
1384         else  /* Show and enable scroll-bar */
1385         {
1386             new_flags = 0;
1387             if (nBar != SB_CTL)
1388                 *action |= SA_SSI_SHOW;
1389         }
1390
1391         if (infoPtr->flags != new_flags) /* check arrow flags */
1392         {
1393             infoPtr->flags = new_flags;
1394            *action |= SA_SSI_REPAINT_ARROWS;
1395         }
1396     }
1397
1398 done:
1399     /* Return current position */
1400
1401     return infoPtr->CurVal;
1402 }
1403
1404
1405 /*************************************************************************
1406  *           GetScrollInfo16   (USER.476)
1407  */
1408 BOOL16 WINAPI GetScrollInfo16( HWND16 hwnd, INT16 nBar, LPSCROLLINFO info )
1409 {
1410     return GetScrollInfo( hwnd, nBar, info );
1411 }
1412
1413
1414 /*************************************************************************
1415  *           GetScrollInfo32   (USER32.284)
1416  * GetScrollInfo32 can be used to retrieve the position, upper bound, 
1417  * lower bound, and page size of a scrollbar control.
1418  *
1419  * RETURNS STD
1420  */
1421 BOOL WINAPI GetScrollInfo( 
1422   HWND hwnd /* [I] Handle of window */ , 
1423   INT nBar /* [I] One of SB_HORZ, SB_VERT, or SB_CTL */, 
1424   LPSCROLLINFO info /* [IO] (info.fMask [I] specifies which values are to retrieve) */)
1425 {
1426     SCROLLBAR_INFO *infoPtr;
1427
1428     if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar ))) return FALSE;
1429     if (info->fMask & ~(SIF_ALL | SIF_DISABLENOSCROLL)) return FALSE;
1430     if ((info->cbSize != sizeof(*info)) &&
1431         (info->cbSize != sizeof(*info)-sizeof(info->nTrackPos))) return FALSE;
1432
1433     if (info->fMask & SIF_PAGE) info->nPage = infoPtr->Page;
1434     if (info->fMask & SIF_POS) info->nPos = infoPtr->CurVal;
1435     if ((info->fMask & SIF_TRACKPOS) && (info->cbSize == sizeof(*info)))
1436         info->nTrackPos = (SCROLL_TrackingWin==hwnd) ? SCROLL_TrackingVal : infoPtr->CurVal;
1437     if (info->fMask & SIF_RANGE)
1438     {
1439         info->nMin = infoPtr->MinVal;
1440         info->nMax = infoPtr->MaxVal;
1441     }
1442     return (info->fMask & SIF_ALL) != 0;
1443 }
1444
1445
1446 /*************************************************************************
1447  *           SetScrollPos16   (USER.62)
1448  */
1449 INT16 WINAPI SetScrollPos16( HWND16 hwnd, INT16 nBar, INT16 nPos,
1450                              BOOL16 bRedraw )
1451 {
1452     return (INT16)SetScrollPos( hwnd, nBar, nPos, bRedraw );
1453 }
1454
1455
1456 /*************************************************************************
1457  *           SetScrollPos32   (USER32.502)
1458  *
1459  * RETURNS
1460  *    Success: Scrollbar position
1461  *    Failure: 0
1462  *
1463  * REMARKS
1464  *    Note the ambiguity when 0 is returned.  Use GetLastError
1465  *    to make sure there was an error (and to know which one).
1466  */
1467 INT WINAPI SetScrollPos( 
1468 HWND hwnd /* [I] Handle of window whose scrollbar will be affected */,
1469 INT nBar /* [I] One of SB_HORZ, SB_VERT, or SB_CTL */,
1470 INT nPos /* [I] New value */,
1471 BOOL bRedraw /* [I] Should scrollbar be redrawn afterwards ? */ )
1472 {
1473     SCROLLINFO info;
1474     SCROLLBAR_INFO *infoPtr;
1475     INT oldPos;
1476
1477     if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar ))) return 0;
1478     oldPos      = infoPtr->CurVal;
1479     info.cbSize = sizeof(info);
1480     info.nPos   = nPos;
1481     info.fMask  = SIF_POS;
1482     SetScrollInfo( hwnd, nBar, &info, bRedraw );
1483     return oldPos;
1484 }
1485
1486
1487 /*************************************************************************
1488  *           GetScrollPos16   (USER.63)
1489  */
1490 INT16 WINAPI GetScrollPos16( HWND16 hwnd, INT16 nBar )
1491 {
1492     return (INT16)GetScrollPos( hwnd, nBar );
1493 }
1494
1495
1496 /*************************************************************************
1497  *           GetScrollPos32   (USER32.285)
1498  *
1499  * RETURNS
1500  *    Success: Current position
1501  *    Failure: 0   
1502  *
1503  * REMARKS
1504  *    Note the ambiguity when 0 is returned.  Use GetLastError
1505  *    to make sure there was an error (and to know which one).
1506  */
1507 INT WINAPI GetScrollPos( 
1508 HWND hwnd, /* [I] Handle of window */
1509 INT nBar /* [I] One of SB_HORZ, SB_VERT, or SB_CTL */)
1510 {
1511     SCROLLBAR_INFO *infoPtr;
1512
1513     if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar ))) return 0;
1514     return infoPtr->CurVal;
1515 }
1516
1517
1518 /*************************************************************************
1519  *           SetScrollRange16   (USER.64)
1520  */
1521 void WINAPI SetScrollRange16( HWND16 hwnd, INT16 nBar,
1522                               INT16 MinVal, INT16 MaxVal, BOOL16 bRedraw )
1523 {
1524     /* Invalid range -> range is set to (0,0) */
1525     if ((INT)MaxVal - (INT)MinVal > 0x7fff) MinVal = MaxVal = 0;
1526     SetScrollRange( hwnd, nBar, MinVal, MaxVal, bRedraw );
1527 }
1528
1529
1530 /*************************************************************************
1531  *           SetScrollRange32   (USER32.503)
1532  *
1533  * RETURNS STD
1534  */
1535 BOOL WINAPI SetScrollRange( 
1536 HWND hwnd, /* [I] Handle of window whose scrollbar will be affected */
1537 INT nBar, /* [I] One of SB_HORZ, SB_VERT, or SB_CTL */
1538 INT MinVal, /* [I] New minimum value */
1539 INT MaxVal, /* [I] New maximum value */
1540 BOOL bRedraw /* [I] Should scrollbar be redrawn afterwards ? */)
1541 {
1542     SCROLLINFO info;
1543
1544     info.cbSize = sizeof(info);
1545     info.nMin   = MinVal;
1546     info.nMax   = MaxVal;
1547     info.fMask  = SIF_RANGE;
1548     SetScrollInfo( hwnd, nBar, &info, bRedraw );
1549     return TRUE;
1550 }
1551
1552
1553 /*************************************************************************
1554  *           SCROLL_SetNCSbState
1555  *
1556  * Updates both scrollbars at the same time. Used by MDI CalcChildScroll().
1557  */
1558 INT SCROLL_SetNCSbState(WND* wndPtr, int vMin, int vMax, int vPos,
1559                                        int hMin, int hMax, int hPos)
1560 {
1561     INT vA, hA;
1562     SCROLLINFO vInfo, hInfo;
1563  
1564     vInfo.cbSize = hInfo.cbSize = sizeof(SCROLLINFO);
1565     vInfo.nMin   = vMin;         hInfo.nMin   = hMin;
1566     vInfo.nMax   = vMax;         hInfo.nMax   = hMax;
1567     vInfo.nPos   = vPos;         hInfo.nPos   = hPos;
1568     vInfo.fMask  = hInfo.fMask = SIF_RANGE | SIF_POS;
1569
1570     SCROLL_SetScrollInfo( wndPtr->hwndSelf, SB_VERT, &vInfo, &vA );
1571     SCROLL_SetScrollInfo( wndPtr->hwndSelf, SB_HORZ, &hInfo, &hA );
1572
1573     if( !SCROLL_ShowScrollBar( wndPtr->hwndSelf, SB_BOTH,
1574                               (hA & SA_SSI_SHOW),(vA & SA_SSI_SHOW) ) )
1575     {
1576         /* SetWindowPos() wasn't called, just redraw the scrollbars if needed */
1577         if( vA & SA_SSI_REFRESH )
1578             SCROLL_RefreshScrollBar( wndPtr->hwndSelf, SB_VERT, FALSE, TRUE );
1579
1580         if( hA & SA_SSI_REFRESH )
1581             SCROLL_RefreshScrollBar( wndPtr->hwndSelf, SB_HORZ, FALSE, TRUE );
1582     }
1583     return 0;
1584 }
1585
1586
1587 /*************************************************************************
1588  *           GetScrollRange16   (USER.65)
1589  */
1590 BOOL16 WINAPI GetScrollRange16( HWND16 hwnd, INT16 nBar,
1591                                 LPINT16 lpMin, LPINT16 lpMax)
1592 {
1593     INT min, max;
1594     BOOL16 ret = GetScrollRange( hwnd, nBar, &min, &max );
1595     if (lpMin) *lpMin = min;
1596     if (lpMax) *lpMax = max;
1597     return ret;
1598 }
1599
1600
1601 /*************************************************************************
1602  *           GetScrollRange32   (USER32.286)
1603  *
1604  * RETURNS STD
1605  */
1606 BOOL WINAPI GetScrollRange( 
1607 HWND hwnd, /* [I] Handle of window */
1608 INT nBar, /* [I] One of SB_HORZ, SB_VERT, or SB_CTL  */
1609 LPINT lpMin, /* [O] Where to store minimum value */
1610 LPINT lpMax /* [O] Where to store maximum value */)
1611 {
1612     SCROLLBAR_INFO *infoPtr;
1613
1614     if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar )))
1615     {
1616         if (lpMin) lpMin = 0;
1617         if (lpMax) lpMax = 0;
1618         return FALSE;
1619     }
1620     if (lpMin) *lpMin = infoPtr->MinVal;
1621     if (lpMax) *lpMax = infoPtr->MaxVal;
1622     return TRUE;
1623 }
1624
1625
1626 /*************************************************************************
1627  *           SCROLL_ShowScrollBar()
1628  *
1629  * Back-end for ShowScrollBar(). Returns FALSE if no action was taken.
1630  * NOTE: fShowV/fShowH must be zero when nBar is SB_HORZ/SB_VERT.
1631  */
1632 BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar, 
1633                              BOOL fShowH, BOOL fShowV )
1634 {
1635     WND *wndPtr = WIN_FindWndPtr( hwnd );
1636     BOOL retvalue = FALSE;
1637
1638     if (!wndPtr) return FALSE;
1639     TRACE("hwnd=%04x bar=%d horz=%d, vert=%d\n",
1640                     hwnd, nBar, fShowH, fShowV );
1641
1642     switch(nBar)
1643     {
1644     case SB_CTL:
1645         ShowWindow( hwnd, fShowH ? SW_SHOW : SW_HIDE );
1646         retvalue = TRUE;
1647         goto END;
1648
1649     case SB_BOTH:
1650     case SB_HORZ:
1651         if (fShowH)
1652         {
1653             fShowH = !(wndPtr->dwStyle & WS_HSCROLL);
1654             wndPtr->dwStyle |= WS_HSCROLL;
1655         }
1656         else  /* hide it */
1657         {
1658             fShowH = (wndPtr->dwStyle & WS_HSCROLL);
1659             wndPtr->dwStyle &= ~WS_HSCROLL;
1660         }
1661         if( nBar == SB_HORZ ) {
1662             fShowV = FALSE;
1663             break;
1664         }
1665         /* fall through */
1666
1667     case SB_VERT:
1668         if (fShowV)
1669         {
1670             fShowV = !(wndPtr->dwStyle & WS_VSCROLL);
1671             wndPtr->dwStyle |= WS_VSCROLL;
1672         }
1673         else  /* hide it */
1674         {
1675             fShowV = (wndPtr->dwStyle & WS_VSCROLL);
1676             wndPtr->dwStyle &= ~WS_VSCROLL;
1677         }
1678         if ( nBar == SB_VERT )
1679            fShowH = FALSE;
1680         break;
1681
1682     default:
1683         retvalue = FALSE;  /* Nothing to do! */
1684         goto END;
1685     }
1686
1687     if( fShowH || fShowV ) /* frame has been changed, let the window redraw itself */
1688     {
1689         SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE
1690                     | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
1691         retvalue = TRUE;
1692         goto END;
1693     }
1694
1695     retvalue = FALSE; /* no frame changes */
1696 END:
1697     WIN_ReleaseWndPtr(wndPtr);
1698     return retvalue;
1699 }
1700
1701
1702 /*************************************************************************
1703  *           ShowScrollBar16   (USER.267)
1704  */
1705 void WINAPI ShowScrollBar16( HWND16 hwnd, INT16 nBar, BOOL16 fShow )
1706 {
1707     SCROLL_ShowScrollBar( hwnd, nBar, (nBar == SB_VERT) ? 0 : fShow,
1708                                       (nBar == SB_HORZ) ? 0 : fShow );
1709 }
1710
1711
1712 /*************************************************************************
1713  *           ShowScrollBar32   (USER32.532)
1714  *
1715  * RETURNS STD
1716  */
1717 BOOL WINAPI ShowScrollBar(
1718 HWND hwnd, /* [I] Handle of window whose scrollbar(s) will be affected   */
1719 INT nBar, /* [I] One of SB_HORZ, SB_VERT, SB_BOTH or SB_CTL */
1720 BOOL fShow /* [I] TRUE = show, FALSE = hide  */)
1721 {
1722     SCROLL_ShowScrollBar( hwnd, nBar, (nBar == SB_VERT) ? 0 : fShow,
1723                                       (nBar == SB_HORZ) ? 0 : fShow );
1724     return TRUE;
1725 }
1726
1727
1728 /*************************************************************************
1729  *           EnableScrollBar16   (USER.482)
1730  */
1731 BOOL16 WINAPI EnableScrollBar16( HWND16 hwnd, INT16 nBar, UINT16 flags )
1732 {
1733     return EnableScrollBar( hwnd, nBar, flags );
1734 }
1735
1736
1737 /*************************************************************************
1738  *           EnableScrollBar32   (USER32.171)
1739  */
1740 BOOL WINAPI EnableScrollBar( HWND hwnd, INT nBar, UINT flags )
1741 {
1742     BOOL bFineWithMe;
1743     SCROLLBAR_INFO *infoPtr;
1744
1745     TRACE("%04x %d %d\n", hwnd, nBar, flags );
1746
1747     flags &= ESB_DISABLE_BOTH;
1748
1749     if (nBar == SB_BOTH)
1750     {
1751         if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, SB_VERT ))) return FALSE;
1752         if (!(bFineWithMe = (infoPtr->flags == flags)) )
1753         {
1754             infoPtr->flags = flags;
1755             SCROLL_RefreshScrollBar( hwnd, SB_VERT, TRUE, TRUE );
1756         }
1757         nBar = SB_HORZ;
1758     }
1759     else
1760         bFineWithMe = TRUE;
1761    
1762     if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar ))) return FALSE;
1763     if (bFineWithMe && infoPtr->flags == flags) return FALSE;
1764     infoPtr->flags = flags;
1765
1766     SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );
1767     return TRUE;
1768 }