source: trunk/src/user32/scroll.cpp@ 6040

Last change on this file since 6040 was 6040, checked in by sandervl, 24 years ago

WS_VISIBLE flag change allowed in SetWindowLong; scrollbar fix for sizebox/grip style

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