r2108: *** empty log message ***
[ctsim.git] / src / views.cpp
index bd54f07afa54af3165a2182a55f1d306e2988614..7636f07ede17d1fd0d3f3e3e79cae45c300108c6 100644 (file)
@@ -9,7 +9,7 @@
 **  This is part of the CTSim program
 **  Copyright (c) 1983-2001 Kevin Rosenberg
 **
-**  $Id: views.cpp,v 1.160 2002/06/03 16:57:22 kevin Exp $
+**  $Id: views.cpp,v 1.161 2002/06/06 22:50:24 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
@@ -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()
 {
@@ -3199,33 +3199,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 +3234,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 +3245,7 @@ PlotFileView::~PlotFileView()
     delete m_pEZPlot;
   
   GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);  
+  GetDocumentManager()->ActivateView(this, FALSE, TRUE);
 }
 
 void
@@ -3341,11 +3331,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 +3347,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);
   
@@ -3427,17 +3414,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 +3431,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 +3518,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;