r3847: mac changes
[ctsim.git] / src / views.cpp
index 19b0c5632dc0126bc0dbfc9d3e77bcf0413929de..758390aef76217b731328588ae6bba1daf97fc26 100644 (file)
@@ -9,7 +9,7 @@
 **  This is part of the CTSim program
 **  Copyright (c) 1983-2001 Kevin Rosenberg
 **
-**  $Id: views.cpp,v 1.159 2002/06/02 23:39:22 kevin Exp $
+**  $Id: views.cpp,v 1.163 2003/01/22 22:15:10 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
@@ -184,7 +184,7 @@ ImageFileCanvas::OnChar (wxKeyEvent& event)
     if (m_pView)
       m_pView->OnUpdate (NULL);
   } else
-    wxScrolledWindow::OnChar (event);
+    event.Skip();
 }
 
 wxSize
@@ -268,10 +268,10 @@ EVT_MENU(IFMENU_PLOT_HISTOGRAM, ImageFileView::OnPlotHistogram)
 END_EVENT_TABLE()
 
 ImageFileView::ImageFileView() 
-: wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pFileMenu(0), m_pFilterMenu(0), m_bMinSpecified(false), m_bMaxSpecified(false)
-{
-  m_iDefaultExportFormatID = ImageFile::EXPORT_FORMAT_PNG;
-}
+: wxView(), m_pFrame(0), m_pCanvas(0), m_pFileMenu(0), m_pFilterMenu(0), 
+  m_bMinSpecified(false), m_bMaxSpecified(false), 
+  m_iDefaultExportFormatID(ImageFile::EXPORT_FORMAT_PNG)
+{}
 
 ImageFileView::~ImageFileView()
 {
@@ -908,11 +908,9 @@ ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view)
   m_pFileMenu->Append(wxID_PREVIEW, "Print Preview");
   m_pFileMenu->AppendSeparator();
   m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
-#ifdef CTSIM_MDI
   m_pFileMenu->AppendSeparator();
   m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
   m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
-#endif
   GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
   GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
   
@@ -1019,8 +1017,8 @@ ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view)
 #if wxUSE_GLCANVAS
   accelEntries[iEntry++].Set (wxACCEL_CTRL, static_cast<int>('3'), IFMENU_IMAGE_CONVERT3D);
 #endif
+
   wxAcceleratorTable accelTable (iEntry, accelEntries);
-  
   subframe->SetAcceleratorTable (accelTable);
   
   return subframe;
@@ -2299,11 +2297,9 @@ PhantomFileView::CreateChildFrame(wxDocument *doc, wxView *view)
   m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
   m_pFileMenu->AppendSeparator();
   m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
-#ifdef CTSIM_MDI
   m_pFileMenu->AppendSeparator();
   m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
   m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
-#endif
   GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
   GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
   
@@ -3020,11 +3016,9 @@ ProjectionFileView::CreateChildFrame(wxDocument *doc, wxView *view)
   m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
   m_pFileMenu->AppendSeparator();
   m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
-#ifdef CTSIM_MDI
   m_pFileMenu->AppendSeparator();
   m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
   m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
-#endif
   GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
   GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
   
@@ -3199,33 +3193,21 @@ ProjectionFileView::OnClose (bool deleteWindow)
 
 // PlotFileCanvas
 PlotFileCanvas::PlotFileCanvas (PlotFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
-: wxScrolledWindow(frame, -1, pos, size, style)
+  : wxScrolledWindow(frame, -1, pos, size, style), m_pView(v)
 {
-  m_pView = v;
 }
 
-wxSize
-PlotFileCanvas::GetBestSize() const
+PlotFileCanvas::~PlotFileCanvas ()
 {
-  if (! m_pView)
-    return wxSize(0,0);
-  
-  int xSize, ySize;
-  theApp->getMainFrame()->GetClientSize (&xSize, &ySize);
-  xSize = maxValue<int> (xSize, ySize);
-#ifdef CTSIM_MDI
-  ySize = xSize = (xSize / 4);
-#else
-  ySize = xSize;
-#endif
-  return wxSize (xSize, ySize);
 }
 
-PlotFileCanvas::~PlotFileCanvas ()
+wxSize
+PlotFileCanvas::GetBestSize() const
 {
-  m_pView = NULL;
+  return wxSize (500, 300);
 }
 
+
 void 
 PlotFileCanvas::OnDraw(wxDC& dc)
 {
@@ -3246,7 +3228,8 @@ EVT_MENU(PLOTMENU_VIEW_SCALE_FULL, PlotFileView::OnScaleFull)
 END_EVENT_TABLE()
 
 PlotFileView::PlotFileView() 
-: wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pEZPlot(NULL), m_pFileMenu(0), m_bMinSpecified(false), m_bMaxSpecified(false)
+: wxView(), m_pFrame(0), m_pCanvas(0), m_pEZPlot(0), m_pFileMenu(0), 
+  m_bMinSpecified(false), m_bMaxSpecified(false)
 {
 }
 
@@ -3256,6 +3239,7 @@ PlotFileView::~PlotFileView()
     delete m_pEZPlot;
   
   GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);  
+  GetDocumentManager()->ActivateView(this, FALSE, TRUE);
 }
 
 void
@@ -3341,11 +3325,8 @@ PlotFileCanvas*
 PlotFileView::CreateCanvas (wxFrame* parent)
 {
   PlotFileCanvas* pCanvas;
-  int width, height;
-  parent->GetClientSize(&width, &height);
-  
-  pCanvas = new PlotFileCanvas (this, parent, wxPoint(-1,-1), wxSize(width, height), 0);
   
+  pCanvas = new PlotFileCanvas (this, parent, wxPoint(-1,-1), wxSize(-1,-1), 0);  
   pCanvas->SetBackgroundColour(*wxWHITE);
   pCanvas->Clear();
   
@@ -3360,9 +3341,9 @@ wxDocChildFrame*
 PlotFileView::CreateChildFrame(wxDocument *doc, wxView *view)
 {
 #ifdef CTSIM_MDI
-  wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(-1,-1), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
+  wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE);
 #else
-  wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(-1,-1), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
+  wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE);
 #endif
   theApp->setIconForFrame (subframe);
   
@@ -3384,11 +3365,9 @@ PlotFileView::CreateChildFrame(wxDocument *doc, wxView *view)
   m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
   m_pFileMenu->AppendSeparator();
   m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
-#ifdef CTSIM_MDI
   m_pFileMenu->AppendSeparator();
   m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
   m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
-#endif
   GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
   GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
   
@@ -3427,17 +3406,16 @@ PlotFileView::CreateChildFrame(wxDocument *doc, wxView *view)
 bool 
 PlotFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
 {
-  m_pFrame = CreateChildFrame(doc, this);
-  SetFrame(m_pFrame);
-  
   m_bMinSpecified = false;
   m_bMaxSpecified = false;
   m_dAutoScaleFactor = 1.;
   
-  int width, height;
-  m_pFrame->GetClientSize(&width, &height);
-  m_pFrame->SetTitle ("Plot File");
+  m_pFrame = CreateChildFrame(doc, this);
+  SetFrame(m_pFrame);
   m_pCanvas = CreateCanvas (m_pFrame);
+  m_pFrame->SetClientSize (m_pCanvas->GetBestSize());
+  m_pCanvas->SetClientSize (m_pCanvas->GetBestSize());
+  m_pFrame->SetTitle ("Plot File");
   
   m_pFrame->Show(true);
   Activate(true);
@@ -3445,6 +3423,19 @@ PlotFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
   return true;
 }
 
+void 
+PlotFileView::setInitialClientSize ()
+{
+  if (m_pFrame && m_pCanvas) {
+    wxSize bestSize = m_pCanvas->GetBestSize();
+    
+    m_pFrame->SetClientSize (bestSize);
+    m_pFrame->Show (true);
+    m_pFrame->SetFocus();
+  }
+}  
+
+
 void 
 PlotFileView::OnDraw (wxDC* dc)
 {
@@ -3519,7 +3510,6 @@ PlotFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
 bool 
 PlotFileView::OnClose (bool deleteWindow)
 {
-  //GetDocumentManager()->ActivateView (this, false, true);
   if (! GetDocument() || ! GetDocument()->Close())
     return false;
   
@@ -3632,11 +3622,9 @@ TextFileView::CreateChildFrame (wxDocument *doc, wxView *view)
   m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
   m_pFileMenu->AppendSeparator();
   m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
-#ifdef CTSIM_MDI
   m_pFileMenu->AppendSeparator();
   m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
   m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
-#endif
   GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
   GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);