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.

343 lines
9.6 KiB

  1. /*
  2. * HATCH.C
  3. *
  4. * Miscellaneous API's to generate hatch window for in-place active
  5. * objects. This is part of the OLE 2.0 User Interface Support Library.
  6. *
  7. * Copyright (c)1993 Microsoft Corporation, All Right Reserved
  8. */
  9. #define STRICT 1
  10. #include <windows.h>
  11. #ifdef MTN
  12. #pragma warning(disable: 4103) // used #pragma pack to change alignment (on Chicago)
  13. #endif
  14. #include <ole2.h>
  15. #include "mplayer.h"
  16. #include "ole2ui.h"
  17. // offsets in the extra bytes stored with the hatch window
  18. #define EB_HATCHWIDTH (0 * sizeof(INT))
  19. #define EB_HATCHRECT_LEFT (1 * sizeof(INT))
  20. #define EB_HATCHRECT_TOP (2 * sizeof(INT))
  21. #define EB_HATCHRECT_RIGHT (3 * sizeof(INT))
  22. #define EB_HATCHRECT_BOTTOM (4 * sizeof(INT))
  23. #define EB_HATCHRECT_HANDLE (5 * sizeof(INT))
  24. // class name of hatch window
  25. static TCHAR szHatchWindow[] = TEXT("Hatch Window");
  26. // local function prototypes
  27. LRESULT FAR PASCAL _EXPORT HatchWndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam);
  28. /*
  29. * HatchRegisterClass
  30. *
  31. * Purpose:
  32. * Register the hatch window
  33. *
  34. * Parameters:
  35. * hInst Process instance
  36. *
  37. * Return Value:
  38. * TRUE if successful
  39. * FALSE if failed
  40. *
  41. */
  42. STDAPI_(BOOL) RegisterHatchWindowClass(HINSTANCE hInst)
  43. {
  44. WNDCLASS wc;
  45. // Register Hatch Window Class
  46. wc.style = CS_BYTEALIGNWINDOW;
  47. wc.lpfnWndProc = HatchWndProc;
  48. wc.cbClsExtra = 0;
  49. wc.cbWndExtra = 6 * sizeof(int); // extra bytes stores
  50. // uHatchWidth
  51. // rcHatchRect
  52. wc.hInstance = hInst;
  53. wc.hIcon = NULL;
  54. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  55. wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  56. wc.lpszMenuName = NULL;
  57. wc.lpszClassName = szHatchWindow;
  58. if (!RegisterClass(&wc))
  59. return FALSE;
  60. else
  61. return TRUE;
  62. }
  63. /*
  64. * CreateHatchWindow
  65. *
  66. * Purpose:
  67. * Create the hatch window
  68. *
  69. * Parameters:
  70. * hWndParent parent of hatch window
  71. * hInst instance handle
  72. *
  73. * Return Value:
  74. * pointer to hatch window if successful
  75. * NULL if failed
  76. *
  77. */
  78. STDAPI_(HWND) CreateHatchWindow(HWND hWndParent, HINSTANCE hInst)
  79. {
  80. HWND hWnd;
  81. if (!hWndParent || !hInst)
  82. return NULL;
  83. hWnd = CreateWindowEx(
  84. gfdwFlagsEx,
  85. szHatchWindow,
  86. szHatchWindow,
  87. WS_CHILDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
  88. 0, 0, 0, 0,
  89. hWndParent,
  90. (HMENU)NULL,
  91. hInst,
  92. 0L
  93. );
  94. if (!hWnd)
  95. return NULL;
  96. return hWnd;
  97. }
  98. /*
  99. * GetHatchWidth
  100. *
  101. * Purpose:
  102. * Get width of hatch border
  103. *
  104. * Parameters:
  105. * hWndHatch hatch window handle
  106. *
  107. * Return Value:
  108. * width of the hatch border
  109. */
  110. STDAPI_(UINT) GetHatchWidth(HWND hWndHatch)
  111. {
  112. if (!IsWindow(hWndHatch))
  113. return 0;
  114. return (UINT)GETWINDOWUINT(hWndHatch, EB_HATCHWIDTH);
  115. }
  116. /*
  117. * GetHatchRect
  118. *
  119. * Purpose:
  120. * Get hatch rect. this is the size of the hatch window if it were
  121. * not clipped by the ClipRect.
  122. *
  123. * Parameters:
  124. * hWndHatch hatch window handle
  125. * lprcHatchRect hatch rect
  126. *
  127. * Return Value:
  128. * none
  129. */
  130. STDAPI_(void) GetHatchRect(HWND hWndHatch, LPRECT lprcHatchRect)
  131. {
  132. if (!IsWindow(hWndHatch)) {
  133. SetRect(lprcHatchRect, 0, 0, 0, 0);
  134. return;
  135. }
  136. lprcHatchRect->left = GETWINDOWUINT(hWndHatch, EB_HATCHRECT_LEFT);
  137. lprcHatchRect->top = GETWINDOWUINT(hWndHatch, EB_HATCHRECT_TOP);
  138. lprcHatchRect->right = GETWINDOWUINT(hWndHatch, EB_HATCHRECT_RIGHT);
  139. lprcHatchRect->bottom = GETWINDOWUINT(hWndHatch, EB_HATCHRECT_BOTTOM);
  140. }
  141. /* SetHatchRect
  142. *
  143. *
  144. * Purpose:
  145. * Store hatch rect with HatchRect window.
  146. * this rect is the size of the hatch window if it were
  147. * not clipped by the ClipRect.
  148. *
  149. * Parameters:
  150. * hWndHatch hatch window handle
  151. * lprcHatchRect hatch rect
  152. *
  153. * Return Value:
  154. * none
  155. */
  156. STDAPI_(void) SetHatchRect(HWND hWndHatch, LPRECT lprcHatchRect)
  157. {
  158. if (!IsWindow(hWndHatch))
  159. return;
  160. SETWINDOWUINT(hWndHatch, EB_HATCHRECT_LEFT, lprcHatchRect->left);
  161. SETWINDOWUINT(hWndHatch, EB_HATCHRECT_TOP, lprcHatchRect->top);
  162. SETWINDOWUINT(hWndHatch, EB_HATCHRECT_RIGHT, lprcHatchRect->right);
  163. SETWINDOWUINT(hWndHatch, EB_HATCHRECT_BOTTOM, lprcHatchRect->bottom);
  164. SETWINDOWUINT(hWndHatch, EB_HATCHRECT_HANDLE, 0);
  165. }
  166. /* SetHatchWindowSize
  167. *
  168. *
  169. * Purpose:
  170. * Move/size the HatchWindow correctly given the rect required by the
  171. * in-place server object window and the lprcClipRect imposed by the
  172. * in-place container. both rect's are expressed in the client coord.
  173. * of the in-place container's window (which is the parent of the
  174. * HatchWindow).
  175. *
  176. * OLE2NOTE: the in-place server must honor the lprcClipRect specified
  177. * by its in-place container. it must NOT draw outside of the ClipRect.
  178. * in order to achieve this, the hatch window is sized to be
  179. * exactly the size that should be visible (rcVisRect). the
  180. * rcVisRect is defined as the intersection of the full size of
  181. * the HatchRect window and the lprcClipRect.
  182. * the ClipRect could infact clip the HatchRect on the
  183. * right/bottom and/or on the top/left. if it is clipped on the
  184. * right/bottom then it is sufficient to simply resize the hatch
  185. * window. but if the HatchRect is clipped on the top/left then
  186. * in-place server document window (child of HatchWindow) must be moved
  187. * by the delta that was clipped. the window origin of the
  188. * in-place server window will then have negative coordinates relative
  189. * to its parent HatchWindow.
  190. *
  191. * Parameters:
  192. * hWndHatch hatch window handle
  193. * lprcIPObjRect full size of in-place server object window
  194. * lprcClipRect clipping rect imposed by in-place container
  195. * lpptOffset offset required to position in-place server object
  196. * window properly. caller should call:
  197. * OffsetRect(&rcObjRect,lpptOffset->x,lpptOffset->y)
  198. *
  199. * Return Value:
  200. * none
  201. */
  202. STDAPI_(void) SetHatchWindowSize(
  203. HWND hWndHatch,
  204. LPCRECT lprcIPObjRect,
  205. LPCRECT lprcClipRect,
  206. LPPOINT lpptOffset,
  207. BOOL handle
  208. )
  209. {
  210. RECT rcHatchRect;
  211. RECT rcVisRect;
  212. UINT uHatchWidth;
  213. POINT ptOffset;
  214. if (!IsWindow(hWndHatch))
  215. return;
  216. rcHatchRect = *lprcIPObjRect;
  217. uHatchWidth = GetHatchWidth(hWndHatch);
  218. if (uHatchWidth > 0) // If it's 0, we're hiding the hatch window
  219. InflateRect((LPRECT)&rcHatchRect, uHatchWidth + 1, uHatchWidth + 1);
  220. IntersectRect((LPRECT)&rcVisRect, (LPRECT)&rcHatchRect, lprcClipRect);
  221. MoveWindow(
  222. hWndHatch,
  223. rcVisRect.left,
  224. rcVisRect.top,
  225. rcVisRect.right-rcVisRect.left,
  226. rcVisRect.bottom-rcVisRect.top,
  227. TRUE /* fRepaint */
  228. );
  229. InvalidateRect(hWndHatch, NULL, TRUE);
  230. ptOffset.x = -rcHatchRect.left + (rcHatchRect.left - rcVisRect.left);
  231. ptOffset.y = -rcHatchRect.top + (rcHatchRect.top - rcVisRect.top);
  232. /* convert the rcHatchRect into the client coordinate system of the
  233. ** HatchWindow itself
  234. */
  235. OffsetRect((LPRECT)&rcHatchRect, ptOffset.x, ptOffset.y);
  236. SetHatchRect(hWndHatch, (LPRECT)&rcHatchRect);
  237. // calculate offset required to position in-place server doc window
  238. lpptOffset->x = ptOffset.x;
  239. lpptOffset->y = ptOffset.y;
  240. // No size handles:
  241. // SETWINDOWUINT(hWndHatch, EB_HATCHRECT_HANDLE, handle);
  242. }
  243. /*
  244. * HatchWndProc
  245. *
  246. * Purpose:
  247. * WndProc for hatch window
  248. *
  249. * Parameters:
  250. * hWnd
  251. * Message
  252. * wParam
  253. * lParam
  254. *
  255. * Return Value:
  256. * message dependent
  257. */
  258. LRESULT FAR PASCAL _EXPORT HatchWndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
  259. {
  260. int nBorderWidth;
  261. switch (Message) {
  262. case WM_CREATE:
  263. nBorderWidth = GetProfileInt(
  264. TEXT("windows"),
  265. TEXT("oleinplaceborderwidth"),
  266. DEFAULT_HATCHBORDER_WIDTH
  267. );
  268. SETWINDOWUINT(hWnd, EB_HATCHWIDTH, nBorderWidth);
  269. break;
  270. case WM_PAINT:
  271. {
  272. HDC hDC;
  273. PAINTSTRUCT ps;
  274. RECT rcHatchRect;
  275. nBorderWidth = GetHatchWidth(hWnd);
  276. hDC = BeginPaint(hWnd, &ps);
  277. GetHatchRect(hWnd, (LPRECT)&rcHatchRect);
  278. OleUIDrawShading(&rcHatchRect, hDC, OLEUI_SHADE_BORDERIN,
  279. nBorderWidth);
  280. InflateRect((LPRECT)&rcHatchRect, -nBorderWidth, -nBorderWidth);
  281. if (GETWINDOWUINT(hWnd,EB_HATCHRECT_HANDLE))
  282. OleUIDrawHandles(&rcHatchRect, hDC, OLEUI_HANDLES_OUTSIDE,
  283. nBorderWidth+1, TRUE);
  284. EndPaint(hWnd, &ps);
  285. break;
  286. }
  287. case WM_ERASEBKGND:
  288. /* If the hatch is hidden, don't bother erasing the background,
  289. * since the media clip will fill it in.
  290. */
  291. if (GETWINDOWUINT(hWnd, EB_HATCHWIDTH) == 0)
  292. return 1;
  293. /* Fall through ... */
  294. default:
  295. return DefWindowProc(hWnd, Message, wParam, lParam);
  296. }
  297. return 0L;
  298. }
  299.