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

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

changed menu & scrollbar behaviour in os/2 mode

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