1 
2 /*
3  * ===========================
4  * VDK Visual Development Kit
5  * Version 2.0.2
6  * May 2002
7  * ===========================
8  *
9  * Copyright (C) 1998, Mario Motta
10  * Developed by Mario Motta <mmotta@guest.net>
11  * Based on ISDataBox
12  * Developed by Ionutz Borcoman <borco@borco-ei.eng.hokudai.ac.jp>
13  * based on  GtkDatabox - An extension to the gtk+ library
14  * Copyright (C) 1998-1999 Roland Bock
15  *
16  * This library is free software; you can redistribute it and/or
17  * modify it under the terms of the GNU Library General Public
18  * License as published by the Free Software Foundation; either
19  * version 2 of the License, or (at your option) any later version.
20  *
21  * This library is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
24  * Library General Public License for more details.
25  *
26  * You should have received a copy of the GNU Library General Public
27  * License along with this library; if not, write to the Free Software
28  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
29  * 02111-1307, USA.
30  */
31 
32 #ifndef _vdkdatabox_h_
33 #define _vdkdatabox_h_
34 
35 #include <vdk/vdk.h>
36 #include <vdk/gtkdatabox.h>
37 
38 
39 /*! \class VDKDataBox
40  *  \brief Databox widget.
41  *
42  *  This is a simple (almost 1:1) wrapper of
43  *	<b><a href="http://www.eudoxos.net/gtk/gtkdatabox/index.html">
44  *		GtkDatabox 0.1.11.0
45  *	</a></b>
46  *  widget.
47  *  Some of the functions have been modified in order to return
48  *  a value, instead to change the value sent as parameter, as
49  *  I have thought this is more in the VDK spirit. Also, wherever
50  *  the case, I used a VDKColor instead of GdkColor, for the same
51  *  reason: VDK spirit.
52  *
53  *  The data box has the following styles (but check
54  *  \e GtkDataboxDataType for other styles):
55  *  \arg GTK_DATABOX_NOT_DISPLAYED
56  *  \arg GTK_DATABOX_POINTS
57  *  \arg GTK_DATABOX_LINES
58  *  \arg GTK_DATABOX_BARS
59  *  \arg GTK_DATABOX_CROSS_SIMPLE,
60  *  \arg GTK_DATABOX_GRID
61  *
62  *  <b>Public Members</b>
63  *  \arg None.
64  *
65  *  <b>Properties</b>
66  *  \arg bool \b Rulers
67  *  \arg bool \b Scrollbars
68  *  \arg bool \b Zoom
69  *  \arg GtkDataboxValue \b Mark \e (read-only)
70  *  \arg GtkDataboxValue \b Select \e (read-only)
71  *  \arg GtkDataboxCoord \b TopLeft \e (read-only)
72  *  \arg GtkDataboxCoord \b BottomRight \e (read-only)
73  *
74  *  <b>Static Table Signals</b>
75  *  \arg \b databox_zoomed_signal Emitted when databox is zoomed.
76  *  \arg \b databox_marked_signal Emitted when mouse is clicked in databox.
77  *  \arg \b databox_selection_started_signal Emitted when a selection is started in databox.
78  *  \arg \b databox_selection_changed_signal Emitted when the selection is changed.
79  *  \arg \b databox_selection_stopped_signal Emitted when the selection is finished.
80  *  \arg \b databox_selection_canceled_signal Emitted when the selection is canceled
81  *                             (by clicking outside the selection).
82  *
83  *  <b>Dynamic Table Signals</b>
84  *  \arg \b "databox_zoomed"
85  *  \arg \b "databox_marked"
86  *  \arg \b "databox_selection_started"
87  *  \arg \b "databox_selection_changed"
88  *  \arg \b "databox_selection_stopped"
89  *  \arg \b "databox_selection_canceled"
90  *
91  *  Dynamic table signals are different from the equivalent databox signals in
92  *  that that they do not send values of the marked point or selection, for
93  *  instance. These values can be read using the \e read-only properties.
94  *
95  *  \author Ionutz Borcoman <borco@borco-ei.eng.hokudai.ac.jp>
96  *  \date March 1999
97  *  \author Mario Motta <mmotta@guest.net> that have done the porting to vdk 2.x
98  *  \date May 2002
99  */
100 class VDKDataBox: public VDKObject
101 {
102 public:
103   //! Constructor.
104   VDKDataBox(VDKForm *owner);
105   //! Destructor.
106   ~VDKDataBox();
107 
108   //! Shows or hides the rulers.
109   VDKReadWriteValueProp<VDKDataBox, bool> Rulers;
110   void SetRulers(bool);
111 
112   //! Show or hides the scrollbars.
113   VDKReadWriteValueProp<VDKDataBox, bool> Scrollbars;
114   void SetScrollbars(bool);
115 
116   //! Enable or disable the zoom.
117   VDKReadWriteValueProp<VDKDataBox, bool> Zoom;
118   void SetZoom(bool);
119 
120   //! Read the value of the top left corner of the window after a zoom.
121   VDKReadOnlyValueProp<VDKDataBox, GtkDataboxValue> TopLeft;
122 
123   //! Read the value of the bottom right corner of the window after a zoom.
124   VDKReadOnlyValueProp<VDKDataBox, GtkDataboxValue> BottomRight;
125 
126   //! Read the value of the marked (where you clicked down the mouse) point.
127   VDKReadOnlyValueProp<VDKDataBox, GtkDataboxCoord> Mark;
128 
129   //! Read the value of the selection.
130   VDKReadOnlyValueProp<VDKDataBox, GtkDataboxCoord> Select;
131 
132   //! Get the color of a dataset.
133   /*! \param index dataset index
134    *  \return pointer to a VDKColor identical with the one of the dataset.
135    *  \bug The returned value is a pointer to a new allocated VDKColor. Therefore,
136    *       it will not reflect furthure changes in the color of the \e index dataset.
137    *       You can free memory associated with it using Destroy() method.
138    */
139   VDKColor* GetColor(int index);
140 
141   //! Set the color of a dataset.
142   /*! \param index dataset index
143    *  \param color new color for the dataset
144    *  \param redraw constrols if we call or not a subsequent Redraw().
145    *                Set to \e false if you don't want a redraw.
146    */
147   void SetColor(int index, VDKColor *color, bool redraw = true);
148 
149   //! Get data value.
150   /*! \param coord screen coordinates of a point.
151    *  \return data value associated with the \e coord.
152    */
153   GtkDataboxValue GetValue(GtkDataboxCoord coord);
154 
155   //! Get the extreme values.
156   /*! \param min returns the minimum x and y values of the databox.
157    *  \param max returns the maximum x and y values of the databox.
158    *  \param visible if true, then \e min and \e max are computed
159    *                 for the visible window; otherwise, they are
160    *                 computed for the whole databox.
161    */
162   void GetExtrema(GtkDataboxValue& min, GtkDataboxValue& max,
163 				  bool visible = true);
164 
165   //! Rescale the databox using given minimum and maximum values.
166   /*! \param min the minimum x and y values.
167    *  \param max the maximum x and y values.
168    */
169   void Rescale(GtkDataboxValue min, GtkDataboxValue max);
170 
171   /*! \brief Rescale the databox using the minimum and maximum
172    *         values from the datasets associated with the databox.
173    */
174   void Rescale();
175 
176   //! Redraw the databox. Use it after you change your datas.
177   void Redraw();
178 
179   //! Remove a single dataset.
180   /*! \param index index of dataset to be removed.
181    *  \return 0 on success.
182    */
183   gint RemoveData(gint index);
184 
185   //! Remove all datasets.
186   /*! \return 0 on success.
187    */
188   gint RemoveData();
189 
190   //! Remove a single dataset and destroy data associated with it.
191   /*! \param index index of dataset to be destroyed.
192    *  \return 0 on success.
193    *  \bug this function destroys data associated using g_free().
194    *       Do not use it, unless you have used g_new() to allocate
195    *       the memory for your data.
196    */
197   gint DestroyData(gint index);
198 
199   //! Remove all datasets and destroy data associated with them.
200   /*! \return 0 on success.
201    *  \sa Destroy(gint)
202    */
203   gint DestroyData();
204 
205   //! Add a dataset.
206   /*! Both X and Y must be supplied. Also the number of points and a color
207    *  to be used for ploting the dataset.
208    *  \param length number of points from the dataset.
209    *  \param X pointer to x vector of data.
210    *  \param Y pointer to y vector of data.
211    *  \param color color for the ploting the dataset
212    *  \param type type of points.
213    *  \param dotsize size of the dots used.
214    *  \return index of the dataset added, on success, or -1, on error.
215    */
216   gint AddXY(guint length, gfloat *X, gfloat *Y, VDKColor *color,
217 			 GtkDataboxDataType type = GTK_DATABOX_POINTS, guint dotSize = 1);
218 
219   //! Add a dataset.
220   /*! You must supply a X vector of data and an index to an existent Y vector.
221    *  Also the number of points and a color to be used for ploting the dataset.
222    *  If the number of points of X and shared Y vector are different, an error
223    *  is generated.
224    *  \param length number of points from the dataset.
225    *  \param X pointer to x vector of data.
226    *  \param indexSharedY index to a shared y vector of data.
227    *  \param color color for the ploting the dataset
228    *  \param type type of points.
229    *  \param dotsize size of the dots used.
230    *  \return index of the dataset added, on success, or -1, on error.
231    */
232   gint AddX (guint length, gfloat *X, guint indexSharedY, VDKColor *color,
233 			 GtkDataboxDataType type = GTK_DATABOX_POINTS, guint dotSize = 1);
234 
235   //! Add a dataset.
236   /*! You must supply a Y vector of data and an index to an existent X vector.
237    *  Also the number of points and a color to be used for ploting the dataset.
238    *  If the number of points of X and shared Y vector are different, an error
239    *  is generated.
240    *  \param length number of points from the dataset.
241    *  \param Y pointer to y vector of data.
242    *  \param indexSharedX index to a shared x vector of data.
243    *  \param color color for the ploting the dataset
244    *  \param type type of points.
245    *  \param dotsize size of the dots used.
246    *  \return index of the dataset added, on success, or -1, on error.
247    */
248   gint AddY (guint length, gfloat *Y, guint indexSharedX, VDKColor *color,
249 			 GtkDataboxDataType type = GTK_DATABOX_POINTS, guint dotSize = 1);
250 
251 virtual void SetBackground(VDKRgb color, GtkStateType state);
252 protected:
253   // Signal handling functions
254   static gint _zoomed(GtkDatabox *box,
255 					  GtkDataboxValue *top_left,
256 					  GtkDataboxValue *bottom_right,
257 					  gpointer);
258 
259   static gint _marked(GtkDatabox *,
260 					  GtkDataboxCoord *mark,
261 					  gpointer gp);
262 
263   static gint _selectionStarted(GtkDatabox *,
264 								GtkDataboxCoord *mark,
265 								gpointer gp);
266 
267   static gint _selectionChanged(GtkDatabox *,
268 								GtkDataboxCoord *mark,
269 								GtkDataboxCoord *select,
270 								gpointer gp);
271 
272   static gint _selectionStoped(GtkDatabox *,
273 							   GtkDataboxCoord *mark,
274 							   GtkDataboxCoord *select,
275 							   gpointer gp);
276 
277   static gint _selectionCanceled(GtkDatabox *,
278 								 gpointer gp);
279 
280 };
281 #endif
282