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.

317 lines
8.9 KiB

  1. /****************************** Module Header ******************************\
  2. * Module Name: sysmet.c
  3. *
  4. * Copyright (c) 1985 - 1999, Microsoft Corporation
  5. *
  6. * System metrics APIs and support routines.
  7. *
  8. * History:
  9. * 24-Sep-1990 DarrinM Generated stubs.
  10. * 12-Feb-1991 JimA Added access checks
  11. \***************************************************************************/
  12. #include "precomp.h"
  13. #pragma hdrstop
  14. /***************************************************************************\
  15. * _SwapMouseButton (API)
  16. *
  17. * History:
  18. * 24-Sep-1990 DarrinM Generated stubs.
  19. * 25-Jan-1991 DavidPe Did the real thing.
  20. * 12-Feb-1991 JimA Added access check
  21. \***************************************************************************/
  22. BOOL APIENTRY _SwapMouseButton(
  23. BOOL fSwapButtons)
  24. {
  25. BOOL fSwapOld;
  26. PPROCESSINFO ppiCurrent = PpiCurrent();
  27. /*
  28. * Blow it off if the caller doesn't have the proper access rights
  29. */
  30. RETURN_IF_ACCESS_DENIED(ppiCurrent->amwinsta,
  31. WINSTA_READATTRIBUTES | WINSTA_WRITEATTRIBUTES,
  32. FALSE);
  33. if (!(ppiCurrent->W32PF_Flags & W32PF_IOWINSTA)) {
  34. RIPERR0(ERROR_REQUIRES_INTERACTIVE_WINDOWSTATION,
  35. RIP_WARNING,
  36. "SwapMouseButton invalid on a non-interactive WindowStation.");
  37. return FALSE;
  38. }
  39. fSwapOld = SYSMET(SWAPBUTTON);
  40. SYSMET(SWAPBUTTON) = fSwapButtons;
  41. /*
  42. * Give xxxButtonEvent a hint that a mouse button event may have to be
  43. * left/right swapped to correspond with our current async key state.
  44. * Toggle the global since an even number of SwapMouseButtons has no effect.
  45. */
  46. if (fSwapButtons != fSwapOld) {
  47. gbMouseButtonsRecentlySwapped = !gbMouseButtonsRecentlySwapped;
  48. }
  49. /*
  50. * Return previous state
  51. */
  52. return fSwapOld;
  53. }
  54. /***************************************************************************\
  55. * _SetDoubleClickTime (API)
  56. *
  57. * History:
  58. * 24-Sep-1990 DarrinM Generated stubs.
  59. * 25-Jan-1991 DavidPe Did the real thing.
  60. * 12-Feb-1991 JimA Added access check
  61. * 16-May-1991 MikeKe Changed to return BOOL
  62. \***************************************************************************/
  63. BOOL APIENTRY _SetDoubleClickTime(
  64. UINT dtTime)
  65. {
  66. PWINDOWSTATION pwinsta = PpiCurrent()->rpwinsta;
  67. /*
  68. * Blow it off if the caller doesn't have the proper access rights
  69. */
  70. if (!CheckWinstaWriteAttributesAccess()) {
  71. return FALSE;
  72. }
  73. if (!dtTime) {
  74. dtTime = 500;
  75. } else if (dtTime > 5000) {
  76. dtTime = 5000;
  77. }
  78. gdtDblClk = dtTime;
  79. gpsi->dtLBSearch = dtTime * 4; // dtLBSearch = 4 * gdtDblClk
  80. gpsi->dtScroll = gpsi->dtLBSearch / 5; // dtScroll = 4/5 * gdtDblClk
  81. /*
  82. * This value should be set through SPI_SETMENUSHOWDELAY
  83. * gdtMNDropDown = gpsi->dtScroll; // gdtMNDropDown = 4/5 * gdtDblClk
  84. */
  85. /*
  86. * Recalculate delays for tooltip windows on all desktops.
  87. */
  88. if (pwinsta != NULL) {
  89. PDESKTOP pdesk;
  90. for (pdesk = pwinsta->rpdeskList; pdesk; pdesk = pdesk->rpdeskNext) {
  91. InitTooltipDelay((PTOOLTIPWND)pdesk->spwndTooltip);
  92. }
  93. }
  94. return TRUE;
  95. }
  96. /***************************************************************************\
  97. * SetSysColor()
  98. *
  99. * Changes the value of a system color, and updates the brush. Tries to
  100. * recover in case of an error.
  101. *
  102. * History:
  103. \***************************************************************************/
  104. VOID SetSysColor(
  105. UINT icol,
  106. DWORD rgb,
  107. UINT uOptions
  108. )
  109. {
  110. gpsi->argbSystemUnmatched[icol] = rgb;
  111. if ((uOptions & SSCF_SETMAGICCOLORS) && gpDispInfo->fAnyPalette) {
  112. union {
  113. DWORD rgb;
  114. PALETTEENTRY pe;
  115. } peMagic;
  116. peMagic.rgb = rgb;
  117. /*
  118. * when any of the 3D colors are changing, call GDI to
  119. * set the apropiate "magic" color
  120. *
  121. * the four magic colors are reserved like so
  122. *
  123. * 8 - UI color (3D shadow)
  124. * 9 - UI color (3D face)
  125. *
  126. * F6 - UI color (3D hilight)
  127. * F7 - UI color (desktop)
  128. *
  129. * NOTE (3D hilight) inverts to (3D shadow)
  130. * (3D face) inverts to sys gray
  131. *
  132. */
  133. switch (icol)
  134. {
  135. case COLOR_3DSHADOW:
  136. GreSetMagicColors(gpDispInfo->hdcScreen, peMagic.pe, 8);
  137. break;
  138. case COLOR_3DFACE:
  139. GreSetMagicColors(gpDispInfo->hdcScreen, peMagic.pe, 9);
  140. break;
  141. case COLOR_3DHILIGHT:
  142. GreSetMagicColors(gpDispInfo->hdcScreen, peMagic.pe, 246);
  143. break;
  144. case COLOR_DESKTOP:
  145. GreSetMagicColors(gpDispInfo->hdcScreen, peMagic.pe, 247);
  146. break;
  147. }
  148. }
  149. if (uOptions & SSCF_16COLORS) {
  150. /*
  151. * Force solid colors for all elements in 16 color or less modes.
  152. */
  153. rgb = GreGetNearestColor(gpDispInfo->hdcScreen, rgb);
  154. } else if (uOptions & SSCF_FORCESOLIDCOLOR) {
  155. /*
  156. * Force solid colors for certain window elements.
  157. */
  158. switch (icol) {
  159. /*
  160. * These can be dithers
  161. */
  162. case COLOR_DESKTOP:
  163. case COLOR_ACTIVEBORDER:
  164. case COLOR_INACTIVEBORDER:
  165. case COLOR_APPWORKSPACE:
  166. case COLOR_INFOBK:
  167. case COLOR_GRADIENTACTIVECAPTION:
  168. case COLOR_GRADIENTINACTIVECAPTION:
  169. break;
  170. default:
  171. rgb = GreGetNearestColor(gpDispInfo->hdcScreen, rgb);
  172. break;
  173. }
  174. }
  175. gpsi->argbSystem[icol] = rgb;
  176. if (SYSHBRUSH(icol) == NULL) {
  177. /*
  178. * This is the first time we're setting up the system colors.
  179. * We need to create the brush
  180. */
  181. SYSHBRUSH(icol) = GreCreateSolidBrush(rgb);
  182. GreMarkUndeletableBrush(SYSHBRUSH(icol));
  183. GreSetBrushOwnerPublic(SYSHBRUSH(icol));
  184. GreSetBrushGlobal(SYSHBRUSH(icol));
  185. } else {
  186. GreSetSolidBrush(SYSHBRUSH(icol), rgb);
  187. }
  188. }
  189. /***************************************************************************\
  190. * xxxSetSysColors (API)
  191. *
  192. *
  193. * History:
  194. * 12-Feb-1991 JimA Created stub and added access check
  195. * 22-Apr-1991 DarrinM Ported from Win 3.1 sources.
  196. * 16-May-1991 MikeKe Changed to return BOOL
  197. \***************************************************************************/
  198. BOOL APIENTRY xxxSetSysColors(PUNICODE_STRING pProfileUserName,
  199. int cicol,
  200. PUINT picolor,
  201. COLORREF *prgb,
  202. UINT uOptions
  203. )
  204. {
  205. int i;
  206. UINT icol;
  207. COLORREF rgb;
  208. /*
  209. * Blow it off if the caller doesn't have the proper access rights
  210. */
  211. if ((uOptions & SSCF_NOTIFY) && !CheckWinstaWriteAttributesAccess()) {
  212. return FALSE;
  213. }
  214. if (GreGetDeviceCaps(gpDispInfo->hdcScreen, NUMCOLORS) <= 16) {
  215. uOptions |= SSCF_16COLORS;
  216. }
  217. if (uOptions & SSCF_SETMAGICCOLORS) {
  218. /*
  219. * Set the Magic colors first
  220. */
  221. for(i = 0; i < cicol; i++) {
  222. icol = picolor[i];
  223. rgb = prgb[i];
  224. if ( icol == COLOR_3DFACE ||
  225. icol == COLOR_3DSHADOW ||
  226. icol == COLOR_3DHILIGHT ||
  227. icol == COLOR_DESKTOP) {
  228. SetSysColor(icol, rgb, uOptions);
  229. }
  230. }
  231. }
  232. for (i = 0; i < cicol; i++) {
  233. icol = *picolor++;
  234. rgb = *prgb++;
  235. if (icol >= COLOR_MAX)
  236. continue;
  237. if ((uOptions & SSCF_SETMAGICCOLORS) &&
  238. (icol == COLOR_3DFACE ||
  239. icol == COLOR_3DSHADOW ||
  240. icol == COLOR_3DHIGHLIGHT ||
  241. icol == COLOR_DESKTOP)) {
  242. continue;
  243. }
  244. SetSysColor(icol, rgb, uOptions);
  245. }
  246. if (uOptions & SSCF_NOTIFY) {
  247. /*
  248. * Recolor all the current desktop
  249. */
  250. RecolorDeskPattern();
  251. /*
  252. * Render the system bitmaps in new colors before we broadcast
  253. */
  254. xxxSetWindowNCMetrics(pProfileUserName,NULL, FALSE, -1);
  255. /*
  256. * Notify everyone that the colors have changed.
  257. */
  258. xxxSendNotifyMessage(PWND_BROADCAST, WM_SYSCOLORCHANGE, 0, 0L);
  259. /*
  260. * Just redraw the entire screen. Trying to just draw the parts
  261. * that were changed isn't worth it, since Control Panel always
  262. * resets every color anyway.
  263. *
  264. * Anyway, it could get messy, sending apps NCPAINT messages without
  265. * accumulating update regions too.
  266. */
  267. xxxRedrawScreen();
  268. }
  269. return TRUE;
  270. }