r7061: initial property settings
[ctsim.git] / src / dlgezplot.cpp
index acebadb413f3ad0fc172078b380d527e4ca0c24e..880e89763ad9fad11b8cd288f5bfdfdb4f7751dc 100644 (file)
@@ -7,9 +7,9 @@
 **   Date Started:  Jan 2001
 **
 **  This is part of the CTSim program
-**  Copyright (C) 1983-2001 Kevin Rosenberg
+**  Copyright (c) 1983-2001 Kevin Rosenberg
 **
-**  $Id: dlgezplot.cpp,v 1.1 2001/01/12 16:41:56 kevin Exp $
+**  $Id$
 **
 **  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
 **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 ******************************************************************************/
 
-#ifdef __GNUG__
-#pragma implementation "dlgezplot.h"
+#ifdef HAVE_CONFIG_H
+#include "config.h"
 #endif
 
+#ifdef HAVE_WXWINDOWS
+
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
-#ifdef __BORLANDC__
-#pragma hdrstop
-#endif
-
 #ifndef WX_PRECOMP
 #include "wx/utils.h"
 #include "wx/frame.h"
 #include "wx/timer.h"
 #endif
 
-#include "dlgezplot.h"
 #include "ct.h"
+#include "../src/ctsim.h"
+#include "dlgezplot.h"
 
 
 static const int LAYOUT_X_MARGIN = 4;
 static const int LAYOUT_Y_MARGIN = 4;
 
-BEGIN_EVENT_TABLE(EZPlotDialog, wxDialog)
-EVT_BUTTON(wxID_CANCEL, EZPlotDialog::OnCancel)
-EVT_CLOSE(EZPlotDialog::OnClose)
-EVT_PAINT(EZPlotDialog::OnPaint)
+BEGIN_EVENT_TABLE(EZPlotControl, wxPanel)
+EVT_PAINT(EZPlotControl::OnPaint)
 END_EVENT_TABLE()
 
-IMPLEMENT_CLASS(EZPlotDialog, wxDialog)
+IMPLEMENT_CLASS(EZPlotControl, wxPanel)
 
 
-EZPlotDialog::EZPlotDialog (wxWindow *parent)
-: wxDialog(parent, -1, wxString("EZPlot"), wxDefaultPosition, wxDefaultSize, wxDIALOG_MODAL | wxDEFAULT_DIALOG_STYLE), 
-  m_pEZPlot(0), m_pSGPDriver(0), m_pSGP(0), m_pDC(0)
+EZPlotControl::EZPlotControl (wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, 
+                              long style, const wxValidator& validator, const wxString& name)
+     : m_pEZPlot(0), m_pSGPDriver(0), m_pSGP(0), m_pDC(0)
 {
-    m_parentTop = parent;
-    while ( m_parentTop && m_parentTop->GetParent() )
-        m_parentTop = m_parentTop->GetParent();
-    
-    wxLayoutConstraints* c = new wxLayoutConstraints;
-    c->right.SameAs(this, wxRight, 2*LAYOUT_X_MARGIN);
-    c->bottom.SameAs(this, wxBottom, 2*LAYOUT_Y_MARGIN);
-       
-    wxSize sizeBtn = wxButton::GetDefaultSize();
-    c->width.Absolute(sizeBtn.x);
-    c->height.Absolute(sizeBtn.y);
-       
-    SetAutoLayout(TRUE);
-    Layout();
-       
-    wxSize sizeDlg (500,500);
-    if (sizeDlg.x != sizeDlg.y) {
-               sizeDlg.x = max(sizeDlg.x,sizeDlg.y);
-               sizeDlg.y = max(sizeDlg.x,sizeDlg.y);
-    }
-       
-    m_iClientX = sizeDlg.x;
-    m_iClientY = sizeDlg.y;
-    SetClientSize(sizeDlg);
-       
-    Centre(wxCENTER_FRAME | wxBOTH);
-       
-    if ( m_parentTop )
-               m_parentTop->Enable(FALSE);
-       
-    Show(TRUE);
-    Enable(TRUE); // enable this window
-       
-    m_pDC = dynamic_cast<wxDC*> (new wxClientDC (this));
-    int x, y;
-    this->GetClientSize(&x, &y);
-    m_pSGPDriver = new SGPDriver (m_pDC, x, y);
-    m_pSGP = new SGP (*m_pSGPDriver);
-    m_pSGP->setTextPointSize(10);
-    m_pEZPlot = new EZPlot;
-    
-#ifdef __WXMAC__
-    MacUpdateImmediately();
-#endif
-}
+  Create(parent, id, pos, size, style, name);
 
+  SetSize (GetBestSize());
+
+  m_pEZPlot = new EZPlot;
+}
 
-void EZPlotDialog::OnClose(wxCloseEvent& event)
+wxSize
+EZPlotControl::GetBestSize () const
 {
+  return wxSize (500,500);
+}
+
+EZPlotControl::~EZPlotControl()
+{    
+  delete m_pEZPlot;
+  delete m_pSGP;
+  delete m_pSGPDriver;
+  delete m_pDC;
 }
 
 void
-EZPlotDialog::OnPaint (wxPaintEvent& event)
+EZPlotControl::OnPaint (wxPaintEvent& event)
 {
-  m_pEZPlot->plot (m_pSGP);
+  wxPaintDC dc(this);
+  GetClientSize (&m_iClientX, &m_iClientY);
+  m_pSGPDriver = new SGPDriver (&dc, m_iClientX, m_iClientY);
+  m_pSGP = new SGP (*m_pSGPDriver);
+  m_pSGP->setTextPointSize(10);
+//  m_pSGP->setViewport (0, 0, 1., 0.5);  // for debugging testing only
+  if (m_pEZPlot && m_pSGP) {
+    m_pSGP->eraseWindow();
+    m_pEZPlot->plot (m_pSGP);
+  }
 }
 
 
-/////////////////////////////////////////////////////
-// destruction
+wxEZPlotDialog::wxEZPlotDialog (wxWindow *parent, bool bCancelButton)
+: wxDialog((parent ? parent : theApp->getMainFrame()), -1, wxString("EZPlot"), wxDefaultPosition, wxDefaultSize, wxDIALOG_MODAL),
+  m_parentTop(0)
+{
+  if (! parent)
+    parent = theApp->getMainFrame();
+
+  m_parentTop = parent;
+  while ( m_parentTop && m_parentTop->GetParent() )
+    m_parentTop = m_parentTop->GetParent();
+    
+  wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL);
+
+  pTopSizer->Add (m_pEZPlotCtrl = new EZPlotControl (this), 0, wxALIGN_CENTER | wxALL, 5);
+  
+  wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL);
+  wxButton* pButtonOk = new wxButton (this, wxID_OK, "Ok");
+  pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10);
+  if (bCancelButton) {
+    wxButton* pButtonCancel = new wxButton (this, wxID_CANCEL, "Cancel");
+    pButtonSizer->Add (pButtonCancel, 0, wxEXPAND | wxALL, 10);
+  }  
+  pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER);
+  
+  SetAutoLayout (true);
+  SetSizer (pTopSizer);
+  pTopSizer->Fit (this);
+  pTopSizer->SetSizeHints (this);
+}
 
-EZPlotDialog::~EZPlotDialog()
+
+
+EZPlotDialog::EZPlotDialog(wxWindow* parent, bool bCancelButton)
+    : m_pDialog(new wxEZPlotDialog(parent, bCancelButton))
 {
-       if ( m_parentTop )
-               m_parentTop->Enable(TRUE);
+}
 
-  delete m_pEZPlot;
-       delete m_pSGP;
-       delete m_pSGPDriver;
-       delete m_pDC;
+EZPlot*
+EZPlotDialog::getEZPlot()
+{ return m_pDialog->getEZPlot(); }
+
+int
+EZPlotDialog::ShowModal()
+{ return m_pDialog->ShowModal(); }
+
+wxEZPlotDialog::~wxEZPlotDialog()
+{
+  if ( m_parentTop )
+    m_parentTop->Enable(TRUE);
 }
 
+
+
+#endif // HAVE_WXWINDOWS