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.

183 lines
6.1 KiB

  1. /****************************** Module Header ******************************\
  2. * Module Name: winevent.c
  3. *
  4. * Copyright (c) 1985 - 1999, Microsoft Corporation
  5. *
  6. * This module contains routines common to client and kernel.
  7. *
  8. * History:
  9. * 07-18-2000 DwayneN Created
  10. \***************************************************************************/
  11. /*
  12. * Event Space Partitioning
  13. * This map describes how the event space is partioned up into separate
  14. * categories. Each entry describes where a range of events begins, and
  15. * what category that range belongs to. The range implicitly extends up
  16. * to, but not including the beginning of the next range. The first range
  17. * must begin with EVENT_MIN. The last range must begin with EVENT_MAX.
  18. * This last range is ignored except that it defines where the
  19. * next-to-last range ends.
  20. *
  21. * Be sure to keep this in sync with the category definitions!
  22. */
  23. typedef struct _EVCATINFO
  24. {
  25. DWORD dwBeginRange;
  26. DWORD dwCategory;
  27. } EVCATINFO, *PEVCATINFO;
  28. static EVCATINFO geci[] = {
  29. {EVENT_MIN, EVENTCATEGORY_OTHER},
  30. {EVENT_SYSTEM_MENUSTART, EVENTCATEGORY_SYSTEM_MENU},
  31. {EVENT_SYSTEM_CAPTURESTART, EVENTCATEGORY_OTHER},
  32. {EVENT_CONSOLE_CARET, EVENTCATEGORY_CONSOLE},
  33. {EVENT_CONSOLE_END_APPLICATION + 1, EVENTCATEGORY_OTHER},
  34. {EVENT_OBJECT_FOCUS, EVENTCATEGORY_FOCUS},
  35. {EVENT_OBJECT_SELECTION, EVENTCATEGORY_OTHER},
  36. {EVENT_OBJECT_STATECHANGE, EVENTCATEGORY_STATECHANGE},
  37. {EVENT_OBJECT_LOCATIONCHANGE, EVENTCATEGORY_LOCATIONCHANGE},
  38. {EVENT_OBJECT_NAMECHANGE, EVENTCATEGORY_NAMECHANGE},
  39. {EVENT_OBJECT_DESCRIPTIONCHANGE, EVENTCATEGORY_OTHER},
  40. {EVENT_OBJECT_VALUECHANGE, EVENTCATEGORY_VALUECHANGE},
  41. {EVENT_OBJECT_PARENTCHANGE, EVENTCATEGORY_OTHER},
  42. {EVENT_MAX, EVENTCATEGORY_OTHER}};
  43. /***************************************************************************\
  44. * IsEventInRange
  45. *
  46. * Returns TRUE if the specified event falls within the specified range,
  47. * and FALSE if not.
  48. *
  49. \***************************************************************************/
  50. __inline BOOL IsEventInRange(
  51. DWORD event,
  52. DWORD eventMin,
  53. DWORD eventMax)
  54. {
  55. return ((event >= eventMin) && (event <= eventMax));
  56. }
  57. /***************************************************************************\
  58. * RangesOverlap
  59. *
  60. * Returns TRUE if the two ranges overlap at all, FALSE if not.
  61. *
  62. * Note that the ranges are both assumed to be inclusinve on both ends.
  63. *
  64. \***************************************************************************/
  65. __inline BOOL RangesOverlap(
  66. DWORD r1Min,
  67. DWORD r1Max,
  68. DWORD r2Min,
  69. DWORD r2Max)
  70. {
  71. UserAssert(r1Min <= r1Max);
  72. UserAssert(r2Min <= r2Max);
  73. return (r1Min <= r2Max) && (r1Max >= r2Min);
  74. }
  75. /***************************************************************************\
  76. * CategoryMaskFromEvent
  77. *
  78. * Returns the bit-mask for the category that the specified event belongs to.
  79. *
  80. \***************************************************************************/
  81. DWORD CategoryMaskFromEvent(
  82. DWORD event)
  83. {
  84. UserAssert(IsEventInRange(event, EVENT_MIN, EVENT_MAX));
  85. switch (event) {
  86. case EVENT_SYSTEM_MENUSTART:
  87. case EVENT_SYSTEM_MENUEND:
  88. case EVENT_SYSTEM_MENUPOPUPSTART:
  89. case EVENT_SYSTEM_MENUPOPUPEND:
  90. return EVENTCATEGORY_SYSTEM_MENU;
  91. case EVENT_CONSOLE_CARET:
  92. case EVENT_CONSOLE_UPDATE_REGION:
  93. case EVENT_CONSOLE_UPDATE_SIMPLE:
  94. case EVENT_CONSOLE_UPDATE_SCROLL:
  95. case EVENT_CONSOLE_LAYOUT:
  96. case EVENT_CONSOLE_START_APPLICATION:
  97. case EVENT_CONSOLE_END_APPLICATION:
  98. return EVENTCATEGORY_CONSOLE;
  99. case EVENT_OBJECT_FOCUS:
  100. return EVENTCATEGORY_FOCUS;
  101. case EVENT_OBJECT_NAMECHANGE:
  102. return EVENTCATEGORY_NAMECHANGE;
  103. case EVENT_OBJECT_VALUECHANGE:
  104. return EVENTCATEGORY_VALUECHANGE;
  105. case EVENT_OBJECT_STATECHANGE:
  106. return EVENTCATEGORY_STATECHANGE;
  107. case EVENT_OBJECT_LOCATIONCHANGE:
  108. return EVENTCATEGORY_LOCATIONCHANGE;
  109. default:
  110. return EVENTCATEGORY_OTHER;
  111. }
  112. }
  113. /***************************************************************************\
  114. * CategoryMaskFromEventRange
  115. *
  116. * Returns a bit-mask for the categories that the events in the specified
  117. * event range belong to.
  118. *
  119. \***************************************************************************/
  120. DWORD CategoryMaskFromEventRange(
  121. DWORD eventMin,
  122. DWORD eventMax)
  123. {
  124. DWORD dwCategoryMask = 0;
  125. DWORD i;
  126. DWORD iMax = ARRAY_SIZE(geci) - 1;
  127. /*
  128. * This is a DEBUG section that tries to verify some aspects of the
  129. * geci array.
  130. */
  131. #if DBG
  132. UserAssert(iMax >= 1);
  133. UserAssert(geci[0].dwBeginRange == EVENT_MIN);
  134. UserAssert(geci[iMax].dwBeginRange == EVENT_MAX);
  135. for (i = 0; i < iMax; i++) {
  136. UserAssert(geci[i].dwBeginRange >= EVENT_MIN);
  137. UserAssert(geci[i].dwBeginRange <= EVENT_MAX);
  138. UserAssert(geci[i].dwBeginRange < geci[i+1].dwBeginRange);
  139. dwCategoryMask |= geci[i].dwCategory;
  140. }
  141. UserAssert(dwCategoryMask == EVENTCATEGORY_ALL);
  142. dwCategoryMask = 0;
  143. #endif // DBG
  144. /*
  145. * Spin through the geci array and check to see which ranges overlap
  146. * the range passed to this function.
  147. */
  148. for (i = 0; i < iMax; i++) {
  149. /*
  150. * Bail out early once we pass the range we are checking.
  151. */
  152. if (geci[i].dwBeginRange > eventMax) {
  153. break;
  154. }
  155. /*
  156. * Check to see if the ith range in the table overlaps the range
  157. * passed to this function.
  158. */
  159. if (RangesOverlap(geci[i].dwBeginRange, geci[i+1].dwBeginRange-1, eventMin, eventMax)) {
  160. dwCategoryMask |= geci[ i ].dwCategory;
  161. }
  162. }
  163. return dwCategoryMask;
  164. }