1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxPlotWindow
4 // Author: Robert Roebling
7 // Copyright: (c) Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "plot.h"
21 #include "wx/scrolwin.h"
23 #include "wx/dynarray.h"
25 //-----------------------------------------------------------------------------
27 //-----------------------------------------------------------------------------
29 class WXDLLEXPORT wxPlotEvent
;
30 class WXDLLEXPORT wxPlotCurve
;
31 class WXDLLEXPORT wxPlotValues
;
32 class WXDLLEXPORT wxPlotArea
;
33 class WXDLLEXPORT wxPlotXAxisArea
;
34 class WXDLLEXPORT wxPlotYAxisArea
;
35 class WXDLLEXPORT wxPlotWindow
;
37 //-----------------------------------------------------------------------------
39 //-----------------------------------------------------------------------------
41 extern const int wxEVT_PLOT_SEL_CHANGING
;
42 extern const int wxEVT_PLOT_SEL_CHANGED
;
43 extern const int wxEVT_PLOT_CLICKED
;
44 extern const int wxEVT_PLOT_DOUBLECLICKED
;
45 extern const int wxEVT_PLOT_ZOOM_IN
;
46 extern const int wxEVT_PLOT_ZOOM_OUT
;
47 extern const int wxEVT_PLOT_VALUE_SEL_CREATING
;
48 extern const int wxEVT_PLOT_VALUE_SEL_CREATED
;
49 extern const int wxEVT_PLOT_VALUE_SEL_CHANGING
;
50 extern const int wxEVT_PLOT_VALUE_SEL_CHANGED
;
51 extern const int wxEVT_PLOT_AREA_SEL_CREATING
;
52 extern const int wxEVT_PLOT_AREA_SEL_CREATED
;
53 extern const int wxEVT_PLOT_AREA_SEL_CHANGING
;
54 extern const int wxEVT_PLOT_AREA_SEL_CHANGED
;
55 extern const int wxEVT_PLOT_BEGIN_X_LABEL_EDIT
;
56 extern const int wxEVT_PLOT_END_X_LABEL_EDIT
;
57 extern const int wxEVT_PLOT_BEGIN_Y_LABEL_EDIT
;
58 extern const int wxEVT_PLOT_END_Y_LABEL_EDIT
;
59 extern const int wxEVT_PLOT_BEGIN_TITLE_EDIT
;
60 extern const int wxEVT_PLOT_END_TITLE_EDIT
;
61 extern const int wxEVT_PLOT_AREA_CREATE
;
63 //-----------------------------------------------------------------------------
65 //-----------------------------------------------------------------------------
67 #define wxPLOT_X_AXIS 0x0004
68 #define wxPLOT_Y_AXIS 0x0008
69 #define wxPLOT_BUTTON_MOVE 0x0010
70 #define wxPLOT_BUTTON_ZOOM 0x0020
71 #define wxPLOT_BUTTON_ENLARGE 0x0040
73 #define wxPLOT_BUTTON_ALL (wxPLOT_BUTTON_MOVE|wxPLOT_BUTTON_ZOOM|wxPLOT_BUTTON_ENLARGE)
74 #define wxPLOT_DEFAULT (wxPLOT_X_AXIS|wxPLOT_Y_AXIS | wxPLOT_BUTTON_ALL)
76 //-----------------------------------------------------------------------------
78 //-----------------------------------------------------------------------------
80 class WXDLLEXPORT wxPlotEvent
: public wxNotifyEvent
83 wxPlotEvent( wxEventType commandType
= wxEVT_NULL
, int id
= 0 );
85 wxPlotCurve
*GetCurve()
87 void SetCurve( wxPlotCurve
*curve
)
92 void SetZoom( double zoom
)
96 { return m_position
; }
97 void SetPosition( wxInt32 pos
)
101 wxPlotCurve
*m_curve
;
106 //-----------------------------------------------------------------------------
108 //-----------------------------------------------------------------------------
110 class WXDLLEXPORT wxPlotCurve
: public wxObject
113 wxPlotCurve( int offsetY
, double startY
, double endY
);
115 virtual wxInt32
GetStartX() = 0;
116 virtual wxInt32
GetEndX() = 0;
118 virtual double GetY( wxInt32 x
) = 0;
120 void SetStartY( double startY
)
121 { m_startY
= startY
; }
124 void SetEndY( double endY
)
128 void SetOffsetY( int offsetY
)
129 { m_offsetY
= offsetY
; }
131 { return m_offsetY
; }
133 void SetPenNormal( const wxPen
&pen
)
134 { m_penNormal
= pen
; }
135 void SetPenSelected( const wxPen
&pen
)
136 { m_penSelected
= pen
; }
145 DECLARE_ABSTRACT_CLASS(wxPlotCurve
)
148 //-----------------------------------------------------------------------------
150 //-----------------------------------------------------------------------------
152 class WXDLLEXPORT wxPlotOnOff
162 WX_DECLARE_EXPORTED_OBJARRAY(wxPlotOnOff
, wxArrayPlotOnOff
);
164 class WXDLLEXPORT wxPlotOnOffCurve
: public wxObject
167 wxPlotOnOffCurve( int offsetY
);
174 void SetOffsetY( int offsetY
)
175 { m_offsetY
= offsetY
; }
177 { return m_offsetY
; }
179 void Add( wxInt32 on
, wxInt32 off
, void *clientData
= NULL
);
182 wxInt32
GetOn( size_t index
);
183 wxInt32
GetOff( size_t index
);
184 void* GetClientData( size_t index
);
185 wxPlotOnOff
*GetAt( size_t index
);
187 virtual void DrawOnLine( wxDC
&dc
, wxCoord y
, wxCoord start
, wxCoord end
, void *clientData
);
188 virtual void DrawOffLine( wxDC
&dc
, wxCoord y
, wxCoord start
, wxCoord end
);
195 wxArrayPlotOnOff m_marks
;
197 DECLARE_CLASS(wxPlotOnOffCurve
)
200 //-----------------------------------------------------------------------------
202 //-----------------------------------------------------------------------------
204 class WXDLLEXPORT wxPlotArea
: public wxWindow
208 wxPlotArea( wxPlotWindow
*parent
);
210 void OnPaint( wxPaintEvent
&event
);
211 void OnMouse( wxMouseEvent
&event
);
213 void DrawCurve( wxDC
*dc
, wxPlotCurve
*curve
, int from
= -1, int to
= -1 );
214 void DrawOnOffCurve( wxDC
*dc
, wxPlotOnOffCurve
*curve
, int from
= -1, int to
= -1 );
215 void DeleteCurve( wxPlotCurve
*curve
, int from
= -1, int to
= -1 );
217 virtual void ScrollWindow( int dx
, int dy
, const wxRect
*rect
);
220 wxPlotWindow
*m_owner
;
223 DECLARE_CLASS(wxPlotArea
)
224 DECLARE_EVENT_TABLE()
227 //-----------------------------------------------------------------------------
229 //-----------------------------------------------------------------------------
231 class WXDLLEXPORT wxPlotXAxisArea
: public wxWindow
235 wxPlotXAxisArea( wxPlotWindow
*parent
);
237 void OnPaint( wxPaintEvent
&event
);
238 void OnMouse( wxMouseEvent
&event
);
241 wxPlotWindow
*m_owner
;
243 DECLARE_CLASS(wxPlotXAxisArea
)
244 DECLARE_EVENT_TABLE()
247 //-----------------------------------------------------------------------------
249 //-----------------------------------------------------------------------------
251 class WXDLLEXPORT wxPlotYAxisArea
: public wxWindow
255 wxPlotYAxisArea( wxPlotWindow
*parent
);
257 void OnPaint( wxPaintEvent
&event
);
258 void OnMouse( wxMouseEvent
&event
);
261 wxPlotWindow
*m_owner
;
263 DECLARE_CLASS(wxPlotYAxisArea
)
264 DECLARE_EVENT_TABLE()
267 //-----------------------------------------------------------------------------
269 //-----------------------------------------------------------------------------
271 class WXDLLEXPORT wxPlotWindow
: public wxScrolledWindow
275 wxPlotWindow( wxWindow
*parent
, wxWindowID id
, const wxPoint
&pos
, const wxSize
&size
, int flags
= wxPLOT_DEFAULT
);
281 void Add( wxPlotCurve
*curve
);
282 void Delete( wxPlotCurve
* curve
);
285 wxPlotCurve
*GetAt( size_t n
);
287 void SetCurrent( wxPlotCurve
* current
);
288 wxPlotCurve
*GetCurrent();
290 // mark list accessors
291 // -------------------
293 void Add( wxPlotOnOffCurve
*curve
);
294 void Delete( wxPlotOnOffCurve
* curve
);
296 size_t GetOnOffCurveCount();
297 wxPlotOnOffCurve
*GetOnOffCurveAt( size_t n
);
299 // vertical representation
300 // -----------------------
302 void Move( wxPlotCurve
* curve
, int pixels_up
);
303 void Enlarge( wxPlotCurve
*curve
, double factor
);
305 // horizontal representation
306 // -------------------------
308 void SetUnitsPerValue( double upv
);
309 double GetUnitsPerValue()
310 { return m_xUnitsPerValue
; }
312 void SetZoom( double zoom
);
319 void SetScrollOnThumbRelease( bool scrollOnThumbRelease
= TRUE
)
320 { m_scrollOnThumbRelease
= scrollOnThumbRelease
; }
321 bool GetScrollOnThumbRelease()
322 { return m_scrollOnThumbRelease
; }
324 void SetEnlargeAroundWindowCentre( bool enlargeAroundWindowCentre
= TRUE
)
325 { m_enlargeAroundWindowCentre
= enlargeAroundWindowCentre
; }
326 bool GetEnlargeAroundWindowCentre()
327 { return m_enlargeAroundWindowCentre
; }
329 // events (may be overridden)
330 // --------------------------
332 void OnMoveUp( wxCommandEvent
& event
);
333 void OnMoveDown( wxCommandEvent
& event
);
335 void OnEnlarge( wxCommandEvent
& event
);
336 void OnShrink( wxCommandEvent
& event
);
337 void OnZoomIn( wxCommandEvent
& event
);
338 void OnZoomOut( wxCommandEvent
& event
);
340 void OnScroll2( wxScrollWinEvent
& event
);
345 void RedrawEverything();
349 void ResetScrollbar();
352 friend class wxPlotArea
;
353 friend class wxPlotXAxisArea
;
354 friend class wxPlotYAxisArea
;
356 double m_xUnitsPerValue
;
360 wxList m_onOffCurves
;
363 wxPlotXAxisArea
*m_xaxis
;
364 wxPlotYAxisArea
*m_yaxis
;
365 wxPlotCurve
*m_current
;
367 bool m_scrollOnThumbRelease
;
368 bool m_enlargeAroundWindowCentre
;
370 DECLARE_CLASS(wxPlotWindow
)
371 DECLARE_EVENT_TABLE()
374 // ----------------------------------------------------------------------------
376 // ----------------------------------------------------------------------------
378 typedef void (wxEvtHandler::*wxPlotEventFunction
)(wxPlotEvent
&);
380 #define EVT_PLOT(id, fn) { wxEVT_PLOT_DOUBLECLICKED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL },
381 #define EVT_PLOT_SEL_CHANGING(id, fn) { wxEVT_PLOT_SEL_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL },
382 #define EVT_PLOT_SEL_CHANGED(id, fn) { wxEVT_PLOT_SEL_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL },
383 #define EVT_PLOT_CLICKED(id, fn) { wxEVT_PLOT_CLICKED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL },
384 #define EVT_PLOT_DOUBLECLICKED(id, fn) { wxEVT_PLOT_DOUBLECLICKED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL },
385 #define EVT_PLOT_ZOOM_IN(id, fn) { wxEVT_PLOT_ZOOM_IN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL },
386 #define EVT_PLOT_ZOOM_OUT(id, fn) { wxEVT_PLOT_ZOOM_OUT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL },
387 #define EVT_PLOT_VALUE_SEL_CREATING(id, fn) { wxEVT_PLOT_VALUE_SEL_CREATING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL },
388 #define EVT_PLOT_VALUE_SEL_CREATED(id, fn) { wxEVT_PLOT_VALUE_SEL_CREATED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL },
389 #define EVT_PLOT_VALUE_SEL_CHANGING(id, fn) { wxEVT_PLOT_VALUE_SEL_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL },
390 #define EVT_PLOT_VALUE_SEL_CHANGED(id, fn) { wxEVT_PLOT_VALUE_SEL_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL },
391 #define EVT_PLOT_AREA_SEL_CREATING(id, fn) { wxEVT_PLOT_AREA_SEL_CREATING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL },
392 #define EVT_PLOT_AREA_SEL_CREATED(id, fn) { wxEVT_PLOT_AREA_SEL_CREATED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL },
393 #define EVT_PLOT_AREA_SEL_CHANGING(id, fn) { wxEVT_PLOT_AREA_SEL_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL },
394 #define EVT_PLOT_AREA_SEL_CHANGED(id, fn) { wxEVT_PLOT_AREA_SEL_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL },
395 #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 },
396 #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 },
397 #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 },
398 #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 },
399 #define EVT_PLOT_BEGIN_TITLE_EDIT(id, fn) { wxEVT_PLOT_BEGIN_TITLE_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL },
400 #define EVT_PLOT_END_TITLE_EDIT(id, fn) { wxEVT_PLOT_END_TITLE_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL },