1 // StatesView.cpp : implementation file
5 #include "logic_editor.h"
6 #include "StatesView.h"
9 #include "Logic_editorDoc.h"
12 #include "EditorFormView.h"
17 static char THIS_FILE
[] = __FILE__
;
20 /////////////////////////////////////////////////////////////////////////////
23 IMPLEMENT_DYNCREATE(CStatesView
, CTreeView
)
25 CStatesView::CStatesView()
29 CStatesView::~CStatesView()
34 BEGIN_MESSAGE_MAP(CStatesView
, CTreeView
)
35 //{{AFX_MSG_MAP(CStatesView)
37 ON_NOTIFY_REFLECT(TVN_SELCHANGED
, OnSelchanged
)
41 /////////////////////////////////////////////////////////////////////////////
42 // CStatesView drawing
44 void CStatesView::OnDraw(CDC
* pDC
)
46 CDocument
* pDoc
= GetDocument();
47 // TODO: add draw code here
50 /////////////////////////////////////////////////////////////////////////////
51 // CStatesView diagnostics
54 void CStatesView::AssertValid() const
56 CTreeView::AssertValid();
59 void CStatesView::Dump(CDumpContext
& dc
) const
72 void CStatesView::expand(UINT nCode
, HTREEITEM hItem
)
77 CTreeCtrl
&m_tree
= GetTreeCtrl();
80 hElement
= m_tree
.GetRootItem();
83 m_tree
.Expand(hItem
,nCode
);
84 hElement
= m_tree
.GetChildItem(hItem
);
89 while ((hElement
!= NULL
) || (pile
.GetSize() != 0))
91 while ((hElement
== NULL
) && (pile
.GetSize()!=0))
93 hElement
= pile
[pile
.GetSize()-1];
94 pile
.RemoveAt(pile
.GetSize()-1);
95 hElement
= m_tree
.GetNextSiblingItem(hElement
);
100 m_tree
.Expand(hElement
,nCode
);
101 hElement
= m_tree
.GetChildItem(hElement
);
111 /////////////////////////////////////////////////////////////////////////////
112 // CStatesView message handlers
114 void CStatesView::OnUpdate(CView
* pSender
, LPARAM lHint
, CObject
* pHint
)
116 /************* TO DO : REDRAW ONLY IF Some states have changed *****/
120 CTreeView::OnUpdate(pSender
,lHint
,pHint
);
123 BOOL bSelection
= FALSE
;
126 CLogic_editorDoc
*pDoc
= static_cast<CLogic_editorDoc
*>(GetDocument());
129 CTreeCtrl
&m_tree
= GetTreeCtrl();
131 m_tree
.DeleteAllItems();
132 m_mapItemToEvent
.RemoveAll();
134 m_tree
.InsertItem(_T("States"));
136 // get the states map
139 POSITION pos
= pDoc
->m_states
.GetStartPosition();
144 pDoc
->m_states
.GetNextAssoc( pos
, stateName
, (void*&)pState
);
145 hItem
= m_tree
.InsertItem( stateName
, m_tree
.GetRootItem());
147 // if this is the selected state (and there was no selected event), select it)
148 if ( m_pSelectedEvent
== NULL
&& m_pSelectedState
== pState
)
150 m_tree
.SelectItem( hItem
);
154 // insert every event as children nodes
155 CEvent
*pEvent
= NULL
;
156 HTREEITEM hItemCurrent
;
158 POSITION eventPos
= pState
->m_evEvents
.GetHeadPosition();
159 while (eventPos
!= NULL
)
161 pEvent
= pState
->m_evEvents
.GetNext( eventPos
);
164 hItemCurrent
= m_tree
.InsertItem( pEvent
->getEventAsString() , hItem
);
165 m_mapItemToEvent
.SetAt( hItemCurrent
, pEvent
);
166 // if this is the selected event, select it
167 if ( m_pSelectedEvent
== pEvent
)
169 m_tree
.SelectItem( hItemCurrent
);
177 expand(/*TVE_EXPAND ,NULL*/ );
182 m_pSelectedEvent
= NULL
;
183 m_pSelectedState
= NULL
;
189 BOOL
CStatesView::PreCreateWindow(CREATESTRUCT
& cs
)
191 // modify arborescence style
192 cs
.style
|=(TVS_HASLINES
|TVS_LINESATROOT
|TVS_HASBUTTONS
/*|TVS_EDITLABELS*/);
193 // cs.style &= ~TVS_DISABLEDRAGDROP;
195 return CTreeView::PreCreateWindow(cs
);
198 void CStatesView::OnKillFocus(CWnd
* pNewWnd
)
200 // CTreeView::OnKillFocus(pNewWnd);
203 void CStatesView::OnSelchanged(NMHDR
* pNMHDR
, LRESULT
* pResult
)
205 NM_TREEVIEW
* pNMTreeView
= (NM_TREEVIEW
*)pNMHDR
;
208 m_pSelectedEvent
= NULL
;
209 m_pSelectedState
= NULL
;
213 CTreeCtrl
&treeCtrl
= GetTreeCtrl();
216 hItem
= treeCtrl
.GetSelectedItem();
219 if (hItem
== treeCtrl
.GetRootItem())
222 // get the event selected (if any)
223 if ( ! m_mapItemToEvent
.Lookup(hItem
, m_pSelectedEvent
) )
224 m_pSelectedEvent
= NULL
;
230 // get the state (if any)
231 while ( treeCtrl
.GetParentItem( hItem
) != treeCtrl
.GetRootItem() )
232 hItem
= treeCtrl
.GetParentItem( hItem
);
234 CString stateName
= treeCtrl
.GetItemText( hItem
);
236 CLogic_editorDoc
*pDoc
= static_cast<CLogic_editorDoc
*> (GetDocument());
238 // to update the fields of the condition page in the form view
239 CMainFrame
*pFrame
= (CMainFrame
*)AfxGetApp()->m_pMainWnd
;
241 // Get the active MDI child window.
242 CChildFrame
*pChild
= (CChildFrame
*) pFrame
->GetActiveFrame();
244 CEditorFormView
*pFormView
= static_cast<CEditorFormView
*> ( pChild
->m_wndSplitter
.GetPane(0,1) );
245 CStatePage
*pStatePage
= static_cast<CStatePage
*> ( pFormView
->m_pPropertySheet
->GetPage(3) );
247 if ( pDoc
->m_states
.Lookup( stateName
, (void*&) m_pSelectedState
) )
249 pFormView
->m_pPropertySheet
->SetActivePage( pStatePage
);
251 if ( this->m_pSelectedEvent
== NULL
|| pStatePage
->m_pSelectedEvent
!= this->m_pSelectedEvent
)
253 pStatePage
->m_pSelectedEvent
= this->m_pSelectedEvent
;
254 pStatePage
->m_pSelectedState
= this->m_pSelectedState
;
256 pStatePage
->Update();
259 else //this->m_pSelectedState == NULL
261 if (pStatePage
->m_pSelectedState
!= NULL
)
263 pStatePage
->m_pSelectedEvent
= this->m_pSelectedEvent
; // = NULL
264 pStatePage
->m_pSelectedState
= this->m_pSelectedState
; // = NULL
266 pStatePage
->Update();
273 void CStatesView::OnInitialUpdate()
275 CTreeView::OnInitialUpdate();
277 m_pSelectedEvent
= NULL
;
278 m_pSelectedState
= NULL
;