ISeeExplorerView.cpp
上传用户:yatsl7111
上传日期:2007-01-08
资源大小:1433k
文件大小:13k
源码类别:

图形图象

开发平台:

Visual C++

  1. // ISeeExplorerView.cpp : implementation of the CISeeExplorerView class
  2. //
  3. #include "stdafx.h"
  4. #include "ISeeExplorer.h"
  5. #include "WorkSpace.h"
  6. #include "ISeeExplorerDoc.h"
  7. #include "ISeeExplorerView.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CISeeExplorerView
  15. IMPLEMENT_DYNCREATE(CISeeExplorerView, CView)
  16. BEGIN_MESSAGE_MAP(CISeeExplorerView, CView)
  17. //{{AFX_MSG_MAP(CISeeExplorerView)
  18. ON_WM_ERASEBKGND()
  19. ON_WM_CREATE()
  20. ON_WM_SIZE()
  21. ON_COMMAND(ID_C_SWITCH, OnViewSwitch)
  22. ON_UPDATE_COMMAND_UI(ID_C_SWITCH, OnUpdateViewSwitch)
  23. ON_COMMAND(ID_C_ZOOM, OnViewZoom)
  24. ON_UPDATE_COMMAND_UI(ID_C_ZOOM, OnUpdateViewZoom)
  25. ON_COMMAND(ID_C_ZOOMIN, OnViewZoomin)
  26. ON_UPDATE_COMMAND_UI(ID_C_ZOOMIN, OnUpdateViewZoomin)
  27. ON_COMMAND(ID_C_ZOOMOUT, OnViewZoomout)
  28. ON_UPDATE_COMMAND_UI(ID_C_ZOOMOUT, OnUpdateViewZoomout)
  29. //}}AFX_MSG_MAP
  30. // Standard printing commands
  31. ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
  32. ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
  33. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  34. ON_MESSAGE(IMN_CHANGING_DEM, OnChangDem)
  35. ON_MESSAGE(WM_ISEE_UPDATE_IMAGE, OnSelChanged)
  36. END_MESSAGE_MAP()
  37. /////////////////////////////////////////////////////////////////////////////
  38. // CISeeExplorerView construction/destruction
  39. CISeeExplorerView::CISeeExplorerView()
  40. {
  41. m_bmini = TRUE;
  42. m_bsil  = FALSE;
  43. m_rmax.SetRectEmpty();
  44. m_rcur.SetRectEmpty();
  45. m_rloc.SetRectEmpty();
  46. m_pCRRt = NULL;
  47. m_wsfoci = ISEE_EXPLORER_VIEW_FOCI_ZOOM;
  48. m_wsdisp = ISEE_EXPLORER_VIEW_SWITCH_DISP_AUTO;
  49. m_xl.x = m_xl.y = 0;
  50. m_xr.x = m_xr.y = 0;
  51. m_yt.x = m_yt.y = 0;
  52. m_yb.x = m_yb.y = 0;
  53. m_rdisploc.SetRectEmpty();
  54. m_rimgrect.SetRectEmpty();
  55. m_rdemx.SetRectEmpty();
  56. m_rdemy.SetRectEmpty();
  57. m_sbn.CreatePen(PS_SOLID,1,(COLORREF)RGB(255,255,255));
  58. m_scn.CreatePen(PS_SOLID,1,(COLORREF)RGB(128,128,128));
  59. }
  60. CISeeExplorerView::~CISeeExplorerView()
  61. {
  62. m_sbn.DeleteObject();
  63. m_scn.DeleteObject();
  64. }
  65. BOOL CISeeExplorerView::PreCreateWindow(CREATESTRUCT& cs)
  66. {
  67. cs.style |= WS_CLIPCHILDREN;
  68. return CView::PreCreateWindow(cs);
  69. }
  70. /////////////////////////////////////////////////////////////////////////////
  71. // CISeeExplorerView drawing
  72. void CISeeExplorerView::OnDraw(CDC* pDC)
  73. {
  74. CISeeExplorerDoc* pDoc = GetDocument();
  75. ASSERT_VALID(pDoc);
  76. DrawDem(pDC);
  77. }
  78. /////////////////////////////////////////////////////////////////////////////
  79. // CISeeExplorerView printing
  80. BOOL CISeeExplorerView::OnPreparePrinting(CPrintInfo* pInfo)
  81. {
  82. // default preparation
  83. return DoPreparePrinting(pInfo);
  84. }
  85. void CISeeExplorerView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  86. {
  87. // TODO: add extra initialization before printing
  88. }
  89. void CISeeExplorerView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  90. {
  91. // TODO: add cleanup after printing
  92. }
  93. /////////////////////////////////////////////////////////////////////////////
  94. // CISeeExplorerView diagnostics
  95. #ifdef _DEBUG
  96. void CISeeExplorerView::AssertValid() const
  97. {
  98. CView::AssertValid();
  99. }
  100. void CISeeExplorerView::Dump(CDumpContext& dc) const
  101. {
  102. CView::Dump(dc);
  103. }
  104. CISeeExplorerDoc* CISeeExplorerView::GetDocument() // non-debug version is inline
  105. {
  106. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CISeeExplorerDoc)));
  107. return (CISeeExplorerDoc*)m_pDocument;
  108. }
  109. #endif //_DEBUG
  110. /////////////////////////////////////////////////////////////////////////////
  111. // CISeeExplorerView message handlers
  112. void CISeeExplorerView::OnInitialUpdate() 
  113. {
  114. CView::OnInitialUpdate();
  115. CISeeExplorerDoc * pDoc = GetDocument();
  116. ASSERT_VALID(pDoc);
  117. pDoc->m_pWorkView = this;
  118. ModifyStyleEx(WS_EX_CLIENTEDGE, 0, FALSE);
  119. }
  120. BOOL CISeeExplorerView::OnEraseBkgnd(CDC* pDC) 
  121. {
  122. CRect rect;
  123. GetClientRect(rect);
  124. pDC->FillSolidRect(rect, (COLORREF)::GetSysColor(COLOR_3DFACE));
  125. pDC->DrawEdge(rect, EDGE_ETCHED, BF_RECT);
  126. return TRUE;
  127. }
  128. int CISeeExplorerView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  129. {
  130. if (CView::OnCreate(lpCreateStruct) == -1)
  131. return -1;
  132. if (!m_ws.Create(NULL, NULL, WS_CHILD|WS_VISIBLE, CRect(0,0,0,0), 
  133. this, ISEE_EXPLORER_WS_WNDID))
  134. return -1;
  135. return 0;
  136. }
  137. void CISeeExplorerView::OnSize(UINT nType, int cx, int cy) 
  138. {
  139. CView::OnSize(nType, cx, cy);
  140. if ((cx <= (ISEE_EXPLORER_VIEW_WNDREV_WIDTH_LEFT+ISEE_EXPLORER_VIEW_WNDREV_WIDTH_RIGHT))||
  141. (cy <= (ISEE_EXPLORER_VIEW_WNDREV_HEIGHT_TOP+ISEE_EXPLORER_VIEW_WNDREV_HEIGHT_BOTTOM)))
  142. {
  143. m_bmini = TRUE;
  144. m_rmax.SetRectEmpty();
  145. m_xl.x = m_xl.y = 0;
  146. m_xr.x = m_xr.y = 0;
  147. m_yt.x = m_yt.y = 0;
  148. m_yb.x = m_yb.y = 0;
  149. }
  150. else
  151. {
  152. m_bmini = FALSE;
  153. m_rmax.SetRect(ISEE_EXPLORER_VIEW_WNDREV_WIDTH_LEFT, 
  154. ISEE_EXPLORER_VIEW_WNDREV_HEIGHT_TOP, 
  155. cx-ISEE_EXPLORER_VIEW_WNDREV_WIDTH_RIGHT, 
  156. cy-ISEE_EXPLORER_VIEW_WNDREV_HEIGHT_BOTTOM);
  157. m_xl.x = m_rmax.left;
  158. m_xl.y = cy-ISEE_EXPLORER_VIEW_WNDREV_HEIGHT_BOTTOM/2-2;
  159. //m_xr.x = cx-ISEE_EXPLORER_VIEW_WNDREV_WIDTH_RIGHT/2-2;
  160. m_xr.x = m_rmax.right;
  161. m_xr.y = cy-ISEE_EXPLORER_VIEW_WNDREV_HEIGHT_BOTTOM/2-2;
  162. m_yt.x = cx-ISEE_EXPLORER_VIEW_WNDREV_WIDTH_RIGHT/2-2;
  163. m_yt.y = m_rmax.top;
  164. m_yb.x = cx-ISEE_EXPLORER_VIEW_WNDREV_WIDTH_RIGHT/2-2;
  165. //m_yb.y = cy-ISEE_EXPLORER_VIEW_WNDREV_HEIGHT_BOTTOM/2-2;
  166. m_yb.y = m_rmax.bottom;
  167. }
  168. if (m_ws.GetSafeHwnd())
  169. {
  170. UpdateWSize();
  171. m_ws.PostMessage(IMN_CHANGING_FOCI, 0, (LPARAM)(CRect*)&m_rcur);
  172. m_ws.MoveWindow(m_rloc, TRUE);
  173. }
  174. }
  175. void CISeeExplorerView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
  176. {
  177. }
  178. CReturnReceipt * CISeeExplorerView::GetCurCRRt()
  179. {
  180. return GetDocument()->m_pRReceipt;
  181. }
  182. void CISeeExplorerView::UpdateWSize()
  183. {
  184. if (!m_pCRRt)
  185. return;
  186. if (m_pCRRt->GetDataPackState() < PKST_PASSINFO)
  187. return;
  188. float fy;
  189. CRect rect(0,0,m_pCRRt->GetImageWidth(),m_pCRRt->GetImageHeight());
  190. if (m_wsdisp == ISEE_EXPLORER_VIEW_SWITCH_DISP_AUTO)
  191. {
  192. fy = (float)m_pCRRt->GetImageWidth()/(float)m_pCRRt->GetImageHeight();
  193. if ((rect.Width() > m_rmax.Width())||(rect.Height() > m_rmax.Height()))
  194. {
  195. m_bsil = TRUE;
  196. if (rect.Width() > m_rmax.Width())
  197. rect.DeflateRect(0, 0, rect.Width()-m_rmax.Width(), (int)((rect.Width()-m_rmax.Width())/fy));
  198. if (rect.Height() > m_rmax.Height())
  199. rect.DeflateRect(0, 0, (int)((rect.Height()-m_rmax.Height())*fy), rect.Height()-m_rmax.Height());
  200. }
  201. else
  202. m_bsil = FALSE;
  203. }
  204. else
  205. {
  206. ASSERT(m_wsdisp == ISEE_EXPLORER_VIEW_SWITCH_DISP_HAND);
  207. if (m_wsfoci == ISEE_EXPLORER_VIEW_FOCI_ZOOM)
  208. { // 原始尺寸
  209. ;
  210. }
  211. else if ((ISEE_EXPLORER_VIEW_FOCI_ZOOM < m_wsfoci)&&(m_wsfoci < ISEE_EXPLORER_VIEW_FOCI_OUT))
  212. { // 放大显示方式
  213. rect.right = rect.right*m_wsfoci;
  214. rect.bottom= rect.bottom*m_wsfoci;
  215. }
  216. else if ((ISEE_EXPLORER_VIEW_FOCI_IN < m_wsfoci)&&(m_wsfoci < ISEE_EXPLORER_VIEW_FOCI_ZOOM))
  217. { // 缩小显示方式
  218. ASSERT(m_wsfoci);
  219. rect.right = rect.right/::abs(m_wsfoci);
  220. rect.bottom= rect.bottom/::abs(m_wsfoci);
  221. }
  222. else
  223. ASSERT(FALSE); // 非法的缩放倍数值
  224. if ((rect.Width() > m_rmax.Width())||(rect.Height() > m_rmax.Height()))
  225. {
  226. m_bsil = TRUE;
  227. if (rect.Width() > m_rmax.Width())
  228. rect.right = m_rmax.Width();
  229. if (rect.Height() > m_rmax.Height())
  230. rect.bottom= m_rmax.Height();
  231. }
  232. else
  233. m_bsil = FALSE;
  234. }
  235. m_rcur = rect;
  236. rect.OffsetRect((m_rmax.Width()-rect.Width())/2, (m_rmax.Height()-rect.Height())/2);
  237. rect.OffsetRect(m_rmax.left, m_rmax.top);
  238. m_ws.CalcWindowRect(rect, CWnd::adjustOutside);
  239. m_rloc = rect;
  240. return;
  241. }
  242. void CISeeExplorerView::DrawDem(CDC *pDC)
  243. {
  244. if (m_wsdisp == ISEE_EXPLORER_VIEW_SWITCH_DISP_AUTO)
  245. return;
  246. CPen *pOldPen = pDC->SelectObject((CPen*)&m_sbn);
  247. if ((m_pCRRt)&&(!m_rdisploc.IsRectNull())&&(m_bsil))
  248. {
  249. ASSERT(!m_rimgrect.IsRectNull());
  250. int   i;
  251. float fdemx = (m_xr.x-m_xl.x)/(float)m_rimgrect.Width();
  252. float fdemy = (m_yb.y-m_yt.y)/(float)m_rimgrect.Height();
  253. float fx = ((float)m_rmax.Width())/10;
  254. float fy = ((float)m_rmax.Height())/10;
  255. m_rdemx.left = (LONG)((float)m_xl.x + m_rdisploc.left*fdemx);
  256. m_rdemx.top  = m_xl.y;
  257. m_rdemx.right  = (LONG)((float)m_xl.x + m_rdisploc.right*fdemx);
  258. m_rdemx.bottom = m_xl.y;
  259. m_rdemy.left = m_yt.x;
  260. m_rdemy.top  = (LONG)((float)m_yt.y + m_rdisploc.top*fdemy);
  261. m_rdemy.right  = m_yt.x;
  262. m_rdemy.bottom = (LONG)((float)m_yt.y + m_rdisploc.bottom*fdemy);
  263. int foci = (m_wsfoci == 0) ? 1 : ::abs(m_wsfoci);
  264. BOOL  bSing = ((m_rdisploc.Width()/foci<m_rimgrect.Width()/foci)&&
  265. (m_rdisploc.Height()/foci<m_rimgrect.Height()/foci)) ? TRUE:FALSE;
  266. if (m_rdisploc.Width()/foci < m_rimgrect.Width()/foci)
  267. {
  268. for (i=0;i<=10;i++)
  269. {
  270. if (i == 0)
  271. {
  272. pDC->MoveTo(m_xl);
  273. pDC->LineTo(m_xl.x, m_xl.y-ISEE_EXPLORER_VIEW_DEM_HEAD);
  274. }
  275. else if (i == 10)
  276. {
  277. pDC->MoveTo(m_xl.x+(int)(i*fx+0.5), m_xl.y);
  278. pDC->LineTo(m_xl.x+(int)(i*fx+0.5), m_xl.y-ISEE_EXPLORER_VIEW_DEM_TAIL);
  279. }
  280. else
  281. {
  282. pDC->MoveTo(m_xl.x+(int)(i*fx+0.5), m_xl.y);
  283. pDC->LineTo(m_xl.x+(int)(i*fx+0.5), m_xl.y-ISEE_EXPLORER_VIEW_DEM_NAML);
  284. }
  285. }
  286. pDC->MoveTo(m_xl);
  287. pDC->LineTo(m_rdemx.TopLeft());
  288. pDC->SelectObject((CPen*)&m_scn);
  289. pDC->LineTo(m_rdemx.BottomRight());
  290. pDC->SelectObject((CPen*)&m_sbn);
  291. pDC->LineTo(m_xr);
  292. }
  293. if (m_rdisploc.Height()/foci < m_rimgrect.Height()/foci)
  294. {
  295. for (i=0;i<=10;i++)
  296. {
  297. if (i == 0)
  298. {
  299. pDC->MoveTo(m_yt);
  300. pDC->LineTo(m_yt.x-ISEE_EXPLORER_VIEW_DEM_HEAD, m_yt.y);
  301. }
  302. else if (i == 10)
  303. {
  304. pDC->MoveTo(m_yt.x, m_yt.y+(int)(i*fy+0.5));
  305. pDC->LineTo(m_yt.x-ISEE_EXPLORER_VIEW_DEM_TAIL, m_yt.y+(int)(i*fy+0.5));
  306. }
  307. else
  308. {
  309. pDC->MoveTo(m_yt.x, m_yt.y+(int)(i*fy+0.5));
  310. pDC->LineTo(m_yt.x-ISEE_EXPLORER_VIEW_DEM_NAML, m_yt.y+(int)(i*fy+0.5));
  311. }
  312. }
  313. pDC->MoveTo(m_yt);
  314. pDC->LineTo(m_rdemy.TopLeft());
  315. pDC->SelectObject((CPen*)&m_scn);
  316. pDC->LineTo(m_rdemy.BottomRight());
  317. pDC->SelectObject((CPen*)&m_sbn);
  318. pDC->LineTo(m_yb);
  319. }
  320. if (bSing)
  321. pDC->Rectangle(m_xr.x+1, m_yb.y+1, m_yb.x+1, m_xr.y+1);
  322. }
  323. pDC->SelectObject(pOldPen);
  324. }
  325. void CISeeExplorerView::OnViewSwitch() 
  326. {
  327. m_wsdisp = (ISEE_EXPLORER_VIEW_SWITCH_DISP_AUTO == m_wsdisp) ? ISEE_EXPLORER_VIEW_SWITCH_DISP_HAND:ISEE_EXPLORER_VIEW_SWITCH_DISP_AUTO;
  328. UpdateWSize();
  329. m_ws.PostMessage(IMN_CHANGING_FOCI, 0, (LPARAM)(CRect*)&m_rcur);
  330. m_ws.MoveWindow(m_rloc, TRUE);
  331. RedrawWindow();
  332. }
  333. void CISeeExplorerView::OnUpdateViewSwitch(CCmdUI* pCmdUI) 
  334. {
  335. if (ISEE_EXPLORER_VIEW_SWITCH_DISP_AUTO == m_wsdisp)
  336. pCmdUI->SetCheck(0);
  337. else
  338. pCmdUI->SetCheck(1);
  339. }
  340. void CISeeExplorerView::OnViewZoom() 
  341. {
  342. m_wsfoci = ISEE_EXPLORER_VIEW_FOCI_ZOOM;
  343. UpdateWSize();
  344. m_ws.SendMessage(IMN_CHANGING_FOCI, 0, (LPARAM)(CRect*)&m_rcur);
  345. m_ws.MoveWindow(m_rloc, TRUE);
  346. RedrawWindow();
  347. }
  348. void CISeeExplorerView::OnUpdateViewZoom(CCmdUI* pCmdUI) 
  349. {
  350. if (m_wsdisp == ISEE_EXPLORER_VIEW_SWITCH_DISP_AUTO)
  351. pCmdUI->Enable(FALSE);
  352. else
  353. {
  354. if (m_wsfoci == ISEE_EXPLORER_VIEW_FOCI_ZOOM)
  355. pCmdUI->Enable(FALSE);
  356. else
  357. pCmdUI->Enable();
  358. }
  359. }
  360. void CISeeExplorerView::OnViewZoomin() 
  361. {
  362. ASSERT(m_wsfoci > ISEE_EXPLORER_VIEW_FOCI_IN);
  363. if (::abs(--m_wsfoci) == 1)
  364. m_wsfoci--;
  365. UpdateWSize();
  366. m_ws.SendMessage(IMN_CHANGING_FOCI, 0, (LPARAM)(CRect*)&m_rcur);
  367. m_ws.MoveWindow(m_rloc, TRUE);
  368. RedrawWindow();
  369. }
  370. void CISeeExplorerView::OnUpdateViewZoomin(CCmdUI* pCmdUI) 
  371. {
  372. if (m_wsdisp == ISEE_EXPLORER_VIEW_SWITCH_DISP_AUTO)
  373. pCmdUI->Enable(FALSE);
  374. else
  375. {
  376. if (m_wsfoci > (ISEE_EXPLORER_VIEW_FOCI_IN+1))
  377. pCmdUI->Enable();
  378. else
  379. pCmdUI->Enable(FALSE);
  380. }
  381. }
  382. void CISeeExplorerView::OnViewZoomout() 
  383. {
  384. ASSERT(m_wsfoci < ISEE_EXPLORER_VIEW_FOCI_OUT);
  385. if (::abs(++m_wsfoci) == 1)
  386. m_wsfoci++;
  387. UpdateWSize();
  388. m_ws.SendMessage(IMN_CHANGING_FOCI, 0, (LPARAM)(CRect*)&m_rcur);
  389. m_ws.MoveWindow(m_rloc, TRUE);
  390. RedrawWindow();
  391. }
  392. void CISeeExplorerView::OnUpdateViewZoomout(CCmdUI* pCmdUI) 
  393. {
  394. if (m_wsdisp == ISEE_EXPLORER_VIEW_SWITCH_DISP_AUTO)
  395. pCmdUI->Enable(FALSE);
  396. else
  397. {
  398. if (m_wsfoci < (ISEE_EXPLORER_VIEW_FOCI_OUT-1))
  399. pCmdUI->Enable();
  400. else
  401. pCmdUI->Enable(FALSE);
  402. }
  403. }
  404. int CISeeExplorerView::GetDispMode()
  405. {
  406. return m_wsdisp;
  407. }
  408. int CISeeExplorerView::GetFoci()
  409. {
  410. return m_wsfoci;
  411. }
  412. BOOL CISeeExplorerView::GetSliMark()
  413. {
  414. return m_bsil;
  415. }
  416. LONG CISeeExplorerView::OnChangDem(UINT parm1, LONG parm2)
  417. {
  418. m_rdisploc = *((CRect*)parm1);
  419. m_rimgrect = *((CRect*)parm2);
  420. CDC dc;
  421. HDC hDC = ::GetDC(GetSafeHwnd());
  422. dc.Attach(hDC);
  423. DrawDem(&dc);
  424. hDC = dc.Detach();
  425. ::ReleaseDC(GetSafeHwnd(), hDC);
  426. return 0L;
  427. }
  428. LONG CISeeExplorerView::OnSelChanged(UINT pm1, LONG pm2)
  429. {
  430. if (!GetCurCRRt())
  431. return -1;
  432. m_pCRRt = GetCurCRRt();
  433. while (m_pCRRt->GetResult() == IRWERRT_ING);
  434. m_wsfoci = ISEE_EXPLORER_VIEW_FOCI_ZOOM;
  435. UpdateWSize();
  436. m_ws.PostMessage(IMN_CHANGING_IMAGE, 0, (LPARAM)(CRect*)&m_rcur);
  437. m_ws.MoveWindow(m_rloc, TRUE);
  438. InvalidateRect(NULL);
  439. return 0L;
  440. }