projView.cpp
上传用户:ywlong9188
上传日期:2022-05-31
资源大小:2656k
文件大小:33k
源码类别:

远程控制编程

开发平台:

C/C++

  1. // ProjView.cpp : implementation of the CProjView class
  2. //
  3. #include "stdafx.h"
  4. #include <afxpriv.h>
  5. #include "Proj.h"
  6. #include "ProjDoc.h"
  7. #include "drawobj.h"
  8. #include "splitdlg.h"
  9. #include "ProjView.h"
  10. #include "drawobj.h"
  11. #include "drawtool.h"
  12. #include "palettebar.h"
  13. #include "mainfrm.h"
  14. #ifdef _DEBUG
  15. #define new DEBUG_NEW
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19. /////////////////////////////////////////////////////////////////////////////
  20. // CProjView
  21. IMPLEMENT_DYNCREATE(CProjView, CScrollView)
  22. BEGIN_MESSAGE_MAP(CProjView, CScrollView)
  23. //{{AFX_MSG_MAP(CProjView)
  24. ON_WM_LBUTTONDOWN()
  25. ON_WM_LBUTTONDBLCLK()
  26. ON_WM_LBUTTONUP()
  27. ON_WM_MOUSEMOVE()
  28. ON_WM_CONTEXTMENU()
  29. ON_COMMAND(ID_VIEW_GRID, OnViewGrid)
  30. ON_COMMAND(ID_CANCEL_EDIT, OnCancelEdit)
  31. ON_UPDATE_COMMAND_UI(ID_VIEW_GRID, OnUpdateViewGrid)
  32. ON_COMMAND(ID_OBJECT_MOVETOFRONT, OnObjectMovetofront)
  33. ON_UPDATE_COMMAND_UI(ID_OBJECT_MOVETOFRONT, OnUpdateObjectMovetofront)
  34. ON_COMMAND(ID_OBJECT_MOVETOBACK, OnObjectMovetoback)
  35. ON_UPDATE_COMMAND_UI(ID_OBJECT_MOVETOBACK, OnUpdateObjectMovetoback)
  36. ON_COMMAND(ID_OBJECT_MOVEFORWARD, OnObjectMoveforward)
  37. ON_UPDATE_COMMAND_UI(ID_OBJECT_MOVEFORWARD, OnUpdateObjectMoveforward)
  38. ON_COMMAND(ID_OBJECT_LINECOLOR, OnObjectLinecolor)
  39. ON_UPDATE_COMMAND_UI(ID_OBJECT_LINECOLOR, OnUpdateObjectLinecolor)
  40. ON_COMMAND(ID_OBJECT_FILL_COLOR, OnObjectFillColor)
  41. ON_UPDATE_COMMAND_UI(ID_OBJECT_FILL_COLOR, OnUpdateObjectFillColor)
  42. ON_COMMAND(ID_EDIT_SELECT_ALL, OnEditSelectAll)
  43. ON_COMMAND(ID_EDIT_CLEAR, OnEditClear)
  44. ON_UPDATE_COMMAND_UI(ID_EDIT_CLEAR, OnUpdateAnySelect)
  45. ON_UPDATE_COMMAND_UI(ID_EDIT_SELECT_ALL, OnUpdateEditSelectAll)
  46. ON_COMMAND(ID_EDIT_PROPERTIES, OnEditProperties)
  47. ON_UPDATE_COMMAND_UI(ID_EDIT_PROPERTIES, OnUpdateEditProperties)
  48. ON_COMMAND(ID_EDIT_PASTE, OnEditPaste)
  49. ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, OnUpdateEditPaste)
  50. ON_COMMAND(ID_EDIT_CUT, OnEditCut)
  51. ON_UPDATE_COMMAND_UI(ID_EDIT_CUT, OnUpdateEditCut)
  52. ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
  53. ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, OnUpdateEditCopy)
  54. ON_COMMAND(ID_DRAW_SELECTION, OnDrawSelection)
  55. ON_UPDATE_COMMAND_UI(ID_DRAW_SELECTION, OnUpdateDrawSelection)
  56. ON_COMMAND(ID_DRAW_RECT, OnDrawRect)
  57. ON_UPDATE_COMMAND_UI(ID_DRAW_RECT, OnUpdateDrawRect)
  58. ON_COMMAND(ID_DRAW_POLYGON, OnDrawPolygon)
  59. ON_UPDATE_COMMAND_UI(ID_DRAW_POLYGON, OnUpdateDrawPolygon)
  60. ON_COMMAND(ID_DRAW_LINE, OnDrawLine)
  61. ON_UPDATE_COMMAND_UI(ID_DRAW_LINE, OnUpdateDrawLine)
  62. ON_COMMAND(ID_DRAW_ELLIPSE, OnDrawEllipse)
  63. ON_UPDATE_COMMAND_UI(ID_DRAW_ELLIPSE, OnUpdateDrawEllipse)
  64. ON_COMMAND(ID_OBJECT_MOVEBACK, OnObjectMoveback)
  65. ON_UPDATE_COMMAND_UI(ID_OBJECT_MOVEBACK, OnUpdateObjectMoveback)
  66. ON_WM_ERASEBKGND()
  67. ON_WM_SIZE()
  68. ON_COMMAND(ID_DRAW_TEXT, OnDrawText)
  69. ON_UPDATE_COMMAND_UI(ID_DRAW_TEXT, OnUpdateDrawText)
  70. ON_COMMAND(ID_DRAW_BAR_GRAPH, OnDrawBarGraph)
  71. ON_UPDATE_COMMAND_UI(ID_DRAW_BAR_GRAPH, OnUpdateDrawBarGraph)
  72. ON_COMMAND(ID_DRAW_CLOCK, OnDrawClock)
  73. ON_UPDATE_COMMAND_UI(ID_DRAW_CLOCK, OnUpdateDrawClock)
  74. ON_WM_TIMER()
  75. ON_WM_CREATE()
  76. ON_COMMAND(ID_DRAW_ANIMATE_TAG, OnDrawAnimateTag)
  77. ON_UPDATE_COMMAND_UI(ID_DRAW_ANIMATE_TAG, OnUpdateDrawAnimateTag)
  78. ON_UPDATE_COMMAND_UI(ID_DRAW_CURSOR, OnUpdateDrawCursor)
  79. ON_COMMAND(ID_DRAW_CURSOR, OnDrawCursor)
  80. ON_COMMAND(ID_RUN_RUN, OnRunRun)
  81. ON_UPDATE_COMMAND_UI(ID_RUN_RUN, OnUpdateRunRun)
  82. ON_COMMAND(ID_RUN_STOP, OnRunStop)
  83. ON_UPDATE_COMMAND_UI(ID_RUN_STOP, OnUpdateRunStop)
  84. ON_WM_SETCURSOR()
  85. ON_WM_RBUTTONDOWN()
  86. ON_COMMAND(ID_DRAW_ISA, OnDrawIsa)
  87. ON_UPDATE_COMMAND_UI(ID_DRAW_ISA, OnUpdateDrawIsa)
  88. ON_COMMAND(ID_DRAW_LOOP, OnDrawLoop)
  89. ON_UPDATE_COMMAND_UI(ID_DRAW_LOOP, OnUpdateDrawLoop)
  90. ON_COMMAND(ID_OBJECT_MERGE, OnObjectMerge)
  91. ON_UPDATE_COMMAND_UI(ID_OBJECT_MERGE, OnUpdateObjectMerge)
  92. ON_COMMAND(ID_OBJECT_LIB, OnObjectLib)
  93. ON_UPDATE_COMMAND_UI(ID_OBJECT_LIB, OnUpdateObjectLib)
  94. ON_COMMAND(ID_DRAW_LIB, OnDrawLib)
  95. ON_UPDATE_COMMAND_UI(ID_DRAW_LIB, OnUpdateDrawLib)
  96. ON_WM_CHAR()
  97. ON_WM_KEYDOWN()
  98. ON_COMMAND(ID_OBJECT_SPLIT, OnObjectSplit)
  99. ON_UPDATE_COMMAND_UI(ID_OBJECT_SPLIT, OnUpdateObjectSplit)
  100. ON_COMMAND(ID_EDIT_CLEAR, OnEditClear)
  101. ON_COMMAND(ID_DRAW_BUTTON, OnDrawButton)
  102. ON_UPDATE_COMMAND_UI(ID_DRAW_BUTTON, OnUpdateDrawButton)
  103. //}}AFX_MSG_MAP
  104. ON_COMMAND(ID_EDIT_ROTATE, OnEditRotate)
  105. ON_UPDATE_COMMAND_UI(ID_EDIT_ROTATE, OnUpdateEditRotate)
  106. ON_COMMAND_RANGE(ID_EDIT_LEFT,ID_EDIT_BOTTOM,OnAlign)
  107. ON_UPDATE_COMMAND_UI_RANGE(ID_EDIT_LEFT,ID_EDIT_BOTTOM,OnUpdateAlign)
  108. END_MESSAGE_MAP()
  109. /////////////////////////////////////////////////////////////////////////////
  110. // CProjView construction/destruction
  111. CProjView::CProjView() :m_tracker(CRect(0,0,10,10),CRectTracker::solidLine|CRectTracker::resizeInside)
  112. //,CScrollView(CProjView::IDD)
  113. {
  114. m_bGrid = FALSE;
  115. m_gridColor = RGB(0, 0, 128);
  116. m_bActive = FALSE;
  117. nTemp = 0;
  118. m_bRun = FALSE;
  119. m_bCursor = FALSE;
  120. }
  121. CProjView::~CProjView()
  122. {
  123. while( m_backup.GetHeadPosition() != NULL )
  124. delete m_backup.RemoveHead();
  125. }
  126. BOOL CProjView::PreCreateWindow(CREATESTRUCT& cs)
  127. {
  128. ASSERT(cs.style & WS_CHILD);
  129. if (cs.lpszClass == NULL)
  130. cs.lpszClass = AfxRegisterWndClass(CS_DBLCLKS);
  131. return TRUE;
  132. }
  133. /////////////////////////////////////////////////////////////////////////////
  134. // CProjView drawing
  135. void CProjView::OnDraw(CDC* pDC)
  136. {
  137. CProjDoc* pDoc = GetDocument();
  138. ASSERT_VALID(pDoc);
  139. CDC dc;
  140. CDC* pDrawDC = pDC;
  141. CBitmap bitmap;
  142. CBitmap* pOldBitmap;
  143. // only paint the rect that needs repainting
  144. CRect client;
  145. pDC->GetClipBox(client);
  146. CRect rect = client;
  147. DocToClient(rect);
  148. // draw to offscreen bitmap for fast looking repaints
  149. if (dc.CreateCompatibleDC(pDC))
  150. {
  151. if (bitmap.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height()))
  152. {
  153. OnPrepareDC(&dc, NULL);
  154. pDrawDC = &dc;
  155. // offset origin more because bitmap is just piece of the whole drawing
  156. dc.OffsetViewportOrg(-rect.left, -rect.top);
  157. pOldBitmap = dc.SelectObject(&bitmap);
  158. dc.SetBrushOrg(rect.left % 8, rect.top % 8);
  159. // might as well clip to the same rectangle
  160. dc.IntersectClipRect(client);
  161. }
  162. }
  163. // paint background
  164. CBrush brush;
  165. if (!brush.CreateSolidBrush(pDoc->GetPaperColor()))
  166. return;
  167. brush.UnrealizeObject();
  168. pDrawDC->FillRect(client, &brush);
  169. pDoc->Draw(pDrawDC, this);
  170. if (!pDC->IsPrinting() && m_bGrid)
  171. DrawGrid(pDrawDC);
  172. if (pDrawDC != pDC)
  173. {
  174. pDC->SetViewportOrg(0, 0);
  175. pDC->SetWindowOrg(0,0);
  176. pDC->SetMapMode(MM_TEXT);
  177. dc.SetViewportOrg(0, 0);
  178. dc.SetWindowOrg(0,0);
  179. dc.SetMapMode(MM_TEXT);
  180. pDC->BitBlt(rect.left, rect.top, rect.Width(), rect.Height(),
  181. &dc, 0, 0, SRCCOPY);
  182. dc.SelectObject(pOldBitmap);
  183. bitmap.DeleteObject();
  184. brush.DeleteObject();
  185. }
  186. }
  187. void CProjView::OnInitialUpdate()
  188. {
  189. CSize size = GetDocument()->GetSize();
  190. CClientDC dc(NULL);
  191. size.cx = MulDiv(size.cx, dc.GetDeviceCaps(LOGPIXELSX), 100);
  192. size.cy = MulDiv(size.cy, dc.GetDeviceCaps(LOGPIXELSY), 100);
  193. SetScrollSizes(MM_TEXT, size);
  194. m_selection.RemoveAll();
  195. OnUpdate(NULL,HINT_UPDATE_WINDOW,NULL);
  196. }
  197. /////////////////////////////////////////////////////////////////////////////
  198. // CProjView diagnostics
  199. #ifdef _DEBUG
  200. void CProjView::AssertValid() const
  201. {
  202. CScrollView::AssertValid();
  203. }
  204. void CProjView::Dump(CDumpContext& dc) const
  205. {
  206. CScrollView::Dump(dc);
  207. }
  208. CProjDoc* CProjView::GetDocument() // non-debug version is inline
  209. {
  210. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CProjDoc)));
  211. return (CProjDoc*)m_pDocument;
  212. }
  213. #endif //_DEBUG
  214. /////////////////////////////////////////////////////////////////////////////
  215. // CProjView message handlers
  216. void CProjView::OnLButtonDown(UINT nFlags, CPoint point) 
  217. {
  218. if (!m_bActive)
  219. return;
  220. CDrawTool* pTool = CDrawTool::FindTool(CDrawTool::c_drawShape);
  221. if (pTool != NULL)
  222. pTool->OnLButtonDown(this, nFlags, point);
  223. }
  224. void CProjView::OnLButtonDblClk(UINT nFlags, CPoint point) 
  225. {
  226. if (!m_bActive)
  227. return;
  228. CDrawTool* pTool = CDrawTool::FindTool(CDrawTool::c_drawShape);
  229. if (pTool != NULL)
  230. pTool->OnLButtonDblClk(this, nFlags, point);
  231. }
  232. void CProjView::OnLButtonUp(UINT nFlags, CPoint point) 
  233. {
  234. if (!m_bActive)
  235. return;
  236. CDrawTool* pTool = CDrawTool::FindTool(CDrawTool::c_drawShape);
  237. if (pTool != NULL)
  238. pTool->OnLButtonUp(this, nFlags, point);
  239. }
  240. void CProjView::OnMouseMove(UINT nFlags, CPoint point) 
  241. {
  242. if (!m_bActive)
  243. return;
  244. CDrawTool* pTool = CDrawTool::FindTool(CDrawTool::c_drawShape);
  245. if (pTool != NULL)
  246. pTool->OnMouseMove(this, nFlags, point);
  247.     CPoint temp = point;
  248. ClientToDoc(temp);
  249. CPoint tempPoint ;
  250. tempPoint.x = temp.x;
  251. tempPoint.y = -temp.y;
  252. char text[100];
  253. CStatusBar* pStatus = (CStatusBar* )AfxGetApp()->m_pMainWnd->
  254. GetDescendantWindow(AFX_IDW_STATUS_BAR);
  255. wsprintf(text,"x = %d",tempPoint.x);
  256. pStatus->SetPaneText(0,text);
  257. wsprintf(text,"y = %d",tempPoint.y);
  258. pStatus->SetPaneText(1,text);
  259. /* CClientDC dc(this);
  260. int old = dc.SetROP2(R2_NOT);
  261. CRect rc;
  262. GetClientRect(rc);
  263. dc.MoveTo(m_prePoint.x,rc.top);
  264. dc.LineTo(m_prePoint.x,rc.bottom);
  265. dc.MoveTo(rc.left,m_prePoint.y);
  266. dc.LineTo(rc.right,m_prePoint.y);
  267. dc.MoveTo(point.x,rc.top);
  268. dc.LineTo(point.x,rc.bottom);
  269. dc.MoveTo(rc.left,point.y);
  270. dc.LineTo(rc.right,point.y);
  271. dc.SetROP2(old);
  272. m_prePoint = point;*/
  273. }
  274. void CProjView::OnContextMenu(CWnd* pWnd, CPoint point) 
  275. {
  276. GetParentFrame()->ActivateFrame();
  277. CPoint local = point;
  278. ScreenToClient(&local);
  279. ClientToDoc(local);
  280. CDrawObj* pObj;
  281. pObj = GetDocument()->ObjectAt(local);
  282. if(pObj != NULL)
  283. {
  284.     if(!IsSelected(pObj))
  285. Select( pObj, FALSE ); // reselect item if appropriate
  286. UpdateWindow();
  287. CMenu menu;
  288. if (menu.LoadMenu(ID_POPUP_MENU))
  289. {
  290. CMenu* pPopup = menu.GetSubMenu(0);
  291. ASSERT(pPopup != NULL);
  292. pPopup->TrackPopupMenu(TPM_RIGHTBUTTON | TPM_LEFTALIGN,
  293.    point.x, point.y,
  294.    AfxGetMainWnd()); // route commands through main window
  295. }
  296. }
  297. }
  298. void CProjView::OnViewGrid() 
  299. {
  300. m_bGrid = !m_bGrid;
  301. Invalidate(FALSE);
  302. }
  303. void CProjView::OnUpdateViewGrid(CCmdUI* pCmdUI) 
  304. {
  305. pCmdUI->SetCheck(m_bGrid);
  306. }
  307. void CProjView::OnObjectMovetofront() 
  308. {
  309. CProjDoc* pDoc = GetDocument();
  310. CDrawObj* pObj = m_selection.GetHead();
  311. CDrawObjList* pObjects = pDoc->GetObjects();
  312. POSITION pos = pObjects->Find(pObj);
  313. ASSERT(pos != NULL);
  314. pObjects->RemoveAt(pos);
  315. pObjects->AddTail(pObj);
  316. InvalObj(pObj);
  317. }
  318. void CProjView::OnUpdateObjectMovetofront(CCmdUI* pCmdUI) 
  319. {
  320. pCmdUI -> Enable(!m_selection.IsEmpty());
  321. }
  322. void CProjView::OnObjectMovetoback() 
  323. {
  324. CProjDoc* pDoc = GetDocument();
  325. CDrawObj* pObj = m_selection.GetHead();
  326. CDrawObjList* pObjects = pDoc->GetObjects();
  327. POSITION pos = pObjects->Find(pObj);
  328. ASSERT(pos != NULL);
  329. pObjects->RemoveAt(pos);
  330. pObjects->AddHead(pObj);
  331. InvalObj(pObj);
  332. }
  333. void CProjView::OnUpdateObjectMovetoback(CCmdUI* pCmdUI) 
  334. {
  335. pCmdUI -> Enable(!m_selection.IsEmpty());
  336. }
  337. void CProjView::OnObjectMoveforward() 
  338. {
  339. CProjDoc* pDoc = GetDocument();
  340. if(m_selection.IsEmpty())
  341. return;
  342. CDrawObj* pObj = m_selection.GetHead();
  343. CDrawObjList* pObjects = pDoc->GetObjects();
  344. POSITION pos = pObjects->Find(pObj);
  345. ASSERT(pos != NULL);
  346. if (pos != pObjects->GetTailPosition())
  347. {
  348. POSITION posNext = pos;
  349. pObjects->GetNext(posNext);
  350. pObjects->RemoveAt(pos);
  351. pObjects->InsertAfter(posNext, pObj);
  352. InvalObj(pObj);
  353. }
  354. }
  355. void CProjView::OnUpdateObjectMoveforward(CCmdUI* pCmdUI) 
  356. {
  357. pCmdUI -> Enable(!m_selection.IsEmpty());
  358. }
  359. void CProjView::OnObjectLinecolor() 
  360. {
  361. CColorDialog dlg;
  362. if (dlg.DoModal() != IDOK)
  363. return;
  364. COLORREF color = dlg.GetColor();
  365. POSITION pos = m_selection.GetHeadPosition();
  366. while (pos != NULL)
  367. {
  368. CDrawObj* pObj = m_selection.GetNext(pos);
  369. pObj->SetLineColor(color);
  370. }
  371. }
  372. void CProjView::OnUpdateObjectLinecolor(CCmdUI* pCmdUI) 
  373. {
  374. // TODO: Add your command update UI handler code here
  375. }
  376. void CProjView::OnObjectFillColor() 
  377. {
  378. CColorDialog dlg;
  379. if (dlg.DoModal() != IDOK)
  380. return;
  381. COLORREF color = dlg.GetColor();
  382. POSITION pos = m_selection.GetHeadPosition();
  383. while (pos != NULL)
  384. {
  385. CDrawObj* pObj = m_selection.GetNext(pos);
  386. pObj->SetFillColor(color);
  387. }
  388. }
  389. void CProjView::OnUpdateObjectFillColor(CCmdUI* pCmdUI) 
  390. {
  391. // TODO: Add your command update UI handler code here
  392. }
  393. void CProjView::OnEditSelectAll() 
  394. {
  395. CDrawObjList* pObList = GetDocument()->GetObjects();
  396. POSITION pos = pObList->GetHeadPosition();
  397. while (pos != NULL)
  398. Select(pObList->GetNext(pos), TRUE);
  399. }
  400. void CProjView::OnEditProperties() 
  401. if (m_selection.GetCount() == 1 && CDrawTool::c_drawShape == selection)
  402. {
  403. CDrawTool* pTool = CDrawTool::FindTool(CDrawTool::c_drawShape);
  404. ASSERT(pTool != NULL);
  405. pTool->OnEditProperties(this);
  406. }
  407. }
  408. void CProjView::OnUpdateEditProperties(CCmdUI* pCmdUI) 
  409. {
  410. pCmdUI->Enable(m_selection.GetCount() == 1 &&
  411.    CDrawTool::c_drawShape == selection);
  412. }
  413. void CProjView::OnEditPaste() 
  414. {
  415. POSITION pos = m_backup.GetHeadPosition();
  416. while( pos != NULL ){
  417. CDrawObj* pTemp = m_backup.GetNext(pos);
  418. //pTemp = pTemp->Clone( NULL);
  419. pTemp = pTemp->Clone(GetDocument());
  420. CRect rect = pTemp->m_position;
  421. rect.OffsetRect(30,-30);
  422. pTemp->MoveTo(rect,this);
  423. // pTemp->m_position.OffsetRect(30,-30);
  424. // pTemp->ReConsist();
  425. // GetDocument()->Add( pTemp );
  426. //pTemp->ReConsist();
  427. //Select( pTemp ,TRUE);
  428. }
  429. GetDocument()->SetModifiedFlag();
  430. Invalidate();
  431.  }
  432. void CProjView::OnUpdateEditPaste(CCmdUI* pCmdUI) 
  433. {
  434. pCmdUI->Enable(!m_backup.IsEmpty());
  435. }
  436. void CProjView::OnEditCut() 
  437. {
  438. OnEditCopy();
  439. OnEditClear();
  440. }
  441. void CProjView::OnUpdateEditCut(CCmdUI* pCmdUI) 
  442. {
  443. pCmdUI->Enable(!m_selection.IsEmpty());
  444. }
  445. void CProjView::OnEditCopy() 
  446. {
  447. if(!m_backup.IsEmpty())
  448. {
  449. while(  m_backup.GetHeadPosition() != NULL )
  450. delete m_backup.RemoveHead();
  451. }
  452. POSITION pos = m_selection.GetHeadPosition();
  453. while (pos != NULL)
  454. {
  455. CDrawObj* pObj = m_selection.GetNext(pos);
  456. CDrawObj* pTemp = pObj->Clone( NULL );
  457. m_backup.AddTail( pTemp );
  458. }
  459. }
  460. void CProjView::OnUpdateEditCopy(CCmdUI* pCmdUI) 
  461. {
  462. pCmdUI->Enable(!m_selection.IsEmpty());
  463. }
  464. void CProjView::OnDrawSelection() 
  465. {
  466. CDrawTool::c_drawShape = selection;
  467. }
  468. void CProjView::OnUpdateDrawSelection(CCmdUI* pCmdUI) 
  469. {
  470. pCmdUI->SetRadio(CDrawTool::c_drawShape == selection);
  471. }
  472. void CProjView::OnDrawRect() 
  473. {
  474. CDrawTool::c_drawShape = rect;
  475. }
  476. void CProjView::OnUpdateDrawRect(CCmdUI* pCmdUI) 
  477. {
  478. pCmdUI->SetRadio(CDrawTool::c_drawShape == rect);
  479. }
  480. void CProjView::OnDrawPolygon() 
  481. {
  482. // TODO: Add your command handler code here
  483. CDrawTool::c_drawShape = poly;
  484. }
  485. void CProjView::OnUpdateDrawPolygon(CCmdUI* pCmdUI) 
  486. {
  487. pCmdUI->SetRadio(CDrawTool::c_drawShape == poly);
  488. }
  489. void CProjView::OnDrawLine() 
  490. {
  491. CDrawTool::c_drawShape = line;
  492. }
  493. void CProjView::OnUpdateDrawLine(CCmdUI* pCmdUI) 
  494. {
  495. pCmdUI->SetRadio(CDrawTool::c_drawShape == line);
  496. }
  497. void CProjView::OnDrawEllipse() 
  498. {
  499.     CDrawTool::c_drawShape = ellipse;
  500. }
  501. void CProjView::OnUpdateDrawEllipse(CCmdUI* pCmdUI) 
  502. {
  503. pCmdUI->SetRadio(CDrawTool::c_drawShape == ellipse);
  504. }
  505. void CProjView::OnObjectMoveback() 
  506. {
  507. CProjDoc* pDoc = GetDocument();
  508. CDrawObj* pObj = m_selection.GetHead();
  509. CDrawObjList* pObjects = pDoc->GetObjects();
  510. POSITION pos = pObjects->Find(pObj);
  511. ASSERT(pos != NULL);
  512. if (pos != pObjects->GetHeadPosition())
  513. {
  514. POSITION posPrev = pos;
  515. pObjects->GetPrev(posPrev);
  516. pObjects->RemoveAt(pos);
  517. pObjects->InsertBefore(posPrev, pObj);
  518. InvalObj(pObj);
  519. }
  520. }
  521. void CProjView::OnUpdateObjectMoveback(CCmdUI* pCmdUI) 
  522. {
  523. pCmdUI->Enable(m_selection.GetCount() == 1);
  524. }
  525. BOOL CProjView::OnEraseBkgnd(CDC* pDC) 
  526. {
  527. CProjDoc* pDoc = GetDocument();
  528. CBrush brush;
  529. CRect rect;
  530. GetClientRect(rect);
  531. if (!brush.CreateSolidBrush(pDoc->GetPaperColor()))
  532. return TRUE;
  533. brush.UnrealizeObject();
  534. pDC->FillRect(rect,&brush);
  535. return FALSE;
  536. }
  537. void CProjView::OnSize(UINT nType, int cx, int cy) 
  538. {
  539. CScrollView::OnSize(nType, cx, cy);
  540. }
  541. void CProjView::OnUpdateEditSelectAll(CCmdUI* pCmdUI)
  542. {
  543. pCmdUI->Enable(GetDocument()->GetObjects()->GetCount() != 0);
  544. }
  545. void CProjView::OnEditClear()
  546. {
  547. // update all the views before the selection goes away
  548. //GetDocument()->UpdateAllViews(NULL, HINT_DELETE_SELECTION, &m_selection); // Comment the two lines for test;
  549.     //OnUpdate(NULL, HINT_UPDATE_SELECTION, NULL);
  550. // now remove the selection from the document
  551. POSITION pos = m_selection.GetHeadPosition();
  552. while (pos != NULL)
  553. {
  554. CDrawObj* pObj = m_selection.GetNext(pos);
  555. GetDocument()->Remove(pObj);
  556. pObj->Remove();
  557. }
  558. m_selection.RemoveAll();
  559. Invalidate();// Add this line for test!
  560. }
  561. BOOL CProjView::IsSelected(const CObject* pDocItem) const
  562. {
  563. CDrawObj* pDrawObj = (CDrawObj*)pDocItem;
  564. return m_selection.Find(pDrawObj) != NULL;
  565. }
  566. void CProjView::CloneSelection()
  567. {
  568. POSITION pos = m_selection.GetHeadPosition();
  569. while (pos != NULL)
  570. {
  571. CDrawObj* pObj = m_selection.GetNext(pos);
  572. pObj->Clone(pObj->m_pDocument);
  573. // copies object and adds it to the document
  574. }
  575. }
  576. void CProjView::Deselect(CDrawObj* pObj)
  577. {
  578. POSITION pos = m_selection.Find(pObj);
  579. if (pos != NULL)
  580. {
  581. InvalObj(pObj);
  582. m_selection.RemoveAt(pos);
  583. }
  584. }
  585. void CProjView::SelectWithinRect(CRect rect, BOOL bAdd)
  586. {
  587. if (!bAdd)
  588. Select(NULL);
  589. ClientToDoc(rect);
  590. CDrawObjList* pObList = GetDocument()->GetObjects();
  591. POSITION posObj = pObList->GetHeadPosition();
  592. while (posObj != NULL)
  593. {
  594. CDrawObj* pObj = pObList->GetNext(posObj);
  595. if( pObj != NULL )
  596. if (pObj->Intersects(rect))
  597. Select(pObj, TRUE);
  598. }
  599. }
  600. CRect CProjView::GetInitialPosition()
  601. {
  602. CRect rect(10, 10, 10, 10);
  603. ClientToDoc(rect);
  604. return rect;
  605. }
  606. void CProjView::ClientToDoc(CPoint& point)
  607. {
  608. CClientDC dc(this);
  609. OnPrepareDC(&dc, NULL);
  610. dc.DPtoLP(&point);
  611. }
  612. void CProjView::ClientToDoc(CRect& rect)
  613. {
  614. CClientDC dc(this);
  615. OnPrepareDC(&dc, NULL);
  616. dc.DPtoLP(rect);
  617. ASSERT(rect.left <= rect.right);
  618. ASSERT(rect.bottom <= rect.top);
  619. }
  620. void CProjView::DocToClient(CPoint& point)
  621. {
  622. CClientDC dc(this);
  623. OnPrepareDC(&dc, NULL);
  624. dc.LPtoDP(&point);
  625. }
  626. void CProjView::DocToClient(CRect& rect)
  627. {
  628. CClientDC dc(this);
  629. OnPrepareDC(&dc, NULL);
  630. dc.LPtoDP(rect);
  631. rect.NormalizeRect();
  632. }
  633. void CProjView::Select(CDrawObj* pObj, BOOL bAdd)
  634. {
  635. if (!bAdd)
  636. {
  637. OnUpdate(NULL, HINT_UPDATE_SELECTION, NULL);
  638. m_selection.RemoveAll();
  639. }
  640. if (pObj == NULL || IsSelected(pObj))
  641. return;
  642. m_selection.AddTail(pObj);
  643. InvalObj(pObj);
  644. }
  645. void CProjView::OnCancelEdit()
  646. {
  647. ReleaseCapture();
  648. CDrawTool* pTool = CDrawTool::FindTool(CDrawTool::c_drawShape);
  649. if (pTool != NULL)
  650. pTool->OnCancel(this);
  651. CDrawTool::c_drawShape = selection;
  652. }
  653. void CProjView::SetPageSize(CSize size)
  654. {
  655. CClientDC dc(NULL);
  656. size.cx = MulDiv(size.cx, dc.GetDeviceCaps(LOGPIXELSX), 100);
  657. size.cy = MulDiv(size.cy, dc.GetDeviceCaps(LOGPIXELSY), 100);
  658. SetScrollSizes(MM_TEXT, size);
  659. GetDocument()->UpdateAllViews(NULL, HINT_UPDATE_WINDOW, NULL);
  660. }
  661. void CProjView::DrawGrid(CDC* pDC)
  662. {
  663. CProjDoc* pDoc = GetDocument();
  664. COLORREF oldBkColor = pDC->SetBkColor(pDoc->GetPaperColor());
  665. CRect rect;
  666. rect.left = 0;
  667. rect.top = 0;
  668. rect.right = pDoc->GetSize().cx;
  669. rect.bottom = -pDoc->GetSize().cy;
  670. // Center lines
  671. int old = pDC->SetROP2(R2_NOTXORPEN);
  672. int old1 = pDC->SetBkMode(TRANSPARENT);
  673. CPen penDash;
  674. penDash.CreatePen(PS_DASH, 1, m_gridColor);
  675. CPen* pOldPen = pDC->SelectObject(&penDash);
  676. pDC->MoveTo(0, rect.top);
  677. pDC->LineTo(0, rect.bottom);
  678. pDC->MoveTo(rect.left, 0);
  679. pDC->LineTo(rect.right, 0);
  680. //for(int i = rect.top/20*20;i<rect.bottom;i+=20)
  681. //{
  682. // pDC->Ellipse(CRect(-1,i-1,1,i+1));
  683. //}
  684. // Major unit lines
  685. CPen penDot;
  686. penDot.CreatePen(PS_DOT, 1, m_gridColor);
  687. pDC->SelectObject(&penDot);
  688. for (int x = rect.left / 100 * 100; x < rect.right; x += 100)
  689. {
  690. if (x != 0)
  691. {
  692.             pDC->MoveTo(x, rect.top);
  693.      pDC->LineTo(x, rect.bottom);
  694.    /*for (int y = rect.top / 20 * 20; y < rect.bottom; y += 20)
  695.    {
  696.       if (y != 0)
  697.      {
  698.     pDC->MoveTo(x, rect.top);
  699.      pDC->LineTo(x, rect.bottom);
  700.  pDC->Ellipse(CRect(x-1,y-1,x+1,y+1));
  701.  }
  702.    }*/
  703. }
  704. }
  705. for (int y = rect.top / 100 * 100; y >rect.bottom; y -= 100)
  706. {
  707. if (y != 0)
  708. {
  709. pDC->MoveTo(rect.left, y);
  710. pDC->LineTo(rect.right, y);
  711. }
  712. }
  713. // Outlines
  714. CPen penSolid;
  715. penSolid.CreatePen(PS_SOLID, 1, m_gridColor);
  716. pDC->SelectObject(&penSolid);
  717. pDC->MoveTo(rect.left, rect.top);
  718. pDC->LineTo(rect.right, rect.top);
  719. pDC->LineTo(rect.right, rect.bottom);
  720. pDC->LineTo(rect.left, rect.bottom);
  721. pDC->LineTo(rect.left, rect.top);
  722. pDC->SetROP2(old);
  723. pDC->SetBkMode(old1);
  724. pDC->SelectObject(pOldPen);
  725. pDC->SetBkColor(oldBkColor);
  726. }
  727. void CProjView::Remove(CDrawObj* pObj)
  728. {
  729. POSITION pos = m_selection.Find(pObj);
  730. CRect rect;
  731. GetClientRect(rect);
  732. if (pos != NULL)
  733. m_selection.RemoveAt(pos);
  734. InvalidateRect(rect,FALSE);
  735. }
  736. void CProjView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo) 
  737. {
  738. CScrollView::OnPrepareDC(pDC, pInfo);
  739. // mapping mode is MM_ANISOTROPIC
  740. // these extents setup a mode similar to MM_LOENGLISH
  741. // MM_LOENGLISH is in .01 physical inches
  742. // these extents provide .01 logical inches
  743. pDC->SetMapMode(MM_ANISOTROPIC);
  744. pDC->SetViewportExt(pDC->GetDeviceCaps(LOGPIXELSX),
  745. pDC->GetDeviceCaps(LOGPIXELSY));
  746. int n = pDC->GetDeviceCaps(LOGPIXELSX);//for debug
  747. int m = pDC->GetDeviceCaps(LOGPIXELSY);//for debug
  748. //pDC->SetWindowExt(100, -100);
  749. pDC->SetWindowExt(100, -100);
  750. // set the origin of the coordinate system to the center of the page
  751. CPoint ptOrg;
  752. ptOrg.x = GetDocument()->GetSize().cx / 2;
  753. ptOrg.y = GetDocument()->GetSize().cy / 2;
  754. // ptOrg is in logical coordinates
  755. // pDC->OffsetWindowOrg(-ptOrg.x,ptOrg.y);
  756. //pDC->OffsetViewportOrg(ptOrg.x,ptOrg.y);
  757. pDC->OffsetViewportOrg(0,0);
  758. }
  759. void CProjView::InvalObj(CDrawObj* pObj)
  760. {
  761. CRect rect = pObj->m_position;
  762. DocToClient(rect);
  763. if (m_bActive && IsSelected(pObj))
  764. {
  765. rect.left -= 40;
  766. rect.top -= 50;
  767. rect.right += 50;
  768. rect.bottom += 40;
  769. }
  770. rect.InflateRect(1, 1); // handles CDrawOleObj objects
  771. //rect.InflateRect(5, 5);//For debug
  772. InvalidateRect(rect, FALSE);
  773. }
  774. void CProjView::OnUpdate(CView* , LPARAM lHint, CObject* pHint)
  775. {
  776. switch (lHint)
  777. {
  778. case HINT_UPDATE_WINDOW:    // redraw entire window
  779. Invalidate(FALSE);
  780. break;
  781. case HINT_UPDATE_DRAWOBJ:   // a single object has changed
  782. InvalObj((CDrawObj*)pHint);
  783. break;
  784. case HINT_UPDATE_SELECTION: // an entire selection has changed
  785. {
  786. CDrawObjList* pList = pHint != NULL ?
  787. (CDrawObjList*)pHint : &m_selection;
  788. POSITION pos = pList->GetHeadPosition();
  789. while (pos != NULL)
  790. InvalObj(pList->GetNext(pos));
  791. }
  792. break;
  793. case HINT_DELETE_SELECTION: // an entire selection has been removed
  794. if (pHint != &m_selection)
  795. {
  796. CDrawObjList* pList = (CDrawObjList*)pHint;
  797. POSITION pos = pList->GetHeadPosition();
  798. while (pos != NULL)
  799. {
  800. CDrawObj* pObj = pList->GetNext(pos);
  801. InvalObj(pObj);
  802. Remove(pObj);   // remove it from this view's selection
  803. }
  804. }
  805. break;
  806. default:
  807. ASSERT(FALSE);
  808. break;
  809. }
  810. Invalidate(FALSE);
  811. }
  812. BOOL CProjView::DestroyWindow() 
  813. {
  814. // TODO: Add your specialized code here and/or call the base class
  815. return CScrollView::DestroyWindow();
  816. }
  817. void CProjView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) 
  818. {
  819. CView::OnActivateView(bActivate, pActivateView, pDeactiveView);
  820. // invalidate selections when active status changes
  821. if (m_bActive != bActivate)
  822. {
  823. if (bActivate)  // if becoming active update as if active
  824. m_bActive = bActivate;
  825. if (!m_selection.IsEmpty())
  826. OnUpdate(NULL, HINT_UPDATE_SELECTION, NULL);
  827. m_bActive = bActivate;
  828. }
  829. }
  830. void CProjView::OnUpdateAnySelect(CCmdUI* pCmdUI)
  831. {
  832. pCmdUI->Enable(!m_selection.IsEmpty());
  833. }
  834. void CProjView::OnDrawText() 
  835. {
  836. // TODO: Add your command handler code here
  837. CDrawTool::c_drawShape = text;
  838. }
  839. void CProjView::OnUpdateDrawText(CCmdUI* pCmdUI) 
  840. {
  841. // TODO: Add your command update UI handler code here
  842. pCmdUI->SetRadio(CDrawTool::c_drawShape == text);
  843. }
  844. void CProjView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
  845. {
  846.     TRACE("Into OnCharn");
  847. if (!m_bActive)
  848. return;
  849. CDrawTool* pTool = CDrawTool::FindTool(CDrawTool::c_drawShape);
  850. if (pTool != NULL)
  851. pTool->OnChar(this, nFlags, nChar);
  852. CScrollView::OnChar(nChar, nRepCnt, nFlags);
  853. }
  854. void CProjView::OnDrawBarGraph() 
  855. {
  856. // TODO: Add your command handler code here
  857. CDrawTool::c_drawShape = barGraph;
  858. }
  859. void CProjView::OnUpdateDrawBarGraph(CCmdUI* pCmdUI) 
  860. {
  861. // TODO: Add your command update UI handler code here
  862. pCmdUI->SetRadio(CDrawTool::c_drawShape == barGraph);
  863. }
  864. void CProjView::OnDrawClock() 
  865. {
  866. // TODO: Add your command handler code here
  867. CDrawTool::c_drawShape = clockGraph;
  868. }
  869. void CProjView::OnUpdateDrawClock(CCmdUI* pCmdUI) 
  870. {
  871. // TODO: Add your command update UI handler code here
  872. pCmdUI->SetRadio(CDrawTool::c_drawShape == clockGraph);
  873. }
  874. void CProjView::LoopSearch(CDrawObjList& list,int nTemp)
  875. {
  876. CDrawObjList tempList;
  877. POSITION pos = list.GetHeadPosition();
  878. while(pos!=NULL)
  879. {
  880. if(list.GetNext(pos)->GetActiveObj(tempList))
  881. {
  882. POSITION pos1 = tempList.GetHeadPosition();
  883. while( pos1 != NULL )
  884. {
  885. (tempList.GetNext( pos1 ))->SendData( nTemp );
  886. }
  887. }
  888. else
  889. {
  890. LoopSearch(tempList,nTemp);
  891. }
  892. }
  893. }
  894. void CProjView::OnTimer(UINT nIDEvent) 
  895. {
  896. nTemp += 10;
  897. if(nTemp >100 )
  898. nTemp = 0;
  899.   if( m_bRun )
  900.   
  901. LoopSearch(GetDocument()->m_objects,nTemp);
  902.   
  903. }
  904. int CProjView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  905. {
  906. if (CScrollView::OnCreate(lpCreateStruct) == -1)
  907. return -1;
  908. int nRes = SetTimer( 1, 500, NULL);
  909. // TODO: Add your specialized creation code here
  910. return 0;
  911. }
  912. void CProjView::OnDrawAnimateTag() 
  913. {
  914. // TODO: Add your command handler code here
  915. CDrawTool::c_drawShape = animateTag;
  916. }
  917. void CProjView::OnUpdateDrawAnimateTag(CCmdUI* pCmdUI) 
  918. {
  919. // TODO: Add your command update UI handler code here
  920. pCmdUI->SetRadio(CDrawTool::c_drawShape == animateTag);
  921. }
  922. void CProjView::OnUpdateDrawCursor(CCmdUI* pCmdUI) 
  923. {
  924. // TODO: Add your command update UI handler code here
  925. pCmdUI->SetRadio(CDrawTool::c_drawShape == cursor);
  926. }
  927. void CProjView::OnDrawCursor() 
  928. {
  929. // TODO: Add your command handler code here
  930. CDrawTool::c_drawShape = cursor;
  931. }
  932. void CProjView::OnRunRun() 
  933. {
  934. // TODO: Add your command handler code here
  935. m_bRun = TRUE;
  936. }
  937. void CProjView::OnUpdateRunRun(CCmdUI* pCmdUI) 
  938. {
  939. // TODO: Add your command update UI handler code here
  940. pCmdUI->Enable( !m_bRun && !(GetDocument()->m_objects).IsEmpty() );
  941. }
  942. void CProjView::OnRunStop() 
  943. {
  944. // TODO: Add your command handler code here
  945. m_bRun = FALSE;
  946. }
  947. void CProjView::OnUpdateRunStop(CCmdUI* pCmdUI) 
  948. {
  949. // TODO: Add your command update UI handler code here
  950. pCmdUI->Enable( m_bRun );
  951. }
  952. void CProjView::OnAlign( UINT nID )
  953. {
  954. POSITION pos = m_selection.GetHeadPosition();
  955. CRect rect = m_selection.GetNext(pos)->m_position;
  956. switch( nID )
  957. {
  958. case ID_EDIT_TOP:
  959. while( pos != NULL )
  960. m_selection.GetNext(pos)->AlignToTop( rect );
  961. break;
  962. case ID_EDIT_RIGHT:
  963. while( pos != NULL )
  964. m_selection.GetNext(pos)->AlignToRight( rect );
  965. break;
  966. case ID_EDIT_LEFT:
  967. while( pos != NULL )
  968. m_selection.GetNext(pos)->AlignToLeft( rect );
  969. break;
  970. case ID_EDIT_BOTTOM:
  971. while( pos != NULL )
  972. m_selection.GetNext(pos)->AlignToBottom( rect );
  973. break;
  974. default:
  975. ASSERT( FALSE );
  976. }
  977. Invalidate();
  978. }
  979. void CProjView::OnUpdateAlign( CCmdUI* pCmdUI)
  980. {
  981. pCmdUI->Enable( m_selection.GetCount() >= 2);
  982. }
  983. // End of the implemention
  984. BOOL CProjView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) 
  985. {
  986. if( m_bCursor )
  987. return m_tracker.SetCursor( pWnd,nHitTest );
  988. else
  989. return CScrollView::OnSetCursor(pWnd, nHitTest, message);
  990. }
  991. void CProjView::OnRButtonDown(UINT nFlags, CPoint point) 
  992. {
  993. OnCancelEdit();
  994. }
  995. void CProjView::OnDrawIsa() 
  996. {
  997. CDrawTool::c_drawShape = isa;
  998. }
  999. void CProjView::OnUpdateDrawIsa(CCmdUI* pCmdUI) 
  1000. {
  1001. pCmdUI->SetRadio(CDrawTool::c_drawShape == isa);
  1002. }
  1003. void CProjView::OnDrawLoop() 
  1004. {
  1005. CDrawTool::c_drawShape = loop;
  1006. }
  1007. void CProjView::OnUpdateDrawLoop(CCmdUI* pCmdUI) 
  1008. {
  1009. pCmdUI->SetRadio(CDrawTool::c_drawShape == loop);
  1010. }
  1011. void CProjView::OnObjectMerge() 
  1012. {
  1013. BeginWaitCursor();
  1014. POSITION pos = m_selection.GetHeadPosition();
  1015. CRect rect = (m_selection.GetNext(pos))->m_position;
  1016. while( pos!=NULL)
  1017. {
  1018. rect.NormalizeRect();
  1019. CRect temp = (m_selection.GetNext(pos))->m_position;
  1020. temp.NormalizeRect();
  1021. rect |= temp;
  1022. }
  1023. CMergeObj* pMerge = new CMergeObj(rect);
  1024. pMerge->SetList(m_selection);
  1025. CRect rect1 = pMerge->m_position;
  1026. pMerge->RightRect(rect1);
  1027. pMerge->m_position = rect1;
  1028. GetDocument()->Add(pMerge);
  1029. pos = m_selection.GetHeadPosition();
  1030. while( pos!=NULL)
  1031. {
  1032. CDrawObj* pObj = m_selection.GetNext(pos);
  1033. GetDocument()->Remove(pObj);
  1034. }
  1035. m_selection.RemoveAll();
  1036. Invalidate();
  1037. EndWaitCursor();
  1038. }
  1039. void CProjView::OnUpdateObjectMerge(CCmdUI* pCmdUI) 
  1040. {
  1041. pCmdUI->Enable( m_selection.GetCount() >= 2);
  1042. }
  1043. void CProjView::OnObjectLib() 
  1044. {
  1045. CProjDoc* pDoc = (CProjDoc* )GetDocument();
  1046. ASSERT_VALID(pDoc);
  1047. if(!pDoc->IsExist())
  1048. {
  1049. if(!pDoc->CreateLib())
  1050. return;
  1051. }
  1052. pDoc->LoadFromLib();
  1053. pDoc->AddToList((m_selection.GetHead())->Clone(NULL));
  1054. pDoc->StoreToLib();
  1055. }
  1056. void CProjView::OnUpdateObjectLib(CCmdUI* pCmdUI) 
  1057. {
  1058. pCmdUI->Enable( m_selection.GetCount() == 1
  1059. && (m_selection.GetHead())->IsKindOf(RUNTIME_CLASS(CMergeObj)));
  1060. }
  1061. void CProjView::OnDrawLib() 
  1062. {
  1063. // TODO: Add your command handler code here
  1064. CDrawTool::c_drawShape = custom;
  1065. }
  1066. void CProjView::OnUpdateDrawLib(CCmdUI* pCmdUI) 
  1067. {
  1068. // TODO: Add your command update UI handler code here
  1069. pCmdUI->SetRadio(CDrawTool::c_drawShape == custom);
  1070. }
  1071. void CProjView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
  1072. {
  1073. // TODO: Add your message handler code here and/or call default
  1074. if(nChar == VK_DELETE && !m_selection.IsEmpty())
  1075. OnEditClear();
  1076. if(nChar == VK_F5)
  1077. Invalidate(FALSE);
  1078. if(!m_selection.IsEmpty())
  1079. {
  1080. CRect rect;
  1081. int nStep = 5;
  1082. if(::GetKeyState(VK_CONTROL)<0)
  1083. nStep = 1;
  1084. POSITION pos = m_selection.GetHeadPosition();
  1085. while(pos != NULL)
  1086. {
  1087. CDrawObj* pObj = m_selection.GetNext(pos);
  1088. ASSERT_VALID(pObj);
  1089. rect = pObj->m_position;
  1090. switch(nChar)
  1091. {
  1092. case VK_RIGHT:
  1093. rect.OffsetRect(nStep,0);
  1094. //pObj->m_position = rect;
  1095. break;
  1096. case VK_LEFT:
  1097. rect.OffsetRect(-nStep,0);
  1098. //pObj->m_position = rect;
  1099. break;
  1100. case VK_UP:
  1101. rect.OffsetRect(0,nStep);
  1102. //pObj->m_position = rect;
  1103. break;
  1104. case VK_DOWN:
  1105. rect.OffsetRect(0,-nStep);
  1106. break;
  1107. default:
  1108. break;
  1109. }
  1110. pObj->MoveTo(rect);
  1111. }
  1112. Invalidate(FALSE);
  1113. }
  1114. CScrollView::OnKeyDown(nChar, nRepCnt, nFlags);
  1115. }
  1116. void CProjView::OnObjectSplit() 
  1117. {
  1118. CDrawObj* pSplit;
  1119. CMergeObj* pObj = (CMergeObj* )m_selection.GetHead();
  1120. CSplitDlg dlg;
  1121. POSITION pos = (pObj->m_consist).GetHeadPosition();
  1122. while(pos!=NULL)
  1123. {
  1124. dlg.m_list.AddTail(((pObj->m_consist).GetNext(pos))->m_name);
  1125. }
  1126. if(dlg.DoModal()!=IDOK)
  1127. return;
  1128. if(dlg.m_index >= 0){
  1129. pos = (pObj->m_consist).FindIndex(dlg.m_index);
  1130. pSplit = (pObj->m_consist).GetAt(pos);
  1131. (pObj->m_consist).RemoveAt(pos);
  1132. /*if((pObj->m_consist).IsEmpty())
  1133. {
  1134. GetDocument()->Remove(pObj);
  1135. pObj->Remove();
  1136. }*/
  1137.  if((pObj->m_consist).GetCount() == 1)
  1138. {
  1139. GetDocument()->Remove(pObj);
  1140. GetDocument()->Add((pObj->m_consist).RemoveHead());
  1141. pObj->Remove();
  1142. }
  1143. else{
  1144. pObj->ReRect();
  1145. }
  1146. GetDocument()->Add(pSplit);
  1147. }
  1148. Invalidate();
  1149. GetDocument()->SetModifiedFlag();
  1150. }
  1151. void CProjView::OnUpdateObjectSplit(CCmdUI* pCmdUI) 
  1152. {
  1153. pCmdUI->Enable( m_selection.GetCount() == 1
  1154. && (m_selection.GetHead())->IsKindOf(RUNTIME_CLASS(CMergeObj)));
  1155. }
  1156. void CProjView::OnDrawButton() 
  1157. {
  1158. CDrawTool::c_drawShape = button;
  1159. }
  1160. void CProjView::OnUpdateDrawButton(CCmdUI* pCmdUI) 
  1161. {
  1162. pCmdUI->SetRadio(CDrawTool::c_drawShape == button);
  1163. }
  1164. void CProjView::OnEditRotate()
  1165. {
  1166. CDrawISA* pObj = (CDrawISA* )m_selection.GetHead();
  1167. if((++(pObj->m_nRotate))>3)
  1168. pObj->m_nRotate = 0;
  1169.     Invalidate(FALSE);
  1170. }
  1171. void CProjView::OnUpdateEditRotate(CCmdUI* pCmdUI)
  1172. {
  1173. pCmdUI->Enable((m_selection.GetCount()==1)
  1174.  && (m_selection.GetHead())->IsKindOf(RUNTIME_CLASS(CDrawISA)));
  1175. }