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.

333 lines
11 KiB

  1. /*++
  2. Copyright (c) 1990-1998 Microsoft Corporation, All Rights Reserved
  3. Module Name:
  4. UIGUIDE.C
  5. ++*/
  6. /**********************************************************************/
  7. #include "windows.h"
  8. #include "immdev.h"
  9. #include "fakeime.h"
  10. /**********************************************************************/
  11. /* */
  12. /* GuideWndProc() */
  13. /* IME UI window procedure */
  14. /* */
  15. /**********************************************************************/
  16. LRESULT CALLBACK GuideWndProc( hWnd, message, wParam, lParam )
  17. HWND hWnd;
  18. UINT message;
  19. WPARAM wParam;
  20. LPARAM lParam;
  21. {
  22. PAINTSTRUCT ps;
  23. HWND hUIWnd;
  24. HDC hDC;
  25. HBITMAP hbmpGuide;
  26. RECT rc;
  27. switch (message)
  28. {
  29. case WM_UI_HIDE:
  30. ShowWindow(hWnd, SW_HIDE);
  31. break;
  32. case WM_UI_UPDATE:
  33. InvalidateRect(hWnd,NULL,FALSE);
  34. break;
  35. case WM_PAINT:
  36. hDC = BeginPaint(hWnd,&ps);
  37. PaintGuide(hWnd,hDC,NULL,0);
  38. EndPaint(hWnd,&ps);
  39. break;
  40. case WM_MOUSEMOVE:
  41. case WM_SETCURSOR:
  42. case WM_LBUTTONUP:
  43. case WM_RBUTTONUP:
  44. ButtonGuide(hWnd,message,wParam,lParam);
  45. if ((message == WM_SETCURSOR) &&
  46. (HIWORD(lParam) != WM_LBUTTONDOWN) &&
  47. (HIWORD(lParam) != WM_RBUTTONDOWN))
  48. return DefWindowProc(hWnd,message,wParam,lParam);
  49. if ((message == WM_LBUTTONUP) || (message == WM_RBUTTONUP))
  50. {
  51. SetWindowLong(hWnd,FIGWL_MOUSE,0L);
  52. SetWindowLong(hWnd,FIGWL_PUSHSTATUS,0L);
  53. }
  54. break;
  55. case WM_MOVE:
  56. hUIWnd = (HWND)GetWindowLongPtr(hWnd,FIGWL_SVRWND);
  57. if (IsWindow(hUIWnd))
  58. SendMessage(hUIWnd,WM_UI_GUIDEMOVE,wParam,lParam);
  59. break;
  60. case WM_CREATE:
  61. hbmpGuide = LoadBitmap(hInst,TEXT("CLOSEBMP"));
  62. SetWindowLongPtr(hWnd,FIGWL_CLOSEBMP,(LONG_PTR)hbmpGuide);
  63. GetClientRect(hWnd,&rc);
  64. break;
  65. case WM_DESTROY:
  66. hbmpGuide = (HBITMAP)GetWindowLongPtr(hWnd,FIGWL_CLOSEBMP);
  67. DeleteObject(hbmpGuide);
  68. break;
  69. default:
  70. if (!MyIsIMEMessage(message))
  71. return DefWindowProc(hWnd,message,wParam,lParam);
  72. break;
  73. }
  74. return 0;
  75. }
  76. /**********************************************************************/
  77. /* */
  78. /* CheckPushedGuide() */
  79. /* */
  80. /**********************************************************************/
  81. DWORD PASCAL CheckPushedGuide( HWND hGuideWnd, LPPOINT lppt)
  82. {
  83. POINT pt;
  84. RECT rc;
  85. if (lppt)
  86. {
  87. pt = *lppt;
  88. ScreenToClient(hGuideWnd,&pt);
  89. GetClientRect(hGuideWnd,&rc);
  90. if (!PtInRect(&rc,pt))
  91. return 0;
  92. rc.left = rc.right-STCLBT_DX-2;
  93. rc.top = STCLBT_Y;
  94. rc.right = rc.left + STCLBT_DX;
  95. rc.bottom = rc.top + STCLBT_DY;
  96. if (PtInRect(&rc,pt))
  97. return PUSHED_STATUS_CLOSE;
  98. }
  99. return 0;
  100. }
  101. /**********************************************************************/
  102. /* */
  103. /* PaintGuide() */
  104. /* */
  105. /**********************************************************************/
  106. void PASCAL PaintGuide( HWND hGuideWnd , HDC hDC, LPPOINT lppt, DWORD dwPushedGuide)
  107. {
  108. HIMC hIMC;
  109. HDC hMemDC;
  110. HBITMAP hbmpOld;
  111. HWND hSvrWnd;
  112. HANDLE hGLStr;
  113. LPTSTR lpGLStr;
  114. DWORD dwLevel;
  115. DWORD dwSize;
  116. hSvrWnd = (HWND)GetWindowLongPtr(hGuideWnd,FIGWL_SVRWND);
  117. if (hIMC = (HIMC)GetWindowLongPtr(hSvrWnd,IMMGWLP_IMC))
  118. {
  119. HBITMAP hbmpGuide;
  120. HBRUSH hOldBrush,hBrush;
  121. int nCyCap = GetSystemMetrics(SM_CYSMCAPTION);
  122. RECT rc;
  123. hMemDC = CreateCompatibleDC(hDC);
  124. // Paint Caption.
  125. hBrush = CreateSolidBrush(GetSysColor(COLOR_ACTIVECAPTION));
  126. hOldBrush = SelectObject(hDC,hBrush);
  127. GetClientRect(hGuideWnd,&rc);
  128. //rc.top = rc.left = 0;
  129. //rc.right = BTX*3;
  130. rc.bottom = nCyCap;
  131. FillRect(hDC,&rc,hBrush);
  132. SelectObject(hDC,hOldBrush);
  133. DeleteObject(hBrush);
  134. // Paint CloseButton.
  135. hbmpGuide = (HBITMAP)GetWindowLongPtr(hGuideWnd,FIGWL_CLOSEBMP);
  136. hbmpOld = SelectObject(hMemDC,hbmpGuide);
  137. if (!(dwPushedGuide & PUSHED_STATUS_CLOSE))
  138. BitBlt(hDC,rc.right-STCLBT_DX-2,STCLBT_Y,STCLBT_DX,STCLBT_DY,
  139. hMemDC,0,0,SRCCOPY);
  140. else
  141. BitBlt(hDC,rc.right-STCLBT_DX-2,STCLBT_Y,STCLBT_DX,STCLBT_DY,
  142. hMemDC,STCLBT_DX,0,SRCCOPY);
  143. if (dwLevel = ImmGetGuideLine(hIMC,GGL_LEVEL,NULL,0))
  144. {
  145. dwSize = ImmGetGuideLine(hIMC,GGL_STRING,NULL,0) + 1;
  146. if ((dwSize > 1) && (hGLStr = GlobalAlloc(GHND,dwSize)))
  147. {
  148. if (lpGLStr = (LPTSTR)GlobalLock(hGLStr))
  149. {
  150. COLORREF rgb = 0;
  151. HBRUSH hbrLGR = GetStockObject(LTGRAY_BRUSH);
  152. HBRUSH hbr;
  153. hbr = SelectObject(hDC,hbrLGR);
  154. GetClientRect(hGuideWnd,&rc);
  155. PatBlt(hDC,0,nCyCap,rc.right,rc.bottom-nCyCap,PATCOPY);
  156. SelectObject(hDC,hbr);
  157. switch (dwLevel)
  158. {
  159. case GL_LEVEL_FATAL:
  160. case GL_LEVEL_ERROR:
  161. rgb = RGB(255,0,0);
  162. break;
  163. case GL_LEVEL_WARNING:
  164. rgb = RGB(0,0,255);
  165. break;
  166. case GL_LEVEL_INFORMATION:
  167. default:
  168. rgb = RGB(0,0,0);
  169. break;
  170. }
  171. if (dwSize = ImmGetGuideLine(hIMC,GGL_STRING,lpGLStr,dwSize))
  172. {
  173. SetTextColor(hDC,rgb);
  174. SetBkMode(hDC,TRANSPARENT);
  175. TextOut(hDC,0,nCyCap,lpGLStr,dwSize);
  176. }
  177. GlobalUnlock(hGLStr);
  178. }
  179. GlobalFree(hGLStr);
  180. }
  181. }
  182. SelectObject(hMemDC,hbmpOld);
  183. DeleteDC(hMemDC);
  184. }
  185. }
  186. /**********************************************************************/
  187. /* */
  188. /* ButtonGuide(hGuideWnd,message,wParam,lParam) */
  189. /* */
  190. /**********************************************************************/
  191. void PASCAL ButtonGuide( HWND hGuideWnd, UINT message, WPARAM wParam, LPARAM lParam)
  192. {
  193. POINT pt;
  194. HDC hDC;
  195. DWORD dwMouse;
  196. DWORD dwPushedGuide;
  197. DWORD dwTemp;
  198. HIMC hIMC;
  199. HWND hSvrWnd;
  200. static POINT ptdif;
  201. static RECT drc;
  202. static RECT rc;
  203. static DWORD dwCurrentPushedGuide;
  204. hDC = GetDC(hGuideWnd);
  205. switch (message)
  206. {
  207. case WM_SETCURSOR:
  208. if ( HIWORD(lParam) == WM_LBUTTONDOWN
  209. || HIWORD(lParam) == WM_RBUTTONDOWN )
  210. {
  211. GetCursorPos( &pt );
  212. SetCapture(hGuideWnd);
  213. GetWindowRect(hGuideWnd,&drc);
  214. ptdif.x = pt.x - drc.left;
  215. ptdif.y = pt.y - drc.top;
  216. rc = drc;
  217. rc.right -= rc.left;
  218. rc.bottom -= rc.top;
  219. SetWindowLong(hGuideWnd,FIGWL_MOUSE,FIM_CAPUTURED);
  220. SetWindowLong(hGuideWnd, FIGWL_PUSHSTATUS, dwPushedGuide = CheckPushedGuide(hGuideWnd,&pt));
  221. PaintGuide(hGuideWnd,hDC,&pt, dwPushedGuide);
  222. dwCurrentPushedGuide = dwPushedGuide;
  223. }
  224. break;
  225. case WM_MOUSEMOVE:
  226. dwMouse = GetWindowLong(hGuideWnd,FIGWL_MOUSE);
  227. if (!(dwPushedGuide = GetWindowLong(hGuideWnd, FIGWL_PUSHSTATUS)))
  228. {
  229. if (dwMouse & FIM_MOVED)
  230. {
  231. DrawUIBorder(&drc);
  232. GetCursorPos( &pt );
  233. drc.left = pt.x - ptdif.x;
  234. drc.top = pt.y - ptdif.y;
  235. drc.right = drc.left + rc.right;
  236. drc.bottom = drc.top + rc.bottom;
  237. DrawUIBorder(&drc);
  238. }
  239. else if (dwMouse & FIM_CAPUTURED)
  240. {
  241. DrawUIBorder(&drc);
  242. SetWindowLong(hGuideWnd,FIGWL_MOUSE,dwMouse | FIM_MOVED);
  243. }
  244. }
  245. else
  246. {
  247. GetCursorPos(&pt);
  248. dwTemp = CheckPushedGuide(hGuideWnd,&pt);
  249. if ((dwTemp ^ dwCurrentPushedGuide) & dwPushedGuide)
  250. PaintGuide(hGuideWnd,hDC,&pt, dwPushedGuide & dwTemp);
  251. dwCurrentPushedGuide = dwTemp;
  252. }
  253. break;
  254. case WM_LBUTTONUP:
  255. case WM_RBUTTONUP:
  256. dwMouse = GetWindowLong(hGuideWnd,FIGWL_MOUSE);
  257. if (dwMouse & FIM_CAPUTURED)
  258. {
  259. ReleaseCapture();
  260. if (dwMouse & FIM_MOVED)
  261. {
  262. DrawUIBorder(&drc);
  263. GetCursorPos( &pt );
  264. MoveWindow(hGuideWnd,pt.x - ptdif.x,
  265. pt.y - ptdif.y,
  266. rc.right,
  267. rc.bottom,TRUE);
  268. }
  269. }
  270. hSvrWnd = (HWND)GetWindowLongPtr(hGuideWnd,FIGWL_SVRWND);
  271. if (hIMC = (HIMC)GetWindowLongPtr(hSvrWnd,IMMGWLP_IMC))
  272. {
  273. GetCursorPos(&pt);
  274. dwPushedGuide = GetWindowLong(hGuideWnd, FIGWL_PUSHSTATUS);
  275. dwPushedGuide &= CheckPushedGuide(hGuideWnd,&pt);
  276. if (!dwPushedGuide) {
  277. } else if (dwPushedGuide == PUSHED_STATUS_CLOSE) {
  278. PostMessage(hGuideWnd,WM_UI_HIDE,0,0);
  279. }
  280. }
  281. PaintGuide(hGuideWnd,hDC,NULL,0);
  282. break;
  283. }
  284. ReleaseDC(hGuideWnd,hDC);
  285. }
  286. /**********************************************************************/
  287. /* */
  288. /* UpdateGuideWindow(lpUIExtra) */
  289. /* */
  290. /**********************************************************************/
  291. void PASCAL UpdateGuideWindow(LPUIEXTRA lpUIExtra)
  292. {
  293. if (IsWindow(lpUIExtra->uiGuide.hWnd))
  294. SendMessage(lpUIExtra->uiGuide.hWnd,WM_UI_UPDATE,0,0L);
  295. }