winocc.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10. #include "stdafx.h"
  11. #include "occimpl.h"
  12. #ifdef AFX_CORE1_SEG
  13. #pragma code_seg(AFX_CORE1_SEG)
  14. #endif
  15. #ifdef _DEBUG
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19. #define new DEBUG_NEW
  20. #ifndef _AFX_NO_OCC_SUPPORT
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CWnd overridable for ambient properties
  23. BOOL CWnd::OnAmbientProperty(COleControlSite* pSite, DISPID dispid,
  24. VARIANT* pvar)
  25. {
  26. ASSERT(m_pCtrlCont != NULL);
  27. return m_pCtrlCont->GetAmbientProp(pSite, dispid, pvar);
  28. }
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CWnd access to underlying OLE control interface
  31. LPUNKNOWN CWnd::GetControlUnknown()
  32. {
  33. if (m_pCtrlSite == NULL)
  34. return NULL;
  35. return m_pCtrlSite->m_pObject;
  36. }
  37. /////////////////////////////////////////////////////////////////////////////
  38. // CWnd functions with special cases for OLE Control containment
  39. void CWnd::CheckDlgButton(int nIDButton, UINT nCheck)
  40. {
  41. ASSERT(::IsWindow(m_hWnd));
  42. if (m_pCtrlCont == NULL)
  43. ::CheckDlgButton(m_hWnd, nIDButton, nCheck);
  44. else
  45. m_pCtrlCont->CheckDlgButton(nIDButton, nCheck);
  46. }
  47. void CWnd::CheckRadioButton(int nIDFirstButton, int nIDLastButton,
  48. int nIDCheckButton)
  49. {
  50. ASSERT(::IsWindow(m_hWnd));
  51. if (m_pCtrlCont == NULL)
  52. ::CheckRadioButton(m_hWnd, nIDFirstButton, nIDLastButton,
  53. nIDCheckButton);
  54. else
  55. m_pCtrlCont->CheckRadioButton(nIDFirstButton, nIDLastButton,
  56. nIDCheckButton);
  57. }
  58. CWnd* CWnd::GetDlgItem(int nID) const
  59. {
  60. ASSERT(::IsWindow(m_hWnd));
  61. if (m_pCtrlCont == NULL)
  62. return CWnd::FromHandle(::GetDlgItem(m_hWnd, nID));
  63. else
  64. return m_pCtrlCont->GetDlgItem(nID);
  65. }
  66. void CWnd::GetDlgItem(int nID, HWND* phWnd) const
  67. {
  68. ASSERT(::IsWindow(m_hWnd));
  69. ASSERT(phWnd != NULL);
  70. if (m_pCtrlCont == NULL)
  71. *phWnd = ::GetDlgItem(m_hWnd, nID);
  72. else
  73. m_pCtrlCont->GetDlgItem(nID, phWnd);
  74. }
  75. UINT CWnd::GetDlgItemInt(int nID, BOOL* lpTrans, BOOL bSigned) const
  76. {
  77. ASSERT(::IsWindow(m_hWnd));
  78. if (m_pCtrlCont == NULL)
  79. return ::GetDlgItemInt(m_hWnd, nID, lpTrans, bSigned);
  80. else
  81. return m_pCtrlCont->GetDlgItemInt(nID, lpTrans, bSigned);
  82. }
  83. int CWnd::GetDlgItemText(int nID, LPTSTR lpStr, int nMaxCount) const
  84. {
  85. ASSERT(::IsWindow(m_hWnd));
  86. if (m_pCtrlCont == NULL)
  87. return ::GetDlgItemText(m_hWnd, nID, lpStr, nMaxCount);
  88. else
  89. return m_pCtrlCont->GetDlgItemText(nID, lpStr, nMaxCount);
  90. }
  91. LRESULT CWnd::SendDlgItemMessage(int nID, UINT message, WPARAM wParam,
  92. LPARAM lParam)
  93. {
  94. ASSERT(::IsWindow(m_hWnd));
  95. if (m_pCtrlCont == NULL)
  96. return ::SendDlgItemMessage(m_hWnd, nID, message, wParam, lParam);
  97. else
  98. return m_pCtrlCont->SendDlgItemMessage(nID, message, wParam, lParam);
  99. }
  100. void CWnd::SetDlgItemInt(int nID, UINT nValue, BOOL bSigned)
  101. {
  102. ASSERT(::IsWindow(m_hWnd));
  103. if (m_pCtrlCont == NULL)
  104. ::SetDlgItemInt(m_hWnd, nID, nValue, bSigned);
  105. else
  106. m_pCtrlCont->SetDlgItemInt(nID, nValue, bSigned);
  107. }
  108. void CWnd::SetDlgItemText(int nID, LPCTSTR lpszString)
  109. {
  110. ASSERT(::IsWindow(m_hWnd));
  111. if (m_pCtrlCont == NULL)
  112. ::SetDlgItemText(m_hWnd, nID, lpszString);
  113. else
  114. m_pCtrlCont->SetDlgItemText(nID, lpszString);
  115. }
  116. UINT CWnd::IsDlgButtonChecked(int nIDButton) const
  117. {
  118. ASSERT(::IsWindow(m_hWnd));
  119. if (m_pCtrlCont == NULL)
  120. return ::IsDlgButtonChecked(m_hWnd, nIDButton);
  121. else
  122. return m_pCtrlCont->IsDlgButtonChecked(nIDButton);
  123. }
  124. int CWnd::ScrollWindowEx(int dx, int dy, LPCRECT lpRectScroll,
  125. LPCRECT lpRectClip, CRgn* prgnUpdate, LPRECT lpRectUpdate,
  126. UINT flags)
  127. {
  128. ASSERT(::IsWindow(m_hWnd));
  129. int iReturn = ::ScrollWindowEx(m_hWnd, dx, dy, lpRectScroll, lpRectClip,
  130. (HRGN)prgnUpdate->GetSafeHandle(), lpRectUpdate, flags);
  131. if ((m_pCtrlCont == NULL) || !(flags & SW_SCROLLCHILDREN))
  132. return iReturn;
  133. // the following code is for OLE control containers only
  134. m_pCtrlCont->ScrollChildren(dx, dy);
  135. return iReturn;
  136. }
  137. BOOL CWnd::IsDialogMessage(LPMSG lpMsg)
  138. {
  139. ASSERT(::IsWindow(m_hWnd));
  140. if (m_nFlags & WF_OLECTLCONTAINER)
  141. return afxOccManager->IsDialogMessage(this, lpMsg);
  142. else
  143. return ::IsDialogMessage(m_hWnd, lpMsg);
  144. }
  145. /////////////////////////////////////////////////////////////////////////////
  146. // CWnd functions with special cases for OLE Control wrappers
  147. DWORD CWnd::GetStyle() const
  148. {
  149. ASSERT(::IsWindow(m_hWnd));
  150. if (m_pCtrlSite == NULL)
  151. return (DWORD)GetWindowLong(m_hWnd, GWL_STYLE);
  152. else
  153. return m_pCtrlSite->GetStyle();
  154. }
  155. DWORD CWnd::GetExStyle() const
  156. {
  157. ASSERT(::IsWindow(m_hWnd));
  158. if (m_pCtrlSite == NULL)
  159. return (DWORD)GetWindowLong(m_hWnd, GWL_EXSTYLE);
  160. else
  161. return m_pCtrlSite->GetExStyle();
  162. }
  163. BOOL CWnd::ModifyStyle(DWORD dwRemove, DWORD dwAdd, UINT nFlags)
  164. {
  165. ASSERT(::IsWindow(m_hWnd));
  166. if (m_pCtrlSite == NULL)
  167. return ModifyStyle(m_hWnd, dwRemove, dwAdd, nFlags);
  168. else
  169. return m_pCtrlSite->ModifyStyle(dwRemove, dwAdd, nFlags);
  170. }
  171. BOOL CWnd::ModifyStyleEx(DWORD dwRemove, DWORD dwAdd, UINT nFlags)
  172. {
  173. ASSERT(::IsWindow(m_hWnd));
  174. if (m_pCtrlSite == NULL)
  175. return ModifyStyleEx(m_hWnd, dwRemove, dwAdd, nFlags);
  176. else
  177. return m_pCtrlSite->ModifyStyleEx(dwRemove, dwAdd, nFlags);
  178. }
  179. void CWnd::SetWindowText(LPCTSTR lpszString)
  180. {
  181. ASSERT(::IsWindow(m_hWnd));
  182. if (m_pCtrlSite == NULL)
  183. ::SetWindowText(m_hWnd, lpszString);
  184. else
  185. m_pCtrlSite->SetWindowText(lpszString);
  186. }
  187. int CWnd::GetWindowText(LPTSTR lpszString, int nMaxCount) const
  188. {
  189. ASSERT(::IsWindow(m_hWnd));
  190. if (m_pCtrlSite == NULL)
  191. return ::GetWindowText(m_hWnd, lpszString, nMaxCount);
  192. else
  193. return m_pCtrlSite->GetWindowText(lpszString, nMaxCount);
  194. }
  195. int CWnd::GetWindowTextLength() const
  196. {
  197. ASSERT(::IsWindow(m_hWnd));
  198. if (m_pCtrlSite == NULL)
  199. return ::GetWindowTextLength(m_hWnd);
  200. else
  201. return m_pCtrlSite->GetWindowTextLength();
  202. }
  203. int CWnd::GetDlgCtrlID() const
  204. {
  205. ASSERT(::IsWindow(m_hWnd));
  206. if (m_pCtrlSite == NULL)
  207. return ::GetDlgCtrlID(m_hWnd);
  208. else
  209. return m_pCtrlSite->GetDlgCtrlID();
  210. }
  211. int CWnd::SetDlgCtrlID(int nID)
  212. {
  213. ASSERT(::IsWindow(m_hWnd));
  214. if (m_pCtrlSite == NULL)
  215. return (int)::SetWindowLong(m_hWnd, GWL_ID, nID);
  216. else
  217. return m_pCtrlSite->SetDlgCtrlID(nID);
  218. }
  219. void CWnd::MoveWindow(int x, int y, int nWidth, int nHeight, BOOL bRepaint)
  220. {
  221. ASSERT(::IsWindow(m_hWnd));
  222. if (m_pCtrlSite == NULL)
  223. ::MoveWindow(m_hWnd, x, y, nWidth, nHeight, bRepaint);
  224. else
  225. m_pCtrlSite->MoveWindow(x, y, nWidth, nHeight, bRepaint);
  226. }
  227. BOOL CWnd::SetWindowPos(const CWnd* pWndInsertAfter, int x, int y, int cx,
  228. int cy, UINT nFlags)
  229. {
  230. ASSERT(::IsWindow(m_hWnd));
  231. if (m_pCtrlSite == NULL)
  232. return ::SetWindowPos(m_hWnd, pWndInsertAfter->GetSafeHwnd(),
  233. x, y, cx, cy, nFlags);
  234. else
  235. return m_pCtrlSite->SetWindowPos(pWndInsertAfter, x, y, cx, cy, nFlags);
  236. }
  237. BOOL CWnd::ShowWindow(int nCmdShow)
  238. {
  239. ASSERT(::IsWindow(m_hWnd));
  240. if (m_pCtrlSite == NULL)
  241. return ::ShowWindow(m_hWnd, nCmdShow);
  242. else
  243. return m_pCtrlSite->ShowWindow(nCmdShow);
  244. }
  245. BOOL CWnd::IsWindowEnabled() const
  246. {
  247. ASSERT(::IsWindow(m_hWnd));
  248. if (m_pCtrlSite == NULL)
  249. return ::IsWindowEnabled(m_hWnd);
  250. else
  251. return m_pCtrlSite->IsWindowEnabled();
  252. }
  253. BOOL CWnd::EnableWindow(BOOL bEnable)
  254. {
  255. ASSERT(::IsWindow(m_hWnd));
  256. if (m_pCtrlSite == NULL)
  257. return ::EnableWindow(m_hWnd, bEnable);
  258. else
  259. return m_pCtrlSite->EnableWindow(bEnable);
  260. }
  261. CWnd* CWnd::SetFocus()
  262. {
  263. ASSERT(::IsWindow(m_hWnd));
  264. if (m_pCtrlSite == NULL)
  265. return CWnd::FromHandle(::SetFocus(m_hWnd));
  266. else
  267. return m_pCtrlSite->SetFocus();
  268. }
  269. /////////////////////////////////////////////////////////////////////////////
  270. // CWnd invoke helpers for OLE Control wrappers
  271. void AFX_CDECL CWnd::InvokeHelper(DISPID dwDispID, WORD wFlags, VARTYPE vtRet,
  272. void* pvRet, const BYTE* pbParamInfo, ...)
  273. {
  274. ASSERT(m_pCtrlSite != NULL); // not an OLE control (not yet, at least)
  275. if (m_pCtrlSite == NULL)
  276. return;
  277. va_list argList;
  278. va_start(argList, pbParamInfo);
  279. m_pCtrlSite->InvokeHelperV(dwDispID, wFlags, vtRet, pvRet, pbParamInfo,
  280. argList);
  281. va_end(argList);
  282. }
  283. void CWnd::GetProperty(DISPID dwDispID, VARTYPE vtProp,
  284. void* pvProp) const
  285. {
  286. ASSERT(m_pCtrlSite != NULL); // not an OLE control (not yet, at least)
  287. if (m_pCtrlSite == NULL)
  288. return;
  289. const_cast<CWnd*>(this)->InvokeHelper(dwDispID, DISPATCH_PROPERTYGET,
  290. vtProp, pvProp, NULL);
  291. }
  292. void AFX_CDECL CWnd::SetProperty(DISPID dwDispID, VARTYPE vtProp, ...)
  293. {
  294. ASSERT(m_pCtrlSite != NULL); // not an OLE control (not yet, at least)
  295. if (m_pCtrlSite == NULL)
  296. return;
  297. va_list argList; // really only one arg, but...
  298. va_start(argList, vtProp);
  299. m_pCtrlSite->SetPropertyV(dwDispID, vtProp, argList);
  300. va_end(argList);
  301. }
  302. IUnknown* CWnd::GetDSCCursor()
  303. {
  304. ASSERT(m_pCtrlSite != NULL); // not an OLE control (not yet, at least)
  305. if (m_pCtrlSite == NULL)
  306. return NULL;
  307. m_pCtrlSite->EnableDSC();
  308. IUnknown* pCursor = m_pCtrlSite->m_pDataSourceControl->GetCursor();
  309. ASSERT(pCursor != NULL); // data source control has no cursor
  310. return pCursor;
  311. }
  312. void CWnd::BindDefaultProperty(DISPID dwDispID, VARTYPE vtProp, LPCTSTR szFieldName, CWnd* pDSCWnd)
  313. {
  314. ASSERT(m_pCtrlSite != NULL); // not an OLE control (not yet, at least)
  315. m_pCtrlSite->BindDefaultProperty(dwDispID, vtProp, szFieldName, pDSCWnd);
  316. }
  317. void CWnd::BindProperty(DISPID dwDispId, CWnd* pWndDSC)
  318. {
  319. ASSERT(m_pCtrlSite != NULL); // not an OLE control (not yet, at least)
  320. m_pCtrlSite->BindProperty(dwDispId, pWndDSC);
  321. }
  322. /////////////////////////////////////////////////////////////////////////////
  323. // CWnd implementation helpers
  324. void CWnd::AttachControlSite(CHandleMap* pMap)
  325. {
  326. if (this != NULL && m_pCtrlSite == NULL)
  327. {
  328. // Determine if parent is an OLE control container
  329. CWnd* pWndParent = (CWnd*)pMap->LookupPermanent(::GetParent(m_hWnd));
  330. if (pWndParent != NULL && pWndParent->m_pCtrlCont != NULL)
  331. {
  332. // delegate through helper in COleControlSite
  333. pWndParent->m_pCtrlCont->AttachControlSite(this);
  334. }
  335. }
  336. }
  337. void CWnd::AttachControlSite(CWnd* pWndParent)
  338. {
  339. ASSERT(this != NULL);
  340. ASSERT(pWndParent != NULL);
  341. if (m_pCtrlSite == NULL && pWndParent->m_pCtrlCont != NULL)
  342. {
  343. // delegate through helper in COleControlSite
  344. pWndParent->m_pCtrlCont->AttachControlSite(this);
  345. }
  346. }
  347. void COleControlContainer::AttachControlSite(CWnd* pWnd)
  348. {
  349. ASSERT(this != NULL);
  350. ASSERT(pWnd != NULL);
  351. // If a matching control site exists, it's an OLE control
  352. COleControlSite* pSite = (COleControlSite*)m_siteMap.GetValueAt(pWnd->m_hWnd);
  353. if (pSite != NULL)
  354. {
  355. // detach any existing CWnd from this site (last one wins)
  356. CWnd* pOldCtrl = pSite->m_pWndCtrl;
  357. if (pOldCtrl != NULL && pOldCtrl->m_pCtrlSite == pSite)
  358. pOldCtrl->m_pCtrlSite = NULL;
  359. // now wire the site and CWnd together
  360. pWnd->m_pCtrlSite = pSite;
  361. pSite->m_pWndCtrl = pWnd;
  362. }
  363. }
  364. #endif // !_AFX_NO_OCC_SUPPORT