grim/purple-plugin-pack
/* GTK - The GIMP Toolkit * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02111-1301, USA. * GtkTicker Copyright 2000 Syd Logan static void gtk_ticker_compute_offsets (GtkTicker *ticker); static void gtk_ticker_class_init (GtkTickerClass *klass); static void gtk_ticker_init (GtkTicker *ticker); static void gtk_ticker_map (GtkWidget *widget); static void gtk_ticker_realize (GtkWidget *widget); static void gtk_ticker_size_request (GtkWidget *widget, GtkRequisition *requisition); static void gtk_ticker_size_allocate (GtkWidget *widget, GtkAllocation *allocation); static void gtk_ticker_add_real (GtkContainer *container, static void gtk_ticker_remove_real (GtkContainer *container, static void gtk_ticker_forall (GtkContainer *container, gboolean include_internals, static GtkType gtk_ticker_child_type (GtkContainer *container); static GtkContainerClass *parent_class = NULL; GType gtk_ticker_get_type (void) static GType ticker_type = 0; ticker_type = g_type_from_name("GtkTicker"); static const GTypeInfo ticker_info = (GClassInitFunc) gtk_ticker_class_init, (GInstanceInitFunc) gtk_ticker_init ticker_type = g_type_register_static (GTK_TYPE_CONTAINER, "GtkTicker", /* kludge to re-initialise the class if it's already registered */ else if (parent_class == NULL) { gtk_ticker_class_init((GtkTickerClass *)g_type_class_peek(ticker_type)); static void gtk_ticker_finalize(GObject *object) { gtk_ticker_stop_scroll(GTK_TICKER(object)); G_OBJECT_CLASS(parent_class)->finalize(object); static void gtk_ticker_class_init (GtkTickerClass *class) GObjectClass *gobject_class; GtkWidgetClass *widget_class; GtkContainerClass *container_class; gobject_class = (GObjectClass*) class; widget_class = (GtkWidgetClass*) class; container_class = (GtkContainerClass*) class; parent_class = gtk_type_class (GTK_TYPE_CONTAINER); gobject_class->finalize = gtk_ticker_finalize; widget_class->map = gtk_ticker_map; widget_class->realize = gtk_ticker_realize; widget_class->size_request = gtk_ticker_size_request; widget_class->size_allocate = gtk_ticker_size_allocate; container_class->add = gtk_ticker_add_real; container_class->remove = gtk_ticker_remove_real; container_class->forall = gtk_ticker_forall; container_class->child_type = gtk_ticker_child_type; static GtkType gtk_ticker_child_type (GtkContainer *container) static void gtk_ticker_init (GtkTicker *ticker) GTK_WIDGET_UNSET_FLAGS (ticker, GTK_NO_WINDOW); ticker->interval = (guint) 200; ticker->scootch = (guint) 2; GtkWidget* gtk_ticker_new (void) return GTK_WIDGET(g_object_new(GTK_TYPE_TICKER, NULL)); static void gtk_ticker_put (GtkTicker *ticker, GtkWidget *widget) GtkTickerChild *child_info; g_return_if_fail (ticker != NULL); g_return_if_fail (GTK_IS_TICKER (ticker)); g_return_if_fail (widget != NULL); child_info = g_new(GtkTickerChild, 1); child_info->widget = widget; gtk_widget_set_parent(widget, GTK_WIDGET (ticker)); ticker->children = g_list_append (ticker->children, child_info); if (GTK_WIDGET_REALIZED (ticker)) gtk_widget_realize (widget); if (GTK_WIDGET_VISIBLE (ticker) && GTK_WIDGET_VISIBLE (widget)) if (GTK_WIDGET_MAPPED (ticker)) gtk_widget_queue_resize (GTK_WIDGET (ticker)); void gtk_ticker_set_interval (GtkTicker *ticker, gint interval) g_return_if_fail (ticker != NULL); g_return_if_fail (GTK_IS_TICKER (ticker)); ticker->interval = interval; guint gtk_ticker_get_interval (GtkTicker *ticker) g_return_val_if_fail (ticker != NULL, -1); g_return_val_if_fail (GTK_IS_TICKER (ticker), -1); void gtk_ticker_set_scootch (GtkTicker *ticker, gint scootch) g_return_if_fail (ticker != NULL); g_return_if_fail (GTK_IS_TICKER (ticker)); ticker->scootch = scootch; guint gtk_ticker_get_scootch (GtkTicker *ticker ) g_return_val_if_fail (ticker != NULL, -1); g_return_val_if_fail (GTK_IS_TICKER (ticker), -1); void gtk_ticker_set_spacing (GtkTicker *ticker, gint spacing ) g_return_if_fail (ticker != NULL); g_return_if_fail (GTK_IS_TICKER (ticker)); ticker->spacing = spacing; static int ticker_timeout(gpointer data) GtkTicker *ticker = (GtkTicker *) data; if (GTK_WIDGET_VISIBLE (ticker)) gtk_widget_queue_resize (GTK_WIDGET (ticker)); void gtk_ticker_start_scroll(GtkTicker *ticker) g_return_if_fail (ticker != NULL); g_return_if_fail (GTK_IS_TICKER (ticker)); if ( ticker->timer != 0 ) ticker->timer = g_timeout_add(ticker->interval, ticker_timeout, ticker); void gtk_ticker_stop_scroll(GtkTicker *ticker) g_return_if_fail (ticker != NULL); g_return_if_fail (GTK_IS_TICKER (ticker)); if ( ticker->timer == 0 ) g_source_remove(ticker->timer); guint gtk_ticker_get_spacing (GtkTicker *ticker ) g_return_val_if_fail (ticker != NULL, -1); g_return_val_if_fail (GTK_IS_TICKER (ticker), -1); static void gtk_ticker_map (GtkWidget *widget) g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_TICKER (widget)); GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED); ticker = GTK_TICKER (widget); children = ticker->children; children = children->next; if (GTK_WIDGET_VISIBLE (child->widget) && !GTK_WIDGET_MAPPED (child->widget)) gtk_widget_map (child->widget); gdk_window_show (widget->window); static void gtk_ticker_realize (GtkWidget *widget) GdkWindowAttr attributes; g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_TICKER (widget)); GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); 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.wclass = GDK_INPUT_OUTPUT; attributes.visual = gtk_widget_get_visual (widget); attributes.colormap = gtk_widget_get_colormap (widget); attributes.event_mask = gtk_widget_get_events (widget); attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK; 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, widget); widget->style = gtk_style_attach (widget->style, widget->window); gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL); static void gtk_ticker_size_request (GtkWidget *widget, GtkRequisition *requisition) GtkRequisition child_requisition; g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_TICKER (widget)); g_return_if_fail (requisition != NULL); ticker = GTK_TICKER (widget); children = ticker->children; children = children->next; if (GTK_WIDGET_VISIBLE (child->widget)) gtk_widget_size_request (child->widget, &child_requisition); requisition->height = MAX (requisition->height, child_requisition.height); requisition->width += child_requisition.width + ticker->spacing; if ( requisition->width > ticker->spacing ) requisition->width -= ticker->spacing; requisition->height += GTK_CONTAINER (ticker)->border_width * 2; requisition->width += GTK_CONTAINER (ticker)->border_width * 2; static void gtk_ticker_compute_offsets (GtkTicker *ticker) GtkRequisition child_requisition; g_return_if_fail (ticker != NULL); g_return_if_fail (GTK_IS_TICKER(ticker)); border_width = GTK_CONTAINER (ticker)->border_width; ticker->width = GTK_WIDGET(ticker)->allocation.width; children = ticker->children; if (GTK_WIDGET_VISIBLE (child->widget)) { gtk_widget_get_child_requisition (child->widget, &child_requisition); child->offset = ticker->total; child_requisition.width + border_width + ticker->spacing; children = children->next; static void gtk_ticker_size_allocate (GtkWidget *widget, GtkAllocation *allocation) GtkAllocation child_allocation; GtkRequisition child_requisition; g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_TICKER(widget)); g_return_if_fail (allocation != NULL); ticker = GTK_TICKER (widget); if ( GTK_WIDGET(ticker)->allocation.width != ticker->width ) if ( ticker->dirty == TRUE ) { gtk_ticker_compute_offsets( ticker ); widget->allocation = *allocation; if (GTK_WIDGET_REALIZED (widget)) gdk_window_move_resize (widget->window, border_width = GTK_CONTAINER (ticker)->border_width; children = ticker->children; child->x -= ticker->scootch; if (GTK_WIDGET_VISIBLE (child->widget)) { gtk_widget_get_child_requisition (child->widget, &child_requisition); child_allocation.width = child_requisition.width; child_allocation.x = child->offset + border_width + child->x; if ( ( child_allocation.x + child_allocation.width ) < GTK_WIDGET(ticker)->allocation.x ) { if ( ticker->total >= GTK_WIDGET(ticker)->allocation.width ) { child->x += GTK_WIDGET(ticker)->allocation.x + GTK_WIDGET(ticker)->allocation.width + ( ticker->total - ( GTK_WIDGET(ticker)->allocation.x + GTK_WIDGET(ticker)->allocation.width ) ); child->x += GTK_WIDGET(ticker)->allocation.x + GTK_WIDGET(ticker)->allocation.width; child_allocation.y = border_width; child_allocation.height = child_requisition.height; gtk_widget_size_allocate (child->widget, &child_allocation); children = children->next; void gtk_ticker_add(GtkTicker *ticker, GtkWidget *widget) gtk_ticker_add_real( GTK_CONTAINER( ticker ), widget ); void gtk_ticker_remove(GtkTicker *ticker, GtkWidget *widget) gtk_ticker_remove_real( GTK_CONTAINER( ticker ), widget ); static void gtk_ticker_add_real(GtkContainer *container, GtkWidget *widget) g_return_if_fail (container != NULL); g_return_if_fail (GTK_IS_TICKER (container)); g_return_if_fail (widget != NULL); gtk_ticker_put(GTK_TICKER (container), widget); static void gtk_ticker_remove_real(GtkContainer *container, GtkWidget *widget) g_return_if_fail (container != NULL); g_return_if_fail (GTK_IS_TICKER (container)); g_return_if_fail (widget != NULL); ticker = GTK_TICKER (container); children = ticker->children; if (child->widget == widget) gboolean was_visible = GTK_WIDGET_VISIBLE (widget); gtk_widget_unparent (widget); ticker->children = g_list_remove_link (ticker->children, children); if (was_visible && GTK_WIDGET_VISIBLE (container)) gtk_widget_queue_resize (GTK_WIDGET (container)); children = children->next; static void gtk_ticker_forall (GtkContainer *container, gboolean include_internals, g_return_if_fail (container != NULL); g_return_if_fail (GTK_IS_TICKER (container)); g_return_if_fail (callback != NULL); ticker = GTK_TICKER (container); children = ticker->children; children = children->next; (* callback) (child->widget, callback_data);