home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 5 / MasteringVisualBasic5.iso / protview / demowinx / data.1 / TREEDLG.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-29  |  3.9 KB  |  143 lines

  1. // TreeDialog.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "allctls.h"
  6. #include "TreeDlg.h"
  7. #include "branch.h"
  8. #include "ptreedef.h"
  9.  
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CTreeDialog dialog
  18.  
  19.  
  20. CTreeDialog::CTreeDialog(CWnd* pParent /*=NULL*/)
  21.     : CDialog(CTreeDialog::IDD, pParent)
  22. {
  23.     //{{AFX_DATA_INIT(CTreeDialog)
  24.     //}}AFX_DATA_INIT
  25. }
  26.  
  27.  
  28. void CTreeDialog::DoDataExchange(CDataExchange* pDX)
  29. {
  30.     CDialog::DoDataExchange(pDX);
  31.     //{{AFX_DATA_MAP(CTreeDialog)
  32.     DDX_Control(pDX, IDC_TREEVIEW1, m_treeview);
  33.     //}}AFX_DATA_MAP
  34. }
  35.  
  36.  
  37. BEGIN_MESSAGE_MAP(CTreeDialog, CDialog)
  38.     //{{AFX_MSG_MAP(CTreeDialog)
  39.     //}}AFX_MSG_MAP
  40. END_MESSAGE_MAP()
  41.  
  42. /////////////////////////////////////////////////////////////////////////////
  43. // CTreeDialog message handlers
  44.  
  45. BOOL CTreeDialog::OnInitDialog()
  46. {
  47.     CDialog::OnInitDialog();
  48.  
  49.     // TODO: Add extra initialization here
  50.     CBranch parent;
  51.  
  52.     //root = m_treeview.GetBranches();
  53.  
  54.     parent = m_treeview.GetBranches().Add(pvtPositionInOrder, 0, "Parent Node");
  55.     parent.Select(pvtNode);
  56.     parent.Add(pvtPositionInOrder, 0, "Child Node 1 ");
  57.     parent.Add(pvtPositionInOrder, 0, "Child Node 2");
  58.     parent.Add(pvtPositionInOrder, 0, "Child Node 3");
  59.     parent = m_treeview.GetBranches().Add(pvtPositionInOrder, 0, "Parent Node");
  60.     parent.Add(pvtPositionInOrder, 0, "Child Node 4");
  61.  
  62.     return TRUE;  // return TRUE unless you set the focus to a control
  63.                   // EXCEPTION: OCX Property Pages should return FALSE
  64. }
  65.  
  66. BEGIN_EVENTSINK_MAP(CTreeDialog, CDialog)
  67.     //{{AFX_EVENTSINK_MAP(CTreeDialog)
  68.     ON_EVENT(CTreeDialog, IDC_MULTIBTNCTRL1, 3 /* Up */, OnUpMultibtnctrl1, VTS_NONE)
  69.     ON_EVENT(CTreeDialog, IDC_MULTIBTNCTRL1, 4 /* Down */, OnDownMultibtnctrl1, VTS_NONE)
  70.     ON_EVENT(CTreeDialog, IDC_MULTIBTNCTRL1, 1 /* Left */, OnLeftMultibtnctrl1, VTS_NONE)
  71.     ON_EVENT(CTreeDialog, IDC_MULTIBTNCTRL1, 2 /* Right */, OnRightMultibtnctrl1, VTS_NONE)
  72.     ON_EVENT(CTreeDialog, IDC_BUTTON1, -600 /* Click */, OnClickButton1, VTS_NONE)
  73.     ON_EVENT(CTreeDialog, IDC_TREEVIEW1, -602 /* KeyDown */, OnKeyDownTreeview1, VTS_PI2 VTS_I2)
  74.     //}}AFX_EVENTSINK_MAP
  75. END_EVENTSINK_MAP()
  76.  
  77. void CTreeDialog::OnUpMultibtnctrl1()
  78. {
  79.     // TODO: Add your control notification handler code here
  80.     CBranch Selected;
  81.  
  82.     Selected = m_treeview.GetBranches().Get(pvtGetNextSelected,0);
  83.     Selected = Selected.Get(pvtGetPrevVisible,0);
  84.     if (!Selected.IsValid())
  85.         Selected = m_treeview.GetBranches().Get(pvtGetChild, 0);
  86.  
  87.     Selected.Select(pvtNode);
  88. }
  89.  
  90. void CTreeDialog::OnDownMultibtnctrl1()
  91. {
  92.     // TODO: Add your control notification handler code here
  93.     CBranch Selected;
  94.  
  95.     // gets the currently selected item
  96.     Selected = m_treeview.GetBranches().Get(pvtGetNextSelected,0);
  97.  
  98.     if (Selected.IsValid())
  99.     {
  100.         // gets the next visible item
  101.         Selected = Selected.Get(pvtGetNextVisible,0);
  102.  
  103.         // selects the item
  104.         Selected.Select(pvtNode);
  105.     }
  106. }
  107.  
  108. void CTreeDialog::OnLeftMultibtnctrl1()
  109. {
  110.     // TODO: Add your control notification handler code here
  111.     CBranch Selected;
  112.  
  113.     Selected = m_treeview.GetBranches().Get(pvtGetNextSelected, 0);
  114.     Selected.Clear();
  115.     Selected.Remove();
  116. }
  117.  
  118. void CTreeDialog::OnRightMultibtnctrl1()
  119. {
  120.     // TODO: Add your control notification handler code here
  121.     CBranch Selected;
  122.  
  123.     Selected = m_treeview.GetBranches().Get(pvtGetNextSelected, 0);
  124.     if (!Selected.IsValid())
  125.         return;
  126.  
  127.     Selected.Add(pvtPositionInOrder, 0, "Newly inserted Child Node");
  128. }
  129.  
  130. void CTreeDialog::OnClickButton1() 
  131. {
  132.     // TODO: Add your control notification handler code here
  133.     m_treeview.GetBranches().Add(pvtPositionInOrder, 0, "New Parent Node");
  134. }
  135.  
  136. void CTreeDialog::OnKeyDownTreeview1(short FAR* KeyCode, short Shift) 
  137. {
  138.     // TODO: Add your control notification handler code here
  139.     if (*KeyCode == VK_RETURN)
  140.         m_treeview.BeginInPlaceEdit();    
  141.     
  142. }
  143.