From dc5eb7b285e647a99535740a99d73d468a856ba3 Mon Sep 17 00:00:00 2001 From: "Kevin M. Rosenberg" Date: Fri, 3 May 2002 00:40:30 +0000 Subject: [PATCH] r1864: border fixes --- src/ctsim.cpp | 67 ++++--------------- src/docs.cpp | 5 +- src/views.cpp | 176 +++++++++++++++++++++++++++----------------------- src/views.h | 6 +- 4 files changed, 117 insertions(+), 137 deletions(-) diff --git a/src/ctsim.cpp b/src/ctsim.cpp index a51a365..d8b0737 100644 --- a/src/ctsim.cpp +++ b/src/ctsim.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (c) 1983-2001 Kevin Rosenberg ** -** $Id: ctsim.cpp,v 1.104 2001/09/24 15:16:41 kevin Exp $ +** $Id: ctsim.cpp,v 1.105 2002/05/03 00:40:30 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 @@ -70,7 +70,7 @@ #endif #endif -static const char* rcsindent = "$Id: ctsim.cpp,v 1.104 2001/09/24 15:16:41 kevin Exp $"; +static const char* rcsindent = "$Id: ctsim.cpp,v 1.105 2002/05/03 00:40:30 kevin Exp $"; struct option CTSimApp::ctsimOptions[] = { @@ -186,7 +186,7 @@ CTSimApp::OnInit() int xSize, ySize; m_pFrame->GetClientSize(&xSize, &ySize); int yLogSize = ySize / 4; - m_pLogDoc->getView()->getFrame()->SetSize (0, ySize - yLogSize, xSize, yLogSize); + m_pLogDoc->getView()->getFrame()->SetClientSize (0, ySize - yLogSize, xSize, yLogSize); m_pLogDoc->getView()->getFrame()->Show (true); } else #else @@ -524,8 +524,8 @@ MainFrame::OnSize (wxSizeEvent& event) int xSize, ySize; GetClientSize(&xSize, &ySize); int yLogSize = ySize / 4; - theApp->getLogDoc()->getView()->getFrame()->SetSize (0, ySize - yLogSize, xSize, yLogSize); - theApp->getLogDoc()->getView()->getFrame()->Show (true); + theApp->getLogDoc()->getView()->getFrame()->SetSize (0, ySize - yLogSize, xSize, yLogSize); + theApp->getLogDoc()->getView()->getFrame()->Show (true); } #endif @@ -624,15 +624,14 @@ MainFrame::OnNewImageFile (wxCommandEvent& event) return; } pImageDoc->setImageFile (pImageFile); - pImageDoc->UpdateAllViews (NULL); - if (ImageFileView* imageView = pImageDoc->getView()) { - imageView->OnUpdate (imageView, NULL); - imageView->getFrame()->SetFocus(); - imageView->getFrame()->Show(true); - } + // pImageDoc->UpdateAllViews (NULL); + // if (ImageFileView* imageView = pImageDoc->getView()) { + // imageView->OnUpdate (imageView, NULL); + // imageView->getFrame()->SetFocus(); + // imageView->getFrame()->Show(true); + // } if (theApp->getAskDeleteNewDocs()) pImageDoc->Modify (true); - } void @@ -1076,7 +1075,9 @@ CTSimApp::newProjectionDoc() if (pView) { wxFrame* pFrame = pView->getFrame(); if (pFrame) { - pFrame->SetSize (0,0); + // wxSize size; + // m_pFrame->GetClientSize (&size.x, &size.y); + // pFrame->SetClientSize (size.x / 2, size.y / 2); pFrame->Show (false); } } @@ -1093,14 +1094,6 @@ CTSimApp::newImageDoc() { ImageFileDocument* newDoc = dynamic_cast(m_pDocTemplImage->CreateDocument ("")); if (newDoc) { - ImageFileView* pView = newDoc->getView(); - if (pView) { - wxFrame* pFrame = pView->getFrame(); - if (pFrame) { - pFrame->SetSize (0,0); - pFrame->Show (false); - } - } newDoc->SetDocumentName (m_pDocTemplImage->GetDocumentName()); newDoc->SetDocumentTemplate (m_pDocTemplImage); newDoc->OnNewDocument(); @@ -1114,16 +1107,6 @@ CTSimApp::newPlotDoc() { PlotFileDocument* newDoc = dynamic_cast(m_pDocTemplPlot->CreateDocument ("")); if (newDoc) { - PlotFileView* pView = newDoc->getView(); - if (pView) { - wxFrame* pFrame = pView->getFrame(); - if (pFrame) { - wxSize size; - m_pFrame->GetClientSize (&size.x, &size.y); - pFrame->SetSize (size.x / 2, size.y / 2); - pFrame->Show (false); - } - } newDoc->SetDocumentName (m_pDocTemplPlot->GetDocumentName()); newDoc->SetDocumentTemplate (m_pDocTemplPlot); newDoc->OnNewDocument(); @@ -1141,16 +1124,6 @@ CTSimApp::newTextDoc() TextFileDocument* newDoc = dynamic_cast(m_pDocTemplText->CreateDocument ("")); if (newDoc) { - TextFileView* pView = newDoc->getView(); - if (pView) { - wxFrame* pFrame = pView->getFrame(); - if (pFrame) { - wxSize size; - m_pFrame->GetClientSize (&size.x, &size.y);; - pFrame->SetSize (size.x / 2, size.y / 2); - pFrame->Show (false); - } - } newDoc->SetDocumentName (m_pDocTemplText->GetDocumentName()); newDoc->SetDocumentTemplate (m_pDocTemplText); newDoc->OnNewDocument(); @@ -1165,12 +1138,6 @@ CTSimApp::newPhantomDoc() { PhantomFileDocument* newDoc = dynamic_cast(m_pDocTemplPhantom->CreateDocument ("")); if (newDoc) { - PhantomFileView* pView = newDoc->getView(); - if (pView) { - wxFrame* pFrame = pView->getFrame(); - if (pFrame) - pFrame->SetSize (0,0); - } newDoc->SetDocumentName (m_pDocTemplPhantom->GetDocumentName()); newDoc->SetDocumentTemplate (m_pDocTemplPhantom); newDoc->OnNewDocument(); @@ -1186,12 +1153,6 @@ CTSimApp::newGraph3dDoc() { Graph3dFileDocument* newDoc = dynamic_cast(m_pDocTemplGraph3d->CreateDocument ("")); if (newDoc) { - Graph3dFileView* pView = newDoc->getView(); - if (pView) { - wxFrame* pFrame = pView->getFrame(); - if (pFrame) - pFrame->SetSize (0,0); - } newDoc->SetDocumentName (m_pDocTemplGraph3d->GetDocumentName()); newDoc->SetDocumentTemplate (m_pDocTemplGraph3d); newDoc->OnNewDocument(); diff --git a/src/docs.cpp b/src/docs.cpp index 2c18e4a..47ca4dc 100644 --- a/src/docs.cpp +++ b/src/docs.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (c) 1983-2001 Kevin Rosenberg ** -** $Id: docs.cpp,v 1.37 2002/04/30 18:13:40 kevin Exp $ +** $Id: docs.cpp,v 1.38 2002/05/03 00:40:30 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 @@ -80,7 +80,7 @@ bool ImageFileDocument::OnOpenDocument(const wxString& filename) SetFilename(filename, true); Modify(false); UpdateAllViews(); - // getView()->OnUpdate (NULL, NULL); + getView()->setInitialClientSize(); m_bBadFileOpen = false; return true; @@ -226,6 +226,7 @@ ProjectionFileDocument::OnOpenDocument(const wxString& filename) SetFilename(filename, true); Modify(false); UpdateAllViews(); + getView()->setInitialClientSize(); m_bBadFileOpen = false; return true; diff --git a/src/views.cpp b/src/views.cpp index 3aca5d4..1ce18db 100644 --- a/src/views.cpp +++ b/src/views.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (c) 1983-2001 Kevin Rosenberg ** -** $Id: views.cpp,v 1.150 2002/05/01 15:17:36 kevin Exp $ +** $Id: views.cpp,v 1.151 2002/05/03 00:40:30 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 @@ -408,9 +408,8 @@ ImageFileView::OnCompare (wxCommandEvent& event) pDifferenceImage->labelAdd (os.str().c_str()); if (theApp->getAskDeleteNewDocs()) pDifferenceDoc->Modify (true); - pDifferenceDoc->UpdateAllViews (this); - pDifferenceDoc->getView()->OnUpdate (this, NULL); - pDifferenceDoc->getView()->getFrame()->Show(true); + pDifferenceDoc->UpdateAllViews(this); + pDifferenceDoc->getView()->setInitialClientSize(); pDifferenceDoc->Activate(); } wxMessageBox(os.str().c_str(), "Image Comparison"); @@ -513,7 +512,7 @@ ImageFileView::OnAdd (wxCommandEvent& event) if (theApp->getAskDeleteNewDocs()) pNewDoc->Modify (true); pNewDoc->UpdateAllViews (this); - pNewDoc->getView()->getFrame()->Show(true); + pNewDoc->getView()->setInitialClientSize(); pNewDoc->Activate(); } } @@ -554,7 +553,7 @@ ImageFileView::OnSubtract (wxCommandEvent& event) if (theApp->getAskDeleteNewDocs()) pNewDoc->Modify (true); pNewDoc->UpdateAllViews (this); - pNewDoc->getView()->getFrame()->Show(true); + pNewDoc->getView()->setInitialClientSize(); pNewDoc->Activate(); } } @@ -595,7 +594,7 @@ ImageFileView::OnMultiply (wxCommandEvent& event) if (theApp->getAskDeleteNewDocs()) pNewDoc->Modify (true); pNewDoc->UpdateAllViews (this); - pNewDoc->getView()->getFrame()->Show(true); + pNewDoc->getView()->setInitialClientSize(); pNewDoc->Activate(); } } @@ -636,7 +635,7 @@ ImageFileView::OnDivide (wxCommandEvent& event) if (theApp->getAskDeleteNewDocs()) pNewDoc->Modify (true); pNewDoc->UpdateAllViews (this); - pNewDoc->getView()->getFrame()->Show(true); + pNewDoc->getView()->setInitialClientSize(); pNewDoc->Activate(); } } @@ -1042,14 +1041,26 @@ ImageFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) ) return true; } +void +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); + m_pFrame->SetFocus(); + } +} + void ImageFileView::OnDraw (wxDC* dc) { - wxSize sizeWindow = m_pFrame->GetClientSize(); - wxSize sizeBest = m_pCanvas->GetBestSize(); - if (sizeWindow.x > sizeBest.x || sizeWindow.y > sizeBest.y) - m_pFrame->SetClientSize (sizeBest); - if (m_bitmap.Ok()) dc->DrawBitmap(m_bitmap, 0, 0, false); @@ -1103,10 +1114,6 @@ ImageFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) ) wxImage image (nx, ny, imageData, true); m_bitmap = image.ConvertToBitmap(); delete imageData; - int xSize = nx; - int ySize = ny; - ySize = clamp (ySize, 0, 800); - // m_pFrame->SetClientSize (xSize, ySize); // KMR m_pCanvas->SetScrollbars(20, 20, nx/20, ny/20); m_pCanvas->SetBackgroundColour(*wxWHITE); } @@ -1304,7 +1311,7 @@ ImageFileView::OnScaleSize (wxCommandEvent& event) if (theApp->getAskDeleteNewDocs()) pScaledDoc->Modify (true); pScaledDoc->UpdateAllViews (this); - pScaledDoc->getView()->getFrame()->Show(true); + pScaledDoc->getView()->setInitialClientSize(); pScaledDoc->Activate(); } } @@ -2181,6 +2188,7 @@ PhantomFileView::OnProjections (wxCommandEvent& event) if (theApp->getAskDeleteNewDocs()) pProjectionDoc-> Modify(true); pProjectionDoc->UpdateAllViews (this); + pProjectionDoc->getView()->setInitialClientSize(); pProjectionDoc->Activate(); } @@ -2248,14 +2256,9 @@ PhantomFileView::OnRasterize (wxCommandEvent& event) *theApp->getLog() << os.str().c_str() << "\n"; pImageFile->labelAdd (os.str().c_str(), timer.timerEnd()); - if (ImageFileView* rasterView = pRasterDoc->getView()) { - rasterView->getFrame()->Show(true); - rasterView->getFrame()->SetFocus(); - rasterView->OnUpdate (rasterView, NULL); - } - // Causes loss of frame in wxGTK - // pRasterDoc->UpdateAllViews (this); - // pRasterDoc->Activate(); + pRasterDoc->UpdateAllViews(); + pRasterDoc->getView()->setInitialClientSize(); + pRasterDoc->Activate(); } } @@ -2349,15 +2352,8 @@ PhantomFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) ) m_pCanvas = CreateCanvas (m_pFrame); m_pFrame->SetClientSize (m_pCanvas->GetBestSize()); m_pCanvas->SetClientSize (m_pCanvas->GetBestSize()); - m_pFrame->SetTitle ("PhantomFileView"); - -#ifdef __X__ - int x, y; // X requires a forced resize - m_pFrame->GetSize(&x, &y); - m_pFrame->SetSize(-1, -1, x, y); -#endif - + m_pFrame->Show(true); Activate(true); @@ -2435,6 +2431,9 @@ wxSize ProjectionFileCanvas::GetBestSize () const { wxSize best (0, 0); + if (! m_pView) + return best; + if (m_pView) { Projections& rProj = m_pView->GetDocument()->getProjections(); best.Set (rProj.nDet(), rProj.nView()); @@ -2543,8 +2542,7 @@ ProjectionFileView::OnConvertRectangular (wxCommandEvent& event) pIF->labelAdd (os.str().c_str()); if (theApp->getAskDeleteNewDocs()) pRectDoc->Modify (true); - pRectDoc->getView()->getFrame()->Show(true); - pRectDoc->UpdateAllViews (); + pRectDoc->getView()->setInitialClientSize(); pRectDoc->Activate(); } @@ -2584,8 +2582,8 @@ ProjectionFileView::OnConvertPolar (wxCommandEvent& event) pIF->labelAdd (os.str().c_str()); if (theApp->getAskDeleteNewDocs()) pPolarDoc->Modify (true); - pPolarDoc->getView()->getFrame()->Show(true); pPolarDoc->UpdateAllViews (); + pPolarDoc->getView()->setInitialClientSize(); pPolarDoc->Activate(); } } @@ -2625,8 +2623,8 @@ ProjectionFileView::OnConvertFFTPolar (wxCommandEvent& event) pIF->labelAdd (os.str().c_str()); if (theApp->getAskDeleteNewDocs()) pPolarDoc->Modify (true); - pPolarDoc->getView()->getFrame()->Show(true); pPolarDoc->UpdateAllViews (); + pPolarDoc->getView()->setInitialClientSize(); pPolarDoc->Activate(); } } @@ -2774,6 +2772,7 @@ ProjectionFileView::OnConvertParallel (wxCommandEvent& event) if (theApp->getAskDeleteNewDocs()) pProjDocNew-> Modify(true); pProjDocNew->UpdateAllViews (this); + pProjDocNew->getView()->setInitialClientSize(); pProjDocNew->Activate(); } @@ -2818,8 +2817,8 @@ ProjectionFileView::OnReconstructFourier (wxCommandEvent& event) pIF->labelAdd (os.str().c_str()); if (theApp->getAskDeleteNewDocs()) pPolarDoc->Modify (true); - pPolarDoc->getView()->getFrame()->Show(true); pPolarDoc->UpdateAllViews (); + pPolarDoc->getView()->setInitialClientSize(); pPolarDoc->Activate(); } } @@ -2950,22 +2949,16 @@ ProjectionFileView::doReconstructFBP (const Projections& rProj, bool bRebinToPar sys_error (ERR_SEVERE, "Unable to create image file"); return; } - pReconDoc->setImageFile (pImageFile); - if (theApp->getAskDeleteNewDocs()) - pReconDoc->Modify (true); *theApp->getLog() << os.str().c_str() << "\n"; pImageFile->labelAdd (rProj.getLabel()); pImageFile->labelAdd (os.str().c_str(), timerRecon.timerEnd()); - // if (ImageFileView* rasterView = pReconDoc->getView()) { - // rasterView->getFrame()->Show(true); - // rasterView->getFrame()->SetFocus(); - // rasterView->OnUpdate (rasterView, NULL); - // } - // causes loss of frame in wxGTK - pReconDoc->GetFirstView()->GetFrame()->Show(true); - pReconDoc->UpdateAllViews (); - // pReconDoc->Activate(); + pReconDoc->setImageFile (pImageFile); + if (theApp->getAskDeleteNewDocs()) + pReconDoc->Modify (true); + pReconDoc->UpdateAllViews(); + pReconDoc->getView()->setInitialClientSize(); + pReconDoc->Activate(); } @@ -3095,12 +3088,6 @@ ProjectionFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) ) m_pFrame->SetTitle ("ProjectionFileView"); m_pCanvas = CreateCanvas (m_pFrame); -#ifdef __X__ - int x, y; // X requires a forced resize - m_pFrame->GetSize(&x, &y); - m_pFrame->SetSize(-1, -1, x, y); -#endif - m_pFrame->Show(true); Activate(true); @@ -3110,17 +3097,26 @@ ProjectionFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) ) void ProjectionFileView::OnDraw (wxDC* dc) { - wxSize clientSize = m_pFrame->GetClientSize(); - wxSize bestSize = m_pCanvas->GetBestSize(); - - if (clientSize.x > bestSize.x || clientSize.y > bestSize.y) - m_pFrame->SetClientSize (bestSize); - if (m_bitmap.Ok()) dc->DrawBitmap (m_bitmap, 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; + + m_pFrame->SetClientSize (bestSize); + m_pFrame->Show (true); + m_pFrame->SetFocus(); +} + void ProjectionFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) ) { @@ -3162,11 +3158,11 @@ ProjectionFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) wxImage image (nDet, nView, imageData, true); m_bitmap = image.ConvertToBitmap(); delete imageData; - int xSize = nDet; - int ySize = nView; - xSize = clamp (xSize, 0, 800); - ySize = clamp (ySize, 0, 800); - m_pFrame->SetClientSize (xSize, ySize); + //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); } @@ -3211,6 +3207,23 @@ PlotFileCanvas::PlotFileCanvas (PlotFileView* v, wxFrame *frame, const wxPoint& m_pView = v; } +wxSize +PlotFileCanvas::GetBestSize() const +{ + if (! m_pView) + return wxSize(0,0); + + int xSize, ySize; + theApp->getMainFrame()->GetClientSize (&xSize, &ySize); + xSize = maxValue (xSize, ySize); +#ifdef CTSIM_MDI + ySize = xSize = (xSize / 4); +#else + ySize = xSize; +#endif + return wxSize (xSize, ySize); +} + PlotFileCanvas::~PlotFileCanvas () { m_pView = NULL; @@ -3429,12 +3442,6 @@ PlotFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) ) m_pFrame->SetTitle ("Plot File"); m_pCanvas = CreateCanvas (m_pFrame); -#ifdef __X__ - int x, y; // X requires a forced resize - m_pFrame->GetSize(&x, &y); - m_pFrame->SetSize(-1, -1, x, y); -#endif - m_pFrame->Show(true); Activate(true); @@ -3562,13 +3569,6 @@ bool TextFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) ) m_pCanvas = new TextFileCanvas (this, m_pFrame, wxPoint(0, 0), wxSize(width, height), wxTE_MULTILINE | wxTE_READONLY); m_pFrame->SetTitle("Log"); -#ifdef __X__ - // X seems to require a forced resize - int x, y; - frame->GetSize(&x, &y); - frame->SetSize(-1, -1, x, y); -#endif - m_pFrame->Show (true); Activate (true); @@ -3671,3 +3671,17 @@ TextFileCanvas::~TextFileCanvas () { m_pView = NULL; } + +wxSize +PlotFileCanvas::GetBestSize() const +{ + int xSize, ySize; + theApp->getMainFrame()->GetClientSize (&xSize, &ySize); + xSize = maxValue (xSize, ySize); +#ifdef CTSIM_MDI + ySize = xSize = (xSize / 4); +#else + ySize = xSize; +#endif + return wxSize (xSize, ySize); +} diff --git a/src/views.h b/src/views.h index 40cc6fd..b820eef 100644 --- a/src/views.h +++ b/src/views.h @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (c) 1983-2001 Kevin Rosenberg ** -** $Id: views.h,v 1.56 2001/09/24 09:40:42 kevin Exp $ +** $Id: views.h,v 1.57 2002/05/03 00:40:30 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 @@ -151,6 +151,7 @@ public: #else wxDocChildFrame* getFrame() { return m_pFrame; } #endif + void setInitialClientSize(); wxMenu* getMenuAnalyze() { return m_pMenuAnalyze; } @@ -262,6 +263,7 @@ public: wxDocChildFrame* getFrame() { return m_pFrame; } #endif ProjectionFileCanvas* getCanvas() { return m_pCanvas; } + void setInitialClientSize(); wxMenu* getFileMenu() { return m_pFileMenu; } @@ -440,6 +442,7 @@ public: virtual ~PlotFileCanvas(); virtual void OnDraw(wxDC& dc); + virtual wxSize GetBestSize() const; void setView (PlotFileView* pView) { m_pView = pView; } @@ -494,6 +497,7 @@ class TextFileCanvas: public wxTextCtrl public: TextFileCanvas (TextFileView *v, wxFrame *frame, const wxPoint& pos, const wxSize& size, long style); ~TextFileCanvas (); + virtual wxSize GetBestSize() const; }; -- 2.34.1