]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/tools/radiant/EntityListDlg.cpp
hello world
[icculus/iodoom3.git] / neo / tools / radiant / EntityListDlg.cpp
1 /*
2 ===========================================================================
3
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company. 
6
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).  
8
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code.  If not, see <http://www.gnu.org/licenses/>.
21
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code.  If not, please request a copy in writing from id Software at the address below.
23
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25
26 ===========================================================================
27 */
28
29 #include "../../idlib/precompiled.h"
30 #pragma hdrstop
31
32 #include "qe3.h"
33 #include "Radiant.h"
34 #include "EntityListDlg.h"
35
36 #ifdef _DEBUG
37 #define new DEBUG_NEW
38 #undef THIS_FILE
39 static char THIS_FILE[] = __FILE__;
40 #endif
41
42 CEntityListDlg g_EntityListDlg;
43 /////////////////////////////////////////////////////////////////////////////
44 // CEntityListDlg dialog
45
46 void CEntityListDlg::ShowDialog() {
47         if (g_EntityListDlg.GetSafeHwnd() == NULL) {
48                 g_EntityListDlg.Create(IDD_DLG_ENTITYLIST);
49         } 
50         g_EntityListDlg.UpdateList();
51         g_EntityListDlg.ShowWindow(SW_SHOW);
52
53 }
54
55 CEntityListDlg::CEntityListDlg(CWnd* pParent /*=NULL*/)
56         : CDialog(CEntityListDlg::IDD, pParent)
57 {
58         //{{AFX_DATA_INIT(CEntityListDlg)
59         //}}AFX_DATA_INIT
60 }
61
62
63 void CEntityListDlg::DoDataExchange(CDataExchange* pDX)
64 {
65         CDialog::DoDataExchange(pDX);
66         //{{AFX_DATA_MAP(CEntityListDlg)
67         DDX_Control(pDX, IDC_LIST_ENTITY, m_lstEntity);
68         //}}AFX_DATA_MAP
69         DDX_Control(pDX, IDC_LIST_ENTITIES, listEntities);
70 }
71
72 BEGIN_MESSAGE_MAP(CEntityListDlg, CDialog)
73         //{{AFX_MSG_MAP(CEntityListDlg)
74         ON_BN_CLICKED(IDC_SELECT, OnSelect)
75         ON_WM_CLOSE()
76         ON_WM_DESTROY()
77         //}}AFX_MSG_MAP
78         ON_LBN_SELCHANGE(IDC_LIST_ENTITIES, OnLbnSelchangeListEntities)
79         ON_LBN_DBLCLK(IDC_LIST_ENTITIES, OnLbnDblclkListEntities)
80 END_MESSAGE_MAP()
81
82 /////////////////////////////////////////////////////////////////////////////
83 // CEntityListDlg message handlers
84
85 void CEntityListDlg::OnSelect() 
86 {
87         int index = listEntities.GetCurSel();
88         if (index != LB_ERR) {
89                 entity_t *ent = reinterpret_cast<entity_t*>(listEntities.GetItemDataPtr(index));
90                 if (ent) {
91                         Select_Deselect();
92                         Select_Brush (ent->brushes.onext);
93                 }
94         }
95   Sys_UpdateWindows(W_ALL);
96 }
97
98 void CEntityListDlg::UpdateList() {
99         listEntities.ResetContent();
100         for (entity_t* pEntity=entities.next ; pEntity != &entities ; pEntity=pEntity->next) {
101                 int index = listEntities.AddString(pEntity->epairs.GetString("name"));
102                 if (index != LB_ERR) {
103                         listEntities.SetItemDataPtr(index, (void*)pEntity);
104                 }
105         }
106 }
107
108 void CEntityListDlg::OnSysCommand(UINT nID,  LPARAM lParam) {
109         if (nID == SC_CLOSE) {
110                 DestroyWindow();
111         }
112 }
113
114 void CEntityListDlg::OnCancel() {
115         DestroyWindow();
116 }
117
118 BOOL CEntityListDlg::OnInitDialog() 
119 {
120         CDialog::OnInitDialog();
121         
122         UpdateList();
123
124         CRect rct;
125         m_lstEntity.GetClientRect(rct);
126         m_lstEntity.InsertColumn(0, "Key", LVCFMT_LEFT, rct.Width() / 2);
127         m_lstEntity.InsertColumn(1, "Value", LVCFMT_LEFT, rct.Width() / 2);
128         m_lstEntity.DeleteColumn(2);
129         UpdateData(FALSE);
130         
131         return TRUE;  // return TRUE unless you set the focus to a control
132                       // EXCEPTION: OCX Property Pages should return FALSE
133 }
134
135 void CEntityListDlg::OnClose() {
136         DestroyWindow();
137 }
138
139 void CEntityListDlg::OnLbnSelchangeListEntities()
140 {
141         int index = listEntities.GetCurSel();
142         if (index != LB_ERR) {
143                 m_lstEntity.DeleteAllItems();
144                 entity_t* pEntity = reinterpret_cast<entity_t*>(listEntities.GetItemDataPtr(index));
145             if (pEntity) {
146                         int count = pEntity->epairs.GetNumKeyVals();
147                         for (int i = 0; i < count; i++) {
148                                 int nParent = m_lstEntity.InsertItem(0, pEntity->epairs.GetKeyVal(i)->GetKey());
149                                 m_lstEntity.SetItem(nParent, 1, LVIF_TEXT, pEntity->epairs.GetKeyVal(i)->GetValue(), 0, 0, 0, reinterpret_cast<DWORD>(pEntity));
150                         }
151                 }
152         }
153 }
154
155 void CEntityListDlg::OnLbnDblclkListEntities()
156 {
157   OnSelect();
158 }