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
);
220 void SetScrollOnThumbRelease( bool scrollOnThumbRelease
= TRUE
)
221 { m_scrollOnThumbRelease
= scrollOnThumbRelease
; }
222 bool GetScrollOnThumbRelease()
223 { return m_scrollOnThumbRelease
; }
225 void SetEnlargeAroundWindowCentre( bool enlargeAroundWindowCentre
= TRUE
)
226 { m_enlargeAroundWindowCentre
= enlargeAroundWindowCentre
; }
227 bool GetEnlargeAroundWindowCentre()
228 { return m_enlargeAroundWindowCentre
; }
230 // events (may be overridden)
231 // --------------------------
233 void OnMoveUp( wxCommandEvent
& event
);
234 void OnMoveDown( wxCommandEvent
& event
);
236 void OnEnlarge( wxCommandEvent
& event
);
237 void OnShrink( wxCommandEvent
& event
);
238 void OnZoomIn( wxCommandEvent
& event
);
239 void OnZoomOut( wxCommandEvent
& event
);
241 void OnScroll2( wxScrollWinEvent
& event
);
246 void RedrawEverything();
250 void ResetScrollbar();
254 friend wxPlotXAxisArea
;
255 friend wxPlotYAxisArea
;
257 double m_xUnitsPerValue
;
262 wxPlotXAxisArea
*m_xaxis
;
263 wxPlotYAxisArea
*m_yaxis
;
264 wxPlotCurve
*m_current
;
266 bool m_scrollOnThumbRelease
;
267 bool m_enlargeAroundWindowCentre
;
269 DECLARE_CLASS(wxPlotWindow
)
270 DECLARE_EVENT_TABLE()
273 // ----------------------------------------------------------------------------
274 // calendar events macros
275 // ----------------------------------------------------------------------------
277 #define EVT_PLOT(id, fn) { wxEVT_PLOT_DOUBLECLICKED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
278 #define EVT_PLOT_SEL_CHANGING(id, fn) { wxEVT_PLOT_SEL_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
279 #define EVT_PLOT_SEL_CHANGED(id, fn) { wxEVT_PLOT_SEL_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
280 #define EVT_PLOT_CLICKED(id, fn) { wxEVT_PLOT_CLICKED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
281 #define EVT_PLOT_DOUBLECLICKED(id, fn) { wxEVT_PLOT_DOUBLECLICKED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
282 #define EVT_PLOT_ZOOM_IN(id, fn) { wxEVT_PLOT_ZOOM_IN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
283 #define EVT_PLOT_ZOOM_OUT(id, fn) { wxEVT_PLOT_ZOOM_OUT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
284 #define EVT_PLOT_VALUE_SEL_CREATING(id, fn) { wxEVT_PLOT_VALUE_SEL_CREATING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
285 #define EVT_PLOT_VALUE_SEL_CREATED(id, fn) { wxEVT_PLOT_VALUE_SEL_CREATED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
286 #define EVT_PLOT_VALUE_SEL_CHANGING(id, fn) { wxEVT_PLOT_VALUE_SEL_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
287 #define EVT_PLOT_VALUE_SEL_CHANGED(id, fn) { wxEVT_PLOT_VALUE_SEL_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
288 #define EVT_PLOT_AREA_SEL_CREATING(id, fn) { wxEVT_PLOT_AREA_SEL_CREATING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
289 #define EVT_PLOT_AREA_SEL_CREATED(id, fn) { wxEVT_PLOT_AREA_SEL_CREATED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
290 #define EVT_PLOT_AREA_SEL_CHANGING(id, fn) { wxEVT_PLOT_AREA_SEL_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
291 #define EVT_PLOT_AREA_SEL_CHANGED(id, fn) { wxEVT_PLOT_AREA_SEL_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
292 #define EVT_PLOT_BEGIN_X_LABEL_EDIT(id, fn) { wxEVT_PLOT_BEGIN_X_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
293 #define EVT_PLOT_END_X_LABEL_EDIT(id, fn) { wxEVT_PLOT_END_X_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
294 #define EVT_PLOT_BEGIN_Y_LABEL_EDIT(id, fn) { wxEVT_PLOT_BEGIN_Y_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
295 #define EVT_PLOT_END_Y_LABEL_EDIT(id, fn) { wxEVT_PLOT_END_Y_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
296 #define EVT_PLOT_BEGIN_TITLE_EDIT(id, fn) { wxEVT_PLOT_BEGIN_TITLE_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },
297 #define EVT_PLOT_END_TITLE_EDIT(id, fn) { wxEVT_PLOT_END_TITLE_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL },