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.

284 lines
8.0 KiB

  1. /****************************************************************************
  2. UISUBS.CPP
  3. Owner: cslim
  4. Copyright (c) 1997-1999 Microsoft Corporation
  5. UI subfunctions
  6. History:
  7. 14-JUL-1999 cslim Copied from IME98 source tree
  8. *****************************************************************************/
  9. #include "precomp.h"
  10. #include "ui.h"
  11. #include "imedefs.h"
  12. #include "winex.h"
  13. #include "debug.h"
  14. // For OurLoadImage()
  15. typedef struct tagCOLORRPL
  16. {
  17. COLORREF cColOrg;
  18. COLORREF cColRpl;
  19. } COLORRPL;
  20. VOID PASCAL DrawBitmap(
  21. HDC hDC,
  22. LONG xStart,
  23. LONG yStart,
  24. HBITMAP hBitmap)
  25. {
  26. HDC hMemDC;
  27. HBITMAP hBMOld;
  28. BITMAP bm;
  29. POINT pt;
  30. if (hDC == 0 || hBitmap == 0)
  31. return;
  32. hMemDC = CreateCompatibleDC(hDC);
  33. hBMOld = (HBITMAP)SelectObject(hMemDC, hBitmap);
  34. GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
  35. DbgAssert(&bm != NULL);
  36. pt.x = bm.bmWidth;
  37. pt.y = bm.bmHeight;
  38. BitBlt(hDC, xStart, yStart, pt.x, pt.y, hMemDC, 0, 0, SRCCOPY);
  39. SelectObject(hMemDC, hBMOld);
  40. DeleteDC(hMemDC);
  41. return;
  42. }
  43. HBITMAP WINAPI ReplaceBitmapColor( HBITMAP hBmp, UINT uiColor, COLORRPL* pColOrg )
  44. {
  45. BITMAP bmp;
  46. HBITMAP hBmpNew;
  47. HDC hDC, hDCNew, hDCBmp;
  48. HBITMAP hBmpOld1;
  49. if (GetObject(hBmp, sizeof(BITMAP), &bmp) == 0)
  50. return 0;
  51. hBmpNew = CreateBitmap( bmp.bmWidth, bmp.bmHeight, 1, bmp.bmBitsPixel, (VOID*)NULL );
  52. hDC = GetDC( 0 );
  53. if ((hDCNew = CreateCompatibleDC(hDC)) == 0)
  54. return 0;
  55. if ((hDCBmp = CreateCompatibleDC(hDC)) == 0)
  56. {
  57. DeleteDC(hDCNew);
  58. return 0;
  59. }
  60. hBmpOld1 = (HBITMAP)SelectObject(hDCBmp, hBmpNew);
  61. //
  62. // Special case : LIGHT GRAY COLOR on WinNT
  63. //
  64. COLORRPL* pCol = (COLORRPL*)GlobalAlloc(GPTR, uiColor * sizeof(COLORRPL) );
  65. INT x = 0;
  66. INT y = 0;
  67. UINT iCol = 0;
  68. COLORREF col = {0};
  69. for( iCol = 0; iCol < uiColor; iCol++ ) {
  70. pCol[iCol].cColOrg = SetPixel( hDCBmp, 0, 0, pColOrg[iCol].cColOrg); // #IMPORTANT# - copy
  71. pCol[iCol].cColRpl= pColOrg[iCol].cColRpl; // copy
  72. }
  73. // master copy
  74. HBITMAP hBmpOld = (HBITMAP)SelectObject(hDCNew, hBmp);
  75. BitBlt(hDCBmp, 0, 0, bmp.bmWidth, bmp.bmHeight, hDCNew, 0, 0, SRCCOPY); // Fxx
  76. SelectObject(hDCNew, hBmpOld);
  77. DeleteObject(hBmp);
  78. DeleteDC(hDCNew);
  79. // replace color
  80. for( y=0; y<bmp.bmHeight; y++ ) {
  81. for( x=0; x<bmp.bmWidth; x++ ) {
  82. col = GetPixel( hDCBmp, x, y );
  83. for( iCol = 0; iCol < uiColor; iCol++ ) {
  84. if( col == pCol[iCol].cColOrg ) {
  85. SetPixel( hDCBmp, x, y, pCol[iCol].cColRpl );
  86. }
  87. }
  88. }
  89. }
  90. GlobalFree(pCol);
  91. SelectObject(hDCBmp, hBmpOld1);
  92. DeleteDC(hDCBmp);
  93. ReleaseDC(0, hDC);
  94. hBmp = hBmpNew;
  95. return hBmp;
  96. }
  97. HANDLE WINAPI OurLoadImage( LPCTSTR pszName, UINT uiType, INT cx, INT cy, UINT uiLoad)
  98. {
  99. #define MAXREPL 3
  100. HBITMAP hBmp = (HBITMAP)0;
  101. if (vpInstData->hInst == NULL)
  102. return NULL;
  103. if (GetSysColor(COLOR_3DFACE) == RGB(0,0,0))
  104. {
  105. static COLORRPL colRpl[MAXREPL] =
  106. {
  107. RGB(0,0,0), RGB(255,255,255),
  108. RGB(192,192,192), RGB(0,0,0),
  109. RGB(0,0,128), RGB(0,192,192),
  110. };
  111. HBITMAP hBmpNew;
  112. uiLoad &= ~LR_LOADMAP3DCOLORS;
  113. hBmp = (HBITMAP)LoadImage(vpInstData->hInst, pszName, uiType, cx, cy, uiLoad);
  114. if (hBmp == 0)
  115. return 0;
  116. hBmpNew = ReplaceBitmapColor(hBmp, MAXREPL, (COLORRPL*)&colRpl);
  117. DeleteObject(hBmp);
  118. hBmp = hBmpNew;
  119. }
  120. else
  121. {
  122. hBmp = (HBITMAP)LoadImage(vpInstData->hInst, pszName, uiType, cx, cy, uiLoad);
  123. }
  124. return hBmp;
  125. }
  126. BOOL WINAPI OurTextOutW(HDC hDC, INT x, INT y, WCHAR wch)
  127. {
  128. CHAR szOut[4]; // For one DBCS plus one SBCS NULL + extra one byte
  129. INT cch;
  130. if (IsWinNT() || IsMemphis())
  131. return TextOutW( hDC, x, y, &wch, 1);
  132. // Convert to ANSI
  133. cch = WideCharToMultiByte(CP_KOREA, 0,
  134. &wch, 1, (LPSTR)szOut, sizeof(szOut),
  135. NULL, NULL );
  136. DbgAssert(cch == 2);
  137. return TextOutA(hDC, x, y, szOut, cch);
  138. }
  139. #if 1 // MultiMonitor support
  140. /**********************************************************************/
  141. /* ImeMonitorFromWindow() */
  142. /**********************************************************************/
  143. HMONITOR PASCAL ImeMonitorFromWindow(
  144. HWND hAppWnd)
  145. {
  146. if (!g_pfnMonitorFromWindow) { return NULL; }
  147. return (*g_pfnMonitorFromWindow)(hAppWnd, MONITOR_DEFAULTTONEAREST);
  148. }
  149. /**********************************************************************/
  150. /* ImeMonitorWorkAreaFromWindow() */
  151. /**********************************************************************/
  152. void PASCAL ImeMonitorWorkAreaFromWindow(HWND hAppWnd, RECT* pRect)
  153. {
  154. HMONITOR hMonitor;
  155. CIMEData ImeData;
  156. RECT rect;
  157. hMonitor = ImeMonitorFromWindow(hAppWnd);
  158. if (hMonitor) {
  159. MONITORINFO sMonitorInfo;
  160. sMonitorInfo.cbSize = sizeof(sMonitorInfo);
  161. // init a default value to avoid GetMonitorInfo fails
  162. sMonitorInfo.rcWork = ImeData->rcWorkArea;
  163. (*g_pfnGetMonitorInfo)(hMonitor, &sMonitorInfo);
  164. *pRect = sMonitorInfo.rcWork;
  165. } else {
  166. *pRect = ImeData->rcWorkArea;
  167. }
  168. }
  169. /**********************************************************************/
  170. /* ImeMonitorFromPoint() */
  171. /**********************************************************************/
  172. HMONITOR PASCAL ImeMonitorFromPoint(
  173. POINT ptPoint)
  174. {
  175. if (!g_pfnMonitorFromPoint) { return NULL; }
  176. return (*g_pfnMonitorFromPoint)(ptPoint, MONITOR_DEFAULTTONEAREST);
  177. }
  178. /**********************************************************************/
  179. /* ImeMonitorWorkAreaFromPoint() */
  180. /**********************************************************************/
  181. void PASCAL ImeMonitorWorkAreaFromPoint(POINT ptPoint, RECT* pRect)
  182. {
  183. HMONITOR hMonitor;
  184. CIMEData ImeData;
  185. hMonitor = ImeMonitorFromPoint(ptPoint);
  186. if (hMonitor) {
  187. MONITORINFO sMonitorInfo;
  188. sMonitorInfo.cbSize = sizeof(sMonitorInfo);
  189. // init a default value to avoid GetMonitorInfo fails
  190. sMonitorInfo.rcWork = ImeData->rcWorkArea;
  191. (*g_pfnGetMonitorInfo)(hMonitor, &sMonitorInfo);
  192. *pRect = sMonitorInfo.rcWork;
  193. } else {
  194. *pRect = ImeData->rcWorkArea;
  195. }
  196. }
  197. /**********************************************************************/
  198. /* ImeMonitorFromRect() */
  199. /**********************************************************************/
  200. HMONITOR PASCAL ImeMonitorFromRect(
  201. LPRECT lprcRect)
  202. {
  203. if (!g_pfnMonitorFromRect) { return NULL; }
  204. return (*g_pfnMonitorFromRect)(lprcRect, MONITOR_DEFAULTTONEAREST);
  205. }
  206. /**********************************************************************/
  207. /* ImeMonitorWorkAreaFromRect() */
  208. /**********************************************************************/
  209. void PASCAL ImeMonitorWorkAreaFromRect(LPRECT lprcRect, RECT* pRect)
  210. {
  211. HMONITOR hMonitor;
  212. CIMEData ImeData;
  213. hMonitor = ImeMonitorFromRect(lprcRect);
  214. if (hMonitor) {
  215. MONITORINFO sMonitorInfo;
  216. sMonitorInfo.cbSize = sizeof(sMonitorInfo);
  217. // init a default value to avoid GetMonitorInfo fails
  218. sMonitorInfo.rcWork = ImeData->rcWorkArea;
  219. (*g_pfnGetMonitorInfo)(hMonitor, &sMonitorInfo);
  220. *pRect = sMonitorInfo.rcWork;
  221. } else {
  222. *pRect = ImeData->rcWorkArea;
  223. }
  224. }
  225. #endif