?? splitter.cpp
字號:
//this file is part of notepad++
//Copyright (C)2003 Don HO ( donho@altern.org )
//
//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either
//version 2 of the License, or (at your option) any later version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include "SysMsg.h"
#include "Splitter.h"
//#include "resource.h"
bool Splitter::_isHorizontalRegistered = false;
bool Splitter::_isVerticalRegistered = false;
bool Splitter::_isHorizontalFixedRegistered = false;
bool Splitter::_isVerticalFixedRegistered = false;
#define SPLITTER_SIZE 8
Splitter::Splitter() : Window()
{
//hInstance = GetModuleHandle(NULL);
_rect.left = 0; // x axis
_rect.top = 0; // y axis
_rect.right = 0; // Width of the spliter.
_rect.bottom = 0; // Height of the spliter
_isFixed = false;
}
void Splitter::init( HINSTANCE hInst, HWND hPere, int splitterSize,
int iSplitRatio, DWORD dwFlags)
{
Window::init(hInst, hPere);
_spiltterSize = splitterSize;
WNDCLASSEX wcex;
DWORD dwExStyle = 0L;
DWORD dwStyle = WS_CHILD | WS_VISIBLE;
if (hPere == NULL)
{
::MessageBox(NULL, "pas de pere?", "Splitter::init", MB_OK);
throw int(96);
}
if (iSplitRatio < 0)
{
::MessageBox(NULL, "it shoulds be 0 < ratio < 100", "Splitter::init", MB_OK);
throw int(96);
}
_hParent = hPere;
_dwFlags = dwFlags;
if (_dwFlags & SV_FIXED)
{
//Fixed spliter
_isFixed = true;
}
else
{
if (iSplitRatio >= 100)
{
//cant be 100 % or more
::MessageBox(NULL, "it shoulds be 0 < ratio < 100", "Splitter::init", MB_OK);
throw int(96);
}
}
_splitPercent = iSplitRatio;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)staticWndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = _hInst;
wcex.hIcon = NULL;
::GetClientRect(_hParent, &_rect);
if (_dwFlags & SV_HORIZONTAL) //Horizontal spliter
{
_rect.top = ((_rect.bottom * _splitPercent)/100);
// y axis determined by the split% of the parent windows height
_rect.left = 0;
// x axis is always 0
_rect.bottom = _spiltterSize;
// the height of the spliter
// the width of the splitter remains the same as the width of the parent window.
}
else //Vertical spliter
{
// y axis is 0 always
_rect.left = ((_rect.right * _splitPercent)/100);
// x axis determined by split% of the parent windows width.
_rect.right = _spiltterSize;
// width of the spliter.
//height of the spliter remains the same as the height of the parent window
}
if (!_isFixed)
{
if ((_dwFlags & SV_ENABLERDBLCLK) || (_dwFlags & SV_ENABLELDBLCLK))
{
wcex.style = wcex.style | CS_DBLCLKS;
// enable mouse double click messages.
}
}
if (_isFixed)
{
wcex.hCursor = ::LoadCursor(NULL, IDC_ARROW);
// if fixed spliter then choose default cursor type.
if (_dwFlags & SV_HORIZONTAL)
wcex.lpszClassName = "fxdnsspliter";
else
wcex.lpszClassName = "fxdwespliter";
}
else
{
if (_dwFlags & SV_HORIZONTAL)
{
//double sided arrow pointing north-south as cursor
wcex.hCursor = ::LoadCursor(NULL,IDC_SIZENS);
wcex.lpszClassName = "nsspliter";
}
else
{
// double sided arrow pointing east-west as cursor
wcex.hCursor = ::LoadCursor(NULL,IDC_SIZEWE);
wcex.lpszClassName = "wespliter";
}
}
wcex.hbrBackground = (HBRUSH)(COLOR_3DFACE+1);
wcex.lpszMenuName = NULL;
wcex.hIconSm = NULL;
if ((_dwFlags & SV_HORIZONTAL)&&(!_isHorizontalRegistered))
{
RegisterClassEx(&wcex);
_isHorizontalRegistered = true;
}
else if (isVertical()&&(!_isVerticalRegistered))
{
RegisterClassEx(&wcex);
_isVerticalRegistered = true;
}
else if ((_dwFlags & SV_HORIZONTAL)&&(!_isHorizontalFixedRegistered))
{
RegisterClassEx(&wcex);
_isHorizontalFixedRegistered = true;
}
else if (isVertical()&&(!_isVerticalFixedRegistered))
{
RegisterClassEx(&wcex);
_isVerticalFixedRegistered = true;
}
_hSelf = CreateWindowEx(
dwExStyle,
wcex.lpszClassName,
"",
dwStyle,
_rect.left,
_rect.top,
_rect.right,
_rect.bottom,
_hParent,
NULL,
_hInst,
(LPVOID)this);
if (!_hSelf)
{
systemMessage("System Err");
throw int(345);
}
RECT rc;
getClientRect(rc);
//::GetClientRect(_hParent,&rc);
_clickZone2TL.left = rc.left;
_clickZone2TL.top = rc.top;
int clickZoneWidth = getClickZone(WIDTH);
int clickZoneHeight = getClickZone(HEIGHT);
_clickZone2TL.right = clickZoneWidth;
_clickZone2TL.bottom = clickZoneHeight;
_clickZone2BR.left = rc.right - clickZoneWidth;
_clickZone2BR.top = rc.bottom - clickZoneHeight;
_clickZone2BR.right = clickZoneWidth;
_clickZone2BR.bottom = clickZoneHeight;
display();
::SendMessage(_hParent, WM_RESIZE_CONTAINER, _rect.left, _rect.top);
}
// determinated by (_dwFlags & SV_VERTICAL) && _splitterSize
int Splitter::getClickZone(WH which)
{
if (_spiltterSize <= 8)
{
return isVertical()?(which==WIDTH?_spiltterSize:HIEGHT_MINIMAL)
:(which==WIDTH?HIEGHT_MINIMAL:_spiltterSize);
}
else // (_spiltterSize > 8)
{
return isVertical()?(which==WIDTH? 8:15)
:(which==WIDTH?15:8);
}
}
LRESULT CALLBACK Splitter::staticWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_NCCREATE:
{
Splitter * pSplitter = (Splitter *)((LPCREATESTRUCT)lParam)->lpCreateParams;
pSplitter->_hSelf = hWnd;
::SetWindowLong(hWnd, GWL_USERDATA, (long)pSplitter);
return TRUE;
}
default:
{
Splitter * pSplitter = (Splitter *)::GetWindowLong(hWnd, GWL_USERDATA);
if (!pSplitter)
return ::DefWindowProc(hWnd, uMsg, wParam, lParam);
return pSplitter->spliterWndProc(uMsg, wParam, lParam);
}
}
}
LRESULT CALLBACK Splitter::spliterWndProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
/*
case WM_LBUTTONDBLCLK:
{
::MessageBox(NULL, "", "", MB_OK);
}
return 0;
case WM_RBUTTONDBLCLK:
{
}
return 0;
*/
case WM_LBUTTONDOWN:
{
POINT p;
p.x = LOWORD(lParam);
p.y = HIWORD(lParam);
if ((isInLeftTopZone(p))&&(wParam == MK_LBUTTON))
{
gotoTopLeft();
return TRUE;
}
if ((isInRightBottomZone(p))&&(wParam == MK_LBUTTON))
{
gotoRightBouuom();
return TRUE;
}
if (!_isFixed)
{
::SetCapture(_hSelf);
_isDraged = true;
}
}
return 0;
case WM_RBUTTONDOWN :
::SendMessage(_hParent, WM_DOPOPUPMENU, wParam, lParam);
return TRUE;
case WM_MOUSEMOVE:
{
POINT p;
p.x = LOWORD(lParam);
p.y = HIWORD(lParam);
if (isInLeftTopZone(p) || isInRightBottomZone(p))
{
//::SetCursor(::LoadCursor(_hInst, MAKEINTRESOURCE(IDC_UP_ARROW)));
::SetCursor(::LoadCursor(NULL, IDC_ARROW));
return TRUE;
}
if ((!_isFixed) && (wParam == MK_LBUTTON))
{
POINT pt; RECT rt;
::GetClientRect(_hParent, &rt);
::GetCursorPos(&pt);
::ScreenToClient(_hParent, &pt);
if (_dwFlags & SV_HORIZONTAL)
{
if (pt.y <= 1)
{
_rect.top = 1;
_splitPercent = 1;
}
else
{
if (pt.y <= (rt.bottom - 5))
{
_rect.top = pt.y;
_splitPercent = ((pt.y * 100 / rt.bottom*100) / 100);
}
else
{
_rect.top = rt.bottom - 5;
_splitPercent = 99;
}
}
}
else
{
if (pt.x <= 1)
{
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -