2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
4 * All source code herein is the property of Volition, Inc. You may not sell
5 * or otherwise commercially exploit the source or things you created based on
9 // AddVariableDlg.cpp : implementation file
14 #include "addvariabledlg.h"
20 static char THIS_FILE[] = __FILE__;
23 #define NO_RESET_FOCUS 0
26 /////////////////////////////////////////////////////////////////////////////
27 // CAddVariableDlg dialog
30 CAddVariableDlg::CAddVariableDlg(CWnd* pParent /*=NULL*/)
31 : CDialog(CAddVariableDlg::IDD, pParent)
33 //{{AFX_DATA_INIT(CAddVariableDlg)
34 m_default_value = _T("");
35 m_variable_name = _T("");
40 void CAddVariableDlg::DoDataExchange(CDataExchange* pDX)
42 CDialog::DoDataExchange(pDX);
43 //{{AFX_DATA_MAP(CAddVariableDlg)
44 DDX_Text(pDX, IDC_ADD_VARIABLE_DEFAULT_VALUE, m_default_value);
45 DDV_MaxChars(pDX, m_default_value, 31);
46 DDX_Text(pDX, IDC_ADD_VARIABLE_NAME, m_variable_name);
47 DDV_MaxChars(pDX, m_variable_name, 31);
52 BEGIN_MESSAGE_MAP(CAddVariableDlg, CDialog)
53 //{{AFX_MSG_MAP(CAddVariableDlg)
54 ON_BN_CLICKED(IDC_TYPE_NUMBER, OnTypeNumber)
55 ON_BN_CLICKED(IDC_TYPE_STRING, OnTypeString)
59 /////////////////////////////////////////////////////////////////////////////
60 // CAddVariableDlg message handlers
62 void CAddVariableDlg::OnOK()
65 validate_variable_name(RESET_FOCUS);
68 if ( m_name_validated ) {
69 validate_data(RESET_FOCUS);
72 // both ok, then store results
73 if ( m_name_validated && m_data_validated ) {
74 // int sexp_add_variable(char *text, char*, int type);
75 // char temp_name[32];
76 // char temp_value[32];
77 // strcpy(temp_name, m_variable_name);
78 // strcpy(temp_value, m_default_value);
79 // SEXP_VARIABLE_NUMBER SEXP_VARIABLE_STRING
82 // if (m_type_number) {
83 // type = SEXP_VARIABLE_NUMBER;
85 // type = SEXP_VARIABLE_STRING;
88 // m_sexp_var_index = sexp_add_variable(temp_value, temp_name, type);
89 // this get done for free CDialog::OnOk() UpdateData(TRUE);
96 BOOL CAddVariableDlg::OnInitDialog()
98 CDialog::OnInitDialog();
100 // TODO: Add extra initialization here
101 m_variable_name = "<Variable Name>";
102 m_default_value = "<Default Value>";
104 // Set variable type to number
105 m_type_number = true;
108 m_name_validated = false;
109 m_data_validated = false;
112 // Send default name and values into dialog box
115 return TRUE; // return TRUE unless you set the focus to a control
116 // EXCEPTION: OCX Property Pages should return FALSE
119 bool is_sexp_variable_name(const char* temp_name)
121 for (int i=0; i<MAX_SEXP_VARIABLES; i++) {
122 if (Sexp_variables[i].type & SEXP_VARIABLE_SET) {
123 if ( !strcmp(Sexp_variables[i].text, temp_name) ) {
133 // Check variable name (1) changed (2) > 0 length (3) does not already exist
134 void CAddVariableDlg::validate_variable_name(int set_focus)
138 CEdit *edit = (CEdit *) GetDlgItem(IDC_ADD_VARIABLE_NAME);
139 edit->GetWindowText(temp_name);
141 // Check if any change and not already in list
142 if ( stricmp(temp_name, "<Variable Name>") ) {
143 if ( (strlen(temp_name) > 0) && (get_index_sexp_variable_name(LPCTSTR(temp_name)) == -1) ) { //not already in list and length > 0 {
144 m_name_validated = true;
146 // conflicting variable name
147 if (strlen(temp_name) == 0) {
148 edit->SetWindowText("<Variable Name>");
150 m_name_validated = false;
151 if (set_focus == RESET_FOCUS) {
152 MessageBox("Conflicting variable name");
158 // name unchanged from default
159 m_name_validated = false;
160 if (set_focus == RESET_FOCUS) {
161 MessageBox("Invalid variable name");
169 void CAddVariableDlg::validate_data(int set_focus)
173 CEdit *edit = (CEdit *) GetDlgItem(IDC_ADD_VARIABLE_DEFAULT_VALUE);
174 edit->GetWindowText(temp_data);
176 // check for 0 string length
177 if (strlen(temp_data) == 0) {
178 m_data_validated = false;
181 // verify valid number
182 int temp_num = atoi(temp_data);
183 char buf[TOKEN_LENGTH];
184 sprintf(buf, "%d", temp_num);
186 if ( stricmp(buf, temp_data) ) {
187 m_data_validated = false;
189 m_data_validated = true;
192 m_data_validated = true;
196 // Display message and reset focus
197 if ( (!m_data_validated) && (set_focus == RESET_FOCUS) ) {
198 MessageBox("Invalid Default Value.");
204 // Set type to number
205 void CAddVariableDlg::OnTypeNumber()
207 m_type_number = true;
211 // Set type to string
212 void CAddVariableDlg::OnTypeString()
214 m_type_number = false;
218 // Set type check boxes
219 void CAddVariableDlg::set_variable_type()
222 CButton *button_string = (CButton *) GetDlgItem(IDC_TYPE_STRING);
223 CButton *button_number = (CButton *) GetDlgItem(IDC_TYPE_NUMBER);
225 button_number->SetCheck( m_type_number);
226 button_string->SetCheck(!m_type_number);