1 // CounterPage.cpp : implementation file
5 #include "logic_editor.h"
6 #include "CounterPage.h"
11 #include "logic_editorDoc.h"
12 #include "EditorFormView.h"
17 static char THIS_FILE
[] = __FILE__
;
20 /////////////////////////////////////////////////////////////////////////////
21 // CCounterPage property page
23 IMPLEMENT_DYNCREATE(CCounterPage
, CPropertyPage
)
25 CCounterPage::CCounterPage() : CPropertyPage(CCounterPage::IDD
)
27 //{{AFX_DATA_INIT(CCounterPage)
29 m_sWay
= _T("Increment");
30 m_sCounterName
= _T("");
36 CCounterPage::~CCounterPage()
40 void CCounterPage::DoDataExchange(CDataExchange
* pDX
)
42 CPropertyPage::DoDataExchange(pDX
);
43 //{{AFX_DATA_MAP(CCounterPage)
44 DDX_Control(pDX
, IDC_EDIT_COUNTER_LOWER_LIMIT
, m_neLowerLimit
);
45 DDX_Control(pDX
, IDC_LIST_COUNTERS
, m_counters
);
46 DDX_CBString(pDX
, IDC_COMBO_COUNTER_MODE
, m_sMode
);
47 DDX_CBString(pDX
, IDC_COMBO_COUNTER_INCDEC
, m_sWay
);
48 DDX_Text(pDX
, IDC_COUNTER_NAME
, m_sCounterName
);
49 DDX_Text(pDX
, IDC_EDIT_COUNTER_UPPER_LIMIT
, m_nUpperLimit
);
50 DDX_Text(pDX
, IDC_EDIT_COUNTER_LOWER_LIMIT
, m_nLowerLimit
);
55 BEGIN_MESSAGE_MAP(CCounterPage
, CPropertyPage
)
56 //{{AFX_MSG_MAP(CCounterPage)
57 ON_BN_CLICKED(IDC_BUTTON_ADD_COUNTER
, OnButtonAddCounter
)
58 ON_LBN_SELCHANGE(IDC_LIST_COUNTERS
, OnSelchangeListCounters
)
59 ON_BN_CLICKED(IDC_BUTTON_COUNTER_REMOVE
, OnButtonCounterRemove
)
60 ON_BN_CLICKED(IDC_BUTTON_COUNTER_APPLY
, OnButtonCounterApply
)
64 /////////////////////////////////////////////////////////////////////////////
65 // CCounterPage message handlers
67 BOOL
CCounterPage::OnInitDialog()
69 CPropertyPage::OnInitDialog();
71 // init the combo boxes with the right values
72 // CComboBox *comboBox = static_cast<CComboBox*> (GetDlgItem(IDC____));
75 return TRUE
; // return TRUE unless you set the focus to a control
76 // EXCEPTION: OCX Property Pages should return FALSE
80 //---------------------------------------------------------
83 //---------------------------------------------------------
84 void CCounterPage::addCounter( CLogic_editorDoc
*pDoc
, CCounter
* pCounter
)
86 // check if a var or a counter with the same name already exist in the page
87 if( m_counters
.FindString(0,pCounter
->m_sName
) == LB_ERR
)
89 m_counters
.AddString( pCounter
->m_sName
);
92 // if the doc has not been loaded from file, the counter is not yet in doc
94 if( (pDoc
->m_variables
.Find(pCounter
->m_sName
) == NULL
) || (pDoc
->m_counters
.Lookup(pCounter
->m_sName
, pointer
) == FALSE
) )
96 pDoc
->m_counters
.SetAt( pCounter
->m_sName
, pCounter
);
106 //---------------------------------------------------------
107 // OnButtonAddCounter
109 //---------------------------------------------------------
110 void CCounterPage::OnButtonAddCounter()
114 // if some infos are missing, do nothing
115 if (m_sCounterName
.IsEmpty() )
120 // if a counter with thsi name already exist, do nothing
121 CMainFrame
*pFrame
= (CMainFrame
*)AfxGetApp()->m_pMainWnd
;
122 // Get the active MDI child window.
123 CChildFrame
*pChild
= (CChildFrame
*) pFrame
->GetActiveFrame();
125 CLogic_editorDoc
*pDoc
= static_cast<CLogic_editorDoc
*> (pChild
->GetActiveDocument());
128 CCounter
*pCounter
= new CCounter( m_sCounterName
);
129 pCounter
->mode( m_sMode
);
130 pCounter
->way( m_sWay
);
131 pCounter
->lowerLimit( m_nLowerLimit
);
132 pCounter
->upperLimit( m_nUpperLimit
);
134 addCounter( pDoc
, pCounter
);
136 } // OnButtonAddCounter //
141 void CCounterPage::OnSelchangeListCounters()
143 m_counters
.GetText( m_counters
.GetCurSel(), m_sCounterName
);
145 CMainFrame
*pFrame
= (CMainFrame
*)AfxGetApp()->m_pMainWnd
;
146 // Get the active MDI child window.
147 CChildFrame
*pChild
= (CChildFrame
*) pFrame
->GetActiveFrame();
149 CLogic_editorDoc
*pDoc
= static_cast<CLogic_editorDoc
*> (pChild
->GetActiveDocument());
153 if (pDoc
->m_counters
.Lookup( m_sCounterName
, p
) == FALSE
)
158 CCounter
*pCounter
= static_cast<CCounter
*> (p
);
160 // set the value in the different fields
161 m_sMode
= pCounter
->mode();
162 m_sWay
= pCounter
->way();
163 m_nLowerLimit
= pCounter
->lowerLimit();
164 m_nUpperLimit
= pCounter
->upperLimit();
173 void CCounterPage::OnButtonCounterRemove()
177 //get the selected counter name
178 const int sel
= m_counters
.GetCurSel();
183 m_counters
.GetText( sel
, name
);
185 // get the pointer from the document
186 CMainFrame
*pFrame
= (CMainFrame
*)AfxGetApp()->m_pMainWnd
;
187 // Get the active MDI child window.
188 CChildFrame
*pChild
= (CChildFrame
*) pFrame
->GetActiveFrame();
189 CLogic_editorDoc
*pDoc
= static_cast<CLogic_editorDoc
*> (pChild
->GetActiveDocument());
192 pDoc
->deleteCounter( name
);
193 m_counters
.DeleteString( sel
);
197 AfxMessageBox(_T("No counter selected ! Choose a counter first"));
202 void CCounterPage::OnButtonCounterApply()
206 //get the selected counter name
207 const int sel
= m_counters
.GetCurSel();
212 m_counters
.GetText( sel
, name
);
214 // get the pointer from the document
215 CMainFrame
*pFrame
= (CMainFrame
*)AfxGetApp()->m_pMainWnd
;
216 // Get the active MDI child window.
217 CChildFrame
*pChild
= (CChildFrame
*) pFrame
->GetActiveFrame();
218 CLogic_editorDoc
*pDoc
= static_cast<CLogic_editorDoc
*> (pChild
->GetActiveDocument());
221 if ( pDoc
->changeCounterName( name
, m_sCounterName
) == FALSE
)
224 CCounter
*pCounter
= NULL
;
225 pDoc
->m_counters
.Lookup( m_sCounterName
, (void*&)(pCounter
) );
230 pCounter
->lowerLimit( m_nLowerLimit
);
231 pCounter
->upperLimit( m_nUpperLimit
);
232 pCounter
->mode( m_sMode
);
233 pCounter
->way( m_sWay
);
235 m_counters
.DeleteString( sel
);
236 m_counters
.AddString( m_sCounterName
);
240 AfxMessageBox(_T("No counter selected ! Choose a counter first"));
247 //---------------------------------------------------------
250 //---------------------------------------------------------
251 BOOL
CCounterPage::OnSetActive()
253 // get the child frame
254 CMainFrame
*pFrame
= (CMainFrame
*)AfxGetApp()->m_pMainWnd
;
255 CChildFrame
*pChild
= (CChildFrame
*) pFrame
->MDIGetActive();
258 CEditorFormView
*pFormView
= static_cast<CEditorFormView
*> ( pChild
->m_wndSplitter
.GetPane(0,1) );
259 ASSERT_VALID(pFormView
);
262 CLogic_editorDoc
* pDoc
= (CLogic_editorDoc
*)pFormView
->GetDocument();
264 if( pDoc
->InitConditionPage
)
269 for( pos
= pDoc
->m_counters
.GetStartPosition(); pos
!= NULL
; )
271 CCounter
* pCounter
= new CCounter();
272 pDoc
->m_counters
.GetNextAssoc( pos
, eltName
, (void*&)pCounter
);
273 addCounter( pDoc
, pCounter
);
276 pDoc
->InitConditionPage
= FALSE
;
278 return CPropertyPage::OnSetActive();