r3877: Auto commit for Debian build
[ctsim.git] / src / views.cpp
index 1ce18dbda6210b05b51697e6c446da78820cfdb9..88e5f042fc7dc22b2a030fec80d9713b98c7b42f 100644 (file)
@@ -9,7 +9,7 @@
 **  This is part of the CTSim program
 **  Copyright (c) 1983-2001 Kevin Rosenberg
 **
-**  $Id: views.cpp,v 1.151 2002/05/03 00:40:30 kevin Exp $
+**  $Id: views.cpp,v 1.167 2003/01/29 07:18:38 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
@@ -58,6 +58,8 @@
 #include <sstream_subst>
 #endif
 
+// Used to reduce calls to progress bar update function
+const short int ITER_PER_UPDATE = 10;
 
 // ImageFileCanvas
 
@@ -73,9 +75,7 @@ ImageFileCanvas::ImageFileCanvas (ImageFileView* v, wxFrame *frame, const wxPoin
 }
 
 ImageFileCanvas::~ImageFileCanvas()
-{
-  m_pView = NULL;
-}
+{}
 
 void 
 ImageFileCanvas::OnDraw(wxDC& dc)
@@ -184,17 +184,32 @@ ImageFileCanvas::OnChar (wxKeyEvent& event)
     if (m_pView)
       m_pView->OnUpdate (NULL);
   } else
-    wxScrolledWindow::OnChar (event);
+    event.Skip();
 }
 
 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;
 }
 
 
@@ -253,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_pBitmap(0), 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()
 {
@@ -314,6 +329,7 @@ ImageFileView::OnScaleAuto (wxCommandEvent& event)
       m_dMinPixel = dMin;
       m_dMaxPixel = dMax;
       m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
+      OnUpdate(this, NULL);
       GetDocument()->UpdateAllViews (this);
     }
   }
@@ -852,13 +868,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();
   
@@ -873,12 +884,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");
@@ -898,11 +909,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);
   
@@ -1009,8 +1018,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;
@@ -1020,23 +1029,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;
 }
@@ -1046,11 +1051,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);
@@ -1061,8 +1061,10 @@ ImageFileView::setInitialClientSize ()
 void 
 ImageFileView::OnDraw (wxDC* dc)
 {
-  if (m_bitmap.Ok())
-    dc->DrawBitmap(m_bitmap, 0, 0, false);
+  if (m_pBitmap && m_pBitmap->Ok()) {
+    *theApp->getLog() << "Drawing bitmap";
+    dc->DrawBitmap(*m_pBitmap, 0, 0, false);
+  }
   
   int xCursor, yCursor;
   if (m_pCanvas->GetCurrentCursor (xCursor, yCursor))
@@ -1112,7 +1114,12 @@ ImageFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
       }
     }
     wxImage image (nx, ny, imageData, true);
-    m_bitmap = image.ConvertToBitmap();
+    if (m_pBitmap) {
+      delete m_pBitmap;
+      m_pBitmap = NULL;
+    }
+    *theApp->getLog() << "Making new bitmap bitmap";
+    m_pBitmap = new wxBitmap (image);
     delete imageData;
     m_pCanvas->SetScrollbars(20, 20, nx/20, ny/20);
     m_pCanvas->SetBackgroundColour(*wxWHITE);
@@ -1125,7 +1132,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;
   
@@ -1154,8 +1160,9 @@ void
 ImageFileView::OnEditCopy (wxCommandEvent& event)
 {
   wxBitmapDataObject *pBitmapObject = new wxBitmapDataObject;
-  
-  pBitmapObject->SetBitmap (m_bitmap);
+
+  if (m_pBitmap)
+    pBitmapObject->SetBitmap (*m_pBitmap);
   
   if (wxTheClipboard->Open()) {
     wxTheClipboard->SetData (pBitmapObject);
@@ -1198,7 +1205,7 @@ ImageFileView::OnEditPaste (wxCommandEvent& event)
     bool bMonochrome = false;
 
     if (bitmap.Ok() == true && bitmap.GetWidth() == nx && bitmap.GetHeight() == ny) {
-      wxImage image (bitmap);
+      wxImage image (bitmap.ConvertToImage());
       double dScale3 = 3 * 255;
       unsigned char* pixels = image.GetData();
       ImageFileArray v = rIF.getArray();
@@ -1322,13 +1329,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();
 }
@@ -1956,9 +1962,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 ()
@@ -1985,8 +1990,9 @@ PhantomCanvas::GetBestSize() const
 #ifdef CTSIM_MDI
   ySize = xSize = (xSize / 4);
 #else
-  ySize = xSize;
+  xSize = ySize = static_cast<int>(ySize * .7);
 #endif
+
   return wxSize (xSize, ySize);
 }
 
@@ -2155,10 +2161,11 @@ PhantomFileView::OnProjections (wxCommandEvent& event)
       for (int i = 0; i < pProj->nView(); i++) {
         //theScanner.collectProjections (*pProj, rPhantom, i, 1, true, m_iDefaultTrace);
         theScanner.collectProjections (*pProj, rPhantom, i, 1, theScanner.offsetView(), true, m_iDefaultTrace);
-        if (! dlgProgress.Update (i+1)) {
-          delete pProj;
-          return;
-        }
+       if ((i + 1) % ITER_PER_UPDATE == 0)
+         if (! dlgProgress.Update (i+1)) {
+           delete pProj;
+           return;
+         }
       }
     }
   }
@@ -2173,18 +2180,6 @@ PhantomFileView::OnProjections (wxCommandEvent& event)
     return;
   }
   pProjectionDoc->setProjections (pProj);
-  ProjectionFileView* projView = pProjectionDoc->getView();
-  if (projView) {
-    projView->OnUpdate (projView, NULL);
-    if (projView->getCanvas())
-      projView->getCanvas()->SetClientSize (m_iDefaultNDet, m_iDefaultNView);
-    if (wxFrame* pFrame = projView->getFrame()) {
-      pFrame->Show(true);
-      pFrame->SetFocus();
-      pFrame->Raise();
-    }
-    GetDocumentManager()->ActivateView (projView, true, false);
-  }
   if (theApp->getAskDeleteNewDocs())
     pProjectionDoc-> Modify(true);
   pProjectionDoc->UpdateAllViews (this);
@@ -2234,15 +2229,21 @@ PhantomFileView::OnRasterize (wxCommandEvent& event)
   {
     ImageFile* pImageFile = new ImageFile (m_iDefaultRasterNX, m_iDefaultRasterNY);
 
-    wxProgressDialog dlgProgress (wxString("Rasterize"), wxString("Rasterization Progress"), 
-                 pImageFile->nx() + 1, getFrameForChild(), wxPD_CAN_ABORT );
+    wxProgressDialog dlgProgress (wxString("Rasterize"), 
+                                 wxString("Rasterization Progress"), 
+                                 pImageFile->nx() + 1,
+                                 getFrameForChild(), 
+                                 wxPD_CAN_ABORT );
     Timer timer;
     for (unsigned int i = 0; i < pImageFile->nx(); i++) {
-      rPhantom.convertToImagefile (*pImageFile, m_dDefaultRasterViewRatio, m_iDefaultRasterNSamples, Trace::TRACE_NONE, i, 1, true);
-      if (! dlgProgress.Update (i+1)) {
-       delete pImageFile;
-       return;
-      }
+      rPhantom.convertToImagefile (*pImageFile, m_dDefaultRasterViewRatio, 
+                                  m_iDefaultRasterNSamples, Trace::TRACE_NONE,
+                                  i, 1, true);
+      if ((i + 1) % ITER_PER_UPDATE == 0) 
+       if (! dlgProgress.Update (i+1)) {
+         delete pImageFile;
+         return;
+       }
     }
     
     ImageFileDocument* pRasterDoc = theApp->newImageDoc();
@@ -2256,7 +2257,7 @@ PhantomFileView::OnRasterize (wxCommandEvent& event)
     *theApp->getLog() << os.str().c_str() << "\n";
     pImageFile->labelAdd (os.str().c_str(), timer.timerEnd());
 
-    pRasterDoc->UpdateAllViews();
+    pRasterDoc->UpdateAllViews(this);
     pRasterDoc->getView()->setInitialClientSize();
     pRasterDoc->Activate();
   }
@@ -2266,9 +2267,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();
   
@@ -2283,9 +2283,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);
   
@@ -2306,11 +2306,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);
   
@@ -2370,7 +2368,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;
   
@@ -2430,16 +2427,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;
 }
 
 
@@ -2463,7 +2470,7 @@ END_EVENT_TABLE()
 
 
 ProjectionFileView::ProjectionFileView() 
-: wxView(), m_pFrame(0), m_pCanvas(0), m_pFileMenu(0)
+  : wxView(), m_pBitmap(0), m_pFrame(0), m_pCanvas(0), m_pFileMenu(0)
 {
 #ifdef DEBUG
   m_iDefaultNX = 115;
@@ -2542,6 +2549,7 @@ ProjectionFileView::OnConvertRectangular (wxCommandEvent& event)
   pIF->labelAdd (os.str().c_str());
   if (theApp->getAskDeleteNewDocs())
     pRectDoc->Modify (true);
+  pRectDoc->UpdateAllViews();
   pRectDoc->getView()->setInitialClientSize();
   pRectDoc->Activate();
 }
@@ -2623,7 +2631,7 @@ ProjectionFileView::OnConvertFFTPolar (wxCommandEvent& event)
     pIF->labelAdd (os.str().c_str());
     if (theApp->getAskDeleteNewDocs())
       pPolarDoc->Modify (true);
-    pPolarDoc->UpdateAllViews ();
+    pPolarDoc->UpdateAllViews (this);
     pPolarDoc->getView()->setInitialClientSize();
     pPolarDoc->Activate();
   }
@@ -2935,10 +2943,11 @@ ProjectionFileView::doReconstructFBP (const Projections& rProj, bool bRebinToPar
       
       for (int iView = 0; iView < rProj.nView(); iView++) {
         pReconstructor->reconstructView (iView, 1);
-        if (! dlgProgress.Update (iView + 1)) {
-          delete pReconstructor;
-          return; // don't make new window, thread will do this
-        }
+       if ((iView + 1) % ITER_PER_UPDATE == 0) 
+         if (! dlgProgress.Update (iView + 1)) {
+           delete pReconstructor;
+           return; // don't make new window, thread will do this
+         }
       }
       pReconstructor->postProcessing();
       delete pReconstructor;
@@ -2975,7 +2984,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 +3001,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);
   
@@ -3016,11 +3025,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);
   
@@ -3082,12 +3089,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);
   
@@ -3097,24 +3103,21 @@ ProjectionFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
 void 
 ProjectionFileView::OnDraw (wxDC* dc)
 {
-  if (m_bitmap.Ok())
-    dc->DrawBitmap (m_bitmap, 0, 0, false);
+  if (m_pBitmap && m_pBitmap->Ok())
+    dc->DrawBitmap (*m_pBitmap, 0, 0, false);
 }
 
 
 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 
@@ -3156,18 +3159,19 @@ ProjectionFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint)
       }
     }
     wxImage image (nDet, nView, imageData, true);
-    m_bitmap = image.ConvertToBitmap();
+    if (m_pBitmap) {
+      delete m_pBitmap;
+      m_pBitmap = NULL;
+    }
+    m_pBitmap = new wxBitmap (image);
     delete imageData;
-    //int xSize = nDet;
-    //int ySize = nView;
-    //xSize = clamp (xSize, 0, 800);
-    //ySize = clamp (ySize, 0, 800);
-    //m_pFrame->SetClientSize (xSize, ySize);
-    m_pCanvas->SetScrollbars (20, 20, nDet/20, nView/20);
   }
   
-  if (m_pCanvas)
-    m_pCanvas->Refresh();
+    m_pCanvas->SetScrollbars(20, 20, nDet/20, nView/20);
+    m_pCanvas->SetBackgroundColour(*wxWHITE);
+
+    if (m_pCanvas)
+      m_pCanvas->Refresh();
 }
 
 bool 
@@ -3202,33 +3206,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)
 {
@@ -3249,7 +3241,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)
 {
 }
 
@@ -3259,6 +3252,7 @@ PlotFileView::~PlotFileView()
     delete m_pEZPlot;
   
   GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);  
+  GetDocumentManager()->ActivateView(this, FALSE, TRUE);
 }
 
 void
@@ -3344,11 +3338,8 @@ PlotFileCanvas*
 PlotFileView::CreateCanvas (wxFrame* parent)
 {
   PlotFileCanvas* pCanvas;
-  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(-1,-1), 0);  
   pCanvas->SetBackgroundColour(*wxWHITE);
   pCanvas->Clear();
   
@@ -3363,9 +3354,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(-1,-1), 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(-1,-1), wxDEFAULT_FRAME_STYLE);
 #endif
   theApp->setIconForFrame (subframe);
   
@@ -3387,11 +3378,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);
   
@@ -3430,17 +3419,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);
@@ -3448,6 +3436,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)
 {
@@ -3522,7 +3523,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;
   
@@ -3566,7 +3566,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);
@@ -3614,7 +3614,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
@@ -3635,11 +3635,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);
   
@@ -3673,7 +3671,7 @@ TextFileCanvas::~TextFileCanvas ()
 }
 
 wxSize
-PlotFileCanvas::GetBestSize() const
+TextFileCanvas::GetBestSize() const
 {
   int xSize, ySize;
   theApp->getMainFrame()->GetClientSize (&xSize, &ySize);