home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / Basic / Visual Basic.60 / COMMON / TOOLS / VCM / VCM.MDB / VcmComponentContainer / 14_Cabinet / EDITDLG.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1998-05-18  |  4.3 KB  |  194 lines

  1. // EditDlg.cpp : implementation file
  2. //
  3. // This is a part of the Microsoft Foundation Classes and
  4. // Templates (MFC&T).
  5. // Copyright (C) 1998 Microsoft Corporation
  6. // All rights reserved.
  7. //
  8. // This source code is only intended as a supplement to the
  9. // MFC&T Reference and related electronic documentation provided
  10. // with the library.  See these sources for detailed information
  11. // regarding the MFC&T product.
  12. //
  13.  
  14. #include "stdafx.h"
  15. #include "DBViewer.h"
  16. #include "ctrlext.h"
  17. #include "EditDlg.h"
  18.  
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24.  
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CEditDlg
  27.  
  28. CEditDlg::CEditDlg() : CDialog(CEditDlg::IDD)
  29. {
  30.     m_pListCtrl = NULL;
  31.     m_nItem = 0;
  32.     m_nFields = 0;
  33.     m_nCurSel = 0;
  34. }
  35.  
  36. CEditDlg::CEditDlg(CListCtrlEx* pCtrl, int nItem, int nFields)
  37.     : CDialog(CEditDlg::IDD)
  38. {
  39.     //{{AFX_DATA_INIT(CEditDlg)
  40.     m_strEdit = _T("");
  41.     //}}AFX_DATA_INIT
  42.     m_pListCtrl = pCtrl;
  43.     m_nItem = nItem;
  44.     m_nFields = nFields;
  45.     m_nCurSel = 0;
  46.     m_bMode = FALSE;
  47. }
  48.  
  49. CEditDlg::CEditDlg(CMapStringToString& mapData)
  50.     : CDialog(CEditDlg::IDD)
  51. {
  52.     m_pListCtrl = NULL;
  53.     m_nCurSel = 0;
  54.     m_bMode = TRUE;
  55.  
  56.     POSITION pos = mapData.GetStartPosition();
  57.     while(pos != NULL)
  58.     {
  59.         CString strKey, strValue;
  60.         mapData.GetNextAssoc(pos, strKey, strValue);
  61.         m_mapField.SetAt(strKey, strValue);
  62.     }
  63.  
  64.     m_nFields = m_mapField.GetCount();
  65. }
  66.  
  67. CEditDlg::~CEditDlg()
  68. {
  69.     m_pListCtrl = NULL;
  70.     m_nItem = 0;
  71. }
  72.  
  73.  
  74. BEGIN_MESSAGE_MAP(CEditDlg, CDialog)
  75.     //{{AFX_MSG_MAP(CEditDlg)
  76.     ON_LBN_SELCHANGE(IDC_LIST1, OnFieldChange)
  77.     //}}AFX_MSG_MAP
  78. END_MESSAGE_MAP()
  79.  
  80. /////////////////////////////////////////////////////////////////////////////
  81. // CEditDlg message handlers
  82.  
  83.  
  84. BOOL CEditDlg::OnInitDialog()
  85. {
  86.     LV_COLUMN   lvCol;
  87.     LV_ITEM     lvItem;
  88.     TCHAR       szColName[40];
  89.     TCHAR       szItem[40];
  90.  
  91.     CDialog::OnInitDialog();
  92.  
  93.     // If using procedures, don't get data from list view
  94.     if (m_bMode)
  95.     {
  96.         // We were created with a map
  97.         POSITION pos = m_mapField.GetStartPosition();
  98.         while(pos != NULL)
  99.         {
  100.             CString strKey, strValue;
  101.             m_mapField.GetNextAssoc(pos, strKey, strValue);
  102.             m_ctlListBox.AddString(strKey);
  103.         }
  104.  
  105.         return TRUE;
  106.     }
  107.  
  108.     // Populate List Control and Map
  109.     ASSERT(m_pListCtrl);
  110.     ASSERT(m_nItem != -1);
  111.  
  112.     lvCol.mask          = LVCF_TEXT;
  113.     lvCol.pszText       = &szColName[0];
  114.     lvCol.cchTextMax    = 40;
  115.  
  116.     lvItem.mask         = LVIF_TEXT;
  117.     lvItem.iItem        = m_nItem;
  118.     lvItem.pszText      = &szItem[0];
  119.     lvItem.cchTextMax   = 40;
  120.  
  121.     for (int i=0; i<m_nFields; i++)
  122.     {
  123.         lvItem.iSubItem = i;
  124.  
  125.         m_pListCtrl->GetColumn(i, &lvCol);
  126.         m_pListCtrl->GetItem(&lvItem);
  127.  
  128.         CString strKey = lvCol.pszText;
  129.         CString strValue = lvItem.pszText;
  130.  
  131. //      if (m_nItem==0)
  132. //          strValue = _T("");
  133.  
  134.         m_mapField.SetAt(strKey, strValue);
  135.         m_ctlListBox.AddString(strKey);
  136.  
  137.         if (i==0)
  138.             m_ctlEdit.SetWindowText(strValue);
  139.     }
  140.  
  141.     m_ctlListBox.SetCurSel(0);
  142.  
  143.     return TRUE;  // return TRUE unless you set the focus to a control
  144.                   // EXCEPTION: OCX Property Pages should return FALSE
  145. }
  146.  
  147. void CEditDlg::DoDataExchange(CDataExchange* pDX)
  148. {
  149.     CDialog::DoDataExchange(pDX);
  150.  
  151.     //{{AFX_DATA_MAP(CEditDlg)
  152.     DDX_Control(pDX, IDC_EDIT2, m_ctlEdit);
  153.     DDX_Control(pDX, IDC_LIST1, m_ctlListBox);
  154.     DDX_Text(pDX, IDC_EDIT2, m_strEdit);
  155.     DDV_MaxChars(pDX, m_strEdit, 39);
  156.     //}}AFX_DATA_MAP
  157. }
  158.  
  159. void CEditDlg::OnFieldChange()
  160. {
  161.     // This gets called whenever the user changes the selection
  162.     // Place the data in the map.
  163.     CString strField, strValue, strValueOld;
  164.  
  165.     // Update the contents of the previous selection, necessary.
  166.     m_ctlListBox.GetText(m_nCurSel, strField);
  167.     m_ctlEdit.GetWindowText(strValue);
  168.     m_mapField.Lookup(strField, strValueOld);
  169.  
  170.     if (strValueOld != strValue)
  171.         m_mapField.SetAt(strField, strValue);
  172.  
  173.     // Load in the contents of the new key.
  174.     m_nCurSel = m_ctlListBox.GetCurSel();
  175.  
  176.     if (m_nCurSel == -1)
  177.         m_nCurSel = 0;
  178.  
  179.     m_ctlListBox.GetText(m_nCurSel, strField);
  180.     m_mapField.Lookup(strField, strValue);
  181.     m_ctlEdit.SetWindowText(strValue);
  182. }
  183.  
  184. CString CEditDlg::GetValue(CString strKey)
  185. {
  186.     return m_mapField[strKey];
  187. }
  188.  
  189. void CEditDlg::OnOK()
  190. {
  191.     OnFieldChange();
  192.     CDialog::OnOK();
  193. }
  194.