Initial
This commit is contained in:
184
splitter/SplitterWnd.cpp
Normal file
184
splitter/SplitterWnd.cpp
Normal file
@@ -0,0 +1,184 @@
|
||||
#include <splitter/SplitterWnd.hpp>
|
||||
#include <common/purehdc.hpp>
|
||||
|
||||
char SplitterWnd::smszClassName[]="SplitterWnd";
|
||||
|
||||
SplitterWnd::SplitterWnd(GUIWindow &parent,GUIWindow &pane1,GUIWindow &pane2,int splitRatio)
|
||||
: mBkGndBrush(RGBColor(COLORREF(::GetSysColor(COLOR_3DFACE)))),
|
||||
mParent(&parent), mPane1(&pane1), mPane2(&pane2), mSplitRatio(splitRatio),
|
||||
mSplitWidth(SplitWidth), mLightPen(RGBColor((COLORREF)::GetSysColor(COLOR_3DLIGHT))),
|
||||
mHiLightPen(RGBColor((COLORREF)::GetSysColor(COLOR_3DHILIGHT))),
|
||||
mShadowPen(RGBColor((COLORREF)::GetSysColor(COLOR_3DSHADOW))),
|
||||
mDkShadowPen(RGBColor((COLORREF)::GetSysColor(COLOR_3DDKSHADOW)))
|
||||
{
|
||||
mCreateHandler.setCallback(this,&SplitterWnd::createHandler);
|
||||
mPaintHandler.setCallback(this,&SplitterWnd::paintHandler);
|
||||
mLeftButtonDownHandler.setCallback(this,&SplitterWnd::leftButtonDownHandler);
|
||||
mLeftButtonUpHandler.setCallback(this,&SplitterWnd::leftButtonUpHandler);
|
||||
mMouseMoveHandler.setCallback(this,&SplitterWnd::mouseMoveHandler);
|
||||
mCaptureChangedHandler.setCallback(this,&SplitterWnd::captureChangedHandler);
|
||||
mDestroyHandler.setCallback(this,&SplitterWnd::destroyHandler);
|
||||
mSizeHandler.setCallback(this,&SplitterWnd::parentSizeHandler);
|
||||
registerClass();
|
||||
insertHandlers();
|
||||
Rect winRect(CW_USEDEFAULT,CW_USEDEFAULT,SplitWidth,mParent->height());
|
||||
createWindow(smszClassName,"Splitter",WS_VISIBLE|WS_CHILD,winRect,parent,(HMENU)ControlID,processInstance(),this);
|
||||
show(SW_SHOW);
|
||||
update();
|
||||
}
|
||||
|
||||
SplitterWnd::~SplitterWnd()
|
||||
{
|
||||
removeHandlers();
|
||||
}
|
||||
|
||||
void SplitterWnd::registerClass()
|
||||
{
|
||||
WNDCLASS wndClass;
|
||||
HINSTANCE hInstance;
|
||||
|
||||
hInstance=processInstance();
|
||||
if(::GetClassInfo(hInstance,smszClassName,(WNDCLASS FAR *)&wndClass))return;
|
||||
wndClass.style =CS_HREDRAW|CS_VREDRAW;
|
||||
wndClass.lpfnWndProc =(WNDPROC)GUIWindow::WndProc;
|
||||
wndClass.cbClsExtra =0;
|
||||
wndClass.cbWndExtra =sizeof(SplitterWnd*);
|
||||
wndClass.hInstance =hInstance;
|
||||
wndClass.hIcon =0;
|
||||
wndClass.hCursor =::LoadCursor(NULL,IDC_SIZEWE);
|
||||
wndClass.hbrBackground =mBkGndBrush.getBrush();
|
||||
wndClass.lpszMenuName =0;
|
||||
wndClass.lpszClassName =smszClassName;
|
||||
::RegisterClass(&wndClass);
|
||||
}
|
||||
|
||||
void SplitterWnd::insertHandlers()
|
||||
{
|
||||
insertHandler(VectorHandler::CreateHandler,&mCreateHandler);
|
||||
insertHandler(VectorHandler::PaintHandler,&mPaintHandler);
|
||||
insertHandler(VectorHandler::LeftButtonDownHandler,&mLeftButtonDownHandler);
|
||||
insertHandler(VectorHandler::LeftButtonUpHandler,&mLeftButtonUpHandler);
|
||||
insertHandler(VectorHandler::MouseMoveHandler,&mMouseMoveHandler);
|
||||
insertHandler(VectorHandler::CaptureChangedHandler,&mCaptureChangedHandler);
|
||||
insertHandler(VectorHandler::DestroyHandler,&mDestroyHandler);
|
||||
mParent->insertHandler(VectorHandler::SizeHandler,&mSizeHandler);
|
||||
}
|
||||
|
||||
void SplitterWnd::removeHandlers()
|
||||
{
|
||||
removeHandler(VectorHandler::CreateHandler,&mCreateHandler);
|
||||
removeHandler(VectorHandler::PaintHandler,&mPaintHandler);
|
||||
removeHandler(VectorHandler::LeftButtonDownHandler,&mLeftButtonDownHandler);
|
||||
removeHandler(VectorHandler::LeftButtonUpHandler,&mLeftButtonUpHandler);
|
||||
removeHandler(VectorHandler::MouseMoveHandler,&mMouseMoveHandler);
|
||||
removeHandler(VectorHandler::CaptureChangedHandler,&mCaptureChangedHandler);
|
||||
removeHandler(VectorHandler::DestroyHandler,&mDestroyHandler);
|
||||
mParent->removeHandler(VectorHandler::SizeHandler,&mSizeHandler);
|
||||
}
|
||||
|
||||
CallbackData::ReturnType SplitterWnd::createHandler(CallbackData &cbData)
|
||||
{
|
||||
sizeControls();
|
||||
return true;
|
||||
}
|
||||
|
||||
CallbackData::ReturnType SplitterWnd::paintHandler(CallbackData &cbData)
|
||||
{
|
||||
PaintInformation *pPaintInfo=(PaintInformation*)cbData.lParam();
|
||||
PureDevice &pureDevice=(PureDevice&)*pPaintInfo;
|
||||
|
||||
pureDevice.line(Point(0,0),Point(0,height()-1),mLightPen);
|
||||
pureDevice.line(Point(1,0),Point(1,height()-1),mHiLightPen);
|
||||
pureDevice.line(Point(width()-2,0),Point(width()-2,height()-1),mShadowPen);
|
||||
pureDevice.line(Point(width()-1,0),Point(width()-1,height()-1),mDkShadowPen);
|
||||
return false;
|
||||
}
|
||||
|
||||
CallbackData::ReturnType SplitterWnd::parentSizeHandler(CallbackData &cbData)
|
||||
{
|
||||
sizeControls();
|
||||
return false;
|
||||
}
|
||||
|
||||
CallbackData::ReturnType SplitterWnd::leftButtonDownHandler(CallbackData &cbData)
|
||||
{
|
||||
Rect parentRect;
|
||||
Rect currRect;
|
||||
Point clickPoint;
|
||||
|
||||
clickPoint.x(cbData.loWord());
|
||||
clickPoint.y(cbData.hiWord());
|
||||
setCapture();
|
||||
mParent->clientRect(parentRect);
|
||||
mParent->clientToScreen(parentRect);
|
||||
clientRect(currRect);
|
||||
clientToScreen(currRect);
|
||||
mDragStart=currRect.left()-parentRect.left()+width()/2-clickPoint.x();
|
||||
mDragx=mDragStart+clickPoint.x();
|
||||
PureDevice pureDevice(*mParent);
|
||||
pureDevice.setDrawMode(PureDevice::R2NOTXORPEN);
|
||||
pureDevice.line(Point(mDragx,0),Point(mDragx,height()-1));
|
||||
return false;
|
||||
}
|
||||
|
||||
CallbackData::ReturnType SplitterWnd::leftButtonUpHandler(CallbackData &cbData)
|
||||
{
|
||||
Point mousePoint;
|
||||
|
||||
mousePoint.x(cbData.loWord());
|
||||
mousePoint.y(cbData.hiWord());
|
||||
releaseCapture();
|
||||
moveSplitter(mDragStart+mousePoint.x());
|
||||
return false;
|
||||
}
|
||||
|
||||
CallbackData::ReturnType SplitterWnd::mouseMoveHandler(CallbackData &cbData)
|
||||
{
|
||||
if(!hasCapture())return false;
|
||||
Point mousePoint;
|
||||
|
||||
mousePoint.x(cbData.loWord());
|
||||
mousePoint.y(cbData.hiWord());
|
||||
PureDevice pureDevice(*mParent);
|
||||
pureDevice.setDrawMode(PureDevice::R2NOTXORPEN);
|
||||
pureDevice.line(Point(mDragx,0),Point(mDragx,height()-1));
|
||||
mDragx=mDragStart+mousePoint.x();
|
||||
pureDevice.line(Point(mDragx,0),Point(mDragx,height()-1));
|
||||
return false;
|
||||
}
|
||||
|
||||
CallbackData::ReturnType SplitterWnd::captureChangedHandler(CallbackData &cbData)
|
||||
{
|
||||
PureDevice pureDevice(*mParent);
|
||||
pureDevice.setDrawMode(PureDevice::R2NOTXORPEN);
|
||||
pureDevice.line(Point(mDragx,0),Point(mDragx,height()-1));
|
||||
return false;
|
||||
}
|
||||
|
||||
CallbackData::ReturnType SplitterWnd::destroyHandler(CallbackData &cbData)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void SplitterWnd::sizeControls()
|
||||
{
|
||||
int parentWidth=mParent->width();
|
||||
int parentHeight=mParent->height();
|
||||
int xsplit=(parentWidth*mSplitRatio)/100.00;
|
||||
if(xsplit<0)xsplit=0;
|
||||
if(xsplit+mSplitWidth>=parentWidth)xsplit=parentWidth-mSplitWidth;
|
||||
moveWindow(xsplit,0,mSplitWidth,parentHeight,false);
|
||||
mPane1->moveWindow(0,0,xsplit,parentHeight,true);
|
||||
mPane2->moveWindow(xsplit+mSplitWidth,0,parentWidth-xsplit-mSplitWidth,parentHeight,true);
|
||||
update();
|
||||
}
|
||||
|
||||
void SplitterWnd::moveSplitter(int xLoc)
|
||||
{
|
||||
mSplitRatio=xLoc*100.00/mParent->width();
|
||||
if(mSplitRatio<0)mSplitRatio=0;
|
||||
else if(mSplitRatio>100)mSplitRatio=100;
|
||||
sizeControls();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user