Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

221 lines
5.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. // vkeyeditView.cpp : implementation of the CVkeyeditView class
  9. //
  10. #include "stdafx.h"
  11. #include "vkeyedit.h"
  12. #include "vkeyeditDoc.h"
  13. #include "vkeyeditView.h"
  14. #include <COMMCTRL.H>
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CVkeyeditView
  22. IMPLEMENT_DYNCREATE(CVkeyeditView, CTreeView)
  23. BEGIN_MESSAGE_MAP(CVkeyeditView, CTreeView)
  24. //{{AFX_MSG_MAP(CVkeyeditView)
  25. ON_NOTIFY_REFLECT(TVN_SELCHANGED, OnSelchanged)
  26. //}}AFX_MSG_MAP
  27. // Standard printing commands
  28. ON_COMMAND(ID_FILE_PRINT, CTreeView::OnFilePrint)
  29. ON_COMMAND(ID_FILE_PRINT_DIRECT, CTreeView::OnFilePrint)
  30. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CTreeView::OnFilePrintPreview)
  31. END_MESSAGE_MAP()
  32. /////////////////////////////////////////////////////////////////////////////
  33. // CVkeyeditView construction/destruction
  34. CVkeyeditView::CVkeyeditView()
  35. {
  36. // TODO: add construction code here
  37. }
  38. CVkeyeditView::~CVkeyeditView()
  39. {
  40. }
  41. BOOL CVkeyeditView::PreCreateWindow(CREATESTRUCT& cs)
  42. {
  43. // TODO: Modify the Window class or styles here by modifying
  44. // the CREATESTRUCT cs
  45. cs.style |= TVS_HASLINES|TVS_EDITLABELS|TVS_HASBUTTONS|TVS_LINESATROOT;
  46. return CTreeView::PreCreateWindow(cs);
  47. }
  48. /////////////////////////////////////////////////////////////////////////////
  49. // CVkeyeditView drawing
  50. void CVkeyeditView::OnDraw(CDC* pDC)
  51. {
  52. CVkeyeditDoc* pDoc = GetDocument();
  53. ASSERT_VALID(pDoc);
  54. // TODO: add draw code for native data here
  55. }
  56. //DEL void CVkeyeditView::OnInitialUpdate()
  57. //DEL {
  58. //DEL CTreeView::OnInitialUpdate();
  59. //DEL
  60. //DEL CTreeCtrl &tree = GetTreeCtrl();
  61. //DEL
  62. //DEL // tree.InsertItem( _T("Test") );
  63. //DEL
  64. //DEL
  65. //DEL // TODO: You may populate your TreeView with items by directly accessing
  66. //DEL // its tree control through a call to GetTreeCtrl().
  67. //DEL }
  68. /////////////////////////////////////////////////////////////////////////////
  69. // CVkeyeditView printing
  70. BOOL CVkeyeditView::OnPreparePrinting(CPrintInfo* pInfo)
  71. {
  72. // default preparation
  73. return DoPreparePrinting(pInfo);
  74. }
  75. void CVkeyeditView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  76. {
  77. // TODO: add extra initialization before printing
  78. }
  79. void CVkeyeditView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  80. {
  81. // TODO: add cleanup after printing
  82. }
  83. /////////////////////////////////////////////////////////////////////////////
  84. // CVkeyeditView diagnostics
  85. #ifdef _DEBUG
  86. void CVkeyeditView::AssertValid() const
  87. {
  88. CTreeView::AssertValid();
  89. }
  90. void CVkeyeditView::Dump(CDumpContext& dc) const
  91. {
  92. CTreeView::Dump(dc);
  93. }
  94. CVkeyeditDoc* CVkeyeditView::GetDocument() // non-debug version is inline
  95. {
  96. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CVkeyeditDoc)));
  97. return (CVkeyeditDoc*)m_pDocument;
  98. }
  99. #endif //_DEBUG
  100. /////////////////////////////////////////////////////////////////////////////
  101. // CVkeyeditView message handlers
  102. void CVkeyeditView::CalcWindowRect(LPRECT lpClientRect, UINT nAdjustType)
  103. {
  104. // TODO: Add your specialized code here and/or call the base class
  105. CTreeView::CalcWindowRect(lpClientRect, nAdjustType);
  106. }
  107. // Sort the item in reverse alphabetical order.
  108. static int CALLBACK MyCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
  109. {
  110. return strcmp( ((KeyValues*)(lParam1))->GetName(), ((KeyValues*)(lParam2))->GetName() );
  111. }
  112. void CVkeyeditView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
  113. {
  114. // TODO: Add your specialized code here and/or call the base class
  115. CTreeCtrl &theTree = GetTreeCtrl();
  116. KeyValues *kv = (KeyValues *)pHint;
  117. if ( !kv || lHint != 1 )
  118. return;
  119. theTree.DeleteAllItems();
  120. while ( kv )
  121. {
  122. InsertKeyValues( kv, TVI_ROOT );
  123. kv = kv->GetNextKey();
  124. }
  125. // The pointer to my tree control.
  126. TVSORTCB tvs;
  127. // Sort the tree control's items using my
  128. // callback procedure.
  129. tvs.hParent = TVI_ROOT;
  130. tvs.lpfnCompare = MyCompareProc;
  131. tvs.lParam = (LPARAM) &theTree;
  132. theTree.SortChildrenCB(&tvs);
  133. }
  134. bool CVkeyeditView::InsertKeyValues(KeyValues *kv, HTREEITEM hParent)
  135. {
  136. CTreeCtrl &theTree = GetTreeCtrl();
  137. TVINSERTSTRUCT tvInsert;
  138. tvInsert.hParent = hParent;
  139. tvInsert.hInsertAfter = TVI_LAST;
  140. tvInsert.item.mask = TVIF_TEXT;
  141. tvInsert.item.lParam = (LPARAM)kv;
  142. tvInsert.item.pszText = (char*)kv->GetName();
  143. HTREEITEM hItem = theTree.InsertItem( &tvInsert );
  144. theTree.SetItemData(hItem, (DWORD) kv );
  145. KeyValues * subkey = kv->GetFirstTrueSubKey();
  146. while ( subkey )
  147. {
  148. InsertKeyValues( subkey, hItem );
  149. subkey = subkey->GetNextKey();
  150. }
  151. // The pointer to my tree control.
  152. TVSORTCB tvs;
  153. // Sort the tree control's items using my
  154. // callback procedure.
  155. tvs.hParent = hParent;
  156. tvs.lpfnCompare = MyCompareProc;
  157. tvs.lParam = (LPARAM) &theTree;
  158. theTree.SortChildrenCB(&tvs);
  159. return true;
  160. }
  161. void CVkeyeditView::OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult)
  162. {
  163. NM_TREEVIEW *pNMTreeView = (NM_TREEVIEW*) pNMHDR;
  164. CTreeCtrl &tTree = this->GetTreeCtrl ();
  165. CTreeCtrl &theTree = this->GetTreeCtrl ();
  166. HTREEITEM hItem = pNMTreeView->itemNew.hItem;
  167. GetDocument()->UpdateAllViews ( this, 2, (CObject*)theTree.GetItemData(hItem) );
  168. *pResult = 0;
  169. }