DRAWVW.CPP
上传用户:sesekoo
上传日期:2020-07-18
资源大小:21543k
文件大小:62k
源码类别:

界面编程

开发平台:

Visual C++

  1. // drawvw.cpp : implementation of the CDrawView class
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12. #include "stdafx.h"
  13. #include <afxpriv.h>
  14. #include "drawcli.h"
  15. #include "drawdoc.h"
  16. #include "drawobj.h"
  17. #include "cntritem.h"
  18. #include "drawvw.h"
  19. #include "drawobj.h"
  20. #include "drawtool.h"
  21. #include "mainfrm.h"
  22. #ifdef _DEBUG
  23. #undef THIS_FILE
  24. static char BASED_CODE THIS_FILE[] = __FILE__;
  25. #endif
  26. // private clipboard format (list of Draw objects)
  27. CLIPFORMAT CDrawView::m_cfDraw = (CLIPFORMAT)
  28. ::RegisterClipboardFormat(_T("MFC Draw Sample"));
  29. CLIPFORMAT CDrawView::m_cfObjectDescriptor = NULL;
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CDrawView
  32. IMPLEMENT_DYNCREATE (CDrawView, CScrollView )
  33. BEGIN_MESSAGE_MAP( CDrawView, CScrollView )
  34. //{{AFX_MSG_MAP(CDrawView)
  35. ON_COMMAND(ID_OLE_INSERT_NEW, OnInsertObject)
  36. ON_COMMAND(ID_CANCEL_EDIT, OnCancelEdit)
  37. ON_COMMAND(ID_CANCEL_EDIT_CNTR, OnCancelEditCntr)
  38. ON_COMMAND(ID_CANCEL_EDIT_SRVR, OnCancelEditSrvr)
  39. ON_WM_LBUTTONDOWN()
  40. ON_WM_LBUTTONUP()
  41. ON_WM_MOUSEMOVE()
  42. ON_WM_LBUTTONDBLCLK()
  43. ON_COMMAND(ID_DRAW_SELECT, OnDrawSelect)
  44. ON_COMMAND(ID_DRAW_ROUNDRECT, OnDrawRoundRect)
  45. ON_COMMAND(ID_DRAW_RECT, OnDrawRect)
  46. ON_COMMAND(ID_DRAW_LINE, OnDrawLine)
  47. ON_COMMAND(ID_DRAW_ELLIPSE, OnDrawEllipse)
  48. ON_UPDATE_COMMAND_UI(ID_DRAW_ELLIPSE, OnUpdateDrawEllipse)
  49. ON_UPDATE_COMMAND_UI(ID_DRAW_LINE, OnUpdateDrawLine)
  50. ON_UPDATE_COMMAND_UI(ID_DRAW_RECT, OnUpdateDrawRect)
  51. ON_UPDATE_COMMAND_UI(ID_DRAW_ROUNDRECT, OnUpdateDrawRoundRect)
  52. ON_UPDATE_COMMAND_UI(ID_DRAW_SELECT, OnUpdateDrawSelect)
  53. ON_UPDATE_COMMAND_UI(ID_OBJECT_MOVEBACK, OnUpdateSingleSelect)
  54. ON_COMMAND(ID_EDIT_SELECT_ALL, OnEditSelectAll)
  55. ON_COMMAND(ID_EDIT_CLEAR, OnEditClear)
  56. ON_UPDATE_COMMAND_UI(ID_EDIT_CLEAR, OnUpdateAnySelect)
  57. ON_COMMAND(ID_DRAW_POLYGON, OnDrawPolygon)
  58. ON_UPDATE_COMMAND_UI(ID_DRAW_POLYGON, OnUpdateDrawPolygon)
  59. ON_WM_SIZE()
  60. ON_COMMAND(ID_VIEW_GRID, OnViewGrid)
  61. ON_UPDATE_COMMAND_UI(ID_VIEW_GRID, OnUpdateViewGrid)
  62. ON_WM_ERASEBKGND()
  63. ON_COMMAND(ID_OBJECT_FILLCOLOR, OnObjectFillColor)
  64. ON_COMMAND(ID_OBJECT_LINECOLOR, OnObjectLineColor)
  65. ON_COMMAND(ID_OBJECT_MOVEBACK, OnObjectMoveBack)
  66. ON_COMMAND(ID_OBJECT_MOVEFORWARD, OnObjectMoveForward)
  67. ON_COMMAND(ID_OBJECT_MOVETOBACK, OnObjectMoveToBack)
  68. ON_COMMAND(ID_OBJECT_MOVETOFRONT, OnObjectMoveToFront)
  69. ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
  70. ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, OnUpdateEditCopy)
  71. ON_COMMAND(ID_EDIT_CUT, OnEditCut)
  72. ON_UPDATE_COMMAND_UI(ID_EDIT_CUT, OnUpdateEditCut)
  73. ON_COMMAND(ID_EDIT_PASTE, OnEditPaste)
  74. ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, OnUpdateEditPaste)
  75. ON_WM_SETFOCUS()
  76. ON_COMMAND(ID_VIEW_SHOWOBJECTS, OnViewShowObjects)
  77. ON_UPDATE_COMMAND_UI(ID_VIEW_SHOWOBJECTS, OnUpdateViewShowObjects)
  78. ON_COMMAND(ID_EDIT_PROPERTIES, OnEditProperties)
  79. ON_UPDATE_COMMAND_UI(ID_EDIT_PROPERTIES, OnUpdateEditProperties)
  80. ON_WM_DESTROY()
  81. ON_UPDATE_COMMAND_UI(ID_EDIT_SELECT_ALL, OnUpdateEditSelectAll)
  82. ON_WM_CREATE()
  83. ON_WM_CONTEXTMENU()
  84. ON_UPDATE_COMMAND_UI(ID_OBJECT_MOVEFORWARD, OnUpdateSingleSelect)
  85. ON_UPDATE_COMMAND_UI(ID_OBJECT_MOVETOBACK, OnUpdateSingleSelect)
  86. ON_UPDATE_COMMAND_UI(ID_OBJECT_MOVETOFRONT, OnUpdateSingleSelect)
  87. ON_UPDATE_COMMAND_UI(ID_DOC_LINE_WIDTH, OnUpdateDocLineWidth)
  88. //}}AFX_MSG_MAP
  89. ON_REGISTERED_MESSAGE(
  90. CExtPopupMenuWnd::g_nMsgPrepareOneMenuLevel,
  91. OnExtMenuPrepare
  92. )
  93. //  ON_UPDATE_COMMAND_UI(ID_OBJECT_MOVEBACK, OnUpdateSelectionSingle)
  94. //  ON_UPDATE_COMMAND_UI(ID_OBJECT_MOVEFORWARD, OnUpdateSelectionSingle)
  95. //  ON_UPDATE_COMMAND_UI(ID_OBJECT_MOVETOBACK, OnUpdateSelectionSingle)
  96. //  ON_UPDATE_COMMAND_UI(ID_OBJECT_MOVETOFRONT, OnUpdateSelectionSingle)
  97. ON_UPDATE_COMMAND_UI(ID_OBJECT_FILLCOLOR, OnUpdateSelectionNonEmpty)
  98. ON_UPDATE_COMMAND_UI(ID_OBJECT_LINECOLOR, OnUpdateSelectionNonEmpty)
  99. // color popup menu
  100. ON_REGISTERED_MESSAGE(
  101. CExtPopupColorMenuWnd::g_nMsgNotifyColorChangedFinally,
  102. OnColorChangedFinally
  103. )
  104. ON_REGISTERED_MESSAGE(
  105. CExtPopupColorMenuWnd::g_nMsgNotifyCustColor,
  106. OnColorSelectCustom
  107. )
  108. ON_COMMAND_RANGE(
  109. ID_LINE_WIDTH_0,
  110. ID_LINE_WIDTH_OTHER,
  111. OnLineWidth
  112. )
  113. ON_UPDATE_COMMAND_UI_RANGE(
  114. ID_LINE_WIDTH_0,
  115. ID_LINE_WIDTH_OTHER,
  116. OnUpdateLineWidth
  117. )
  118. ON_REGISTERED_MESSAGE(
  119. CExtPopupMenuWnd::g_nMsgPopupDrawItem,
  120. OnDrawPopupMenuItem
  121. )
  122. #if (defined __EXT_MFC_NO_PRINT)
  123. ON_COMMAND( ID_FILE_PRINT, OnFilePrint )
  124. ON_COMMAND( ID_FILE_PRINT_PREVIEW, OnFilePrintPreview )
  125. #endif
  126. END_MESSAGE_MAP()
  127. /////////////////////////////////////////////////////////////////////////////
  128. // CDrawView construction/destruction
  129. CDrawView::CDrawView()
  130. {
  131. m_bGrid = TRUE;
  132. m_gridColor = RGB(0, 0, 128);
  133. m_bActive = FALSE;
  134. // new
  135. if( m_cfObjectDescriptor == NULL )
  136. m_cfObjectDescriptor = (CLIPFORMAT)::RegisterClipboardFormat(_T("Object Descriptor") );
  137. m_prevDropEffect = DROPEFFECT_NONE;
  138. // end new
  139. }
  140. CDrawView::~CDrawView()
  141. {
  142. }
  143. BOOL CDrawView::PreCreateWindow(CREATESTRUCT& cs)
  144. {
  145. ASSERT(cs.style & WS_CHILD);
  146. if (cs.lpszClass == NULL)
  147. cs.lpszClass = AfxRegisterWndClass(CS_DBLCLKS);
  148. cs.dwExStyle &= ~(WS_EX_CLIENTEDGE|WS_EX_WINDOWEDGE|WS_EX_STATICEDGE);
  149. return TRUE;
  150. }
  151. void CDrawView::OnActivateView(BOOL bActivate, CView* pActiveView,
  152. CView* pDeactiveView)
  153. {
  154. CView::OnActivateView(bActivate, pActiveView, pDeactiveView);
  155. // invalidate selections when active status changes
  156. if (m_bActive != bActivate)
  157. {
  158. if( bActivate )  // if becoming active update as if active
  159. {
  160. m_bActive = bActivate;
  161. SyncToolbarObjButtons();
  162. }
  163. if (!m_selection.IsEmpty())
  164. OnUpdate(NULL, HINT_UPDATE_SELECTION, NULL);
  165. m_bActive = bActivate;
  166. }
  167. }
  168. /////////////////////////////////////////////////////////////////////////////
  169. // CDrawView drawing
  170. void CDrawView::InvalObj(CDrawObj* pObj)
  171. {
  172. CRect rect = pObj->m_position;
  173. DocToClient(rect);
  174. if (m_bActive && IsSelected(pObj))
  175. {
  176. rect.left -= 4;
  177. rect.top -= 5;
  178. rect.right += 5;
  179. rect.bottom += 4;
  180. }
  181. rect.InflateRect(1, 1); // handles CDrawOleObj objects
  182. InvalidateRect(rect, FALSE);
  183. }
  184. void CDrawView::OnUpdate(CView* , LPARAM lHint, CObject* pHint)
  185. {
  186. switch (lHint)
  187. {
  188. case HINT_UPDATE_WINDOW:    // redraw entire window
  189. Invalidate(FALSE);
  190. break;
  191. case HINT_UPDATE_DRAWOBJ:   // a single object has changed
  192. InvalObj((CDrawObj*)pHint);
  193. break;
  194. case HINT_UPDATE_SELECTION: // an entire selection has changed
  195. {
  196. CDrawObjList* pList = pHint != NULL ?
  197. (CDrawObjList*)pHint : &m_selection;
  198. POSITION pos = pList->GetHeadPosition();
  199. while (pos != NULL)
  200. InvalObj(pList->GetNext(pos));
  201. }
  202. break;
  203. case HINT_DELETE_SELECTION: // an entire selection has been removed
  204. if (pHint != &m_selection)
  205. {
  206. CDrawObjList* pList = (CDrawObjList*)pHint;
  207. POSITION pos = pList->GetHeadPosition();
  208. while (pos != NULL)
  209. {
  210. CDrawObj* pObj = pList->GetNext(pos);
  211. InvalObj(pObj);
  212. Remove(pObj);   // remove it from this view's selection
  213. }
  214. }
  215. break;
  216. case HINT_UPDATE_OLE_ITEMS:
  217. {
  218. CDrawDoc* pDoc = GetDocument();
  219. POSITION pos = pDoc->GetObjects()->GetHeadPosition();
  220. while (pos != NULL)
  221. {
  222. CDrawObj* pObj = pDoc->GetObjects()->GetNext(pos);
  223. if (pObj->IsKindOf(RUNTIME_CLASS(CDrawOleObj)))
  224. InvalObj(pObj);
  225. }
  226. }
  227. break;
  228. case HINT_UPDATE_TOOLBAR_COLOR_BUTTONS:
  229. {
  230. CWnd * pWndFocus = GetFocus();
  231. if( pWndFocus != NULL
  232. && (pWndFocus == this || IsChild(pWndFocus) )
  233. )
  234. SyncToolbarObjButtons();
  235. }
  236. break;
  237. default:
  238. ASSERT(FALSE);
  239. break;
  240. }
  241. }
  242. void CDrawView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
  243. {
  244. CScrollView :: OnPrepareDC( pDC, pInfo );
  245. // mapping mode is MM_ANISOTROPIC
  246. // these extents setup a mode similar to MM_LOENGLISH
  247. // MM_LOENGLISH is in .01 physical inches
  248. // these extents provide .01 logical inches
  249. pDC->SetMapMode(MM_ANISOTROPIC);
  250. pDC->SetViewportExt(
  251. ::GetDeviceCaps( pDC->m_hDC, LOGPIXELSX ),
  252. ::GetDeviceCaps( pDC->m_hDC, LOGPIXELSY )
  253. );
  254. pDC->SetWindowExt(100, -100);
  255. // set the origin of the coordinate system to the center of the page
  256. CPoint ptOrg;
  257. ptOrg.x = GetDocument()->GetSize().cx / 2;
  258. ptOrg.y = GetDocument()->GetSize().cy / 2;
  259. // ptOrg is in logical coordinates
  260. pDC->OffsetWindowOrg(-ptOrg.x,ptOrg.y);
  261. }
  262. BOOL CDrawView::OnScrollBy(CSize sizeScroll, BOOL bDoScroll)
  263. {
  264. // do the scroll
  265. if( ! __BASE_OF_CDrawView__ :: OnScrollBy( sizeScroll, bDoScroll ) )
  266. return FALSE;
  267. // update the position of any in-place active item
  268. if( bDoScroll )
  269. {
  270. UpdateActiveItem();
  271. UpdateWindow();
  272. }
  273. return TRUE;
  274. }
  275. void CDrawView::OnDraw(CDC* pDC)
  276. {
  277. CDrawDoc * pDoc = GetDocument();
  278. ASSERT_VALID(pDoc);
  279. CDC dc;
  280. CDC * pDrawDC = pDC;
  281. CBitmap bitmap;
  282. CBitmap * pOldBitmap = NULL;
  283. // only paint the rect that needs repainting
  284. CRect client;
  285. pDC->GetClipBox(client);
  286. CRect rect = client;
  287. DocToClient(rect);
  288. if( ! pDC->IsPrinting() )
  289. {
  290. ////////////////////////////////////////////////////////
  291. ////////////////////////////////////////////////////////
  292. // BEGIN: FIRST VERSION OF THE "TRASH-LINES" PROBLEM FIX
  293. GetClientRect( &rect );
  294. client = rect;
  295. ClientToDoc( client );
  296. pDC->SelectClipRgn( NULL );
  297. // END: FIRST VERSION OF THE "TRASH-LINES" PROBLEM FIX
  298. ////////////////////////////////////////////////////////
  299. ////////////////////////////////////////////////////////
  300. // draw to offscreen bitmap for fast looking repaints
  301. if( dc.CreateCompatibleDC( pDC ) )
  302. {
  303. if( bitmap.CreateCompatibleBitmap(
  304. pDC,
  305. rect.Width(),
  306. rect.Height()
  307. )
  308. )
  309. {
  310. OnPrepareDC(&dc, NULL);
  311. pDrawDC = &dc;
  312. // offset origin more because bitmap is just piece
  313. // of the whole drawing
  314. dc.OffsetViewportOrg( -rect.left, -rect.top );
  315. pOldBitmap = dc.SelectObject( &bitmap );
  316. dc.SetBrushOrg( rect.left % 8, rect.top % 8 );
  317. // might as well clip to the same rectangle
  318. dc.IntersectClipRect( client );
  319. }
  320. }
  321. }
  322. // paint background
  323. if( (! pDC->IsPrinting() ) && m_bGrid )
  324. {
  325. CBrush brush;
  326. if( ! brush.CreateSolidBrush( pDoc->GetPaperColor() ) )
  327. return;
  328. brush.UnrealizeObject();
  329. pDrawDC->FillRect( client, &brush );
  330. DrawGrid( pDrawDC );
  331. }
  332. pDoc->Draw( pDrawDC, this );
  333. if( pDrawDC != pDC )
  334. {
  335. pDC->SetViewportOrg( 0, 0 );
  336. pDC->SetWindowOrg( 0, 0 );
  337. pDC->SetMapMode( MM_TEXT );
  338. dc.SetViewportOrg( 0, 0 );
  339. dc.SetWindowOrg( 0, 0 );
  340. dc.SetMapMode( MM_TEXT );
  341. pDC->BitBlt(
  342. rect.left,
  343. rect.top,
  344. rect.Width(),
  345. rect.Height(),
  346. &dc,
  347. 0,
  348. 0,
  349. SRCCOPY
  350. );
  351. dc.SelectObject( pOldBitmap );
  352. }
  353. }
  354. void CDrawView::Remove(CDrawObj* pObj)
  355. {
  356. POSITION pos = m_selection.Find(pObj);
  357. if (pos != NULL)
  358. m_selection.RemoveAt(pos);
  359. }
  360. void CDrawView::PasteNative(COleDataObject& dataObject)
  361. {
  362. // get file refering to clipboard data
  363. CFile* pFile = dataObject.GetFileData(m_cfDraw);
  364. if (pFile == NULL)
  365. return;
  366. // connect the file to the archive
  367. CArchive ar(pFile, CArchive::load);
  368. TRY
  369. {
  370. ar.m_pDocument = GetDocument(); // set back-pointer in archive
  371. // read the selection
  372. m_selection.Serialize(ar);
  373. }
  374. CATCH_ALL(e)
  375. {
  376. ar.Close();
  377. delete pFile;
  378. THROW_LAST();
  379. }
  380. END_CATCH_ALL
  381. ar.Close();
  382. delete pFile;
  383. }
  384. void CDrawView::PasteEmbedded(COleDataObject& dataObject, CPoint point )
  385. {
  386. BeginWaitCursor();
  387. // paste embedded
  388. CDrawOleObj* pObj = new CDrawOleObj(GetInitialPosition());
  389. ASSERT_VALID(pObj);
  390. CDrawItem* pItem = new CDrawItem(GetDocument(), pObj);
  391. ASSERT_VALID(pItem);
  392. pObj->m_pClientItem = pItem;
  393. TRY
  394. {
  395. if (!pItem->CreateFromData(&dataObject) &&
  396. !pItem->CreateStaticFromData(&dataObject))
  397. {
  398. AfxThrowMemoryException();      // any exception will do
  399. }
  400. // add the object to the document
  401. GetDocument()->Add(pObj);
  402. m_selection.AddTail(pObj);
  403. ClientToDoc( point );
  404. pObj->MoveTo( CRect( point, pObj->m_extent ), this );
  405. // try to get initial presentation data
  406. pItem->UpdateLink();
  407. pItem->UpdateExtent();
  408. }
  409. CATCH_ALL(e)
  410. {
  411. // clean up item
  412. pItem->Delete();
  413. pObj->m_pClientItem = NULL;
  414. GetDocument()->Remove(pObj);
  415. pObj->Remove();
  416. AfxMessageBox(IDP_FAILED_TO_CREATE);
  417. }
  418. END_CATCH_ALL
  419. EndWaitCursor();
  420. }
  421. void CDrawView::DrawGrid(CDC* pDC)
  422. {
  423. CDrawDoc* pDoc = GetDocument();
  424. COLORREF oldBkColor = pDC->SetBkColor(pDoc->GetPaperColor());
  425. CRect rect;
  426. rect.left = -pDoc->GetSize().cx / 2;
  427. rect.top = -pDoc->GetSize().cy / 2;
  428. rect.right = rect.left + pDoc->GetSize().cx;
  429. rect.bottom = rect.top + pDoc->GetSize().cy;
  430. // Center lines
  431. CPen penDash;
  432. penDash.CreatePen(PS_DASH, 1, m_gridColor);
  433. CPen* pOldPen = pDC->SelectObject(&penDash);
  434. pDC->MoveTo(0, rect.top);
  435. pDC->LineTo(0, rect.bottom);
  436. pDC->MoveTo(rect.left, 0);
  437. pDC->LineTo(rect.right, 0);
  438. // Major unit lines
  439. CPen penDot;
  440. penDot.CreatePen(PS_DOT, 1, m_gridColor);
  441. pDC->SelectObject(&penDot);
  442. for (int x = rect.left / 100 * 100; x < rect.right; x += 100)
  443. {
  444. if (x != 0)
  445. {
  446. pDC->MoveTo(x, rect.top);
  447. pDC->LineTo(x, rect.bottom);
  448. }
  449. }
  450. for (int y = rect.top / 100 * 100; y < rect.bottom; y += 100)
  451. {
  452. if (y != 0)
  453. {
  454. pDC->MoveTo(rect.left, y);
  455. pDC->LineTo(rect.right, y);
  456. }
  457. }
  458. // Outlines
  459. CPen penSolid;
  460. penSolid.CreatePen(PS_SOLID, 1, m_gridColor);
  461. pDC->SelectObject(&penSolid);
  462. pDC->MoveTo(rect.left, rect.top);
  463. pDC->LineTo(rect.right, rect.top);
  464. pDC->LineTo(rect.right, rect.bottom);
  465. pDC->LineTo(rect.left, rect.bottom);
  466. pDC->LineTo(rect.left, rect.top);
  467. pDC->SelectObject(pOldPen);
  468. pDC->SetBkColor(oldBkColor);
  469. }
  470. void CDrawView::OnInitialUpdate()
  471. {
  472. CSize size = GetDocument()->GetSize();
  473. CClientDC dc(NULL);
  474. size.cx =
  475. MulDiv(
  476. size.cx,
  477. ::GetDeviceCaps( dc.m_hDC, LOGPIXELSX ),
  478. 100
  479. );
  480. size.cy =
  481. MulDiv(
  482. size.cy,
  483. ::GetDeviceCaps( dc.m_hDC, LOGPIXELSY ),
  484. 100
  485. );
  486. SetScrollSizes( MM_TEXT, size, sizeDefault, CSize( 1, 1 ) );
  487. }
  488. void CDrawView::SetPageSize(CSize size)
  489. {
  490. CClientDC dc(NULL);
  491. size.cx =
  492. MulDiv(
  493. size.cx,
  494. ::GetDeviceCaps( dc.m_hDC, LOGPIXELSX ),
  495. 100
  496. );
  497. size.cy =
  498. MulDiv(
  499. size.cy,
  500. ::GetDeviceCaps( dc.m_hDC, LOGPIXELSY ),
  501. 100
  502. );
  503. SetScrollSizes(MM_TEXT, size);
  504. GetDocument()->UpdateAllViews(NULL, HINT_UPDATE_WINDOW, NULL);
  505. }
  506. /////////////////////////////////////////////////////////////////////////////
  507. // CDrawView printing
  508. BOOL CDrawView::OnPreparePrinting(CPrintInfo* pInfo)
  509. {
  510. if( ! DoPreparePrinting( pInfo ) )
  511. return FALSE;
  512. WORD nPageNoMin = 1, nPageNoMax = 1;
  513. pInfo->m_nNumPreviewPages    = nPageNoMax;
  514. pInfo->m_pPD->m_pd.nMinPage  = nPageNoMin;
  515. pInfo->m_pPD->m_pd.nFromPage = nPageNoMin;
  516. pInfo->m_pPD->m_pd.nMaxPage  = nPageNoMax;
  517. pInfo->m_pPD->m_pd.nToPage   = nPageNoMax;
  518. return TRUE;
  519. }
  520. void CDrawView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
  521. {
  522. CScrollView :: OnBeginPrinting( pDC, pInfo );
  523. // check page size -- user could have gone into print setup
  524. // from print dialog and changed paper or orientation
  525. GetDocument()->ComputePageSize();
  526. }
  527. void CDrawView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  528. {
  529. // TODO: add cleanup after printing
  530. }
  531. /////////////////////////////////////////////////////////////////////////////
  532. // OLE Client support and commands
  533. BOOL CDrawView::IsSelected(const CObject* pDocItem) const
  534. {
  535. CDrawObj* pDrawObj = (CDrawObj*)pDocItem;
  536. if (pDocItem->IsKindOf(RUNTIME_CLASS(CDrawItem)))
  537. pDrawObj = ((CDrawItem*)pDocItem)->m_pDrawObj;
  538. return m_selection.Find(pDrawObj) != NULL;
  539. }
  540. void CDrawView::OnInsertObject()
  541. {
  542. // Invoke the standard Insert Object dialog box to obtain information
  543. //  for new CDrawItem object.
  544. COleInsertDialog dlgOleInsert;
  545. if( dlgOleInsert.DoModal() != IDOK )
  546. return;
  547. BeginWaitCursor();
  548. // First create the C++ object
  549. CDrawOleObj* pObj = new CDrawOleObj(GetInitialPosition());
  550. ASSERT_VALID(pObj);
  551. CDrawItem* pItem = new CDrawItem(GetDocument(), pObj);
  552. ASSERT_VALID(pItem);
  553. pObj->m_pClientItem = pItem;
  554. // Now create the OLE object/item
  555. TRY
  556. {
  557. if( ! dlgOleInsert.CreateItem(pObj->m_pClientItem ) )
  558. AfxThrowMemoryException();
  559. // add the object to the document
  560. GetDocument()->Add(pObj);
  561. // try to get initial presentation data
  562. pItem->UpdateLink();
  563. pItem->UpdateExtent();
  564. // if insert new object -- initially show the object
  565. if (dlgOleInsert.GetSelectionType() == COleInsertDialog::createNewItem)
  566. pItem->DoVerb(OLEIVERB_SHOW, this);
  567. }
  568. CATCH_ALL(e)
  569. {
  570. // clean up item
  571. pItem->Delete();
  572. pObj->m_pClientItem = NULL;
  573. GetDocument()->Remove(pObj);
  574. pObj->Remove();
  575. AfxMessageBox(IDP_FAILED_TO_CREATE);
  576. }
  577. END_CATCH_ALL
  578. EndWaitCursor();
  579. }
  580. // The following command handler provides the standard keyboard
  581. //  user interface to cancel an in-place editing session.
  582. void CDrawView::OnCancelEdit()
  583. {
  584. // deactivate any in-place active item on this view!
  585. COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
  586. if (pActiveItem != NULL)
  587. {
  588. // if we found one, deactivate it
  589. pActiveItem->Close();
  590. }
  591. ASSERT(GetDocument()->GetInPlaceActiveItem(this) == NULL);
  592. // escape also brings us back into select mode
  593. ReleaseCapture();
  594. CDrawTool* pTool = CDrawTool::FindTool(CDrawTool::c_drawShape);
  595. if (pTool != NULL)
  596. pTool->OnCancel();
  597. CDrawTool::c_drawShape = selection;
  598. }
  599. void CDrawView::OnSetFocus(CWnd* pOldWnd)
  600. {
  601. COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
  602. if (pActiveItem != NULL &&
  603. pActiveItem->GetItemState() == COleClientItem::activeUIState)
  604. {
  605. // need to set focus to this item if it is in the same view
  606. CWnd* pWnd = pActiveItem->GetInPlaceWindow();
  607. if (pWnd != NULL)
  608. {
  609. pWnd->SetFocus();
  610. return;
  611. }
  612. }
  613. __BASE_OF_CDrawView__ :: OnSetFocus( pOldWnd );
  614. }
  615. CRect CDrawView::GetInitialPosition()
  616. {
  617. CRect rect(10, 10, 10, 10);
  618. ClientToDoc(rect);
  619. return rect;
  620. }
  621. void CDrawView::ClientToDoc(CPoint& point)
  622. {
  623. CClientDC dc(this);
  624. OnPrepareDC(&dc, NULL);
  625. dc.DPtoLP(&point);
  626. }
  627. void CDrawView::ClientToDoc(CRect& rect)
  628. {
  629. CClientDC dc(this);
  630. OnPrepareDC(&dc, NULL);
  631. dc.DPtoLP(rect);
  632. ASSERT(rect.left <= rect.right);
  633. ASSERT(rect.bottom <= rect.top);
  634. }
  635. void CDrawView::DocToClient(CPoint& point)
  636. {
  637. CClientDC dc(this);
  638. OnPrepareDC(&dc, NULL);
  639. dc.LPtoDP(&point);
  640. }
  641. void CDrawView::DocToClient(CRect& rect)
  642. {
  643. CClientDC dc(this);
  644. OnPrepareDC(&dc, NULL);
  645. dc.LPtoDP(rect);
  646. rect.NormalizeRect();
  647. }
  648. void CDrawView::Select(CDrawObj* pObj, BOOL bAdd)
  649. {
  650. if (!bAdd)
  651. {
  652. OnUpdate(NULL, HINT_UPDATE_SELECTION, NULL);
  653. m_selection.RemoveAll();
  654. }
  655. if (pObj == NULL || IsSelected(pObj))
  656. return;
  657. m_selection.AddTail(pObj);
  658. InvalObj(pObj);
  659. }
  660. // rect is in device coordinates
  661. void CDrawView::SelectWithinRect(CRect rect, BOOL bAdd)
  662. {
  663. if (!bAdd)
  664. Select(NULL);
  665. ClientToDoc(rect);
  666. CDrawObjList* pObList = GetDocument()->GetObjects();
  667. POSITION posObj = pObList->GetHeadPosition();
  668. while (posObj != NULL)
  669. {
  670. CDrawObj* pObj = pObList->GetNext(posObj);
  671. if (pObj->Intersects(rect))
  672. Select(pObj, TRUE);
  673. }
  674. }
  675. void CDrawView::Deselect(CDrawObj* pObj)
  676. {
  677. POSITION pos = m_selection.Find(pObj);
  678. if (pos != NULL)
  679. {
  680. InvalObj(pObj);
  681. m_selection.RemoveAt(pos);
  682. }
  683. }
  684. void CDrawView::CloneSelection()
  685. {
  686. POSITION pos = m_selection.GetHeadPosition();
  687. while (pos != NULL)
  688. {
  689. CDrawObj* pObj = m_selection.GetNext(pos);
  690. pObj->Clone(pObj->m_pDocument);
  691. // copies object and adds it to the document
  692. }
  693. }
  694. void CDrawView::UpdateActiveItem()
  695. {
  696. COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
  697. if (pActiveItem != NULL &&
  698. pActiveItem->GetItemState() == COleClientItem::activeUIState)
  699. {
  700. // this will update the item rectangles by calling
  701. //  OnGetPosRect & OnGetClipRect.
  702. pActiveItem->SetItemRects();
  703. }
  704. }
  705. /////////////////////////////////////////////////////////////////////////////
  706. // CDrawView message handlers
  707. void CDrawView::OnLButtonDown(UINT nFlags, CPoint point)
  708. {
  709. if (!m_bActive)
  710. return;
  711. CDrawTool* pTool = CDrawTool::FindTool(CDrawTool::c_drawShape);
  712. if (pTool != NULL)
  713. pTool->OnLButtonDown(this, nFlags, point);
  714. SyncToolbarObjButtons();
  715. }
  716. void CDrawView::OnLButtonUp(UINT nFlags, CPoint point)
  717. {
  718. if (!m_bActive)
  719. return;
  720. CDrawTool* pTool = CDrawTool::FindTool(CDrawTool::c_drawShape);
  721. if (pTool != NULL)
  722. pTool->OnLButtonUp(this, nFlags, point);
  723. SyncToolbarObjButtons();
  724. }
  725. void CDrawView::OnMouseMove(UINT nFlags, CPoint point)
  726. {
  727. if (!m_bActive)
  728. return;
  729. CDrawTool* pTool = CDrawTool::FindTool(CDrawTool::c_drawShape);
  730. if (pTool != NULL)
  731. pTool->OnMouseMove(this, nFlags, point);
  732. }
  733. void CDrawView::OnLButtonDblClk(UINT nFlags, CPoint point)
  734. {
  735. if (!m_bActive)
  736. return;
  737. CDrawTool* pTool = CDrawTool::FindTool(CDrawTool::c_drawShape);
  738. if (pTool != NULL)
  739. pTool->OnLButtonDblClk(this, nFlags, point);
  740. }
  741. void CDrawView::OnDestroy()
  742. {
  743. __BASE_OF_CDrawView__ :: OnDestroy();
  744. // deactivate the inplace active item on this view
  745. COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
  746. if (pActiveItem != NULL && pActiveItem->GetActiveView() == this)
  747. {
  748. pActiveItem->Deactivate();
  749. ASSERT(GetDocument()->GetInPlaceActiveItem(this) == NULL);
  750. }
  751. }
  752. void CDrawView::OnDrawSelect()
  753. {
  754. CDrawTool::c_drawShape = selection;
  755. }
  756. void CDrawView::OnDrawRoundRect()
  757. {
  758. CDrawTool::c_drawShape = roundRect;
  759. }
  760. void CDrawView::OnDrawRect()
  761. {
  762. CDrawTool::c_drawShape = rect;
  763. }
  764. void CDrawView::OnDrawLine()
  765. {
  766. CDrawTool::c_drawShape = line;
  767. }
  768. void CDrawView::OnDrawEllipse()
  769. {
  770. CDrawTool::c_drawShape = ellipse;
  771. }
  772. void CDrawView::OnDrawPolygon()
  773. {
  774. CDrawTool::c_drawShape = poly;
  775. }
  776. void CDrawView::OnUpdateDrawEllipse(CCmdUI* pCmdUI)
  777. {
  778. if( IsPrintPreviewMode() )
  779. {
  780. pCmdUI->SetRadio();
  781. pCmdUI->Enable( FALSE );
  782. return;
  783. }
  784. pCmdUI->SetRadio(CDrawTool::c_drawShape == ellipse);
  785. }
  786. void CDrawView::OnUpdateDrawLine(CCmdUI* pCmdUI)
  787. {
  788. if( IsPrintPreviewMode() )
  789. {
  790. pCmdUI->SetRadio();
  791. pCmdUI->Enable( FALSE );
  792. return;
  793. }
  794. pCmdUI->SetRadio(CDrawTool::c_drawShape == line);
  795. }
  796. void CDrawView::OnUpdateDrawRect(CCmdUI* pCmdUI)
  797. {
  798. if( IsPrintPreviewMode() )
  799. {
  800. pCmdUI->SetRadio();
  801. pCmdUI->Enable( FALSE );
  802. return;
  803. }
  804. pCmdUI->SetRadio(CDrawTool::c_drawShape == rect);
  805. }
  806. void CDrawView::OnUpdateDrawRoundRect(CCmdUI* pCmdUI)
  807. {
  808. if( IsPrintPreviewMode() )
  809. {
  810. pCmdUI->SetRadio();
  811. pCmdUI->Enable( FALSE );
  812. return;
  813. }
  814. pCmdUI->SetRadio(CDrawTool::c_drawShape == roundRect);
  815. }
  816. void CDrawView::OnUpdateDrawSelect(CCmdUI* pCmdUI)
  817. {
  818. if( IsPrintPreviewMode() )
  819. {
  820. pCmdUI->SetRadio();
  821. pCmdUI->Enable( FALSE );
  822. return;
  823. }
  824. pCmdUI->Enable();
  825. pCmdUI->SetRadio(CDrawTool::c_drawShape == selection);
  826. }
  827. void CDrawView::OnUpdateSingleSelect(CCmdUI* pCmdUI)
  828. {
  829. if( IsPrintPreviewMode() )
  830. {
  831. pCmdUI->SetCheck( 0 );
  832. return;
  833. }
  834. pCmdUI->Enable( m_selection.GetCount() == 1 && GetDocument()->GetObjects()->GetCount() > 1 );
  835. }
  836. void CDrawView::OnEditSelectAll()
  837. {
  838. CDrawObjList* pObList = GetDocument()->GetObjects();
  839. POSITION pos = pObList->GetHeadPosition();
  840. while (pos != NULL)
  841. Select(pObList->GetNext(pos), TRUE);
  842. }
  843. void CDrawView::OnUpdateEditSelectAll(CCmdUI* pCmdUI)
  844. {
  845. if( IsPrintPreviewMode() )
  846. {
  847. pCmdUI->Enable( FALSE );
  848. return;
  849. }
  850. pCmdUI->Enable(GetDocument()->GetObjects()->GetCount() != 0);
  851. }
  852. void CDrawView::OnEditClear()
  853. {
  854. // update all the views before the selection goes away
  855. GetDocument()->UpdateAllViews(NULL, HINT_DELETE_SELECTION, &m_selection);
  856. OnUpdate(NULL, HINT_UPDATE_SELECTION, NULL);
  857. // now remove the selection from the document
  858. POSITION pos = m_selection.GetHeadPosition();
  859. while (pos != NULL)
  860. {
  861. CDrawObj* pObj = m_selection.GetNext(pos);
  862. GetDocument()->Remove(pObj);
  863. pObj->Remove();
  864. }
  865. m_selection.RemoveAll();
  866. }
  867. void CDrawView::OnUpdateAnySelect(CCmdUI* pCmdUI)
  868. {
  869. if( IsPrintPreviewMode() )
  870. {
  871. pCmdUI->Enable( FALSE );
  872. return;
  873. }
  874. pCmdUI->Enable(!m_selection.IsEmpty());
  875. }
  876. void CDrawView::OnUpdateDrawPolygon(CCmdUI* pCmdUI)
  877. {
  878. if( IsPrintPreviewMode() )
  879. {
  880. pCmdUI->SetRadio();
  881. pCmdUI->Enable( FALSE );
  882. return;
  883. }
  884. pCmdUI->SetRadio(CDrawTool::c_drawShape == poly);
  885. }
  886. void CDrawView::OnSize(UINT nType, int cx, int cy)
  887. {
  888. __BASE_OF_CDrawView__ :: OnSize( nType, cx, cy );
  889. UpdateActiveItem();
  890. // if( m_wndScrollBarH.GetSafeHwnd() != NULL
  891. // || m_wndScrollBarV.GetSafeHwnd() != NULL
  892. // )
  893. // RepositionBars( 0, 0xFFFF, 0 );
  894. }
  895. void CDrawView::OnViewGrid()
  896. {
  897. m_bGrid = !m_bGrid;
  898. Invalidate(FALSE);
  899. }
  900. void CDrawView::OnUpdateViewGrid(CCmdUI* pCmdUI)
  901. {
  902. if( IsPrintPreviewMode() )
  903. {
  904. pCmdUI->SetCheck( 0 );
  905. pCmdUI->Enable( FALSE );
  906. return;
  907. }
  908. pCmdUI->Enable();
  909. pCmdUI->SetCheck(m_bGrid);
  910. }
  911. BOOL CDrawView::OnEraseBkgnd( CDC * pDC )
  912. {
  913. pDC;
  914. return TRUE;
  915. }
  916. void CDrawView::OnObjectFillColor()
  917. {
  918. int nSelCount = int( m_selection.GetCount() );
  919. if( nSelCount == 0 )
  920. {
  921. ASSERT( FALSE ); // should be disabled
  922. return;
  923. }
  924. POSITION pos = m_selection.GetHeadPosition();
  925. ASSERT( pos != NULL );
  926. CDrawObj * pObj = m_selection.GetNext( pos );
  927. ASSERT( pObj != NULL );
  928. CExtColorDlg dlgColor;
  929. dlgColor.m_clrInit
  930. = dlgColor.m_clrNew
  931. = pObj->GetFillColor();
  932. VERIFY(
  933. dlgColor.m_strCaption.LoadString( ID_OBJECT_FILLCOLOR )
  934. );
  935. if( dlgColor.DoModal() != IDOK )
  936. return;
  937. pos = m_selection.GetHeadPosition();
  938. ASSERT( pos != NULL );
  939. while( pos != NULL )
  940. {
  941. pObj = m_selection.GetNext( pos );
  942. ASSERT( pObj != NULL );
  943. pObj->SetNoFill( FALSE );
  944. pObj->SetFillColor( dlgColor.m_clrNew );
  945. }
  946. SyncToolbarObjButtons();
  947. }
  948. void CDrawView::OnObjectLineColor()
  949. {
  950. int nSelCount = int( m_selection.GetCount() );
  951. if( nSelCount == 0 )
  952. {
  953. ASSERT( FALSE ); // should be disabled
  954. return;
  955. }
  956. POSITION pos = m_selection.GetHeadPosition();
  957. ASSERT( pos != NULL );
  958. CDrawObj * pObj = m_selection.GetNext( pos );
  959. ASSERT( pObj != NULL );
  960. CExtColorDlg dlgColor;
  961. dlgColor.m_clrInit
  962. = dlgColor.m_clrNew
  963. = pObj->GetLineColor();
  964. VERIFY(
  965. dlgColor.m_strCaption.LoadString( ID_OBJECT_LINECOLOR )
  966. );
  967. if( dlgColor.DoModal() != IDOK )
  968. return;
  969. pos = m_selection.GetHeadPosition();
  970. ASSERT( pos != NULL );
  971. while( pos != NULL )
  972. {
  973. pObj = m_selection.GetNext( pos );
  974. ASSERT( pObj != NULL );
  975. pObj->SetNoOutline( FALSE );
  976. pObj->SetLineColor( dlgColor.m_clrNew );
  977. }
  978. SyncToolbarObjButtons();
  979. }
  980. void CDrawView::OnObjectMoveBack()
  981. {
  982. CDrawDoc* pDoc = GetDocument();
  983. CDrawObj* pObj = m_selection.GetHead();
  984. CDrawObjList* pObjects = pDoc->GetObjects();
  985. POSITION pos = pObjects->Find(pObj);
  986. ASSERT(pos != NULL);
  987. if (pos != pObjects->GetHeadPosition())
  988. {
  989. POSITION posPrev = pos;
  990. pObjects->GetPrev(posPrev);
  991. pObjects->RemoveAt(pos);
  992. pObjects->InsertBefore(posPrev, pObj);
  993. InvalObj(pObj);
  994. }
  995. }
  996. void CDrawView::OnObjectMoveForward()
  997. {
  998. CDrawDoc* pDoc = GetDocument();
  999. CDrawObj* pObj = m_selection.GetHead();
  1000. CDrawObjList* pObjects = pDoc->GetObjects();
  1001. POSITION pos = pObjects->Find(pObj);
  1002. ASSERT(pos != NULL);
  1003. if (pos != pObjects->GetTailPosition())
  1004. {
  1005. POSITION posNext = pos;
  1006. pObjects->GetNext(posNext);
  1007. pObjects->RemoveAt(pos);
  1008. pObjects->InsertAfter(posNext, pObj);
  1009. InvalObj(pObj);
  1010. }
  1011. }
  1012. void CDrawView::OnObjectMoveToBack()
  1013. {
  1014. CDrawDoc* pDoc = GetDocument();
  1015. CDrawObj* pObj = m_selection.GetHead();
  1016. CDrawObjList* pObjects = pDoc->GetObjects();
  1017. POSITION pos = pObjects->Find(pObj);
  1018. ASSERT(pos != NULL);
  1019. pObjects->RemoveAt(pos);
  1020. pObjects->AddHead(pObj);
  1021. InvalObj(pObj);
  1022. }
  1023. void CDrawView::OnObjectMoveToFront()
  1024. {
  1025. CDrawDoc* pDoc = GetDocument();
  1026. CDrawObj* pObj = m_selection.GetHead();
  1027. CDrawObjList* pObjects = pDoc->GetObjects();
  1028. POSITION pos = pObjects->Find(pObj);
  1029. ASSERT(pos != NULL);
  1030. pObjects->RemoveAt(pos);
  1031. pObjects->AddTail(pObj);
  1032. InvalObj(pObj);
  1033. }
  1034. void CDrawView::OnEditCopy()
  1035. {
  1036. ASSERT_VALID(this);
  1037. ASSERT(m_cfDraw != NULL);
  1038. // Create a shared file and associate a CArchive with it
  1039. CSharedFile file;
  1040. CArchive ar(&file, CArchive::store);
  1041. // Serialize selected objects to the archive
  1042. m_selection.Serialize(ar);
  1043. ar.Close();
  1044. COleDataSource* pDataSource = NULL;
  1045. TRY
  1046. {
  1047. pDataSource = new COleDataSource;
  1048. // put on local format instead of or in addation to
  1049. pDataSource->CacheGlobalData(m_cfDraw, file.Detach());
  1050. // if only one item and it is a COleClientItem then also
  1051. // paste in that format
  1052. CDrawObj* pDrawObj = m_selection.GetHead();
  1053. if (m_selection.GetCount() == 1 &&
  1054. pDrawObj->IsKindOf(RUNTIME_CLASS(CDrawOleObj)))
  1055. {
  1056. CDrawOleObj* pDrawOle = (CDrawOleObj*)pDrawObj;
  1057. pDrawOle->m_pClientItem->GetClipboardData(pDataSource, FALSE);
  1058. }
  1059. pDataSource->SetClipboard();
  1060. }
  1061. CATCH_ALL(e)
  1062. {
  1063. delete pDataSource;
  1064. THROW_LAST();
  1065. }
  1066. END_CATCH_ALL
  1067. }
  1068. void CDrawView::OnUpdateEditCopy(CCmdUI* pCmdUI)
  1069. {
  1070. if( IsPrintPreviewMode() )
  1071. {
  1072. pCmdUI->Enable( FALSE );
  1073. return;
  1074. }
  1075. pCmdUI->Enable(!m_selection.IsEmpty());
  1076. }
  1077. void CDrawView::OnEditCut()
  1078. {
  1079. OnEditCopy();
  1080. OnEditClear();
  1081. OnDrawSelect();
  1082. }
  1083. void CDrawView::OnUpdateEditCut(CCmdUI* pCmdUI)
  1084. {
  1085. if( IsPrintPreviewMode() )
  1086. {
  1087. pCmdUI->Enable( FALSE );
  1088. return;
  1089. }
  1090. pCmdUI->Enable(!m_selection.IsEmpty());
  1091. }
  1092. void CDrawView::OnEditPaste()
  1093. {
  1094. COleDataObject dataObject;
  1095. dataObject.AttachClipboard();
  1096. // invalidate current selection since it will be deselected
  1097. OnUpdate(NULL, HINT_UPDATE_SELECTION, NULL);
  1098. m_selection.RemoveAll();
  1099. if (dataObject.IsDataAvailable(m_cfDraw))
  1100. {
  1101. PasteNative(dataObject);
  1102. // now add all items in m_selection to document
  1103. POSITION pos = m_selection.GetHeadPosition();
  1104. while (pos != NULL)
  1105. GetDocument()->Add(m_selection.GetNext(pos));
  1106. }
  1107. else
  1108. PasteEmbedded(dataObject, GetInitialPosition().TopLeft() );
  1109. GetDocument()->SetModifiedFlag();
  1110. // invalidate new pasted stuff
  1111. GetDocument()->UpdateAllViews(NULL, HINT_UPDATE_SELECTION, &m_selection);
  1112. }
  1113. void CDrawView::OnUpdateEditPaste(CCmdUI* pCmdUI)
  1114. {
  1115. if( IsPrintPreviewMode() )
  1116. {
  1117. pCmdUI->Enable( FALSE );
  1118. return;
  1119. }
  1120. // determine if private or standard OLE formats are on the clipboard
  1121. COleDataObject dataObject;
  1122. BOOL bEnable = dataObject.AttachClipboard() &&
  1123. (dataObject.IsDataAvailable(m_cfDraw) ||
  1124.  COleClientItem::CanCreateFromData(&dataObject));
  1125. // enable command based on availability
  1126. pCmdUI->Enable(bEnable);
  1127. }
  1128. void CDrawView::OnViewShowObjects()
  1129. {
  1130. CDrawOleObj::c_bShowItems = !CDrawOleObj::c_bShowItems;
  1131. GetDocument()->UpdateAllViews(NULL, HINT_UPDATE_OLE_ITEMS, NULL);
  1132. }
  1133. void CDrawView::OnUpdateViewShowObjects(CCmdUI* pCmdUI)
  1134. {
  1135. if( IsPrintPreviewMode() )
  1136. {
  1137. pCmdUI->SetCheck( 0 );
  1138. pCmdUI->Enable( FALSE );
  1139. return;
  1140. }
  1141. pCmdUI->Enable();
  1142. pCmdUI->SetCheck(CDrawOleObj::c_bShowItems);
  1143. }
  1144. void CDrawView::OnEditProperties()
  1145. {
  1146. if (m_selection.GetCount() == 1 && CDrawTool::c_drawShape == selection)
  1147. {
  1148. CDrawTool* pTool =
  1149. CDrawTool::FindTool(
  1150. CDrawTool::c_drawShape
  1151. );
  1152. ASSERT(pTool != NULL);
  1153. pTool->OnEditProperties(this);
  1154. }
  1155. }
  1156. void CDrawView::OnUpdateEditProperties(CCmdUI* pCmdUI)
  1157. {
  1158. if( IsPrintPreviewMode() )
  1159. {
  1160. pCmdUI->Enable( FALSE );
  1161. return;
  1162. }
  1163. pCmdUI->Enable( m_selection.GetCount() == 1 && CDrawTool::c_drawShape == selection );
  1164. }
  1165. /////////////////////////////////////////////////////////////////////////////
  1166. // CDrawView diagnostics
  1167. #ifdef _DEBUG
  1168. void CDrawView::AssertValid() const
  1169. {
  1170. __BASE_OF_CDrawView__ :: AssertValid();
  1171. }
  1172. void CDrawView::Dump(CDumpContext& dc) const
  1173. {
  1174. __BASE_OF_CDrawView__ :: Dump( dc );
  1175. }
  1176. #endif //_DEBUG
  1177. /////////////////////////////////////////////////////////////////////////////
  1178. // new
  1179. // support for drag/drop
  1180. int CDrawView::OnCreate(LPCREATESTRUCT lpCreateStruct)
  1181. {
  1182. if( __BASE_OF_CDrawView__ :: OnCreate( lpCreateStruct ) == -1 )
  1183. return -1;
  1184. //CFrameWnd * pWndFrame = GetParentFrame();
  1185. // if( pWndFrame == NULL
  1186. // || (! pWndFrame->IsKindOf( RUNTIME_CLASS(CMDIChildWnd) ) )
  1187. // || pWndFrame->IsKindOf( RUNTIME_CLASS(CDrawInPlaceFrame) )
  1188. // )
  1189. // {
  1190. // m_wndScrollBarH.m_eSO = CExtScrollBar::__ESO_BOTTOM;
  1191. // m_wndScrollBarV.m_eSO = CExtScrollBar::__ESO_RIGHT;
  1192. // if( ! m_wndScrollBarV.Create(
  1193. // WS_CHILD|WS_VISIBLE|SBS_VERT|SBS_RIGHTALIGN,
  1194. // CRect(0,0,0,0),
  1195. // this,
  1196. // 1
  1197. // )
  1198. // )
  1199. // {
  1200. // ASSERT( FALSE );
  1201. // return -1;
  1202. // }
  1203. // if( ! m_wndScrollBarH.Create(
  1204. // WS_CHILD|WS_VISIBLE|SBS_HORZ|SBS_BOTTOMALIGN,
  1205. // CRect(0,0,0,0),
  1206. // this,
  1207. // 2
  1208. // )
  1209. // )
  1210. // {
  1211. // ASSERT( FALSE );
  1212. // return -1;
  1213. // }
  1214. // m_wndScrollBarH.SyncReservedSpace( &m_wndScrollBarV );
  1215. // m_wndScrollBarV.SyncReservedSpace( &m_wndScrollBarH );
  1216. // ModifyStyle( WS_HSCROLL|WS_VSCROLL, 0, SWP_FRAMECHANGED );
  1217. // }
  1218. // register drop target
  1219. if( m_dropTarget.Register( this ) )
  1220. return 0;
  1221. else
  1222. return -1;
  1223. }
  1224. CScrollBar* CDrawView::GetScrollBarCtrl(int nBar) const
  1225. {
  1226. ASSERT_VALID( this );
  1227. if( m_hWnd == NULL || (! ::IsWindow(m_hWnd) ) )
  1228. return NULL;
  1229. // ASSERT( nBar == SB_HORZ || nBar == SB_VERT );
  1230. // if( nBar == SB_HORZ )
  1231. // {
  1232. // if( m_wndScrollBarH.GetSafeHwnd() != NULL )
  1233. // return ( const_cast < CExtScrollBar * > ( &m_wndScrollBarH ) );
  1234. // } // if( nBar == SB_HORZ )
  1235. // else if( nBar == SB_VERT )
  1236. // {
  1237. // if( m_wndScrollBarV.GetSafeHwnd() != NULL )
  1238. // return ( const_cast < CExtScrollBar * > ( &m_wndScrollBarV ) );
  1239. // } // else from if( nBar == SB_HORZ )
  1240. return __BASE_OF_CDrawView__ :: GetScrollBarCtrl( nBar );
  1241. }
  1242. BOOL CDrawView::GetObjectInfo(COleDataObject* pDataObject,
  1243. CSize* pSize, CSize* pOffset)
  1244. {
  1245. ASSERT(pSize != NULL);
  1246. // get object descriptor data
  1247. HGLOBAL hObjDesc = pDataObject->GetGlobalData(m_cfObjectDescriptor);
  1248. if (hObjDesc == NULL)
  1249. {
  1250. if (pOffset != NULL)
  1251. *pOffset = CSize(0, 0); // fill in defaults instead
  1252. *pSize = CSize(0, 0);
  1253. return FALSE;
  1254. }
  1255. ASSERT(hObjDesc != NULL);
  1256. // otherwise, got CF_OBJECTDESCRIPTOR ok.  Lock it down and extract size.
  1257. LPOBJECTDESCRIPTOR pObjDesc = (LPOBJECTDESCRIPTOR)GlobalLock(hObjDesc);
  1258. ASSERT(pObjDesc != NULL);
  1259. pSize->cx = (int)pObjDesc->sizel.cx;
  1260. pSize->cy = (int)pObjDesc->sizel.cy;
  1261. if (pOffset != NULL)
  1262. {
  1263. pOffset->cx = (int)pObjDesc->pointl.x;
  1264. pOffset->cy = (int)pObjDesc->pointl.y;
  1265. }
  1266. GlobalUnlock(hObjDesc);
  1267. GlobalFree(hObjDesc);
  1268. // successfully retrieved pSize & pOffset info
  1269. return TRUE;
  1270. }
  1271. DROPEFFECT CDrawView::OnDragEnter(COleDataObject* pDataObject,
  1272. DWORD grfKeyState, CPoint point)
  1273. {
  1274. ASSERT(m_prevDropEffect == DROPEFFECT_NONE);
  1275. m_bDragDataAcceptable = FALSE;
  1276. if (!COleClientItem::CanCreateFromData(pDataObject))
  1277. return DROPEFFECT_NONE;
  1278. m_bDragDataAcceptable = TRUE;
  1279. GetObjectInfo(pDataObject, &m_dragSize, &m_dragOffset);
  1280. CClientDC dc(NULL);
  1281. dc.HIMETRICtoDP(&m_dragSize);
  1282. dc.HIMETRICtoDP(&m_dragOffset);
  1283. return OnDragOver(pDataObject, grfKeyState, point);
  1284. }
  1285. DROPEFFECT CDrawView::OnDragOver(COleDataObject*,
  1286. DWORD grfKeyState, CPoint point)
  1287. {
  1288. if(m_bDragDataAcceptable == FALSE)
  1289. return DROPEFFECT_NONE;
  1290. point -= m_dragOffset;  // adjust target rect by original cursor offset
  1291. // check for point outside logical area -- i.e. in hatched region
  1292. // GetTotalSize() returns the size passed to SetScrollSizes
  1293. CRect rectScroll(CPoint(0, 0), GetTotalSize());
  1294. CRect rectItem(point,m_dragSize);
  1295. rectItem.OffsetRect(GetDeviceScrollPosition());
  1296. DROPEFFECT de = DROPEFFECT_NONE;
  1297. CRect rectTemp;
  1298. if (rectTemp.IntersectRect(rectScroll, rectItem))
  1299. {
  1300. // check for force link
  1301. if ((grfKeyState & (MK_CONTROL|MK_SHIFT)) == (MK_CONTROL|MK_SHIFT))
  1302. de = DROPEFFECT_NONE; // DRAWCLI isn't a linking container
  1303. // check for force copy
  1304. else if ((grfKeyState & MK_CONTROL) == MK_CONTROL)
  1305. de = DROPEFFECT_COPY;
  1306. // check for force move
  1307. else if ((grfKeyState & MK_ALT) == MK_ALT)
  1308. de = DROPEFFECT_MOVE;
  1309. // default -- recommended action is move
  1310. else
  1311. de = DROPEFFECT_MOVE;
  1312. }
  1313. if (point == m_dragPoint)
  1314. return de;
  1315. // otherwise, cursor has moved -- need to update the drag feedback
  1316. CClientDC dc(this);
  1317. if (m_prevDropEffect != DROPEFFECT_NONE)
  1318. {
  1319. // erase previous focus rect
  1320. dc.DrawFocusRect(CRect(m_dragPoint, m_dragSize));
  1321. }
  1322. m_prevDropEffect = de;
  1323. if (m_prevDropEffect != DROPEFFECT_NONE)
  1324. {
  1325. m_dragPoint = point;
  1326. dc.DrawFocusRect(CRect(point, m_dragSize));
  1327. }
  1328. return de;
  1329. }
  1330. BOOL CDrawView::OnDrop(COleDataObject* pDataObject,
  1331. DROPEFFECT /*dropEffect*/, CPoint point)
  1332. {
  1333. ASSERT_VALID(this);
  1334. // clean up focus rect
  1335. OnDragLeave();
  1336. // offset point as appropriate for dragging
  1337. GetObjectInfo(pDataObject, &m_dragSize, &m_dragOffset);
  1338. CClientDC dc(NULL);
  1339. dc.HIMETRICtoDP(&m_dragSize);
  1340. dc.HIMETRICtoDP(&m_dragOffset);
  1341. point -= m_dragOffset;
  1342. // invalidate current selection since it will be deselected
  1343. OnUpdate(NULL, HINT_UPDATE_SELECTION, NULL);
  1344. m_selection.RemoveAll();
  1345. if (m_bDragDataAcceptable)
  1346. PasteEmbedded(*pDataObject, point);
  1347. // update the document and views
  1348. GetDocument()->SetModifiedFlag();
  1349. GetDocument()->UpdateAllViews(NULL, 0, NULL);      // including this view
  1350. return TRUE;
  1351. }
  1352. void CDrawView::OnDragLeave()
  1353. {
  1354. CClientDC dc(this);
  1355. if (m_prevDropEffect != DROPEFFECT_NONE)
  1356. {
  1357. dc.DrawFocusRect(CRect(m_dragPoint,m_dragSize)); // erase previous focus rect
  1358. m_prevDropEffect = DROPEFFECT_NONE;
  1359. }
  1360. }
  1361. void CDrawView::OnContextMenu(CWnd* /*pWnd*/, CPoint point)
  1362. {
  1363. if( IsPrintPreviewMode() )
  1364. return;
  1365. CDrawDoc * pDoc = GetDocument();
  1366. ASSERT_VALID( pDoc );
  1367. // make sure window is active
  1368. GetParentFrame()->ActivateFrame();
  1369. CPoint ptLocal = point;
  1370. ScreenToClient( &ptLocal );
  1371. ClientToDoc( ptLocal );
  1372. bool bTryProcessItemFocus = !( (point.x < 0) || (point.y < 0) );
  1373. CDrawObj * pObj = NULL;
  1374. if( bTryProcessItemFocus )
  1375. {
  1376. pObj = GetDocument()->ObjectAt( ptLocal );
  1377. if( pObj == NULL )
  1378. return;
  1379. if( !IsSelected(pObj) )
  1380. Select( pObj, FALSE ); // reselect item if appropriate
  1381. Invalidate();
  1382. UpdateWindow();
  1383. } // if( bTryProcessItemFocus )
  1384. else
  1385. {
  1386. POSITION pos = m_selection.GetHeadPosition();
  1387. if( pos == NULL )
  1388. return;
  1389. pObj = m_selection.GetNext( pos );
  1390. } // else from if( bTryProcessItemFocus )
  1391. ASSERT( pObj != NULL );
  1392. SyncToolbarObjButtons();
  1393. CMenu menu;
  1394. if( !menu.LoadMenu(ID_POPUP_MENU) )
  1395. {
  1396. ASSERT( FALSE );
  1397. return;
  1398. }
  1399. HWND hWnd = AfxGetMainWnd()->GetSafeHwnd();
  1400. ASSERT( hWnd != NULL );
  1401. ASSERT( ::IsWindow( hWnd ) );
  1402. CExtPopupMenuWnd * pPopup = new CExtPopupMenuWnd;
  1403. VERIFY( pPopup->UpdateFromMenu( hWnd, &menu ) );
  1404. VERIFY(
  1405. pPopup->TrackPopupMenu(
  1406. TPMX_OWNERDRAW_FIXED|TPMX_HIDE_KEYBOARD_ACCELERATORS,
  1407. point.x,
  1408. point.y
  1409. )
  1410. );
  1411. }
  1412. void CDrawView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
  1413. {
  1414. if (pInfo->m_bPreview == FALSE)
  1415. ((CDrawDoc*)GetDocument())->m_pSummInfo->RecordPrintDate();
  1416. OnDraw(pDC);
  1417. }
  1418. LRESULT CDrawView::OnExtMenuPrepare(WPARAM wParam, LPARAM lParam)
  1419. {
  1420. lParam;
  1421. CExtPopupMenuWnd::MsgPrepareMenuData_t * pData =
  1422. reinterpret_cast
  1423. < CExtPopupMenuWnd::MsgPrepareMenuData_t * >
  1424. ( wParam );
  1425. ASSERT( pData != NULL );
  1426. CExtPopupMenuWnd * pPopup = pData->m_pPopup;
  1427. ASSERT( pPopup != NULL );
  1428. if( ( pPopup->TrackFlagsGet() & TPMX_NO_CMD_UI ) != 0 )
  1429. return 0;
  1430. CDrawDoc * pDoc = GetDocument();
  1431. ASSERT_VALID( pDoc );
  1432. CDrawObj * pObj = NULL;
  1433. POSITION pos = m_selection.GetHeadPosition();
  1434. if( pos != NULL )
  1435. {
  1436. pObj = m_selection.GetNext( pos );
  1437. ASSERT( pObj != NULL );
  1438. }
  1439. INT nDefaultItemPos =
  1440. pPopup->ItemFindPosForCmdID(ID_EDIT_PROPERTIES);
  1441. if( nDefaultItemPos >= 0 )
  1442. pPopup->ItemDefaultSet(nDefaultItemPos);
  1443. INT nNextPos, nReplacePos =
  1444. pPopup->ItemFindPosForCmdID( ID_OLE_VERB_FIRST, -1 );
  1445. for( nNextPos = nReplacePos;
  1446. nReplacePos >= 0;
  1447. nNextPos = nReplacePos =
  1448. pPopup->ItemFindPosForCmdID( ID_OLE_VERB_FIRST, nNextPos + 1 )
  1449. )
  1450. {
  1451. CDrawOleObj * pDrawOleObj =
  1452. DYNAMIC_DOWNCAST(CDrawOleObj,pObj);
  1453. if( pDrawOleObj != NULL )
  1454. { // if menu for OLE object
  1455. // delete OLE verb entry
  1456. VERIFY( pPopup->ItemRemove( nReplacePos ) );
  1457. CMenu menu;
  1458. VERIFY( menu.CreatePopupMenu() );
  1459. ASSERT( menu.GetSafeHmenu() != NULL );
  1460. CMenu * pMenuPopup = &menu; // menu.GetSubMenu(0);
  1461. //ASSERT( pMenuPopup->GetSafeHmenu() != NULL );
  1462. VERIFY( pMenuPopup->AppendMenu( 0, ID_OLE_VERB_FIRST ) );
  1463. nNextPos ++;
  1464. UINT nConvertID = ID_OLE_EDIT_CONVERT;
  1465. AFX_CMDHANDLERINFO info;
  1466. if( ! pDoc->OnCmdMsg( ID_OLE_EDIT_CONVERT, CN_COMMAND, NULL, &info ) )
  1467. nConvertID = 0;
  1468. ASSERT( pDrawOleObj->m_pClientItem != NULL );
  1469. ASSERT( ::IsMenu( pMenuPopup->GetSafeHmenu() ) );
  1470. AfxOleSetEditMenu(
  1471. pDrawOleObj->m_pClientItem,
  1472. pMenuPopup, // &menu,
  1473. pMenuPopup->GetMenuItemCount() - 1, // First OLE cmd
  1474. ID_OLE_VERB_FIRST,
  1475. ID_OLE_VERB_LAST,
  1476. nConvertID
  1477. );
  1478. const CExtCmdIcon & _iconOLE =
  1479. g_CmdManager->CmdGetIcon(
  1480. g_CmdManager->ProfileNameFromWnd( GetSafeHwnd() ),
  1481. ID_OLE_INSERT_NEW
  1482. );
  1483. CString sOlePopupText;
  1484. pMenuPopup->GetMenuString(0,sOlePopupText,MF_BYPOSITION);
  1485. ASSERT( !sOlePopupText.IsEmpty() );
  1486. VERIFY(
  1487. pPopup->ItemInsert(
  1488. (UINT)CExtPopupMenuWnd::TYPE_POPUP,
  1489. nReplacePos,
  1490. (LPCTSTR)sOlePopupText,
  1491. _iconOLE
  1492. )
  1493. );
  1494. nNextPos ++;
  1495. pPopup->ItemSetDisplayed( nReplacePos, true );
  1496. CExtPopupMenuWnd * pOlePopup = pPopup->ItemGetPopup( nReplacePos );
  1497. ASSERT( pOlePopup != NULL );
  1498. if( pOlePopup != NULL )
  1499. {
  1500. if( ! pOlePopup->UpdateFromMenu(
  1501. AfxGetMainWnd()->GetSafeHwnd(),
  1502. &menu,
  1503. true,
  1504. false,
  1505. true
  1506. )
  1507. )
  1508. {
  1509. pPopup->ItemRemove( nReplacePos );
  1510. nNextPos ++;
  1511. }
  1512. else
  1513. pOlePopup->TrackFlagsSet( pOlePopup->TrackFlagsGet() | TPMX_NO_CMD_UI );
  1514. } // if( pOlePopup != NULL )
  1515. } // if menu for OLE object
  1516. else
  1517. { // if menu for internal object
  1518. // delete OLE verb entry
  1519. VERIFY( pPopup->ItemRemove( nReplacePos ) );
  1520. nNextPos --;
  1521. if( nReplacePos > 0
  1522. && pPopup->ItemGetCmdID( nReplacePos - 1 ) == ID_SEPARATOR
  1523. )
  1524. { // delete separator before OLE verb entry
  1525. VERIFY( pPopup->ItemRemove( nReplacePos - 1 ) );
  1526. nNextPos --;
  1527. } // delete separator before OLE verb entry
  1528. } // if menu for internal object
  1529. }
  1530. if( pObj != NULL )
  1531. {
  1532. CExtPopupColorMenuWnd * pColorPopup;
  1533. CString sNoColor;
  1534. nReplacePos =
  1535. pPopup->ItemFindPosForCmdID(ID_OBJECT_FILLCOLOR);
  1536. if( nReplacePos >= 0 )
  1537. {
  1538. VERIFY( sNoColor.LoadString(IDS_STRING_NO_COLOR_FILL) );
  1539. ASSERT( !sNoColor.IsEmpty() );
  1540. pColorPopup = new CExtPopupColorMenuWnd;
  1541. pColorPopup->m_sBtnTextColorDefault = sNoColor;
  1542. pColorPopup->m_lParamCookie = LPARAM(ID_OBJECT_FILLCOLOR);
  1543. pColorPopup->m_hWndNotifyColorChanged = GetSafeHwnd();
  1544. pColorPopup->m_clrDefault = COLORREF(-1);
  1545. pColorPopup->m_clrInitial =
  1546. pObj->IsNoFill() ? COLORREF(-1) : pObj->GetFillColor();
  1547. VERIFY(
  1548. pPopup->ItemInsertSpecPopup(
  1549. pColorPopup,
  1550. nReplacePos + 1,
  1551. pPopup->ItemGetText(nReplacePos),
  1552. pPopup->ItemGetIcon(nReplacePos)
  1553. )
  1554. );
  1555. pPopup->ItemSetDisplayed( nReplacePos + 1, true );
  1556. VERIFY( pPopup->ItemRemove(nReplacePos) );
  1557. } // if( nReplacePos >= 0 )
  1558. nReplacePos =
  1559. pPopup->ItemFindPosForCmdID(ID_OBJECT_LINECOLOR);
  1560. if( nReplacePos >= 0 )
  1561. {
  1562. VERIFY( sNoColor.LoadString(IDS_STRING_NO_COLOR_OUTLINE) );
  1563. ASSERT( !sNoColor.IsEmpty() );
  1564. pColorPopup = new CExtPopupColorMenuWnd;
  1565. pColorPopup->m_sBtnTextColorDefault = sNoColor;
  1566. //pColorPopup->m_bEnableBtnColorDefault = false;
  1567. pColorPopup->m_lParamCookie = LPARAM(ID_OBJECT_LINECOLOR);
  1568. pColorPopup->m_hWndNotifyColorChanged = GetSafeHwnd();
  1569. pColorPopup->m_clrDefault = COLORREF(-1);
  1570. pColorPopup->m_clrInitial =
  1571. pObj->IsNoOutline() ? COLORREF(-1) : pObj->GetLineColor();
  1572. VERIFY(
  1573. pPopup->ItemInsertSpecPopup(
  1574. pColorPopup,
  1575. nReplacePos + 1,
  1576. pPopup->ItemGetText(nReplacePos),
  1577. pPopup->ItemGetIcon(nReplacePos)
  1578. )
  1579. );
  1580. pPopup->ItemSetDisplayed( nReplacePos + 1, true );
  1581. VERIFY( pPopup->ItemRemove(nReplacePos) );
  1582. } // if( nReplacePos >= 0 )
  1583. } // if( pObj != NULL )
  1584. nReplacePos = pPopup->ItemFindByText( _T("Line &Width...") );
  1585. if( nReplacePos >= 0 )
  1586. {
  1587. const CExtCmdIcon & _icon =
  1588. g_CmdManager->CmdGetIcon(
  1589. g_CmdManager->ProfileNameFromWnd( GetSafeHwnd() ),
  1590. ID_DOC_LINE_WIDTH
  1591. );
  1592. pPopup->ItemSetPopupIcon( nReplacePos, _icon );
  1593. }
  1594. return TRUE;
  1595. }
  1596. LRESULT CDrawView::OnColorChangedFinally(WPARAM wParam, LPARAM lParam)
  1597. {
  1598. POSITION pos = m_selection.GetHeadPosition();
  1599. ASSERT( pos != NULL );
  1600. while( pos != NULL )
  1601. {
  1602. CDrawObj * pObj = m_selection.GetNext( pos );
  1603. ASSERT( pObj != NULL );
  1604. switch( lParam )
  1605. {
  1606. case ID_OBJECT_FILLCOLOR:
  1607. if( COLORREF(wParam) == COLORREF(-1) )
  1608. pObj->SetNoFill();
  1609. else
  1610. {
  1611. pObj->SetNoFill( FALSE );
  1612. pObj->SetFillColor( COLORREF(wParam) );
  1613. }
  1614. break;
  1615. case ID_OBJECT_LINECOLOR:
  1616. if( COLORREF(wParam) == COLORREF(-1) )
  1617. pObj->SetNoOutline();
  1618. else
  1619. {
  1620. pObj->SetNoOutline( FALSE );
  1621. pObj->SetLineColor( COLORREF(wParam) );
  1622. }
  1623. break;
  1624. } // switch( lParam )
  1625. }
  1626. Invalidate();
  1627. UpdateWindow();
  1628. SyncToolbarObjButtons();
  1629. return 0;
  1630. }
  1631. LRESULT CDrawView::OnColorSelectCustom(WPARAM wParam, LPARAM lParam)
  1632. {
  1633. wParam;
  1634. switch( lParam )
  1635. {
  1636. case ID_OBJECT_FILLCOLOR:
  1637. case ID_OBJECT_LINECOLOR:
  1638. PostMessage(WM_COMMAND,lParam,0);
  1639. break;
  1640. } // switch( lParam )
  1641. return 0;
  1642. }
  1643. void CDrawView::OnUpdateSelectionSingle(CCmdUI* pCmdUI)
  1644. {
  1645. if( IsPrintPreviewMode() )
  1646. {
  1647. pCmdUI->Enable( FALSE );
  1648. return;
  1649. }
  1650. int nSelCount = int( m_selection.GetCount() );
  1651. pCmdUI->Enable( nSelCount == 1 );
  1652. }
  1653. void CDrawView::OnUpdateSelectionNonEmpty(CCmdUI* pCmdUI)
  1654. {
  1655. if( IsPrintPreviewMode() )
  1656. {
  1657. pCmdUI->Enable( FALSE );
  1658. return;
  1659. }
  1660. int nSelCount = int( m_selection.GetCount() );
  1661. pCmdUI->Enable( nSelCount > 0 );
  1662. }
  1663. void CDrawView::OnLineWidth( UINT nCmdID )
  1664. {
  1665. ASSERT( ID_LINE_WIDTH_0 <= nCmdID && nCmdID <= ID_LINE_WIDTH_OTHER );
  1666. #ifdef _DEBUG
  1667. int nSelCount = int( m_selection.GetCount() );
  1668. ASSERT( nSelCount > 0 );
  1669. #endif // _DEBUG
  1670. POSITION pos = m_selection.GetHeadPosition();
  1671. ASSERT( pos != NULL );
  1672. while( pos != NULL )
  1673. {
  1674. CDrawObj * pObj = m_selection.GetNext( pos );
  1675. ASSERT( pObj != NULL );
  1676. switch( nCmdID )
  1677. {
  1678. case ID_LINE_WIDTH_OTHER:
  1679. ASSERT( nSelCount == 1 );
  1680. if( CDrawTool::c_drawShape == selection )
  1681. PostMessage( WM_COMMAND, ID_EDIT_PROPERTIES );
  1682. return;
  1683. case ID_LINE_WIDTH_0:
  1684. pObj->SetNoOutline( TRUE );
  1685. break;
  1686. default:
  1687. {
  1688. ASSERT( ID_LINE_WIDTH_1 <= nCmdID && nCmdID <= ID_LINE_WIDTH_10 );
  1689. UINT nLineWidth = nCmdID - ID_LINE_WIDTH_0;
  1690. ASSERT( 1 <= nLineWidth && nLineWidth <= 10 );
  1691. pObj->SetNoOutline( FALSE );
  1692. pObj->m_logpen.lopnWidth.x = nLineWidth;
  1693. pObj->m_logpen.lopnWidth.y = nLineWidth;
  1694. }
  1695. break;
  1696. } // switch( nCmdID )
  1697. } // while( pos != NULL )
  1698. Invalidate();
  1699. }
  1700. void CDrawView::OnUpdateLineWidth( CCmdUI * pCmdUI )
  1701. {
  1702. ASSERT( pCmdUI != NULL );
  1703. if( IsPrintPreviewMode() )
  1704. {
  1705. pCmdUI->SetRadio( 0 );
  1706. pCmdUI->Enable( FALSE );
  1707. return;
  1708. }
  1709. UINT nCmdID = pCmdUI->m_nID;
  1710. ASSERT( ID_LINE_WIDTH_0 <= nCmdID && nCmdID <= ID_LINE_WIDTH_OTHER );
  1711. int nSelCount = int( m_selection.GetCount() );
  1712. CDrawObj * pObj = NULL;
  1713. if( nSelCount > 0 )
  1714. {
  1715. POSITION pos = m_selection.GetHeadPosition();
  1716. ASSERT( pos != NULL );
  1717. pObj = m_selection.GetNext( pos );
  1718. ASSERT( pObj != NULL );
  1719. }
  1720. else
  1721. {
  1722. pCmdUI->Enable( FALSE );
  1723. pCmdUI->SetRadio( FALSE );
  1724. }
  1725. if( nCmdID == ID_LINE_WIDTH_OTHER )
  1726. {
  1727. pCmdUI->Enable( nSelCount == 1 && m_selection.GetCount() == 1 && CDrawTool::c_drawShape == selection );
  1728. if( pObj != NULL )
  1729. pCmdUI->SetRadio( pObj->m_logpen.lopnWidth.x > 10 );
  1730. return;
  1731. }
  1732. pCmdUI->Enable( nSelCount > 0 );
  1733. if( nCmdID == ID_LINE_WIDTH_0 )
  1734. {
  1735. if( pObj != NULL )
  1736. pCmdUI->SetRadio( pObj->IsNoOutline() );
  1737. return;
  1738. }
  1739. ASSERT( ID_LINE_WIDTH_1 <= nCmdID && nCmdID <= ID_LINE_WIDTH_10 );
  1740. UINT nLineWidth = nCmdID - ID_LINE_WIDTH_0;
  1741. ASSERT( 1 <= nLineWidth && nLineWidth <= 10 );
  1742. pCmdUI->Enable( nSelCount > 0 );
  1743. if( pObj != NULL )
  1744. pCmdUI->SetRadio( UINT(pObj->m_logpen.lopnWidth.x) == nLineWidth );
  1745. }
  1746. LRESULT CDrawView::OnDrawPopupMenuItem(WPARAM wParam, LPARAM lParam)
  1747. {
  1748. wParam;
  1749. CExtPopupMenuWnd::DRAWITEMDATA * pDrawItemData =
  1750. reinterpret_cast < CExtPopupMenuWnd::DRAWITEMDATA * > ( lParam );
  1751. ASSERT( pDrawItemData != NULL );
  1752. UINT nCmdID = pDrawItemData->GetCmdID();
  1753. if( ! ( ID_LINE_WIDTH_1 <= nCmdID && nCmdID <= ID_LINE_WIDTH_10 ) )
  1754. return FALSE; // default painting
  1755. #if (!defined __EXT_MFC_NO_CUSTOMIZE)
  1756. const CExtCustomizeCmdTreeNode * pNode =
  1757. pDrawItemData->m_pItemData->GetCmdNode();
  1758. if( pNode != NULL )
  1759. {
  1760. ASSERT_VALID( pNode );
  1761. if( (pNode->GetFlags() & __ECTN_TBB_SEPARATED_DROPDOWN) != 0 )
  1762. return FALSE;
  1763. } // if( pNode != NULL )
  1764. #endif // (!defined __EXT_MFC_NO_CUSTOMIZE)
  1765. // paint default menu item background
  1766. pDrawItemData->PaintDefault(
  1767. false,
  1768. true,
  1769. false,
  1770. false,
  1771. false
  1772. );
  1773. UINT nLineWidth = nCmdID - ID_LINE_WIDTH_0;
  1774. ASSERT( 1 <= nLineWidth && nLineWidth <= 10 );
  1775. INT nIconAreaWidth = g_PaintManager->GetMenuIconAreaWidth();
  1776. if( nIconAreaWidth < 0 )
  1777. {
  1778. nIconAreaWidth = __EXT_MENU_ICON_CX + __EXT_MENU_GAP * 2;
  1779. nIconAreaWidth = g_PaintManager->UiScalingDo( nIconAreaWidth, CExtPaintManager::__EUIST_X );
  1780. bool bRTL = pDrawItemData->m_pPopup->OnQueryLayoutRTL();
  1781. CRect rcItem = LPCRECT(*pDrawItemData);
  1782. if( bRTL )
  1783. rcItem.DeflateRect( 2, 0, nIconAreaWidth + 4, 0 );
  1784. else
  1785. rcItem.DeflateRect( nIconAreaWidth + 4, 0, 2, 0 );
  1786. rcItem.top += rcItem.Height()/2;
  1787. rcItem.top -= nLineWidth/2;
  1788. rcItem.bottom = rcItem.top + nLineWidth;
  1789. // get draw DC
  1790. CDC & dc = *( (CDC *) *pDrawItemData );
  1791. dc.FillSolidRect(
  1792. &rcItem,
  1793. g_PaintManager->GetColor(
  1794. (m_selection.GetCount() > 0)
  1795. ? COLOR_3DDKSHADOW
  1796. : COLOR_3DSHADOW
  1797. ,
  1798. this
  1799. )
  1800. );
  1801. return TRUE;
  1802. }
  1803. void CDrawView::OnUpdateDocLineWidth(CCmdUI* pCmdUI) 
  1804. {
  1805. if( IsPrintPreviewMode() )
  1806. {
  1807. pCmdUI->Enable( FALSE );
  1808. return;
  1809. }
  1810. pCmdUI->Enable( m_selection.GetCount() > 0 );
  1811. }
  1812. void CDrawView::SyncToolbarObjButtons()
  1813. {
  1814. if( IsPrintPreviewMode() )
  1815. return;
  1816. CFrameWnd * pFrame = GetParentFrame();
  1817. ASSERT_VALID( pFrame );
  1818. if( pFrame->IsKindOf( RUNTIME_CLASS(CMDIChildWnd) ) )
  1819. {
  1820. CMainFrame * pMainFrame = (CMainFrame *)pFrame->GetParentFrame();
  1821. ASSERT_VALID( pMainFrame );
  1822. ASSERT_KINDOF( CMainFrame, pMainFrame );
  1823. int nSelCount = int( m_selection.GetCount() );
  1824. CDrawObj * pObj = NULL;
  1825. if( nSelCount > 0 )
  1826. {
  1827. POSITION pos = m_selection.GetHeadPosition();
  1828. ASSERT( pos != NULL );
  1829. pObj = m_selection.GetNext( pos );
  1830. ASSERT( pObj != NULL );
  1831. } // if( nSelCount > 0 )
  1832. #if (defined __EXT_MFC_NO_CUSTOMIZE)
  1833. if( pObj != NULL )
  1834. {
  1835. if( pMainFrame->m_pBtnColorFillS != NULL
  1836. && pMainFrame->m_pBtnColorFillS->ColorGet(true)
  1837. != pObj->GetFillColor()
  1838. )
  1839. {
  1840. ASSERT_VALID( pMainFrame->m_pBtnColorFillS );
  1841. ASSERT( pMainFrame->m_pBtnColorFillP != NULL );
  1842. ASSERT_VALID( pMainFrame->m_pBtnColorFillS );
  1843. pMainFrame->m_pBtnColorFillS->ColorSet(
  1844. pObj->IsNoFill() ? COLORREF(-1) : pObj->GetFillColor(),
  1845. false
  1846. );
  1847. pMainFrame->m_pBtnColorFillP->ColorSet(
  1848. pObj->IsNoFill() ? COLORREF(-1) : pObj->GetFillColor(),
  1849. false
  1850. );
  1851. pMainFrame->m_pBtnColorFillS->ColorSet(
  1852. COLORREF(-1),
  1853. true
  1854. );
  1855. pMainFrame->m_pBtnColorFillP->ColorSet(
  1856. COLORREF(-1),
  1857. true
  1858. );
  1859. pMainFrame->m_pBtnColorFillS->RedrawButton();
  1860. pMainFrame->m_pBtnColorFillP->RedrawButton();
  1861. }
  1862. if( pMainFrame->m_pBtnColorOutlineS != NULL
  1863. && pMainFrame->m_pBtnColorOutlineS->ColorGet(false)
  1864. != pObj->GetLineColor()
  1865. )
  1866. {
  1867. ASSERT_VALID( pMainFrame->m_pBtnColorOutlineS );
  1868. ASSERT( pMainFrame->m_pBtnColorOutlineP != NULL );
  1869. ASSERT_VALID( pMainFrame->m_pBtnColorOutlineP );
  1870. pMainFrame->m_pBtnColorOutlineS->ColorSet(
  1871. pObj->IsNoOutline() ? COLORREF(-1) : pObj->GetLineColor(),
  1872. false
  1873. );
  1874. pMainFrame->m_pBtnColorOutlineP->ColorSet(
  1875. pObj->IsNoOutline() ? COLORREF(-1) : pObj->GetLineColor(),
  1876. false
  1877. );
  1878. pMainFrame->m_pBtnColorOutlineS->ColorSet(
  1879. COLORREF(-1),
  1880. true
  1881. );
  1882. pMainFrame->m_pBtnColorOutlineP->ColorSet(
  1883. COLORREF(-1),
  1884. true
  1885. );
  1886. pMainFrame->m_pBtnColorOutlineS->RedrawButton();
  1887. pMainFrame->m_pBtnColorOutlineP->RedrawButton();
  1888. }
  1889. CExtBarButton * pTBB =
  1890. pMainFrame->m_wndToolBarStandard.GetButton(
  1891. pMainFrame->m_wndToolBarStandard.CommandToIndex(
  1892. ID_DOC_LINE_WIDTH
  1893. )
  1894. );
  1895. ASSERT_VALID( pTBB );
  1896. UINT nCmdID = pTBB->GetCmdID( true );
  1897. ASSERT( ID_LINE_WIDTH_0 <= nCmdID && nCmdID <= ID_LINE_WIDTH_OTHER );
  1898. UINT nAdjustCmdID = ID_LINE_WIDTH_0;
  1899. if( !pObj->IsNoOutline() )
  1900. {
  1901. UINT xw = (UINT)pObj->m_logpen.lopnWidth.x;
  1902. if( xw <= 10 )
  1903. {
  1904. ASSERT( xw > 0 );
  1905. nAdjustCmdID = ID_LINE_WIDTH_0 + xw;
  1906. ASSERT( ID_LINE_WIDTH_1 <= nAdjustCmdID && nAdjustCmdID <= ID_LINE_WIDTH_10 );
  1907. }
  1908. else
  1909. nAdjustCmdID = ID_LINE_WIDTH_OTHER;
  1910. }
  1911. if( nCmdID != nAdjustCmdID )
  1912. pTBB->SetCmdID( nAdjustCmdID, true, true );
  1913. } // if( pObj != NULL )
  1914. #else // (defined __EXT_MFC_NO_CUSTOMIZE)
  1915. if( pObj != NULL )
  1916. {
  1917. if( pMainFrame->m_pBtnColorFillP != NULL
  1918. && pMainFrame->m_pBtnColorFillP->ColorGet(true)
  1919. != pObj->GetFillColor()
  1920. )
  1921. {
  1922. ASSERT_VALID( pMainFrame->m_pBtnColorFillP );
  1923. pMainFrame->m_pBtnColorFillP->ColorSet(
  1924. pObj->IsNoFill() ? COLORREF(-1) : pObj->GetFillColor(),
  1925. false
  1926. );
  1927. pMainFrame->m_pBtnColorFillP->ColorSet(
  1928. COLORREF(-1),
  1929. true
  1930. );
  1931. pMainFrame->m_pBtnColorFillP->RedrawButton();
  1932. }
  1933. if( pMainFrame->m_pBtnColorOutlineP != NULL
  1934. && pMainFrame->m_pBtnColorOutlineP->ColorGet(false)
  1935. != pObj->GetLineColor()
  1936. )
  1937. {
  1938. ASSERT_VALID( pMainFrame->m_pBtnColorOutlineP );
  1939. pMainFrame->m_pBtnColorOutlineP->ColorSet(
  1940. pObj->IsNoOutline() ? COLORREF(-1) : pObj->GetLineColor(),
  1941. false
  1942. );
  1943. pMainFrame->m_pBtnColorOutlineP->ColorSet(
  1944. COLORREF(-1),
  1945. true
  1946. );
  1947. pMainFrame->m_pBtnColorOutlineP->RedrawButton();
  1948. }
  1949. } // if( pObj != NULL )
  1950. pMainFrame->RedrawCommandItems( ID_OBJECT_FILLCOLOR ); 
  1951. pMainFrame->RedrawCommandItems( ID_OBJECT_LINECOLOR ); 
  1952. pMainFrame->RedrawCommandItems( ID_LINE_WIDTH_OTHER ); 
  1953. #endif // not - (defined __EXT_MFC_NO_CUSTOMIZE)
  1954. return;
  1955. } // if( pFrame->IsKindOf( RUNTIME_CLASS(CMDIChildWnd) ) );
  1956. else if( pFrame->IsKindOf( RUNTIME_CLASS(CDrawInPlaceFrame) ) )
  1957. {
  1958. CDrawInPlaceFrame * pMainFrame = (CDrawInPlaceFrame*)pFrame;
  1959. ASSERT_VALID( pMainFrame );
  1960. ASSERT_KINDOF( CDrawInPlaceFrame, pMainFrame );
  1961. int nSelCount = int( m_selection.GetCount() );
  1962. CDrawObj * pObj = NULL;
  1963. if( nSelCount > 0 )
  1964. {
  1965. POSITION pos = m_selection.GetHeadPosition();
  1966. ASSERT( pos != NULL );
  1967. pObj = m_selection.GetNext( pos );
  1968. ASSERT( pObj != NULL );
  1969. } // if( nSelCount > 0 )
  1970. if( pObj != NULL )
  1971. {
  1972. if( pMainFrame->m_pBtnColorFillS != NULL
  1973. && pMainFrame->m_pBtnColorFillS->ColorGet(true)
  1974. != pObj->GetFillColor()
  1975. )
  1976. {
  1977. ASSERT_VALID( pMainFrame->m_pBtnColorFillS );
  1978. ASSERT( pMainFrame->m_pBtnColorFillP != NULL );
  1979. ASSERT_VALID( pMainFrame->m_pBtnColorFillS );
  1980. pMainFrame->m_pBtnColorFillS->ColorSet(
  1981. pObj->IsNoFill() ? COLORREF(-1) : pObj->GetFillColor(),
  1982. false
  1983. );
  1984. pMainFrame->m_pBtnColorFillP->ColorSet(
  1985. pObj->IsNoFill() ? COLORREF(-1) : pObj->GetFillColor(),
  1986. false
  1987. );
  1988. pMainFrame->m_pBtnColorFillS->ColorSet(
  1989. COLORREF(-1),
  1990. true
  1991. );
  1992. pMainFrame->m_pBtnColorFillP->ColorSet(
  1993. COLORREF(-1),
  1994. true
  1995. );
  1996. pMainFrame->m_pBtnColorFillS->RedrawButton();
  1997. pMainFrame->m_pBtnColorFillP->RedrawButton();
  1998. }
  1999. if( pMainFrame->m_pBtnColorOutlineS != NULL
  2000. && pMainFrame->m_pBtnColorOutlineS->ColorGet(false)
  2001. != pObj->GetLineColor()
  2002. )
  2003. {
  2004. ASSERT_VALID( pMainFrame->m_pBtnColorOutlineS );
  2005. ASSERT( pMainFrame->m_pBtnColorOutlineP != NULL );
  2006. ASSERT_VALID( pMainFrame->m_pBtnColorOutlineP );
  2007. pMainFrame->m_pBtnColorOutlineS->ColorSet(
  2008. pObj->IsNoOutline() ? COLORREF(-1) : pObj->GetLineColor(),
  2009. false
  2010. );
  2011. pMainFrame->m_pBtnColorOutlineP->ColorSet(
  2012. pObj->IsNoOutline() ? COLORREF(-1) : pObj->GetLineColor(),
  2013. false
  2014. );
  2015. pMainFrame->m_pBtnColorOutlineS->ColorSet(
  2016. COLORREF(-1),
  2017. true
  2018. );
  2019. pMainFrame->m_pBtnColorOutlineP->ColorSet(
  2020. COLORREF(-1),
  2021. true
  2022. );
  2023. pMainFrame->m_pBtnColorOutlineS->RedrawButton();
  2024. pMainFrame->m_pBtnColorOutlineP->RedrawButton();
  2025. }
  2026. CExtBarButton * pTBB =
  2027. pMainFrame->m_wndToolBarStandard.GetButton(
  2028. pMainFrame->m_wndToolBarStandard.CommandToIndex(
  2029. ID_DOC_LINE_WIDTH
  2030. )
  2031. );
  2032. ASSERT_VALID( pTBB );
  2033. UINT nCmdID = pTBB->GetCmdID( true );
  2034. ASSERT( ID_LINE_WIDTH_0 <= nCmdID && nCmdID <= ID_LINE_WIDTH_OTHER );
  2035. UINT nAdjustCmdID = ID_LINE_WIDTH_0;
  2036. if( !pObj->IsNoOutline() )
  2037. {
  2038. UINT xw = (UINT)pObj->m_logpen.lopnWidth.x;
  2039. if( xw <= 10 )
  2040. {
  2041. ASSERT( xw > 0 );
  2042. nAdjustCmdID = ID_LINE_WIDTH_0 + xw;
  2043. ASSERT( ID_LINE_WIDTH_1 <= nAdjustCmdID && nAdjustCmdID <= ID_LINE_WIDTH_10 );
  2044. }
  2045. else
  2046. nAdjustCmdID = ID_LINE_WIDTH_OTHER;
  2047. }
  2048. if( nCmdID != nAdjustCmdID )
  2049. pTBB->SetCmdID( nAdjustCmdID, true, true );
  2050. } // if( pObj != NULL )
  2051. return;
  2052. } // else if( pFrame->IsKindOf( RUNTIME_CLASS(CDrawInPlaceFrame) ) )
  2053. /*
  2054. #if (defined __EXT_MFC_NO_CUSTOMIZE)
  2055. if( pObj != NULL )
  2056. {
  2057. if( pMainFrame->m_pBtnColorFillS != NULL
  2058. && pMainFrame->m_pBtnColorFillS->ColorGet(true)
  2059. != pObj->GetFillColor()
  2060. )
  2061. {
  2062. ASSERT_VALID( pMainFrame->m_pBtnColorFillS );
  2063. ASSERT( pMainFrame->m_pBtnColorFillP != NULL );
  2064. ASSERT_VALID( pMainFrame->m_pBtnColorFillS );
  2065. pMainFrame->m_pBtnColorFillS->ColorSet(
  2066. pObj->IsNoFill() ? COLORREF(-1) : pObj->GetFillColor(),
  2067. false
  2068. );
  2069. pMainFrame->m_pBtnColorFillP->ColorSet(
  2070. pObj->IsNoFill() ? COLORREF(-1) : pObj->GetFillColor(),
  2071. false
  2072. );
  2073. pMainFrame->m_pBtnColorFillS->ColorSet(
  2074. COLORREF(-1),
  2075. true
  2076. );
  2077. pMainFrame->m_pBtnColorFillP->ColorSet(
  2078. COLORREF(-1),
  2079. true
  2080. );
  2081. pMainFrame->m_pBtnColorFillS->RedrawButton();
  2082. pMainFrame->m_pBtnColorFillP->RedrawButton();
  2083. }
  2084. if( pMainFrame->m_pBtnColorOutlineS != NULL
  2085. && pMainFrame->m_pBtnColorOutlineS->ColorGet(false)
  2086. != pObj->GetLineColor()
  2087. )
  2088. {
  2089. ASSERT_VALID( pMainFrame->m_pBtnColorOutlineS );
  2090. ASSERT( pMainFrame->m_pBtnColorOutlineP != NULL );
  2091. ASSERT_VALID( pMainFrame->m_pBtnColorOutlineP );
  2092. pMainFrame->m_pBtnColorOutlineS->ColorSet(
  2093. pObj->IsNoOutline() ? COLORREF(-1) : pObj->GetLineColor(),
  2094. false
  2095. );
  2096. pMainFrame->m_pBtnColorOutlineP->ColorSet(
  2097. pObj->IsNoOutline() ? COLORREF(-1) : pObj->GetLineColor(),
  2098. false
  2099. );
  2100. pMainFrame->m_pBtnColorOutlineS->ColorSet(
  2101. COLORREF(-1),
  2102. true
  2103. );
  2104. pMainFrame->m_pBtnColorOutlineP->ColorSet(
  2105. COLORREF(-1),
  2106. true
  2107. );
  2108. pMainFrame->m_pBtnColorOutlineS->RedrawButton();
  2109. pMainFrame->m_pBtnColorOutlineP->RedrawButton();
  2110. }
  2111. CExtBarButton * pTBB =
  2112. pMainFrame->m_wndToolBarStandard.GetButton(
  2113. pMainFrame->m_wndToolBarStandard.CommandToIndex(
  2114. ID_DOC_LINE_WIDTH
  2115. )
  2116. );
  2117. ASSERT_VALID( pTBB );
  2118. UINT nCmdID = pTBB->GetCmdID( true );
  2119. ASSERT( ID_LINE_WIDTH_0 <= nCmdID && nCmdID <= ID_LINE_WIDTH_OTHER );
  2120. UINT nAdjustCmdID = ID_LINE_WIDTH_0;
  2121. if( !pObj->IsNoOutline() )
  2122. {
  2123. UINT xw = (UINT)pObj->m_logpen.lopnWidth.x;
  2124. if( xw <= 10 )
  2125. {
  2126. ASSERT( xw > 0 );
  2127. nAdjustCmdID = ID_LINE_WIDTH_0 + xw;
  2128. ASSERT( ID_LINE_WIDTH_1 <= nAdjustCmdID && nAdjustCmdID <= ID_LINE_WIDTH_10 );
  2129. }
  2130. else
  2131. nAdjustCmdID = ID_LINE_WIDTH_OTHER;
  2132. }
  2133. if( nCmdID != nAdjustCmdID )
  2134. pTBB->SetCmdID( nAdjustCmdID, true, true );
  2135. } // if( pObj != NULL )
  2136. #else // (defined __EXT_MFC_NO_CUSTOMIZE)
  2137. if( pObj != NULL )
  2138. {
  2139. if( pMainFrame->m_pBtnColorFillP != NULL
  2140. && pMainFrame->m_pBtnColorFillP->ColorGet(true)
  2141. != pObj->GetFillColor()
  2142. )
  2143. {
  2144. ASSERT_VALID( pMainFrame->m_pBtnColorFillP );
  2145. pMainFrame->m_pBtnColorFillP->ColorSet(
  2146. pObj->IsNoFill() ? COLORREF(-1) : pObj->GetFillColor(),
  2147. false
  2148. );
  2149. pMainFrame->m_pBtnColorFillP->ColorSet(
  2150. COLORREF(-1),
  2151. true
  2152. );
  2153. pMainFrame->m_pBtnColorFillP->RedrawButton();
  2154. }
  2155. if( pMainFrame->m_pBtnColorOutlineP != NULL
  2156. && pMainFrame->m_pBtnColorOutlineP->ColorGet(false)
  2157. != pObj->GetLineColor()
  2158. )
  2159. {
  2160. ASSERT_VALID( pMainFrame->m_pBtnColorOutlineP );
  2161. pMainFrame->m_pBtnColorOutlineP->ColorSet(
  2162. pObj->IsNoOutline() ? COLORREF(-1) : pObj->GetLineColor(),
  2163. false
  2164. );
  2165. pMainFrame->m_pBtnColorOutlineP->ColorSet(
  2166. COLORREF(-1),
  2167. true
  2168. );
  2169. pMainFrame->m_pBtnColorOutlineP->RedrawButton();
  2170. }
  2171. } // if( pObj != NULL )
  2172. pMainFrame->RedrawCommandItems( ID_OBJECT_FILLCOLOR ); 
  2173. pMainFrame->RedrawCommandItems( ID_OBJECT_LINECOLOR ); 
  2174. pMainFrame->RedrawCommandItems( ID_LINE_WIDTH_OTHER ); 
  2175. #endif // not - (defined __EXT_MFC_NO_CUSTOMIZE)
  2176. */
  2177. }
  2178. // The following command handler provides the standard keyboard
  2179. //  user interface to cancel an in-place editing session.  Here,
  2180. //  the container (not the server) causes the deactivation.
  2181. void CDrawView::OnCancelEditCntr()
  2182. {
  2183. // Close any in-place active item on this view.
  2184. COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
  2185. if (pActiveItem != NULL)
  2186. {
  2187. pActiveItem->Close();
  2188. }
  2189. ASSERT(GetDocument()->GetInPlaceActiveItem(this) == NULL);
  2190. }
  2191. // The following command handler provides the standard keyboard
  2192. //  user interface to cancel an in-place editing session.  Here,
  2193. //  the server (not the container) causes the deactivation.
  2194. void CDrawView::OnCancelEditSrvr()
  2195. {
  2196. GetDocument()->OnDeactivateUI(FALSE);
  2197. }