1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxPlotWindow
4 // Author: Robert Roebling
7 // Copyright: (c) Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "plot.h"
19 #include "wx/scrolwin.h"
22 //-----------------------------------------------------------------------------
24 //-----------------------------------------------------------------------------
26 class WXDLLEXPORT wxPlotEvent
;
27 class WXDLLEXPORT wxPlotCurve
;
28 class WXDLLEXPORT wxPlotArea
;
29 class WXDLLEXPORT wxPlotXAxisArea
;
30 class WXDLLEXPORT wxPlotYAxisArea
;
31 class WXDLLEXPORT wxPlotWindow
;
33 //-----------------------------------------------------------------------------
35 //-----------------------------------------------------------------------------
37 #define wxPLOT_X_AXIS 0x0004
38 #define wxPLOT_Y_AXIS 0x0008
39 #define wxPLOT_BUTTON_MOVE 0x0010
40 #define wxPLOT_BUTTON_ZOOM 0x0020
41 #define wxPLOT_BUTTON_ENLARGE 0x0040
43 #define wxPLOT_BUTTON_ALL (wxPLOT_BUTTON_MOVE|wxPLOT_BUTTON_ZOOM|wxPLOT_BUTTON_ENLARGE)
44 #define wxPLOT_DEFAULT (wxPLOT_X_AXIS|wxPLOT_Y_AXIS | wxPLOT_BUTTON_ALL)
46 //-----------------------------------------------------------------------------
48 //-----------------------------------------------------------------------------
50 class WXDLLEXPORT wxPlotEvent
: public wxNotifyEvent
53 wxPlotEvent( wxEventType commandType
= wxEVT_NULL
, int id
= 0 );
55 wxPlotCurve
*GetCurve()
57 void SetCurve( wxPlotCurve
*curve
)
62 void SetZoom( double zoom
)
66 { return m_position
; }
67 void SetPosition( wxInt32 pos
)
76 //-----------------------------------------------------------------------------
78 //-----------------------------------------------------------------------------
80 class WXDLLEXPORT wxPlotCurve
: public wxObject
83 wxPlotCurve( int offsetY
, double startY
, double endY
);
85 virtual wxInt32
GetStartX() = 0;
86 virtual wxInt32
GetEndX() = 0;
88 virtual double GetY( wxInt32 x
) = 0;
90 void SetStartY( double startY
)
91 { m_startY
= startY
; }
94 void SetEndY( double endY
)
98 void SetOffsetY( int offsetY
)
99 { m_offsetY
= offsetY
; }
101 { return m_offsetY
; }
108 DECLARE_ABSTRACT_CLASS(wxPlotCurve
)
111 //-----------------------------------------------------------------------------
113 //-----------------------------------------------------------------------------
115 class WXDLLEXPORT wxPlotArea
: public wxWindow
119 wxPlotArea( wxPlotWindow
*parent
);
121 void OnPaint( wxPaintEvent
&event
);
122 void OnMouse( wxMouseEvent
&event
);
124 void DrawCurve( wxDC
*dc
, wxPlotCurve
*curve
, int from
= -1, int to
= -1 );
125 void DeleteCurve( wxPlotCurve
*curve
, int from
= -1, int to
= -1 );
127 virtual void ScrollWindow( int dx
, int dy
, const wxRect
*rect
);
130 wxPlotWindow
*m_owner
;
133 DECLARE_CLASS(wxPlotArea
)
134 DECLARE_EVENT_TABLE()
137 //-----------------------------------------------------------------------------
139 //-----------------------------------------------------------------------------
141 class WXDLLEXPORT wxPlotXAxisArea
: public wxWindow
145 wxPlotXAxisArea( wxPlotWindow
*parent
);
147 void OnPaint( wxPaintEvent
&event
);
148 void OnMouse( wxMouseEvent
&event
);
151 wxPlotWindow
*m_owner
;
153 DECLARE_CLASS(wxPlotXAxisArea
)
154 DECLARE_EVENT_TABLE()
157 //-----------------------------------------------------------------------------
159 //-----------------------------------------------------------------------------
161 class WXDLLEXPORT wxPlotYAxisArea
: public wxWindow
165 wxPlotYAxisArea( wxPlotWindow
*parent
);
167 void OnPaint( wxPaintEvent
&event
);
168 void OnMouse( wxMouseEvent
&event
);
171 wxPlotWindow
*m_owner
;
173 DECLARE_CLASS(wxPlotYAxisArea
)
174 DECLARE_EVENT_TABLE()
177 //-----------------------------------------------------------------------------
179 //-----------------------------------------------------------------------------
181 class WXDLLEXPORT wxPlotWindow
: public wxScrolledWindow
185 wxPlotWindow( wxWindow
*parent
, wxWindowID id
, const wxPoint
&pos
, const wxSize
&size
, int flags
= wxPLOT_DEFAULT
);
191 void Add( wxPlotCurve
*curve
);
193 wxPlotCurve
*GetAt( size_t n
);
195 void SetCurrent( wxPlotCurve
* current
);
196 wxPlotCurve
*GetCurrent();
198 void Delete( wxPlotCurve
* curve
);
200 // vertical representation
201 // -----------------------
203 void Move( wxPlotCurve
* curve
, int pixels_up
);
204 void Enlarge( wxPlotCurve
*curve
, double factor
);
206 // horizontal representation
207 // -------------------------
209 void SetUnitsPerValue( double upv
);
210 double GetUnitsPerValue()
211 { return m_xUnitsPerValue
; }
213 void SetZoom( double zoom
);
217 // events (may be overridden)
218 // --------------------------
220 void OnMoveUp( wxCommandEvent
& event
);
221 void OnMoveDown( wxCommandEvent
& event
);
223 void OnEnlarge( wxCommandEvent
& event
);
224 void OnShrink( wxCommandEvent
& event
);
225 void OnZoomIn( wxCommandEvent
& event
);
226 void OnZoomOut( wxCommandEvent
& event
);
228 void OnScroll2( wxScrollWinEvent
& event
);
233 void RedrawEverything();
237 void ResetScrollbar();
241 friend wxPlotXAxisArea
;
242 friend wxPlotYAxisArea
;
244 double m_xUnitsPerValue
;
249 wxPlotXAxisArea
*m_xaxis
;
250 wxPlotYAxisArea
*m_yaxis
;
251 wxPlotCurve
*m_current
;
253 DECLARE_CLASS(wxPlotWindow
)
254 DECLARE_EVENT_TABLE()
257 // ----------------------------------------------------------------------------
258 // calendar events macros
259 // ----------------------------------------------------------------------------
261 #define EVT_PLOT(id, fn) { wxEVT_PLOT_DOUBLECLICKED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
262 #define EVT_PLOT_SEL_CHANGING(id, fn) { wxEVT_PLOT_SEL_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
263 #define EVT_PLOT_SEL_CHANGED(id, fn) { wxEVT_PLOT_SEL_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
264 #define EVT_PLOT_CLICKED(id, fn) { wxEVT_PLOT_CLICKED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
265 #define EVT_PLOT_DOUBLECLICKED(id, fn) { wxEVT_PLOT_DOUBLECLICKED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
266 #define EVT_PLOT_ZOOM_IN(id, fn) { wxEVT_PLOT_ZOOM_IN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
267 #define EVT_PLOT_ZOOM_OUT(id, fn) { wxEVT_PLOT_ZOOM_OUT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
268 #define EVT_PLOT_VALUE_SEL_CREATING(id, fn) { wxEVT_PLOT_VALUE_SEL_CREATING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
269 #define EVT_PLOT_VALUE_SEL_CREATED(id, fn) { wxEVT_PLOT_VALUE_SEL_CREATED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
270 #define EVT_PLOT_VALUE_SEL_CHANGING(id, fn) { wxEVT_PLOT_VALUE_SEL_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
271 #define EVT_PLOT_VALUE_SEL_CHANGED(id, fn) { wxEVT_PLOT_VALUE_SEL_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
272 #define EVT_PLOT_AREA_SEL_CREATING(id, fn) { wxEVT_PLOT_AREA_SEL_CREATING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
273 #define EVT_PLOT_AREA_SEL_CREATED(id, fn) { wxEVT_PLOT_AREA_SEL_CREATED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
274 #define EVT_PLOT_AREA_SEL_CHANGING(id, fn) { wxEVT_PLOT_AREA_SEL_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
275 #define EVT_PLOT_AREA_SEL_CHANGED(id, fn) { wxEVT_PLOT_AREA_SEL_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
276 #define EVT_PLOT_BEGIN_X_LABEL_EDIT(id, fn) { wxEVT_PLOT_BEGIN_X_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
277 #define EVT_PLOT_END_X_LABEL_EDIT(id, fn) { wxEVT_PLOT_END_X_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
278 #define EVT_PLOT_BEGIN_Y_LABEL_EDIT(id, fn) { wxEVT_PLOT_BEGIN_Y_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
279 #define EVT_PLOT_END_Y_LABEL_EDIT(id, fn) { wxEVT_PLOT_END_Y_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
280 #define EVT_PLOT_BEGIN_TITLE_EDIT(id, fn) { wxEVT_PLOT_BEGIN_TITLE_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
281 #define EVT_PLOT_END_TITLE_EDIT(id, fn) { wxEVT_PLOT_END_TITLE_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },