1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxPlotWindow
4 // Author: Robert Roebling
7 // Copyright: (c) Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "plot.h"
23 #include "wx/scrolwin.h"
26 //-----------------------------------------------------------------------------
28 //-----------------------------------------------------------------------------
30 class WXDLLEXPORT wxPlotEvent
;
31 class WXDLLEXPORT wxPlotCurve
;
32 class WXDLLEXPORT wxPlotArea
;
33 class WXDLLEXPORT wxPlotXAxisArea
;
34 class WXDLLEXPORT wxPlotYAxisArea
;
35 class WXDLLEXPORT wxPlotWindow
;
37 //-----------------------------------------------------------------------------
39 //-----------------------------------------------------------------------------
41 #define wxPLOT_X_AXIS 0x0004
42 #define wxPLOT_Y_AXIS 0x0008
43 #define wxPLOT_BUTTON_MOVE 0x0010
44 #define wxPLOT_BUTTON_ZOOM 0x0020
45 #define wxPLOT_BUTTON_ENLARGE 0x0040
47 #define wxPLOT_BUTTON_ALL (wxPLOT_BUTTON_MOVE|wxPLOT_BUTTON_ZOOM|wxPLOT_BUTTON_ENLARGE)
48 #define wxPLOT_DEFAULT (wxPLOT_X_AXIS|wxPLOT_Y_AXIS | wxPLOT_BUTTON_ALL)
50 //-----------------------------------------------------------------------------
52 //-----------------------------------------------------------------------------
54 class WXDLLEXPORT wxPlotEvent
: public wxNotifyEvent
57 wxPlotEvent( wxEventType commandType
= wxEVT_NULL
, int id
= 0 );
59 wxPlotCurve
*GetCurve()
61 void SetCurve( wxPlotCurve
*curve
)
66 void SetZoom( double zoom
)
70 { return m_position
; }
71 void SetPosition( wxInt32 pos
)
80 //-----------------------------------------------------------------------------
82 //-----------------------------------------------------------------------------
84 class WXDLLEXPORT wxPlotCurve
: public wxObject
87 wxPlotCurve( int offsetY
, double startY
, double endY
);
89 virtual wxInt32
GetStartX() = 0;
90 virtual wxInt32
GetEndX() = 0;
92 virtual double GetY( wxInt32 x
) = 0;
94 void SetStartY( double startY
)
95 { m_startY
= startY
; }
98 void SetEndY( double endY
)
102 void SetOffsetY( int offsetY
)
103 { m_offsetY
= offsetY
; }
105 { return m_offsetY
; }
112 DECLARE_ABSTRACT_CLASS(wxPlotCurve
)
115 //-----------------------------------------------------------------------------
117 //-----------------------------------------------------------------------------
119 class WXDLLEXPORT wxPlotArea
: public wxWindow
123 wxPlotArea( wxPlotWindow
*parent
);
125 void OnPaint( wxPaintEvent
&event
);
126 void OnMouse( wxMouseEvent
&event
);
128 void DrawCurve( wxDC
*dc
, wxPlotCurve
*curve
, int from
= -1, int to
= -1 );
129 void DeleteCurve( wxPlotCurve
*curve
, int from
= -1, int to
= -1 );
131 virtual void ScrollWindow( int dx
, int dy
, const wxRect
*rect
);
134 wxPlotWindow
*m_owner
;
137 DECLARE_CLASS(wxPlotArea
)
138 DECLARE_EVENT_TABLE()
141 //-----------------------------------------------------------------------------
143 //-----------------------------------------------------------------------------
145 class WXDLLEXPORT wxPlotXAxisArea
: public wxWindow
149 wxPlotXAxisArea( wxPlotWindow
*parent
);
151 void OnPaint( wxPaintEvent
&event
);
152 void OnMouse( wxMouseEvent
&event
);
155 wxPlotWindow
*m_owner
;
157 DECLARE_CLASS(wxPlotXAxisArea
)
158 DECLARE_EVENT_TABLE()
161 //-----------------------------------------------------------------------------
163 //-----------------------------------------------------------------------------
165 class WXDLLEXPORT wxPlotYAxisArea
: public wxWindow
169 wxPlotYAxisArea( wxPlotWindow
*parent
);
171 void OnPaint( wxPaintEvent
&event
);
172 void OnMouse( wxMouseEvent
&event
);
175 wxPlotWindow
*m_owner
;
177 DECLARE_CLASS(wxPlotYAxisArea
)
178 DECLARE_EVENT_TABLE()
181 //-----------------------------------------------------------------------------
183 //-----------------------------------------------------------------------------
185 class WXDLLEXPORT wxPlotWindow
: public wxScrolledWindow
189 wxPlotWindow( wxWindow
*parent
, wxWindowID id
, const wxPoint
&pos
, const wxSize
&size
, int flags
= wxPLOT_DEFAULT
);
195 void Add( wxPlotCurve
*curve
);
197 wxPlotCurve
*GetAt( size_t n
);
199 void SetCurrent( wxPlotCurve
* current
);
200 wxPlotCurve
*GetCurrent();
202 void Delete( wxPlotCurve
* curve
);
204 // vertical representation
205 // -----------------------
207 void Move( wxPlotCurve
* curve
, int pixels_up
);
208 void Enlarge( wxPlotCurve
*curve
, double factor
);
210 // horizontal representation
211 // -------------------------
213 void SetUnitsPerValue( double upv
);
214 double GetUnitsPerValue()
215 { return m_xUnitsPerValue
; }
217 void SetZoom( double zoom
);
224 void SetScrollOnThumbRelease( bool scrollOnThumbRelease
= TRUE
)
225 { m_scrollOnThumbRelease
= scrollOnThumbRelease
; }
226 bool GetScrollOnThumbRelease()
227 { return m_scrollOnThumbRelease
; }
229 void SetEnlargeAroundWindowCentre( bool enlargeAroundWindowCentre
= TRUE
)
230 { m_enlargeAroundWindowCentre
= enlargeAroundWindowCentre
; }
231 bool GetEnlargeAroundWindowCentre()
232 { return m_enlargeAroundWindowCentre
; }
234 // events (may be overridden)
235 // --------------------------
237 void OnMoveUp( wxCommandEvent
& event
);
238 void OnMoveDown( wxCommandEvent
& event
);
240 void OnEnlarge( wxCommandEvent
& event
);
241 void OnShrink( wxCommandEvent
& event
);
242 void OnZoomIn( wxCommandEvent
& event
);
243 void OnZoomOut( wxCommandEvent
& event
);
245 void OnScroll2( wxScrollWinEvent
& event
);
250 void RedrawEverything();
254 void ResetScrollbar();
258 friend wxPlotXAxisArea
;
259 friend wxPlotYAxisArea
;
261 double m_xUnitsPerValue
;
266 wxPlotXAxisArea
*m_xaxis
;
267 wxPlotYAxisArea
*m_yaxis
;
268 wxPlotCurve
*m_current
;
270 bool m_scrollOnThumbRelease
;
271 bool m_enlargeAroundWindowCentre
;
273 DECLARE_CLASS(wxPlotWindow
)
274 DECLARE_EVENT_TABLE()
277 // ----------------------------------------------------------------------------
278 // calendar events macros
279 // ----------------------------------------------------------------------------
281 #define EVT_PLOT(id, fn) { wxEVT_PLOT_DOUBLECLICKED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
282 #define EVT_PLOT_SEL_CHANGING(id, fn) { wxEVT_PLOT_SEL_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
283 #define EVT_PLOT_SEL_CHANGED(id, fn) { wxEVT_PLOT_SEL_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
284 #define EVT_PLOT_CLICKED(id, fn) { wxEVT_PLOT_CLICKED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
285 #define EVT_PLOT_DOUBLECLICKED(id, fn) { wxEVT_PLOT_DOUBLECLICKED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
286 #define EVT_PLOT_ZOOM_IN(id, fn) { wxEVT_PLOT_ZOOM_IN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
287 #define EVT_PLOT_ZOOM_OUT(id, fn) { wxEVT_PLOT_ZOOM_OUT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
288 #define EVT_PLOT_VALUE_SEL_CREATING(id, fn) { wxEVT_PLOT_VALUE_SEL_CREATING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
289 #define EVT_PLOT_VALUE_SEL_CREATED(id, fn) { wxEVT_PLOT_VALUE_SEL_CREATED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
290 #define EVT_PLOT_VALUE_SEL_CHANGING(id, fn) { wxEVT_PLOT_VALUE_SEL_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
291 #define EVT_PLOT_VALUE_SEL_CHANGED(id, fn) { wxEVT_PLOT_VALUE_SEL_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
292 #define EVT_PLOT_AREA_SEL_CREATING(id, fn) { wxEVT_PLOT_AREA_SEL_CREATING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
293 #define EVT_PLOT_AREA_SEL_CREATED(id, fn) { wxEVT_PLOT_AREA_SEL_CREATED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
294 #define EVT_PLOT_AREA_SEL_CHANGING(id, fn) { wxEVT_PLOT_AREA_SEL_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
295 #define EVT_PLOT_AREA_SEL_CHANGED(id, fn) { wxEVT_PLOT_AREA_SEL_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
296 #define EVT_PLOT_BEGIN_X_LABEL_EDIT(id, fn) { wxEVT_PLOT_BEGIN_X_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
297 #define EVT_PLOT_END_X_LABEL_EDIT(id, fn) { wxEVT_PLOT_END_X_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
298 #define EVT_PLOT_BEGIN_Y_LABEL_EDIT(id, fn) { wxEVT_PLOT_BEGIN_Y_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
299 #define EVT_PLOT_END_Y_LABEL_EDIT(id, fn) { wxEVT_PLOT_END_Y_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
300 #define EVT_PLOT_BEGIN_TITLE_EDIT(id, fn) { wxEVT_PLOT_BEGIN_TITLE_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
301 #define EVT_PLOT_END_TITLE_EDIT(id, fn) { wxEVT_PLOT_END_TITLE_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },