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.

258 lines
6.7 KiB

  1. // Copyright (C) 1996-1997 Microsoft Corporation. All rights reserved.
  2. // wrappers for various routines that have slightly different implementations
  3. // for windowed and windowless controls.
  4. #include "header.h"
  5. #include "internet.h"
  6. #ifndef _DEBUG
  7. #undef THIS_FILE
  8. static const char THIS_FILE[] = __FILE__;
  9. #endif
  10. //=--------------------------------------------------------------------------=
  11. // COleControl::OcxGetFocus [wrapper]
  12. //=--------------------------------------------------------------------------=
  13. // indicates whether or not we have the focus.
  14. //
  15. // Parameters:
  16. // none
  17. //
  18. // Output:
  19. // TRUE if we have focus, else false
  20. BOOL COleControl::OcxGetFocus(void)
  21. {
  22. DBWIN("COleControl::OcxGetFocus");
  23. // if we're windowless, the site provides this functionality
  24. if (m_pInPlaceSiteWndless) {
  25. return (m_pInPlaceSiteWndless->GetFocus() == S_OK);
  26. }
  27. else {
  28. // we've got a window. just let the APIs do our work
  29. if (m_fInPlaceActive)
  30. return (GetFocus() == m_hwnd);
  31. else
  32. return FALSE;
  33. }
  34. }
  35. //=--------------------------------------------------------------------------=
  36. // COleControl::OcxGetWindowRect [wrapper]
  37. //=--------------------------------------------------------------------------=
  38. // returns the current rectangle for this control, and correctly handles
  39. // windowless vs windowed.
  40. //
  41. // Parameters:
  42. // LPRECT - [out] duh.
  43. //
  44. // Output:
  45. // BOOL - false means unexpected.
  46. BOOL COleControl::OcxGetWindowRect(LPRECT prc)
  47. {
  48. // if we're windowless, then we have this information already.
  49. if (Windowless()) {
  50. CopyRect(prc, &m_rcLocation);
  51. return TRUE;
  52. }
  53. else
  54. return GetWindowRect(m_hwnd, prc);
  55. }
  56. //=--------------------------------------------------------------------------=
  57. // COleControl::OcxDefWindowProc [wrapper]
  58. //=--------------------------------------------------------------------------=
  59. // default window processing
  60. LRESULT COleControl::OcxDefWindowProc(UINT msg, WPARAM wParam, LPARAM lParam)
  61. {
  62. // if we're windowless, this is a site provided pointer
  63. if (m_pInPlaceSiteWndless) {
  64. LRESULT result;
  65. m_pInPlaceSiteWndless->OnDefWindowMessage(msg, wParam, lParam, &result);
  66. return result;
  67. }
  68. else
  69. // we've got a window -- just pass it along
  70. return DefWindowProc(m_hwnd, msg, wParam, lParam);
  71. }
  72. //=--------------------------------------------------------------------------=
  73. // COleControl::OcxGetDC [wrapper]
  74. //=--------------------------------------------------------------------------=
  75. // wraps the functionality of GetDC, and correctly handles windowless controls
  76. //
  77. // Parameters:
  78. // none
  79. //
  80. // Output:
  81. // HDC - null means we couldn't get one
  82. //
  83. // Notes:
  84. // - we don't bother with a bunch of the IOleInPlaceSiteWindowless::GetDc
  85. // parameters, since the windows GetDC doesn't expose these either. users
  86. // wanting that sort of fine tuned control can call said routine
  87. // explicitly
  88. //
  89. HDC COleControl::OcxGetDC(void)
  90. {
  91. // if we're windowless, the site provides this functionality.
  92. if (m_pInPlaceSiteWndless) {
  93. HDC hdc;
  94. m_pInPlaceSiteWndless->GetDC(NULL, 0, &hdc);
  95. return hdc;
  96. }
  97. else
  98. return GetDC(m_hwnd);
  99. }
  100. //=--------------------------------------------------------------------------=
  101. // COleControl::OcxReleaseDC [wrapper]
  102. //=--------------------------------------------------------------------------=
  103. // releases a DC returned by OcxGetDC
  104. //
  105. // Parameters:
  106. // HDC - [in] release me
  107. void COleControl::OcxReleaseDC(HDC hdc)
  108. {
  109. // if we're windowless, the site does this for us
  110. if (m_pInPlaceSiteWndless)
  111. m_pInPlaceSiteWndless->ReleaseDC(hdc);
  112. else
  113. ReleaseDC(m_hwnd, hdc);
  114. }
  115. //=--------------------------------------------------------------------------=
  116. // COleControl::OcxSetCapture [wrapper]
  117. //=--------------------------------------------------------------------------=
  118. // provides a means for the control to get or release capture.
  119. //
  120. // Parameters:
  121. // BOOL - [in] true means take, false release
  122. //
  123. // Output:
  124. // BOOL - true means it's yours, false nuh-uh
  125. //
  126. // Notes:
  127. //
  128. BOOL COleControl::OcxSetCapture(BOOL fGrab)
  129. {
  130. HRESULT hr;
  131. // the host does this for us if we're windowless
  132. if (m_pInPlaceSiteWndless) {
  133. hr = m_pInPlaceSiteWndless->SetCapture(fGrab);
  134. return (hr == S_OK);
  135. } else {
  136. // people shouldn't call this when they're not in-place active, but
  137. // just in case...
  138. if (m_fInPlaceActive) {
  139. SetCapture(m_hwnd);
  140. return TRUE;
  141. } else
  142. return FALSE;
  143. }
  144. // dead code
  145. }
  146. //=--------------------------------------------------------------------------=
  147. // COleControl::OcxGetCapture [wrapper]
  148. //=--------------------------------------------------------------------------=
  149. // tells you whether or not you have the capture.
  150. //
  151. // Parameters:
  152. // none
  153. //
  154. // Output:
  155. // BOOL - true it's yours, false it's not
  156. BOOL COleControl::OcxGetCapture ( void )
  157. {
  158. // host does this for windowless dudes
  159. if (m_pInPlaceSiteWndless)
  160. return m_pInPlaceSiteWndless->GetCapture() == S_OK;
  161. else {
  162. // people shouldn't call this when they're not in-place active, but
  163. // just in case.
  164. if (m_fInPlaceActive)
  165. return GetCapture() == m_hwnd;
  166. else
  167. return FALSE;
  168. }
  169. }
  170. //=--------------------------------------------------------------------------=
  171. // COleControl::OcxInvalidateRect [wrapper]
  172. //=--------------------------------------------------------------------------=
  173. // invalidates the control's rectangle
  174. //
  175. // Parameters:
  176. // LPCRECT - [in] rectangle to invalidate
  177. // BOOL - [in] do we erase background first?
  178. BOOL COleControl::OcxInvalidateRect(LPCRECT prcInvalidate, BOOL fErase)
  179. {
  180. // if we're windowless, then we need to get the site to do all this for
  181. // us
  182. if (m_pInPlaceSiteWndless)
  183. return m_pInPlaceSiteWndless->InvalidateRect(prcInvalidate, fErase) == S_OK;
  184. else {
  185. // otherwise do something different depending on whether or not we're
  186. // in place active or not
  187. if (m_fInPlaceActive)
  188. return InvalidateRect(m_hwnd, prcInvalidate, TRUE);
  189. else
  190. ViewChanged();
  191. }
  192. return TRUE;
  193. }
  194. //=--------------------------------------------------------------------------=
  195. // COleControl::OcxScrollRect [wrapper]
  196. //=--------------------------------------------------------------------------=
  197. // does some window scrolling for the control
  198. //
  199. // Parameters:
  200. // LPCRECT - [in] region to scroll
  201. // LPCRECT - [in] region to clip
  202. // int - [in] dx to scroll
  203. // int - [in] dy to scroll
  204. BOOL COleControl::OcxScrollRect(LPCRECT prcBounds, LPCRECT prcClip, int dx, int dy)
  205. {
  206. // if we're windowless, the site provides this functionality, otherwise
  207. // APIs do the job
  208. if (m_pInPlaceSiteWndless)
  209. return m_pInPlaceSiteWndless->ScrollRect(dx, dy, prcBounds, prcClip) == S_OK;
  210. else {
  211. if (m_fInPlaceActive)
  212. ScrollWindowEx(m_hwnd, dx, dy, prcBounds, prcClip, NULL, NULL, SW_INVALIDATE);
  213. else
  214. return FALSE;
  215. }
  216. return TRUE;
  217. }