You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

209 lines
4.2 KiB
C++

1 month ago
#include "StdAfx.h"
#include "resource.h" // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#include "itemfocusrect.h"
namespace NItem
{
CItemFocusRect::CItemFocusRect(CSigmaDoc * ppDoc)
: CItem(ppDoc)
, m_bShiftDown(FALSE)
, m_nDrawMode(0)
{
}
CItemFocusRect::~CItemFocusRect(void)
{
}
void CItemFocusRect::DrawMode(CDC *pDC, CRect8* pRect)
{
if(m_nDrawMode<0) return;
int old= pDC->SetROP2(R2_MASKPENNOT|R2_MASKNOTPEN);
CRect rt=GetDC()->GetScreen(*pRect); //rt.NormalizeRect();
switch(m_nDrawMode)
{
default:
case 0:
if ((rt.Width() == 0) && (rt.Height() == 0))
{
}
else
{
//CString strMsg;
//strMsg.Format(_T("<22><>ǰΪ<C7B0><CEAA>%d X %d %d %d\n"), rt.left, rt.top, rt.right, rt.bottom);
//TRACE(strMsg);
pDC->DrawFocusRect(rt);
{
CPen pen(PS_DOT, 1, RGB(0, 0, 0));
CPen* pOldPen = (CPen*)pDC->SelectObject(&pen);
CPoint pt = rt.CenterPoint();
pDC->MoveTo(pt.x, rt.top);
pDC->LineTo(pt.x, rt.bottom);
pDC->MoveTo(rt.left, pt.y);
pDC->LineTo(rt.right, pt.y);
pDC->SelectObject(pOldPen);
}
}
break;
case 1:
GetDC()->MoveTo(c_down);
GetDC()->LineTo(c_last);
break;
case 2:
{
CGdiObject* pob= pDC->SelectStockObject(NULL_BRUSH);
pDC->Rectangle(&rt);
pDC->SelectObject(pob);
}
break;
}
pDC->SetROP2(old);
}
void CItemFocusRect::OnLButtonDown(CDC *pDC, UINT nFlags, CPoint point, int vk)
{
CPoint2D dp = GetDC()->GetReal(point);
c_down = dp;
c_last = dp;
//m_bShiftDown=(nFlags&MK_SHIFT) ? TRUE:FALSE;
m_bShiftDown = ::IsKeyDown(VK_SHIFT)|| vk == VK_SHIFT;
//CRect8 rect=GetRect();
//m_oldRect=GetDC()->GetScreen(rect);
//DrawMode(&rect);
//DoDrawOther(1);
//m_IsFocusing == TRUE;
CRect8 rect = GetRect();
DrawMode(pDC, &rect);
//GetView()->SetCapture();
TRACE("mouse move:down pt.x=%f, y=%f\n", c_down.x0, c_down.y0);
}
int CItemFocusRect::OnMouseMove(CDC *pDC, UINT nFlags, CPoint point)
{
//if(!IsCaptureState()) return;
CPoint2D dp = GetDC()->GetReal(point);
CRect8 rect = GetRect();
//if (m_IsFocusBegin == TRUE)
//{
// c_last = dp;
// rect = GetRect();
// DrawMode(pDC, &rect);
// DoDrawOther(2);
// m_oldRect = GetDC()->GetScreen(rect);
// m_IsFocusBegin = FALSE;
// return;
//}
//if (m_IsFocusing == TRUE) {
//TRACE("CItemFocusRect::OnMouseMove:before c_down.x=%f, y=%f--last pt.x=%f, y=%f\n", c_down.x0, c_down.y0, c_last.x0, c_last.y0);
DrawMode(pDC, &rect);
DoDrawOther(pDC, 2);
//}
c_last = dp;
//m_bShiftDown = (nFlags&MK_SHIFT) ? TRUE : FALSE;
m_bShiftDown = ::IsKeyDown(VK_SHIFT);
rect = GetRect();
DrawMode(pDC, &rect);
DoDrawOther(pDC, 2);
m_oldRect = GetDC()->GetScreen(rect);
//m_IsFocusing = TRUE;
return 1;
}
void CItemFocusRect::OnLButtonUp(CDC *pDC, UINT nFlags, CPoint point, int vk)
{
CRect8 rect = GetRect();
if (pDC != NULL)
{
DrawMode(pDC, &rect);
//DoDrawOther(pDC, 3);
//ReleaseCapture();
if (rect.IsEmpty()) return;
DoLButtonUp(pDC);
//m_IsFocusing = FALSE;
}
}
BOOL CItemFocusRect::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if (nChar == VK_ESCAPE)
{
CRect8 rect = GetRect();
if (m_pScreenDC)
{
DrawMode(m_pScreenDC, &rect);
DoDrawOther(m_pScreenDC, 3);
}
}
// if(IsCaptureState())
// {
// CRect8 rect=GetRect();
// DrawMode(&rect);
// DoDrawOther(3);
// ReleaseCapture();
// return TRUE;
// }
return FALSE;
}
CRect8 CItemFocusRect::GetRect(void)
{
CRect8 rect(c_down.x0, c_down.y0, c_last.x0, c_last.y0);
if(m_bShiftDown)
{
int sf=1;
if(c_last.x0>c_down.x0)
{
if(c_last.y0<c_down.y0)
sf=-1;
}
else if(c_last.y0>c_down.y0)
sf=-1;
rect.bottom=rect.top+rect.Width()*sf;
}
rect.NormalizeRect();
return rect;
}
BOOL CItemFocusRect::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
return TRUE;
//GetDoc()->GetCursor().SetCursor(CursorRange);
//return GetDoc()->GetCursor().SetCursor();
}
void CItemFocusRect::DoDrawOther(CDC* pDC, int nButton)
{
//CString info;
//switch(nButton)
//{
//case 1: //<2F><><EFBFBD><EFBFBD>DOWN
//case 2: //<2F><><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD>
// info.Format(IDS_STRING_OBJECT_WIDTH_AND_HEIGHT,c_last.x0-c_down.x0,c_last.y0-c_down.y0);
// break;
//default:
//case 3: //<2F><><EFBFBD><EFBFBD>UP
// info.LoadString(AFX_IDS_IDLEMESSAGE);
// break;
//}
//m_pDoc->SetStatusBarInfo(0,info);
}
void CItemFocusRect::DoLButtonUp(CDC *pDC)
{
}
}//namespace