-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTHEORY.CPP
279 lines (233 loc) · 6.53 KB
/
THEORY.CPP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
// Theory.cpp: implementation of the CTheory class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Virtual Robot.h"
#include "Theory.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CTheory::CTheory()
{
m_nActiveTab = 0;
}
CTheory::~CTheory()
{
while(!m_views.IsEmpty())
{
TCB_ITEM *pMember=m_views.RemoveHead();
delete pMember;
}
}
BEGIN_MESSAGE_MAP(CTheory, CSizingControlBar)
//{{AFX_MSG_MAP(CTheory)
ON_WM_CREATE()
ON_WM_SIZE()
ON_NOTIFY(TCN_SELCHANGE, 1155, OnTabSelChange)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Behandlungsroutinen für Nachrichten CTheory
int CTheory::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CSizingControlBar::OnCreate(lpCreateStruct) == -1)
return -1;
SetSCBStyle(GetSCBStyle() | SCBS_SIZECHILD);
//Create the Tab Control
CRect rect;
m_tabctrl.Create(WS_VISIBLE | WS_CHILD | TCS_BOTTOM,
rect, this, 1155);
m_images.Create(IDB_THEORY, 18, 18, RGB(255,255,255));
m_tabctrl.SetImageList(&m_images);
// set "normal" GUI-font
CFont *font = CFont::FromHandle((HFONT)::GetStockObject(DEFAULT_GUI_FONT));
m_tabctrl.SetFont(font);
return 0;
}
void CTheory::OnSize(UINT nType, int cx, int cy)
{
CSizingControlBar::OnSize(nType, cx, cy);
int bottom = (IsHorz() || IsFloating()) ? cy - 14 : cy - 18;
m_tabctrl.MoveWindow(7, 7, cx - 14, bottom);
CWnd *pWnd;
for (POSITION pos=m_views.GetHeadPosition(); pos; m_views.GetNext(pos))
{
pWnd=m_views.GetAt(pos)->pWnd;
pWnd->MoveWindow(9, 9, cx-19, bottom-26);
}
}
BOOL CTheory::AddView(LPCTSTR lpszLabel, CRuntimeClass *pViewClass, CCreateContext *pContext)
{
#ifdef _DEBUG
ASSERT_VALID(this);
ASSERT(pViewClass != NULL);
ASSERT(pViewClass->IsDerivedFrom(RUNTIME_CLASS(CWnd)));
ASSERT(AfxIsValidAddress(pViewClass, sizeof(CRuntimeClass), FALSE));
#endif
CCreateContext context;
if (pContext == NULL)
{
// if no context specified, generate one from the currently selected
// client if possible
CView* pOldView = NULL;
if (pOldView != NULL && pOldView->IsKindOf(RUNTIME_CLASS(CView)))
{
// set info about last pane
ASSERT(context.m_pCurrentFrame == NULL);
context.m_pLastView = pOldView;
context.m_pCurrentDoc = pOldView->GetDocument();
if (context.m_pCurrentDoc != NULL)
context.m_pNewDocTemplate =
context.m_pCurrentDoc->GetDocTemplate();
}
pContext = &context;
}
CWnd* pWnd;
TRY
{
pWnd = (CWnd*)pViewClass->CreateObject();
if (pWnd == NULL)
AfxThrowMemoryException();
}
CATCH_ALL(e)
{
TRACE0("Out of memory creating a view.\n");
// Note: DELETE_EXCEPTION(e) not required
return FALSE;
}
END_CATCH_ALL
ASSERT_KINDOF(CWnd, pWnd);
ASSERT(pWnd->m_hWnd == NULL); // not yet created
DWORD dwStyle = AFX_WS_DEFAULT_VIEW;
CRect rect;
// Create with the right size and position
if (!pWnd->Create(NULL, NULL, dwStyle, rect, this, 2667, pContext))
{
TRACE0("Warning: couldn't create client pane for view.\n");
// pWnd will be cleaned up by PostNcDestroy
return FALSE;
}
m_pActiveView = (CView*) pWnd;
TCB_ITEM *pMember=new TCB_ITEM;
pMember->pWnd=pWnd;
strcpy(pMember->szLabel, lpszLabel);
m_views.AddTail(pMember);
int nViews = m_views.GetCount();
if (nViews!=1)
{
pWnd->EnableWindow(FALSE);
pWnd->ShowWindow(SW_HIDE);
}
else
{
((CFrameWnd *)GetParent())->SetActiveView((CView *)m_pActiveView);
}
TC_ITEM tci;
tci.mask = TCIF_TEXT | TCIF_IMAGE;
tci.pszText = (LPTSTR)(LPCTSTR)lpszLabel;
tci.iImage = nViews-1;
m_tabctrl.InsertItem(nViews, &tci);
return TRUE;
}
void CTheory::RemoveView(int nView)
{
ASSERT_VALID(this);
ASSERT(nView >= 0);
// remove the page from internal list
m_views.RemoveAt(m_views.FindIndex(nView));
}
void CTheory::OnTabSelChange(NMHDR* pNMHDR, LRESULT* pResult)
{
SetActiveView(m_tabctrl.GetCurSel());
}
void CTheory::SetActiveView(int nNewTab)
{
ASSERT_VALID(this);
ASSERT(nNewTab >= 0);
if (nNewTab!=-1 && nNewTab!=m_nActiveTab)
{
TCB_ITEM *newMember=m_views.GetAt(m_views.FindIndex(nNewTab));
TCB_ITEM *oldMember=NULL;
if (m_nActiveTab!=-1)
{
oldMember=m_views.GetAt(m_views.FindIndex(m_nActiveTab));
oldMember->pWnd->EnableWindow(FALSE);
oldMember->pWnd->ShowWindow(SW_HIDE);
}
newMember->pWnd->EnableWindow(TRUE);
newMember->pWnd->ShowWindow(SW_SHOW);
newMember->pWnd->SetFocus();
m_pActiveView = (CView *)newMember->pWnd;
((CFrameWnd *)GetParent())->SetActiveView(m_pActiveView);
m_nActiveTab = nNewTab;
// select the tab (if tab programmatically changed)
m_tabctrl.SetCurSel(m_nActiveTab);
}
}
void CTheory::SetActiveView(CRuntimeClass *pViewClass)
{
ASSERT_VALID(this);
ASSERT(pViewClass != NULL);
ASSERT(pViewClass->IsDerivedFrom(RUNTIME_CLASS(CWnd)));
ASSERT(AfxIsValidAddress(pViewClass, sizeof(CRuntimeClass), FALSE));
int nNewTab = 0;
for (POSITION pos=m_views.GetHeadPosition(); pos; m_views.GetNext(pos))
{
TCB_ITEM *pMember=m_views.GetAt(pos);
if (pMember->pWnd->IsKindOf(pViewClass))
{
//first hide old first view
m_pActiveView->EnableWindow(FALSE);
m_pActiveView->ShowWindow(SW_HIDE);
// set new active view
m_pActiveView = (CView*)pMember->pWnd;
// enable, show, set focus to new view
m_pActiveView->EnableWindow(TRUE);
m_pActiveView->ShowWindow(SW_SHOW);
m_pActiveView->SetFocus();
((CFrameWnd *)GetParent())->SetActiveView(m_pActiveView);
m_nActiveTab = nNewTab;
// select the tab
m_tabctrl.SetCurSel(m_nActiveTab);
break;
}
nNewTab++;
}
}
CView* CTheory::GetActiveView()
{
return m_pActiveView;
}
CView* CTheory::GetView(int nView)
{
ASSERT_VALID(this);
ASSERT(nView >= 0);
if (nView!=-1)
{
TCB_ITEM *pMember=m_views.GetAt(m_views.FindIndex(nView));
return (CView*)pMember->pWnd;
}
else
return NULL;
}
CView* CTheory::GetView(CRuntimeClass *pViewClass)
{
ASSERT_VALID(this);
ASSERT(pViewClass != NULL);
ASSERT(pViewClass->IsDerivedFrom(RUNTIME_CLASS(CWnd)));
ASSERT(AfxIsValidAddress(pViewClass, sizeof(CRuntimeClass), FALSE));
for (POSITION pos=m_views.GetHeadPosition(); pos; m_views.GetNext(pos))
{
TCB_ITEM *pMember=m_views.GetAt(pos);
if (pMember->pWnd->IsKindOf(pViewClass))
{
return (CView*)pMember->pWnd;
}
}
return NULL;
}