OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [MW_0_8_9PRE7/] [mw/] [src/] [mwin/] [winsbar.c] - Diff between revs 674 and 1765

Only display areas with differences | Details | Blame | View Log

Rev 674 Rev 1765
/*
/*
 * Copyright (c) 2000 Greg Haerr <greg@censoft.com>
 * Copyright (c) 2000 Greg Haerr <greg@censoft.com>
 * Portions Copyright (c) 1999, 2000, Wei Yongming.
 * Portions Copyright (c) 1999, 2000, Wei Yongming.
 * jmt: scrollbar thumb ported
 * jmt: scrollbar thumb ported
 *
 *
 * Microwindows win32 NonClient Scrollbars
 * Microwindows win32 NonClient Scrollbars
 */
 */
#define MWINCLUDECOLORS
#define MWINCLUDECOLORS
#include "windows.h"
#include "windows.h"
#include "wintern.h"
#include "wintern.h"
#include "wintools.h"
#include "wintools.h"
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <stdio.h>
#include <stdio.h>
 
 
/* scrollbar status/positions*/
/* scrollbar status/positions*/
#define SBS_UNKNOWN             0x0000
#define SBS_UNKNOWN             0x0000
#define SBS_LEFTARROW           0x0001
#define SBS_LEFTARROW           0x0001
#define SBS_RIGHTARROW          0x0002
#define SBS_RIGHTARROW          0x0002
#define SBS_LEFTSPACE           0x0004
#define SBS_LEFTSPACE           0x0004
#define SBS_RIGHTSPACE          0x0008
#define SBS_RIGHTSPACE          0x0008
#define SBS_HORZTHUMB           0x0010
#define SBS_HORZTHUMB           0x0010
#define SBS_UPARROW             0x0020
#define SBS_UPARROW             0x0020
#define SBS_DOWNARROW           0x0040
#define SBS_DOWNARROW           0x0040
#define SBS_UPSPACE             0x0080
#define SBS_UPSPACE             0x0080
#define SBS_DOWNSPACE           0x0100
#define SBS_DOWNSPACE           0x0100
#define SBS_VERTTHUMB           0x0200
#define SBS_VERTTHUMB           0x0200
#define SBS_MASK                0x03ff
#define SBS_MASK                0x03ff
#define SBS_DISABLED            0x4000
#define SBS_DISABLED            0x4000
#define SBS_HIDE                0x8000
#define SBS_HIDE                0x8000
 
 
#define HSCROLLBARVISIBLE(hwnd) ((hwnd)->style & WS_HSCROLL)
#define HSCROLLBARVISIBLE(hwnd) ((hwnd)->style & WS_HSCROLL)
#define VSCROLLBARVISIBLE(hwnd) ((hwnd)->style & WS_VSCROLL)
#define VSCROLLBARVISIBLE(hwnd) ((hwnd)->style & WS_VSCROLL)
 
 
/*
/*
 * Adjust client area smaller if scrollbars visible.
 * Adjust client area smaller if scrollbars visible.
 * Also, compute the NC hittest regions for the scrollbars.
 * Also, compute the NC hittest regions for the scrollbars.
 */
 */
void
void
MwAdjustNCScrollbars(HWND hwnd)
MwAdjustNCScrollbars(HWND hwnd)
{
{
        BOOL    vertbar = VSCROLLBARVISIBLE(hwnd);
        BOOL    vertbar = VSCROLLBARVISIBLE(hwnd);
        BOOL    horzbar = HSCROLLBARVISIBLE(hwnd);
        BOOL    horzbar = HSCROLLBARVISIBLE(hwnd);
 
 
        if (vertbar) {
        if (vertbar) {
                hwnd->clirect.right -= mwSYSMETRICS_CXVSCROLL;
                hwnd->clirect.right -= mwSYSMETRICS_CXVSCROLL;
                if (horzbar)
                if (horzbar)
                        hwnd->clirect.bottom -= mwSYSMETRICS_CYHSCROLL;
                        hwnd->clirect.bottom -= mwSYSMETRICS_CYHSCROLL;
                hwnd->vscroll.rc.left = hwnd->clirect.right;
                hwnd->vscroll.rc.left = hwnd->clirect.right;
                hwnd->vscroll.rc.right = hwnd->clirect.right +
                hwnd->vscroll.rc.right = hwnd->clirect.right +
                        mwSYSMETRICS_CXVSCROLL;
                        mwSYSMETRICS_CXVSCROLL;
                hwnd->vscroll.rc.top = hwnd->clirect.top;
                hwnd->vscroll.rc.top = hwnd->clirect.top;
                hwnd->vscroll.rc.bottom = hwnd->clirect.bottom;
                hwnd->vscroll.rc.bottom = hwnd->clirect.bottom;
        } else
        } else
                SetRectEmpty(&hwnd->vscroll.rc);
                SetRectEmpty(&hwnd->vscroll.rc);
        if (horzbar) {
        if (horzbar) {
                if (!vertbar)
                if (!vertbar)
                        hwnd->clirect.bottom -= mwSYSMETRICS_CYHSCROLL;
                        hwnd->clirect.bottom -= mwSYSMETRICS_CYHSCROLL;
                hwnd->hscroll.rc.top = hwnd->clirect.bottom;
                hwnd->hscroll.rc.top = hwnd->clirect.bottom;
                hwnd->hscroll.rc.bottom = hwnd->clirect.bottom +
                hwnd->hscroll.rc.bottom = hwnd->clirect.bottom +
                        mwSYSMETRICS_CYHSCROLL;
                        mwSYSMETRICS_CYHSCROLL;
                hwnd->hscroll.rc.left = hwnd->clirect.left;
                hwnd->hscroll.rc.left = hwnd->clirect.left;
                hwnd->hscroll.rc.right = hwnd->clirect.right;
                hwnd->hscroll.rc.right = hwnd->clirect.right;
        } else
        } else
                SetRectEmpty(&hwnd->hscroll.rc);
                SetRectEmpty(&hwnd->hscroll.rc);
}
}
 
 
static int
static int
wndGetBorder(HWND hwnd)
wndGetBorder(HWND hwnd)
{
{
        if (hwnd->style & WS_BORDER)  {
        if (hwnd->style & WS_BORDER)  {
                if ((hwnd->style & WS_CAPTION) == WS_CAPTION)
                if ((hwnd->style & WS_CAPTION) == WS_CAPTION)
                        return mwSYSMETRICS_CXFRAME;
                        return mwSYSMETRICS_CXFRAME;
                return mwSYSMETRICS_CXBORDER;
                return mwSYSMETRICS_CXBORDER;
        }
        }
        return 0;
        return 0;
}
}
 
 
static BOOL
static BOOL
wndGetVScrollBarRect (HWND hwnd, RECT* rcVBar)
wndGetVScrollBarRect (HWND hwnd, RECT* rcVBar)
{
{
    if (hwnd->style & WS_VSCROLL) {
    if (hwnd->style & WS_VSCROLL) {
        rcVBar->left = hwnd->winrect.right - mwSYSMETRICS_CXVSCROLL
        rcVBar->left = hwnd->winrect.right - mwSYSMETRICS_CXVSCROLL
                        - wndGetBorder (hwnd);
                        - wndGetBorder (hwnd);
        rcVBar->right = hwnd->winrect.right - wndGetBorder (hwnd);
        rcVBar->right = hwnd->winrect.right - wndGetBorder (hwnd);
        rcVBar->top  = hwnd->clirect.top;
        rcVBar->top  = hwnd->clirect.top;
        rcVBar->bottom = hwnd->winrect.bottom - wndGetBorder (hwnd);
        rcVBar->bottom = hwnd->winrect.bottom - wndGetBorder (hwnd);
 
 
        if (hwnd->style & WS_HSCROLL && !(hwnd->hscroll.status & SBS_HIDE))
        if (hwnd->style & WS_HSCROLL && !(hwnd->hscroll.status & SBS_HIDE))
            rcVBar->bottom -= mwSYSMETRICS_CYHSCROLL;
            rcVBar->bottom -= mwSYSMETRICS_CYHSCROLL;
 
 
        return TRUE;
        return TRUE;
    }
    }
 
 
    return FALSE;
    return FALSE;
}
}
 
 
static BOOL
static BOOL
wndGetHScrollBarRect (HWND hwnd, RECT* rcHBar)
wndGetHScrollBarRect (HWND hwnd, RECT* rcHBar)
{
{
    if (hwnd->style & WS_HSCROLL) {
    if (hwnd->style & WS_HSCROLL) {
        rcHBar->top = hwnd->winrect.bottom - mwSYSMETRICS_CYHSCROLL
        rcHBar->top = hwnd->winrect.bottom - mwSYSMETRICS_CYHSCROLL
                        - wndGetBorder (hwnd);
                        - wndGetBorder (hwnd);
        rcHBar->bottom = hwnd->winrect.bottom - wndGetBorder (hwnd);
        rcHBar->bottom = hwnd->winrect.bottom - wndGetBorder (hwnd);
        rcHBar->left  = hwnd->clirect.left;
        rcHBar->left  = hwnd->clirect.left;
        rcHBar->right = hwnd->winrect.right - wndGetBorder (hwnd);
        rcHBar->right = hwnd->winrect.right - wndGetBorder (hwnd);
 
 
        if (hwnd->style & WS_VSCROLL && !(hwnd->vscroll.status & SBS_HIDE))
        if (hwnd->style & WS_VSCROLL && !(hwnd->vscroll.status & SBS_HIDE))
            rcHBar->right -= mwSYSMETRICS_CXVSCROLL;
            rcHBar->right -= mwSYSMETRICS_CXVSCROLL;
 
 
        return TRUE;
        return TRUE;
    }
    }
 
 
    return FALSE;
    return FALSE;
}
}
 
 
void
void
MwPaintNCScrollbars(HWND hwnd, HDC hdc)
MwPaintNCScrollbars(HWND hwnd, HDC hdc)
{
{
        BOOL    vertbar = VSCROLLBARVISIBLE(hwnd);
        BOOL    vertbar = VSCROLLBARVISIBLE(hwnd);
        BOOL    horzbar = HSCROLLBARVISIBLE(hwnd);
        BOOL    horzbar = HSCROLLBARVISIBLE(hwnd);
        BOOL    fGotDC = FALSE;
        BOOL    fGotDC = FALSE;
        RECT    rc,rc2;
        RECT    rc,rc2;
 
 
        POINT   p3[3];
        POINT   p3[3];
        int     shrink=2;
        int     shrink=2;
 
 
        int start = 0;
        int start = 0;
        RECT rcHBar, rcVBar;
        RECT rcHBar, rcVBar;
 
 
 
 
        if (!hdc && (horzbar || vertbar)) {
        if (!hdc && (horzbar || vertbar)) {
                hdc = GetWindowDC(hwnd);
                hdc = GetWindowDC(hwnd);
                fGotDC = TRUE;
                fGotDC = TRUE;
        }
        }
 
 
        if (horzbar && vertbar) {
        if (horzbar && vertbar) {
                rc.left = hwnd->clirect.right;
                rc.left = hwnd->clirect.right;
                rc.top = hwnd->clirect.bottom;
                rc.top = hwnd->clirect.bottom;
                rc.right = rc.left + mwSYSMETRICS_CXVSCROLL;
                rc.right = rc.left + mwSYSMETRICS_CXVSCROLL;
                rc.bottom = rc.top + mwSYSMETRICS_CYHSCROLL;
                rc.bottom = rc.top + mwSYSMETRICS_CYHSCROLL;
                FillRect(hdc, &rc, (HBRUSH)(COLOR_BTNFACE+1));
                FillRect(hdc, &rc, (HBRUSH)(COLOR_BTNFACE+1));
        }
        }
        if (vertbar) {
        if (vertbar) {
                rc = hwnd->vscroll.rc;
                rc = hwnd->vscroll.rc;
#if 1
#if 1
                /* bkgnd */
                /* bkgnd */
                rc2.left=rc.left; rc2.right=rc2.left+ mwSYSMETRICS_CXVSCROLL;
                rc2.left=rc.left; rc2.right=rc2.left+ mwSYSMETRICS_CXVSCROLL;
                rc2.top=rc.top;
                rc2.top=rc.top;
                rc2.bottom=rc2.top+ mwSYSMETRICS_CYHSCROLL;
                rc2.bottom=rc2.top+ mwSYSMETRICS_CYHSCROLL;
                FillRect(hdc, &rc2, (HBRUSH)(COLOR_BTNFACE+1));
                FillRect(hdc, &rc2, (HBRUSH)(COLOR_BTNFACE+1));
                rc2.top=rc.bottom- mwSYSMETRICS_CYHSCROLL;
                rc2.top=rc.bottom- mwSYSMETRICS_CYHSCROLL;
                rc2.bottom=rc2.top+ mwSYSMETRICS_CYHSCROLL;
                rc2.bottom=rc2.top+ mwSYSMETRICS_CYHSCROLL;
                FillRect(hdc, &rc2, (HBRUSH)(COLOR_BTNFACE+1));
                FillRect(hdc, &rc2, (HBRUSH)(COLOR_BTNFACE+1));
#endif
#endif
                /* up */
                /* up */
                Draw3dUpDownState(hdc, rc.left, rc.top,
                Draw3dUpDownState(hdc, rc.left, rc.top,
                        mwSYSMETRICS_CXVSCROLL, mwSYSMETRICS_CYHSCROLL,
                        mwSYSMETRICS_CXVSCROLL, mwSYSMETRICS_CYHSCROLL,
                        hwnd->vscroll.status & SBS_UPARROW);
                        hwnd->vscroll.status & SBS_UPARROW);
                /* down */
                /* down */
                Draw3dUpDownState(hdc, rc.left,rc.bottom-mwSYSMETRICS_CYHSCROLL,
                Draw3dUpDownState(hdc, rc.left,rc.bottom-mwSYSMETRICS_CYHSCROLL,
                        mwSYSMETRICS_CXVSCROLL, mwSYSMETRICS_CYHSCROLL,
                        mwSYSMETRICS_CXVSCROLL, mwSYSMETRICS_CYHSCROLL,
                        hwnd->vscroll.status & SBS_DOWNARROW);
                        hwnd->vscroll.status & SBS_DOWNARROW);
/* jmt: draw arrows */
/* jmt: draw arrows */
                SelectObject(hdc,GetStockObject(BLACK_BRUSH));
                SelectObject(hdc,GetStockObject(BLACK_BRUSH));
                /* up */
                /* up */
                p3[0].x= rc.left + (mwSYSMETRICS_CXVSCROLL/2) - 1;
                p3[0].x= rc.left + (mwSYSMETRICS_CXVSCROLL/2) - 1;
                p3[0].y= rc.top + 2 + shrink;
                p3[0].y= rc.top + 2 + shrink;
                p3[1].x= rc.left + 2 + shrink - 1;
                p3[1].x= rc.left + 2 + shrink - 1;
                p3[1].y= rc.top + (mwSYSMETRICS_CYHSCROLL-4) - shrink;
                p3[1].y= rc.top + (mwSYSMETRICS_CYHSCROLL-4) - shrink;
                p3[2].x= rc.left + (mwSYSMETRICS_CXVSCROLL-4) - shrink;
                p3[2].x= rc.left + (mwSYSMETRICS_CXVSCROLL-4) - shrink;
                p3[2].y= rc.top + (mwSYSMETRICS_CYHSCROLL-4) - shrink;
                p3[2].y= rc.top + (mwSYSMETRICS_CYHSCROLL-4) - shrink;
                Polygon(hdc,p3,3);
                Polygon(hdc,p3,3);
                /* down */
                /* down */
                p3[0].x= rc.left + (mwSYSMETRICS_CXVSCROLL/2) - 1;
                p3[0].x= rc.left + (mwSYSMETRICS_CXVSCROLL/2) - 1;
                p3[0].y= rc.bottom - 4 - shrink;
                p3[0].y= rc.bottom - 4 - shrink;
                p3[1].x= rc.left + 2 + shrink - 1;
                p3[1].x= rc.left + 2 + shrink - 1;
                p3[1].y= rc.bottom-mwSYSMETRICS_CYHSCROLL + 2 + shrink;
                p3[1].y= rc.bottom-mwSYSMETRICS_CYHSCROLL + 2 + shrink;
                p3[2].x= rc.left + (mwSYSMETRICS_CXVSCROLL-4) - shrink;
                p3[2].x= rc.left + (mwSYSMETRICS_CXVSCROLL-4) - shrink;
                p3[2].y= rc.bottom-mwSYSMETRICS_CYHSCROLL + 2 + shrink;
                p3[2].y= rc.bottom-mwSYSMETRICS_CYHSCROLL + 2 + shrink;
                Polygon(hdc,p3,3);
                Polygon(hdc,p3,3);
 
 
                /* draw moving bar */
                /* draw moving bar */
 
 
                wndGetVScrollBarRect (hwnd, &rcVBar);
                wndGetVScrollBarRect (hwnd, &rcVBar);
                rcVBar.left -- ;
                rcVBar.left -- ;
                rcVBar.right -- ;
                rcVBar.right -- ;
 
 
                start = rcVBar.top + mwSYSMETRICS_CYVSCROLL + hwnd->vscroll.barStart;
                start = rcVBar.top + mwSYSMETRICS_CYVSCROLL + hwnd->vscroll.barStart;
 
 
                if (start + hwnd->vscroll.barLen > rcVBar.bottom)
                if (start + hwnd->vscroll.barLen > rcVBar.bottom)
                        start = rcVBar.bottom - hwnd->vscroll.barLen;
                        start = rcVBar.bottom - hwnd->vscroll.barLen;
 
 
                if (hwnd->vscroll.barLen == 0)
                if (hwnd->vscroll.barLen == 0)
                        hwnd->vscroll.barLen=rc.bottom-rc.top-(mwSYSMETRICS_CYVSCROLL*2);
                        hwnd->vscroll.barLen=rc.bottom-rc.top-(mwSYSMETRICS_CYVSCROLL*2);
 
 
                /* bkgnd */
                /* bkgnd */
                rc2.left=rc.left; rc2.right=rc.right/*-1*/;
                rc2.left=rc.left; rc2.right=rc.right/*-1*/;
                rc2.top=rc.top+mwSYSMETRICS_CYHSCROLL;
                rc2.top=rc.top+mwSYSMETRICS_CYHSCROLL;
                rc2.bottom=start;
                rc2.bottom=start;
                if (rc2.bottom>rc2.top)
                if (rc2.bottom>rc2.top)
                        FillRect(hdc, &rc2, (HBRUSH)GetStockObject(DKGRAY_BRUSH));
                        FillRect(hdc, &rc2, (HBRUSH)GetStockObject(DKGRAY_BRUSH));
 
 
                rc2.top=start+hwnd->vscroll.barLen;
                rc2.top=start+hwnd->vscroll.barLen;
                rc2.bottom=rc.bottom-mwSYSMETRICS_CYHSCROLL;
                rc2.bottom=rc.bottom-mwSYSMETRICS_CYHSCROLL;
                if (rc2.bottom>rc2.top)
                if (rc2.bottom>rc2.top)
                        FillRect(hdc, &rc2, (HBRUSH)GetStockObject(DKGRAY_BRUSH));
                        FillRect(hdc, &rc2, (HBRUSH)GetStockObject(DKGRAY_BRUSH));
 
 
                Draw3dUpFrame (hdc, rcVBar.left, start, rcVBar.right,
                Draw3dUpFrame (hdc, rcVBar.left, start, rcVBar.right,
                        start + hwnd->vscroll.barLen);
                        start + hwnd->vscroll.barLen);
                /*printf("barv:(l,t,r,b):(%d,%d,%d,%d)\n",
                /*printf("barv:(l,t,r,b):(%d,%d,%d,%d)\n",
                        rcVBar.left, start, rcVBar.right,
                        rcVBar.left, start, rcVBar.right,
                        start + hwnd->vscroll.barLen);*/
                        start + hwnd->vscroll.barLen);*/
        }
        }
        if (horzbar) {
        if (horzbar) {
                rc = hwnd->hscroll.rc;
                rc = hwnd->hscroll.rc;
 
 
#if 1
#if 1
                /* bkgnd */
                /* bkgnd */
                rc2.top=rc.top; rc2.bottom=rc2.top+ mwSYSMETRICS_CYHSCROLL;
                rc2.top=rc.top; rc2.bottom=rc2.top+ mwSYSMETRICS_CYHSCROLL;
                rc2.left=rc.left;
                rc2.left=rc.left;
                rc2.right=rc2.left+ mwSYSMETRICS_CXVSCROLL;
                rc2.right=rc2.left+ mwSYSMETRICS_CXVSCROLL;
                FillRect(hdc, &rc2, (HBRUSH)(COLOR_BTNFACE+1));
                FillRect(hdc, &rc2, (HBRUSH)(COLOR_BTNFACE+1));
                rc2.left=rc.right- mwSYSMETRICS_CXVSCROLL;
                rc2.left=rc.right- mwSYSMETRICS_CXVSCROLL;
                rc2.right=rc2.left+ mwSYSMETRICS_CXVSCROLL;
                rc2.right=rc2.left+ mwSYSMETRICS_CXVSCROLL;
                FillRect(hdc, &rc2, (HBRUSH)(COLOR_BTNFACE+1));
                FillRect(hdc, &rc2, (HBRUSH)(COLOR_BTNFACE+1));
#endif
#endif
 
 
                /* left */
                /* left */
                Draw3dUpDownState(hdc, rc.left, rc.top,
                Draw3dUpDownState(hdc, rc.left, rc.top,
                        mwSYSMETRICS_CXVSCROLL, mwSYSMETRICS_CYHSCROLL,
                        mwSYSMETRICS_CXVSCROLL, mwSYSMETRICS_CYHSCROLL,
                        hwnd->hscroll.status & SBS_LEFTARROW);
                        hwnd->hscroll.status & SBS_LEFTARROW);
                /* right */
                /* right */
                Draw3dUpDownState(hdc, rc.right-mwSYSMETRICS_CXVSCROLL, rc.top,
                Draw3dUpDownState(hdc, rc.right-mwSYSMETRICS_CXVSCROLL, rc.top,
                        mwSYSMETRICS_CXVSCROLL, mwSYSMETRICS_CYHSCROLL,
                        mwSYSMETRICS_CXVSCROLL, mwSYSMETRICS_CYHSCROLL,
                        hwnd->hscroll.status & SBS_RIGHTARROW);
                        hwnd->hscroll.status & SBS_RIGHTARROW);
/* jmt: draw arrows */
/* jmt: draw arrows */
                SelectObject(hdc,GetStockObject(BLACK_BRUSH));
                SelectObject(hdc,GetStockObject(BLACK_BRUSH));
                /* left */
                /* left */
                p3[0].x= rc.left + 2 + shrink;
                p3[0].x= rc.left + 2 + shrink;
                p3[0].y= rc.top + (mwSYSMETRICS_CYHSCROLL/2) ;
                p3[0].y= rc.top + (mwSYSMETRICS_CYHSCROLL/2) ;
                p3[1].x= rc.left + (mwSYSMETRICS_CXVSCROLL-4) - shrink ;
                p3[1].x= rc.left + (mwSYSMETRICS_CXVSCROLL-4) - shrink ;
                p3[1].y= rc.top + 2 + shrink;
                p3[1].y= rc.top + 2 + shrink;
                p3[2].x= rc.left + (mwSYSMETRICS_CXVSCROLL-4) - shrink;
                p3[2].x= rc.left + (mwSYSMETRICS_CXVSCROLL-4) - shrink;
                p3[2].y= rc.bottom - 4 - shrink + 1;
                p3[2].y= rc.bottom - 4 - shrink + 1;
                Polygon(hdc,p3,3);
                Polygon(hdc,p3,3);
                /* right */
                /* right */
                p3[0].x= rc.right - 4 - shrink;
                p3[0].x= rc.right - 4 - shrink;
                p3[0].y= rc.top + (mwSYSMETRICS_CYHSCROLL/2) ;
                p3[0].y= rc.top + (mwSYSMETRICS_CYHSCROLL/2) ;
                p3[1].x= rc.right-mwSYSMETRICS_CXVSCROLL + 2 + shrink ;
                p3[1].x= rc.right-mwSYSMETRICS_CXVSCROLL + 2 + shrink ;
                p3[1].y= rc.top + 2 + shrink;
                p3[1].y= rc.top + 2 + shrink;
                p3[2].x= rc.right-mwSYSMETRICS_CXVSCROLL + 2 + shrink;
                p3[2].x= rc.right-mwSYSMETRICS_CXVSCROLL + 2 + shrink;
                p3[2].y= rc.bottom - 4 - shrink + 1;
                p3[2].y= rc.bottom - 4 - shrink + 1;
                Polygon(hdc,p3,3);
                Polygon(hdc,p3,3);
 
 
                /* draw moving bar. */
                /* draw moving bar. */
 
 
                wndGetHScrollBarRect (hwnd, &rcHBar);
                wndGetHScrollBarRect (hwnd, &rcHBar);
                rcHBar.top -- ;
                rcHBar.top -- ;
                rcHBar.bottom -- ;
                rcHBar.bottom -- ;
 
 
                start = rcHBar.left + mwSYSMETRICS_CXHSCROLL + hwnd->hscroll.barStart;
                start = rcHBar.left + mwSYSMETRICS_CXHSCROLL + hwnd->hscroll.barStart;
 
 
                if (start + hwnd->hscroll.barLen > rcHBar.right)
                if (start + hwnd->hscroll.barLen > rcHBar.right)
                        start = rcHBar.right - hwnd->hscroll.barLen;
                        start = rcHBar.right - hwnd->hscroll.barLen;
 
 
                if (hwnd->hscroll.barLen == 0)
                if (hwnd->hscroll.barLen == 0)
                        hwnd->hscroll.barLen=rc.right-rc.left-(mwSYSMETRICS_CXHSCROLL*2);
                        hwnd->hscroll.barLen=rc.right-rc.left-(mwSYSMETRICS_CXHSCROLL*2);
 
 
                /* bkgnd */
                /* bkgnd */
                rc2.top=rc.top; rc2.bottom=rc.bottom/*-1*/;
                rc2.top=rc.top; rc2.bottom=rc.bottom/*-1*/;
                rc2.left=rc.left+mwSYSMETRICS_CXVSCROLL;
                rc2.left=rc.left+mwSYSMETRICS_CXVSCROLL;
                rc2.right=start;
                rc2.right=start;
                if (rc2.right>rc2.left)
                if (rc2.right>rc2.left)
                        FillRect(hdc, &rc2, (HBRUSH)GetStockObject(DKGRAY_BRUSH));
                        FillRect(hdc, &rc2, (HBRUSH)GetStockObject(DKGRAY_BRUSH));
 
 
                rc2.left=start+hwnd->hscroll.barLen;
                rc2.left=start+hwnd->hscroll.barLen;
                rc2.right=rc.right-mwSYSMETRICS_CXVSCROLL;
                rc2.right=rc.right-mwSYSMETRICS_CXVSCROLL;
                if (rc2.right>rc2.left)
                if (rc2.right>rc2.left)
                        FillRect(hdc, &rc2, (HBRUSH)GetStockObject(DKGRAY_BRUSH));
                        FillRect(hdc, &rc2, (HBRUSH)GetStockObject(DKGRAY_BRUSH));
 
 
                Draw3dUpFrame (hdc, start, rcHBar.top, start + hwnd->hscroll.barLen,
                Draw3dUpFrame (hdc, start, rcHBar.top, start + hwnd->hscroll.barLen,
                        rcHBar.bottom);
                        rcHBar.bottom);
                /*printf("barh:(l,t,r,b):(%d,%d,%d,%d)\n",
                /*printf("barh:(l,t,r,b):(%d,%d,%d,%d)\n",
                        start, rcHBar.top, start + hwnd->hscroll.barLen,
                        start, rcHBar.top, start + hwnd->hscroll.barLen,
                        rcHBar.bottom);*/
                        rcHBar.bottom);*/
 
 
        }
        }
 
 
        if (fGotDC)
        if (fGotDC)
                ReleaseDC(hwnd, hdc);
                ReleaseDC(hwnd, hdc);
}
}
 
 
/* handle a non-client message for a scrollbar*/
/* handle a non-client message for a scrollbar*/
void
void
MwHandleNCMessageScrollbar(HWND hwnd, UINT msg, WPARAM hitcode, LPARAM lParam)
MwHandleNCMessageScrollbar(HWND hwnd, UINT msg, WPARAM hitcode, LPARAM lParam)
{
{
        int     pos = SBS_UNKNOWN;
        int     pos = SBS_UNKNOWN;
        BOOL    vertbar = VSCROLLBARVISIBLE(hwnd);
        BOOL    vertbar = VSCROLLBARVISIBLE(hwnd);
        BOOL    horzbar = HSCROLLBARVISIBLE(hwnd);
        BOOL    horzbar = HSCROLLBARVISIBLE(hwnd);
        int *   pStat;
        int *   pStat;
        POINT   pt;
        POINT   pt;
        RECT    rc;
        RECT    rc;
 
 
        static BOOL bDraw;
        static BOOL bDraw;
 
 
        static int downPos = SBS_UNKNOWN;
        static int downPos = SBS_UNKNOWN;
        static int sbCode;
        static int sbCode;
        int newThumbPos;
        int newThumbPos;
 
 
        int itemMoveable,itemCount,itemVisible,moveRange;       /* jmt:2k0819 */
        int itemMoveable,itemCount,itemVisible,moveRange;       /* jmt:2k0819 */
        int moveTop,moveBottom,moveLeft,moveRight;      /* jmt:2k0819 */
        int moveTop,moveBottom,moveLeft,moveRight;      /* jmt:2k0819 */
 
 
        POINTSTOPOINT(pt, lParam);
        POINTSTOPOINT(pt, lParam);
        for (;;) {      /* use for() to allow break statement*/
        for (;;) {      /* use for() to allow break statement*/
                if (hitcode == HTVSCROLL && vertbar)
                if (hitcode == HTVSCROLL && vertbar)
                {
                {
                        pStat = &hwnd->vscroll.status;
                        pStat = &hwnd->vscroll.status;
                        rc = hwnd->vscroll.rc;
                        rc = hwnd->vscroll.rc;
                        rc.bottom = rc.top + mwSYSMETRICS_CYVSCROLL;
                        rc.bottom = rc.top + mwSYSMETRICS_CYVSCROLL;
                        if (PtInRect(&rc, pt))
                        if (PtInRect(&rc, pt))
                        {
                        {
                                pos = SBS_UPARROW;
                                pos = SBS_UPARROW;
                                break;
                                break;
                        }
                        }
                        rc.bottom = hwnd->vscroll.rc.bottom;
                        rc.bottom = hwnd->vscroll.rc.bottom;
                        rc.top = rc.bottom - mwSYSMETRICS_CYVSCROLL;
                        rc.top = rc.bottom - mwSYSMETRICS_CYVSCROLL;
                        if (PtInRect(&rc, pt))
                        if (PtInRect(&rc, pt))
                        {
                        {
                                pos = SBS_DOWNARROW;
                                pos = SBS_DOWNARROW;
                                break;
                                break;
                        }
                        }
                        pos = SBS_VERTTHUMB;
                        pos = SBS_VERTTHUMB;
                } else if (hitcode == HTHSCROLL && horzbar)
                } else if (hitcode == HTHSCROLL && horzbar)
                {
                {
                        pStat = &hwnd->hscroll.status;
                        pStat = &hwnd->hscroll.status;
                        rc = hwnd->hscroll.rc;
                        rc = hwnd->hscroll.rc;
                        rc.right = rc.left + mwSYSMETRICS_CXHSCROLL;
                        rc.right = rc.left + mwSYSMETRICS_CXHSCROLL;
                        if (PtInRect(&rc, pt)) {
                        if (PtInRect(&rc, pt)) {
                                pos = SBS_LEFTARROW;
                                pos = SBS_LEFTARROW;
                                break;
                                break;
                        }
                        }
                        rc.right = hwnd->hscroll.rc.right;
                        rc.right = hwnd->hscroll.rc.right;
                        rc.left = rc.right - mwSYSMETRICS_CXHSCROLL;
                        rc.left = rc.right - mwSYSMETRICS_CXHSCROLL;
                        if (PtInRect(&rc, pt)) {
                        if (PtInRect(&rc, pt)) {
                                pos = SBS_RIGHTARROW;
                                pos = SBS_RIGHTARROW;
                                break;
                                break;
                        }
                        }
                        pos = SBS_HORZTHUMB;
                        pos = SBS_HORZTHUMB;
                } else
                } else
                        return;
                        return;
                break;
                break;
        }
        }
 
 
        if (pos == SBS_UNKNOWN)
        if (pos == SBS_UNKNOWN)
                return;
                return;
 
 
        *pStat &= ~SBS_MASK;            /* remove stray mouse states*/
        *pStat &= ~SBS_MASK;            /* remove stray mouse states*/
 
 
        if (msg == WM_NCLBUTTONDOWN || msg == WM_NCLBUTTONDBLCLK)       /* jmt:2k0819 */
        if (msg == WM_NCLBUTTONDOWN || msg == WM_NCLBUTTONDBLCLK)       /* jmt:2k0819 */
                *pStat |= pos;
                *pStat |= pos;
        else *pStat &= ~pos;
        else *pStat &= ~pos;
 
 
        if (msg == WM_NCLBUTTONDOWN || msg == WM_NCLBUTTONDBLCLK)       /* jmt:2k0819 */
        if (msg == WM_NCLBUTTONDOWN || msg == WM_NCLBUTTONDBLCLK)       /* jmt:2k0819 */
                bDraw=TRUE;
                bDraw=TRUE;
 
 
        if (bDraw)
        if (bDraw)
                MwPaintNCScrollbars(hwnd, NULL);
                MwPaintNCScrollbars(hwnd, NULL);
 
 
        if (pos == SBS_UPARROW || pos == SBS_LEFTARROW)         /* jmt:2k0820 */
        if (pos == SBS_UPARROW || pos == SBS_LEFTARROW)         /* jmt:2k0820 */
        {
        {
                if (hwnd->vscroll.curPos != hwnd->vscroll.minPos)
                if (hwnd->vscroll.curPos != hwnd->vscroll.minPos)
                        sbCode = SB_LINEUP;
                        sbCode = SB_LINEUP;
        }
        }
        else if (pos == SBS_DOWNARROW || pos == SBS_RIGHTARROW)         /* jmt:2k0820 */
        else if (pos == SBS_DOWNARROW || pos == SBS_RIGHTARROW)         /* jmt:2k0820 */
        {
        {
                if (hwnd->vscroll.curPos != hwnd->vscroll.maxPos)
                if (hwnd->vscroll.curPos != hwnd->vscroll.maxPos)
                        sbCode = SB_LINEDOWN;
                        sbCode = SB_LINEDOWN;
        }
        }
        else if (pos == SBS_VERTTHUMB || pos == SBS_HORZTHUMB)
        else if (pos == SBS_VERTTHUMB || pos == SBS_HORZTHUMB)
        {
        {
                sbCode = SB_THUMBTRACK;
                sbCode = SB_THUMBTRACK;
        }
        }
 
 
        switch(msg)
        switch(msg)
        {
        {
        case WM_NCLBUTTONDOWN:
        case WM_NCLBUTTONDOWN:
        case WM_NCLBUTTONDBLCLK:        /* jmt:2k0819 */
        case WM_NCLBUTTONDBLCLK:        /* jmt:2k0819 */
            downPos = pos;
            downPos = pos;
#if MWCLIENT
#if MWCLIENT
            InvalidateRect(hwnd,NULL,TRUE);
            InvalidateRect(hwnd,NULL,TRUE);
#endif
#endif
        break;
        break;
 
 
        case WM_NCMOUSEMOVE:    /* jmt:2k0819 */
        case WM_NCMOUSEMOVE:    /* jmt:2k0819 */
            if (hitcode == HTVSCROLL && vertbar)
            if (hitcode == HTVSCROLL && vertbar)
            {
            {
                if (sbCode == SB_THUMBTRACK && downPos == SBS_VERTTHUMB)
                if (sbCode == SB_THUMBTRACK && downPos == SBS_VERTTHUMB)
                {
                {
                        /* jmt(2k0819): new algorithm for SB_THUMBTRACK */
                        /* jmt(2k0819): new algorithm for SB_THUMBTRACK */
 
 
                        rc = hwnd->vscroll.rc;
                        rc = hwnd->vscroll.rc;
                        moveTop = rc.top + mwSYSMETRICS_CYVSCROLL;
                        moveTop = rc.top + mwSYSMETRICS_CYVSCROLL;
                        moveBottom = hwnd->vscroll.rc.bottom - mwSYSMETRICS_CYVSCROLL;
                        moveBottom = hwnd->vscroll.rc.bottom - mwSYSMETRICS_CYVSCROLL;
                        moveRange = moveBottom - moveTop;
                        moveRange = moveBottom - moveTop;
 
 
                        itemCount = hwnd->vscroll.maxPos - hwnd->vscroll.minPos + 1;
                        itemCount = hwnd->vscroll.maxPos - hwnd->vscroll.minPos + 1;
                        itemVisible = hwnd->vscroll.pageStep;
                        itemVisible = hwnd->vscroll.pageStep;
                        itemMoveable = itemCount - itemVisible + 1;
                        itemMoveable = itemCount - itemVisible + 1;
 
 
                        newThumbPos = ((pt.y - moveTop) * itemMoveable) / moveRange;
                        newThumbPos = ((pt.y - moveTop) * itemMoveable) / moveRange;
                        printf("((%d-%d)*%d)/%d=%d\n",
                        printf("((%d-%d)*%d)/%d=%d\n",
                                pt.y,moveTop,itemMoveable,moveRange,newThumbPos);
                                pt.y,moveTop,itemMoveable,moveRange,newThumbPos);
 
 
                        if ( newThumbPos >= hwnd->vscroll.minPos &&
                        if ( newThumbPos >= hwnd->vscroll.minPos &&
                             newThumbPos <= hwnd->vscroll.maxPos)
                             newThumbPos <= hwnd->vscroll.maxPos)
                                SendMessage (hwnd,
                                SendMessage (hwnd,
                                        WM_VSCROLL, SB_THUMBTRACK, newThumbPos);
                                        WM_VSCROLL, SB_THUMBTRACK, newThumbPos);
                        break;
                        break;
                }
                }
            }
            }
 
 
            if (hitcode == HTHSCROLL && horzbar)
            if (hitcode == HTHSCROLL && horzbar)
            {
            {
                if (sbCode == SB_THUMBTRACK && downPos == SBS_HORZTHUMB)
                if (sbCode == SB_THUMBTRACK && downPos == SBS_HORZTHUMB)
                {
                {
                        /* jmt(2k0819): new algorithm for SB_THUMBTRACK */
                        /* jmt(2k0819): new algorithm for SB_THUMBTRACK */
 
 
                        rc = hwnd->hscroll.rc;
                        rc = hwnd->hscroll.rc;
                        moveLeft = rc.left + mwSYSMETRICS_CXHSCROLL;
                        moveLeft = rc.left + mwSYSMETRICS_CXHSCROLL;
                        moveRight = hwnd->hscroll.rc.right - mwSYSMETRICS_CXHSCROLL;
                        moveRight = hwnd->hscroll.rc.right - mwSYSMETRICS_CXHSCROLL;
                        moveRange = moveRight - moveLeft;
                        moveRange = moveRight - moveLeft;
 
 
                        itemCount = hwnd->hscroll.maxPos - hwnd->hscroll.minPos + 1;
                        itemCount = hwnd->hscroll.maxPos - hwnd->hscroll.minPos + 1;
                        itemVisible = hwnd->hscroll.pageStep;
                        itemVisible = hwnd->hscroll.pageStep;
                        itemMoveable = itemCount - itemVisible + 1;
                        itemMoveable = itemCount - itemVisible + 1;
 
 
                        newThumbPos = ((pt.x - moveLeft) * itemMoveable) / moveRange;
                        newThumbPos = ((pt.x - moveLeft) * itemMoveable) / moveRange;
                        printf("((%d-%d)*%d)/%d=%d\n",
                        printf("((%d-%d)*%d)/%d=%d\n",
                                pt.y,moveLeft,itemMoveable,moveRange,newThumbPos);
                                pt.y,moveLeft,itemMoveable,moveRange,newThumbPos);
 
 
                        if ( newThumbPos >= hwnd->hscroll.minPos &&
                        if ( newThumbPos >= hwnd->hscroll.minPos &&
                             newThumbPos <= hwnd->hscroll.maxPos)
                             newThumbPos <= hwnd->hscroll.maxPos)
                                SendMessage (hwnd,
                                SendMessage (hwnd,
                                        WM_HSCROLL, SB_THUMBTRACK, newThumbPos);
                                        WM_HSCROLL, SB_THUMBTRACK, newThumbPos);
                        break;
                        break;
                }
                }
             }
             }
 
 
        break;
        break;
 
 
        case WM_NCLBUTTONUP:    /* jmt:2k0819 */
        case WM_NCLBUTTONUP:    /* jmt:2k0819 */
            bDraw=FALSE;
            bDraw=FALSE;
            downPos = SBS_UNKNOWN;
            downPos = SBS_UNKNOWN;
 
 
            if (sbCode==SB_THUMBTRACK)
            if (sbCode==SB_THUMBTRACK)
            {
            {
                    if (hitcode == HTVSCROLL && vertbar)
                    if (hitcode == HTVSCROLL && vertbar)
                    {
                    {
                        /* jmt(2k0819): new algorithm for SB_THUMBTRACK */
                        /* jmt(2k0819): new algorithm for SB_THUMBTRACK */
 
 
                        rc = hwnd->vscroll.rc;
                        rc = hwnd->vscroll.rc;
                        moveTop = rc.top + mwSYSMETRICS_CYVSCROLL;
                        moveTop = rc.top + mwSYSMETRICS_CYVSCROLL;
                        moveBottom = hwnd->vscroll.rc.bottom - mwSYSMETRICS_CYVSCROLL;
                        moveBottom = hwnd->vscroll.rc.bottom - mwSYSMETRICS_CYVSCROLL;
                        moveRange = moveBottom - moveTop;
                        moveRange = moveBottom - moveTop;
 
 
                        itemCount = hwnd->vscroll.maxPos - hwnd->vscroll.minPos + 1;
                        itemCount = hwnd->vscroll.maxPos - hwnd->vscroll.minPos + 1;
                        itemVisible = hwnd->vscroll.pageStep;
                        itemVisible = hwnd->vscroll.pageStep;
                        itemMoveable = itemCount - itemVisible + 1;
                        itemMoveable = itemCount - itemVisible + 1;
 
 
                        newThumbPos = ((pt.y - moveTop) * itemMoveable) / moveRange;
                        newThumbPos = ((pt.y - moveTop) * itemMoveable) / moveRange;
                        printf("((%d-%d)*%d)/%d=%d\n",
                        printf("((%d-%d)*%d)/%d=%d\n",
                                pt.y,moveTop,itemMoveable,moveRange,newThumbPos);
                                pt.y,moveTop,itemMoveable,moveRange,newThumbPos);
 
 
                        if ( newThumbPos >= hwnd->vscroll.minPos &&
                        if ( newThumbPos >= hwnd->vscroll.minPos &&
                             newThumbPos <= hwnd->vscroll.maxPos)
                             newThumbPos <= hwnd->vscroll.maxPos)
                                SendMessage (hwnd,
                                SendMessage (hwnd,
                                        WM_VSCROLL, SB_THUMBTRACK, newThumbPos);
                                        WM_VSCROLL, SB_THUMBTRACK, newThumbPos);
                        break;
                        break;
                    }
                    }
 
 
                    if (hitcode == HTHSCROLL && horzbar)
                    if (hitcode == HTHSCROLL && horzbar)
                    {
                    {
                        /* jmt(2k0819): new algorithm for SB_THUMBTRACK */
                        /* jmt(2k0819): new algorithm for SB_THUMBTRACK */
 
 
                        rc = hwnd->hscroll.rc;
                        rc = hwnd->hscroll.rc;
                        moveLeft = rc.left + mwSYSMETRICS_CXHSCROLL;
                        moveLeft = rc.left + mwSYSMETRICS_CXHSCROLL;
                        moveRight = hwnd->hscroll.rc.right - mwSYSMETRICS_CXHSCROLL;
                        moveRight = hwnd->hscroll.rc.right - mwSYSMETRICS_CXHSCROLL;
                        moveRange = moveRight - moveLeft;
                        moveRange = moveRight - moveLeft;
 
 
                        itemCount = hwnd->hscroll.maxPos - hwnd->hscroll.minPos + 1;
                        itemCount = hwnd->hscroll.maxPos - hwnd->hscroll.minPos + 1;
                        itemVisible = hwnd->hscroll.pageStep;
                        itemVisible = hwnd->hscroll.pageStep;
                        itemMoveable = itemCount - itemVisible + 1;
                        itemMoveable = itemCount - itemVisible + 1;
 
 
                        newThumbPos = ((pt.x - moveLeft) * itemMoveable) / moveRange;
                        newThumbPos = ((pt.x - moveLeft) * itemMoveable) / moveRange;
                        printf("((%d-%d)*%d)/%d=%d\n",
                        printf("((%d-%d)*%d)/%d=%d\n",
                                pt.y,moveLeft,itemMoveable,moveRange,newThumbPos);
                                pt.y,moveLeft,itemMoveable,moveRange,newThumbPos);
 
 
                        if ( newThumbPos >= hwnd->hscroll.minPos &&
                        if ( newThumbPos >= hwnd->hscroll.minPos &&
                             newThumbPos <= hwnd->hscroll.maxPos)
                             newThumbPos <= hwnd->hscroll.maxPos)
                                SendMessage (hwnd,
                                SendMessage (hwnd,
                                        WM_HSCROLL, SB_THUMBTRACK, newThumbPos);
                                        WM_HSCROLL, SB_THUMBTRACK, newThumbPos);
                        break;
                        break;
                    }
                    }
             }
             }
             else       /* jmt:2k0820 */
             else       /* jmt:2k0820 */
             {
             {
                    if (hitcode == HTVSCROLL && vertbar)
                    if (hitcode == HTVSCROLL && vertbar)
                        SendMessage (hwnd, WM_VSCROLL, sbCode, 0);
                        SendMessage (hwnd, WM_VSCROLL, sbCode, 0);
 
 
                    if (hitcode == HTHSCROLL && horzbar)
                    if (hitcode == HTHSCROLL && horzbar)
                        SendMessage (hwnd, WM_HSCROLL, sbCode, 0);
                        SendMessage (hwnd, WM_HSCROLL, sbCode, 0);
             }
             }
        break;
        break;
        }
        }
 
 
}
}
 
 
 
 
static BOOL
static BOOL
PtInRect2(const RECT *lprc, int x, int y)
PtInRect2(const RECT *lprc, int x, int y)
{
{
        POINT   p;
        POINT   p;
 
 
        p.x = x;
        p.x = x;
        p.y = y;
        p.y = y;
        return PtInRect(lprc, p);
        return PtInRect(lprc, p);
}
}
 
 
#if 1   /* 0000 */
#if 1   /* 0000 */
 
 
 
 
static void
static void
wndScrollBarPos (HWND hwnd, BOOL bIsHBar, RECT* rcBar)
wndScrollBarPos (HWND hwnd, BOOL bIsHBar, RECT* rcBar)
{
{
    UINT moveRange;
    UINT moveRange;
    PMWSCROLLBARINFO pSBar;
    PMWSCROLLBARINFO pSBar;
 
 
    if (bIsHBar)
    if (bIsHBar)
        pSBar = &hwnd->hscroll;
        pSBar = &hwnd->hscroll;
    else
    else
        pSBar = &hwnd->vscroll;
        pSBar = &hwnd->vscroll;
 
 
    if (pSBar->minPos == pSBar->maxPos) {
    if (pSBar->minPos == pSBar->maxPos) {
        pSBar->status |= SBS_HIDE;
        pSBar->status |= SBS_HIDE;
        return;
        return;
    }
    }
 
 
    if (bIsHBar)
    if (bIsHBar)
        moveRange = (rcBar->right - rcBar->left) - (mwSYSMETRICS_CXHSCROLL<<1);
        moveRange = (rcBar->right - rcBar->left) - (mwSYSMETRICS_CXHSCROLL<<1);
    else
    else
        moveRange = (rcBar->bottom - rcBar->top) - (mwSYSMETRICS_CYVSCROLL<<1);
        moveRange = (rcBar->bottom - rcBar->top) - (mwSYSMETRICS_CYVSCROLL<<1);
 
 
#define MWM_DEFBARLEN   18
#define MWM_DEFBARLEN   18
#define MWM_MINBARLEN   8
#define MWM_MINBARLEN   8
 
 
    if (pSBar->pageStep == 0)
    if (pSBar->pageStep == 0)
    {
    {
        pSBar->barLen = MWM_DEFBARLEN;
        pSBar->barLen = MWM_DEFBARLEN;
 
 
        if (pSBar->barLen > moveRange)
        if (pSBar->barLen > moveRange)
            pSBar->barLen = MWM_MINBARLEN;
            pSBar->barLen = MWM_MINBARLEN;
    }
    }
    else
    else
    {
    {
        pSBar->barLen = moveRange * pSBar->pageStep /
        pSBar->barLen = moveRange * pSBar->pageStep /
              (pSBar->maxPos - pSBar->minPos + 1);
              (pSBar->maxPos - pSBar->minPos + 1);
        if (pSBar->barLen < MWM_MINBARLEN)
        if (pSBar->barLen < MWM_MINBARLEN)
            pSBar->barLen = MWM_MINBARLEN;
            pSBar->barLen = MWM_MINBARLEN;
    }
    }
 
 
    pSBar->barStart = moveRange * (pSBar->curPos - pSBar->minPos) /
    pSBar->barStart = moveRange * (pSBar->curPos - pSBar->minPos) /
       (pSBar->maxPos - pSBar->minPos + 1);
       (pSBar->maxPos - pSBar->minPos + 1);
 
 
 
 
    if (pSBar->barStart + pSBar->barLen > moveRange)
    if (pSBar->barStart + pSBar->barLen > moveRange)
        pSBar->barStart = moveRange - pSBar->barLen;
        pSBar->barStart = moveRange - pSBar->barLen;
 
 
 
 
    if (pSBar->barStart < 0)
    if (pSBar->barStart < 0)
        pSBar->barStart = 0;
        pSBar->barStart = 0;
}
}
 
 
static PMWSCROLLBARINFO wndGetScrollBar (HWND pWin, int iSBar)
static PMWSCROLLBARINFO wndGetScrollBar (HWND pWin, int iSBar)
{
{
    if (iSBar == SB_HORZ) {
    if (iSBar == SB_HORZ) {
        if (pWin->style & WS_HSCROLL)
        if (pWin->style & WS_HSCROLL)
            return &pWin->hscroll;
            return &pWin->hscroll;
    }
    }
    else if (iSBar == SB_VERT) {
    else if (iSBar == SB_VERT) {
        if (pWin->style & WS_VSCROLL)
        if (pWin->style & WS_VSCROLL)
            return &pWin->vscroll;
            return &pWin->vscroll;
    }
    }
 
 
    return NULL;
    return NULL;
}
}
 
 
BOOL  EnableScrollBar (HWND hWnd, int iSBar, BOOL bEnable)
BOOL  EnableScrollBar (HWND hWnd, int iSBar, BOOL bEnable)
{
{
    PMWSCROLLBARINFO pSBar;
    PMWSCROLLBARINFO pSBar;
    HWND pWin;
    HWND pWin;
    BOOL bPrevState;
    BOOL bPrevState;
    RECT rcBar;
    RECT rcBar;
 
 
    pWin = (HWND)hWnd;
    pWin = (HWND)hWnd;
 
 
    if ( !(pSBar = wndGetScrollBar (pWin, iSBar)) )
    if ( !(pSBar = wndGetScrollBar (pWin, iSBar)) )
        return FALSE;
        return FALSE;
 
 
    bPrevState = !(pSBar->status & SBS_DISABLED);
    bPrevState = !(pSBar->status & SBS_DISABLED);
 
 
    if (bEnable && !bPrevState)
    if (bEnable && !bPrevState)
        pSBar->status &= ~SBS_DISABLED;
        pSBar->status &= ~SBS_DISABLED;
    else if (!bEnable && bPrevState)
    else if (!bEnable && bPrevState)
        pSBar->status |= SBS_DISABLED;
        pSBar->status |= SBS_DISABLED;
    else
    else
        return FALSE;
        return FALSE;
 
 
    if (iSBar == SB_VERT)
    if (iSBar == SB_VERT)
    {
    {
        wndGetVScrollBarRect (pWin, &rcBar);
        wndGetVScrollBarRect (pWin, &rcBar);
        rcBar.left --;
        rcBar.left --;
        rcBar.right --;
        rcBar.right --;
    }
    }
    else
    else
    {
    {
        wndGetHScrollBarRect (pWin, &rcBar);
        wndGetHScrollBarRect (pWin, &rcBar);
        rcBar.top  --;
        rcBar.top  --;
        rcBar.bottom --;
        rcBar.bottom --;
    }
    }
#if 0
#if 0
    SendMessage (hWnd, WM_NCPAINT, 0, (LPARAM)(&rcBar));
    SendMessage (hWnd, WM_NCPAINT, 0, (LPARAM)(&rcBar));
#else
#else
    MwPaintNCScrollbars(hWnd,NULL);     /* a must */
    MwPaintNCScrollbars(hWnd,NULL);     /* a must */
#endif
#endif
 
 
    return TRUE;
    return TRUE;
}
}
 
 
BOOL  GetScrollPos (HWND hWnd, int iSBar, int* pPos)
BOOL  GetScrollPos (HWND hWnd, int iSBar, int* pPos)
{
{
    PMWSCROLLBARINFO pSBar;
    PMWSCROLLBARINFO pSBar;
    HWND pWin;
    HWND pWin;
 
 
    pWin = (HWND)hWnd;
    pWin = (HWND)hWnd;
 
 
    if ( !(pSBar = wndGetScrollBar (pWin, iSBar)) )
    if ( !(pSBar = wndGetScrollBar (pWin, iSBar)) )
        return FALSE;
        return FALSE;
 
 
    *pPos = pSBar->curPos;
    *pPos = pSBar->curPos;
    return TRUE;
    return TRUE;
}
}
 
 
BOOL  GetScrollRange (HWND hWnd, int iSBar, int* pMinPos, int* pMaxPos)
BOOL  GetScrollRange (HWND hWnd, int iSBar, int* pMinPos, int* pMaxPos)
{
{
    PMWSCROLLBARINFO pSBar;
    PMWSCROLLBARINFO pSBar;
    HWND pWin;
    HWND pWin;
 
 
    pWin = (HWND)hWnd;
    pWin = (HWND)hWnd;
 
 
    if ( !(pSBar = wndGetScrollBar (pWin, iSBar)) )
    if ( !(pSBar = wndGetScrollBar (pWin, iSBar)) )
        return FALSE;
        return FALSE;
 
 
    *pMinPos = pSBar->minPos;
    *pMinPos = pSBar->minPos;
    *pMaxPos = pSBar->maxPos;
    *pMaxPos = pSBar->maxPos;
    return TRUE;
    return TRUE;
}
}
 
 
BOOL  SetScrollPos (HWND hWnd, int iSBar, int iNewPos)
BOOL  SetScrollPos (HWND hWnd, int iSBar, int iNewPos)
{
{
    PMWSCROLLBARINFO pSBar;
    PMWSCROLLBARINFO pSBar;
    HWND pWin;
    HWND pWin;
    RECT rcBar;
    RECT rcBar;
 
 
    pWin = (HWND)hWnd;
    pWin = (HWND)hWnd;
 
 
    if ( !(pSBar = wndGetScrollBar (pWin, iSBar)) )
    if ( !(pSBar = wndGetScrollBar (pWin, iSBar)) )
        return FALSE;
        return FALSE;
 
 
    if (iNewPos < pSBar->minPos)
    if (iNewPos < pSBar->minPos)
        pSBar->curPos = pSBar->minPos;
        pSBar->curPos = pSBar->minPos;
    else
    else
        pSBar->curPos = iNewPos;
        pSBar->curPos = iNewPos;
 
 
    {
    {
        int max = pSBar->maxPos;
        int max = pSBar->maxPos;
        max -= ((pSBar->pageStep - 1) > 0)?(pSBar->pageStep - 1):0;
        max -= ((pSBar->pageStep - 1) > 0)?(pSBar->pageStep - 1):0;
 
 
        if (pSBar->curPos > max)
        if (pSBar->curPos > max)
            pSBar->curPos = max;
            pSBar->curPos = max;
    }
    }
 
 
    if (iSBar == SB_VERT)
    if (iSBar == SB_VERT)
    {
    {
        wndGetVScrollBarRect (pWin, &rcBar);
        wndGetVScrollBarRect (pWin, &rcBar);
        rcBar.left --;
        rcBar.left --;
        rcBar.right --;
        rcBar.right --;
    }
    }
    else
    else
    {
    {
        wndGetHScrollBarRect (pWin, &rcBar);
        wndGetHScrollBarRect (pWin, &rcBar);
        rcBar.top  --;
        rcBar.top  --;
        rcBar.bottom --;
        rcBar.bottom --;
    }
    }
 
 
    wndScrollBarPos (pWin, iSBar == SB_HORZ, &rcBar);
    wndScrollBarPos (pWin, iSBar == SB_HORZ, &rcBar);
 
 
#if 0
#if 0
    SendMessage (hWnd, WM_NCPAINT, 0, (LPARAM)(&rcBar));
    SendMessage (hWnd, WM_NCPAINT, 0, (LPARAM)(&rcBar));
#else
#else
    MwPaintNCScrollbars(hWnd,NULL);     /* a must */
    MwPaintNCScrollbars(hWnd,NULL);     /* a must */
#endif
#endif
    return TRUE;
    return TRUE;
}
}
 
 
BOOL  SetScrollRange (HWND hWnd, int iSBar, int iMinPos, int iMaxPos)
BOOL  SetScrollRange (HWND hWnd, int iSBar, int iMinPos, int iMaxPos)
{
{
    PMWSCROLLBARINFO pSBar;
    PMWSCROLLBARINFO pSBar;
    HWND pWin;
    HWND pWin;
    RECT rcBar;
    RECT rcBar;
 
 
    pWin = (HWND)hWnd;
    pWin = (HWND)hWnd;
 
 
    if ( !(pSBar = wndGetScrollBar (pWin, iSBar)) )
    if ( !(pSBar = wndGetScrollBar (pWin, iSBar)) )
        return FALSE;
        return FALSE;
 
 
    pSBar->minPos = (iMinPos < iMaxPos)?iMinPos:iMaxPos;
    pSBar->minPos = (iMinPos < iMaxPos)?iMinPos:iMaxPos;
    pSBar->maxPos = (iMinPos > iMaxPos)?iMinPos:iMaxPos;
    pSBar->maxPos = (iMinPos > iMaxPos)?iMinPos:iMaxPos;
 
 
    /* validate parameters. */
    /* validate parameters. */
    if (pSBar->curPos < pSBar->minPos)
    if (pSBar->curPos < pSBar->minPos)
        pSBar->curPos = pSBar->minPos;
        pSBar->curPos = pSBar->minPos;
 
 
    if (pSBar->pageStep <= 0)
    if (pSBar->pageStep <= 0)
        pSBar->pageStep = 0;
        pSBar->pageStep = 0;
    else if (pSBar->pageStep > (pSBar->maxPos - pSBar->minPos + 1))
    else if (pSBar->pageStep > (pSBar->maxPos - pSBar->minPos + 1))
        pSBar->pageStep = pSBar->maxPos - pSBar->minPos + 1;
        pSBar->pageStep = pSBar->maxPos - pSBar->minPos + 1;
 
 
    {
    {
        int max = pSBar->maxPos;
        int max = pSBar->maxPos;
        max -= ((pSBar->pageStep - 1) > 0)?(pSBar->pageStep - 1):0;
        max -= ((pSBar->pageStep - 1) > 0)?(pSBar->pageStep - 1):0;
 
 
        if (pSBar->curPos > max)
        if (pSBar->curPos > max)
            pSBar->curPos = max;
            pSBar->curPos = max;
    }
    }
 
 
    if (iSBar == SB_VERT)
    if (iSBar == SB_VERT)
    {
    {
        wndGetVScrollBarRect (pWin, &rcBar);
        wndGetVScrollBarRect (pWin, &rcBar);
        rcBar.left --;
        rcBar.left --;
        rcBar.right --;
        rcBar.right --;
    }
    }
    else
    else
    {
    {
        wndGetHScrollBarRect (pWin, &rcBar);
        wndGetHScrollBarRect (pWin, &rcBar);
        rcBar.top  --;
        rcBar.top  --;
        rcBar.bottom --;
        rcBar.bottom --;
    }
    }
    wndScrollBarPos (pWin, iSBar == SB_HORZ, &rcBar);
    wndScrollBarPos (pWin, iSBar == SB_HORZ, &rcBar);
 
 
#if 0
#if 0
    SendMessage (hWnd, WM_NCPAINT, 0, (LPARAM)(&rcBar));
    SendMessage (hWnd, WM_NCPAINT, 0, (LPARAM)(&rcBar));
#else
#else
    MwPaintNCScrollbars(hWnd,NULL);     /* a must */
    MwPaintNCScrollbars(hWnd,NULL);     /* a must */
#endif
#endif
 
 
    return TRUE;
    return TRUE;
}
}
 
 
BOOL  SetScrollInfo (HWND hWnd, int iSBar,
BOOL  SetScrollInfo (HWND hWnd, int iSBar,
                LPCSCROLLINFO lpsi, BOOL fRedraw)
                LPCSCROLLINFO lpsi, BOOL fRedraw)
{
{
    PMWSCROLLBARINFO pSBar;
    PMWSCROLLBARINFO pSBar;
    HWND pWin;
    HWND pWin;
    RECT rcBar;
    RECT rcBar;
 
 
    pWin = (HWND)hWnd;
    pWin = (HWND)hWnd;
 
 
    if ( !(pSBar = wndGetScrollBar (pWin, iSBar)) )
    if ( !(pSBar = wndGetScrollBar (pWin, iSBar)) )
        return FALSE;
        return FALSE;
 
 
    if( lpsi->fMask & SIF_RANGE )
    if( lpsi->fMask & SIF_RANGE )
    {
    {
        pSBar->minPos = (lpsi->nMin < lpsi->nMax)?lpsi->nMin:lpsi->nMax;
        pSBar->minPos = (lpsi->nMin < lpsi->nMax)?lpsi->nMin:lpsi->nMax;
        pSBar->maxPos = (lpsi->nMin < lpsi->nMax)?lpsi->nMax:lpsi->nMin;
        pSBar->maxPos = (lpsi->nMin < lpsi->nMax)?lpsi->nMax:lpsi->nMin;
    }
    }
 
 
    if( lpsi->fMask & SIF_POS )
    if( lpsi->fMask & SIF_POS )
        pSBar->curPos = lpsi->nPos;
        pSBar->curPos = lpsi->nPos;
 
 
    if( lpsi->fMask & SIF_PAGE )
    if( lpsi->fMask & SIF_PAGE )
        pSBar->pageStep = lpsi->nPage;
        pSBar->pageStep = lpsi->nPage;
 
 
    /* validate parameters. */
    /* validate parameters. */
    if (pSBar->curPos < pSBar->minPos)
    if (pSBar->curPos < pSBar->minPos)
        pSBar->curPos = pSBar->minPos;
        pSBar->curPos = pSBar->minPos;
 
 
    if (pSBar->pageStep <= 0)
    if (pSBar->pageStep <= 0)
        pSBar->pageStep = 0;
        pSBar->pageStep = 0;
    else if (pSBar->pageStep > (pSBar->maxPos - pSBar->minPos + 1))
    else if (pSBar->pageStep > (pSBar->maxPos - pSBar->minPos + 1))
        pSBar->pageStep = pSBar->maxPos - pSBar->minPos + 1;
        pSBar->pageStep = pSBar->maxPos - pSBar->minPos + 1;
 
 
    {
    {
        int max = pSBar->maxPos;
        int max = pSBar->maxPos;
        max -= ((pSBar->pageStep - 1) > 0)?(pSBar->pageStep - 1):0;
        max -= ((pSBar->pageStep - 1) > 0)?(pSBar->pageStep - 1):0;
 
 
        if (pSBar->curPos > max)
        if (pSBar->curPos > max)
            pSBar->curPos = max;
            pSBar->curPos = max;
    }
    }
 
 
    if(fRedraw)
    if(fRedraw)
    {
    {
        if (iSBar == SB_VERT)
        if (iSBar == SB_VERT)
        {
        {
            wndGetVScrollBarRect (pWin, &rcBar);
            wndGetVScrollBarRect (pWin, &rcBar);
            rcBar.left --;
            rcBar.left --;
            rcBar.right --;
            rcBar.right --;
        }
        }
        else
        else
        {
        {
            wndGetHScrollBarRect (pWin, &rcBar);
            wndGetHScrollBarRect (pWin, &rcBar);
            rcBar.top --;
            rcBar.top --;
            rcBar.bottom --;
            rcBar.bottom --;
        }
        }
        wndScrollBarPos (pWin, iSBar == SB_HORZ, &rcBar);
        wndScrollBarPos (pWin, iSBar == SB_HORZ, &rcBar);
 
 
#if 0
#if 0
        SendMessage (hWnd, WM_NCPAINT, 0, (LPARAM)(&rcBar));
        SendMessage (hWnd, WM_NCPAINT, 0, (LPARAM)(&rcBar));
#else
#else
        MwPaintNCScrollbars(hWnd,NULL); /* a must */
        MwPaintNCScrollbars(hWnd,NULL); /* a must */
#endif
#endif
    }
    }
 
 
    return TRUE;
    return TRUE;
}
}
 
 
BOOL  GetScrollInfo(HWND hWnd, int iSBar, LPSCROLLINFO lpsi)
BOOL  GetScrollInfo(HWND hWnd, int iSBar, LPSCROLLINFO lpsi)
{
{
    PMWSCROLLBARINFO pSBar;
    PMWSCROLLBARINFO pSBar;
    HWND pWin;
    HWND pWin;
 
 
    pWin = (HWND)hWnd;
    pWin = (HWND)hWnd;
 
 
    if ( !(pSBar = wndGetScrollBar (pWin, iSBar)) )
    if ( !(pSBar = wndGetScrollBar (pWin, iSBar)) )
        return FALSE;
        return FALSE;
 
 
    if( lpsi->fMask & SIF_RANGE )
    if( lpsi->fMask & SIF_RANGE )
    {
    {
        lpsi->nMin = pSBar->minPos;
        lpsi->nMin = pSBar->minPos;
        lpsi->nMax = pSBar->maxPos;
        lpsi->nMax = pSBar->maxPos;
    }
    }
 
 
    if( lpsi->fMask & SIF_POS )
    if( lpsi->fMask & SIF_POS )
    {
    {
        lpsi->nPos = pSBar->curPos;
        lpsi->nPos = pSBar->curPos;
    }
    }
 
 
    if( lpsi->fMask & SIF_PAGE )
    if( lpsi->fMask & SIF_PAGE )
        lpsi->nPage = pSBar->pageStep;
        lpsi->nPage = pSBar->pageStep;
 
 
    return TRUE;
    return TRUE;
}
}
 
 
BOOL  ShowScrollBar (HWND hWnd, int iSBar, BOOL bShow)
BOOL  ShowScrollBar (HWND hWnd, int iSBar, BOOL bShow)
{
{
    PMWSCROLLBARINFO pSBar;
    PMWSCROLLBARINFO pSBar;
    HWND pWin;
    HWND pWin;
    BOOL bPrevState;
    BOOL bPrevState;
    RECT rcBar;
    RECT rcBar;
 
 
    pWin = (HWND)hWnd;
    pWin = (HWND)hWnd;
 
 
    if ( !(pSBar = wndGetScrollBar (pWin, iSBar)) )
    if ( !(pSBar = wndGetScrollBar (pWin, iSBar)) )
        return FALSE;
        return FALSE;
 
 
    bPrevState = !(pSBar->status & SBS_HIDE);
    bPrevState = !(pSBar->status & SBS_HIDE);
 
 
    if (bShow && !bPrevState)
    if (bShow && !bPrevState)
        pSBar->status &= ~SBS_HIDE;
        pSBar->status &= ~SBS_HIDE;
    else if (!bShow && bPrevState)
    else if (!bShow && bPrevState)
        pSBar->status |= SBS_HIDE;
        pSBar->status |= SBS_HIDE;
    else
    else
        return FALSE;
        return FALSE;
#if 0   /* fix: no WM_CHANGESIZE */
#if 0   /* fix: no WM_CHANGESIZE */
    SendMessage (hWnd, WM_CHANGESIZE, 0, 0);
    SendMessage (hWnd, WM_CHANGESIZE, 0, 0);
#endif
#endif
    if (iSBar == SB_VERT)
    if (iSBar == SB_VERT)
        wndGetVScrollBarRect (pWin, &rcBar);
        wndGetVScrollBarRect (pWin, &rcBar);
    else
    else
        wndGetHScrollBarRect (pWin, &rcBar);
        wndGetHScrollBarRect (pWin, &rcBar);
 
 
    {
    {
        RECT rcWin, rcClient;
        RECT rcWin, rcClient;
 
 
        memcpy (&rcWin, &pWin->winrect.left, sizeof (RECT));
        memcpy (&rcWin, &pWin->winrect.left, sizeof (RECT));
 
 
        rcClient.left = 0;
        rcClient.left = 0;
        rcClient.top  = 0;
        rcClient.top  = 0;
        rcClient.right = pWin->clirect.right - pWin->clirect.left;
        rcClient.right = pWin->clirect.right - pWin->clirect.left;
        rcClient.bottom = pWin->clirect.bottom - pWin->clirect.top;
        rcClient.bottom = pWin->clirect.bottom - pWin->clirect.top;
#if 0   /* fix: no WM_SIZECHANGED */
#if 0   /* fix: no WM_SIZECHANGED */
        SendMessage/*SendAsyncMessage*/ (hWnd, WM_SIZECHANGED,
        SendMessage/*SendAsyncMessage*/ (hWnd, WM_SIZECHANGED,
            (WPARAM)&rcWin, (LPARAM)&rcClient);
            (WPARAM)&rcWin, (LPARAM)&rcClient);
#endif
#endif
    }
    }
 
 
    if (bShow) {
    if (bShow) {
        SendMessage (hWnd, WM_NCPAINT, 0, 0);
        SendMessage (hWnd, WM_NCPAINT, 0, 0);
    }
    }
    else {
    else {
        rcBar.left -= pWin->clirect.left;
        rcBar.left -= pWin->clirect.left;
        rcBar.top  -= pWin->clirect.top;
        rcBar.top  -= pWin->clirect.top;
        rcBar.right -= pWin->clirect.left;
        rcBar.right -= pWin->clirect.left;
        rcBar.bottom -= pWin->clirect.top;
        rcBar.bottom -= pWin->clirect.top;
        SendMessage (hWnd, WM_NCPAINT, 0, 0);
        SendMessage (hWnd, WM_NCPAINT, 0, 0);
        InvalidateRect (hWnd, &rcBar, TRUE);
        InvalidateRect (hWnd, &rcBar, TRUE);
    }
    }
 
 
    return TRUE;
    return TRUE;
}
}
#endif
#endif
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.