1 // AddVariableDlg.cpp : implementation file
6 #include "addvariabledlg.h"
12 static char THIS_FILE[] = __FILE__;
15 #define NO_RESET_FOCUS 0
18 /////////////////////////////////////////////////////////////////////////////
19 // CAddVariableDlg dialog
22 CAddVariableDlg::CAddVariableDlg(CWnd* pParent /*=NULL*/)
23 : CDialog(CAddVariableDlg::IDD, pParent)
25 //{{AFX_DATA_INIT(CAddVariableDlg)
26 m_default_value = _T("");
27 m_variable_name = _T("");
32 void CAddVariableDlg::DoDataExchange(CDataExchange* pDX)
34 CDialog::DoDataExchange(pDX);
35 //{{AFX_DATA_MAP(CAddVariableDlg)
36 DDX_Text(pDX, IDC_ADD_VARIABLE_DEFAULT_VALUE, m_default_value);
37 DDV_MaxChars(pDX, m_default_value, 31);
38 DDX_Text(pDX, IDC_ADD_VARIABLE_NAME, m_variable_name);
39 DDV_MaxChars(pDX, m_variable_name, 31);
44 BEGIN_MESSAGE_MAP(CAddVariableDlg, CDialog)
45 //{{AFX_MSG_MAP(CAddVariableDlg)
46 ON_BN_CLICKED(IDC_TYPE_NUMBER, OnTypeNumber)
47 ON_BN_CLICKED(IDC_TYPE_STRING, OnTypeString)
51 /////////////////////////////////////////////////////////////////////////////
52 // CAddVariableDlg message handlers
54 void CAddVariableDlg::OnOK()
57 validate_variable_name(RESET_FOCUS);
60 if ( m_name_validated ) {
61 validate_data(RESET_FOCUS);
64 // both ok, then store results
65 if ( m_name_validated && m_data_validated ) {
66 // int sexp_add_variable(char *text, char*, int type);
67 // char temp_name[32];
68 // char temp_value[32];
69 // strcpy(temp_name, m_variable_name);
70 // strcpy(temp_value, m_default_value);
71 // SEXP_VARIABLE_NUMBER SEXP_VARIABLE_STRING
74 // if (m_type_number) {
75 // type = SEXP_VARIABLE_NUMBER;
77 // type = SEXP_VARIABLE_STRING;
80 // m_sexp_var_index = sexp_add_variable(temp_value, temp_name, type);
81 // this get done for free CDialog::OnOk() UpdateData(TRUE);
88 BOOL CAddVariableDlg::OnInitDialog()
90 CDialog::OnInitDialog();
92 // TODO: Add extra initialization here
93 m_variable_name = "<Variable Name>";
94 m_default_value = "<Default Value>";
96 // Set variable type to number
100 m_name_validated = false;
101 m_data_validated = false;
104 // Send default name and values into dialog box
107 return TRUE; // return TRUE unless you set the focus to a control
108 // EXCEPTION: OCX Property Pages should return FALSE
111 bool is_sexp_variable_name(const char* temp_name)
113 for (int i=0; i<MAX_SEXP_VARIABLES; i++) {
114 if (Sexp_variables[i].type & SEXP_VARIABLE_SET) {
115 if ( !strcmp(Sexp_variables[i].text, temp_name) ) {
125 // Check variable name (1) changed (2) > 0 length (3) does not already exist
126 void CAddVariableDlg::validate_variable_name(int set_focus)
130 CEdit *edit = (CEdit *) GetDlgItem(IDC_ADD_VARIABLE_NAME);
131 edit->GetWindowText(temp_name);
133 // Check if any change and not already in list
134 if ( stricmp(temp_name, "<Variable Name>") ) {
135 if ( (strlen(temp_name) > 0) && (get_index_sexp_variable_name(LPCTSTR(temp_name)) == -1) ) { //not already in list and length > 0 {
136 m_name_validated = true;
138 // conflicting variable name
139 if (strlen(temp_name) == 0) {
140 edit->SetWindowText("<Variable Name>");
142 m_name_validated = false;
143 if (set_focus == RESET_FOCUS) {
144 MessageBox("Conflicting variable name");
150 // name unchanged from default
151 m_name_validated = false;
152 if (set_focus == RESET_FOCUS) {
153 MessageBox("Invalid variable name");
161 void CAddVariableDlg::validate_data(int set_focus)
165 CEdit *edit = (CEdit *) GetDlgItem(IDC_ADD_VARIABLE_DEFAULT_VALUE);
166 edit->GetWindowText(temp_data);
168 // check for 0 string length
169 if (strlen(temp_data) == 0) {
170 m_data_validated = false;
173 // verify valid number
174 int temp_num = atoi(temp_data);
175 char buf[TOKEN_LENGTH];
176 sprintf(buf, "%d", temp_num);
178 if ( stricmp(buf, temp_data) ) {
179 m_data_validated = false;
181 m_data_validated = true;
184 m_data_validated = true;
188 // Display message and reset focus
189 if ( (!m_data_validated) && (set_focus == RESET_FOCUS) ) {
190 MessageBox("Invalid Default Value.");
196 // Set type to number
197 void CAddVariableDlg::OnTypeNumber()
199 m_type_number = true;
203 // Set type to string
204 void CAddVariableDlg::OnTypeString()
206 m_type_number = false;
210 // Set type check boxes
211 void CAddVariableDlg::set_variable_type()
214 CButton *button_string = (CButton *) GetDlgItem(IDC_TYPE_STRING);
215 CButton *button_number = (CButton *) GetDlgItem(IDC_TYPE_NUMBER);
217 button_number->SetCheck( m_type_number);
218 button_string->SetCheck(!m_type_number);