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.

302 lines
8.6 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 1999,2000
  4. *
  5. * TITLE: SSHNDLER.CPP
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: ShaunIv
  10. *
  11. * DATE: 12/4/1999
  12. *
  13. * DESCRIPTION:
  14. *
  15. *******************************************************************************/
  16. #include "precomp.h"
  17. #pragma hdrstop
  18. #include "sshndler.h"
  19. #include "ssutil.h"
  20. CScreenSaverHandler::CScreenSaverHandler( HWND hWnd, UINT nFindNotifyMessage, UINT nPaintTimer, UINT nChangeTimer, UINT nBackupStartTimer, LPCTSTR szRegistryPath, HINSTANCE hInstance )
  21. : m_hWnd(hWnd),
  22. m_hInstance(hInstance),
  23. m_strRegistryPath(szRegistryPath),
  24. m_nFindNotifyMessage(nFindNotifyMessage),
  25. m_nPaintTimerId(nPaintTimer),
  26. m_nChangeTimerId(nChangeTimer),
  27. m_nBackupStartTimerId(nBackupStartTimer),
  28. m_nBackupStartTimerPeriod(BACKUP_START_TIMER_PERIOD),
  29. m_pImageScreenSaver(NULL),
  30. m_bPaused(false),
  31. m_hFindThread(NULL),
  32. m_hFindCancel(NULL),
  33. m_bScreensaverStarted(false),
  34. m_nStartImage(0),
  35. m_nShuffleInterval(SHUFFLE_INTERVAL)
  36. {
  37. m_nStartImage = m_Random.Generate(MAX_START_IMAGE);
  38. }
  39. void CScreenSaverHandler::Initialize(void)
  40. {
  41. CWaitCursor wc;
  42. HDC hDC = GetDC(m_hWnd);
  43. if (hDC)
  44. {
  45. m_pImageScreenSaver = new CImageScreenSaver( m_hInstance, m_strRegistryPath );
  46. if (m_pImageScreenSaver)
  47. {
  48. m_pImageScreenSaver->SetScreenRect(m_hWnd);
  49. if (m_pImageScreenSaver->IsValid())
  50. {
  51. m_hFindCancel = CreateEvent( NULL, TRUE, FALSE, NULL );
  52. if (m_hFindCancel)
  53. {
  54. m_hFindThread = m_pImageScreenSaver->Initialize( m_hWnd, m_nFindNotifyMessage, m_hFindCancel );
  55. }
  56. SetTimer( m_hWnd, m_nBackupStartTimerId, m_nBackupStartTimerPeriod, NULL );
  57. }
  58. else
  59. {
  60. WIA_TRACE((TEXT("CScreenSaverHandler::CScreenSaverHandler, m_pImageScreenSaver->IsValid() returned failed\n")));
  61. delete m_pImageScreenSaver;
  62. m_pImageScreenSaver = NULL;
  63. }
  64. }
  65. else
  66. {
  67. WIA_TRACE((TEXT("CScreenSaverHandler::CScreenSaverHandler, unable to create m_pImageScreenSaver\n")));
  68. }
  69. ReleaseDC( m_hWnd, hDC );
  70. }
  71. else
  72. {
  73. WIA_TRACE((TEXT("CScreenSaverHandler::CScreenSaverHandler, GetDC failed\n")));
  74. }
  75. }
  76. CScreenSaverHandler::~CScreenSaverHandler(void)
  77. {
  78. if (m_pImageScreenSaver)
  79. {
  80. delete m_pImageScreenSaver;
  81. m_pImageScreenSaver = NULL;
  82. }
  83. if (m_hFindCancel)
  84. {
  85. SetEvent(m_hFindCancel);
  86. CloseHandle(m_hFindCancel);
  87. m_hFindCancel = NULL;
  88. }
  89. if (m_hFindThread)
  90. {
  91. WaitForSingleObject( m_hFindThread, INFINITE );
  92. CloseHandle(m_hFindThread);
  93. m_hFindThread = NULL;
  94. }
  95. }
  96. bool CScreenSaverHandler::HandleKeyboardMessage( UINT nMessage, WPARAM nVirtkey )
  97. {
  98. if (m_pImageScreenSaver && m_pImageScreenSaver->AllowKeyboardControl())
  99. {
  100. if (nMessage == WM_KEYDOWN)
  101. {
  102. switch (nVirtkey)
  103. {
  104. case VK_DOWN:
  105. if (nMessage == WM_KEYDOWN)
  106. {
  107. m_bPaused = !m_bPaused;
  108. if (!m_bPaused)
  109. {
  110. if (m_pImageScreenSaver && m_pImageScreenSaver->ReplaceImage(true,false))
  111. m_Timer.Set( m_hWnd, m_nPaintTimerId, m_pImageScreenSaver->PaintTimerInterval() );
  112. }
  113. }
  114. return true;
  115. case VK_LEFT:
  116. if (nMessage == WM_KEYDOWN)
  117. {
  118. if (m_pImageScreenSaver && m_pImageScreenSaver->ReplaceImage(false,true))
  119. m_Timer.Set( m_hWnd, m_nPaintTimerId, m_pImageScreenSaver->PaintTimerInterval() );
  120. }
  121. return true;
  122. case VK_RIGHT:
  123. if (nMessage == WM_KEYDOWN)
  124. {
  125. if (m_pImageScreenSaver && m_pImageScreenSaver->ReplaceImage(true,true))
  126. m_Timer.Set( m_hWnd, m_nPaintTimerId, m_pImageScreenSaver->PaintTimerInterval() );
  127. }
  128. return true;
  129. }
  130. }
  131. }
  132. return false;
  133. }
  134. void CScreenSaverHandler::HandleConfigChanged(void)
  135. {
  136. if (m_pImageScreenSaver)
  137. {
  138. m_pImageScreenSaver->SetScreenRect(m_hWnd);
  139. m_pImageScreenSaver->ReadConfigData();
  140. }
  141. }
  142. void CScreenSaverHandler::HandleTimer( WPARAM nEvent )
  143. {
  144. if (nEvent == m_nPaintTimerId)
  145. {
  146. if (m_pImageScreenSaver)
  147. {
  148. CSimpleDC ClientDC;
  149. if (ClientDC.GetDC(m_hWnd))
  150. {
  151. bool bResult = m_pImageScreenSaver->TimerTick( ClientDC );
  152. if (bResult)
  153. {
  154. m_Timer.Set( m_hWnd, m_nChangeTimerId, m_pImageScreenSaver->ChangeTimerInterval() );
  155. }
  156. }
  157. }
  158. }
  159. else if (nEvent == m_nChangeTimerId)
  160. {
  161. m_Timer.Kill();
  162. if (!m_bPaused && m_pImageScreenSaver && m_pImageScreenSaver->ReplaceImage(true,false))
  163. {
  164. m_Timer.Set( m_hWnd, m_nPaintTimerId, m_pImageScreenSaver->PaintTimerInterval() );
  165. //
  166. // Mark that we've been started
  167. //
  168. if (!m_bScreensaverStarted)
  169. {
  170. m_bScreensaverStarted = true;
  171. }
  172. }
  173. }
  174. else if (nEvent == m_nBackupStartTimerId)
  175. {
  176. //
  177. // Make sure we don't get any more of these
  178. //
  179. KillTimer( m_hWnd, m_nBackupStartTimerId );
  180. //
  181. // If the screensaver hasn't started, start it.
  182. //
  183. if (!m_bScreensaverStarted)
  184. {
  185. //
  186. // Shuffle the list
  187. //
  188. m_pImageScreenSaver->ResetFileQueue();
  189. //
  190. // If we haven't gotten any images, start the timer so we can display the error message
  191. //
  192. SendMessage( m_hWnd, WM_TIMER, m_nChangeTimerId, 0 );
  193. }
  194. }
  195. }
  196. void CScreenSaverHandler::HandlePaint(void)
  197. {
  198. if (m_pImageScreenSaver)
  199. {
  200. CSimpleDC PaintDC;
  201. if (PaintDC.BeginPaint(m_hWnd))
  202. {
  203. m_pImageScreenSaver->Paint( PaintDC );
  204. }
  205. }
  206. }
  207. void CScreenSaverHandler::HandleFindFile( CFoundFileMessageData *pFoundFileMessageData )
  208. {
  209. WIA_PUSHFUNCTION(TEXT("CScreenSaverHandler::HandleFindFile"));
  210. //
  211. // Make sure we have a screensaver object
  212. //
  213. if (m_pImageScreenSaver)
  214. {
  215. //
  216. // If this is a found file message
  217. //
  218. if (pFoundFileMessageData)
  219. {
  220. //
  221. // Add it to the list, and check for cancel
  222. //
  223. bool bResult = m_pImageScreenSaver->FoundFile( pFoundFileMessageData->Name() );
  224. //
  225. // If the find operation was cancelled, set the cancel event
  226. //
  227. if (!bResult)
  228. {
  229. SetEvent( m_hFindCancel );
  230. }
  231. //
  232. // If this is the image on which we should start, start up the screensaver pump
  233. //
  234. if (!m_bScreensaverStarted && m_pImageScreenSaver->Count() && m_nStartImage+1 == m_pImageScreenSaver->Count())
  235. {
  236. WIA_TRACE((TEXT("Starting after image %d was found"), m_nStartImage ));
  237. //
  238. // Shuffle the images
  239. //
  240. m_pImageScreenSaver->ResetFileQueue();
  241. //
  242. // If this is our first image, start things up
  243. //
  244. SendMessage( m_hWnd, WM_TIMER, m_nChangeTimerId, 0 );
  245. }
  246. //
  247. // If we have some images, and the shuffle count interval has been reached, shuffle the images
  248. //
  249. if (m_pImageScreenSaver->Count() && (m_pImageScreenSaver->Count() % m_nShuffleInterval) == 0)
  250. {
  251. WIA_TRACE((TEXT("Shuffling the image list at %d images"), m_pImageScreenSaver->Count() ));
  252. //
  253. // Shuffle the images
  254. //
  255. m_pImageScreenSaver->ResetFileQueue();
  256. }
  257. delete pFoundFileMessageData;
  258. }
  259. else
  260. {
  261. //
  262. // Last message
  263. //
  264. m_pImageScreenSaver->ResetFileQueue();
  265. //
  266. // If we haven't gotten any images, start the timer so we can display the error message
  267. //
  268. if (!m_bScreensaverStarted)
  269. {
  270. SendMessage( m_hWnd, WM_TIMER, m_nChangeTimerId, 0 );
  271. }
  272. }
  273. }
  274. }