Commit 4283c9de authored by Owen Taylor's avatar Owen Taylor Committed by Owen Taylor

A few more GPOINTER_TO_UINT fixes.

Wed May 13 00:53:52 1998  Owen Taylor  <otaylor@gtk.org>

	* gtk/gtktypeutils.c gtk/gtksignal.c: A few more
	  GPOINTER_TO_UINT fixes.

	* gtk/gtksignal.c: Include <string.h> for memset.

Tue May 12 23:10:53 1998  Owen Taylor  <otaylor@gtk.org>
	(Maximilian Bisani <bisani@kawo2.rwth-aachen.de>: gtk-bisani-980320-0)

	* gtk/gtkvruler.c gtk/gtkhruler.c gtk/gtkruler.h:
	Cleanups, comments and the ability to have rulers with
	a reversed direction.
parent 43dfe74c
Wed May 13 00:53:52 1998 Owen Taylor <otaylor@gtk.org>
* gtk/gtktypeutils.c gtk/gtksignal.c: A few more
GPOINTER_TO_UINT fixes.
* gtk/gtksignal.c: Include <string.h> for memset.
Tue May 12 23:10:53 1998 Owen Taylor <otaylor@gtk.org>
(Maximilian Bisani <bisani@kawo2.rwth-aachen.de>: gtk-bisani-980320-0)
* gtk/gtkvruler.c gtk/gtkhruler.c gtk/gtkruler.h:
Cleanups, comments and the ability to have rulers with
a reversed direction.
Tue May 12 19:37:55 1998 Owen Taylor <otaylor@gtk.org>
* gtk/gtkrc.c (gtk_rc_parse_file): Fixed up a stat()
......
Wed May 13 00:53:52 1998 Owen Taylor <otaylor@gtk.org>
* gtk/gtktypeutils.c gtk/gtksignal.c: A few more
GPOINTER_TO_UINT fixes.
* gtk/gtksignal.c: Include <string.h> for memset.
Tue May 12 23:10:53 1998 Owen Taylor <otaylor@gtk.org>
(Maximilian Bisani <bisani@kawo2.rwth-aachen.de>: gtk-bisani-980320-0)
* gtk/gtkvruler.c gtk/gtkhruler.c gtk/gtkruler.h:
Cleanups, comments and the ability to have rulers with
a reversed direction.
Tue May 12 19:37:55 1998 Owen Taylor <otaylor@gtk.org>
* gtk/gtkrc.c (gtk_rc_parse_file): Fixed up a stat()
......
Wed May 13 00:53:52 1998 Owen Taylor <otaylor@gtk.org>
* gtk/gtktypeutils.c gtk/gtksignal.c: A few more
GPOINTER_TO_UINT fixes.
* gtk/gtksignal.c: Include <string.h> for memset.
Tue May 12 23:10:53 1998 Owen Taylor <otaylor@gtk.org>
(Maximilian Bisani <bisani@kawo2.rwth-aachen.de>: gtk-bisani-980320-0)
* gtk/gtkvruler.c gtk/gtkhruler.c gtk/gtkruler.h:
Cleanups, comments and the ability to have rulers with
a reversed direction.
Tue May 12 19:37:55 1998 Owen Taylor <otaylor@gtk.org>
* gtk/gtkrc.c (gtk_rc_parse_file): Fixed up a stat()
......
Wed May 13 00:53:52 1998 Owen Taylor <otaylor@gtk.org>
* gtk/gtktypeutils.c gtk/gtksignal.c: A few more
GPOINTER_TO_UINT fixes.
* gtk/gtksignal.c: Include <string.h> for memset.
Tue May 12 23:10:53 1998 Owen Taylor <otaylor@gtk.org>
(Maximilian Bisani <bisani@kawo2.rwth-aachen.de>: gtk-bisani-980320-0)
* gtk/gtkvruler.c gtk/gtkhruler.c gtk/gtkruler.h:
Cleanups, comments and the ability to have rulers with
a reversed direction.
Tue May 12 19:37:55 1998 Owen Taylor <otaylor@gtk.org>
* gtk/gtkrc.c (gtk_rc_parse_file): Fixed up a stat()
......
Wed May 13 00:53:52 1998 Owen Taylor <otaylor@gtk.org>
* gtk/gtktypeutils.c gtk/gtksignal.c: A few more
GPOINTER_TO_UINT fixes.
* gtk/gtksignal.c: Include <string.h> for memset.
Tue May 12 23:10:53 1998 Owen Taylor <otaylor@gtk.org>
(Maximilian Bisani <bisani@kawo2.rwth-aachen.de>: gtk-bisani-980320-0)
* gtk/gtkvruler.c gtk/gtkhruler.c gtk/gtkruler.h:
Cleanups, comments and the ability to have rulers with
a reversed direction.
Tue May 12 19:37:55 1998 Owen Taylor <otaylor@gtk.org>
* gtk/gtkrc.c (gtk_rc_parse_file): Fixed up a stat()
......
Wed May 13 00:53:52 1998 Owen Taylor <otaylor@gtk.org>
* gtk/gtktypeutils.c gtk/gtksignal.c: A few more
GPOINTER_TO_UINT fixes.
* gtk/gtksignal.c: Include <string.h> for memset.
Tue May 12 23:10:53 1998 Owen Taylor <otaylor@gtk.org>
(Maximilian Bisani <bisani@kawo2.rwth-aachen.de>: gtk-bisani-980320-0)
* gtk/gtkvruler.c gtk/gtkhruler.c gtk/gtkruler.h:
Cleanups, comments and the ability to have rulers with
a reversed direction.
Tue May 12 19:37:55 1998 Owen Taylor <otaylor@gtk.org>
* gtk/gtkrc.c (gtk_rc_parse_file): Fixed up a stat()
......
Wed May 13 00:53:52 1998 Owen Taylor <otaylor@gtk.org>
* gtk/gtktypeutils.c gtk/gtksignal.c: A few more
GPOINTER_TO_UINT fixes.
* gtk/gtksignal.c: Include <string.h> for memset.
Tue May 12 23:10:53 1998 Owen Taylor <otaylor@gtk.org>
(Maximilian Bisani <bisani@kawo2.rwth-aachen.de>: gtk-bisani-980320-0)
* gtk/gtkvruler.c gtk/gtkhruler.c gtk/gtkruler.h:
Cleanups, comments and the ability to have rulers with
a reversed direction.
Tue May 12 19:37:55 1998 Owen Taylor <otaylor@gtk.org>
* gtk/gtkrc.c (gtk_rc_parse_file): Fixed up a stat()
......
......@@ -132,98 +132,112 @@ gtk_hruler_draw_ticks (GtkRuler *ruler)
gint xthickness;
gint ythickness;
gint length, ideal_length;
gfloat lower, upper; /* Upper and lower limits, in ruler units */
gfloat increment; /* Number of pixels per unit */
gint scale; /* Number of units per major unit */
gfloat subd_incr;
gfloat step_incr;
gfloat increment;
gfloat start, end, cur;
gchar unit_str[32];
gint text_height;
gint digit_height;
gint text_width;
gint pos;
gint scale;
g_return_if_fail (ruler != NULL);
g_return_if_fail (GTK_IS_HRULER (ruler));
if (GTK_WIDGET_DRAWABLE (ruler))
{
widget = GTK_WIDGET (ruler);
if (!GTK_WIDGET_DRAWABLE (ruler))
return;
gc = widget->style->fg_gc[GTK_STATE_NORMAL];
bg_gc = widget->style->bg_gc[GTK_STATE_NORMAL];
font = widget->style->font;
xthickness = widget->style->klass->xthickness;
ythickness = widget->style->klass->ythickness;
digit_height = font->ascent; /* assume descent == 0? */
widget = GTK_WIDGET (ruler);
width = widget->allocation.width;
height = widget->allocation.height - ythickness * 2;
gdk_draw_line (ruler->backing_store, gc,
xthickness,
height + ythickness,
widget->allocation.width - xthickness,
height + ythickness);
if ((ruler->upper - ruler->lower) == 0)
return;
increment = (gfloat) width * ruler->metric->pixels_per_unit / (ruler->upper - ruler->lower);
/* determine the scale
* use the maximum extents of the ruler to determine the largest possible
* number to be displayed. calculate the height in pixels of this displayed
* text as for the vertical ruler case. use this height to find a scale
* which leaves sufficient room for drawing the ruler.
*/
scale = ceil (ruler->max_size / ruler->metric->pixels_per_unit);
sprintf (unit_str, "%d", scale);
text_height = strlen (unit_str) * digit_height + 1;
gc = widget->style->fg_gc[GTK_STATE_NORMAL];
bg_gc = widget->style->bg_gc[GTK_STATE_NORMAL];
font = widget->style->font;
xthickness = widget->style->klass->xthickness;
ythickness = widget->style->klass->ythickness;
digit_height = font->ascent; /* assume descent == 0 ? */
width = widget->allocation.width;
height = widget->allocation.height - ythickness * 2;
gdk_draw_line (ruler->backing_store, gc,
xthickness,
height + ythickness,
widget->allocation.width - xthickness,
height + ythickness);
upper = ruler->upper / ruler->metric->pixels_per_unit;
lower = ruler->lower / ruler->metric->pixels_per_unit;
for (scale = 0; scale < MAXIMUM_SCALES; scale++)
if (ruler->metric->ruler_scale[scale] * increment > 2 * text_height)
break;
if ((upper - lower) == 0)
return;
increment = (gfloat) width / (upper - lower);
if (scale == MAXIMUM_SCALES)
scale = MAXIMUM_SCALES - 1;
/* determine the scale
* We calculate the text size as for the vruler instead of using
* text_width = gdk_string_width(font, unit_str), so that the result
* for the scale looks consistent with an accompanying vruler
*/
scale = ceil (ruler->max_size / ruler->metric->pixels_per_unit);
sprintf (unit_str, "%d", scale);
text_width = strlen (unit_str) * digit_height + 1;
length = 0;
for (i = MAXIMUM_SUBDIVIDE - 1; i >= 0; i--)
for (scale = 0; scale < MAXIMUM_SCALES; scale++)
if (ruler->metric->ruler_scale[scale] * fabs(increment) > 2 * text_width)
break;
if (scale == MAXIMUM_SCALES)
scale = MAXIMUM_SCALES - 1;
/* drawing starts here */
length = 0;
for (i = MAXIMUM_SUBDIVIDE - 1; i >= 0; i--)
{
subd_incr = (gfloat) ruler->metric->ruler_scale[scale] /
(gfloat) ruler->metric->subdivide[i];
if (subd_incr * fabs(increment) <= MINIMUM_INCR)
continue;
/* Calculate the length of the tickmarks. Make sure that
* this length increases for each set of ticks
*/
ideal_length = height / (i + 1) - 1;
if (ideal_length > ++length)
length = ideal_length;
if (lower < upper)
{
subd_incr = (gfloat) ruler->metric->ruler_scale[scale] / (gfloat) ruler->metric->subdivide[i];
step_incr = subd_incr * increment;
if (step_incr <= MINIMUM_INCR)
continue;
start = floor ((ruler->lower / ruler->metric->pixels_per_unit) / subd_incr) * subd_incr;
end = ceil ((ruler->upper / ruler->metric->pixels_per_unit) / subd_incr) * subd_incr;
ideal_length = height / (i + 1) - 1;
if (ideal_length > ++length)
length = ideal_length;
cur = start;
while (cur <= end)
start = floor (lower / subd_incr) * subd_incr;
end = ceil (upper / subd_incr) * subd_incr;
}
else
{
start = floor (upper / subd_incr) * subd_incr;
end = ceil (lower / subd_incr) * subd_incr;
}
for (cur = start; cur <= end; cur += subd_incr)
{
pos = ROUND ((cur - lower) * increment);
gdk_draw_line (ruler->backing_store, gc,
pos, height + ythickness,
pos, height - length + ythickness);
/* draw label */
if (i == 0)
{
pos = ROUND ((cur - (ruler->lower / ruler->metric->pixels_per_unit)) * increment);
gdk_draw_line (ruler->backing_store, gc,
pos, height + ythickness, pos,
height - length + ythickness);
if (i == 0)
{
sprintf (unit_str, "%d", (int) cur);
gdk_draw_rectangle (ruler->backing_store,
bg_gc, TRUE,
pos + 1, ythickness,
gdk_string_width(font, unit_str) + 1,
digit_height);
gdk_draw_string (ruler->backing_store, font, gc,
pos + 2, ythickness + font->ascent - 1,
unit_str);
}
cur += subd_incr;
sprintf (unit_str, "%d", (int) cur);
gdk_draw_rectangle (ruler->backing_store,
bg_gc, TRUE,
pos + 1, ythickness,
gdk_string_width(font, unit_str) + 1,
digit_height);
gdk_draw_string (ruler->backing_store, font, gc,
pos + 2, ythickness + font->ascent - 1,
unit_str);
}
}
}
......
......@@ -38,6 +38,9 @@ typedef struct _GtkRuler GtkRuler;
typedef struct _GtkRulerClass GtkRulerClass;
typedef struct _GtkRulerMetric GtkRulerMetric;
/* All distances below are in 1/72nd's of an inch. (According to
* Adobe that's a point, but points are really 1/72.27 in.)
*/
struct _GtkRuler
{
GtkWidget widget;
......@@ -48,9 +51,13 @@ struct _GtkRuler
gint xsrc, ysrc;
gint slider_size;
/* The upper limit of the ruler (in points) */
gfloat lower;
/* The lower limit of the ruler */
gfloat upper;
/* The position of the mark on the ruler */
gfloat position;
/* The maximum size of the ruler */
gfloat max_size;
};
......@@ -66,6 +73,8 @@ struct _GtkRulerMetric
{
gchar *metric_name;
gchar *abbrev;
/* This should be points_per_unit. This is the size of the unit
* in 1/72nd's of an inch and has nothing to do with screen pixels */
gfloat pixels_per_unit;
gfloat ruler_scale[10];
gint subdivide[5]; /* five possible modes of subdivision */
......
......@@ -17,6 +17,7 @@
* Boston, MA 02111-1307, USA.
*/
#include <stdarg.h>
#include <string.h>
#include "gtksignal.h"
......@@ -322,7 +323,7 @@ gtk_signal_newv (const gchar *r_name,
hash->object_type = object_type;
hash->name_key_id = gtk_object_data_force_id (signal->name);
hash->signal_id = signal->signal_id;
g_hash_table_insert (gtk_signal_hash_table, hash, (gpointer) hash->signal_id);
g_hash_table_insert (gtk_signal_hash_table, hash, GUINT_TO_POINTER (hash->signal_id));
/* insert "signal-name" into hash table
*/
......@@ -334,7 +335,7 @@ gtk_signal_newv (const gchar *r_name,
hash->object_type = object_type;
hash->name_key_id = id;
hash->signal_id = signal->signal_id;
g_hash_table_insert (gtk_signal_hash_table, hash, (gpointer) hash->signal_id);
g_hash_table_insert (gtk_signal_hash_table, hash, GUINT_TO_POINTER (hash->signal_id));
}
return signal->signal_id;
......@@ -403,7 +404,7 @@ gtk_signal_lookup (const gchar *name,
hash.object_type = object_type;
signal_id = (guint) g_hash_table_lookup (gtk_signal_hash_table, &hash);
signal_id = GPOINTER_TO_UINT (g_hash_table_lookup (gtk_signal_hash_table, &hash));
if (signal_id)
return signal_id;
......
......@@ -175,7 +175,7 @@ gtk_type_unique (GtkType parent_type,
new_node->children_types = NULL;
if (parent)
parent->children_types = g_list_append (parent->children_types, (gpointer) new_node->type);
parent->children_types = g_list_append (parent->children_types, GUINT_TO_POINTER (new_node->type));
parent = new_node;
for (i = 0; i < new_node->n_supers + 1; i++)
......@@ -184,7 +184,7 @@ gtk_type_unique (GtkType parent_type,
LOOKUP_TYPE_NODE (parent, parent->parent_type);
}
g_hash_table_insert (type_name_2_type_ht, new_node->type_info.type_name, (gpointer) new_node->type);
g_hash_table_insert (type_name_2_type_ht, new_node->type_info.type_name, GUINT_TO_POINTER (new_node->type));
return new_node->type;
}
......@@ -209,7 +209,7 @@ gtk_type_from_name (const gchar *name)
{
GtkType type;
type = (GtkType) g_hash_table_lookup (type_name_2_type_ht, (gpointer) name);
type = GPOINTER_TO_UINT (g_hash_table_lookup (type_name_2_type_ht, (gpointer) name));
return type;
}
......@@ -354,7 +354,7 @@ gtk_type_describe_tree (GtkType type,
indent += 4;
for (list = node->children_types; list; list = list->next)
gtk_type_describe_tree ((GtkType) list->data, show_size);
gtk_type_describe_tree (GPOINTER_TO_UINT (list->data), show_size);
indent = old_indent;
}
......
......@@ -126,118 +126,130 @@ gtk_vruler_draw_ticks (GtkRuler *ruler)
{
GtkWidget *widget;
GdkGC *gc, *bg_gc;
GdkFont * font;
GdkFont *font;
gint i, j;
gint width, height;
gint xthickness;
gint ythickness;
gint length, ideal_length;
gfloat lower, upper; /* Upper and lower limits, in ruler units */
gfloat increment; /* Number of pixels per unit */
gint scale; /* Number of units per major unit */
gfloat subd_incr;
gfloat step_incr;
gfloat increment;
gfloat start, end, cur;
gchar unit_str[32];
gchar digit_str[2] = { '\0', '\0' };
gint text_height;
gint digit_height;
gint text_height;
gint pos;
gint scale;
g_return_if_fail (ruler != NULL);
g_return_if_fail (GTK_IS_VRULER (ruler));
if (GTK_WIDGET_DRAWABLE (ruler))
if (!GTK_WIDGET_DRAWABLE (ruler))
return;
widget = GTK_WIDGET (ruler);
gc = widget->style->fg_gc[GTK_STATE_NORMAL];
bg_gc = widget->style->bg_gc[GTK_STATE_NORMAL];
font = widget->style->font;
xthickness = widget->style->klass->xthickness;
ythickness = widget->style->klass->ythickness;
digit_height = font->ascent; /* assume descent == 0 ? */
width = widget->allocation.height;
height = widget->allocation.width - ythickness * 2;
gdk_draw_line (ruler->backing_store, gc,
height + xthickness,
ythickness,
height + xthickness,
widget->allocation.height - ythickness);
upper = ruler->upper / ruler->metric->pixels_per_unit;
lower = ruler->lower / ruler->metric->pixels_per_unit;
if ((upper - lower) == 0)
return;
increment = (gfloat) width / (upper - lower);
/* determine the scale
* use the maximum extents of the ruler to determine the largest
* possible number to be displayed. Calculate the height in pixels
* of this displayed text. Use this height to find a scale which
* leaves sufficient room for drawing the ruler.
*/
scale = ceil (ruler->max_size / ruler->metric->pixels_per_unit);
sprintf (unit_str, "%d", scale);
text_height = strlen (unit_str) * digit_height + 1;
for (scale = 0; scale < MAXIMUM_SCALES; scale++)
if (ruler->metric->ruler_scale[scale] * fabs(increment) > 2 * text_height)
break;
if (scale == MAXIMUM_SCALES)
scale = MAXIMUM_SCALES - 1;
/* drawing starts here */
length = 0;
for (i = MAXIMUM_SUBDIVIDE - 1; i >= 0; i--)
{
widget = GTK_WIDGET (ruler);
subd_incr = (gfloat) ruler->metric->ruler_scale[scale] /
(gfloat) ruler->metric->subdivide[i];
if (subd_incr * fabs(increment) <= MINIMUM_INCR)
continue;
gc = widget->style->fg_gc[GTK_STATE_NORMAL];
bg_gc = widget->style->bg_gc[GTK_STATE_NORMAL];
font = widget->style->font;
xthickness = widget->style->klass->xthickness;
ythickness = widget->style->klass->ythickness;
digit_height = font->ascent; /* Assume descent == 0 ? */
width = widget->allocation.height;
height = widget->allocation.width - ythickness * 2;
gdk_draw_line (ruler->backing_store, gc,
height + xthickness,
ythickness,
height + xthickness,
widget->allocation.height - ythickness);
if ((ruler->upper - ruler->lower) == 0)
return;
increment = (gfloat) width * ruler->metric->pixels_per_unit / (ruler->upper - ruler->lower);
/* determine the scale
* use the maximum extents of the ruler to determine the largest possible
* number to be displayed. calculate the height in pixels of this displayed
* text as for the vertical ruler case. use this height to find a scale
* which leaves sufficient room for drawing the ruler.
/* Calculate the length of the tickmarks. Make sure that
* this length increases for each set of ticks
*/
scale = ceil (ruler->max_size / ruler->metric->pixels_per_unit);
sprintf (unit_str, "%d", scale);
text_height = strlen (unit_str) * digit_height + 1;
for (scale = 0; scale < MAXIMUM_SCALES; scale++)
if (ruler->metric->ruler_scale[scale] * increment > 2 * text_height)
break;
ideal_length = height / (i + 1) - 1;
if (ideal_length > ++length)
length = ideal_length;
if (scale == MAXIMUM_SCALES)
scale = MAXIMUM_SCALES - 1;
length = 0;
for (i = MAXIMUM_SUBDIVIDE - 1; i >= 0; i--)
if (lower < upper)
{
start = floor (lower / subd_incr) * subd_incr;
end = ceil (upper / subd_incr) * subd_incr;
}
else
{
subd_incr = (gfloat) ruler->metric->ruler_scale[scale] / (gfloat) ruler->metric->subdivide[i];
step_incr = subd_incr * increment;
if (step_incr <= MINIMUM_INCR)
continue;
start = floor (upper / subd_incr) * subd_incr;
end = ceil (lower / subd_incr) * subd_incr;
}
start = floor ((ruler->lower / ruler->metric->pixels_per_unit) / subd_incr) * subd_incr;
end = ceil ((ruler->upper / ruler->metric->pixels_per_unit) / subd_incr) * subd_incr;
for (cur = start; cur <= end; cur += subd_incr)
{
pos = ROUND ((cur - lower) * increment);
ideal_length = height / (i + 1) - 1;
if (ideal_length > ++length)
length = ideal_length;
gdk_draw_line (ruler->backing_store, gc,
height + xthickness - length, pos,
height + xthickness, pos);
cur = start;
while (cur <= end)
/* draw label */
if (i == 0)
{
pos = ROUND ((cur - (ruler->lower / ruler->metric->pixels_per_unit)) * increment);
gdk_draw_line (ruler->backing_store, gc,
height + xthickness - length,
pos,
height + xthickness,
pos);
if (i == 0)
sprintf (unit_str, "%d", (int) cur);
for (j = 0; j < (int) strlen (unit_str); j++)
{
sprintf (unit_str, "%d", (int) cur);
for (j = 0; j < (int) strlen (unit_str); j++)
{
digit_str[0] = unit_str[j];
gdk_draw_rectangle (ruler->backing_store,
bg_gc, TRUE,
xthickness + 1,
pos + digit_height * j + 1,
gdk_string_width(font, digit_str),
digit_height);
gdk_draw_string (ruler->backing_store, font, gc,
xthickness + 1,
pos + digit_height * (j + 1) + 1,
digit_str);
}
digit_str[0] = unit_str[j];
gdk_draw_rectangle (ruler->backing_store,
bg_gc, TRUE,
xthickness + 1,
pos + digit_height * j + 1,
gdk_string_width(font, digit_str),
digit_height);
gdk_