mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-11 03:10:09 +00:00
gtk/gtkruler.c: use accessor functions to access GtkWidget
This commit is contained in:
parent
e4dc454f59
commit
a338d5dea5
115
gtk/gtkruler.c
115
gtk/gtkruler.c
@ -456,7 +456,9 @@ gtk_ruler_draw_pos (GtkRuler *ruler)
|
||||
static void
|
||||
gtk_ruler_realize (GtkWidget *widget)
|
||||
{
|
||||
GtkAllocation allocation;
|
||||
GtkRuler *ruler;
|
||||
GdkWindow *window;
|
||||
GdkWindowAttr attributes;
|
||||
gint attributes_mask;
|
||||
|
||||
@ -464,11 +466,13 @@ gtk_ruler_realize (GtkWidget *widget)
|
||||
|
||||
gtk_widget_set_realized (widget, TRUE);
|
||||
|
||||
gtk_widget_get_allocation (widget, &allocation);
|
||||
|
||||
attributes.window_type = GDK_WINDOW_CHILD;
|
||||
attributes.x = widget->allocation.x;
|
||||
attributes.y = widget->allocation.y;
|
||||
attributes.width = widget->allocation.width;
|
||||
attributes.height = widget->allocation.height;
|
||||
attributes.x = allocation.x;
|
||||
attributes.y = allocation.y;
|
||||
attributes.width = allocation.width;
|
||||
attributes.height = allocation.height;
|
||||
attributes.wclass = GDK_INPUT_OUTPUT;
|
||||
attributes.visual = gtk_widget_get_visual (widget);
|
||||
attributes.colormap = gtk_widget_get_colormap (widget);
|
||||
@ -479,11 +483,14 @@ gtk_ruler_realize (GtkWidget *widget)
|
||||
|
||||
attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
|
||||
|
||||
widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
|
||||
gdk_window_set_user_data (widget->window, ruler);
|
||||
window = gdk_window_new (gtk_widget_get_parent_window (widget),
|
||||
&attributes, attributes_mask);
|
||||
gtk_widget_set_window (widget, window);
|
||||
gdk_window_set_user_data (window, ruler);
|
||||
|
||||
widget->style = gtk_style_attach (widget->style, widget->window);
|
||||
gtk_style_set_background (widget->style, widget->window, GTK_STATE_ACTIVE);
|
||||
gtk_widget_style_attach (widget);
|
||||
gtk_style_set_background (gtk_widget_get_style (widget),
|
||||
window, GTK_STATE_ACTIVE);
|
||||
|
||||
gtk_ruler_make_pixmap (ruler);
|
||||
}
|
||||
@ -509,16 +516,19 @@ gtk_ruler_size_request (GtkWidget *widget,
|
||||
{
|
||||
GtkRuler *ruler = GTK_RULER (widget);
|
||||
GtkRulerPrivate *priv = ruler->priv;
|
||||
GtkStyle *style;
|
||||
|
||||
style = gtk_widget_get_style (widget);
|
||||
|
||||
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
|
||||
{
|
||||
requisition->width = widget->style->xthickness * 2 + 1;
|
||||
requisition->height = widget->style->ythickness * 2 + RULER_WIDTH;
|
||||
requisition->width = style->xthickness * 2 + 1;
|
||||
requisition->height = style->ythickness * 2 + RULER_WIDTH;
|
||||
}
|
||||
else
|
||||
{
|
||||
requisition->width = widget->style->xthickness * 2 + RULER_WIDTH;
|
||||
requisition->height = widget->style->ythickness * 2 + 1;
|
||||
requisition->width = style->xthickness * 2 + RULER_WIDTH;
|
||||
requisition->height = style->ythickness * 2 + 1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -528,11 +538,11 @@ gtk_ruler_size_allocate (GtkWidget *widget,
|
||||
{
|
||||
GtkRuler *ruler = GTK_RULER (widget);
|
||||
|
||||
widget->allocation = *allocation;
|
||||
gtk_widget_set_allocation (widget, allocation);
|
||||
|
||||
if (gtk_widget_get_realized (widget))
|
||||
{
|
||||
gdk_window_move_resize (widget->window,
|
||||
gdk_window_move_resize (gtk_widget_get_window (widget),
|
||||
allocation->x, allocation->y,
|
||||
allocation->width, allocation->height);
|
||||
|
||||
@ -544,6 +554,7 @@ static gboolean
|
||||
gtk_ruler_motion_notify (GtkWidget *widget,
|
||||
GdkEventMotion *event)
|
||||
{
|
||||
GtkAllocation allocation;
|
||||
GtkRuler *ruler = GTK_RULER (widget);
|
||||
GtkRulerPrivate *priv = ruler->priv;
|
||||
gint x;
|
||||
@ -553,10 +564,11 @@ gtk_ruler_motion_notify (GtkWidget *widget,
|
||||
x = event->x;
|
||||
y = event->y;
|
||||
|
||||
gtk_widget_get_allocation (widget, &allocation);
|
||||
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
|
||||
priv->position = priv->lower + ((priv->upper - priv->lower) * x) / widget->allocation.width;
|
||||
priv->position = priv->lower + ((priv->upper - priv->lower) * x) / allocation.width;
|
||||
else
|
||||
priv->position = priv->lower + ((priv->upper - priv->lower) * y) / widget->allocation.height;
|
||||
priv->position = priv->lower + ((priv->upper - priv->lower) * y) / allocation.height;
|
||||
|
||||
g_object_notify (G_OBJECT (ruler), "position");
|
||||
|
||||
@ -578,8 +590,8 @@ gtk_ruler_expose (GtkWidget *widget,
|
||||
cairo_t *cr;
|
||||
|
||||
gtk_ruler_draw_ticks (ruler);
|
||||
|
||||
cr = gdk_cairo_create (widget->window);
|
||||
|
||||
cr = gdk_cairo_create (gtk_widget_get_window (widget));
|
||||
gdk_cairo_set_source_pixmap (cr, priv->backing_store, 0, 0);
|
||||
gdk_cairo_rectangle (cr, &event->area);
|
||||
cairo_fill (cr);
|
||||
@ -595,25 +607,28 @@ static void
|
||||
gtk_ruler_make_pixmap (GtkRuler *ruler)
|
||||
{
|
||||
GtkRulerPrivate *priv = ruler->priv;
|
||||
GtkAllocation allocation;
|
||||
GtkWidget *widget;
|
||||
gint width;
|
||||
gint height;
|
||||
|
||||
widget = GTK_WIDGET (ruler);
|
||||
|
||||
gtk_widget_get_allocation (widget, &allocation);
|
||||
|
||||
if (priv->backing_store)
|
||||
{
|
||||
gdk_drawable_get_size (priv->backing_store, &width, &height);
|
||||
if ((width == widget->allocation.width) &&
|
||||
(height == widget->allocation.height))
|
||||
if ((width == allocation.width) &&
|
||||
(height == allocation.height))
|
||||
return;
|
||||
|
||||
g_object_unref (priv->backing_store);
|
||||
}
|
||||
|
||||
priv->backing_store = gdk_pixmap_new (widget->window,
|
||||
widget->allocation.width,
|
||||
widget->allocation.height,
|
||||
priv->backing_store = gdk_pixmap_new (gtk_widget_get_window (widget),
|
||||
allocation.width,
|
||||
allocation.height,
|
||||
-1);
|
||||
|
||||
priv->xsrc = 0;
|
||||
@ -623,8 +638,10 @@ gtk_ruler_make_pixmap (GtkRuler *ruler)
|
||||
static void
|
||||
gtk_ruler_real_draw_ticks (GtkRuler *ruler)
|
||||
{
|
||||
GtkAllocation allocation;
|
||||
GtkWidget *widget = GTK_WIDGET (ruler);
|
||||
GtkRulerPrivate *priv = ruler->priv;
|
||||
GtkStyle *style;
|
||||
cairo_t *cr;
|
||||
gint i, j;
|
||||
gint width, height;
|
||||
@ -648,8 +665,11 @@ gtk_ruler_real_draw_ticks (GtkRuler *ruler)
|
||||
if (!gtk_widget_is_drawable (widget))
|
||||
return;
|
||||
|
||||
xthickness = widget->style->xthickness;
|
||||
ythickness = widget->style->ythickness;
|
||||
style = gtk_widget_get_style (widget);
|
||||
gtk_widget_get_allocation (widget, &allocation);
|
||||
|
||||
xthickness = style->xthickness;
|
||||
ythickness = style->ythickness;
|
||||
|
||||
layout = gtk_widget_create_pango_layout (widget, "012456789");
|
||||
pango_layout_get_extents (layout, &ink_rect, &logical_rect);
|
||||
@ -659,34 +679,34 @@ gtk_ruler_real_draw_ticks (GtkRuler *ruler)
|
||||
|
||||
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
|
||||
{
|
||||
width = widget->allocation.width;
|
||||
height = widget->allocation.height - ythickness * 2;
|
||||
width = allocation.width;
|
||||
height = allocation.height - ythickness * 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
width = widget->allocation.height;
|
||||
height = widget->allocation.width - ythickness * 2;
|
||||
width = allocation.height;
|
||||
height = allocation.width - ythickness * 2;
|
||||
}
|
||||
|
||||
#define DETAILE(private) (priv->orientation == GTK_ORIENTATION_HORIZONTAL ? "hruler" : "vruler");
|
||||
|
||||
gtk_paint_box (widget->style, priv->backing_store,
|
||||
gtk_paint_box (style, priv->backing_store,
|
||||
GTK_STATE_NORMAL, GTK_SHADOW_OUT,
|
||||
NULL, widget,
|
||||
priv->orientation == GTK_ORIENTATION_HORIZONTAL ?
|
||||
"hruler" : "vruler",
|
||||
0, 0,
|
||||
widget->allocation.width, widget->allocation.height);
|
||||
allocation.width, allocation.height);
|
||||
|
||||
cr = gdk_cairo_create (priv->backing_store);
|
||||
gdk_cairo_set_source_color (cr, &widget->style->fg[widget->state]);
|
||||
gdk_cairo_set_source_color (cr, &style->fg[gtk_widget_get_state (widget)]);
|
||||
|
||||
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
|
||||
{
|
||||
cairo_rectangle (cr,
|
||||
xthickness,
|
||||
height + ythickness,
|
||||
widget->allocation.width - 2 * xthickness,
|
||||
allocation.width - 2 * xthickness,
|
||||
1);
|
||||
}
|
||||
else
|
||||
@ -695,7 +715,7 @@ gtk_ruler_real_draw_ticks (GtkRuler *ruler)
|
||||
height + xthickness,
|
||||
ythickness,
|
||||
1,
|
||||
widget->allocation.height - 2 * ythickness);
|
||||
allocation.height - 2 * ythickness);
|
||||
}
|
||||
|
||||
upper = priv->upper / priv->metric->pixels_per_unit;
|
||||
@ -793,7 +813,7 @@ gtk_ruler_real_draw_ticks (GtkRuler *ruler)
|
||||
pango_layout_set_text (layout, unit_str, -1);
|
||||
pango_layout_get_extents (layout, &logical_rect, NULL);
|
||||
|
||||
gtk_paint_layout (widget->style,
|
||||
gtk_paint_layout (style,
|
||||
priv->backing_store,
|
||||
gtk_widget_get_state (widget),
|
||||
FALSE,
|
||||
@ -810,7 +830,7 @@ gtk_ruler_real_draw_ticks (GtkRuler *ruler)
|
||||
pango_layout_set_text (layout, unit_str + j, 1);
|
||||
pango_layout_get_extents (layout, NULL, &logical_rect);
|
||||
|
||||
gtk_paint_layout (widget->style,
|
||||
gtk_paint_layout (style,
|
||||
priv->backing_store,
|
||||
gtk_widget_get_state (widget),
|
||||
FALSE,
|
||||
@ -836,8 +856,10 @@ out:
|
||||
static void
|
||||
gtk_ruler_real_draw_pos (GtkRuler *ruler)
|
||||
{
|
||||
GtkAllocation allocation;
|
||||
GtkWidget *widget = GTK_WIDGET (ruler);
|
||||
GtkRulerPrivate *priv = ruler->priv;
|
||||
GtkStyle *style;
|
||||
gint x, y;
|
||||
gint width, height;
|
||||
gint bs_width, bs_height;
|
||||
@ -847,10 +869,13 @@ gtk_ruler_real_draw_pos (GtkRuler *ruler)
|
||||
|
||||
if (gtk_widget_is_drawable (widget))
|
||||
{
|
||||
xthickness = widget->style->xthickness;
|
||||
ythickness = widget->style->ythickness;
|
||||
width = widget->allocation.width;
|
||||
height = widget->allocation.height;
|
||||
style = gtk_widget_get_style (widget);
|
||||
gtk_widget_get_allocation (widget, &allocation);
|
||||
|
||||
xthickness = style->xthickness;
|
||||
ythickness = style->ythickness;
|
||||
width = allocation.width;
|
||||
height = allocation.height;
|
||||
|
||||
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
|
||||
{
|
||||
@ -871,11 +896,15 @@ gtk_ruler_real_draw_pos (GtkRuler *ruler)
|
||||
|
||||
if ((bs_width > 0) && (bs_height > 0))
|
||||
{
|
||||
cairo_t *cr = gdk_cairo_create (widget->window);
|
||||
GdkWindow *window;
|
||||
|
||||
window = gtk_widget_get_window (widget);
|
||||
|
||||
cairo_t *cr = gdk_cairo_create (window);
|
||||
|
||||
/* If a backing store exists, restore the ruler */
|
||||
if (priv->backing_store) {
|
||||
cairo_t *cr = gdk_cairo_create (widget->window);
|
||||
cairo_t *cr = gdk_cairo_create (window);
|
||||
|
||||
gdk_cairo_set_source_pixmap (cr, priv->backing_store, 0, 0);
|
||||
cairo_rectangle (cr, priv->xsrc, priv->ysrc, bs_width, bs_height);
|
||||
@ -899,7 +928,7 @@ gtk_ruler_real_draw_pos (GtkRuler *ruler)
|
||||
y = ROUND ((priv->position - priv->lower) * increment) + (ythickness - bs_height) / 2 - 1;
|
||||
}
|
||||
|
||||
gdk_cairo_set_source_color (cr, &widget->style->fg[widget->state]);
|
||||
gdk_cairo_set_source_color (cr, &style->fg[gtk_widget_get_state (widget)]);
|
||||
|
||||
cairo_move_to (cr, x, y);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user