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

Last change on this file since 1064 was 1064, checked in by sandervl, 26 years ago

ScrollWindow fix

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