| 1 | /* $Id: scroll.cpp,v 1.44 2001-10-11 17:05:02 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) 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 | } else if ((msg == WM_LBUTTONUP) || (msg == WM_CAPTURECHANGED)) | 
|---|
| 983 | { | 
|---|
| 984 | UINT val; | 
|---|
| 985 | INT oldPos = infoPtr->CurVal; | 
|---|
| 986 |  | 
|---|
| 987 | SCROLL_MovingThumb = FALSE; | 
|---|
| 988 | SCROLL_TrackingWin = 0; | 
|---|
| 989 | SCROLL_trackHitTest = SCROLL_NOWHERE;  /* Terminate tracking */ | 
|---|
| 990 | val = SCROLL_GetThumbVal( infoPtr, &rect, vertical, | 
|---|
| 991 | trackThumbPos + lastMousePos - lastClickPos ); | 
|---|
| 992 |  | 
|---|
| 993 | if ((val != infoPtr->CurVal) || thumbTrackSent) | 
|---|
| 994 | SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL, | 
|---|
| 995 | MAKEWPARAM( SB_THUMBPOSITION, val ), hwndCtl ); | 
|---|
| 996 |  | 
|---|
| 997 | if (oldPos == infoPtr->CurVal) | 
|---|
| 998 | { | 
|---|
| 999 | vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect, | 
|---|
| 1000 | &arrowSize, &thumbSize, &thumbPos ); | 
|---|
| 1001 | SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize, | 
|---|
| 1002 | thumbPos, infoPtr->flags, vertical, | 
|---|
| 1003 | FALSE, FALSE ); | 
|---|
| 1004 | } | 
|---|
| 1005 |  | 
|---|
| 1006 | ReleaseDC(hwnd,hdc); | 
|---|
| 1007 | return res; | 
|---|
| 1008 | } else if (msg == WM_MOUSEMOVE) | 
|---|
| 1009 | { | 
|---|
| 1010 | UINT pos; | 
|---|
| 1011 |  | 
|---|
| 1012 | #ifdef __WIN32OS2__ | 
|---|
| 1013 | if (!SCROLL_PtInRectEx( &rect, pt, vertical ) && !fOS2Look) pos = lastClickPos; | 
|---|
| 1014 | #else | 
|---|
| 1015 | if (!SCROLL_PtInRectEx( &rect, pt, vertical )) pos = lastClickPos; | 
|---|
| 1016 | #endif | 
|---|
| 1017 | else | 
|---|
| 1018 | { | 
|---|
| 1019 | pt = SCROLL_ClipPos( &rect, pt ); | 
|---|
| 1020 | pos = vertical ? pt.y:pt.x; | 
|---|
| 1021 | } | 
|---|
| 1022 | if (pos != lastMousePos) | 
|---|
| 1023 | { | 
|---|
| 1024 | lastMousePos = pos; | 
|---|
| 1025 | SCROLL_TrackingPos = trackThumbPos + pos - lastClickPos; | 
|---|
| 1026 | SCROLL_TrackingVal = SCROLL_GetThumbVal( infoPtr, &rect, | 
|---|
| 1027 | vertical, | 
|---|
| 1028 | SCROLL_TrackingPos ); | 
|---|
| 1029 | SCROLL_DrawMovingThumb( hdc, &rect, vertical, | 
|---|
| 1030 | arrowSize, thumbSize ); | 
|---|
| 1031 | SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL, | 
|---|
| 1032 | MAKEWPARAM( SB_THUMBTRACK, SCROLL_TrackingVal), | 
|---|
| 1033 | hwndCtl ); | 
|---|
| 1034 | thumbTrackSent = TRUE; | 
|---|
| 1035 | } | 
|---|
| 1036 | } | 
|---|
| 1037 | break; | 
|---|
| 1038 |  | 
|---|
| 1039 | case SCROLL_BOTTOM_RECT: | 
|---|
| 1040 | if ((msg == WM_LBUTTONUP) || (msg == WM_CAPTURECHANGED)) | 
|---|
| 1041 | KillSystemTimer(hwnd,SCROLL_TIMER); | 
|---|
| 1042 | else if ((msg == WM_LBUTTONDOWN) || (!timerRunning && (msg == WM_SYSTIMER))) | 
|---|
| 1043 | { | 
|---|
| 1044 | SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ? | 
|---|
| 1045 | SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, | 
|---|
| 1046 | (TIMERPROC)0 ); | 
|---|
| 1047 | if (msg != WM_LBUTTONDOWN) timerRunning = TRUE; | 
|---|
| 1048 | } | 
|---|
| 1049 |  | 
|---|
| 1050 | if ((msg == WM_LBUTTONDOWN) || (SCROLL_lastHitTest != hittest)) | 
|---|
| 1051 | { | 
|---|
| 1052 | SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize, | 
|---|
| 1053 | thumbPos, infoPtr->flags, vertical, | 
|---|
| 1054 | FALSE, (hittest == SCROLL_trackHitTest) ); | 
|---|
| 1055 | SCROLL_lastHitTest = hittest; | 
|---|
| 1056 | } | 
|---|
| 1057 |  | 
|---|
| 1058 | if ((hittest == SCROLL_trackHitTest) && ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))) | 
|---|
| 1059 | SendMessageA(hwndOwner,vertical ? WM_VSCROLL:WM_HSCROLL,SB_PAGEDOWN,hwndCtl); | 
|---|
| 1060 |  | 
|---|
| 1061 | break; | 
|---|
| 1062 |  | 
|---|
| 1063 | case SCROLL_BOTTOM_ARROW: | 
|---|
| 1064 | if ((msg == WM_LBUTTONUP) || (msg == WM_CAPTURECHANGED)) | 
|---|
| 1065 | KillSystemTimer(hwnd,SCROLL_TIMER); | 
|---|
| 1066 | else if ((msg == WM_LBUTTONDOWN) || (!timerRunning && (msg == WM_SYSTIMER))) | 
|---|
| 1067 | { | 
|---|
| 1068 | SetSystemTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ? | 
|---|
| 1069 | SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, | 
|---|
| 1070 | (TIMERPROC)0 ); | 
|---|
| 1071 | if (msg != WM_LBUTTONDOWN) timerRunning = TRUE; | 
|---|
| 1072 | } | 
|---|
| 1073 |  | 
|---|
| 1074 | if ((msg == WM_LBUTTONDOWN) || (SCROLL_lastHitTest != hittest)) | 
|---|
| 1075 | { | 
|---|
| 1076 | SCROLL_DrawBottomArrow(hdc,infoPtr,&rect,arrowSize,vertical,(hittest == SCROLL_trackHitTest)); | 
|---|
| 1077 | SCROLL_lastHitTest = hittest; | 
|---|
| 1078 | } | 
|---|
| 1079 | if ((hittest == SCROLL_trackHitTest) && ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER))) | 
|---|
| 1080 | SendMessageA(hwndOwner,vertical ? WM_VSCROLL:WM_HSCROLL,SB_LINEDOWN,hwndCtl); | 
|---|
| 1081 |  | 
|---|
| 1082 | break; | 
|---|
| 1083 | } | 
|---|
| 1084 |  | 
|---|
| 1085 | if ((msg == WM_LBUTTONUP) || (msg == WM_CAPTURECHANGED)) | 
|---|
| 1086 | { | 
|---|
| 1087 | SCROLL_trackHitTest = SCROLL_NOWHERE;  /* Terminate tracking */ | 
|---|
| 1088 |  | 
|---|
| 1089 | SendMessageA(hwndOwner,vertical ? WM_VSCROLL:WM_HSCROLL,SB_ENDSCROLL,hwndCtl); | 
|---|
| 1090 | } | 
|---|
| 1091 |  | 
|---|
| 1092 | ReleaseDC( hwnd, hdc ); | 
|---|
| 1093 |  | 
|---|
| 1094 | return res; | 
|---|
| 1095 | } | 
|---|
| 1096 |  | 
|---|
| 1097 | /*********************************************************************** | 
|---|
| 1098 | *           SCROLL_HandleKbdEvent | 
|---|
| 1099 | * | 
|---|
| 1100 | * Handle a keyboard event (only for SB_CTL scrollbars). | 
|---|
| 1101 | */ | 
|---|
| 1102 | LRESULT SCROLL_KeyDown(HWND hwnd,WPARAM wParam,LPARAM lParam) | 
|---|
| 1103 | { | 
|---|
| 1104 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE); | 
|---|
| 1105 | UINT msg; | 
|---|
| 1106 |  | 
|---|
| 1107 | if (dwStyle & (SBS_SIZEBOX | SBS_SIZEGRIP)) return 0; | 
|---|
| 1108 |  | 
|---|
| 1109 | switch(wParam) | 
|---|
| 1110 | { | 
|---|
| 1111 | case VK_PRIOR: msg = SB_PAGEUP; break; | 
|---|
| 1112 | case VK_NEXT:  msg = SB_PAGEDOWN; break; | 
|---|
| 1113 | case VK_HOME:  msg = SB_TOP; break; | 
|---|
| 1114 | case VK_END:   msg = SB_BOTTOM; break; | 
|---|
| 1115 | case VK_UP:    msg = SB_LINEUP; break; | 
|---|
| 1116 | case VK_DOWN:  msg = SB_LINEDOWN; break; | 
|---|
| 1117 | default: | 
|---|
| 1118 | return 0; | 
|---|
| 1119 | } | 
|---|
| 1120 | SendMessageA( GetParent(hwnd), | 
|---|
| 1121 | (dwStyle & SBS_VERT) ? WM_VSCROLL : WM_HSCROLL, | 
|---|
| 1122 | msg, hwnd ); | 
|---|
| 1123 |  | 
|---|
| 1124 | return 0; | 
|---|
| 1125 | } | 
|---|
| 1126 |  | 
|---|
| 1127 | LRESULT SCROLL_Paint(HWND hwnd,WPARAM wParam,LPARAM lParam,INT nBar) | 
|---|
| 1128 | { | 
|---|
| 1129 | PAINTSTRUCT ps; | 
|---|
| 1130 | HDC hdc = wParam ? (HDC)wParam:BeginPaint( hwnd, &ps ); | 
|---|
| 1131 |  | 
|---|
| 1132 | SCROLL_DrawScrollBar( hwnd, hdc, nBar, TRUE, TRUE ); | 
|---|
| 1133 | if (!wParam) EndPaint( hwnd, &ps ); | 
|---|
| 1134 |  | 
|---|
| 1135 | return 0; | 
|---|
| 1136 | } | 
|---|
| 1137 |  | 
|---|
| 1138 | LRESULT SCROLL_SetRange(HWND hwnd,WPARAM wParam,LPARAM lParam,INT nBar,BOOL redraw) | 
|---|
| 1139 | { | 
|---|
| 1140 | SCROLLBAR_INFO *infoPtr = SCROLL_GetInfoPtr(hwnd,nBar); | 
|---|
| 1141 | INT oldPos = infoPtr->CurVal; | 
|---|
| 1142 |  | 
|---|
| 1143 | SetScrollRange(hwnd,nBar,wParam,lParam,redraw); | 
|---|
| 1144 | return (oldPos != infoPtr->CurVal) ? infoPtr->CurVal:0; | 
|---|
| 1145 | } | 
|---|
| 1146 |  | 
|---|
| 1147 | /* Window Procedures */ | 
|---|
| 1148 |  | 
|---|
| 1149 | /*********************************************************************** | 
|---|
| 1150 | *           ScrollBarWndProc | 
|---|
| 1151 | */ | 
|---|
| 1152 | LRESULT WINAPI ScrollBarWndProc( HWND hwnd, UINT message, WPARAM wParam, | 
|---|
| 1153 | LPARAM lParam ) | 
|---|
| 1154 | { | 
|---|
| 1155 | switch(message) | 
|---|
| 1156 | { | 
|---|
| 1157 | case WM_NCCREATE: | 
|---|
| 1158 | return SCROLL_NCCreate(hwnd,wParam,lParam); | 
|---|
| 1159 |  | 
|---|
| 1160 | case WM_CREATE: | 
|---|
| 1161 | return SCROLL_Create(hwnd,wParam,lParam); | 
|---|
| 1162 |  | 
|---|
| 1163 | case WM_DESTROY: | 
|---|
| 1164 | return SCROLL_Destroy(hwnd,wParam,lParam); | 
|---|
| 1165 |  | 
|---|
| 1166 | case WM_LBUTTONDOWN: | 
|---|
| 1167 | case WM_LBUTTONUP: | 
|---|
| 1168 | case WM_NCHITTEST: | 
|---|
| 1169 | case WM_CAPTURECHANGED: | 
|---|
| 1170 | case WM_MOUSEMOVE: | 
|---|
| 1171 | case WM_SYSTIMER: | 
|---|
| 1172 | case WM_SETFOCUS: | 
|---|
| 1173 | case WM_KILLFOCUS: | 
|---|
| 1174 | return SCROLL_HandleScrollEvent(hwnd,wParam,lParam,SB_CTL,message); | 
|---|
| 1175 |  | 
|---|
| 1176 | case WM_KEYDOWN: | 
|---|
| 1177 | return SCROLL_KeyDown(hwnd,wParam,lParam); | 
|---|
| 1178 |  | 
|---|
| 1179 | #ifdef __WIN32OS2__ | 
|---|
| 1180 | case WM_ENABLE: | 
|---|
| 1181 | return SCROLL_Enable(hwnd, wParam); | 
|---|
| 1182 |  | 
|---|
| 1183 | case WM_SYSCOMMAND: | 
|---|
| 1184 | //Not entirely sure this is 100% correct, but it seems the logical thing to do | 
|---|
| 1185 | //(for scrollbar control windows with the size grip style) | 
|---|
| 1186 | //Might need to send it to top parent | 
|---|
| 1187 | return SendMessageA(GetParent(hwnd), message, wParam, lParam); | 
|---|
| 1188 | #endif | 
|---|
| 1189 |  | 
|---|
| 1190 | case WM_ERASEBKGND: | 
|---|
| 1191 | return 1; | 
|---|
| 1192 |  | 
|---|
| 1193 | case WM_GETDLGCODE: | 
|---|
| 1194 | return DLGC_WANTARROWS; /* Windows returns this value */ | 
|---|
| 1195 |  | 
|---|
| 1196 | case WM_PAINT: | 
|---|
| 1197 | return SCROLL_Paint(hwnd,wParam,lParam,SB_CTL); | 
|---|
| 1198 |  | 
|---|
| 1199 | case SBM_SETPOS: | 
|---|
| 1200 | return SetScrollPos( hwnd, SB_CTL, wParam, (BOOL)lParam ); | 
|---|
| 1201 |  | 
|---|
| 1202 | case SBM_GETPOS: | 
|---|
| 1203 | return GetScrollPos( hwnd, SB_CTL ); | 
|---|
| 1204 |  | 
|---|
| 1205 | case SBM_SETRANGE: | 
|---|
| 1206 | return SCROLL_SetRange(hwnd,wParam,lParam,SB_CTL,FALSE); | 
|---|
| 1207 |  | 
|---|
| 1208 | case SBM_GETRANGE: | 
|---|
| 1209 | GetScrollRange( hwnd, SB_CTL, (LPINT)wParam, (LPINT)lParam ); | 
|---|
| 1210 | return 0; | 
|---|
| 1211 |  | 
|---|
| 1212 | case SBM_ENABLE_ARROWS: | 
|---|
| 1213 | return EnableScrollBar( hwnd, SB_CTL, wParam ); | 
|---|
| 1214 |  | 
|---|
| 1215 | case SBM_SETRANGEREDRAW: | 
|---|
| 1216 | return SCROLL_SetRange(hwnd,wParam,lParam,SB_CTL,TRUE); | 
|---|
| 1217 |  | 
|---|
| 1218 | case SBM_SETSCROLLINFO: | 
|---|
| 1219 | return SetScrollInfo(hwnd,SB_CTL,(SCROLLINFO*)lParam,wParam); | 
|---|
| 1220 |  | 
|---|
| 1221 | case SBM_GETSCROLLINFO: | 
|---|
| 1222 | return GetScrollInfo( hwnd, SB_CTL, (SCROLLINFO *)lParam ); | 
|---|
| 1223 |  | 
|---|
| 1224 | case 0x00e5: | 
|---|
| 1225 | case 0x00e7: | 
|---|
| 1226 | case 0x00e8: | 
|---|
| 1227 | case 0x00eb: | 
|---|
| 1228 | case 0x00ec: | 
|---|
| 1229 | case 0x00ed: | 
|---|
| 1230 | case 0x00ee: | 
|---|
| 1231 | case 0x00ef: | 
|---|
| 1232 | //ERR("unknown Win32 msg %04x wp=%08x lp=%08lx\n", | 
|---|
| 1233 | //            message, wParam, lParam ); | 
|---|
| 1234 | break; | 
|---|
| 1235 |  | 
|---|
| 1236 | default: | 
|---|
| 1237 | return DefWindowProcA( hwnd, message, wParam, lParam ); | 
|---|
| 1238 | } | 
|---|
| 1239 |  | 
|---|
| 1240 | return 0; | 
|---|
| 1241 | } | 
|---|
| 1242 |  | 
|---|
| 1243 | /* Scrollbar API */ | 
|---|
| 1244 |  | 
|---|
| 1245 | /************************************************************************* | 
|---|
| 1246 | *           SetScrollInfo   (USER32.501) | 
|---|
| 1247 | * SetScrollInfo32 can be used to set the position, upper bound, | 
|---|
| 1248 | * lower bound, and page size of a scrollbar control. | 
|---|
| 1249 | * | 
|---|
| 1250 | * RETURNS | 
|---|
| 1251 | *    Scrollbar position | 
|---|
| 1252 | * | 
|---|
| 1253 | * NOTE | 
|---|
| 1254 | *    For 100 lines of text to be displayed in a window of 25 lines, | 
|---|
| 1255 | *  one would for instance use info->nMin=0, info->nMax=75 | 
|---|
| 1256 | *  (corresponding to the 76 different positions of the window on | 
|---|
| 1257 | *  the text), and info->nPage=25. | 
|---|
| 1258 | */ | 
|---|
| 1259 | INT WINAPI SetScrollInfo(HWND hwnd,INT nBar,const SCROLLINFO *info,BOOL bRedraw) | 
|---|
| 1260 | { | 
|---|
| 1261 | /* Update the scrollbar state and set action flags according to | 
|---|
| 1262 | * what has to be done graphics wise. */ | 
|---|
| 1263 |  | 
|---|
| 1264 | SCROLLBAR_INFO *infoPtr; | 
|---|
| 1265 | UINT new_flags; | 
|---|
| 1266 | INT action = 0; | 
|---|
| 1267 | BOOL bChangeParams = FALSE; /* don't show/hide scrollbar if params don't change */ | 
|---|
| 1268 |  | 
|---|
| 1269 | dprintf(("USER32: SetScrollInfo %x %d",hwnd,nBar)); | 
|---|
| 1270 |  | 
|---|
| 1271 | if (!(infoPtr = SCROLL_GetInfoPtr(hwnd,nBar))) return 0; | 
|---|
| 1272 | if (info->fMask & ~(SIF_ALL | SIF_DISABLENOSCROLL)) return 0; | 
|---|
| 1273 | if ((info->cbSize != sizeof(*info)) && | 
|---|
| 1274 | (info->cbSize != sizeof(*info)-sizeof(info->nTrackPos))) return 0; | 
|---|
| 1275 |  | 
|---|
| 1276 | /* Set the page size */ | 
|---|
| 1277 | if (info->fMask & SIF_PAGE) | 
|---|
| 1278 | { | 
|---|
| 1279 | if( infoPtr->Page != info->nPage ) | 
|---|
| 1280 | { | 
|---|
| 1281 | infoPtr->Page = info->nPage; | 
|---|
| 1282 | action |= SA_SSI_REPAINT_INTERIOR; | 
|---|
| 1283 | bChangeParams = TRUE; | 
|---|
| 1284 | } | 
|---|
| 1285 | } | 
|---|
| 1286 |  | 
|---|
| 1287 | /* Set the scroll pos */ | 
|---|
| 1288 | if (info->fMask & SIF_POS) | 
|---|
| 1289 | { | 
|---|
| 1290 | //dsprintf(scroll, " pos=%d", info->nPos ); | 
|---|
| 1291 | if( infoPtr->CurVal != info->nPos ) | 
|---|
| 1292 | { | 
|---|
| 1293 | infoPtr->CurVal = info->nPos; | 
|---|
| 1294 | action |= SA_SSI_MOVE_THUMB; | 
|---|
| 1295 | } | 
|---|
| 1296 | } | 
|---|
| 1297 |  | 
|---|
| 1298 | /* Set the scroll range */ | 
|---|
| 1299 | if (info->fMask & SIF_RANGE) | 
|---|
| 1300 | { | 
|---|
| 1301 | /* Invalid range -> range is set to (0,0) */ | 
|---|
| 1302 | if ((info->nMin > info->nMax) || | 
|---|
| 1303 | ((UINT)(info->nMax - info->nMin) >= 0x80000000)) | 
|---|
| 1304 | { | 
|---|
| 1305 | //NOTE: This does not fail in NT4 (unlike SetScrollRange) | 
|---|
| 1306 | infoPtr->MinVal = 0; | 
|---|
| 1307 | infoPtr->MaxVal = 0; | 
|---|
| 1308 | bChangeParams = TRUE; | 
|---|
| 1309 | } | 
|---|
| 1310 | else | 
|---|
| 1311 | { | 
|---|
| 1312 | if( infoPtr->MinVal != info->nMin || | 
|---|
| 1313 | infoPtr->MaxVal != info->nMax ) | 
|---|
| 1314 | { | 
|---|
| 1315 | action |= SA_SSI_REPAINT_INTERIOR; | 
|---|
| 1316 | infoPtr->MinVal = info->nMin; | 
|---|
| 1317 | infoPtr->MaxVal = info->nMax; | 
|---|
| 1318 | bChangeParams = TRUE; | 
|---|
| 1319 | } | 
|---|
| 1320 | } | 
|---|
| 1321 | } | 
|---|
| 1322 |  | 
|---|
| 1323 | /* Make sure the page size is valid */ | 
|---|
| 1324 | if (infoPtr->Page < 0) infoPtr->Page = 0; | 
|---|
| 1325 | else if (infoPtr->Page > infoPtr->MaxVal - infoPtr->MinVal + 1 ) | 
|---|
| 1326 | infoPtr->Page = infoPtr->MaxVal - infoPtr->MinVal + 1; | 
|---|
| 1327 |  | 
|---|
| 1328 | /* Make sure the pos is inside the range */ | 
|---|
| 1329 |  | 
|---|
| 1330 | if (infoPtr->CurVal < infoPtr->MinVal) | 
|---|
| 1331 | infoPtr->CurVal = infoPtr->MinVal; | 
|---|
| 1332 | else if (infoPtr->CurVal > infoPtr->MaxVal - MAX( infoPtr->Page-1, 0 )) | 
|---|
| 1333 | infoPtr->CurVal = infoPtr->MaxVal - MAX( infoPtr->Page-1, 0 ); | 
|---|
| 1334 |  | 
|---|
| 1335 | //testestest | 
|---|
| 1336 | dprintf(("new values: page=%d pos=%d min=%d max=%d\n", | 
|---|
| 1337 | infoPtr->Page, infoPtr->CurVal, | 
|---|
| 1338 | infoPtr->MinVal, infoPtr->MaxVal )); | 
|---|
| 1339 |  | 
|---|
| 1340 | /* don't change the scrollbar state if SetScrollInfo | 
|---|
| 1341 | * is just called with SIF_DISABLENOSCROLL | 
|---|
| 1342 | */ | 
|---|
| 1343 | if(!(info->fMask & SIF_ALL)) goto done; | 
|---|
| 1344 |  | 
|---|
| 1345 | /* Check if the scrollbar should be hidden or disabled */ | 
|---|
| 1346 | if (info->fMask & (SIF_RANGE | SIF_PAGE | SIF_DISABLENOSCROLL)) | 
|---|
| 1347 | { | 
|---|
| 1348 | new_flags = infoPtr->flags; | 
|---|
| 1349 | if (infoPtr->MinVal >= infoPtr->MaxVal - MAX( infoPtr->Page-1, 0 )) | 
|---|
| 1350 | { | 
|---|
| 1351 | /* Hide or disable scroll-bar */ | 
|---|
| 1352 | if (info->fMask & SIF_DISABLENOSCROLL) | 
|---|
| 1353 | { | 
|---|
| 1354 | new_flags = ESB_DISABLE_BOTH; | 
|---|
| 1355 | action |= SA_SSI_REFRESH; | 
|---|
| 1356 | } | 
|---|
| 1357 | else | 
|---|
| 1358 | if (nBar != SB_CTL && bChangeParams) | 
|---|
| 1359 | { | 
|---|
| 1360 | action = SA_SSI_HIDE; | 
|---|
| 1361 | infoPtr->flags = 0; | 
|---|
| 1362 | goto done; | 
|---|
| 1363 | } | 
|---|
| 1364 | } | 
|---|
| 1365 | else  /* Show and enable scroll-bar */ | 
|---|
| 1366 | { | 
|---|
| 1367 | new_flags = 0; | 
|---|
| 1368 | if (nBar != SB_CTL && bChangeParams) action |= SA_SSI_SHOW; | 
|---|
| 1369 | if (infoPtr->flags) action |= SA_SSI_REFRESH; | 
|---|
| 1370 | } | 
|---|
| 1371 |  | 
|---|
| 1372 | if (infoPtr->flags != new_flags) /* check arrow flags */ | 
|---|
| 1373 | { | 
|---|
| 1374 | infoPtr->flags = new_flags; | 
|---|
| 1375 | action |= SA_SSI_REPAINT_ARROWS; | 
|---|
| 1376 | } | 
|---|
| 1377 | } | 
|---|
| 1378 |  | 
|---|
| 1379 | done: | 
|---|
| 1380 | /* Update scrollbar */ | 
|---|
| 1381 |  | 
|---|
| 1382 | if( action & SA_SSI_HIDE ) | 
|---|
| 1383 | ShowScrollBar(hwnd,nBar,FALSE); | 
|---|
| 1384 | else | 
|---|
| 1385 | { | 
|---|
| 1386 | if(action & SA_SSI_SHOW) | 
|---|
| 1387 | ShowScrollBar(hwnd,nBar,TRUE); | 
|---|
| 1388 |  | 
|---|
| 1389 | if (bRedraw) | 
|---|
| 1390 | { | 
|---|
| 1391 | if (action & SA_SSI_REFRESH) | 
|---|
| 1392 | SCROLL_RefreshScrollBar(hwnd,nBar,TRUE,TRUE); | 
|---|
| 1393 | else | 
|---|
| 1394 | { | 
|---|
| 1395 | if (action & (SA_SSI_REPAINT_INTERIOR | SA_SSI_MOVE_THUMB)) | 
|---|
| 1396 | SCROLL_RefreshScrollBar(hwnd,nBar,FALSE,TRUE); | 
|---|
| 1397 | if (action & SA_SSI_REPAINT_ARROWS) | 
|---|
| 1398 | SCROLL_RefreshScrollBar(hwnd,nBar,TRUE,FALSE); | 
|---|
| 1399 | } | 
|---|
| 1400 | } | 
|---|
| 1401 | } | 
|---|
| 1402 |  | 
|---|
| 1403 | /* Return current position */ | 
|---|
| 1404 |  | 
|---|
| 1405 | return infoPtr->CurVal; | 
|---|
| 1406 | } | 
|---|
| 1407 | /************************************************************************* | 
|---|
| 1408 | *           GetScrollInfo   (USER32.284) | 
|---|
| 1409 | * GetScrollInfo32 can be used to retrieve the position, upper bound, | 
|---|
| 1410 | * lower bound, and page size of a scrollbar control. | 
|---|
| 1411 | * | 
|---|
| 1412 | * RETURNS STD | 
|---|
| 1413 | */ | 
|---|
| 1414 | BOOL WINAPI GetScrollInfo( | 
|---|
| 1415 | HWND hwnd /* [I] Handle of window */ , | 
|---|
| 1416 | INT nBar /* [I] One of SB_HORZ, SB_VERT, or SB_CTL */, | 
|---|
| 1417 | LPSCROLLINFO info /* [IO] (info.fMask [I] specifies which values are to retrieve) */) | 
|---|
| 1418 | { | 
|---|
| 1419 | SCROLLBAR_INFO *infoPtr; | 
|---|
| 1420 |  | 
|---|
| 1421 | dprintf(("USER32: GetScrollInfo")); | 
|---|
| 1422 |  | 
|---|
| 1423 | if (!(infoPtr = SCROLL_GetInfoPtr(hwnd,nBar))) return FALSE; | 
|---|
| 1424 | if (info->fMask & ~(SIF_ALL | SIF_DISABLENOSCROLL)) return FALSE; | 
|---|
| 1425 | if ((info->cbSize != sizeof(*info)) && | 
|---|
| 1426 | (info->cbSize != sizeof(*info)-sizeof(info->nTrackPos))) return FALSE; | 
|---|
| 1427 |  | 
|---|
| 1428 | if (info->fMask & SIF_PAGE) info->nPage = infoPtr->Page; | 
|---|
| 1429 | if (info->fMask & SIF_POS) info->nPos = infoPtr->CurVal; | 
|---|
| 1430 | if ((info->fMask & SIF_TRACKPOS) && (info->cbSize == sizeof(*info))) | 
|---|
| 1431 | info->nTrackPos = (SCROLL_MovingThumb && SCROLL_TrackingWin == hwnd && SCROLL_TrackingBar == nBar) ? SCROLL_TrackingVal:infoPtr->CurVal; | 
|---|
| 1432 |  | 
|---|
| 1433 | if (info->fMask & SIF_RANGE) | 
|---|
| 1434 | { | 
|---|
| 1435 | info->nMin = infoPtr->MinVal; | 
|---|
| 1436 | info->nMax = infoPtr->MaxVal; | 
|---|
| 1437 | } | 
|---|
| 1438 | return (info->fMask & SIF_ALL) != 0; | 
|---|
| 1439 | } | 
|---|
| 1440 | /************************************************************************* | 
|---|
| 1441 | *           SetScrollPos   (USER32.502) | 
|---|
| 1442 | * | 
|---|
| 1443 | * RETURNS | 
|---|
| 1444 | *    Success: Scrollbar position | 
|---|
| 1445 | *    Failure: 0 | 
|---|
| 1446 | * | 
|---|
| 1447 | * REMARKS | 
|---|
| 1448 | *    Note the ambiguity when 0 is returned.  Use GetLastError | 
|---|
| 1449 | *    to make sure there was an error (and to know which one). | 
|---|
| 1450 | */ | 
|---|
| 1451 | INT WINAPI SetScrollPos( | 
|---|
| 1452 | HWND hwnd /* [I] Handle of window whose scrollbar will be affected */, | 
|---|
| 1453 | INT nBar /* [I] One of SB_HORZ, SB_VERT, or SB_CTL */, | 
|---|
| 1454 | INT nPos /* [I] New value */, | 
|---|
| 1455 | BOOL bRedraw /* [I] Should scrollbar be redrawn afterwards ? */ ) | 
|---|
| 1456 | { | 
|---|
| 1457 | SCROLLINFO info; | 
|---|
| 1458 | SCROLLBAR_INFO *infoPtr; | 
|---|
| 1459 | INT oldPos; | 
|---|
| 1460 |  | 
|---|
| 1461 | dprintf(("SetScrollPos %x %d %d %d", hwnd, nBar, nPos, bRedraw)); | 
|---|
| 1462 | if (!(infoPtr = SCROLL_GetInfoPtr(hwnd,nBar))) return 0; | 
|---|
| 1463 | oldPos      = infoPtr->CurVal; | 
|---|
| 1464 | info.cbSize = sizeof(info); | 
|---|
| 1465 | info.nPos   = nPos; | 
|---|
| 1466 | info.fMask  = SIF_POS; | 
|---|
| 1467 | SetScrollInfo( hwnd, nBar, &info, bRedraw ); | 
|---|
| 1468 | return oldPos; | 
|---|
| 1469 | } | 
|---|
| 1470 | /************************************************************************* | 
|---|
| 1471 | *           GetScrollPos   (USER32.285) | 
|---|
| 1472 | * | 
|---|
| 1473 | * RETURNS | 
|---|
| 1474 | *    Success: Current position | 
|---|
| 1475 | *    Failure: 0 | 
|---|
| 1476 | * | 
|---|
| 1477 | * REMARKS | 
|---|
| 1478 | *    Note the ambiguity when 0 is returned.  Use GetLastError | 
|---|
| 1479 | *    to make sure there was an error (and to know which one). | 
|---|
| 1480 | */ | 
|---|
| 1481 | INT WINAPI GetScrollPos( | 
|---|
| 1482 | HWND hwnd, /* [I] Handle of window */ | 
|---|
| 1483 | INT nBar /* [I] One of SB_HORZ, SB_VERT, or SB_CTL */) | 
|---|
| 1484 | { | 
|---|
| 1485 | SCROLLBAR_INFO *infoPtr; | 
|---|
| 1486 |  | 
|---|
| 1487 | dprintf(("GetScrollPos %x %d", hwnd, nBar)); | 
|---|
| 1488 |  | 
|---|
| 1489 | infoPtr = SCROLL_GetInfoPtr(hwnd,nBar); | 
|---|
| 1490 | if (!infoPtr) return 0; | 
|---|
| 1491 |  | 
|---|
| 1492 | return infoPtr->CurVal; | 
|---|
| 1493 | } | 
|---|
| 1494 |  | 
|---|
| 1495 | /************************************************************************* | 
|---|
| 1496 | *           SetScrollRange   (USER32.503) | 
|---|
| 1497 | * | 
|---|
| 1498 | * RETURNS STD | 
|---|
| 1499 | */ | 
|---|
| 1500 | BOOL WINAPI SetScrollRange( | 
|---|
| 1501 | HWND hwnd,   /* [I] Handle of window whose scrollbar will be affected */ | 
|---|
| 1502 | INT nBar,    /* [I] One of SB_HORZ, SB_VERT, or SB_CTL */ | 
|---|
| 1503 | INT MinVal,  /* [I] New minimum value */ | 
|---|
| 1504 | INT MaxVal,  /* [I] New maximum value */ | 
|---|
| 1505 | BOOL bRedraw /* [I] Should scrollbar be redrawn afterwards ? */) | 
|---|
| 1506 | { | 
|---|
| 1507 | SCROLLINFO info; | 
|---|
| 1508 |  | 
|---|
| 1509 | dprintf(("SetScrollRange %x %x %d %d %d", hwnd, nBar, MinVal, MaxVal, bRedraw)); | 
|---|
| 1510 |  | 
|---|
| 1511 | //This is what NT4 does | 
|---|
| 1512 | if ((MinVal > MaxVal) || | 
|---|
| 1513 | ((UINT)(MaxVal - MinVal) >= 0x80000000)) | 
|---|
| 1514 | { | 
|---|
| 1515 | dprintf(("Invalid range")); | 
|---|
| 1516 | SetLastError(ERROR_INVALID_SCROLLBAR_RANGE); | 
|---|
| 1517 | return FALSE; | 
|---|
| 1518 | } | 
|---|
| 1519 |  | 
|---|
| 1520 | info.cbSize = sizeof(info); | 
|---|
| 1521 | info.nMin   = MinVal; | 
|---|
| 1522 | info.nMax   = MaxVal; | 
|---|
| 1523 | info.fMask  = SIF_RANGE; | 
|---|
| 1524 | SetScrollInfo( hwnd, nBar, &info, bRedraw ); | 
|---|
| 1525 | return TRUE; | 
|---|
| 1526 | } | 
|---|
| 1527 |  | 
|---|
| 1528 | /************************************************************************* | 
|---|
| 1529 | *           GetScrollRange   (USER32.286) | 
|---|
| 1530 | * | 
|---|
| 1531 | * RETURNS STD | 
|---|
| 1532 | */ | 
|---|
| 1533 | BOOL WINAPI GetScrollRange( | 
|---|
| 1534 | HWND hwnd,   /* [I] Handle of window */ | 
|---|
| 1535 | INT nBar,    /* [I] One of SB_HORZ, SB_VERT, or SB_CTL  */ | 
|---|
| 1536 | LPINT lpMin, /* [O] Where to store minimum value */ | 
|---|
| 1537 | LPINT lpMax  /* [O] Where to store maximum value */) | 
|---|
| 1538 | { | 
|---|
| 1539 | SCROLLBAR_INFO *infoPtr; | 
|---|
| 1540 |  | 
|---|
| 1541 | infoPtr = SCROLL_GetInfoPtr(hwnd,nBar); | 
|---|
| 1542 | if (!infoPtr) | 
|---|
| 1543 | { | 
|---|
| 1544 | if (lpMin) lpMin = 0; | 
|---|
| 1545 | if (lpMax) lpMax = 0; | 
|---|
| 1546 | return FALSE; | 
|---|
| 1547 | } | 
|---|
| 1548 | if (lpMin) *lpMin = infoPtr->MinVal; | 
|---|
| 1549 | if (lpMax) *lpMax = infoPtr->MaxVal; | 
|---|
| 1550 | return TRUE; | 
|---|
| 1551 | } | 
|---|
| 1552 |  | 
|---|
| 1553 | /************************************************************************* | 
|---|
| 1554 | *           ShowScrollBar   (USER32.532) | 
|---|
| 1555 | * | 
|---|
| 1556 | * RETURNS STD | 
|---|
| 1557 | */ | 
|---|
| 1558 | BOOL WINAPI ShowScrollBar( | 
|---|
| 1559 | HWND hwnd,  /* [I] Handle of window whose scrollbar(s) will be affected   */ | 
|---|
| 1560 | INT nBar,   /* [I] One of SB_HORZ, SB_VERT, SB_BOTH or SB_CTL */ | 
|---|
| 1561 | BOOL fShow  /* [I] TRUE = show, FALSE = hide  */) | 
|---|
| 1562 | { | 
|---|
| 1563 | BOOL fShowH = (nBar == SB_HORZ) ? fShow : 0; | 
|---|
| 1564 | BOOL fShowV = (nBar == SB_VERT) ? fShow : 0; | 
|---|
| 1565 | DWORD dwStyle; | 
|---|
| 1566 |  | 
|---|
| 1567 | dprintf(("ShowScrollBar %04x %d %d\n", hwnd, nBar, fShow)); | 
|---|
| 1568 | if (!IsWindow(hwnd)) return FALSE; | 
|---|
| 1569 |  | 
|---|
| 1570 | dwStyle = GetWindowLongA(hwnd, GWL_STYLE); | 
|---|
| 1571 |  | 
|---|
| 1572 | //CB: does Win32 send a WM_STYLECHANGED message? | 
|---|
| 1573 | switch(nBar) | 
|---|
| 1574 | { | 
|---|
| 1575 | case SB_CTL: | 
|---|
| 1576 | ShowWindow(hwnd,fShow ? SW_SHOW:SW_HIDE); | 
|---|
| 1577 | return TRUE; | 
|---|
| 1578 |  | 
|---|
| 1579 | case SB_BOTH: | 
|---|
| 1580 | case SB_HORZ: | 
|---|
| 1581 | if (fShow) | 
|---|
| 1582 | { | 
|---|
| 1583 | fShowH = !(dwStyle & WS_HSCROLL); | 
|---|
| 1584 | SetWindowLongA(hwnd, GWL_STYLE, dwStyle | WS_HSCROLL); | 
|---|
| 1585 | } | 
|---|
| 1586 | else  /* hide it */ | 
|---|
| 1587 | { | 
|---|
| 1588 | fShowH = (dwStyle & WS_HSCROLL); | 
|---|
| 1589 | SetWindowLongA(hwnd, GWL_STYLE, dwStyle & ~WS_HSCROLL); | 
|---|
| 1590 | } | 
|---|
| 1591 | if( nBar == SB_HORZ ) | 
|---|
| 1592 | { | 
|---|
| 1593 | fShowV = FALSE; | 
|---|
| 1594 | break; | 
|---|
| 1595 | } | 
|---|
| 1596 | /* fall through */ | 
|---|
| 1597 |  | 
|---|
| 1598 | case SB_VERT: | 
|---|
| 1599 | if (fShow) | 
|---|
| 1600 | { | 
|---|
| 1601 | fShowV = !(dwStyle & WS_VSCROLL); | 
|---|
| 1602 | SetWindowLongA(hwnd, GWL_STYLE, dwStyle | WS_VSCROLL); | 
|---|
| 1603 | } | 
|---|
| 1604 | else  /* hide it */ | 
|---|
| 1605 | { | 
|---|
| 1606 | fShowV = (dwStyle & WS_VSCROLL); | 
|---|
| 1607 | SetWindowLongA(hwnd, GWL_STYLE, dwStyle & ~WS_VSCROLL); | 
|---|
| 1608 | } | 
|---|
| 1609 | if ( nBar == SB_VERT ) | 
|---|
| 1610 | fShowH = FALSE; | 
|---|
| 1611 | break; | 
|---|
| 1612 |  | 
|---|
| 1613 | default: | 
|---|
| 1614 | return TRUE;  /* Nothing to do! */ | 
|---|
| 1615 | } | 
|---|
| 1616 |  | 
|---|
| 1617 | if( fShowH || fShowV ) /* frame has been changed, let the window redraw itself */ | 
|---|
| 1618 | { | 
|---|
| 1619 | SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | 
|---|
| 1620 | | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED ); | 
|---|
| 1621 | } | 
|---|
| 1622 |  | 
|---|
| 1623 | return TRUE; | 
|---|
| 1624 | } | 
|---|
| 1625 |  | 
|---|
| 1626 | /************************************************************************* | 
|---|
| 1627 | *           EnableScrollBar   (USER32.171) | 
|---|
| 1628 | */ | 
|---|
| 1629 | BOOL WINAPI EnableScrollBar( HWND hwnd, INT nBar, UINT flags) | 
|---|
| 1630 | { | 
|---|
| 1631 | BOOL bFineWithMe; | 
|---|
| 1632 | SCROLLBAR_INFO *infoPtr; | 
|---|
| 1633 |  | 
|---|
| 1634 | dprintf(("EnableScrollBar %04x %d %d\n", hwnd, nBar, flags)); | 
|---|
| 1635 |  | 
|---|
| 1636 | flags &= ESB_DISABLE_BOTH; | 
|---|
| 1637 |  | 
|---|
| 1638 | if (nBar == SB_BOTH) | 
|---|
| 1639 | { | 
|---|
| 1640 | if (!(infoPtr = SCROLL_GetInfoPtr( hwnd, SB_VERT ))) return FALSE; | 
|---|
| 1641 | if (!(bFineWithMe = (infoPtr->flags == flags)) ) | 
|---|
| 1642 | { | 
|---|
| 1643 | infoPtr->flags = flags; | 
|---|
| 1644 | SCROLL_RefreshScrollBar( hwnd, SB_VERT, TRUE, TRUE ); | 
|---|
| 1645 | } | 
|---|
| 1646 | nBar = SB_HORZ; | 
|---|
| 1647 | } | 
|---|
| 1648 | else | 
|---|
| 1649 | bFineWithMe = TRUE; | 
|---|
| 1650 |  | 
|---|
| 1651 | if (!(infoPtr = SCROLL_GetInfoPtr( hwnd, nBar ))) return FALSE; | 
|---|
| 1652 | if (bFineWithMe && infoPtr->flags == flags) return FALSE; | 
|---|
| 1653 | infoPtr->flags = flags; | 
|---|
| 1654 |  | 
|---|
| 1655 | SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE ); | 
|---|
| 1656 | return TRUE; | 
|---|
| 1657 | } | 
|---|
| 1658 |  | 
|---|
| 1659 | BOOL WINAPI GetScrollBarInfo(HWND hwnd,LONG idObject,PSCROLLBARINFO psbi) | 
|---|
| 1660 | { | 
|---|
| 1661 | if (!psbi || (psbi->cbSize != sizeof(SCROLLBARINFO))) | 
|---|
| 1662 | { | 
|---|
| 1663 | SetLastError(ERROR_INVALID_PARAMETER); | 
|---|
| 1664 |  | 
|---|
| 1665 | return FALSE; | 
|---|
| 1666 | } | 
|---|
| 1667 |  | 
|---|
| 1668 | INT nBar,arrowSize; | 
|---|
| 1669 |  | 
|---|
| 1670 | switch (idObject) | 
|---|
| 1671 | { | 
|---|
| 1672 | case OBJID_CLIENT: | 
|---|
| 1673 | nBar = SB_CTL; | 
|---|
| 1674 | break; | 
|---|
| 1675 |  | 
|---|
| 1676 | case OBJID_HSCROLL: | 
|---|
| 1677 | nBar = SB_HORZ; | 
|---|
| 1678 | break; | 
|---|
| 1679 |  | 
|---|
| 1680 | case OBJID_VSCROLL: | 
|---|
| 1681 | nBar = SB_VERT; | 
|---|
| 1682 | break; | 
|---|
| 1683 |  | 
|---|
| 1684 | default: | 
|---|
| 1685 | return FALSE; | 
|---|
| 1686 | } | 
|---|
| 1687 |  | 
|---|
| 1688 | SCROLL_GetScrollBarRect(hwnd,nBar,&psbi->rcScrollBar,&arrowSize,&psbi->dxyLineButton,&psbi->xyThumbTop); | 
|---|
| 1689 | psbi->xyThumbBottom = psbi->xyThumbTop+psbi->dxyLineButton; | 
|---|
| 1690 | psbi->bogus = 0; //CB: undocumented! | 
|---|
| 1691 | psbi->rgstate[0] = IsWindowVisible(hwnd) ? STATE_SYSTEM_INVISIBLE:0; | 
|---|
| 1692 | psbi->rgstate[1] = psbi->rgstate[2] = psbi->rgstate[3] = psbi->rgstate[4] = psbi->rgstate[5] = psbi->rgstate[0]; //CB: todo | 
|---|
| 1693 |  | 
|---|
| 1694 | return TRUE; | 
|---|
| 1695 | } | 
|---|
| 1696 | //****************************************************************************** | 
|---|
| 1697 | //****************************************************************************** | 
|---|
| 1698 | BOOL SCROLLBAR_Register() | 
|---|
| 1699 | { | 
|---|
| 1700 | WNDCLASSA wndClass; | 
|---|
| 1701 |  | 
|---|
| 1702 | //SvL: Don't check this now | 
|---|
| 1703 | //    if (GlobalFindAtomA(SCROLLBARCLASSNAME)) return FALSE; | 
|---|
| 1704 |  | 
|---|
| 1705 | ZeroMemory(&wndClass,sizeof(WNDCLASSA)); | 
|---|
| 1706 | wndClass.style         = CS_GLOBALCLASS | CS_HREDRAW | CS_VREDRAW | CS_PARENTDC; | 
|---|
| 1707 | wndClass.lpfnWndProc   = (WNDPROC)ScrollBarWndProc; | 
|---|
| 1708 | wndClass.cbClsExtra    = 0; | 
|---|
| 1709 | wndClass.cbWndExtra    = sizeof(SCROLLBAR_INFO); | 
|---|
| 1710 | wndClass.hCursor       = LoadCursorA(0,IDC_ARROWA); | 
|---|
| 1711 | wndClass.hbrBackground = (HBRUSH)0; | 
|---|
| 1712 | wndClass.lpszClassName = SCROLLBARCLASSNAME; | 
|---|
| 1713 |  | 
|---|
| 1714 | return RegisterClassA(&wndClass); | 
|---|
| 1715 | } | 
|---|
| 1716 | //****************************************************************************** | 
|---|
| 1717 | //****************************************************************************** | 
|---|
| 1718 | BOOL SCROLLBAR_Unregister() | 
|---|
| 1719 | { | 
|---|
| 1720 | if (GlobalFindAtomA(SCROLLBARCLASSNAME)) | 
|---|
| 1721 | return UnregisterClassA(SCROLLBARCLASSNAME,(HINSTANCE)NULL); | 
|---|
| 1722 | else return FALSE; | 
|---|
| 1723 | } | 
|---|
| 1724 | //****************************************************************************** | 
|---|
| 1725 | //****************************************************************************** | 
|---|
| 1726 |  | 
|---|