Linux multi-monitor fullscreen support
[ryzomcore.git] / nel / tools / logic / logic_editor_dll / StatesView.cpp
blobe466b99d8d2e1b985aba07ecb356d23aa87310f4
1 // StatesView.cpp : implementation file
2 //
4 #include "stdafx.h"
5 #include "logic_editor.h"
6 #include "StatesView.h"
9 #include "Logic_editorDoc.h"
10 #include "MainFrm.h"
11 #include "ChildFrm.h"
12 #include "EditorFormView.h"
14 #ifdef _DEBUG
15 #define new DEBUG_NEW
16 #undef THIS_FILE
17 static char THIS_FILE[] = __FILE__;
18 #endif
20 /////////////////////////////////////////////////////////////////////////////
21 // CStatesView
23 IMPLEMENT_DYNCREATE(CStatesView, CTreeView)
25 CStatesView::CStatesView()
29 CStatesView::~CStatesView()
34 BEGIN_MESSAGE_MAP(CStatesView, CTreeView)
35 //{{AFX_MSG_MAP(CStatesView)
36 ON_WM_KILLFOCUS()
37 ON_NOTIFY_REFLECT(TVN_SELCHANGED, OnSelchanged)
38 //}}AFX_MSG_MAP
39 END_MESSAGE_MAP()
41 /////////////////////////////////////////////////////////////////////////////
42 // CStatesView drawing
44 void CStatesView::OnDraw(CDC* pDC)
46 CDocument* pDoc = GetDocument();
47 // TODO: add draw code here
50 /////////////////////////////////////////////////////////////////////////////
51 // CStatesView diagnostics
53 #ifdef _DEBUG
54 void CStatesView::AssertValid() const
56 CTreeView::AssertValid();
59 void CStatesView::Dump(CDumpContext& dc) const
61 CTreeView::Dump(dc);
63 #endif //_DEBUG
72 void CStatesView::expand(UINT nCode, HTREEITEM hItem)
74 HTREEITEM hElement;
76 HTreeItemArray pile;
77 CTreeCtrl &m_tree = GetTreeCtrl();
79 if (hItem == NULL)
80 hElement = m_tree.GetRootItem();
81 else
83 m_tree.Expand(hItem,nCode);
84 hElement = m_tree.GetChildItem(hItem);
87 pile.RemoveAll();
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);
97 if (hElement)
99 pile.Add(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 *****/
118 SetRedraw(FALSE);
120 CTreeView::OnUpdate(pSender,lHint,pHint);
123 BOOL bSelection = FALSE;
126 CLogic_editorDoc *pDoc = static_cast<CLogic_editorDoc*>(GetDocument());
127 ASSERT_VALID(pDoc);
129 CTreeCtrl &m_tree = GetTreeCtrl();
131 m_tree.DeleteAllItems();
132 m_mapItemToEvent.RemoveAll();
134 m_tree.InsertItem(_T("States"));
136 // get the states map
137 CState *pState;
138 CString stateName;
139 POSITION pos = pDoc->m_states.GetStartPosition();
140 HTREEITEM hItem;
142 while (pos != NULL)
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);
151 bSelection = TRUE;
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 );
162 if (pEvent != NULL)
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);
170 bSelection = TRUE;
176 // expand all tree
177 expand(/*TVE_EXPAND ,NULL*/ );
180 if (!bSelection)
182 m_pSelectedEvent = NULL;
183 m_pSelectedState = NULL;
186 SetRedraw(/*TRUE*/);
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();
215 HTREEITEM hItem;
216 hItem = treeCtrl.GetSelectedItem();
219 if (hItem == treeCtrl.GetRootItem())
220 return;
222 // get the event selected (if any)
223 if ( ! m_mapItemToEvent.Lookup(hItem, m_pSelectedEvent) )
224 m_pSelectedEvent = NULL;
225 else
227 // nothing special
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();
270 *pResult = 0;
273 void CStatesView::OnInitialUpdate()
275 CTreeView::OnInitialUpdate();
277 m_pSelectedEvent = NULL;
278 m_pSelectedState = NULL;