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