home *** CD-ROM | disk | FTP | other *** search
/ Supercompiler 1997 / SUPERCOMPILER97.iso / MS_VC.50 / VC / MFC / SRC / WINOCC.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-08  |  11.2 KB  |  454 lines

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