Source code of Windows XP (NT5)
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.

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