]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/plot.h
SCROLLWIN instead of SCROLL again
[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/scrolwin.h"
20 #include "wx/event.h"
21
22 //-----------------------------------------------------------------------------
23 // classes
24 //-----------------------------------------------------------------------------
25
26 class WXDLLEXPORT wxPlotEvent;
27 class WXDLLEXPORT wxPlotCurve;
28 class WXDLLEXPORT wxPlotArea;
29 class WXDLLEXPORT wxPlotXAxisArea;
30 class WXDLLEXPORT wxPlotYAxisArea;
31 class WXDLLEXPORT wxPlotWindow;
32
33 //-----------------------------------------------------------------------------
34 // consts
35 //-----------------------------------------------------------------------------
36
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
42
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)
45
46 //-----------------------------------------------------------------------------
47 // wxPlotEvent
48 //-----------------------------------------------------------------------------
49
50 class WXDLLEXPORT wxPlotEvent: public wxNotifyEvent
51 {
52 public:
53 wxPlotEvent( wxEventType commandType = wxEVT_NULL, int id = 0 );
54
55 wxPlotCurve *GetCurve()
56 { return m_curve; }
57 void SetCurve( wxPlotCurve *curve )
58 { m_curve = curve; }
59
60 double GetZoom()
61 { return m_zoom; }
62 void SetZoom( double zoom )
63 { m_zoom = zoom; }
64
65 wxInt32 GetPosition()
66 { return m_position; }
67 void SetPosition( wxInt32 pos )
68 { m_position = pos; }
69
70 private:
71 wxPlotCurve *m_curve;
72 double m_zoom;
73 wxInt32 m_position;
74 };
75
76 //-----------------------------------------------------------------------------
77 // wxPlotCurve
78 //-----------------------------------------------------------------------------
79
80 class WXDLLEXPORT wxPlotCurve: public wxObject
81 {
82 public:
83 wxPlotCurve( int offsetY, double startY, double endY );
84
85 virtual wxInt32 GetStartX() = 0;
86 virtual wxInt32 GetEndX() = 0;
87
88 virtual double GetY( wxInt32 x ) = 0;
89
90 void SetStartY( double startY )
91 { m_startY = startY; }
92 double GetStartY()
93 { return m_startY; }
94 void SetEndY( double endY )
95 { m_endY = endY; }
96 double GetEndY()
97 { return m_endY; }
98 void SetOffsetY( int offsetY )
99 { m_offsetY = offsetY; }
100 int GetOffsetY()
101 { return m_offsetY; }
102
103 private:
104 int m_offsetY;
105 double m_startY;
106 double m_endY;
107
108 DECLARE_ABSTRACT_CLASS(wxPlotCurve)
109 };
110
111 //-----------------------------------------------------------------------------
112 // wxPlotArea
113 //-----------------------------------------------------------------------------
114
115 class WXDLLEXPORT wxPlotArea: public wxWindow
116 {
117 public:
118 wxPlotArea() {}
119 wxPlotArea( wxPlotWindow *parent );
120
121 void OnPaint( wxPaintEvent &event );
122 void OnMouse( wxMouseEvent &event );
123
124 void DrawCurve( wxDC *dc, wxPlotCurve *curve, int from = -1, int to = -1 );
125 void DeleteCurve( wxPlotCurve *curve, int from = -1, int to = -1 );
126
127 virtual void ScrollWindow( int dx, int dy, const wxRect *rect );
128
129 private:
130 wxPlotWindow *m_owner;
131 bool m_zooming;
132
133 DECLARE_CLASS(wxPlotArea)
134 DECLARE_EVENT_TABLE()
135 };
136
137 //-----------------------------------------------------------------------------
138 // wxPlotXAxisArea
139 //-----------------------------------------------------------------------------
140
141 class WXDLLEXPORT wxPlotXAxisArea: public wxWindow
142 {
143 public:
144 wxPlotXAxisArea() {}
145 wxPlotXAxisArea( wxPlotWindow *parent );
146
147 void OnPaint( wxPaintEvent &event );
148 void OnMouse( wxMouseEvent &event );
149
150 private:
151 wxPlotWindow *m_owner;
152
153 DECLARE_CLASS(wxPlotXAxisArea)
154 DECLARE_EVENT_TABLE()
155 };
156
157 //-----------------------------------------------------------------------------
158 // wxPlotYAxisArea
159 //-----------------------------------------------------------------------------
160
161 class WXDLLEXPORT wxPlotYAxisArea: public wxWindow
162 {
163 public:
164 wxPlotYAxisArea() {}
165 wxPlotYAxisArea( wxPlotWindow *parent );
166
167 void OnPaint( wxPaintEvent &event );
168 void OnMouse( wxMouseEvent &event );
169
170 private:
171 wxPlotWindow *m_owner;
172
173 DECLARE_CLASS(wxPlotYAxisArea)
174 DECLARE_EVENT_TABLE()
175 };
176
177 //-----------------------------------------------------------------------------
178 // wxPlotWindow
179 //-----------------------------------------------------------------------------
180
181 class WXDLLEXPORT wxPlotWindow: public wxScrolledWindow
182 {
183 public:
184 wxPlotWindow() {}
185 wxPlotWindow( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, int flags = wxPLOT_DEFAULT );
186 ~wxPlotWindow();
187
188 // curve accessors
189 // ---------------
190
191 void Add( wxPlotCurve *curve );
192 size_t GetCount();
193 wxPlotCurve *GetAt( size_t n );
194
195 void SetCurrent( wxPlotCurve* current );
196 wxPlotCurve *GetCurrent();
197
198 void Delete( wxPlotCurve* curve );
199
200 // vertical representation
201 // -----------------------
202
203 void Move( wxPlotCurve* curve, int pixels_up );
204 void Enlarge( wxPlotCurve *curve, double factor );
205
206 // horizontal representation
207 // -------------------------
208
209 void SetUnitsPerValue( double upv );
210 double GetUnitsPerValue()
211 { return m_xUnitsPerValue; }
212
213 void SetZoom( double zoom );
214 double GetZoom()
215 { return m_xZoom; }
216
217 // options
218 // -------
219
220 void SetScrollOnThumbRelease( bool scrollOnThumbRelease = TRUE )
221 { m_scrollOnThumbRelease = scrollOnThumbRelease; }
222 bool GetScrollOnThumbRelease()
223 { return m_scrollOnThumbRelease; }
224
225 void SetEnlargeAroundWindowCentre( bool enlargeAroundWindowCentre = TRUE )
226 { m_enlargeAroundWindowCentre = enlargeAroundWindowCentre; }
227 bool GetEnlargeAroundWindowCentre()
228 { return m_enlargeAroundWindowCentre; }
229
230 // events (may be overridden)
231 // --------------------------
232
233 void OnMoveUp( wxCommandEvent& event );
234 void OnMoveDown( wxCommandEvent& event );
235
236 void OnEnlarge( wxCommandEvent& event );
237 void OnShrink( wxCommandEvent& event );
238 void OnZoomIn( wxCommandEvent& event );
239 void OnZoomOut( wxCommandEvent& event );
240
241 void OnScroll2( wxScrollWinEvent& event );
242
243 // utilities
244 // ---------
245
246 void RedrawEverything();
247 void RedrawXAxis();
248 void RedrawYAxis();
249
250 void ResetScrollbar();
251
252 private:
253 friend wxPlotArea;
254 friend wxPlotXAxisArea;
255 friend wxPlotYAxisArea;
256
257 double m_xUnitsPerValue;
258 double m_xZoom;
259
260 wxList m_curves;
261 wxPlotArea *m_area;
262 wxPlotXAxisArea *m_xaxis;
263 wxPlotYAxisArea *m_yaxis;
264 wxPlotCurve *m_current;
265
266 bool m_scrollOnThumbRelease;
267 bool m_enlargeAroundWindowCentre;
268
269 DECLARE_CLASS(wxPlotWindow)
270 DECLARE_EVENT_TABLE()
271 };
272
273 // ----------------------------------------------------------------------------
274 // calendar events macros
275 // ----------------------------------------------------------------------------
276
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 },
298
299 #endif
300 // _WX_PLOT_H_