home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c480 / 19.ddi / MFC / SRC / VBDDX.CP_ / VBDDX.CP
Encoding:
Text File  |  1993-02-08  |  5.4 KB  |  187 lines

  1. // This is a part of the Microsoft Classes C++ Class Library.
  2. // Copyright (C) 1992 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 Microsoft
  7. // QuickHelp and/or WinHelp 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.  
  13. #ifdef AFX_VBX_SEG
  14. #pragma code_seg(AFX_VBX_SEG)
  15. #endif
  16.  
  17. #ifdef _DEBUG
  18. #undef THIS_FILE
  19. static char BASED_CODE THIS_FILE[] = __FILE__;
  20. #endif
  21.  
  22. /////////////////////////////////////////////////////////////////////////////
  23. // VB specific DDX procs
  24.  
  25. // VB controls are special
  26. void AFXAPI DDX_VBControl(CDataExchange* pDX, int nIDC, CVBControl*& rpControl)
  27. {
  28.     if (rpControl == NULL)
  29.     {
  30.         ASSERT(!pDX->m_bSaveAndValidate);
  31.         rpControl = pDX->PrepareVBCtrl(nIDC);
  32.     }
  33. }
  34.  
  35. CVBControl* CDataExchange::PrepareVBCtrl(int nIDC)
  36. {
  37.     ASSERT(nIDC != 0);
  38.     ASSERT(nIDC != -1); // not allowed
  39.     HWND hWndCtrl = ::GetDlgItem(m_pDlgWnd->m_hWnd, nIDC);
  40.     if (hWndCtrl == NULL)
  41.     {
  42.         TRACE1("Error: no data exchange control with ID 0x%04X\n", nIDC);
  43.         ASSERT(FALSE);
  44.         AfxThrowNotSupportedException();
  45.     }
  46.     m_hWndLastControl = hWndCtrl;
  47.     m_bEditLastControl = FALSE; // not an edit item by default
  48.     ASSERT(hWndCtrl != NULL);       // never return NULL handle
  49.     CWnd* pWnd = CWnd::FromHandle(hWndCtrl);
  50.     ASSERT(pWnd->IsKindOf(RUNTIME_CLASS(CVBControl)));
  51.     return (CVBControl*)pWnd;
  52. }
  53.  
  54. /////////////////////////////////////////////////////////////////////////////
  55. // Simple formatting to text item
  56.  
  57. void AFXAPI DDX_VBText(CDataExchange* pDX, int nIDC, int nPropIndex,
  58.     CString& value)
  59. {
  60.     CVBControl* pControl = pDX->PrepareVBCtrl(nIDC);
  61.     ASSERT(pControl->GetPropType(nPropIndex) == DT_HSZ);
  62.     if (pDX->m_bSaveAndValidate)
  63.         value = pControl->GetStrProperty(nPropIndex);
  64.     else
  65.         pControl->SetStrProperty(nPropIndex, value);
  66. }
  67.  
  68. void AFXAPI DDX_VBTextRO(CDataExchange* pDX, int nIDC, int nPropIndex,
  69.     CString& value)
  70. {
  71.     if (pDX->m_bSaveAndValidate)
  72.     {
  73.         CVBControl* pControl = pDX->PrepareVBCtrl(nIDC);
  74.         ASSERT(pControl->GetPropType(nPropIndex) == DT_HSZ);
  75.         value = pControl->GetStrProperty(nPropIndex);
  76.     }
  77. }
  78.  
  79. /////////////////////////////////////////////////////////////////////////////
  80. // non-text properties
  81.  
  82. void AFXAPI DDX_VBBool(CDataExchange* pDX, int nIDC, int nPropIndex,
  83.     BOOL& value)
  84. {
  85.     CVBControl* pControl = pDX->PrepareVBCtrl(nIDC);
  86.     ASSERT(pControl->GetPropType(nPropIndex) == DT_BOOL);
  87.     if (pDX->m_bSaveAndValidate)
  88.         value = (BOOL)pControl->GetNumProperty(nPropIndex);
  89.     else
  90.         pControl->SetNumProperty(nPropIndex, value);
  91. }
  92.  
  93. void AFXAPI DDX_VBBoolRO(CDataExchange* pDX, int nIDC, int nPropIndex,
  94.     BOOL& value)
  95. {
  96.     if (pDX->m_bSaveAndValidate)
  97.     {
  98.         CVBControl* pControl = pDX->PrepareVBCtrl(nIDC);
  99.         ASSERT(pControl->GetPropType(nPropIndex) == DT_BOOL);
  100.         value = (BOOL)pControl->GetNumProperty(nPropIndex);
  101.     }
  102. }
  103.  
  104. void AFXAPI DDX_VBInt(CDataExchange* pDX, int nIDC, int nPropIndex,
  105.     int& value)
  106. {
  107.     CVBControl* pControl = pDX->PrepareVBCtrl(nIDC);
  108. #ifdef _DEBUG
  109.     UINT nPropType = pControl->GetPropType(nPropIndex);
  110.     ASSERT(nPropType == DT_ENUM || nPropType == DT_SHORT ||
  111.            nPropType == DT_XPOS || nPropType == DT_XSIZE ||
  112.            nPropType == DT_YPOS || nPropType == DT_YSIZE);
  113. #endif
  114.     if (pDX->m_bSaveAndValidate)
  115.         value = (int)pControl->GetNumProperty(nPropIndex);
  116.     else
  117.         pControl->SetNumProperty(nPropIndex, value);
  118. }
  119.  
  120. void AFXAPI DDX_VBIntRO(CDataExchange* pDX, int nIDC, int nPropIndex,
  121.     int& value)
  122. {
  123.     if (pDX->m_bSaveAndValidate)
  124.     {
  125.         CVBControl* pControl = pDX->PrepareVBCtrl(nIDC);
  126. #ifdef _DEBUG
  127.         UINT nPropType = pControl->GetPropType(nPropIndex);
  128.         ASSERT(nPropType == DT_ENUM || nPropType == DT_SHORT ||
  129.                nPropType == DT_XPOS || nPropType == DT_XSIZE ||
  130.                nPropType == DT_YPOS || nPropType == DT_YSIZE);
  131. #endif
  132.         value = (int)pControl->GetNumProperty(nPropIndex);
  133.     }
  134. }
  135.  
  136. void AFXAPI DDX_VBLong(CDataExchange* pDX, int nIDC, int nPropIndex,
  137.     LONG& value)
  138. {
  139.     CVBControl* pControl = pDX->PrepareVBCtrl(nIDC);
  140. #ifdef _DEBUG
  141.     UINT nPropType = pControl->GetPropType(nPropIndex);
  142.     ASSERT(nPropType == DT_LONG);
  143. #endif
  144.     if (pDX->m_bSaveAndValidate)
  145.         value = pControl->GetNumProperty(nPropIndex);
  146.     else
  147.         pControl->SetNumProperty(nPropIndex, value);
  148. }
  149.  
  150. void AFXAPI DDX_VBLongRO(CDataExchange* pDX, int nIDC, int nPropIndex,
  151.     LONG& value)
  152. {
  153.     if (pDX->m_bSaveAndValidate)
  154.     {
  155.         CVBControl* pControl = pDX->PrepareVBCtrl(nIDC);
  156. #ifdef _DEBUG
  157.         UINT nPropType = pControl->GetPropType(nPropIndex);
  158.         ASSERT(nPropType == DT_LONG);
  159. #endif
  160.         value = pControl->GetNumProperty(nPropIndex);
  161.     }
  162. }
  163.  
  164. void AFXAPI DDX_VBColor(CDataExchange* pDX, int nIDC, int nPropIndex,
  165.     COLORREF& value)
  166. {
  167.     CVBControl* pControl = pDX->PrepareVBCtrl(nIDC);
  168.     ASSERT(pControl->GetPropType(nPropIndex) == DT_COLOR);
  169.     if (pDX->m_bSaveAndValidate)
  170.         value = (COLORREF)pControl->GetNumProperty(nPropIndex);
  171.     else
  172.         pControl->SetNumProperty(nPropIndex, (DWORD)value);
  173. }
  174.  
  175. void AFXAPI DDX_VBColorRO(CDataExchange* pDX, int nIDC, int nPropIndex,
  176.     COLORREF& value)
  177. {
  178.     if (pDX->m_bSaveAndValidate)
  179.     {
  180.         CVBControl* pControl = pDX->PrepareVBCtrl(nIDC);
  181.         ASSERT(pControl->GetPropType(nPropIndex) == DT_COLOR);
  182.         value = (COLORREF)pControl->GetNumProperty(nPropIndex);
  183.     }
  184. }
  185.  
  186. /////////////////////////////////////////////////////////////////////////////
  187.