home *** CD-ROM | disk | FTP | other *** search
- // AdderDlg.cpp : implementation file
- //
-
- #include "stdafx.h"
- #include "listbox.h"
- #include "AdderDlg.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- BOOL g_bEdsort;
-
- /////////////////////////////////////////////////////////////////////////////
- // CAdderDlg dialog
-
-
- CAdderDlg::CAdderDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CAdderDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CAdderDlg)
- //}}AFX_DATA_INIT
-
- //ASSERT(m_pParent != NULL);
-
- m_pParent = pParent;
- m_nID = CAdderDlg::IDD;
-
- }
-
-
- void CAdderDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CAdderDlg)
- DDX_Control(pDX, IDC_CHECK1, m_Check);
- //}}AFX_DATA_MAP
- }
-
-
- BEGIN_MESSAGE_MAP(CAdderDlg, CDialog)
- //{{AFX_MSG_MAP(CAdderDlg)
- ON_BN_CLICKED(IDC_CHECK1, OnCheck1)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
-
- BOOL CAdderDlg::Create()
- {
- return CDialog::Create(m_nID, m_pParent);
-
- } // Create
-
-
- void CAdderDlg::OnCancel()
- {
- CloseDialog();
-
- } // OnCancel
-
-
- void CAdderDlg::OnOK()
- {
- int selcnt,cnt, i,j;
- UINT chk;
- CListBox* pList;
-
- selcnt = Getselcount(); // number of selected items
-
- // get pointer to ListBox window
- if (SingleSelection)
- {
- g_pList = (CListBox*) (m_pParent->GetDlgItem(IDC_LIST2));
- }
- else
- {
- pList = (CListBox*) (m_pParent->GetDlgItem(IDC_LIST1));
- }
-
- CEdit* pEdit = (CEdit*) GetDlgItem(IDC_EDIT1);
- CString str;
-
- pEdit->GetWindowText(str);
-
- if (!str.IsEmpty()) // do not insert NULL strings
- {
- chk = m_Check.GetState() && 3; // is checkbox checked ?
-
- if ( (selcnt == 1) && (chk) )
- {
-
- // ok, we should insert the new item at the current position
- cnt = Getcount(); // number of items in listbox
-
- i=0;
- while (Getsel(i+1)==0)
- {
- i++;
- }
-
- j=i;
-
- // variable 'j' now contains the selected item. Add the item on this position now !
- pList->InsertString(j, str);
- }
- else
- {
- pList->AddString(str); // add item to the list and sort the list
- }
-
- } // not empty string
-
- CloseDialog();
-
- } // OnOK
-
-
- void CAdderDlg::CloseDialog()
- {
- ((ListboxDlg*)m_pParent)->AdderBoxDone();
- DestroyWindow();
-
- } // CloseDialog
-
-
- BOOL CAdderDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- // enable the "No sorting" checkbox if neccessary
- if (!g_bEdsort)
- {
- m_Check.ModifyStyle(WS_DISABLED, 0, 0);
- }
-
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
-
- } // OnInitDialog
-
-
- void CAdderDlg::PostNcDestroy()
- {
- delete this;
-
- } // PostNcDestroy
-
-
- void CAdderDlg::OnCheck1()
- {
- CEdit* pEdit = (CEdit*) GetDlgItem(IDC_EDIT1);
-
- pEdit->SetFocus(); // returns the focus to the Edit window
-
- } // OnCheck1
-
-