Leaked source code of windows server 2003
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.

498 lines
10 KiB

  1. /*++
  2. Copyright (c) 1991 - 2001 Microsoft Corporation
  3. Module Name:
  4. ### ### ##### #### ### ##### ## ### ## ## #### ##### #####
  5. ## # ### ## ## ## ## # ## ## ## ### ## ## ## # ## ## ## ##
  6. ### ## ## ## ## ## ### ## ## ## ## ## #### ## ## ## ## ##
  7. ### ## ## ## ## ## ### ## ## ## ## ## #### ## ## ## ## ##
  8. ### ####### ## ## ## ### ##### ## ####### ## ## ##### #####
  9. # ## ## ## ## ## ## # ## ## ## ## ## ## ## ## # ## ##
  10. ### ## ## ##### #### ### ## ##### ## ## ## ## #### ## ##
  11. Abstract:
  12. This module contains the implementation for
  13. the ISaDisplay interface class.
  14. Author:
  15. Wesley Witt (wesw) 1-Oct-2001
  16. Environment:
  17. User mode only.
  18. Notes:
  19. --*/
  20. #include "internal.h"
  21. CSaDisplay::CSaDisplay()
  22. {
  23. m_hFile = OpenSaDevice( SA_DEVICE_DISPLAY );
  24. if (m_hFile != INVALID_HANDLE_VALUE) {
  25. ULONG Bytes;
  26. m_DisplayCaps.SizeOfStruct = sizeof(SA_DISPLAY_CAPS);
  27. BOOL b = DeviceIoControl(
  28. m_hFile,
  29. IOCTL_SA_GET_CAPABILITIES,
  30. NULL,
  31. 0,
  32. &m_DisplayCaps,
  33. sizeof(SA_DISPLAY_CAPS),
  34. &Bytes,
  35. NULL
  36. );
  37. if (!b) {
  38. CloseHandle( m_hFile );
  39. m_hFile = NULL;
  40. }
  41. b = DeviceIoControl(
  42. m_hFile,
  43. IOCTL_SA_GET_VERSION,
  44. NULL,
  45. 0,
  46. &m_InterfaceVersion,
  47. sizeof(ULONG),
  48. &Bytes,
  49. NULL
  50. );
  51. if (!b) {
  52. CloseHandle( m_hFile );
  53. m_hFile = NULL;
  54. }
  55. m_CachedBitmapSize = m_DisplayCaps.DisplayHeight * (m_DisplayCaps.DisplayWidth / 8);
  56. m_CachedBitmap = (PUCHAR) malloc( m_CachedBitmapSize );
  57. if (m_CachedBitmap == NULL) {
  58. CloseHandle( m_hFile );
  59. m_hFile = NULL;
  60. }
  61. } else {
  62. m_hFile = NULL;
  63. }
  64. }
  65. CSaDisplay::~CSaDisplay()
  66. {
  67. if (m_hFile != NULL) {
  68. CloseHandle( m_hFile );
  69. }
  70. if (m_CachedBitmap) {
  71. free( m_CachedBitmap );
  72. }
  73. }
  74. STDMETHODIMP CSaDisplay::get_InterfaceVersion(long *pVal)
  75. {
  76. *pVal = m_InterfaceVersion;
  77. return S_OK;
  78. }
  79. STDMETHODIMP CSaDisplay::get_DisplayType(long *pVal)
  80. {
  81. *pVal = m_DisplayCaps.DisplayType;
  82. return S_OK;
  83. }
  84. STDMETHODIMP CSaDisplay::get_CharacterSet(long *pVal)
  85. {
  86. *pVal = m_DisplayCaps.CharacterSet;
  87. return S_OK;
  88. }
  89. STDMETHODIMP CSaDisplay::get_DisplayHeight(long *pVal)
  90. {
  91. *pVal = m_DisplayCaps.DisplayHeight;
  92. return S_OK;
  93. }
  94. STDMETHODIMP CSaDisplay::get_DisplayWidth(long *pVal)
  95. {
  96. *pVal = m_DisplayCaps.DisplayWidth;
  97. return S_OK;
  98. }
  99. void
  100. CSaDisplay::ConvertBottomLeft2TopLeft(
  101. PUCHAR Bits,
  102. ULONG Width,
  103. ULONG Height
  104. )
  105. {
  106. ULONG Row;
  107. ULONG Col;
  108. UCHAR Temp;
  109. Width = Width >> 3;
  110. for (Row = 0; Row < (Height / 2); Row++) {
  111. for (Col = 0; Col < Width; Col++) {
  112. Temp = Bits[Row * Width + Col];
  113. Bits[Row * Width + Col] = Bits[(Height - Row - 1) * Width + Col];
  114. Bits[(Height - Row - 1) * Width + Col] = Temp;
  115. }
  116. }
  117. }
  118. int
  119. CSaDisplay::DisplayBitmap(
  120. long MsgCode,
  121. long Width,
  122. long Height,
  123. unsigned char *Bits
  124. )
  125. {
  126. ULONG SizeOfBits;
  127. ULONG Bytes;
  128. BOOL b;
  129. if (m_hFile == NULL){
  130. return HRESULT_FROM_WIN32(ERROR_INVALID_HANDLE);
  131. }
  132. ConvertBottomLeft2TopLeft( Bits, Width, Height );
  133. //
  134. // Check the cache for a hit
  135. //
  136. SizeOfBits = Height * (Width >> 3);
  137. if (SizeOfBits == m_CachedBitmapSize && (memcmp( m_CachedBitmap, Bits, SizeOfBits ) == 0)) {
  138. return ERROR_SUCCESS;
  139. }
  140. //
  141. // Display the new bitmap
  142. //
  143. m_SaDisplay.SizeOfStruct = sizeof(SA_DISPLAY_SHOW_MESSAGE);
  144. m_SaDisplay.MsgCode = MsgCode;
  145. m_SaDisplay.Width = (USHORT)Width;
  146. m_SaDisplay.Height = (USHORT)Height;
  147. memcpy( m_SaDisplay.Bits, Bits, SizeOfBits );
  148. b = WriteFile( m_hFile, &m_SaDisplay, sizeof(SA_DISPLAY_SHOW_MESSAGE), &Bytes, NULL );
  149. if (b == FALSE || Bytes != sizeof(SA_DISPLAY_SHOW_MESSAGE)) {
  150. return HRESULT_FROM_WIN32(GetLastError());
  151. }
  152. //
  153. // Cache the bitmap
  154. //
  155. m_CachedBitmapSize = SizeOfBits;
  156. memcpy( m_CachedBitmap, Bits, m_CachedBitmapSize );
  157. return ERROR_SUCCESS;
  158. }
  159. STDMETHODIMP
  160. CSaDisplay::ShowMessage(
  161. long MsgCode,
  162. long Width,
  163. long Height,
  164. unsigned char *Bits
  165. )
  166. {
  167. if (Width > m_DisplayCaps.DisplayWidth) {
  168. return E_FAIL;
  169. }
  170. if (Height > m_DisplayCaps.DisplayHeight) {
  171. return E_FAIL;
  172. }
  173. if (DisplayBitmap( MsgCode, Width, Height, Bits) == -1) {
  174. return E_FAIL;
  175. }
  176. return S_OK;
  177. }
  178. STDMETHODIMP CSaDisplay::ClearDisplay()
  179. {
  180. ULONG Bytes;
  181. BOOL b;
  182. if (m_hFile == NULL){
  183. return HRESULT_FROM_WIN32(ERROR_INVALID_HANDLE);
  184. }
  185. memset( &m_SaDisplay, 0, sizeof(SA_DISPLAY_SHOW_MESSAGE) );
  186. m_SaDisplay.SizeOfStruct = sizeof(SA_DISPLAY_SHOW_MESSAGE);
  187. m_SaDisplay.MsgCode = SA_DISPLAY_READY;
  188. m_SaDisplay.Width = m_DisplayCaps.DisplayWidth;
  189. m_SaDisplay.Height = m_DisplayCaps.DisplayHeight;
  190. b = WriteFile( m_hFile, &m_SaDisplay, sizeof(SA_DISPLAY_SHOW_MESSAGE), &Bytes, NULL );
  191. if (b == FALSE || Bytes != sizeof(SA_DISPLAY_SHOW_MESSAGE)) {
  192. return HRESULT_FROM_WIN32(GetLastError());
  193. }
  194. //
  195. // Clear the bitmap cache
  196. //
  197. m_CachedBitmapSize = 0;
  198. return S_OK;
  199. }
  200. STDMETHODIMP
  201. CSaDisplay::ShowMessageFromFile(
  202. long MsgCode,
  203. BSTR BitmapFileName
  204. )
  205. {
  206. HRESULT hr = E_FAIL;
  207. HANDLE hFile = INVALID_HANDLE_VALUE;
  208. PBITMAPFILEHEADER bmf;
  209. PBITMAPINFOHEADER bmi;
  210. PUCHAR BitmapData = NULL;
  211. ULONG FileSize;
  212. ULONG Bytes;
  213. __try {
  214. hFile = CreateFile(
  215. BitmapFileName,
  216. GENERIC_READ,
  217. FILE_SHARE_READ | FILE_SHARE_WRITE,
  218. NULL,
  219. OPEN_EXISTING,
  220. 0,
  221. NULL
  222. );
  223. if (hFile == INVALID_HANDLE_VALUE) {
  224. __leave;
  225. }
  226. FileSize = GetFileSize( hFile, NULL );
  227. BitmapData = (PUCHAR) malloc( FileSize );
  228. if (BitmapData == NULL) {
  229. __leave;
  230. }
  231. if (!ReadFile( hFile, BitmapData, FileSize, &Bytes, NULL )) {
  232. __leave;
  233. }
  234. bmf = (PBITMAPFILEHEADER) BitmapData;
  235. bmi = (PBITMAPINFOHEADER) (BitmapData + sizeof(BITMAPFILEHEADER));
  236. if (bmf->bfType != 0x4d42) {
  237. __leave;
  238. }
  239. if (bmi->biBitCount != 1 && bmi->biCompression != 0) {
  240. __leave;
  241. }
  242. if (DisplayBitmap( 0, bmi->biWidth, bmi->biHeight, (PUCHAR)(BitmapData + bmf->bfOffBits) ) == -1) {
  243. __leave;
  244. }
  245. hr = S_OK;
  246. } __finally {
  247. if (BitmapData) {
  248. free( BitmapData );
  249. }
  250. if (hFile != INVALID_HANDLE_VALUE) {
  251. CloseHandle( hFile );
  252. }
  253. }
  254. return hr;
  255. }
  256. STDMETHODIMP
  257. CSaDisplay::StoreBitmap(
  258. long MessageId,
  259. long Width,
  260. long Height,
  261. unsigned char *Bits
  262. )
  263. {
  264. BOOL b;
  265. ULONG Bytes;
  266. if (m_hFile == NULL){
  267. return HRESULT_FROM_WIN32(ERROR_INVALID_HANDLE);
  268. }
  269. ConvertBottomLeft2TopLeft( Bits, Width, Height );
  270. m_SaDisplay.SizeOfStruct = sizeof(SA_DISPLAY_SHOW_MESSAGE);
  271. m_SaDisplay.MsgCode = MessageId;
  272. m_SaDisplay.Width = (USHORT)Width;
  273. m_SaDisplay.Height = (USHORT)Height;
  274. memcpy( m_SaDisplay.Bits, Bits, Height * (Width >> 3) );
  275. b = DeviceIoControl(
  276. m_hFile,
  277. IOCTL_FUNC_DISPLAY_STORE_BITMAP,
  278. &m_SaDisplay,
  279. sizeof(SA_DISPLAY_SHOW_MESSAGE),
  280. NULL,
  281. 0,
  282. &Bytes,
  283. NULL
  284. );
  285. if (!b) {
  286. return HRESULT_FROM_WIN32(GetLastError());
  287. }
  288. return S_OK;
  289. }
  290. STDMETHODIMP CSaDisplay::Lock()
  291. {
  292. BOOL b;
  293. ULONG Bytes;
  294. if (m_hFile == NULL){
  295. return HRESULT_FROM_WIN32(ERROR_INVALID_HANDLE);
  296. }
  297. b = DeviceIoControl(
  298. m_hFile,
  299. IOCTL_SADISPLAY_LOCK,
  300. NULL,
  301. 0,
  302. NULL,
  303. 0,
  304. &Bytes,
  305. NULL
  306. );
  307. if (!b) {
  308. return HRESULT_FROM_WIN32(GetLastError());
  309. }
  310. return S_OK;
  311. }
  312. STDMETHODIMP CSaDisplay::UnLock()
  313. {
  314. BOOL b;
  315. ULONG Bytes;
  316. if (m_hFile == NULL){
  317. return HRESULT_FROM_WIN32(ERROR_INVALID_HANDLE);
  318. }
  319. b = DeviceIoControl(
  320. m_hFile,
  321. IOCTL_SADISPLAY_UNLOCK,
  322. NULL,
  323. 0,
  324. NULL,
  325. 0,
  326. &Bytes,
  327. NULL
  328. );
  329. if (!b) {
  330. return HRESULT_FROM_WIN32(GetLastError());
  331. }
  332. return S_OK;
  333. }
  334. STDMETHODIMP CSaDisplay::ReloadRegistryBitmaps()
  335. {
  336. BOOL b;
  337. ULONG Bytes;
  338. if (m_hFile == NULL){
  339. return HRESULT_FROM_WIN32(ERROR_INVALID_HANDLE);
  340. }
  341. b = DeviceIoControl(
  342. m_hFile,
  343. IOCTL_SADISPLAY_CHANGE_LANGUAGE,
  344. NULL,
  345. 0,
  346. NULL,
  347. 0,
  348. &Bytes,
  349. NULL
  350. );
  351. if (!b) {
  352. return HRESULT_FROM_WIN32(GetLastError());
  353. }
  354. return S_OK;
  355. }
  356. STDMETHODIMP CSaDisplay::ShowRegistryBitmap(long MessageId)
  357. {
  358. BOOL b;
  359. DWORD dwIoControlCode = 0;
  360. ULONG Bytes;
  361. if (m_hFile == NULL){
  362. return HRESULT_FROM_WIN32(ERROR_INVALID_HANDLE);
  363. }
  364. if (MessageId == SA_DISPLAY_CHECK_DISK){
  365. dwIoControlCode = IOCTL_SADISPLAY_BUSY_MESSAGE;
  366. }
  367. else if (MessageId == SA_DISPLAY_SHUTTING_DOWN){
  368. dwIoControlCode = IOCTL_SADISPLAY_SHUTDOWN_MESSAGE;
  369. }
  370. else{
  371. return E_INVALIDARG;
  372. }
  373. b = DeviceIoControl(
  374. m_hFile,
  375. dwIoControlCode,
  376. NULL,
  377. 0,
  378. NULL,
  379. 0,
  380. &Bytes,
  381. NULL
  382. );
  383. if (!b) {
  384. return HRESULT_FROM_WIN32(GetLastError());
  385. }
  386. return S_OK;
  387. }