1 // VariablePage.cpp : implementation file
5 #include "logic_editor.h"
6 #include "VariablePage.h"
10 #include "logic_editorDoc.h"
12 #include "EditorFormView.h"
17 static char THIS_FILE
[] = __FILE__
;
20 /////////////////////////////////////////////////////////////////////////////
21 // CVariablePage property page
23 IMPLEMENT_DYNCREATE(CVariablePage
, CPropertyPage
)
25 CVariablePage::CVariablePage() : CPropertyPage(CVariablePage::IDD
)
27 //{{AFX_DATA_INIT(CVariablePage)
32 CVariablePage::~CVariablePage()
36 void CVariablePage::DoDataExchange(CDataExchange
* pDX
)
38 CPropertyPage::DoDataExchange(pDX
);
39 //{{AFX_DATA_MAP(CVariablePage)
40 DDX_Control(pDX
, IDC_LIST_VARIABLES
, m_listVariables
);
41 DDX_Text(pDX
, IDC_EDIT_VARIABLE_NAME
, m_sVarName
);
46 BEGIN_MESSAGE_MAP(CVariablePage
, CPropertyPage
)
47 //{{AFX_MSG_MAP(CVariablePage)
48 ON_BN_CLICKED(IDC_BUTTON_ADD
, OnButtonAdd
)
49 ON_LBN_SELCHANGE(IDC_LIST_VARIABLES
, OnSelchangeListVariables
)
50 ON_BN_CLICKED(IDC_BUTTON_VAR_DELETE
, OnButtonVarDelete
)
51 ON_BN_CLICKED(IDC_BUTTON_VAR_APPLY
, OnButtonVarApply
)
55 /////////////////////////////////////////////////////////////////////////////
56 // CVariablePage message handlers
58 BOOL
CVariablePage::OnInitDialog()
60 CPropertyPage::OnInitDialog();
62 // TODO: Add extra initialization here
64 return TRUE
; // return TRUE unless you set the focus to a control
65 // EXCEPTION: OCX Property Pages should return FALSE
69 //---------------------------------------------------------
72 //---------------------------------------------------------
73 void CVariablePage::addVariable( CLogic_editorDoc
*pDoc
, CString varName
)
75 // check if a var or a counter with the same name already exist in the page
76 if( m_listVariables
.FindStringExact(0,varName
) == LB_ERR
)
78 // add the variable in the page
79 m_listVariables
.AddString( varName
);
82 // if the doc has not been loaded from file, the variable is not yet in doc
84 if( (pDoc
->m_variables
.Find(varName
) == NULL
) )//|| (pDoc->m_counters.Lookup(varName, pointer) == FALSE) )
86 pDoc
->m_variables
.AddTail( varName
);
96 void CVariablePage::OnButtonAdd()
100 if ( m_sVarName
.IsEmpty() )
103 CMainFrame
*pFrame
= (CMainFrame
*)AfxGetApp()->m_pMainWnd
;
104 // Get the active MDI child window.
105 CChildFrame
*pChild
= (CChildFrame
*) pFrame
->GetActiveFrame();
107 CLogic_editorDoc
*pDoc
= static_cast<CLogic_editorDoc
*> (pChild
->GetActiveDocument());
110 addVariable( pDoc
, m_sVarName
);
115 void CVariablePage::OnSelchangeListVariables()
117 const int sel
= m_listVariables
.GetCurSel();
119 // set the text in the edit box
120 m_listVariables
.GetText( sel
, m_sVarName
);
124 void CVariablePage::OnButtonVarDelete()
126 // get the selected variable if any
127 const int sel
= m_listVariables
.GetCurSel();
132 m_listVariables
.GetText( sel
, txt
);
134 m_listVariables
.DeleteString( sel
);
136 CMainFrame
*pFrame
= (CMainFrame
*)AfxGetApp()->m_pMainWnd
;
137 // Get the active MDI child window.
138 CChildFrame
*pChild
= (CChildFrame
*) pFrame
->GetActiveFrame();
140 CLogic_editorDoc
*pDoc
= static_cast<CLogic_editorDoc
*> (pChild
->GetActiveDocument());
144 pDoc
->deleteVar( txt
);
148 AfxMessageBox(_T("No variable selected ! Choose a variable first"));
153 void CVariablePage::OnButtonVarApply()
157 // get the selected variable if any
158 const int sel
= m_listVariables
.GetCurSel();
163 m_listVariables
.GetText( sel
, txt
);
165 CMainFrame
*pFrame
= (CMainFrame
*)AfxGetApp()->m_pMainWnd
;
166 // Get the active MDI child window.
167 CChildFrame
*pChild
= (CChildFrame
*) pFrame
->GetActiveFrame();
169 CLogic_editorDoc
*pDoc
= static_cast<CLogic_editorDoc
*> (pChild
->GetActiveDocument());
173 if ( pDoc
->changeVarName( txt
, m_sVarName
) == TRUE
)
175 m_listVariables
.DeleteString( sel
);
176 m_listVariables
.AddString( m_sVarName
);
181 AfxMessageBox(_T("No variable selected ! Choose a variable first"));