]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/plot.h
Modified generic wxTreeCtrl to work under non-Unix platforms simultaneously
[wxWidgets.git] / include / wx / generic / plot.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: plot.h
3 // Purpose: wxPlotWindow
4 // Author: Robert Roebling
5 // Modified by:
6 // Created: 12/1/2000
7 // Copyright: (c) Robert Roebling
8 // RCS-ID: $Id$
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_PLOT_H_
13 #define _WX_PLOT_H_
14
15 #ifdef __GNUG__
16 #pragma interface "plot.h"
17 #endif
18
19 #include "wx/defs.h"
20
21 #if wxUSE_PLOT
22
23 #include "wx/scrolwin.h"
24 #include "wx/event.h"
25 #include "wx/dynarray.h"
26
27 //-----------------------------------------------------------------------------
28 // classes
29 //-----------------------------------------------------------------------------
30
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;
38
39 //-----------------------------------------------------------------------------
40 // consts
41 //-----------------------------------------------------------------------------
42
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
48
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)
51
52 //-----------------------------------------------------------------------------
53 // wxPlotEvent
54 //-----------------------------------------------------------------------------
55
56 class WXDLLEXPORT wxPlotEvent: public wxNotifyEvent
57 {
58 public:
59 wxPlotEvent( wxEventType commandType = wxEVT_NULL, int id = 0 );
60
61 wxPlotCurve *GetCurve()
62 { return m_curve; }
63 void SetCurve( wxPlotCurve *curve )
64 { m_curve = curve; }
65
66 double GetZoom()
67 { return m_zoom; }
68 void SetZoom( double zoom )
69 { m_zoom = zoom; }
70
71 wxInt32 GetPosition()
72 { return m_position; }
73 void SetPosition( wxInt32 pos )
74 { m_position = pos; }
75
76 private:
77 wxPlotCurve *m_curve;
78 double m_zoom;
79 wxInt32 m_position;
80 };
81
82 //-----------------------------------------------------------------------------
83 // wxPlotCurve
84 //-----------------------------------------------------------------------------
85
86 class WXDLLEXPORT wxPlotCurve: public wxObject
87 {
88 public:
89 wxPlotCurve( int offsetY, double startY, double endY );
90
91 virtual wxInt32 GetStartX() = 0;
92 virtual wxInt32 GetEndX() = 0;
93
94 virtual double GetY( wxInt32 x ) = 0;
95
96 void SetStartY( double startY )
97 { m_startY = startY; }
98 double GetStartY()
99 { return m_startY; }
100 void SetEndY( double endY )
101 { m_endY = endY; }
102 double GetEndY()
103 { return m_endY; }
104 void SetOffsetY( int offsetY )
105 { m_offsetY = offsetY; }
106 int GetOffsetY()
107 { return m_offsetY; }
108
109 void SetPenNormal( const wxPen &pen )
110 { m_penNormal = pen; }
111 void SetPenSelected( const wxPen &pen )
112 { m_penSelected = pen; }
113
114 private:
115 int m_offsetY;
116 double m_startY;
117 double m_endY;
118 wxPen m_penNormal;
119 wxPen m_penSelected;
120
121 DECLARE_ABSTRACT_CLASS(wxPlotCurve)
122 };
123
124 //-----------------------------------------------------------------------------
125 // wxPlotOnOffCurve
126 //-----------------------------------------------------------------------------
127
128 class WXDLLEXPORT wxPlotOnOff
129 {
130 public:
131 wxPlotOnOff() { }
132
133 wxInt32 m_on;
134 wxInt32 m_off;
135 void *m_clientData;
136 };
137
138 WX_DECLARE_EXPORTED_OBJARRAY(wxPlotOnOff, wxArrayPlotOnOff);
139
140 class WXDLLEXPORT wxPlotOnOffCurve: public wxObject
141 {
142 public:
143 wxPlotOnOffCurve( int offsetY );
144
145 wxInt32 GetStartX()
146 { return m_minX; }
147 wxInt32 GetEndX()
148 { return m_maxX; }
149
150 void SetOffsetY( int offsetY )
151 { m_offsetY = offsetY; }
152 int GetOffsetY()
153 { return m_offsetY; }
154
155 void Add( wxInt32 on, wxInt32 off, void *clientData = NULL );
156 size_t GetCount();
157
158 wxInt32 GetOn( size_t index );
159 wxInt32 GetOff( size_t index );
160 void* GetClientData( size_t index );
161 wxPlotOnOff *GetAt( size_t index );
162
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 );
165
166 private:
167 int m_offsetY;
168 wxInt32 m_minX;
169 wxInt32 m_maxX;
170
171 wxArrayPlotOnOff m_marks;
172
173 DECLARE_CLASS(wxPlotOnOffCurve)
174 };
175
176 //-----------------------------------------------------------------------------
177 // wxPlotArea
178 //-----------------------------------------------------------------------------
179
180 class WXDLLEXPORT wxPlotArea: public wxWindow
181 {
182 public:
183 wxPlotArea() {}
184 wxPlotArea( wxPlotWindow *parent );
185
186 void OnPaint( wxPaintEvent &event );
187 void OnMouse( wxMouseEvent &event );
188
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 );
192
193 virtual void ScrollWindow( int dx, int dy, const wxRect *rect );
194
195 private:
196 wxPlotWindow *m_owner;
197 bool m_zooming;
198
199 DECLARE_CLASS(wxPlotArea)
200 DECLARE_EVENT_TABLE()
201 };
202
203 //-----------------------------------------------------------------------------
204 // wxPlotXAxisArea
205 //-----------------------------------------------------------------------------
206
207 class WXDLLEXPORT wxPlotXAxisArea: public wxWindow
208 {
209 public:
210 wxPlotXAxisArea() {}
211 wxPlotXAxisArea( wxPlotWindow *parent );
212
213 void OnPaint( wxPaintEvent &event );
214 void OnMouse( wxMouseEvent &event );
215
216 private:
217 wxPlotWindow *m_owner;
218
219 DECLARE_CLASS(wxPlotXAxisArea)
220 DECLARE_EVENT_TABLE()
221 };
222
223 //-----------------------------------------------------------------------------
224 // wxPlotYAxisArea
225 //-----------------------------------------------------------------------------
226
227 class WXDLLEXPORT wxPlotYAxisArea: public wxWindow
228 {
229 public:
230 wxPlotYAxisArea() {}
231 wxPlotYAxisArea( wxPlotWindow *parent );
232
233 void OnPaint( wxPaintEvent &event );
234 void OnMouse( wxMouseEvent &event );
235
236 private:
237 wxPlotWindow *m_owner;
238
239 DECLARE_CLASS(wxPlotYAxisArea)
240 DECLARE_EVENT_TABLE()
241 };
242
243 //-----------------------------------------------------------------------------
244 // wxPlotWindow
245 //-----------------------------------------------------------------------------
246
247 class WXDLLEXPORT wxPlotWindow: public wxScrolledWindow
248 {
249 public:
250 wxPlotWindow() {}
251 wxPlotWindow( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, int flags = wxPLOT_DEFAULT );
252 ~wxPlotWindow();
253
254 // curve accessors
255 // ---------------
256
257 void Add( wxPlotCurve *curve );
258 void Delete( wxPlotCurve* curve );
259
260 size_t GetCount();
261 wxPlotCurve *GetAt( size_t n );
262
263 void SetCurrent( wxPlotCurve* current );
264 wxPlotCurve *GetCurrent();
265
266 // mark list accessors
267 // -------------------
268
269 void Add( wxPlotOnOffCurve *curve );
270 void Delete( wxPlotOnOffCurve* curve );
271
272 size_t GetOnOffCurveCount();
273 wxPlotOnOffCurve *GetOnOffCurveAt( size_t n );
274
275 // vertical representation
276 // -----------------------
277
278 void Move( wxPlotCurve* curve, int pixels_up );
279 void Enlarge( wxPlotCurve *curve, double factor );
280
281 // horizontal representation
282 // -------------------------
283
284 void SetUnitsPerValue( double upv );
285 double GetUnitsPerValue()
286 { return m_xUnitsPerValue; }
287
288 void SetZoom( double zoom );
289 double GetZoom()
290 { return m_xZoom; }
291
292 // options
293 // -------
294
295 void SetScrollOnThumbRelease( bool scrollOnThumbRelease = TRUE )
296 { m_scrollOnThumbRelease = scrollOnThumbRelease; }
297 bool GetScrollOnThumbRelease()
298 { return m_scrollOnThumbRelease; }
299
300 void SetEnlargeAroundWindowCentre( bool enlargeAroundWindowCentre = TRUE )
301 { m_enlargeAroundWindowCentre = enlargeAroundWindowCentre; }
302 bool GetEnlargeAroundWindowCentre()
303 { return m_enlargeAroundWindowCentre; }
304
305 // events (may be overridden)
306 // --------------------------
307
308 void OnMoveUp( wxCommandEvent& event );
309 void OnMoveDown( wxCommandEvent& event );
310
311 void OnEnlarge( wxCommandEvent& event );
312 void OnShrink( wxCommandEvent& event );
313 void OnZoomIn( wxCommandEvent& event );
314 void OnZoomOut( wxCommandEvent& event );
315
316 void OnScroll2( wxScrollWinEvent& event );
317
318 // utilities
319 // ---------
320
321 void RedrawEverything();
322 void RedrawXAxis();
323 void RedrawYAxis();
324
325 void ResetScrollbar();
326
327 private:
328 friend class wxPlotArea;
329 friend class wxPlotXAxisArea;
330 friend class wxPlotYAxisArea;
331
332 double m_xUnitsPerValue;
333 double m_xZoom;
334
335 wxList m_curves;
336 wxList m_onOffCurves;
337
338 wxPlotArea *m_area;
339 wxPlotXAxisArea *m_xaxis;
340 wxPlotYAxisArea *m_yaxis;
341 wxPlotCurve *m_current;
342
343 bool m_scrollOnThumbRelease;
344 bool m_enlargeAroundWindowCentre;
345
346 DECLARE_CLASS(wxPlotWindow)
347 DECLARE_EVENT_TABLE()
348 };
349
350 // ----------------------------------------------------------------------------
351 // plot event macros
352 // ----------------------------------------------------------------------------
353
354 typedef void (wxEvtHandler::*wxPlotEventFunction)(wxPlotEvent&);
355
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 },
377
378 #endif // wxUSE_PLOT
379
380 #endif
381 // _WX_PLOT_H_