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.

393 lines
9.0 KiB

  1. // WIAPreview.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "wiatest.h"
  5. #include "WIAPreview.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CWIAPreview
  13. /**************************************************************************\
  14. * CWIAPreview::CWIAPreview()
  15. *
  16. * Constructor for the CWIAPreview class
  17. *
  18. *
  19. * Arguments:
  20. *
  21. * none
  22. *
  23. * Return Value:
  24. *
  25. * none
  26. *
  27. * History:
  28. *
  29. * 2/14/1999 Original Version
  30. *
  31. \**************************************************************************/
  32. CWIAPreview::CWIAPreview()
  33. {
  34. m_PaintMode = PAINT_TOFIT;
  35. m_pDIB = NULL;
  36. m_Scrollpt.x = 0;
  37. m_Scrollpt.y = 0;
  38. }
  39. /**************************************************************************\
  40. * CWIAPreview::~CWIAPreview()
  41. *
  42. * Destructor for the CWIAPreview class
  43. *
  44. *
  45. * Arguments:
  46. *
  47. * none
  48. *
  49. * Return Value:
  50. *
  51. * none
  52. *
  53. * History:
  54. *
  55. * 2/14/1999 Original Version
  56. *
  57. \**************************************************************************/
  58. CWIAPreview::~CWIAPreview()
  59. {
  60. }
  61. BEGIN_MESSAGE_MAP(CWIAPreview, CWnd)
  62. //{{AFX_MSG_MAP(CWIAPreview)
  63. ON_WM_PAINT()
  64. ON_WM_HSCROLL()
  65. ON_WM_VSCROLL()
  66. //}}AFX_MSG_MAP
  67. END_MESSAGE_MAP()
  68. /////////////////////////////////////////////////////////////////////////////
  69. // CWIAPreview message handlers
  70. /**************************************************************************\
  71. * CWIAPreview::OnPaint()
  72. *
  73. * Handles painting of the DIB
  74. *
  75. *
  76. * Arguments:
  77. *
  78. * none
  79. *
  80. * Return Value:
  81. *
  82. * none
  83. *
  84. * History:
  85. *
  86. * 2/14/1999 Original Version
  87. *
  88. \**************************************************************************/
  89. void CWIAPreview::OnPaint()
  90. {
  91. CPaintDC dc(this); // device context for painting
  92. CleanBackground();
  93. PaintImage();
  94. // Do not call CWnd::OnPaint() for painting messages
  95. }
  96. /**************************************************************************\
  97. * CWIAPreview::SetDIB()
  98. *
  99. * Initializes Preview window with a DIB pointer to data display.
  100. *
  101. *
  102. * Arguments:
  103. *
  104. * pDib - DIB data to display
  105. *
  106. * Return Value:
  107. *
  108. * none
  109. *
  110. * History:
  111. *
  112. * 2/14/1999 Original Version
  113. *
  114. \**************************************************************************/
  115. void CWIAPreview::SetDIB(CDib *pDib)
  116. {
  117. m_pDIB = pDib;
  118. if(pDib != NULL)
  119. {
  120. //
  121. // Set Scroll sizes according to DIB data size
  122. //
  123. SetScrollRange(SB_HORZ,0,pDib->Width(),TRUE);
  124. SetScrollRange(SB_VERT,0,pDib->Height(),TRUE);
  125. }
  126. }
  127. /**************************************************************************\
  128. * CWIAPreview::SetPaintMode()
  129. *
  130. * Toggle the preview mode.
  131. *
  132. *
  133. * Arguments:
  134. *
  135. * modeflag - Toggle flag for setting display modes
  136. * PAINT_ACTUAL - actual size of image (1 to 1)
  137. * PAINT_TOFIT - scales image to fit window frame
  138. *
  139. * Return Value:
  140. *
  141. * none
  142. *
  143. * History:
  144. *
  145. * 2/14/1999 Original Version
  146. *
  147. \**************************************************************************/
  148. void CWIAPreview::SetPaintMode(int modeflag)
  149. {
  150. m_PaintMode = modeflag;
  151. }
  152. /**************************************************************************\
  153. * CWIAPreview::OnHScroll()
  154. *
  155. * Handles Horizontal scroll messages
  156. *
  157. *
  158. * Arguments:
  159. *
  160. * nSBCode - Scroll bar code
  161. * nPos - Scroll position (valid only is SB_THUMBTRACK,SB_THUMBPOSITION)
  162. * pScrollBar - pointer to Scrollbar control
  163. *
  164. * Return Value:
  165. *
  166. * none
  167. *
  168. * History:
  169. *
  170. * 2/14/1999 Original Version
  171. *
  172. \**************************************************************************/
  173. void CWIAPreview::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  174. {
  175. switch(nSBCode)
  176. {
  177. case SB_LINELEFT:
  178. m_Scrollpt.x +=1;
  179. if(m_Scrollpt.x >0)
  180. m_Scrollpt.x = 0;
  181. SetScrollPos(SB_HORZ,-m_Scrollpt.x,TRUE);
  182. break;
  183. case SB_LINERIGHT:
  184. m_Scrollpt.x -=1;
  185. SetScrollPos(SB_HORZ,-m_Scrollpt.x,TRUE);
  186. break;
  187. case SB_PAGERIGHT:
  188. m_Scrollpt.x -=5;
  189. SetScrollPos(SB_HORZ,-m_Scrollpt.x,TRUE);
  190. break;
  191. case SB_PAGELEFT:
  192. m_Scrollpt.x +=5;
  193. if(m_Scrollpt.x >0)
  194. m_Scrollpt.x = 0;
  195. SetScrollPos(SB_HORZ,-m_Scrollpt.x,TRUE);
  196. break;
  197. case SB_THUMBPOSITION:
  198. case SB_THUMBTRACK:
  199. m_Scrollpt.x = (nPos * -1);
  200. SetScrollPos(SB_HORZ,nPos,TRUE);
  201. break;
  202. case SB_ENDSCROLL:
  203. // OutputDebugString("END SCROLL\n");
  204. break;
  205. default:
  206. // OutputDebugString("Default????\n");
  207. break;
  208. }
  209. PaintImage();
  210. CWnd::OnHScroll(nSBCode, nPos, pScrollBar);
  211. }
  212. /**************************************************************************\
  213. * CWIAPreview::OnVScroll()
  214. *
  215. * Handles Vertical scroll messages
  216. *
  217. *
  218. * Arguments:
  219. *
  220. * nSBCode - Scroll bar code
  221. * nPos - Scroll position (valid only is SB_THUMBTRACK,SB_THUMBPOSITION)
  222. * pScrollBar - pointer to Scrollbar control
  223. *
  224. * Return Value:
  225. *
  226. * none
  227. *
  228. * History:
  229. *
  230. * 2/14/1999 Original Version
  231. *
  232. \**************************************************************************/
  233. void CWIAPreview::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  234. {
  235. switch(nSBCode)
  236. {
  237. case SB_LINEUP:
  238. m_Scrollpt.y +=1;
  239. if(m_Scrollpt.y >0)
  240. m_Scrollpt.y = 0;
  241. SetScrollPos(SB_VERT,-m_Scrollpt.y,TRUE);
  242. break;
  243. case SB_LINEDOWN:
  244. m_Scrollpt.y -=1;
  245. SetScrollPos(SB_VERT,-m_Scrollpt.y,TRUE);
  246. break;
  247. case SB_PAGEUP:
  248. m_Scrollpt.y +=5;
  249. if(m_Scrollpt.y >0)
  250. m_Scrollpt.y = 0;
  251. SetScrollPos(SB_VERT,-m_Scrollpt.y,TRUE);
  252. break;
  253. case SB_PAGEDOWN:
  254. m_Scrollpt.y -=5;
  255. SetScrollPos(SB_VERT,-m_Scrollpt.y,TRUE);
  256. break;
  257. case SB_THUMBPOSITION:
  258. case SB_THUMBTRACK:
  259. m_Scrollpt.y = (nPos * -1);
  260. SetScrollPos(SB_VERT,nPos,TRUE);
  261. break;
  262. case SB_ENDSCROLL:
  263. // OutputDebugString("END SCROLL\n");
  264. break;
  265. default:
  266. // OutputDebugString("Default????\n");
  267. break;
  268. }
  269. PaintImage();
  270. CWnd::OnVScroll(nSBCode, nPos, pScrollBar);
  271. }
  272. /**************************************************************************\
  273. * CWIAPreview::PaintImage()
  274. *
  275. * Handles image painting according to set mode
  276. *
  277. *
  278. * Arguments:
  279. *
  280. * none
  281. *
  282. * Return Value:
  283. *
  284. * none
  285. *
  286. * History:
  287. *
  288. * 2/14/1999 Original Version
  289. *
  290. \**************************************************************************/
  291. void CWIAPreview::PaintImage()
  292. {
  293. if(m_pDIB != NULL)
  294. {
  295. RECT ImageRect;
  296. RECT WindowRect;
  297. DWORD ScaleFactor = 0;
  298. CDC* pDC = NULL;
  299. pDC = GetDC();
  300. if(m_pDIB->GotImage())
  301. {
  302. if(m_PaintMode == PAINT_TOFIT)
  303. {
  304. ImageRect.top = 0;
  305. ImageRect.left = 0;
  306. ImageRect.right = m_pDIB->Width();
  307. ImageRect.bottom = m_pDIB->Height();
  308. GetWindowRect(&WindowRect);
  309. ScreenToClient(&WindowRect);
  310. WindowRect.bottom-=1;
  311. WindowRect.left+=1;
  312. WindowRect.right-=1;
  313. WindowRect.top+=1;
  314. m_pDIB->Paint(pDC->m_hDC,&WindowRect,&ImageRect);
  315. ShowScrollBar(SB_BOTH,FALSE);
  316. }
  317. else
  318. {
  319. ImageRect.top = 0;
  320. ImageRect.left = 0;
  321. ImageRect.right = m_pDIB->Width();
  322. ImageRect.bottom = m_pDIB->Height();
  323. WindowRect.bottom = ImageRect.bottom;
  324. WindowRect.left = m_Scrollpt.x;
  325. WindowRect.right = ImageRect.right;
  326. WindowRect.top = m_Scrollpt.y;
  327. m_pDIB->Paint(pDC->m_hDC,&WindowRect,&ImageRect);
  328. ShowScrollBar(SB_BOTH,TRUE);
  329. }
  330. }
  331. else
  332. {
  333. GetWindowRect(&WindowRect);
  334. ScreenToClient(&WindowRect);
  335. WindowRect.bottom-=1;
  336. WindowRect.left+=1;
  337. WindowRect.right-=1;
  338. WindowRect.top+=1;
  339. HBRUSH hBrush = CreateSolidBrush(GetBkColor(pDC->m_hDC));
  340. FillRect(pDC->m_hDC,&WindowRect,hBrush);
  341. DeleteObject(hBrush);
  342. }
  343. }
  344. }
  345. /**************************************************************************\
  346. * CWIAPreview::CleanBackground()
  347. *
  348. * Wipes the surface for a repaint to take place (WHITE)
  349. *
  350. *
  351. * Arguments:
  352. *
  353. * none
  354. *
  355. * Return Value:
  356. *
  357. * none
  358. *
  359. * History:
  360. *
  361. * 2/14/1999 Original Version
  362. *
  363. \**************************************************************************/
  364. void CWIAPreview::CleanBackground()
  365. {
  366. RECT WindowRect;
  367. CDC* pDC = NULL;
  368. pDC = GetDC();
  369. GetWindowRect(&WindowRect);
  370. ScreenToClient(&WindowRect);
  371. WindowRect.bottom-=1;
  372. WindowRect.left+=1;
  373. WindowRect.right-=1;
  374. WindowRect.top+=1;
  375. HBRUSH hBrush = CreateSolidBrush(GetBkColor(pDC->m_hDC));
  376. FillRect(pDC->m_hDC,&WindowRect,hBrush);
  377. DeleteObject(hBrush);
  378. }