Debian Codegraph @

editor/ObjectListCombo.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 // ObjectListCombo.cpp : implementation file
20 //
21
22 #include "stdafx.h"
23
24 #ifndef NEWEDITOR
25 #include "editor.h"
26 #else
27 #include "neweditor.h"
28 #endif
29
30 #include "ObjectListCombo.h"
31 #include "object.h"
32
33 #ifdef _DEBUG
34 #define new DEBUG_NEW
35 #undef THIS_FILE
36 static char THIS_FILE[] = __FILE__;
37 #endif
38
39 /////////////////////////////////////////////////////////////////////////////
40 // CObjectListCombo
41
42 CObjectListCombo::CObjectListCombo() {}
43
44 CObjectListCombo::~CObjectListCombo() {}
45
46 BEGIN_MESSAGE_MAP(CObjectListCombo, CComboBox)
47 //{{AFX_MSG_MAP(CObjectListCombo)
48 ON_CONTROL_REFLECT(CBN_SETFOCUS, OnSetfocus)
49 //}}AFX_MSG_MAP
50 END_MESSAGE_MAP()
51
52 /////////////////////////////////////////////////////////////////////////////
53 // CObjectListCombo message handlers
54
55 void CObjectListCombo::Init(int type, int selected_handle) {
56 // Save the type
57 m_type = type;
58
59 // Clear the combo box
60 ResetContent();
61
62 // Add the "none" sound
63 AddString("<none>");
64 SetItemData(0, OBJECT_HANDLE_NONE);
65 SetCurSel(0); // default
66
67 // Now add all the sounsd
68 for (int i = 0; i <= Highest_object_index; i++) {
69 if (Objects[i].type == OBJ_NONE) {
70 continue;
71 }
72
73 // Only lists named objects. If we ever need all objects, add a flag.
74 if (Objects[i].name && ((type == OBJ_NONE) || (Objects[i].type == type))) {
75 char str[100];
76 sprintf(str, "%s (%s, %x)", Objects[i].name ? Objects[i].name : "<no name>", Object_type_names[Objects[i].type],
77 Objects[i].handle);
78
79 int index = AddString(str);
80 SetItemData(index, Objects[i].handle);
81 if (Objects[i].handle == selected_handle) {
82 SetCurSel(index);
83 }
84 }
85 }
86 }
87
88 // takes object handle
89 void CObjectListCombo::SetSelected(int selected_handle) {
90 // Now add all the sounsd
91 int count = GetCount();
92 for (int i = 0; i < count; i++) {
93 if (selected_handle == (int)GetItemData(i)) {
94 SetCurSel(i);
95 return;
96 }
97 }
98
99 // Couldn't find selected -- use none
100 SetCurSel(0);
101 }
102
103 int CObjectListCombo::GetSelected() { return (int)GetItemData(GetCurSel()); }
104
105 void CObjectListCombo::OnSetfocus() {
106 // Update list in case the items have changed
107 Init(m_type, GetSelected());
108 }