📄 drawtool.cpp
字号:
// drawtool.cpp - implementation for drawing tools
//
// This is a part of the Microsoft Foundation Classes C++ library.
// Copyright (C) 1992-1997 Microsoft Corporation
// All rights reserved.
//
// This source code is only intended as a supplement to the
// Microsoft Foundation Classes Reference and related
// electronic documentation provided with the library.
// See these sources for detailed information regarding the
// Microsoft Foundation Classes product.
#include "stdafx.h"
#include <afxpriv.h>
#include "drawcli.h"
#include "drawdoc.h"
#include "drawvw.h"
#include "drawobj.h"
#include "drawtool.h"
/////////////////////////////////////////////////////////////////////////////
// CDrawTool implementation
CPtrList CDrawTool::c_tools;
static CSelectTool selectTool;
static CRectTool lineTool(line);
static CRectTool rectTool(rect);
static CRectTool roundRectTool(roundRect);
static CRectTool ellipseTool(ellipse);
static CRectTool textTool(text);
static CRectTool recttextTool(recttext);
static CPolyTool polyTool(poly);
static CPolyTool polyLineTool(poly_line);
static CPolyTool polyFaultTool(polyFault);
static CPolyTool polyLinkTool(polylink);
CPoint CDrawTool::c_down;
UINT CDrawTool::c_nDownFlags;
CPoint CDrawTool::c_last;
DrawShape CDrawTool::c_drawShape = selection;
CDrawTool::CDrawTool(DrawShape drawShape)
{
m_drawShape = drawShape;
c_tools.AddTail(this);
}
CDrawTool* CDrawTool::FindTool(DrawShape drawShape)
{
POSITION pos = c_tools.GetHeadPosition();
while (pos != NULL)
{
CDrawTool* pTool = (CDrawTool*)c_tools.GetNext(pos);
if (pTool->m_drawShape == drawShape)
return pTool;
}
return NULL;
}
void CDrawTool::OnLButtonDown(CDrawView* pView, UINT nFlags, const CPoint& point)
{
// deactivate any in-place active item on this view!
COleClientItem* pActiveItem = pView->GetDocument()->GetInPlaceActiveItem(pView);
if (pActiveItem != NULL)
{
pActiveItem->Close();
ASSERT(pView->GetDocument()->GetInPlaceActiveItem(pView) == NULL);
}
pView->SetCapture();
c_nDownFlags = nFlags;
c_down = point;
c_last = point;
}
void CDrawTool::OnLButtonDblClk(CDrawView* /*pView*/, UINT /*nFlags*/, const CPoint& /*point*/)
{
}
void CDrawTool::OnLButtonUp(CDrawView* /*pView*/, UINT /*nFlags*/, const CPoint& point)
{
ReleaseCapture();
if (point == c_down)
c_drawShape = selection;
}
void CDrawTool::OnMouseMove(CDrawView* /*pView*/, UINT /*nFlags*/, const CPoint& point)
{
c_last = point;
SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
}
void CDrawTool::OnEditProperties(CDrawView* /*pView*/)
{
}
void CDrawTool::OnCancel()
{
c_drawShape = selection;
}
////////////////////////////////////////////////////////////////////////////
// CResizeTool
enum SelectMode
{
none,
netSelect,
move,
size
};
SelectMode selectMode = none;
int nDragHandle;
CPoint lastPoint;
CSelectTool::CSelectTool()
: CDrawTool(selection)
{
}
void CSelectTool::OnLButtonDown(CDrawView* pView, UINT nFlags, const CPoint& point)
{
CPoint local = point;
pView->ClientToDoc(local);
CDrawObj* pObj;
selectMode = none;
// Check for resizing (only allowed on single selections)
if (pView->m_selection.GetCount() == 1)
{
pObj = pView->m_selection.GetHead();
nDragHandle = pObj->HitTest(local, pView, TRUE);
if (nDragHandle != 0)
selectMode = size;
}
// See if the click was on an object, select and start move if so
if (selectMode == none)
{
pObj = pView->GetDocument()->ObjectAt(local);
if (pObj != NULL)
{
selectMode = move;
if (!pView->IsSelected(pObj))
pView->Select(pObj, (nFlags & MK_SHIFT) != 0);
// Ctrl+Click clones the selection...
#ifndef _MAC
if ((nFlags & MK_CONTROL) != 0)
#else
if ((nFlags & MK_OPTION) != 0)
#endif
pView->CloneSelection();
}
}
// Click on background, start a net-selection
if (selectMode == none)
{
if ((nFlags & MK_SHIFT) == 0)
pView->Select(NULL);
selectMode = netSelect;
CClientDC dc(pView);
CRect rect(point.x, point.y, point.x, point.y);
rect.NormalizeRect();
dc.DrawFocusRect(rect);
}
lastPoint = local;
CDrawTool::OnLButtonDown(pView, nFlags, point);
}
void CSelectTool::OnLButtonDblClk(CDrawView* pView, UINT nFlags, const CPoint& point)
{
if ((nFlags & MK_SHIFT) != 0)
{
// Shift+DblClk deselects object...
CPoint local = point;
pView->ClientToDoc(local);
CDrawObj* pObj = pView->GetDocument()->ObjectAt(local);
if (pObj != NULL)
pView->Deselect(pObj);
}
else
{
// "Normal" DblClk opens properties, or OLE server...
if (pView->m_selection.GetCount() == 1)
pView->m_selection.GetHead()->OnOpen(pView);
}
CDrawTool::OnLButtonDblClk(pView, nFlags, point);
}
void CSelectTool::OnEditProperties(CDrawView* pView)
{
if (pView->m_selection.GetCount() == 1)
pView->m_selection.GetHead()->OnEditProperties();
}
void CSelectTool::OnLButtonUp(CDrawView* pView, UINT nFlags, const CPoint& point)
{
if (pView->GetCapture() == pView)
{
if (selectMode == netSelect)
{
CClientDC dc(pView);
CRect rect(c_down.x, c_down.y, c_last.x, c_last.y);
rect.NormalizeRect();
dc.DrawFocusRect(rect);
pView->SelectWithinRect(rect, TRUE);
}
else if (selectMode != none)
{
//说明:在这里判断,如果是选择后的状态,如果有ellipsecopy对象,就清除
if(m_drawShape == ::selection)
{
BOOL bFlag = FALSE;
POSITION pos = pView->m_selection.GetHeadPosition();
while (pos != NULL)
{
CDrawObj* pDrawObj = pView->m_selection.GetNext(pos);
if (pDrawObj->m_DShape == ellipsecopy)
{
pView->DrawMoveWell(pDrawObj->m_position,pDrawObj->m_sWellNO);
pView->GetDocument()->Remove(pDrawObj);
//pDrawObj->Remove();
bFlag = TRUE;
}
}
if (bFlag ) pView->m_selection.RemoveAll();
//接着就移动井位
}
pView->GetDocument()->UpdateAllViews(pView);
}
}
CDrawTool::OnLButtonUp(pView, nFlags, point);
}
void CSelectTool::OnMouseMove(CDrawView* pView, UINT nFlags, const CPoint& point)
{
if (pView->GetCapture() != pView)
{
if (c_drawShape == selection && pView->m_selection.GetCount() == 1)
{
CDrawObj* pObj = pView->m_selection.GetHead();
CPoint local = point;
pView->ClientToDoc(local);
int nHandle = pObj->HitTest(local, pView, TRUE);
if (nHandle != 0)
{
SetCursor(pObj->GetHandleCursor(nHandle));
return; // bypass CDrawTool
}
}
if (c_drawShape == selection)
CDrawTool::OnMouseMove(pView, nFlags, point);
return;
}
if (selectMode == netSelect)
{
CClientDC dc(pView);
CRect rect(c_down.x, c_down.y, c_last.x, c_last.y);
rect.NormalizeRect();
dc.DrawFocusRect(rect);
rect.SetRect(c_down.x, c_down.y, point.x, point.y);
rect.NormalizeRect();
dc.DrawFocusRect(rect);
CDrawTool::OnMouseMove(pView, nFlags, point);
return;
}
CPoint local = point;
pView->ClientToDoc(local);
CPoint delta = (CPoint)(local - lastPoint);
// int ik1 = pView->m_selection.GetCount();
// int ik2 = pView->GetDocument()->GetObjects()->GetCount();
// int ik3 = pView->m_ArrayWell.GetSize();
if(pView->m_selection.GetCount()!=1 )
{
return;
}
//else if(pView->m_selection.GetCount()==1 )//&& pView->m_selection.GetCount() != pView->GetDocument()->GetObjects()->GetCount()
//{
POSITION pos = pView->m_selection.GetHeadPosition();
while (pos != NULL)
{
CDrawObj* pObj = pView->m_selection.GetNext(pos);
//修改说明:判断,如果是选择状态,如果以下几类,就不让其移动
//当ellipse时复制一份,设为ellipsecopy 并将选择项设为刚才复制的对象
//在LButtonUp时,删除ellipsecopy,将刚才那对象移到此,并画相关连通线
//时间:2006-11-7 hjq
if(pView->m_selection.GetCount()==1 )
{
if(m_drawShape == ::selection )
{
switch(pObj->m_DShape)
{
case line:
case rect:
case roundRect:
case text:
case recttext:
case ellipseCenter:
//case poly_line:
// case vtext:
return;
//break;
case poly:
if (selectMode == move) return;
break;
case ellipse:
CloneEllipse(pView);
return;
//case ellipsecopy:
//break;
}
}
}
//if (pObj->m_DShape != ::ellipse && m_drawShape == ::selection) return;
CRect position = pObj->m_position;
if (selectMode == move)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -