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

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

reference count (window + class objects) rewrite

File size: 51.0 KB
Line 
1/* $Id: scroll.cpp,v 1.39 2001-06-09 14:50:19 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 if (!(lpCreat->style & (SBS_SIZEBOX | SBS_SIZEGRIP)) && (lpCreat->style & (SBS_LEFTALIGN | SBS_RIGHTALIGN)))
673 {
674 if (lpCreat->style & SBS_VERT)
675 {
676 INT w,h;
677
678 w = GetSystemMetrics(SM_CXVSCROLL);
679 h = lpCreat->cy;
680
681 if (lpCreat->style & SBS_LEFTALIGN)
682 MoveWindow(hwnd,lpCreat->x,lpCreat->y,w,h,FALSE);
683 else if (lpCreat->style & SBS_RIGHTALIGN)
684 MoveWindow(hwnd,lpCreat->x+lpCreat->cx-w,lpCreat->y,w,h,FALSE);
685 } else /* SBS_HORZ */
686 {
687 INT w,h;
688
689 w = lpCreat->cx;
690 h = GetSystemMetrics(SM_CYHSCROLL);
691
692 if (lpCreat->style & SBS_TOPALIGN)
693 MoveWindow(hwnd,lpCreat->x,lpCreat->y,w,h,FALSE);
694 else if (lpCreat->style & SBS_BOTTOMALIGN)
695 MoveWindow(hwnd,lpCreat->x,lpCreat->y+lpCreat->cy-h,w,h,FALSE);
696 }
697 }
698
699 return 0;
700}
701
702static LRESULT SCROLL_Destroy(HWND hwnd,WPARAM wParam,LPARAM lParam)
703{
704 SCROLLBAR_INFO* infoPtr = (SCROLLBAR_INFO*)GetInfoPtr(hwnd);
705
706 free(infoPtr);
707
708 return 0;
709}
710
711/***********************************************************************
712 * SCROLL_HandleScrollEvent
713 *
714 * Handle a mouse or timer event for the scrollbar.
715 * 'pt' is the location of the mouse event in client (for SB_CTL) or
716 * windows coordinates.
717 */
718LRESULT SCROLL_HandleScrollEvent(HWND hwnd,WPARAM wParam,LPARAM lParam,INT nBar,UINT msg)
719{
720 static POINT prevPt; /* Previous mouse position for timer events */
721 static UINT trackThumbPos; /* Thumb position when tracking started. */
722 static BOOL thumbTrackSent;
723 static INT lastClickPos; /* Position in the scroll-bar of the last button-down event. */
724 static INT lastMousePos; /* Position in the scroll-bar of the last mouse event. */
725 static BOOL timerRunning;
726
727 enum SCROLL_HITTEST hittest;
728 HWND hwndOwner, hwndCtl;
729 BOOL vertical;
730 INT arrowSize, thumbSize, thumbPos;
731 RECT rect;
732 HDC hdc;
733 POINT pt;
734 LRESULT res = 0;
735
736 SCROLLBAR_INFO *infoPtr = SCROLL_GetInfoPtr(hwnd,nBar);
737 if (!infoPtr) return res;
738
739 if (nBar == SB_CTL)
740 {
741 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
742
743 if ((dwStyle & (SBS_SIZEBOX | SBS_SIZEGRIP)))
744 {
745 if (!(dwStyle & SBS_SIZEGRIP)) return res;
746
747 if (msg == WM_NCHITTEST)
748 {
749 if (dwStyle & SBS_SIZEGRIP)
750 {
751 RECT rect;
752
753 pt.x = (SHORT)LOWORD(lParam);
754 pt.y = (SHORT)HIWORD(lParam);
755 ScreenToClient(hwnd,&pt);
756 SCROLL_GetSizeBox(hwnd,dwStyle,&rect);
757 if (PtInRect(&rect,pt))
758 {
759 if (dwStyle & SBS_SIZEBOXTOPLEFTALIGN)
760 return HTTOPLEFT;
761 else
762 return HTBOTTOMRIGHT;
763 }
764 }
765 return DefWindowProcA(hwnd,WM_NCHITTEST,wParam,lParam);
766 } else if (msg == WM_LBUTTONDOWN)
767 {
768 return DefWindowProcA(hwnd,WM_LBUTTONDOWN,wParam,lParam);
769 }
770
771 return res;
772 }
773 }
774
775 if (msg == WM_NCHITTEST) return DefWindowProcA(hwnd,WM_NCHITTEST,wParam,lParam);
776
777 vertical = SCROLL_GetScrollBarRect(hwnd,nBar,&rect,&arrowSize,&thumbSize,&thumbPos);
778 hwndOwner = (nBar == SB_CTL) ? GetParent(hwnd):hwnd;
779
780 hwndCtl = (nBar == SB_CTL) ? hwnd:0;
781
782 switch (msg)
783 {
784 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
785 pt.x = (SHORT)LOWORD(lParam);
786 pt.y = (SHORT)HIWORD(lParam);
787 SCROLL_trackVertical = vertical;
788 SCROLL_trackHitTest = hittest = SCROLL_HitTest(hwnd,nBar,pt,FALSE);
789 if (SCROLL_trackHitTest == SCROLL_NOWHERE)
790 {
791 MessageBeep(MB_ICONEXCLAMATION);
792
793 return res;
794 }
795 SCROLL_Scrolling = TRUE;
796 timerRunning = FALSE;
797 if ((SCROLL_FocusWin == hwnd) && SCROLL_Highlighted)
798 {
799 hdc = GetDCEx(hwnd,0,DCX_CACHE | ((nBar == SB_CTL) ? 0:DCX_WINDOW));
800 SCROLL_DrawScrollBar(hwnd,hdc,nBar,FALSE,TRUE);
801 ReleaseDC(hwnd,hdc);
802 }
803 lastClickPos = vertical ? pt.y:pt.x;
804 lastMousePos = lastClickPos;
805 trackThumbPos = thumbPos;
806 prevPt = pt;
807 if (nBar == SB_CTL) SetFocus(hwnd);
808 SetCapture(hwnd);
809 break;
810
811 case WM_MOUSEMOVE:
812 if (SCROLL_Scrolling)
813 {
814 pt.x = (SHORT)LOWORD(lParam);
815 pt.y = (SHORT)HIWORD(lParam);
816 hittest = SCROLL_HitTest(hwnd,nBar,pt,TRUE);
817 prevPt = pt;
818 } else return res;
819 break;
820
821 case WM_LBUTTONUP:
822 if (SCROLL_Scrolling)
823 {
824 pt.x = (SHORT)LOWORD(lParam);
825 pt.y = (SHORT)HIWORD(lParam);
826 hittest = SCROLL_NOWHERE;
827 ReleaseCapture();
828 SCROLL_Scrolling = FALSE;
829 } else return res;
830 break;
831
832 case WM_CAPTURECHANGED:
833 if (SCROLL_Scrolling)
834 {
835 hittest = SCROLL_NOWHERE;
836 SCROLL_Scrolling = FALSE;
837 } else return res;
838 break;
839
840 case WM_SETFOCUS:
841 if (nBar == SB_CTL)
842 {
843 SCROLL_FocusWin = hwnd;
844 SCROLL_HasFocus = TRUE;
845 SCROLL_Highlighted = FALSE;
846 SetSystemTimer(hwnd,BLINK_TIMER,SCROLL_BLINK_DELAY,(TIMERPROC)0);
847 }
848 return res;
849
850 case WM_KILLFOCUS:
851 if (SCROLL_FocusWin == hwnd)
852 {
853 SCROLL_FocusWin = 0;
854 SCROLL_HasFocus = FALSE;
855 if (SCROLL_Highlighted)
856 {
857 SCROLL_Highlighted = FALSE;
858 hdc = GetDCEx(hwnd,0,DCX_CACHE | ((nBar == SB_CTL) ? 0:DCX_WINDOW));
859 SCROLL_DrawScrollBar(hwnd,hdc,nBar,FALSE,TRUE);
860 ReleaseDC(hwnd,hdc);
861 }
862 KillSystemTimer(hwnd,BLINK_TIMER);
863 }
864 return res;
865
866 case WM_SYSTIMER:
867 if (wParam == SCROLL_TIMER)
868 {
869 pt = prevPt;
870 hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE );
871 break;
872 } else if (wParam == BLINK_TIMER)
873 {
874 SCROLL_Highlighted = ~SCROLL_Highlighted;
875 if (!SCROLL_Scrolling)
876 {
877 hdc = GetDCEx(hwnd,0,DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW));
878 SCROLL_DrawScrollBar(hwnd,hdc,nBar,FALSE,TRUE);
879 ReleaseDC(hwnd,hdc);
880 }
881 return res;
882 } else return res;
883
884 default:
885 return res; /* Should never happen */
886 }
887
888 hdc = GetDCEx(hwnd,0,DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW));
889
890 switch(SCROLL_trackHitTest)
891 {
892 case SCROLL_NOWHERE: /* No tracking in progress */
893 break;
894
895 case SCROLL_TOP_ARROW:
896 if ((msg == WM_LBUTTONUP) || (msg == WM_CAPTURECHANGED))
897 KillSystemTimer(hwnd,SCROLL_TIMER);
898 else if ((msg == WM_LBUTTONDOWN) || (!timerRunning && msg == WM_SYSTIMER))
899 {
900 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
901 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
902 (TIMERPROC)0 );
903 if (msg != WM_LBUTTONDOWN) timerRunning = TRUE;
904 }
905
906 if ((msg == WM_LBUTTONDOWN) || (SCROLL_lastHitTest != hittest))
907 {
908 SCROLL_DrawTopArrow(hdc,infoPtr,&rect,arrowSize,vertical,(hittest == SCROLL_trackHitTest));
909 SCROLL_lastHitTest = hittest;
910 }
911 if ((hittest == SCROLL_trackHitTest) && ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER)))
912 SendMessageA(hwndOwner,vertical ? WM_VSCROLL:WM_HSCROLL,SB_LINEUP,hwndCtl);
913
914 break;
915
916 case SCROLL_TOP_RECT:
917 if ((msg == WM_LBUTTONUP) || (msg == WM_CAPTURECHANGED))
918 KillSystemTimer(hwnd,SCROLL_TIMER);
919 else if ((msg == WM_LBUTTONDOWN) || (!timerRunning && (msg == WM_SYSTIMER)))
920 {
921 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
922 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
923 (TIMERPROC)0 );
924 if (msg != WM_LBUTTONDOWN) timerRunning = TRUE;
925 }
926
927 if ((msg == WM_LBUTTONDOWN) || (SCROLL_lastHitTest != hittest))
928 {
929 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
930 thumbPos, infoPtr->flags, vertical,
931 (hittest == SCROLL_trackHitTest), FALSE );
932 SCROLL_lastHitTest = hittest;
933 }
934
935 if ((hittest == SCROLL_trackHitTest) && ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER)))
936 SendMessageA(hwndOwner,vertical ? WM_VSCROLL:WM_HSCROLL,SB_PAGEUP,hwndCtl);
937
938 break;
939
940 case SCROLL_THUMB:
941 if (msg == WM_LBUTTONDOWN)
942 {
943 SCROLL_TrackingWin = hwnd;
944 SCROLL_TrackingBar = nBar;
945 SCROLL_TrackingPos = trackThumbPos + lastMousePos - lastClickPos;
946 SCROLL_TrackingVal = infoPtr->CurVal;
947 SCROLL_MovingThumb = TRUE;
948 thumbTrackSent = FALSE;
949 SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize);
950 } else if ((msg == WM_LBUTTONUP) || (msg == WM_CAPTURECHANGED))
951 {
952 UINT val;
953 INT oldPos = infoPtr->CurVal;
954
955 SCROLL_MovingThumb = FALSE;
956 SCROLL_TrackingWin = 0;
957 SCROLL_trackHitTest = SCROLL_NOWHERE; /* Terminate tracking */
958 val = SCROLL_GetThumbVal( infoPtr, &rect, vertical,
959 trackThumbPos + lastMousePos - lastClickPos );
960
961 if ((val != infoPtr->CurVal) || thumbTrackSent)
962 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
963 MAKEWPARAM( SB_THUMBPOSITION, val ), hwndCtl );
964
965 if (oldPos == infoPtr->CurVal)
966 {
967 vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect,
968 &arrowSize, &thumbSize, &thumbPos );
969 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
970 thumbPos, infoPtr->flags, vertical,
971 FALSE, FALSE );
972 }
973
974 ReleaseDC(hwnd,hdc);
975 return res;
976 } else if (msg == WM_MOUSEMOVE)
977 {
978 UINT pos;
979
980 if (!SCROLL_PtInRectEx( &rect, pt, vertical )) pos = lastClickPos;
981 else
982 {
983 pt = SCROLL_ClipPos( &rect, pt );
984 pos = vertical ? pt.y:pt.x;
985 }
986 if (pos != lastMousePos)
987 {
988 lastMousePos = pos;
989 SCROLL_TrackingPos = trackThumbPos + pos - lastClickPos;
990 SCROLL_TrackingVal = SCROLL_GetThumbVal( infoPtr, &rect,
991 vertical,
992 SCROLL_TrackingPos );
993 SCROLL_DrawMovingThumb( hdc, &rect, vertical,
994 arrowSize, thumbSize );
995 SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
996 MAKEWPARAM( SB_THUMBTRACK, SCROLL_TrackingVal),
997 hwndCtl );
998 thumbTrackSent = TRUE;
999 }
1000 }
1001 break;
1002
1003 case SCROLL_BOTTOM_RECT:
1004 if ((msg == WM_LBUTTONUP) || (msg == WM_CAPTURECHANGED))
1005 KillSystemTimer(hwnd,SCROLL_TIMER);
1006 else if ((msg == WM_LBUTTONDOWN) || (!timerRunning && (msg == WM_SYSTIMER)))
1007 {
1008 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1009 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
1010 (TIMERPROC)0 );
1011 if (msg != WM_LBUTTONDOWN) timerRunning = TRUE;
1012 }
1013
1014 if ((msg == WM_LBUTTONDOWN) || (SCROLL_lastHitTest != hittest))
1015 {
1016 SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize,
1017 thumbPos, infoPtr->flags, vertical,
1018 FALSE, (hittest == SCROLL_trackHitTest) );
1019 SCROLL_lastHitTest = hittest;
1020 }
1021
1022 if ((hittest == SCROLL_trackHitTest) && ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER)))
1023 SendMessageA(hwndOwner,vertical ? WM_VSCROLL:WM_HSCROLL,SB_PAGEDOWN,hwndCtl);
1024
1025 break;
1026
1027 case SCROLL_BOTTOM_ARROW:
1028 if ((msg == WM_LBUTTONUP) || (msg == WM_CAPTURECHANGED))
1029 KillSystemTimer(hwnd,SCROLL_TIMER);
1030 else if ((msg == WM_LBUTTONDOWN) || (!timerRunning && (msg == WM_SYSTIMER)))
1031 {
1032 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
1033 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY,
1034 (TIMERPROC)0 );
1035 if (msg != WM_LBUTTONDOWN) timerRunning = TRUE;
1036 }
1037
1038 if ((msg == WM_LBUTTONDOWN) || (SCROLL_lastHitTest != hittest))
1039 {
1040 SCROLL_DrawBottomArrow(hdc,infoPtr,&rect,arrowSize,vertical,(hittest == SCROLL_trackHitTest));
1041 SCROLL_lastHitTest = hittest;
1042 }
1043 if ((hittest == SCROLL_trackHitTest) && ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER)))
1044 SendMessageA(hwndOwner,vertical ? WM_VSCROLL:WM_HSCROLL,SB_LINEDOWN,hwndCtl);
1045
1046 break;
1047 }
1048
1049 if ((msg == WM_LBUTTONUP) || (msg == WM_CAPTURECHANGED))
1050 {
1051 SCROLL_trackHitTest = SCROLL_NOWHERE; /* Terminate tracking */
1052
1053 SendMessageA(hwndOwner,vertical ? WM_VSCROLL:WM_HSCROLL,SB_ENDSCROLL,hwndCtl);
1054 }
1055
1056 ReleaseDC( hwnd, hdc );
1057
1058 return res;
1059}
1060
1061/***********************************************************************
1062 * SCROLL_HandleKbdEvent
1063 *
1064 * Handle a keyboard event (only for SB_CTL scrollbars).
1065 */
1066LRESULT SCROLL_KeyDown(HWND hwnd,WPARAM wParam,LPARAM lParam)
1067{
1068 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
1069 UINT msg;
1070
1071 if (dwStyle & (SBS_SIZEBOX | SBS_SIZEGRIP)) return 0;
1072
1073 switch(wParam)
1074 {
1075 case VK_PRIOR: msg = SB_PAGEUP; break;
1076 case VK_NEXT: msg = SB_PAGEDOWN; break;
1077 case VK_HOME: msg = SB_TOP; break;
1078 case VK_END: msg = SB_BOTTOM; break;
1079 case VK_UP: msg = SB_LINEUP; break;
1080 case VK_DOWN: msg = SB_LINEDOWN; break;
1081 default:
1082 return 0;
1083 }
1084 SendMessageA( GetParent(hwnd),
1085 (dwStyle & SBS_VERT) ? WM_VSCROLL : WM_HSCROLL,
1086 msg, hwnd );
1087
1088 return 0;
1089}
1090
1091LRESULT SCROLL_Paint(HWND hwnd,WPARAM wParam,LPARAM lParam,INT nBar)
1092{
1093 PAINTSTRUCT ps;
1094 HDC hdc = wParam ? (HDC)wParam:BeginPaint( hwnd, &ps );
1095
1096 SCROLL_DrawScrollBar( hwnd, hdc, nBar, TRUE, TRUE );
1097 if (!wParam) EndPaint( hwnd, &ps );
1098
1099 return 0;
1100}
1101
1102LRESULT SCROLL_SetRange(HWND hwnd,WPARAM wParam,LPARAM lParam,INT nBar,BOOL redraw)
1103{
1104 SCROLLBAR_INFO *infoPtr = SCROLL_GetInfoPtr(hwnd,nBar);
1105 INT oldPos = infoPtr->CurVal;
1106
1107 SetScrollRange(hwnd,nBar,wParam,lParam,redraw);
1108 return (oldPos != infoPtr->CurVal) ? infoPtr->CurVal:0;
1109}
1110
1111/* Window Procedures */
1112
1113/***********************************************************************
1114 * ScrollBarWndProc
1115 */
1116LRESULT WINAPI ScrollBarWndProc( HWND hwnd, UINT message, WPARAM wParam,
1117 LPARAM lParam )
1118{
1119 switch(message)
1120 {
1121 case WM_NCCREATE:
1122 return SCROLL_NCCreate(hwnd,wParam,lParam);
1123
1124 case WM_CREATE:
1125 return SCROLL_Create(hwnd,wParam,lParam);
1126
1127 case WM_DESTROY:
1128 return SCROLL_Destroy(hwnd,wParam,lParam);
1129
1130 case WM_LBUTTONDOWN:
1131 case WM_LBUTTONUP:
1132 case WM_NCHITTEST:
1133 case WM_CAPTURECHANGED:
1134 case WM_MOUSEMOVE:
1135 case WM_SYSTIMER:
1136 case WM_SETFOCUS:
1137 case WM_KILLFOCUS:
1138 return SCROLL_HandleScrollEvent(hwnd,wParam,lParam,SB_CTL,message);
1139
1140 case WM_KEYDOWN:
1141 return SCROLL_KeyDown(hwnd,wParam,lParam);
1142
1143 case WM_ERASEBKGND:
1144 return 1;
1145
1146 case WM_GETDLGCODE:
1147 return DLGC_WANTARROWS; /* Windows returns this value */
1148
1149 case WM_PAINT:
1150 return SCROLL_Paint(hwnd,wParam,lParam,SB_CTL);
1151
1152 case SBM_SETPOS:
1153 return SetScrollPos( hwnd, SB_CTL, wParam, (BOOL)lParam );
1154
1155 case SBM_GETPOS:
1156 return GetScrollPos( hwnd, SB_CTL );
1157
1158 case SBM_SETRANGE:
1159 return SCROLL_SetRange(hwnd,wParam,lParam,SB_CTL,FALSE);
1160
1161 case SBM_GETRANGE:
1162 GetScrollRange( hwnd, SB_CTL, (LPINT)wParam, (LPINT)lParam );
1163 return 0;
1164
1165 case SBM_ENABLE_ARROWS:
1166 return EnableScrollBar( hwnd, SB_CTL, wParam );
1167
1168 case SBM_SETRANGEREDRAW:
1169 return SCROLL_SetRange(hwnd,wParam,lParam,SB_CTL,TRUE);
1170
1171 case SBM_SETSCROLLINFO:
1172 return SetScrollInfo(hwnd,SB_CTL,(SCROLLINFO*)lParam,wParam);
1173
1174 case SBM_GETSCROLLINFO:
1175 return GetScrollInfo( hwnd, SB_CTL, (SCROLLINFO *)lParam );
1176
1177 case 0x00e5:
1178 case 0x00e7:
1179 case 0x00e8:
1180 case 0x00eb:
1181 case 0x00ec:
1182 case 0x00ed:
1183 case 0x00ee:
1184 case 0x00ef:
1185 //ERR("unknown Win32 msg %04x wp=%08x lp=%08lx\n",
1186 // message, wParam, lParam );
1187 break;
1188
1189 default:
1190 return DefWindowProcA( hwnd, message, wParam, lParam );
1191 }
1192
1193 return 0;
1194}
1195
1196/* Scrollbar API */
1197
1198/*************************************************************************
1199 * SetScrollInfo (USER32.501)
1200 * SetScrollInfo32 can be used to set the position, upper bound,
1201 * lower bound, and page size of a scrollbar control.
1202 *
1203 * RETURNS
1204 * Scrollbar position
1205 *
1206 * NOTE
1207 * For 100 lines of text to be displayed in a window of 25 lines,
1208 * one would for instance use info->nMin=0, info->nMax=75
1209 * (corresponding to the 76 different positions of the window on
1210 * the text), and info->nPage=25.
1211 */
1212INT WINAPI SetScrollInfo(HWND hwnd,INT nBar,const SCROLLINFO *info,BOOL bRedraw)
1213{
1214 /* Update the scrollbar state and set action flags according to
1215 * what has to be done graphics wise. */
1216
1217 SCROLLBAR_INFO *infoPtr;
1218 UINT new_flags;
1219 INT action = 0;
1220 BOOL bChangeParams = FALSE; /* don't show/hide scrollbar if params don't change */
1221
1222 dprintf(("USER32: SetScrollInfo %x %d",hwnd,nBar));
1223
1224 if (!(infoPtr = SCROLL_GetInfoPtr(hwnd,nBar))) return 0;
1225 if (info->fMask & ~(SIF_ALL | SIF_DISABLENOSCROLL)) return 0;
1226 if ((info->cbSize != sizeof(*info)) &&
1227 (info->cbSize != sizeof(*info)-sizeof(info->nTrackPos))) return 0;
1228
1229 /* Set the page size */
1230 if (info->fMask & SIF_PAGE)
1231 {
1232 if( infoPtr->Page != info->nPage )
1233 {
1234 infoPtr->Page = info->nPage;
1235 action |= SA_SSI_REPAINT_INTERIOR;
1236 bChangeParams = TRUE;
1237 }
1238 }
1239
1240 /* Set the scroll pos */
1241 if (info->fMask & SIF_POS)
1242 {
1243 //dsprintf(scroll, " pos=%d", info->nPos );
1244 if( infoPtr->CurVal != info->nPos )
1245 {
1246 infoPtr->CurVal = info->nPos;
1247 action |= SA_SSI_MOVE_THUMB;
1248 }
1249 }
1250
1251 /* Set the scroll range */
1252 if (info->fMask & SIF_RANGE)
1253 {
1254 /* Invalid range -> range is set to (0,0) */
1255 if ((info->nMin > info->nMax) ||
1256 ((UINT)(info->nMax - info->nMin) >= 0x80000000))
1257 {
1258 infoPtr->MinVal = 0;
1259 infoPtr->MaxVal = 0;
1260 bChangeParams = TRUE;
1261 }
1262 else
1263 {
1264 if( infoPtr->MinVal != info->nMin ||
1265 infoPtr->MaxVal != info->nMax )
1266 {
1267 action |= SA_SSI_REPAINT_INTERIOR;
1268 infoPtr->MinVal = info->nMin;
1269 infoPtr->MaxVal = info->nMax;
1270 bChangeParams = TRUE;
1271 }
1272 }
1273 }
1274
1275 /* Make sure the page size is valid */
1276
1277 if (infoPtr->Page < 0) infoPtr->Page = 0;
1278 else if (infoPtr->Page > infoPtr->MaxVal - infoPtr->MinVal + 1 )
1279 infoPtr->Page = infoPtr->MaxVal - infoPtr->MinVal + 1;
1280
1281 /* Make sure the pos is inside the range */
1282
1283 if (infoPtr->CurVal < infoPtr->MinVal)
1284 infoPtr->CurVal = infoPtr->MinVal;
1285 else if (infoPtr->CurVal > infoPtr->MaxVal - MAX( infoPtr->Page-1, 0 ))
1286 infoPtr->CurVal = infoPtr->MaxVal - MAX( infoPtr->Page-1, 0 );
1287
1288 //TRACE(" new values: page=%d pos=%d min=%d max=%d\n",
1289 // infoPtr->Page, infoPtr->CurVal,
1290 // infoPtr->MinVal, infoPtr->MaxVal );
1291
1292 /* don't change the scrollbar state if SetScrollInfo
1293 * is just called with SIF_DISABLENOSCROLL
1294 */
1295 if(!(info->fMask & SIF_ALL)) goto done;
1296
1297 /* Check if the scrollbar should be hidden or disabled */
1298 if (info->fMask & (SIF_RANGE | SIF_PAGE | SIF_DISABLENOSCROLL))
1299 {
1300 new_flags = infoPtr->flags;
1301 if (infoPtr->MinVal >= infoPtr->MaxVal - MAX( infoPtr->Page-1, 0 ))
1302 {
1303 /* Hide or disable scroll-bar */
1304 if (info->fMask & SIF_DISABLENOSCROLL)
1305 {
1306 new_flags = ESB_DISABLE_BOTH;
1307 action |= SA_SSI_REFRESH;
1308 }
1309 else
1310 if (nBar != SB_CTL && bChangeParams)
1311 {
1312 action = SA_SSI_HIDE;
1313 infoPtr->flags = 0;
1314 goto done;
1315 }
1316 }
1317 else /* Show and enable scroll-bar */
1318 {
1319 new_flags = 0;
1320 if (nBar != SB_CTL && bChangeParams) action |= SA_SSI_SHOW;
1321 if (infoPtr->flags) action |= SA_SSI_REFRESH;
1322 }
1323
1324 if (infoPtr->flags != new_flags) /* check arrow flags */
1325 {
1326 infoPtr->flags = new_flags;
1327 action |= SA_SSI_REPAINT_ARROWS;
1328 }
1329 }
1330
1331done:
1332 /* Update scrollbar */
1333
1334 if( action & SA_SSI_HIDE )
1335 ShowScrollBar(hwnd,nBar,FALSE);
1336 else
1337 {
1338 if(action & SA_SSI_SHOW)
1339 ShowScrollBar(hwnd,nBar,TRUE);
1340
1341 if (bRedraw)
1342 {
1343 if (action & SA_SSI_REFRESH)
1344 SCROLL_RefreshScrollBar(hwnd,nBar,TRUE,TRUE);
1345 else
1346 {
1347 if (action & (SA_SSI_REPAINT_INTERIOR | SA_SSI_MOVE_THUMB))
1348 SCROLL_RefreshScrollBar(hwnd,nBar,FALSE,TRUE);
1349 if (action & SA_SSI_REPAINT_ARROWS)
1350 SCROLL_RefreshScrollBar(hwnd,nBar,TRUE,FALSE);
1351 }
1352 }
1353 }
1354
1355 /* Return current position */
1356
1357 return infoPtr->CurVal;
1358}
1359/*************************************************************************
1360 * GetScrollInfo (USER32.284)
1361 * GetScrollInfo32 can be used to retrieve the position, upper bound,
1362 * lower bound, and page size of a scrollbar control.
1363 *
1364 * RETURNS STD
1365 */
1366BOOL WINAPI GetScrollInfo(
1367 HWND hwnd /* [I] Handle of window */ ,
1368 INT nBar /* [I] One of SB_HORZ, SB_VERT, or SB_CTL */,
1369 LPSCROLLINFO info /* [IO] (info.fMask [I] specifies which values are to retrieve) */)
1370{
1371 SCROLLBAR_INFO *infoPtr;
1372
1373 dprintf(("USER32: GetScrollInfo"));
1374
1375 if (!(infoPtr = SCROLL_GetInfoPtr(hwnd,nBar))) return FALSE;
1376 if (info->fMask & ~(SIF_ALL | SIF_DISABLENOSCROLL)) return FALSE;
1377 if ((info->cbSize != sizeof(*info)) &&
1378 (info->cbSize != sizeof(*info)-sizeof(info->nTrackPos))) return FALSE;
1379
1380 if (info->fMask & SIF_PAGE) info->nPage = infoPtr->Page;
1381 if (info->fMask & SIF_POS) info->nPos = infoPtr->CurVal;
1382 if ((info->fMask & SIF_TRACKPOS) && (info->cbSize == sizeof(*info)))
1383 info->nTrackPos = (SCROLL_MovingThumb && SCROLL_TrackingWin == hwnd && SCROLL_TrackingBar == nBar) ? SCROLL_TrackingVal:infoPtr->CurVal;
1384
1385 if (info->fMask & SIF_RANGE)
1386 {
1387 info->nMin = infoPtr->MinVal;
1388 info->nMax = infoPtr->MaxVal;
1389 }
1390 return (info->fMask & SIF_ALL) != 0;
1391}
1392/*************************************************************************
1393 * SetScrollPos (USER32.502)
1394 *
1395 * RETURNS
1396 * Success: Scrollbar position
1397 * Failure: 0
1398 *
1399 * REMARKS
1400 * Note the ambiguity when 0 is returned. Use GetLastError
1401 * to make sure there was an error (and to know which one).
1402 */
1403INT WINAPI SetScrollPos(
1404 HWND hwnd /* [I] Handle of window whose scrollbar will be affected */,
1405 INT nBar /* [I] One of SB_HORZ, SB_VERT, or SB_CTL */,
1406 INT nPos /* [I] New value */,
1407 BOOL bRedraw /* [I] Should scrollbar be redrawn afterwards ? */ )
1408{
1409 SCROLLINFO info;
1410 SCROLLBAR_INFO *infoPtr;
1411 INT oldPos;
1412
1413 dprintf(("SetScrollPos %x %d %d %d", hwnd, nBar, nPos, bRedraw));
1414 if (!(infoPtr = SCROLL_GetInfoPtr(hwnd,nBar))) return 0;
1415 oldPos = infoPtr->CurVal;
1416 info.cbSize = sizeof(info);
1417 info.nPos = nPos;
1418 info.fMask = SIF_POS;
1419 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1420 return oldPos;
1421}
1422/*************************************************************************
1423 * GetScrollPos (USER32.285)
1424 *
1425 * RETURNS
1426 * Success: Current position
1427 * Failure: 0
1428 *
1429 * REMARKS
1430 * Note the ambiguity when 0 is returned. Use GetLastError
1431 * to make sure there was an error (and to know which one).
1432 */
1433INT WINAPI GetScrollPos(
1434 HWND hwnd, /* [I] Handle of window */
1435 INT nBar /* [I] One of SB_HORZ, SB_VERT, or SB_CTL */)
1436{
1437 SCROLLBAR_INFO *infoPtr;
1438
1439 dprintf(("GetScrollPos %x %d", hwnd, nBar));
1440
1441 infoPtr = SCROLL_GetInfoPtr(hwnd,nBar);
1442 if (!infoPtr) return 0;
1443
1444 return infoPtr->CurVal;
1445}
1446
1447/*************************************************************************
1448 * SetScrollRange (USER32.503)
1449 *
1450 * RETURNS STD
1451 */
1452BOOL WINAPI SetScrollRange(
1453 HWND hwnd, /* [I] Handle of window whose scrollbar will be affected */
1454 INT nBar, /* [I] One of SB_HORZ, SB_VERT, or SB_CTL */
1455 INT MinVal, /* [I] New minimum value */
1456 INT MaxVal, /* [I] New maximum value */
1457 BOOL bRedraw /* [I] Should scrollbar be redrawn afterwards ? */)
1458{
1459 SCROLLINFO info;
1460
1461 dprintf(("SetScrollRange %x %x %d %d %d", hwnd, nBar, MinVal, MaxVal, bRedraw));
1462 info.cbSize = sizeof(info);
1463 info.nMin = MinVal;
1464 info.nMax = MaxVal;
1465 info.fMask = SIF_RANGE;
1466 SetScrollInfo( hwnd, nBar, &info, bRedraw );
1467 return TRUE;
1468}
1469
1470/*************************************************************************
1471 * GetScrollRange (USER32.286)
1472 *
1473 * RETURNS STD
1474 */
1475BOOL WINAPI GetScrollRange(
1476 HWND hwnd, /* [I] Handle of window */
1477 INT nBar, /* [I] One of SB_HORZ, SB_VERT, or SB_CTL */
1478 LPINT lpMin, /* [O] Where to store minimum value */
1479 LPINT lpMax /* [O] Where to store maximum value */)
1480{
1481 SCROLLBAR_INFO *infoPtr;
1482
1483 infoPtr = SCROLL_GetInfoPtr(hwnd,nBar);
1484 if (!infoPtr)
1485 {
1486 if (lpMin) lpMin = 0;
1487 if (lpMax) lpMax = 0;
1488 return FALSE;
1489 }
1490 if (lpMin) *lpMin = infoPtr->MinVal;
1491 if (lpMax) *lpMax = infoPtr->MaxVal;
1492 return TRUE;
1493}
1494
1495/*************************************************************************
1496 * ShowScrollBar (USER32.532)
1497 *
1498 * RETURNS STD
1499 */
1500BOOL WINAPI ShowScrollBar(
1501 HWND hwnd, /* [I] Handle of window whose scrollbar(s) will be affected */
1502 INT nBar, /* [I] One of SB_HORZ, SB_VERT, SB_BOTH or SB_CTL */
1503 BOOL fShow /* [I] TRUE = show, FALSE = hide */)
1504{
1505 BOOL fShowH = (nBar == SB_HORZ) ? fShow : 0;
1506 BOOL fShowV = (nBar == SB_VERT) ? fShow : 0;
1507 DWORD dwStyle;
1508
1509 dprintf(("ShowScrollBar %04x %d %d\n", hwnd, nBar, fShow));
1510 if (!IsWindow(hwnd)) return FALSE;
1511
1512 dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
1513
1514 //CB: does Win32 send a WM_STYLECHANGED message?
1515 switch(nBar)
1516 {
1517 case SB_CTL:
1518 ShowWindow(hwnd,fShow ? SW_SHOW:SW_HIDE);
1519 return TRUE;
1520
1521 case SB_BOTH:
1522 case SB_HORZ:
1523 if (fShow)
1524 {
1525 fShowH = !(dwStyle & WS_HSCROLL);
1526 SetWindowLongA(hwnd, GWL_STYLE, dwStyle | WS_HSCROLL);
1527 }
1528 else /* hide it */
1529 {
1530 fShowH = (dwStyle & WS_HSCROLL);
1531 SetWindowLongA(hwnd, GWL_STYLE, dwStyle & ~WS_HSCROLL);
1532 }
1533 if( nBar == SB_HORZ )
1534 {
1535 fShowV = FALSE;
1536 break;
1537 }
1538 /* fall through */
1539
1540 case SB_VERT:
1541 if (fShow)
1542 {
1543 fShowV = !(dwStyle & WS_VSCROLL);
1544 SetWindowLongA(hwnd, GWL_STYLE, dwStyle | WS_VSCROLL);
1545 }
1546 else /* hide it */
1547 {
1548 fShowV = (dwStyle & WS_VSCROLL);
1549 SetWindowLongA(hwnd, GWL_STYLE, dwStyle & ~WS_VSCROLL);
1550 }
1551 if ( nBar == SB_VERT )
1552 fShowH = FALSE;
1553 break;
1554
1555 default:
1556 return TRUE; /* Nothing to do! */
1557 }
1558
1559 if( fShowH || fShowV ) /* frame has been changed, let the window redraw itself */
1560 {
1561 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE
1562 | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
1563 }
1564
1565 return TRUE;
1566}
1567
1568/*************************************************************************
1569 * EnableScrollBar (USER32.171)
1570 */
1571BOOL WINAPI EnableScrollBar( HWND hwnd, INT nBar, UINT flags)
1572{
1573 BOOL bFineWithMe;
1574 SCROLLBAR_INFO *infoPtr;
1575
1576 dprintf(("EnableScrollBar %04x %d %d\n", hwnd, nBar, flags));
1577
1578 flags &= ESB_DISABLE_BOTH;
1579
1580 if (nBar == SB_BOTH)
1581 {
1582 if (!(infoPtr = SCROLL_GetInfoPtr( hwnd, SB_VERT ))) return FALSE;
1583 if (!(bFineWithMe = (infoPtr->flags == flags)) )
1584 {
1585 infoPtr->flags = flags;
1586 SCROLL_RefreshScrollBar( hwnd, SB_VERT, TRUE, TRUE );
1587 }
1588 nBar = SB_HORZ;
1589 }
1590 else
1591 bFineWithMe = TRUE;
1592
1593 if (!(infoPtr = SCROLL_GetInfoPtr( hwnd, nBar ))) return FALSE;
1594 if (bFineWithMe && infoPtr->flags == flags) return FALSE;
1595 infoPtr->flags = flags;
1596
1597 SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE );
1598 return TRUE;
1599}
1600
1601//CB: not listed in user32.exp -> don't know the id!
1602
1603BOOL WINAPI GetScrollBarInfo(HWND hwnd,LONG idObject,PSCROLLBARINFO psbi)
1604{
1605 if (!psbi || (psbi->cbSize != sizeof(SCROLLBARINFO)))
1606 {
1607 SetLastError(ERROR_INVALID_PARAMETER);
1608
1609 return FALSE;
1610 }
1611
1612 INT nBar,arrowSize;
1613
1614 switch (idObject)
1615 {
1616 case OBJID_CLIENT:
1617 nBar = SB_CTL;
1618 break;
1619
1620 case OBJID_HSCROLL:
1621 nBar = SB_HORZ;
1622 break;
1623
1624 case OBJID_VSCROLL:
1625 nBar = SB_VERT;
1626 break;
1627
1628 default:
1629 return FALSE;
1630 }
1631
1632 SCROLL_GetScrollBarRect(hwnd,nBar,&psbi->rcScrollBar,&arrowSize,&psbi->dxyLineButton,&psbi->xyThumbTop);
1633 psbi->xyThumbBottom = psbi->xyThumbTop+psbi->dxyLineButton;
1634 psbi->bogus = 0; //CB: undocumented!
1635 psbi->rgstate[0] = IsWindowVisible(hwnd) ? STATE_SYSTEM_INVISIBLE:0;
1636 psbi->rgstate[1] = psbi->rgstate[2] = psbi->rgstate[3] = psbi->rgstate[4] = psbi->rgstate[5] = psbi->rgstate[0]; //CB: todo
1637
1638 return TRUE;
1639}
1640//******************************************************************************
1641//******************************************************************************
1642BOOL SCROLLBAR_Register()
1643{
1644 WNDCLASSA wndClass;
1645
1646//SvL: Don't check this now
1647// if (GlobalFindAtomA(SCROLLBARCLASSNAME)) return FALSE;
1648
1649 ZeroMemory(&wndClass,sizeof(WNDCLASSA));
1650 wndClass.style = CS_GLOBALCLASS | CS_HREDRAW | CS_VREDRAW | CS_PARENTDC;
1651 wndClass.lpfnWndProc = (WNDPROC)ScrollBarWndProc;
1652 wndClass.cbClsExtra = 0;
1653 wndClass.cbWndExtra = sizeof(SCROLLBAR_INFO);
1654 wndClass.hCursor = LoadCursorA(0,IDC_ARROWA);
1655 wndClass.hbrBackground = (HBRUSH)0;
1656 wndClass.lpszClassName = SCROLLBARCLASSNAME;
1657
1658 return RegisterClassA(&wndClass);
1659}
1660//******************************************************************************
1661//******************************************************************************
1662BOOL SCROLLBAR_Unregister()
1663{
1664 if (GlobalFindAtomA(SCROLLBARCLASSNAME))
1665 return UnregisterClassA(SCROLLBARCLASSNAME,(HINSTANCE)NULL);
1666 else return FALSE;
1667}
1668//******************************************************************************
1669//******************************************************************************
1670
Note: See TracBrowser for help on using the repository browser.