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