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