Linux multi-monitor fullscreen support
[ryzomcore.git] / nel / tools / logic / logic_editor_dll / StatePage.cpp
blob9135f274f335257c581808d2d2f8fb5969172e21
1 // StatePage.cpp : implementation file
2 //
4 #include "stdafx.h"
5 #include "logic_editor.h"
6 #include "StatePage.h"
8 #include "ChildFrm.h"
9 #include "MainFrm.h"
10 #include "LogicTreeView.h"
11 #include "StatesView.h"
12 #include "EditorFormView.h"
15 #ifdef _DEBUG
16 #define new DEBUG_NEW
17 #undef THIS_FILE
18 static char THIS_FILE[] = __FILE__;
19 #endif
21 /////////////////////////////////////////////////////////////////////////////
22 // CStatePage property page
24 IMPLEMENT_DYNCREATE(CStatePage, CPropertyPage)
26 CStatePage::CStatePage() : CPropertyPage(CStatePage::IDD)
28 //{{AFX_DATA_INIT(CStatePage)
29 m_nEventMessage = 0;
30 m_sConditionName = _T("");
31 m_sNextStateName = _T("");
32 m_sStateName = _T("");
33 m_sMessageID = _T("");
34 m_sArgument = _T("");
35 m_sDestination = _T("");
36 //}}AFX_DATA_INIT
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);
54 //}}AFX_DATA_MAP
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)
68 //}}AFX_MSG_MAP
69 END_MESSAGE_MAP()
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();
97 else
99 OnRadioStateChange();
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;
109 else
111 m_sConditionName.Empty();
112 m_sArgument.Empty();
113 m_sDestination.Empty();
114 m_sMessageID.Empty();
115 m_sNextStateName.Empty();
118 else
120 m_sStateName.Empty();
123 // get the document
124 CMainFrame *pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
125 CChildFrame *pChild = (CChildFrame *) pFrame->GetActiveFrame();
126 CLogic_editorDoc *pDoc = static_cast<CLogic_editorDoc *> (pChild->GetActiveDocument());
127 ASSERT_VALID(pDoc);
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();
135 void *pointer;
136 CString name;
138 while (pos != NULL)
140 pDoc->m_conditions.GetNextAssoc( pos, name, pointer);
141 comboBox->AddString( name );
144 // list of states
145 comboBox = static_cast<CComboBox *> (GetDlgItem(IDC_COMBO_STATE_CHANGE) );
147 comboBox->ResetContent();
149 pos = pDoc->m_states.GetStartPosition();
150 while (pos != NULL)
152 pDoc->m_states.GetNextAssoc( pos, name, pointer);
153 comboBox->AddString( name );
157 UpdateData(FALSE);
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 //---------------------------------------------------------
215 // addState
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
229 void *pState;
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 );
236 // update views
237 pDoc->UpdateAllViews( (CView*)this->GetParent() );
238 UpdateData(FALSE);
240 } // addState //
244 //---------------------------------------------------------
245 // OnButtonAddState
247 //---------------------------------------------------------
248 void CStatePage::OnButtonAddState()
250 UpdateData();
252 if (m_sStateName.IsEmpty())
254 AfxMessageBox(_T("State name cannot be empty, please enter a valid name"));
255 return;
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());
265 ASSERT_VALID(pDoc);
267 // create the new state
268 CState *state = new CState(m_sStateName);
270 // add the state
271 addState( pDoc, state );
274 } // OnButtonAddState //
279 void CStatePage::OnButtonAddEvent()
281 UpdateData();
283 // do nothing is no state is selected
284 if (m_pSelectedState == NULL)
285 return;
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;
299 else // state change
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());
314 ASSERT_VALID(pDoc);
316 pDoc->UpdateAllViews( (CView*)this->GetParent() );
321 //---------------------------------------------------------
322 // OnSetActive
324 //---------------------------------------------------------
325 BOOL CStatePage::OnSetActive()
328 // get the child frame
329 CMainFrame *pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
330 CChildFrame *pChild = (CChildFrame *) pFrame->MDIGetActive();
332 // get the form view
333 CEditorFormView *pFormView = static_cast<CEditorFormView *> ( pChild->m_wndSplitter.GetPane(0,1) );
334 ASSERT_VALID(pFormView);
336 // get the document
337 CLogic_editorDoc * pDoc = (CLogic_editorDoc*)pFormView->GetDocument();
339 if( pDoc->InitStatePage )
341 // init the states
342 POSITION pos;
343 CString eltName;
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;
354 Update();
356 return CPropertyPage::OnSetActive();
358 } // 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());
374 ASSERT_VALID(pDoc);
376 pDoc->deleteState( m_pSelectedState->m_sName );
378 m_pSelectedState = NULL;
379 m_pSelectedEvent = NULL;
381 Update();
382 pDoc->UpdateAllViews( (CView*)this->GetParent() );
385 else
387 AfxMessageBox(_T("No state selected ! Choose a state first"));
394 void CStatePage::OnButtonStateApply()
396 UpdateData();
398 if (m_pSelectedState != NULL)
400 if (m_sStateName.IsEmpty())
402 AfxMessageBox(_T("State name cannot be empty, please enter a valid name"));
403 return;
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());
411 ASSERT_VALID(pDoc);
413 pDoc->changeStateName( m_pSelectedState->m_sName, m_sStateName );
415 Update();
416 pDoc->UpdateAllViews( (CView*)this->GetParent() );
419 else
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());
439 ASSERT_VALID(pDoc);
441 m_pSelectedState->removeEvent( m_pSelectedEvent );
443 m_pSelectedEvent = NULL;
445 // Update();
446 pDoc->UpdateAllViews( (CView*)this->GetParent() );
448 else
450 AfxMessageBox(_T("No event selected ! Choose a event first"));