r2101: Committing for 3.5.4
[ctsim.git] / src / views.cpp
index 1b54cbb93ef99314a0e0780fa7b42e552ebc6ca6..19b0c5632dc0126bc0dbfc9d3e77bcf0413929de 100644 (file)
@@ -9,7 +9,7 @@
 **  This is part of the CTSim program
 **  Copyright (c) 1983-2001 Kevin Rosenberg
 **
-**  $Id: views.cpp,v 1.156 2002/05/30 17:02:32 kevin Exp $
+**  $Id: views.cpp,v 1.159 2002/06/02 23:39: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
@@ -75,9 +75,7 @@ ImageFileCanvas::ImageFileCanvas (ImageFileView* v, wxFrame *frame, const wxPoin
 }
 
 ImageFileCanvas::~ImageFileCanvas()
-{
-  m_pView = NULL;
-}
+{}
 
 void 
 ImageFileCanvas::OnDraw(wxDC& dc)
@@ -192,11 +190,26 @@ ImageFileCanvas::OnChar (wxKeyEvent& event)
 wxSize
 ImageFileCanvas::GetBestSize() const
 {
-  if (! m_pView)
-    return wxSize(0,0);
+  const int iMinX = 50;
+  const int iMinY = 20;
+  wxSize bestSize (iMinX,iMinY);
+
+  if (m_pView) {
+    const ImageFile& rIF = m_pView->GetDocument()->getImageFile();
+    bestSize.Set  (rIF.nx(), rIF.ny());
+  }
+
+  if (bestSize.x > 800)
+    bestSize.x = 800;
+  if (bestSize.y > 800)
+    bestSize.y = 800;
   
-  const ImageFile& rIF = m_pView->GetDocument()->getImageFile();
-  return wxSize (rIF.nx(), rIF.ny());
+  if (bestSize.y < iMinY)
+    bestSize.y = iMinY;
+  if (bestSize.x < iMinX)
+    bestSize.x = iMinX;
+  
+  return bestSize;
 }
 
 
@@ -854,13 +867,8 @@ ImageFileView::OnImaginary (wxCommandEvent& event)
 ImageFileCanvas* 
 ImageFileView::CreateCanvas (wxFrame* parent)
 {
-  ImageFileCanvas* pCanvas;
-  int width, height;
-  parent->GetClientSize(&width, &height);
-  
-  pCanvas = new ImageFileCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
-  
-  pCanvas->SetScrollbars(20, 20, 50, 50);
+  ImageFileCanvas* pCanvas = new ImageFileCanvas (this, parent, wxPoint(-1,-1),
+                                                 wxSize(-1,-1), 0);
   pCanvas->SetBackgroundColour(*wxWHITE);
   pCanvas->Clear();
   
@@ -875,12 +883,12 @@ wxDocChildFrame*
 ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view)
 {
 #if CTSIM_MDI
-  wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
+  wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE);
 #else
-  wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
+  wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE);
 #endif
   theApp->setIconForFrame (subframe);
-  
+
   m_pFileMenu = new wxMenu;
   m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
   m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
@@ -1022,23 +1030,19 @@ ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view)
 bool 
 ImageFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
 {
-  m_pFrame = CreateChildFrame(doc, this);
-  
   m_bMinSpecified = false;
   m_bMaxSpecified = false;
   m_dAutoScaleFactor = 1.;
   
-  //  int width, height;
-  //  m_pFrame->GetClientSize (&width, &height);
-  m_pFrame->SetTitle("ImageFileView");
+  m_pFrame = CreateChildFrame(doc, this);
+  SetFrame (m_pFrame);
   m_pCanvas = CreateCanvas (m_pFrame);
-  
-  //  int x, y;  // X requires a forced resize
-  //  m_pFrame->GetSize(&x, &y);
-  //  m_pFrame->SetSize(-1, -1, x, y);
-  m_pFrame->SetFocus();
+  m_pFrame->SetClientSize (m_pCanvas->GetBestSize());
+  m_pCanvas->SetClientSize (m_pCanvas->GetBestSize());
+  m_pFrame->SetTitle("ImageFileView");
+
   m_pFrame->Show(true);
-  //  Activate(true);
+  Activate(true);
   
   return true;
 }
@@ -1048,11 +1052,6 @@ ImageFileView::setInitialClientSize ()
 {
   if (m_pFrame && m_pCanvas) {
     wxSize bestSize = m_pCanvas->GetBestSize();
-
-    if (bestSize.x > 800)
-      bestSize.x = 800;
-    if (bestSize.y > 800)
-      bestSize.y = 800;
     
     m_pFrame->SetClientSize (bestSize);
     m_pFrame->Show (true);
@@ -1127,7 +1126,6 @@ ImageFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
 bool 
 ImageFileView::OnClose (bool deleteWindow)
 {
-  //GetDocumentManager()->ActivateView (this, false, true);
   if (! GetDocument() || ! GetDocument()->Close())
     return false;
   
@@ -1324,13 +1322,12 @@ ImageFileView::OnConvert3d (wxCommandEvent& event)
 {
   ImageFile& rIF = GetDocument()->getImageFile();
   Graph3dFileDocument* pGraph3d = theApp->newGraph3dDoc();
+  pGraph3d->getView()->getFrame()->Show (false);
   pGraph3d->setBadFileOpen();
   pGraph3d->createFromImageFile (rIF);
-  pGraph3d->getView()->OnUpdate (this, NULL);
   pGraph3d->UpdateAllViews();
-  pGraph3d->getView()->getFrame()->SetClientSize (400, 400);
   pGraph3d->getView()->getFrame()->Show (true);
-  GetDocumentManager()->ActivateView (pGraph3d->getView(), true, false);
+  pGraph3d->getView()->Activate(true);
   ::wxYield();
   pGraph3d->getView()->getCanvas()->SetFocus();
 }
@@ -1958,9 +1955,8 @@ ImageFileView::OnPlotHistogram (wxCommandEvent& event)
 // PhantomCanvas
 
 PhantomCanvas::PhantomCanvas (PhantomFileView* 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;
 }
 
 PhantomCanvas::~PhantomCanvas ()
@@ -2264,9 +2260,8 @@ PhantomFileView::OnRasterize (wxCommandEvent& event)
 PhantomCanvas* 
 PhantomFileView::CreateCanvas (wxFrame *parent)
 {
-  PhantomCanvas* pCanvas;
-  
-  pCanvas = new PhantomCanvas (this, parent, wxPoint(0, 0), wxSize(0,0), 0);
+  PhantomCanvas* pCanvas = new PhantomCanvas (this, parent, wxPoint(-1,-1), 
+                                             wxSize(-1,-1), 0);
   pCanvas->SetBackgroundColour(*wxWHITE);
   pCanvas->Clear();
   
@@ -2281,9 +2276,9 @@ wxDocChildFrame*
 PhantomFileView::CreateChildFrame(wxDocument *doc, wxView *view)
 {
 #if CTSIM_MDI
-  wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
+  wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE);
 #else
-  wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
+  wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE);
 #endif
   theApp->setIconForFrame (subframe);
   
@@ -2368,7 +2363,6 @@ PhantomFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
 bool 
 PhantomFileView::OnClose (bool deleteWindow)
 {
-  //GetDocumentManager()->ActivateView (this, false, true);
   if (! GetDocument() || ! GetDocument()->Close())
     return false;
   
@@ -2428,16 +2422,26 @@ ProjectionFileCanvas::OnDraw(wxDC& dc)
 wxSize
 ProjectionFileCanvas::GetBestSize () const
 {
-  wxSize best (0, 0);
-  if (! m_pView)
-    return best;
+  const int iMinX = 50;
+  const int iMinY = 20;
+  wxSize bestSize (iMinX,iMinY);
 
   if (m_pView) {
     Projections& rProj = m_pView->GetDocument()->getProjections();
-    best.Set (rProj.nDet(), rProj.nView());
+    bestSize.Set (rProj.nDet(), rProj.nView());
   }
   
-  return best;
+  if (bestSize.x > 800)
+    bestSize.x = 800;
+  if (bestSize.y > 800)
+    bestSize.y = 800;
+
+  if (bestSize.x < iMinX)
+    bestSize.x = iMinX;
+  if (bestSize.y < iMinY)
+    bestSize.y = iMinY;
+
+  return bestSize;
 }
 
 
@@ -2975,7 +2979,7 @@ ProjectionFileView::CreateCanvas (wxFrame *parent)
   int width, height;
   parent->GetClientSize(&width, &height);
   
-  pCanvas = new ProjectionFileCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
+  pCanvas = new ProjectionFileCanvas (this, parent, wxPoint(-1,-1), wxSize(width, height), 0);
   
   pCanvas->SetScrollbars(20, 20, 50, 50);
   pCanvas->SetBackgroundColour(*wxWHITE);
@@ -2992,9 +2996,9 @@ wxDocChildFrame*
 ProjectionFileView::CreateChildFrame(wxDocument *doc, wxView *view)
 {
 #ifdef CTSIM_MDI
-  wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
+  wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE);
 #else
-  wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
+  wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE);
 #endif
   theApp->setIconForFrame (subframe);
   
@@ -3082,12 +3086,11 @@ ProjectionFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
 {
   m_pFrame = CreateChildFrame(doc, this);
   SetFrame(m_pFrame);
-  
-  int width, height;
-  m_pFrame->GetClientSize (&width, &height);
-  m_pFrame->SetTitle ("ProjectionFileView");
   m_pCanvas = CreateCanvas (m_pFrame);
-  
+  m_pFrame->SetClientSize (m_pCanvas->GetBestSize());
+  m_pCanvas->SetClientSize (m_pCanvas->GetBestSize());
+  m_pFrame->SetTitle ("ProjectionFileView");
+
   m_pFrame->Show(true);
   Activate(true);
   
@@ -3105,16 +3108,13 @@ ProjectionFileView::OnDraw (wxDC* dc)
 void 
 ProjectionFileView::setInitialClientSize ()
 {
-  wxSize bestSize = m_pCanvas->GetBestSize();
-
-  if (bestSize.x > 800)
-    bestSize.x = 800;
-  if (bestSize.y > 800)
-    bestSize.y = 800;
+  if (m_pFrame && m_pCanvas) {
+    wxSize bestSize = m_pCanvas->GetBestSize();
 
-  m_pFrame->SetClientSize (bestSize);
-  m_pFrame->Show (true);
-  m_pFrame->SetFocus();
+    m_pFrame->SetClientSize (bestSize);
+    m_pFrame->Show (true);
+    m_pFrame->SetFocus();
+  }
 }  
 
 void 
@@ -3344,7 +3344,7 @@ PlotFileView::CreateCanvas (wxFrame* parent)
   int width, height;
   parent->GetClientSize(&width, &height);
   
-  pCanvas = new PlotFileCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
+  pCanvas = new PlotFileCanvas (this, parent, wxPoint(-1,-1), wxSize(width, height), 0);
   
   pCanvas->SetBackgroundColour(*wxWHITE);
   pCanvas->Clear();
@@ -3360,9 +3360,9 @@ wxDocChildFrame*
 PlotFileView::CreateChildFrame(wxDocument *doc, wxView *view)
 {
 #ifdef CTSIM_MDI
-  wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
+  wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(-1,-1), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
 #else
-  wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
+  wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(-1,-1), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
 #endif
   theApp->setIconForFrame (subframe);
   
@@ -3563,7 +3563,7 @@ bool TextFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
   int width, height;
   m_pFrame->GetClientSize(&width, &height);
   m_pFrame->SetTitle("TextFile");
-  m_pCanvas = new TextFileCanvas (this, m_pFrame, wxPoint(0, 0), wxSize(width, height), wxTE_MULTILINE | wxTE_READONLY);
+  m_pCanvas = new TextFileCanvas (this, m_pFrame, wxPoint(-1,-1), wxSize(width, height), wxTE_MULTILINE | wxTE_READONLY);
   m_pFrame->SetTitle("Log");
   
   m_pFrame->Show (true);
@@ -3611,7 +3611,7 @@ wxDocChildFrame*
 TextFileView::CreateChildFrame (wxDocument *doc, wxView *view)
 {
 #if CTSIM_MDI
-  wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "TextFile Frame", wxPoint(-1, -1), wxSize(0,0), wxDEFAULT_FRAME_STYLE, "Log");
+  wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "TextFile Frame", wxPoint(-1, -1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE, "Log");
 #else
   wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "TextFile Frame", wxPoint(-1, -1), wxSize(300, 150), wxDEFAULT_FRAME_STYLE, "Log");
 #endif