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"
25 #include "wx/dynarray.h"
27 //-----------------------------------------------------------------------------
29 //-----------------------------------------------------------------------------
31 class WXDLLEXPORT wxPlotEvent
;
32 class WXDLLEXPORT wxPlotCurve
;
33 class WXDLLEXPORT wxPlotValues
;
34 class WXDLLEXPORT wxPlotArea
;
35 class WXDLLEXPORT wxPlotXAxisArea
;
36 class WXDLLEXPORT wxPlotYAxisArea
;
37 class WXDLLEXPORT wxPlotWindow
;
39 //-----------------------------------------------------------------------------
41 //-----------------------------------------------------------------------------
43 #define wxPLOT_X_AXIS 0x0004
44 #define wxPLOT_Y_AXIS 0x0008
45 #define wxPLOT_BUTTON_MOVE 0x0010
46 #define wxPLOT_BUTTON_ZOOM 0x0020
47 #define wxPLOT_BUTTON_ENLARGE 0x0040
49 #define wxPLOT_BUTTON_ALL (wxPLOT_BUTTON_MOVE|wxPLOT_BUTTON_ZOOM|wxPLOT_BUTTON_ENLARGE)
50 #define wxPLOT_DEFAULT (wxPLOT_X_AXIS|wxPLOT_Y_AXIS | wxPLOT_BUTTON_ALL)
52 //-----------------------------------------------------------------------------
54 //-----------------------------------------------------------------------------
56 class WXDLLEXPORT wxPlotEvent
: public wxNotifyEvent
59 wxPlotEvent( wxEventType commandType
= wxEVT_NULL
, int id
= 0 );
61 wxPlotCurve
*GetCurve()
63 void SetCurve( wxPlotCurve
*curve
)
68 void SetZoom( double zoom
)
72 { return m_position
; }
73 void SetPosition( wxInt32 pos
)
82 //-----------------------------------------------------------------------------
84 //-----------------------------------------------------------------------------
86 class WXDLLEXPORT wxPlotCurve
: public wxObject
89 wxPlotCurve( int offsetY
, double startY
, double endY
);
91 virtual wxInt32
GetStartX() = 0;
92 virtual wxInt32
GetEndX() = 0;
94 virtual double GetY( wxInt32 x
) = 0;
96 void SetStartY( double startY
)
97 { m_startY
= startY
; }
100 void SetEndY( double endY
)
104 void SetOffsetY( int offsetY
)
105 { m_offsetY
= offsetY
; }
107 { return m_offsetY
; }
109 void SetPenNormal( const wxPen
&pen
)
110 { m_penNormal
= pen
; }
111 void SetPenSelected( const wxPen
&pen
)
112 { m_penSelected
= pen
; }
121 DECLARE_ABSTRACT_CLASS(wxPlotCurve
)
124 //-----------------------------------------------------------------------------
126 //-----------------------------------------------------------------------------
128 class WXDLLEXPORT wxPlotOnOff
138 WX_DECLARE_EXPORTED_OBJARRAY(wxPlotOnOff
, wxArrayPlotOnOff
);
140 class WXDLLEXPORT wxPlotOnOffCurve
: public wxObject
143 wxPlotOnOffCurve( int offsetY
);
150 void SetOffsetY( int offsetY
)
151 { m_offsetY
= offsetY
; }
153 { return m_offsetY
; }
155 void Add( wxInt32 on
, wxInt32 off
, void *clientData
= NULL
);
158 wxInt32
GetOn( size_t index
);
159 wxInt32
GetOff( size_t index
);
160 void* GetClientData( size_t index
);
161 wxPlotOnOff
*GetAt( size_t index
);
163 virtual void DrawOnLine( wxDC
&dc
, wxCoord y
, wxCoord start
, wxCoord end
, void *clientData
);
164 virtual void DrawOffLine( wxDC
&dc
, wxCoord y
, wxCoord start
, wxCoord end
);
171 wxArrayPlotOnOff m_marks
;
173 DECLARE_CLASS(wxPlotOnOffCurve
)
176 //-----------------------------------------------------------------------------
178 //-----------------------------------------------------------------------------
180 class WXDLLEXPORT wxPlotArea
: public wxWindow
184 wxPlotArea( wxPlotWindow
*parent
);
186 void OnPaint( wxPaintEvent
&event
);
187 void OnMouse( wxMouseEvent
&event
);
189 void DrawCurve( wxDC
*dc
, wxPlotCurve
*curve
, int from
= -1, int to
= -1 );
190 void DrawOnOffCurve( wxDC
*dc
, wxPlotOnOffCurve
*curve
, int from
= -1, int to
= -1 );
191 void DeleteCurve( wxPlotCurve
*curve
, int from
= -1, int to
= -1 );
193 virtual void ScrollWindow( int dx
, int dy
, const wxRect
*rect
);
196 wxPlotWindow
*m_owner
;
199 DECLARE_CLASS(wxPlotArea
)
200 DECLARE_EVENT_TABLE()
203 //-----------------------------------------------------------------------------
205 //-----------------------------------------------------------------------------
207 class WXDLLEXPORT wxPlotXAxisArea
: public wxWindow
211 wxPlotXAxisArea( wxPlotWindow
*parent
);
213 void OnPaint( wxPaintEvent
&event
);
214 void OnMouse( wxMouseEvent
&event
);
217 wxPlotWindow
*m_owner
;
219 DECLARE_CLASS(wxPlotXAxisArea
)
220 DECLARE_EVENT_TABLE()
223 //-----------------------------------------------------------------------------
225 //-----------------------------------------------------------------------------
227 class WXDLLEXPORT wxPlotYAxisArea
: public wxWindow
231 wxPlotYAxisArea( wxPlotWindow
*parent
);
233 void OnPaint( wxPaintEvent
&event
);
234 void OnMouse( wxMouseEvent
&event
);
237 wxPlotWindow
*m_owner
;
239 DECLARE_CLASS(wxPlotYAxisArea
)
240 DECLARE_EVENT_TABLE()
243 //-----------------------------------------------------------------------------
245 //-----------------------------------------------------------------------------
247 class WXDLLEXPORT wxPlotWindow
: public wxScrolledWindow
251 wxPlotWindow( wxWindow
*parent
, wxWindowID id
, const wxPoint
&pos
, const wxSize
&size
, int flags
= wxPLOT_DEFAULT
);
257 void Add( wxPlotCurve
*curve
);
258 void Delete( wxPlotCurve
* curve
);
261 wxPlotCurve
*GetAt( size_t n
);
263 void SetCurrent( wxPlotCurve
* current
);
264 wxPlotCurve
*GetCurrent();
266 // mark list accessors
267 // -------------------
269 void Add( wxPlotOnOffCurve
*curve
);
270 void Delete( wxPlotOnOffCurve
* curve
);
272 size_t GetOnOffCurveCount();
273 wxPlotOnOffCurve
*GetOnOffCurveAt( size_t n
);
275 // vertical representation
276 // -----------------------
278 void Move( wxPlotCurve
* curve
, int pixels_up
);
279 void Enlarge( wxPlotCurve
*curve
, double factor
);
281 // horizontal representation
282 // -------------------------
284 void SetUnitsPerValue( double upv
);
285 double GetUnitsPerValue()
286 { return m_xUnitsPerValue
; }
288 void SetZoom( double zoom
);
295 void SetScrollOnThumbRelease( bool scrollOnThumbRelease
= TRUE
)
296 { m_scrollOnThumbRelease
= scrollOnThumbRelease
; }
297 bool GetScrollOnThumbRelease()
298 { return m_scrollOnThumbRelease
; }
300 void SetEnlargeAroundWindowCentre( bool enlargeAroundWindowCentre
= TRUE
)
301 { m_enlargeAroundWindowCentre
= enlargeAroundWindowCentre
; }
302 bool GetEnlargeAroundWindowCentre()
303 { return m_enlargeAroundWindowCentre
; }
305 // events (may be overridden)
306 // --------------------------
308 void OnMoveUp( wxCommandEvent
& event
);
309 void OnMoveDown( wxCommandEvent
& event
);
311 void OnEnlarge( wxCommandEvent
& event
);
312 void OnShrink( wxCommandEvent
& event
);
313 void OnZoomIn( wxCommandEvent
& event
);
314 void OnZoomOut( wxCommandEvent
& event
);
316 void OnScroll2( wxScrollWinEvent
& event
);
321 void RedrawEverything();
325 void ResetScrollbar();
328 friend class wxPlotArea
;
329 friend class wxPlotXAxisArea
;
330 friend class wxPlotYAxisArea
;
332 double m_xUnitsPerValue
;
336 wxList m_onOffCurves
;
339 wxPlotXAxisArea
*m_xaxis
;
340 wxPlotYAxisArea
*m_yaxis
;
341 wxPlotCurve
*m_current
;
343 bool m_scrollOnThumbRelease
;
344 bool m_enlargeAroundWindowCentre
;
346 DECLARE_CLASS(wxPlotWindow
)
347 DECLARE_EVENT_TABLE()
350 // ----------------------------------------------------------------------------
352 // ----------------------------------------------------------------------------
354 typedef void (wxEvtHandler::*wxPlotEventFunction
)(wxPlotEvent
&);
356 #define EVT_PLOT(id, fn) { wxEVT_PLOT_DOUBLECLICKED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL },
357 #define EVT_PLOT_SEL_CHANGING(id, fn) { wxEVT_PLOT_SEL_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL },
358 #define EVT_PLOT_SEL_CHANGED(id, fn) { wxEVT_PLOT_SEL_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL },
359 #define EVT_PLOT_CLICKED(id, fn) { wxEVT_PLOT_CLICKED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL },
360 #define EVT_PLOT_DOUBLECLICKED(id, fn) { wxEVT_PLOT_DOUBLECLICKED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL },
361 #define EVT_PLOT_ZOOM_IN(id, fn) { wxEVT_PLOT_ZOOM_IN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL },
362 #define EVT_PLOT_ZOOM_OUT(id, fn) { wxEVT_PLOT_ZOOM_OUT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL },
363 #define EVT_PLOT_VALUE_SEL_CREATING(id, fn) { wxEVT_PLOT_VALUE_SEL_CREATING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL },
364 #define EVT_PLOT_VALUE_SEL_CREATED(id, fn) { wxEVT_PLOT_VALUE_SEL_CREATED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL },
365 #define EVT_PLOT_VALUE_SEL_CHANGING(id, fn) { wxEVT_PLOT_VALUE_SEL_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL },
366 #define EVT_PLOT_VALUE_SEL_CHANGED(id, fn) { wxEVT_PLOT_VALUE_SEL_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL },
367 #define EVT_PLOT_AREA_SEL_CREATING(id, fn) { wxEVT_PLOT_AREA_SEL_CREATING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL },
368 #define EVT_PLOT_AREA_SEL_CREATED(id, fn) { wxEVT_PLOT_AREA_SEL_CREATED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL },
369 #define EVT_PLOT_AREA_SEL_CHANGING(id, fn) { wxEVT_PLOT_AREA_SEL_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL },
370 #define EVT_PLOT_AREA_SEL_CHANGED(id, fn) { wxEVT_PLOT_AREA_SEL_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL },
371 #define EVT_PLOT_BEGIN_X_LABEL_EDIT(id, fn) { wxEVT_PLOT_BEGIN_X_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL },
372 #define EVT_PLOT_END_X_LABEL_EDIT(id, fn) { wxEVT_PLOT_END_X_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL },
373 #define EVT_PLOT_BEGIN_Y_LABEL_EDIT(id, fn) { wxEVT_PLOT_BEGIN_Y_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL },
374 #define EVT_PLOT_END_Y_LABEL_EDIT(id, fn) { wxEVT_PLOT_END_Y_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL },
375 #define EVT_PLOT_BEGIN_TITLE_EDIT(id, fn) { wxEVT_PLOT_BEGIN_TITLE_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL },
376 #define EVT_PLOT_END_TITLE_EDIT(id, fn) { wxEVT_PLOT_END_TITLE_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL },