d23cd16531799b5499bdf8b9e1bb27cb06742e60
[reactos.git] / reactos / dll / win32 / uxtheme / ncscrollbar.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS uxtheme.dll
4 * FILE: dll/win32/uxtheme/ncscrollbar.c
5 * PURPOSE: uxtheme scrollbar support
6 * PROGRAMMER: Giannis Adamopoulos
7 * This file is heavily based on code from the wine project:
8 * Copyright 1993 Martin Ayotte
9 * Copyright 1994, 1996 Alexandre Julliard
10 */
11
12 #include "uxthemep.h"
13
14 #include <assert.h>
15
16 static BOOL SCROLL_trackVertical;
17 static enum SCROLL_HITTEST SCROLL_trackHitTest;
18 /* Is the moving thumb being displayed? */
19 static BOOL SCROLL_MovingThumb = FALSE;
20 static HWND SCROLL_TrackingWin = 0;
21 static INT SCROLL_TrackingBar = 0;
22 static INT SCROLL_TrackingPos = 0;
23 static INT SCROLL_TrackingVal = 0;
24
25 static void ScreenToWindow( HWND hWnd, POINT* pt)
26 {
27 RECT rcWnd;
28 GetWindowRect(hWnd, &rcWnd);
29 pt->x -= rcWnd.left;
30 pt->y -= rcWnd.top;
31 }
32
33 static BOOL SCROLL_IsVertical(HWND hwnd, INT nBar)
34 {
35 switch(nBar)
36 {
37 case SB_HORZ:
38 return FALSE;
39 case SB_VERT:
40 return TRUE;
41 default:
42 assert(FALSE);
43 return FALSE;
44 }
45 }
46
47 static LONG SCROLL_getObjectId(INT nBar)
48 {
49 switch(nBar)
50 {
51 case SB_HORZ:
52 return OBJID_HSCROLL;
53 case SB_VERT:
54 return OBJID_VSCROLL;
55 default:
56 assert(FALSE);
57 return 0;
58 }
59 }
60
61 /***********************************************************************
62 * SCROLL_PtInRectEx
63 */
64 static BOOL SCROLL_PtInRectEx( LPRECT lpRect, POINT pt, BOOL vertical )
65 {
66 RECT rect = *lpRect;
67 int scrollbarWidth;
68
69 /* Pad hit rect to allow mouse to be dragged outside of scrollbar and
70 * still be considered in the scrollbar. */
71 if (vertical)
72 {
73 scrollbarWidth = lpRect->right - lpRect->left;
74 rect.left -= scrollbarWidth*8;
75 rect.right += scrollbarWidth*8;
76 rect.top -= scrollbarWidth*2;
77 rect.bottom += scrollbarWidth*2;
78 }
79 else
80 {
81 scrollbarWidth = lpRect->bottom - lpRect->top;
82 rect.left -= scrollbarWidth*2;
83 rect.right += scrollbarWidth*2;
84 rect.top -= scrollbarWidth*8;
85 rect.bottom += scrollbarWidth*8;
86 }
87 return PtInRect( &rect, pt );
88 }
89
90
91 /***********************************************************************
92 * SCROLL_HitTest
93 *
94 * Scroll-bar hit testing (don't confuse this with WM_NCHITTEST!).
95 */
96 static enum SCROLL_HITTEST SCROLL_HitTest( HWND hwnd, SCROLLBARINFO* psbi, BOOL vertical,
97 POINT pt, BOOL bDragging )
98 {
99 if ( (bDragging && !SCROLL_PtInRectEx( &psbi->rcScrollBar, pt, vertical )) ||
100 (!PtInRect( &psbi->rcScrollBar, pt )) )
101 {
102 return SCROLL_NOWHERE;
103 }
104
105 if (vertical)
106 {
107 if (pt.y < psbi->rcScrollBar.top + psbi->dxyLineButton)
108 return SCROLL_TOP_ARROW;
109 if (pt.y >= psbi->rcScrollBar.bottom - psbi->dxyLineButton)
110 return SCROLL_BOTTOM_ARROW;
111 if (!psbi->xyThumbTop)
112 return SCROLL_TOP_RECT;
113 pt.y -= psbi->rcScrollBar.top;
114 if (pt.y < psbi->xyThumbTop)
115 return SCROLL_TOP_RECT;
116 if (pt.y >= psbi->xyThumbBottom)
117 return SCROLL_BOTTOM_RECT;
118 }
119 else /* horizontal */
120 {
121 if (pt.x < psbi->rcScrollBar.left + psbi->dxyLineButton)
122 return SCROLL_TOP_ARROW;
123 if (pt.x >= psbi->rcScrollBar.right - psbi->dxyLineButton)
124 return SCROLL_BOTTOM_ARROW;
125 if (!psbi->xyThumbTop)
126 return SCROLL_TOP_RECT;
127 pt.x -= psbi->rcScrollBar.left;
128 if (pt.x < psbi->xyThumbTop)
129 return SCROLL_TOP_RECT;
130 if (pt.x >= psbi->xyThumbBottom)
131 return SCROLL_BOTTOM_RECT;
132 }
133 return SCROLL_THUMB;
134 }
135
136 static void SCROLL_ThemeDrawPart(PDRAW_CONTEXT pcontext, int iPartId,int iStateId, SCROLLBARINFO* psbi, int htCurrent, int htDown, int htHot, RECT* r)
137 {
138 if(psbi->rgstate[htCurrent] & STATE_SYSTEM_UNAVAILABLE)
139 iStateId += BUTTON_DISABLED - BUTTON_NORMAL;
140 else if (htHot == htCurrent)
141 iStateId += BUTTON_HOT - BUTTON_NORMAL;
142 else if (htDown == htCurrent)
143 iStateId += BUTTON_PRESSED - BUTTON_NORMAL;
144
145 DrawThemeBackground(pcontext->scrolltheme, pcontext->hDC, iPartId, iStateId, r, NULL);
146 }
147
148 /***********************************************************************
149 * SCROLL_DrawArrows
150 *
151 * Draw the scroll bar arrows.
152 */
153 static void SCROLL_DrawArrows( PDRAW_CONTEXT pcontext, SCROLLBARINFO* psbi,
154 BOOL vertical, int htDown, int htHot )
155 {
156 RECT r;
157 int iStateId;
158
159 r = psbi->rcScrollBar;
160 if( vertical )
161 {
162 r.bottom = r.top + psbi->dxyLineButton;
163 iStateId = ABS_UPNORMAL;
164 }
165 else
166 {
167 r.right = r.left + psbi->dxyLineButton;
168 iStateId = ABS_LEFTNORMAL;
169 }
170
171 SCROLL_ThemeDrawPart(pcontext, SBP_ARROWBTN, iStateId, psbi, SCROLL_TOP_ARROW, htDown, htHot, &r);
172
173 r = psbi->rcScrollBar;
174 if( vertical )
175 {
176 r.top = r.bottom - psbi->dxyLineButton;
177 iStateId = ABS_DOWNNORMAL;
178 }
179 else
180 {
181 iStateId = ABS_RIGHTNORMAL;
182 r.left = r.right - psbi->dxyLineButton;
183 }
184
185 SCROLL_ThemeDrawPart(pcontext, SBP_ARROWBTN, iStateId, psbi, SCROLL_BOTTOM_ARROW, htDown, htHot, &r);
186 }
187
188 static void SCROLL_DrawInterior( PDRAW_CONTEXT pcontext, SCROLLBARINFO* psbi,
189 INT thumbPos, BOOL vertical,
190 int htDown, int htHot )
191 {
192 RECT r, rcPart;
193
194 r = psbi->rcScrollBar;
195 if (vertical)
196 {
197 r.top += psbi->dxyLineButton;
198 r.bottom -= (psbi->dxyLineButton);
199 }
200 else
201 {
202 r.left += psbi->dxyLineButton;
203 r.right -= psbi->dxyLineButton;
204 }
205
206 /* Draw the scroll rectangles and thumb */
207
208 if (!thumbPos) /* No thumb to draw */
209 {
210 rcPart = r;
211 SCROLL_ThemeDrawPart(pcontext, vertical ? SBP_UPPERTRACKVERT: SBP_UPPERTRACKHORZ , BUTTON_NORMAL, psbi, SCROLL_THUMB, 0, 0, &rcPart);
212 return;
213 }
214
215 if (vertical)
216 {
217 rcPart = r;
218 rcPart.bottom = thumbPos;
219 SCROLL_ThemeDrawPart(pcontext, SBP_UPPERTRACKVERT, BUTTON_NORMAL, psbi, SCROLL_TOP_RECT, htDown, htHot, &rcPart);
220 r.top = rcPart.bottom;
221
222 rcPart = r;
223 rcPart.top += psbi->xyThumbBottom - psbi->xyThumbTop;
224 SCROLL_ThemeDrawPart(pcontext, SBP_LOWERTRACKVERT, BUTTON_NORMAL, psbi, SCROLL_BOTTOM_RECT, htDown, htHot, &rcPart);
225 r.bottom = rcPart.top;
226
227 SCROLL_ThemeDrawPart(pcontext, SBP_THUMBBTNVERT, BUTTON_NORMAL, psbi, SCROLL_THUMB, htDown, htHot, &r);
228 SCROLL_ThemeDrawPart(pcontext, SBP_GRIPPERVERT, BUTTON_NORMAL, psbi, SCROLL_THUMB, htDown, htHot, &r);
229 }
230 else /* horizontal */
231 {
232 rcPart = r;
233 rcPart.right = thumbPos;
234 SCROLL_ThemeDrawPart(pcontext, SBP_UPPERTRACKHORZ, BUTTON_NORMAL, psbi, SCROLL_TOP_RECT, htDown, htHot, &rcPart);
235 r.left = rcPart.right;
236
237 rcPart = r;
238 rcPart.left += psbi->xyThumbBottom - psbi->xyThumbTop;
239 SCROLL_ThemeDrawPart(pcontext, SBP_LOWERTRACKHORZ, BUTTON_NORMAL, psbi, SCROLL_BOTTOM_RECT, htDown, htHot, &rcPart);
240 r.right = rcPart.left;
241
242 SCROLL_ThemeDrawPart(pcontext, SBP_THUMBBTNHORZ, BUTTON_NORMAL, psbi, SCROLL_THUMB, htDown, htHot, &r);
243 SCROLL_ThemeDrawPart(pcontext, SBP_GRIPPERHORZ, BUTTON_NORMAL, psbi, SCROLL_THUMB, htDown, htHot, &r);
244 }
245 }
246
247 static void SCROLL_DrawMovingThumb( PDRAW_CONTEXT pcontext, SCROLLBARINFO* psbi, BOOL vertical)
248 {
249 INT pos = SCROLL_TrackingPos;
250 INT max_size;
251
252 if( vertical )
253 max_size = psbi->rcScrollBar.bottom - psbi->rcScrollBar.top;
254 else
255 max_size = psbi->rcScrollBar.right - psbi->rcScrollBar.left;
256
257 max_size -= psbi->xyThumbBottom - psbi->xyThumbTop + psbi->dxyLineButton;
258
259 if( pos < (psbi->dxyLineButton) )
260 pos = (psbi->dxyLineButton);
261 else if( pos > max_size )
262 pos = max_size;
263
264 SCROLL_DrawInterior(pcontext, psbi, pos, vertical, SCROLL_THUMB, 0);
265
266 SCROLL_MovingThumb = !SCROLL_MovingThumb;
267 }
268
269
270 void
271 ThemeDrawScrollBar(PDRAW_CONTEXT pcontext, INT nBar, POINT* pt)
272 {
273 SCROLLINFO si;
274 SCROLLBARINFO sbi;
275 BOOL vertical;
276 enum SCROLL_HITTEST htHot = SCROLL_NOWHERE;
277
278 if (SCROLL_TrackingWin)
279 return;
280
281 if (((nBar == SB_VERT) && !(pcontext->wi.dwStyle & WS_VSCROLL)) ||
282 ((nBar == SB_HORZ) && !(pcontext->wi.dwStyle & WS_HSCROLL))) return;
283
284 /* Retrieve scrollbar info */
285 sbi.cbSize = sizeof(sbi);
286 si.cbSize = sizeof(si);
287 si.fMask = SIF_ALL ;
288 GetScrollInfo(pcontext->hWnd, nBar, &si);
289 GetScrollBarInfo(pcontext->hWnd, SCROLL_getObjectId(nBar), &sbi);
290 vertical = SCROLL_IsVertical(pcontext->hWnd, nBar);
291 if(sbi.rgstate[SCROLL_TOP_ARROW] & STATE_SYSTEM_UNAVAILABLE &&
292 sbi.rgstate[SCROLL_BOTTOM_ARROW] & STATE_SYSTEM_UNAVAILABLE )
293 {
294 sbi.xyThumbTop = 0;
295 }
296
297 /* The scrollbar rect is in screen coordinates */
298 OffsetRect(&sbi.rcScrollBar, -pcontext->wi.rcWindow.left, -pcontext->wi.rcWindow.top);
299
300 if(pt)
301 {
302 ScreenToWindow(pcontext->hWnd, pt);
303 htHot = SCROLL_HitTest(pcontext->hWnd, &sbi, vertical, *pt, FALSE);
304 }
305
306 /* do not draw if the scrollbar rectangle is empty */
307 if(IsRectEmpty(&sbi.rcScrollBar)) return;
308
309 /* Draw the scrollbar */
310 SCROLL_DrawArrows( pcontext, &sbi, vertical, 0, htHot );
311 SCROLL_DrawInterior( pcontext, &sbi, sbi.xyThumbTop, vertical, 0, htHot );
312 }
313
314
315
316 /***********************************************************************
317 * SCROLL_ClipPos
318 */
319 static POINT SCROLL_ClipPos( LPRECT lpRect, POINT pt )
320 {
321 if( pt.x < lpRect->left )
322 pt.x = lpRect->left;
323 else
324 if( pt.x > lpRect->right )
325 pt.x = lpRect->right;
326
327 if( pt.y < lpRect->top )
328 pt.y = lpRect->top;
329 else
330 if( pt.y > lpRect->bottom )
331 pt.y = lpRect->bottom;
332
333 return pt;
334 }
335
336
337
338 /***********************************************************************
339 * SCROLL_GetThumbVal
340 *
341 * Compute the current scroll position based on the thumb position in pixels
342 * from the top of the scroll-bar.
343 */
344 static UINT SCROLL_GetThumbVal( SCROLLINFO *psi, RECT *rect,
345 BOOL vertical, INT pos )
346 {
347 INT thumbSize;
348 INT pixels = vertical ? rect->bottom-rect->top : rect->right-rect->left;
349 INT range;
350
351 if ((pixels -= 2*(GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP)) <= 0)
352 return psi->nMin;
353
354 if (psi->nPage)
355 {
356 thumbSize = MulDiv(pixels,psi->nPage,(psi->nMax-psi->nMin+1));
357 if (thumbSize < SCROLL_MIN_THUMB) thumbSize = SCROLL_MIN_THUMB;
358 }
359 else thumbSize = GetSystemMetrics(SM_CXVSCROLL);
360
361 if ((pixels -= thumbSize) <= 0) return psi->nMin;
362
363 pos = max( 0, pos - (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP) );
364 if (pos > pixels) pos = pixels;
365
366 if (!psi->nPage)
367 range = psi->nMax - psi->nMin;
368 else
369 range = psi->nMax - psi->nMin - psi->nPage + 1;
370
371 return psi->nMin + MulDiv(pos, range, pixels);
372 }
373
374 static void
375 SCROLL_HandleScrollEvent( HWND hwnd, INT nBar, UINT msg, POINT pt)
376 {
377 /* Previous mouse position for timer events */
378 static POINT prevPt;
379 /* Thumb position when tracking started. */
380 static UINT trackThumbPos;
381 /* Position in the scroll-bar of the last button-down event. */
382 static INT lastClickPos;
383 /* Position in the scroll-bar of the last mouse event. */
384 static INT lastMousePos;
385
386 enum SCROLL_HITTEST hittest;
387 HWND hwndOwner, hwndCtl;
388 BOOL vertical;
389 SCROLLINFO si;
390 SCROLLBARINFO sbi;
391 DRAW_CONTEXT context;
392
393 si.cbSize = sizeof(si);
394 sbi.cbSize = sizeof(sbi);
395 si.fMask = SIF_ALL;
396 GetScrollInfo(hwnd, nBar, &si);
397 GetScrollBarInfo(hwnd, SCROLL_getObjectId(nBar), &sbi);
398 vertical = SCROLL_IsVertical(hwnd, nBar);
399 if(sbi.rgstate[SCROLL_TOP_ARROW] & STATE_SYSTEM_UNAVAILABLE &&
400 sbi.rgstate[SCROLL_BOTTOM_ARROW] & STATE_SYSTEM_UNAVAILABLE )
401 {
402 return;
403 }
404
405 if ((SCROLL_trackHitTest == SCROLL_NOWHERE) && (msg != WM_LBUTTONDOWN))
406 return;
407
408 ThemeInitDrawContext(&context, hwnd, 0);
409
410 /* The scrollbar rect is in screen coordinates */
411 OffsetRect(&sbi.rcScrollBar, -context.wi.rcWindow.left, -context.wi.rcWindow.top);
412
413 hwndOwner = (nBar == SB_CTL) ? GetParent(hwnd) : hwnd;
414 hwndCtl = (nBar == SB_CTL) ? hwnd : 0;
415
416 switch(msg)
417 {
418 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
419 HideCaret(hwnd); /* hide caret while holding down LBUTTON */
420 SCROLL_trackVertical = vertical;
421 SCROLL_trackHitTest = hittest = SCROLL_HitTest( hwnd, &sbi, vertical, pt, FALSE );
422 lastClickPos = vertical ? (pt.y - sbi.rcScrollBar.top) : (pt.x - sbi.rcScrollBar.left);
423 lastMousePos = lastClickPos;
424 trackThumbPos = sbi.xyThumbTop;
425 prevPt = pt;
426 SetCapture( hwnd );
427 break;
428
429 case WM_MOUSEMOVE:
430 hittest = SCROLL_HitTest( hwnd, &sbi, vertical, pt, TRUE );
431 prevPt = pt;
432 break;
433
434 case WM_LBUTTONUP:
435 hittest = SCROLL_NOWHERE;
436 ReleaseCapture();
437 /* if scrollbar has focus, show back caret */
438 if (hwnd==GetFocus())
439 ShowCaret(hwnd);
440 break;
441
442 case WM_SYSTIMER:
443 pt = prevPt;
444 hittest = SCROLL_HitTest( hwnd, &sbi, vertical, pt, FALSE );
445 break;
446
447 default:
448 return; /* Should never happen */
449 }
450
451 //TRACE("Event: hwnd=%p bar=%d msg=%s pt=%d,%d hit=%d\n",
452 // hwnd, nBar, SPY_GetMsgName(msg,hwnd), pt.x, pt.y, hittest );
453
454 switch(SCROLL_trackHitTest)
455 {
456 case SCROLL_NOWHERE: /* No tracking in progress */
457 break;
458
459 case SCROLL_TOP_ARROW:
460 if (hittest == SCROLL_trackHitTest)
461 {
462 SCROLL_DrawArrows( &context, &sbi, vertical, SCROLL_trackHitTest, 0 );
463 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
464 {
465 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
466 SB_LINEUP, (LPARAM)hwndCtl );
467 }
468
469 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
470 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, NULL );
471 }
472 else
473 {
474 SCROLL_DrawArrows( &context, &sbi, vertical, 0, 0 );
475 KillSystemTimer( hwnd, SCROLL_TIMER );
476 }
477
478 break;
479
480 case SCROLL_TOP_RECT:
481 SCROLL_DrawInterior( &context, &sbi, sbi.xyThumbTop, vertical, SCROLL_trackHitTest, 0);
482 if (hittest == SCROLL_trackHitTest)
483 {
484 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
485 {
486 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
487 SB_PAGEUP, (LPARAM)hwndCtl );
488 }
489 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
490 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, NULL );
491 }
492 else KillSystemTimer( hwnd, SCROLL_TIMER );
493 break;
494
495 case SCROLL_THUMB:
496 if (msg == WM_LBUTTONDOWN)
497 {
498 SCROLL_TrackingWin = hwnd;
499 SCROLL_TrackingBar = nBar;
500 SCROLL_TrackingPos = trackThumbPos + lastMousePos - lastClickPos;
501 SCROLL_TrackingVal = SCROLL_GetThumbVal( &si, &sbi.rcScrollBar,
502 vertical, SCROLL_TrackingPos );
503 if (!SCROLL_MovingThumb)
504 SCROLL_DrawMovingThumb(&context, &sbi, vertical);
505 }
506 else if (msg == WM_LBUTTONUP)
507 {
508 if (SCROLL_MovingThumb)
509 SCROLL_DrawMovingThumb(&context, &sbi, vertical);
510
511 SCROLL_DrawInterior( &context, &sbi, sbi.xyThumbTop, vertical, 0, SCROLL_trackHitTest );
512 }
513 else /* WM_MOUSEMOVE */
514 {
515 INT pos;
516
517 if (!SCROLL_PtInRectEx( &sbi.rcScrollBar, pt, vertical ))
518 pos = lastClickPos;
519 else
520 {
521 pt = SCROLL_ClipPos( &sbi.rcScrollBar, pt );
522 pos = vertical ? (pt.y - sbi.rcScrollBar.top) : (pt.x - sbi.rcScrollBar.left);
523 }
524 if ( (pos != lastMousePos) || (!SCROLL_MovingThumb) )
525 {
526 if (SCROLL_MovingThumb)
527 SCROLL_DrawMovingThumb( &context, &sbi, vertical);
528 lastMousePos = pos;
529 SCROLL_TrackingPos = trackThumbPos + pos - lastClickPos;
530 SCROLL_TrackingVal = SCROLL_GetThumbVal( &si, &sbi.rcScrollBar,
531 vertical,
532 SCROLL_TrackingPos );
533 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
534 MAKEWPARAM( SB_THUMBTRACK, SCROLL_TrackingVal),
535 (LPARAM)hwndCtl );
536 if (!SCROLL_MovingThumb)
537 SCROLL_DrawMovingThumb( &context, &sbi, vertical);
538 }
539 }
540 break;
541
542 case SCROLL_BOTTOM_RECT:
543 if (hittest == SCROLL_trackHitTest)
544 {
545 SCROLL_DrawInterior( &context, &sbi, sbi.xyThumbTop, vertical, SCROLL_trackHitTest, 0 );
546 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
547 {
548 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
549 SB_PAGEDOWN, (LPARAM)hwndCtl );
550 }
551 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
552 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, NULL );
553 }
554 else
555 {
556 SCROLL_DrawInterior( &context, &sbi, sbi.xyThumbTop, vertical, 0, 0 );
557 KillSystemTimer( hwnd, SCROLL_TIMER );
558 }
559 break;
560
561 case SCROLL_BOTTOM_ARROW:
562 if (hittest == SCROLL_trackHitTest)
563 {
564 SCROLL_DrawArrows( &context, &sbi, vertical, SCROLL_trackHitTest, 0 );
565 if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))
566 {
567 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
568 SB_LINEDOWN, (LPARAM)hwndCtl );
569 }
570
571 SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ?
572 SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, NULL );
573 }
574 else
575 {
576 SCROLL_DrawArrows( &context, &sbi, vertical, 0, 0 );
577 KillSystemTimer( hwnd, SCROLL_TIMER );
578 }
579 break;
580 }
581
582 if (msg == WM_LBUTTONDOWN)
583 {
584
585 if (hittest == SCROLL_THUMB)
586 {
587 UINT val = SCROLL_GetThumbVal( &si, &sbi.rcScrollBar, vertical,
588 trackThumbPos + lastMousePos - lastClickPos );
589 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
590 MAKEWPARAM( SB_THUMBTRACK, val ), (LPARAM)hwndCtl );
591 }
592 }
593
594 if (msg == WM_LBUTTONUP)
595 {
596 hittest = SCROLL_trackHitTest;
597 SCROLL_trackHitTest = SCROLL_NOWHERE; /* Terminate tracking */
598
599 if (hittest == SCROLL_THUMB)
600 {
601 UINT val = SCROLL_GetThumbVal( &si, &sbi.rcScrollBar, vertical,
602 trackThumbPos + lastMousePos - lastClickPos );
603 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
604 MAKEWPARAM( SB_THUMBPOSITION, val ), (LPARAM)hwndCtl );
605 }
606 /* SB_ENDSCROLL doesn't report thumb position */
607 SendMessageW( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL,
608 SB_ENDSCROLL, (LPARAM)hwndCtl );
609
610 /* Terminate tracking */
611 SCROLL_TrackingWin = 0;
612 }
613
614 ThemeCleanupDrawContext(&context);
615 }
616
617 static void
618 SCROLL_TrackScrollBar( HWND hwnd, INT scrollbar, POINT pt )
619 {
620 MSG msg;
621
622 ScreenToWindow(hwnd, &pt);
623
624 SCROLL_HandleScrollEvent( hwnd, scrollbar, WM_LBUTTONDOWN, pt );
625
626 do
627 {
628 if (!GetMessageW( &msg, 0, 0, 0 )) break;
629 if (CallMsgFilterW( &msg, MSGF_SCROLLBAR )) continue;
630 if (msg.message == WM_LBUTTONUP ||
631 msg.message == WM_MOUSEMOVE ||
632 (msg.message == WM_SYSTIMER && msg.wParam == SCROLL_TIMER))
633 {
634 pt.x = GET_X_LPARAM(msg.lParam);
635 pt.y = GET_Y_LPARAM(msg.lParam);
636 ClientToScreen(hwnd, &pt);
637 ScreenToWindow(hwnd, &pt);
638 SCROLL_HandleScrollEvent( hwnd, scrollbar, msg.message, pt );
639 }
640 else
641 {
642 TranslateMessage( &msg );
643 DispatchMessageW( &msg );
644 }
645 if (!IsWindow( hwnd ))
646 {
647 ReleaseCapture();
648 break;
649 }
650 } while (msg.message != WM_LBUTTONUP && GetCapture() == hwnd);
651 }
652
653 void NC_TrackScrollBar( HWND hwnd, WPARAM wParam, POINT pt )
654 {
655 INT scrollbar;
656
657 if ((wParam & 0xfff0) == SC_HSCROLL)
658 {
659 if ((wParam & 0x0f) != HTHSCROLL) return;
660 scrollbar = SB_HORZ;
661 }
662 else /* SC_VSCROLL */
663 {
664 if ((wParam & 0x0f) != HTVSCROLL) return;
665 scrollbar = SB_VERT;
666 }
667 SCROLL_TrackScrollBar( hwnd, scrollbar, pt );
668 }