#include "StdAfx.h" #include "resource.h" // 主符号 #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("当前为:%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.y0c_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: //左键DOWN //case 2: //鼠标移动 // info.Format(IDS_STRING_OBJECT_WIDTH_AND_HEIGHT,c_last.x0-c_down.x0,c_last.y0-c_down.y0); // break; //default: //case 3: //左键UP // info.LoadString(AFX_IDS_IDLEMESSAGE); // break; //} //m_pDoc->SetStatusBarInfo(0,info); } void CItemFocusRect::DoLButtonUp(CDC *pDC) { } }//namespace