X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=gtk%2Fgtkarrow.c;h=fedf544b5e9e59fc6c2297ae12f7d1b7cd3f1d8b;hb=4bb90a74433d2d38dcf63a2dbc549f549b51c3c3;hp=414fc18bdc016a3a18289515a68b7d0f2862b105;hpb=f8cfb895ed7d6e064ad45e6628986fda00809fda;p=~andy%2Fgtk diff --git a/gtk/gtkarrow.c b/gtk/gtkarrow.c index 414fc18bd..fedf544b5 100644 --- a/gtk/gtkarrow.c +++ b/gtk/gtkarrow.c @@ -12,9 +12,7 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * License along with this library. If not, see . */ /* @@ -28,7 +26,7 @@ * SECTION:gtkarrow * @Short_description: Displays an arrow * @Title: GtkArrow - * @See_also: gtk_paint_arrow() + * @See_also: gtk_render_arrow() * * GtkArrow should be used to draw simple arrows that need to point in * one of the four cardinal directions (up, down, left, or right). The @@ -48,9 +46,12 @@ #include #include "gtkarrow.h" #include "gtksizerequest.h" +#include "gtktypebuiltins.h" #include "gtkprivate.h" #include "gtkintl.h" +#include "a11y/gtkarrowaccessible.h" + #define MIN_ARROW_SIZE 15 struct _GtkArrowPrivate @@ -74,20 +75,17 @@ static void gtk_arrow_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); -static gboolean gtk_arrow_expose (GtkWidget *widget, - GdkEventExpose *event); +static gboolean gtk_arrow_draw (GtkWidget *widget, + cairo_t *cr); -static void gtk_arrow_size_request_init (GtkSizeRequestIface *iface); -static void gtk_arrow_get_width (GtkSizeRequest *widget, - gint *minimum_size, - gint *natural_size); -static void gtk_arrow_get_height (GtkSizeRequest *widget, - gint *minimum_size, - gint *natural_size); +static void gtk_arrow_get_preferred_width (GtkWidget *widget, + gint *minimum_size, + gint *natural_size); +static void gtk_arrow_get_preferred_height (GtkWidget *widget, + gint *minimum_size, + gint *natural_size); -G_DEFINE_TYPE_WITH_CODE (GtkArrow, gtk_arrow, GTK_TYPE_MISC, - G_IMPLEMENT_INTERFACE (GTK_TYPE_SIZE_REQUEST, - gtk_arrow_size_request_init)) +G_DEFINE_TYPE (GtkArrow, gtk_arrow, GTK_TYPE_MISC) static void @@ -102,7 +100,9 @@ gtk_arrow_class_init (GtkArrowClass *class) gobject_class->set_property = gtk_arrow_set_property; gobject_class->get_property = gtk_arrow_get_property; - widget_class->expose_event = gtk_arrow_expose; + widget_class->draw = gtk_arrow_draw; + widget_class->get_preferred_width = gtk_arrow_get_preferred_width; + widget_class->get_preferred_height = gtk_arrow_get_preferred_height; g_object_class_install_property (gobject_class, PROP_ARROW_TYPE, @@ -130,6 +130,8 @@ gtk_arrow_class_init (GtkArrowClass *class) GTK_PARAM_READABLE)); g_type_class_add_private (class, sizeof (GtkArrowPrivate)); + + gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_ARROW_ACCESSIBLE); } static void @@ -199,45 +201,37 @@ gtk_arrow_init (GtkArrow *arrow) } static void -gtk_arrow_size_request_init (GtkSizeRequestIface *iface) +gtk_arrow_get_preferred_width (GtkWidget *widget, + gint *minimum_size, + gint *natural_size) { - iface->get_width = gtk_arrow_get_width; - iface->get_height = gtk_arrow_get_height; -} + GtkBorder border; -static void -gtk_arrow_get_width (GtkSizeRequest *widget, - gint *minimum_size, - gint *natural_size) -{ - gint xpad; - - gtk_misc_get_padding (GTK_MISC (widget), &xpad, NULL); + _gtk_misc_get_padding_and_border (GTK_MISC (widget), &border); if (minimum_size) - *minimum_size = MIN_ARROW_SIZE + xpad * 2; + *minimum_size = MIN_ARROW_SIZE + border.left + border.right; if (natural_size) - *natural_size = MIN_ARROW_SIZE + xpad * 2; + *natural_size = MIN_ARROW_SIZE + border.left + border.right; } static void -gtk_arrow_get_height (GtkSizeRequest *widget, - gint *minimum_size, - gint *natural_size) +gtk_arrow_get_preferred_height (GtkWidget *widget, + gint *minimum_size, + gint *natural_size) { - gint ypad; + GtkBorder border; - gtk_misc_get_padding (GTK_MISC (widget), NULL, &ypad); + _gtk_misc_get_padding_and_border (GTK_MISC (widget), &border); if (minimum_size) - *minimum_size = MIN_ARROW_SIZE + ypad * 2; + *minimum_size = MIN_ARROW_SIZE + border.top + border.bottom; if (natural_size) - *natural_size = MIN_ARROW_SIZE + ypad * 2; + *natural_size = MIN_ARROW_SIZE + border.top + border.bottom; } - /** * gtk_arrow_new: * @arrow_type: a valid #GtkArrowType. @@ -309,73 +303,67 @@ gtk_arrow_set (GtkArrow *arrow, } } - static gboolean -gtk_arrow_expose (GtkWidget *widget, - GdkEventExpose *event) +gtk_arrow_draw (GtkWidget *widget, + cairo_t *cr) { - if (gtk_widget_is_drawable (widget)) + GtkArrow *arrow = GTK_ARROW (widget); + GtkArrowPrivate *priv = arrow->priv; + GtkStyleContext *context; + gdouble x, y; + gint width, height; + gint extent; + GtkBorder border; + gfloat xalign, yalign; + GtkArrowType effective_arrow_type; + gfloat arrow_scaling; + gdouble angle; + + if (priv->arrow_type == GTK_ARROW_NONE) + return FALSE; + + context = gtk_widget_get_style_context (widget); + gtk_widget_style_get (widget, "arrow-scaling", &arrow_scaling, NULL); + + _gtk_misc_get_padding_and_border (GTK_MISC (widget), &border); + gtk_misc_get_alignment (GTK_MISC (widget), &xalign, &yalign); + + width = gtk_widget_get_allocated_width (widget) - border.left - border.right; + height = gtk_widget_get_allocated_height (widget) - border.top - border.bottom; + + extent = MIN (width, height) * arrow_scaling; + effective_arrow_type = priv->arrow_type; + + if (gtk_widget_get_direction (widget) != GTK_TEXT_DIR_LTR) { - GtkArrow *arrow = GTK_ARROW (widget); - GtkArrowPrivate *priv = arrow->priv; - GtkAllocation allocation; - GtkMisc *misc = GTK_MISC (widget); - GtkShadowType shadow_type; - GtkStateType state; - gint width, height; - gint x, y; - gint extent; - gint xpad, ypad; - gfloat xalign, yalign; - GtkArrowType effective_arrow_type; - gfloat arrow_scaling; - - gtk_widget_style_get (widget, "arrow-scaling", &arrow_scaling, NULL); - - gtk_widget_get_allocation (widget, &allocation); - gtk_misc_get_padding (misc, &xpad, &ypad); - gtk_misc_get_alignment (misc, &xalign, &yalign); - - width = allocation.width - xpad * 2; - height = allocation.height - ypad * 2; - extent = MIN (width, height) * arrow_scaling; - effective_arrow_type = priv->arrow_type; - - if (gtk_widget_get_direction (widget) != GTK_TEXT_DIR_LTR) - { - xalign = 1.0 - xalign; - if (priv->arrow_type == GTK_ARROW_LEFT) - effective_arrow_type = GTK_ARROW_RIGHT; - else if (priv->arrow_type == GTK_ARROW_RIGHT) - effective_arrow_type = GTK_ARROW_LEFT; - } - - x = floor (allocation.x + xpad + ((allocation.width - extent) * xalign)); - y = floor (allocation.y + ypad + ((allocation.height - extent) * yalign)); - - shadow_type = priv->shadow_type; - - state = gtk_widget_get_state (widget); - - if (state == GTK_STATE_ACTIVE) - { - if (shadow_type == GTK_SHADOW_IN) - shadow_type = GTK_SHADOW_OUT; - else if (shadow_type == GTK_SHADOW_OUT) - shadow_type = GTK_SHADOW_IN; - else if (shadow_type == GTK_SHADOW_ETCHED_IN) - shadow_type = GTK_SHADOW_ETCHED_OUT; - else if (shadow_type == GTK_SHADOW_ETCHED_OUT) - shadow_type = GTK_SHADOW_ETCHED_IN; - } - - gtk_paint_arrow (gtk_widget_get_style (widget), - gtk_widget_get_window (widget), - state, shadow_type, - &event->area, widget, "arrow", - effective_arrow_type, TRUE, - x, y, extent, extent); + xalign = 1.0 - xalign; + if (priv->arrow_type == GTK_ARROW_LEFT) + effective_arrow_type = GTK_ARROW_RIGHT; + else if (priv->arrow_type == GTK_ARROW_RIGHT) + effective_arrow_type = GTK_ARROW_LEFT; } + x = border.left + ((width - extent) * xalign); + y = border.top + ((height - extent) * yalign); + + switch (effective_arrow_type) + { + case GTK_ARROW_UP: + angle = 0; + break; + case GTK_ARROW_RIGHT: + angle = G_PI / 2; + break; + case GTK_ARROW_DOWN: + angle = G_PI; + break; + case GTK_ARROW_LEFT: + default: + angle = (3 * G_PI) / 2; + break; + } + + gtk_render_arrow (context, cr, angle, x, y, extent); + return FALSE; }