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.

279 lines
7.9 KiB

  1. /****************************** Module Header ******************************\
  2. * Module Name: random.c
  3. *
  4. * Copyright (c) 1985 - 1999, Microsoft Corporation
  5. *
  6. * This file contains global function pointers that are called trough to get
  7. * to either a client or a server function depending on which side we are on
  8. *
  9. * History:
  10. * 10-Nov-1993 MikeKe Created
  11. \***************************************************************************/
  12. #include "precomp.h"
  13. #pragma hdrstop
  14. /***************************************************************************\
  15. *
  16. *
  17. * History:
  18. * 10-Nov-1993 MikeKe Created
  19. \***************************************************************************/
  20. HBRUSH ghbrWhite = NULL;
  21. HBRUSH ghbrBlack = NULL;
  22. /***************************************************************************\
  23. * GetSysColorBrush
  24. *
  25. * Retrieves the system-color-brush.
  26. *
  27. \***************************************************************************/
  28. FUNCLOG1(LOG_GENERAL, HBRUSH, WINAPI, GetSysColorBrush, int, nIndex)
  29. HBRUSH WINAPI GetSysColorBrush(
  30. int nIndex)
  31. {
  32. if ((nIndex < 0) || (nIndex >= COLOR_MAX))
  33. return NULL;
  34. return SYSHBRUSH(nIndex);
  35. }
  36. /***************************************************************************\
  37. * SetSysColorTemp
  38. *
  39. * Sets the global system colors all at once. Also remembers the old colors
  40. * so they can be reset.
  41. *
  42. * Sets/Resets the color and brush arrays for user USER drawing.
  43. * lpRGBs and lpBrushes are pointers to arrays paralleling the argbSystem and
  44. * gpsi->hbrSystem arrays. wCnt is a sanity check so that this does the "right"
  45. * thing in a future windows version. The current argbSystem and hbrSystem
  46. * arrays are saved off, and a handle to those saved arrays is returned.
  47. *
  48. * To reset the arrays, pass in NULL for lpRGBs, NULL for lpBrushes, and the
  49. * handle (from the first set) for wCnt.
  50. *
  51. * History:
  52. * 18-Sep-1995 JohnC Gave this miserable function a life
  53. \***************************************************************************/
  54. LPCOLORREF gpOriginalRGBs = NULL;
  55. UINT gcOriginalRGBs = 0;
  56. WINUSERAPI HANDLE WINAPI SetSysColorsTemp(
  57. CONST COLORREF *lpRGBs,
  58. CONST HBRUSH *lpBrushes,
  59. UINT_PTR cBrushes) // Count of brushes or handle
  60. {
  61. UINT cbRGBSize;
  62. UINT i;
  63. UINT abElements[COLOR_MAX];
  64. /*
  65. * See if we are resetting the colors back to a saved state
  66. */
  67. if (lpRGBs == NULL) {
  68. /*
  69. * When restoring cBrushes is really a handle to the old global
  70. * handle. Make sure that is true. Also lpBrushes is unused
  71. */
  72. UNREFERENCED_PARAMETER(lpBrushes);
  73. UserAssert(lpBrushes == NULL);
  74. UserAssert(cBrushes == (ULONG_PTR)gpOriginalRGBs);
  75. if (gpOriginalRGBs == NULL) {
  76. RIPMSG0(RIP_ERROR, "SetSysColorsTemp: Can not restore if not saved");
  77. return NULL;
  78. }
  79. /*
  80. * reset the global Colors
  81. */
  82. UserAssert((sizeof(abElements)/sizeof(abElements[0])) >= gcOriginalRGBs);
  83. for (i = 0; i < gcOriginalRGBs; i++)
  84. abElements[i] = i;
  85. NtUserSetSysColors(gcOriginalRGBs, abElements, gpOriginalRGBs, 0);
  86. UserLocalFree(gpOriginalRGBs);
  87. gpOriginalRGBs = NULL;
  88. gcOriginalRGBs = 0;
  89. return (HANDLE)TRUE;
  90. }
  91. /*
  92. * Make sure we aren't trying to set too many colors
  93. * If we allow more then COLOR_MAX change the abElements array
  94. */
  95. if (cBrushes > COLOR_MAX) {
  96. RIPMSG1(RIP_ERROR, "SetSysColorsTemp: trying to set too many colors %lX", cBrushes);
  97. return NULL;
  98. }
  99. /*
  100. * If we have already a saved state then don't let them save it again
  101. */
  102. if (gpOriginalRGBs != NULL) {
  103. RIPMSG0(RIP_ERROR, "SetSysColorsTemp: temp colors already set");
  104. return NULL;
  105. }
  106. /*
  107. * If we are here then we must be setting the new temp colors
  108. *
  109. * First save the old colors
  110. */
  111. cbRGBSize = sizeof(COLORREF) * (UINT)cBrushes;
  112. UserAssert(sizeof(COLORREF) == sizeof(int));
  113. gpOriginalRGBs = UserLocalAlloc(HEAP_ZERO_MEMORY, cbRGBSize);
  114. if (gpOriginalRGBs == NULL) {
  115. RIPMSG0(RIP_WARNING, "SetSysColorsTemp: unable to alloc temp colors buffer");
  116. return NULL;
  117. }
  118. RtlCopyMemory(gpOriginalRGBs, gpsi->argbSystem, cbRGBSize);
  119. /*
  120. * Now set the new colors.
  121. */
  122. UserAssert( (sizeof(abElements)/sizeof(abElements[0])) >= cBrushes);
  123. for (i = 0; i < cBrushes; i++)
  124. abElements[i] = i;
  125. NtUserSetSysColors((UINT)cBrushes, abElements, lpRGBs, 0);
  126. gcOriginalRGBs = (UINT)cBrushes;
  127. return gpOriginalRGBs;
  128. }
  129. /***************************************************************************\
  130. * TextAlloc
  131. *
  132. * History:
  133. * 25-Oct-1990 MikeHar Wrote.
  134. * 09-Nov-1990 DarrinM Fixed.
  135. * 13-Jan-1992 GregoryW Neutralized.
  136. \***************************************************************************/
  137. LPWSTR TextAlloc(
  138. LPCWSTR lpszSrc)
  139. {
  140. LPWSTR pszT;
  141. DWORD cbString;
  142. if (lpszSrc == NULL)
  143. return NULL;
  144. cbString = (wcslen(lpszSrc) + 1) * sizeof(WCHAR);
  145. if (pszT = (LPWSTR)UserLocalAlloc(HEAP_ZERO_MEMORY, cbString)) {
  146. RtlCopyMemory(pszT, lpszSrc, cbString);
  147. }
  148. return pszT;
  149. }
  150. #if DBG
  151. /***************************************************************************\
  152. * CheckCurrentDesktop
  153. *
  154. * Ensure that the pointer is valid for the current desktop.
  155. *
  156. * History:
  157. * 10-Apr-1995 JimA Created.
  158. \***************************************************************************/
  159. VOID CheckCurrentDesktop(
  160. PVOID p)
  161. {
  162. UserAssert(p >= GetClientInfo()->pDeskInfo->pvDesktopBase &&
  163. p < GetClientInfo()->pDeskInfo->pvDesktopLimit);
  164. }
  165. #endif
  166. /***************************************************************************\
  167. * SetLastErrorEx
  168. *
  169. * Sets the last error, ignoring dwtype.
  170. \***************************************************************************/
  171. FUNCLOGVOID2(LOG_GENERAL, WINAPI, SetLastErrorEx, DWORD, dwErrCode, DWORD, dwType)
  172. VOID WINAPI SetLastErrorEx(
  173. DWORD dwErrCode,
  174. DWORD dwType
  175. )
  176. {
  177. UNREFERENCED_PARAMETER(dwType);
  178. SetLastError(dwErrCode);
  179. }
  180. #if defined(_X86_)
  181. /***************************************************************************\
  182. * InitializeWin32EntryTable
  183. *
  184. * Initializes a Win32 entry table so our test apps will know which entry
  185. * points to avoid. This should be removed before we ship.
  186. \***************************************************************************/
  187. static CONST PROC FunctionsToSkip[] = {
  188. NtUserWaitMessage,
  189. NtUserLockWorkStation,
  190. };
  191. FUNCLOG1(LOG_GENERAL, UINT, DUMMYCALLINGTYPE, InitializeWin32EntryTable, PBOOLEAN, pbEntryTable)
  192. UINT InitializeWin32EntryTable(
  193. PBOOLEAN pbEntryTable)
  194. {
  195. #if DBG
  196. // We'll only define this on free systems for now. Checked systems
  197. // will hit too many asserts.
  198. UNREFERENCED_PARAMETER(pbEntryTable);
  199. return 0;
  200. #else
  201. UINT i;
  202. PBYTE pb;
  203. if (pbEntryTable) {
  204. for (i = 0; i < ARRAY_SIZE(FunctionsToSkip); i++) {
  205. pb = (PBYTE)FunctionsToSkip[i];
  206. pbEntryTable[*((WORD *)(pb+1)) - 0x1000] = TRUE;
  207. }
  208. }
  209. return gDispatchTableValues;
  210. #endif
  211. }
  212. #endif
  213. /***************************************************************************\
  214. * GetLastInputInfo
  215. *
  216. * Retrieves information about the last input event
  217. *
  218. * 05/30/07 GerardoB Created
  219. \***************************************************************************/
  220. BOOL GetLastInputInfo (PLASTINPUTINFO plii)
  221. {
  222. if (plii->cbSize != sizeof(LASTINPUTINFO)) {
  223. VALIDATIONFAIL(plii->cbSize);
  224. }
  225. plii->dwTime = gpsi->dwLastRITEventTickCount;
  226. return TRUE;
  227. VALIDATIONERROR(FALSE);
  228. }