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