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

远程控制编程

开发平台:

C/C++

  1. #include "stdafx.h"
  2. #include "proj.h"
  3. #include "projdoc.h"
  4. #include "projview.h"
  5. #include "drawobj.h"
  6. #include "customDlg.h"
  7. #include "drawtool.h"
  8. /////////////////////////////////////////////////////////////////////////////
  9. // CDrawTool implementation
  10. CPtrList CDrawTool::c_tools;
  11. static CSelectTool selectTool;
  12. static CLineTool lineTool(line);
  13. static CRectTool rectTool(rect);
  14. static CEllipseTool ellipseTool(ellipse);
  15. static CPolyTool polyTool;
  16. static CTextTool textTool;
  17. static CBarTool barTool;
  18. static CAnimateTagTool animateTagTool;
  19. static CCursorTool cursorTool;
  20. static CISATool isaTool;
  21. static CLoopTool loopTool;
  22. static CCustomTool customTool;
  23. static CButtonTool buttonTool;
  24. CPoint CDrawTool::c_down;
  25. UINT CDrawTool::c_nDownFlags;
  26. CPoint CDrawTool::c_last;
  27. DrawShape CDrawTool::c_drawShape = selection;
  28. CDrawTool::CDrawTool(DrawShape drawShape)
  29. {
  30. m_drawShape = drawShape;
  31. c_tools.AddTail(this);
  32. }
  33. CDrawTool* CDrawTool::FindTool(DrawShape drawShape)
  34. {
  35. POSITION pos = c_tools.GetHeadPosition();
  36. while (pos != NULL)
  37. {
  38. CDrawTool* pTool = (CDrawTool*)c_tools.GetNext(pos);
  39. if (pTool->m_drawShape == drawShape)
  40. return pTool;
  41. }
  42. return NULL;
  43. }
  44. void CDrawTool::OnChar(CProjView* pView,UINT nFlags,UINT nChar)
  45. {
  46. }
  47. void CDrawTool::OnLButtonDown(CProjView* pView, UINT nFlags, const CPoint& point)
  48. {
  49. // deactivate any in-place active item on this view!
  50. pView->SetCapture();
  51. c_nDownFlags = nFlags;
  52. c_down = point;
  53. c_last = point;
  54. }
  55. /*void CDrawTool::OnRButtonDown(CProjView* pView, UINT nFlags, const CPoint& point)
  56. {
  57. }*/
  58. void CDrawTool::OnLButtonDblClk(CProjView* /*pView*/, UINT /*nFlags*/, const CPoint& /*point*/)
  59. {
  60. }
  61. void CDrawTool::OnLButtonUp(CProjView* /*pView*/, UINT /*nFlags*/, const CPoint& point)
  62. {
  63. ReleaseCapture();
  64. if (point == c_down)
  65. c_drawShape = selection;
  66. }
  67. void CDrawTool::OnMouseMove(CProjView* /*pView*/, UINT /*nFlags*/, const CPoint& point)
  68. {
  69. c_last = point;
  70. SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
  71. //SetCursor(AfxGetApp()->LoadStandardCursor(IDC_CROSS));
  72. }
  73. void CDrawTool::OnEditProperties(CProjView* /*pView*/)
  74. {
  75. }
  76. void CDrawTool::OnCancel(CProjView* pView)
  77. {
  78. c_drawShape = selection;
  79. }
  80. ////////////////////////////////////////////////////////////////////////////
  81. // CResizeTool
  82. enum SelectMode
  83. {
  84. none,
  85. netSelect,
  86. move,
  87. size
  88. };
  89. SelectMode selectMode = none;
  90. int nDragHandle;
  91. CPoint lastPoint;
  92. CSelectTool::CSelectTool()
  93. : CDrawTool(selection)
  94. {
  95. }
  96. void CSelectTool::OnLButtonDown(CProjView* pView, UINT nFlags, const CPoint& point)
  97. {
  98. CPoint local = point;
  99. pView->ClientToDoc(local);
  100. CDrawObj* pObj;
  101. selectMode = none;
  102. // Check for resizing (only allowed on single selections)
  103. if (pView->m_selection.GetCount() == 1)
  104. {
  105. pObj = pView->m_selection.GetHead();
  106. nDragHandle = pObj->HitTest(local, pView, TRUE);
  107. if (nDragHandle != 0 && nDragHandle != 10)//Add && nDragHandle != 10 for debug
  108. selectMode = size;
  109. }
  110. // See if the click was on an object, select and start move if so
  111. if (selectMode == none)
  112. {
  113. pObj = pView->GetDocument()->ObjectAt(local);
  114. if (pObj != NULL)
  115. {
  116. selectMode = move;
  117. if (!pView->IsSelected(pObj))
  118. pView->Select(pObj, (nFlags & MK_SHIFT) != 0);
  119. pObj->SetFlag(FALSE);
  120. // Ctrl+Click clones the selection...
  121. if ((nFlags & MK_CONTROL) != 0)
  122. pView->CloneSelection();
  123. }
  124. }
  125. // Click on background, start a net-selection
  126. if (selectMode == none)
  127. {
  128. if ((nFlags & MK_SHIFT) == 0)
  129. pView->Select(NULL);
  130. selectMode = netSelect;
  131. CClientDC dc(pView);
  132. CRect rect(point.x, point.y, point.x, point.y);
  133. rect.NormalizeRect();
  134. dc.DrawFocusRect(rect); //Comment this for test
  135. }
  136. lastPoint = local;
  137. CDrawTool::OnLButtonDown(pView, nFlags, point);
  138. }
  139. void CSelectTool::OnLButtonDblClk(CProjView* pView, UINT nFlags, const CPoint& point)
  140. {
  141. if ((nFlags & MK_SHIFT) != 0)
  142. {
  143. // Shift+DblClk deselects object...
  144. CPoint local = point;
  145. pView->ClientToDoc(local);
  146. CDrawObj* pObj = pView->GetDocument()->ObjectAt(local);
  147. if (pObj != NULL)
  148. pView->Deselect(pObj);
  149. }
  150. else
  151. {
  152. // "Normal" DblClk opens properties, or OLE server...
  153. if (pView->m_selection.GetCount() == 1)
  154. pView->m_selection.GetHead()->OnOpen(pView);
  155. }
  156. CDrawTool::OnLButtonDblClk(pView, nFlags, point);
  157. }
  158. void CSelectTool::OnEditProperties(CProjView* pView)
  159. {
  160. if (pView->m_selection.GetCount() == 1)
  161. // pView->m_selection.GetHead()->OnEditProperties( pView );
  162. pView->m_selection.GetHead()->OnOpen(pView);
  163. }
  164. void CSelectTool::OnLButtonUp(CProjView* pView, UINT nFlags, const CPoint& point)
  165. {
  166. if (pView->GetCapture() == pView)
  167. {
  168. if (selectMode == netSelect)
  169. {
  170. CClientDC dc(pView);
  171. CRect rect(c_down.x, c_down.y, c_last.x, c_last.y);
  172. rect.NormalizeRect();
  173. dc.DrawFocusRect(rect);
  174. pView->SelectWithinRect(rect, TRUE);
  175. // add these lines for a test
  176. /*if( pView->m_selection.GetCount()>=2)
  177. {
  178. POSITION pos = pView->m_selection.GetHeadPosition();
  179. CRect rect = (pView->m_selection.GetNext(pos))->m_position;
  180. while( pos!=NULL)
  181. {
  182. rect.NormalizeRect();
  183. CRect temp = (pView->m_selection.GetNext(pos))->m_position;
  184. temp.NormalizeRect();
  185. rect |= temp;
  186. }
  187. m_pOutRect = new CDrawOutRect(rect);
  188. pView->GetDocument()->Add(m_pOutRect);
  189. POSITION pos1 = pView->m_selection.GetHeadPosition();
  190. while( pos1 != NULL )
  191. m_pOutRect->m_objs.AddTail(pView->m_selection.GetNext(pos1));
  192. pView->Select(m_pOutRect);
  193. }*/
  194. // end of the test
  195. }
  196. else if (selectMode != none)
  197. {
  198. pView->GetDocument()->UpdateAllViews(pView);
  199. }
  200. }
  201. CDrawTool::OnLButtonUp(pView, nFlags, point);
  202. }
  203. void CSelectTool::OnMouseMove(CProjView* pView, UINT nFlags, const CPoint& point)
  204. {
  205. if (pView->GetCapture() != pView)
  206. {
  207. if (c_drawShape == selection && pView->m_selection.GetCount() == 1)
  208. {
  209. CDrawObj* pObj = pView->m_selection.GetHead();
  210. CPoint local = point;
  211. pView->ClientToDoc(local);
  212. int nHandle = pObj->HitTest(local, pView, TRUE);
  213. if (nHandle != 0)
  214. {
  215. SetCursor(pObj->GetHandleCursor(nHandle));
  216. return; // bypass CDrawTool
  217. }
  218. }
  219. if (c_drawShape == selection)
  220. CDrawTool::OnMouseMove(pView, nFlags, point);
  221. return;
  222. }
  223. if (selectMode == netSelect)
  224. {
  225. CClientDC dc(pView);
  226. CRect rect(c_down.x, c_down.y, c_last.x, c_last.y);
  227. rect.NormalizeRect();
  228. dc.DrawFocusRect(rect);
  229. rect.SetRect(c_down.x, c_down.y, point.x, point.y);
  230. rect.NormalizeRect();
  231. dc.DrawFocusRect(rect);
  232. /*pView->m_tracker.m_rect.NormalizeRect();
  233. if( pView->m_tracker.m_rect.PtInRect( point ))
  234. pView->m_bCursor = TRUE;
  235. else
  236. pView->m_bCursor = FALSE;
  237. */
  238. CDrawTool::OnMouseMove(pView, nFlags, point);
  239. return;
  240. }
  241. CPoint local = point;
  242. pView->ClientToDoc(local);
  243. CPoint delta = (CPoint)(local - lastPoint);
  244. POSITION pos = pView->m_selection.GetHeadPosition();
  245. while (pos != NULL)
  246. {
  247. CDrawObj* pObj = pView->m_selection.GetNext(pos);
  248. CRect position = pObj->m_position;
  249. if (selectMode == move)
  250. {
  251. position += delta;
  252. pObj->MoveTo(position, pView);
  253. }
  254. else if (nDragHandle != 0 && nDragHandle != 10)
  255. {
  256. pObj->MoveHandleTo(nDragHandle, local, pView);
  257. }
  258. }
  259. lastPoint = local;
  260. if (selectMode == size && c_drawShape == selection)
  261. {
  262. c_last = point;
  263. SetCursor(pView->m_selection.GetHead()->GetHandleCursor(nDragHandle));
  264. return; // bypass CDrawTool
  265. }
  266. c_last = point;
  267. // if (c_drawShape == selection)
  268. // CDrawTool::OnMouseMove(pView, nFlags, point);
  269. }
  270. ////////////////////////////////////////////////////////////////////////////
  271. // CRectTool 
  272. CRectTool::CRectTool(DrawShape drawShape)
  273. : CDrawTool(rect)
  274. {
  275. }
  276. void CRectTool::OnLButtonDown(CProjView* pView, UINT nFlags, const CPoint& point)
  277. {
  278. CDrawTool::OnLButtonDown(pView, nFlags, point);
  279. CPoint local = point;
  280. pView->ClientToDoc(local);
  281. CDrawRect* pObj = new CDrawRect(CRect(local, CSize(0, 0)));
  282. pView->GetDocument()->Add(pObj);
  283. pView->Select(pObj);
  284. pObj->SetFlag();
  285. selectMode = size;
  286. nDragHandle = 1;
  287. lastPoint = local;
  288. }
  289. void CRectTool::OnLButtonDblClk(CProjView* pView, UINT nFlags, const CPoint& point)
  290. {
  291. CDrawTool::OnLButtonDblClk(pView, nFlags, point);
  292. }
  293. void CRectTool::OnLButtonUp(CProjView* pView, UINT nFlags, const CPoint& point)
  294. {
  295. CDrawObj *pObj = pView->m_selection.GetTail();
  296. pObj->SetFlag(FALSE);
  297. if (point == c_down)
  298. {
  299. // Don't create empty objects...
  300. pView->GetDocument()->Remove(pObj);
  301. pObj->Remove();
  302. CDrawObj::c_identify = CDrawObj::c_identify-1;
  303. selectTool.OnLButtonDown(pView, nFlags, point); // try a select!
  304. }
  305. selectTool.OnLButtonUp(pView, nFlags, point);
  306. }
  307. void CRectTool::OnMouseMove(CProjView* pView, UINT nFlags, const CPoint& point)
  308. {
  309. SetCursor(AfxGetApp()->LoadStandardCursor(IDC_CROSS));
  310. selectTool.OnMouseMove(pView, nFlags, point);
  311. }
  312. ////////////////////////////////////////////////////////////////////////////
  313. // CPolyTool
  314. CPolyTool::CPolyTool()
  315. : CDrawTool(poly)
  316. {
  317. m_pDrawObj = NULL;
  318. }
  319. void CPolyTool::OnLButtonDown(CProjView* pView, UINT nFlags, const CPoint& point)
  320. {
  321. CDrawTool::OnLButtonDown(pView, nFlags, point);
  322. CPoint local = point;
  323. pView->ClientToDoc(local);
  324. if (m_pDrawObj == NULL)
  325. {
  326. pView->SetCapture();
  327. m_pDrawObj = new CDrawPoly(CRect(local, CSize(0, 0)));
  328. pView->GetDocument()->Add(m_pDrawObj);
  329. pView->Select(m_pDrawObj);
  330. m_pDrawObj->AddPoint(local, pView);
  331. }
  332. else if (local == m_pDrawObj->m_points[0])
  333. {
  334. // Stop when the first point is repeated...
  335. ReleaseCapture();
  336. m_pDrawObj->m_nPoints -= 1;
  337. if (m_pDrawObj->m_nPoints < 2)
  338. {
  339. m_pDrawObj->Remove();
  340. CDrawObj::c_identify = CDrawObj::c_identify-1;
  341. }
  342. else
  343. {
  344. pView->InvalObj(m_pDrawObj);
  345. }
  346. m_pDrawObj = NULL;
  347. c_drawShape = selection;
  348. return;
  349. }
  350. local.x += 1; // adjacent points can't be the same!
  351. m_pDrawObj->AddPoint(local, pView);
  352. selectMode = size;
  353. nDragHandle = m_pDrawObj->GetHandleCount();
  354. lastPoint = local;
  355. }
  356. void CPolyTool::OnLButtonUp(CProjView* /*pView*/, UINT /*nFlags*/, const CPoint& /*point*/)
  357. {
  358. // Don't release capture yet!
  359. }
  360. void CPolyTool::OnMouseMove(CProjView* pView, UINT nFlags, const CPoint& point)
  361. {
  362. if (m_pDrawObj != NULL && (nFlags & MK_LBUTTON) != 0)
  363. {
  364. CPoint local = point;
  365. pView->ClientToDoc(local);
  366. m_pDrawObj->AddPoint(local);
  367. nDragHandle = m_pDrawObj->GetHandleCount();
  368. lastPoint = local;
  369. c_last = point;
  370. // SetCursor(AfxGetApp()->LoadCursor(IDC_PENCIL));
  371. }
  372. else
  373. {
  374. SetCursor(AfxGetApp()->LoadStandardCursor(IDC_CROSS));
  375. selectTool.OnMouseMove(pView, nFlags, point);
  376. }
  377. }
  378. void CPolyTool::OnLButtonDblClk(CProjView* pView, UINT , const CPoint& )
  379. {
  380. ReleaseCapture();
  381. int nPoints = m_pDrawObj->m_nPoints;
  382. if (nPoints > 2 &&
  383. (m_pDrawObj->m_points[nPoints - 1] == m_pDrawObj->m_points[nPoints - 2] ||
  384. m_pDrawObj->m_points[nPoints - 1].x - 1 == m_pDrawObj->m_points[nPoints - 2].x &&
  385. m_pDrawObj->m_points[nPoints - 1].y == m_pDrawObj->m_points[nPoints - 2].y))
  386. {
  387. // Nuke the last point if it's the same as the next to last...
  388. m_pDrawObj->m_nPoints -= 1;
  389. pView->InvalObj(m_pDrawObj);
  390. }
  391. m_pDrawObj = NULL;
  392. c_drawShape = selection;
  393. }
  394. void CPolyTool::OnCancel(CProjView* pView)
  395. {
  396. CDrawTool::OnCancel(pView);
  397. int nPoints = m_pDrawObj->m_nPoints;
  398. if (nPoints > 2 &&
  399. (m_pDrawObj->m_points[nPoints - 1] == m_pDrawObj->m_points[nPoints - 2] ||
  400. m_pDrawObj->m_points[nPoints - 1].x - 1 == m_pDrawObj->m_points[nPoints - 2].x &&
  401. m_pDrawObj->m_points[nPoints - 1].y == m_pDrawObj->m_points[nPoints - 2].y))
  402. {
  403. // Nuke the last point if it's the same as the next to last...
  404. m_pDrawObj->m_nPoints -= 1;
  405. pView->InvalObj(m_pDrawObj);
  406. }
  407. m_pDrawObj = NULL;
  408. c_drawShape = selection;
  409. }
  410. ////////////////////////////////////////////////////////////////////////////
  411. // CISATool 
  412. CISATool::CISATool()
  413. {
  414. CDrawTool::m_drawShape = isa;
  415. }
  416. void CISATool::OnMouseMove(CProjView* pView, UINT nFlags, const CPoint& point){
  417. CPoint local = point;
  418. pView->ClientToDoc(local);
  419. if(m_pDrawText == NULL)
  420. {
  421. m_pDrawText = new CDrawISA(CRect(local,CSize(0,0)));
  422. pView->GetDocument()->Add(m_pDrawText);
  423. // pView->Select(m_pDrawText);
  424. }else{
  425. lastPoint = local;
  426. m_pDrawText->MoveTo(CRect(local,m_pDrawText->m_position.Size()),pView);
  427. }
  428. SetCursor(AfxGetApp()->LoadStandardCursor(IDC_IBEAM));
  429. }
  430. /////////////////////////////////////////////////////////////////////////////
  431. // CTextTool
  432. CTextTool::CTextTool()
  433. : CDrawTool(text)
  434. {
  435. m_pDrawText = NULL;
  436. }
  437. void CTextTool::OnLButtonDown(CProjView* pView, UINT nFlags, const CPoint& point)
  438. {
  439. //ReleaseCapture();
  440. if(m_pDrawText->m_text.IsEmpty()){
  441. CDrawObj *pObj = (pView->GetDocument())->m_objects.GetTail();
  442. pView->GetDocument()->Remove(pObj);
  443. pObj->Remove();
  444. selectTool.OnLButtonDown(pView, nFlags, point); // try a select!
  445. }
  446. m_pDrawText = NULL;
  447. c_drawShape = selection;
  448. }
  449. /*void CTextTool::OnRButtonDown(CProjView* pView, UINT nFlags, const CPoint& point)
  450. {
  451. //ReleaseCapture();
  452. if(m_pDrawText->m_text.IsEmpty()){
  453. CDrawObj *pObj = pView->m_selection.GetTail();
  454. pView->GetDocument()->Remove(pObj);
  455. pObj->Remove();
  456. selectTool.OnLButtonDown(pView, nFlags, point); // try a select!
  457. }
  458. m_pDrawText = NULL;
  459. c_drawShape = selection;
  460. }*/
  461. void CTextTool::OnCancel(CProjView* pView)
  462. {
  463. if(m_pDrawText->m_text.IsEmpty()){
  464. CDrawObj *pObj = (pView->GetDocument())->m_objects.GetTail();
  465. pView->GetDocument()->Remove(pObj);
  466. pObj->Remove();
  467. }
  468. m_pDrawText = NULL;
  469. c_drawShape = selection;
  470.     CDrawTool::OnCancel(pView);
  471. }
  472. void CTextTool::OnLButtonUp(CProjView* /*pView*/, UINT /*nFlags*/, const CPoint& /*point*/)
  473. {
  474. // Don't release capture yet!
  475. }
  476. void CTextTool::OnLButtonDblClk(CProjView* pView, UINT , const CPoint& )
  477. {
  478. }
  479. void CTextTool::OnMouseMove(CProjView* pView, UINT nFlags, const CPoint& point)
  480. {
  481. //pView->SetCapture();
  482. CPoint local = point;
  483. pView->ClientToDoc(local);
  484. if(m_pDrawText == NULL)
  485. {
  486. m_pDrawText = new CDrawText(CRect(local,CSize(0,0)));
  487. pView->GetDocument()->Add(m_pDrawText);
  488. //pView->Select(m_pDrawText);
  489. }else{
  490. lastPoint = local;
  491. m_pDrawText->MoveTo(CRect(local,m_pDrawText->m_position.Size()),pView);
  492. }
  493. SetCursor(AfxGetApp()->LoadStandardCursor(IDC_IBEAM));
  494. }
  495. void CTextTool::OnChar(CProjView* pView,UINT nFlags,UINT nChar)
  496. {
  497.     
  498. if(nChar == 0x8){
  499. m_pDrawText->m_text = m_pDrawText->m_text.Left(m_pDrawText->m_text.GetLength()-1);
  500. }
  501. //else if((nChar == 0x20 )|| (nChar>=0x30 && nChar<=0x39)
  502. //|| (nChar >=0x41 && nChar <=0x5A) || (nChar>=0x60 && nChar <=0x6F)){
  503. else if( (nChar >= 0x20 && nChar <= 0xff)){
  504. m_pDrawText->m_text+=nChar;
  505. }
  506. // m_pDrawText->RecalRect(pView);
  507. m_pDrawText->Invalidate();
  508. }
  509. ////////////////////////////////////////////////////////////////////////////
  510. // CBarTool 
  511. CBarTool::CBarTool() : CDrawTool(barGraph)
  512. {
  513. }
  514. void CBarTool::OnLButtonDown(CProjView* pView, UINT nFlags, const CPoint& point)
  515. {
  516. CDrawTool::OnLButtonDown(pView, nFlags, point);
  517. CPoint local = point;
  518. pView->ClientToDoc(local);
  519. CDrawBar* pObj = new CDrawBar(CRect(local, CSize(0, 0)));
  520. pView->GetDocument()->Add(pObj);
  521. pView->Select(pObj);
  522. selectMode = size;
  523. nDragHandle = 1;
  524. lastPoint = local;
  525. }
  526. void CBarTool::OnLButtonDblClk(CProjView* pView, UINT nFlags, const CPoint& point)
  527. {
  528. CDrawTool::OnLButtonDblClk(pView, nFlags, point);
  529. }
  530. void CBarTool::OnLButtonUp(CProjView* pView, UINT nFlags, const CPoint& point)
  531. {
  532. if (point == c_down)
  533. {
  534. // Don't create empty objects...
  535. CDrawObj *pObj = pView->m_selection.GetTail();
  536. pView->GetDocument()->Remove(pObj);
  537. pObj->Remove();
  538. CDrawObj::c_identify = CDrawObj::c_identify-1;
  539. selectTool.OnLButtonDown(pView, nFlags, point); // try a select!
  540. }
  541. selectTool.OnLButtonUp(pView, nFlags, point);
  542. }
  543. void CBarTool::OnMouseMove(CProjView* pView, UINT nFlags, const CPoint& point)
  544. {
  545. SetCursor(AfxGetApp()->LoadStandardCursor(IDC_CROSS));
  546. selectTool.OnMouseMove(pView, nFlags, point);
  547. }
  548. ////////////////////////////////////////////////////////////////////////////
  549. // CLineTool 
  550. CLineTool::CLineTool(DrawShape drawShape)
  551. : CDrawTool(drawShape)
  552. {
  553. }
  554. void CLineTool::OnLButtonDown(CProjView* pView, UINT nFlags, const CPoint& point)
  555. {
  556. CDrawTool::OnLButtonDown(pView, nFlags, point);
  557. CPoint local = point;
  558. pView->ClientToDoc(local);
  559. CDrawLine* pObj = new CDrawLine(CRect(local, CSize(0, 0)));
  560. pView->GetDocument()->Add(pObj);
  561. pView->Select(pObj);
  562. if((nFlags&MK_CONTROL)!=0)
  563. pObj->SetFlag(true);
  564. else
  565. pObj->SetFlag(false);
  566. selectMode = size;
  567. nDragHandle = 1;
  568. lastPoint = local;
  569. }
  570. void CLineTool::OnLButtonDblClk(CProjView* pView, UINT nFlags, const CPoint& point)
  571. {
  572. CDrawTool::OnLButtonDblClk(pView, nFlags, point);
  573. }
  574. void CLineTool::OnLButtonUp(CProjView* pView, UINT nFlags, const CPoint& point)
  575. {
  576. CDrawObj *pObj = pView->m_selection.GetTail();
  577. pObj->SetFlag(FALSE);
  578. if (point == c_down)
  579. {
  580. // Don't create empty objects...
  581. pView->GetDocument()->Remove(pObj);
  582. pObj->Remove();
  583. CDrawObj::c_identify = CDrawObj::c_identify-1;
  584. selectTool.OnLButtonDown(pView, nFlags, point); // try a select!
  585. }
  586. selectTool.OnLButtonUp(pView, nFlags, point);
  587. }
  588. void CLineTool::OnMouseMove(CProjView* pView, UINT nFlags, const CPoint& point)
  589. {
  590. SetCursor(AfxGetApp()->LoadStandardCursor(IDC_CROSS));
  591. selectTool.OnMouseMove(pView, nFlags, point);
  592. }
  593. ////////////////////////////////////////////////////////////////////////////
  594. // CEllipseTool 
  595. CEllipseTool::CEllipseTool(DrawShape drawShape)
  596. : CDrawTool(drawShape)
  597. {
  598. }
  599. void CEllipseTool::OnLButtonDown(CProjView* pView, UINT nFlags, const CPoint& point)
  600. {
  601. CDrawTool::OnLButtonDown(pView, nFlags, point);
  602. CPoint local = point;
  603. pView->ClientToDoc(local);
  604. CDrawEllipse* pObj = new CDrawEllipse(CRect(local, CSize(0, 0)));
  605. pView->GetDocument()->Add(pObj);
  606. pView->Select(pObj);
  607. selectMode = size;
  608. nDragHandle = 1;
  609. lastPoint = local;
  610. }
  611. void CEllipseTool::OnLButtonDblClk(CProjView* pView, UINT nFlags, const CPoint& point)
  612. {
  613. CDrawTool::OnLButtonDblClk(pView, nFlags, point);
  614. }
  615. void CEllipseTool::OnLButtonUp(CProjView* pView, UINT nFlags, const CPoint& point)
  616. {
  617. if (point == c_down)
  618. {
  619. // Don't create empty objects...
  620. CDrawObj *pObj = pView->m_selection.GetTail();
  621. pView->GetDocument()->Remove(pObj);
  622. pObj->Remove();
  623. CDrawObj::c_identify = CDrawObj::c_identify-1;
  624. selectTool.OnLButtonDown(pView, nFlags, point); // try a select!
  625. }
  626. selectTool.OnLButtonUp(pView, nFlags, point);
  627. }
  628. void CEllipseTool::OnMouseMove(CProjView* pView, UINT nFlags, const CPoint& point)
  629. {
  630. SetCursor(AfxGetApp()->LoadStandardCursor(IDC_CROSS));
  631. selectTool.OnMouseMove(pView, nFlags, point);
  632. }
  633. ////////////////////////////////////////////////////////////////////////////
  634. // CClockTool 
  635. /*CClockTool::CClockTool()
  636. : CDrawTool(clockGraph)
  637. {
  638. }
  639. void CClockTool::OnLButtonDown(CProjView* pView, UINT nFlags, const CPoint& point)
  640. {
  641. CDrawTool::OnLButtonDown(pView, nFlags, point);
  642. CPoint local = point;
  643. pView->ClientToDoc(local);
  644. CDrawClock* pObj = new CDrawClock(CRect(local, CSize(90, -250)));
  645. pView->GetDocument()->Add(pObj);
  646. pObj->ReConsist();
  647. pView->Select(pObj);
  648. selectMode = size;
  649. nDragHandle = 1;
  650. lastPoint = local;
  651. }
  652. void CClockTool::OnLButtonDblClk(CProjView* pView, UINT nFlags, const CPoint& point)
  653. {
  654. CDrawTool::OnLButtonDblClk(pView, nFlags, point);
  655. }
  656. void CClockTool::OnLButtonUp(CProjView* pView, UINT nFlags, const CPoint& point)
  657. {
  658. c_drawShape = selection;
  659. selectTool.OnLButtonUp(pView, nFlags, point);
  660. }
  661. void CClockTool::OnMouseMove(CProjView* pView, UINT nFlags, const CPoint& point)
  662. {
  663. }
  664. */
  665. /////////////////////////////////////////////////////////////////////////////
  666. // CAnimateTagTool
  667. CAnimateTagTool::CAnimateTagTool()
  668. {
  669.     CDrawTool::m_drawShape = animateTag;
  670. }
  671. void CAnimateTagTool::OnMouseMove(CProjView* pView, UINT nFlags, const CPoint& point)
  672. {
  673. //pView->SetCapture();
  674. CPoint local = point;
  675. pView->ClientToDoc(local);
  676. if(m_pDrawText == NULL)
  677. {
  678. m_pDrawText = new CDrawAnimateTag(CRect(local,CSize(0,0)));
  679. pView->GetDocument()->Add(m_pDrawText);
  680. // pView->Select(m_pDrawText);
  681. }else{
  682. lastPoint = local;
  683. m_pDrawText->MoveTo(CRect(local,m_pDrawText->m_position.Size()),pView);
  684. }
  685. SetCursor(AfxGetApp()->LoadStandardCursor(IDC_IBEAM));
  686. }
  687. void CAnimateTagTool::OnChar(CProjView* pView,UINT nFlags,UINT nChar)
  688. {
  689.     
  690. }
  691. ////////////////////////////////////////////////////////////////////////////
  692. // CCursorTool 
  693. CCursorTool::CCursorTool()
  694. : CDrawTool(cursor)
  695. {
  696. }
  697. void CCursorTool::OnLButtonDown(CProjView* pView, UINT nFlags, const CPoint& point)
  698. {
  699. CDrawTool::OnLButtonDown(pView, nFlags, point);
  700. CPoint local = point;
  701. pView->ClientToDoc(local);
  702. //CDrawCursor* pObj = new CDrawCursor(CRect(local, CSize(0, 0)));
  703. CDrawCursor* pObj = new CDrawCursor(CRect(local, CSize(0, 0)));
  704. pView->GetDocument()->Add(pObj);
  705. pView->Select(pObj);
  706. selectMode = size;
  707. nDragHandle = 1;
  708. lastPoint = local;
  709. }
  710. void CCursorTool::OnLButtonDblClk(CProjView* pView, UINT nFlags, const CPoint& point)
  711. {
  712. CDrawTool::OnLButtonDblClk(pView, nFlags, point);
  713. }
  714. void CCursorTool::OnLButtonUp(CProjView* pView, UINT nFlags, const CPoint& point)
  715. {
  716. if (point == c_down)
  717. {
  718. // Don't create empty objects...
  719. CDrawObj *pObj = pView->m_selection.GetTail();
  720. pView->GetDocument()->Remove(pObj);
  721. pObj->Remove();
  722. CDrawObj::c_identify = CDrawObj::c_identify-1;
  723. selectTool.OnLButtonDown(pView, nFlags, point); // try a select!
  724. }
  725. selectTool.OnLButtonUp(pView, nFlags, point);
  726. }
  727. void CCursorTool::OnMouseMove(CProjView* pView, UINT nFlags, const CPoint& point)
  728. {
  729. SetCursor(AfxGetApp()->LoadStandardCursor(IDC_CROSS));
  730. selectTool.OnMouseMove(pView, nFlags, point);
  731. }
  732. ////////////////////////////////////////////////////////////////////////////
  733. // CLoopTool 
  734. CLoopTool::CLoopTool()
  735. : CDrawTool(loop)
  736. {
  737. }
  738. void CLoopTool::OnLButtonDown(CProjView* pView, UINT nFlags, const CPoint& point)
  739. {
  740. CDrawTool::OnLButtonDown(pView, nFlags, point);
  741. CPoint local = point;
  742. pView->ClientToDoc(local);
  743. CDrawLoop* pObj = new CDrawLoop(CRect(local, CSize(80, 20)));
  744. pView->GetDocument()->Add(pObj);
  745. pView->Select(pObj);
  746. selectMode = size;
  747. nDragHandle = 1;
  748. lastPoint = local;
  749. }
  750. void CLoopTool::OnLButtonDblClk(CProjView* pView, UINT nFlags, const CPoint& point)
  751. {
  752. CDrawTool::OnLButtonDblClk(pView, nFlags, point);
  753. }
  754. void CLoopTool::OnLButtonUp(CProjView* pView, UINT nFlags, const CPoint& point)
  755. {
  756. c_drawShape = selection;
  757. selectTool.OnLButtonUp(pView, nFlags, point);
  758. }
  759. void CLoopTool::OnMouseMove(CProjView* pView, UINT nFlags, const CPoint& point)
  760. {
  761. SetCursor(AfxGetApp()->LoadStandardCursor(IDC_CROSS));
  762. selectTool.OnMouseMove(pView, nFlags, point);
  763. }
  764. ////////////////////////////////////////////////////////////////////////////
  765. // CCustomTool 
  766. CCustomTool::CCustomTool()
  767. : CDrawTool(custom)
  768. {
  769. }
  770. void CCustomTool::OnLButtonDown(CProjView* pView, UINT nFlags, const CPoint& point)
  771. {
  772. CDrawTool::OnLButtonDown(pView, nFlags, point);
  773. POSITION pos;
  774. CCustomDlg dlg;
  775. CPoint local = point;
  776. pView->ClientToDoc(local);
  777. CProjDoc* pDoc = (CProjDoc* )pView->GetDocument();
  778. if(pDoc->LoadFromLib())
  779. {
  780. POSITION pos1 = (pDoc->m_customList).GetHeadPosition();
  781. while(pos1!=NULL)
  782. {
  783. dlg.m_list.AddTail((pDoc->m_customList).GetNext(pos1)->m_name);
  784. }
  785. dlg.PrepareView(pView);
  786. if(dlg.DoModal()!=IDOK)
  787. return;
  788. if(dlg.m_index >= 0){
  789. pos = (pDoc->m_customList).FindIndex(dlg.m_index);
  790. CDrawObj* pObj = ((pDoc->m_customList).GetAt(pos))->Clone(NULL);
  791. pDoc->Add(pObj);
  792. ((CMergeObj* )pObj)->ResetDoc();
  793. CRect rect(local,CSize(pObj->m_position.Width(),pObj->m_position.Height()));
  794. ((CMergeObj* )pObj)->MoveTo(rect,pView);
  795. pDoc->SetModifiedFlag();
  796. pDoc->UpdateAllViews(NULL);
  797. }
  798. }
  799. selectTool.OnLButtonUp(pView, nFlags, point);
  800. }
  801. ////////////////////////////////////////////////////////////////////////////
  802. // CButtonTool 
  803. CButtonTool::CButtonTool()
  804. : CDrawTool(button)
  805. {
  806. }
  807. void CButtonTool::OnLButtonDown(CProjView* pView, UINT nFlags, const CPoint& point)
  808. {
  809. CDrawTool::OnLButtonDown(pView, nFlags, point);
  810. CPoint local = point;
  811. pView->ClientToDoc(local);
  812. CDrawButton* pObj = new CDrawButton(CRect(local, CSize(0, 0)));
  813. pView->GetDocument()->Add(pObj);
  814. pView->Select(pObj);
  815. selectMode = size;
  816. nDragHandle = 1;
  817. lastPoint = local;
  818. }
  819. void CButtonTool::OnLButtonDblClk(CProjView* pView, UINT nFlags, const CPoint& point)
  820. {
  821. CDrawTool::OnLButtonDblClk(pView, nFlags, point);
  822. }
  823. void CButtonTool::OnLButtonUp(CProjView* pView, UINT nFlags, const CPoint& point)
  824. {
  825. if (point == c_down)
  826. {
  827. // Don't create empty objects...
  828. CDrawObj *pObj = pView->m_selection.GetTail();
  829. pView->GetDocument()->Remove(pObj);
  830. pObj->Remove();
  831. CDrawObj::c_identify = CDrawObj::c_identify-1;
  832. selectTool.OnLButtonDown(pView, nFlags, point); // try a select!
  833. }
  834. selectTool.OnLButtonUp(pView, nFlags, point);
  835. }
  836. void CButtonTool::OnMouseMove(CProjView* pView, UINT nFlags, const CPoint& point)
  837. {
  838. SetCursor(AfxGetApp()->LoadStandardCursor(IDC_CROSS));
  839. selectTool.OnMouseMove(pView, nFlags, point);
  840. }
  841. // End of class implemention