X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=gtk%2Fgtkspinner.c;h=06840c88fe441b6674fae97de6a8be4f074583c6;hb=9f41970832b60f3cf6644dfbd154df7ec24f26ce;hp=78c6b994df6e871e72b7826c4c35efe8fe67fea3;hpb=a47a557fc3e17ed99d125df781055a399f72891b;p=~andy%2Fgtk diff --git a/gtk/gtkspinner.c b/gtk/gtkspinner.c index 78c6b994d..06840c88f 100644 --- a/gtk/gtkspinner.c +++ b/gtk/gtkspinner.c @@ -14,9 +14,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 . * * Code adapted from egg-spinner * by Christian Hergert @@ -31,11 +29,12 @@ #include "config.h" -#include "gtkintl.h" -#include "gtkaccessible.h" -#include "gtkimage.h" #include "gtkspinner.h" -#include "gtkstyle.h" + +#include "gtkimage.h" +#include "gtkintl.h" +#include "gtkstylecontext.h" +#include "a11y/gtkspinneraccessible.h" /** @@ -84,8 +83,6 @@ static void gtk_spinner_get_preferred_height (GtkWidget *widget, gint *minimum_size, gint *natural_size); -static AtkObject *gtk_spinner_get_accessible (GtkWidget *widget); -static GType gtk_spinner_accessible_get_type (void); G_DEFINE_TYPE (GtkSpinner, gtk_spinner, GTK_TYPE_WIDGET) @@ -102,7 +99,6 @@ gtk_spinner_class_init (GtkSpinnerClass *klass) widget_class = GTK_WIDGET_CLASS(klass); widget_class->draw = gtk_spinner_draw; - widget_class->get_accessible = gtk_spinner_get_accessible; widget_class->get_preferred_width = gtk_spinner_get_preferred_width; widget_class->get_preferred_height = gtk_spinner_get_preferred_height; @@ -119,43 +115,8 @@ gtk_spinner_class_init (GtkSpinnerClass *klass) P_("Whether the spinner is active"), FALSE, G_PARAM_READWRITE)); - /** - * GtkSpinner:num-steps: - * - * The number of steps for the spinner to complete a full loop. - * The animation will complete a full cycle in one second by default - * (see the #GtkSpinner:cycle-duration style property). - * - * Since: 2.20 - * - * Deprecated: 3.0 - */ - gtk_widget_class_install_style_property (widget_class, - g_param_spec_uint ("num-steps", - P_("Number of steps"), - P_("The number of steps for the spinner to complete a full loop. The animation will complete a full cycle in one second by default (see #GtkSpinner:cycle-duration)."), - 1, - G_MAXUINT, - 12, - G_PARAM_READABLE)); - - /** - * GtkSpinner:cycle-duration: - * - * The duration in milliseconds for the spinner to complete a full cycle. - * - * Since: 2.20 - * - * Deprecated: 3.0 - */ - gtk_widget_class_install_style_property (widget_class, - g_param_spec_uint ("cycle-duration", - P_("Animation duration"), - P_("The length of time in milliseconds for the spinner to complete a full loop"), - 500, - G_MAXUINT, - 1000, - G_PARAM_READABLE)); + + gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_SPINNER_ACCESSIBLE); } static void @@ -239,18 +200,20 @@ static gboolean gtk_spinner_draw (GtkWidget *widget, cairo_t *cr) { - GtkSpinnerPrivate *priv; GtkStyleContext *context; - GtkStateFlags state; + gint width, height; + gint size; - priv = GTK_SPINNER (widget)->priv; context = gtk_widget_get_style_context (widget); - state = gtk_widget_get_state_flags (widget); - gtk_style_context_set_state (context, state); - gtk_render_activity (context, cr, 0, 0, - gtk_widget_get_allocated_width (widget), - gtk_widget_get_allocated_height (widget)); + width = gtk_widget_get_allocated_width (widget); + height = gtk_widget_get_allocated_height (widget); + size = MIN (width, height); + + gtk_render_activity (context, cr, + (width - size) / 2, + (height - size) / 2, + size, size); return FALSE; } @@ -278,137 +241,6 @@ gtk_spinner_set_active (GtkSpinner *spinner, } } -/* accessible implementation */ - -static void -gtk_spinner_accessible_image_get_size (AtkImage *image, - gint *width, - gint *height) -{ - GtkAllocation allocation; - GtkWidget *widget; - - widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (image)); - if (widget == NULL) - { - *width = *height = 0; - } - else - { - gtk_widget_get_allocation (widget, &allocation); - *width = allocation.width; - *height = allocation.height; - } -} - -static void -gtk_spinner_accessible_image_iface_init (AtkImageIface *iface) -{ - iface->get_image_size = gtk_spinner_accessible_image_get_size; -} - -/* dummy typedef */ -typedef struct _GtkSpinnerAccessible GtkSpinnerAccessible; -typedef struct _GtkSpinnerAccessibleClass GtkSpinnerAccessibleClass; - -ATK_DEFINE_TYPE_WITH_CODE (GtkSpinnerAccessible, - gtk_spinner_accessible, - GTK_TYPE_IMAGE, - G_IMPLEMENT_INTERFACE (ATK_TYPE_IMAGE, - gtk_spinner_accessible_image_iface_init)); - -static void -gtk_spinner_accessible_initialize (AtkObject *accessible, - gpointer widget) -{ - ATK_OBJECT_CLASS (gtk_spinner_accessible_parent_class)->initialize (accessible, widget); - - atk_object_set_name (accessible, C_("throbbing progress animation widget", "Spinner")); - atk_object_set_description (accessible, _("Provides visual indication of progress")); -} - -static void -gtk_spinner_accessible_class_init (GtkSpinnerAccessibleClass *klass) -{ - AtkObjectClass *atk_class = ATK_OBJECT_CLASS (klass); - - atk_class->initialize = gtk_spinner_accessible_initialize; -} - -static void -gtk_spinner_accessible_init (GtkSpinnerAccessible *self) -{ -} - -/* factory */ -typedef AtkObjectFactory GtkSpinnerAccessibleFactory; -typedef AtkObjectFactoryClass GtkSpinnerAccessibleFactoryClass; - -G_DEFINE_TYPE (GtkSpinnerAccessibleFactory, - _gtk_spinner_accessible_factory, - ATK_TYPE_OBJECT_FACTORY); - -static GType -gtk_spinner_accessible_factory_get_accessible_type (void) -{ - return gtk_spinner_accessible_get_type (); -} - -static AtkObject * -gtk_spinner_accessible_factory_create_accessible (GObject *obj) -{ - AtkObject *accessible; - - accessible = g_object_new (gtk_spinner_accessible_get_type (), NULL); - atk_object_initialize (accessible, obj); - - return accessible; -} - -static void -_gtk_spinner_accessible_factory_class_init (AtkObjectFactoryClass *klass) -{ - klass->create_accessible = gtk_spinner_accessible_factory_create_accessible; - klass->get_accessible_type = gtk_spinner_accessible_factory_get_accessible_type; -} - -static void -_gtk_spinner_accessible_factory_init (AtkObjectFactory *factory) -{ -} - -static AtkObject * -gtk_spinner_get_accessible (GtkWidget *widget) -{ - static gboolean first_time = TRUE; - - if (first_time) - { - AtkObjectFactory *factory; - AtkRegistry *registry; - GType derived_type; - GType derived_atk_type; - - /* - * Figure out whether accessibility is enabled by looking at the - * type of the accessible object which would be created for - * the parent type of GtkSpinner. - */ - derived_type = g_type_parent (GTK_TYPE_SPINNER); - - registry = atk_get_default_registry (); - factory = atk_registry_get_factory (registry, derived_type); - derived_atk_type = atk_object_factory_get_accessible_type (factory); - if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE)) - atk_registry_set_factory_type (registry, - GTK_TYPE_SPINNER, - _gtk_spinner_accessible_factory_get_type ()); - first_time = FALSE; - } - - return GTK_WIDGET_CLASS (gtk_spinner_parent_class)->get_accessible (widget); -} - /** * gtk_spinner_new: *