📄 splitter.cpp
字号:
_rect.left = 1;
_splitPercent = 1;
}
else
{
if (pt.x <= (rt.right - 5))
{
_rect.left = pt.x;
_splitPercent = ((pt.x*100/rt.right*100)/100);
}
else
{
_rect.left = rt.right - 5;
_splitPercent = 99;
}
}
}
::SendMessage(_hParent, WM_RESIZE_CONTAINER, _rect.left, _rect.top);
::MoveWindow(_hSelf, _rect.left, _rect.top, _rect.right, _rect.bottom, FALSE);
redraw();
}
return 0;
}
case WM_LBUTTONUP:
{
if (!_isFixed)
{
ReleaseCapture();
}
return 0;
}
case WM_CAPTURECHANGED:
{
if (_isDraged)
{
::SendMessage(_hParent, WM_RESIZE_CONTAINER, _rect.left, _rect.top);
::MoveWindow(_hSelf, _rect.left, _rect.top, _rect.right, _rect.bottom, TRUE);
_isDraged = false;
}
return 0;
}
case WM_PAINT :
drawSplitter();
return 0;
case WM_CLOSE:
destroy();
return 0;
}
return ::DefWindowProc(_hSelf, uMsg, wParam, lParam);
}
void Splitter::resizeSpliter(RECT *pRect)
{
RECT rect;
if (pRect)
rect = *pRect;
else
::GetClientRect(_hParent,&rect);
if (_dwFlags & SV_HORIZONTAL)
{
// for a Horizontal spliter the width remains the same
// as the width of the parent window, so get the new width of the parent.
_rect.right = rect.right;
//if resizeing should be done proportionately.
if (_dwFlags & SV_RESIZEWTHPERCNT)
_rect.top = ((rect.bottom * _splitPercent)/100);
else // soit la fenetre en haut soit la fenetre en bas qui est fixee
_rect.top = getSplitterFixPosY();
}
else
{
// for a (default) Vertical spliter the height remains the same
// as the height of the parent window, so get the new height of the parent.
_rect.bottom = rect.bottom;
//if resizeing should be done proportionately.
if (_dwFlags & SV_RESIZEWTHPERCNT)
{
_rect.left = ((rect.right * _splitPercent)/100);
}
else // soit la fenetre gauche soit la fenetre droit qui est fixee
_rect.left = getSplitterFixPosX();
}
::MoveWindow(_hSelf, _rect.left, _rect.top, _rect.right, _rect.bottom, TRUE);
::SendMessage(_hParent, WM_RESIZE_CONTAINER, _rect.left, _rect.top);
RECT rc;
getClientRect(rc);
_clickZone2BR.right = getClickZone(WIDTH);
_clickZone2BR.bottom = getClickZone(HEIGHT);
_clickZone2BR.left = rc.right - _clickZone2BR.right;
_clickZone2BR.top = rc.bottom - _clickZone2BR.bottom;
//force the window to repaint, to make sure the splitter is visible
// in the new position.
redraw();
}
void Splitter::gotoTopLeft()
{
if ((_dwFlags & SV_ENABLELDBLCLK) && (!_isFixed) && (_splitPercent > 1))
{
if (_dwFlags & SV_HORIZONTAL)
_rect.top = 1;
else
_rect.left = 1;
_splitPercent = 1;
::SendMessage(_hParent, WM_RESIZE_CONTAINER, _rect.left, _rect.top);
::MoveWindow(_hSelf, _rect.left, _rect.top, _rect.right, _rect.bottom, TRUE);
redraw();
}
}
void Splitter::gotoRightBouuom()
{
if ((_dwFlags & SV_ENABLERDBLCLK) && (!_isFixed) && (_splitPercent < 99))
{
RECT rt;
GetClientRect(_hParent,&rt);
if (_dwFlags & SV_HORIZONTAL)
_rect.top = rt.bottom - _spiltterSize;
else
_rect.left = rt.right - _spiltterSize;
_splitPercent = 99;
::SendMessage(_hParent, WM_RESIZE_CONTAINER, _rect.left, _rect.top);
::MoveWindow(_hSelf, _rect.left, _rect.top, _rect.right, _rect.bottom, TRUE);
redraw();
}
}
void Splitter::drawSplitter()
{
PAINTSTRUCT ps;
RECT rc, rcToDraw1, rcToDraw2, TLrc, BRrc;
HDC hdc = ::BeginPaint(_hSelf, &ps);
getClientRect(rc);
if ((_spiltterSize >= 4) && (_dwFlags & SV_RESIZEWTHPERCNT))
{
adjustZoneToDraw(TLrc, TOP_LEFT);
adjustZoneToDraw(BRrc, BOTTOM_RIGHT);
paintArrow(hdc, TLrc, isVertical()?ARROW_LEFT:ARROW_UP);
}
if (isVertical())
{
rcToDraw2.top = (_dwFlags & SV_RESIZEWTHPERCNT)?_clickZone2TL.bottom:0;
rcToDraw2.bottom = rcToDraw2.top + 2;
rcToDraw1.top = rcToDraw2.top + 1;
rcToDraw1.bottom = rcToDraw1.top + 2;
}
else
{
rcToDraw2.top = 1;
rcToDraw2.bottom = 3;
rcToDraw1.top = 2;
rcToDraw1.bottom = 4;
}
int bottom = 0;
if (_dwFlags & SV_RESIZEWTHPERCNT)
bottom = (isVertical() ? rc.bottom - _clickZone2BR.bottom : rc.bottom);
else
bottom = rc.bottom;
while (rcToDraw1.bottom <= bottom)
{
if (isVertical())
{
rcToDraw2.left = 1;
rcToDraw2.right = 3;
rcToDraw1.left = 2;
rcToDraw1.right = 4;
}
else
{
rcToDraw2.left = _clickZone2TL.right;
rcToDraw2.right = rcToDraw2.left + 2;
rcToDraw1.left = rcToDraw2.left;
rcToDraw1.right = rcToDraw1.left + 2;
}
while (rcToDraw1.right <= (isVertical() ? rc.right : rc.right - _clickZone2BR.right))
{
::FillRect(hdc, &rcToDraw1, (HBRUSH)(RGB(0xFF, 0xFF, 0xFF)));
::FillRect(hdc, &rcToDraw2, (HBRUSH)(COLOR_3DSHADOW+1));
rcToDraw2.left += 4;
rcToDraw2.right += 4;
rcToDraw1.left += 4;
rcToDraw1.right += 4;
}
rcToDraw2.top += 4;
rcToDraw2.bottom += 4;
rcToDraw1.top += 4;
rcToDraw1.bottom += 4;
}
if ((_spiltterSize >= 4) && (_dwFlags & SV_RESIZEWTHPERCNT))
paintArrow(hdc, BRrc, isVertical()?ARROW_RIGHT:ARROW_DOWN);
::EndPaint(_hSelf, &ps);
}
void Splitter::rotate()
{
if (!_isFixed)
{
destroy();
if (_dwFlags & SV_HORIZONTAL)
{
_dwFlags ^= SV_HORIZONTAL;
_dwFlags |= SV_VERTICAL;
}
else //SV_VERTICAL
{
_dwFlags ^= SV_VERTICAL;
_dwFlags |= SV_HORIZONTAL;
}
init(_hInst, _hParent, _spiltterSize, _splitPercent, _dwFlags);
}
}
void Splitter::paintArrow(HDC hdc, const RECT &rect, Arrow arrowDir)
{
RECT rc;
rc.left = rect.left; rc.top = rect.top;
rc.right = rect.right; rc.bottom = rect.bottom;
if (arrowDir == ARROW_LEFT)
{
int x = rc.right;
int y = rc.top;
//::MoveToEx(hdc, x, y, NULL);
for (; (x > rc.left) && (y != rc.bottom) ; x--)
{
::MoveToEx(hdc, x, y++, NULL);
::LineTo(hdc, x, rc.bottom--);
}
}
else if (arrowDir == ARROW_RIGHT)
{
int x = rc.left;
int y = rc.top;
//::MoveToEx(hdc, x, y, NULL);
for (; (x < rc.right) && (y != rc.bottom) ; x++)
{
::MoveToEx(hdc, x, y++, NULL);
::LineTo(hdc, x, rc.bottom--);
}
}
else if (arrowDir == ARROW_UP)
{
int x = rc.left;
int y = rc.bottom;
//::MoveToEx(hdc, x, y, NULL);
for (; (y > rc.top) && (x != rc.right) ; y--)
{
::MoveToEx(hdc, x++, y, NULL);
::LineTo(hdc, rc.right--, y);
}
}
else if (arrowDir == ARROW_DOWN)
{
int x = rc.left;
int y = rc.top;
//::MoveToEx(hdc, x, y, NULL);
for (; (y < rc.bottom) && (x != rc.right) ; y++)
{
::MoveToEx(hdc, x++, y, NULL);
::LineTo(hdc, rc.right--, y);
}
}
}
void Splitter::adjustZoneToDraw(RECT & rc2def, ZONE_TYPE whichZone)
{
if (_spiltterSize < 4) return;
int x0, y0, x1, y1, w, h;
if ((4 <= _spiltterSize) && (_spiltterSize <= 8))
{
w = (isVertical()?4:7);
h = (isVertical()?7:4);
}
else // (_spiltterSize > 8)
{
w = (isVertical()?6:11);
h = (isVertical()?11:6);
}
if (isVertical())
{//w=4 h=7
if (whichZone == TOP_LEFT)
{
x0 = 0;
y0 = (_clickZone2TL.bottom - h) / 2;
}
else // whichZone == BOTTOM_RIGHT
{
x0 = _clickZone2BR.left + _clickZone2BR.right - w;
y0 = (_clickZone2BR.bottom - h) / 2 + _clickZone2BR.top;
}
x1 = x0 + w;
y1 = y0 + h;
}
else // Horizontal
{//w=7 h=4
if (whichZone == TOP_LEFT)
{
x0 = (_clickZone2TL.right - w) / 2;
y0 = 0;
}
else // whichZone == BOTTOM_RIGHT
{
x0 = ((_clickZone2BR.right - w) / 2) + _clickZone2BR.left;
y0 = _clickZone2BR.top + _clickZone2BR.bottom - h;
}
x1 = x0 + w;
y1 = y0 + h;
}
rc2def.left = x0;
rc2def.top = y0;
rc2def.right = x1;
rc2def.bottom = y1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -