Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
propedit.cpp
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(tm)
3** Copyright 2025 Electronic Arts Inc.
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// propedit.cpp : implementation file
20//
21
22#include "stdafx.h"
23#include "worldbuilder.h"
24#include "..\include\propedit.h"
25
27// PropEdit dialog
28
29#define NO_RESTRICT_KEYS
30
31PropEdit::PropEdit(AsciiString* key, Dict::DataType* type, AsciiString* value, Bool valueOnly, CWnd *parent)
32 : CDialog(PropEdit::IDD, parent), m_key(key), m_type(type), m_value(value), m_updating(0), m_valueOnly(valueOnly)
33{
34 //{{AFX_DATA_INIT(PropEdit)
35 // NOTE: the ClassWizard will add member initialization here
36 //}}AFX_DATA_INIT
37}
38
39
40void PropEdit::DoDataExchange(CDataExchange* pDX)
41{
42 CDialog::DoDataExchange(pDX);
43 //{{AFX_DATA_MAP(PropEdit)
44 // NOTE: the ClassWizard will add DDX and DDV calls here
45 //}}AFX_DATA_MAP
46}
47
48
49BEGIN_MESSAGE_MAP(PropEdit, CDialog)
50 //{{AFX_MSG_MAP(PropEdit)
51 ON_EN_CHANGE(IDC_KEYNAME, OnChangeKeyname)
52 ON_CBN_EDITCHANGE(IDC_KEYTYPE, OnEditchangeKeytype)
53 ON_CBN_CLOSEUP(IDC_KEYTYPE, OnCloseupKeytype)
54 ON_CBN_SELCHANGE(IDC_KEYTYPE, OnSelchangeKeytype)
55 ON_EN_CHANGE(IDC_VALUE, OnChangeValue)
56 ON_BN_CLICKED(IDC_PROPBOOL, OnPropbool)
57 //}}AFX_MSG_MAP
58END_MESSAGE_MAP()
59
61{
62 if (m_updating > 0)
63 return;
64
65 Bool enabOK = true;
66 CWnd *ok = GetDlgItem(IDOK);
67 CWnd *keyname = GetDlgItem(IDC_KEYNAME);
68 CWnd *valuename = GetDlgItem(IDC_VALUE);
69 CComboBox *keytype = (CComboBox*)GetDlgItem(IDC_KEYTYPE);
70 CButton *valuebool = (CButton*)GetDlgItem(IDC_PROPBOOL);
71 *m_type = (Dict::DataType)keytype->GetCurSel();
72
73 valuename->ShowWindow(*m_type != Dict::DICT_BOOL ? SW_SHOW : SW_HIDE);
74 valuebool->ShowWindow(*m_type == Dict::DICT_BOOL ? SW_SHOW : SW_HIDE);
75
76 keyname->EnableWindow(!m_valueOnly);
77 keytype->EnableWindow(!m_valueOnly);
78
79 CString tmp;
80
81 keyname->GetWindowText(tmp);
82#ifdef RESTRICT_KEYS
83 tmp.MakeLower(); // we force user-entered keys to all-lowercase, to prevent case issues
84#endif
85 *m_key = (LPCTSTR)tmp;
86
87 if (!m_valueOnly)
88 {
89 int len = tmp.GetLength();
90 if (len <= 0)
91 enabOK = false;
92
93#ifdef RESTRICT_KEYS
94 // only letters, numbers, and underline allowed
95 for (int i = 0; i < len; i++)
96 if (!isalnum(tmp[i]) && tmp[i] != '_')
97 enabOK = false;
98#endif
99 }
100
101 valuename->GetWindowText(tmp);
102 *m_value = (LPCTSTR)tmp;
103 switch (*m_type)
104 {
105 case Dict::DICT_BOOL:
106 *m_value = valuebool->GetCheck() ? "true" : "false";
107 break;
108 case Dict::DICT_INT:
109 break;
110 case Dict::DICT_REAL:
111 break;
113 break;
115 break;
116 default:
117 enabOK = false;
118 break;
119 }
120
121 ok->EnableWindow(enabOK);
122}
123
125// PropEdit message handlers
126
128{
129 validate();
130}
131
136
138{
139 validate();
140}
141
146
148{
149 validate();
150}
151
152
154{
155 CDialog::OnInitDialog();
156
157 CWnd *keyname = GetDlgItem(IDC_KEYNAME);
158 CWnd *valuename = GetDlgItem(IDC_VALUE);
159 CComboBox *keytype = (CComboBox*)GetDlgItem(IDC_KEYTYPE);
160 CButton *valuebool = (CButton*)GetDlgItem(IDC_PROPBOOL);
161
162 ++m_updating;
163 keytype->SetCurSel((Int)*m_type);
164 keyname->SetWindowText(m_key->str());
165 valuename->SetWindowText(m_value->str());
166 valuebool->SetCheck(strcmp(m_value->str(), "true")==0 ? 1 : 0);
167 --m_updating;
168 validate();
169
170 return TRUE; // return TRUE unless you set the focus to a control
171}
172
174{
175 validate();
176}
bool Bool
Definition BaseType.h:132
#define TRUE
Definition BaseType.h:109
void const char * value
#define IDC_KEYTYPE
Definition resource.h:235
#define IDC_VALUE
Definition resource.h:233
#define IDC_PROPBOOL
Definition resource.h:247
#define IDC_KEYNAME
Definition resource.h:231
#define BOOL
Definition Wnd_File.h:57
DataType
Definition Dict.h:75
@ DICT_REAL
Definition Dict.h:79
@ DICT_BOOL
Definition Dict.h:77
@ DICT_ASCIISTRING
Definition Dict.h:80
@ DICT_INT
Definition Dict.h:78
@ DICT_UNICODESTRING
Definition Dict.h:81
afx_msg void OnPropbool()
Definition propedit.cpp:173
PropEdit(AsciiString *key, Dict::DataType *type, AsciiString *value, Bool valueOnly, CWnd *parent=NULL)
Definition propedit.cpp:31
afx_msg void OnCloseupKeytype()
Definition propedit.cpp:137
Dict::DataType * m_type
Definition propedit.h:54
afx_msg void OnSelchangeKeytype()
Definition propedit.cpp:142
afx_msg void OnChangeValue()
Definition propedit.cpp:147
virtual void DoDataExchange(CDataExchange *pDX)
Definition propedit.cpp:40
int m_updating
Definition propedit.h:57
AsciiString * m_key
Definition propedit.h:53
void validate()
Definition propedit.cpp:60
Bool m_valueOnly
Definition propedit.h:56
afx_msg void OnEditchangeKeytype()
Definition propedit.cpp:132
afx_msg void OnChangeKeyname()
Definition propedit.cpp:127
virtual BOOL OnInitDialog()
Definition propedit.cpp:153
AsciiString * m_value
Definition propedit.h:55