Merge changes from Debian Med packaging of 5.2.0-4
[ctsim.git] / src / ctsim.cpp
index 9b7957966c5fbc06b5668510edf909e944be53c1..e2e3f2766a4cea7fee821e4ab1a98fb3210977d7 100644 (file)
@@ -93,18 +93,18 @@ CTSimApp::CTSimApp()
 void CTSimApp::OnInitCmdLine(wxCmdLineParser& parser)
 {
   static const wxCmdLineEntryDesc cmdLineDesc[] = {
-    { wxCMD_LINE_SWITCH, _T("l"), _T("verbose"), _T("verbose logging") },
-    { wxCMD_LINE_SWITCH, _T("v"), _T("version"), _T("print version") },
-    { wxCMD_LINE_SWITCH, _T("p"), _T("print"), _T("print images from command line"),
+    { wxCMD_LINE_SWITCH, wxT_2("l"), wxT_2("verbose"), wxT_2("verbose logging") },
+    { wxCMD_LINE_SWITCH, wxT_2("v"), wxT_2("version"), wxT_2("print version") },
+    { wxCMD_LINE_SWITCH, wxT_2("p"), wxT_2("print"), wxT_2("print images from command line"),
       wxCMD_LINE_VAL_NONE,
       wxCMD_LINE_PARAM_OPTIONAL },
-    { wxCMD_LINE_SWITCH, _T("h"), _T("help"), _T("print this help message"),
+    { wxCMD_LINE_SWITCH, wxT_2("h"), wxT_2("help"), wxT_2("print this help message"),
       wxCMD_LINE_VAL_NONE,
       wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_OPTION_HELP },
-    { wxCMD_LINE_PARAM, NULL, NULL, _T("input file"),
+    { wxCMD_LINE_PARAM, NULL, NULL, wxT_2("input file"),
       wxCMD_LINE_VAL_STRING,
       wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_PARAM_MULTIPLE },
-    { wxCMD_LINE_NONE }
+    wxCMD_LINE_DESC_END
   };
 
   parser.SetDesc(cmdLineDesc);
@@ -193,9 +193,9 @@ CTSimApp::OnInit()
   m_pLogDoc = newTextDoc();
   if (m_pLogDoc) {
     m_pLog = m_pLogDoc->getTextCtrl();
-    m_pLogDoc->SetDocumentName("Log.txt");
-    m_pLogDoc->SetFilename("Log.txt");
-    m_pLogDoc->getView()->getFrame()->SetTitle("Log");
+    m_pLogDoc->SetDocumentName(_T("Log.txt"));
+    m_pLogDoc->SetFilename(_T("Log.txt"));
+    m_pLogDoc->getView()->getFrame()->SetTitle(_T("Log"));
     int xSize, ySize;
     m_pFrame->GetClientSize(&xSize, &ySize);
     int yLogSize = ySize / 4;
@@ -247,10 +247,11 @@ CTSimApp::OnInit()
       m_docManager->OnFileClose (nullEvent);
     }
   }
+
   if (m_bPrintCmdLineImages) {
     wxCommandEvent closeEvent;
     closeEvent.SetInt (MAINMENU_FILE_EXIT);
-    m_pFrame->AddPendingEvent(closeEvent);
+    m_pFrame->GetEventHandler()->ProcessEvent(closeEvent);
   }
 
   if (getStartupTips())
@@ -347,18 +348,6 @@ CTSimApp::closeConfig()
 }
 
 
-wxString
-CTSimApp::getUntitledFilename()
-{
-  static int untitledNumber = 1;
-
-  wxString filename (_T("Untitled"));
-  filename << untitledNumber++;
-
-  return (filename);
-}
-
-
 // Top-level window for CTSim
 
 #if CTSIM_MDI
@@ -400,7 +389,9 @@ EVT_MENU(MAINMENU_HELP_SECONDARY, MainFrame::OnHelpSecondary)
 EVT_MENU(MAINMENU_FILE_CREATE_PHANTOM, MainFrame::OnCreatePhantom)
 EVT_MENU(MAINMENU_FILE_CREATE_FILTER, MainFrame::OnCreateFilter)
 EVT_MENU(MAINMENU_FILE_EXIT, MainFrame::OnExit)
+
 EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, MainFrame::OnMRUFile)
+
 EVT_MENU(MAINMENU_WINDOW_BASE, MainFrame::OnWindowMenu0)
 EVT_MENU(MAINMENU_WINDOW_BASE+1, MainFrame::OnWindowMenu1)
 EVT_MENU(MAINMENU_WINDOW_BASE+2, MainFrame::OnWindowMenu2)
@@ -428,7 +419,7 @@ 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)
-: wxDocMDIParentFrame(manager, NULL, id, title, pos, size, type, "MainFrame")
+: wxDocMDIParentFrame(manager, NULL, id, title, pos, size, type, _T("MainFrame"))
 #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, _T("MainFrame"))
@@ -597,7 +588,6 @@ MainFrame::OnCreateFilter (wxCommandEvent& WXUNUSED(event))
       m_dDefaultFilterBandwidth
        << _T(", inputScale=") << m_dDefaultFilterInputScale << _T(", outputScale=") << m_dDefaultFilterOutputScale;
     *theApp->getLog() << os << _T("\n");
-    wxString filename = _T("untitled.if");
     ImageFileDocument* pFilterDoc = theApp->newImageDoc();
     pFilterDoc->setBadFileOpen();
     if (! pFilterDoc) {
@@ -904,7 +894,7 @@ public:
 };
 
 BitmapDialog::BitmapDialog (wxBitmap* pBitmap, char const* pszTitle)
-  : wxDialog(theApp->getMainFrame(), -1, wxString(pszTitle,*wxConvCurrent), wxDefaultPosition, wxDefaultSize, wxDIALOG_MODAL | wxDEFAULT_DIALOG_STYLE)
+  : wxDialog(theApp->getMainFrame(), -1, wxString(pszTitle,*wxConvCurrent))
 {
   wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL);
 
@@ -973,13 +963,8 @@ MainFrame::OnImport (wxCommandEvent& WXUNUSED(event) )
     return;
   }
 
-#if WXWIN_COMPATIBILITY_2_4
   wxString strFilename = wxFileSelector (wxString(wxConvUTF8.cMB2WX("Import Filename")), wxString(wxConvUTF8.cMB2WX("")),
-                                         wxString(wxConvUTF8.cMB2WX("")), strExt, strWildcard, wxHIDE_READONLY | wxOPEN);
-#else
-  wxString strFilename = wxFileSelector (wxString(wxConvUTF8.cMB2WX("Import Filename")), wxString(wxConvUTF8.cMB2WX("")),
-                                         wxString(wxConvUTF8.cMB2WX("")), strExt, strWildcard, wxOPEN);
-#endif
+                                         wxString(wxConvUTF8.cMB2WX("")), strExt, strWildcard, wxFD_OPEN);
 
   if (! strFilename.IsEmpty()) {
     if (m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_PPM || m_iDefaultImportFormat == ImageFile::IMPORT_FORMAT_PNG) {
@@ -1081,28 +1066,40 @@ MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
 
 // Create new documents
 
-ProjectionFileDocument*
-CTSimApp::newProjectionDoc()
-{
-  ProjectionFileDocument* newDoc = dynamic_cast<ProjectionFileDocument*>(m_pDocTemplProjection->CreateDocument (_T("")));
+wxDocument* 
+CTSimApp::newDocumentHelper (wxDocTemplate* tmpl) {
+  wxDocument* newDoc = tmpl->CreateDocument (_T(""));
   if (newDoc) {
-    newDoc->SetDocumentName (m_pDocTemplProjection->GetDocumentName());
-    newDoc->SetDocumentTemplate (m_pDocTemplProjection);
+    newDoc->SetDocumentTemplate (tmpl);
     newDoc->OnNewDocument();
+    wxString fname = newDoc->GetFilename();
+    fname += _T(".");
+    fname += tmpl->GetDefaultExtension();
+    newDoc->SetDocumentName(fname);
+    newDoc->SetTitle(fname);
+    newDoc->SetFilename(fname, true);
   }
 
   return newDoc;
 }
 
+ProjectionFileDocument*
+CTSimApp::newProjectionDoc()
+{
+  ProjectionFileDocument* newDoc = dynamic_cast<ProjectionFileDocument*>
+    (newDocumentHelper(m_pDocTemplProjection));
+  if (newDoc)
+    newDoc->getView()->getFrame()->SetTitle(newDoc->GetDocumentName());
+  return newDoc;
+}
+
 ImageFileDocument*
 CTSimApp::newImageDoc()
 {
-  ImageFileDocument* newDoc = dynamic_cast<ImageFileDocument*>(m_pDocTemplImage->CreateDocument (_T("")));
-  if (newDoc) {
-    newDoc->SetDocumentName (m_pDocTemplImage->GetDocumentName());
-    newDoc->SetDocumentTemplate (m_pDocTemplImage);
-    newDoc->OnNewDocument();
-  }
+  ImageFileDocument* newDoc = dynamic_cast<ImageFileDocument*>
+    (newDocumentHelper(m_pDocTemplImage));
+  if (newDoc)
+    newDoc->getView()->getFrame()->SetTitle(newDoc->GetDocumentName());
 
   return newDoc;
 }
@@ -1110,12 +1107,10 @@ CTSimApp::newImageDoc()
 PlotFileDocument*
 CTSimApp::newPlotDoc()
 {
-  PlotFileDocument* newDoc = dynamic_cast<PlotFileDocument*>(m_pDocTemplPlot->CreateDocument (_T("")));
-  if (newDoc) {
-    newDoc->SetDocumentName (m_pDocTemplPlot->GetDocumentName());
-    newDoc->SetDocumentTemplate (m_pDocTemplPlot);
-    newDoc->OnNewDocument();
-  }
+  PlotFileDocument* newDoc = dynamic_cast<PlotFileDocument*>
+    (newDocumentHelper(m_pDocTemplPlot));
+  if (newDoc)
+    newDoc->getView()->getFrame()->SetTitle(newDoc->GetDocumentName());
 
   return newDoc;
 }
@@ -1124,15 +1119,10 @@ CTSimApp::newPlotDoc()
 TextFileDocument*
 CTSimApp::newTextDoc()
 {
-  wxString strFilename (getUntitledFilename());
-  strFilename += wxString(".txt", *wxConvCurrent);
-
-  TextFileDocument* newDoc = dynamic_cast<TextFileDocument*>(m_pDocTemplText->CreateDocument (_T("")));
-  if (newDoc) {
-    newDoc->SetDocumentName (m_pDocTemplText->GetDocumentName());
-    newDoc->SetDocumentTemplate (m_pDocTemplText);
-    newDoc->OnNewDocument();
-  }
+  TextFileDocument* newDoc = dynamic_cast<TextFileDocument*>
+    (newDocumentHelper(m_pDocTemplText));
+  if (newDoc)
+    newDoc->getView()->getFrame()->SetTitle(newDoc->GetDocumentName());
 
   return newDoc;
 }
@@ -1141,12 +1131,10 @@ CTSimApp::newTextDoc()
 PhantomFileDocument*
 CTSimApp::newPhantomDoc()
 {
-  PhantomFileDocument* newDoc = dynamic_cast<PhantomFileDocument*>(m_pDocTemplPhantom->CreateDocument (_T("")));
-  if (newDoc) {
-    newDoc->SetDocumentName (m_pDocTemplPhantom->GetDocumentName());
-    newDoc->SetDocumentTemplate (m_pDocTemplPhantom);
-    newDoc->OnNewDocument();
-  }
+  PhantomFileDocument* newDoc = dynamic_cast<PhantomFileDocument*>
+    (newDocumentHelper(m_pDocTemplPhantom));
+  if (newDoc)
+    newDoc->getView()->getFrame()->SetTitle(newDoc->GetDocumentName());
 
   return newDoc;
 }
@@ -1156,13 +1144,12 @@ CTSimApp::newPhantomDoc()
 Graph3dFileDocument*
 CTSimApp::newGraph3dDoc()
 {
-  Graph3dFileDocument* newDoc = dynamic_cast<Graph3dFileDocument*>(m_pDocTemplGraph3d->CreateDocument (_T("")));
-  if (newDoc) {
-    newDoc->SetDocumentName (m_pDocTemplGraph3d->GetDocumentName());
-    newDoc->SetDocumentTemplate (m_pDocTemplGraph3d);
-    newDoc->OnNewDocument();
-  }
+  Graph3dFileDocument* newDoc = dynamic_cast<Graph3dFileDocument*>
+    (newDocumentHelper(m_pDocTemplGraph3d));
+  if (newDoc)
+    newDoc->getView()->getFrame()->SetTitle(newDoc->GetDocumentName());
 
   return newDoc;
 }
+
 #endif