home *** CD-ROM | disk | FTP | other *** search
/ HTBasic 9.3 / HTBasic 9.3.iso / 93win / data1.cab / DLL_Toolkit / Source / HTBListBox / AdderDlg.cpp next >
Encoding:
C/C++ Source or Header  |  2005-03-02  |  2.9 KB  |  159 lines

  1. // AdderDlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "listbox.h"
  6. #include "AdderDlg.h"
  7.  
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14. BOOL g_bEdsort;
  15.  
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CAdderDlg dialog
  18.  
  19.  
  20. CAdderDlg::CAdderDlg(CWnd* pParent /*=NULL*/)
  21.     : CDialog(CAdderDlg::IDD, pParent)
  22. {
  23.     //{{AFX_DATA_INIT(CAdderDlg)
  24.     //}}AFX_DATA_INIT
  25.  
  26.     //ASSERT(m_pParent != NULL);
  27.  
  28.     m_pParent = pParent;
  29.     m_nID = CAdderDlg::IDD;
  30.  
  31. }
  32.  
  33.  
  34. void CAdderDlg::DoDataExchange(CDataExchange* pDX)
  35. {
  36.     CDialog::DoDataExchange(pDX);
  37.     //{{AFX_DATA_MAP(CAdderDlg)
  38.     DDX_Control(pDX, IDC_CHECK1, m_Check);
  39.     //}}AFX_DATA_MAP
  40. }
  41.  
  42.  
  43. BEGIN_MESSAGE_MAP(CAdderDlg, CDialog)
  44.     //{{AFX_MSG_MAP(CAdderDlg)
  45.     ON_BN_CLICKED(IDC_CHECK1, OnCheck1)
  46.     //}}AFX_MSG_MAP
  47. END_MESSAGE_MAP()
  48.  
  49.  
  50. BOOL CAdderDlg::Create()
  51. {
  52.     return CDialog::Create(m_nID, m_pParent);
  53.  
  54. }    // Create
  55.  
  56.  
  57. void CAdderDlg::OnCancel() 
  58. {
  59.     CloseDialog();
  60.  
  61. }    // OnCancel
  62.  
  63.  
  64. void CAdderDlg::OnOK() 
  65. {
  66.     int selcnt,cnt, i,j;
  67.     UINT chk;
  68.     CListBox* pList;
  69.  
  70.     selcnt = Getselcount();                  // number of selected items
  71.  
  72.     // get pointer to ListBox window
  73.     if (SingleSelection)
  74.     {
  75.         g_pList = (CListBox*) (m_pParent->GetDlgItem(IDC_LIST2));
  76.     }
  77.     else
  78.     {
  79.         pList = (CListBox*) (m_pParent->GetDlgItem(IDC_LIST1));
  80.     }
  81.  
  82.     CEdit* pEdit = (CEdit*) GetDlgItem(IDC_EDIT1);
  83.     CString str;
  84.  
  85.     pEdit->GetWindowText(str);
  86.     
  87.     if (!str.IsEmpty())                       // do not insert NULL strings
  88.     {
  89.         chk = m_Check.GetState() && 3;           // is checkbox checked ?
  90.  
  91.         if ( (selcnt == 1) && (chk) ) 
  92.         {
  93.  
  94.             // ok, we should insert the new item at the current position
  95.             cnt = Getcount();                    // number of items in listbox
  96.  
  97.             i=0;
  98.             while (Getsel(i+1)==0)
  99.             {
  100.                 i++;
  101.             }
  102.  
  103.             j=i;
  104.  
  105.             // variable 'j' now contains the selected item. Add the item on this position now !
  106.             pList->InsertString(j, str);
  107.         }
  108.         else
  109.         {
  110.             pList->AddString(str);               // add item to the list and sort the list
  111.         }
  112.  
  113.     }    // not empty string
  114.  
  115.     CloseDialog();
  116.  
  117. }    // OnOK
  118.  
  119.  
  120. void CAdderDlg::CloseDialog()
  121. {
  122.     ((ListboxDlg*)m_pParent)->AdderBoxDone();
  123.     DestroyWindow();
  124.  
  125. }    // CloseDialog
  126.  
  127.  
  128. BOOL CAdderDlg::OnInitDialog() 
  129. {
  130.     CDialog::OnInitDialog();
  131.     
  132.     // enable the "No sorting" checkbox if neccessary
  133.     if (!g_bEdsort)
  134.     {
  135.         m_Check.ModifyStyle(WS_DISABLED, 0, 0);
  136.     }
  137.  
  138.     return TRUE;  // return TRUE unless you set the focus to a control
  139.                   // EXCEPTION: OCX Property Pages should return FALSE
  140.  
  141. }    // OnInitDialog
  142.  
  143.  
  144. void CAdderDlg::PostNcDestroy() 
  145. {
  146.     delete this;    
  147.  
  148. }    // PostNcDestroy
  149.  
  150.  
  151. void CAdderDlg::OnCheck1() 
  152. {
  153.    CEdit* pEdit = (CEdit*) GetDlgItem(IDC_EDIT1);
  154.  
  155.    pEdit->SetFocus();    // returns the focus to the Edit window
  156.  
  157. }    // OnCheck1
  158.  
  159.