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.

212 lines
6.3 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 <windows.h>
  14. #ifdef MTN
  15. #pragma warning(disable: 4103) // used #pragma pack to change alignment (on Chicago)
  16. #endif
  17. #include <ole2.h>
  18. #include "ole2ui.h"
  19. static void DrawHandle(HDC hdc, int x, int y, UINT cSize, BOOL bInvert, BOOL fDraw);
  20. /*
  21. * OleUIDrawHandles
  22. *
  23. * Purpose:
  24. * Draw handles or/and boundary around Container Object when selected
  25. *
  26. * Parameters:
  27. * lpRect Dimensions of Container Object
  28. * hdc HDC of Container Object (MM_TEXT mapping mode)
  29. * dwFlags-
  30. * Exclusive flags
  31. * OLEUI_HANDLES_INSIDE Draw handles on inside of rect
  32. * OLEUI_HANDLES_OUTSIDE Draw handles on outside of rect
  33. * Optional flags
  34. * OLEUI_HANDLES_NOBORDER Draw handles only, no rect
  35. * OLEUI_HANDLES_USEINVERSE
  36. * use invert for handles and rect, o.t. use COLOR_WINDOWTEXT
  37. * cSize size of handle box
  38. * fDraw Draw if TRUE, erase if FALSE
  39. *
  40. * Return Value: null
  41. *
  42. */
  43. STDAPI_(void) OleUIDrawHandles(
  44. LPRECT lpRect,
  45. HDC hdc,
  46. DWORD dwFlags,
  47. UINT cSize,
  48. BOOL fDraw
  49. )
  50. {
  51. HBRUSH hbr;
  52. RECT rc;
  53. int bkmodeOld;
  54. BOOL bInvert = (BOOL) (dwFlags & OLEUI_HANDLES_USEINVERSE);
  55. CopyRect((LPRECT)&rc, lpRect);
  56. bkmodeOld = SetBkMode(hdc, TRANSPARENT);
  57. if (dwFlags & OLEUI_HANDLES_OUTSIDE)
  58. InflateRect((LPRECT)&rc, cSize - 1, cSize - 1);
  59. // Draw the handles inside the rectangle boundary
  60. DrawHandle(hdc, rc.left, rc.top, cSize, bInvert, fDraw);
  61. DrawHandle(hdc, rc.left, rc.top+(rc.bottom-rc.top-cSize)/2, cSize, bInvert, fDraw);
  62. DrawHandle(hdc, rc.left, rc.bottom-cSize, cSize, bInvert, fDraw);
  63. DrawHandle(hdc, rc.left+(rc.right-rc.left-cSize)/2, rc.top, cSize, bInvert, fDraw);
  64. DrawHandle(hdc, rc.left+(rc.right-rc.left-cSize)/2, rc.bottom-cSize, cSize, bInvert, fDraw);
  65. DrawHandle(hdc, rc.right-cSize, rc.top, cSize, bInvert, fDraw);
  66. DrawHandle(hdc, rc.right-cSize, rc.top+(rc.bottom-rc.top-cSize)/2, cSize, bInvert, fDraw);
  67. DrawHandle(hdc, rc.right-cSize, rc.bottom-cSize, cSize, bInvert, fDraw);
  68. if (!(dwFlags & OLEUI_HANDLES_NOBORDER)) {
  69. if (fDraw)
  70. hbr = GetStockObject(BLACK_BRUSH);
  71. else
  72. hbr = GetStockObject(WHITE_BRUSH);
  73. if (hbr)
  74. FrameRect(hdc, lpRect, hbr);
  75. }
  76. SetBkMode(hdc, bkmodeOld);
  77. }
  78. /*
  79. * DrawHandle
  80. *
  81. * Purpose:
  82. * Draw a handle box at the specified coordinate
  83. *
  84. * Parameters:
  85. * hdc HDC to be drawn into
  86. * x, y upper left corner coordinate of the handle box
  87. * cSize size of handle box
  88. * bInvert use InvertRect() if TRUE, otherwise use Rectangle()
  89. * fDraw Draw if TRUE, erase if FALSE, ignored if bInvert is TRUE
  90. *
  91. * Return Value: null
  92. *
  93. */
  94. static void DrawHandle(HDC hdc, int x, int y, UINT cSize, BOOL bInvert, BOOL fDraw)
  95. {
  96. HBRUSH hbr;
  97. HBRUSH hbrOld;
  98. HPEN hpen;
  99. HPEN hpenOld;
  100. RECT rc;
  101. if (!bInvert) {
  102. if (fDraw) {
  103. hpen = GetStockObject(BLACK_PEN);
  104. hbr = GetStockObject(BLACK_BRUSH);
  105. } else {
  106. hpen = GetStockObject(WHITE_PEN);
  107. hbr = GetStockObject(WHITE_PEN);
  108. }
  109. hpenOld = SelectObject(hdc, hpen);
  110. hbrOld = SelectObject(hdc, hbr);
  111. Rectangle(hdc, x, y, x+cSize, y+cSize);
  112. SelectObject(hdc, hpenOld);
  113. SelectObject(hdc, hbrOld);
  114. }
  115. else {
  116. rc.left = x;
  117. rc.top = y;
  118. rc.right = x + cSize;
  119. rc.bottom = y + cSize;
  120. InvertRect(hdc, (LPRECT)&rc);
  121. }
  122. }
  123. /*
  124. * OleUIDrawShading
  125. *
  126. * Purpose:
  127. * Shade the object when it is in in-place editing. Borders are drawn
  128. * on the Object rectangle. The right and bottom edge of the rectangle
  129. * are excluded in the drawing.
  130. *
  131. * Parameters:
  132. * lpRect Dimensions of Container Object
  133. * hdc HDC for drawing
  134. * dwFlags-
  135. * Exclusive flags
  136. * OLEUI_SHADE_FULLRECT Shade the whole rectangle
  137. * OLEUI_SHADE_BORDERIN Shade cWidth pixels inside rect
  138. * OLEUI_SHADE_BORDEROUT Shade cWidth pixels outside rect
  139. * Optional flags
  140. * OLEUI_SHADE_USEINVERSE
  141. * use PATINVERT instead of the hex value
  142. * cWidth width of border in pixel
  143. *
  144. * Return Value: null
  145. *
  146. */
  147. STDAPI_(void) OleUIDrawShading(LPRECT lpRect, HDC hdc, DWORD dwFlags, UINT cWidth)
  148. {
  149. HBRUSH hbr;
  150. HBRUSH hbrOld;
  151. HBITMAP hbm;
  152. RECT rc;
  153. WORD wHatchBmp[] = {0x11, 0x22, 0x44, 0x88, 0x11, 0x22, 0x44, 0x88};
  154. COLORREF cvText;
  155. COLORREF cvBk;
  156. hbm = CreateBitmap(8, 8, 1, 1, wHatchBmp);
  157. hbr = CreatePatternBrush(hbm);
  158. hbrOld = SelectObject(hdc, hbr);
  159. rc = *lpRect;
  160. if (dwFlags == OLEUI_SHADE_FULLRECT) {
  161. cvText = SetTextColor(hdc, RGB(255, 255, 255));
  162. cvBk = SetBkColor(hdc, RGB(0, 0, 0));
  163. PatBlt(hdc, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
  164. 0x00A000C9L /* DPa */ );
  165. } else { // either inside or outside rect
  166. if (dwFlags == OLEUI_SHADE_BORDEROUT)
  167. InflateRect((LPRECT)&rc, cWidth - 1, cWidth - 1);
  168. cvText = SetTextColor(hdc, RGB(255, 255, 255));
  169. cvBk = SetBkColor(hdc, RGB(0, 0, 0));
  170. PatBlt(hdc, rc.left, rc.top, rc.right - rc.left,
  171. cWidth, 0x00A000C9L /* DPa */);
  172. PatBlt(hdc, rc.left, rc.top, cWidth, rc.bottom - rc.top,
  173. 0x00A000C9L /* DPa */);
  174. PatBlt(hdc, rc.right - cWidth, rc.top, cWidth,
  175. rc.bottom - rc.top, 0x00A000C9L /* DPa */);
  176. PatBlt(hdc, rc.left, rc.bottom - cWidth, rc.right-rc.left,
  177. cWidth, 0x00A000C9L /* DPa */);
  178. }
  179. SetTextColor(hdc, cvText);
  180. SetBkColor(hdc, cvBk);
  181. SelectObject(hdc, hbrOld);
  182. if (hbr)
  183. DeleteObject(hbr);
  184. if (hbm)
  185. DeleteObject(hbm);
  186. }
  187.