1 // StatePage.cpp : implementation file
5 #include "logic_editor.h"
10 #include "LogicTreeView.h"
11 #include "StatesView.h"
12 #include "EditorFormView.h"
18 static char THIS_FILE
[] = __FILE__
;
21 /////////////////////////////////////////////////////////////////////////////
22 // CStatePage property page
24 IMPLEMENT_DYNCREATE(CStatePage
, CPropertyPage
)
26 CStatePage::CStatePage() : CPropertyPage(CStatePage::IDD
)
28 //{{AFX_DATA_INIT(CStatePage)
30 m_sConditionName
= _T("");
31 m_sNextStateName
= _T("");
32 m_sStateName
= _T("");
33 m_sMessageID
= _T("");
35 m_sDestination
= _T("");
39 CStatePage::~CStatePage()
43 void CStatePage::DoDataExchange(CDataExchange
* pDX
)
45 CPropertyPage::DoDataExchange(pDX
);
46 //{{AFX_DATA_MAP(CStatePage)
47 DDX_Radio(pDX
, IDC_RADIO_STATE_EVENT_MSG
, m_nEventMessage
);
48 DDX_CBString(pDX
, IDC_COMBO_STATE_COND_NAMES
, m_sConditionName
);
49 DDX_CBString(pDX
, IDC_COMBO_STATE_CHANGE
, m_sNextStateName
);
50 DDX_Text(pDX
, IDC_EDIT_STATE_NAME
, m_sStateName
);
51 DDX_CBString(pDX
, IDC_COMBO_STATE_MSG_ID
, m_sMessageID
);
52 DDX_Text(pDX
, IDC_EDIT_STATE_ARGUMENT
, m_sArgument
);
53 DDX_Text(pDX
, IDC_EDIT_STATE_MSG_DEST
, m_sDestination
);
58 BEGIN_MESSAGE_MAP(CStatePage
, CPropertyPage
)
59 //{{AFX_MSG_MAP(CStatePage)
60 ON_BN_CLICKED(IDC_RADIO_STATE_CHANGE
, OnRadioStateChange
)
61 ON_BN_CLICKED(IDC_RADIO_STATE_EVENT_MSG
, OnRadioStateEventMsg
)
62 ON_BN_CLICKED(IDC_BUTTON_ADD_STATE
, OnButtonAddState
)
63 ON_BN_CLICKED(IDC_BUTTON_ADD_EVENT
, OnButtonAddEvent
)
64 ON_BN_CLICKED(IDC_BUTTON_STATE_REMOVE
, OnButtonStateRemove
)
65 ON_BN_CLICKED(IDC_BUTTON_STATE_APPLY
, OnButtonStateApply
)
66 ON_BN_CLICKED(IDC_BUTTON_EVENT_APPLY
, OnButtonEventApply
)
67 ON_BN_CLICKED(IDC_BUTTON_EVENT_REMOVE
, OnButtonEventRemove
)
75 void CStatePage::Update()
77 if (m_pSelectedState
!= NULL
)
80 m_sStateName
= m_pSelectedState
->m_sName
;
82 if (m_pSelectedEvent
!= NULL
)
84 this->m_sConditionName
= m_pSelectedEvent
->m_sConditionName
;
86 if (m_pSelectedEvent
->m_bActionIsMessage
== TRUE
)
88 OnRadioStateEventMsg();
90 this->m_nEventMessage
= 0;
91 this->m_sArgument
= m_pSelectedEvent
->m_sArguments
;
92 this->m_sDestination
= m_pSelectedEvent
->m_sMessageDestination
;
93 this->m_sMessageID
= m_pSelectedEvent
->m_sMessageID
;
95 this->m_sNextStateName
.Empty();
101 this->m_nEventMessage
= 1;
103 this->m_sArgument
.Empty();
104 this->m_sDestination
.Empty();
105 this->m_sMessageID
.Empty();
106 this->m_sNextStateName
= m_pSelectedEvent
->m_sStateChange
;
111 m_sConditionName
.Empty();
113 m_sDestination
.Empty();
114 m_sMessageID
.Empty();
115 m_sNextStateName
.Empty();
120 m_sStateName
.Empty();
124 CMainFrame
*pFrame
= (CMainFrame
*)AfxGetApp()->m_pMainWnd
;
125 CChildFrame
*pChild
= (CChildFrame
*) pFrame
->GetActiveFrame();
126 CLogic_editorDoc
*pDoc
= static_cast<CLogic_editorDoc
*> (pChild
->GetActiveDocument());
129 // list of conditions
130 CComboBox
*comboBox
= static_cast<CComboBox
*> (GetDlgItem(IDC_COMBO_STATE_COND_NAMES
) );
132 comboBox
->ResetContent();
134 POSITION pos
= pDoc
->m_conditions
.GetStartPosition();
140 pDoc
->m_conditions
.GetNextAssoc( pos
, name
, pointer
);
141 comboBox
->AddString( name
);
145 comboBox
= static_cast<CComboBox
*> (GetDlgItem(IDC_COMBO_STATE_CHANGE
) );
147 comboBox
->ResetContent();
149 pos
= pDoc
->m_states
.GetStartPosition();
152 pDoc
->m_states
.GetNextAssoc( pos
, name
, pointer
);
153 comboBox
->AddString( name
);
163 /////////////////////////////////////////////////////////////////////////////
164 // CStatePage message handlers
166 BOOL
CStatePage::OnInitDialog()
168 CPropertyPage::OnInitDialog();
170 // TODO: Add extra initialization here
171 m_pSelectedState
= NULL
;
172 m_pSelectedEvent
= NULL
;
174 // select the State Change radio button
175 if ( m_nEventMessage
== 0)
176 OnRadioStateEventMsg();
177 else if ( m_nEventMessage
== 1)
178 OnRadioStateChange();
180 return TRUE
; // return TRUE unless you set the focus to a control
181 // EXCEPTION: OCX Property Pages should return FALSE
185 void CStatePage::OnRadioStateChange()
187 GetDlgItem(IDC_STATIC_STATE_CHANGE
)->EnableWindow();
188 GetDlgItem(IDC_COMBO_STATE_CHANGE
)->EnableWindow();
190 GetDlgItem(IDC_STATIC_STATE_MSG1
)->EnableWindow(FALSE
);
191 GetDlgItem(IDC_STATIC_STATE_MSG2
)->EnableWindow(FALSE
);
192 GetDlgItem(IDC_STATIC_STATE_MSG3
)->EnableWindow(FALSE
);
193 GetDlgItem(IDC_COMBO_STATE_MSG_ID
)->EnableWindow(FALSE
);
194 GetDlgItem(IDC_EDIT_STATE_ARGUMENT
)->EnableWindow(FALSE
);
195 GetDlgItem(IDC_EDIT_STATE_MSG_DEST
)->EnableWindow(FALSE
);
198 void CStatePage::OnRadioStateEventMsg()
200 GetDlgItem(IDC_STATIC_STATE_CHANGE
)->EnableWindow(FALSE
);
201 GetDlgItem(IDC_COMBO_STATE_CHANGE
)->EnableWindow(FALSE
);
203 GetDlgItem(IDC_STATIC_STATE_MSG1
)->EnableWindow(TRUE
);
204 GetDlgItem(IDC_STATIC_STATE_MSG2
)->EnableWindow(TRUE
);
205 GetDlgItem(IDC_STATIC_STATE_MSG3
)->EnableWindow(TRUE
);
206 GetDlgItem(IDC_COMBO_STATE_MSG_ID
)->EnableWindow(TRUE
);
207 GetDlgItem(IDC_EDIT_STATE_ARGUMENT
)->EnableWindow(TRUE
);
208 GetDlgItem(IDC_EDIT_STATE_MSG_DEST
)->EnableWindow(TRUE
);
214 //---------------------------------------------------------
217 //---------------------------------------------------------
218 void CStatePage::addState( CLogic_editorDoc
*pDoc
, CState
* state
)
220 // check whether this state is already in the combo box
221 CComboBox
*comboBox
= static_cast<CComboBox
*> (GetDlgItem(IDC_COMBO_STATE_CHANGE
) );
222 if( comboBox
->FindStringExact(0, state
->m_sName
) == LB_ERR
)
224 // add the state in the combo box
225 comboBox
->AddString( state
->m_sName
);
228 // check whether this state already exists
230 if( pDoc
->m_states
.Lookup(state
->m_sName
, pState
) == FALSE
)
232 // add the new state to the states tree, and to the vector of states in the document
233 pDoc
->m_states
.SetAt( state
->m_sName
, state
);
237 pDoc
->UpdateAllViews( (CView
*)this->GetParent() );
244 //---------------------------------------------------------
247 //---------------------------------------------------------
248 void CStatePage::OnButtonAddState()
252 if (m_sStateName
.IsEmpty())
254 AfxMessageBox(_T("State name cannot be empty, please enter a valid name"));
258 CMainFrame
*pFrame
= (CMainFrame
*)AfxGetApp()->m_pMainWnd
;
260 // Get the active MDI child window.
261 CChildFrame
*pChild
= (CChildFrame
*) pFrame
->GetActiveFrame();
263 /// \toto Malkav : check if a state with this name does not already exist in the document
264 CLogic_editorDoc
*pDoc
= static_cast<CLogic_editorDoc
*> (pChild
->GetActiveDocument());
267 // create the new state
268 CState
*state
= new CState(m_sStateName
);
271 addState( pDoc
, state
);
274 } // OnButtonAddState //
279 void CStatePage::OnButtonAddEvent()
283 // do nothing is no state is selected
284 if (m_pSelectedState
== NULL
)
287 CEvent
*pEvent
= new CEvent();
289 pEvent
->m_sConditionName
= this->m_sConditionName
;
291 if (this->m_nEventMessage
== 0)
293 pEvent
->m_bActionIsMessage
= TRUE
;
294 pEvent
->m_sStateChange
.Empty();
295 pEvent
->m_sArguments
= this->m_sArgument
;
296 pEvent
->m_sMessageDestination
= this->m_sDestination
;
297 pEvent
->m_sMessageID
= this->m_sMessageID
;
301 pEvent
->m_bActionIsMessage
= FALSE
;
302 pEvent
->m_sStateChange
= this->m_sNextStateName
;
303 pEvent
->m_sArguments
.Empty();
304 pEvent
->m_sMessageDestination
.Empty();
305 pEvent
->m_sMessageID
.Empty();
308 // add the event to the selected state
309 m_pSelectedState
->addEvent( pEvent
);
311 CMainFrame
*pFrame
= (CMainFrame
*)AfxGetApp()->m_pMainWnd
;
312 CChildFrame
*pChild
= (CChildFrame
*) pFrame
->GetActiveFrame();
313 CLogic_editorDoc
*pDoc
= static_cast<CLogic_editorDoc
*> (pChild
->GetActiveDocument());
316 pDoc
->UpdateAllViews( (CView
*)this->GetParent() );
321 //---------------------------------------------------------
324 //---------------------------------------------------------
325 BOOL
CStatePage::OnSetActive()
328 // get the child frame
329 CMainFrame *pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
330 CChildFrame *pChild = (CChildFrame *) pFrame->MDIGetActive();
333 CEditorFormView *pFormView = static_cast<CEditorFormView *> ( pChild->m_wndSplitter.GetPane(0,1) );
334 ASSERT_VALID(pFormView);
337 CLogic_editorDoc * pDoc = (CLogic_editorDoc*)pFormView->GetDocument();
339 if( pDoc->InitStatePage )
344 for( pos = pDoc->m_states.GetStartPosition(); pos != NULL; )
346 CState * pState = new CState();
347 pDoc->m_states.GetNextAssoc( pos, eltName, (void*&)pState );
348 addState( pDoc, pState );
351 pDoc->InitStatePage = FALSE;
356 return CPropertyPage::OnSetActive();
364 void CStatePage::OnButtonStateRemove()
366 // get selected state
367 if (m_pSelectedState
!= NULL
)
369 if (AfxMessageBox(_T("Your are about to permanently delete this state.\nDoing so will invalidate all references to this state.\nDo you want to continue anyway ?") ,MB_OKCANCEL
|MB_DEFBUTTON2
) == IDOK
)
371 CMainFrame
*pFrame
= (CMainFrame
*)AfxGetApp()->m_pMainWnd
;
372 CChildFrame
*pChild
= (CChildFrame
*) pFrame
->GetActiveFrame();
373 CLogic_editorDoc
*pDoc
= static_cast<CLogic_editorDoc
*> (pChild
->GetActiveDocument());
376 pDoc
->deleteState( m_pSelectedState
->m_sName
);
378 m_pSelectedState
= NULL
;
379 m_pSelectedEvent
= NULL
;
382 pDoc
->UpdateAllViews( (CView
*)this->GetParent() );
387 AfxMessageBox(_T("No state selected ! Choose a state first"));
394 void CStatePage::OnButtonStateApply()
398 if (m_pSelectedState
!= NULL
)
400 if (m_sStateName
.IsEmpty())
402 AfxMessageBox(_T("State name cannot be empty, please enter a valid name"));
406 if (AfxMessageBox(_T("Your are about to change this state name.\nDoing so will change all occurence of the old name to the new one.\nDo you want to continue anyway ?") ,MB_OKCANCEL
|MB_DEFBUTTON2
) == IDOK
)
408 CMainFrame
*pFrame
= (CMainFrame
*)AfxGetApp()->m_pMainWnd
;
409 CChildFrame
*pChild
= (CChildFrame
*) pFrame
->GetActiveFrame();
410 CLogic_editorDoc
*pDoc
= static_cast<CLogic_editorDoc
*> (pChild
->GetActiveDocument());
413 pDoc
->changeStateName( m_pSelectedState
->m_sName
, m_sStateName
);
416 pDoc
->UpdateAllViews( (CView
*)this->GetParent() );
421 AfxMessageBox(_T("No state selected ! Choose a state first"));
425 void CStatePage::OnButtonEventApply()
427 // TODO: Add your control notification handler code here
428 AfxMessageBox(_T("Features not implemented"));
431 void CStatePage::OnButtonEventRemove()
433 // get selected state
434 if (m_pSelectedEvent
!= NULL
&& m_pSelectedState
!= NULL
)
436 CMainFrame
*pFrame
= (CMainFrame
*)AfxGetApp()->m_pMainWnd
;
437 CChildFrame
*pChild
= (CChildFrame
*) pFrame
->GetActiveFrame();
438 CLogic_editorDoc
*pDoc
= static_cast<CLogic_editorDoc
*> (pChild
->GetActiveDocument());
441 m_pSelectedState
->removeEvent( m_pSelectedEvent
);
443 m_pSelectedEvent
= NULL
;
446 pDoc
->UpdateAllViews( (CView
*)this->GetParent() );
450 AfxMessageBox(_T("No event selected ! Choose a event first"));