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.

338 lines
8.7 KiB

  1. //=--------------------------------------------------------------------------=
  2. // CtlWrap.Cpp
  3. //=--------------------------------------------------------------------------=
  4. // Copyright 1995 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 "pch.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. if (fGrab)
  200. SetCapture(m_hwnd);
  201. else
  202. ReleaseCapture();
  203. return TRUE;
  204. } else
  205. return FALSE;
  206. }
  207. // dead code
  208. }
  209. //=--------------------------------------------------------------------------=
  210. // COleControl::OcxGetCapture [wrapper]
  211. //=--------------------------------------------------------------------------=
  212. // tells you whether or not you have the capture.
  213. //
  214. // Parameters:
  215. // none
  216. //
  217. // Output:
  218. // BOOL - true it's yours, false it's not
  219. //
  220. // Notes:
  221. //
  222. BOOL COleControl::OcxGetCapture
  223. (
  224. void
  225. )
  226. {
  227. // host does this for windowless dudes
  228. //
  229. if (m_pInPlaceSiteWndless)
  230. return m_pInPlaceSiteWndless->GetCapture() == S_OK;
  231. else {
  232. // people shouldn't call this when they're not in-place active, but
  233. // just in case.
  234. //
  235. if (m_fInPlaceActive)
  236. return GetCapture() == m_hwnd;
  237. else
  238. return FALSE;
  239. }
  240. // dead code
  241. }
  242. //=--------------------------------------------------------------------------=
  243. // COleControl::OcxInvalidateRect [wrapper]
  244. //=--------------------------------------------------------------------------=
  245. // invalidates the control's rectangle
  246. //
  247. // Parameters:
  248. // LPCRECT - [in] rectangle to invalidate
  249. // BOOL - [in] do we erase background first?
  250. //
  251. // Output:
  252. // BOOL
  253. //
  254. // Notes:
  255. //
  256. BOOL COleControl::OcxInvalidateRect
  257. (
  258. LPCRECT prcInvalidate,
  259. BOOL fErase
  260. )
  261. {
  262. // if we're windowless, then we need to get the site to do all this for
  263. // us
  264. if (m_pInPlaceSiteWndless)
  265. return m_pInPlaceSiteWndless->InvalidateRect(prcInvalidate, fErase) == S_OK;
  266. else {
  267. // otherwise do something different depending on whether or not we're
  268. // in place active or not
  269. //
  270. if (m_fInPlaceActive && m_hwnd)
  271. return InvalidateRect(m_hwnd, prcInvalidate, fErase);
  272. else
  273. ViewChanged();
  274. }
  275. return TRUE;
  276. }
  277. //=--------------------------------------------------------------------------=
  278. // COleControl::OcxScrollRect [wrapper]
  279. //=--------------------------------------------------------------------------=
  280. // does some window scrolling for the control
  281. //
  282. // Parameters:
  283. // LPCRECT - [in] region to scroll
  284. // LPCRECT - [in] region to clip
  285. // int - [in] dx to scroll
  286. // int - [in] dy to scroll
  287. //
  288. // Output:
  289. // BOOL
  290. //
  291. // Notes:
  292. //
  293. BOOL COleControl::OcxScrollRect
  294. (
  295. LPCRECT prcBounds,
  296. LPCRECT prcClip,
  297. int dx,
  298. int dy
  299. )
  300. {
  301. // if we're windowless, the site provides this functionality, otherwise
  302. // APIs do the job
  303. //
  304. if (m_pInPlaceSiteWndless)
  305. return m_pInPlaceSiteWndless->ScrollRect(dx, dy, prcBounds, prcClip) == S_OK;
  306. else {
  307. if (m_fInPlaceActive)
  308. ScrollWindowEx(m_hwnd, dx, dy, prcBounds, prcClip, NULL, NULL, SW_INVALIDATE);
  309. else
  310. return FALSE;
  311. }
  312. return TRUE;
  313. }