home *** CD-ROM | disk | FTP | other *** search
- // phnview.cpp : implementation file
- //
-
- #include "stdafx.h"
- #include "phn.h"
-
- //////////////////////
- // MY CODE STARTS HERE
- //////////////////////
-
- #include "phone.h"
- #include "phndoc.h"
-
- ////////////////////
- // MY CODE ENDS HERE
- ////////////////////
-
-
-
- #include "phnview.h"
-
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CPhnView
-
- IMPLEMENT_DYNCREATE(CPhnView, CFormView)
-
- CPhnView::CPhnView()
- : CFormView(CPhnView::IDD)
- {
- //{{AFX_DATA_INIT(CPhnView)
- m_Name = "";
- m_Phone = "";
- //}}AFX_DATA_INIT
- }
-
- CPhnView::~CPhnView()
- {
- }
-
- void CPhnView::DoDataExchange(CDataExchange* pDX)
- {
- CFormView::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CPhnView)
- DDX_Text(pDX, IDC_NAME, m_Name);
- DDX_Text(pDX, IDC_PHONE, m_Phone);
- //}}AFX_DATA_MAP
- }
-
-
- BEGIN_MESSAGE_MAP(CPhnView, CFormView)
- //{{AFX_MSG_MAP(CPhnView)
- ON_EN_CHANGE(IDC_NAME, OnChangeName)
- ON_EN_CHANGE(IDC_PHONE, OnChangePhone)
- ON_BN_CLICKED(IDC_PREVIOUS_BUTTON, OnPreviousButton)
- ON_BN_CLICKED(IDC_NEXT_BUTTON, OnNextButton)
- ON_BN_CLICKED(IDC_ADD_BUTTON, OnAddButton)
- ON_BN_CLICKED(IDC_DELETE_BUTTON, OnDeleteButton)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CPhnView message handlers
-
-
- //////////////////////
- // MY CODE STARTS HERE
- //////////////////////
-
- void CPhnView::OnInitialUpdate()
- {
-
- // Get a pointer to the document.
- CPhnDoc* pDoc = (CPhnDoc*) GetDocument();
-
- // Get the address of m_PhoneList of the document class.
- m_pList = &(pDoc->m_PhoneList);
-
- // Get head position.
- m_position = m_pList->GetHeadPosition();
-
-
- // Update m_Name and m_Phone with values from the list.
- CPhone* pPhone = (CPhone*)m_pList->GetAt(m_position);
- m_Name = pPhone->m_Name;
- m_Phone = pPhone->m_Phone;
-
- // Update the screen with the new values of the variables.
- UpdateData(FALSE);
-
- // Place the cursor inside the IDC_NAME edit box.
- ((CDialog*) this)->GotoDlgCtrl(GetDlgItem(IDC_NAME));
-
- }
-
- ////////////////////
- // MY CODE ENDS HERE
- ////////////////////
-
-
-
- void CPhnView::OnChangeName()
- {
- // TODO: Add your control notification handler code here
-
-
- //////////////////////
- // MY CODE STARTS HERE
- //////////////////////
-
- // Update controls variables with screen contents.
- UpdateData(TRUE);
-
- // Get a pointer to the document.
- CPhnDoc* pDoc = (CPhnDoc*) GetDocument();
-
- // Update the document.
- CPhone* pPhone = (CPhone*)m_pList->GetAt(m_position);
- pPhone->m_Name = m_Name;
-
- // Set the Modified flag to TRUE.
- pDoc->SetModifiedFlag();
-
- ////////////////////
- // MY CODE ENDS HERE
- ////////////////////
-
- }
-
- void CPhnView::OnChangePhone()
- {
- // TODO: Add your control notification handler code here
-
-
- //////////////////////
- // MY CODE STARTS HERE
- //////////////////////
-
- // Update controls variables with screen contents.
- UpdateData(TRUE);
-
- // Get a pointer to the document.
- CPhnDoc* pDoc = (CPhnDoc*) GetDocument();
-
- // Update the document.
- CPhone* pPhone = (CPhone*)m_pList->GetAt(m_position);
- pPhone->m_Phone = m_Phone;
-
- // Set the Modified flag to TRUE.
- pDoc->SetModifiedFlag();
-
- ////////////////////
- // MY CODE ENDS HERE
- ////////////////////
-
-
- }
-
- void CPhnView::OnPreviousButton()
- {
- // TODO: Add your control notification handler code here
-
- //////////////////////
- // MY CODE STARTS HERE
- //////////////////////
-
- // Declare a Temporary POSITION variable.
- POSITION temp_pos;
-
- // Update temp_pos with the current position of the list.
- temp_pos = m_position;
-
- // Update temp_pos with the previous position.
- m_pList->GetPrev(temp_pos);
-
- if (temp_pos == NULL)
- {
- // No previous element.
- MessageBox("Bottom of file encountered!",
- "Phone for Windows");
- }
- else
- {
- // Update m_position, m_Name, and m_Phone.
- m_position = temp_pos;
- CPhone* pPhone = (CPhone*)m_pList->GetAt(m_position);
- m_Name = pPhone->m_Name;
- m_Phone = pPhone->m_Phone;
- UpdateData (FALSE);
- }
-
- // Place the cursor inside the IDC_NAME edit box.
- ((CDialog*) this)->GotoDlgCtrl(GetDlgItem(IDC_NAME));
-
- ////////////////////
- // MY CODE ENDS HERE
- ////////////////////
-
- }
-
- void CPhnView::OnNextButton()
- {
- // TODO: Add your control notification handler code here
-
- //////////////////////
- // MY CODE STARTS HERE
- //////////////////////
-
- // Declare a temporary POSITION variable.
- POSITION temp_pos;
-
- // Update temp_pos with the current position of the list.
- temp_pos = m_position;
-
- // Update temp_pos with the next position.
- m_pList->GetNext(temp_pos);
-
- if (temp_pos == NULL)
- {
- // No next element.
- MessageBox("End of file encountered!",
- "Phone for Windows");
- }
- else
- {
- // Update m_position, m_Name, and m_Phone.
- m_position = temp_pos;
- CPhone* pPhone = (CPhone*)m_pList->GetAt(m_position);
- m_Name = pPhone->m_Name;
- m_Phone = pPhone->m_Phone;
- UpdateData (FALSE);
- }
-
- // Place the cursor inside the IDC_NAME edit box.
- ((CDialog*) this)->GotoDlgCtrl(GetDlgItem(IDC_NAME));
-
- ////////////////////
- // MY CODE ENDS HERE
- ////////////////////
-
-
- }
-
- void CPhnView::OnAddButton()
- {
- // TODO: Add your control notification handler code here
-
- //////////////////////
- // MY CODE STARTS HERE
- //////////////////////
-
- // Update m_Name, m_Phone and the screen with blanks.
- m_Name = "";
- m_Phone = "";
- UpdateData (FALSE);
-
- // Create a new object of class CPhone.
- CPhone* pPhone = new CPhone();
- pPhone->m_Name = m_Name;
- pPhone->m_Phone = m_Phone;
-
- // Add the new object to the tail of the list, and
- // update m_position with the new position.
- m_position = m_pList->AddTail(pPhone);
-
- // Get a pointer to the document.
- CPhnDoc* pDoc = (CPhnDoc*) GetDocument();
-
- // Set the Modified flag to TRUE.
- pDoc->SetModifiedFlag();
-
- // Place the cursor inside the IDC_NAME edit box.
- ((CDialog*) this)->GotoDlgCtrl(GetDlgItem(IDC_NAME));
-
- ////////////////////
- // MY CODE ENDS HERE
- ////////////////////
-
-
- }
-
- void CPhnView::OnDeleteButton()
- {
- // TODO: Add your control notification handler code here
-
- ///////////////////////
- // MY CODE STARTS HERE
- //////////////////////
-
- // Save the old pointer for deletion.
- CObject* pOld;
- pOld = m_pList->GetAt( m_position );
-
- // Remove the element from the list.
- m_pList->RemoveAt( m_position );
-
- // Delete the object from memory.
- delete pOld;
-
- // If the list is now completely empty, add a blank item.
- if ( m_pList->IsEmpty() )
- OnAddButton();
-
- // Get a pointer to the document.
- CPhnDoc* pDoc = (CPhnDoc*) GetDocument();
-
- // Set the Modified flag to TRUE.
- pDoc->SetModifiedFlag();
-
- // Display the first item of the list.
- OnInitialUpdate();
-
- ////////////////////
- // MY CODE ENDS HERE
- ////////////////////
-
- }
-