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.

245 lines
7.1 KiB

  1. /*
  2. * OBJFDBK.C
  3. *
  4. * Miscellaneous API's to generate UI feedback effects for OLE objects. This
  5. * is part of the OLE 2.0 User Interface Support Library.
  6. * The following feedback effects are supported:
  7. * 1. Object selection handles (OleUIDrawHandles)
  8. * 2. Open Object window shading (OleUIDrawShading)
  9. *
  10. * Copyright (c)1992 Microsoft Corporation, All Right Reserved
  11. */
  12. #define STRICT 1
  13. #include "ole2ui.h"
  14. static void DrawHandle(HDC hdc, int x, int y, UINT cSize, BOOL bInvert, BOOL fDraw);
  15. /*
  16. * OleUIDrawHandles
  17. *
  18. * Purpose:
  19. * Draw handles or/and boundary around Container Object when selected
  20. *
  21. * Parameters:
  22. * lpRect Dimensions of Container Object
  23. * hdc HDC of Container Object (MM_TEXT mapping mode)
  24. * dwFlags-
  25. * Exclusive flags
  26. * OLEUI_HANDLES_INSIDE Draw handles on inside of rect
  27. * OLEUI_HANDLES_OUTSIDE Draw handles on outside of rect
  28. * Optional flags
  29. * OLEUI_HANDLES_NOBORDER Draw handles only, no rect
  30. * OLEUI_HANDLES_USEINVERSE
  31. * use invert for handles and rect, o.t. use COLOR_WINDOWTEXT
  32. * cSize size of handle box
  33. * fDraw Draw if TRUE, erase if FALSE
  34. *
  35. * Return Value: null
  36. *
  37. */
  38. STDAPI_(void) OleUIDrawHandles(
  39. LPRECT lpRect,
  40. HDC hdc,
  41. DWORD dwFlags,
  42. UINT cSize,
  43. BOOL fDraw
  44. )
  45. {
  46. HBRUSH hbr;
  47. RECT rc;
  48. int bkmodeOld;
  49. BOOL bInvert = (BOOL) (dwFlags & OLEUI_HANDLES_USEINVERSE);
  50. CopyRect((LPRECT)&rc, lpRect);
  51. bkmodeOld = SetBkMode(hdc, TRANSPARENT);
  52. if (dwFlags & OLEUI_HANDLES_OUTSIDE)
  53. InflateRect((LPRECT)&rc, cSize - 1, cSize - 1);
  54. // Draw the handles inside the rectangle boundary
  55. DrawHandle(hdc, rc.left, rc.top, cSize, bInvert, fDraw);
  56. DrawHandle(hdc, rc.left, rc.top+(rc.bottom-rc.top-cSize)/2, cSize, bInvert, fDraw);
  57. DrawHandle(hdc, rc.left, rc.bottom-cSize, cSize, bInvert, fDraw);
  58. DrawHandle(hdc, rc.left+(rc.right-rc.left-cSize)/2, rc.top, cSize, bInvert, fDraw);
  59. DrawHandle(hdc, rc.left+(rc.right-rc.left-cSize)/2, rc.bottom-cSize, cSize, bInvert, fDraw);
  60. DrawHandle(hdc, rc.right-cSize, rc.top, cSize, bInvert, fDraw);
  61. DrawHandle(hdc, rc.right-cSize, rc.top+(rc.bottom-rc.top-cSize)/2, cSize, bInvert, fDraw);
  62. DrawHandle(hdc, rc.right-cSize, rc.bottom-cSize, cSize, bInvert, fDraw);
  63. if (!(dwFlags & OLEUI_HANDLES_NOBORDER)) {
  64. if (fDraw)
  65. hbr = GetStockObject(BLACK_BRUSH);
  66. else
  67. hbr = GetStockObject(WHITE_BRUSH);
  68. FrameRect(hdc, lpRect, hbr);
  69. }
  70. SetBkMode(hdc, bkmodeOld);
  71. }
  72. /*
  73. * DrawHandle
  74. *
  75. * Purpose:
  76. * Draw a handle box at the specified coordinate
  77. *
  78. * Parameters:
  79. * hdc HDC to be drawn into
  80. * x, y upper left corner coordinate of the handle box
  81. * cSize size of handle box
  82. * bInvert use InvertRect() if TRUE, otherwise use Rectangle()
  83. * fDraw Draw if TRUE, erase if FALSE, ignored if bInvert is TRUE
  84. *
  85. * Return Value: null
  86. *
  87. */
  88. static void DrawHandle(HDC hdc, int x, int y, UINT cSize, BOOL bInvert, BOOL fDraw)
  89. {
  90. HBRUSH hbr;
  91. HBRUSH hbrOld;
  92. HPEN hpen;
  93. HPEN hpenOld;
  94. RECT rc;
  95. if (!bInvert) {
  96. if (fDraw) {
  97. hpen = GetStockObject(BLACK_PEN);
  98. hbr = GetStockObject(BLACK_BRUSH);
  99. } else {
  100. hpen = GetStockObject(WHITE_PEN);
  101. hbr = GetStockObject(WHITE_PEN);
  102. }
  103. hpenOld = SelectObject(hdc, hpen);
  104. hbrOld = SelectObject(hdc, hbr);
  105. Rectangle(hdc, x, y, x+cSize, y+cSize);
  106. SelectObject(hdc, hpenOld);
  107. SelectObject(hdc, hbrOld);
  108. }
  109. else {
  110. rc.left = x;
  111. rc.top = y;
  112. rc.right = x + cSize;
  113. rc.bottom = y + cSize;
  114. InvertRect(hdc, (LPRECT)&rc);
  115. }
  116. }
  117. /*
  118. * OleUIDrawShading
  119. *
  120. * Purpose:
  121. * Shade the object when it is in in-place editing. Borders are drawn
  122. * on the Object rectangle. The right and bottom edge of the rectangle
  123. * are excluded in the drawing.
  124. *
  125. * Parameters:
  126. * lpRect Dimensions of Container Object
  127. * hdc HDC for drawing
  128. * dwFlags-
  129. * Exclusive flags
  130. * OLEUI_SHADE_FULLRECT Shade the whole rectangle
  131. * OLEUI_SHADE_BORDERIN Shade cWidth pixels inside rect
  132. * OLEUI_SHADE_BORDEROUT Shade cWidth pixels outside rect
  133. * Optional flags
  134. * OLEUI_SHADE_USEINVERSE
  135. * use PATINVERT instead of the hex value
  136. * cWidth width of border in pixel
  137. *
  138. * Return Value: null
  139. *
  140. */
  141. STDAPI_(void) OleUIDrawShading(LPRECT lpRect, HDC hdc, DWORD dwFlags, UINT cWidth)
  142. {
  143. HBRUSH hbr;
  144. HBRUSH hbrOld;
  145. HBITMAP hbm;
  146. RECT rc;
  147. WORD wHatchBmp[] = {0x11, 0x22, 0x44, 0x88, 0x11, 0x22, 0x44, 0x88};
  148. COLORREF cvText;
  149. COLORREF cvBk;
  150. hbm = CreateBitmap(8, 8, 1, 1, wHatchBmp);
  151. hbr = CreatePatternBrush(hbm);
  152. hbrOld = SelectObject(hdc, hbr);
  153. rc = *lpRect;
  154. if (dwFlags == OLEUI_SHADE_FULLRECT) {
  155. cvText = SetTextColor(hdc, RGB(255, 255, 255));
  156. cvBk = SetBkColor(hdc, RGB(0, 0, 0));
  157. PatBlt(hdc, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
  158. 0x00A000C9L /* DPa */ );
  159. } else { // either inside or outside rect
  160. if (dwFlags == OLEUI_SHADE_BORDEROUT)
  161. InflateRect((LPRECT)&rc, cWidth - 1, cWidth - 1);
  162. cvText = SetTextColor(hdc, RGB(255, 255, 255));
  163. cvBk = SetBkColor(hdc, RGB(0, 0, 0));
  164. PatBlt(hdc, rc.left, rc.top, rc.right - rc.left,
  165. cWidth, 0x00A000C9L /* DPa */);
  166. PatBlt(hdc, rc.left, rc.top, cWidth, rc.bottom - rc.top,
  167. 0x00A000C9L /* DPa */);
  168. PatBlt(hdc, rc.right - cWidth, rc.top, cWidth,
  169. rc.bottom - rc.top, 0x00A000C9L /* DPa */);
  170. PatBlt(hdc, rc.left, rc.bottom - cWidth, rc.right-rc.left,
  171. cWidth, 0x00A000C9L /* DPa */);
  172. }
  173. SetTextColor(hdc, cvText);
  174. SetBkColor(hdc, cvBk);
  175. SelectObject(hdc, hbrOld);
  176. DeleteObject(hbr);
  177. DeleteObject(hbm);
  178. }
  179. /*
  180. * OleUIShowObject
  181. *
  182. * Purpose:
  183. * Draw the ShowObject effect around the object
  184. *
  185. * Parameters:
  186. * lprc rectangle for drawing
  187. * hdc HDC for drawing
  188. * fIsLink linked object (TRUE) or embedding object (FALSE)
  189. *
  190. * Return Value: null
  191. *
  192. */
  193. STDAPI_(void) OleUIShowObject(LPCRECT lprc, HDC hdc, BOOL fIsLink)
  194. {
  195. HPEN hpen;
  196. HPEN hpenOld;
  197. HBRUSH hbrOld;
  198. if (!lprc || !hdc)
  199. return;
  200. hpen = fIsLink ? CreatePen(PS_DASH, 1, RGB(0,0,0)) :
  201. GetStockObject(BLACK_PEN);
  202. if (!hpen)
  203. return;
  204. hpenOld = SelectObject(hdc, hpen);
  205. hbrOld = SelectObject(hdc, GetStockObject(NULL_BRUSH));
  206. Rectangle(hdc, lprc->left, lprc->top, lprc->right, lprc->bottom);
  207. SelectObject(hdc, hpenOld);
  208. SelectObject(hdc, hbrOld);
  209. if (fIsLink)
  210. DeleteObject(hpen);
  211. }