-
Notifications
You must be signed in to change notification settings - Fork 0
/
PropertyComboBox.cpp
367 lines (333 loc) · 11.5 KB
/
PropertyComboBox.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
/* Copyright (c) 2002-2012 Croteam Ltd.
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as published by
the Free Software Foundation
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
// PropertyComboBox.cpp : implementation file
//
#include "StdH.h"
#include "PropertyComboBox.h"
#ifdef _DEBUG
#undef new
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPropertyComboBox
CPropertyComboBox::CPropertyComboBox()
{
}
CPropertyComboBox::~CPropertyComboBox()
{
// delete current property list
FORDELETELIST(CPropertyID, pid_lnNode, m_lhProperties, itDel)
{
delete &itDel.Current();
}
}
void CPropertyComboBox::SetDialogPtr( CPropertyComboBar *pDialog)
{
m_pDialog = pDialog;
DisableCombo();
}
BEGIN_MESSAGE_MAP(CPropertyComboBox, CComboBox)
//{{AFX_MSG_MAP(CPropertyComboBox)
ON_WM_CONTEXTMENU()
ON_CONTROL_REFLECT(CBN_SELCHANGE, OnSelchange)
ON_CONTROL_REFLECT(CBN_DROPDOWN, OnDropdown)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPropertyComboBox message handlers
void CPropertyComboBox::OnContextMenu(CWnd* pWnd, CPoint point)
{
INDEX i=0;
}
void CPropertyComboBox::JoinProperties( CEntity *penEntity, BOOL bIntersect)
{
// if we should add all of this entity's properties (if this is first entity)
if( !bIntersect)
{
// obtain entity class ptr
CDLLEntityClass *pdecDLLClass = penEntity->GetClass()->ec_pdecDLLClass;
// for all classes in hierarchy of this entity
for(;pdecDLLClass!=NULL; pdecDLLClass = pdecDLLClass->dec_pdecBase)
{
// for all properties
for(INDEX iProperty=0; iProperty<pdecDLLClass->dec_ctProperties; iProperty++)
{
CEntityProperty &epProperty = pdecDLLClass->dec_aepProperties[iProperty];
// don't add properties with no name
if( epProperty.ep_strName != CTString("") )
{
CAnimData *pAD = NULL;
// remember anim data
if( epProperty.ep_eptType == CEntityProperty::EPT_ANIMATION)
{
pAD = penEntity->GetAnimData( epProperty.ep_slOffset);
}
// create current CPropertyID
CPropertyID *pPropertyID = new CPropertyID( epProperty.ep_strName,
epProperty.ep_eptType, &epProperty, pAD);
// if we should add all of this entity's properties (if this is first entity)
// and add it into list
m_lhProperties.AddTail( pPropertyID->pid_lnNode);
}
}
}
}
// in case of intersecting properties we should take one of existing properties in list
// and see if investigating entity has property with same descriptive name
// If not, remove it that existing property.
else
{
FORDELETELIST(CPropertyID, pid_lnNode, m_lhProperties, itProp)
{
CTString strCurrentName = itProp->pid_strName;
CEntityProperty::PropertyType eptCurrentType = itProp->pid_eptType;
// mark that property with same name is not found
BOOL bSameFound = FALSE;
// obtain entity class ptr
CDLLEntityClass *pdecDLLClass = penEntity->GetClass()->ec_pdecDLLClass;
// for all classes in hierarchy of this entity
for(; pdecDLLClass!=NULL; pdecDLLClass = pdecDLLClass->dec_pdecBase)
{
// for all properties
for(INDEX iProperty=0; iProperty<pdecDLLClass->dec_ctProperties; iProperty++)
{
CEntityProperty &epProperty = pdecDLLClass->dec_aepProperties[iProperty];
CAnimData *pAD = NULL;
// remember anim data
if( epProperty.ep_eptType == CEntityProperty::EPT_ANIMATION)
{
pAD = penEntity->GetAnimData( epProperty.ep_slOffset);
}
// create current CPropertyID
CPropertyID PropertyID = CPropertyID( epProperty.ep_strName, epProperty.ep_eptType,
&epProperty, pAD);
// is this property same as one we are investigating
if( (strCurrentName == PropertyID.pid_strName) &&
(eptCurrentType == PropertyID.pid_eptType) )
{
// if propperty is enum, enum ptr must also be the same
if( itProp->pid_eptType == CEntityProperty::EPT_ENUM)
{
// only then,
if( itProp->pid_penpProperty->ep_pepetEnumType ==
PropertyID.pid_penpProperty->ep_pepetEnumType)
{
// same property is found
bSameFound = TRUE;
}
else
{
bSameFound = FALSE;
}
goto pcb_OutLoop_JoinProperties;
}
// if propperty is animation, anim data ptr must be the same
else if( itProp->pid_eptType == CEntityProperty::EPT_ANIMATION)
{
if(itProp->pid_padAnimData == PropertyID.pid_padAnimData)
{
// same property is found
bSameFound = TRUE;
}
else
{
bSameFound = FALSE;
}
goto pcb_OutLoop_JoinProperties;
}
else
{
// same property is found
bSameFound = TRUE;
goto pcb_OutLoop_JoinProperties;
}
}
}
}
pcb_OutLoop_JoinProperties:;
// if property with same name is not found
if( !bSameFound)
{
// remove our investigating property from list
itProp->pid_lnNode.Remove();
// and delete it
delete &itProp.Current();
}
}
}
}
BOOL CPropertyComboBox::OnIdle(LONG lCount)
{
// get active document
CWorldEditorDoc* pDoc = theApp.GetActiveDocument();
// if document ptr has changed
// or if document was closed (pDoc == NULL and pLastDoc != NULL)
// or if mode was changed
// or if selection was changed from last OnIdle, refresh properties
if( (m_pLastDoc != pDoc) ||
((pDoc == NULL) && (m_pLastDoc != NULL)) ||
((pDoc != NULL) && (m_iLastMode != pDoc->m_iMode)) ||
((pDoc != NULL) && !pDoc->m_chSelections.IsUpToDate( m_udComboEntries)) )
{
// refresh selected members message
if( (pDoc != NULL))
{
pDoc->SetStatusLineModeInfoMessage();
}
// remove all combo entries
ResetContent();
// if document exists and mode is entities
if( (pDoc != NULL) && (pDoc->m_iMode == ENTITY_MODE) )
{
// delete current property list
FORDELETELIST(CPropertyID, pid_lnNode, m_lhProperties, itDel)
{
delete &itDel.Current();
}
// lock selection's dynamic container
pDoc->m_selEntitySelection.Lock();
// for each of the selected entities
FOREACHINDYNAMICCONTAINER(pDoc->m_selEntitySelection, CEntity, iten)
{
// if this is first entity in dynamic container
if( pDoc->m_selEntitySelection.Pointer(0) == iten)
{
// add all of its properties into joint list but don't intersect with existing ones
JoinProperties( iten, FALSE);
}
else
{
// intersect entity's properties with existing ones
JoinProperties( iten, TRUE);
}
}
// unlock selection's dynamic container
pDoc->m_selEntitySelection.Unlock();
if( pDoc->m_selEntitySelection.Count() != 0)
{
// ----------------- Add spawn flags property
CPropertyID *ppidSpawnFlags = new CPropertyID( "Spawn flags (Alt+Shift+S)",
CEntityProperty::EPT_SPAWNFLAGS, NULL, NULL);
m_lhProperties.AddTail( ppidSpawnFlags->pid_lnNode);
// ----------------- Add parent entity property
CPropertyID *ppidParent = new CPropertyID( "Parent (Alt+Shift+A)",
CEntityProperty::EPT_PARENT, NULL, NULL);
m_lhProperties.AddTail( ppidParent->pid_lnNode);
}
// if there are some intersecting properties
if( !m_lhProperties.IsEmpty())
{
// add intersecting properties of selected entities into combo box
FOREACHINLIST(CPropertyID, pid_lnNode, m_lhProperties, itProp)
{
char achrShortcutKey[ 64] = "";
if( itProp->pid_chrShortcutKey != 0)
{
sprintf( achrShortcutKey, " (%c)", itProp->pid_chrShortcutKey);
}
// add property name and shortcut key
INDEX iAddedAs = AddString( CString(itProp->pid_strName + achrShortcutKey));
// set ptr to property ID object
SetItemData( iAddedAs, (ULONG) &*itProp);
// enable combo
EnableWindow();
}
}
// if there are no properties to choose from
else
{
DisableCombo();
}
}
// if there are no document or application is not in edit entitiy mode
else
{
DisableCombo();
}
// index of property that is selected (trying to keep the same property active)
INDEX iSelectedProperty = 0;
// for all members in combo box
for( INDEX iMembers = 0; iMembers<GetCount(); iMembers++)
{
CPropertyID *ppidPropertyID = (CPropertyID *) GetItemData( iMembers);
// if this is valid property
if( ppidPropertyID != NULL)
{
// if name of this property is same as last selected property name
if( ppidPropertyID->pid_strName == m_strLastPropertyName)
{
// mark this property as selected by default
iSelectedProperty = iMembers;
break;
}
}
}
// select entity 0 by default
SetCurSel( iSelectedProperty);
// mark possible document change
m_pLastDoc = pDoc;
// set new mode
if( pDoc != NULL)
{
m_iLastMode = pDoc->m_iMode;
}
m_pDialog->ArrangeControls();
// if edit color property is active
if( m_pDialog->m_EditColorCtrl.IsWindowVisible())
{
// invalidate it so it will be refreshed properly
m_pDialog->m_EditColorCtrl.Invalidate( FALSE);
}
m_udComboEntries.MarkUpdated();
}
return TRUE;
}
void CPropertyComboBox::OnSelchange()
{
SelectProperty();
}
void CPropertyComboBox::SelectProperty(void)
{
CPropertyID *ppidPropertyID = (CPropertyID *) GetItemData( GetCurSel());
// must be valid property
ASSERT( ppidPropertyID != NULL);
// remember name of this property as last selected property name
m_strLastPropertyName = ppidPropertyID->pid_strName;
// show/hide appropriate editing propterty controls
m_pDialog->ArrangeControls();
}
void CPropertyComboBox::DisableCombo()
{
// remove all combo entries
ResetContent();
// set default message
INDEX iAddedAs = AddString( _T("None Available"));
// set invalid ptr
SetItemData( iAddedAs, NULL);
// disable combo
EnableWindow( FALSE);
}
void CPropertyComboBox::OnDropdown()
{
INDEX ctItems = GetCount();
if( ctItems == CB_ERR) return;
CRect rectCombo;
GetWindowRect( &rectCombo);
PIX pixScreenHeight = ::GetSystemMetrics(SM_CYSCREEN);
PIX pixMaxHeight = pixScreenHeight - rectCombo.top;
m_pDialog->ScreenToClient( &rectCombo);
PIX pixNewHeight = GetItemHeight(0)*(ctItems+2);
rectCombo.bottom = rectCombo.top + ClampUp( pixNewHeight, pixMaxHeight);
MoveWindow( rectCombo);
}