EntityListDlg.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. ===========================================================================
  3. Copyright (C) 1999-2005 Id Software, Inc.
  4. This file is part of Quake III Arena source code.
  5. Quake III Arena source code is free software; you can redistribute it
  6. and/or modify it under the terms of the GNU General Public License as
  7. published by the Free Software Foundation; either version 2 of the License,
  8. or (at your option) any later version.
  9. Quake III Arena source code is distributed in the hope that it will be
  10. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with Foobar; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. ===========================================================================
  17. */
  18. // EntityListDlg.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "Radiant.h"
  22. #include "EntityListDlg.h"
  23. #ifdef _DEBUG
  24. #define new DEBUG_NEW
  25. #undef THIS_FILE
  26. static char THIS_FILE[] = __FILE__;
  27. #endif
  28. /////////////////////////////////////////////////////////////////////////////
  29. // CEntityListDlg dialog
  30. CEntityListDlg::CEntityListDlg(CWnd* pParent /*=NULL*/)
  31. : CDialog(CEntityListDlg::IDD, pParent)
  32. {
  33. //{{AFX_DATA_INIT(CEntityListDlg)
  34. //}}AFX_DATA_INIT
  35. }
  36. void CEntityListDlg::DoDataExchange(CDataExchange* pDX)
  37. {
  38. CDialog::DoDataExchange(pDX);
  39. //{{AFX_DATA_MAP(CEntityListDlg)
  40. DDX_Control(pDX, IDC_LIST_ENTITY, m_lstEntity);
  41. DDX_Control(pDX, IDC_TREE_ENTITY, m_treeEntity);
  42. //}}AFX_DATA_MAP
  43. }
  44. BEGIN_MESSAGE_MAP(CEntityListDlg, CDialog)
  45. //{{AFX_MSG_MAP(CEntityListDlg)
  46. ON_BN_CLICKED(IDSELECT, OnSelect)
  47. ON_NOTIFY(TVN_SELCHANGED, IDC_TREE_ENTITY, OnSelchangedTreeEntity)
  48. ON_NOTIFY(NM_DBLCLK, IDC_TREE_ENTITY, OnDblclkTreeEntity)
  49. //}}AFX_MSG_MAP
  50. END_MESSAGE_MAP()
  51. /////////////////////////////////////////////////////////////////////////////
  52. // CEntityListDlg message handlers
  53. void CEntityListDlg::OnSelect()
  54. {
  55. HTREEITEM hItem = m_treeEntity.GetSelectedItem();
  56. if (hItem)
  57. {
  58. entity_t* pEntity = reinterpret_cast<entity_t*>(m_treeEntity.GetItemData(hItem));
  59. if (pEntity)
  60. {
  61. Select_Deselect();
  62. Select_Brush (pEntity->brushes.onext);
  63. }
  64. }
  65. Sys_UpdateWindows(W_ALL);
  66. }
  67. BOOL CEntityListDlg::OnInitDialog()
  68. {
  69. CDialog::OnInitDialog();
  70. CMapStringToPtr mapEntity;
  71. HTREEITEM hParent = m_treeEntity.InsertItem(world_entity->eclass->name);
  72. HTREEITEM hChild = m_treeEntity.InsertItem(world_entity->eclass->name, hParent);
  73. m_treeEntity.SetItemData(hChild, reinterpret_cast<DWORD>(world_entity));
  74. for (entity_t* pEntity=entities.next ; pEntity != &entities ; pEntity=pEntity->next)
  75. {
  76. hParent = NULL;
  77. if (mapEntity.Lookup(pEntity->eclass->name, reinterpret_cast<void*&>(hParent)) == FALSE)
  78. {
  79. hParent = m_treeEntity.InsertItem(pEntity->eclass->name);
  80. mapEntity.SetAt(pEntity->eclass->name, reinterpret_cast<void*>(hParent));
  81. }
  82. hChild = m_treeEntity.InsertItem(pEntity->eclass->name, hParent);
  83. m_treeEntity.SetItemData(hChild, reinterpret_cast<DWORD>(pEntity));
  84. }
  85. CRect rct;
  86. m_lstEntity.GetClientRect(rct);
  87. m_lstEntity.InsertColumn(0, "Key", LVCFMT_LEFT, rct.Width() / 2);
  88. m_lstEntity.InsertColumn(1, "Value", LVCFMT_LEFT, rct.Width() / 2);
  89. m_lstEntity.DeleteColumn(2);
  90. UpdateData(FALSE);
  91. return TRUE; // return TRUE unless you set the focus to a control
  92. // EXCEPTION: OCX Property Pages should return FALSE
  93. }
  94. void CEntityListDlg::OnSelchangedTreeEntity(NMHDR* pNMHDR, LRESULT* pResult)
  95. {
  96. NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
  97. HTREEITEM hItem = m_treeEntity.GetSelectedItem();
  98. m_lstEntity.DeleteAllItems();
  99. if (hItem)
  100. {
  101. CString strList;
  102. entity_t* pEntity = reinterpret_cast<entity_t*>(m_treeEntity.GetItemData(hItem));
  103. if (pEntity)
  104. {
  105. for (epair_t* pEpair = pEntity->epairs ; pEpair ; pEpair = pEpair->next)
  106. {
  107. if (strlen(pEpair->key) > 8)
  108. strList.Format("%s\t%s", pEpair->key, pEpair->value);
  109. else
  110. strList.Format("%s\t\t%s", pEpair->key, pEpair->value);
  111. int nParent = m_lstEntity.InsertItem(0, pEpair->key);
  112. m_lstEntity.SetItem(nParent, 1, LVIF_TEXT, pEpair->value, 0, 0, 0, reinterpret_cast<DWORD>(pEntity));
  113. }
  114. }
  115. }
  116. *pResult = 0;
  117. }
  118. void CEntityListDlg::OnDblclkListInfo()
  119. {
  120. // TODO: Add your control notification handler code here
  121. }
  122. void CEntityListDlg::OnDblclkTreeEntity(NMHDR* pNMHDR, LRESULT* pResult)
  123. {
  124. OnSelect();
  125. *pResult = 0;
  126. }