Linux multi-monitor fullscreen support
[ryzomcore.git] / nel / tools / logic / logic_editor_dll / CounterPage.cpp
blob8ca41516d16d488b6b2584cad3084047bf6956ac
1 // CounterPage.cpp : implementation file
2 //
4 #include "stdafx.h"
5 #include "logic_editor.h"
6 #include "CounterPage.h"
7 #include "Counter.h"
9 #include "MainFrm.h"
10 #include "ChildFrm.h"
11 #include "logic_editorDoc.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 // CCounterPage property page
23 IMPLEMENT_DYNCREATE(CCounterPage, CPropertyPage)
25 CCounterPage::CCounterPage() : CPropertyPage(CCounterPage::IDD)
27 //{{AFX_DATA_INIT(CCounterPage)
28 m_sMode = _T("Loop");
29 m_sWay = _T("Increment");
30 m_sCounterName = _T("");
31 m_nUpperLimit = 0;
32 m_nLowerLimit = 0;
33 //}}AFX_DATA_INIT
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);
51 //}}AFX_DATA_MAP
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)
61 //}}AFX_MSG_MAP
62 END_MESSAGE_MAP()
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 //---------------------------------------------------------
81 // addCounter
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
93 void * pointer;
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 );
99 // update page
100 UpdateData(FALSE);
102 } // addCounter //
106 //---------------------------------------------------------
107 // OnButtonAddCounter
109 //---------------------------------------------------------
110 void CCounterPage::OnButtonAddCounter()
112 UpdateData();
114 // if some infos are missing, do nothing
115 if (m_sCounterName.IsEmpty() )
117 return;
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());
126 ASSERT_VALID(pDoc);
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());
150 ASSERT_VALID(pDoc);
152 void *p;
153 if (pDoc->m_counters.Lookup( m_sCounterName, p) == FALSE)
155 return;
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();
166 UpdateData(FALSE);
173 void CCounterPage::OnButtonCounterRemove()
175 UpdateData();
177 //get the selected counter name
178 const int sel = m_counters.GetCurSel();
180 if (sel != LB_ERR)
182 CString name;
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());
190 ASSERT_VALID(pDoc);
192 pDoc->deleteCounter( name );
193 m_counters.DeleteString( sel );
195 else
197 AfxMessageBox(_T("No counter selected ! Choose a counter first"));
202 void CCounterPage::OnButtonCounterApply()
204 UpdateData();
206 //get the selected counter name
207 const int sel = m_counters.GetCurSel();
209 if (sel != LB_ERR)
211 CString name;
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());
219 ASSERT_VALID(pDoc);
221 if ( pDoc->changeCounterName( name, m_sCounterName ) == FALSE)
222 return;
224 CCounter *pCounter = NULL;
225 pDoc->m_counters.Lookup( m_sCounterName, (void*&)(pCounter) );
227 if (!pCounter)
228 return;
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 );
238 else
240 AfxMessageBox(_T("No counter selected ! Choose a counter first"));
247 //---------------------------------------------------------
248 // OnSetActive
250 //---------------------------------------------------------
251 BOOL CCounterPage::OnSetActive()
253 // get the child frame
254 CMainFrame *pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
255 CChildFrame *pChild = (CChildFrame *) pFrame->MDIGetActive();
257 // get the form view
258 CEditorFormView *pFormView = static_cast<CEditorFormView *> ( pChild->m_wndSplitter.GetPane(0,1) );
259 ASSERT_VALID(pFormView);
261 // get the document
262 CLogic_editorDoc * pDoc = (CLogic_editorDoc*)pFormView->GetDocument();
264 if( pDoc->InitConditionPage )
266 // init the counters
267 POSITION pos;
268 CString eltName;
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();
280 } // OnSetActive //