drawvw.cpp
上传用户:szled88
上传日期:2015-04-09
资源大小:43957k
文件大小:32k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // drawvw.cpp : implementation of the CDrawView class
  2. //
  3. // This file is a part of the XTREME TOOLKIT PRO MFC class library.
  4. // (c)1998-2008 Codejock Software, All Rights Reserved.
  5. //
  6. // THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE
  7. // RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN
  8. // CONSENT OF CODEJOCK SOFTWARE.
  9. //
  10. // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED
  11. // IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO
  12. // YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A
  13. // SINGLE COMPUTER.
  14. //
  15. // CONTACT INFORMATION:
  16. // support@codejock.com
  17. // http://www.codejock.com
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #include "stdafx.h"
  21. #include <afxpriv.h>
  22. #include "drawcli.h"
  23. #include "drawdoc.h"
  24. #include "drawobj.h"
  25. #include "cntritem.h"
  26. #include "drawvw.h"
  27. #include "drawobj.h"
  28. #include "drawtool.h"
  29. #include "mainfrm.h"
  30. #ifdef _DEBUG
  31. #undef THIS_FILE
  32. static char BASED_CODE THIS_FILE[] = __FILE__;
  33. #endif
  34. // private clipboard format (list of Draw objects)
  35. CLIPFORMAT CDrawView::m_cfDraw = (CLIPFORMAT)
  36. ::RegisterClipboardFormat(_T("MFC Draw Sample"));
  37. CLIPFORMAT CDrawView::m_cfObjectDescriptor = NULL;
  38. /////////////////////////////////////////////////////////////////////////////
  39. // CDrawView
  40. IMPLEMENT_DYNCREATE(CDrawView, CScrollView)
  41. BEGIN_MESSAGE_MAP(CDrawView, CScrollView)
  42. //{{AFX_MSG_MAP(CDrawView)
  43. ON_COMMAND(ID_OLE_INSERT_NEW, OnInsertObject)
  44. ON_COMMAND(ID_CANCEL_EDIT, OnCancelEdit)
  45. ON_WM_LBUTTONDOWN()
  46. ON_WM_LBUTTONUP()
  47. ON_WM_MOUSEMOVE()
  48. ON_WM_LBUTTONDBLCLK()
  49. ON_COMMAND(ID_DRAW_SELECT, OnDrawSelect)
  50. ON_COMMAND(ID_DRAW_ROUNDRECT, OnDrawRoundRect)
  51. ON_COMMAND(ID_DRAW_RECT, OnDrawRect)
  52. ON_COMMAND(ID_DRAW_LINE, OnDrawLine)
  53. ON_COMMAND(ID_DRAW_ELLIPSE, OnDrawEllipse)
  54. ON_UPDATE_COMMAND_UI(ID_DRAW_ELLIPSE, OnUpdateDrawEllipse)
  55. ON_UPDATE_COMMAND_UI(ID_DRAW_LINE, OnUpdateDrawLine)
  56. ON_UPDATE_COMMAND_UI(ID_DRAW_RECT, OnUpdateDrawRect)
  57. ON_UPDATE_COMMAND_UI(ID_DRAW_ROUNDRECT, OnUpdateDrawRoundRect)
  58. ON_UPDATE_COMMAND_UI(ID_DRAW_SELECT, OnUpdateDrawSelect)
  59. ON_UPDATE_COMMAND_UI(ID_OBJECT_MOVEBACK, OnUpdateSingleSelect)
  60. ON_COMMAND(ID_EDIT_SELECT_ALL, OnEditSelectAll)
  61. ON_COMMAND(ID_EDIT_CLEAR, OnEditClear)
  62. ON_UPDATE_COMMAND_UI(ID_EDIT_CLEAR, OnUpdateAnySelect)
  63. ON_COMMAND(ID_DRAW_POLYGON, OnDrawPolygon)
  64. ON_UPDATE_COMMAND_UI(ID_DRAW_POLYGON, OnUpdateDrawPolygon)
  65. ON_WM_SIZE()
  66. ON_COMMAND(ID_VIEW_GRID, OnViewGrid)
  67. ON_UPDATE_COMMAND_UI(ID_VIEW_GRID, OnUpdateViewGrid)
  68. ON_WM_ERASEBKGND()
  69. ON_COMMAND(ID_OBJECT_FILLCOLOR, OnObjectFillColor)
  70. ON_COMMAND(ID_OBJECT_LINECOLOR, OnObjectLineColor)
  71. ON_COMMAND(ID_OBJECT_MOVEBACK, OnObjectMoveBack)
  72. ON_COMMAND(ID_OBJECT_MOVEFORWARD, OnObjectMoveForward)
  73. ON_COMMAND(ID_OBJECT_MOVETOBACK, OnObjectMoveToBack)
  74. ON_COMMAND(ID_OBJECT_MOVETOFRONT, OnObjectMoveToFront)
  75. ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
  76. ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, OnUpdateEditCopy)
  77. ON_COMMAND(ID_EDIT_CUT, OnEditCut)
  78. ON_UPDATE_COMMAND_UI(ID_EDIT_CUT, OnUpdateEditCut)
  79. ON_COMMAND(ID_EDIT_PASTE, OnEditPaste)
  80. ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, OnUpdateEditPaste)
  81. ON_WM_SETFOCUS()
  82. ON_COMMAND(ID_VIEW_SHOWOBJECTS, OnViewShowObjects)
  83. ON_UPDATE_COMMAND_UI(ID_VIEW_SHOWOBJECTS, OnUpdateViewShowObjects)
  84. ON_COMMAND(ID_EDIT_PROPERTIES, OnEditProperties)
  85. ON_UPDATE_COMMAND_UI(ID_EDIT_PROPERTIES, OnUpdateEditProperties)
  86. ON_WM_DESTROY()
  87. ON_UPDATE_COMMAND_UI(ID_EDIT_SELECT_ALL, OnUpdateEditSelectAll)
  88. ON_WM_CREATE()
  89. ON_UPDATE_COMMAND_UI(ID_OBJECT_MOVEFORWARD, OnUpdateSingleSelect)
  90. ON_UPDATE_COMMAND_UI(ID_OBJECT_MOVETOBACK, OnUpdateSingleSelect)
  91. ON_UPDATE_COMMAND_UI(ID_OBJECT_MOVETOFRONT, OnUpdateSingleSelect)
  92. ON_WM_CONTEXTMENU()
  93. //}}AFX_MSG_MAP
  94. // Standard printing commands
  95. ON_COMMAND(ID_FILE_PRINT, OnFilePrint)
  96. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
  97. ON_WM_CANCELMODE()
  98. END_MESSAGE_MAP()
  99. /////////////////////////////////////////////////////////////////////////////
  100. // CDrawView construction/destruction
  101. #pragma warning(disable: 4355) // OK here
  102. CDrawView::CDrawView()
  103. : m_selection(this)
  104. {
  105. m_bGrid = TRUE;
  106. m_gridColor = RGB(0, 0, 128);
  107. m_bActive = FALSE;
  108. // new
  109. if( m_cfObjectDescriptor == NULL )
  110. m_cfObjectDescriptor = (CLIPFORMAT)::RegisterClipboardFormat(_T("Object Descriptor") );
  111. m_prevDropEffect = DROPEFFECT_NONE;
  112. // end new
  113. }
  114. CDrawView::~CDrawView()
  115. {
  116. }
  117. BOOL CDrawView::PreCreateWindow(CREATESTRUCT& cs)
  118. {
  119. ASSERT(cs.style & WS_CHILD);
  120. if (cs.lpszClass == NULL)
  121. cs.lpszClass = AfxRegisterWndClass(CS_DBLCLKS);
  122. return TRUE;
  123. }
  124. void CDrawView::OnActivateView(BOOL bActivate, CView* pActiveView,
  125. CView* pDeactiveView)
  126. {
  127. CView::OnActivateView(bActivate, pActiveView, pDeactiveView);
  128. CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd();
  129. if (!bActivate && !pMainFrame->IsWindowEnabled())
  130. return;
  131. // invalidate selections when active status changes
  132. if (m_bActive != bActivate)
  133. {
  134. if (bActivate)  // if becoming active update as if active
  135. m_bActive = bActivate;
  136. if (!m_selection.IsEmpty())
  137. OnUpdate(NULL, HINT_UPDATE_SELECTION, NULL);
  138. m_bActive = bActivate;
  139. }
  140. if (!bActivate && pMainFrame->MDIGetActive() != GetParentFrame())
  141. {
  142. pMainFrame->UpdatePropertyGridContent(0);
  143. }
  144. }
  145. /////////////////////////////////////////////////////////////////////////////
  146. // CDrawView drawing
  147. void CDrawView::InvalObj(CDrawObj* pObj)
  148. {
  149. CRect rect = pObj->m_position;
  150. DocToClient(rect);
  151. if (m_bActive && IsSelected(pObj))
  152. {
  153. rect.left -= 4;
  154. rect.top -= 5;
  155. rect.right += 5;
  156. rect.bottom += 4;
  157. }
  158. rect.InflateRect(1, 1); // handles CDrawOleObj objects
  159. InvalidateRect(rect, FALSE);
  160. }
  161. void CDrawView::OnUpdate(CView* , LPARAM lHint, CObject* pHint)
  162. {
  163. switch (lHint)
  164. {
  165. case HINT_UPDATE_WINDOW:    // redraw entire window
  166. Invalidate(FALSE);
  167. break;
  168. case HINT_UPDATE_DRAWOBJ:   // a single object has changed
  169. InvalObj((CDrawObj*)pHint);
  170. break;
  171. case HINT_UPDATE_SELECTION: // an entire selection has changed
  172. {
  173. CDrawObjList* pList = pHint != NULL ?
  174. (CDrawObjList*)pHint : &m_selection;
  175. POSITION pos = pList->GetHeadPosition();
  176. while (pos != NULL)
  177. InvalObj(pList->GetNext(pos));
  178. ((CMainFrame*)AfxGetMainWnd())->UpdatePropertyGridContent(this);
  179. }
  180. break;
  181. case HINT_DELETE_SELECTION: // an entire selection has been removed
  182. if (pHint != &m_selection)
  183. {
  184. CDrawObjList* pList = (CDrawObjList*)pHint;
  185. POSITION pos = pList->GetHeadPosition();
  186. while (pos != NULL)
  187. {
  188. CDrawObj* pObj = pList->GetNext(pos);
  189. InvalObj(pObj);
  190. Remove(pObj);   // remove it from this view's selection
  191. }
  192. }
  193. ((CMainFrame*)AfxGetMainWnd())->UpdatePropertyGridContent(this);
  194. break;
  195. case HINT_UPDATE_OLE_ITEMS:
  196. {
  197. CDrawDoc* pDoc = GetDocument();
  198. POSITION pos = pDoc->GetObjects()->GetHeadPosition();
  199. while (pos != NULL)
  200. {
  201. CDrawObj* pObj = pDoc->GetObjects()->GetNext(pos);
  202. if (pObj->IsKindOf(RUNTIME_CLASS(CDrawOleObj)))
  203. InvalObj(pObj);
  204. }
  205. }
  206. break;
  207. default:
  208. ASSERT(FALSE);
  209. break;
  210. }
  211. }
  212. void CDrawView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
  213. {
  214. CScrollView::OnPrepareDC(pDC, pInfo);
  215. // mapping mode is MM_ANISOTROPIC
  216. // these extents setup a mode similar to MM_LOENGLISH
  217. // MM_LOENGLISH is in .01 physical inches
  218. // these extents provide .01 logical inches
  219. pDC->SetMapMode(MM_ANISOTROPIC);
  220. pDC->SetViewportExt(pDC->GetDeviceCaps(LOGPIXELSX),
  221. pDC->GetDeviceCaps(LOGPIXELSY));
  222. pDC->SetWindowExt(100, -100);
  223. // set the origin of the coordinate system to the center of the page
  224. CPoint ptOrg;
  225. ptOrg.x = GetDocument()->GetSize().cx / 2;
  226. ptOrg.y = GetDocument()->GetSize().cy / 2;
  227. // ptOrg is in logical coordinates
  228. pDC->OffsetWindowOrg(-ptOrg.x,ptOrg.y);
  229. }
  230. BOOL CDrawView::OnScrollBy(CSize sizeScroll, BOOL bDoScroll)
  231. {
  232. // do the scroll
  233. if (!CScrollView::OnScrollBy(sizeScroll, bDoScroll))
  234. return FALSE;
  235. // update the position of any in-place active item
  236. if (bDoScroll)
  237. {
  238. UpdateActiveItem();
  239. UpdateWindow();
  240. }
  241. return TRUE;
  242. }
  243. void CDrawView::OnDraw(CDC* pDC)
  244. {
  245. CDrawDoc* pDoc = GetDocument();
  246. ASSERT_VALID(pDoc);
  247. CDC dc;
  248. CDC* pDrawDC = pDC;
  249. CBitmap bitmap;
  250. CBitmap* pOldBitmap = 0;
  251. // only paint the rect that needs repainting
  252. CRect client;
  253. pDC->GetClipBox(client);
  254. CRect rect = client;
  255. DocToClient(rect);
  256. if (!pDC->IsPrinting())
  257. {
  258. // draw to offscreen bitmap for fast looking repaints
  259. if (dc.CreateCompatibleDC(pDC))
  260. {
  261. if (bitmap.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height()))
  262. {
  263. OnPrepareDC(&dc, NULL);
  264. pDrawDC = &dc;
  265. // offset origin more because bitmap is just piece of the whole drawing
  266. dc.OffsetViewportOrg(-rect.left, -rect.top);
  267. pOldBitmap = dc.SelectObject(&bitmap);
  268. dc.SetBrushOrg(rect.left % 8, rect.top % 8);
  269. // might as well clip to the same rectangle
  270. dc.IntersectClipRect(client);
  271. }
  272. }
  273. }
  274. // paint background
  275. CBrush brush;
  276. if (!brush.CreateSolidBrush(pDoc->GetPaperColor()))
  277. return;
  278. brush.UnrealizeObject();
  279. pDrawDC->FillRect(client, &brush);
  280. if (!pDC->IsPrinting() && m_bGrid)
  281. DrawGrid(pDrawDC);
  282. pDoc->Draw(pDrawDC, this);
  283. if (pDrawDC != pDC)
  284. {
  285. pDC->SetViewportOrg(0, 0);
  286. pDC->SetWindowOrg(0,0);
  287. pDC->SetMapMode(MM_TEXT);
  288. dc.SetViewportOrg(0, 0);
  289. dc.SetWindowOrg(0,0);
  290. dc.SetMapMode(MM_TEXT);
  291. pDC->BitBlt(rect.left, rect.top, rect.Width(), rect.Height(),
  292. &dc, 0, 0, SRCCOPY);
  293. dc.SelectObject(pOldBitmap);
  294. }
  295. }
  296. void CDrawView::Remove(CDrawObj* pObj)
  297. {
  298. POSITION pos = m_selection.Find(pObj);
  299. if (pos != NULL)
  300. m_selection.RemoveAt(pos);
  301. }
  302. void CDrawView::PasteNative(COleDataObject& dataObject)
  303. {
  304. // get file refering to clipboard data
  305. CFile* pFile = dataObject.GetFileData(m_cfDraw);
  306. if (pFile == NULL)
  307. return;
  308. // connect the file to the archive
  309. CArchive ar(pFile, CArchive::load);
  310. TRY
  311. {
  312. ar.m_pDocument = GetDocument(); // set back-pointer in archive
  313. // read the selection
  314. m_selection.Serialize(ar);
  315. }
  316. CATCH_ALL(e)
  317. {
  318. ar.Close();
  319. delete pFile;
  320. THROW_LAST();
  321. }
  322. END_CATCH_ALL
  323. ar.Close();
  324. delete pFile;
  325. }
  326. void CDrawView::PasteEmbedded(COleDataObject& dataObject, CPoint point )
  327. {
  328. BeginWaitCursor();
  329. // paste embedded
  330. CDrawOleObj* pObj = new CDrawOleObj(GetInitialPosition());
  331. ASSERT_VALID(pObj);
  332. CDrawItem* pItem = new CDrawItem(GetDocument(), pObj);
  333. ASSERT_VALID(pItem);
  334. pObj->m_pClientItem = pItem;
  335. TRY
  336. {
  337. if (!pItem->CreateFromData(&dataObject) &&
  338. !pItem->CreateStaticFromData(&dataObject))
  339. {
  340. AfxThrowMemoryException();      // any exception will do
  341. }
  342. // add the object to the document
  343. GetDocument()->Add(pObj);
  344. m_selection.AddTail(pObj);
  345. ClientToDoc( point );
  346. pObj->MoveTo( CRect( point, pObj->m_extent ), this );
  347. // try to get initial presentation data
  348. pItem->UpdateLink();
  349. pItem->UpdateExtent();
  350. }
  351. CATCH_ALL(e)
  352. {
  353. // clean up item
  354. pItem->Delete();
  355. pObj->m_pClientItem = NULL;
  356. GetDocument()->Remove(pObj);
  357. pObj->Remove();
  358. AfxMessageBox(IDP_FAILED_TO_CREATE);
  359. }
  360. END_CATCH_ALL
  361. EndWaitCursor();
  362. }
  363. void CDrawView::DrawGrid(CDC* pDC)
  364. {
  365. CDrawDoc* pDoc = GetDocument();
  366. COLORREF oldBkColor = pDC->SetBkColor(pDoc->GetPaperColor());
  367. CRect rect;
  368. rect.left = -pDoc->GetSize().cx / 2;
  369. rect.top = -pDoc->GetSize().cy / 2;
  370. rect.right = rect.left + pDoc->GetSize().cx;
  371. rect.bottom = rect.top + pDoc->GetSize().cy;
  372. // Center lines
  373. CPen penDash;
  374. penDash.CreatePen(PS_DASH, 1, m_gridColor);
  375. CPen* pOldPen = pDC->SelectObject(&penDash);
  376. pDC->MoveTo(0, rect.top);
  377. pDC->LineTo(0, rect.bottom);
  378. pDC->MoveTo(rect.left, 0);
  379. pDC->LineTo(rect.right, 0);
  380. // Major unit lines
  381. CPen penDot;
  382. penDot.CreatePen(PS_DOT, 1, m_gridColor);
  383. pDC->SelectObject(&penDot);
  384. for (int x = rect.left / 100 * 100; x < rect.right; x += 100)
  385. {
  386. if (x != 0)
  387. {
  388. pDC->MoveTo(x, rect.top);
  389. pDC->LineTo(x, rect.bottom);
  390. }
  391. }
  392. for (int y = rect.top / 100 * 100; y < rect.bottom; y += 100)
  393. {
  394. if (y != 0)
  395. {
  396. pDC->MoveTo(rect.left, y);
  397. pDC->LineTo(rect.right, y);
  398. }
  399. }
  400. // Outlines
  401. /*CPen penSolid;
  402. penSolid.CreatePen(PS_SOLID, 1, m_gridColor);
  403. pDC->SelectObject(&penSolid);
  404. pDC->MoveTo(rect.left, rect.top);
  405. pDC->LineTo(rect.right, rect.top);
  406. pDC->LineTo(rect.right, rect.bottom);
  407. pDC->LineTo(rect.left, rect.bottom);
  408. pDC->LineTo(rect.left, rect.top);*/
  409. pDC->SelectObject(pOldPen);
  410. pDC->SetBkColor(oldBkColor);
  411. }
  412. void CDrawView::OnInitialUpdate()
  413. {
  414. CSize size = GetDocument()->GetSize();
  415. CClientDC dc(NULL);
  416. size.cx = MulDiv(size.cx, dc.GetDeviceCaps(LOGPIXELSX), 100);
  417. size.cy = MulDiv(size.cy, dc.GetDeviceCaps(LOGPIXELSY), 100);
  418. SetScrollSizes(MM_TEXT, size);
  419. }
  420. void CDrawView::SetPageSize(CSize size)
  421. {
  422. CClientDC dc(NULL);
  423. size.cx = MulDiv(size.cx, dc.GetDeviceCaps(LOGPIXELSX), 100);
  424. size.cy = MulDiv(size.cy, dc.GetDeviceCaps(LOGPIXELSY), 100);
  425. SetScrollSizes(MM_TEXT, size);
  426. GetDocument()->UpdateAllViews(NULL, HINT_UPDATE_WINDOW, NULL);
  427. }
  428. /////////////////////////////////////////////////////////////////////////////
  429. // CDrawView printing
  430. BOOL CDrawView::OnPreparePrinting(CPrintInfo* pInfo)
  431. {
  432. // default preparation
  433. return DoPreparePrinting(pInfo);
  434. }
  435. void CDrawView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
  436. {
  437. CScrollView::OnBeginPrinting(pDC,pInfo);
  438. // check page size -- user could have gone into print setup
  439. // from print dialog and changed paper or orientation
  440. GetDocument()->ComputePageSize();
  441. }
  442. void CDrawView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  443. {
  444. // TODO: add cleanup after printing
  445. }
  446. /////////////////////////////////////////////////////////////////////////////
  447. // OLE Client support and commands
  448. BOOL CDrawView::IsSelected(const CObject* pDocItem) const
  449. {
  450. CDrawObj* pDrawObj = (CDrawObj*)pDocItem;
  451. if (pDocItem->IsKindOf(RUNTIME_CLASS(CDrawItem)))
  452. pDrawObj = ((CDrawItem*)pDocItem)->m_pDrawObj;
  453. return m_selection.Find(pDrawObj) != NULL;
  454. }
  455. void CDrawView::OnInsertObject()
  456. {
  457. // Invoke the standard Insert Object dialog box to obtain information
  458. //  for new CDrawItem object.
  459. COleInsertDialog dlg;
  460. if (dlg.DoModal() != IDOK)
  461. return;
  462. BeginWaitCursor();
  463. // First create the C++ object
  464. CDrawOleObj* pObj = new CDrawOleObj(GetInitialPosition());
  465. ASSERT_VALID(pObj);
  466. CDrawItem* pItem = new CDrawItem(GetDocument(), pObj);
  467. ASSERT_VALID(pItem);
  468. pObj->m_pClientItem = pItem;
  469. // Now create the OLE object/item
  470. TRY
  471. {
  472. if (!dlg.CreateItem(pObj->m_pClientItem))
  473. AfxThrowMemoryException();
  474. // add the object to the document
  475. GetDocument()->Add(pObj);
  476. // try to get initial presentation data
  477. pItem->UpdateLink();
  478. pItem->UpdateExtent();
  479. // if insert new object -- initially show the object
  480. if (dlg.GetSelectionType() == COleInsertDialog::createNewItem)
  481. pItem->DoVerb(OLEIVERB_SHOW, this);
  482. }
  483. CATCH_ALL(e)
  484. {
  485. // clean up item
  486. pItem->Delete();
  487. pObj->m_pClientItem = NULL;
  488. GetDocument()->Remove(pObj);
  489. pObj->Remove();
  490. AfxMessageBox(IDP_FAILED_TO_CREATE);
  491. }
  492. END_CATCH_ALL
  493. EndWaitCursor();
  494. }
  495. // The following command handler provides the standard keyboard
  496. //  user interface to cancel an in-place editing session.
  497. void CDrawView::OnCancelEdit()
  498. {
  499. // deactivate any in-place active item on this view!
  500. COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
  501. if (pActiveItem != NULL)
  502. {
  503. // if we found one, deactivate it
  504. pActiveItem->Close();
  505. }
  506. ASSERT(GetDocument()->GetInPlaceActiveItem(this) == NULL);
  507. // escape also brings us back into select mode
  508. ReleaseCapture();
  509. CDrawTool* pTool = CDrawTool::FindTool(CDrawTool::c_drawShape);
  510. if (pTool != NULL)
  511. pTool->OnCancel();
  512. CDrawTool::c_drawShape = selection;
  513. }
  514. void CDrawView::OnSetFocus(CWnd* pOldWnd)
  515. {
  516. COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
  517. if (pActiveItem != NULL &&
  518. pActiveItem->GetItemState() == COleClientItem::activeUIState)
  519. {
  520. // need to set focus to this item if it is in the same view
  521. CWnd* pWnd = pActiveItem->GetInPlaceWindow();
  522. if (pWnd != NULL)
  523. {
  524. pWnd->SetFocus();
  525. return;
  526. }
  527. }
  528. CScrollView::OnSetFocus(pOldWnd);
  529. }
  530. CRect CDrawView::GetInitialPosition()
  531. {
  532. CRect rect(10, 10, 10, 10);
  533. ClientToDoc(rect);
  534. return rect;
  535. }
  536. void CDrawView::ClientToDoc(CPoint& point)
  537. {
  538. CClientDC dc(this);
  539. OnPrepareDC(&dc, NULL);
  540. dc.DPtoLP(&point);
  541. }
  542. void CDrawView::ClientToDoc(CRect& rect)
  543. {
  544. CClientDC dc(this);
  545. OnPrepareDC(&dc, NULL);
  546. dc.DPtoLP(rect);
  547. ASSERT(rect.left <= rect.right);
  548. ASSERT(rect.bottom <= rect.top);
  549. }
  550. void CDrawView::DocToClient(CPoint& point)
  551. {
  552. CClientDC dc(this);
  553. OnPrepareDC(&dc, NULL);
  554. dc.LPtoDP(&point);
  555. }
  556. void CDrawView::DocToClient(CRect& rect)
  557. {
  558. CClientDC dc(this);
  559. OnPrepareDC(&dc, NULL);
  560. dc.LPtoDP(rect);
  561. rect.NormalizeRect();
  562. }
  563. void CDrawView::Select(CDrawObj* pObj, BOOL bAdd)
  564. {
  565. if (!bAdd)
  566. {
  567. OnUpdate(NULL, HINT_UPDATE_SELECTION, NULL);
  568. m_selection.RemoveAll();
  569. }
  570. if (pObj == NULL || IsSelected(pObj))
  571. return;
  572. m_selection.AddTail(pObj);
  573. InvalObj(pObj);
  574. }
  575. // rect is in device coordinates
  576. void CDrawView::SelectWithinRect(CRect rect, BOOL bAdd)
  577. {
  578. if (!bAdd)
  579. Select(NULL);
  580. ClientToDoc(rect);
  581. CDrawObjList* pObList = GetDocument()->GetObjects();
  582. POSITION posObj = pObList->GetHeadPosition();
  583. while (posObj != NULL)
  584. {
  585. CDrawObj* pObj = pObList->GetNext(posObj);
  586. if (pObj->Intersects(rect))
  587. Select(pObj, TRUE);
  588. }
  589. }
  590. void CDrawView::Deselect(CDrawObj* pObj)
  591. {
  592. POSITION pos = m_selection.Find(pObj);
  593. if (pos != NULL)
  594. {
  595. InvalObj(pObj);
  596. m_selection.RemoveAt(pos);
  597. }
  598. }
  599. void CDrawView::CloneSelection()
  600. {
  601. POSITION pos = m_selection.GetHeadPosition();
  602. while (pos != NULL)
  603. {
  604. CDrawObj* pObj = m_selection.GetNext(pos);
  605. pObj->Clone(pObj->m_pDocument);
  606. // copies object and adds it to the document
  607. }
  608. }
  609. void CDrawView::UpdateActiveItem()
  610. {
  611. COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
  612. if (pActiveItem != NULL &&
  613. pActiveItem->GetItemState() == COleClientItem::activeUIState)
  614. {
  615. // this will update the item rectangles by calling
  616. //  OnGetPosRect & OnGetClipRect.
  617. pActiveItem->SetItemRects();
  618. }
  619. }
  620. /////////////////////////////////////////////////////////////////////////////
  621. // CDrawView message handlers
  622. void CDrawView::OnLButtonDown(UINT nFlags, CPoint point)
  623. {
  624. if (!m_bActive)
  625. return;
  626. CDrawTool* pTool = CDrawTool::FindTool(CDrawTool::c_drawShape);
  627. if (pTool != NULL)
  628. pTool->OnLButtonDown(this, nFlags, point);
  629. }
  630. void CDrawView::OnLButtonUp(UINT nFlags, CPoint point)
  631. {
  632. if (!m_bActive)
  633. return;
  634. CDrawTool* pTool = CDrawTool::FindTool(CDrawTool::c_drawShape);
  635. if (pTool != NULL)
  636. pTool->OnLButtonUp(this, nFlags, point);
  637. }
  638. void CDrawView::OnMouseMove(UINT nFlags, CPoint point)
  639. {
  640. if (!m_bActive)
  641. return;
  642. CDrawTool* pTool = CDrawTool::FindTool(CDrawTool::c_drawShape);
  643. if (pTool != NULL)
  644. pTool->OnMouseMove(this, nFlags, point);
  645. }
  646. void CDrawView::OnLButtonDblClk(UINT nFlags, CPoint point)
  647. {
  648. if (!m_bActive)
  649. return;
  650. CDrawTool* pTool = CDrawTool::FindTool(CDrawTool::c_drawShape);
  651. if (pTool != NULL)
  652. pTool->OnLButtonDblClk(this, nFlags, point);
  653. }
  654. void CDrawView::OnCancelMode()
  655. {
  656. // deactivate the inplace active item on this view
  657. COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
  658. if (pActiveItem != NULL && pActiveItem->GetActiveView() == this)
  659. {
  660. pActiveItem->Deactivate();
  661. ASSERT(GetDocument()->GetInPlaceActiveItem(this) == NULL);
  662. }
  663. }
  664. void CDrawView::OnDestroy()
  665. {
  666. CScrollView::OnDestroy();
  667. OnCancelMode();
  668. }
  669. void CDrawView::OnDrawSelect()
  670. {
  671. CDrawTool::c_drawShape = selection;
  672. }
  673. void CDrawView::OnDrawRoundRect()
  674. {
  675. CDrawTool::c_drawShape = roundRect;
  676. }
  677. void CDrawView::OnDrawRect()
  678. {
  679. CDrawTool::c_drawShape = rect;
  680. }
  681. void CDrawView::OnDrawLine()
  682. {
  683. CDrawTool::c_drawShape = line;
  684. }
  685. void CDrawView::OnDrawEllipse()
  686. {
  687. CDrawTool::c_drawShape = ellipse;
  688. }
  689. void CDrawView::OnDrawPolygon()
  690. {
  691. CDrawTool::c_drawShape = poly;
  692. }
  693. void CDrawView::OnUpdateDrawEllipse(CCmdUI* pCmdUI)
  694. {
  695. pCmdUI->SetRadio(CDrawTool::c_drawShape == ellipse);
  696. }
  697. void CDrawView::OnUpdateDrawLine(CCmdUI* pCmdUI)
  698. {
  699. pCmdUI->SetRadio(CDrawTool::c_drawShape == line);
  700. }
  701. void CDrawView::OnUpdateDrawRect(CCmdUI* pCmdUI)
  702. {
  703. pCmdUI->SetRadio(CDrawTool::c_drawShape == rect);
  704. }
  705. void CDrawView::OnUpdateDrawRoundRect(CCmdUI* pCmdUI)
  706. {
  707. pCmdUI->SetRadio(CDrawTool::c_drawShape == roundRect);
  708. }
  709. void CDrawView::OnUpdateDrawSelect(CCmdUI* pCmdUI)
  710. {
  711. pCmdUI->SetRadio(CDrawTool::c_drawShape == selection);
  712. }
  713. void CDrawView::OnUpdateSingleSelect(CCmdUI* pCmdUI)
  714. {
  715. pCmdUI->Enable(m_selection.GetCount() == 1);
  716. }
  717. void CDrawView::OnEditSelectAll()
  718. {
  719. CDrawObjList* pObList = GetDocument()->GetObjects();
  720. POSITION pos = pObList->GetHeadPosition();
  721. while (pos != NULL)
  722. Select(pObList->GetNext(pos), TRUE);
  723. }
  724. void CDrawView::OnUpdateEditSelectAll(CCmdUI* pCmdUI)
  725. {
  726. pCmdUI->Enable(GetDocument()->GetObjects()->GetCount() != 0);
  727. }
  728. void CDrawView::OnEditClear()
  729. {
  730. // update all the views before the selection goes away
  731. GetDocument()->UpdateAllViews(NULL, HINT_DELETE_SELECTION, &m_selection);
  732. OnUpdate(NULL, HINT_UPDATE_SELECTION, NULL);
  733. // now remove the selection from the document
  734. POSITION pos = m_selection.GetHeadPosition();
  735. while (pos != NULL)
  736. {
  737. CDrawObj* pObj = m_selection.GetNext(pos);
  738. GetDocument()->Remove(pObj);
  739. pObj->Remove();
  740. }
  741. m_selection.RemoveAll();
  742. }
  743. void CDrawView::OnUpdateAnySelect(CCmdUI* pCmdUI)
  744. {
  745. pCmdUI->Enable(!m_selection.IsEmpty());
  746. }
  747. void CDrawView::OnUpdateDrawPolygon(CCmdUI* pCmdUI)
  748. {
  749. pCmdUI->SetRadio(CDrawTool::c_drawShape == poly);
  750. }
  751. void CDrawView::OnSize(UINT nType, int cx, int cy)
  752. {
  753. CScrollView::OnSize(nType, cx, cy);
  754. UpdateActiveItem();
  755. }
  756. void CDrawView::OnViewGrid()
  757. {
  758. m_bGrid = !m_bGrid;
  759. Invalidate(FALSE);
  760. }
  761. void CDrawView::OnUpdateViewGrid(CCmdUI* pCmdUI)
  762. {
  763. pCmdUI->SetCheck(m_bGrid);
  764. }
  765. BOOL CDrawView::OnEraseBkgnd(CDC*)
  766. {
  767. return TRUE;
  768. }
  769. void CDrawView::OnObjectFillColor()
  770. {
  771. CColorDialog dlg;
  772. if (dlg.DoModal() != IDOK)
  773. return;
  774. COLORREF color = dlg.GetColor();
  775. POSITION pos = m_selection.GetHeadPosition();
  776. while (pos != NULL)
  777. {
  778. CDrawObj* pObj = m_selection.GetNext(pos);
  779. pObj->SetFillColor(color);
  780. }
  781. }
  782. void CDrawView::OnObjectLineColor()
  783. {
  784. CColorDialog dlg;
  785. if (dlg.DoModal() != IDOK)
  786. return;
  787. COLORREF color = dlg.GetColor();
  788. POSITION pos = m_selection.GetHeadPosition();
  789. while (pos != NULL)
  790. {
  791. CDrawObj* pObj = m_selection.GetNext(pos);
  792. pObj->SetLineColor(color);
  793. }
  794. }
  795. void CDrawView::OnObjectMoveBack()
  796. {
  797. CDrawDoc* pDoc = GetDocument();
  798. CDrawObj* pObj = m_selection.GetHead();
  799. CDrawObjList* pObjects = pDoc->GetObjects();
  800. POSITION pos = pObjects->Find(pObj);
  801. ASSERT(pos != NULL);
  802. if (pos != pObjects->GetHeadPosition())
  803. {
  804. POSITION posPrev = pos;
  805. pObjects->GetPrev(posPrev);
  806. pObjects->RemoveAt(pos);
  807. pObjects->InsertBefore(posPrev, pObj);
  808. InvalObj(pObj);
  809. }
  810. }
  811. void CDrawView::OnObjectMoveForward()
  812. {
  813. CDrawDoc* pDoc = GetDocument();
  814. CDrawObj* pObj = m_selection.GetHead();
  815. CDrawObjList* pObjects = pDoc->GetObjects();
  816. POSITION pos = pObjects->Find(pObj);
  817. ASSERT(pos != NULL);
  818. if (pos != pObjects->GetTailPosition())
  819. {
  820. POSITION posNext = pos;
  821. pObjects->GetNext(posNext);
  822. pObjects->RemoveAt(pos);
  823. pObjects->InsertAfter(posNext, pObj);
  824. InvalObj(pObj);
  825. }
  826. }
  827. void CDrawView::OnObjectMoveToBack()
  828. {
  829. CDrawDoc* pDoc = GetDocument();
  830. CDrawObj* pObj = m_selection.GetHead();
  831. CDrawObjList* pObjects = pDoc->GetObjects();
  832. POSITION pos = pObjects->Find(pObj);
  833. ASSERT(pos != NULL);
  834. pObjects->RemoveAt(pos);
  835. pObjects->AddHead(pObj);
  836. InvalObj(pObj);
  837. }
  838. void CDrawView::OnObjectMoveToFront()
  839. {
  840. CDrawDoc* pDoc = GetDocument();
  841. CDrawObj* pObj = m_selection.GetHead();
  842. CDrawObjList* pObjects = pDoc->GetObjects();
  843. POSITION pos = pObjects->Find(pObj);
  844. ASSERT(pos != NULL);
  845. pObjects->RemoveAt(pos);
  846. pObjects->AddTail(pObj);
  847. InvalObj(pObj);
  848. }
  849. void CDrawView::OnEditCopy()
  850. {
  851. ASSERT_VALID(this);
  852. ASSERT(m_cfDraw != NULL);
  853. // Create a shared file and associate a CArchive with it
  854. CSharedFile file;
  855. CArchive ar(&file, CArchive::store);
  856. // Serialize selected objects to the archive
  857. m_selection.Serialize(ar);
  858. ar.Close();
  859. COleDataSource* pDataSource = NULL;
  860. TRY
  861. {
  862. pDataSource = new COleDataSource;
  863. // put on local format instead of or in addation to
  864. pDataSource->CacheGlobalData(m_cfDraw, file.Detach());
  865. // if only one item and it is a COleClientItem then also
  866. // paste in that format
  867. CDrawObj* pDrawObj = m_selection.GetHead();
  868. if (m_selection.GetCount() == 1 &&
  869. pDrawObj->IsKindOf(RUNTIME_CLASS(CDrawOleObj)))
  870. {
  871. CDrawOleObj* pDrawOle = (CDrawOleObj*)pDrawObj;
  872. pDrawOle->m_pClientItem->GetClipboardData(pDataSource, FALSE);
  873. }
  874. pDataSource->SetClipboard();
  875. }
  876. CATCH_ALL(e)
  877. {
  878. delete pDataSource;
  879. THROW_LAST();
  880. }
  881. END_CATCH_ALL
  882. }
  883. void CDrawView::OnUpdateEditCopy(CCmdUI* pCmdUI)
  884. {
  885. pCmdUI->Enable(!m_selection.IsEmpty());
  886. }
  887. void CDrawView::OnEditCut()
  888. {
  889. OnEditCopy();
  890. OnEditClear();
  891. }
  892. void CDrawView::OnUpdateEditCut(CCmdUI* pCmdUI)
  893. {
  894. pCmdUI->Enable(!m_selection.IsEmpty());
  895. }
  896. void CDrawView::OnEditPaste()
  897. {
  898. COleDataObject dataObject;
  899. dataObject.AttachClipboard();
  900. // invalidate current selection since it will be deselected
  901. OnUpdate(NULL, HINT_UPDATE_SELECTION, NULL);
  902. m_selection.RemoveAll();
  903. if (dataObject.IsDataAvailable(m_cfDraw))
  904. {
  905. PasteNative(dataObject);
  906. // now add all items in m_selection to document
  907. POSITION pos = m_selection.GetHeadPosition();
  908. while (pos != NULL)
  909. GetDocument()->Add(m_selection.GetNext(pos));
  910. }
  911. else
  912. PasteEmbedded(dataObject, GetInitialPosition().TopLeft() );
  913. GetDocument()->SetModifiedFlag();
  914. // invalidate new pasted stuff
  915. GetDocument()->UpdateAllViews(NULL, HINT_UPDATE_SELECTION, &m_selection);
  916. }
  917. void CDrawView::OnUpdateEditPaste(CCmdUI* pCmdUI)
  918. {
  919. // determine if private or standard OLE formats are on the clipboard
  920. COleDataObject dataObject;
  921. BOOL bEnable = dataObject.AttachClipboard() &&
  922. (dataObject.IsDataAvailable(m_cfDraw) ||
  923. COleClientItem::CanCreateFromData(&dataObject));
  924. // enable command based on availability
  925. pCmdUI->Enable(bEnable);
  926. }
  927. void CDrawView::OnFilePrint()
  928. {
  929. CScrollView::OnFilePrint();
  930. GetDocument()->ComputePageSize();
  931. }
  932. void CDrawView::OnViewShowObjects()
  933. {
  934. CDrawOleObj::c_bShowItems = !CDrawOleObj::c_bShowItems;
  935. GetDocument()->UpdateAllViews(NULL, HINT_UPDATE_OLE_ITEMS, NULL);
  936. }
  937. void CDrawView::OnUpdateViewShowObjects(CCmdUI* pCmdUI)
  938. {
  939. pCmdUI->SetCheck(CDrawOleObj::c_bShowItems);
  940. }
  941. void CDrawView::OnEditProperties()
  942. {
  943. if (m_selection.GetCount() == 1 && CDrawTool::c_drawShape == selection)
  944. {
  945. CDrawTool* pTool = CDrawTool::FindTool(CDrawTool::c_drawShape);
  946. ASSERT(pTool != NULL);
  947. pTool->OnEditProperties(this);
  948. }
  949. }
  950. void CDrawView::OnUpdateEditProperties(CCmdUI* pCmdUI)
  951. {
  952. pCmdUI->Enable(m_selection.GetCount() == 1 &&
  953. CDrawTool::c_drawShape == selection);
  954. }
  955. /////////////////////////////////////////////////////////////////////////////
  956. // CDrawView diagnostics
  957. #ifdef _DEBUG
  958. void CDrawView::AssertValid() const
  959. {
  960. CScrollView::AssertValid();
  961. }
  962. void CDrawView::Dump(CDumpContext& dc) const
  963. {
  964. CScrollView::Dump(dc);
  965. }
  966. #endif //_DEBUG
  967. /////////////////////////////////////////////////////////////////////////////
  968. // new
  969. // support for drag/drop
  970. int CDrawView::OnCreate(LPCREATESTRUCT lpCreateStruct)
  971. {
  972. if (CScrollView::OnCreate(lpCreateStruct) == -1)
  973. return -1;
  974. // register drop target
  975. if( m_dropTarget.Register( this ) )
  976. return 0;
  977. else
  978. return -1;
  979. }
  980. BOOL CDrawView::GetObjectInfo(COleDataObject* pDataObject,
  981. CSize* pSize, CSize* pOffset)
  982. {
  983. ASSERT(pSize != NULL);
  984. // get object descriptor data
  985. HGLOBAL hObjDesc = pDataObject->GetGlobalData(m_cfObjectDescriptor);
  986. if (hObjDesc == NULL)
  987. {
  988. if (pOffset != NULL)
  989. *pOffset = CSize(0, 0); // fill in defaults instead
  990. *pSize = CSize(0, 0);
  991. return FALSE;
  992. }
  993. ASSERT(hObjDesc != NULL);
  994. // otherwise, got CF_OBJECTDESCRIPTOR ok.  Lock it down and extract size.
  995. LPOBJECTDESCRIPTOR pObjDesc = (LPOBJECTDESCRIPTOR)GlobalLock(hObjDesc);
  996. ASSERT(pObjDesc != NULL);
  997. pSize->cx = (int)pObjDesc->sizel.cx;
  998. pSize->cy = (int)pObjDesc->sizel.cy;
  999. if (pOffset != NULL)
  1000. {
  1001. pOffset->cx = (int)pObjDesc->pointl.x;
  1002. pOffset->cy = (int)pObjDesc->pointl.y;
  1003. }
  1004. GlobalUnlock(hObjDesc);
  1005. GlobalFree(hObjDesc);
  1006. // successfully retrieved pSize & pOffset info
  1007. return TRUE;
  1008. }
  1009. DROPEFFECT CDrawView::OnDragEnter(COleDataObject* pDataObject,
  1010. DWORD grfKeyState, CPoint point)
  1011. {
  1012. ASSERT(m_prevDropEffect == DROPEFFECT_NONE);
  1013. m_bDragDataAcceptable = FALSE;
  1014. if (!COleClientItem::CanCreateFromData(pDataObject))
  1015. return DROPEFFECT_NONE;
  1016. m_bDragDataAcceptable = TRUE;
  1017. GetObjectInfo(pDataObject, &m_dragSize, &m_dragOffset);
  1018. CClientDC dc(NULL);
  1019. dc.HIMETRICtoDP(&m_dragSize);
  1020. dc.HIMETRICtoDP(&m_dragOffset);
  1021. return OnDragOver(pDataObject, grfKeyState, point);
  1022. }
  1023. DROPEFFECT CDrawView::OnDragOver(COleDataObject*,
  1024. DWORD grfKeyState, CPoint point)
  1025. {
  1026. if(m_bDragDataAcceptable == FALSE)
  1027. return DROPEFFECT_NONE;
  1028. point -= m_dragOffset;  // adjust target rect by original cursor offset
  1029. // check for point outside logical area -- i.e. in hatched region
  1030. // GetTotalSize() returns the size passed to SetScrollSizes
  1031. CRect rectScroll(CPoint(0, 0), GetTotalSize());
  1032. CRect rectItem(point,m_dragSize);
  1033. rectItem.OffsetRect(GetDeviceScrollPosition());
  1034. DROPEFFECT de = DROPEFFECT_NONE;
  1035. CRect rectTemp;
  1036. if (rectTemp.IntersectRect(rectScroll, rectItem))
  1037. {
  1038. // check for force link
  1039. if ((grfKeyState & (MK_CONTROL|MK_SHIFT)) == (MK_CONTROL|MK_SHIFT))
  1040. de = DROPEFFECT_NONE; // DRAWCLI isn't a linking container
  1041. // check for force copy
  1042. else if ((grfKeyState & MK_CONTROL) == MK_CONTROL)
  1043. de = DROPEFFECT_COPY;
  1044. // check for force move
  1045. else if ((grfKeyState & MK_ALT) == MK_ALT)
  1046. de = DROPEFFECT_MOVE;
  1047. // default -- recommended action is move
  1048. else
  1049. de = DROPEFFECT_MOVE;
  1050. }
  1051. if (point == m_dragPoint)
  1052. return de;
  1053. // otherwise, cursor has moved -- need to update the drag feedback
  1054. CClientDC dc(this);
  1055. if (m_prevDropEffect != DROPEFFECT_NONE)
  1056. {
  1057. // erase previous focus rect
  1058. dc.DrawFocusRect(CRect(m_dragPoint, m_dragSize));
  1059. }
  1060. m_prevDropEffect = de;
  1061. if (m_prevDropEffect != DROPEFFECT_NONE)
  1062. {
  1063. m_dragPoint = point;
  1064. dc.DrawFocusRect(CRect(point, m_dragSize));
  1065. }
  1066. return de;
  1067. }
  1068. BOOL CDrawView::OnDrop(COleDataObject* pDataObject,
  1069. DROPEFFECT /*dropEffect*/, CPoint point)
  1070. {
  1071. ASSERT_VALID(this);
  1072. // clean up focus rect
  1073. OnDragLeave();
  1074. // offset point as appropriate for dragging
  1075. GetObjectInfo(pDataObject, &m_dragSize, &m_dragOffset);
  1076. CClientDC dc(NULL);
  1077. dc.HIMETRICtoDP(&m_dragSize);
  1078. dc.HIMETRICtoDP(&m_dragOffset);
  1079. point -= m_dragOffset;
  1080. // invalidate current selection since it will be deselected
  1081. OnUpdate(NULL, HINT_UPDATE_SELECTION, NULL);
  1082. m_selection.RemoveAll();
  1083. if (m_bDragDataAcceptable)
  1084. PasteEmbedded(*pDataObject, point);
  1085. // update the document and views
  1086. GetDocument()->SetModifiedFlag();
  1087. GetDocument()->UpdateAllViews(NULL, 0, NULL);      // including this view
  1088. return TRUE;
  1089. }
  1090. void CDrawView::OnDragLeave()
  1091. {
  1092. CClientDC dc(this);
  1093. if (m_prevDropEffect != DROPEFFECT_NONE)
  1094. {
  1095. dc.DrawFocusRect(CRect(m_dragPoint,m_dragSize)); // erase previous focus rect
  1096. m_prevDropEffect = DROPEFFECT_NONE;
  1097. }
  1098. }
  1099. void CDrawView::OnContextMenu(CWnd* /*pWnd*/, CPoint point)
  1100. {
  1101. // make sure window is active
  1102. GetParentFrame()->ActivateFrame();
  1103. CPoint local = point;
  1104. ScreenToClient(&local);
  1105. ClientToDoc(local);
  1106. CDrawObj* pObj;
  1107. pObj = GetDocument()->ObjectAt(local);
  1108. if(pObj != NULL)
  1109. {
  1110. if(!IsSelected(pObj))
  1111. Select( pObj, FALSE );          // reselect item if appropriate
  1112. UpdateWindow();
  1113. CMenu menu;
  1114. if (menu.LoadMenu(ID_POPUP_MENU))
  1115. {
  1116. CMenu* pPopup = menu.GetSubMenu(0);
  1117. ASSERT(pPopup != NULL);
  1118. CXTPCommandBars::TrackPopupMenu(pPopup,
  1119. TPM_RIGHTBUTTON | TPM_LEFTALIGN,
  1120. point.x, point.y,
  1121. AfxGetMainWnd());
  1122. }
  1123. }
  1124. }
  1125. void CDrawView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
  1126. {
  1127. if (pInfo->m_bPreview == FALSE)
  1128. ((CDrawDoc*)GetDocument())->m_pSummInfo->RecordPrintDate();
  1129. OnDraw(pDC);
  1130. }