362 lines
8.0 KiB
C++
362 lines
8.0 KiB
C++
#ifndef _NNTP_SCROLLINFO_HPP_
|
|
#define _NNTP_SCROLLINFO_HPP_
|
|
#ifndef _COMMON_WINDOWS_HPP_
|
|
#include <common/windows.hpp>
|
|
#endif
|
|
|
|
class ScrollInfo
|
|
{
|
|
public:
|
|
ScrollInfo(void);
|
|
ScrollInfo(const ScrollInfo &someScrollInfo);
|
|
virtual ~ScrollInfo();
|
|
ScrollInfo &operator=(const ScrollInfo &someScrollInfo);
|
|
BOOL operator==(const ScrollInfo &someScrollInfo)const;
|
|
void handleHorizontalScroll(CallbackData &someCallbackData);
|
|
void handleVerticalScroll(CallbackData &someCallbackData);
|
|
void handleSize(CallbackData &someCallbackData);
|
|
int minScrollx(void)const;
|
|
void minScrollx(int minScrollx);
|
|
int maxScrollx(void)const;
|
|
void maxScrollx(int maxScrollx);
|
|
int currScrollx(void)const;;
|
|
void currScrollx(int currScrollx);
|
|
int minScrolly(void)const;
|
|
void minScrolly(int minScrolly);
|
|
int maxScrolly(void)const;
|
|
void maxScrolly(int maxScrolly);
|
|
int currScrolly(void)const;
|
|
void currScrolly(int curScrolly);
|
|
void scrollableObjectDimensions(int width,int height);
|
|
int scrollableObjectWidth(void)const;
|
|
int scrollableObjectHeight(void)const;
|
|
BOOL scrollEvent(void)const;
|
|
void scrollEvent(BOOL scrollEvent);
|
|
BOOL sizeEvent(void)const;
|
|
void sizeEvent(BOOL sizeEvent);
|
|
HWND hwndOwner(void)const;
|
|
void hwndOwner(HWND hwndOwner);
|
|
private:
|
|
void scrollableObjectWidth(int scrollableObjectWidth);
|
|
void scrollableObjectHeight(int scrollableObjectHeight);
|
|
enum{PageIncrement=50,LineIncrement=5};
|
|
int imax(int param1,int param2);
|
|
int imin(int param1,int param2);
|
|
|
|
HWND mhWndOwner;
|
|
BOOL mSizeEvent;
|
|
BOOL mScrollEvent;
|
|
int mScrollableObjectWidth;
|
|
int mScrollableObjectHeight;
|
|
int mMinScrollx;
|
|
int mMaxScrollx;
|
|
int mCurrScrollx;
|
|
int mMinScrolly;
|
|
int mMaxScrolly;
|
|
int mCurrScrolly;
|
|
};
|
|
|
|
inline
|
|
ScrollInfo::ScrollInfo(void)
|
|
: mMinScrollx(0), mMaxScrollx(0), mCurrScrollx(0), mMinScrolly(0), mMaxScrolly(0), mCurrScrolly(0),
|
|
mScrollableObjectWidth(0), mScrollableObjectHeight(0), mSizeEvent(FALSE), mhWndOwner(0), mScrollEvent(FALSE)
|
|
{
|
|
}
|
|
|
|
inline
|
|
ScrollInfo::ScrollInfo(const ScrollInfo &someScrollInfo)
|
|
{
|
|
*this=someScrollInfo;
|
|
}
|
|
|
|
inline
|
|
ScrollInfo::~ScrollInfo()
|
|
{
|
|
}
|
|
|
|
inline
|
|
ScrollInfo &ScrollInfo::operator=(const ScrollInfo &someScrollInfo)
|
|
{
|
|
minScrollx(someScrollInfo.minScrollx());
|
|
maxScrollx(someScrollInfo.maxScrollx());
|
|
currScrollx(someScrollInfo.currScrollx());
|
|
maxScrolly(someScrollInfo.currScrolly());
|
|
minScrolly(someScrollInfo.maxScrolly());
|
|
currScrolly(someScrollInfo.minScrollx());
|
|
sizeEvent(someScrollInfo.minScrollx());
|
|
scrollEvent(someScrollInfo.scrollEvent());
|
|
scrollableObjectWidth(someScrollInfo.scrollableObjectWidth());
|
|
scrollableObjectHeight(someScrollInfo.scrollableObjectHeight());
|
|
hwndOwner(someScrollInfo.hwndOwner());
|
|
return *this;
|
|
}
|
|
|
|
inline
|
|
BOOL ScrollInfo::operator==(const ScrollInfo &someScrollInfo)const
|
|
{
|
|
return (minScrollx()==someScrollInfo.minScrollx()&&
|
|
maxScrollx()==someScrollInfo.maxScrollx()&&
|
|
currScrollx()==someScrollInfo.currScrollx()&&
|
|
minScrolly()==someScrollInfo.minScrolly()&&
|
|
maxScrolly()==someScrollInfo.maxScrolly()&&
|
|
currScrolly()==someScrollInfo.currScrolly()&&
|
|
sizeEvent()==someScrollInfo.sizeEvent()&&
|
|
scrollEvent()==someScrollInfo.scrollEvent()&&
|
|
scrollableObjectWidth()==someScrollInfo.scrollableObjectWidth()&&
|
|
scrollableObjectHeight()==someScrollInfo.scrollableObjectHeight()&&
|
|
hwndOwner()==someScrollInfo.hwndOwner());
|
|
}
|
|
|
|
inline
|
|
int ScrollInfo::minScrollx(void)const
|
|
{
|
|
return mMinScrollx;
|
|
}
|
|
|
|
inline
|
|
void ScrollInfo::minScrollx(int minScrollx)
|
|
{
|
|
mMinScrollx=minScrollx;
|
|
}
|
|
|
|
inline
|
|
int ScrollInfo::maxScrollx(void)const
|
|
{
|
|
return mMaxScrollx;
|
|
}
|
|
|
|
inline
|
|
void ScrollInfo::maxScrollx(int maxScrollx)
|
|
{
|
|
mMaxScrollx=maxScrollx;
|
|
}
|
|
|
|
inline
|
|
int ScrollInfo::currScrollx(void)const
|
|
{
|
|
return mCurrScrollx;
|
|
}
|
|
|
|
inline
|
|
void ScrollInfo::currScrollx(int currScrollx)
|
|
{
|
|
mCurrScrollx=currScrollx;
|
|
}
|
|
|
|
inline
|
|
int ScrollInfo::minScrolly(void)const
|
|
{
|
|
return mMinScrolly;
|
|
}
|
|
|
|
inline
|
|
void ScrollInfo::minScrolly(int minScrolly)
|
|
{
|
|
mMinScrolly=minScrolly;
|
|
}
|
|
|
|
inline
|
|
int ScrollInfo::maxScrolly(void)const
|
|
{
|
|
return mMaxScrolly;
|
|
}
|
|
|
|
inline
|
|
void ScrollInfo::maxScrolly(int maxScrolly)
|
|
{
|
|
mMaxScrolly=maxScrolly;
|
|
}
|
|
|
|
inline
|
|
int ScrollInfo::currScrolly(void)const
|
|
{
|
|
return mCurrScrolly;
|
|
}
|
|
|
|
inline
|
|
void ScrollInfo::currScrolly(int currScrolly)
|
|
{
|
|
mCurrScrolly=currScrolly;
|
|
}
|
|
|
|
inline
|
|
BOOL ScrollInfo::scrollEvent(void)const
|
|
{
|
|
return mScrollEvent;
|
|
}
|
|
|
|
inline
|
|
void ScrollInfo::scrollEvent(BOOL scrollEvent)
|
|
{
|
|
mScrollEvent=scrollEvent;
|
|
}
|
|
|
|
inline
|
|
BOOL ScrollInfo::sizeEvent(void)const
|
|
{
|
|
return mSizeEvent;
|
|
}
|
|
|
|
inline
|
|
void ScrollInfo::sizeEvent(BOOL sizeEvent)
|
|
{
|
|
mSizeEvent=sizeEvent;
|
|
}
|
|
|
|
inline
|
|
void ScrollInfo::scrollableObjectDimensions(int width,int height)
|
|
{
|
|
RECT clientRect;
|
|
scrollableObjectWidth(width);
|
|
scrollableObjectHeight(height);
|
|
sizeEvent(FALSE);
|
|
scrollEvent(FALSE);
|
|
::GetClientRect(hwndOwner(),&clientRect);
|
|
handleSize(CallbackData(0,MAKELPARAM(clientRect.right,clientRect.bottom)));
|
|
}
|
|
|
|
inline
|
|
int ScrollInfo::scrollableObjectWidth(void)const
|
|
{
|
|
return mScrollableObjectWidth;
|
|
}
|
|
|
|
inline
|
|
void ScrollInfo::scrollableObjectWidth(int scrollableObjectWidth)
|
|
{
|
|
mScrollableObjectWidth=scrollableObjectWidth;
|
|
}
|
|
|
|
inline
|
|
int ScrollInfo::scrollableObjectHeight(void)const
|
|
{
|
|
return mScrollableObjectHeight;
|
|
}
|
|
|
|
inline
|
|
void ScrollInfo::scrollableObjectHeight(int scrollableObjectHeight)
|
|
{
|
|
mScrollableObjectHeight=scrollableObjectHeight;
|
|
}
|
|
|
|
inline
|
|
HWND ScrollInfo::hwndOwner(void)const
|
|
{
|
|
return mhWndOwner;
|
|
}
|
|
|
|
inline
|
|
void ScrollInfo::hwndOwner(HWND hwndOwner)
|
|
{
|
|
mhWndOwner=hwndOwner;
|
|
}
|
|
|
|
inline
|
|
void ScrollInfo::handleHorizontalScroll(CallbackData &someCallbackData)
|
|
{
|
|
int xDelta;
|
|
int yDelta;
|
|
int xNew;
|
|
|
|
yDelta=0;
|
|
switch(LOWORD(someCallbackData.wParam()))
|
|
{
|
|
case SB_PAGEUP :
|
|
xNew=currScrollx()-PageIncrement;
|
|
break;
|
|
case SB_PAGEDOWN :
|
|
xNew=currScrollx()+PageIncrement;
|
|
break;
|
|
case SB_LINEUP :
|
|
xNew=currScrollx()-LineIncrement;
|
|
break;
|
|
case SB_LINEDOWN :
|
|
xNew=currScrollx()+LineIncrement;
|
|
break;
|
|
case SB_THUMBPOSITION :
|
|
xNew= HIWORD(someCallbackData.wParam());
|
|
break;
|
|
default :
|
|
xNew=currScrollx();
|
|
break;
|
|
}
|
|
xNew=imax(0,xNew);
|
|
xNew=imin(maxScrollx(),xNew);
|
|
if(xNew==currScrollx())return;
|
|
scrollEvent(TRUE);
|
|
xDelta=xNew-currScrollx();
|
|
currScrollx(xNew);
|
|
::ScrollWindow(hwndOwner(),-xDelta,-yDelta,(const RECT*)0,(const RECT*)0);
|
|
::UpdateWindow(hwndOwner());
|
|
::SetScrollPos(hwndOwner(),SB_HORZ,currScrollx(),TRUE);
|
|
}
|
|
|
|
inline
|
|
void ScrollInfo::handleVerticalScroll(CallbackData &someCallbackData)
|
|
{
|
|
int yDelta;
|
|
int yNew;
|
|
int xDelta;
|
|
|
|
xDelta=0;
|
|
switch(LOWORD(someCallbackData.wParam()))
|
|
{
|
|
case SB_PAGEUP :
|
|
yNew=currScrolly()-PageIncrement;
|
|
break;
|
|
case SB_PAGEDOWN :
|
|
yNew=currScrolly()+PageIncrement;
|
|
break;
|
|
case SB_LINEUP :
|
|
yNew=currScrolly()-LineIncrement;
|
|
break;
|
|
case SB_LINEDOWN :
|
|
yNew=currScrolly()+LineIncrement;
|
|
break;
|
|
case SB_THUMBPOSITION :
|
|
yNew=HIWORD(someCallbackData.wParam());
|
|
break;
|
|
default :
|
|
yNew=currScrolly();
|
|
break;
|
|
}
|
|
yNew=imax(0,yNew);
|
|
yNew=imin(maxScrolly(),yNew);
|
|
if(yNew==currScrolly())return;
|
|
scrollEvent(TRUE);
|
|
yDelta=yNew-currScrolly();
|
|
currScrolly(yNew);
|
|
::ScrollWindow(hwndOwner(),-xDelta,-yDelta,(const RECT*)0,(const RECT*)0);
|
|
::UpdateWindow(hwndOwner());
|
|
::SetScrollPos(hwndOwner(),SB_VERT,currScrolly(),TRUE);
|
|
}
|
|
|
|
inline
|
|
void ScrollInfo::handleSize(CallbackData &someCallbackData)
|
|
{
|
|
int xNew(someCallbackData.loWord());
|
|
int yNew(someCallbackData.hiWord());
|
|
|
|
sizeEvent(TRUE);
|
|
maxScrollx(imax(scrollableObjectWidth()-xNew,0));
|
|
::SetScrollRange(hwndOwner(),SB_HORZ,minScrollx(),maxScrollx(),FALSE);
|
|
currScrollx(imin(currScrollx(),maxScrollx()));
|
|
::SetScrollPos(hwndOwner(),SB_HORZ,currScrollx(),TRUE);
|
|
maxScrolly(imax(scrollableObjectHeight()-yNew,0));
|
|
::SetScrollRange(hwndOwner(),SB_VERT,minScrolly(),maxScrolly(),FALSE);
|
|
currScrolly(imin(currScrolly(),maxScrolly()));
|
|
::SetScrollPos(hwndOwner(),SB_VERT,currScrolly(),TRUE);
|
|
}
|
|
|
|
inline
|
|
int ScrollInfo::imax(int param1,int param2)
|
|
{
|
|
return param1>param2?param1:param2;
|
|
}
|
|
|
|
inline
|
|
int ScrollInfo::imin(int param1,int param2)
|
|
{
|
|
return param1<param2?param1:param2;
|
|
}
|
|
#endif |