Beispiel #1
0
BOOL WINAPI
SetScrollRangeEx (HWND hWnd, int iSBar, int iMinPos, int iMaxPos)	/* jmt: iSBar not used */
{
    PMWSCROLLBARINFO pSBar;
    HWND pWin;
    RECT rcBar;
    
    DWORD dwStyle;	/* jmt:2k0820 */

    pWin = (HWND)hWnd;
    
    if ( !(pSBar = wndGetScrollbar (pWin)) )
        return FALSE;

    pSBar->minPos = (iMinPos < iMaxPos)?iMinPos:iMaxPos;
    pSBar->maxPos = (iMinPos > iMaxPos)?iMinPos:iMaxPos;
    
    /* validate parameters. */
    if (pSBar->curPos < pSBar->minPos)
        pSBar->curPos = pSBar->minPos;

    if (pSBar->pageStep <= 0)
        pSBar->pageStep = 0;
    else if (pSBar->pageStep > (pSBar->maxPos - pSBar->minPos + 1))
        pSBar->pageStep = pSBar->maxPos - pSBar->minPos + 1;
    
    {
        int max = pSBar->maxPos;
        max -= ((pSBar->pageStep - 1) > 0)?(pSBar->pageStep - 1):0;

        if (pSBar->curPos > max)
            pSBar->curPos = max;
    }

    dwStyle = (GetWindowStyle (hWnd) & SBS_TYPEMASK);	/* jmt: 2k0820 */

    if (dwStyle == SBS_VERT)
    {
        wndGetVScrollbarRect (pWin, &rcBar);
    	rcBar.left --;
      	rcBar.right --;
    }
    else
    {
        wndGetHScrollbarRect (pWin, &rcBar);
    	rcBar.top  --;
    	rcBar.bottom --;
    }
    wndScrollbarPos (pWin, dwStyle == SBS_HORZ, &rcBar);

#if 0
    SendMessage (hWnd, WM_NCPAINT, 0, (LPARAM)(&rcBar));
#else
    MwPaintScrollbars(hWnd,NULL,dwStyle);	/* a must */
#endif

    return TRUE;
}
Beispiel #2
0
BOOL SetScrollPosEx (HWND hWnd, int iSBar, int iNewPos)	/* jmt: iSBar not used */
{
    PMWSCROLLBARINFO pSBar;
    HWND pWin;
    RECT rcBar;
    
    DWORD dwStyle;	/* jmt:2k0820 */

    pWin = (HWND)hWnd;
    
    if ( !(pSBar = wndGetScrollBar (pWin)) )
        return FALSE;

    if (iNewPos < pSBar->minPos)
        pSBar->curPos = pSBar->minPos;
    else
        pSBar->curPos = iNewPos;

    {
        int max = pSBar->maxPos;
        max -= ((pSBar->pageStep - 1) > 0)?(pSBar->pageStep - 1):0;

        if (pSBar->curPos > max)
            pSBar->curPos = max;
    }
    
    dwStyle = (GetWindowStyle (hWnd) & SBS_TYPEMASK);	/* jmt: 2k0820 */

    if (dwStyle == SBS_VERT)
    {
        wndGetVScrollBarRect (pWin, &rcBar);
        rcBar.left --;
        rcBar.right --;
    }
    else
    {
        wndGetHScrollBarRect (pWin, &rcBar);
        rcBar.top  --;
        rcBar.bottom --;
    }

    wndScrollBarPos (pWin, dwStyle == SBS_HORZ, &rcBar);

#if 0
    SendMessage (hWnd, WM_NCPAINT, 0, (LPARAM)(&rcBar));
#else
    MwPaintScrollbars(hWnd,NULL,dwStyle);	/* a must */
#endif
    return TRUE;
}
Beispiel #3
0
BOOL WINAPI
EnableScrollBarEx (HWND hWnd, int iSBar, BOOL bEnable)	/* jmt: iSBar not used */
{
    PMWSCROLLBARINFO pSBar;
    HWND pWin;
    BOOL bPrevState;
    RECT rcBar;
    
    DWORD dwStyle;	/* jmt:2k0820 */

    pWin = (HWND)hWnd;
    
    if ( !(pSBar = wndGetScrollbar (pWin)) )
        return FALSE;

    bPrevState = !(pSBar->status & SBS_DISABLED);

    if (bEnable && !bPrevState)
        pSBar->status &= ~SBS_DISABLED;
    else if (!bEnable && bPrevState)
        pSBar->status |= SBS_DISABLED;
    else
        return FALSE;

    dwStyle = (GetWindowStyle (hWnd) & SBS_TYPEMASK);	/* jmt: 2k0820 */

    if (dwStyle == SBS_VERT)
    {
        wndGetVScrollbarRect (pWin, &rcBar);
        rcBar.left --;
        rcBar.right --;
    }
    else
    {
        wndGetHScrollbarRect (pWin, &rcBar);
        rcBar.top  --;
        rcBar.bottom --;
    }
#if 0
    SendMessage (hWnd, WM_NCPAINT, 0, (LPARAM)(&rcBar));
#else
    MwPaintScrollbars(hWnd,NULL,dwStyle);	/* a must */
#endif

    return TRUE;
}
Beispiel #4
0
static LRESULT CALLBACK
ScrollbarControlProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)	/* jmt:2k0820 */
{
    	DWORD dwStyle;
    	MWSCROLLBARINFO* pData;

	int moveRange;
	RECT rcBar;

	dwStyle = (GetWindowStyle (hwnd) & SBS_TYPEMASK);
    	switch (message) 
	{
        case WM_CREATE:
            	if (!(pData = malloc (sizeof (MWSCROLLBARINFO)))) 
		{
                	fprintf(stderr, "Create scroll bar control failure!\n");
                	return -1;
            	}

		pData->minPos=0;           /* min value of scroll range.*/
		/* max value of scroll range.*/
		pData->maxPos=0;     
		if  (dwStyle==SBS_VERT)
			moveRange=((hwnd->winrect.bottom-hwnd->winrect.top)
				-((hwnd->winrect.right-hwnd->winrect.left)<<1));
		else
			moveRange=((hwnd->winrect.right-hwnd->winrect.left)
				-((hwnd->winrect.bottom-hwnd->winrect.top)<<1));
		if (moveRange > MWM_MINBARLEN)
		{


			pData->maxPos=moveRange / MWM_MINBARLEN;
			if( (moveRange % MWM_MINBARLEN) )
				pData->maxPos++;
		}     
		printf("maxPos=%d\n",pData->maxPos);

		pData->curPos=0;             /* current scroll pos.*/

		/* steps per page.*/
		pData->pageStep=1;
		if ( (pData->maxPos - 2) > 1)
			pData->pageStep = pData->maxPos - 2;
		printf("pageStep=%d\n",pData->pageStep);

		pData->barStart=0;           /* start pixel of bar.*/
		pData->barLen=MWM_MINBARLEN; /* length of bar.*/
		pData->status=SBS_UNKNOWN;   /* status of scroll bar.*/
#if 0	/* jmt: must handle WM_MOVE */
		pData->rc=hwnd->winrect;   /* screen coordinates position*/
#endif
            	hwnd->userdata = (DWORD)pData;

		if (dwStyle == SBS_VERT)
		{
		    wndGetVScrollBarRect (hwnd, &rcBar);
		    rcBar.left --;
		    rcBar.right --;
		}
		else
		{
		    wndGetHScrollBarRect (hwnd, &rcBar);
		    rcBar.top --;
		    rcBar.bottom --;
		}
		/* adjust pData->barLen */
		wndScrollBarPos (hwnd, dwStyle == SBS_HORZ, &rcBar);

        	break;
            
        case WM_DESTROY: 
            	free ((void *)(hwnd->userdata));
            	break;

        case WM_PAINT:
		MwPaintScrollbars(hwnd,NULL,dwStyle);
            	break;
	
	case WM_NCLBUTTONDOWN:
	case WM_NCLBUTTONDBLCLK:
	case WM_NCMOUSEMOVE:
	case WM_NCLBUTTONUP:
		MwHandleMessageScrollbar(hwnd, wParam, lParam, message, dwStyle);
		break;

        case WM_HSCROLL:
        case WM_VSCROLL:
        {
            int newTop,itemCount,itemVisibles;

	    pData = (MWSCROLLBARINFO *)hwnd->userdata;
            newTop = pData->curPos;
	    itemCount = pData->maxPos - pData->minPos + 1;
	    itemVisibles = pData->pageStep;

            switch(wParam)
            {
                case SB_LINEDOWN:
#define ITEM_BOTTOM(x)  (x->curPos + itemVisibles - 1)
                    if (ITEM_BOTTOM (pData) < (itemCount - 1 )) 
		    {
                        newTop ++;
                    }
                break;
                
                case SB_LINEUP:
                    if (pData->curPos > 0) 
		    {
                        newTop --;
                    }
                break;
                
                case SB_PAGEDOWN:
                    if ((pData->curPos + (itemVisibles << 1)) <=
                            itemCount)
                        newTop += itemVisibles;
                    else
                        newTop = itemCount - itemVisibles;

                    if (newTop < 0)
                        return 0;

                break;

                case SB_PAGEUP:
                    if (pData->curPos >= itemVisibles)
                        newTop -= itemVisibles;
                    else
                        newTop = 0;

                break;

                case SB_THUMBTRACK:
                    newTop = (int)lParam;
                break;
            }
            
            pData->curPos = newTop;

            SendMessage (hwnd, WM_PAINT, 0, 0);

            sbSetScrollInfo (hwnd, pData, TRUE);

            return 0;
        }
        break;

        default:
    		return DefWindowProc (hwnd, message, wParam, lParam);
    	}
    	return 0;
}
Beispiel #5
0
BOOL SetScrollInfoEx (HWND hWnd, int iSBar, 
                LPCSCROLLINFO lpsi, BOOL fRedraw)	/* jmt: iSBar not used */
{
    PMWSCROLLBARINFO pSBar;
    HWND pWin;
    RECT rcBar;
    
    DWORD dwStyle;	/* jmt:2k0820 */

    pWin = (HWND)hWnd;
    
    if ( !(pSBar = wndGetScrollBar (pWin)) )
        return FALSE;
        
    if( lpsi->fMask & SIF_RANGE )
    {
        pSBar->minPos = (lpsi->nMin < lpsi->nMax)?lpsi->nMin:lpsi->nMax;
        pSBar->maxPos = (lpsi->nMin < lpsi->nMax)?lpsi->nMax:lpsi->nMin;
    }
    
    if( lpsi->fMask & SIF_POS )
        pSBar->curPos = lpsi->nPos;
    
    if( lpsi->fMask & SIF_PAGE )
        pSBar->pageStep = lpsi->nPage;

    /* validate parameters. */
    if (pSBar->curPos < pSBar->minPos)
        pSBar->curPos = pSBar->minPos;

    if (pSBar->pageStep <= 0)
        pSBar->pageStep = 0;
    else if (pSBar->pageStep > (pSBar->maxPos - pSBar->minPos + 1))
        pSBar->pageStep = pSBar->maxPos - pSBar->minPos + 1;
    
    {
        int max = pSBar->maxPos;
        max -= ((pSBar->pageStep - 1) > 0)?(pSBar->pageStep - 1):0;

        if (pSBar->curPos > max)
            pSBar->curPos = max;
    }

    dwStyle = (GetWindowStyle (hWnd) & SBS_TYPEMASK);	/* jmt: 2k0820 */

    if(fRedraw)
    {
        if (dwStyle == SBS_VERT)
	{
            wndGetVScrollBarRect (pWin, &rcBar);
            rcBar.left --;
            rcBar.right --;
	}
        else
	{
            wndGetHScrollBarRect (pWin, &rcBar);
            rcBar.top --;
            rcBar.bottom --;
	}
        wndScrollBarPos (pWin, dwStyle == SBS_HORZ, &rcBar);

#if 0
        SendMessage (hWnd, WM_NCPAINT, 0, (LPARAM)(&rcBar));
#else
	MwPaintScrollbars(hWnd,NULL,dwStyle);	/* a must */
#endif
    }
    
    return TRUE;
}
Beispiel #6
0
/* handle a non-client message for a scrollbar*/
void
MwHandleMessageScrollbar(HWND hwnd, WPARAM hitcode, LPARAM lParam, UINT msg, DWORD style)
{
	int	pos = SBS_UNKNOWN;
	BOOL	vertbar = (style==SBS_VERT);
        BOOL	horzbar = (style==SBS_HORZ);
	int *	pStat;
	POINT	pt;
	RECT	rc;

	static BOOL bDraw;

    	static int downPos = SBS_UNKNOWN;
    	static int sbCode;
    	int newThumbPos;

	int itemMoveable,itemCount,itemVisible,moveRange;	/* jmt:2k0819 */
	int moveTop,moveBottom,moveLeft,moveRight;	/* jmt:2k0819 */

	int cx,cy;
    	MWSCROLLBARINFO* pData;
	
        pData = (MWSCROLLBARINFO *)hwnd->userdata;
	rc = hwnd->winrect;
	cx=rc.right-rc.left;
	cy=rc.bottom-rc.top;

	POINTSTOPOINT(pt, lParam);
	for (;;) {	/* use for() to allow break statement*/
		if (vertbar) 
		{
			pStat = &pData->status;
			rc = hwnd->winrect;
			rc.bottom = rc.top + cx;
			if (PtInRect(&rc, pt)) 
			{
				pos = SBS_UPARROW;
				break;
			}
			rc.bottom = hwnd->winrect.bottom;
			rc.top = rc.bottom - cx;
			if (PtInRect(&rc, pt)) 
			{
				pos = SBS_DOWNARROW;
				break;
			}
			pos = SBS_VERTTHUMB;
		} else if (horzbar) 
		{
			pStat = &pData->status;
			rc = hwnd->winrect;
			rc.right = rc.left + cy;
			if (PtInRect(&rc, pt)) {
				pos = SBS_LEFTARROW;
				break;
			}
			rc.right = hwnd->winrect.right;
			rc.left = rc.right - cy;
			if (PtInRect(&rc, pt)) {
				pos = SBS_RIGHTARROW;
				break;
			}
			pos = SBS_HORZTHUMB;
		} else
			return;
		break;
	}

	if (pos == SBS_UNKNOWN)
		return;

	*pStat &= ~SBS_MASK;		/* remove stray mouse states*/

	if (msg == WM_NCLBUTTONDOWN || msg == WM_NCLBUTTONDBLCLK)
		*pStat |= pos;
	else *pStat &= ~pos;

	if (msg == WM_NCLBUTTONDOWN || msg == WM_NCLBUTTONDBLCLK)
		bDraw=TRUE;

	if (bDraw)
		MwPaintScrollbars(hwnd, NULL,style);

        if (pos == SBS_UPARROW || pos == SBS_LEFTARROW)	/* jmt:2k0820 */
	{
                if (pData->curPos != pData->minPos)
			sbCode = SB_LINEUP;
        }
        else if (pos == SBS_DOWNARROW || pos == SBS_RIGHTARROW)	/* jmt:2k0820 */
	{
                if (pData->curPos != pData->maxPos)
			sbCode = SB_LINEDOWN;
        }
        else if (pos == SBS_VERTTHUMB || pos == SBS_HORZTHUMB)
	{
                sbCode = SB_THUMBTRACK;
        }

	switch(msg)
	{
	case WM_NCLBUTTONDOWN:
	case WM_NCLBUTTONDBLCLK:
	    downPos = pos;
        break;

        case WM_NCMOUSEMOVE:
	    if (vertbar) 
	    {
		if (sbCode == SB_THUMBTRACK && downPos == SBS_VERTTHUMB)
	    	{
			/* jmt(2k0819): new algorithm for SB_THUMBTRACK */

			rc = hwnd->winrect;
			moveTop = rc.top + cx;
			moveBottom = hwnd->winrect.bottom - cx;
			moveRange = moveBottom - moveTop;

			itemCount = pData->maxPos - pData->minPos + 1;
			itemVisible = pData->pageStep;
			itemMoveable = itemCount - itemVisible + 1;

			newThumbPos = ((pt.y - moveTop) * itemMoveable) / moveRange;
			printf("((%d-%d)*%d)/%d=%d\n",
				pt.y,moveTop,itemMoveable,moveRange,newThumbPos);

                	if ( newThumbPos >= pData->minPos &&
                    	     newThumbPos <= pData->maxPos)
			{
                    	     	SendMessage (hwnd,
                        		WM_VSCROLL, SB_THUMBTRACK, newThumbPos);

                    	     	SendMessage (GetParent(hwnd),
                        		WM_VSCROLL, SB_THUMBTRACK, newThumbPos);
			}
                	break;
            	}
	    }
	    if (horzbar) 
	    {
		if (sbCode == SB_THUMBTRACK && downPos == SBS_HORZTHUMB)
		{
			/* jmt(2k0819): new algorithm for SB_THUMBTRACK */

			rc = hwnd->winrect;
			moveLeft = rc.left + cy;
			moveRight = hwnd->winrect.right - cy;
			moveRange = moveRight - moveLeft;

			itemCount = pData->maxPos - pData->minPos + 1;
			itemVisible = pData->pageStep;
			itemMoveable = itemCount - itemVisible + 1;

			newThumbPos = ((pt.x - moveLeft) * itemMoveable) / moveRange;
			printf("((%d-%d)*%d)/%d=%d\n",
				pt.y,moveLeft,itemMoveable,moveRange,newThumbPos);
			    
			if ( newThumbPos >= pData->minPos &&
			     newThumbPos <= pData->maxPos)
			{
			    	SendMessage (hwnd,
					WM_HSCROLL, SB_THUMBTRACK, newThumbPos);

			    	SendMessage (GetParent(hwnd),
					WM_HSCROLL, SB_THUMBTRACK, newThumbPos);
			}
			break;
		}
             }
        break;

	case WM_NCLBUTTONUP:
	    bDraw=FALSE;
	    downPos = SBS_UNKNOWN;

	    if (sbCode==SB_THUMBTRACK)
	    {
		    if (vertbar) 
		    {
			/* jmt(2k0819): new algorithm for SB_THUMBTRACK */

			rc = hwnd->winrect;
			moveTop = rc.top + cx;
			moveBottom = hwnd->winrect.bottom - cx;
			moveRange = moveBottom - moveTop;

			itemCount = pData->maxPos - pData->minPos + 1;
			itemVisible = pData->pageStep;
			itemMoveable = itemCount - itemVisible + 1;

			newThumbPos = ((pt.y - moveTop) * itemMoveable) / moveRange;
			printf("((%d-%d)*%d)/%d=%d\n",
				pt.y,moveTop,itemMoveable,moveRange,newThumbPos);

			if ( newThumbPos >= pData->minPos &&
			     newThumbPos <= pData->maxPos)
			{
				SendMessage (hwnd,
					WM_VSCROLL, SB_THUMBTRACK, newThumbPos);

				SendMessage (GetParent(hwnd),
					WM_VSCROLL, SB_THUMBTRACK, newThumbPos);
			}
			break;	/* case */
		    }
		    if (horzbar) 
		    {
			/* jmt(2k0819): new algorithm for SB_THUMBTRACK */

			rc = hwnd->winrect;
			moveLeft = rc.left + cy;
			moveRight = hwnd->winrect.right - cy;
			moveRange = moveRight - moveLeft;

			itemCount = pData->maxPos - pData->minPos + 1;
			itemVisible = pData->pageStep;
			itemMoveable = itemCount - itemVisible + 1;

			newThumbPos = ((pt.x - moveLeft) * itemMoveable) / moveRange;
			printf("((%d-%d)*%d)/%d=%d\n",
				pt.y,moveLeft,itemMoveable,moveRange,newThumbPos);
				    
			if ( newThumbPos >= pData->minPos &&
			     newThumbPos <= pData->maxPos)
			{
			    SendMessage (hwnd,
					WM_HSCROLL, SB_THUMBTRACK, newThumbPos);

			    SendMessage (GetParent(hwnd),
					WM_HSCROLL, SB_THUMBTRACK, newThumbPos);
			}
			break;	/* case */
		    }
	    }
	    else
	    {
		if (vertbar) 
		{
			SendMessage (hwnd, WM_VSCROLL, sbCode, 0);
			SendMessage (GetParent(hwnd), WM_VSCROLL, sbCode, 0);
		}
		if (horzbar) 
		{
			SendMessage (hwnd, WM_HSCROLL, sbCode, 0);
			SendMessage (GetParent(hwnd), WM_HSCROLL, sbCode, 0);
		}
	    }
	break;
	}
}