Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

251 lines
5.8 KiB

  1. // ImageView.cpp : implementation of the CImageView class
  2. //
  3. #include "stdafx.h"
  4. #include "shimgvwr.h"
  5. #include "ImageDoc.h"
  6. #include "ImageView.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CImageView
  14. IMPLEMENT_DYNCREATE(CImageView, CView)
  15. BEGIN_MESSAGE_MAP(CImageView, CView)
  16. //{{AFX_MSG_MAP(CImageView)
  17. ON_WM_CREATE()
  18. ON_WM_SIZE()
  19. ON_COMMAND(ID_VIEW_ACTUALSIZE, OnViewActualsize)
  20. ON_UPDATE_COMMAND_UI(ID_VIEW_ACTUALSIZE, OnUpdateViewMenu)
  21. ON_COMMAND(ID_VIEW_BESTFIT, OnViewBestfit)
  22. ON_UPDATE_COMMAND_UI(ID_VIEW_BESTFIT, OnUpdateViewMenu)
  23. ON_COMMAND(ID_VIEW_SLIDESHOW, OnViewSlideshow)
  24. ON_UPDATE_COMMAND_UI(ID_VIEW_SLIDESHOW, OnUpdateViewMenu)
  25. ON_COMMAND(ID_VIEW_ZOOM_IN, OnViewZoomIn)
  26. ON_UPDATE_COMMAND_UI(ID_VIEW_ZOOM_IN, OnUpdateViewMenu)
  27. ON_COMMAND(ID_VIEW_ZOOM_OUT, OnViewZoomOut)
  28. ON_UPDATE_COMMAND_UI(ID_VIEW_ZOOM_OUT, OnUpdateViewMenu)
  29. ON_UPDATE_COMMAND_UI(ID_ROTATE_90, OnUpdateViewMenu)
  30. ON_UPDATE_COMMAND_UI(ID_ROTATE_CLOCKWISE, OnUpdateViewMenu)
  31. ON_UPDATE_COMMAND_UI(ID_ROTATE_COUNTER, OnUpdateViewMenu)
  32. ON_COMMAND(ID_ROTATE_CLOCKWISE, OnEditRotateClockwise)
  33. ON_COMMAND(ID_ROTATE_COUNTER, OnEditRotateCounter)
  34. //}}AFX_MSG_MAP
  35. END_MESSAGE_MAP()
  36. /////////////////////////////////////////////////////////////////////////////
  37. // CImageView construction/destruction
  38. CImageView::CImageView()
  39. {
  40. m_bBestFit = true;
  41. }
  42. CImageView::~CImageView()
  43. {
  44. }
  45. BOOL CImageView::PreCreateWindow(CREATESTRUCT& cs)
  46. {
  47. // TODO: Modify the Window class or styles here by modifying
  48. // the CREATESTRUCT cs
  49. return CView::PreCreateWindow(cs);
  50. }
  51. /////////////////////////////////////////////////////////////////////////////
  52. // CImageView drawing
  53. void CImageView::OnDraw(CDC* pDC)
  54. {
  55. CImageDoc* pDoc = GetDocument();
  56. ASSERT_VALID(pDoc);
  57. // TODO: add draw code for native data here
  58. }
  59. /////////////////////////////////////////////////////////////////////////////
  60. // CImageView diagnostics
  61. #ifdef _DEBUG
  62. void CImageView::AssertValid() const
  63. {
  64. CView::AssertValid();
  65. }
  66. void CImageView::Dump(CDumpContext& dc) const
  67. {
  68. CView::Dump(dc);
  69. }
  70. CImageDoc* CImageView::GetDocument() // non-debug version is inline
  71. {
  72. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CImageDoc)));
  73. return (CImageDoc*)m_pDocument;
  74. }
  75. #endif //_DEBUG
  76. /////////////////////////////////////////////////////////////////////////////
  77. // CImageView message handlers
  78. BEGIN_EVENTSINK_MAP(CImageView, CView)
  79. //{{AFX_EVENTSINK_MAP(CImageView)
  80. ON_EVENT(CImageView, ID_PREVCTRL, 3 /* OnError */, OnErrorPrevctrl, VTS_NONE)
  81. ON_EVENT(CImageView, ID_PREVCTRL, 2 /* OnPreviewReady */, OnPreviewReady, VTS_NONE)
  82. ON_EVENT(CImageView, ID_PREVCTRL, 4 /* OnBestFitPress */, OnBestFitPress, VTS_NONE)
  83. ON_EVENT(CImageView, ID_PREVCTRL, 5 /* OnActualSizePress */, OnActualSizePress, VTS_NONE)
  84. //}}AFX_EVENTSINK_MAP
  85. END_EVENTSINK_MAP()
  86. void CImageView::OnErrorPrevctrl()
  87. {
  88. // TODO: Add your control notification handler code here
  89. }
  90. void CImageView::OnPreviewReady()
  91. {
  92. // TODO: Add your control notification handler code here
  93. }
  94. void CImageView::OnBestFitPress()
  95. {
  96. m_bBestFit = true;
  97. }
  98. void CImageView::OnActualSizePress()
  99. {
  100. m_bBestFit = false;
  101. }
  102. void CImageView::OnInitialUpdate()
  103. {
  104. CView::OnInitialUpdate();
  105. }
  106. int CImageView::OnCreate(LPCREATESTRUCT lpCreateStruct)
  107. {
  108. if (CView::OnCreate(lpCreateStruct) == -1)
  109. return -1;
  110. DWORD dwToolbarMask = 0x43;
  111. CMemFile ParamFile(reinterpret_cast<BYTE*>(&dwToolbarMask), sizeof(dwToolbarMask));
  112. if (!m_PrevCtrl.Create (NULL, WS_CHILD | WS_VISIBLE,
  113. CRect (), this, ID_PREVCTRL, &ParamFile, FALSE))
  114. {
  115. return -1;
  116. }
  117. m_PrevCtrl.ShowFile (dynamic_cast<CImageDoc*>(m_pDocument)->GetImagePathName(), 1);
  118. return 0;
  119. }
  120. void CImageView::OnSize(UINT nType, int cx, int cy)
  121. {
  122. CView::OnSize(nType, cx, cy);
  123. m_PrevCtrl.MoveWindow (0, 0, cx , cy);
  124. m_PrevCtrl.UpdateWindow ();
  125. }
  126. void CImageView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
  127. {
  128. m_PrevCtrl.ShowFile (dynamic_cast<CImageDoc*>(m_pDocument)->GetImagePathName(), 1);
  129. }
  130. void CImageView::OnViewActualsize()
  131. {
  132. OnActualSizePress();
  133. m_PrevCtrl.ActualSize();
  134. }
  135. void CImageView::OnUpdateViewMenu(CCmdUI* pCmdUI)
  136. {
  137. switch (pCmdUI->m_nID)
  138. {
  139. case ID_ROTATE_90:
  140. case ID_ROTATE_COUNTER:
  141. case ID_ROTATE_CLOCKWISE:
  142. // eventually, ask the control if rotate is valid for this image
  143. pCmdUI->Enable( m_pDocument->GetPathName().GetLength());
  144. return;
  145. case ID_VIEW_BESTFIT:
  146. pCmdUI->SetCheck(m_bBestFit?1:0);
  147. pCmdUI->Enable();
  148. return;
  149. case ID_VIEW_ACTUALSIZE:
  150. pCmdUI->SetCheck(m_bBestFit?0:1);
  151. pCmdUI->Enable();
  152. return;
  153. default:
  154. // most view menu items are only available for images that have been saved to disk
  155. pCmdUI->Enable(!(m_pDocument->IsModified()));
  156. break;
  157. }
  158. }
  159. void CImageView::OnViewBestfit()
  160. {
  161. m_PrevCtrl.BestFit();
  162. OnBestFitPress();
  163. }
  164. void CImageView::OnViewSlideshow()
  165. {
  166. m_PrevCtrl.SlideShow();
  167. }
  168. void CImageView::OnViewZoomIn()
  169. {
  170. m_PrevCtrl.Zoom(1);
  171. }
  172. void CImageView::OnViewZoomOut()
  173. {
  174. m_PrevCtrl.Zoom(-1);
  175. }
  176. void CImageView::OnEditRotateClockwise()
  177. {
  178. m_PrevCtrl.Rotate (90);
  179. }
  180. void CImageView::OnEditRotateCounter()
  181. {
  182. m_PrevCtrl.Rotate (270);
  183. }
  184. HRESULT CImageView::SaveImageAs (LPCTSTR lpszPath)
  185. {
  186. TRY
  187. {
  188. m_PrevCtrl.SaveAs(CComBSTR(lpszPath));
  189. }
  190. CATCH (COleDispatchException ,e)
  191. {
  192. return ResultFromScode (e->m_scError);
  193. }
  194. END_CATCH
  195. return S_OK;
  196. }