"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "gtk/gtkdatabox.c" between
gtkdatabox-0.9.3.1.tar.gz and gtkdatabox-1.0.0.tar.gz

About: GtkDatabox is a Gtk+-widget for live display of large amounts of fluctuating numerical data.

gtkdatabox.c  (gtkdatabox-0.9.3.1):gtkdatabox.c  (gtkdatabox-1.0.0)
skipping to change at line 17 skipping to change at line 17
* as published by the Free Software Foundation; either version 2.1 * as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version. * of the License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gtkdatabox.h> #include <gtkdatabox.h>
#include <gtkdatabox_marshal.h> #include <gtkdatabox_marshal.h>
#include <gtkdatabox_ruler.h> #include <gtkdatabox_ruler.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <math.h> #include <math.h>
#ifdef _MSC_VER
#ifndef _DATABOX_LOG2_
#define _DATABOX_LOG2_
/*< private >*/
#define log2(x) (log(x)/log(2))
#endif /*_DATABOX_LOG2_ */
#endif /*_MSC_VER */
static gint gtk_databox_button_press (GtkWidget * widget, static gint gtk_databox_button_press (GtkWidget * widget,
GdkEventButton * event); GdkEventButton * event);
static gint gtk_databox_scroll_event (GtkWidget *widget, static gint gtk_databox_scroll_event (GtkWidget *widget,
GdkEventScroll *event); GdkEventScroll *event);
static gint gtk_databox_button_release (GtkWidget * widget, static gint gtk_databox_button_release (GtkWidget * widget,
GdkEventButton * event); GdkEventButton * event);
static gint gtk_databox_motion_notify (GtkWidget * widget, static gint gtk_databox_motion_notify (GtkWidget * widget,
GdkEventMotion * event); GdkEventMotion * event);
static void gtk_databox_realize (GtkWidget * widget); static void gtk_databox_realize (GtkWidget * widget);
static void gtk_databox_unrealize (GtkWidget * widget); static void gtk_databox_unrealize (GtkWidget * widget);
static void gtk_databox_size_allocate (GtkWidget * widget, static void gtk_databox_size_allocate (GtkWidget * widget,
GtkAllocation * allocation); GtkAllocation * allocation);
static gint gtk_databox_expose (GtkWidget * widget, static gint gtk_databox_draw (GtkWidget * widget,
GdkEventExpose * event); cairo_t * cr);
static void gtk_databox_set_property (GObject * object, static void gtk_databox_set_property (GObject * object,
guint prop_id, guint prop_id,
const GValue * value, const GValue * value,
GParamSpec * pspec); GParamSpec * pspec);
static void gtk_databox_get_property (GObject * object, static void gtk_databox_get_property (GObject * object,
guint prop_id, guint prop_id,
GValue * value, GValue * value,
GParamSpec * pspec); GParamSpec * pspec);
static gfloat gtk_databox_get_offset_x (GtkDatabox* box); static gfloat gtk_databox_get_offset_x (GtkDatabox* box);
static gfloat gtk_databox_get_page_size_x (GtkDatabox* box); static gfloat gtk_databox_get_page_size_x (GtkDatabox* box);
static gfloat gtk_databox_get_offset_y (GtkDatabox* box); static gfloat gtk_databox_get_offset_y (GtkDatabox* box);
static gfloat gtk_databox_get_page_size_y (GtkDatabox* box); static gfloat gtk_databox_get_page_size_y (GtkDatabox* box);
static void gtk_databox_calculate_visible_limits (GtkDatabox * box); static void gtk_databox_calculate_visible_limits (GtkDatabox * box);
static void gtk_databox_create_backing_pixmap (GtkDatabox * box); static void gtk_databox_create_backing_surface (GtkDatabox * box);
static void gtk_databox_calculate_selection_values (GtkDatabox * box); static void gtk_databox_calculate_selection_values (GtkDatabox * box);
static void gtk_databox_selection_cancel (GtkDatabox * box); static void gtk_databox_selection_cancel (GtkDatabox * box);
static void gtk_databox_zoomed (GtkDatabox * box); static void gtk_databox_zoomed (GtkDatabox * box);
static void gtk_databox_draw_selection (GtkDatabox * box, static void gtk_databox_draw_selection (GtkDatabox * box, gboolean clear);
GdkRectangle * pixmapCopyRect);
static void gtk_databox_adjustment_value_changed (GtkDatabox * box); static void gtk_databox_adjustment_value_changed (GtkDatabox * box);
static void gtk_databox_ruler_update (GtkDatabox * box); static void gtk_databox_ruler_update (GtkDatabox * box);
/* IDs of signals */ /* IDs of signals */
enum { enum {
ZOOMED_SIGNAL, ZOOMED_SIGNAL,
SELECTION_STARTED_SIGNAL, SELECTION_STARTED_SIGNAL,
SELECTION_CHANGED_SIGNAL, SELECTION_CHANGED_SIGNAL,
SELECTION_FINALIZED_SIGNAL, SELECTION_FINALIZED_SIGNAL,
SELECTION_CANCELED_SIGNAL, SELECTION_CANCELED_SIGNAL,
skipping to change at line 90 skipping to change at line 101
ADJUSTMENT_X, ADJUSTMENT_X,
ADJUSTMENT_Y, ADJUSTMENT_Y,
RULER_X, RULER_X,
RULER_Y, RULER_Y,
SCALE_TYPE_X, SCALE_TYPE_X,
SCALE_TYPE_Y, SCALE_TYPE_Y,
BOX_SHADOW, BOX_SHADOW,
LAST_PROPERTY LAST_PROPERTY
}; };
/** /*
* GtkDataboxPrivate * GtkDataboxPrivate
* *
* A private data structure used by the #GtkDatabox. It shields all internal thi ngs * A private data structure used by the #GtkDatabox. It shields all internal thi ngs
* from developers who are just using the widget. * from developers who are just using the widget.
* *
**/ */
typedef struct _GtkDataboxPrivate GtkDataboxPrivate; typedef struct _GtkDataboxPrivate GtkDataboxPrivate;
struct _GtkDataboxPrivate { struct _GtkDataboxPrivate {
GdkPixmap *backing_pixmap; cairo_surface_t *backing_surface;
gint old_width;
gint old_height;
/* Total and visible limits (values, not pixels) */ /* Total and visible limits (values, not pixels) */
gfloat total_left; gfloat total_left;
gfloat total_right; gfloat total_right;
gfloat total_top; gfloat total_top;
gfloat total_bottom; gfloat total_bottom;
gfloat visible_left; gfloat visible_left;
gfloat visible_right; gfloat visible_right;
gfloat visible_top; gfloat visible_top;
gfloat visible_bottom; gfloat visible_bottom;
skipping to change at line 128 skipping to change at line 141
/* Properties */ /* Properties */
gboolean enable_selection; gboolean enable_selection;
gboolean enable_zoom; gboolean enable_zoom;
GtkAdjustment *adj_x; GtkAdjustment *adj_x;
GtkAdjustment *adj_y; GtkAdjustment *adj_y;
GtkDataboxRuler *ruler_x; GtkDataboxRuler *ruler_x;
GtkDataboxRuler *ruler_y; GtkDataboxRuler *ruler_y;
/* Other private stuff */ /* Other private stuff */
GList *graphs; GList *graphs;
GdkGC *select_gc;
GdkPoint marked; GdkPoint marked;
GdkPoint select; GdkPoint select;
GtkDataboxValueRectangle selectionValues; GtkDataboxValueRectangle selectionValues;
gfloat zoom_limit; gfloat zoom_limit;
/* flags */ /* flags */
gboolean selection_active; gboolean selection_active;
gboolean selection_finalized; gboolean selection_finalized;
GtkShadowType box_shadow; /* The type of shadow drawn on the pixmap edge */ GtkShadowType box_shadow; /* The type of shadow drawn on the pixmap edge */
GtkCssProvider *cssp; /* Internal style sheet used for background-color */
}; };
/** /**
* gtk_databox_get_type * gtk_databox_get_type
* *
* Determines the #GType of the GtkDatabox widget type. * Determines the #GType of the GtkDatabox widget type.
* *
* Return value: The #GType of the GtkDatabox widget type. * Return value: The #GType of the GtkDatabox widget type.
* *
*/ */
G_DEFINE_TYPE (GtkDatabox, gtk_databox, GTK_TYPE_WIDGET) G_DEFINE_TYPE_WITH_PRIVATE(GtkDatabox, gtk_databox, GTK_TYPE_WIDGET)
static void static void
gtk_databox_class_init (GtkDataboxClass * class) { gtk_databox_class_init (GtkDataboxClass * class) {
GObjectClass *gobject_class; GObjectClass *gobject_class;
GtkWidgetClass *widget_class; GtkWidgetClass *widget_class;
gobject_class = G_OBJECT_CLASS (class); gobject_class = G_OBJECT_CLASS (class);
widget_class = (GtkWidgetClass *) class; widget_class = (GtkWidgetClass *) class;
gobject_class->set_property = gtk_databox_set_property; gobject_class->set_property = gtk_databox_set_property;
gobject_class->get_property = gtk_databox_get_property; gobject_class->get_property = gtk_databox_get_property;
widget_class->realize = gtk_databox_realize; widget_class->realize = gtk_databox_realize;
widget_class->unrealize = gtk_databox_unrealize; widget_class->unrealize = gtk_databox_unrealize;
widget_class->size_allocate = gtk_databox_size_allocate; widget_class->size_allocate = gtk_databox_size_allocate;
widget_class->expose_event = gtk_databox_expose; widget_class->draw = gtk_databox_draw;
widget_class->motion_notify_event = gtk_databox_motion_notify; widget_class->motion_notify_event = gtk_databox_motion_notify;
widget_class->button_press_event = gtk_databox_button_press; widget_class->button_press_event = gtk_databox_button_press;
widget_class->button_release_event = gtk_databox_button_release; widget_class->button_release_event = gtk_databox_button_release;
widget_class->scroll_event = gtk_databox_scroll_event; widget_class->scroll_event = gtk_databox_scroll_event;
/** /**
* GtkDatabox:enable-selection: * GtkDatabox:enable-selection:
* *
* Defines whether the user can select * Defines whether the user can select
* rectangular areas with the mouse (#TRUE) or not (#FALSE). * rectangular areas with the mouse (#TRUE) or not (#FALSE).
skipping to change at line 404 skipping to change at line 417
NULL, /* accumulator_data */ NULL, /* accumulator_data */
gtk_databox_marshal_VOID__VOID, gtk_databox_marshal_VOID__VOID,
G_TYPE_NONE, G_TYPE_NONE,
0); 0);
class->zoomed = NULL; class->zoomed = NULL;
class->selection_started = NULL; class->selection_started = NULL;
class->selection_changed = NULL; class->selection_changed = NULL;
class->selection_finalized = NULL; class->selection_finalized = NULL;
class->selection_canceled = NULL; class->selection_canceled = NULL;
g_type_class_add_private (class, sizeof (GtkDataboxPrivate));
} }
static void static void
gtk_databox_init (GtkDatabox * box) { gtk_databox_init (GtkDatabox * box) {
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(box); GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
priv->backing_pixmap = NULL; priv->backing_surface = NULL;
priv->scale_type_x = GTK_DATABOX_SCALE_LINEAR; priv->scale_type_x = GTK_DATABOX_SCALE_LINEAR;
priv->scale_type_y = GTK_DATABOX_SCALE_LINEAR; priv->scale_type_y = GTK_DATABOX_SCALE_LINEAR;
priv->translation_factor_x = 0; priv->translation_factor_x = 0;
priv->translation_factor_y = 0; priv->translation_factor_y = 0;
priv->enable_selection = TRUE; priv->enable_selection = TRUE;
priv->enable_zoom = TRUE; priv->enable_zoom = TRUE;
priv->ruler_x = NULL; priv->ruler_x = NULL;
priv->ruler_y = NULL; priv->ruler_y = NULL;
priv->graphs = NULL; priv->graphs = NULL;
priv->select_gc = NULL;
priv->zoom_limit = 0.01; priv->zoom_limit = 0.01;
priv->selection_active = FALSE; priv->selection_active = FALSE;
priv->selection_finalized = FALSE; priv->selection_finalized = FALSE;
priv->box_shadow=GTK_SHADOW_NONE; priv->box_shadow=GTK_SHADOW_NONE;
priv->cssp = gtk_css_provider_new ();
/* gtk_databox_set_total_limits(box, -1., 1., 1., -1.); */
priv->visible_left = priv->total_left = -1.0;
priv->visible_right = priv->total_right = 1.0;
priv->visible_top = priv->total_top = 1.0;
priv->visible_bottom = priv->total_bottom = -1.0;
gtk_databox_set_adjustment_x (box, NULL); gtk_databox_set_adjustment_x (box, NULL);
gtk_databox_set_adjustment_y (box, NULL); gtk_databox_set_adjustment_y (box, NULL);
gtk_databox_set_total_limits(box, -1., 1., 1., -1.); /*gtk_databox_set_total_limits(box, -1., 1., 1., -1.);*/
g_object_set(GTK_WIDGET(box), "expand", TRUE, NULL);
} }
/** /**
* gtk_databox_new * gtk_databox_new
* *
* Creates a new #GtkDatabox widget. * Creates a new #GtkDatabox widget.
* *
* Return value: The new #GtkDatabox widget. * Return value: The new #GtkDatabox widget.
* *
*/ */
GtkWidget * GtkWidget *
gtk_databox_new (void) { gtk_databox_new (void) {
return g_object_new (GTK_TYPE_DATABOX, NULL); return g_object_new (GTK_TYPE_DATABOX, NULL);
} }
/**
* gtk_databox_get_graphs
* @box: A #GtkDatabox widget
*
* Return a list of graphs that were previously added to @box.
*
* Return value: A #GList that contains all graphs
*/
GList *
gtk_databox_get_graphs (GtkDatabox *box)
{
g_return_val_if_fail (GTK_IS_DATABOX (box), (GList*)-1);
GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
return priv->graphs;
}
static gint static gint
gtk_databox_motion_notify (GtkWidget * widget, GdkEventMotion * event) { gtk_databox_motion_notify (GtkWidget *widget, GdkEventMotion *event) {
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(widget); GtkDatabox *box = GTK_DATABOX (widget);
GtkDatabox *box; GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
GdkModifierType state; GdkModifierType state;
gint x; gint x;
gint y; gint y;
box = GTK_DATABOX (widget);
if (event->is_hint) { if (event->is_hint) {
gdk_window_get_pointer (gtk_widget_get_window (widget), &x, &y, &state); gdk_window_get_device_position (gtk_widget_get_window(widget), event->de vice, &x, &y, &state);
} else { } else {
state = event->state; state = event->state;
x = event->x; x = event->x;
y = event->y; y = event->y;
} }
if (state & GDK_BUTTON1_MASK if (state & GDK_BUTTON1_MASK
&& priv->enable_selection && !priv->selection_finalized) { && priv->enable_selection && !priv->selection_finalized) {
GdkRectangle rect; GdkRectangle rect;
gint width; gint width;
gint height; gint height;
width = gdk_window_get_width(gtk_widget_get_window (widget)); width = gdk_window_get_width(gtk_widget_get_window(widget));
height = gdk_window_get_height(gtk_widget_get_window (widget)); height = gdk_window_get_height(gtk_widget_get_window(widget));
x = MAX (0, MIN (width - 1, x)); x = MAX (0, MIN (width - 1, x));
y = MAX (0, MIN (height - 1, y)); y = MAX (0, MIN (height - 1, y));
if (priv->selection_active) { if (priv->selection_active) {
/* Clear current selection from backing_pixmap */ /* Clear current selection from backing_surface */
gtk_databox_draw_selection (box, NULL); gtk_databox_draw_selection (box, TRUE);
} else { } else {
priv->selection_active = TRUE; priv->selection_active = TRUE;
priv->marked.x = x; priv->marked.x = x;
priv->marked.y = y; priv->marked.y = y;
priv->select.x = x; priv->select.x = x;
priv->select.y = y; priv->select.y = y;
gtk_databox_calculate_selection_values (box); gtk_databox_calculate_selection_values (box);
g_signal_emit (G_OBJECT (box), g_signal_emit (G_OBJECT (box),
gtk_databox_signals[SELECTION_STARTED_SIGNAL], 0, gtk_databox_signals[SELECTION_STARTED_SIGNAL], 0,
&priv->selectionValues); &priv->selectionValues);
skipping to change at line 502 skipping to change at line 533
rect.y = MIN (MIN (priv->marked.y, priv->select.y), y); rect.y = MIN (MIN (priv->marked.y, priv->select.y), y);
rect.width = MAX (MAX (priv->marked.x, priv->select.x), x) rect.width = MAX (MAX (priv->marked.x, priv->select.x), x)
- rect.x + 1; - rect.x + 1;
rect.height = MAX (MAX (priv->marked.y, priv->select.y), y) rect.height = MAX (MAX (priv->marked.y, priv->select.y), y)
- rect.y + 1; - rect.y + 1;
priv->select.x = x; priv->select.x = x;
priv->select.y = y; priv->select.y = y;
/* Draw new selection */ /* Draw new selection */
gtk_databox_draw_selection (box, &rect); gtk_databox_draw_selection (box, FALSE);
gtk_databox_calculate_selection_values (box); gtk_databox_calculate_selection_values (box);
g_signal_emit (G_OBJECT (box), g_signal_emit (G_OBJECT (box),
gtk_databox_signals[SELECTION_CHANGED_SIGNAL], gtk_databox_signals[SELECTION_CHANGED_SIGNAL],
0, &priv->selectionValues); 0, &priv->selectionValues);
} }
return FALSE; return FALSE;
} }
skipping to change at line 558 skipping to change at line 589
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break; break;
} }
} }
static void static void
gtk_databox_get_property (GObject * object, gtk_databox_get_property (GObject * object,
guint property_id, guint property_id,
GValue * value, GParamSpec * pspec) { GValue * value, GParamSpec * pspec) {
GtkDatabox *box = GTK_DATABOX (object); GtkDatabox *box = GTK_DATABOX (object);
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(box); GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
switch (property_id) { switch (property_id) {
case ENABLE_SELECTION: case ENABLE_SELECTION:
g_value_set_boolean (value, gtk_databox_get_enable_selection (box)); g_value_set_boolean (value, gtk_databox_get_enable_selection (box));
break; break;
case ENABLE_ZOOM: case ENABLE_ZOOM:
g_value_set_boolean (value, gtk_databox_get_enable_zoom (box)); g_value_set_boolean (value, gtk_databox_get_enable_zoom (box));
break; break;
case ADJUSTMENT_X: case ADJUSTMENT_X:
g_value_set_object (value, G_OBJECT (gtk_databox_get_adjustment_x (box)) ); g_value_set_object (value, G_OBJECT (gtk_databox_get_adjustment_x (box)) );
skipping to change at line 599 skipping to change at line 630
/* We don't have any other property... */ /* We don't have any other property... */
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break; break;
} }
} }
static void static void
gtk_databox_realize (GtkWidget * widget) { gtk_databox_realize (GtkWidget * widget) {
GtkDatabox *box; GtkDatabox *box;
GdkWindowAttr attributes; GdkWindowAttr attributes;
GtkAllocation allocation;
GdkWindow *window;
gint attributes_mask; gint attributes_mask;
GtkAllocation allocation;
GtkStyleContext *stylecontext;
box = GTK_DATABOX (widget); box = GTK_DATABOX (widget);
gtk_widget_set_realized(widget, GTK_REALIZED); gtk_widget_set_realized(widget, TRUE);
gtk_widget_get_allocation(widget, &allocation); gtk_widget_get_allocation(widget, &allocation);
attributes.window_type = GDK_WINDOW_CHILD; attributes.window_type = GDK_WINDOW_CHILD;
attributes.x = allocation.x; attributes.x = allocation.x;
attributes.y = allocation.y; attributes.y = allocation.y;
attributes.width = allocation.width; attributes.width = allocation.width;
attributes.height = allocation.height; attributes.height = allocation.height;
attributes.wclass = GDK_INPUT_OUTPUT; attributes.wclass = GDK_INPUT_OUTPUT;
attributes.visual = gtk_widget_get_visual (widget); attributes.visual = gtk_widget_get_visual (widget);
attributes.colormap = gtk_widget_get_colormap (widget);
attributes.event_mask = gtk_widget_get_events (widget); attributes.event_mask = gtk_widget_get_events (widget);
attributes.event_mask |= (GDK_EXPOSURE_MASK | attributes.event_mask |= (GDK_EXPOSURE_MASK |
GDK_SCROLL_MASK |
GDK_TOUCH_MASK |
GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_MASK |
GDK_POINTER_MOTION_HINT_MASK); GDK_POINTER_MOTION_HINT_MASK);
attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, gtk_widget_set_window(widget,
attributes_mask); gdk_window_new (gtk_widget_get_parent_window (widget), &attributes,
gdk_window_set_user_data (window, box); attributes_mask));
gtk_widget_set_window (widget, window); gdk_window_set_user_data (gtk_widget_get_window(widget), box);
#ifdef GSEAL_ENABLE
gtk_widget_set_style (widget,
gtk_style_attach (gtk_widget_get_style (widget),
window));
#else
widget->style = gtk_style_attach (widget->style, widget->window);
#endif
gtk_style_set_background (gtk_widget_get_style (widget), stylecontext = gtk_widget_get_style_context(widget);
window, GTK_STATE_NORMAL); gtk_style_context_add_class(stylecontext, GTK_STYLE_CLASS_BACKGROUND);
gtk_databox_create_backing_pixmap (box); gtk_databox_create_backing_surface (box);
} }
static void static void
gtk_databox_unrealize (GtkWidget * widget) { gtk_databox_unrealize (GtkWidget * widget) {
GtkDatabox *box = GTK_DATABOX (widget); GtkDatabox *box = GTK_DATABOX (widget);
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(box); GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
gtk_widget_set_realized(widget, FALSE); gtk_widget_set_realized(widget, FALSE);
if (priv->backing_pixmap) if (priv->backing_surface)
g_object_unref (priv->backing_pixmap); cairo_surface_destroy (priv->backing_surface);
priv->backing_pixmap = NULL; priv->backing_surface=NULL;
if (priv->select_gc)
gtk_gc_release (priv->select_gc);
if (priv->adj_x) if (priv->adj_x)
g_object_unref (priv->adj_x); g_object_unref (priv->adj_x);
priv->adj_x=NULL;
if (priv->adj_y) if (priv->adj_y)
g_object_unref (priv->adj_y); g_object_unref (priv->adj_y);
g_list_free (priv->graphs); g_list_free (priv->graphs);
priv->graphs = NULL; priv->graphs=NULL;
if (GTK_WIDGET_CLASS (gtk_databox_parent_class)->unrealize) if (GTK_WIDGET_CLASS (gtk_databox_parent_class)->unrealize)
(*GTK_WIDGET_CLASS (gtk_databox_parent_class)->unrealize) (widget); (*GTK_WIDGET_CLASS (gtk_databox_parent_class)->unrealize) (widget);
} }
/** /**
* gtk_databox_set_enable_selection * gtk_databox_set_enable_selection
* @box: A #GtkDatabox widget * @box: A #GtkDatabox widget
* @enable: Whether selection via mouse is enabled or not. * @enable: Whether selection via mouse is enabled or not.
* *
* Setter function for the #GtkDatabox:enable-selection property. * Setter function for the #GtkDatabox:enable-selection property.
* *
*/ */
void void
gtk_databox_set_enable_selection (GtkDatabox * box, gboolean enable) { gtk_databox_set_enable_selection (GtkDatabox * box, gboolean enable) {
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(box); GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
g_return_if_fail (GTK_IS_DATABOX (box)); g_return_if_fail (GTK_IS_DATABOX (box));
priv->enable_selection = enable; priv->enable_selection = enable;
if (priv->selection_active) { if (priv->selection_active) {
gtk_databox_selection_cancel (box); gtk_databox_selection_cancel (box);
} }
g_object_notify (G_OBJECT (box), "enable-selection"); g_object_notify (G_OBJECT (box), "enable-selection");
} }
/** /**
* gtk_databox_set_enable_zoom * gtk_databox_set_enable_zoom
* @box: A #GtkDatabox widget * @box: A #GtkDatabox widget
* @enable: Whether zoom via mouse is enabled or not. * @enable: Whether zoom via mouse is enabled or not.
* *
* Setter function for the #GtkDatabox:enable-zoom property. * Setter function for the #GtkDatabox:enable-zoom property.
* *
*/ */
void void
gtk_databox_set_enable_zoom (GtkDatabox * box, gboolean enable) { gtk_databox_set_enable_zoom (GtkDatabox * box, gboolean enable) {
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(box); GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
g_return_if_fail (GTK_IS_DATABOX (box)); g_return_if_fail (GTK_IS_DATABOX (box));
priv->enable_zoom = enable; priv->enable_zoom = enable;
g_object_notify (G_OBJECT (box), "enable-zoom"); g_object_notify (G_OBJECT (box), "enable-zoom");
} }
/** /**
* gtk_databox_set_adjustment_x * gtk_databox_set_adjustment_x
* @box: A #GtkDatabox widget * @box: A #GtkDatabox widget
* @adj: A #GtkAdjustment object * @adj: A #GtkAdjustment object
* *
* Setter function for the #GtkDatabox:adjustment-x property. Normally, it shoul d not be * Setter function for the #GtkDatabox:adjustment-x property. Normally, it shoul d not be
* required to use this function, see property documentation. * required to use this function, see property documentation.
* *
*/ */
void void
gtk_databox_set_adjustment_x (GtkDatabox * box, GtkAdjustment * adj) { gtk_databox_set_adjustment_x (GtkDatabox * box, GtkAdjustment * adj) {
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(box); gdouble page_size_x;
gdouble page_size; GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
g_return_if_fail (GTK_IS_DATABOX (box));
if (!adj) if (!adj)
adj = GTK_ADJUSTMENT(gtk_adjustment_new (0, 0, 0, 0, 0, 0)); adj = GTK_ADJUSTMENT(gtk_adjustment_new (0, 0, 0, 0, 0, 0));
g_return_if_fail (GTK_IS_DATABOX (box));
g_return_if_fail (GTK_IS_ADJUSTMENT (adj)); g_return_if_fail (GTK_IS_ADJUSTMENT (adj));
if (priv->adj_x) { if (priv->adj_x) {
/* @@@ Do we need to disconnect from the signals here? */ /* @@@ Do we need to disconnect from the signals here? */
g_object_unref (priv->adj_x); g_object_unref (priv->adj_x);
if (g_object_is_floating(G_OBJECT(priv->adj_x))) if (g_object_is_floating(G_OBJECT(priv->adj_x)))
g_object_ref_sink (priv->adj_x); g_object_ref_sink (priv->adj_x);
} }
priv->adj_x = adj; priv->adj_x = adj;
g_object_ref (priv->adj_x); g_object_ref (priv->adj_x);
/* We always scroll from 0 to 1.0 */ /* We always scroll from 0 to 1.0 */
page_size = gtk_databox_get_page_size_x (box); if (priv->total_left != priv->total_right)
gtk_adjustment_configure(priv->adj_x, {
gtk_databox_get_offset_x (box), page_size_x = gtk_databox_get_page_size_x(box);
0.0, } else {
1.0, page_size_x = 1.0;
page_size / 20, }
page_size * 0.9,
page_size); gtk_adjustment_configure(priv->adj_x,
gtk_databox_get_offset_x (box), /* value */
0.0, /* lower */
1.0, /* upper */
page_size_x / 20, /* step_increment */
page_size_x * 0.9, /* page_increment */
page_size_x); /* page_size */
g_signal_connect_swapped (G_OBJECT (priv->adj_x), "value_changed", g_signal_connect_swapped (G_OBJECT (priv->adj_x), "value_changed",
G_CALLBACK G_CALLBACK
(gtk_databox_adjustment_value_changed), box); (gtk_databox_adjustment_value_changed), box);
g_object_notify (G_OBJECT (box), "adjustment-x"); g_object_notify (G_OBJECT (box), "adjustment-x");
} }
/** /**
* gtk_databox_set_adjustment_y * gtk_databox_set_adjustment_y
* @box: A #GtkDatabox widget * @box: A #GtkDatabox widget
* @adj: A #GtkAdjustment object * @adj: A #GtkAdjustment object
* *
* Setter function for the #GtkDatabox:adjustment-y property. Normally, it shoul d not be * Setter function for the #GtkDatabox:adjustment-y property. Normally, it shoul d not be
* required to use this function, see property documentation. * required to use this function, see property documentation.
* *
*/ */
void void
gtk_databox_set_adjustment_y (GtkDatabox * box, GtkAdjustment * adj) { gtk_databox_set_adjustment_y (GtkDatabox * box, GtkAdjustment * adj) {
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(box); GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
gdouble page_size; gdouble page_size_y;
g_return_if_fail (GTK_IS_DATABOX (box));
if (!adj) if (!adj)
adj = GTK_ADJUSTMENT(gtk_adjustment_new (0, 0, 0, 0, 0, 0)); adj = GTK_ADJUSTMENT(gtk_adjustment_new (0, 0, 0, 0, 0, 0));
g_return_if_fail (GTK_IS_DATABOX (box));
g_return_if_fail (GTK_IS_ADJUSTMENT (adj)); g_return_if_fail (GTK_IS_ADJUSTMENT (adj));
if (priv->adj_y) { if (priv->adj_y) {
/* @@@ Do we need to disconnect from the signals here? */ /* @@@ Do we need to disconnect from the signals here? */
g_object_unref (priv->adj_y); g_object_unref (priv->adj_y);
if (g_object_is_floating(G_OBJECT(priv->adj_y))) if (g_object_is_floating(G_OBJECT(priv->adj_y)))
g_object_ref_sink (priv->adj_y); g_object_ref_sink (priv->adj_y);
} }
priv->adj_y = adj; priv->adj_y = adj;
g_object_ref (priv->adj_y); g_object_ref (priv->adj_y);
/* We always scroll from 0 to 1.0 */ /* We always scroll from 0 to 1.0 */
page_size = gtk_databox_get_page_size_y (box); if (priv->total_top != priv->total_bottom)
gtk_adjustment_configure(priv->adj_y, {
gtk_databox_get_offset_y (box), page_size_y = gtk_databox_get_page_size_y(box);
0.0, } else {
1.0, page_size_y = 1.0;
page_size / 20, }
page_size * 0.9,
page_size); gtk_adjustment_configure(priv->adj_y,
gtk_databox_get_offset_y (box), /* value */
0.0, /* lower */
1.0, /* upper */
page_size_y / 20, /* step_increment */
page_size_y * 0.9, /* page_increment */
page_size_y); /* page_size */
g_signal_connect_swapped (G_OBJECT (priv->adj_y), "value_changed", g_signal_connect_swapped (G_OBJECT (priv->adj_y), "value_changed",
G_CALLBACK G_CALLBACK
(gtk_databox_adjustment_value_changed), box); (gtk_databox_adjustment_value_changed), box);
g_object_notify (G_OBJECT (box), "adjustment-y"); g_object_notify (G_OBJECT (box), "adjustment-y");
} }
/** /**
* gtk_databox_set_ruler_x * gtk_databox_set_ruler_x
* @box: A #GtkDatabox widget * @box: A #GtkDatabox widget
* @ruler: A #GtkDataboxRuler object * @ruler: A #GtkDataboxRuler object
* *
* Setter function for the #GtkDatabox:ruler-x property. * Setter function for the #GtkDatabox:ruler-x property.
* *
*/ */
void void
gtk_databox_set_ruler_x (GtkDatabox * box, GtkDataboxRuler * ruler) { gtk_databox_set_ruler_x (GtkDatabox * box, GtkDataboxRuler * ruler) {
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(box); GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
g_return_if_fail (GTK_IS_DATABOX (box)); g_return_if_fail (GTK_IS_DATABOX (box));
g_return_if_fail (ruler == NULL || GTK_DATABOX_IS_RULER (ruler)); g_return_if_fail (ruler == NULL || GTK_DATABOX_IS_RULER (ruler));
g_return_if_fail (ruler == NULL || gtk_databox_ruler_get_orientation(ruler) == GTK_ORIENTATION_HORIZONTAL); g_return_if_fail (ruler == NULL || gtk_databox_ruler_get_orientation(ruler) == GTK_ORIENTATION_HORIZONTAL);
if (priv->ruler_x) { if (priv->ruler_x) {
/* @@@ Do we need to disconnect the signals here? */ /* @@@ Do we need to disconnect the signals here? */
/* @@@ Do we need to call object_ref and object_unref here and for adjus tments? */ /* @@@ Do we need to call object_ref and object_unref here and for adjus tments? */
} }
skipping to change at line 846 skipping to change at line 882
/** /**
* gtk_databox_set_ruler_y * gtk_databox_set_ruler_y
* @box: A #GtkDatabox widget * @box: A #GtkDatabox widget
* @ruler: An #GtkDataboxRuler object * @ruler: An #GtkDataboxRuler object
* *
* Setter function for the #GtkDatabox:ruler-y property. * Setter function for the #GtkDatabox:ruler-y property.
* *
*/ */
void void
gtk_databox_set_ruler_y (GtkDatabox * box, GtkDataboxRuler * ruler) { gtk_databox_set_ruler_y (GtkDatabox * box, GtkDataboxRuler * ruler) {
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(box); GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
g_return_if_fail (GTK_IS_DATABOX (box)); g_return_if_fail (GTK_IS_DATABOX (box));
g_return_if_fail (ruler == NULL || GTK_DATABOX_IS_RULER (ruler)); g_return_if_fail (ruler == NULL || GTK_DATABOX_IS_RULER (ruler));
g_return_if_fail (ruler == NULL || gtk_databox_ruler_get_orientation(ruler) == GTK_ORIENTATION_VERTICAL); g_return_if_fail (ruler == NULL || gtk_databox_ruler_get_orientation(ruler) == GTK_ORIENTATION_VERTICAL);
if (priv->ruler_y) { if (priv->ruler_y) {
/* @@@ Do we need to disconnect the signals here? */ /* @@@ Do we need to disconnect the signals here? */
/* @@@ Do we need to call object_ref and object_unref here and for adjus tments? */ /* @@@ Do we need to call object_ref and object_unref here and for adjus tments? */
} }
skipping to change at line 885 skipping to change at line 921
* gtk_databox_set_scale_type_x * gtk_databox_set_scale_type_x
* @box: A #GtkDatabox widget * @box: A #GtkDatabox widget
* @scale_type: An #GtkDataboxScaleType (linear or logarithmic) * @scale_type: An #GtkDataboxScaleType (linear or logarithmic)
* *
* Setter function for the #GtkDatabox:scale-type-x property. * Setter function for the #GtkDatabox:scale-type-x property.
* *
*/ */
void void
gtk_databox_set_scale_type_x (GtkDatabox * box, gtk_databox_set_scale_type_x (GtkDatabox * box,
GtkDataboxScaleType scale_type) { GtkDataboxScaleType scale_type) {
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(box); GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
priv->scale_type_x = scale_type; priv->scale_type_x = scale_type;
if (priv->ruler_x) if (priv->ruler_x)
gtk_databox_ruler_set_scale_type (priv->ruler_x, scale_type); gtk_databox_ruler_set_scale_type (priv->ruler_x, scale_type);
g_object_notify (G_OBJECT (box), "scale-type-x"); g_object_notify (G_OBJECT (box), "scale-type-x");
} }
/** /**
* gtk_databox_set_scale_type_y * gtk_databox_set_scale_type_y
* @box: A #GtkDatabox widget * @box: A #GtkDatabox widget
* @scale_type: An #GtkDataboxScaleType (linear or logarithmic) * @scale_type: An #GtkDataboxScaleType (linear or logarithmic)
* *
* Setter function for the #GtkDatabox:scale-type-y property. * Setter function for the #GtkDatabox:scale-type-y property.
* *
*/ */
void void
gtk_databox_set_scale_type_y (GtkDatabox * box, gtk_databox_set_scale_type_y (GtkDatabox * box,
GtkDataboxScaleType scale_type) { GtkDataboxScaleType scale_type) {
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(box); GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
priv->scale_type_y = scale_type; priv->scale_type_y = scale_type;
if (priv->ruler_y) if (priv->ruler_y)
gtk_databox_ruler_set_scale_type (priv->ruler_y, scale_type); gtk_databox_ruler_set_scale_type (priv->ruler_y, scale_type);
g_object_notify (G_OBJECT (box), "scale-type-y"); g_object_notify (G_OBJECT (box), "scale-type-y");
} }
/** /**
* gtk_databox_set_box_shadow: * gtk_databox_set_box_shadow:
* @box: a #GtkDatabox widget. * @box: a #GtkDatabox widget.
* @which_shadow: How to render the box shadow on the GtkDatabox edges. * @which_shadow: How to render the box shadow on the GtkDatabox edges.
* *
* Sets the shadow type when using gtk_paint_box. This will draw the desired edg e shadow. * Sets the shadow type when using gtk_paint_box. This will draw the desired edg e shadow.
**/ **/
void void
gtk_databox_set_box_shadow(GtkDatabox * box, GtkShadowType which_shadow) { gtk_databox_set_box_shadow(GtkDatabox * box, GtkShadowType which_shadow) {
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(box); GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
g_return_if_fail (GTK_IS_DATABOX (box)); g_return_if_fail (GTK_IS_DATABOX (box));
g_return_if_fail (which_shadow>=0);
g_return_if_fail (which_shadow<=GTK_SHADOW_ETCHED_OUT); g_return_if_fail (which_shadow<=GTK_SHADOW_ETCHED_OUT);
if (priv->box_shadow!=which_shadow) { if (priv->box_shadow!=which_shadow) {
priv->box_shadow=which_shadow; priv->box_shadow=which_shadow;
if (gtk_widget_is_drawable (GTK_WIDGET (box))) if (gtk_widget_is_drawable (GTK_WIDGET (box)))
gtk_widget_queue_draw (GTK_WIDGET (box)); gtk_widget_queue_draw (GTK_WIDGET (box));
} }
} }
/** /**
skipping to change at line 948 skipping to change at line 983
* @box: A #GtkDatabox widget. * @box: A #GtkDatabox widget.
* *
* Getter function for the #GtkDatabox:enable-selection property. * Getter function for the #GtkDatabox:enable-selection property.
* *
* Return value: The #GtkDatabox:enable-selection property value. * Return value: The #GtkDatabox:enable-selection property value.
* *
*/ */
gboolean gboolean
gtk_databox_get_enable_selection (GtkDatabox * box) { gtk_databox_get_enable_selection (GtkDatabox * box) {
g_return_val_if_fail (GTK_IS_DATABOX (box), FALSE); g_return_val_if_fail (GTK_IS_DATABOX (box), FALSE);
GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
return GTK_DATABOX_GET_PRIVATE(box)->enable_selection; return priv->enable_selection;
} }
/** /**
* gtk_databox_get_enable_zoom * gtk_databox_get_enable_zoom
* @box: A #GtkDatabox widget. * @box: A #GtkDatabox widget.
* *
* Getter function for the #GtkDatabox:enable-zoom property. * Getter function for the #GtkDatabox:enable-zoom property.
* *
* Return value: The #GtkDatabox:enable-zoom property value. * Return value: The #GtkDatabox:enable-zoom property value.
* *
*/ */
gboolean gboolean
gtk_databox_get_enable_zoom (GtkDatabox * box) { gtk_databox_get_enable_zoom (GtkDatabox * box) {
g_return_val_if_fail (GTK_IS_DATABOX (box), FALSE); g_return_val_if_fail (GTK_IS_DATABOX (box), FALSE);
GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
return GTK_DATABOX_GET_PRIVATE(box)->enable_zoom; return priv->enable_zoom;
} }
/** /**
* gtk_databox_get_adjustment_x * gtk_databox_get_adjustment_x
* @box: A #GtkDatabox widget. * @box: A #GtkDatabox widget.
* *
* Getter function for the #GtkDatabox:adjustment-x property. * Getter function for the #GtkDatabox:adjustment-x property.
* *
* Return value: The #GtkDatabox:adjustment-x property value. * Return value: The #GtkDatabox:adjustment-x property value.
* *
*/ */
GtkAdjustment * GtkAdjustment *
gtk_databox_get_adjustment_x (GtkDatabox * box) { gtk_databox_get_adjustment_x (GtkDatabox * box) {
g_return_val_if_fail (GTK_IS_DATABOX (box), NULL); g_return_val_if_fail (GTK_IS_DATABOX (box), NULL);
GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
return GTK_DATABOX_GET_PRIVATE(box)->adj_x; return priv->adj_x;
} }
/** /**
* gtk_databox_get_adjustment_y * gtk_databox_get_adjustment_y
* @box: A #GtkDatabox widget. * @box: A #GtkDatabox widget.
* *
* Getter function for the #GtkDatabox:adjustment-y property. * Getter function for the #GtkDatabox:adjustment-y property.
* *
* Return value: The #GtkDatabox:adjustment-y property value. * Return value: The #GtkDatabox:adjustment-y property value.
* *
*/ */
GtkAdjustment * GtkAdjustment *
gtk_databox_get_adjustment_y (GtkDatabox * box) { gtk_databox_get_adjustment_y (GtkDatabox * box) {
g_return_val_if_fail (GTK_IS_DATABOX (box), NULL); g_return_val_if_fail (GTK_IS_DATABOX (box), NULL);
GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
return GTK_DATABOX_GET_PRIVATE(box)->adj_y; return priv->adj_y;
} }
/** /**
* gtk_databox_get_ruler_x * gtk_databox_get_ruler_x
* @box: A #GtkDatabox widget. * @box: A #GtkDatabox widget.
* *
* Getter function for the #GtkDatabox:ruler-x property. * Getter function for the #GtkDatabox:ruler-x property.
* *
* Return value: The #GtkDatabox:ruler-x property value. * Return value: The #GtkDatabox:ruler-x property value.
* *
*/ */
GtkDataboxRuler * GtkDataboxRuler *
gtk_databox_get_ruler_x (GtkDatabox * box) { gtk_databox_get_ruler_x (GtkDatabox * box) {
g_return_val_if_fail (GTK_IS_DATABOX (box), NULL); g_return_val_if_fail (GTK_IS_DATABOX (box), NULL);
GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
return GTK_DATABOX_GET_PRIVATE(box)->ruler_x; return priv->ruler_x;
} }
/** /**
* gtk_databox_get_ruler_y * gtk_databox_get_ruler_y
* @box: A #GtkDatabox widget. * @box: A #GtkDatabox widget.
* *
* Getter function for the #GtkDatabox:ruler-y property. * Getter function for the #GtkDatabox:ruler-y property.
* *
* Return value: The #GtkDatabox:ruler-y property value. * Return value: The #GtkDatabox:ruler-y property value.
* *
*/ */
GtkDataboxRuler * GtkDataboxRuler *
gtk_databox_get_ruler_y (GtkDatabox * box) { gtk_databox_get_ruler_y (GtkDatabox * box) {
g_return_val_if_fail (GTK_IS_DATABOX (box), NULL); g_return_val_if_fail (GTK_IS_DATABOX (box), NULL);
GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
return GTK_DATABOX_GET_PRIVATE(box)->ruler_y; return priv->ruler_y;
} }
/** /**
* gtk_databox_get_scale_type_x * gtk_databox_get_scale_type_x
* @box: A #GtkDatabox widget. * @box: A #GtkDatabox widget.
* *
* Getter function for the #GtkDatabox:scale-type-x property. * Getter function for the #GtkDatabox:scale-type-x property.
* *
* Return value: The #GtkDatabox:scale-type-x property value. * Return value: The #GtkDatabox:scale-type-x property value.
* *
*/ */
GtkDataboxScaleType GtkDataboxScaleType
gtk_databox_get_scale_type_x (GtkDatabox * box) { gtk_databox_get_scale_type_x (GtkDatabox * box) {
return GTK_DATABOX_GET_PRIVATE(box)->scale_type_x; GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
return priv->scale_type_x;
} }
/** /**
* gtk_databox_get_scale_type_y * gtk_databox_get_scale_type_y
* @box: A #GtkDatabox widget. * @box: A #GtkDatabox widget.
* *
* Getter function for the #GtkDatabox:scale-type-y property. * Getter function for the #GtkDatabox:scale-type-y property.
* *
* Return value: The #GtkDatabox:scale-type-y property value. * Return value: The #GtkDatabox:scale-type-y property value.
* *
*/ */
GtkDataboxScaleType GtkDataboxScaleType
gtk_databox_get_scale_type_y (GtkDatabox * box) { gtk_databox_get_scale_type_y (GtkDatabox * box) {
return GTK_DATABOX_GET_PRIVATE(box)->scale_type_y; GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
return priv->scale_type_y;
} }
/** /**
* gtk_databox_get_box_shadow: * gtk_databox_get_box_shadow:
* @box: a #GtkDatabox widget * @box: a #GtkDatabox widget
* *
* Gets the type of shadow being rendered to the @box (GTK_SHADOW_NONE, GTK_SHAD OW_IN, GTK_SHADOW_OUT, GTK_SHADOW_ETCHED_IN, GTK_SHADOW_ETCHED_OUT). * Gets the type of shadow being rendered to the @box (GTK_SHADOW_NONE, GTK_SHAD OW_IN, GTK_SHADOW_OUT, GTK_SHADOW_ETCHED_IN, GTK_SHADOW_ETCHED_OUT).
* *
* Return value: The currently used shadow type of the @box, -1 on failure. * Return value: The currently used shadow type of the @box, -1 on failure.
**/ **/
GtkShadowType GtkShadowType
gtk_databox_get_box_shadow(GtkDatabox * box) { gtk_databox_get_box_shadow(GtkDatabox * box) {
g_return_val_if_fail (GTK_IS_DATABOX (box), -1); g_return_val_if_fail (GTK_IS_DATABOX (box), -1);
GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
return priv->box_shadow;
}
/**
* gtk_databox_set_bg_color:
* @box: a #GtkDatabox widget
* @bg_color: a color name, as used in CSS (html color)
*
* Convenience function to override the background color of @box, acording to @b
g_color.
*
**/
void
gtk_databox_set_bg_color (GtkDatabox * box, gchar *bg_color) {
GtkWidget * widget;
GtkDataboxPrivate *priv;
GtkStyleContext *stylecontext;
gchar *css_bg_color;
g_return_if_fail (GTK_IS_DATABOX (box));
widget = GTK_WIDGET (box);
priv = gtk_databox_get_instance_private (box);
return GTK_DATABOX_GET_PRIVATE(box)->box_shadow; stylecontext = gtk_widget_get_style_context (widget);
gtk_style_context_remove_provider (stylecontext, GTK_STYLE_PROVIDER (priv->c
ssp));
css_bg_color = g_strdup_printf (".%s {background-color: %s;}", GTK_STYLE_CLA
SS_BACKGROUND, bg_color);
gtk_css_provider_load_from_data (priv->cssp, css_bg_color, -1, NULL);
gtk_style_context_add_provider (stylecontext, GTK_STYLE_PROVIDER (priv->cssp
), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
g_free (css_bg_color);
} }
static void static void
gtk_databox_calculate_translation_factors (GtkDatabox * box) { gtk_databox_calculate_translation_factors (GtkDatabox * box) {
/* @@@ Check for all external functions, if type checks are implemented! */ /* @@@ Check for all external functions, if type checks are implemented! */
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(box); GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
GtkWidget *widget = GTK_WIDGET(box); GtkWidget *widget = GTK_WIDGET(box);
GtkAllocation allocation; GtkAllocation allocation;
gtk_widget_get_allocation(widget, &allocation);
gtk_widget_get_allocation(widget, &allocation);
if (priv->scale_type_x == GTK_DATABOX_SCALE_LINEAR) if (priv->scale_type_x == GTK_DATABOX_SCALE_LINEAR)
priv->translation_factor_x = priv->translation_factor_x =
allocation.width / (priv->visible_right - (gfloat)allocation.width / (priv->visible_right -
priv->visible_left); priv->visible_left);
else if (priv->scale_type_x == GTK_DATABOX_SCALE_LOG2) else if (priv->scale_type_x == GTK_DATABOX_SCALE_LOG2)
priv->translation_factor_x = priv->translation_factor_x =
allocation.width / log2 (priv->visible_right / (gfloat)allocation.width / log2 (priv->visible_right /
priv->visible_left); priv->visible_left);
else else
priv->translation_factor_x = priv->translation_factor_x =
allocation.width / log10 (priv->visible_right / (gfloat)allocation.width / log10 (priv->visible_right /
priv->visible_left); priv->visible_left);
if (priv->scale_type_y == GTK_DATABOX_SCALE_LINEAR) if (priv->scale_type_y == GTK_DATABOX_SCALE_LINEAR)
priv->translation_factor_y = priv->translation_factor_y =
allocation.height / (priv->visible_bottom - (gfloat)allocation.height / (priv->visible_bottom -
priv->visible_top); priv->visible_top);
else if (priv->scale_type_y == GTK_DATABOX_SCALE_LOG2) else if (priv->scale_type_y == GTK_DATABOX_SCALE_LOG2)
priv->translation_factor_y = priv->translation_factor_y =
allocation.height / log2 (priv->visible_bottom / (gfloat)allocation.height / log2 (priv->visible_bottom /
priv->visible_top); priv->visible_top);
else else
priv->translation_factor_y = priv->translation_factor_y =
allocation.height / log10 (priv->visible_bottom / (gfloat)allocation.height / log10 (priv->visible_bottom /
priv->visible_top); priv->visible_top);
} }
static void static void
gtk_databox_create_backing_pixmap(GtkDatabox * box) { gtk_databox_create_backing_surface(GtkDatabox * box) {
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(box); GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
GtkAllocation allocation; GtkAllocation allocation;
GtkWidget *widget; GtkWidget *widget;
GdkDrawingContext *drawc;
cairo_region_t *crr;
cairo_t *cr;
gint width; gint width;
gint height; gint height;
widget = GTK_WIDGET (box); widget = GTK_WIDGET (box);
if (priv->backing_pixmap) { gtk_widget_get_allocation(widget, &allocation);
gdk_drawable_get_size (priv->backing_pixmap, &width, &height);
if ((width == allocation.width) &&
(height == allocation.height))
return;
g_object_unref (priv->backing_pixmap);
}
gtk_widget_get_allocation (widget, &allocation);
width = allocation.width; width = allocation.width;
height = allocation.height; height = allocation.height;
priv->backing_pixmap = gdk_pixmap_new (gtk_widget_get_window (widget), if (priv->backing_surface) {
width, height, -1); if ((width == priv->old_width) &&
(height == priv->old_height))
return;
cairo_surface_destroy (priv->backing_surface);
}
priv->old_width = width;
priv->old_height = height;
crr = gdk_window_get_visible_region (gtk_widget_get_window (widget));
drawc = gdk_window_begin_draw_frame (gtk_widget_get_window (widget), crr);
cr = gdk_drawing_context_get_cairo_context (drawc);
priv->backing_surface = cairo_surface_create_similar(
cairo_get_target (cr),
CAIRO_CONTENT_COLOR,
width, height);
gdk_window_end_draw_frame (gtk_widget_get_window (widget), drawc);
cairo_region_destroy (crr);
} }
/** /**
* gtk_databox_get_backing_pixmap: * gtk_databox_get_backing_surface:
* @box: A #GtkDatabox widget * @box: A #GtkDatabox widget
* *
* This function returns the pixmap which is used by @box and its #GtkDataboxGra ph objects * This function returns the surface which is used by @box and its #GtkDataboxGr aph objects
* for drawing operations before copying the result to the screen. * for drawing operations before copying the result to the screen.
* *
* The function is typically called by the #GtkDataboxGraph objects. * The function is typically called by the #GtkDataboxGraph objects.
* *
* Return value: Backing pixmap * Return value: Backing surface
*/ */
GdkPixmap * cairo_surface_t *
gtk_databox_get_backing_pixmap(GtkDatabox * box) { gtk_databox_get_backing_surface(GtkDatabox * box) {
g_return_val_if_fail (GTK_IS_DATABOX (box), NULL); g_return_val_if_fail (GTK_IS_DATABOX (box), NULL);
GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
return GTK_DATABOX_GET_PRIVATE(box)->backing_pixmap; return priv->backing_surface;
} }
static void static void
gtk_databox_size_allocate (GtkWidget * widget, GtkAllocation * allocation) { gtk_databox_size_allocate (GtkWidget * widget, GtkAllocation * allocation) {
GtkDatabox *box = GTK_DATABOX (widget); GtkDatabox *box = GTK_DATABOX (widget);
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(box); GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
gtk_widget_set_allocation (widget, allocation); gtk_widget_set_allocation(widget, allocation);
gtk_databox_calculate_translation_factors (box); if (gtk_widget_get_window(widget)) /* don't move_resize an unrealize
d window */
if (!gtk_widget_get_realized(widget)) {
return; gdk_window_move_resize (gtk_widget_get_window(widget),
allocation->x, allocation->y,
gdk_window_move_resize (gtk_widget_get_window (widget), allocation->width, allocation->height);
allocation->x, allocation->y, }
allocation->width, allocation->height);
gtk_databox_create_backing_pixmap (box);
if (priv->selection_active) { if (priv->selection_active) {
gtk_databox_selection_cancel (box); gtk_databox_selection_cancel (box);
} }
gtk_databox_calculate_translation_factors (box);
} }
static gint static gint
gtk_databox_expose (GtkWidget * widget, GdkEventExpose * event) { gtk_databox_draw (GtkWidget * widget, cairo_t * cr) {
GtkDatabox *box = GTK_DATABOX (widget); GtkDatabox *box = GTK_DATABOX (widget);
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(box); GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
GList *list; GList *list;
gint width, height; cairo_t *cr2;
GtkStyleContext *stylecontext = gtk_widget_get_style_context(widget);
GtkAllocation allocation; GtkAllocation allocation;
gtk_databox_create_backing_surface (box);
cr2 = cairo_create(priv->backing_surface);
gtk_widget_get_allocation (widget, &allocation); gtk_widget_get_allocation (widget, &allocation);
gtk_render_background (stylecontext, cr2, 0.0, 0.0, allocation.width, alloca
tion.height);
cairo_destroy(cr2);
gdk_draw_rectangle (priv->backing_pixmap, list = g_list_last (priv->graphs);
gtk_widget_get_style (widget)->bg_gc[0], while (list) {
TRUE, 0, 0, if (list->data)
allocation.width, gtk_databox_graph_draw (GTK_DATABOX_GRAPH (list->data), box);
allocation.height); list = g_list_previous (list);
}
width = allocation.width;
height = allocation.height;
gtk_paint_box (gtk_widget_get_style(widget), priv->backing_pixmap,
GTK_STATE_NORMAL, priv->box_shadow,
NULL, widget, "box", 0, 0, width, height);
list = g_list_last (priv->graphs);
while (list) {
if (list->data) {
gtk_databox_graph_draw (GTK_DATABOX_GRAPH (list->data), box);
} else {
/* Do nothing if data == NULL */
}
list = g_list_previous (list);
}
if (priv->selection_active) { if (priv->selection_active)
gtk_databox_draw_selection (box, NULL); gtk_databox_draw_selection (box, TRUE);
}
cairo_set_source_surface (cr, priv->backing_surface, 0, 0);
cairo_paint(cr);
/* the following was removed - unsure if it creates problems
gtk_databox_draw_selection (box, FALSE);
*/
gdk_draw_drawable (gtk_widget_get_window (widget),
gtk_widget_get_style(widget)->fg_gc[gtk_widget_get_st
ate (widget)],
priv->backing_pixmap,
event->area.x, event->area.y,
event->area.x, event->area.y,
event->area.width,
event->area.height);
return FALSE; return FALSE;
} }
static void static void
gtk_databox_calculate_selection_values (GtkDatabox * box) { gtk_databox_calculate_selection_values (GtkDatabox * box) {
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(box); GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
priv->selectionValues.x1 = priv->selectionValues.x1 =
gtk_databox_pixel_to_value_x (box, priv->marked.x); gtk_databox_pixel_to_value_x (box, priv->marked.x);
priv->selectionValues.x2 = priv->selectionValues.x2 =
gtk_databox_pixel_to_value_x (box, priv->select.x); gtk_databox_pixel_to_value_x (box, priv->select.x);
priv->selectionValues.y1 = priv->selectionValues.y1 =
gtk_databox_pixel_to_value_y (box, priv->marked.y); gtk_databox_pixel_to_value_y (box, priv->marked.y);
priv->selectionValues.y2 = priv->selectionValues.y2 =
gtk_databox_pixel_to_value_y (box, priv->select.y); gtk_databox_pixel_to_value_y (box, priv->select.y);
} }
static gint static gint
gtk_databox_button_press (GtkWidget * widget, GdkEventButton * event) { gtk_databox_button_press (GtkWidget * widget, GdkEventButton * event) {
GtkDatabox *box = GTK_DATABOX (widget); GtkDatabox *box = GTK_DATABOX (widget);
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(widget); GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
if (event->type != GDK_BUTTON_PRESS && event->type != GDK_2BUTTON_PRESS) if (event->type != GDK_BUTTON_PRESS && event->type != GDK_2BUTTON_PRESS)
return FALSE; return FALSE;
priv->selection_finalized = FALSE; priv->selection_finalized = FALSE;
if ((event->button == 1 || event->button == 2) & !(event->type==GDK_2BUTTON_ PRESS)) { if ((event->button == 1 || event->button == 2) & !(event->type==GDK_2BUTTON_ PRESS)) {
if (priv->selection_active) { if (priv->selection_active) {
if (event->x > MIN (priv->marked.x, priv->select.x) if (event->x > MIN (priv->marked.x, priv->select.x)
&& event->x < MAX (priv->marked.x, priv->select.x) && event->x < MAX (priv->marked.x, priv->select.x)
&& event->y > MIN (priv->marked.y, priv->select.y) && event->y > MIN (priv->marked.y, priv->select.y)
skipping to change at line 1276 skipping to change at line 1338
gtk_databox_zoom_out (box); gtk_databox_zoom_out (box);
} }
} }
return FALSE; return FALSE;
} }
static gint static gint
gtk_databox_button_release (GtkWidget * widget, GdkEventButton * event) { gtk_databox_button_release (GtkWidget * widget, GdkEventButton * event) {
GtkDatabox *box = GTK_DATABOX (widget); GtkDatabox *box = GTK_DATABOX (widget);
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(widget); GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
if (event->type != GDK_BUTTON_RELEASE) if (event->type != GDK_BUTTON_RELEASE)
return FALSE; return FALSE;
if (priv->selection_active) { if (priv->selection_active) {
priv->selection_finalized = TRUE; priv->selection_finalized = TRUE;
g_signal_emit (G_OBJECT (box), g_signal_emit (G_OBJECT (box),
gtk_databox_signals[SELECTION_FINALIZED_SIGNAL], gtk_databox_signals[SELECTION_FINALIZED_SIGNAL],
0, &priv->selectionValues); 0, &priv->selectionValues);
} }
return FALSE; return FALSE;
} }
static gint static gint
gtk_databox_scroll_event (GtkWidget *widget, GdkEventScroll *event) { gtk_databox_scroll_event (GtkWidget *widget, GdkEventScroll *event) {
GtkDatabox *box = GTK_DATABOX (widget); GtkDatabox *box = GTK_DATABOX (widget);
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(widget); GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
if (event->state & GDK_CONTROL_MASK && priv->enable_zoom) { if (event->state & GDK_CONTROL_MASK && priv->enable_zoom) {
if (event->direction == GDK_SCROLL_DOWN) { if (event->direction == GDK_SCROLL_DOWN) {
gtk_databox_zoom_out(box); gtk_databox_zoom_out(box);
} else if (event->direction == GDK_SCROLL_UP && } else if (event->direction == GDK_SCROLL_UP &&
gtk_adjustment_get_page_size (priv->adj_x) / 2 >= priv->zoom_ (gtk_adjustment_get_page_size(priv->adj_x) / 2) >= priv->zoom
limit && _limit &&
gtk_adjustment_get_page_size (priv->adj_y) / 2 >= priv->zoom_ (gtk_adjustment_get_page_size(priv->adj_y) / 2) >= priv->zoom
limit) { _limit) {
gdouble x_val, y_val; gdouble x_val, y_val;
gdouble x_proportion, y_proportion; gdouble x_proportion, y_proportion;
x_val = gtk_databox_pixel_to_value_x(box, event->x); x_val = gtk_databox_pixel_to_value_x(box, event->x);
y_val = gtk_databox_pixel_to_value_y(box, event->y); y_val = gtk_databox_pixel_to_value_y(box, event->y);
if (priv->scale_type_x == GTK_DATABOX_SCALE_LINEAR) { if (priv->scale_type_x == GTK_DATABOX_SCALE_LINEAR) {
x_proportion = (x_val - priv->total_left) / x_proportion = (x_val - priv->total_left) /
(priv->total_right - priv->total_left); (priv->total_right - priv->total_left);
} else { } else {
skipping to change at line 1325 skipping to change at line 1387
} }
if (priv->scale_type_y == GTK_DATABOX_SCALE_LINEAR) { if (priv->scale_type_y == GTK_DATABOX_SCALE_LINEAR) {
y_proportion = (y_val - priv->total_top) / y_proportion = (y_val - priv->total_top) /
(priv->total_bottom - priv->total_top); (priv->total_bottom - priv->total_top);
} else { } else {
y_proportion = log(y_val/priv->total_top) / y_proportion = log(y_val/priv->total_top) /
log(priv->total_bottom / priv->total_top); log(priv->total_bottom / priv->total_top);
} }
gtk_adjustment_set_page_size (priv->adj_x, gtk_adjustment_get_page_s g_object_freeze_notify(G_OBJECT(priv->adj_x));
ize (priv->adj_x)/ 2); gtk_adjustment_set_page_size(priv->adj_x, gtk_adjustment_get_page_si
gtk_adjustment_set_value (priv->adj_x, (x_proportion + ze(priv->adj_x) / 2);
gtk_adjustment_get_value (priv->adj_x)) / gtk_adjustment_set_value(priv->adj_x, (x_proportion +
2); gtk_adjustment_get_value(priv->adj_x)) /
2);
gtk_adjustment_set_page_size (priv->adj_y, gtk_adjustment_get_page_s g_object_thaw_notify(G_OBJECT(priv->adj_x));
ize (priv->adj_y)/ 2);
gtk_adjustment_set_value (priv->adj_y, (y_proportion + g_object_freeze_notify(G_OBJECT(priv->adj_y));
gtk_adjustment_get_value (priv->adj_y)) / gtk_adjustment_set_page_size(priv->adj_y, gtk_adjustment_get_page_si
2); ze(priv->adj_y) / 2);
gtk_adjustment_set_value(priv->adj_y, (y_proportion +
gtk_adjustment_get_value(priv->adj_y)) /
2);
g_object_thaw_notify(G_OBJECT(priv->adj_y));
gtk_databox_calculate_visible_limits(box); gtk_databox_calculate_visible_limits(box);
gtk_databox_zoomed (box); gtk_databox_zoomed (box);
} }
} else { } else {
GtkAdjustment *adj; GtkAdjustment *adj;
gdouble delta, new_value; gdouble delta = 0.0, new_value;
if ((event->direction == GDK_SCROLL_UP || if ((event->direction == GDK_SCROLL_UP ||
event->direction == GDK_SCROLL_DOWN) && event->direction == GDK_SCROLL_DOWN) &&
!(event->state & GDK_MOD1_MASK)) { !(event->state & GDK_SHIFT_MASK)) {
adj = priv->adj_y; adj = priv->adj_y;
} else { } else {
adj = priv->adj_x; adj = priv->adj_x;
} }
switch (event->direction) { switch (event->direction) {
case GDK_SCROLL_UP: case GDK_SCROLL_UP:
case GDK_SCROLL_SMOOTH:
case GDK_SCROLL_LEFT: case GDK_SCROLL_LEFT:
delta = - gtk_adjustment_get_step_increment(adj); delta = 0 - gtk_adjustment_get_step_increment(adj);
break; break;
case GDK_SCROLL_DOWN: case GDK_SCROLL_DOWN:
case GDK_SCROLL_RIGHT: case GDK_SCROLL_RIGHT:
delta = gtk_adjustment_get_step_increment(adj); delta = gtk_adjustment_get_step_increment(adj);
break; break;
default:
delta = 0;
break;
} }
new_value = CLAMP (gtk_adjustment_get_value(adj) + delta, new_value = CLAMP (gtk_adjustment_get_value(adj) + delta, gtk_adjustment
gtk_adjustment_get_lower(adj), _get_lower(adj),
gtk_adjustment_get_upper(adj) - gtk_adjustment_get_upper(adj) - gtk_adjustment_get_pa
gtk_adjustment_get_page_size(adj)); ge_size(adj));
gtk_adjustment_set_value(adj, new_value); gtk_adjustment_set_value(adj, new_value);
} }
return FALSE; return FALSE;
} }
static void static void
gtk_databox_selection_cancel (GtkDatabox * box) { gtk_databox_selection_cancel (GtkDatabox * box) {
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(box); GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
GdkRectangle rect;
/* There is no active selection after cancellation */ /* There is no active selection after cancellation */
priv->selection_active = FALSE; priv->selection_active = FALSE;
/* Only active selections can be stopped */ /* Only active selections can be stopped */
priv->selection_finalized = FALSE; priv->selection_finalized = FALSE;
/* Remove selection box */ /* Remove selection box */
rect.x = MIN (priv->marked.x, priv->select.x); gtk_databox_draw_selection (box, TRUE);
rect.y = MIN (priv->marked.y, priv->select.y);
rect.width = ABS (priv->marked.x - priv->select.x) + 1;
rect.height = ABS (priv->marked.y - priv->select.y) + 1;
gtk_databox_draw_selection (box, &rect);
/* Let everyone know that the selection has been canceled */ /* Let everyone know that the selection has been canceled */
g_signal_emit (G_OBJECT (box), g_signal_emit (G_OBJECT (box),
gtk_databox_signals[SELECTION_CANCELED_SIGNAL], 0); gtk_databox_signals[SELECTION_CANCELED_SIGNAL], 0);
} }
static void static void
gtk_databox_zoomed (GtkDatabox * box) { gtk_databox_zoomed (GtkDatabox * box) {
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(box); GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
g_return_if_fail(GTK_IS_DATABOX(box)); g_return_if_fail(GTK_IS_DATABOX(box));
g_return_if_fail(GTK_IS_ADJUSTMENT(priv->adj_x)); g_return_if_fail(GTK_IS_ADJUSTMENT(priv->adj_x));
g_return_if_fail(GTK_IS_ADJUSTMENT(priv->adj_y)); g_return_if_fail(GTK_IS_ADJUSTMENT(priv->adj_y));
priv->selection_active = FALSE; priv->selection_active = FALSE;
priv->selection_finalized = FALSE; priv->selection_finalized = FALSE;
#ifndef GTK3_18
gtk_adjustment_changed (priv->adj_x); gtk_adjustment_changed (priv->adj_x);
gtk_adjustment_changed (priv->adj_y); gtk_adjustment_changed (priv->adj_y);
#endif
gtk_widget_queue_draw (GTK_WIDGET(box)); gtk_widget_queue_draw (GTK_WIDGET(box));
g_signal_emit (G_OBJECT (box), g_signal_emit (G_OBJECT (box),
gtk_databox_signals[ZOOMED_SIGNAL], 0, NULL); gtk_databox_signals[ZOOMED_SIGNAL], 0, NULL);
} }
/** /**
* gtk_databox_zoom_to_selection: * gtk_databox_zoom_to_selection:
* @box: A #GtkDatabox widget * @box: A #GtkDatabox widget
* *
* This is equivalent to left-clicking into the selected area. * This is equivalent to left-clicking into the selected area.
* *
* This function works, if the attribute #enable-zoom is set to #TRUE. Calling t he function * This function works, if the attribute #enable-zoom is set to #TRUE. Calling t he function
* then zooms to the area selected with the mouse. * then zooms to the area selected with the mouse.
* *
* Side effect: The @box emits #GtkDatabox::zoomed. * Side effect: The @box emits #GtkDatabox::zoomed.
*/ */
void void
gtk_databox_zoom_to_selection (GtkDatabox * box) { gtk_databox_zoom_to_selection (GtkDatabox * box) {
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(box); GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
GtkWidget *widget; GtkWidget *widget;
GtkAllocation allocation; GtkAllocation allocation;
gdouble value_x, value_y; gdouble temp_value, temp_page_size;
gdouble page_size_x, page_size_y;
g_return_if_fail(GTK_IS_DATABOX(box)); g_return_if_fail(GTK_IS_DATABOX(box));
widget = GTK_WIDGET (box); widget = GTK_WIDGET (box);
gtk_widget_get_allocation(widget, &allocation);
if (!priv->enable_zoom) { if (!priv->enable_zoom) {
gtk_databox_selection_cancel (box); gtk_databox_selection_cancel (box);
return; return;
} }
gtk_widget_get_allocation (widget, &allocation); g_object_freeze_notify(G_OBJECT(priv->adj_x));
g_object_freeze_notify(G_OBJECT(priv->adj_y));
value_x = gtk_adjustment_get_value(priv->adj_x) + temp_value = gtk_adjustment_get_value(priv->adj_x);
(gfloat) (MIN (priv->marked.x, temp_value += (gdouble) (MIN (priv->marked.x, priv->select.x))
priv->select.x))
* gtk_adjustment_get_page_size(priv->adj_x) * gtk_adjustment_get_page_size(priv->adj_x)
/ allocation.width; / allocation.width;
value_y = gtk_adjustment_get_value(priv->adj_y) + temp_page_size = gtk_adjustment_get_page_size(priv->adj_x);
(gfloat) (MIN (priv->marked.y, temp_page_size *=
priv->select.y))
* gtk_adjustment_get_page_size(priv->adj_y)
/ allocation.height;
page_size_x = gtk_adjustment_get_page_size(priv->adj_x) *
(gdouble) (ABS (priv->marked.x - priv->select.x) + 1) (gdouble) (ABS (priv->marked.x - priv->select.x) + 1)
/ allocation.width; / allocation.width;
page_size_y = gtk_adjustment_get_page_size(priv->adj_y) * gtk_adjustment_set_page_size(priv->adj_x, temp_page_size);
(gdouble) (ABS (priv->marked.y - priv->select.y) + 1) gtk_adjustment_set_value(priv->adj_x, temp_value);
temp_value = gtk_adjustment_get_value(priv->adj_y);
temp_value += (gdouble) (MIN (priv->marked.y, priv->select.y))
* gtk_adjustment_get_page_size(priv->adj_y)
/ allocation.height;
temp_page_size = gtk_adjustment_get_page_size(priv->adj_y);
temp_page_size *=
(gfloat) (ABS (priv->marked.y - priv->select.y) + 1)
/ allocation.height; / allocation.height;
gtk_adjustment_set_page_size(priv->adj_y, temp_page_size);
gtk_adjustment_set_value(priv->adj_y, temp_value);
/* If we zoom too far into the data, we will get funny results, because /* If we zoom too far into the data, we will get funny results, because
* of overflow effects. Therefore zooming is limited to box->zoom_limit. * of overflow effects. Therefore zooming is limited to zoom_limit.
*/ */
if (page_size_x < priv->zoom_limit) { if (gtk_adjustment_get_page_size(priv->adj_x) < priv->zoom_limit) {
value_x = (gfloat) MAX (0, temp_value = (gfloat) MAX (0, gtk_adjustment_get_value(priv->adj_x)
value_x - (priv->zoom_limit - page_size_x) / 2.0 - (priv->zoom_limit -
); gtk_adjustment_get_page_s
page_size_x = priv->zoom_limit; ize(priv->adj_x)) /
} 2.0);
gtk_adjustment_set_page_size(priv->adj_x, priv->zoom_limit);
if (page_size_y < priv->zoom_limit) { gtk_adjustment_set_value(priv->adj_x, temp_value);
value_y = (gfloat) MAX (0, }
value_y - (priv->zoom_limit - page_size_y) / 2.0
); if (gtk_adjustment_get_page_size(priv->adj_y) < priv->zoom_limit) {
page_size_y = priv->zoom_limit; temp_value = (gfloat) MAX (0, gtk_adjustment_get_value(priv->adj_y)
} - (priv->zoom_limit -
gtk_adjustment_get_page_s
gtk_adjustment_set_page_size(priv->adj_x, page_size_x); ize(priv->adj_y)) /
gtk_adjustment_set_page_size(priv->adj_y, page_size_y); 2.0);
gtk_adjustment_set_value(priv->adj_x, value_x); gtk_adjustment_set_page_size(priv->adj_y, priv->zoom_limit);
gtk_adjustment_set_value(priv->adj_y, value_y); gtk_adjustment_set_value(priv->adj_y, temp_value);
}
g_object_thaw_notify(G_OBJECT(priv->adj_y));
g_object_thaw_notify(G_OBJECT(priv->adj_x));
gtk_databox_calculate_visible_limits(box); gtk_databox_calculate_visible_limits(box);
gtk_databox_zoomed (box); gtk_databox_zoomed (box);
} }
/** /**
* gtk_databox_zoom_out: * gtk_databox_zoom_out:
* @box: A #GtkDatabox widget * @box: A #GtkDatabox widget
* *
* This is equivalent to right-clicking into the @box. * This is equivalent to right-clicking into the @box.
* *
* This function works, if the attribute #enable-zoom is set to #TRUE. Calling t he function * This function works, if the attribute #enable-zoom is set to #TRUE. Calling t he function
* then zooms out by a factor of 2 in both dimensions (the maximum is defined by the total * then zooms out by a factor of 2 in both dimensions (the maximum is defined by the total
* limits, see gtk_databox_set_total_limits()). * limits, see gtk_databox_set_total_limits()).
* *
* Side effect: The @box emits #GtkDatabox::zoomed. * Side effect: The @box emits #GtkDatabox::zoomed.
*/ */
void void
gtk_databox_zoom_out (GtkDatabox * box) { gtk_databox_zoom_out (GtkDatabox * box) {
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(box); GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
if (!priv->enable_zoom) { if (!priv->enable_zoom) {
return; return;
} }
gtk_adjustment_set_page_size (priv->adj_x, MIN (1.0, gtk_adjustment_get_page g_object_freeze_notify(G_OBJECT(priv->adj_x));
_size (priv->adj_x) * 2)); g_object_freeze_notify(G_OBJECT(priv->adj_y));
gtk_adjustment_set_page_size (priv->adj_y, MIN (1.0, gtk_adjustment_get_page gtk_adjustment_set_page_size(priv->adj_x, MIN (1.0, gtk_adjustment_get_page_
_size (priv->adj_y) * 2)); size(priv->adj_x) * 2));
gtk_adjustment_set_value (priv->adj_x, gtk_adjustment_set_page_size(priv->adj_y, MIN (1.0, gtk_adjustment_get_page_
(gtk_adjustment_get_page_size (priv->adj_x) == 1.0) size(priv->adj_y) * 2));
gtk_adjustment_set_value(priv->adj_x,
(gtk_adjustment_get_page_size(priv->adj_x) == 1.0)
? 0 ? 0
: MAX (0, MIN (gtk_adjustment_get_value (priv->adj_x) - gtk_adjustment_g : MAX (0, MIN (gtk_adjustment_get_value(priv->adj_x) - gtk_adjustment_ge
et_page_size (priv->adj_x) / 4, t_page_size(priv->adj_x) / 4,
1.0 - gtk_adjustment_get_page_size (priv->adj_x)))); 1.0 - gtk_adjustment_get_page_size(priv->adj_x))));
gtk_adjustment_set_value (priv->adj_y, gtk_adjustment_set_value(priv->adj_y,
(gtk_adjustment_get_page_size (priv->adj_y) == 1.0) (gtk_adjustment_get_page_size(priv->adj_y) == 1.0)
? 0 ? 0
: MAX (0, MIN (gtk_adjustment_get_value (priv->adj_y) - gtk_adjustment_g : MAX (0, MIN (gtk_adjustment_get_value(priv->adj_y) - gtk_adjustment_ge
et_page_size (priv->adj_y) / 4, t_page_size(priv->adj_y) / 4,
1.0 - gtk_adjustment_get_page_size (priv->adj_y)))); 1.0 - gtk_adjustment_get_page_size(priv->adj_y))));
g_object_thaw_notify(G_OBJECT(priv->adj_y));
g_object_thaw_notify(G_OBJECT(priv->adj_x));
gtk_databox_calculate_visible_limits(box); gtk_databox_calculate_visible_limits(box);
gtk_databox_zoomed (box); gtk_databox_zoomed (box);
} }
/** /**
* gtk_databox_zoom_home: * gtk_databox_zoom_home:
* @box: A #GtkDatabox widget * @box: A #GtkDatabox widget
* *
* This is equivalent to shift right-clicking into the @box. * This is equivalent to shift right-clicking into the @box.
* *
* This function works, if the attribute #enable-zoom is set to #TRUE. It is equ ivalent to * This function works, if the attribute #enable-zoom is set to #TRUE. It is equ ivalent to
* calling the gtk_databox_set_visible_limits() with the total limits. * calling the gtk_databox_set_visible_limits() with the total limits.
* *
*/ */
void void
gtk_databox_zoom_home (GtkDatabox * box) { gtk_databox_zoom_home (GtkDatabox * box) {
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(box); GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
if (!priv->enable_zoom) { if (!priv->enable_zoom) {
return; return;
} }
gtk_databox_set_visible_limits (box, gtk_databox_set_visible_limits (box,
priv->total_left, priv->total_right, priv->total_left, priv->total_right,
priv->total_top, priv->total_bottom); priv->total_top, priv->total_bottom);
} }
static void static void
gtk_databox_draw_selection (GtkDatabox * box, GdkRectangle * pixmapCopyRect) { gtk_databox_draw_selection (GtkDatabox * box, gboolean clear) {
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(box); GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
GtkWidget *widget = GTK_WIDGET (box); GtkWidget *widget = GTK_WIDGET (box);
GdkDrawingContext *drawc;
if (!priv->select_gc) { cairo_region_t *crr;
GdkGCValues values; cairo_t *cr;
values.foreground = gtk_widget_get_style (widget)->white; crr = gdk_window_get_visible_region (gtk_widget_get_window (widget));
values.function = GDK_XOR; drawc = gdk_window_begin_draw_frame (gtk_widget_get_window (widget), crr);
priv->select_gc = gtk_gc_get (gtk_widget_get_style (widget)->depth, cr = gdk_drawing_context_get_cairo_context (drawc);
gtk_widget_get_style (widget)->colorm cairo_rectangle (cr,
ap, MIN (priv->marked.x, priv->select.x) - 0.5,
&values, MIN (priv->marked.y, priv->select.y) - 0.5,
GDK_GC_FUNCTION | GDK_GC_FOREGROUND); ABS (priv->marked.x - priv->select.x) + 1.0,
} ABS (priv->marked.y - priv->select.y) + 1.0);
/* Draw a selection box in XOR mode onto the buffer backing_pixmap */ if (clear) {
gdk_draw_rectangle (priv->backing_pixmap, cairo_set_source_surface (cr, priv->backing_surface, 0, 0);
priv->select_gc, cairo_paint(cr);
FALSE, cairo_set_line_width (cr, 2.0);
MIN (priv->marked.x, priv->select.x), } else {
MIN (priv->marked.y, priv->select.y), cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
ABS (priv->marked.x - priv->select.x), cairo_set_operator (cr, CAIRO_OPERATOR_DIFFERENCE);
ABS (priv->marked.y - priv->select.y)); cairo_set_line_width (cr, 1.0);
}
/* Copy a part of the backing_pixmap to the screen */ cairo_stroke(cr);
if (pixmapCopyRect) gdk_window_end_draw_frame (gtk_widget_get_window (widget), drawc);
gdk_draw_drawable (gtk_widget_get_window (widget), cairo_region_destroy (crr);
gtk_widget_get_style (widget)->fg_gc[gtk_widget_get_s
tate (widget)],
priv->backing_pixmap,
pixmapCopyRect->x,
pixmapCopyRect->y,
pixmapCopyRect->x,
pixmapCopyRect->y,
pixmapCopyRect->width, pixmapCopyRect->height);
} }
static void static void
gtk_databox_adjustment_value_changed (GtkDatabox * box) { gtk_databox_adjustment_value_changed (GtkDatabox * box) {
gtk_databox_calculate_visible_limits (box); gtk_databox_calculate_visible_limits (box);
gtk_widget_queue_draw (GTK_WIDGET(box)); gtk_widget_queue_draw (GTK_WIDGET(box));
} }
static void static void
gtk_databox_ruler_update (GtkDatabox * box) { gtk_databox_ruler_update (GtkDatabox * box) {
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(box); GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
if (priv->ruler_x) { if (priv->ruler_x) {
gtk_databox_ruler_set_range ( gtk_databox_ruler_set_range (
GTK_DATABOX_RULER (priv->ruler_x), GTK_DATABOX_RULER (priv->ruler_x),
priv->visible_left, priv->visible_left,
priv->visible_right, priv->visible_right,
0.5 * (priv->visible_left + priv->visible_right)); 0.5 * (priv->visible_left + priv->visible_right));
} }
if (priv->ruler_y) { if (priv->ruler_y) {
gtk_databox_ruler_set_range ( gtk_databox_ruler_set_range (
skipping to change at line 1676 skipping to change at line 1741
* #GtkDataboxGraph objects which have been added to the #GtkDatabox widget via gtk_databox_graph_add(). * #GtkDataboxGraph objects which have been added to the #GtkDatabox widget via gtk_databox_graph_add().
* *
* Return value: 0 on success, * Return value: 0 on success,
* -1 if @box is no GtkDatabox widget, * -1 if @box is no GtkDatabox widget,
* -2 if no datasets are available * -2 if no datasets are available
*/ */
gint gint
gtk_databox_calculate_extrema (GtkDatabox * box, gtk_databox_calculate_extrema (GtkDatabox * box,
gfloat * min_x, gfloat * max_x, gfloat * min_y, gfloat * min_x, gfloat * max_x, gfloat * min_y,
gfloat * max_y) { gfloat * max_y) {
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(box); GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
GList *list; GList *list;
gint return_val = -2; gint return_val = -2;
gboolean first = TRUE; gboolean first = TRUE;
g_return_val_if_fail (GTK_IS_DATABOX (box), -1); g_return_val_if_fail (GTK_IS_DATABOX (box), -1);
list = g_list_last (priv->graphs); list = g_list_last (priv->graphs);
while (list) { while (list) {
gfloat graph_min_x; gfloat graph_min_x;
gfloat graph_max_x; gfloat graph_max_x;
skipping to change at line 1729 skipping to change at line 1794
} }
} }
list = g_list_previous (list); list = g_list_previous (list);
} }
return return_val; return return_val;
} }
static gfloat static gfloat
gtk_databox_get_offset_x (GtkDatabox* box) { gtk_databox_get_offset_x (GtkDatabox* box) {
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(box); GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
if (priv->scale_type_x == GTK_DATABOX_SCALE_LINEAR) if (priv->scale_type_x == GTK_DATABOX_SCALE_LINEAR)
return (priv->visible_left - priv->total_left) return (priv->visible_left - priv->total_left)
/ (priv->total_right - priv->total_left); / (priv->total_right - priv->total_left);
else if (priv->scale_type_x == GTK_DATABOX_SCALE_LOG2) else if (priv->scale_type_x == GTK_DATABOX_SCALE_LOG2)
return log2 (priv->visible_left / priv->total_left) return log2 (priv->visible_left / priv->total_left)
/ log2 (priv->total_right / priv->total_left); / log2 (priv->total_right / priv->total_left);
else else
return log10 (priv->visible_left / priv->total_left) return log10 (priv->visible_left / priv->total_left)
/ log10 (priv->total_right / priv->total_left); / log10 (priv->total_right / priv->total_left);
} }
static gfloat static gfloat
gtk_databox_get_page_size_x (GtkDatabox* box) { gtk_databox_get_page_size_x (GtkDatabox* box) {
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(box); GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
if (priv->total_left == priv->total_right) if (priv->scale_type_x == GTK_DATABOX_SCALE_LINEAR)
return 0;
else if (priv->scale_type_x == GTK_DATABOX_SCALE_LINEAR)
return (priv->visible_left - priv->visible_right) return (priv->visible_left - priv->visible_right)
/ (priv->total_left - priv->total_right); / (priv->total_left - priv->total_right);
else if (priv->scale_type_x == GTK_DATABOX_SCALE_LOG2) else if (priv->scale_type_x == GTK_DATABOX_SCALE_LOG2)
return log2 (priv->visible_left / priv->visible_right) return log2 (priv->visible_left / priv->visible_right)
/ log2 (priv->total_left / priv->total_right); / log2 (priv->total_left / priv->total_right);
else else
return log10 (priv->visible_left / priv->visible_right) return log10 (priv->visible_left / priv->visible_right)
/ log10 (priv->total_left / priv->total_right); / log10 (priv->total_left / priv->total_right);
} }
static gfloat static gfloat
gtk_databox_get_offset_y (GtkDatabox* box) { gtk_databox_get_offset_y (GtkDatabox* box) {
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(box); GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
if (priv->scale_type_y == GTK_DATABOX_SCALE_LINEAR) if (priv->scale_type_y == GTK_DATABOX_SCALE_LINEAR)
return (priv->visible_top - priv->total_top) return (priv->visible_top - priv->total_top)
/ (priv->total_bottom - priv->total_top); / (priv->total_bottom - priv->total_top);
else if (priv->scale_type_y == GTK_DATABOX_SCALE_LOG2) else if (priv->scale_type_y == GTK_DATABOX_SCALE_LOG2)
return log2 (priv->visible_top / priv->total_top) return log2 (priv->visible_top / priv->total_top)
/ log2 (priv->total_bottom / priv->total_top); / log2 (priv->total_bottom / priv->total_top);
else else
return log10 (priv->visible_top / priv->total_top) return log10 (priv->visible_top / priv->total_top)
/ log10 (priv->total_bottom / priv->total_top); / log10 (priv->total_bottom / priv->total_top);
} }
static gfloat static gfloat
gtk_databox_get_page_size_y (GtkDatabox* box) { gtk_databox_get_page_size_y (GtkDatabox* box) {
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(box); GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
if (priv->total_top == priv->total_bottom) if (priv->scale_type_y == GTK_DATABOX_SCALE_LINEAR)
return 0;
else if (priv->scale_type_y == GTK_DATABOX_SCALE_LINEAR)
return (priv->visible_top - priv->visible_bottom) return (priv->visible_top - priv->visible_bottom)
/ (priv->total_top - priv->total_bottom); / (priv->total_top - priv->total_bottom);
else if (priv->scale_type_y == GTK_DATABOX_SCALE_LOG2) else if (priv->scale_type_y == GTK_DATABOX_SCALE_LOG2)
return log2 (priv->visible_top / priv->visible_bottom) return log2 (priv->visible_top / priv->visible_bottom)
/ log2 (priv->total_top / priv->total_bottom); / log2 (priv->total_top / priv->total_bottom);
else else
return log10 (priv->visible_top / priv->visible_bottom) return log10 (priv->visible_top / priv->visible_bottom)
/ log10 (priv->total_top / priv->total_bottom); / log10 (priv->total_top / priv->total_bottom);
} }
skipping to change at line 1811 skipping to change at line 1872
* This function can be used to invert the orientation of the displayed graphs, * This function can be used to invert the orientation of the displayed graphs,
* e.g. @top=-1000 and @bottom=0. * e.g. @top=-1000 and @bottom=0.
* *
* Side effect: The @box also internally calls gtk_databox_set_visible_limits() with the same values. * Side effect: The @box also internally calls gtk_databox_set_visible_limits() with the same values.
* *
*/ */
void void
gtk_databox_set_total_limits (GtkDatabox * box, gtk_databox_set_total_limits (GtkDatabox * box,
gfloat left, gfloat right, gfloat left, gfloat right,
gfloat top, gfloat bottom) { gfloat top, gfloat bottom) {
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(box); GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
g_return_if_fail (GTK_IS_DATABOX (box)); g_return_if_fail (GTK_IS_DATABOX (box));
g_return_if_fail (left != right); g_return_if_fail (left != right);
g_return_if_fail (top != bottom); g_return_if_fail (top != bottom);
priv->total_left = left; priv->total_left = left;
priv->total_right = right; priv->total_right = right;
priv->total_top = top; priv->total_top = top;
priv->total_bottom = bottom; priv->total_bottom = bottom;
gtk_databox_set_visible_limits(box, left, right, top, bottom); gtk_databox_set_visible_limits(box, left, right, top, bottom);
skipping to change at line 1847 skipping to change at line 1908
* the visible limits have to be within the total limits. The * the visible limits have to be within the total limits. The
* values will not be used otherwise. * values will not be used otherwise.
* *
* Side effect: The @box emits #GtkDatabox::zoomed. * Side effect: The @box emits #GtkDatabox::zoomed.
* *
*/ */
void void
gtk_databox_set_visible_limits (GtkDatabox * box, gtk_databox_set_visible_limits (GtkDatabox * box,
gfloat left, gfloat right, gfloat left, gfloat right,
gfloat top, gfloat bottom) { gfloat top, gfloat bottom) {
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(box); GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
gboolean visible_inside_total = FALSE; gboolean visible_inside_total = FALSE;
g_return_if_fail (GTK_IS_DATABOX (box)); g_return_if_fail (GTK_IS_DATABOX (box));
visible_inside_total = visible_inside_total =
((priv->total_left <= left && left < right ((priv->total_left <= left && left < right
&& right <= priv->total_right) && right <= priv->total_right)
|| (priv->total_left >= left && left > right || (priv->total_left >= left && left > right
&& right >= priv->total_right)) && right >= priv->total_right))
&& &&
skipping to change at line 1872 skipping to change at line 1933
g_return_if_fail (visible_inside_total); g_return_if_fail (visible_inside_total);
priv->visible_left = left; priv->visible_left = left;
priv->visible_right = right; priv->visible_right = right;
priv->visible_top = top; priv->visible_top = top;
priv->visible_bottom = bottom; priv->visible_bottom = bottom;
gtk_databox_calculate_translation_factors (box); gtk_databox_calculate_translation_factors (box);
gtk_adjustment_set_value (priv->adj_x, gtk_databox_get_offset_x (box)); g_object_freeze_notify(G_OBJECT(priv->adj_x));
gtk_adjustment_set_page_size (priv->adj_x, gtk_databox_get_page_size_x (box) g_object_freeze_notify(G_OBJECT(priv->adj_y));
);
gtk_adjustment_set_value (priv->adj_y, gtk_databox_get_offset_y (box)); gtk_adjustment_set_value(priv->adj_x, gtk_databox_get_offset_x (box));
gtk_adjustment_set_page_size (priv->adj_y, gtk_databox_get_page_size_y (box) gtk_adjustment_set_page_size(priv->adj_x, gtk_databox_get_page_size_x (box))
); ;
gtk_adjustment_set_value(priv->adj_y, gtk_databox_get_offset_y (box));
gtk_adjustment_set_page_size(priv->adj_y, gtk_databox_get_page_size_y (box))
;
g_object_thaw_notify(G_OBJECT(priv->adj_y));
g_object_thaw_notify(G_OBJECT(priv->adj_x));
/* Update rulers */ /* Update rulers */
gtk_databox_ruler_update(box); gtk_databox_ruler_update(box);
gtk_databox_calculate_translation_factors (box); gtk_databox_calculate_translation_factors (box);
gtk_databox_zoomed (box); gtk_databox_zoomed (box);
} }
/** /**
* gtk_databox_calculate_visible_limits: * gtk_databox_calculate_visible_limits:
* @box: A #GtkDatabox widget * @box: A #GtkDatabox widget
* *
* Calculates the visible limits based on the adjustment values and page sizes * Calculates the visible limits based on the adjustment values and page sizes
* and calls gtk_databox_set_visible_limits(); * and calls gtk_databox_set_visible_limits();
*/ */
static void static void
gtk_databox_calculate_visible_limits (GtkDatabox * box) { gtk_databox_calculate_visible_limits (GtkDatabox * box) {
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(box); GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
if (!gtk_widget_get_visible (GTK_WIDGET(box))) if (!gtk_widget_get_visible (GTK_WIDGET(box)))
return; return;
if (priv->scale_type_x == GTK_DATABOX_SCALE_LINEAR) { if (priv->scale_type_x == GTK_DATABOX_SCALE_LINEAR) {
priv->visible_left = priv->visible_left =
priv->total_left priv->total_left
+ (priv->total_right - priv->total_left) + (priv->total_right - priv->total_left)
* gtk_adjustment_get_value (priv->adj_x); * gtk_adjustment_get_value(priv->adj_x);
priv->visible_right = priv->visible_right =
priv->total_left priv->total_left
+ (priv->total_right - priv->total_left) + (priv->total_right - priv->total_left)
* (gtk_adjustment_get_value (priv->adj_x) + gtk_adjustment_get_page_ size (priv->adj_x)); * (gtk_adjustment_get_value(priv->adj_x) + gtk_adjustment_get_page_s ize(priv->adj_x));
} else { } else {
priv->visible_left = priv->visible_left =
priv->total_left priv->total_left
* pow (priv->total_right / priv->total_left, * pow (priv->total_right / priv->total_left,
gtk_adjustment_get_value (priv->adj_x)); gtk_adjustment_get_value(priv->adj_x));
priv->visible_right = priv->visible_right =
priv->total_left priv->total_left
* pow (priv->total_right / priv->total_left, * pow (priv->total_right / priv->total_left,
gtk_adjustment_get_value (priv->adj_x) + gtk_adjustment_get_p age_size (priv->adj_x)); gtk_adjustment_get_value(priv->adj_x) + gtk_adjustment_get_pa ge_size(priv->adj_x));
} }
if (priv->scale_type_y == GTK_DATABOX_SCALE_LINEAR) { if (priv->scale_type_y == GTK_DATABOX_SCALE_LINEAR) {
priv->visible_top = priv->visible_top =
priv->total_top priv->total_top
+ (priv->total_bottom - priv->total_top) + (priv->total_bottom - priv->total_top)
* gtk_adjustment_get_value (priv->adj_y); * gtk_adjustment_get_value(priv->adj_y);
priv->visible_bottom = priv->visible_bottom =
priv->total_top priv->total_top
+ (priv->total_bottom - priv->total_top) + (priv->total_bottom - priv->total_top)
* (gtk_adjustment_get_value (priv->adj_y) + gtk_adjustment_get_page_ size (priv->adj_y)); * (gtk_adjustment_get_value(priv->adj_y) + gtk_adjustment_get_page_s ize(priv->adj_y));
} else { } else {
priv->visible_top = priv->visible_top =
priv->total_top priv->total_top
* pow (priv->total_bottom / priv->total_top, * pow (priv->total_bottom / priv->total_top,
gtk_adjustment_get_value (priv->adj_y)), gtk_adjustment_get_value(priv->adj_y)),
priv->visible_bottom = priv->visible_bottom =
priv->total_top priv->total_top
* pow (priv->total_bottom / priv->total_top, * pow (priv->total_bottom / priv->total_top,
gtk_adjustment_get_value (priv->adj_y) + gtk_adjustment_g et_page_size (priv->adj_y)); gtk_adjustment_get_value(priv->adj_y) + gtk_adjustment_ge t_page_size(priv->adj_y));
} }
/* Adjustments are the basis for the calculations in this function /* Adjustments are the basis for the calculations in this function
* so they do not need to be updated * so they do not need to be updated
*/ */
/* Update rulers */ /* Update rulers */
gtk_databox_ruler_update(box); gtk_databox_ruler_update(box);
gtk_databox_calculate_translation_factors (box); gtk_databox_calculate_translation_factors (box);
skipping to change at line 1962 skipping to change at line 2029
* @right: Space for total right value or #NULL * @right: Space for total right value or #NULL
* @top: Space for total top value or #NULL * @top: Space for total top value or #NULL
* @bottom: Space for total bottom value or #NULL * @bottom: Space for total bottom value or #NULL
* *
* Gives the total limits (as set by gtk_databox_auto_rescale() or gtk_databox_s et_total_limits()). * Gives the total limits (as set by gtk_databox_auto_rescale() or gtk_databox_s et_total_limits()).
*/ */
void void
gtk_databox_get_total_limits (GtkDatabox * box, gtk_databox_get_total_limits (GtkDatabox * box,
gfloat * left, gfloat * right, gfloat * left, gfloat * right,
gfloat * top, gfloat * bottom) { gfloat * top, gfloat * bottom) {
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(box); GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
g_return_if_fail (GTK_IS_DATABOX (box)); g_return_if_fail (GTK_IS_DATABOX (box));
if (left) if (left)
*left = priv->total_left; *left = priv->total_left;
if (right) if (right)
*right = priv->total_right; *right = priv->total_right;
if (top) if (top)
*top = priv->total_top; *top = priv->total_top;
if (bottom) if (bottom)
*bottom = priv->total_bottom; *bottom = priv->total_bottom;
skipping to change at line 1991 skipping to change at line 2058
* @bottom: Space for visible bottom value or #NULL * @bottom: Space for visible bottom value or #NULL
* *
* Gives the current visible limits. These differ from those given by gtk_databo x_get_total_limits() if * Gives the current visible limits. These differ from those given by gtk_databo x_get_total_limits() if
* you zoomed into the data for instance by gtk_databox_zoom_to_selection() or g tk_databox_set_visible_limits() (these values * you zoomed into the data for instance by gtk_databox_zoom_to_selection() or g tk_databox_set_visible_limits() (these values
* can be changed by scrolling, of course). * can be changed by scrolling, of course).
*/ */
void void
gtk_databox_get_visible_limits (GtkDatabox * box, gtk_databox_get_visible_limits (GtkDatabox * box,
gfloat * left, gfloat * right, gfloat * left, gfloat * right,
gfloat * top, gfloat * bottom) { gfloat * top, gfloat * bottom) {
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(box); GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
g_return_if_fail (GTK_IS_DATABOX (box)); g_return_if_fail (GTK_IS_DATABOX (box));
if (left) if (left)
*left = priv->visible_left; *left = priv->visible_left;
if (right) if (right)
*right = priv->visible_right; *right = priv->visible_right;
if (top) if (top)
*top = priv->visible_top; *top = priv->visible_top;
if (bottom) if (bottom)
*bottom = priv->visible_bottom; *bottom = priv->visible_bottom;
skipping to change at line 2017 skipping to change at line 2084
* @graph: A graph, e.g. a #GtkDataboxPoints or a #GtkDataboxGrid object * @graph: A graph, e.g. a #GtkDataboxPoints or a #GtkDataboxGrid object
* *
* Adds the @graph to the @box. The next time the @box is re-drawn, the graph wi ll be shown. * Adds the @graph to the @box. The next time the @box is re-drawn, the graph wi ll be shown.
* *
* It might be becessary to modify the total_limits in order for the graph to be displayed properly (see gtk_databox_set_total_limits()). * It might be becessary to modify the total_limits in order for the graph to be displayed properly (see gtk_databox_set_total_limits()).
* *
* Return value: 0 on success, -1 otherwise * Return value: 0 on success, -1 otherwise
*/ */
gint gint
gtk_databox_graph_add (GtkDatabox * box, GtkDataboxGraph * graph) { gtk_databox_graph_add (GtkDatabox * box, GtkDataboxGraph * graph) {
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(box); GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
g_return_val_if_fail (GTK_IS_DATABOX (box), -1); g_return_val_if_fail (GTK_IS_DATABOX (box), -1);
g_return_val_if_fail (GTK_DATABOX_IS_GRAPH (graph), -1); g_return_val_if_fail (GTK_DATABOX_IS_GRAPH (graph), -1);
priv->graphs = g_list_append (priv->graphs, graph); priv->graphs = g_list_append (priv->graphs, graph);
return (priv->graphs == NULL) ? -1 : 0; return (priv->graphs == NULL) ? -1 : 0;
} }
/** /**
* gtk_databox_graph_add_front: * gtk_databox_graph_add_front:
skipping to change at line 2040 skipping to change at line 2107
* *
* Adds the @graph to the @box and will be plotted on top. The next time the @bo x is re-drawn, the graph will be shown. * Adds the @graph to the @box and will be plotted on top. The next time the @bo x is re-drawn, the graph will be shown.
* *
* It might be becessary to modify the total_limits in order for the graph to be displayed properly (see gtk_databox_set_total_limits()). * It might be becessary to modify the total_limits in order for the graph to be displayed properly (see gtk_databox_set_total_limits()).
* *
* Return value: 0 on success, -1 otherwise * Return value: 0 on success, -1 otherwise
*/ */
gint gint
gtk_databox_graph_add_front (GtkDatabox * box, GtkDataboxGraph * graph) { gtk_databox_graph_add_front (GtkDatabox * box, GtkDataboxGraph * graph) {
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(box); GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
g_return_val_if_fail (GTK_IS_DATABOX (box), -1); g_return_val_if_fail (GTK_IS_DATABOX (box), -1);
g_return_val_if_fail (GTK_DATABOX_IS_GRAPH (graph), -1); g_return_val_if_fail (GTK_DATABOX_IS_GRAPH (graph), -1);
priv->graphs = g_list_prepend (priv->graphs, graph); priv->graphs = g_list_prepend (priv->graphs, graph);
return (priv->graphs == NULL) ? -1 : 0; return (priv->graphs == NULL) ? -1 : 0;
} }
/** /**
* gtk_databox_graph_remove: * gtk_databox_graph_remove:
* @box: A #GtkDatabox widget * @box: A #GtkDatabox widget
* @graph: A graph, e.g. a #GtkDataboxPoints or a #GtkDataboxGrid object * @graph: A graph, e.g. a #GtkDataboxPoints or a #GtkDataboxGrid object
* *
* Removes the @graph from the @box once. The next time the @box is re-drawn, th e graph will not be shown (unless it was added more * Removes the @graph from the @box once. The next time the @box is re-drawn, th e graph will not be shown (unless it was added more
* than once). * than once).
* *
* Return value: 0 on success, -1 otherwise * Return value: 0 on success, -1 otherwise
*/ */
gint gint
gtk_databox_graph_remove (GtkDatabox * box, GtkDataboxGraph * graph) { gtk_databox_graph_remove (GtkDatabox * box, GtkDataboxGraph * graph) {
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(box); GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
GList *list; GList *list;
g_return_val_if_fail (GTK_IS_DATABOX (box), -1); g_return_val_if_fail (GTK_IS_DATABOX (box), -1);
g_return_val_if_fail (GTK_DATABOX_IS_GRAPH (graph), -1); g_return_val_if_fail (GTK_DATABOX_IS_GRAPH (graph), -1);
list = g_list_find (priv->graphs, graph); list = g_list_find (priv->graphs, graph);
g_return_val_if_fail (list, -1); g_return_val_if_fail (list, -1);
priv->graphs = g_list_delete_link (priv->graphs, list); priv->graphs = g_list_delete_link (priv->graphs, list);
return 0; return 0;
skipping to change at line 2084 skipping to change at line 2151
/** /**
* gtk_databox_graph_remove_all: * gtk_databox_graph_remove_all:
* @box: A #GtkDatabox widget * @box: A #GtkDatabox widget
* *
* Removes all graphs from the @box. The next time the @box is re-drawn, no grap hs will be shown. * Removes all graphs from the @box. The next time the @box is re-drawn, no grap hs will be shown.
* *
* Return value: 0 on success, -1 otherwise * Return value: 0 on success, -1 otherwise
*/ */
gint gint
gtk_databox_graph_remove_all (GtkDatabox * box) { gtk_databox_graph_remove_all (GtkDatabox * box) {
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(box); GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
g_return_val_if_fail (GTK_IS_DATABOX (box), -1); g_return_val_if_fail (GTK_IS_DATABOX (box), -1);
g_list_free (priv->graphs); g_list_free (priv->graphs);
priv->graphs = NULL; priv->graphs = NULL;
return 0; return 0;
} }
/** /**
* gtk_databox_values_to_pixels:
* @box: A #GtkDatabox widget
* @len: Number of values/pixels
* @values_x: Array of X values (length >= len)
* @values_y: Array of Y values (length >= len)
* @pixels: Array of pixel coordinates (length >= len)
*
* Calculates the pixel equivalents of the given X/Y values and stores them in t
he @pixels array.
*/
void
gtk_databox_values_to_pixels (GtkDatabox * box, guint len,
const gfloat * values_x,
const gfloat * values_y,
GdkPoint * pixels) {
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(box);
guint i;
for (i = 0; i < len; ++i, ++values_x, ++values_y, ++pixels) {
if (priv->scale_type_x == GTK_DATABOX_SCALE_LINEAR)
pixels->x =
(*values_x -
priv->visible_left) * priv->translation_factor_x;
else if (priv->scale_type_x == GTK_DATABOX_SCALE_LOG2)
pixels->x =
log2 (*values_x / priv->visible_left) *
priv->translation_factor_x;
else
pixels->x =
log10 (*values_x / priv->visible_left) *
priv->translation_factor_x;
if (priv->scale_type_y == GTK_DATABOX_SCALE_LINEAR)
pixels->y =
(*values_y -
priv->visible_top) * priv->translation_factor_y;
else if (priv->scale_type_y == GTK_DATABOX_SCALE_LOG2)
pixels->y =
log2 (*values_y / priv->visible_top) *
priv->translation_factor_y;
else
pixels->y =
log10 (*values_y / priv->visible_top) *
priv->translation_factor_y;
}
}
/**
* gtk_databox_value_to_pixel_x: * gtk_databox_value_to_pixel_x:
* @box: A #GtkDatabox widget * @box: A #GtkDatabox widget
* @value: An x value * @value: An x value
* *
* Calculates the horizontal pixel coordinate which represents the x @value. * Calculates the horizontal pixel coordinate which represents the x @value.
* Pixel coordinates are relative to the top-left corner of the @box which is eq uivalent to (0,0). * Pixel coordinates are relative to the top-left corner of the @box which is eq uivalent to (0,0).
* *
* Return value: Pixel coordinate * Return value: Pixel coordinate
*/ */
gint16 gint16
gtk_databox_value_to_pixel_x (GtkDatabox * box, gfloat value) { gtk_databox_value_to_pixel_x (GtkDatabox * box, gfloat value) {
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(box); GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
if (priv->scale_type_x == GTK_DATABOX_SCALE_LINEAR) if (priv->scale_type_x == GTK_DATABOX_SCALE_LINEAR)
return (value - return (value -
priv->visible_left) * priv->visible_left) *
priv->translation_factor_x; priv->translation_factor_x;
else if (priv->scale_type_x == GTK_DATABOX_SCALE_LOG2) else if (priv->scale_type_x == GTK_DATABOX_SCALE_LOG2)
return log2 (value / priv->visible_left) * return log2 (value / priv->visible_left) *
priv->translation_factor_x; priv->translation_factor_x;
else else
return log10 (value / priv->visible_left) * return log10 (value / priv->visible_left) *
skipping to change at line 2178 skipping to change at line 2198
* @box: A #GtkDatabox widget * @box: A #GtkDatabox widget
* @value: A y value * @value: A y value
* *
* Calculates the vertical pixel coordinate which represents the y @value. * Calculates the vertical pixel coordinate which represents the y @value.
* Pixel coordinates are relative to the top-left corner of the @box which is eq uivalent to (0,0). * Pixel coordinates are relative to the top-left corner of the @box which is eq uivalent to (0,0).
* *
* Return value: Pixel coordinate * Return value: Pixel coordinate
*/ */
gint16 gint16
gtk_databox_value_to_pixel_y (GtkDatabox * box, gfloat value) { gtk_databox_value_to_pixel_y (GtkDatabox * box, gfloat value) {
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(box); GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
if (priv->scale_type_y == GTK_DATABOX_SCALE_LINEAR) if (priv->scale_type_y == GTK_DATABOX_SCALE_LINEAR)
return (value - return (value -
priv->visible_top) * priv->translation_factor_y; priv->visible_top) * priv->translation_factor_y;
else if (priv->scale_type_y == GTK_DATABOX_SCALE_LOG2) else if (priv->scale_type_y == GTK_DATABOX_SCALE_LOG2)
return log2 (value / priv->visible_top) * return log2 (value / priv->visible_top) *
priv->translation_factor_y; priv->translation_factor_y;
else else
return log10 (value / priv->visible_top) * return log10 (value / priv->visible_top) *
priv->translation_factor_y; priv->translation_factor_y;
} }
/** /**
* gtk_databox_values_to_xpixels:
* @box: A #GtkDatabox widget.
* @pixels: address to return pixel x coordinates.
* @values: An x values array.
* @vtype: GType of @values.
* @maxlen: maximum length of the arrays.
* @start: first value to compute.
* @stride: bytes per row of plotting.
* @len: how many values to compute.
*
* Calculates the horizontal coordinates for @pixels which represents the x @val
ues.
* Pixel coordinates are relative to the left corner of the @box which is equiva
lent to (0).
*
* Return value: Pixel coordinates
*/
void
gtk_databox_values_to_xpixels (GtkDatabox *box, gint16 *pixels,
void *values, GType vtype, guint maxlen, guint start, guint stride, guint
len)
{
GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
guint i, indx;
gfloat fval = 0.0;
GtkDataboxScaleType scale_type;
gfloat tf, minvis;
scale_type = priv->scale_type_x;
tf = priv->translation_factor_x;
minvis = priv->visible_left;
indx = start * stride;
i = 0;
do {
/* This may be excessive, but it handles every conceivable type *
/
if (vtype == G_TYPE_FLOAT)
fval = ((gfloat *)values)[indx];
else if (vtype == G_TYPE_DOUBLE)
fval = ((gdouble *)values)[indx];
else if (vtype == G_TYPE_INT)
fval = ((gint *)values)[indx];
else if (vtype == G_TYPE_UINT)
fval = ((guint *)values)[indx];
else if (vtype == G_TYPE_LONG)
fval = ((glong *)values)[indx];
else if (vtype == G_TYPE_ULONG)
fval = ((gulong *)values)[indx];
else if (vtype == G_TYPE_INT64)
fval = ((gint64 *)values)[indx];
else if (vtype == G_TYPE_UINT64)
fval = ((guint64 *)values)[indx];
else if (vtype == G_TYPE_CHAR)
fval = ((gchar *)values)[indx];
else if (vtype == G_TYPE_UCHAR)
fval = ((guchar *)values)[indx];
if (scale_type == GTK_DATABOX_SCALE_LINEAR)
pixels[i] = tf * (fval - minvis);
else if (scale_type == GTK_DATABOX_SCALE_LOG2)
pixels[i] = tf * log2(fval / minvis);
else
pixels[i] = tf * log10(fval / minvis);
/* handle the wrap-around (ring buffer) issue using modulus. for
efficiency, don't do this for non-wraparound cases. */
/* note this allows multiple wrap-arounds. One could hold a sing
le cycle of a sine wave, and plot a continuous wave */
/* This can be optimized using pointers later */
if (i + start > maxlen)
indx = ((i + start) % maxlen) * stride;
else
indx += stride;
} while (++i < len);
}
/**
* gtk_databox_values_to_ypixels:
* @box: A #GtkDatabox widget
* @pixels: address to return pixel y coordinates.
* @values: an y values array.
* @vtype: GType of @values.
* @maxlen: maximum length of the arrays.
* @start: first value to compute.
* @stride: bytes per row of plotting.
* @len: how many values to compute.
*
* Calculates the vertical coordinates for @pixels which represents the y @value
s.
* Pixel coordinates are relative to the top corner of the @box which is equival
ent to (0).
*
* Return value: Pixel coordinates
*/
void
gtk_databox_values_to_ypixels (GtkDatabox *box, gint16 *pixels,
void *values, GType vtype, guint maxlen, guint start, guint stride, guint
len)
{
GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
guint i, indx;
gfloat fval = 0.0;
GtkDataboxScaleType scale_type;
gfloat tf, minvis;
scale_type = priv->scale_type_y;
tf = priv->translation_factor_y;
minvis = priv->visible_top;
indx = start * stride;
i = 0;
do {
/* This may be excessive, but it handles every conceivable type *
/
if (vtype == G_TYPE_FLOAT)
fval = ((gfloat *)values)[indx];
else if (vtype == G_TYPE_DOUBLE)
fval = ((gdouble *)values)[indx];
else if (vtype == G_TYPE_INT)
fval = ((gint *)values)[indx];
else if (vtype == G_TYPE_UINT)
fval = ((guint *)values)[indx];
else if (vtype == G_TYPE_LONG)
fval = ((glong *)values)[indx];
else if (vtype == G_TYPE_ULONG)
fval = ((gulong *)values)[indx];
else if (vtype == G_TYPE_INT64)
fval = ((gint64 *)values)[indx];
else if (vtype == G_TYPE_UINT64)
fval = ((guint64 *)values)[indx];
else if (vtype == G_TYPE_CHAR)
fval = ((gchar *)values)[indx];
else if (vtype == G_TYPE_UCHAR)
fval = ((guchar *)values)[indx];
if (scale_type == GTK_DATABOX_SCALE_LINEAR)
pixels[i] = tf * (fval - minvis);
else if (scale_type == GTK_DATABOX_SCALE_LOG2)
pixels[i] = tf * log2(fval / minvis);
else
pixels[i] = tf * log10(fval / minvis);
/* handle the wrap-around (ring buffer) issue using modulus. for
efficiency, don't do this for non-wraparound cases. */
/* note this allows multiple wrap-arounds. One could hold a sing
le cycle of a sine wave, and plot a continuous wave */
/* This can be optimized using pointers later */
if (i + start > maxlen)
indx = ((i + start) % maxlen) * stride;
else
indx += stride;
} while (++i < len);
}
/**
* gtk_databox_pixel_to_value_x: * gtk_databox_pixel_to_value_x:
* @box: A #GtkDatabox widget * @box: A #GtkDatabox widget
* @pixel: A horizontal pixel coordinate * @pixel: A horizontal pixel coordinate
* *
* Calculates the x value which is represented by the horizontal @pixel coordina te. * Calculates the x value which is represented by the horizontal @pixel coordina te.
* Pixel coordinates are relative to the top-left corner of the @box which is eq uivalent to (0,0). * Pixel coordinates are relative to the top-left corner of the @box which is eq uivalent to (0,0).
* *
* Return value: x value * Return value: x value
*/ */
gfloat gfloat
gtk_databox_pixel_to_value_x (GtkDatabox * box, gint16 pixel) { gtk_databox_pixel_to_value_x (GtkDatabox * box, gint16 pixel) {
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(box); GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
if (priv->scale_type_x == GTK_DATABOX_SCALE_LINEAR) if (priv->scale_type_x == GTK_DATABOX_SCALE_LINEAR)
return priv->visible_left + return priv->visible_left +
pixel / priv->translation_factor_x; pixel / priv->translation_factor_x;
else if (priv->scale_type_x == GTK_DATABOX_SCALE_LOG2) else if (priv->scale_type_x == GTK_DATABOX_SCALE_LOG2)
return priv->visible_left * pow (2, return priv->visible_left * pow (2,
pixel / pixel /
priv-> priv->
translation_factor_x); translation_factor_x);
else else
skipping to change at line 2232 skipping to change at line 2396
* @box: A #GtkDatabox widget * @box: A #GtkDatabox widget
* @pixel: A vertical pixel coordinate * @pixel: A vertical pixel coordinate
* *
* Calculates the y value which is represented by the vertical @pixel coordinate . * Calculates the y value which is represented by the vertical @pixel coordinate .
* Pixel coordinates are relative to the top-left corner of the @box which is eq uivalent to (0,0). * Pixel coordinates are relative to the top-left corner of the @box which is eq uivalent to (0,0).
* *
* Return value: y value * Return value: y value
*/ */
gfloat gfloat
gtk_databox_pixel_to_value_y (GtkDatabox * box, gint16 pixel) { gtk_databox_pixel_to_value_y (GtkDatabox * box, gint16 pixel) {
GtkDataboxPrivate *priv = GTK_DATABOX_GET_PRIVATE(box); GtkDataboxPrivate *priv = gtk_databox_get_instance_private(box);
if (priv->scale_type_y == GTK_DATABOX_SCALE_LINEAR) if (priv->scale_type_y == GTK_DATABOX_SCALE_LINEAR)
return priv->visible_top + return priv->visible_top +
pixel / priv->translation_factor_y; pixel / priv->translation_factor_y;
else if (priv->scale_type_y == GTK_DATABOX_SCALE_LOG2) else if (priv->scale_type_y == GTK_DATABOX_SCALE_LOG2)
return priv->visible_top * pow (2, return priv->visible_top * pow (2,
pixel / pixel /
priv-> priv->
translation_factor_y); translation_factor_y);
else else
return priv->visible_top * pow (10, return priv->visible_top * pow (10,
pixel / pixel /
priv-> priv->
translation_factor_y); translation_factor_y);
} }
/** /**
* gtk_databox_create_box_with_scrollbars_and_rulers: * gtk_databox_create_box_with_scrollbars_and_rulers:
* @p_box: Will contain a pointer to a #GtkDatabox widget * @p_box: Will contain a pointer to a #GtkDatabox widget
* @p_table: Will contain a pointer to a #GtkTable widget * @p_grid: Will contain a pointer to a #GtkGrid widget
* @scrollbar_x: Whether to attach a horizontal scrollbar * @scrollbar_x: Whether to attach a horizontal scrollbar
* @scrollbar_y: Whether to attach a vertical scrollbar * @scrollbar_y: Whether to attach a vertical scrollbar
* @ruler_x: Whether to attach a horizontal ruler * @ruler_x: Whether to attach a horizontal ruler
* @ruler_y: Whether to attach a vertical ruler * @ruler_y: Whether to attach a vertical ruler
* *
* This is a convenience function which creates a #GtkDatabox widget in a * This is a convenience function which creates a #GtkDatabox widget in a
* GtkTable widget optionally accompanied by scrollbars and rulers. You only * GtkGrid widget optionally accompanied by scrollbars and rulers. You only
* have to fill in the data (gtk_databox_graph_add()) and adjust the limits * have to fill in the data (gtk_databox_graph_add()) and adjust the limits
* (gtk_databox_set_total_limits() or gtk_databox_auto_rescale()). * (gtk_databox_set_total_limits() or gtk_databox_auto_rescale()).
* *
* This function produces the default databox with rulers at the top left and * This function produces the default databox with rulers at the top left and
* scroll bars at the bottom right. * scroll bars at the bottom right.
* *
* Return value: #GtkGrid in the @p_grid object pointer.
*
* @see_also: gtk_databox_new(), gtk_databox_set_adjustment_x(), gtk_databox_set _adjustment_y(), gtk_databox_set_ruler_x(), gtk_databox_set_ruler_y() * @see_also: gtk_databox_new(), gtk_databox_set_adjustment_x(), gtk_databox_set _adjustment_y(), gtk_databox_set_ruler_x(), gtk_databox_set_ruler_y()
*/ */
void void
gtk_databox_create_box_with_scrollbars_and_rulers (GtkWidget ** p_box, gtk_databox_create_box_with_scrollbars_and_rulers (GtkWidget ** p_box,
GtkWidget ** p_table, GtkWidget ** p_grid,
gboolean scrollbar_x, gboolean scrollbar_x,
gboolean scrollbar_y, gboolean scrollbar_y,
gboolean ruler_x, gboolean ruler_x,
gboolean ruler_y) { gboolean ruler_y) {
/* create with rulers top left by default */ /* create with rulers top left by default */
gtk_databox_create_box_with_scrollbars_and_rulers_positioned (p_box, p_table , scrollbar_x, scrollbar_y, ruler_x, ruler_y, TRUE, TRUE); gtk_databox_create_box_with_scrollbars_and_rulers_positioned (p_box, p_grid, scrollbar_x, scrollbar_y, ruler_x, ruler_y, TRUE, TRUE);
} }
/** /**
* gtk_databox_create_box_with_scrollbars_and_rulers_positioned: * gtk_databox_create_box_with_scrollbars_and_rulers_positioned:
* @p_box: Will contain a pointer to a #GtkDatabox widget * @p_box: Will contain a pointer to a #GtkDatabox widget
* @p_table: Will contain a pointer to a #GtkTable widget * @p_grid: Will contain a pointer to a #GtkGrid widget
* @scrollbar_x: Whether to attach a horizontal scrollbar * @scrollbar_x: Whether to attach a horizontal scrollbar
* @scrollbar_y: Whether to attach a vertical scrollbar * @scrollbar_y: Whether to attach a vertical scrollbar
* @ruler_x: Whether to attach a horizontal ruler * @ruler_x: Whether to attach a horizontal ruler
* @ruler_y: Whether to attach a vertical ruler * @ruler_y: Whether to attach a vertical ruler
* @ruler_x_top: Whether to put the ruler_x up the top * @ruler_x_top: Whether to put the ruler_x up the top
* @ruler_y_left: Whether to put the ruler_y on the left * @ruler_y_left: Whether to put the ruler_y on the left
* *
* This is a convenience function which creates a #GtkDatabox widget in a * This is a convenience function which creates a #GtkDatabox widget in a
* GtkTable widget optionally accompanied by scrollbars and rulers. You only * GtkGrid widget optionally accompanied by scrollbars and rulers. You only
* have to fill in the data (gtk_databox_graph_add()) and adjust the limits * have to fill in the data (gtk_databox_graph_add()) and adjust the limits
* (gtk_databox_set_total_limits() or gtk_databox_auto_rescale()). * (gtk_databox_set_total_limits() or gtk_databox_auto_rescale()).
* *
* This function produces the default databox with rulers at the top left and * This function produces the default databox with rulers at the top left and
* scroll bars at the bottom right. * scroll bars at the bottom right.
* *
* Return value: #GtkGrid in the @p_grid object pointer.
*
* @see_also: gtk_databox_new(), gtk_databox_set_adjustment_x(), gtk_databox_set _adjustment_y(), gtk_databox_set_ruler_x(), gtk_databox_set_ruler_y(), gtk_datab ox_create_box_with_scrollbars_and_rulers() * @see_also: gtk_databox_new(), gtk_databox_set_adjustment_x(), gtk_databox_set _adjustment_y(), gtk_databox_set_ruler_x(), gtk_databox_set_ruler_y(), gtk_datab ox_create_box_with_scrollbars_and_rulers()
*/ */
void void
gtk_databox_create_box_with_scrollbars_and_rulers_positioned (GtkWidget ** p_box , gtk_databox_create_box_with_scrollbars_and_rulers_positioned (GtkWidget ** p_box ,
GtkWidget ** p_table, GtkWidget ** p_grid,
gboolean scrollbar_x, gboolean scrollbar_x,
gboolean scrollbar_y, gboolean scrollbar_y,
gboolean ruler_x, gboolean ruler_x,
gboolean ruler_y, gboolean ruler_y,
gboolean ruler_x_top, gboolean ruler_x_top,
gboolean ruler_y_left) { gboolean ruler_y_left) {
GtkTable *table; GtkGrid *grid;
GtkDatabox *box; GtkDatabox *box;
GtkWidget *scrollbar; GtkWidget *scrollbar;
GtkWidget *ruler; GtkWidget *ruler;
gint left_col, top_row;
GtkDataboxPrivate *priv; GtkDataboxPrivate *priv;
gint left_col, right_col, top_row, bot_row;
*p_table = gtk_table_new (3, 3, FALSE); *p_grid = gtk_grid_new ();
*p_box = gtk_databox_new (); *p_box = gtk_databox_new ();
box = GTK_DATABOX (*p_box); box = GTK_DATABOX (*p_box);
table = GTK_TABLE (*p_table); grid = GTK_GRID (*p_grid);
priv = GTK_DATABOX_GET_PRIVATE(box); priv = gtk_databox_get_instance_private(box);
left_col=1; left_col=1;
right_col=2;
top_row=1; top_row=1;
bot_row=2; gtk_grid_attach (grid, GTK_WIDGET (box), left_col, top_row, 1, 1);
gtk_table_attach (table, GTK_WIDGET (box), left_col, right_col, top_row, bot
_row,
GTK_FILL | GTK_EXPAND | GTK_SHRINK,
GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 0);
if (scrollbar_x) { if (scrollbar_x) {
scrollbar = gtk_hscrollbar_new (NULL); scrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, NULL);
gtk_databox_set_adjustment_x (box, gtk_databox_set_adjustment_x (box,
gtk_range_get_adjustment (GTK_RANGE gtk_range_get_adjustment (GTK_RANGE
(scrollbar))); (scrollbar)));
if (ruler_x_top) { if (ruler_x_top) {
left_col=1; left_col=1;
right_col=2;
top_row=2; top_row=2;
bot_row=3;
} else { } else {
left_col=1; left_col=1;
right_col=2;
top_row=0; top_row=0;
bot_row=1;
} }
gtk_table_attach (table, scrollbar, left_col, right_col, top_row, bot_ro gtk_grid_attach (grid, scrollbar, left_col, top_row, 1, 1);
w,
GTK_FILL | GTK_EXPAND | GTK_SHRINK, GTK_FILL, 0, 0);
} }
if (scrollbar_y) { if (scrollbar_y) {
scrollbar = gtk_vscrollbar_new (NULL); scrollbar = gtk_scrollbar_new (GTK_ORIENTATION_VERTICAL, NULL);
gtk_databox_set_adjustment_y (box, gtk_databox_set_adjustment_y (box,
gtk_range_get_adjustment (GTK_RANGE gtk_range_get_adjustment (GTK_RANGE
(scrollbar))); (scrollbar)));
if (ruler_y_left) { if (ruler_y_left) {
left_col=2; left_col=2;
right_col=3;
top_row=1; top_row=1;
bot_row=2;
} else { } else {
left_col=0; left_col=0;
right_col=1;
top_row=1; top_row=1;
bot_row=2;
} }
gtk_table_attach (table, scrollbar, left_col, right_col, top_row, bot_ro gtk_grid_attach (grid, scrollbar, left_col, top_row, 1, 1);
w,
GTK_FILL, GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 0);
} }
if (ruler_x) { if (ruler_x) {
ruler = gtk_databox_ruler_new (GTK_ORIENTATION_HORIZONTAL); ruler = gtk_databox_ruler_new (GTK_ORIENTATION_HORIZONTAL);
gtk_databox_ruler_set_scale_type (GTK_DATABOX_RULER (ruler), gtk_databox_ruler_set_scale_type (GTK_DATABOX_RULER (ruler),
priv->scale_type_x); priv->scale_type_x);
if (ruler_x_top) { if (ruler_x_top) {
left_col=1; left_col=1;
right_col=2;
top_row=0; top_row=0;
bot_row=1;
} else { } else {
gtk_databox_ruler_set_invert_edge(GTK_DATABOX_RULER(ruler), TRUE); / * set the ruler to reverse its edge */ gtk_databox_ruler_set_invert_edge(GTK_DATABOX_RULER(ruler), TRUE); / * set the ruler to reverse its edge */
left_col=1; left_col=1;
right_col=2;
top_row=2; top_row=2;
bot_row=3;
} }
gtk_table_attach (table, ruler, left_col, right_col, top_row, bot_row, gtk_grid_attach (grid, ruler, left_col, top_row, 1, 1);
GTK_FILL | GTK_EXPAND | GTK_SHRINK, GTK_FILL, 0, 0);
gtk_databox_set_ruler_x (box, GTK_DATABOX_RULER (ruler)); gtk_databox_set_ruler_x (box, GTK_DATABOX_RULER (ruler));
} }
if (ruler_y) { if (ruler_y) {
ruler = gtk_databox_ruler_new (GTK_ORIENTATION_VERTICAL); ruler = gtk_databox_ruler_new (GTK_ORIENTATION_VERTICAL);
gtk_databox_ruler_set_scale_type (GTK_DATABOX_RULER (ruler), gtk_databox_ruler_set_scale_type (GTK_DATABOX_RULER (ruler),
priv->scale_type_y); priv->scale_type_y);
if (ruler_y_left) { if (ruler_y_left) {
left_col=0; left_col=0;
right_col=1;
top_row=1; top_row=1;
bot_row=2;
} else { } else {
gtk_databox_ruler_set_invert_edge(GTK_DATABOX_RULER(ruler), TRUE); / * set the ruler to reverse its edge */ gtk_databox_ruler_set_invert_edge(GTK_DATABOX_RULER(ruler), TRUE); / * set the ruler to reverse its edge */
left_col=2; left_col=2;
right_col=3;
top_row=1; top_row=1;
bot_row=2;
} }
gtk_table_attach (table, ruler, left_col, right_col, top_row, bot_row, gtk_grid_attach (grid, ruler, left_col, top_row, 1, 1);
GTK_FILL, GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 0);
gtk_databox_set_ruler_y (box, GTK_DATABOX_RULER (ruler)); gtk_databox_set_ruler_y (box, GTK_DATABOX_RULER (ruler));
} }
} }
 End of changes. 200 change blocks. 
438 lines changed or deleted 595 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)