/*
|
/*
|
* 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 Scrollbars control
|
* Microwindows win32 Scrollbars control
|
*/
|
*/
|
#include <stdio.h>
|
#include <stdio.h>
|
#include <stdlib.h>
|
#include <stdlib.h>
|
#include <string.h>
|
#include <string.h>
|
#define MWINCLUDECOLORS /* jmt: for color macros */
|
#define MWINCLUDECOLORS /* jmt: for color macros */
|
#include "windows.h"
|
#include "windows.h"
|
#include "wintern.h"
|
#include "wintern.h"
|
#include "wintools.h"
|
#include "wintools.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 MWM_DEFBARLEN 18
|
#define MWM_DEFBARLEN 18
|
#define MWM_MINBARLEN 8
|
#define MWM_MINBARLEN 8
|
|
|
static LRESULT CALLBACK
|
static LRESULT CALLBACK
|
ScrollbarControlProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
|
ScrollbarControlProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
|
|
|
|
|
int WINAPI MwRegisterScrollbarControl(HINSTANCE hInstance)
|
int WINAPI MwRegisterScrollbarControl(HINSTANCE hInstance)
|
{
|
{
|
WNDCLASS wc;
|
WNDCLASS wc;
|
|
|
wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_GLOBALCLASS;
|
wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_GLOBALCLASS;
|
wc.lpfnWndProc = (WNDPROC)ScrollbarControlProc;
|
wc.lpfnWndProc = (WNDPROC)ScrollbarControlProc;
|
wc.cbClsExtra = 0;
|
wc.cbClsExtra = 0;
|
wc.cbWndExtra = 0;
|
wc.cbWndExtra = 0;
|
wc.hInstance = hInstance;
|
wc.hInstance = hInstance;
|
wc.hIcon = NULL;
|
wc.hIcon = NULL;
|
wc.hCursor = 0; /*LoadCursor(NULL, IDC_ARROW);*/
|
wc.hCursor = 0; /*LoadCursor(NULL, IDC_ARROW);*/
|
wc.hbrBackground= GetStockObject(WHITE_BRUSH);
|
wc.hbrBackground= GetStockObject(WHITE_BRUSH);
|
wc.lpszMenuName = NULL;
|
wc.lpszMenuName = NULL;
|
wc.lpszClassName= "SCROLLBAR";
|
wc.lpszClassName= "SCROLLBAR";
|
|
|
return RegisterClass(&wc);
|
return RegisterClass(&wc);
|
}
|
}
|
|
|
static DWORD GetWindowStyle (HWND hwnd)
|
static DWORD GetWindowStyle (HWND hwnd)
|
{
|
{
|
return hwnd->style;
|
return hwnd->style;
|
}
|
}
|
|
|
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)
|
{
|
{
|
int cx,cy; RECT rc;
|
int cx,cy; RECT rc;
|
MWSCROLLBARINFO* pData;
|
MWSCROLLBARINFO* pData;
|
|
|
pData = (MWSCROLLBARINFO *)hwnd->userdata;
|
pData = (MWSCROLLBARINFO *)hwnd->userdata;
|
rc = hwnd->winrect;
|
rc = hwnd->winrect;
|
cx=rc.right-rc.left;
|
cx=rc.right-rc.left;
|
cy=rc.bottom-rc.top;
|
cy=rc.bottom-rc.top;
|
|
|
rcVBar->left = hwnd->winrect.right - cx
|
rcVBar->left = hwnd->winrect.right - cx
|
- wndGetBorder (hwnd);
|
- wndGetBorder (hwnd);
|
rcVBar->right = hwnd->winrect.right - wndGetBorder (hwnd);
|
rcVBar->right = hwnd->winrect.right - wndGetBorder (hwnd);
|
rcVBar->top = hwnd->winrect.top;
|
rcVBar->top = hwnd->winrect.top;
|
rcVBar->bottom = hwnd->winrect.bottom - wndGetBorder (hwnd);
|
rcVBar->bottom = hwnd->winrect.bottom - wndGetBorder (hwnd);
|
|
|
return TRUE;
|
return TRUE;
|
}
|
}
|
|
|
static BOOL
|
static BOOL
|
wndGetHScrollBarRect (HWND hwnd, RECT* rcHBar)
|
wndGetHScrollBarRect (HWND hwnd, RECT* rcHBar)
|
{
|
{
|
int cx,cy; RECT rc;
|
int cx,cy; RECT rc;
|
MWSCROLLBARINFO* pData;
|
MWSCROLLBARINFO* pData;
|
|
|
pData = (MWSCROLLBARINFO *)hwnd->userdata;
|
pData = (MWSCROLLBARINFO *)hwnd->userdata;
|
rc = hwnd->winrect;
|
rc = hwnd->winrect;
|
cx=rc.right-rc.left;
|
cx=rc.right-rc.left;
|
cy=rc.bottom-rc.top;
|
cy=rc.bottom-rc.top;
|
|
|
rcHBar->top = hwnd->winrect.bottom - cy
|
rcHBar->top = hwnd->winrect.bottom - cy
|
- wndGetBorder (hwnd);
|
- wndGetBorder (hwnd);
|
rcHBar->bottom = hwnd->winrect.bottom - wndGetBorder (hwnd);
|
rcHBar->bottom = hwnd->winrect.bottom - wndGetBorder (hwnd);
|
rcHBar->left = hwnd->winrect.left;
|
rcHBar->left = hwnd->winrect.left;
|
rcHBar->right = hwnd->winrect.right - wndGetBorder (hwnd);
|
rcHBar->right = hwnd->winrect.right - wndGetBorder (hwnd);
|
|
|
return TRUE;
|
return TRUE;
|
}
|
}
|
|
|
void
|
void
|
MwPaintScrollbars(HWND hwnd, HDC hdc, DWORD style)
|
MwPaintScrollbars(HWND hwnd, HDC hdc, DWORD style)
|
{
|
{
|
BOOL vertbar = (style==SBS_VERT);
|
BOOL vertbar = (style==SBS_VERT);
|
BOOL horzbar = (style==SBS_HORZ);
|
BOOL horzbar = (style==SBS_HORZ);
|
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;
|
|
|
int cx,cy;
|
int cx,cy;
|
MWSCROLLBARINFO* pData;
|
MWSCROLLBARINFO* pData;
|
|
|
pData = (MWSCROLLBARINFO *)hwnd->userdata;
|
pData = (MWSCROLLBARINFO *)hwnd->userdata;
|
rc = hwnd->winrect;
|
rc = hwnd->winrect;
|
cx=rc.right-rc.left;
|
cx=rc.right-rc.left;
|
cy=rc.bottom-rc.top;
|
cy=rc.bottom-rc.top;
|
|
|
if (!hdc && (horzbar || vertbar)) {
|
if (!hdc && (horzbar || vertbar)) {
|
hdc = GetWindowDC(hwnd);
|
hdc = GetWindowDC(hwnd);
|
fGotDC = TRUE;
|
fGotDC = TRUE;
|
}
|
}
|
|
|
if (vertbar) {
|
if (vertbar) {
|
|
|
#if 1
|
#if 1
|
/* bkgnd */
|
/* bkgnd */
|
rc2.left=rc.left; rc2.right=rc2.left+ cx;
|
rc2.left=rc.left; rc2.right=rc2.left+ cx;
|
rc2.top=rc.top;
|
rc2.top=rc.top;
|
rc2.bottom=rc2.top+ cx;
|
rc2.bottom=rc2.top+ cx;
|
FillRect(hdc, &rc2, (HBRUSH)(COLOR_BTNFACE+1));
|
FillRect(hdc, &rc2, (HBRUSH)(COLOR_BTNFACE+1));
|
rc2.top=rc.bottom- cx;
|
rc2.top=rc.bottom- cx;
|
rc2.bottom=rc2.top+ cx;
|
rc2.bottom=rc2.top+ cx;
|
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,
|
cx, cx,
|
cx, cx,
|
pData->status & SBS_UPARROW);
|
pData->status & SBS_UPARROW);
|
/* down */
|
/* down */
|
Draw3dUpDownState(hdc, rc.left,rc.bottom-cx,
|
Draw3dUpDownState(hdc, rc.left,rc.bottom-cx,
|
cx, cx,
|
cx, cx,
|
pData->status & SBS_DOWNARROW);
|
pData->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 + (cx/2) - 1;
|
p3[0].x= rc.left + (cx/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 + (cx-4) - shrink;
|
p3[1].y= rc.top + (cx-4) - shrink;
|
p3[2].x= rc.left + (cx-4) - shrink;
|
p3[2].x= rc.left + (cx-4) - shrink;
|
p3[2].y= rc.top + (cx-4) - shrink;
|
p3[2].y= rc.top + (cx-4) - shrink;
|
Polygon(hdc,p3,3);
|
Polygon(hdc,p3,3);
|
/* down */
|
/* down */
|
p3[0].x= rc.left + (cx/2) - 1;
|
p3[0].x= rc.left + (cx/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-cx + 2 + shrink;
|
p3[1].y= rc.bottom-cx + 2 + shrink;
|
p3[2].x= rc.left + (cx-4) - shrink;
|
p3[2].x= rc.left + (cx-4) - shrink;
|
p3[2].y= rc.bottom-cx + 2 + shrink;
|
p3[2].y= rc.bottom-cx + 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 + cx + pData->barStart;
|
start = rcVBar.top + cx + pData->barStart;
|
|
|
if (start + pData->barLen > rcVBar.bottom)
|
if (start + pData->barLen > rcVBar.bottom)
|
start = rcVBar.bottom - pData->barLen;
|
start = rcVBar.bottom - pData->barLen;
|
|
|
if (pData->barLen == 0)
|
if (pData->barLen == 0)
|
pData->barLen=rc.bottom-rc.top-(cx*2);
|
pData->barLen=rc.bottom-rc.top-(cx*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+cx;
|
rc2.top=rc.top+cx;
|
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+pData->barLen;
|
rc2.top=start+pData->barLen;
|
rc2.bottom=rc.bottom-cx;
|
rc2.bottom=rc.bottom-cx;
|
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 + pData->barLen);
|
start + pData->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 + pData->barLen);*/
|
start + pData->barLen);*/
|
|
|
}
|
}
|
if (horzbar) {
|
if (horzbar) {
|
#if 1
|
#if 1
|
/* bkgnd */
|
/* bkgnd */
|
rc2.top=rc.top; rc2.bottom=rc2.top+ cy;
|
rc2.top=rc.top; rc2.bottom=rc2.top+ cy;
|
rc2.left=rc.left;
|
rc2.left=rc.left;
|
rc2.right=rc2.left+ cy;
|
rc2.right=rc2.left+ cy;
|
FillRect(hdc, &rc2, (HBRUSH)(COLOR_BTNFACE+1));
|
FillRect(hdc, &rc2, (HBRUSH)(COLOR_BTNFACE+1));
|
rc2.left=rc.right- cy;
|
rc2.left=rc.right- cy;
|
rc2.right=rc2.left+ cy;
|
rc2.right=rc2.left+ cy;
|
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,
|
cy, cy,
|
cy, cy,
|
pData->status & SBS_LEFTARROW);
|
pData->status & SBS_LEFTARROW);
|
/* right */
|
/* right */
|
Draw3dUpDownState(hdc, rc.right-cy, rc.top,
|
Draw3dUpDownState(hdc, rc.right-cy, rc.top,
|
cy, cy,
|
cy, cy,
|
pData->status & SBS_RIGHTARROW);
|
pData->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 + (cy/2) ;
|
p3[0].y= rc.top + (cy/2) ;
|
p3[1].x= rc.left + (cy-4) - shrink ;
|
p3[1].x= rc.left + (cy-4) - shrink ;
|
p3[1].y= rc.top + 2 + shrink;
|
p3[1].y= rc.top + 2 + shrink;
|
p3[2].x= rc.left + (cy-4) - shrink;
|
p3[2].x= rc.left + (cy-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 + (cy/2) ;
|
p3[0].y= rc.top + (cy/2) ;
|
p3[1].x= rc.right-cy + 2 + shrink ;
|
p3[1].x= rc.right-cy + 2 + shrink ;
|
p3[1].y= rc.top + 2 + shrink;
|
p3[1].y= rc.top + 2 + shrink;
|
p3[2].x= rc.right-cy + 2 + shrink;
|
p3[2].x= rc.right-cy + 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 + cy + pData->barStart;
|
start = rcHBar.left + cy + pData->barStart;
|
|
|
if (start + pData->barLen > rcHBar.right)
|
if (start + pData->barLen > rcHBar.right)
|
start = rcHBar.right - pData->barLen;
|
start = rcHBar.right - pData->barLen;
|
|
|
if (pData->barLen == 0)
|
if (pData->barLen == 0)
|
pData->barLen=rc.right-rc.left-(cy*2);
|
pData->barLen=rc.right-rc.left-(cy*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+cy;
|
rc2.left=rc.left+cy;
|
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+pData->barLen;
|
rc2.left=start+pData->barLen;
|
rc2.right=rc.right-cy;
|
rc2.right=rc.right-cy;
|
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 + pData->barLen,
|
Draw3dUpFrame (hdc, start, rcHBar.top, start + pData->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 + pData->barLen,
|
start, rcHBar.top, start + pData->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
|
MwHandleMessageScrollbar(HWND hwnd, WPARAM hitcode, LPARAM lParam, UINT msg, DWORD style)
|
MwHandleMessageScrollbar(HWND hwnd, WPARAM hitcode, LPARAM lParam, UINT msg, DWORD style)
|
{
|
{
|
int pos = SBS_UNKNOWN;
|
int pos = SBS_UNKNOWN;
|
BOOL vertbar = (style==SBS_VERT);
|
BOOL vertbar = (style==SBS_VERT);
|
BOOL horzbar = (style==SBS_HORZ);
|
BOOL horzbar = (style==SBS_HORZ);
|
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 */
|
|
|
int cx,cy;
|
int cx,cy;
|
MWSCROLLBARINFO* pData;
|
MWSCROLLBARINFO* pData;
|
|
|
pData = (MWSCROLLBARINFO *)hwnd->userdata;
|
pData = (MWSCROLLBARINFO *)hwnd->userdata;
|
rc = hwnd->winrect;
|
rc = hwnd->winrect;
|
cx=rc.right-rc.left;
|
cx=rc.right-rc.left;
|
cy=rc.bottom-rc.top;
|
cy=rc.bottom-rc.top;
|
|
|
POINTSTOPOINT(pt, lParam);
|
POINTSTOPOINT(pt, lParam);
|
for (;;) { /* use for() to allow break statement*/
|
for (;;) { /* use for() to allow break statement*/
|
if (vertbar)
|
if (vertbar)
|
{
|
{
|
pStat = &pData->status;
|
pStat = &pData->status;
|
rc = hwnd->winrect;
|
rc = hwnd->winrect;
|
rc.bottom = rc.top + cx;
|
rc.bottom = rc.top + cx;
|
if (PtInRect(&rc, pt))
|
if (PtInRect(&rc, pt))
|
{
|
{
|
pos = SBS_UPARROW;
|
pos = SBS_UPARROW;
|
break;
|
break;
|
}
|
}
|
rc.bottom = hwnd->winrect.bottom;
|
rc.bottom = hwnd->winrect.bottom;
|
rc.top = rc.bottom - cx;
|
rc.top = rc.bottom - cx;
|
if (PtInRect(&rc, pt))
|
if (PtInRect(&rc, pt))
|
{
|
{
|
pos = SBS_DOWNARROW;
|
pos = SBS_DOWNARROW;
|
break;
|
break;
|
}
|
}
|
pos = SBS_VERTTHUMB;
|
pos = SBS_VERTTHUMB;
|
} else if (horzbar)
|
} else if (horzbar)
|
{
|
{
|
pStat = &pData->status;
|
pStat = &pData->status;
|
rc = hwnd->winrect;
|
rc = hwnd->winrect;
|
rc.right = rc.left + cy;
|
rc.right = rc.left + cy;
|
if (PtInRect(&rc, pt)) {
|
if (PtInRect(&rc, pt)) {
|
pos = SBS_LEFTARROW;
|
pos = SBS_LEFTARROW;
|
break;
|
break;
|
}
|
}
|
rc.right = hwnd->winrect.right;
|
rc.right = hwnd->winrect.right;
|
rc.left = rc.right - cy;
|
rc.left = rc.right - cy;
|
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)
|
if (msg == WM_NCLBUTTONDOWN || msg == WM_NCLBUTTONDBLCLK)
|
*pStat |= pos;
|
*pStat |= pos;
|
else *pStat &= ~pos;
|
else *pStat &= ~pos;
|
|
|
if (msg == WM_NCLBUTTONDOWN || msg == WM_NCLBUTTONDBLCLK)
|
if (msg == WM_NCLBUTTONDOWN || msg == WM_NCLBUTTONDBLCLK)
|
bDraw=TRUE;
|
bDraw=TRUE;
|
|
|
if (bDraw)
|
if (bDraw)
|
MwPaintScrollbars(hwnd, NULL,style);
|
MwPaintScrollbars(hwnd, NULL,style);
|
|
|
if (pos == SBS_UPARROW || pos == SBS_LEFTARROW) /* jmt:2k0820 */
|
if (pos == SBS_UPARROW || pos == SBS_LEFTARROW) /* jmt:2k0820 */
|
{
|
{
|
if (pData->curPos != pData->minPos)
|
if (pData->curPos != pData->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 (pData->curPos != pData->maxPos)
|
if (pData->curPos != pData->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:
|
case WM_NCLBUTTONDBLCLK:
|
downPos = pos;
|
downPos = pos;
|
break;
|
break;
|
|
|
case WM_NCMOUSEMOVE:
|
case WM_NCMOUSEMOVE:
|
if (vertbar)
|
if (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->winrect;
|
rc = hwnd->winrect;
|
moveTop = rc.top + cx;
|
moveTop = rc.top + cx;
|
moveBottom = hwnd->winrect.bottom - cx;
|
moveBottom = hwnd->winrect.bottom - cx;
|
moveRange = moveBottom - moveTop;
|
moveRange = moveBottom - moveTop;
|
|
|
itemCount = pData->maxPos - pData->minPos + 1;
|
itemCount = pData->maxPos - pData->minPos + 1;
|
itemVisible = pData->pageStep;
|
itemVisible = pData->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 >= pData->minPos &&
|
if ( newThumbPos >= pData->minPos &&
|
newThumbPos <= pData->maxPos)
|
newThumbPos <= pData->maxPos)
|
{
|
{
|
SendMessage (hwnd,
|
SendMessage (hwnd,
|
WM_VSCROLL, SB_THUMBTRACK, newThumbPos);
|
WM_VSCROLL, SB_THUMBTRACK, newThumbPos);
|
|
|
SendMessage (GetParent(hwnd),
|
SendMessage (GetParent(hwnd),
|
WM_VSCROLL, SB_THUMBTRACK, newThumbPos);
|
WM_VSCROLL, SB_THUMBTRACK, newThumbPos);
|
}
|
}
|
break;
|
break;
|
}
|
}
|
}
|
}
|
if (horzbar)
|
if (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->winrect;
|
rc = hwnd->winrect;
|
moveLeft = rc.left + cy;
|
moveLeft = rc.left + cy;
|
moveRight = hwnd->winrect.right - cy;
|
moveRight = hwnd->winrect.right - cy;
|
moveRange = moveRight - moveLeft;
|
moveRange = moveRight - moveLeft;
|
|
|
itemCount = pData->maxPos - pData->minPos + 1;
|
itemCount = pData->maxPos - pData->minPos + 1;
|
itemVisible = pData->pageStep;
|
itemVisible = pData->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 >= pData->minPos &&
|
if ( newThumbPos >= pData->minPos &&
|
newThumbPos <= pData->maxPos)
|
newThumbPos <= pData->maxPos)
|
{
|
{
|
SendMessage (hwnd,
|
SendMessage (hwnd,
|
WM_HSCROLL, SB_THUMBTRACK, newThumbPos);
|
WM_HSCROLL, SB_THUMBTRACK, newThumbPos);
|
|
|
SendMessage (GetParent(hwnd),
|
SendMessage (GetParent(hwnd),
|
WM_HSCROLL, SB_THUMBTRACK, newThumbPos);
|
WM_HSCROLL, SB_THUMBTRACK, newThumbPos);
|
}
|
}
|
break;
|
break;
|
}
|
}
|
}
|
}
|
break;
|
break;
|
|
|
case WM_NCLBUTTONUP:
|
case WM_NCLBUTTONUP:
|
bDraw=FALSE;
|
bDraw=FALSE;
|
downPos = SBS_UNKNOWN;
|
downPos = SBS_UNKNOWN;
|
|
|
if (sbCode==SB_THUMBTRACK)
|
if (sbCode==SB_THUMBTRACK)
|
{
|
{
|
if (vertbar)
|
if (vertbar)
|
{
|
{
|
/* jmt(2k0819): new algorithm for SB_THUMBTRACK */
|
/* jmt(2k0819): new algorithm for SB_THUMBTRACK */
|
|
|
rc = hwnd->winrect;
|
rc = hwnd->winrect;
|
moveTop = rc.top + cx;
|
moveTop = rc.top + cx;
|
moveBottom = hwnd->winrect.bottom - cx;
|
moveBottom = hwnd->winrect.bottom - cx;
|
moveRange = moveBottom - moveTop;
|
moveRange = moveBottom - moveTop;
|
|
|
itemCount = pData->maxPos - pData->minPos + 1;
|
itemCount = pData->maxPos - pData->minPos + 1;
|
itemVisible = pData->pageStep;
|
itemVisible = pData->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 >= pData->minPos &&
|
if ( newThumbPos >= pData->minPos &&
|
newThumbPos <= pData->maxPos)
|
newThumbPos <= pData->maxPos)
|
{
|
{
|
SendMessage (hwnd,
|
SendMessage (hwnd,
|
WM_VSCROLL, SB_THUMBTRACK, newThumbPos);
|
WM_VSCROLL, SB_THUMBTRACK, newThumbPos);
|
|
|
SendMessage (GetParent(hwnd),
|
SendMessage (GetParent(hwnd),
|
WM_VSCROLL, SB_THUMBTRACK, newThumbPos);
|
WM_VSCROLL, SB_THUMBTRACK, newThumbPos);
|
}
|
}
|
break; /* case */
|
break; /* case */
|
}
|
}
|
if (horzbar)
|
if (horzbar)
|
{
|
{
|
/* jmt(2k0819): new algorithm for SB_THUMBTRACK */
|
/* jmt(2k0819): new algorithm for SB_THUMBTRACK */
|
|
|
rc = hwnd->winrect;
|
rc = hwnd->winrect;
|
moveLeft = rc.left + cy;
|
moveLeft = rc.left + cy;
|
moveRight = hwnd->winrect.right - cy;
|
moveRight = hwnd->winrect.right - cy;
|
moveRange = moveRight - moveLeft;
|
moveRange = moveRight - moveLeft;
|
|
|
itemCount = pData->maxPos - pData->minPos + 1;
|
itemCount = pData->maxPos - pData->minPos + 1;
|
itemVisible = pData->pageStep;
|
itemVisible = pData->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 >= pData->minPos &&
|
if ( newThumbPos >= pData->minPos &&
|
newThumbPos <= pData->maxPos)
|
newThumbPos <= pData->maxPos)
|
{
|
{
|
SendMessage (hwnd,
|
SendMessage (hwnd,
|
WM_HSCROLL, SB_THUMBTRACK, newThumbPos);
|
WM_HSCROLL, SB_THUMBTRACK, newThumbPos);
|
|
|
SendMessage (GetParent(hwnd),
|
SendMessage (GetParent(hwnd),
|
WM_HSCROLL, SB_THUMBTRACK, newThumbPos);
|
WM_HSCROLL, SB_THUMBTRACK, newThumbPos);
|
}
|
}
|
break; /* case */
|
break; /* case */
|
}
|
}
|
}
|
}
|
else
|
else
|
{
|
{
|
if (vertbar)
|
if (vertbar)
|
{
|
{
|
SendMessage (hwnd, WM_VSCROLL, sbCode, 0);
|
SendMessage (hwnd, WM_VSCROLL, sbCode, 0);
|
SendMessage (GetParent(hwnd), WM_VSCROLL, sbCode, 0);
|
SendMessage (GetParent(hwnd), WM_VSCROLL, sbCode, 0);
|
}
|
}
|
if (horzbar)
|
if (horzbar)
|
{
|
{
|
SendMessage (hwnd, WM_HSCROLL, sbCode, 0);
|
SendMessage (hwnd, WM_HSCROLL, sbCode, 0);
|
SendMessage (GetParent(hwnd), WM_HSCROLL, sbCode, 0);
|
SendMessage (GetParent(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);
|
}
|
}
|
|
|
static void
|
static void
|
wndScrollBarPos (HWND hwnd, BOOL bIsHBar, RECT* rcBar) /* jmt: 2k0820 */
|
wndScrollBarPos (HWND hwnd, BOOL bIsHBar, RECT* rcBar) /* jmt: 2k0820 */
|
{
|
{
|
UINT moveRange;
|
UINT moveRange;
|
PMWSCROLLBARINFO pSBar;
|
PMWSCROLLBARINFO pSBar;
|
int cx,cy;
|
int cx,cy;
|
RECT rc;
|
RECT rc;
|
|
|
rc = hwnd->winrect;
|
rc = hwnd->winrect;
|
cx=rc.right-rc.left;
|
cx=rc.right-rc.left;
|
cy=rc.bottom-rc.top;
|
cy=rc.bottom-rc.top;
|
pSBar = (MWSCROLLBARINFO *)hwnd->userdata;
|
pSBar = (MWSCROLLBARINFO *)hwnd->userdata;
|
|
|
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) - (cy << 1);
|
moveRange = (rcBar->right - rcBar->left) - (cy << 1);
|
else
|
else
|
moveRange = (rcBar->bottom - rcBar->top) - (cx << 1);
|
moveRange = (rcBar->bottom - rcBar->top) - (cx << 1);
|
|
|
|
|
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) /* jmt: 2k0820 */
|
static PMWSCROLLBARINFO wndGetScrollBar (HWND pWin) /* jmt: 2k0820 */
|
{
|
{
|
MWSCROLLBARINFO* pData;
|
MWSCROLLBARINFO* pData;
|
|
|
pData = (MWSCROLLBARINFO *)pWin->userdata;
|
pData = (MWSCROLLBARINFO *)pWin->userdata;
|
|
|
if (!strcmp(pWin->pClass->lpszClassName,"SCROLLBAR"))
|
if (!strcmp(pWin->pClass->lpszClassName,"SCROLLBAR"))
|
return pData;
|
return pData;
|
else
|
else
|
return NULL;
|
return NULL;
|
}
|
}
|
|
|
BOOL EnableScrollBarEx (HWND hWnd, int iSBar, BOOL bEnable) /* jmt: iSBar not used */
|
BOOL EnableScrollBarEx (HWND hWnd, int iSBar, BOOL bEnable) /* jmt: iSBar not used */
|
{
|
{
|
PMWSCROLLBARINFO pSBar;
|
PMWSCROLLBARINFO pSBar;
|
HWND pWin;
|
HWND pWin;
|
BOOL bPrevState;
|
BOOL bPrevState;
|
RECT rcBar;
|
RECT rcBar;
|
|
|
DWORD dwStyle; /* jmt:2k0820 */
|
DWORD dwStyle; /* jmt:2k0820 */
|
|
|
pWin = (HWND)hWnd;
|
pWin = (HWND)hWnd;
|
|
|
if ( !(pSBar = wndGetScrollBar (pWin)) )
|
if ( !(pSBar = wndGetScrollBar (pWin)) )
|
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;
|
|
|
dwStyle = (GetWindowStyle (hWnd) & SBS_TYPEMASK); /* jmt: 2k0820 */
|
dwStyle = (GetWindowStyle (hWnd) & SBS_TYPEMASK); /* jmt: 2k0820 */
|
|
|
if (dwStyle == SBS_VERT)
|
if (dwStyle == SBS_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
|
MwPaintScrollbars(hWnd,NULL,dwStyle); /* a must */
|
MwPaintScrollbars(hWnd,NULL,dwStyle); /* a must */
|
#endif
|
#endif
|
|
|
return TRUE;
|
return TRUE;
|
}
|
}
|
|
|
BOOL GetScrollPosEx (HWND hWnd, int iSBar, int* pPos) /* jmt: iSBar not used */
|
BOOL GetScrollPosEx (HWND hWnd, int iSBar, int* pPos) /* jmt: iSBar not used */
|
{
|
{
|
PMWSCROLLBARINFO pSBar;
|
PMWSCROLLBARINFO pSBar;
|
HWND pWin;
|
HWND pWin;
|
|
|
pWin = (HWND)hWnd;
|
pWin = (HWND)hWnd;
|
|
|
if ( !(pSBar = wndGetScrollBar (pWin)) )
|
if ( !(pSBar = wndGetScrollBar (pWin)) )
|
return FALSE;
|
return FALSE;
|
|
|
*pPos = pSBar->curPos;
|
*pPos = pSBar->curPos;
|
return TRUE;
|
return TRUE;
|
}
|
}
|
|
|
BOOL GetScrollRangeEx (HWND hWnd, int iSBar, int* pMinPos, int* pMaxPos) /* jmt: iSBar not used */
|
BOOL GetScrollRangeEx (HWND hWnd, int iSBar, int* pMinPos, int* pMaxPos) /* jmt: iSBar not used */
|
{
|
{
|
PMWSCROLLBARINFO pSBar;
|
PMWSCROLLBARINFO pSBar;
|
HWND pWin;
|
HWND pWin;
|
|
|
pWin = (HWND)hWnd;
|
pWin = (HWND)hWnd;
|
|
|
if ( !(pSBar = wndGetScrollBar (pWin)) )
|
if ( !(pSBar = wndGetScrollBar (pWin)) )
|
return FALSE;
|
return FALSE;
|
|
|
*pMinPos = pSBar->minPos;
|
*pMinPos = pSBar->minPos;
|
*pMaxPos = pSBar->maxPos;
|
*pMaxPos = pSBar->maxPos;
|
return TRUE;
|
return TRUE;
|
}
|
}
|
|
|
BOOL SetScrollPosEx (HWND hWnd, int iSBar, int iNewPos) /* jmt: iSBar not used */
|
BOOL SetScrollPosEx (HWND hWnd, int iSBar, int iNewPos) /* jmt: iSBar not used */
|
{
|
{
|
PMWSCROLLBARINFO pSBar;
|
PMWSCROLLBARINFO pSBar;
|
HWND pWin;
|
HWND pWin;
|
RECT rcBar;
|
RECT rcBar;
|
|
|
DWORD dwStyle; /* jmt:2k0820 */
|
DWORD dwStyle; /* jmt:2k0820 */
|
|
|
pWin = (HWND)hWnd;
|
pWin = (HWND)hWnd;
|
|
|
if ( !(pSBar = wndGetScrollBar (pWin)) )
|
if ( !(pSBar = wndGetScrollBar (pWin)) )
|
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;
|
}
|
}
|
|
|
dwStyle = (GetWindowStyle (hWnd) & SBS_TYPEMASK); /* jmt: 2k0820 */
|
dwStyle = (GetWindowStyle (hWnd) & SBS_TYPEMASK); /* jmt: 2k0820 */
|
|
|
if (dwStyle == SBS_VERT)
|
if (dwStyle == SBS_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, dwStyle == SBS_HORZ, &rcBar);
|
wndScrollBarPos (pWin, dwStyle == SBS_HORZ, &rcBar);
|
|
|
#if 0
|
#if 0
|
SendMessage (hWnd, WM_NCPAINT, 0, (LPARAM)(&rcBar));
|
SendMessage (hWnd, WM_NCPAINT, 0, (LPARAM)(&rcBar));
|
#else
|
#else
|
MwPaintScrollbars(hWnd,NULL,dwStyle); /* a must */
|
MwPaintScrollbars(hWnd,NULL,dwStyle); /* a must */
|
#endif
|
#endif
|
return TRUE;
|
return TRUE;
|
}
|
}
|
|
|
BOOL SetScrollRangeEx (HWND hWnd, int iSBar, int iMinPos, int iMaxPos) /* jmt: iSBar not used */
|
BOOL SetScrollRangeEx (HWND hWnd, int iSBar, int iMinPos, int iMaxPos) /* jmt: iSBar not used */
|
{
|
{
|
PMWSCROLLBARINFO pSBar;
|
PMWSCROLLBARINFO pSBar;
|
HWND pWin;
|
HWND pWin;
|
RECT rcBar;
|
RECT rcBar;
|
|
|
DWORD dwStyle; /* jmt:2k0820 */
|
DWORD dwStyle; /* jmt:2k0820 */
|
|
|
pWin = (HWND)hWnd;
|
pWin = (HWND)hWnd;
|
|
|
if ( !(pSBar = wndGetScrollBar (pWin)) )
|
if ( !(pSBar = wndGetScrollBar (pWin)) )
|
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;
|
}
|
}
|
|
|
dwStyle = (GetWindowStyle (hWnd) & SBS_TYPEMASK); /* jmt: 2k0820 */
|
dwStyle = (GetWindowStyle (hWnd) & SBS_TYPEMASK); /* jmt: 2k0820 */
|
|
|
if (dwStyle == SBS_VERT)
|
if (dwStyle == SBS_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, dwStyle == SBS_HORZ, &rcBar);
|
wndScrollBarPos (pWin, dwStyle == SBS_HORZ, &rcBar);
|
|
|
#if 0
|
#if 0
|
SendMessage (hWnd, WM_NCPAINT, 0, (LPARAM)(&rcBar));
|
SendMessage (hWnd, WM_NCPAINT, 0, (LPARAM)(&rcBar));
|
#else
|
#else
|
MwPaintScrollbars(hWnd,NULL,dwStyle); /* a must */
|
MwPaintScrollbars(hWnd,NULL,dwStyle); /* a must */
|
#endif
|
#endif
|
|
|
return TRUE;
|
return TRUE;
|
}
|
}
|
|
|
BOOL SetScrollInfoEx (HWND hWnd, int iSBar,
|
BOOL SetScrollInfoEx (HWND hWnd, int iSBar,
|
LPCSCROLLINFO lpsi, BOOL fRedraw) /* jmt: iSBar not used */
|
LPCSCROLLINFO lpsi, BOOL fRedraw) /* jmt: iSBar not used */
|
{
|
{
|
PMWSCROLLBARINFO pSBar;
|
PMWSCROLLBARINFO pSBar;
|
HWND pWin;
|
HWND pWin;
|
RECT rcBar;
|
RECT rcBar;
|
|
|
DWORD dwStyle; /* jmt:2k0820 */
|
DWORD dwStyle; /* jmt:2k0820 */
|
|
|
pWin = (HWND)hWnd;
|
pWin = (HWND)hWnd;
|
|
|
if ( !(pSBar = wndGetScrollBar (pWin)) )
|
if ( !(pSBar = wndGetScrollBar (pWin)) )
|
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;
|
}
|
}
|
|
|
dwStyle = (GetWindowStyle (hWnd) & SBS_TYPEMASK); /* jmt: 2k0820 */
|
dwStyle = (GetWindowStyle (hWnd) & SBS_TYPEMASK); /* jmt: 2k0820 */
|
|
|
if(fRedraw)
|
if(fRedraw)
|
{
|
{
|
if (dwStyle == SBS_VERT)
|
if (dwStyle == SBS_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, dwStyle == SBS_HORZ, &rcBar);
|
wndScrollBarPos (pWin, dwStyle == SBS_HORZ, &rcBar);
|
|
|
#if 0
|
#if 0
|
SendMessage (hWnd, WM_NCPAINT, 0, (LPARAM)(&rcBar));
|
SendMessage (hWnd, WM_NCPAINT, 0, (LPARAM)(&rcBar));
|
#else
|
#else
|
MwPaintScrollbars(hWnd,NULL,dwStyle); /* a must */
|
MwPaintScrollbars(hWnd,NULL,dwStyle); /* a must */
|
#endif
|
#endif
|
}
|
}
|
|
|
return TRUE;
|
return TRUE;
|
}
|
}
|
|
|
BOOL GetScrollInfoEx(HWND hWnd, int iSBar, LPSCROLLINFO lpsi) /* jmt: iSBar not used */
|
BOOL GetScrollInfoEx(HWND hWnd, int iSBar, LPSCROLLINFO lpsi) /* jmt: iSBar not used */
|
{
|
{
|
PMWSCROLLBARINFO pSBar;
|
PMWSCROLLBARINFO pSBar;
|
HWND pWin;
|
HWND pWin;
|
|
|
pWin = (HWND)hWnd;
|
pWin = (HWND)hWnd;
|
|
|
if ( !(pSBar = wndGetScrollBar (pWin)) )
|
if ( !(pSBar = wndGetScrollBar (pWin)) )
|
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 ShowScrollBarEx (HWND hWnd, int iSBar, BOOL bShow) /* jmt: iSBar not used */
|
BOOL ShowScrollBarEx (HWND hWnd, int iSBar, BOOL bShow) /* jmt: iSBar not used */
|
{
|
{
|
PMWSCROLLBARINFO pSBar;
|
PMWSCROLLBARINFO pSBar;
|
HWND pWin;
|
HWND pWin;
|
BOOL bPrevState;
|
BOOL bPrevState;
|
RECT rcBar;
|
RECT rcBar;
|
|
|
DWORD dwStyle; /* jmt:2k0820 */
|
DWORD dwStyle; /* jmt:2k0820 */
|
|
|
pWin = (HWND)hWnd;
|
pWin = (HWND)hWnd;
|
|
|
if ( !(pSBar = wndGetScrollBar (pWin)) )
|
if ( !(pSBar = wndGetScrollBar (pWin)) )
|
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
|
|
|
dwStyle = (GetWindowStyle (hWnd) & SBS_TYPEMASK); /* jmt: 2k0820 */
|
dwStyle = (GetWindowStyle (hWnd) & SBS_TYPEMASK); /* jmt: 2k0820 */
|
|
|
if (dwStyle == SBS_VERT)
|
if (dwStyle == SBS_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 (hWnd, WM_SIZECHANGED,
|
SendMessage (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;
|
}
|
}
|
|
|
static void sbSetScrollInfo (HWND hwnd, PMWSCROLLBARINFO pData, BOOL fRedraw) /* jmt:2k0820 */
|
static void sbSetScrollInfo (HWND hwnd, PMWSCROLLBARINFO pData, BOOL fRedraw) /* jmt:2k0820 */
|
{
|
{
|
SCROLLINFO si;
|
SCROLLINFO si;
|
|
|
int itemCount,itemVisibles;
|
int itemCount,itemVisibles;
|
|
|
itemCount = pData->maxPos - pData->minPos + 1;
|
itemCount = pData->maxPos - pData->minPos + 1;
|
itemVisibles = pData->pageStep;
|
itemVisibles = pData->pageStep;
|
|
|
if (itemVisibles >= itemCount)
|
if (itemVisibles >= itemCount)
|
{
|
{
|
SetScrollPosEx (hwnd, 0, 0); /* jmt: arg2 not used */
|
SetScrollPosEx (hwnd, 0, 0); /* jmt: arg2 not used */
|
EnableScrollBarEx (hwnd, 0, FALSE); /* jmt: arg2 not used */
|
EnableScrollBarEx (hwnd, 0, FALSE); /* jmt: arg2 not used */
|
return;
|
return;
|
}
|
}
|
|
|
si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
|
si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
|
si.nMax = itemCount - 1;
|
si.nMax = itemCount - 1;
|
si.nMin = 0;
|
si.nMin = 0;
|
|
|
si.nPage = itemVisibles; /* jmt(2k0819): new algorithm for SB_THUMBTRACK */
|
si.nPage = itemVisibles; /* jmt(2k0819): new algorithm for SB_THUMBTRACK */
|
|
|
si.nPos = pData->curPos;
|
si.nPos = pData->curPos;
|
|
|
SetScrollInfoEx (hwnd, 0, &si, fRedraw); /* jmt: arg2 not used */
|
SetScrollInfoEx (hwnd, 0, &si, fRedraw); /* jmt: arg2 not used */
|
EnableScrollBarEx (hwnd, 0, TRUE); /* jmt: arg2 not used */
|
EnableScrollBarEx (hwnd, 0, TRUE); /* jmt: arg2 not used */
|
}
|
}
|
|
|
static LRESULT CALLBACK
|
static LRESULT CALLBACK
|
ScrollbarControlProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) /* jmt:2k0820 */
|
ScrollbarControlProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) /* jmt:2k0820 */
|
{
|
{
|
DWORD dwStyle;
|
DWORD dwStyle;
|
MWSCROLLBARINFO* pData;
|
MWSCROLLBARINFO* pData;
|
|
|
int moveRange;
|
int moveRange;
|
RECT rcBar;
|
RECT rcBar;
|
|
|
dwStyle = (GetWindowStyle (hwnd) & SBS_TYPEMASK);
|
dwStyle = (GetWindowStyle (hwnd) & SBS_TYPEMASK);
|
switch (message)
|
switch (message)
|
{
|
{
|
case WM_CREATE:
|
case WM_CREATE:
|
if (!(pData = malloc (sizeof (MWSCROLLBARINFO))))
|
if (!(pData = malloc (sizeof (MWSCROLLBARINFO))))
|
{
|
{
|
fprintf(stderr, "Create scroll bar control failure!\n");
|
fprintf(stderr, "Create scroll bar control failure!\n");
|
return -1;
|
return -1;
|
}
|
}
|
|
|
pData->minPos=0; /* min value of scroll range.*/
|
pData->minPos=0; /* min value of scroll range.*/
|
/* max value of scroll range.*/
|
/* max value of scroll range.*/
|
pData->maxPos=0;
|
pData->maxPos=0;
|
if (dwStyle==SBS_VERT)
|
if (dwStyle==SBS_VERT)
|
moveRange=((hwnd->winrect.bottom-hwnd->winrect.top)
|
moveRange=((hwnd->winrect.bottom-hwnd->winrect.top)
|
-((hwnd->winrect.right-hwnd->winrect.left)<<1));
|
-((hwnd->winrect.right-hwnd->winrect.left)<<1));
|
else
|
else
|
moveRange=((hwnd->winrect.right-hwnd->winrect.left)
|
moveRange=((hwnd->winrect.right-hwnd->winrect.left)
|
-((hwnd->winrect.bottom-hwnd->winrect.top)<<1));
|
-((hwnd->winrect.bottom-hwnd->winrect.top)<<1));
|
if (moveRange > MWM_MINBARLEN)
|
if (moveRange > MWM_MINBARLEN)
|
{
|
{
|
|
|
|
|
pData->maxPos=moveRange / MWM_MINBARLEN;
|
pData->maxPos=moveRange / MWM_MINBARLEN;
|
if( (moveRange % MWM_MINBARLEN) )
|
if( (moveRange % MWM_MINBARLEN) )
|
pData->maxPos++;
|
pData->maxPos++;
|
}
|
}
|
printf("maxPos=%d\n",pData->maxPos);
|
printf("maxPos=%d\n",pData->maxPos);
|
|
|
pData->curPos=0; /* current scroll pos.*/
|
pData->curPos=0; /* current scroll pos.*/
|
|
|
/* steps per page.*/
|
/* steps per page.*/
|
pData->pageStep=1;
|
pData->pageStep=1;
|
if ( (pData->maxPos - 2) > 1)
|
if ( (pData->maxPos - 2) > 1)
|
pData->pageStep = pData->maxPos - 2;
|
pData->pageStep = pData->maxPos - 2;
|
printf("pageStep=%d\n",pData->pageStep);
|
printf("pageStep=%d\n",pData->pageStep);
|
|
|
pData->barStart=0; /* start pixel of bar.*/
|
pData->barStart=0; /* start pixel of bar.*/
|
pData->barLen=MWM_MINBARLEN; /* length of bar.*/
|
pData->barLen=MWM_MINBARLEN; /* length of bar.*/
|
pData->status=SBS_UNKNOWN; /* status of scroll bar.*/
|
pData->status=SBS_UNKNOWN; /* status of scroll bar.*/
|
#if 0 /* jmt: must handle WM_MOVE */
|
#if 0 /* jmt: must handle WM_MOVE */
|
pData->rc=hwnd->winrect; /* screen coordinates position*/
|
pData->rc=hwnd->winrect; /* screen coordinates position*/
|
#endif
|
#endif
|
hwnd->userdata = (DWORD)pData;
|
hwnd->userdata = (DWORD)pData;
|
|
|
if (dwStyle == SBS_VERT)
|
if (dwStyle == SBS_VERT)
|
{
|
{
|
wndGetVScrollBarRect (hwnd, &rcBar);
|
wndGetVScrollBarRect (hwnd, &rcBar);
|
rcBar.left --;
|
rcBar.left --;
|
rcBar.right --;
|
rcBar.right --;
|
}
|
}
|
else
|
else
|
{
|
{
|
wndGetHScrollBarRect (hwnd, &rcBar);
|
wndGetHScrollBarRect (hwnd, &rcBar);
|
rcBar.top --;
|
rcBar.top --;
|
rcBar.bottom --;
|
rcBar.bottom --;
|
}
|
}
|
/* adjust pData->barLen */
|
/* adjust pData->barLen */
|
wndScrollBarPos (hwnd, dwStyle == SBS_HORZ, &rcBar);
|
wndScrollBarPos (hwnd, dwStyle == SBS_HORZ, &rcBar);
|
|
|
break;
|
break;
|
|
|
case WM_DESTROY:
|
case WM_DESTROY:
|
free ((void *)(hwnd->userdata));
|
free ((void *)(hwnd->userdata));
|
break;
|
break;
|
|
|
case WM_PAINT:
|
case WM_PAINT:
|
MwPaintScrollbars(hwnd,NULL,dwStyle);
|
MwPaintScrollbars(hwnd,NULL,dwStyle);
|
break;
|
break;
|
|
|
case WM_NCLBUTTONDOWN:
|
case WM_NCLBUTTONDOWN:
|
case WM_NCLBUTTONDBLCLK:
|
case WM_NCLBUTTONDBLCLK:
|
case WM_NCMOUSEMOVE:
|
case WM_NCMOUSEMOVE:
|
case WM_NCLBUTTONUP:
|
case WM_NCLBUTTONUP:
|
MwHandleMessageScrollbar(hwnd, wParam, lParam, message, dwStyle);
|
MwHandleMessageScrollbar(hwnd, wParam, lParam, message, dwStyle);
|
break;
|
break;
|
|
|
case WM_HSCROLL:
|
case WM_HSCROLL:
|
case WM_VSCROLL:
|
case WM_VSCROLL:
|
{
|
{
|
int newTop,itemCount,itemVisibles;
|
int newTop,itemCount,itemVisibles;
|
|
|
pData = (MWSCROLLBARINFO *)hwnd->userdata;
|
pData = (MWSCROLLBARINFO *)hwnd->userdata;
|
newTop = pData->curPos;
|
newTop = pData->curPos;
|
itemCount = pData->maxPos - pData->minPos + 1;
|
itemCount = pData->maxPos - pData->minPos + 1;
|
itemVisibles = pData->pageStep;
|
itemVisibles = pData->pageStep;
|
|
|
switch(wParam)
|
switch(wParam)
|
{
|
{
|
case SB_LINEDOWN:
|
case SB_LINEDOWN:
|
#define ITEM_BOTTOM(x) (x->curPos + itemVisibles - 1)
|
#define ITEM_BOTTOM(x) (x->curPos + itemVisibles - 1)
|
if (ITEM_BOTTOM (pData) < (itemCount - 1 ))
|
if (ITEM_BOTTOM (pData) < (itemCount - 1 ))
|
{
|
{
|
newTop ++;
|
newTop ++;
|
}
|
}
|
break;
|
break;
|
|
|
case SB_LINEUP:
|
case SB_LINEUP:
|
if (pData->curPos > 0)
|
if (pData->curPos > 0)
|
{
|
{
|
newTop --;
|
newTop --;
|
}
|
}
|
break;
|
break;
|
|
|
case SB_PAGEDOWN:
|
case SB_PAGEDOWN:
|
if ((pData->curPos + (itemVisibles << 1)) <=
|
if ((pData->curPos + (itemVisibles << 1)) <=
|
itemCount)
|
itemCount)
|
newTop += itemVisibles;
|
newTop += itemVisibles;
|
else
|
else
|
newTop = itemCount - itemVisibles;
|
newTop = itemCount - itemVisibles;
|
|
|
if (newTop < 0)
|
if (newTop < 0)
|
return 0;
|
return 0;
|
|
|
break;
|
break;
|
|
|
case SB_PAGEUP:
|
case SB_PAGEUP:
|
if (pData->curPos >= itemVisibles)
|
if (pData->curPos >= itemVisibles)
|
newTop -= itemVisibles;
|
newTop -= itemVisibles;
|
else
|
else
|
newTop = 0;
|
newTop = 0;
|
|
|
break;
|
break;
|
|
|
case SB_THUMBTRACK:
|
case SB_THUMBTRACK:
|
newTop = (int)lParam;
|
newTop = (int)lParam;
|
break;
|
break;
|
}
|
}
|
|
|
pData->curPos = newTop;
|
pData->curPos = newTop;
|
|
|
SendMessage (hwnd, WM_PAINT, 0, 0);
|
SendMessage (hwnd, WM_PAINT, 0, 0);
|
|
|
sbSetScrollInfo (hwnd, pData, TRUE);
|
sbSetScrollInfo (hwnd, pData, TRUE);
|
|
|
return 0;
|
return 0;
|
}
|
}
|
break;
|
break;
|
|
|
default:
|
default:
|
return DefWindowProc (hwnd, message, wParam, lParam);
|
return DefWindowProc (hwnd, message, wParam, lParam);
|
}
|
}
|
return 0;
|
return 0;
|
}
|
}
|
|
|
|
|