|
Packit Service |
fb6fa5 |
/* GTK - The GIMP Toolkit
|
|
Packit Service |
fb6fa5 |
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
|
Packit Service |
fb6fa5 |
*
|
|
Packit Service |
fb6fa5 |
* This library is free software; you can redistribute it and/or
|
|
Packit Service |
fb6fa5 |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
fb6fa5 |
* License as published by the Free Software Foundation; either
|
|
Packit Service |
fb6fa5 |
* version 2 of the License, or (at your option) any later version.
|
|
Packit Service |
fb6fa5 |
*
|
|
Packit Service |
fb6fa5 |
* This library is distributed in the hope that it will be useful,
|
|
Packit Service |
fb6fa5 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
fb6fa5 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
fb6fa5 |
* Lesser General Public License for more details.
|
|
Packit Service |
fb6fa5 |
*
|
|
Packit Service |
fb6fa5 |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
fb6fa5 |
* License along with this library; if not, write to the
|
|
Packit Service |
fb6fa5 |
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
Packit Service |
fb6fa5 |
* Boston, MA 02111-1307, USA.
|
|
Packit Service |
fb6fa5 |
*/
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
/*
|
|
Packit Service |
fb6fa5 |
* Modified by the GTK+ Team and others 1997-2001. See the AUTHORS
|
|
Packit Service |
fb6fa5 |
* file for a list of people on the GTK+ Team. See the ChangeLog
|
|
Packit Service |
fb6fa5 |
* files for a list of changes. These files are distributed with
|
|
Packit Service |
fb6fa5 |
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
|
|
Packit Service |
fb6fa5 |
*/
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
/**
|
|
Packit Service |
fb6fa5 |
* SECTION:gtkarrow
|
|
Packit Service |
fb6fa5 |
* @Short_description: Displays an arrow
|
|
Packit Service |
fb6fa5 |
* @Title: GtkArrow
|
|
Packit Service |
fb6fa5 |
* @See_also: gtk_paint_arrow()
|
|
Packit Service |
fb6fa5 |
*
|
|
Packit Service |
fb6fa5 |
* GtkArrow should be used to draw simple arrows that need to point in
|
|
Packit Service |
fb6fa5 |
* one of the four cardinal directions (up, down, left, or right). The
|
|
Packit Service |
fb6fa5 |
* style of the arrow can be one of shadow in, shadow out, etched in, or
|
|
Packit Service |
fb6fa5 |
* etched out. Note that these directions and style types may be
|
|
Packit Service |
fb6fa5 |
* ammended in versions of GTK+ to come.
|
|
Packit Service |
fb6fa5 |
*
|
|
Packit Service |
fb6fa5 |
* GtkArrow will fill any space alloted to it, but since it is inherited
|
|
Packit Service |
fb6fa5 |
* from #GtkMisc, it can be padded and/or aligned, to fill exactly the
|
|
Packit Service |
fb6fa5 |
* space the programmer desires.
|
|
Packit Service |
fb6fa5 |
*
|
|
Packit Service |
fb6fa5 |
* Arrows are created with a call to gtk_arrow_new(). The direction or
|
|
Packit Service |
fb6fa5 |
* style of an arrow can be changed after creation by using gtk_arrow_set().
|
|
Packit Service |
fb6fa5 |
*/
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
#include "config.h"
|
|
Packit Service |
fb6fa5 |
#include <math.h>
|
|
Packit Service |
fb6fa5 |
#include "gtkarrow.h"
|
|
Packit Service |
fb6fa5 |
#include "gtkprivate.h"
|
|
Packit Service |
fb6fa5 |
#include "gtkintl.h"
|
|
Packit Service |
fb6fa5 |
#include "gtkalias.h"
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
#define MIN_ARROW_SIZE 15
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
enum {
|
|
Packit Service |
fb6fa5 |
PROP_0,
|
|
Packit Service |
fb6fa5 |
PROP_ARROW_TYPE,
|
|
Packit Service |
fb6fa5 |
PROP_SHADOW_TYPE
|
|
Packit Service |
fb6fa5 |
};
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
static void gtk_arrow_set_property (GObject *object,
|
|
Packit Service |
fb6fa5 |
guint prop_id,
|
|
Packit Service |
fb6fa5 |
const GValue *value,
|
|
Packit Service |
fb6fa5 |
GParamSpec *pspec);
|
|
Packit Service |
fb6fa5 |
static void gtk_arrow_get_property (GObject *object,
|
|
Packit Service |
fb6fa5 |
guint prop_id,
|
|
Packit Service |
fb6fa5 |
GValue *value,
|
|
Packit Service |
fb6fa5 |
GParamSpec *pspec);
|
|
Packit Service |
fb6fa5 |
static gboolean gtk_arrow_expose (GtkWidget *widget,
|
|
Packit Service |
fb6fa5 |
GdkEventExpose *event);
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
G_DEFINE_TYPE (GtkArrow, gtk_arrow, GTK_TYPE_MISC)
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
static void
|
|
Packit Service |
fb6fa5 |
gtk_arrow_class_init (GtkArrowClass *class)
|
|
Packit Service |
fb6fa5 |
{
|
|
Packit Service |
fb6fa5 |
GObjectClass *gobject_class;
|
|
Packit Service |
fb6fa5 |
GtkWidgetClass *widget_class;
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
gobject_class = (GObjectClass*) class;
|
|
Packit Service |
fb6fa5 |
widget_class = (GtkWidgetClass*) class;
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
gobject_class->set_property = gtk_arrow_set_property;
|
|
Packit Service |
fb6fa5 |
gobject_class->get_property = gtk_arrow_get_property;
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
widget_class->expose_event = gtk_arrow_expose;
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
g_object_class_install_property (gobject_class,
|
|
Packit Service |
fb6fa5 |
PROP_ARROW_TYPE,
|
|
Packit Service |
fb6fa5 |
g_param_spec_enum ("arrow-type",
|
|
Packit Service |
fb6fa5 |
P_("Arrow direction"),
|
|
Packit Service |
fb6fa5 |
P_("The direction the arrow should point"),
|
|
Packit Service |
fb6fa5 |
GTK_TYPE_ARROW_TYPE,
|
|
Packit Service |
fb6fa5 |
GTK_ARROW_RIGHT,
|
|
Packit Service |
fb6fa5 |
GTK_PARAM_READWRITE));
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
g_object_class_install_property (gobject_class,
|
|
Packit Service |
fb6fa5 |
PROP_SHADOW_TYPE,
|
|
Packit Service |
fb6fa5 |
g_param_spec_enum ("shadow-type",
|
|
Packit Service |
fb6fa5 |
P_("Arrow shadow"),
|
|
Packit Service |
fb6fa5 |
P_("Appearance of the shadow surrounding the arrow"),
|
|
Packit Service |
fb6fa5 |
GTK_TYPE_SHADOW_TYPE,
|
|
Packit Service |
fb6fa5 |
GTK_SHADOW_OUT,
|
|
Packit Service |
fb6fa5 |
GTK_PARAM_READWRITE));
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
gtk_widget_class_install_style_property (widget_class,
|
|
Packit Service |
fb6fa5 |
g_param_spec_float ("arrow-scaling",
|
|
Packit Service |
fb6fa5 |
P_("Arrow Scaling"),
|
|
Packit Service |
fb6fa5 |
P_("Amount of space used up by arrow"),
|
|
Packit Service |
fb6fa5 |
0.0, 1.0, 0.7,
|
|
Packit Service |
fb6fa5 |
GTK_PARAM_READABLE));
|
|
Packit Service |
fb6fa5 |
}
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
static void
|
|
Packit Service |
fb6fa5 |
gtk_arrow_set_property (GObject *object,
|
|
Packit Service |
fb6fa5 |
guint prop_id,
|
|
Packit Service |
fb6fa5 |
const GValue *value,
|
|
Packit Service |
fb6fa5 |
GParamSpec *pspec)
|
|
Packit Service |
fb6fa5 |
{
|
|
Packit Service |
fb6fa5 |
GtkArrow *arrow = GTK_ARROW (object);
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
switch (prop_id)
|
|
Packit Service |
fb6fa5 |
{
|
|
Packit Service |
fb6fa5 |
case PROP_ARROW_TYPE:
|
|
Packit Service |
fb6fa5 |
gtk_arrow_set (arrow,
|
|
Packit Service |
fb6fa5 |
g_value_get_enum (value),
|
|
Packit Service |
fb6fa5 |
arrow->shadow_type);
|
|
Packit Service |
fb6fa5 |
break;
|
|
Packit Service |
fb6fa5 |
case PROP_SHADOW_TYPE:
|
|
Packit Service |
fb6fa5 |
gtk_arrow_set (arrow,
|
|
Packit Service |
fb6fa5 |
arrow->arrow_type,
|
|
Packit Service |
fb6fa5 |
g_value_get_enum (value));
|
|
Packit Service |
fb6fa5 |
break;
|
|
Packit Service |
fb6fa5 |
default:
|
|
Packit Service |
fb6fa5 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
Packit Service |
fb6fa5 |
break;
|
|
Packit Service |
fb6fa5 |
}
|
|
Packit Service |
fb6fa5 |
}
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
static void
|
|
Packit Service |
fb6fa5 |
gtk_arrow_get_property (GObject *object,
|
|
Packit Service |
fb6fa5 |
guint prop_id,
|
|
Packit Service |
fb6fa5 |
GValue *value,
|
|
Packit Service |
fb6fa5 |
GParamSpec *pspec)
|
|
Packit Service |
fb6fa5 |
{
|
|
Packit Service |
fb6fa5 |
GtkArrow *arrow = GTK_ARROW (object);
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
switch (prop_id)
|
|
Packit Service |
fb6fa5 |
{
|
|
Packit Service |
fb6fa5 |
case PROP_ARROW_TYPE:
|
|
Packit Service |
fb6fa5 |
g_value_set_enum (value, arrow->arrow_type);
|
|
Packit Service |
fb6fa5 |
break;
|
|
Packit Service |
fb6fa5 |
case PROP_SHADOW_TYPE:
|
|
Packit Service |
fb6fa5 |
g_value_set_enum (value, arrow->shadow_type);
|
|
Packit Service |
fb6fa5 |
break;
|
|
Packit Service |
fb6fa5 |
default:
|
|
Packit Service |
fb6fa5 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
Packit Service |
fb6fa5 |
break;
|
|
Packit Service |
fb6fa5 |
}
|
|
Packit Service |
fb6fa5 |
}
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
static void
|
|
Packit Service |
fb6fa5 |
gtk_arrow_init (GtkArrow *arrow)
|
|
Packit Service |
fb6fa5 |
{
|
|
Packit Service |
fb6fa5 |
gtk_widget_set_has_window (GTK_WIDGET (arrow), FALSE);
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
GTK_WIDGET (arrow)->requisition.width = MIN_ARROW_SIZE + GTK_MISC (arrow)->xpad * 2;
|
|
Packit Service |
fb6fa5 |
GTK_WIDGET (arrow)->requisition.height = MIN_ARROW_SIZE + GTK_MISC (arrow)->ypad * 2;
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
arrow->arrow_type = GTK_ARROW_RIGHT;
|
|
Packit Service |
fb6fa5 |
arrow->shadow_type = GTK_SHADOW_OUT;
|
|
Packit Service |
fb6fa5 |
}
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
/**
|
|
Packit Service |
fb6fa5 |
* gtk_arrow_new:
|
|
Packit Service |
fb6fa5 |
* @arrow_type: a valid #GtkArrowType.
|
|
Packit Service |
fb6fa5 |
* @shadow_type: a valid #GtkShadowType.
|
|
Packit Service |
fb6fa5 |
*
|
|
Packit Service |
fb6fa5 |
* Creates a new #GtkArrow widget.
|
|
Packit Service |
fb6fa5 |
*
|
|
Packit Service |
fb6fa5 |
* Returns: the new #GtkArrow widget.
|
|
Packit Service |
fb6fa5 |
*/
|
|
Packit Service |
fb6fa5 |
GtkWidget*
|
|
Packit Service |
fb6fa5 |
gtk_arrow_new (GtkArrowType arrow_type,
|
|
Packit Service |
fb6fa5 |
GtkShadowType shadow_type)
|
|
Packit Service |
fb6fa5 |
{
|
|
Packit Service |
fb6fa5 |
GtkArrow *arrow;
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
arrow = g_object_new (GTK_TYPE_ARROW, NULL);
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
arrow->arrow_type = arrow_type;
|
|
Packit Service |
fb6fa5 |
arrow->shadow_type = shadow_type;
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
return GTK_WIDGET (arrow);
|
|
Packit Service |
fb6fa5 |
}
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
/**
|
|
Packit Service |
fb6fa5 |
* gtk_arrow_set:
|
|
Packit Service |
fb6fa5 |
* @arrow: a widget of type #GtkArrow.
|
|
Packit Service |
fb6fa5 |
* @arrow_type: a valid #GtkArrowType.
|
|
Packit Service |
fb6fa5 |
* @shadow_type: a valid #GtkShadowType.
|
|
Packit Service |
fb6fa5 |
*
|
|
Packit Service |
fb6fa5 |
* Sets the direction and style of the #GtkArrow, @arrow.
|
|
Packit Service |
fb6fa5 |
*/
|
|
Packit Service |
fb6fa5 |
void
|
|
Packit Service |
fb6fa5 |
gtk_arrow_set (GtkArrow *arrow,
|
|
Packit Service |
fb6fa5 |
GtkArrowType arrow_type,
|
|
Packit Service |
fb6fa5 |
GtkShadowType shadow_type)
|
|
Packit Service |
fb6fa5 |
{
|
|
Packit Service |
fb6fa5 |
GtkWidget *widget;
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
g_return_if_fail (GTK_IS_ARROW (arrow));
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
if ( ((GtkArrowType) arrow->arrow_type != arrow_type)
|
|
Packit Service |
fb6fa5 |
|| ((GtkShadowType) arrow->shadow_type != shadow_type))
|
|
Packit Service |
fb6fa5 |
{
|
|
Packit Service |
fb6fa5 |
g_object_freeze_notify (G_OBJECT (arrow));
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
if ((GtkArrowType) arrow->arrow_type != arrow_type)
|
|
Packit Service |
fb6fa5 |
{
|
|
Packit Service |
fb6fa5 |
arrow->arrow_type = arrow_type;
|
|
Packit Service |
fb6fa5 |
g_object_notify (G_OBJECT (arrow), "arrow-type");
|
|
Packit Service |
fb6fa5 |
}
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
if ((GtkShadowType) arrow->shadow_type != shadow_type)
|
|
Packit Service |
fb6fa5 |
{
|
|
Packit Service |
fb6fa5 |
arrow->shadow_type = shadow_type;
|
|
Packit Service |
fb6fa5 |
g_object_notify (G_OBJECT (arrow), "shadow-type");
|
|
Packit Service |
fb6fa5 |
}
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
g_object_thaw_notify (G_OBJECT (arrow));
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
widget = GTK_WIDGET (arrow);
|
|
Packit Service |
fb6fa5 |
if (gtk_widget_is_drawable (widget))
|
|
Packit Service |
fb6fa5 |
gtk_widget_queue_draw (widget);
|
|
Packit Service |
fb6fa5 |
}
|
|
Packit Service |
fb6fa5 |
}
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
static gboolean
|
|
Packit Service |
fb6fa5 |
gtk_arrow_expose (GtkWidget *widget,
|
|
Packit Service |
fb6fa5 |
GdkEventExpose *event)
|
|
Packit Service |
fb6fa5 |
{
|
|
Packit Service |
fb6fa5 |
if (gtk_widget_is_drawable (widget))
|
|
Packit Service |
fb6fa5 |
{
|
|
Packit Service |
fb6fa5 |
GtkArrow *arrow = GTK_ARROW (widget);
|
|
Packit Service |
fb6fa5 |
GtkMisc *misc = GTK_MISC (widget);
|
|
Packit Service |
fb6fa5 |
GtkShadowType shadow_type;
|
|
Packit Service |
fb6fa5 |
gint width, height;
|
|
Packit Service |
fb6fa5 |
gint x, y;
|
|
Packit Service |
fb6fa5 |
gint extent;
|
|
Packit Service |
fb6fa5 |
gfloat xalign;
|
|
Packit Service |
fb6fa5 |
GtkArrowType effective_arrow_type;
|
|
Packit Service |
fb6fa5 |
gfloat arrow_scaling;
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
gtk_widget_style_get (widget, "arrow-scaling", &arrow_scaling, NULL);
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
width = widget->allocation.width - misc->xpad * 2;
|
|
Packit Service |
fb6fa5 |
height = widget->allocation.height - misc->ypad * 2;
|
|
Packit Service |
fb6fa5 |
extent = MIN (width, height) * arrow_scaling;
|
|
Packit Service |
fb6fa5 |
effective_arrow_type = arrow->arrow_type;
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
|
|
Packit Service |
fb6fa5 |
xalign = misc->xalign;
|
|
Packit Service |
fb6fa5 |
else
|
|
Packit Service |
fb6fa5 |
{
|
|
Packit Service |
fb6fa5 |
xalign = 1.0 - misc->xalign;
|
|
Packit Service |
fb6fa5 |
if (arrow->arrow_type == GTK_ARROW_LEFT)
|
|
Packit Service |
fb6fa5 |
effective_arrow_type = GTK_ARROW_RIGHT;
|
|
Packit Service |
fb6fa5 |
else if (arrow->arrow_type == GTK_ARROW_RIGHT)
|
|
Packit Service |
fb6fa5 |
effective_arrow_type = GTK_ARROW_LEFT;
|
|
Packit Service |
fb6fa5 |
}
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
x = floor (widget->allocation.x + misc->xpad
|
|
Packit Service |
fb6fa5 |
+ ((widget->allocation.width - extent) * xalign));
|
|
Packit Service |
fb6fa5 |
y = floor (widget->allocation.y + misc->ypad
|
|
Packit Service |
fb6fa5 |
+ ((widget->allocation.height - extent) * misc->yalign));
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
shadow_type = arrow->shadow_type;
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
if (widget->state == GTK_STATE_ACTIVE)
|
|
Packit Service |
fb6fa5 |
{
|
|
Packit Service |
fb6fa5 |
if (shadow_type == GTK_SHADOW_IN)
|
|
Packit Service |
fb6fa5 |
shadow_type = GTK_SHADOW_OUT;
|
|
Packit Service |
fb6fa5 |
else if (shadow_type == GTK_SHADOW_OUT)
|
|
Packit Service |
fb6fa5 |
shadow_type = GTK_SHADOW_IN;
|
|
Packit Service |
fb6fa5 |
else if (shadow_type == GTK_SHADOW_ETCHED_IN)
|
|
Packit Service |
fb6fa5 |
shadow_type = GTK_SHADOW_ETCHED_OUT;
|
|
Packit Service |
fb6fa5 |
else if (shadow_type == GTK_SHADOW_ETCHED_OUT)
|
|
Packit Service |
fb6fa5 |
shadow_type = GTK_SHADOW_ETCHED_IN;
|
|
Packit Service |
fb6fa5 |
}
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
gtk_paint_arrow (widget->style, widget->window,
|
|
Packit Service |
fb6fa5 |
widget->state, shadow_type,
|
|
Packit Service |
fb6fa5 |
&event->area, widget, "arrow",
|
|
Packit Service |
fb6fa5 |
effective_arrow_type, TRUE,
|
|
Packit Service |
fb6fa5 |
x, y, extent, extent);
|
|
Packit Service |
fb6fa5 |
}
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
return FALSE;
|
|
Packit Service |
fb6fa5 |
}
|
|
Packit Service |
fb6fa5 |
|
|
Packit Service |
fb6fa5 |
#define __GTK_ARROW_C__
|
|
Packit Service |
fb6fa5 |
#include "gtkaliasdef.c"
|