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.

247 lines
5.1 KiB

  1. /*
  2. ** CUTILS.C
  3. **
  4. ** Common utilities for common controls
  5. **
  6. */
  7. #include "ctlspriv.h"
  8. int iDitherCount = 0;
  9. HBRUSH hbrDither = NULL;
  10. int nSysColorChanges = 0;
  11. DWORD rgbFace; // globals used a lot
  12. DWORD rgbShadow;
  13. DWORD rgbHilight;
  14. DWORD rgbFrame;
  15. int iThumbCount = 0;
  16. HBITMAP hbmThumb = NULL; // the thumb bitmap
  17. #define CCS_ALIGN (CCS_TOP|CCS_NOMOVEY|CCS_BOTTOM)
  18. static HBITMAP NEAR PASCAL CreateDitherBitmap()
  19. {
  20. PBITMAPINFO pbmi;
  21. HBITMAP hbm;
  22. HDC hdc;
  23. int i;
  24. long patGray[8];
  25. DWORD rgb;
  26. pbmi = (PBITMAPINFO)LocalAlloc(LPTR, sizeof(BITMAPINFOHEADER) + (sizeof(RGBQUAD) * 16));
  27. if (!pbmi)
  28. return NULL;
  29. pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  30. pbmi->bmiHeader.biWidth = 8;
  31. pbmi->bmiHeader.biHeight = 8;
  32. pbmi->bmiHeader.biPlanes = 1;
  33. pbmi->bmiHeader.biBitCount = 1;
  34. pbmi->bmiHeader.biCompression = BI_RGB;
  35. rgb = GetSysColor(COLOR_BTNFACE);
  36. pbmi->bmiColors[0].rgbBlue = GetBValue(rgb);
  37. pbmi->bmiColors[0].rgbGreen = GetGValue(rgb);
  38. pbmi->bmiColors[0].rgbRed = GetRValue(rgb);
  39. pbmi->bmiColors[0].rgbReserved = 0;
  40. rgb = GetSysColor(COLOR_BTNHIGHLIGHT);
  41. pbmi->bmiColors[1].rgbBlue = GetBValue(rgb);
  42. pbmi->bmiColors[1].rgbGreen = GetGValue(rgb);
  43. pbmi->bmiColors[1].rgbRed = GetRValue(rgb);
  44. pbmi->bmiColors[1].rgbReserved = 0;
  45. /* initialize the brushes */
  46. for (i = 0; i < 8; i++)
  47. if (i & 1)
  48. patGray[i] = 0xAAAA5555L; // 0x11114444L; // lighter gray
  49. else
  50. patGray[i] = 0x5555AAAAL; // 0x11114444L; // lighter gray
  51. hdc = GetDC(NULL);
  52. hbm = CreateDIBitmap(hdc, &pbmi->bmiHeader, CBM_INIT, patGray, pbmi, DIB_RGB_COLORS);
  53. ReleaseDC(NULL, hdc);
  54. LocalFree(pbmi);
  55. return hbm;
  56. }
  57. /*---------------------------------------------------------------------------
  58. MySetObjectOwner
  59. Purpose: Call SetObjectOwner in GDI, eliminating "<Object> not released"
  60. error messages when an app terminates.
  61. Returns: Yep
  62. ---------------------------------------------------------------------------*/
  63. static void MySetObjectOwner(HANDLE hObject)
  64. {
  65. #ifndef _WIN32
  66. VOID (FAR PASCAL *lpSetObjOwner)(HANDLE, HANDLE);
  67. HMODULE hMod;
  68. hMod = GetModuleHandle("GDI");
  69. if (hMod)
  70. {
  71. (FARPROC)lpSetObjOwner = GetProcAddress(hMod, MAKEINTRESOURCE(461));
  72. if (lpSetObjOwner)
  73. {
  74. (lpSetObjOwner)(hObject, hInst);
  75. }
  76. }
  77. #endif
  78. }
  79. // initialize the hbrDither global brush
  80. // Call this with bIgnoreCount == TRUE if you just want to update the
  81. // current dither brush.
  82. BOOL FAR PASCAL CreateDitherBrush(BOOL bIgnoreCount)
  83. {
  84. HBITMAP hbmGray;
  85. HBRUSH hbrSave;
  86. if (bIgnoreCount && !iDitherCount)
  87. {
  88. return TRUE;
  89. }
  90. if (iDitherCount>0 && !bIgnoreCount)
  91. {
  92. iDitherCount++;
  93. return TRUE;
  94. }
  95. hbmGray = CreateDitherBitmap();
  96. if (hbmGray)
  97. {
  98. hbrSave = hbrDither;
  99. hbrDither = CreatePatternBrush(hbmGray);
  100. DeleteObject(hbmGray);
  101. if (hbrDither)
  102. {
  103. MySetObjectOwner(hbrDither);
  104. if (hbrSave)
  105. {
  106. DeleteObject(hbrSave);
  107. }
  108. if (!bIgnoreCount)
  109. {
  110. iDitherCount = 1;
  111. }
  112. return TRUE;
  113. }
  114. else
  115. {
  116. hbrDither = hbrSave;
  117. }
  118. }
  119. return FALSE;
  120. }
  121. BOOL FAR PASCAL FreeDitherBrush(void)
  122. {
  123. iDitherCount--;
  124. if (iDitherCount > 0)
  125. return FALSE;
  126. if (hbrDither)
  127. DeleteObject(hbrDither);
  128. hbrDither = NULL;
  129. return TRUE;
  130. }
  131. // initialize the hbmThumb global bitmap
  132. // Call this with bIgnoreCount == TRUE if you just want to update the
  133. // current bitmap.
  134. void FAR PASCAL CreateThumb(BOOL bIgnoreCount)
  135. {
  136. HBITMAP hbmSave;
  137. if (bIgnoreCount && !iThumbCount)
  138. {
  139. return;
  140. }
  141. if (iThumbCount && !bIgnoreCount)
  142. {
  143. ++iThumbCount;
  144. return;
  145. }
  146. hbmSave = hbmThumb;
  147. hbmThumb = CreateMappedBitmap(hInst, IDB_THUMB, CMB_MASKED, NULL, 0);
  148. if (hbmThumb)
  149. {
  150. if (hbmSave)
  151. {
  152. DeleteObject(hbmSave);
  153. }
  154. if (!bIgnoreCount)
  155. {
  156. iThumbCount = 1;
  157. }
  158. }
  159. else
  160. {
  161. hbmThumb = hbmSave;
  162. }
  163. }
  164. void FAR PASCAL DestroyThumb(void)
  165. {
  166. iThumbCount--;
  167. if (iThumbCount <= 0)
  168. {
  169. if (hbmThumb)
  170. {
  171. DeleteObject(hbmThumb);
  172. }
  173. hbmThumb = NULL;
  174. iThumbCount = 0;
  175. }
  176. }
  177. // Note that the trackbar will pass in NULL for pTBState, because it
  178. // just wants the dither brush to be updated.
  179. void FAR PASCAL CheckSysColors(void)
  180. {
  181. static COLORREF rgbSaveFace = 0xffffffffL,
  182. rgbSaveShadow = 0xffffffffL,
  183. rgbSaveHilight = 0xffffffffL,
  184. rgbSaveFrame = 0xffffffffL;
  185. rgbFace = GetSysColor(COLOR_BTNFACE);
  186. rgbShadow = GetSysColor(COLOR_BTNSHADOW);
  187. rgbHilight = GetSysColor(COLOR_BTNHIGHLIGHT);
  188. rgbFrame = GetSysColor(COLOR_WINDOWFRAME);
  189. if (rgbSaveFace!=rgbFace || rgbSaveShadow!=rgbShadow
  190. || rgbSaveHilight!=rgbHilight || rgbSaveFrame!=rgbFrame)
  191. {
  192. ++nSysColorChanges;
  193. // Update the brush for pushed-in buttons
  194. CreateDitherBrush(TRUE);
  195. CreateThumb(TRUE);
  196. rgbSaveFace = rgbFace;
  197. rgbSaveShadow = rgbShadow;
  198. rgbSaveHilight = rgbHilight;
  199. rgbSaveFrame = rgbFrame;
  200. }
  201. }