r418: no message
[ctsim.git] / src / ctsim.cpp
index fb835ad8b5a9afdaf9d62489d3a9a628be796c69..c52282b0493056063ff8b0d5a0e0850a6c00a4c5 100644 (file)
@@ -9,7 +9,7 @@
 **  This is part of the CTSim program
 **  Copyright (C) 1983-2000 Kevin Rosenberg
 **
-**  $Id: ctsim.cpp,v 1.25 2001/01/02 16:02:13 kevin Exp $
+**  $Id: ctsim.cpp,v 1.35 2001/01/18 21:30:22 kevin Exp $
 **
 **  This program is free software; you can redistribute it and/or modify
 **  it under the terms of the GNU General Public License (version 2) as
@@ -25,6 +25,9 @@
 **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 ******************************************************************************/
 
+#ifdef MSVC
+#define strdup _strdup
+#endif
 
 // For compilers that support precompilation, includes "wx/wx.h".
 #include "wx/wxprec.h"
 #include "wx/wx.h"
 #endif
 
+#include "wx/image.h"
+#include "wx/filesys.h"
+#include "wx/fs_zip.h"
+
 #if !wxUSE_DOC_VIEW_ARCHITECTURE
 #error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in setup.h!
 #endif
 
 #include "ct.h"
 #include "ctsim.h"
+#include "ctsim-map.h"
 #include "docs.h"
 #include "views.h"
 #include "dialogs.h"
@@ -61,9 +69,7 @@
 #endif
 #endif
 
-static const char* rcsindent = "$Id: ctsim.cpp,v 1.25 2001/01/02 16:02:13 kevin Exp $";
-
-class CTSimApp* theApp = NULL;
+static const char* rcsindent = "$Id: ctsim.cpp,v 1.35 2001/01/18 21:30:22 kevin Exp $";
 
 struct option CTSimApp::ctsimOptions[] = 
 {
@@ -94,7 +100,8 @@ CTSimApp::OnInit()
 #ifdef HAVE_SETPRIORITY
   setpriority (PRIO_PROCESS, 0, 15);  // set to low scheduling priority
 #endif
-  
+
+  g_bRunningWXWindows = true;
   // process options
   while (1) {
     int c = getopt_long (argc, argv, "", ctsimOptions, NULL);
@@ -123,16 +130,21 @@ CTSimApp::OnInit()
   m_docManager = new wxDocManager;
   
   new wxDocTemplate (m_docManager, "ImageFile", "*.if", "", "if", "ImageFile doc", "ImageFile View", CLASSINFO(ImageFileDocument), CLASSINFO(ImageFileView));
-  
   new wxDocTemplate (m_docManager, "ProjectionFile", "*.pj", "", "pj", "ProjectionFile doc", "ProjectionFile View", CLASSINFO(ProjectionFileDocument), CLASSINFO(ProjectionFileView));
-  
   new wxDocTemplate (m_docManager, "PhantomFile", "*.phm", "", "phm", "Phantom doc", "Phantom View", CLASSINFO(PhantomDocument), CLASSINFO(PhantomView));
-  
   new wxDocTemplate (m_docManager, "PlotFile", "*.plt", "", "plt", "Plot doc", "Plot View", CLASSINFO(PlotFileDocument), CLASSINFO(PlotFileView));
   
-  //// Create the main frame window
+#if wxUSE_GIF
+    wxImage::AddHandler(new wxGIFHandler);     // Required for images in the online documentation
+#endif
+
+#if wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB
+      wxFileSystem::AddHandler(new wxZipFSHandler);     // Required for advanced HTML help
+#endif
+
+  // Create the main frame window
   m_pFrame = new MainFrame(m_docManager, (wxFrame *) NULL, -1, "CTSim", wxPoint(0, 0), wxSize(500, 400), wxDEFAULT_FRAME_STYLE);
-  
+
   SetTopWindow (m_pFrame);
   m_pFrame->Centre(wxBOTH);
   
@@ -142,10 +154,27 @@ CTSimApp::OnInit()
     wxString filename = argv [i - 1];
     m_docManager->CreateDocument (filename, wxDOC_SILENT);
   }
-  
+
+  setIconForFrame (m_pFrame);
+
+  if (! m_pFrame->getHelpController().Initialize("ctsim"))
+    ::wxMessageBox ("Cannot initialize the help system", "Error");
+
   return true;
 }
 
+
+#include "./ctsim.xpm"
+void
+CTSimApp::setIconForFrame(wxFrame* pFrame)
+{
+  wxIcon iconApp (ctsim16_xpm);
+
+  if (iconApp.Ok())
+    pFrame->SetIcon (iconApp);
+}
+
 void
 CTSimApp::usage(const char* program)
 {
@@ -180,11 +209,19 @@ CTSimApp::getUntitledFilename()
 
 // Top-level window for CTSim
 
+#if CTSIM_MDI
+IMPLEMENT_CLASS(MainFrame, wxMDIParentFrame)
+
+BEGIN_EVENT_TABLE(MainFrame, wxMDIParentFrame)
+#else
 IMPLEMENT_CLASS(MainFrame, wxDocParentFrame)
 
 BEGIN_EVENT_TABLE(MainFrame, wxDocParentFrame)
+#endif
+
 EVT_MENU(MAINMENU_HELP_ABOUT, MainFrame::OnAbout)
 EVT_MENU(MAINMENU_HELP_CONTENTS, MainFrame::OnHelpContents)
+EVT_MENU(MAINMENU_HELP_TOPICS, MainFrame::OnHelpTopics)
 EVT_MENU(MAINMENU_FILE_CREATE_PHANTOM, MainFrame::OnCreatePhantom)
 EVT_MENU(MAINMENU_FILE_CREATE_FILTER, MainFrame::OnCreateFilter)
 EVT_MENU(MAINMENU_FILE_EXIT, MainFrame::OnExit)
@@ -213,8 +250,13 @@ END_EVENT_TABLE()
 
 
 
+#if CTSIM_MDI
+MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
+: wxMDIParentFrame(NULL,  id, title, pos, size, type), m_pLog(NULL)
+#else
 MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type)
 : wxDocParentFrame(manager, frame, id, title, pos, size, type), m_pLog(NULL)
+#endif
 {
   m_pLog = new wxTextCtrl (this, -1, "Log Window\n", wxPoint(0, 250), wxSize(100,50), wxTE_MULTILINE | wxTE_READONLY);
   wxLog::SetActiveTarget(new wxLogTextCtrl(m_pLog));
@@ -224,22 +266,22 @@ MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const
   //// Make a menubar
   wxMenu *file_menu = new wxMenu;
   
-  file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...");
-  file_menu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...");
-  file_menu->Append(wxID_OPEN, "&Open...");
+  file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
+  file_menu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
+  file_menu->Append(wxID_OPEN, "&Open...\tCtrl-O");
   
   file_menu->AppendSeparator();
   file_menu->Append(MAINMENU_FILE_EXIT, "E&xit");
   
   //  history of files visited
-  m_docManager->FileHistoryUseMenu(file_menu);
+  theApp->getDocManager()->FileHistoryUseMenu(file_menu);
   
   m_pWindowMenu = new wxMenu;
   m_pWindowMenu->UpdateUI (this);
   
   wxMenu* help_menu = new wxMenu;
-  help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents");
-  help_menu->AppendSeparator();
+  help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
+  help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-T");
   help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
   
   wxMenuBar* menu_bar = new wxMenuBar;
@@ -285,7 +327,7 @@ MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
 }
 
 void 
-MainFrame::OnCreatePhantom(wxCommandEvent& WXUNUSED(event))
+MainFrame::OnCreatePhantom(wxCommandEvent& event)
 {
   DialogGetPhantom dialogPhantom (this, m_iDefaultPhantomID);
   int dialogReturn = dialogPhantom.ShowModal();
@@ -357,9 +399,34 @@ CTSimApp::getCompatibleImages (const ImageFileDocument* pIFDoc, std::vector<Imag
 }
 
 void 
-MainFrame::OnHelpContents(wxCommandEvent& WXUNUSED(event) )
+MainFrame::OnHelpTopics (wxCommandEvent& event)
 {
-  wxMessageBox("No help available, refer to man pages of command-line tools");
+   showHelp (event.GetId());
+}
+
+void 
+MainFrame::OnHelpContents (wxCommandEvent& event)
+{
+   showHelp (event.GetId());
+}
+
+void
+MainFrame::showHelp (int commandID)
+{
+  m_help.LoadFile();
+
+  switch (commandID) {
+  case MAINMENU_HELP_CONTENTS:
+     m_help.DisplayContents ();
+     break;
+  case MAINMENU_HELP_TOPICS:
+     m_help.DisplaySection (introduction);
+     break;
+
+  default:
+    *getLog() << "Unknown help command # " << commandID << "\n";
+    break;
+  }
 }
 
 void 
@@ -372,7 +439,7 @@ void
 MainFrame::OnUpdateUI (wxUpdateUIEvent& rEvent)
 {
   int iPos = 0;
-  wxList& rListDocs = m_docManager->GetDocuments();
+  wxList& rListDocs = theApp->getDocManager()->GetDocuments();
   wxNode* pNode = rListDocs.GetFirst();
   while (iPos < MAX_WINDOW_MENUITEMS && pNode != NULL) {
     wxDocument* pDoc = static_cast<wxDocument*>(pNode->GetData());