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.

158 lines
4.9 KiB

  1. /****************************** Module*Header *****************************\
  2. * Module Name: mirror.c *
  3. * *
  4. * This module contains all the Right-To-Left (RTL) Mirroring support *
  5. * routines used to Right-To-Left mirror an icon on the fly so that *
  6. * it would be displayed normal on a RTL mirrored localized OS. This is *
  7. * mainly a concern for 3rd party Apps. *
  8. * *
  9. * *
  10. * Created: 01-Feb-1998 8:41:18 pm *
  11. * Author: Samer Arafeh [samera] *
  12. * *
  13. * Copyright (c) 1998 Microsoft Corporation *
  14. \**************************************************************************/
  15. #include "ctlspriv.h"
  16. #include "image.h"
  17. /***************************************************************************\
  18. * MirrorIcon
  19. *
  20. * Mirror an Icon , given an Icon handle so that when these icons are displayed
  21. * on a Mirrored DC, they end would be displayed normal.
  22. *
  23. * History:
  24. * 04-Feb-1998 samera Created
  25. \***************************************************************************/
  26. BOOL WINAPI MirrorIcon(HICON* phiconSmall, HICON* phiconLarge)
  27. {
  28. HDC hdcScreen;
  29. HBITMAP hbm, hbmMask, hbmOld,hbmOldMask;
  30. BITMAP bm;
  31. HICON hicon[2] = {NULL,NULL};
  32. HICON hiconNew[2] = {NULL,NULL};
  33. ICONINFO ii ;
  34. int i;
  35. //
  36. // Synchronize access to global DCs now!
  37. // Allocate DCs if we didn't so far.
  38. //
  39. ENTERCRITICAL;
  40. if (!g_hdc && !g_hdcMask)
  41. {
  42. g_hdc = CreateCompatibleDC(NULL);
  43. if (g_hdc)
  44. {
  45. g_hdcMask = CreateCompatibleDC(NULL);
  46. if( g_hdcMask )
  47. {
  48. SET_DC_RTL_MIRRORED(g_hdc);
  49. SET_DC_RTL_MIRRORED(g_hdcMask);
  50. }
  51. else
  52. {
  53. DeleteDC( g_hdc );
  54. g_hdc = NULL;
  55. }
  56. }
  57. }
  58. if (phiconSmall)
  59. hicon[0] = *phiconSmall;
  60. if (phiconLarge)
  61. hicon[1] = *phiconLarge;
  62. //
  63. // Acquire the screen DC
  64. //
  65. hdcScreen = GetDC(NULL);
  66. if (g_hdc && g_hdcMask && hdcScreen)
  67. {
  68. for( i=0 ; i<(sizeof(hicon)/sizeof(HICON)) ; i++ )
  69. {
  70. if( hicon[i] )
  71. {
  72. if( GetIconInfo(hicon[i], &ii) &&
  73. GetObject(ii.hbmColor, sizeof(BITMAP), &bm))
  74. {
  75. //
  76. // I don't want these.
  77. //
  78. DeleteObject( ii.hbmMask );
  79. DeleteObject( ii.hbmColor );
  80. ii.hbmMask = ii.hbmColor = NULL;
  81. if (bm.bmBitsPixel == 32)
  82. {
  83. hbm = CreateDIB(hdcScreen, bm.bmWidth, bm.bmHeight, NULL);
  84. }
  85. else
  86. {
  87. hbm = CreateCompatibleBitmap(hdcScreen, bm.bmWidth, bm.bmHeight);
  88. }
  89. hbmMask = CreateBitmap(bm.bmWidth, bm.bmHeight, 1, 1, NULL);
  90. hbmOld = (HBITMAP)SelectObject(g_hdc, hbm);
  91. hbmOldMask = (HBITMAP)SelectObject(g_hdcMask, hbmMask);
  92. DrawIconEx(g_hdc, 0, 0, hicon[i], bm.bmWidth, bm.bmHeight, 0,
  93. NULL, DI_IMAGE);
  94. DrawIconEx(g_hdcMask, 0, 0, hicon[i], bm.bmWidth, bm.bmHeight, 0,
  95. NULL, DI_MASK);
  96. SelectObject(g_hdc, hbmOld);
  97. SelectObject(g_hdcMask, hbmOldMask);
  98. //
  99. // create the new mirrored icon, and delete bmps
  100. //
  101. ii.hbmMask = hbmMask;
  102. ii.hbmColor = hbm;
  103. hiconNew[i] = CreateIconIndirect(&ii);
  104. DeleteObject(hbm);
  105. DeleteObject(hbmMask);
  106. }
  107. }
  108. }
  109. }
  110. ReleaseDC(NULL, hdcScreen);
  111. //
  112. // Now we can reuse the global DCs
  113. //
  114. LEAVECRITICAL;
  115. //
  116. // Update icons if needed, and destroy old ones!
  117. //
  118. if (hicon[0] && hiconNew[0])
  119. {
  120. *phiconSmall = hiconNew[0];
  121. DestroyIcon(hicon[0]);
  122. }
  123. if (hicon[1] && hiconNew[1])
  124. {
  125. *phiconLarge = hiconNew[1];
  126. //
  127. // Don't delete twice
  128. //
  129. if (hicon[1] != hicon[0])
  130. DestroyIcon(hicon[1]);
  131. }
  132. return TRUE;
  133. }