2 * Copyright (c) 2000 Greg Haerr <greg@censoft.com>
3 * Portions Copyright (c) 1999, 2000, Wei Yongming.
4 * jmt: scrollbar thumb ported
6 * Microwindows win32 NonClient Scrollbars
8 #define MWINCLUDECOLORS//jmt: for color macros
14 #include <stdio.h>//printf
15 /* scrollbar status/positions*/
16 #define SBS_UNKNOWN 0x0000
17 #define SBS_LEFTARROW 0x0001
18 #define SBS_RIGHTARROW 0x0002
19 #define SBS_LEFTSPACE 0x0004
20 #define SBS_RIGHTSPACE 0x0008
21 #define SBS_HORZTHUMB 0x0010
22 #define SBS_UPARROW 0x0020
23 #define SBS_DOWNARROW 0x0040
24 #define SBS_UPSPACE 0x0080
25 #define SBS_DOWNSPACE 0x0100
26 #define SBS_VERTTHUMB 0x0200
27 #define SBS_MASK 0x03ff
28 #define SBS_DISABLED 0x4000
29 #define SBS_HIDE 0x8000
31 #define HSCROLLBARVISIBLE(hwnd) ((hwnd)->style & WS_HSCROLL)
32 #define VSCROLLBARVISIBLE(hwnd) ((hwnd)->style & WS_VSCROLL)
36 /****************************** Drawing Helpers *******************************/
38 Draw3DUpFrame(HDC hDC, int l, int t, int r, int b)
43 SetRect(&rc, l, t, r, b);
44 Draw3dBox(hDC, rc.left, rc.top,
45 rc.right-rc.left, rc.bottom-rc.top,
46 GetSysColor(COLOR_3DLIGHT),
47 GetSysColor(COLOR_WINDOWFRAME));
48 InflateRect(&rc, -1, -1);
49 Draw3dBox(hDC, rc.left, rc.top,
50 rc.right-rc.left, rc.bottom-rc.top,
51 GetSysColor(COLOR_BTNHIGHLIGHT),
52 GetSysColor(COLOR_BTNSHADOW));
53 InflateRect(&rc, -1, -1);
55 hbr = CreateSolidBrush(LTGRAY);
56 FillRect(hDC, &rc, hbr);
62 * Adjust client area smaller if scrollbars visible.
63 * Also, compute the NC hittest regions for the scrollbars.
66 MwAdjustNCScrollbars(HWND hwnd)
68 BOOL vertbar = VSCROLLBARVISIBLE(hwnd);
69 BOOL horzbar = HSCROLLBARVISIBLE(hwnd);
72 hwnd->clirect.right -= mwSYSMETRICS_CXVSCROLL;
74 hwnd->clirect.bottom -= mwSYSMETRICS_CYHSCROLL;
75 hwnd->vscroll.rc.left = hwnd->clirect.right;
76 hwnd->vscroll.rc.right = hwnd->clirect.right +
77 mwSYSMETRICS_CXVSCROLL;
78 hwnd->vscroll.rc.top = hwnd->clirect.top;
79 hwnd->vscroll.rc.bottom = hwnd->clirect.bottom;
81 SetRectEmpty(&hwnd->vscroll.rc);
84 hwnd->clirect.bottom -= mwSYSMETRICS_CYHSCROLL;
85 hwnd->hscroll.rc.top = hwnd->clirect.bottom;
86 hwnd->hscroll.rc.bottom = hwnd->clirect.bottom +
87 mwSYSMETRICS_CYHSCROLL;
88 hwnd->hscroll.rc.left = hwnd->clirect.left;
89 hwnd->hscroll.rc.right = hwnd->clirect.right;
91 SetRectEmpty(&hwnd->hscroll.rc);
95 wndGetBorder(HWND hwnd)
97 if (hwnd->style & WS_BORDER) {
98 if ((hwnd->style & WS_CAPTION) == WS_CAPTION)
99 return mwSYSMETRICS_CXFRAME;
100 return mwSYSMETRICS_CXBORDER;
106 wndGetVScrollBarRect (HWND hwnd, RECT* rcVBar)
108 if (hwnd->style & WS_VSCROLL) {
109 rcVBar->left = hwnd->winrect.right - mwSYSMETRICS_CXVSCROLL
110 - wndGetBorder (hwnd);
111 rcVBar->right = hwnd->winrect.right - wndGetBorder (hwnd);
112 rcVBar->top = hwnd->clirect.top;
113 rcVBar->bottom = hwnd->winrect.bottom - wndGetBorder (hwnd);
115 if (hwnd->style & WS_HSCROLL && !(hwnd->hscroll.status & SBS_HIDE))
116 rcVBar->bottom -= mwSYSMETRICS_CYHSCROLL;
125 wndGetHScrollBarRect (HWND hwnd, RECT* rcHBar)
127 if (hwnd->style & WS_HSCROLL) {
128 rcHBar->top = hwnd->winrect.bottom - mwSYSMETRICS_CYHSCROLL
129 - wndGetBorder (hwnd);
130 rcHBar->bottom = hwnd->winrect.bottom - wndGetBorder (hwnd);
131 rcHBar->left = hwnd->clirect.left;
132 rcHBar->right = hwnd->winrect.right - wndGetBorder (hwnd);
134 if (hwnd->style & WS_VSCROLL && !(hwnd->vscroll.status & SBS_HIDE))
135 rcHBar->right -= mwSYSMETRICS_CXVSCROLL;
144 MwPaintNCScrollbars(HWND hwnd, HDC hdc)
146 BOOL vertbar = VSCROLLBARVISIBLE(hwnd);
147 BOOL horzbar = HSCROLLBARVISIBLE(hwnd);
158 if (!hdc && (horzbar || vertbar)) {
159 hdc = GetWindowDC(hwnd);
163 if (horzbar && vertbar) {
164 rc.left = hwnd->clirect.right;
165 rc.top = hwnd->clirect.bottom;
166 rc.right = rc.left + mwSYSMETRICS_CXVSCROLL;
167 rc.bottom = rc.top + mwSYSMETRICS_CYHSCROLL;
168 FillRect(hdc, &rc, (HBRUSH)(COLOR_BTNFACE+1));
171 rc = hwnd->vscroll.rc;
174 FillRect(hdc, &rc, (HBRUSH)(COLOR_BTNFACE+1));
177 Draw3dUpDownState(hdc, rc.left, rc.top,
178 mwSYSMETRICS_CXVSCROLL, mwSYSMETRICS_CYHSCROLL,
179 hwnd->vscroll.status & SBS_UPARROW);
181 Draw3dUpDownState(hdc, rc.left,rc.bottom-mwSYSMETRICS_CYHSCROLL,
182 mwSYSMETRICS_CXVSCROLL, mwSYSMETRICS_CYHSCROLL,
183 hwnd->vscroll.status & SBS_DOWNARROW);
184 #if 1//jmt: draw arrows
185 SelectObject(hdc,GetStockObject(BLACK_BRUSH));
187 p3[0].x= rc.left + (mwSYSMETRICS_CXVSCROLL/2) - 1;
188 p3[0].y= rc.top + 2 + shrink;
189 p3[1].x= rc.left + 2 + shrink - 1;
190 p3[1].y= rc.top + (mwSYSMETRICS_CYHSCROLL-4) - shrink;
191 p3[2].x= rc.left + (mwSYSMETRICS_CXVSCROLL-4) - shrink;
192 p3[2].y= rc.top + (mwSYSMETRICS_CYHSCROLL-4) - shrink;
195 p3[0].x= rc.left + (mwSYSMETRICS_CXVSCROLL/2) - 1;
196 p3[0].y= rc.bottom - 4 - shrink;
197 p3[1].x= rc.left + 2 + shrink - 1;
198 p3[1].y= rc.bottom-mwSYSMETRICS_CYHSCROLL + 2 + shrink;
199 p3[2].x= rc.left + (mwSYSMETRICS_CXVSCROLL-4) - shrink;
200 p3[2].y= rc.bottom-mwSYSMETRICS_CYHSCROLL + 2 + shrink;
206 wndGetVScrollBarRect (hwnd, &rcVBar);
210 start = rcVBar.top + mwSYSMETRICS_CYVSCROLL + hwnd->vscroll.barStart;
212 if (start + hwnd->vscroll.barLen > rcVBar.bottom)
213 start = rcVBar.bottom - hwnd->vscroll.barLen;
215 if (hwnd->vscroll.barLen == 0)
216 hwnd->vscroll.barLen=rc.bottom-rc.top-(mwSYSMETRICS_CYVSCROLL*2);
219 rc2.left=rc.left; rc2.right=rc.right/*-1*/;
220 rc2.top=rc.top+mwSYSMETRICS_CYHSCROLL;
222 if (rc2.bottom>rc2.top)
223 FillRect(hdc, &rc2, (HBRUSH)GetStockObject(DKGRAY_BRUSH));
225 rc2.top=start+hwnd->vscroll.barLen;
226 rc2.bottom=rc.bottom-mwSYSMETRICS_CYHSCROLL;
227 if (rc2.bottom>rc2.top)
228 FillRect(hdc, &rc2, (HBRUSH)GetStockObject(DKGRAY_BRUSH));
230 Draw3DUpFrame (hdc, rcVBar.left, start, rcVBar.right,
231 start + hwnd->vscroll.barLen);
233 printf("barv:(l,t,r,b):(%d,%d,%d,%d)\n",
234 rcVBar.left, start, rcVBar.right,
235 start + hwnd->vscroll.barLen);
240 rc = hwnd->hscroll.rc;
243 FillRect(hdc, &rc, (HBRUSH)(COLOR_BTNFACE+1));
246 Draw3dUpDownState(hdc, rc.left, rc.top,
247 mwSYSMETRICS_CXVSCROLL, mwSYSMETRICS_CYHSCROLL,
248 hwnd->hscroll.status & SBS_LEFTARROW);
250 Draw3dUpDownState(hdc, rc.right-mwSYSMETRICS_CXVSCROLL, rc.top,
251 mwSYSMETRICS_CXVSCROLL, mwSYSMETRICS_CYHSCROLL,
252 hwnd->hscroll.status & SBS_RIGHTARROW);
253 #if 1//jmt: draw arrows
254 SelectObject(hdc,GetStockObject(BLACK_BRUSH));
256 p3[0].x= rc.left + 2 + shrink;
257 p3[0].y= rc.top + (mwSYSMETRICS_CYHSCROLL/2) ;
258 p3[1].x= rc.left + (mwSYSMETRICS_CXVSCROLL-4) - shrink ;
259 p3[1].y= rc.top + 2 + shrink;
260 p3[2].x= rc.left + (mwSYSMETRICS_CXVSCROLL-4) - shrink;
261 p3[2].y= rc.bottom - 4 - shrink + 1;
264 p3[0].x= rc.right - 4 - shrink;
265 p3[0].y= rc.top + (mwSYSMETRICS_CYHSCROLL/2) ;
266 p3[1].x= rc.right-mwSYSMETRICS_CXVSCROLL + 2 + shrink ;
267 p3[1].y= rc.top + 2 + shrink;
268 p3[2].x= rc.right-mwSYSMETRICS_CXVSCROLL + 2 + shrink;
269 p3[2].y= rc.bottom - 4 - shrink + 1;
275 wndGetHScrollBarRect (hwnd, &rcHBar);
279 start = rcHBar.left + mwSYSMETRICS_CXHSCROLL + hwnd->hscroll.barStart;
281 if (start + hwnd->hscroll.barLen > rcHBar.right)
282 start = rcHBar.right - hwnd->hscroll.barLen;
284 if (hwnd->hscroll.barLen == 0)
285 hwnd->hscroll.barLen=rc.right-rc.left-(mwSYSMETRICS_CXHSCROLL*2);
288 rc2.top=rc.top; rc2.bottom=rc.bottom/*-1*/;
289 rc2.left=rc.left+mwSYSMETRICS_CXVSCROLL;
291 if (rc2.right>rc2.left)
292 FillRect(hdc, &rc2, (HBRUSH)GetStockObject(DKGRAY_BRUSH));
294 rc2.left=start+hwnd->hscroll.barLen;
295 rc2.right=rc.right-mwSYSMETRICS_CXVSCROLL;
296 if (rc2.right>rc2.left)
297 FillRect(hdc, &rc2, (HBRUSH)GetStockObject(DKGRAY_BRUSH));
299 Draw3DUpFrame (hdc, start, rcHBar.top, start + hwnd->hscroll.barLen,
302 printf("barh:(l,t,r,b):(%d,%d,%d,%d)\n",
303 start, rcHBar.top, start + hwnd->hscroll.barLen,
310 ReleaseDC(hwnd, hdc);
313 /* handle a non-client message for a scrollbar*/
315 MwHandleNCMessageScrollbar(HWND hwnd, WPARAM hitcode, LPARAM lParam, UINT msg/*BOOL fDown*/)
317 int pos = SBS_UNKNOWN;
318 BOOL vertbar = VSCROLLBARVISIBLE(hwnd);
319 BOOL horzbar = HSCROLLBARVISIBLE(hwnd);
326 static int downPos = SBS_UNKNOWN;//
330 int itemMoveable,itemCount,itemVisible,moveRange;//jmt:2k0819
331 int moveTop,moveBottom,moveLeft,moveRight;//jmt:2k0819
333 POINTSTOPOINT(pt, lParam);
334 for (;;) { /* use for() to allow break statement*/
335 if (hitcode == HTVSCROLL && vertbar)
337 pStat = &hwnd->vscroll.status;
338 rc = hwnd->vscroll.rc;
339 rc.bottom = rc.top + mwSYSMETRICS_CYVSCROLL;
340 if (PtInRect(&rc, pt))
345 rc.bottom = hwnd->vscroll.rc.bottom;
346 rc.top = rc.bottom - mwSYSMETRICS_CYVSCROLL;
347 if (PtInRect(&rc, pt))
353 } else if (hitcode == HTHSCROLL && horzbar)
355 pStat = &hwnd->hscroll.status;
356 rc = hwnd->hscroll.rc;
357 rc.right = rc.left + mwSYSMETRICS_CXHSCROLL;
358 if (PtInRect(&rc, pt)) {
362 rc.right = hwnd->hscroll.rc.right;
363 rc.left = rc.right - mwSYSMETRICS_CXHSCROLL;
364 if (PtInRect(&rc, pt)) {
365 pos = SBS_RIGHTARROW;
374 if (pos == SBS_UNKNOWN)
377 *pStat &= ~SBS_MASK; /* remove stray mouse states*/
379 if (msg == WM_NCLBUTTONDOWN || msg == WM_NCLBUTTONDBLCLK)//jmt:2k0819
383 if (msg == WM_NCLBUTTONDOWN || msg == WM_NCLBUTTONDBLCLK)//jmt:2k0819
387 MwPaintNCScrollbars(hwnd, NULL);
389 if (pos == SBS_UPARROW || pos == SBS_LEFTARROW)//jmt:2k0820
391 if (hwnd->vscroll.curPos != hwnd->vscroll.minPos)
394 else if (pos == SBS_DOWNARROW || pos == SBS_RIGHTARROW)//jmt:2k0820
396 if (hwnd->vscroll.curPos != hwnd->vscroll.maxPos)
397 sbCode = SB_LINEDOWN;
399 else if (pos == SBS_VERTTHUMB || pos == SBS_HORZTHUMB)//
401 sbCode = SB_THUMBTRACK;//
406 case WM_NCLBUTTONDOWN:
407 case WM_NCLBUTTONDBLCLK://jmt:2k0819
411 case WM_NCMOUSEMOVE://jmt:2k0819
412 if (hitcode == HTVSCROLL && vertbar)
414 if (sbCode == SB_THUMBTRACK && downPos == SBS_VERTTHUMB)//
416 //jmt(2k0819): new algorithm for SB_THUMBTRACK
418 rc = hwnd->vscroll.rc;
419 moveTop = rc.top + mwSYSMETRICS_CYVSCROLL;
420 moveBottom = hwnd->vscroll.rc.bottom - mwSYSMETRICS_CYVSCROLL;
421 moveRange = moveBottom - moveTop;
423 itemCount = hwnd->vscroll.maxPos - hwnd->vscroll.minPos + 1;
424 itemVisible = hwnd->vscroll.pageStep;
425 itemMoveable = itemCount - itemVisible + 1;
427 newThumbPos = ((pt.y - moveTop) * itemMoveable) / moveRange;
428 printf("((%d-%d)*%d)/%d=%d\n",
429 pt.y,moveTop,itemMoveable,moveRange,newThumbPos);
432 if ( newThumbPos >= hwnd->vscroll.minPos &&
433 newThumbPos <= hwnd->vscroll.maxPos)
435 WM_VSCROLL, SB_THUMBTRACK, newThumbPos);
440 if (hitcode == HTHSCROLL && horzbar)
442 if (sbCode == SB_THUMBTRACK && downPos == SBS_HORZTHUMB)//
444 //jmt(2k0819): new algorithm for SB_THUMBTRACK
446 rc = hwnd->hscroll.rc;
447 moveLeft = rc.left + mwSYSMETRICS_CXHSCROLL;
448 moveRight = hwnd->hscroll.rc.right - mwSYSMETRICS_CXHSCROLL;
449 moveRange = moveRight - moveLeft;
451 itemCount = hwnd->hscroll.maxPos - hwnd->hscroll.minPos + 1;
452 itemVisible = hwnd->hscroll.pageStep;
453 itemMoveable = itemCount - itemVisible + 1;
455 newThumbPos = ((pt.x - moveLeft) * itemMoveable) / moveRange;
456 printf("((%d-%d)*%d)/%d=%d\n",
457 pt.y,moveLeft,itemMoveable,moveRange,newThumbPos);
460 if ( newThumbPos >= hwnd->hscroll.minPos &&
461 newThumbPos <= hwnd->hscroll.maxPos)
463 WM_HSCROLL, SB_THUMBTRACK, newThumbPos);
470 case WM_NCLBUTTONUP://jmt:2k0819
472 downPos = SBS_UNKNOWN;//
474 if (sbCode==SB_THUMBTRACK)
476 if (hitcode == HTVSCROLL && vertbar)
478 //jmt(2k0819): new algorithm for SB_THUMBTRACK
480 rc = hwnd->vscroll.rc;
481 moveTop = rc.top + mwSYSMETRICS_CYVSCROLL;
482 moveBottom = hwnd->vscroll.rc.bottom - mwSYSMETRICS_CYVSCROLL;
483 moveRange = moveBottom - moveTop;
485 itemCount = hwnd->vscroll.maxPos - hwnd->vscroll.minPos + 1;
486 itemVisible = hwnd->vscroll.pageStep;
487 itemMoveable = itemCount - itemVisible + 1;
489 newThumbPos = ((pt.y - moveTop) * itemMoveable) / moveRange;
490 printf("((%d-%d)*%d)/%d=%d\n",
491 pt.y,moveTop,itemMoveable,moveRange,newThumbPos);
493 if ( newThumbPos >= hwnd->vscroll.minPos &&
494 newThumbPos <= hwnd->vscroll.maxPos)
496 WM_VSCROLL, SB_THUMBTRACK, newThumbPos);
500 if (hitcode == HTHSCROLL && horzbar)
502 //jmt(2k0819): new algorithm for SB_THUMBTRACK
504 rc = hwnd->hscroll.rc;
505 moveLeft = rc.left + mwSYSMETRICS_CXHSCROLL;
506 moveRight = hwnd->hscroll.rc.right - mwSYSMETRICS_CXHSCROLL;
507 moveRange = moveRight - moveLeft;
509 itemCount = hwnd->hscroll.maxPos - hwnd->hscroll.minPos + 1;
510 itemVisible = hwnd->hscroll.pageStep;
511 itemMoveable = itemCount - itemVisible + 1;
513 newThumbPos = ((pt.x - moveLeft) * itemMoveable) / moveRange;
514 printf("((%d-%d)*%d)/%d=%d\n",
515 pt.y,moveLeft,itemMoveable,moveRange,newThumbPos);
518 if ( newThumbPos >= hwnd->hscroll.minPos &&
519 newThumbPos <= hwnd->hscroll.maxPos)
521 WM_HSCROLL, SB_THUMBTRACK, newThumbPos);
527 if (hitcode == HTVSCROLL && vertbar)
528 SendMessage (hwnd, WM_VSCROLL, sbCode, 0);
530 if (hitcode == HTHSCROLL && horzbar)
531 SendMessage (hwnd, WM_HSCROLL, sbCode, 0);
540 PtInRect2(const RECT *lprc, int x, int y)
546 return PtInRect(lprc, p);
553 wndScrollBarPos (HWND hwnd, BOOL bIsHBar, RECT* rcBar)
556 PMWSCROLLBARINFO pSBar;
559 pSBar = &hwnd->hscroll;
561 pSBar = &hwnd->vscroll;
563 if (pSBar->minPos == pSBar->maxPos) {
564 pSBar->status |= SBS_HIDE;
569 moveRange = (rcBar->right - rcBar->left) - (mwSYSMETRICS_CXHSCROLL<<1);
571 moveRange = (rcBar->bottom - rcBar->top) - (mwSYSMETRICS_CYVSCROLL<<1);
573 #define MWM_DEFBARLEN 18//
574 #define MWM_MINBARLEN 8//
576 if (pSBar->pageStep == 0)
578 pSBar->barLen = MWM_DEFBARLEN;
580 if (pSBar->barLen > moveRange)
581 pSBar->barLen = MWM_MINBARLEN;
585 pSBar->barLen = moveRange * pSBar->pageStep /
586 (pSBar->maxPos - pSBar->minPos + 1);
587 if (pSBar->barLen < MWM_MINBARLEN)
588 pSBar->barLen = MWM_MINBARLEN;
591 pSBar->barStart = moveRange * (pSBar->curPos - pSBar->minPos) /
592 (pSBar->maxPos - pSBar->minPos + 1);
595 if (pSBar->barStart + pSBar->barLen > moveRange)
596 pSBar->barStart = moveRange - pSBar->barLen;
599 if (pSBar->barStart < 0)
603 static PMWSCROLLBARINFO wndGetScrollBar (HWND pWin, int iSBar)
605 if (iSBar == SB_HORZ) {
606 if (pWin->style & WS_HSCROLL)
607 return &pWin->hscroll;
609 else if (iSBar == SB_VERT) {
610 if (pWin->style & WS_VSCROLL)
611 return &pWin->vscroll;
617 BOOL EnableScrollBar (HWND hWnd, int iSBar, BOOL bEnable)
619 PMWSCROLLBARINFO pSBar;
626 if ( !(pSBar = wndGetScrollBar (pWin, iSBar)) )//ok
629 bPrevState = !(pSBar->status & SBS_DISABLED);
631 if (bEnable && !bPrevState)
632 pSBar->status &= ~SBS_DISABLED;
633 else if (!bEnable && bPrevState)
634 pSBar->status |= SBS_DISABLED;
638 if (iSBar == SB_VERT)
640 wndGetVScrollBarRect (pWin, &rcBar);
646 wndGetHScrollBarRect (pWin, &rcBar);
651 SendMessage (hWnd, WM_NCPAINT, 0, (LPARAM)(&rcBar));
653 MwPaintNCScrollbars(hWnd,NULL);//a must
659 BOOL GetScrollPos (HWND hWnd, int iSBar, int* pPos)
661 PMWSCROLLBARINFO pSBar;
666 if ( !(pSBar = wndGetScrollBar (pWin, iSBar)) )
669 *pPos = pSBar->curPos;
673 BOOL GetScrollRange (HWND hWnd, int iSBar, int* pMinPos, int* pMaxPos)
675 PMWSCROLLBARINFO pSBar;
680 if ( !(pSBar = wndGetScrollBar (pWin, iSBar)) )
683 *pMinPos = pSBar->minPos;
684 *pMaxPos = pSBar->maxPos;
688 BOOL SetScrollPos (HWND hWnd, int iSBar, int iNewPos)//ok
690 PMWSCROLLBARINFO pSBar;
696 if ( !(pSBar = wndGetScrollBar (pWin, iSBar)) )
699 if (iNewPos < pSBar->minPos)
700 pSBar->curPos = pSBar->minPos;
702 pSBar->curPos = iNewPos;
705 int max = pSBar->maxPos;
706 max -= ((pSBar->pageStep - 1) > 0)?(pSBar->pageStep - 1):0;
708 if (pSBar->curPos > max)
712 if (iSBar == SB_VERT)
714 wndGetVScrollBarRect (pWin, &rcBar);
720 wndGetHScrollBarRect (pWin, &rcBar);
725 wndScrollBarPos (pWin, iSBar == SB_HORZ, &rcBar);
728 SendMessage (hWnd, WM_NCPAINT, 0, (LPARAM)(&rcBar));
730 MwPaintNCScrollbars(hWnd,NULL);//a must
735 BOOL SetScrollRange (HWND hWnd, int iSBar, int iMinPos, int iMaxPos)
737 PMWSCROLLBARINFO pSBar;
743 if ( !(pSBar = wndGetScrollBar (pWin, iSBar)) )
746 pSBar->minPos = (iMinPos < iMaxPos)?iMinPos:iMaxPos;
747 pSBar->maxPos = (iMinPos > iMaxPos)?iMinPos:iMaxPos;
749 // validate parameters.
750 if (pSBar->curPos < pSBar->minPos)
751 pSBar->curPos = pSBar->minPos;
753 if (pSBar->pageStep <= 0)
755 else if (pSBar->pageStep > (pSBar->maxPos - pSBar->minPos + 1))
756 pSBar->pageStep = pSBar->maxPos - pSBar->minPos + 1;
759 int max = pSBar->maxPos;
760 max -= ((pSBar->pageStep - 1) > 0)?(pSBar->pageStep - 1):0;
762 if (pSBar->curPos > max)
766 if (iSBar == SB_VERT)
768 wndGetVScrollBarRect (pWin, &rcBar);
774 wndGetHScrollBarRect (pWin, &rcBar);
778 wndScrollBarPos (pWin, iSBar == SB_HORZ, &rcBar);
781 SendMessage (hWnd, WM_NCPAINT, 0, (LPARAM)(&rcBar));
783 MwPaintNCScrollbars(hWnd,NULL);//a must
789 BOOL SetScrollInfo (HWND hWnd, int iSBar,
790 LPCSCROLLINFO lpsi, BOOL fRedraw)//ok
792 PMWSCROLLBARINFO pSBar;
798 if ( !(pSBar = wndGetScrollBar (pWin, iSBar)) )
801 if( lpsi->fMask & SIF_RANGE )
803 pSBar->minPos = (lpsi->nMin < lpsi->nMax)?lpsi->nMin:lpsi->nMax;
804 pSBar->maxPos = (lpsi->nMin < lpsi->nMax)?lpsi->nMax:lpsi->nMin;
807 if( lpsi->fMask & SIF_POS )
808 pSBar->curPos = lpsi->nPos;
810 if( lpsi->fMask & SIF_PAGE )
811 pSBar->pageStep = lpsi->nPage;
813 // validate parameters.
814 if (pSBar->curPos < pSBar->minPos)
815 pSBar->curPos = pSBar->minPos;
817 if (pSBar->pageStep <= 0)
819 else if (pSBar->pageStep > (pSBar->maxPos - pSBar->minPos + 1))
820 pSBar->pageStep = pSBar->maxPos - pSBar->minPos + 1;
823 int max = pSBar->maxPos;
824 max -= ((pSBar->pageStep - 1) > 0)?(pSBar->pageStep - 1):0;
826 if (pSBar->curPos > max)
832 if (iSBar == SB_VERT)
834 wndGetVScrollBarRect (pWin, &rcBar);
840 wndGetHScrollBarRect (pWin, &rcBar);
844 wndScrollBarPos (pWin, iSBar == SB_HORZ, &rcBar);
847 SendMessage (hWnd, WM_NCPAINT, 0, (LPARAM)(&rcBar));
849 MwPaintNCScrollbars(hWnd,NULL);//a must
856 BOOL GetScrollInfo(HWND hWnd, int iSBar, LPSCROLLINFO lpsi)
858 PMWSCROLLBARINFO pSBar;
863 if ( !(pSBar = wndGetScrollBar (pWin, iSBar)) )
866 if( lpsi->fMask & SIF_RANGE )
868 lpsi->nMin = pSBar->minPos;
869 lpsi->nMax = pSBar->maxPos;
872 if( lpsi->fMask & SIF_POS )
874 lpsi->nPos = pSBar->curPos;
877 if( lpsi->fMask & SIF_PAGE )
878 lpsi->nPage = pSBar->pageStep;
883 BOOL ShowScrollBar (HWND hWnd, int iSBar, BOOL bShow)
885 PMWSCROLLBARINFO pSBar;
892 if ( !(pSBar = wndGetScrollBar (pWin, iSBar)) )
895 bPrevState = !(pSBar->status & SBS_HIDE);
897 if (bShow && !bPrevState)
898 pSBar->status &= ~SBS_HIDE;
899 else if (!bShow && bPrevState)
900 pSBar->status |= SBS_HIDE;
903 #if 0//fix: no WM_CHANGESIZE
904 SendMessage (hWnd, WM_CHANGESIZE, 0, 0);
906 if (iSBar == SB_VERT)
907 wndGetVScrollBarRect (pWin, &rcBar);
909 wndGetHScrollBarRect (pWin, &rcBar);
912 RECT rcWin, rcClient;
914 memcpy (&rcWin, &pWin->winrect.left, sizeof (RECT));
918 rcClient.right = pWin->clirect.right - pWin->clirect.left;
919 rcClient.bottom = pWin->clirect.bottom - pWin->clirect.top;
920 #if 0//fix: no WM_SIZECHANGED
921 SendMessage/*SendAsyncMessage*/ (hWnd, WM_SIZECHANGED,
922 (WPARAM)&rcWin, (LPARAM)&rcClient);
927 SendMessage (hWnd, WM_NCPAINT, 0, 0);
930 rcBar.left -= pWin->clirect.left;
931 rcBar.top -= pWin->clirect.top;
932 rcBar.right -= pWin->clirect.left;
933 rcBar.bottom -= pWin->clirect.top;
934 SendMessage (hWnd, WM_NCPAINT, 0, 0);
935 InvalidateRect (hWnd, &rcBar, TRUE);