]> Shamusworld >> Repos - guemap/blob - src/mainwin.cpp
186e085917129d204280aa6ad549ba69cb6cf725
[guemap] / src / mainwin.cpp
1 //
2 // GUEmap
3 // Copyright 1997-2007 by Christopher J. Madsen
4 // (C) 2019 James Hammons
5 //
6 // GUEmap is licensed under either version 2 of the GPL, or (at your option)
7 // any later version.  See LICENSE file for details.
8 //
9 // mainwin.cpp: implementation of the MainWin class
10 //
11
12 #include "mainwin.h"
13 #include "about.h"
14 #include "file.h"
15 #include "globals.h"
16 #include "mapdoc.h"
17 #include "mapview.h"
18 #include "roomwidget.h"
19 #include "undo.h"
20
21 // CMainWin
22
23 #if 0
24 IMPLEMENT_DYNAMIC(CMainWin, CMDIFrameWnd)
25
26 BEGIN_MESSAGE_MAP(CMainWin, CMDIFrameWnd)
27         //{{AFX_MSG_MAP(CMainWin)
28         ON_WM_ACTIVATEAPP()
29         ON_WM_CREATE()
30         ON_WM_DESTROY()
31         //}}AFX_MSG_MAP
32         // Global help commands
33         ON_COMMAND(ID_HELP_FINDER, CMDIFrameWnd::OnHelpFinder)
34         ON_COMMAND(ID_HELP, CMDIFrameWnd::OnHelp)
35         ON_COMMAND(ID_CONTEXT_HELP, CMDIFrameWnd::OnContextHelp)
36         ON_COMMAND(ID_DEFAULT_HELP, CMDIFrameWnd::OnHelpFinder)
37   // Toggle the navigation bar:
38   ON_UPDATE_COMMAND_UI(ID_VIEW_NAVBAR, OnUpdateControlBarMenu)
39   ON_COMMAND_EX(ID_VIEW_NAVBAR, OnBarCheck)
40 END_MESSAGE_MAP();
41
42 static UINT indicators[] =
43 {
44         ID_SEPARATOR,           // status line indicator
45         ID_INDICATOR_CAPS,
46         ID_INDICATOR_NUM,
47         ID_INDICATOR_SCRL,
48 };
49 #endif
50
51 MainWin::MainWin(): settings("Underground Software", "GUEmap")
52 {
53         setCentralWidget(&mdiArea);
54         mdiArea.setViewMode(QMdiArea::TabbedView);
55         mdiArea.setTabsClosable(true);
56
57         setWindowIcon(QIcon(":/res/guemap.ico"));
58         setWindowTitle("GUEmap");
59
60         aboutWin = new AboutWindow(this);
61
62         CreateActions();
63         CreateMenus();
64         CreateToolbars();
65
66         undoAct->setEnabled(false);
67         statusBar()->showMessage(tr("Ready"));
68
69         ReadSettings();
70
71         // Create Dock widgets
72         QDockWidget * dock1 = new QDockWidget(tr("Rooms"), this);
73         /*RoomWidget * */rw = new RoomWidget;
74         dock1->setWidget(rw);
75         addDockWidget(Qt::RightDockWidgetArea, dock1);
76 //      QDockWidget * dock2 = new QDockWidget(tr("Blocks"), this);
77 //      BlockWidget * bw = new BlockWidget;
78 //      dock2->setWidget(bw);
79 //      addDockWidget(Qt::RightDockWidgetArea, dock2);
80 //      QDockWidget * dock3 = new QDockWidget(tr("Object"), this);
81 //      ObjectWidget * ow = new ObjectWidget;
82 //      dock3->setWidget(ow);
83 //      addDockWidget(Qt::RightDockWidgetArea, dock3);
84         // Needed for saveState()
85         dock1->setObjectName("Rooms");
86 //      dock2->setObjectName("Blocks");
87 //      dock3->setObjectName("Object");
88
89         // Create status bar
90 //      zoomIndicator = new QLabel("Grid: 12.0\" BU: Inch");
91 //      statusBar()->addPermanentWidget(zoomIndicator);
92 //      statusBar()->showMessage(tr("Ready"));
93
94 //      ReadSettings();
95 //      setUnifiedTitleAndToolBarOnMac(true);
96 //      Global::font =  new QFont("Verdana", 15, QFont::Bold);
97
98 //      connect(lw, SIGNAL(LayerDeleted(int)), drawing, SLOT(DeleteCurrentLayer(int)));
99 //      connect(lw, SIGNAL(LayerToggled()), drawing, SLOT(HandleLayerToggle()));
100 //      connect(lw, SIGNAL(LayersSwapped(int, int)), drawing, SLOT(HandleLayerSwap(int, int)));
101
102 //      connect(drawing, SIGNAL(ObjectHovered(Object *)), ow, SLOT(ShowInfo(Object *)));
103
104 }
105
106 void MainWin::closeEvent(QCloseEvent * event)
107 {
108         WriteSettings();
109         event->accept();                // Use ignore() if can't close for some reason
110         //Do we have a memory leak here if we don't delete the font in the Object???
111 }
112
113 void MainWin::FileNew(void)
114 {
115         MapView * map = new MapView;
116         map->setWindowTitle("Untitled");
117         map->clearSelection();
118         QMdiSubWindow * sw = mdiArea.addSubWindow(map);
119         mdiArea.setActiveSubWindow(sw);
120         sw->showMaximized();
121         sw->update();
122
123         connect(map, SIGNAL(RoomClicked(MapDoc *, int)), rw, SLOT(ShowInfo(MapDoc *, int)));
124
125         statusBar()->showMessage(tr("New map created."), 2000);
126 }
127
128 void MainWin::FileOpen(void)
129 {
130         QString filename = QFileDialog::getOpenFileName(this, tr("Open Map"), "",
131                 tr("GUEmap files (*.gmp)"));
132
133         // User cancelled open
134         if (filename.isEmpty())
135                 return;
136
137         LoadFile(filename.toUtf8().data());
138 }
139
140 void MainWin::FileOpenRecent(void)
141 {
142         QAction * action = qobject_cast<QAction *>(sender());
143
144         if (!action)
145                 return;
146
147         LoadFile(action->data().toString());
148 }
149
150 void MainWin::LoadFile(QString filename)
151 {
152         MapView * map = new MapView;
153         bool successful = ReadFile(map->doc, filename.toUtf8().data());
154
155         if (!successful)
156         {
157                 // Make sure to delete any hanging objects in the container...
158                 delete map;
159
160                 QMessageBox msg;
161                 msg.setText(QString(tr("Could not load file \"%1\"!")).arg(filename));
162                 msg.setIcon(QMessageBox::Critical);
163                 msg.exec();
164
165                 return;
166         }
167
168         map->doc->filename = filename.toStdString();
169         map->setWindowTitle(map->doc->name.c_str());
170         map->clearSelection();
171         QMdiSubWindow * sw = mdiArea.addSubWindow(map);
172         mdiArea.setActiveSubWindow(sw);
173         sw->showMaximized();
174         sw->update();
175
176         connect(map, SIGNAL(RoomClicked(MapDoc *, int)), rw, SLOT(ShowInfo(MapDoc *, int)));
177
178         AdjustMRU(filename);
179         statusBar()->showMessage(tr("Map loaded."), 2000);
180 }
181
182 void MainWin::FileSaveBase(MapView * map, QString filename)
183 {
184         if (filename.endsWith(".gmp") == false)
185                 filename += ".gmp";
186
187         bool successful = WriteFile(map->doc, filename.toUtf8().data());
188
189         if (!successful)
190         {
191                 // In this case, we should unlink the created file, since it's not
192                 // right...
193                 QFile::remove(filename);
194
195                 QMessageBox msg;
196                 msg.setText(QString(tr("Could not save file \"%1\"!")).arg(filename));
197                 msg.setIcon(QMessageBox::Critical);
198                 msg.exec();
199                 return;
200         }
201
202         map->doc->filename = filename.toStdString();
203         map->doc->isDirty = false;
204         statusBar()->showMessage(tr("Map saved."), 2000);
205 }
206
207 void MainWin::FileSave(void)
208 {
209         QMdiSubWindow * sw = mdiArea.activeSubWindow();
210         MapView * map = (MapView *)(sw->widget());
211         QString filename = map->doc->filename.c_str();
212
213         if (filename.isEmpty())
214         {
215                 filename = QFileDialog::getSaveFileName(this, tr("Save Map"), "",
216                         tr("GUEmap maps (*.gmp)"));
217
218                 // Bail if the user clicked "Cancel"
219                 if (filename.isEmpty())
220                         return;
221         }
222
223         FileSaveBase(map, filename);
224 }
225
226 void MainWin::FileSaveAs(void)
227 {
228         QMdiSubWindow * sw = mdiArea.activeSubWindow();
229         MapView * map = (MapView *)(sw->widget());
230 //      QString filename = map->doc->filename.c_str();
231
232         QString filename = QFileDialog::getSaveFileName(this, tr("Save Map As"),
233                 map->doc->filename.c_str(), tr("GUEmap maps (*.gmp)"));
234
235         // Bail if the user clicked "Cancel"
236         if (filename.isEmpty())
237                 return;
238
239         FileSaveBase(map, filename);
240 }
241
242 void MainWin::FileClose(void)
243 {
244         QMdiSubWindow * sw = mdiArea.activeSubWindow();
245         MapView * map = (MapView *)(sw->widget());
246
247         if (map->doc->isDirty)
248         {
249                 QMessageBox msg;
250                 msg.setText(tr("The map has been modified."));
251                 msg.setInformativeText(tr("Do you want to save your changes?"));
252                 msg.setStandardButtons(QMessageBox::Save | QMessageBox::Discard);
253                 msg.setDefaultButton(QMessageBox::Save);
254                 msg.setIcon(QMessageBox::Warning);
255
256                 int response = msg.exec();
257
258                 if (response == QMessageBox::Save)
259                         FileSave();
260         }
261
262         sw->close();
263         statusBar()->showMessage(tr("Map closed."), 2000);
264 }
265
266 void MainWin::EditUndo(void)
267 {
268         QMdiSubWindow * sw = mdiArea.activeSubWindow();
269
270         if (sw == 0)
271                 return;
272
273         MapView * map = (MapView *)(sw->widget());
274
275         if (map == 0)
276                 return;
277
278         if (map->doc->undoData != 0)
279         {
280                 map->doc->setUndoData(map->doc->undoData->undo(*(map->doc)));
281                 statusBar()->showMessage(tr("Undo successful."));
282                 map->update();
283                 return;
284         }
285
286         statusBar()->showMessage(tr("Ready."));
287 }
288
289 void MainWin::MenuFixUndo(void)
290 {
291         QMdiSubWindow * sw = mdiArea.activeSubWindow();
292
293         if (sw == 0)
294                 return;
295
296         MapView * map = (MapView *)(sw->widget());
297         UndoRec * undo = map->doc->undoData;
298
299         if (undo)
300         {
301                 undoAct->setText(QString(tr("&Undo %1")).arg(undo->getName()));
302                 undoAct->setEnabled(true);
303         }
304         else
305         {
306                 undoAct->setText(tr("Can't Undo"));
307                 undoAct->setEnabled(false);
308         }
309 }
310
311 void MainWin::EditDelete(void)
312 {
313         QMdiSubWindow * sw = mdiArea.activeSubWindow();
314
315         if (sw == 0)
316                 return;
317
318         MapView * map = (MapView *)(sw->widget());
319
320         if (map == 0)
321                 return;
322
323         map->deleteSelection();
324         map->update();
325 }
326
327 void MainWin::EditSelectAll(void)
328 {
329         QMdiSubWindow * sw = mdiArea.activeSubWindow();
330
331         if (sw == 0)
332                 return;
333
334         MapView * map = (MapView *)(sw->widget());
335
336         if (map == 0)
337                 return;
338
339         for(int i=map->doc->room.size()-1; i>=0; i--)
340                 map->selectRoom(i);
341
342         map->update();
343 }
344
345 void MainWin::HelpAbout(void)
346 {
347         aboutWin->show();
348 }
349
350 void MainWin::CreateActions(void)
351 {
352         fileNewAct = CreateAction(tr("&New Map"), tr("New Map"), tr("Creates a new map."), QIcon(":/res/file-new.png"), QKeySequence(tr("Ctrl+n")));
353         connect(fileNewAct, SIGNAL(triggered()), this, SLOT(FileNew()));
354
355         fileOpenAct = CreateAction(tr("&Open Map"), tr("Open Map"), tr("Opens an existing map from a file."), QIcon(":/res/file-open.png"), QKeySequence(tr("Ctrl+o")));
356         connect(fileOpenAct, SIGNAL(triggered()), this, SLOT(FileOpen()));
357
358         fileSaveAct = CreateAction(tr("&Save Map"), tr("Save Map"), tr("Saves the current map to a file."), QIcon(":/res/file-save.png"), QKeySequence(tr("Ctrl+s")));
359         connect(fileSaveAct, SIGNAL(triggered()), this, SLOT(FileSave()));
360
361         fileSaveAsAct = CreateAction(tr("Save Map &As"), tr("Save As"), tr("Saves the current map to a file with a different name."), QIcon(":/res/file-save-as.png"), QKeySequence(tr("Ctrl+Shift+s")));
362         connect(fileSaveAsAct, SIGNAL(triggered()), this, SLOT(FileSaveAs()));
363
364         fileCloseAct = CreateAction(tr("&Close Map"), tr("Close Map"), tr("Closes the current map."), QIcon(":/res/file-close.png"), QKeySequence(tr("Ctrl+c")));
365         connect(fileCloseAct, SIGNAL(triggered()), this, SLOT(FileClose()));
366
367         exitAct = CreateAction(tr("&Quit"), tr("Quit"), tr("Exits the application."), QIcon(":/res/quit.png"), QKeySequence(tr("Ctrl+q")));
368         connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
369
370         undoAct = CreateAction(tr("&Undo"), tr("Undo"), tr("Undoes the last action."), QIcon(), QKeySequence(tr("Ctrl+z")));
371         connect(undoAct, SIGNAL(triggered()), this, SLOT(EditUndo()));
372
373         deleteAct = CreateAction(tr("&Delete"), tr("Delete"), tr("Deletes the selected items."), QIcon(), QKeySequence(tr("Delete")));
374         connect(deleteAct, SIGNAL(triggered()), this, SLOT(EditDelete()));
375
376         selectAllAct = CreateAction(tr("Select &All"), tr("Select All"), tr("Selects all items."), QIcon(), QKeySequence(tr("Ctrl+a")));
377         connect(selectAllAct, SIGNAL(triggered()), this, SLOT(EditSelectAll()));
378
379         aboutAct = CreateAction(tr("About &GUEmap"), tr("About GUEmap"), tr("Gives information about this program."), QIcon(), QKeySequence());
380         connect(aboutAct, SIGNAL(triggered()), this, SLOT(HelpAbout()));
381
382         for(int i=0; i<MRU_MAX; i++)
383         {
384                 QAction * rfa = new QAction(this);
385                 rfa->setVisible(false);
386                 connect(rfa, SIGNAL(triggered()), this, SLOT(FileOpenRecent()));
387                 mruAct.append(rfa);
388         }
389 }
390
391 void MainWin::CreateMenus(void)
392 {
393         QMenu * menu = menuBar()->addMenu(tr("&File"));
394         menu->addAction(fileNewAct);
395         menu->addAction(fileOpenAct);
396
397         QMenu * recentMenu = menu->addMenu(tr("Open &Recent"));
398
399         for(int i=0; i<MRU_MAX; i++)
400                 recentMenu->addAction(mruAct.at(i));
401
402         UpdateMRUActionList();
403
404         menu->addAction(fileSaveAct);
405         menu->addAction(fileSaveAsAct);
406         menu->addAction(fileCloseAct);
407         menu->addSeparator();
408         menu->addAction(exitAct);
409
410         menu = menuBar()->addMenu(tr("&Edit"));
411         menu->addAction(undoAct);
412         connect(menu, SIGNAL(aboutToShow()), this, SLOT(MenuFixUndo()));
413         menu->addSeparator();
414         menu->addAction(deleteAct);
415         menu->addAction(selectAllAct);
416 #if 0
417         menu = menuBar()->addMenu(tr("&View"));
418         menu->addAction(zoomInAct);
419         menu->addAction(zoomOutAct);
420
421         // EDIT
422         menu->addAction(snapToGridAct);
423         menu->addAction(groupAct);
424         menu->addAction(fixAngleAct);
425         menu->addAction(fixLengthAct);
426         menu->addAction(rotateAct);
427         menu->addAction(mirrorAct);
428         menu->addAction(trimAct);
429         menu->addAction(triangulateAct);
430         menu->addAction(connectAct);
431         menu->addAction(disconnectAct);
432         menu->addSeparator();
433         menu->addAction(addLineAct);
434         menu->addAction(addCircleAct);
435         menu->addAction(addArcAct);
436         menu->addAction(addPolygonAct);
437         menu->addAction(addSplineAct);
438         menu->addAction(addDimensionAct);
439         menu->addSeparator();
440         menu->addAction(settingsAct);
441 #endif
442
443         menu = menuBar()->addMenu(tr("&Help"));
444         menu->addAction(aboutAct);
445 }
446
447 void MainWin::CreateToolbars(void)
448 {
449 #if 0
450         QToolBar * toolbar = addToolBar(tr("File"));
451         toolbar->setObjectName("File"); // Needed for saveState()
452         toolbar->addAction(fileNewAct);
453         toolbar->addAction(fileOpenAct);
454         toolbar->addAction(fileSaveAct);
455         toolbar->addAction(fileSaveAsAct);
456         toolbar->addAction(fileCloseAct);
457 //      toolbar->addAction(exitAct);
458
459         toolbar = addToolBar(tr("View"));
460         toolbar->setObjectName("View");
461         toolbar->addAction(zoomInAct);
462         toolbar->addAction(zoomOutAct);
463
464         QSpinBox * spinbox = new QSpinBox;
465         toolbar->addWidget(spinbox);
466 //      QLineEdit * lineedit = new QLineEdit;
467         toolbar->addWidget(baseUnitInput);
468         toolbar->addWidget(dimensionSizeInput);
469
470         toolbar = addToolBar(tr("Edit"));
471         toolbar->setObjectName("Edit");
472         toolbar->addAction(snapToGridAct);
473         toolbar->addAction(groupAct);
474         toolbar->addAction(fixAngleAct);
475         toolbar->addAction(fixLengthAct);
476         toolbar->addAction(rotateAct);
477         toolbar->addAction(mirrorAct);
478         toolbar->addAction(trimAct);
479         toolbar->addAction(triangulateAct);
480         toolbar->addAction(deleteAct);
481         toolbar->addAction(connectAct);
482         toolbar->addAction(disconnectAct);
483         toolbar->addSeparator();
484         toolbar->addAction(addLineAct);
485         toolbar->addAction(addCircleAct);
486         toolbar->addAction(addArcAct);
487         toolbar->addAction(addPolygonAct);
488         toolbar->addAction(addSplineAct);
489         toolbar->addAction(addDimensionAct);
490
491         spinbox->setRange(4, 256);
492         spinbox->setValue(12);
493         baseUnitInput->setText("12");
494         connect(spinbox, SIGNAL(valueChanged(int)), this, SLOT(HandleGridSizeInPixels(int)));
495         connect(baseUnitInput, SIGNAL(textChanged(QString)), this, SLOT(HandleGridSizeInBaseUnits(QString)));
496         connect(dimensionSizeInput, SIGNAL(textChanged(QString)), this, SLOT(HandleDimensionSize(QString)));
497
498         PenWidget * pw = new PenWidget();
499         toolbar = addToolBar(tr("Pen"));
500         toolbar->setObjectName(tr("Pen"));
501         toolbar->addWidget(pw);
502         connect(drawing, SIGNAL(ObjectSelected(Object *)), pw, SLOT(SetFields(Object *)));
503         connect(pw, SIGNAL(WidthSelected(float)), drawing, SLOT(HandlePenWidth(float)));
504         connect(pw, SIGNAL(StyleSelected(int)), drawing, SLOT(HandlePenStyle(int)));
505         connect(pw, SIGNAL(ColorSelected(uint32_t)), drawing, SLOT(HandlePenColor(uint32_t)));
506 #endif
507 }
508
509 void MainWin::ReadSettings(void)
510 {
511         QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
512         QSize size = settings.value("size", QSize(400, 400)).toSize();
513 //      drawing->useAntialiasing = settings.value("useAntialiasing", true).toBool();
514 //      snapToGridAct->setChecked(settings.value("snapToGrid", true).toBool());
515         resize(size);
516         move(pos);
517         restoreState(settings.value("windowState").toByteArray());
518 }
519
520 void MainWin::WriteSettings(void)
521 {
522         settings.setValue("pos", pos());
523         settings.setValue("size", size());
524         settings.setValue("windowState", saveState());
525 //      settings.setValue("useAntialiasing", drawing->useAntialiasing);
526 //      settings.setValue("snapToGrid", snapToGridAct->isChecked());
527 }
528
529 void MainWin::UpdateMRUActionList(void)
530 {
531         QStringList mruFilePaths = settings.value("recentFiles").toStringList();
532
533         int mruSize = (mruFilePaths.size() <= MRU_MAX ? mruFilePaths.size() : MRU_MAX);
534
535         for(int i=0; i<mruSize; i++)
536         {
537                 QString filename = QFileInfo(mruFilePaths.at(i)).fileName();
538                 mruAct.at(i)->setText(filename);
539                 mruAct.at(i)->setData(mruFilePaths.at(i));
540                 mruAct.at(i)->setVisible(true);
541         }
542
543         for(int i=mruSize; i<MRU_MAX; i++)
544                 mruAct.at(i)->setVisible(false);
545 }
546
547 void MainWin::AdjustMRU(const QString & filePath)
548 {
549         documentName = filePath;
550         setWindowFilePath(documentName);
551
552         QStringList mruFilePaths = settings.value("recentFiles").toStringList();
553         mruFilePaths.removeAll(filePath);
554         mruFilePaths.prepend(filePath);
555
556         while (mruFilePaths.size() > MRU_MAX)
557                 mruFilePaths.removeLast();
558
559         settings.setValue("recentFiles", mruFilePaths);
560
561         UpdateMRUActionList();
562 }
563
564 #if 0
565 int MainWin::OnCreate(LPCREATESTRUCT lpCreateStruct)
566 {
567         if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
568                 return -1;
569
570         if (!m_wndToolBar.Create(this) || !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
571         {
572                 TRACE0("Failed to create toolbar\n");
573                 return -1;      // fail to create
574         }
575
576         if (!wndNavBar.Create(this, IDD_NAVBAR, CBRS_TOP, ID_VIEW_NAVBAR))
577         {
578                 TRACE0("Failed to create navigation bar\n");
579                 return -1;      // fail to create
580         }
581
582         if (!m_wndStatusBar.Create(this)
583                 || !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators) / sizeof(UINT)))
584         {
585                 TRACE0("Failed to create status bar\n");
586                 return -1;      // fail to create
587         }
588
589
590         // Add tool tips and resizeable toolbar:
591         m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
592         // Make toolbar dockable:
593         m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
594         EnableDocking(CBRS_ALIGN_ANY);
595         DockControlBar(&m_wndToolBar);
596
597         wndNavBar.SetBarStyle(wndNavBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY);
598         wndNavBar.EnableDocking(CBRS_ALIGN_TOP | CBRS_ALIGN_BOTTOM);
599         DockControlBarLeftOf(&wndNavBar, &m_wndToolBar);
600
601         // Restore toolbar state:
602         CDockState state;
603         state.LoadState("Toolbars");
604         SetDockState(state);
605
606         return 0;
607 }
608
609
610 void MainWin::OnDestroy()
611 {
612         CDockState  state;
613
614         GetDockState(state);
615         state.SaveState("Toolbars");
616
617         WINDOWPLACEMENT pos;
618         GetWindowPlacement(&pos);
619         static_cast<CMapApp *>(AfxGetApp())->saveWindowPos(&pos.rcNormalPosition, iniMainWin);
620
621         CMDIFrameWnd::OnDestroy();
622 }
623
624
625 bool MainWin::PreCreateWindow(CREATESTRUCT & cs)
626 {
627         // TODO: Modify the Window class or styles here by modifying
628         //  the CREATESTRUCT cs
629
630         return CMDIFrameWnd::PreCreateWindow(cs);
631 }
632
633
634 /////////////////////////////////////////////////////////////////////////////
635 // CMainWin message handlers
636 //--------------------------------------------------------------------
637 // Keep track of whether we should be eating mouse clicks:
638
639 void MainWin::OnActivateApp(bool bActive, HTASK task)
640 {
641         GUEmapEatClicks = !bActive;
642         CMDIFrameWnd::OnActivateApp(bActive, task);
643 }
644
645
646 /////////////////////////////////////////////////////////////////////////////
647 // Dock control bars on the same line:
648 //
649 // Taken from \MSDev\Samples\MFC\General\DockTool\MainFrm.cpp
650
651 void MainWin::DockControlBarLeftOf(CControlBar * Bar, CControlBar * LeftOf)
652 {
653         CRect rect;
654         DWORD dw;
655         UINT n;
656
657         // get MFC to adjust the dimensions of all docked ToolBars
658         // so that GetWindowRect will be accurate
659         RecalcLayout();
660         LeftOf->GetWindowRect(&rect);
661         rect.OffsetRect(1, 0);
662         dw = LeftOf->GetBarStyle();
663
664         n = 0;
665         n = (dw & CBRS_ALIGN_TOP ? AFX_IDW_DOCKBAR_TOP : n);
666         n = (dw & CBRS_ALIGN_BOTTOM && n == 0 ? AFX_IDW_DOCKBAR_BOTTOM : n);
667         n = (dw & CBRS_ALIGN_LEFT && n == 0 ? AFX_IDW_DOCKBAR_LEFT : n);
668         n = (dw & CBRS_ALIGN_RIGHT && n == 0 ? AFX_IDW_DOCKBAR_RIGHT : n);
669
670         // When we take the default parameters on rect, DockControlBar will dock
671         // each Toolbar on a seperate line.  By calculating a rectangle, we in effect
672         // are simulating a Toolbar being dragged to that location and docked.
673         DockControlBar(Bar, n, &rect);
674 }
675 #endif