r390: no message
[ctsim.git] / libctgraphics / dlgezplot.cpp
1 /*****************************************************************************
2 ** FILE IDENTIFICATION
3 **
4 **   Name:          dlgezplot.cpp
5 **   Purpose:       EZPlot Dialog
6 **   Programmer:    Kevin Rosenberg
7 **   Date Started:  Jan 2001
8 **
9 **  This is part of the CTSim program
10 **  Copyright (C) 1983-2001 Kevin Rosenberg
11 **
12 **  $Id: dlgezplot.cpp,v 1.1 2001/01/13 04:47:50 kevin Exp $
13 **
14 **  This program is free software; you can redistribute it and/or modify
15 **  it under the terms of the GNU General Public License (version 2) as
16 **  published by the Free Software Foundation.
17 **
18 **  This program is distributed in the hope that it will be useful,
19 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
20 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 **  GNU General Public License for more details.
22 **
23 **  You should have received a copy of the GNU General Public License
24 **  along with this program; if not, write to the Free Software
25 **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26 ******************************************************************************/
27
28 #ifdef HAVE_WXWINDOWS
29
30 #ifdef __GNUG__
31 #pragma implementation "dlgezplot.h"
32 #endif
33
34 // For compilers that support precompilation, includes "wx.h".
35 #include "wx/wxprec.h"
36
37 #ifdef __BORLANDC__
38 #pragma hdrstop
39 #endif
40
41 #ifndef WX_PRECOMP
42 #include "wx/utils.h"
43 #include "wx/frame.h"
44 #include "wx/button.h"
45 #include "wx/stattext.h"
46 #include "wx/layout.h"
47 #include "wx/event.h"
48 #include "wx/intl.h"
49 #include "wx/settings.h"
50 #include "wx/dcclient.h"
51 #include "wx/timer.h"
52 #endif
53
54 #include "ct.h"
55 #include "../src/ctsim.h"
56 #include "dlgezplot.h"
57
58
59 static const int LAYOUT_X_MARGIN = 4;
60 static const int LAYOUT_Y_MARGIN = 4;
61
62 BEGIN_EVENT_TABLE(EZPlotControl, wxPanel)
63 EVT_PAINT(EZPlotControl::OnPaint)
64 END_EVENT_TABLE()
65
66 IMPLEMENT_CLASS(EZPlotControl, wxPanel)
67
68
69 EZPlotControl::EZPlotControl (wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, 
70                        const wxValidator& validator, const wxString& name)
71      : m_pEZPlot(0), m_pSGPDriver(0), m_pSGP(0), m_pDC(0)
72 {
73   Create(parent, id, pos, size, style, name);
74
75   SetSize (GetBestSize());
76
77   m_pEZPlot = new EZPlot;
78 }
79
80 wxSize
81 EZPlotControl::GetBestSize () const
82 {
83   return wxSize (500,500);
84 }
85
86 EZPlotControl::~EZPlotControl()
87 {    
88   delete m_pEZPlot;
89   delete m_pSGP;
90   delete m_pSGPDriver;
91   delete m_pDC;
92 }
93
94 void
95 EZPlotControl::OnPaint (wxPaintEvent& event)
96 {
97   wxPaintDC dc(this);
98   GetClientSize (&m_iClientX, &m_iClientY);
99   m_pSGPDriver = new SGPDriver (&dc, m_iClientX, m_iClientY);
100   m_pSGP = new SGP (*m_pSGPDriver);
101   m_pSGP->setTextPointSize(10);
102   if (m_pEZPlot && m_pSGP) {
103     m_pSGP->eraseWindow();
104     m_pEZPlot->plot (m_pSGP);
105   }
106 }
107
108
109 EZPlotDialog::EZPlotDialog (wxWindow *parent)
110 : wxDialog((parent ? parent : theApp->getMainFrame()), -1, wxString("EZPlot"), wxDefaultPosition, wxDefaultSize, wxDIALOG_MODAL),
111   m_parentTop(0)
112 {
113   if (! parent)
114     parent = theApp->getMainFrame();
115
116   m_parentTop = parent;
117   while ( m_parentTop && m_parentTop->GetParent() )
118     m_parentTop = m_parentTop->GetParent();
119     
120   wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL);
121
122   pTopSizer->Add (m_pEZPlotCtrl = new EZPlotControl (this), 0, wxALIGN_CENTER | wxALL, 5);
123   
124   wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL);
125   wxButton* pButtonOk = new wxButton (this, wxID_OK, "Okay");
126   wxButton* pButtonCancel = new wxButton (this, wxID_CANCEL, "Cancel");
127   pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10);
128   pButtonSizer->Add (pButtonCancel, 0, wxEXPAND | wxALL, 10);
129   
130   pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER);
131   
132   SetAutoLayout (true);
133   SetSizer (pTopSizer);
134   pTopSizer->Fit (this);
135   pTopSizer->SetSizeHints (this);
136 }
137
138
139
140 /////////////////////////////////////////////////////
141 // destruction
142
143 EZPlotDialog::~EZPlotDialog()
144 {
145   if ( m_parentTop )
146     m_parentTop->Enable(TRUE);
147 }
148
149
150 #endif // HAVE_WXWINDOWS