home *** CD-ROM | disk | FTP | other *** search
/ Total C++ 2 / TOTALCTWO.iso / borland / cmnctrl.pak / TREECPG.CPP < prev    next >
C/C++ Source or Header  |  1997-05-06  |  6KB  |  170 lines

  1. // TreeCtrlPage.cpp : implementation file
  2. //
  3.  
  4. // This is a part of the Microsoft Foundation Classes C++ library.
  5. // Copyright (C) 1992-1995 Microsoft Corporation
  6. // All rights reserved.
  7. //
  8. // This source code is only intended as a supplement to the
  9. // Microsoft Foundation Classes Reference and related
  10. // electronic documentation provided with the library.
  11. // See these sources for detailed information regarding the
  12. // Microsoft Foundation Classes product.
  13.  
  14. #include "stdafx.h"
  15. #include "ctrldemo.h"
  16. #include "treecpg.h"
  17. #include "mtreectl.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. // CTreeCtrlPage property page
  27.  
  28. IMPLEMENT_DYNCREATE(CTreeCtrlPage, CPropertyPage)
  29.  
  30. CTreeCtrlPage::CTreeCtrlPage() : CPropertyPage(CTreeCtrlPage::IDD)
  31. {
  32.     //{{AFX_DATA_INIT(CTreeCtrlPage)
  33.     m_bDisableDragDrop = FALSE;
  34.     m_bHasButtons = FALSE;
  35.     m_bHasLines = FALSE;
  36.     m_bLinesAtRoot = FALSE;
  37.     m_bEditLabels = FALSE;
  38.     m_bShowSelAlways = FALSE;
  39.     m_cstrStatus = _T("");
  40.     //}}AFX_DATA_INIT
  41. }
  42.  
  43. CTreeCtrlPage::~CTreeCtrlPage()
  44. {
  45. }
  46.  
  47. void CTreeCtrlPage::DoDataExchange(CDataExchange* pDX)
  48. {
  49.     CPropertyPage::DoDataExchange(pDX);
  50.     //{{AFX_DATA_MAP(CTreeCtrlPage)
  51.     DDX_Control(pDX, IDC_TREESTATUS, m_notifshowcase);
  52.     DDX_Control(pDX, IDC_TREEVIEW1, m_mytreectrl);
  53.     DDX_Check(pDX, IDC_TVDISABLEDDRAGDROP, m_bDisableDragDrop);
  54.     DDX_Check(pDX, IDC_TVHASBUTTONS, m_bHasButtons);
  55.     DDX_Check(pDX, IDC_TVHASLINES, m_bHasLines);
  56.     DDX_Check(pDX, IDC_TVLINESATROOT, m_bLinesAtRoot);
  57.     DDX_Check(pDX, IDC_TVEDITLABELS, m_bEditLabels);
  58.     DDX_Check(pDX, IDC_TVSHOWSELALWAYS, m_bShowSelAlways);
  59.     DDX_Text(pDX, IDC_TREESTATUS, m_cstrStatus);
  60.     //}}AFX_DATA_MAP
  61. }
  62.  
  63.  
  64. BEGIN_MESSAGE_MAP(CTreeCtrlPage, CPropertyPage)
  65.     //{{AFX_MSG_MAP(CTreeCtrlPage)
  66.     ON_BN_CLICKED(IDC_TVEDITLABELS, OnEditLabels)
  67.     ON_BN_CLICKED(IDC_TVHASBUTTONS, OnHasButtons)
  68.     ON_BN_CLICKED(IDC_TVHASLINES, OnHasLines)
  69.     ON_BN_CLICKED(IDC_TVLINESATROOT, OnLinesAtRoot)
  70.     ON_BN_CLICKED(IDC_TVDISABLEDDRAGDROP, OnDisabledDragDrop)
  71.     ON_BN_CLICKED(IDC_TVSHOWSELALWAYS, OnShowSelAlways)
  72.     ON_NOTIFY(TVN_BEGINLABELEDIT, IDC_TREEVIEW1, ShowNotification)
  73.     ON_NOTIFY(TVN_SELCHANGING, IDC_TREEVIEW1, ShowNotification)
  74.     ON_NOTIFY(TVN_SELCHANGED, IDC_TREEVIEW1, ShowNotification)
  75.     ON_NOTIFY(TVN_GETDISPINFO, IDC_TREEVIEW1, ShowNotification)
  76.     ON_NOTIFY(TVN_SETDISPINFO, IDC_TREEVIEW1, ShowNotification)
  77.     ON_NOTIFY(TVN_ITEMEXPANDING, IDC_TREEVIEW1, ShowNotification)
  78.     ON_NOTIFY(TVN_ITEMEXPANDED, IDC_TREEVIEW1, ShowNotification)
  79.     ON_NOTIFY(TVN_BEGINDRAG, IDC_TREEVIEW1, ShowNotification)
  80.     ON_NOTIFY(TVN_KEYDOWN, IDC_TREEVIEW1, ShowNotification)
  81.     ON_NOTIFY(TVN_SELCHANGED, IDC_TREEVIEW1, ShowNotification)
  82.     ON_NOTIFY(TVN_SELCHANGING, IDC_TREEVIEW1, ShowNotification)
  83.     ON_NOTIFY(TVN_ITEMEXPANDING, IDC_TREEVIEW1, ShowNotification)
  84.     ON_NOTIFY(TVN_ITEMEXPANDED, IDC_TREEVIEW1, ShowNotification)
  85.     ON_NOTIFY(TVN_DELETEITEM, IDC_TREEVIEW1, ShowNotification)
  86.     //}}AFX_MSG_MAP
  87. END_MESSAGE_MAP()
  88.  
  89. /////////////////////////////////////////////////////////////////////////////
  90. // CTreeCtrlPage message handlers
  91. BOOL CTreeCtrlPage::OnInitDialog()
  92. {
  93.     CImageList            *pimagelist;
  94.     CBitmap                bitmap;
  95.     CCtrldemoApp        *pApp;
  96.     int                    iItem;
  97.     UINT                nID;
  98.     TV_INSERTSTRUCT        tvstruct;
  99.     TCHAR                rgszItems[][18] = {_T("Dogs"), _T("German Shepherd"), _T("Dalmatian"), _T("Great Dane"),
  100.                                 _T("Birds"), _T("Hummingbird"), _T("Pigeon"), _T("Eagle"),
  101.                                 _T("Fish"), _T("Snapper"), _T("Sole"), _T("Salmon")};
  102.  
  103.     pApp = (CCtrldemoApp *)AfxGetApp();
  104.     CPropertyPage::OnInitDialog();  // let the base class do the default work
  105.     pimagelist = new CImageList();
  106.     pimagelist->Create(32, 16, TRUE/*bMask*/, 6, 4);
  107.  
  108.     for (nID = IDB_BMTREEFIRST; nID <= IDB_BMTREELAST; nID++)  // load bitmaps for dog, bird and fish
  109.     {
  110.         bitmap.LoadBitmap(nID);
  111.         pimagelist->Add(&bitmap, (COLORREF)0xFFFFFF);
  112.         bitmap.DeleteObject();
  113.     }
  114.  
  115.     m_mytreectrl.SetImageList(pimagelist, TVSIL_NORMAL);
  116.     for (iItem = 0; iItem < CELEMS(rgszItems); iItem ++)
  117.     {
  118.         tvstruct.hParent = (iItem % 4 == 0)? NULL : m_rghItem[iItem / 4 * 4];
  119.         tvstruct.hInsertAfter = TVI_SORT;
  120.         tvstruct.item.iImage = iItem / 4 * 2;
  121.         tvstruct.item.iSelectedImage = tvstruct.item.iImage + 1;
  122.         tvstruct.item.pszText = rgszItems[iItem];
  123.         tvstruct.item.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_TEXT;
  124.         m_rghItem[iItem] = m_mytreectrl.InsertItem(&tvstruct);
  125.     }
  126.  
  127.     return FALSE;
  128. }
  129.  
  130. void CTreeCtrlPage::OnEditLabels()
  131. {
  132.     UpdateData(TRUE/*bSaveAndValidate*/);  // get information from the dialog
  133.     m_mytreectrl.SetNewStyle(TVS_EDITLABELS, m_bEditLabels);
  134. }
  135.  
  136. void CTreeCtrlPage::OnHasButtons()
  137. {
  138.     UpdateData(TRUE);
  139.     m_mytreectrl.SetNewStyle(TVS_HASBUTTONS, m_bHasButtons);
  140. }
  141.  
  142. void CTreeCtrlPage::OnHasLines()
  143. {
  144.     UpdateData(TRUE);
  145.     m_mytreectrl.SetNewStyle(TVS_HASLINES, m_bHasLines);
  146. }
  147.  
  148. void CTreeCtrlPage::OnLinesAtRoot()
  149. {
  150.     UpdateData(TRUE);
  151.     m_mytreectrl.SetNewStyle(TVS_LINESATROOT, m_bLinesAtRoot);
  152. }
  153.  
  154. void CTreeCtrlPage::OnDisabledDragDrop()
  155. {
  156.     UpdateData(TRUE);
  157.     m_mytreectrl.SetNewStyle(TVS_DISABLEDRAGDROP, m_bDisableDragDrop);
  158. }
  159.  
  160. void CTreeCtrlPage::OnShowSelAlways()
  161. {
  162.     UpdateData(TRUE);
  163.     m_mytreectrl.SetNewStyle(TVS_SHOWSELALWAYS, m_bShowSelAlways);
  164. }
  165.  
  166. void CTreeCtrlPage::ShowNotification(LPNMHDR pnmhdr, LRESULT *pResult)
  167. {
  168.     ((CNotifyShowCase *)GetDlgItem(IDC_TREESTATUS))->ShowNotification(pnmhdr->code);
  169. }
  170.