谁能找到类似VB窗口编辑器的VC源代码

CyberGhost 2000-09-06 03:50:00
将子定义的图形拖放至编辑区能够改变尺寸并有一定的属性
...全文
135 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
CyberGhost 2000-09-10
  • 打赏
  • 举报
回复
是否可以发一个完整的例子
谢谢
iforever 2000-09-06
  • 打赏
  • 举报
回复
这个问题太大.
不过可以给你一段代码看看:
// drawvw.cpp : implementation of the CDrawView class
//
// 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 "drawobj.h"
//#include "cntritem.h"
#include "drawvw.h"

#include "drawobj.h"
#include "drawtool.h"
#include "mainfrm.h"
#include "math.h"

LOGFONT m_lfDefFont;
UINT id;

#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif

// private clipboard format (list of Draw objects)
CLIPFORMAT CDrawView::m_cfDraw = (CLIPFORMAT)
#ifdef _MAC
::RegisterClipboardFormat(_T("DCLI"));
#else
::RegisterClipboardFormat(_T("MFC Draw Sample"));
#endif
CLIPFORMAT CDrawView::m_cfObjectDescriptor = NULL;

/////////////////////////////////////////////////////////////////////////////
// CDrawView

IMPLEMENT_DYNCREATE(CDrawView, CView)//CScrollView

BEGIN_MESSAGE_MAP(CDrawView, CView)//CScrollView
//{{AFX_MSG_MAP(CDrawView)
ON_COMMAND(ID_OLE_INSERT_NEW, OnInsertObject)
ON_COMMAND(ID_CANCEL_EDIT, OnCancelEdit)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONDBLCLK()
ON_COMMAND(ID_DRAW_SELECT, OnDrawSelect)
ON_COMMAND(ID_DRAW_ROUNDRECT, OnDrawRoundRect)
ON_COMMAND(ID_DRAW_RECT, OnDrawRect)
ON_COMMAND(ID_DRAW_LINE, OnDrawLine)
ON_COMMAND(ID_DRAW_LINE90, OnDrawLine90)
ON_COMMAND(ID_DRAW_ELLIPSE, OnDrawEllipse)
ON_COMMAND(ID_DRAW_TEXT, OnDrawText)
ON_COMMAND(ID_DRAW_DATA, OnDrawData)
ON_COMMAND(ID_DRAW_CURVE, OnDrawCurve)
ON_COMMAND(ID_DRAW_ARC, OnDrawArc)
ON_COMMAND(ID_DRAW_PIE, OnDrawPie)
ON_COMMAND(ID_DRAW_CHORD, OnDrawChord)
ON_UPDATE_COMMAND_UI(ID_DRAW_ELLIPSE, OnUpdateDrawEllipse)
ON_UPDATE_COMMAND_UI(ID_DRAW_LINE, OnUpdateDrawLine)
ON_UPDATE_COMMAND_UI(ID_DRAW_LINE90, OnUpdateDrawLine90)
ON_UPDATE_COMMAND_UI(ID_DRAW_ARC, OnUpdateDrawArc)
ON_UPDATE_COMMAND_UI(ID_DRAW_PIE, OnUpdateDrawPie)
ON_UPDATE_COMMAND_UI(ID_DRAW_CHORD, OnUpdateDrawChord)
ON_UPDATE_COMMAND_UI(ID_DRAW_TEXT, OnUpdateDrawText)
ON_UPDATE_COMMAND_UI(ID_DRAW_DATA, OnUpdateDrawData)
ON_UPDATE_COMMAND_UI(ID_DRAW_CURVE, OnUpdateDrawCurve)
ON_UPDATE_COMMAND_UI(ID_DRAW_RECT, OnUpdateDrawRect)
ON_UPDATE_COMMAND_UI(ID_DRAW_ROUNDRECT, OnUpdateDrawRoundRect)
ON_UPDATE_COMMAND_UI(ID_DRAW_SELECT, OnUpdateDrawSelect)
ON_UPDATE_COMMAND_UI(ID_OBJECT_MOVEBACK, OnUpdateSingleSelect)
ON_COMMAND(ID_EDIT_SELECT_ALL, OnEditSelectAll)
ON_COMMAND(ID_EDIT_CLEAR, OnEditClear)
ON_UPDATE_COMMAND_UI(ID_EDIT_CLEAR, OnUpdateAnySelect)
ON_COMMAND(ID_DRAW_POLYGON, OnDrawPolygon)
ON_COMMAND(ID_DRAW_POLYLINE, OnDrawPolyline)
ON_COMMAND(ID_DRAW_POLYBEZIER, OnDrawPolybezier)
ON_UPDATE_COMMAND_UI(ID_DRAW_POLYGON, OnUpdateDrawPolygon)
ON_UPDATE_COMMAND_UI(ID_DRAW_POLYLINE, OnUpdateDrawPolyline)
ON_UPDATE_COMMAND_UI(ID_DRAW_POLYBEZIER, OnUpdateDrawPolybezier)
ON_WM_SIZE()
ON_COMMAND(ID_VIEW_GRID, OnViewGrid)
ON_UPDATE_COMMAND_UI(ID_VIEW_GRID, OnUpdateViewGrid)
ON_WM_ERASEBKGND()
ON_COMMAND(ID_OBJECT_FILLCOLOR, OnObjectFillColor)
ON_COMMAND(ID_OBJECT_LINECOLOR, OnObjectLineColor)
ON_COMMAND(ID_OBJECT_MOVEBACK, OnObjectMoveBack)
ON_COMMAND(ID_OBJECT_MOVEFORWARD, OnObjectMoveForward)
ON_COMMAND(ID_OBJECT_MOVETOBACK, OnObjectMoveToBack)
ON_COMMAND(ID_OBJECT_MOVETOFRONT, OnObjectMoveToFront)
ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, OnUpdateEditCopy)
ON_COMMAND(ID_EDIT_CUT, OnEditCut)
ON_UPDATE_COMMAND_UI(ID_EDIT_CUT, OnUpdateEditCut)
ON_COMMAND(ID_EDIT_PASTE, OnEditPaste)
ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, OnUpdateEditPaste)
ON_WM_SETFOCUS()
ON_COMMAND(ID_EDIT_PROPERTIES, OnEditProperties)
ON_UPDATE_COMMAND_UI(ID_EDIT_PROPERTIES, OnUpdateEditProperties)
ON_WM_DESTROY()
ON_UPDATE_COMMAND_UI(ID_EDIT_SELECT_ALL, OnUpdateEditSelectAll)
ON_WM_CREATE()
ON_WM_CONTEXTMENU()
ON_COMMAND(ID_UNDOCOMB, OnUndocomb)
ON_WM_CHAR()
ON_WM_TIMER()
ON_COMMAND(ID_CHOOSE_FONT, OnChooseFont)
ON_WM_KEYDOWN()
ON_COMMAND(ID_DRAW_ZOOM, OnDrawZoom)
ON_UPDATE_COMMAND_UI(ID_DRAW_ZOOM, OnUpdateDrawZoom)
ON_COMMAND(ID_DRAW_PAN, OnDrawPan)
ON_UPDATE_COMMAND_UI(ID_DRAW_PAN, OnUpdateDrawPan)
ON_WM_HSCROLL()
ON_WM_VSCROLL()
ON_COMMAND(ID_FILE_PRINT, OnFilePrint)
ON_WM_RBUTTONDOWN()
ON_COMMAND_RANGE(ID_PETRIF00,ID_PETRIF32,OnPetrif)
ON_UPDATE_COMMAND_UI_RANGE(ID_PETRIF00,ID_PETRIF32,OnUpdatePetrif)
ON_COMMAND(ID_TURN_X, OnTurnX)
ON_UPDATE_COMMAND_UI(ID_TURN_X, OnUpdateTurnX)
ON_COMMAND(ID_TURN_Y, OnTurnY)
ON_UPDATE_COMMAND_UI(ID_TURN_Y, OnUpdateTurnY)
ON_COMMAND(ID_TEST_REAL, OnTestReal)
ON_COMMAND(ID_COMBINATION, OnCombination)
ON_UPDATE_COMMAND_UI(ID_OBJECT_MOVEFORWARD, OnUpdateSingleSelect)
ON_UPDATE_COMMAND_UI(ID_OBJECT_MOVETOBACK, OnUpdateSingleSelect)
ON_UPDATE_COMMAND_UI(ID_OBJECT_MOVETOFRONT, OnUpdateSingleSelect)
ON_UPDATE_COMMAND_UI(ID_TEST_REAL, OnUpdateTestReal)
//}}AFX_MSG_MAP
// Standard printing commands
//ON_COMMAND(ID_FILE_PRINT, OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)//CScrollView
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDrawView construction/destruction

CDrawView::CDrawView()
{
m_bGrid = TRUE;
m_bShowReal=FALSE;
m_gridColor = RGB(0, 0, 0);
m_bActive = FALSE;

m_pDrawingObj = NULL;

/* OriginX=0.0;
OriginY=0.0;
Scale=Blc=1.0;*/
m_bMapLimit=true;
// FirstDrawControl=TRUE;
// new
if( m_cfObjectDescriptor == NULL )
m_cfObjectDescriptor = (CLIPFORMAT)::RegisterClipboardFormat(_T("Object Descriptor") );
m_prevDropEffect = DROPEFFECT_NONE;

m_pDrawingObj = NULL;

// end new
}

CDrawView::~CDrawView()
{
}

BOOL CDrawView::PreCreateWindow(CREATESTRUCT& cs)
{
ASSERT(cs.style & WS_CHILD);
if (cs.lpszClass == NULL)
cs.lpszClass = AfxRegisterWndClass(CS_DBLCLKS);
return TRUE;
}

void CDrawView::OnActivateView(BOOL bActivate, CView* pActiveView,
CView* pDeactiveView)
{
CView::OnActivateView(bActivate, pActiveView, pDeactiveView);

// invalidate selections when active status changes
if (m_bActive != bActivate)
{
if (bActivate) // if becoming active update as if active
m_bActive = bActivate;
if (!m_selection.IsEmpty())
OnUpdate(NULL, HINT_UPDATE_SELECTION, NULL);
m_bActive = bActivate;
}
}

/////////////////////////////////////////////////////////////////////////////
// CDrawView drawing

void CDrawView::InvalObjTmp(CDrawObj* pObj)
{
CRect rect = pObj->GetTmpPosition();
rect.NormalizeRect();

int offset = 1;

rect.InflateRect(offset, offset, offset, offset); // handles CDrawOleObj objects

if (m_bActive && IsSelected(pObj))
{
rect.left -= 4;
rect.top -= 5;
rect.right += 5;
rect.bottom += 4;
}

rect.InflateRect(1,1);
InvalidateRect(rect, FALSE);
}

void CDrawView::InvalObj(CDrawObj* pObj)
{
CDRect d_rect = pObj->m_position;
DocToClient(d_rect,false);
CRect rect = d_rect.ToCRect();
rect.NormalizeRect();

int offset;
double penwidth=pObj->m_logpen.lopnWidth.x;
DocToClient(penwidth,false);
offset=(int)(penwidth+0.5);
//offset=(pObj->m_logpen.lopnWidth.x)/2;
offset = max(offset,1);

rect.InflateRect(offset, offset, offset, offset); // handles CDrawOleObj objects
// DocToClient(rect,false);
// rect.NormalizeRect();
if (m_bActive && IsSelected(pObj))
{
rect.left -= 4;
rect.top -= 5;
rect.right += 5;
rect.bottom += 4;
}

// rect.ToCRect().InflateRect(1, 1); // handles CDrawOleObj objects
rect.InflateRect(1,1);
InvalidateRect(rect, FALSE);

//InvalidateRect(rect.ToCRect(), FALSE);
}

void CDrawView::OnUpdate(CView* , LPARAM lHint, CObject* pHint)
{
switch (lHint)
{
case HINT_UPDATE_WINDOW: // redraw entire window
Invalidate(FALSE);
break;

case HINT_UPDATE_DRAWOBJ: // a single object has changed
InvalObj((CDrawObj*)pHint);
break;

case HINT_UPDATE_SELECTION: // an entire selection has changed
{
CDrawObjList* pList = pHint != NULL ?
(CDrawObjList*)pHint : &m_selection;
POSITION pos = pList->GetHeadPosition();
while (pos != NULL)
InvalObj(pList->GetNext(pos));
}
break;

case HINT_DELETE_SELECTION: // an entire selection has been removed
if (pHint != &m_selection)
{
CDrawObjList* pList = (CDrawObjList*)pHint;
POSITION pos = pList->GetHeadPosition();
while (pos != NULL)
{
CDrawObj* pObj = pList->GetNext(pos);
InvalObj(pObj);
Remove(pObj); // remove it from this view's selection
}
}
break;

case HINT_UPDATE_OLE_ITEMS:
{
// CDrawDoc* pDoc = GetDocument();
// POSITION pos = pDoc->GetObjects()->GetHeadPosition();
// while (pos != NULL)
// {
// CDrawObj* pObj = pDoc->GetObjects()->GetNext(pos);
// if (pObj->IsKindOf(RUNTIME_CLASS(CDrawOleObj)))
// InvalObj(pObj);
// }
}
break;

default:
ASSERT(FALSE);
break;
}
}

void CDrawView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
CView::OnPrepareDC(pDC, pInfo);//CScrollView

// mapping mode is MM_ANISOTROPIC
// these extents setup a mode similar to MM_LOENGLISH
// MM_LOENGLISH is in .01 physical inches
// these extents provide .01 logical inches

//pDC->SetMapMode(MM_ANISOTROPIC);
//pDC->SetViewportExt(pDC->GetDeviceCaps(LOGPIXELSX),
// pDC->GetDeviceCaps(LOGPIXELSY));
//pDC->SetWindowExt(100, -100);

// set the origin of the coordinate system to the center of the page
//CPoint ptOrg;
//ptOrg.x = GetDocument()->GetSize().cx / 2;
//ptOrg.y = GetDocument()->GetSize().cy / 2;

// ptOrg is in logical coordinates
//pDC->OffsetWindowOrg(-ptOrg.x,ptOrg.y);
// pDC->SetWindowExt(1000, 1000);
}

BOOL CDrawView::OnScrollBy(CSize sizeScroll, BOOL bDoScroll)
{
// do the scroll
if (!CView::OnScrollBy(sizeScroll, bDoScroll))//CScrollView
return FALSE;

// update the position of any in-place active item

return TRUE;
}

void CDrawView::OnDraw(CDC* pDC)
{
CDrawDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);

CDC dc;
CDC* pDrawDC = pDC;
CBitmap bitmap;
CBitmap* pOldBitmap=NULL;

// only paint the rect that needs repainting
CRect client;
pDC->GetClipBox(client);
CRect rect = client;
// DocToClient(rect);

if (!pDC->IsPrinting())
{
// draw to offscreen bitmap for fast looking repaints
if (dc.CreateCompatibleDC(pDC))
{
if (bitmap.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height()))
{
OnPrepareDC(&dc, NULL);//dc:mem dc
pDrawDC = &dc;

// offset origin more because bitmap is just piece of the whole drawing
dc.OffsetViewportOrg(-rect.left, -rect.top);
pOldBitmap = dc.SelectObject(&bitmap);
dc.SetBrushOrg(rect.left % 8, rect.top % 8);

// might as well clip to the same rectangle
dc.IntersectClipRect(client);
}
}
}
else ScalePrinter(pDC);

// paint background
CBrush brush;
if (!brush.CreateSolidBrush(pDoc->GetPaperColor()))
return;

brush.UnrealizeObject();
pDrawDC->FillRect(client, &brush);

if (!pDC->IsPrinting() && m_bGrid)
DrawGrid(pDrawDC);

pDoc->Draw(pDrawDC, this);

if (pDrawDC != pDC)
{
pDC->SetViewportOrg(0, 0);
pDC->SetWindowOrg(0,0);
pDC->SetMapMode(MM_TEXT);
dc.SetViewportOrg(0, 0);
dc.SetWindowOrg(0,0);
dc.SetMapMode(MM_TEXT);
pDC->BitBlt(rect.left, rect.top, rect.Width(), rect.Height(),
&dc, 0, 0, SRCCOPY);
if (pOldBitmap!=NULL) dc.SelectObject(pOldBitmap);
}
}

void CDrawView::Remove(CDrawObj* pObj)
{
POSITION pos = m_selection.Find(pObj);
if (pos != NULL)
m_selection.RemoveAt(pos);
}

void CDrawView::PasteNative(COleDataObject& dataObject)
{
// get file refering to clipboard data
CFile* pFile = dataObject.GetFileData(m_cfDraw);
if (pFile == NULL)
return;

// connect the file to the archive
CArchive ar(pFile, CArchive::load);
TRY
{
ar.m_pDocument = GetDocument(); // set back-pointer in archive

// read the selection
m_selection.Serialize(ar);
}
CATCH_ALL(e)
{
ar.Close();
delete pFile;
THROW_LAST();
}
END_CATCH_ALL

ar.Close();
delete pFile;
}
/*
void CDrawView::PasteEmbedded(COleDataObject& dataObject, CPoint point )
{
BeginWaitCursor();

// paste embedded
CDrawOleObj* pObj = new CDrawOleObj(GetInitialPosition());
ASSERT_VALID(pObj);
CDrawItem* pItem = new CDrawItem(GetDocument(), pObj);
ASSERT_VALID(pItem);
pObj->m_pClientItem = pItem;

TRY
{
if (!pItem->CreateFromData(&dataObject) &&
!pItem->CreateStaticFromData(&dataObject))
{
AfxThrowMemoryException(); // any exception will do
}

// add the object to the document
GetDocument()->Add(pObj);
m_selection.AddTail(pObj);
ClientToDoc( point );
pObj->MoveTo( CRect( point, pObj->m_extent ), this );

// try to get initial presentation data
pItem->UpdateLink();
pItem->UpdateExtent();
}
CATCH_ALL(e)
{
// clean up item
pItem->Delete();
pObj->m_pClientItem = NULL;
GetDocument()->Remove(pObj);
pObj->Remove();

AfxMessageBox(IDP_FAILED_TO_CREATE);
}
END_CATCH_ALL

EndWaitCursor();
}
*/
void CDrawView::DrawGrid(CDC* pDC)
{
CDrawDoc* pDoc = GetDocument();

int oldMode=pDC->SetROP2(R2_MERGEPENNOT);
COLORREF oldBkColor = pDC->SetBkColor(pDoc->GetPaperColor());

CRect rect;
GetClientRect(&rect);

/* rect.left = 0;
rect.top = 0;
rect.right = 1000;
rect.bottom = 1000;*/

/* rect.left = -pDoc->GetSize().cx / 2;
rect.top = -pDoc->GetSize().cy / 2;
rect.right = rect.left + pDoc->GetSize().cx;
rect.bottom = rect.top + pDoc->GetSize().cy;*/

// Center lines
CPen penDash;
penDash.CreatePen(PS_DOT, 1, m_gridColor);
CPen* pOldPen = pDC->SelectObject(&penDash);

// Major unit lines
int x,y;

for (x = rect.left / 10 * 10; x < rect.right; x += 10)
{
if (x != 0)
{
for (y = rect.top / 10 * 10; y < rect.bottom; y += 10)
{
if (y != 0)
{
pDC->SetPixel(x,y,m_gridColor);
}
}
}
}

// Outlines
CPen penSolid;
penSolid.CreatePen(PS_SOLID, 1, m_gridColor);

CDRect outBound(0,0,pDoc->m_pic.width,pDoc->m_pic.height);
DocToClient(outBound,false);
rect=outBound.ToCRect();

pDC->SelectObject(&penSolid);
pDC->MoveTo(rect.left, rect.top);
pDC->LineTo(rect.right, rect.top);
pDC->LineTo(rect.right, rect.bottom);
pDC->LineTo(rect.left, rect.bottom);
pDC->LineTo(rect.left, rect.top);

pDC->SelectObject(pOldPen);
pDC->SetBkColor(oldBkColor);
pDC->SetROP2(oldMode);
}

void CDrawView::OnInitialUpdate()
{
/* CSize size = GetDocument()->GetSize();
CClientDC dc(NULL);
size.cx = MulDiv(size.cx, dc.GetDeviceCaps(LOGPIXELSX), 100);
size.cy = MulDiv(size.cy, dc.GetDeviceCaps(LOGPIXELSY), 100);
SetScrollSizes(MM_TEXT, size);*/

CRect tmpRect;
GetClientRect(tmpRect);
//SetScrollSizes(MM_TEXT, tmpRect.Size());
// ShowScrollBar(SB_HORZ,true);
// ShowScrollBar(SB_VERT,true);

SetTimer(1, 500, NULL);

}

void CDrawView::OnChooseFont()
{
if (m_selection.GetCount() == 1)
{
POSITION pos = m_selection.GetHeadPosition();
CDrawObj* pObj = (CDrawObj *)m_selection.GetNext(pos);
if (pObj->m_nShape == shp_text)
{
POSITION pos = m_selection.GetHeadPosition();
CDrawText* pTextObj = (CDrawText *)m_selection.GetNext(pos);
CFontDialog dlg(&(pTextObj->m_logfont),CF_SCREENFONTS | CF_EFFECTS | CF_INITTOLOGFONTSTRUCT);
dlg.m_cf.rgbColors=pTextObj->m_logpen.lopnColor;
if (dlg.DoModal() == IDOK)
{
CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
CClientDC dc(&(pMainFrame->m_wndPaletteBar));
CPen* pOldPen;
CBrush* pOldBrush;
pTextObj->m_logpen.lopnColor=dlg.m_cf.rgbColors;
if(pen_lbColor!=dlg.m_cf.rgbColors)
{
pen_lbColor=dlg.m_cf.rgbColors;
CPen MyPen(PS_SOLID,2,RGB(192,192,192));
CBrush MyBrush(pen_lbColor);
pOldPen=dc.SelectObject(&MyPen);
pOldBrush=dc.SelectObject(&MyBrush);
CPoint p(20+6, 12+5);
CRect rec(p,CSize(14, 14));
dc.Rectangle(&rec);
dc.SelectObject(pOldPen);
dc.SelectObject(pOldBrush);
}
m_lfDefFont=pTextObj->m_logfont;
//**********************
CString cstring;

CClientDC dcv(this);
CSize size;
OnPrepareDC(&dcv, NULL);

CFont font;
if(!font.CreateFontIndirect(&pTextObj->m_logfont))
return;
CFont* pOldFont;
pOldFont=dcv.SelectObject(&font);

int i,height;
CString temp_str;
CSize temp_size;
temp_str=pTextObj->text;
if(temp_str.GetLength()==0)
{
temp_size=dcv.GetTextExtent("a",1);
temp_size.cx=0;
}
else
temp_size=dcv.GetTextExtent(pTextObj->text,pTextObj->text.GetLength());
if((i=temp_str.Find(13))>=0)size.cx=0;
else size.cx=temp_size.cx;
size.cy=temp_size.cy;
height=temp_size.cy;
while((i=temp_str.Find(13))>=0)
{
CString temp=temp_str.Mid(0,i);
temp_size=dcv.GetTextExtent(temp,temp.GetLength());
if(temp_size.cx>size.cx)size.cx=temp_size.cx;
temp_str=temp_str.Mid(i+1);
}

temp_size=dcv.GetTextExtent(temp_str,temp_str.GetLength());
if(temp_size.cx>size.cx)size.cx=temp_size.cx;

size.cy=pTextObj->line_num*size.cy;
size+=CSize(CX_INSET * 2, CY_INSET * 2);

CDRect position = pTextObj->m_position;
double left,top;
if(position.left<position.right)
left=position.left;
else
left=position.right;
if(position.bottom<position.top)
top=position.top;
else
top=position.bottom;
CDPoint ponit(left,top);
CDRect rect(ponit, CDSize(size.cx, -size.cy));

int offset;
offset=(pTextObj->m_logpen.lopnWidth.x)/2;
//rect.NormalizeRect();
rect.InflateRect(0, 0, 2*offset, -2*offset); // handles CDrawOleObj objects

//pTextObj->MoveTo(rect, this);
if (this == NULL)
{
pTextObj->Invalidate();
pTextObj->m_position = rect;
pTextObj->Invalidate();
}
else
{
InvalObj(pTextObj);
pTextObj->m_position = rect;
InvalObj(pTextObj);
}

//this->SendMessage(WM_KEYDOWN,VK_LEFT/VK_RIGHT,0);
CSize tsize;
cstring=pTextObj->text.Mid(0,pTextObj->cur_pos);

pTextObj->line_cur=1;

temp_str=cstring;
temp_size=dcv.GetTextExtent(cstring,cstring.GetLength());
if(cstring.GetLength()==0)
{
tsize=dcv.GetTextExtent("a",1);
temp_size.cy=tsize.cy;
}

if((i=temp_str.Find(13))>=0)size.cx=0;
else size.cx=temp_size.cx;
size.cy=temp_size.cy;
height=temp_size.cy;

while((i=temp_str.Find(13))>=0)
{
CString temp=temp_str.Mid(0,i);
temp_size=dcv.GetTextExtent(temp,temp.GetLength());
if(temp_size.cx>size.cx)size.cx=temp_size.cx;
temp_str=temp_str.Mid(i+1);
pTextObj->line_cur++;
}

temp_size=dcv.GetTextExtent(temp_str,temp_str.GetLength());
if(temp_size.cx>size.cx)size.cx=temp_size.cx;

size.cy=pTextObj->line_cur*size.cy;
size+=CSize(CX_INSET * 2, CY_INSET * 2);

position = pTextObj->m_position;
//int left,top;
if(position.left<position.right)
left=position.left;
else
left=position.right;
if(position.bottom<position.top)
top=position.top;
else
top=position.bottom;
ponit=CDPoint(left,top);
rect=CDRect(ponit, CDSize(size.cx, -size.cy));

if(temp_size.cy!=0)
{
pTextObj->cur_start=CDPoint((rect.right+CX_INSET)-(fabs(rect.Width())-temp_size.cx),(rect.bottom+CY_INSET));
pTextObj->cur_end=CDPoint((rect.right+CX_INSET)-(fabs(rect.Width())-temp_size.cx),(rect.top-CY_INSET)-(pTextObj->line_cur-1)*temp_size.cy);
}
else
{
pTextObj->cur_start=CDPoint((rect.right+CX_INSET)-(fabs(rect.Width())-temp_size.cx),(rect.bottom+CY_INSET));
pTextObj->cur_end=CDPoint((rect.right+CX_INSET)-(fabs(rect.Width())-temp_size.cx),(rect.top-CY_INSET)-(pTextObj->line_cur-1)*height);
}
InvalObj(pTextObj);
//this->SendMessage(WM_KEYDOWN,VK_LEFT/VK_RIGHT,0); end

pTextObj->m_pDocument->SetModifiedFlag();
if (pTextObj->m_nObjstate==obj_nochange)
pTextObj->m_nObjstate=obj_update;

dcv.SelectObject(pOldFont);
GetDocument()->UpdateAllViews(this);
//**********************
}
return;
}
}

CClientDC dct(this);
CFontDialog dlg(&m_lfDefFont,CF_SCREENFONTS | CF_EFFECTS | CF_INITTOLOGFONTSTRUCT);
dlg.m_cf.rgbColors=pen_lbColor;
if (dlg.DoModal() == IDOK)
{
CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
CClientDC dc(&(pMainFrame->m_wndPaletteBar));
CPen* pOldPen;
CBrush* pOldBrush;

if(pen_lbColor==dlg.m_cf.rgbColors)return;
pen_lbColor=dlg.m_cf.rgbColors;
CPen MyPen(PS_SOLID,2,RGB(192,192,192));
CBrush MyBrush(pen_lbColor);
pOldPen=dc.SelectObject(&MyPen);
pOldBrush=dc.SelectObject(&MyBrush);
CPoint p(20+6, 12+5);
CRect rec(p,CSize(14, 14));
dc.Rectangle(&rec);
dc.SelectObject(pOldPen);
dc.SelectObject(pOldBrush);
}
}
/*
void CDrawView::SetPageSize(CSize size)
{
CClientDC dc(NULL);
size.cx = MulDiv(size.cx, dc.GetDeviceCaps(LOGPIXELSX), 100);
size.cy = MulDiv(size.cy, dc.GetDeviceCaps(LOGPIXELSY), 100);
SetScrollSizes(MM_TEXT, size);
GetDocument()->UpdateAllViews(NULL, HINT_UPDATE_WINDOW, NULL);
}*/

/////////////////////////////////////////////////////////////////////////////
// CDrawView printing

BOOL CDrawView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}

void CDrawView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
CView::OnBeginPrinting(pDC,pInfo);

// check page size -- user could have gone into print setup
// from print dialog and changed paper or orientation
// GetDocument()->ComputePageSize();
}

void CDrawView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// OLE Client support and commands

BOOL CDrawView::IsSelected(const CObject* pDocItem) const
{
CDrawObj* pDrawObj = (CDrawObj*)pDocItem;
// if (pDocItem->IsKindOf(RUNTIME_CLASS(CDrawItem)))
// pDrawObj = ((CDrawItem*)pDocItem)->m_pDrawObj;
return m_selection.Find(pDrawObj) != NULL;
}

void CDrawView::OnInsertObject()
{
// Invoke the standard Insert Object dialog box to obtain information
// for new CDrawItem object.
/* COleInsertDialog dlg;
if (dlg.DoModal() != IDOK)
return;

BeginWaitCursor();

// First create the C++ object
CDrawOleObj* pObj = new CDrawOleObj(GetInitialPosition());
ASSERT_VALID(pObj);
CDrawItem* pItem = new CDrawItem(GetDocument(), pObj);
ASSERT_VALID(pItem);
pObj->m_pClientItem = pItem;

// Now create the OLE object/item
TRY
{
if (!dlg.CreateItem(pObj->m_pClientItem))
AfxThrowMemoryException();

// add the object to the document
GetDocument()->Add(pObj);

// try to get initial presentation data
pItem->UpdateLink();
pItem->UpdateExtent();

// if insert new object -- initially show the object
if (dlg.GetSelectionType() == COleInsertDialog::createNewItem)
pItem->DoVerb(OLEIVERB_SHOW, this);
}
CATCH_ALL(e)
{
// clean up item
pItem->Delete();
pObj->m_pClientItem = NULL;
GetDocument()->Remove(pObj);
pObj->Remove();

AfxMessageBox(IDP_FAILED_TO_CREATE);
}
END_CATCH_ALL

EndWaitCursor();*/
}

// The following command handler provides the standard keyboard
// user interface to cancel an in-place editing session.
void CDrawView::OnCancelEdit()
{
// deactivate any in-place active item on this view!
COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
if (pActiveItem != NULL)
{
// if we found one, deactivate it
pActiveItem->Close();
}
ASSERT(GetDocument()->GetInPlaceActiveItem(this) == NULL);

// escape also brings us back into select mode
ReleaseCapture();

CDrawTool* pTool = CDrawTool::FindTool(CDrawTool::c_drawShape);
if (pTool != NULL)
{
pTool->OnCancel();
m_pDrawingObj = NULL;
}

CDrawTool::c_drawShape = draw_selection;
}

void CDrawView::OnSetFocus(CWnd* pOldWnd)
{
COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
if (pActiveItem != NULL &&
pActiveItem->GetItemState() == COleClientItem::activeUIState)
{
// need to set focus to this item if it is in the same view
CWnd* pWnd = pActiveItem->GetInPlaceWindow();
if (pWnd != NULL)
{
pWnd->SetFocus();
return;
}
}

CView::OnSetFocus(pOldWnd);
}
/*
CDRect CDrawView::GetInitialPosition()
{
CDRect rect(10, 10, 10, 10);
ClientToDoc(rect);
return rect;
}
*/
void CDrawView::DocToClient(CDPoint& point,bool bPrint)
{
if (bPrint)
{
point.x=point.x/m_PrintScale+m_PrintmapOx;
point.y=m_PrintmapOy-point.y/m_PrintScale;
}
else
{
point.x=point.x/m_Scale+m_mapOx;
point.y=m_mapOy-point.y/m_Scale;
}
}

void CDrawView::DocToClient(CDRect& rect,bool bPrint)
{
if (bPrint)
{
rect.left=rect.left/m_PrintScale+m_PrintmapOx;
rect.top=m_PrintmapOy-rect.top/m_PrintScale;
rect.right=rect.right/m_PrintScale+m_PrintmapOx;
rect.bottom=m_PrintmapOy-rect.bottom/m_PrintScale;
}
else
{
rect.left=rect.left/m_Scale+m_mapOx;
rect.top=m_mapOy-rect.top/m_Scale;
rect.right=rect.right/m_Scale+m_mapOx;
rect.bottom=m_mapOy-rect.bottom/m_Scale;
}
}





/*
void CDrawView::ClientToDoc(CPoint& point)
{
CClientDC dc(this);
OnPrepareDC(&dc, NULL);
dc.DPtoLP(&point);
}

void CDrawView::ClientToDoc(CRect& rect)
{
CClientDC dc(this);
OnPrepareDC(&dc, NULL);
dc.DPtoLP(rect);
ASSERT(rect.left <= rect.right);
ASSERT(rect.bottom <= rect.top);
}

void CDrawView::DocToClient(CPoint& point)
{
CClientDC dc(this);
OnPrepareDC(&dc, NULL);
dc.LPtoDP(&point);
}

void CDrawView::DocToClient(CRect& rect)
{
CClientDC dc(this);
OnPrepareDC(&dc, NULL);
dc.LPtoDP(rect);
rect.NormalizeRect();
}
*/
void CDrawView::Select(CDrawObj* pObj, BOOL bAdd)
{
if (!bAdd)
{
OnUpdate(NULL, HINT_UPDATE_SELECTION, NULL);
m_selection.RemoveAll();
}

if (pObj == NULL || IsSelected(pObj))
return;

m_selection.AddTail(pObj);
InvalObj(pObj);
}

// rect is in device coordinates
void CDrawView::SelectWithinRect(CRect rect, BOOL bAdd)
{
if (!bAdd)
Select(NULL);

// ClientToDoc(rect);

CDrawObjList* pObList = GetDocument()->GetObjects();
POSITION posObj = pObList->GetHeadPosition();
while (posObj != NULL)
{
CDrawObj* pObj = pObList->GetNext(posObj);
if (pObj->Intersects(rect,this))
Select(pObj, TRUE);
}
}

void CDrawView::Deselect(CDrawObj* pObj)
{
POSITION pos = m_selection.Find(pObj);
if (pos != NULL)
{
InvalObj(pObj);
m_selection.RemoveAt(pos);
}
}

void CDrawView::DeSelectAll()
{
POSITION pos = m_selection.GetHeadPosition();
CDrawObj* pObj;
while (pos!=NULL)
{
pObj = m_selection.GetNext(pos);
InvalObj(pObj);
}
m_selection.RemoveAll();
}

void CDrawView::CloneSelection()
{
CDrawObjList tmpsel;
POSITION pos = m_selection.GetHeadPosition();
while (pos != NULL)
{
CDrawObj* pObj = m_selection.GetNext(pos);
tmpsel.AddTail(pObj->Clone(pObj->m_pDocument)); // copies object and adds it to the document
pObj->InitTmpState(NULL);
//pObj->m_tmpState = tmp_normal;
}
m_selection.RemoveAll();

pos = tmpsel.GetHeadPosition();
while (pos != NULL)
{
CDrawObj* pObj = tmpsel.GetNext(pos);
//pObj->m_tmpState = tmp_moving;
m_selection.AddTail(pObj);
}
}

void CDrawView::UpdateActiveItem()
{
COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
if (pActiveItem != NULL &&
pActiveItem->GetItemState() == COleClientItem::activeUIState)
{
// this will update the item rectangles by calling
// OnGetPosRect & OnGetClipRect.
pActiveItem->SetItemRects();
}
}

/////////////////////////////////////////////////////////////////////////////
// CDrawView message handlers

void CDrawView::OnLButtonDown(UINT nFlags, CPoint point)
{
if (!m_bActive)
return;
CDrawTool* pTool = CDrawTool::FindTool(CDrawTool::c_drawShape);
if (pTool != NULL)
pTool->OnLButtonDown(this, nFlags, point);
}

void CDrawView::OnLButtonUp(UINT nFlags, CPoint point)
{
if (!m_bActive)
return;
CDrawTool* pTool = CDrawTool::FindTool(CDrawTool::c_drawShape);
if (pTool != NULL)
pTool->OnLButtonUp(this, nFlags, point);
}

void CDrawView::OnMouseMove(UINT nFlags, CPoint point)
{
char text[100];
CStatusBar* pStatus=(CStatusBar*)
AfxGetApp()->m_pMainWnd->GetDescendantWindow(ID_VIEW_STATUS_BAR);
if(pStatus){
wsprintf(text,"%4d,%4d",point.x,point.y);
pStatus->SetPaneText(1,text);
}

if (!m_bActive)
return;
CDrawTool* pTool = CDrawTool::FindTool(CDrawTool::c_drawShape);
if (pTool != NULL)
pTool->OnMouseMove(this, nFlags, point);
}

void CDrawView::OnLButtonDblClk(UINT nFlags, CPoint point)
{
if (!m_bActive)
return;
CDrawTool* pTool = CDrawTool::FindTool(CDrawTool::c_drawShape);
if (pTool != NULL)
pTool->OnLButtonDblClk(this, nFlags, point);
}

void CDrawView::OnDestroy()
{
CView::OnDestroy();

// deactivate the inplace active item on this view
COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
if (pActiveItem != NULL && pActiveItem->GetActiveView() == this)
{
pActiveItem->Deactivate();
ASSERT(GetDocument()->GetInPlaceActiveItem(this) == NULL);
}
KillTimer(1);
}

void CDrawView::OnDrawSelect()
{
CDrawTool::c_drawShape = draw_selection;
CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
pMainFrame->m_wndMarkersBar.ResetNormal();

}

void CDrawView::OnDrawRoundRect()
{
if (CDrawTool::c_drawShape == draw_roundRect) CDrawTool::c_drawShape = draw_selection;
else CDrawTool::c_drawShape = draw_roundRect;
CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
pMainFrame->m_wndMarkersBar.ResetNormal();
}

void CDrawView::OnDrawRect()
{
if (CDrawTool::c_drawShape == draw_rect) CDrawTool::c_drawShape = draw_selection;
else CDrawTool::c_drawShape = draw_rect;
CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
pMainFrame->m_wndMarkersBar.ResetNormal();
}

void CDrawView::OnDrawLine()
{
if (CDrawTool::c_drawShape == draw_line) CDrawTool::c_drawShape = draw_selection;
else CDrawTool::c_drawShape = draw_line;
CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
pMainFrame->m_wndMarkersBar.ResetNormal();
}

void CDrawView::OnDrawLine90()
{
if (CDrawTool::c_drawShape == draw_line90) CDrawTool::c_drawShape = draw_selection;
else CDrawTool::c_drawShape = draw_line90;
CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
pMainFrame->m_wndMarkersBar.ResetNormal();
}


void CDrawView::OnDrawText()
{
if (CDrawTool::c_drawShape == draw_text) CDrawTool::c_drawShape = draw_selection;
else CDrawTool::c_drawShape = draw_text;
CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
pMainFrame->m_wndMarkersBar.ResetNormal();
}

void CDrawView::OnDrawData()
{
if (CDrawTool::c_drawShape == draw_data) CDrawTool::c_drawShape = draw_selection;
else CDrawTool::c_drawShape = draw_data;
CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
pMainFrame->m_wndMarkersBar.ResetNormal();
}

void CDrawView::OnDrawArc()
{
if (CDrawTool::c_drawShape == draw_arc) CDrawTool::c_drawShape = draw_selection;
else CDrawTool::c_drawShape = draw_arc;
CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
pMainFrame->m_wndMarkersBar.ResetNormal();
}

void CDrawView::OnDrawPie()
{
if (CDrawTool::c_drawShape == draw_pie) CDrawTool::c_drawShape = draw_selection;
else CDrawTool::c_drawShape = draw_pie;
CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
pMainFrame->m_wndMarkersBar.ResetNormal();
}

void CDrawView::OnDrawChord()
{
if (CDrawTool::c_drawShape == draw_chord) CDrawTool::c_drawShape = draw_selection;
else CDrawTool::c_drawShape = draw_chord;
CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
pMainFrame->m_wndMarkersBar.ResetNormal();
}

void CDrawView::OnDrawEllipse()
{
if (CDrawTool::c_drawShape == draw_ellipse) CDrawTool::c_drawShape = draw_selection;
else CDrawTool::c_drawShape = draw_ellipse;
CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
pMainFrame->m_wndMarkersBar.ResetNormal();
}

void CDrawView::OnDrawPolygon()
{
if (CDrawTool::c_drawShape == draw_polygon) CDrawTool::c_drawShape = draw_selection;
else CDrawTool::c_drawShape = draw_polygon;
CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
pMainFrame->m_wndMarkersBar.ResetNormal();
}

void CDrawView::OnDrawPolyline()
{
if (CDrawTool::c_drawShape == draw_polyline) CDrawTool::c_drawShape = draw_selection;
else CDrawTool::c_drawShape = draw_polyline;
CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
pMainFrame->m_wndMarkersBar.ResetNormal();
}

void CDrawView::OnDrawPolybezier()
{
if (CDrawTool::c_drawShape == draw_polybezier) CDrawTool::c_drawShape = draw_selection;
else CDrawTool::c_drawShape = draw_polybezier;
CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
pMainFrame->m_wndMarkersBar.ResetNormal();
}

void CDrawView::OnUpdateDrawEllipse(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(CDrawTool::c_drawShape == draw_ellipse);
}

void CDrawView::OnUpdateDrawText(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(CDrawTool::c_drawShape == draw_text);
}

void CDrawView::OnUpdateDrawData(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(CDrawTool::c_drawShape == draw_data);
}

void CDrawView::OnUpdateDrawArc(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(CDrawTool::c_drawShape == draw_arc);
}

void CDrawView::OnUpdateDrawPie(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(CDrawTool::c_drawShape == draw_pie);
}

void CDrawView::OnUpdateDrawChord(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(CDrawTool::c_drawShape == draw_chord);
}

void CDrawView::OnUpdateDrawLine(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(CDrawTool::c_drawShape == draw_line);
}

void CDrawView::OnUpdateDrawLine90(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(CDrawTool::c_drawShape == draw_line90);
}


void CDrawView::OnUpdateDrawRect(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(CDrawTool::c_drawShape == draw_rect);
}

void CDrawView::OnUpdateDrawRoundRect(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(CDrawTool::c_drawShape == draw_roundRect);
}

void CDrawView::OnUpdateDrawSelect(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(CDrawTool::c_drawShape == draw_selection);
}

void CDrawView::OnUpdateSingleSelect(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_selection.GetCount() == 1);
}

void CDrawView::OnEditSelectAll()
{
CDrawObjList* pObList = GetDocument()->GetObjects();
POSITION pos = pObList->GetHeadPosition();
while (pos != NULL)
Select(pObList->GetNext(pos), TRUE);
}

void CDrawView::OnUpdateEditSelectAll(CCmdUI* pCmdUI)
{
pCmdUI->Enable(GetDocument()->GetObjects()->GetCount() != 0);
}


void CDrawView::Delete(CDrawObjList *pObjs,bool bDelAll)
{
POSITION pos = pObjs->GetHeadPosition();
while (pos != NULL)
{
CDrawObj* pObj = pObjs->GetNext(pos);
if ((bDelAll)&&(pObj->m_nShape==shp_comb))
Delete(&(((CDrawComb*)pObj)->m_combination),true);
////////////add for yxgd
GetDocument()->Remove(pObj);
if (pObj->m_nObjstate==obj_newcreate)
pObj->Remove();
else GetDocument()->GetDelObjects()->AddTail(pObj);
}
pObjs->RemoveAll();
}

void CDrawView::OnEditClear()
{
// update all the views before the selection goes away
GetDocument()->UpdateAllViews(NULL, HINT_DELETE_SELECTION, &m_selection);
OnUpdate(NULL, HINT_UPDATE_SELECTION, NULL);

// now remove the selection from the document
Delete(&m_selection,true);
}

void CDrawView::OnUpdateAnySelect(CCmdUI* pCmdUI)
{
pCmdUI->Enable(!m_selection.IsEmpty());
}

void CDrawView::OnUpdateDrawPolygon(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(CDrawTool::c_drawShape == draw_polygon);
}

void CDrawView::OnUpdateDrawPolyline(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(CDrawTool::c_drawShape == draw_polyline);
}

void CDrawView::OnUpdateDrawPolybezier(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(CDrawTool::c_drawShape == draw_polybezier);
}


void CDrawView::ScaleLimitMap()
{
CRect rect;
GetClientRect(&rect);

double bl1,bl2;
bl1=GetDocument()->m_pic.width/rect.Width();
bl2=GetDocument()->m_pic.height/rect.Height();

if(bl1>bl2) {
m_Scale=bl1;
m_mapOx=0;
m_mapOy=(int)((rect.Height()+GetDocument()->m_pic.height/m_Scale)/2+0.5);
}
else
{
m_Scale=bl2;
m_mapOx=(int)((rect.Width()-GetDocument()->m_pic.width/m_Scale)/2+0.5);
m_mapOy=rect.Height();
}
m_mapOx_INI=m_mapOx;
m_mapOy_INI=m_mapOy;

SetScroller();
}


void CDrawView::ScalePrinter(CDC* pDC)
{
int prt_width=pDC->GetDeviceCaps(HORZRES);
int prt_height=pDC->GetDeviceCaps(VERTRES);
double bl1,bl2;
bl1=GetDocument()->m_pic.width/prt_width;
bl2=GetDocument()->m_pic.height/prt_height;

if(bl1>bl2) {
m_PrintScale=bl1;
m_PrintmapOx=0;
m_PrintmapOy=(int)((prt_height+GetDocument()->m_pic.height/m_PrintScale)/2+0.5);
}
else
{
m_PrintScale=bl2;
m_PrintmapOx=(int)((prt_width-GetDocument()->m_pic.width/m_PrintScale)/2+0.5);
m_PrintmapOy=prt_height;
}
}


void CDrawView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
if (m_bMapLimit) ScaleLimitMap();
UpdateActiveItem();
SetScroller();
}

void CDrawView::OnViewGrid()
{
m_bGrid = !m_bGrid;
Invalidate(FALSE);
}

void CDrawView::OnUpdateViewGrid(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_bGrid);

}

BOOL CDrawView::OnEraseBkgnd(CDC*)
{
return TRUE;
}

void CDrawView::OnObjectFillColor()
{
CColorDialog dlg;
if (dlg.DoModal() != IDOK)
return;

COLORREF color = dlg.GetColor();

POSITION pos = m_selection.GetHeadPosition();
while (pos != NULL)
{
CDrawObj* pObj = m_selection.GetNext(pos);
pObj->SetFillColor(color);
}
}

void CDrawView::OnObjectLineColor()
{
CColorDialog dlg;
if (dlg.DoModal() != IDOK)
return;

COLORREF color = dlg.GetColor();

POSITION pos = m_selection.GetHeadPosition();
while (pos != NULL)
{
CDrawObj* pObj = m_selection.GetNext(pos);
pObj->SetLineColor(color);
}
}

void CDrawView::OnObjectMoveBack()
{
CDrawDoc* pDoc = GetDocument();
CDrawObj* pObj = m_selection.GetHead();
CDrawObjList* pObjects = pDoc->GetObjects();
POSITION pos = pObjects->Find(pObj);
ASSERT(pos != NULL);
if (pos != pObjects->GetHeadPosition())
{
POSITION posPrev = pos;
pObjects->GetPrev(posPrev);
pObjects->RemoveAt(pos);
pObjects->InsertBefore(posPrev, pObj);
InvalObj(pObj);
}
GetDocument()->UpdateAllViews(this);
}

void CDrawView::OnObjectMoveForward()
{
CDrawDoc* pDoc = GetDocument();
CDrawObj* pObj = m_selection.GetHead();
CDrawObjList* pObjects = pDoc->GetObjects();
POSITION pos = pObjects->Find(pObj);
ASSERT(pos != NULL);
if (pos != pObjects->GetTailPosition())
{
POSITION posNext = pos;
pObjects->GetNext(posNext);
pObjects->RemoveAt(pos);
pObjects->InsertAfter(posNext, pObj);
InvalObj(pObj);
}
GetDocument()->UpdateAllViews(this);
}

void CDrawView::OnObjectMoveToBack()
{
CDrawDoc* pDoc = GetDocument();
CDrawObj* pObj = m_selection.GetHead();
CDrawObjList* pObjects = pDoc->GetObjects();
POSITION pos = pObjects->Find(pObj);
ASSERT(pos != NULL);
pObjects->RemoveAt(pos);
pObjects->AddHead(pObj);
InvalObj(pObj);
GetDocument()->UpdateAllViews(this);
}

void CDrawView::OnObjectMoveToFront()
{
CDrawDoc* pDoc = GetDocument();
CDrawObj* pObj = m_selection.GetHead();
CDrawObjList* pObjects = pDoc->GetObjects();
POSITION pos = pObjects->Find(pObj);
ASSERT(pos != NULL);
pObjects->RemoveAt(pos);
pObjects->AddTail(pObj);
InvalObj(pObj);
GetDocument()->UpdateAllViews(this);
}

void CDrawView::OnEditCopy()
{
ASSERT_VALID(this);
ASSERT(m_cfDraw != NULL);

// Create a shared file and associate a CArchive with it
CSharedFile file;
CArchive ar(&file, CArchive::store);

// Serialize selected objects to the archive
m_selection.Serialize(ar);
ar.Close();

COleDataSource* pDataSource = NULL;
TRY
{
pDataSource = new COleDataSource;
// put on local format instead of or in addation to
pDataSource->CacheGlobalData(m_cfDraw, file.Detach());

// if only one item and it is a COleClientItem then also
// paste in that format
// CDrawObj* pDrawObj = m_selection.GetHead();
/*if (m_selection.GetCount() == 1 &&
pDrawObj->IsKindOf(RUNTIME_CLASS(CDrawOleObj)))
{
CDrawOleObj* pDrawOle = (CDrawOleObj*)pDrawObj;
pDrawOle->m_pClientItem->GetClipboardData(pDataSource, FALSE);
}*/
pDataSource->SetClipboard();
}
CATCH_ALL(e)
{
delete pDataSource;
THROW_LAST();
}
END_CATCH_ALL
}

void CDrawView::OnUpdateEditCopy(CCmdUI* pCmdUI)
{
pCmdUI->Enable(!m_selection.IsEmpty());
}

void CDrawView::OnEditCut()
{
OnEditCopy();
OnEditClear();
}

void CDrawView::OnUpdateEditCut(CCmdUI* pCmdUI)
{
pCmdUI->Enable(!m_selection.IsEmpty());
}

void CDrawView::OnEditPaste()
{
COleDataObject dataObject;
dataObject.AttachClipboard();

// invalidate current selection since it will be deselected
OnUpdate(NULL, HINT_UPDATE_SELECTION, NULL);
m_selection.RemoveAll();
if (dataObject.IsDataAvailable(m_cfDraw))
{
PasteNative(dataObject);

// now add all items in m_selection to document
POSITION pos = m_selection.GetHeadPosition();
while (pos != NULL)
GetDocument()->Add(m_selection.GetNext(pos));
}
//else
// PasteEmbedded(dataObject, GetInitialPosition().TopLeft() );

GetDocument()->SetModifiedFlag();

// invalidate new pasted stuff
GetDocument()->UpdateAllViews(NULL, HINT_UPDATE_SELECTION, &m_selection);
}

void CDrawView::OnUpdateEditPaste(CCmdUI* pCmdUI)
{
// determine if private or standard OLE formats are on the clipboard
COleDataObject dataObject;
BOOL bEnable = dataObject.AttachClipboard() &&
(dataObject.IsDataAvailable(m_cfDraw) ||
COleClientItem::CanCreateFromData(&dataObject));

// enable command based on availability
pCmdUI->Enable(bEnable);
}

void CDrawView::OnFilePrint()
{
CView::OnFilePrint();

// GetDocument()->ComputePageSize();
}


void CDrawView::OnEditProperties()
{
if (m_selection.GetCount() == 1 && CDrawTool::c_drawShape == draw_selection)
{
CDrawTool* pTool = CDrawTool::FindTool(CDrawTool::c_drawShape);
ASSERT(pTool != NULL);
pTool->OnEditProperties(this);
}
}

void CDrawView::OnUpdateEditProperties(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_selection.GetCount() == 1 &&
CDrawTool::c_drawShape == draw_selection);
}

/////////////////////////////////////////////////////////////////////////////
// CDrawView diagnostics

#ifdef _DEBUG
void CDrawView::AssertValid() const
{
CView::AssertValid();
}

void CDrawView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// new
// support for drag/drop

int CDrawView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;

// register drop target
if( m_dropTarget.Register( this ) )
return 0;
else
return -1;
}

BOOL CDrawView::GetObjectInfo(COleDataObject* pDataObject,
CSize* pSize, CSize* pOffset)
{
ASSERT(pSize != NULL);

// get object descriptor data
HGLOBAL hObjDesc = pDataObject->GetGlobalData(m_cfObjectDescriptor);
if (hObjDesc == NULL)
{
if (pOffset != NULL)
*pOffset = CSize(0, 0); // fill in defaults instead
*pSize = CSize(0, 0);
return FALSE;
}
ASSERT(hObjDesc != NULL);

// otherwise, got CF_OBJECTDESCRIPTOR ok. Lock it down and extract size.
LPOBJECTDESCRIPTOR pObjDesc = (LPOBJECTDESCRIPTOR)GlobalLock(hObjDesc);
ASSERT(pObjDesc != NULL);
pSize->cx = (int)pObjDesc->sizel.cx;
pSize->cy = (int)pObjDesc->sizel.cy;
if (pOffset != NULL)
{
pOffset->cx = (int)pObjDesc->pointl.x;
pOffset->cy = (int)pObjDesc->pointl.y;
}
GlobalUnlock(hObjDesc);
GlobalFree(hObjDesc);

// successfully retrieved pSize & pOffset info
return TRUE;
}
/*
DROPEFFECT CDrawView::OnDragEnter(COleDataObject* pDataObject,
DWORD grfKeyState, CPoint point)
{
ASSERT(m_prevDropEffect == DROPEFFECT_NONE);
m_bDragDataAcceptable = FALSE;
if (!COleClientItem::CanCreateFromData(pDataObject))
return DROPEFFECT_NONE;

m_bDragDataAcceptable = TRUE;
GetObjectInfo(pDataObject, &m_dragSize, &m_dragOffset);
CClientDC dc(NULL);
dc.HIMETRICtoDP(&m_dragSize);
dc.HIMETRICtoDP(&m_dragOffset);

return OnDragOver(pDataObject, grfKeyState, point);
}

DROPEFFECT CDrawView::OnDragOver(COleDataObject*,
DWORD grfKeyState, CPoint point)
{
if(m_bDragDataAcceptable == FALSE)
return DROPEFFECT_NONE;

point -= m_dragOffset; // adjust target rect by original cursor offset

// check for point outside logical area -- i.e. in hatched region
// GetTotalSize() returns the size passed to SetScrollSizes
CRect rectScroll(CPoint(0, 0), GetTotalSize());

CRect rectItem(point,m_dragSize);
rectItem.OffsetRect(GetDeviceScrollPosition());

DROPEFFECT de = DROPEFFECT_NONE;
CRect rectTemp;
if (rectTemp.IntersectRect(rectScroll, rectItem))
{
// check for force link
#ifndef _MAC
if ((grfKeyState & (MK_CONTROL|MK_SHIFT)) == (MK_CONTROL|MK_SHIFT))
#else
if ((grfKeyState & (MK_OPTION|MK_SHIFT)) == (MK_OPTION|MK_SHIFT))
#endif
de = DROPEFFECT_NONE; // DRAWCLI isn't a linking container
// check for force copy
#ifndef _MAC
else if ((grfKeyState & MK_CONTROL) == MK_CONTROL)
#else
else if ((grfKeyState & MK_CONTROL) == MK_CONTROL)
#endif
de = DROPEFFECT_COPY;
// check for force move
else if ((grfKeyState & MK_ALT) == MK_ALT)
de = DROPEFFECT_MOVE;
// default -- recommended action is move
else
de = DROPEFFECT_MOVE;
}

if (point == m_dragPoint)
return de;

// otherwise, cursor has moved -- need to update the drag feedback
CClientDC dc(this);
if (m_prevDropEffect != DROPEFFECT_NONE)
{
// erase previous focus rect
dc.DrawFocusRect(CRect(m_dragPoint, m_dragSize));
}
m_prevDropEffect = de;
if (m_prevDropEffect != DROPEFFECT_NONE)
{
m_dragPoint = point;
dc.DrawFocusRect(CRect(point, m_dragSize));
}
return de;
}

BOOL CDrawView::OnDrop(COleDataObject* pDataObject,
DROPEFFECT dropEffect, CPoint point)
{
ASSERT_VALID(this);

// clean up focus rect
OnDragLeave();

// offset point as appropriate for dragging
GetObjectInfo(pDataObject, &m_dragSize, &m_dragOffset);
CClientDC dc(NULL);
dc.HIMETRICtoDP(&m_dragSize);
dc.HIMETRICtoDP(&m_dragOffset);
point -= m_dragOffset;

// invalidate current selection since it will be deselected
OnUpdate(NULL, HINT_UPDATE_SELECTION, NULL);
m_selection.RemoveAll();
if (m_bDragDataAcceptable)
PasteEmbedded(*pDataObject, point);

// update the document and views
GetDocument()->SetModifiedFlag();
GetDocument()->UpdateAllViews(NULL, 0, NULL); // including this view

return TRUE;
}
*/
void CDrawView::OnDragLeave()
{
CClientDC dc(this);
if (m_prevDropEffect != DROPEFFECT_NONE)
{
dc.DrawFocusRect(CRect(m_dragPoint,m_dragSize)); // erase previous focus rect
m_prevDropEffect = DROPEFFECT_NONE;
}
}


void CDrawView::OnContextMenu(CWnd* /*pWnd*/, CPoint point)
{
// make sure window is active
/* if (CDrawTool::c_drawShape!=draw_selection) return;
//if (CDrawTool::c_drawShape == draw_zoom) return;
//if (CDrawTool::c_drawShape==draw_pan) return;
GetParentFrame()->ActivateFrame();

CPoint local = point;
ScreenToClient(&local);

CDrawObj* pObj;
pObj = GetDocument()->ObjectAt(local,this);
if(pObj != NULL)// && pObj->m_nShape != CDrawObj::curve)
{
if(!IsSelected(pObj))
Select( pObj, FALSE ); // reselect item if appropriate
UpdateWindow();

CMenu menu;
if (menu.LoadMenu(ID_POPUP_MENU))
{
CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup != NULL);

pPopup->TrackPopupMenu(TPM_RIGHTBUTTON | TPM_LEFTALIGN,
point.x, point.y,
AfxGetMainWnd()); // route commands through main window
}
}
/*else if(pObj != NULL && pObj->m_nShape == CDrawObj::curve)
{
if(!IsSelected(pObj))
Select( pObj, FALSE ); // reselect item if appropriate
UpdateWindow();

CMenu menu;
if (menu.LoadMenu(ID_CURVE_POPUP_MENU))
{
CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup != NULL);

pPopup->TrackPopupMenu(TPM_RIGHTBUTTON | TPM_LEFTALIGN,
point.x, point.y,
AfxGetMainWnd()); // route commands through main window
}
}*/
}

void CDrawView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
#if !defined(_MAC)
// if (pInfo->m_bPreview == FALSE)
// ((CDrawDoc*)GetDocument())->m_pSummInfo->RecordPrintDate();
#endif
OnDraw(pDC);
}

void CDrawView::OnCombination()
{
if (m_selection.GetCount() == 1)
return;

CDRect rect,position;
rect.SetRectEmpty();
rect.NormalizeRect();
POSITION pos = m_selection.GetHeadPosition();
bool bFirst=true;
while (pos != NULL)
{
CDrawObj* pObj = m_selection.GetNext(pos);
position=pObj->m_position;
position.NormalizeRect();
if (bFirst) rect=position;
bFirst=false;
if(position.IsRectEmpty())
position.InflateRect(1,1,0,0);
rect.UnionRect(&position,&rect);
rect.NormalizeRect();
}
position.left=rect.right;
position.top=rect.top;
position.right=rect.left;
position.bottom=rect.bottom;
CDrawComb* pCombObj = new CDrawComb(position);
GetDocument()->Add(pCombObj);

pCombObj->m_pDocument = GetDocument();

CDrawObjList temp_selection;
{
CDrawDoc* pDoc = GetDocument();
CDrawObjList* pObjects = pDoc->GetObjects();
POSITION pos = pObjects->GetHeadPosition();
while (pos != NULL)
{
CDrawObj* pObj = pObjects->GetNext(pos);
if(m_selection.Find(pObj)!=NULL)
temp_selection.AddTail(pObj);
}
}

pos = temp_selection.GetHeadPosition();
while (pos != NULL)
{
CDrawObj* pObj = temp_selection.GetNext(pos);
pCombObj->m_combination.AddTail(pObj);
}
//OnEditClear();
pos = m_selection.GetHeadPosition();
while (pos != NULL)
{
CDrawObj* pObj = m_selection.GetNext(pos);
GetDocument()->Remove(pObj);
//pObj->Remove();
}
m_selection.RemoveAll();

pCombObj->m_nObjstate = obj_newcreate;

pos = pCombObj->m_combination.GetHeadPosition();
while (pos != NULL)
{
double a,b;
CDrawObj* pObj = pCombObj->m_combination.GetNext(pos);
pObj->m_groupNo=1;
if (pObj->m_nObjstate==obj_nochange)
pObj->m_nObjstate = obj_update;
a=fabs(pObj->m_position.bottom-position.top);//bottom
b= position.Height();
pObj->bottom_coeff=a/b;

a=fabs(pObj->m_position.top-position.top);//top
b= position.Height();
pObj->top_coeff=a/b;

a=fabs(pObj->m_position.right-position.left);//right
b= position.Width();
pObj->right_coeff=a/b;

a=fabs(pObj->m_position.left-position.left);//left
b= position.Width();
pObj->left_coeff=a/b;
}

GetDocument()->SetModifiedFlag();
Select(pCombObj);
}

void CDrawView::OnUndocomb()
{
if (m_selection.GetCount() != 1)
return;

CDrawObjList temp_selection;
BOOL add_flg=FALSE;
POSITION pos = m_selection.GetHeadPosition();
CDrawComb* pObj = (CDrawComb *)m_selection.GetNext(pos);
if (!(pObj->m_nShape == shp_comb))
return;

pos = pObj->m_combination.GetHeadPosition();
while (pos != NULL)
{
CDrawObj* subpObj = pObj->m_combination.GetNext(pos);
subpObj->top_coeff=0.0;
subpObj->bottom_coeff=1.0;
subpObj->left_coeff=0.0;
subpObj->right_coeff=1.0;
temp_selection.AddTail(subpObj);
GetDocument()->Add(subpObj);
subpObj->m_groupNo=-1;
if (subpObj->m_nObjstate==obj_nochange)
subpObj->m_nObjstate = obj_update;
}
pObj->m_combination.RemoveAll();
Delete(&m_selection,false);
//OnEditClear();

pos = temp_selection.GetHeadPosition();
while (pos != NULL)
{
CDrawObj* subpObj = temp_selection.GetNext(pos);
Select(subpObj,add_flg);
add_flg=TRUE;
}
}

void CDrawView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
if (!m_bActive)
return;
CDrawTool* pTool = CDrawTool::FindTool(CDrawTool::c_drawShape);
if (pTool != NULL)
pTool->OnChar(this, nChar, nRepCnt, nFlags);

//CScrollView::OnChar(nChar, nRepCnt, nFlags);
}

void CDrawView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
if (!m_bActive)
return;
CDrawTool* pTool = CDrawTool::FindTool(CDrawTool::c_drawShape);
if (pTool != NULL)
pTool->OnKeyDown(this, nChar, nRepCnt, nFlags);

//CScrollView::OnKeyDown(nChar, nRepCnt, nFlags);
}

void CDrawView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default

CDrawObjList* pObList = GetDocument()->GetObjects();
POSITION posObj = pObList->GetHeadPosition();
while (posObj != NULL)
{
CDrawObj* pObj = pObList->GetNext(posObj);
pObj->OnTimer(this,nIDEvent);

}
Invalidate();
}

void CDrawView::OnPetrif(UINT nID)
{
ASSERT(nID >= ID_PETRIF00 && nID <= ID_PETRIF32);

CDrawTool::c_drawShape = draw_petrif;
id=nID;
}

void CDrawView::OnDrawCurve()
{
CDrawTool::c_drawShape = draw_curve;
}

void CDrawView::OnUpdatePetrif(CCmdUI* pCmdUI)
{
UINT nID = pCmdUI->m_nID;
pCmdUI->SetRadio(CDrawTool::c_drawShape == draw_petrif && id==nID);
}

void CDrawView::OnUpdateDrawCurve(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(CDrawTool::c_drawShape == draw_curve);
}

void CDrawView::OnDrawZoom()
{
// TODO: Add your command handler code here
CDrawTool::c_drawShape = draw_zoom;

}

void CDrawView::OnUpdateDrawZoom(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetRadio(CDrawTool::c_drawShape == draw_zoom);

}

void CDrawView::OnDrawPan()
{
// TODO: Add your command handler code here
CDrawTool::c_drawShape = draw_pan;

}

void CDrawView::OnUpdateDrawPan(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetRadio(CDrawTool::c_drawShape == draw_pan);

}

void CDrawView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
CRect rect;
GetClientRect(&rect);

int width=rect.Width();
int xMin,xMax,yMin,yMax;
GetPicEdge(xMin,xMax,yMin,yMax);
//int iPos=GetScrollPos(SB_HORZ);
switch (nSBCode)
{
case SB_LEFT:// Scroll to far left.
// m_mapOx=m_mapOx+width;
break;
case SB_ENDSCROLL:// End scroll.
// m_mapOx=pDoc->m_pic.width/m_Scale-width;
break;
case SB_LINELEFT:// Scroll left.
m_mapOx=m_mapOx+width/10;
m_mapOx=min(m_mapOx,xMax);
//SetScrollPos(SB_HORZ,iPos-width/10,true);
break;
case SB_LINERIGHT:// Scroll right.
m_mapOx=m_mapOx-width/10;
m_mapOx=max(m_mapOx,xMin);
//SetScrollPos(SB_HORZ,iPos+width/10,true);
break;
case SB_PAGELEFT:// Scroll one page left.
m_mapOx=m_mapOx+width/2;
m_mapOx=min(m_mapOx,xMax);
break;
case SB_PAGERIGHT:// Scroll one page right.
m_mapOx=m_mapOx-width/2;
m_mapOx=max(m_mapOx,xMin);
break;
case SB_RIGHT:// Scroll to far right.
m_mapOx=m_mapOx-width;
m_mapOx=max(m_mapOx,xMin);
break;
case SB_THUMBPOSITION:// Scroll to absolute position. The current position is specified by the nPos parameter.
break;
case SB_THUMBTRACK:// Drag scroll box to specified position. The current position is specified by the nPos parameter.
break;
}

UpdateActiveItem();
Invalidate();

CView::OnHScroll(nSBCode, nPos, pScrollBar);
}

void CDrawView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
CRect rect;
GetClientRect(&rect);

int height=rect.Height();
int xMin,xMax,yMin,yMax;
GetPicEdge(xMin,xMax,yMin,yMax);
switch (nSBCode)
{
case SB_BOTTOM:// Scroll to bottom.
break;
case SB_ENDSCROLL:// End scroll.
break;
case SB_LINEDOWN:// Scroll one line down.
m_mapOy=m_mapOy-height/10;
m_mapOy=max(m_mapOy,yMin);
//SetScrollPos(SB_VERT,iPos+height/10,true);
break;
case SB_LINEUP:// Scroll one line up.
m_mapOy=m_mapOy+height/10;
m_mapOy=min(m_mapOy,yMax);
//SetScrollPos(SB_VERT,iPos-height/10,true);
break;
case SB_PAGEDOWN:// Scroll one page down.
case SB_PAGEUP:// Scroll one page up.
case SB_THUMBPOSITION:// Scroll to the absolute position. The current position is provided in nPos.
case SB_THUMBTRACK:// Drag scroll box to specified position. The current position is provided in nPos.
case SB_TOP:// Scroll to top.
break;
}

UpdateActiveItem();
Invalidate();
SetScroller();

CView::OnVScroll(nSBCode, nPos, pScrollBar);
}

void CDrawView::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if (!m_bActive)
return;
CDrawTool* pTool = CDrawTool::FindTool(CDrawTool::c_drawShape);
if (pTool != NULL)
pTool->OnRButtonDown(this, nFlags, point);
CView::OnRButtonDown(nFlags, point);
}



void CDrawView::GetPicEdge(int& xMin,int& xMax,int& yMin,int& yMax)
{
CRect rect;
GetClientRect(&rect);
int clientW=(int)(GetDocument()->m_pic.width/m_Scale);
int clientH=(int)(GetDocument()->m_pic.height/m_Scale);

if (clientW<=rect.Width())
{
xMax=rect.Width()-clientW;
xMin=0;
}
else
{
xMax=10;
xMin=rect.Width()-clientW-10;
}
if (clientH<=rect.Height())
{
yMax=rect.Height();
yMin=clientH;
}
else
{
yMin=rect.Height()-10;
yMax=clientH+10;
}
xMax=max(xMax,m_mapOx_INI);
yMin=min(yMin,m_mapOy_INI);
}


void CDrawView::SetScroller()
{
int xMin,xMax,yMin,yMax;
GetPicEdge(xMin,xMax,yMin,yMax);

SetScrollRange(SB_HORZ,0,xMax-xMin);
SetScrollRange(SB_VERT,0,yMax-yMin);

SetScrollPos(SB_HORZ,xMax-m_mapOx,true);
SetScrollPos(SB_VERT,yMax-m_mapOy,true);
}

void CDrawView::OnTurnX()
{
// TODO: Add your command handler code here
CDrawTool::OnTurn_X(this);
}

void CDrawView::OnUpdateTurnX(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(!m_selection.IsEmpty());
}

void CDrawView::OnTurnY()
{
// TODO: Add your command handler code here
CDrawTool::OnTurn_Y(this);
}

void CDrawView::OnUpdateTurnY(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(!m_selection.IsEmpty());
}

void CDrawView::OnTestReal()
{
// TODO: Add your command handler code here
m_bShowReal = !m_bShowReal;
Invalidate(FALSE);
}
void CDrawView::OnUpdateTestReal(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_bShowReal);
}

[说明] 本文件所在目录应该包含如下文件: icrEdit\ - 目录,icrEdit编辑器的源码 演示例程\ - 目录,演示CSynEditView使用方法的例程 语法编辑类\ - 目录,CSynEditView的头文件和实现文件 使用说明.txt - 本文件,说明书 riched20.dll - CSynEditView必须的支持文件,请留意其版本号5.30.23.1209,文件大小:431888 (如果看不到文件riched20.dll,请在文件夹选项对话框的查看TAB中将隐藏文件和文件夹选为 显示文件和文件夹) [简介] CSynEditView一个支持语法编辑的类,你只要简单的将该类引入你的工程,便可轻松的获得如VC++和VB编程环境中的语法编辑能力。 [使用方法] 1、新建一个工程,在第六步将视类的基类改为CRichEditView。 2、在VC环境中选 Project->Add to Project->Files,将SynEditView.h和SynEditView.cpp引入工程。 3、将你的视类中的CRichEditView字符串全部改为CSynEditView,在你的视类头文件中用#include引入SynEditView.h文件。 4、按F7编译该工程,然后将riched20.dll复制到可执行文件的同一目录下。也就是说,如果你用Debug模式编译,将riched20.dll复制到Debug\目录下,如果你用Release模式编译,将riched20.dll复制到Release\目录下。 5、按F6执行。 [注意] 1、为了使程序能正常执行,必须保证riched20.dll同执行文件在同一目录。 2、CSynEditViw暂不支持中文,如果文本中含有中文字符,可能会引起乱码,请自行更改代码。

16,467

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧