3 // Copyright 1997-2007 by Christopher J. Madsen
4 // (C) 2019 James Hammons
6 // GUEmap is licensed under either version 2 of the GPL, or (at your option)
7 // any later version. See LICENSE file for details.
9 // mainwin.cpp: implementation of the MainWin class
18 #include "roomwidget.h"
25 IMPLEMENT_DYNAMIC(CMainWin, CMDIFrameWnd)
27 BEGIN_MESSAGE_MAP(CMainWin, CMDIFrameWnd)
28 //{{AFX_MSG_MAP(CMainWin)
33 // Global help commands
34 ON_COMMAND(ID_HELP_FINDER, CMDIFrameWnd::OnHelpFinder)
35 ON_COMMAND(ID_HELP, CMDIFrameWnd::OnHelp)
36 ON_COMMAND(ID_CONTEXT_HELP, CMDIFrameWnd::OnContextHelp)
37 ON_COMMAND(ID_DEFAULT_HELP, CMDIFrameWnd::OnHelpFinder)
38 // Toggle the navigation bar:
39 ON_UPDATE_COMMAND_UI(ID_VIEW_NAVBAR, OnUpdateControlBarMenu)
40 ON_COMMAND_EX(ID_VIEW_NAVBAR, OnBarCheck)
43 static UINT indicators[] =
45 ID_SEPARATOR, // status line indicator
53 MainWin::MainWin(): settings("Underground Software", "GUEmap")
55 setCentralWidget(&mdiArea);
56 mdiArea.setViewMode(QMdiArea::TabbedView);
57 mdiArea.setTabsClosable(true);
59 setWindowIcon(QIcon(":/res/guemap.ico"));
60 setWindowTitle("GUEmap");
62 aboutWin = new AboutWindow(this);
68 undoAct->setEnabled(false);
69 statusBar()->showMessage(tr("Ready"));
73 // Create Dock widgets
74 QDockWidget * dock1 = new QDockWidget(tr("Rooms"), this);
75 /*RoomWidget * */rw = new RoomWidget;
77 addDockWidget(Qt::RightDockWidgetArea, dock1);
78 // QDockWidget * dock2 = new QDockWidget(tr("Blocks"), this);
79 // BlockWidget * bw = new BlockWidget;
80 // dock2->setWidget(bw);
81 // addDockWidget(Qt::RightDockWidgetArea, dock2);
82 // QDockWidget * dock3 = new QDockWidget(tr("Object"), this);
83 // ObjectWidget * ow = new ObjectWidget;
84 // dock3->setWidget(ow);
85 // addDockWidget(Qt::RightDockWidgetArea, dock3);
86 // Needed for saveState()
87 dock1->setObjectName("Rooms");
88 // dock2->setObjectName("Blocks");
89 // dock3->setObjectName("Object");
92 // zoomIndicator = new QLabel("Grid: 12.0\" BU: Inch");
93 // statusBar()->addPermanentWidget(zoomIndicator);
94 // statusBar()->showMessage(tr("Ready"));
97 // setUnifiedTitleAndToolBarOnMac(true);
98 // Global::font = new QFont("Verdana", 15, QFont::Bold);
100 // connect(lw, SIGNAL(LayerDeleted(int)), drawing, SLOT(DeleteCurrentLayer(int)));
101 // connect(lw, SIGNAL(LayerToggled()), drawing, SLOT(HandleLayerToggle()));
102 // connect(lw, SIGNAL(LayersSwapped(int, int)), drawing, SLOT(HandleLayerSwap(int, int)));
104 // connect(drawing, SIGNAL(ObjectHovered(Object *)), ow, SLOT(ShowInfo(Object *)));
109 void MainWin::closeEvent(QCloseEvent * event)
112 event->accept(); // Use ignore() if can't close for some reason
113 //Do we have a memory leak here if we don't delete the font in the Object???
117 void MainWin::FileNew(void)
119 MapView * map = new MapView;
120 map->setWindowTitle("Untitled");
121 map->clearSelection();
122 QMdiSubWindow * sw = mdiArea.addSubWindow(map);
123 mdiArea.setActiveSubWindow(sw);
127 connect(map, SIGNAL(RoomClicked(MapDoc *, int)), rw, SLOT(ShowInfo(MapDoc *, int)));
129 statusBar()->showMessage(tr("New map created."), 2000);
133 void MainWin::FileOpen(void)
135 QString filename = QFileDialog::getOpenFileName(this, tr("Open Map"), "",
136 tr("GUEmap files (*.gmp)"));
138 // User cancelled open
139 if (filename.isEmpty())
142 MapView * map = new MapView;
143 bool successful = ReadFile(map->doc, filename.toUtf8().data());
147 // Make sure to delete any hanging objects in the container...
151 msg.setText(QString(tr("Could not load file \"%1\"!")).arg(filename));
152 msg.setIcon(QMessageBox::Critical);
157 map->doc->filename = filename.toStdString();
158 map->setWindowTitle(map->doc->name.c_str());
159 map->clearSelection();
160 QMdiSubWindow * sw = mdiArea.addSubWindow(map);
161 mdiArea.setActiveSubWindow(sw);
165 connect(map, SIGNAL(RoomClicked(MapDoc *, int)), rw, SLOT(ShowInfo(MapDoc *, int)));
167 statusBar()->showMessage(tr("Map loaded."), 2000);
171 void MainWin::FileSaveBase(MapView * map, QString filename)
173 if (filename.endsWith(".gmp") == false)
176 bool successful = WriteFile(map->doc, filename.toUtf8().data());
180 // In this case, we should unlink the created file, since it's not
182 QFile::remove(filename);
185 msg.setText(QString(tr("Could not save file \"%1\"!")).arg(filename));
186 msg.setIcon(QMessageBox::Critical);
191 map->doc->filename = filename.toStdString();
192 map->doc->isDirty = false;
193 statusBar()->showMessage(tr("Map saved."), 2000);
197 void MainWin::FileSave(void)
199 QMdiSubWindow * sw = mdiArea.activeSubWindow();
200 MapView * map = (MapView *)(sw->widget());
201 QString filename = map->doc->filename.c_str();
203 if (filename.isEmpty())
205 filename = QFileDialog::getSaveFileName(this, tr("Save Map"), "",
206 tr("GUEmap maps (*.gmp)"));
208 // Bail if the user clicked "Cancel"
209 if (filename.isEmpty())
213 FileSaveBase(map, filename);
217 void MainWin::FileSaveAs(void)
219 QMdiSubWindow * sw = mdiArea.activeSubWindow();
220 MapView * map = (MapView *)(sw->widget());
221 // QString filename = map->doc->filename.c_str();
223 QString filename = QFileDialog::getSaveFileName(this, tr("Save Map As"),
224 map->doc->filename.c_str(), tr("GUEmap maps (*.gmp)"));
226 // Bail if the user clicked "Cancel"
227 if (filename.isEmpty())
230 FileSaveBase(map, filename);
234 void MainWin::FileClose(void)
236 QMdiSubWindow * sw = mdiArea.activeSubWindow();
237 MapView * map = (MapView *)(sw->widget());
239 if (map->doc->isDirty)
242 msg.setText(tr("The map has been modified."));
243 msg.setInformativeText(tr("Do you want to save your changes?"));
244 msg.setStandardButtons(QMessageBox::Save | QMessageBox::Discard);
245 msg.setDefaultButton(QMessageBox::Save);
246 msg.setIcon(QMessageBox::Warning);
248 int response = msg.exec();
250 if (response == QMessageBox::Save)
255 statusBar()->showMessage(tr("Map closed."), 2000);
259 void MainWin::EditUndo(void)
261 QMdiSubWindow * sw = mdiArea.activeSubWindow();
266 MapView * map = (MapView *)(sw->widget());
271 if (map->doc->undoData != 0)
273 map->doc->setUndoData(map->doc->undoData->undo(*(map->doc)));
274 statusBar()->showMessage(tr("Undo successful."));
279 statusBar()->showMessage(tr("Ready."));
283 void MainWin::MenuFixUndo(void)
285 QMdiSubWindow * sw = mdiArea.activeSubWindow();
290 MapView * map = (MapView *)(sw->widget());
291 UndoRec * undo = map->doc->undoData;
295 undoAct->setText(QString(tr("&Undo %1")).arg(undo->getName()));
296 undoAct->setEnabled(true);
300 undoAct->setText(tr("Can't Undo"));
301 undoAct->setEnabled(false);
306 void MainWin::EditDelete(void)
308 QMdiSubWindow * sw = mdiArea.activeSubWindow();
313 MapView * map = (MapView *)(sw->widget());
318 map->deleteSelection();
323 void MainWin::EditSelectAll(void)
325 QMdiSubWindow * sw = mdiArea.activeSubWindow();
330 MapView * map = (MapView *)(sw->widget());
335 for(int i=map->doc->room.size()-1; i>=0; i--)
342 void MainWin::HelpAbout(void)
348 void MainWin::CreateActions(void)
350 fileNewAct = CreateAction(tr("&New Map"), tr("New Map"), tr("Creates a new map."), QIcon(":/res/file-new.png"), QKeySequence(tr("Ctrl+n")));
351 connect(fileNewAct, SIGNAL(triggered()), this, SLOT(FileNew()));
353 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")));
354 connect(fileOpenAct, SIGNAL(triggered()), this, SLOT(FileOpen()));
356 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")));
357 connect(fileSaveAct, SIGNAL(triggered()), this, SLOT(FileSave()));
359 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")));
360 connect(fileSaveAsAct, SIGNAL(triggered()), this, SLOT(FileSaveAs()));
362 fileCloseAct = CreateAction(tr("&Close Map"), tr("Close Map"), tr("Closes the current map."), QIcon(":/res/file-close.png"), QKeySequence(tr("Ctrl+c")));
363 connect(fileCloseAct, SIGNAL(triggered()), this, SLOT(FileClose()));
365 exitAct = CreateAction(tr("&Quit"), tr("Quit"), tr("Exits the application."), QIcon(":/res/quit.png"), QKeySequence(tr("Ctrl+q")));
366 connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
368 undoAct = CreateAction(tr("&Undo"), tr("Undo"), tr("Undoes the last action."), QIcon(), QKeySequence(tr("Ctrl+z")));
369 connect(undoAct, SIGNAL(triggered()), this, SLOT(EditUndo()));
371 deleteAct = CreateAction(tr("&Delete"), tr("Delete"), tr("Deletes the selected items."), QIcon(), QKeySequence(tr("Delete")));
372 connect(deleteAct, SIGNAL(triggered()), this, SLOT(EditDelete()));
374 selectAllAct = CreateAction(tr("Select &All"), tr("Select All"), tr("Selects all items."), QIcon(), QKeySequence(tr("Ctrl+a")));
375 connect(selectAllAct, SIGNAL(triggered()), this, SLOT(EditSelectAll()));
377 aboutAct = CreateAction(tr("About &GUEmap"), tr("About GUEmap"), tr("Gives information about this program."), QIcon(), QKeySequence());
378 connect(aboutAct, SIGNAL(triggered()), this, SLOT(HelpAbout()));
381 snapToGridAct = CreateAction(tr("Snap To &Grid"), tr("Snap To Grid"), tr("Snaps mouse cursor to the visible grid when moving/creating objects."), QIcon(":/res/snap-to-grid-tool.png"), QKeySequence(tr("S")), true);
382 connect(snapToGridAct, SIGNAL(triggered()), this, SLOT(SnapToGridTool()));
384 fixAngleAct = CreateAction(tr("Fix &Angle"), tr("Fix Angle"), tr("Fixes the angle of an object."),
385 QIcon(":/res/fix-angle.png"), QKeySequence(tr("F,A")), true);
386 connect(fixAngleAct, SIGNAL(triggered()), this, SLOT(FixAngle()));
388 fixLengthAct = CreateAction(tr("Fix &Length"), tr("Fix Length"), tr("Fixes the length of an object."),
389 QIcon(":/res/fix-length.png"), QKeySequence(tr("F,L")), true);
390 connect(fixLengthAct, SIGNAL(triggered()), this, SLOT(FixLength()));
392 deleteAct = CreateAction(tr("&Delete"), tr("Delete Object"), tr("Deletes selected objects."), QIcon(":/res/delete-tool.png"), QKeySequence(tr("Delete")), true);
393 connect(deleteAct, SIGNAL(triggered()), this, SLOT(DeleteTool()));
395 addDimensionAct = CreateAction(tr("Add &Dimension"), tr("Add Dimension"), tr("Adds a dimension to the drawing."), QIcon(":/res/dimension-tool.png"), QKeySequence("D,I"), true);
396 connect(addDimensionAct, SIGNAL(triggered()), this, SLOT(DimensionTool()));
398 addLineAct = CreateAction(tr("Add &Line"), tr("Add Line"), tr("Adds lines to the drawing."), QIcon(":/res/add-line-tool.png"), QKeySequence("A,L"), true);
399 connect(addLineAct, SIGNAL(triggered()), this, SLOT(AddLineTool()));
401 addCircleAct = CreateAction(tr("Add &Circle"), tr("Add Circle"), tr("Adds circles to the drawing."), QIcon(":/res/add-circle-tool.png"), QKeySequence("A,C"), true);
402 connect(addCircleAct, SIGNAL(triggered()), this, SLOT(AddCircleTool()));
404 addArcAct = CreateAction(tr("Add &Arc"), tr("Add Arc"), tr("Adds arcs to the drawing."), QIcon(":/res/add-arc-tool.png"), QKeySequence("A,A"), true);
405 connect(addArcAct, SIGNAL(triggered()), this, SLOT(AddArcTool()));
407 addPolygonAct = CreateAction(tr("Add &Polygon"), tr("Add Polygon"), tr("Add polygons to the drawing."), QIcon(":/res/add-polygon-tool.png"), QKeySequence("A,P"), true);
408 connect(addPolygonAct, SIGNAL(triggered()), this, SLOT(AddPolygonTool()));
410 addSplineAct = CreateAction(tr("Add &Spline"), tr("Add Spline"), tr("Add a NURB spline to the drawing."), QIcon(":/res/add-spline-tool.png"), QKeySequence("A,S"), true);
411 connect(addSplineAct, SIGNAL(triggered()), this, SLOT(AddSplineTool()));
413 rotateAct = CreateAction(tr("&Rotate Objects"), tr("Rotate"), tr("Rotate object(s) around an arbitrary center."), QIcon(":/res/rotate-tool.png"), QKeySequence(tr("R,O")), true);
414 connect(rotateAct, SIGNAL(triggered()), this, SLOT(RotateTool()));
416 zoomInAct = CreateAction(tr("Zoom &In"), tr("Zoom In"), tr("Zoom in on the document."), QIcon(":/res/zoom-in.png"), QKeySequence(tr("+")), QKeySequence(tr("=")));
417 connect(zoomInAct, SIGNAL(triggered()), this, SLOT(ZoomInTool()));
419 zoomOutAct = CreateAction(tr("Zoom &Out"), tr("Zoom Out"), tr("Zoom out of the document."), QIcon(":/res/zoom-out.png"), QKeySequence(tr("-")));
420 connect(zoomOutAct, SIGNAL(triggered()), this, SLOT(ZoomOutTool()));
422 settingsAct = CreateAction(tr("&Settings"), tr("Settings"), tr("Change certain defaults for Architektonas."), QIcon(":/res/settings.png"), QKeySequence());
423 connect(settingsAct, SIGNAL(triggered()), this, SLOT(Settings()));
425 groupAct = CreateAction(tr("&Group"), tr("Group"), tr("Group/ungroup selected objects."), QIcon(":/res/group-tool.png"), QKeySequence("g"));
426 connect(groupAct, SIGNAL(triggered()), this, SLOT(HandleGrouping()));
428 connectAct = CreateAction(tr("&Connect"), tr("Connect"), tr("Connect objects at point."), QIcon(":/res/connect-tool.png"), QKeySequence("c,c"));
429 connect(connectAct, SIGNAL(triggered()), this, SLOT(HandleConnection()));
431 disconnectAct = CreateAction(tr("&Disconnect"), tr("Disconnect"), tr("Disconnect objects joined at point."), QIcon(":/res/disconnect-tool.png"), QKeySequence("d,d"));
432 connect(disconnectAct, SIGNAL(triggered()), this, SLOT(HandleDisconnection()));
434 mirrorAct = CreateAction(tr("&Mirror"), tr("Mirror"), tr("Mirror selected objects around a line."), QIcon(":/res/mirror-tool.png"), QKeySequence("m,i"), true);
435 connect(mirrorAct, SIGNAL(triggered()), this, SLOT(MirrorTool()));
437 trimAct = CreateAction(tr("&Trim"), tr("Trim"), tr("Trim extraneous lines from selected objects."), QIcon(":/res/trim-tool.png"), QKeySequence("t,r"), true);
438 connect(trimAct, SIGNAL(triggered()), this, SLOT(TrimTool()));
440 triangulateAct = CreateAction(tr("&Triangulate"), tr("Triangulate"), tr("Make triangles from selected lines, preserving their lengths."), QIcon(":/res/triangulate-tool.png"), QKeySequence("t,g"), true);
441 connect(triangulateAct, SIGNAL(triggered()), this, SLOT(TriangulateTool()));
446 void MainWin::CreateMenus(void)
448 QMenu * menu = menuBar()->addMenu(tr("&File"));
449 menu->addAction(fileNewAct);
450 menu->addAction(fileOpenAct);
451 menu->addAction(fileSaveAct);
452 menu->addAction(fileSaveAsAct);
453 menu->addAction(fileCloseAct);
454 menu->addSeparator();
455 menu->addAction(exitAct);
457 menu = menuBar()->addMenu(tr("&Edit"));
458 menu->addAction(undoAct);
459 connect(menu, SIGNAL(aboutToShow()), this, SLOT(MenuFixUndo()));
460 menu->addSeparator();
461 menu->addAction(deleteAct);
462 menu->addAction(selectAllAct);
464 menu = menuBar()->addMenu(tr("&View"));
465 menu->addAction(zoomInAct);
466 menu->addAction(zoomOutAct);
469 menu->addAction(snapToGridAct);
470 menu->addAction(groupAct);
471 menu->addAction(fixAngleAct);
472 menu->addAction(fixLengthAct);
473 menu->addAction(rotateAct);
474 menu->addAction(mirrorAct);
475 menu->addAction(trimAct);
476 menu->addAction(triangulateAct);
477 menu->addAction(connectAct);
478 menu->addAction(disconnectAct);
479 menu->addSeparator();
480 menu->addAction(addLineAct);
481 menu->addAction(addCircleAct);
482 menu->addAction(addArcAct);
483 menu->addAction(addPolygonAct);
484 menu->addAction(addSplineAct);
485 menu->addAction(addDimensionAct);
486 menu->addSeparator();
487 menu->addAction(settingsAct);
490 menu = menuBar()->addMenu(tr("&Help"));
491 menu->addAction(aboutAct);
495 void MainWin::CreateToolbars(void)
498 QToolBar * toolbar = addToolBar(tr("File"));
499 toolbar->setObjectName("File"); // Needed for saveState()
500 toolbar->addAction(fileNewAct);
501 toolbar->addAction(fileOpenAct);
502 toolbar->addAction(fileSaveAct);
503 toolbar->addAction(fileSaveAsAct);
504 toolbar->addAction(fileCloseAct);
505 // toolbar->addAction(exitAct);
507 toolbar = addToolBar(tr("View"));
508 toolbar->setObjectName("View");
509 toolbar->addAction(zoomInAct);
510 toolbar->addAction(zoomOutAct);
512 QSpinBox * spinbox = new QSpinBox;
513 toolbar->addWidget(spinbox);
514 // QLineEdit * lineedit = new QLineEdit;
515 toolbar->addWidget(baseUnitInput);
516 toolbar->addWidget(dimensionSizeInput);
518 toolbar = addToolBar(tr("Edit"));
519 toolbar->setObjectName("Edit");
520 toolbar->addAction(snapToGridAct);
521 toolbar->addAction(groupAct);
522 toolbar->addAction(fixAngleAct);
523 toolbar->addAction(fixLengthAct);
524 toolbar->addAction(rotateAct);
525 toolbar->addAction(mirrorAct);
526 toolbar->addAction(trimAct);
527 toolbar->addAction(triangulateAct);
528 toolbar->addAction(deleteAct);
529 toolbar->addAction(connectAct);
530 toolbar->addAction(disconnectAct);
531 toolbar->addSeparator();
532 toolbar->addAction(addLineAct);
533 toolbar->addAction(addCircleAct);
534 toolbar->addAction(addArcAct);
535 toolbar->addAction(addPolygonAct);
536 toolbar->addAction(addSplineAct);
537 toolbar->addAction(addDimensionAct);
539 spinbox->setRange(4, 256);
540 spinbox->setValue(12);
541 baseUnitInput->setText("12");
542 connect(spinbox, SIGNAL(valueChanged(int)), this, SLOT(HandleGridSizeInPixels(int)));
543 connect(baseUnitInput, SIGNAL(textChanged(QString)), this, SLOT(HandleGridSizeInBaseUnits(QString)));
544 connect(dimensionSizeInput, SIGNAL(textChanged(QString)), this, SLOT(HandleDimensionSize(QString)));
546 PenWidget * pw = new PenWidget();
547 toolbar = addToolBar(tr("Pen"));
548 toolbar->setObjectName(tr("Pen"));
549 toolbar->addWidget(pw);
550 connect(drawing, SIGNAL(ObjectSelected(Object *)), pw, SLOT(SetFields(Object *)));
551 connect(pw, SIGNAL(WidthSelected(float)), drawing, SLOT(HandlePenWidth(float)));
552 connect(pw, SIGNAL(StyleSelected(int)), drawing, SLOT(HandlePenStyle(int)));
553 connect(pw, SIGNAL(ColorSelected(uint32_t)), drawing, SLOT(HandlePenColor(uint32_t)));
558 void MainWin::ReadSettings(void)
560 QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
561 QSize size = settings.value("size", QSize(400, 400)).toSize();
562 // drawing->useAntialiasing = settings.value("useAntialiasing", true).toBool();
563 // snapToGridAct->setChecked(settings.value("snapToGrid", true).toBool());
566 restoreState(settings.value("windowState").toByteArray());
570 void MainWin::WriteSettings(void)
572 settings.setValue("pos", pos());
573 settings.setValue("size", size());
574 settings.setValue("windowState", saveState());
575 // settings.setValue("useAntialiasing", drawing->useAntialiasing);
576 // settings.setValue("snapToGrid", snapToGridAct->isChecked());
581 int MainWin::OnCreate(LPCREATESTRUCT lpCreateStruct)
583 if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
586 if (!m_wndToolBar.Create(this) || !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
588 TRACE0("Failed to create toolbar\n");
589 return -1; // fail to create
592 if (!wndNavBar.Create(this, IDD_NAVBAR, CBRS_TOP, ID_VIEW_NAVBAR))
594 TRACE0("Failed to create navigation bar\n");
595 return -1; // fail to create
598 if (!m_wndStatusBar.Create(this)
599 || !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators) / sizeof(UINT)))
601 TRACE0("Failed to create status bar\n");
602 return -1; // fail to create
606 // Add tool tips and resizeable toolbar:
607 m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
608 // Make toolbar dockable:
609 m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
610 EnableDocking(CBRS_ALIGN_ANY);
611 DockControlBar(&m_wndToolBar);
613 wndNavBar.SetBarStyle(wndNavBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY);
614 wndNavBar.EnableDocking(CBRS_ALIGN_TOP | CBRS_ALIGN_BOTTOM);
615 DockControlBarLeftOf(&wndNavBar, &m_wndToolBar);
617 // Restore toolbar state:
619 state.LoadState("Toolbars");
626 void MainWin::OnDestroy()
631 state.SaveState("Toolbars");
634 GetWindowPlacement(&pos);
635 static_cast<CMapApp *>(AfxGetApp())->saveWindowPos(&pos.rcNormalPosition, iniMainWin);
637 CMDIFrameWnd::OnDestroy();
641 bool MainWin::PreCreateWindow(CREATESTRUCT & cs)
643 // TODO: Modify the Window class or styles here by modifying
644 // the CREATESTRUCT cs
646 return CMDIFrameWnd::PreCreateWindow(cs);
650 /////////////////////////////////////////////////////////////////////////////
651 // CMainWin message handlers
652 //--------------------------------------------------------------------
653 // Keep track of whether we should be eating mouse clicks:
655 void MainWin::OnActivateApp(bool bActive, HTASK task)
657 GUEmapEatClicks = !bActive;
658 CMDIFrameWnd::OnActivateApp(bActive, task);
662 /////////////////////////////////////////////////////////////////////////////
663 // Dock control bars on the same line:
665 // Taken from \MSDev\Samples\MFC\General\DockTool\MainFrm.cpp
667 void MainWin::DockControlBarLeftOf(CControlBar * Bar, CControlBar * LeftOf)
673 // get MFC to adjust the dimensions of all docked ToolBars
674 // so that GetWindowRect will be accurate
676 LeftOf->GetWindowRect(&rect);
677 rect.OffsetRect(1, 0);
678 dw = LeftOf->GetBarStyle();
681 n = (dw & CBRS_ALIGN_TOP ? AFX_IDW_DOCKBAR_TOP : n);
682 n = (dw & CBRS_ALIGN_BOTTOM && n == 0 ? AFX_IDW_DOCKBAR_BOTTOM : n);
683 n = (dw & CBRS_ALIGN_LEFT && n == 0 ? AFX_IDW_DOCKBAR_LEFT : n);
684 n = (dw & CBRS_ALIGN_RIGHT && n == 0 ? AFX_IDW_DOCKBAR_RIGHT : n);
686 // When we take the default parameters on rect, DockControlBar will dock
687 // each Toolbar on a seperate line. By calculating a rectangle, we in effect
688 // are simulating a Toolbar being dragged to that location and docked.
689 DockControlBar(Bar, n, &rect);