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.

336 lines
8.2 KiB

  1. //=--------------------------------------------------------------------------=
  2. // CtlWrap.Cpp
  3. //=--------------------------------------------------------------------------=
  4. // Copyright 1995-1996 Microsoft Corporation. All Rights Reserved.
  5. //
  6. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  7. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  8. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  9. // PARTICULAR PURPOSE.
  10. //=--------------------------------------------------------------------------=
  11. //
  12. // wrappers for various routines that have slightly different implementations
  13. // for windowed and windowless controls.
  14. //
  15. #include "IPServer.H"
  16. #include "CtrlObj.H"
  17. // for ASSERT and FAIL
  18. //
  19. SZTHISFILE
  20. //=--------------------------------------------------------------------------=
  21. // COleControl::OcxGetFocus [wrapper]
  22. //=--------------------------------------------------------------------------=
  23. // indicates whether or not we have the focus.
  24. //
  25. // Parameters:
  26. // none
  27. //
  28. // Output:
  29. // TRUE if we have focus, else false
  30. //
  31. // Notes:
  32. //
  33. BOOL COleControl::OcxGetFocus
  34. (
  35. void
  36. )
  37. {
  38. // if we're windowless, the site provides this functionality
  39. //
  40. if (m_pInPlaceSiteWndless) {
  41. return (m_pInPlaceSiteWndless->GetFocus() == S_OK);
  42. } else {
  43. // we've got a window. just let the APIs do our work
  44. //
  45. if (m_fInPlaceActive)
  46. return (GetFocus() == m_hwnd);
  47. else
  48. return FALSE;
  49. }
  50. // dead code
  51. }
  52. //=--------------------------------------------------------------------------=
  53. // COleControl::OcxGetWindowRect [wrapper]
  54. //=--------------------------------------------------------------------------=
  55. // returns the current rectangle for this control, and correctly handles
  56. // windowless vs windowed.
  57. //
  58. // Parameters:
  59. // LPRECT - [out] duh.
  60. //
  61. // Output:
  62. // BOOL - false means unexpected.
  63. //
  64. // Notes:
  65. //
  66. BOOL COleControl::OcxGetWindowRect
  67. (
  68. LPRECT prc
  69. )
  70. {
  71. // if we're windowless, then we have this information already!
  72. //
  73. if (Windowless()) {
  74. *prc = m_rcLocation;
  75. return TRUE;
  76. } else
  77. return GetWindowRect(m_hwnd, prc);
  78. // dead code
  79. }
  80. //=--------------------------------------------------------------------------=
  81. // COleControl::OcxDefWindowProc [wrapper]
  82. //=--------------------------------------------------------------------------=
  83. // default window processing
  84. //
  85. // Parameters:
  86. // UINT - [in] duh.
  87. // WPARAM - [in] duh.
  88. // LPARAM - [in] DUH.
  89. //
  90. // Output:
  91. // LRESULT
  92. //
  93. // Notes:
  94. //
  95. LRESULT COleControl::OcxDefWindowProc
  96. (
  97. UINT msg,
  98. WPARAM wParam,
  99. LPARAM lParam
  100. )
  101. {
  102. LRESULT l;
  103. // if we're windowless, this is a site provided pointer
  104. //
  105. if (m_pInPlaceSiteWndless)
  106. m_pInPlaceSiteWndless->OnDefWindowMessage(msg, wParam, lParam, &l);
  107. else
  108. // we've got a window -- just pass it along
  109. //
  110. l = DefWindowProc(m_hwnd, msg, wParam, lParam);
  111. return l;
  112. }
  113. //=--------------------------------------------------------------------------=
  114. // COleControl::OcxGetDC [wrapper]
  115. //=--------------------------------------------------------------------------=
  116. // wraps the functionality of GetDC, and correctly handles windowless controls
  117. //
  118. // Parameters:
  119. // none
  120. //
  121. // Output:
  122. // HDC - null means we couldn't get one
  123. //
  124. // Notes:
  125. // - we don't bother with a bunch of the IOleInPlaceSiteWindowless::GetDc
  126. // parameters, since the windows GetDC doesn't expose these either. users
  127. // wanting that sort of fine tuned control can call said routine
  128. // explicitly
  129. //
  130. HDC COleControl::OcxGetDC
  131. (
  132. void
  133. )
  134. {
  135. HDC hdc = NULL;
  136. // if we're windowless, the site provides this functionality.
  137. //
  138. if (m_pInPlaceSiteWndless)
  139. m_pInPlaceSiteWndless->GetDC(NULL, 0, &hdc);
  140. else
  141. hdc = GetDC(m_hwnd);
  142. return hdc;
  143. }
  144. //=--------------------------------------------------------------------------=
  145. // COleControl::OcxReleaseDC [wrapper]
  146. //=--------------------------------------------------------------------------=
  147. // releases a DC returned by OcxGetDC
  148. //
  149. // Parameters:
  150. // HDC - [in] release me
  151. //
  152. // Output:
  153. // none
  154. //
  155. // Notes:
  156. //
  157. void COleControl::OcxReleaseDC
  158. (
  159. HDC hdc
  160. )
  161. {
  162. // if we're windowless, the site does this for us
  163. //
  164. if (m_pInPlaceSiteWndless)
  165. m_pInPlaceSiteWndless->ReleaseDC(hdc);
  166. else
  167. ReleaseDC(m_hwnd, hdc);
  168. }
  169. //=--------------------------------------------------------------------------=
  170. // COleControl::OcxSetCapture [wrapper]
  171. //=--------------------------------------------------------------------------=
  172. // provides a means for the control to get or release capture.
  173. //
  174. // Parameters:
  175. // BOOL - [in] true means take, false release
  176. //
  177. // Output:
  178. // BOOL - true means it's yours, false nuh-uh
  179. //
  180. // Notes:
  181. //
  182. BOOL COleControl::OcxSetCapture
  183. (
  184. BOOL fGrab
  185. )
  186. {
  187. HRESULT hr;
  188. // the host does this for us if we're windowless [i'm getting really bored
  189. // of typing that]
  190. //
  191. if (m_pInPlaceSiteWndless) {
  192. hr = m_pInPlaceSiteWndless->SetCapture(fGrab);
  193. return (hr == S_OK);
  194. } else {
  195. // people shouldn't call this when they're not in-place active, but
  196. // just in case...
  197. //
  198. if (m_fInPlaceActive) {
  199. SetCapture(m_hwnd);
  200. return TRUE;
  201. } else
  202. return FALSE;
  203. }
  204. // dead code
  205. }
  206. //=--------------------------------------------------------------------------=
  207. // COleControl::OcxGetCapture [wrapper]
  208. //=--------------------------------------------------------------------------=
  209. // tells you whether or not you have the capture.
  210. //
  211. // Parameters:
  212. // none
  213. //
  214. // Output:
  215. // BOOL - true it's yours, false it's not
  216. //
  217. // Notes:
  218. //
  219. BOOL COleControl::OcxGetCapture
  220. (
  221. void
  222. )
  223. {
  224. // host does this for windowless dudes
  225. //
  226. if (m_pInPlaceSiteWndless)
  227. return m_pInPlaceSiteWndless->GetCapture() == S_OK;
  228. else {
  229. // people shouldn't call this when they're not in-place active, but
  230. // just in case.
  231. //
  232. if (m_fInPlaceActive)
  233. return GetCapture() == m_hwnd;
  234. else
  235. return FALSE;
  236. }
  237. // dead code
  238. }
  239. //=--------------------------------------------------------------------------=
  240. // COleControl::OcxInvalidateRect [wrapper]
  241. //=--------------------------------------------------------------------------=
  242. // invalidates the control's rectangle
  243. //
  244. // Parameters:
  245. // LPCRECT - [in] rectangle to invalidate
  246. // BOOL - [in] do we erase background first?
  247. //
  248. // Output:
  249. // BOOL
  250. //
  251. // Notes:
  252. //
  253. BOOL COleControl::OcxInvalidateRect
  254. (
  255. LPCRECT prcInvalidate,
  256. BOOL fErase
  257. )
  258. {
  259. // if we're windowless, then we need to get the site to do all this for
  260. // us
  261. if (m_pInPlaceSiteWndless)
  262. return m_pInPlaceSiteWndless->InvalidateRect(prcInvalidate, fErase) == S_OK;
  263. else {
  264. // otherwise do something different depending on whether or not we're
  265. // in place active or not
  266. //
  267. if (m_fInPlaceActive)
  268. return InvalidateRect(m_hwnd, prcInvalidate, TRUE);
  269. else
  270. ViewChanged();
  271. }
  272. return TRUE;
  273. }
  274. //=--------------------------------------------------------------------------=
  275. // COleControl::OcxScrollRect [wrapper]
  276. //=--------------------------------------------------------------------------=
  277. // does some window scrolling for the control
  278. //
  279. // Parameters:
  280. // LPCRECT - [in] region to scroll
  281. // LPCRECT - [in] region to clip
  282. // int - [in] dx to scroll
  283. // int - [in] dy to scroll
  284. //
  285. // Output:
  286. // BOOL
  287. //
  288. // Notes:
  289. //
  290. BOOL COleControl::OcxScrollRect
  291. (
  292. LPCRECT prcBounds,
  293. LPCRECT prcClip,
  294. int dx,
  295. int dy
  296. )
  297. {
  298. // if we're windowless, the site provides this functionality, otherwise
  299. // APIs do the job
  300. //
  301. if (m_pInPlaceSiteWndless)
  302. return m_pInPlaceSiteWndless->ScrollRect(dx, dy, prcBounds, prcClip) == S_OK;
  303. else {
  304. if (m_fInPlaceActive)
  305. ScrollWindowEx(m_hwnd, dx, dy, prcBounds, prcClip, NULL, NULL, SW_INVALIDATE);
  306. else
  307. return FALSE;
  308. }
  309. return TRUE;
  310. }
  311.