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

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

EndDialog fix

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