-
Notifications
You must be signed in to change notification settings - Fork 0
/
MAINFRM.CPP
523 lines (432 loc) · 15.8 KB
/
MAINFRM.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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
// mainfrm.cpp : implementation of the CMainFrame class
//
// This is a part of the Microsoft Foundation Classes C++ library.
// Copyright (C) 1992-1993 Microsoft Corporation
// All rights reserved.
//
// This source code is only intended as a supplement to the
// Microsoft Foundation Classes Reference and Microsoft
// QuickHelp and/or WinHelp documentation provided with the library.
// See these sources for detailed information regarding the
// Microsoft Foundation Classes product.
#include "stdafx.h"
#include "train.h"
//#include "tooltip.h"
// TABVIEW: Ordner
#include "mainview.h"
#include "basevw.h"
#include "pagevw.h"
#include "persist.h"
#include "mainfrm.h"
#include "Net_Ed.h"
//#include "Net_Use.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNAMIC(CMainFrame, CMDIPersistentFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CMDIPersistentFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code !
ON_COMMAND(ID_VIEW_NETZ_EDIT, OnViewNetzEdit)
// ON_COMMAND(ID_VIEW_NETZ_USE , OnViewNetzUse)
ON_WM_SYSCOLORCHANGE()
ON_WM_CREATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// arrays of IDs used to initialize control bars
// toolbar buttons - IDs are command buttons
static UINT BASED_CODE buttons[] = // Mainframe
{
// same order as in the bitmap 'toolbar.bmp'
ID_FILE_NEW,
ID_FILE_OPEN,
ID_FILE_SAVE,
ID_SEPARATOR,
ID_APP_ABOUT,
ID_SEPARATOR,
ID_HUNDERTPROZENT,
ID_ZOOM,
ID_SEPARATOR,
ID_EDIT_CUT,
ID_EDIT_COPY,
ID_EDIT_PASTE,
ID_SEPARATOR,
ID_DRAW_SELECT,
ID_SEPARATOR,
ID_SEPARATOR, // Gruppe mit Seiten (was ist, wenn Untergruppen bestehen ?).
ID_SEPARATOR,
ID_SEITE_HOME, // Seitenoperationen für jede View, wenn möglich
ID_SEITE_DN,
ID_DELETE_SEITE,
ID_NEU_SEITE,
ID_SEITE_UP,
ID_SEITE_END,
};
// toolbar buttons - IDs are command buttons
static UINT BASED_CODE tools[] = // Netz editieren
{
// same order as in the bitmap 'toolbar.bmp'
ID_DRAW_TEXT,
//ID_DRAW_TEXT_SENKRECHT,
ID_SEPARATOR,
ID_DRAW_ADD_ELEMENT,
ID_SEPARATOR,
ID_DRAW_BAHNHOF,
ID_CONNECT_BAHNHOF,
ID_SEPARATOR,
ID_DRAW_MAKE_FAHRPLAN,
ID_CHOOSE_FAHRKARTE,
ID_SEPARATOR,
ID_FILE_PRINT,
};
// toolbar buttons - IDs are command buttons
static UINT BASED_CODE toolsfahrplan[] = // Netz editieren
{
// same order as in the bitmap 'toolbar.bmp'
ID_DRAW_TABELLE,
ID_EDIT_TABELLE,
ID_SEPARATOR,
ID_ADD_FAHRT,
ID_ADD_REVERS_FAHRPLAN,
ID_FILE_PRINT,
};
// toolbar buttons - IDs are command buttons
static UINT BASED_CODE windowtools[] = // Window
{
// same order as in the bitmap 'toolbar.bmp'
ID_CREATE_WINDOW,
ID_SEPARATOR,
ID_FILE_PRINT,
};
// toolbar buttons - IDs are command buttons
static UINT BASED_CODE bendeftools[] = // Benutzerdefinierte Objekte
{
// same order as in the bitmap 'toolbar.bmp'
ID_SEPARATOR,
ID_SEPARATOR,
ID_SEPARATOR,
ID_DRAW_LINE,
ID_DRAW_RECT,
ID_DRAW_ROUNDRECT,
ID_DRAW_CIRCLE,
ID_DRAW_POLYGON,
ID_SEPARATOR,
ID_DRAW_ADD_ELEMENT,
ID_DRAW_ATTRIBUTE,
ID_SEPARATOR,
ID_FILE_PRINT,
};
// toolbar buttons - IDs are command buttons
static UINT BASED_CODE kundentools[] = // Benutzerdefinierte Objekte
{
// same order as in the bitmap 'toolbar.bmp'
ID_NEU_KUNDE,
ID_DELETE_KUNDE,
ID_SEPARATOR,
ID_FILE_PRINT,
};
static UINT BASED_CODE indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_SEPARATOR, // Last action
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
}
CMainFrame::~CMainFrame()
{
}
BOOL CMainFrame::OnViewBar(UINT nID)
{
CWnd* pBar;
if ((pBar = GetDlgItem(nID)) == NULL) return FALSE;
pBar->ShowWindow((pBar->GetStyle() & WS_VISIBLE) == 0);
if ((pBar->GetStyle() & WS_VISIBLE) == 0) return FALSE;
RecalcLayout();
return TRUE;
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!CreateToolBar())
return -1;
if (!CreateBenDefBar())
return -1;
if (!CreateKundenBar())
return -1;
// Schienennetz editieren
if (!m_wndNetzEditBar.Create(this, WS_CHILD|CBRS_TOP, IDW_EDIT) ||
!m_wndNetzEditBar.LoadBitmap(IDR_DRAWCLTYPE) ||
!m_wndNetzEditBar.SetButtons(tools,
sizeof(tools)/sizeof(UINT)))
{
TRACE("Failed to create toolbar\n");
return -1; // fail to create
}
if (!m_wndFahrplanBar.Create(this, WS_CHILD|CBRS_TOP, IDW_FAHRPLAN) ||
!m_wndFahrplanBar.LoadBitmap(IDR_DRAWCLTYPEFAHRPLAN) ||
!m_wndFahrplanBar.SetButtons(toolsfahrplan,
sizeof(toolsfahrplan)/sizeof(UINT)))
{
TRACE("Failed to create toolbar\n");
return -1; // fail to create
}
// Schienennetz benutzen (Fahrkarten auswählen etc.)
// Fenster mit Dialog - Elementen
if (!m_wndWindowBar.Create(this, WS_CHILD|CBRS_TOP, IDW_WINDOW) ||
!m_wndWindowBar.LoadBitmap(IDR_DRAWCLTYPEWINDOW) ||
!m_wndWindowBar.SetButtons(windowtools,
sizeof(windowtools)/sizeof(UINT)))
{
TRACE("Failed to create toolbar\n");
return -1; // fail to create
}
if (!m_wndStatusBar.Create(this))
{
TRACE("Failed to create status bar\n");
return -1; // fail to create
}
if (!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE("Failed to create status bar\n");
return -1; // fail to create
}
return 0;
}
BOOL CMainFrame::CreateToolBar()
{
if (!m_wndToolBar.Create(this) ||
!m_wndToolBar.LoadBitmap(IDR_MAINFRAME) ||
!m_wndToolBar.SetButtons(buttons,
sizeof(buttons)/sizeof(UINT)))
{
TRACE("Failed to create toolbar\n");
return -1; // fail to create
}
// Design guide advises 12 pixel gap between combos and buttons
m_wndToolBar.SetButtonInfo(14, ID_SEPARATOR, TBBS_SEPARATOR, 12 );
// Create the combo box
m_wndToolBar.SetButtonInfo(15, IDW_TOOLCOMBO, TBBS_SEPARATOR, 100 );
// Design guide advises 12 pixel gap between combos and buttons
m_wndToolBar.SetButtonInfo(16, ID_SEPARATOR, TBBS_SEPARATOR, 12 );
CRect rect;
m_wndToolBar.GetItemRect( 15, &rect);
rect.top = 1;
rect.bottom = rect.top + 100;
if (!m_wndToolBar.m_comboBox.Create(CBS_DROPDOWNLIST|WS_VISIBLE|WS_TABSTOP,
rect, &m_wndToolBar, IDW_TOOLCOMBO))
{
TRACE("Failed to create combo-box\n");
return FALSE;
}
// Fill the combo box
m_wndToolBar.m_comboBox.AddString("Gruppen");
m_wndToolBar.m_comboBox.AddString("Seiten");
// Create a font for the combobox
LOGFONT logFont;
memset(&logFont, 0, sizeof(logFont));
// Since design guide says toolbars are fixed height so is the font.
logFont.lfHeight = -13;
logFont.lfWeight = FW_NORMAL;
logFont.lfPitchAndFamily = VARIABLE_PITCH | FF_SWISS;
lstrcpy(logFont.lfFaceName, "MS Sans Serif");
if (!m_wndToolBar.m_font.CreateFontIndirect(&logFont))
TRACE("Could Not create font for combo\n");
else
m_wndToolBar.m_comboBox.SetFont(&m_wndToolBar.m_font);
return TRUE;
}
BOOL CMainFrame::CreateBenDefBar()
{
if (!m_wndBenDefBar.Create(this,WS_CHILD|CBRS_TOP, IDW_BENDEF) ||
!m_wndBenDefBar.LoadBitmap(IDR_DRAWCLTYPEBENDEF) ||
!m_wndBenDefBar.SetButtons(bendeftools,
sizeof(bendeftools)/sizeof(UINT)))
{
TRACE("Failed to create stylebar\n");
return FALSE; // fail to create
}
// Create the combo box
m_wndBenDefBar.SetButtonInfo(1, IDW_BENDEFCOMBO, TBBS_SEPARATOR, 100 );
// Design guide advises 12 pixel gap between combos and buttons
m_wndBenDefBar.SetButtonInfo(2, ID_SEPARATOR, TBBS_SEPARATOR, 12 );
CRect rect;
m_wndBenDefBar.GetItemRect( 1, &rect);
rect.top = 1;
rect.bottom = rect.top + 100;
if (!m_wndBenDefBar.m_comboBox.Create(CBS_DROPDOWNLIST|WS_VISIBLE|WS_TABSTOP,
rect, &m_wndBenDefBar, IDW_BENDEFCOMBO))
{
TRACE("Failed to create combo-box\n");
return FALSE;
}
// Fill the combo box
m_wndBenDefBar.m_comboBox.AddString("Bahnhöfe");
m_wndBenDefBar.m_comboBox.AddString("Strecken");
m_wndBenDefBar.m_comboBox.AddString("Kunden - Tabellen");
m_wndBenDefBar.m_comboBox.AddString("Fahrpläne");
// Create a font for the combobox
LOGFONT logFont;
memset(&logFont, 0, sizeof(logFont));
// Since design guide says toolbars are fixed height so is the font.
logFont.lfHeight = -13;
logFont.lfWeight = FW_NORMAL;
logFont.lfPitchAndFamily = VARIABLE_PITCH | FF_SWISS;
lstrcpy(logFont.lfFaceName, "MS Sans Serif");
if (!m_wndBenDefBar.m_font.CreateFontIndirect(&logFont))
TRACE("Could Not create font for combo\n");
else
m_wndBenDefBar.m_comboBox.SetFont(&m_wndBenDefBar.m_font);
return TRUE;
}
BOOL CMainFrame::CreateKundenBar()
{
if (!m_wndKundenBar.Create(this,WS_CHILD|CBRS_TOP, IDW_KUNDEN) ||
!m_wndKundenBar.LoadBitmap(IDR_DRAWCLTYPEKUNDEN) ||
!m_wndKundenBar.SetButtons(kundentools,
sizeof(kundentools)/sizeof(UINT)))
{
TRACE("Failed to create stylebar\n");
return FALSE; // fail to create
}
// Create the combo box
m_wndKundenBar.SetButtonInfo(1, IDW_KUNDENCOMBO, TBBS_SEPARATOR, 100 );
// Design guide advises 12 pixel gap between combos and buttons
m_wndKundenBar.SetButtonInfo(2, ID_SEPARATOR, TBBS_SEPARATOR, 12 );
CRect rect;
m_wndKundenBar.GetItemRect( 1, &rect);
rect.top = 1;
rect.bottom = rect.top + 100;
if (!m_wndKundenBar.m_comboBox.Create(CBS_DROPDOWNLIST|WS_VISIBLE|WS_TABSTOP,
rect, &m_wndKundenBar, IDW_KUNDENCOMBO))
{
TRACE("Failed to create combo-box\n");
return FALSE;
}
// Fill the combo box
m_wndKundenBar.m_comboBox.AddString("Stammkunden");
m_wndKundenBar.m_comboBox.AddString("Gruppen");
// Create a font for the combobox
LOGFONT logFont;
memset(&logFont, 0, sizeof(logFont));
// Since design guide says toolbars are fixed height so is the font.
logFont.lfHeight = -13;
logFont.lfWeight = FW_NORMAL;
logFont.lfPitchAndFamily = VARIABLE_PITCH | FF_SWISS;
lstrcpy(logFont.lfFaceName, "MS Sans Serif");
if (!m_wndKundenBar.m_font.CreateFontIndirect(&logFont))
TRACE("Could Not create font for combo\n");
else
m_wndKundenBar.m_comboBox.SetFont(&m_wndKundenBar.m_font);
return TRUE;
}
CView* CMainFrame::FindView(CRuntimeClass* pViewClass)
{
// If a check view or book view (specified by pViewClass)
// already exists, then activate the MDI child window containing
// the view. Otherwise, create a new view for the document.
CMDIChildWnd* pMDIActive = MDIGetActive();
ASSERT(pMDIActive != NULL);
CDocument* pDoc = pMDIActive->GetActiveDocument();
ASSERT(pDoc != NULL);
CView* pView;
POSITION pos = pDoc->GetFirstViewPosition();
while (pos != NULL)
{
pView = pDoc->GetNextView(pos);
if (pView->IsKindOf(pViewClass))
{
return pView;
}
}
return NULL;
}
void CMainFrame::CreateOrActivateFrame(CDocTemplate* pTemplate,
CRuntimeClass* pViewClass)
{
// If a check view or book view (specified by pViewClass)
// already exists, then activate the MDI child window containing
// the view. Otherwise, create a new view for the document.
CMDIChildWnd* pMDIActive = MDIGetActive();
ASSERT(pMDIActive != NULL);
CDocument* pDoc = pMDIActive->GetActiveDocument();
ASSERT(pDoc != NULL);
CView* pView;
POSITION pos = pDoc->GetFirstViewPosition();
while (pos != NULL)
{
pView = pDoc->GetNextView(pos);
if (pView->IsKindOf(pViewClass))
{
pView->GetParentFrame()->ActivateFrame();
return;
}
}
CMDIChildWnd* pNewFrame = (CMDIChildWnd*)pTemplate->CreateNewFrame(pDoc, NULL);
if (pNewFrame == NULL)
return; // not created
ASSERT(pNewFrame->IsKindOf(RUNTIME_CLASS(CMDIChildWnd)));
pTemplate->InitialUpdateFrame(pNewFrame, pDoc);
MDITile(MDITILE_HORIZONTAL);
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame commands
void CMainFrame::OnViewNetzEdit()
{
CreateOrActivateFrame(theApp.m_pNetzEditViewTemplate,
RUNTIME_CLASS(CNetEd));
}
//TABVIEW: Ordner
BOOL CMainFrame::OnSwitchTabs(UINT nID)
{
CMDIChildWnd* pChild = MDIGetActive();
ASSERT(pChild != NULL);
CView* pView = (CView*)(pChild->GetActiveView());
ASSERT(pView != NULL);
CMainView* pMainView = (CMainView*)pView->GetParent();
ASSERT(pMainView != NULL);
if(!pMainView->IsKindOf(RUNTIME_CLASS(CMainView)))
return 0;
switch(nID)
{
case ID_GRAPHICS:
pMainView->switchTab(0);
break;
case ID_TIMELINE:
pMainView->switchTab(1);
break;
}
return 1;
}
void CMainFrame::OnSysColorChange()
{
CMDIFrameWnd::OnSysColorChange();
Ctl3dColorChange();
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CMDIFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CMDIFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers