Mercurial > pidgin
changeset 430:0cd2ba801eb4
[gaim-migrate @ 440]
First pass at a buddy ticker.
committer: Tailor Script <tailor@pidgin.im>
author | Syd Logan <slogan> |
---|---|
date | Sat, 24 Jun 2000 23:15:48 +0000 |
parents | ccf7fc40263f |
children | 094a08a11e3a |
files | src/aim.c src/buddy.c src/gtkticker.c src/gtkticker.h src/ticker.c |
diffstat | 5 files changed, 914 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/aim.c Fri Jun 23 19:13:04 2000 +0000 +++ b/src/aim.c Sat Jun 24 23:15:48 2000 +0000 @@ -50,6 +50,8 @@ #include "pixmaps/logo.xpm" #endif /* USE_APPLET */ +#include "gtkticker.h" + static GtkWidget *name; static GtkWidget *pass; static GtkWidget *signon; @@ -69,6 +71,8 @@ GtkWidget *mainwindow = NULL; +void BuddyTickerCreateWindow( void ); + char toc_addy[16]; char *quad_addr = NULL; @@ -335,7 +339,7 @@ gtk_widget_show(mainwindow); return; } - + mainwindow = gtk_window_new(GTK_WINDOW_TOPLEVEL); signon = gtk_button_new_with_label(_("Signon")); cancel = gtk_button_new_with_label(_("Cancel"));
--- a/src/buddy.c Fri Jun 23 19:13:04 2000 +0000 +++ b/src/buddy.c Sat Jun 24 23:15:48 2000 +0000 @@ -84,6 +84,8 @@ GtkWidget *buddies; int permdeny; +void BuddyTickerLogonTimeout( gpointer data ); +void BuddyTickerLogoutTimeout( gpointer data ); /* Predefine some functions */ static void new_bp_callback(GtkWidget *w, char *name); @@ -908,7 +910,7 @@ gtk_signal_connect(GTK_OBJECT(b->item), "button_press_event", GTK_SIGNAL_FUNC(handle_click_buddy), b); - + return b; } @@ -1507,6 +1509,11 @@ if (display_options & OPT_DISP_SHOW_PIXMAPS) gtk_widget_show(b->pix); + pm = gdk_pixmap_create_from_xpm_d(blist->window, &bm, + NULL, (gchar **)login_icon_xpm); + + BuddyTickerAddUser( b->name, pm, bm ); + if (display_options & OPT_DISP_SHOW_LOGON) { struct conversation *c = find_conversation(b->name); if (c) { @@ -1527,6 +1534,7 @@ gtk_widget_show(b->item); gtk_widget_show(b->label); b->log_timer = gtk_timeout_add(10000, (GtkFunction) log_timeout, b->name); + gtk_timeout_add(10000, (GtkFunction) BuddyTickerLogonTimeout, b->name); update_num_groups(); update_show_idlepix(); setup_buddy_chats(); @@ -1555,26 +1563,44 @@ pm = gdk_pixmap_create_from_xpm_d(blist->window, &bm, NULL, (gchar **)away_icon_xpm); gtk_pixmap_set(GTK_PIXMAP(b->pix), pm, bm); + pm = gdk_pixmap_create_from_xpm_d(blist->window, &bm, + NULL, (gchar **)away_icon_xpm); + BuddyTickerSetPixmap(b->name, pm, bm); } else if (b->uc & UC_AOL) { pm = gdk_pixmap_create_from_xpm_d(blist->window, &bm, NULL, (gchar **)aol_icon_xpm); gtk_pixmap_set(GTK_PIXMAP(b->pix), pm, bm); + pm = gdk_pixmap_create_from_xpm_d(blist->window, &bm, + NULL, (gchar **)aol_icon_xpm); + BuddyTickerSetPixmap(b->name, pm, bm); } else if (b->uc & UC_NORMAL) { pm = gdk_pixmap_create_from_xpm_d(blist->window, &bm, NULL, (gchar **)free_icon_xpm); gtk_pixmap_set(GTK_PIXMAP(b->pix), pm, bm); + pm = gdk_pixmap_create_from_xpm_d(blist->window, &bm, + NULL, (gchar **)free_icon_xpm); + BuddyTickerSetPixmap(b->name, pm, bm); } else if (b->uc & UC_ADMIN) { pm = gdk_pixmap_create_from_xpm_d(blist->window, &bm, NULL, (gchar **)admin_icon_xpm); gtk_pixmap_set(GTK_PIXMAP(b->pix), pm, bm); + pm = gdk_pixmap_create_from_xpm_d(blist->window, &bm, + NULL, (gchar **)admin_icon_xpm); + BuddyTickerSetPixmap(b->name, pm, bm); } else if (b->uc & UC_UNCONFIRMED) { pm = gdk_pixmap_create_from_xpm_d(blist->window, &bm, NULL, (gchar **)dt_icon_xpm); gtk_pixmap_set(GTK_PIXMAP(b->pix), pm, bm); + pm = gdk_pixmap_create_from_xpm_d(blist->window, &bm, + NULL, (gchar **)dt_icon_xpm); + BuddyTickerSetPixmap(b->name, pm, bm); } else { pm = gdk_pixmap_create_from_xpm_d(blist->window, &bm, NULL, (gchar **)no_icon_xpm); gtk_pixmap_set(GTK_PIXMAP(b->pix), pm, bm); + pm = gdk_pixmap_create_from_xpm_d(blist->window, &bm, + NULL, (gchar **)no_icon_xpm); + BuddyTickerSetPixmap(b->name, pm, bm); } if (display_options & OPT_DISP_SHOW_PIXMAPS) gtk_widget_show(b->pix); @@ -1603,6 +1629,9 @@ NULL, (gchar **)logout_icon_xpm); gtk_widget_hide(b->pix); gtk_pixmap_set(GTK_PIXMAP(b->pix), pm, bm); + pm = gdk_pixmap_create_from_xpm_d(blist->window, &bm, + NULL, (gchar **)logout_icon_xpm); + BuddyTickerSetPixmap( b->name, pm, bm ); if (display_options & OPT_DISP_SHOW_PIXMAPS) gtk_widget_show(b->pix); if (display_options & OPT_DISP_SHOW_LOGON) { @@ -1621,6 +1650,7 @@ } } b->log_timer = gtk_timeout_add(10000, (GtkFunction)log_timeout, b->name); + gtk_timeout_add(10000, (GtkFunction)BuddyTickerLogoutTimeout, b->name); update_num_groups(); update_show_idlepix(); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/gtkticker.c Sat Jun 24 23:15:48 2000 +0000 @@ -0,0 +1,612 @@ +/* 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., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/* + * GtkTicker Copyright 2000 Syd Logan + */ + +#include "gtkticker.h" + +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_paint (GtkWidget *widget, + GdkRectangle *area); +static void gtk_ticker_draw (GtkWidget *widget, + GdkRectangle *area); +static gint gtk_ticker_expose (GtkWidget *widget, + GdkEventExpose *event); +static void gtk_ticker_add_real (GtkContainer *container, + GtkWidget *widget); +static void gtk_ticker_remove_real (GtkContainer *container, + GtkWidget *widget); +static void gtk_ticker_forall (GtkContainer *container, + gboolean include_internals, + GtkCallback callback, + gpointer callback_data); +static GtkType gtk_ticker_child_type (GtkContainer *container); + + +static GtkContainerClass *parent_class = NULL; + + +GtkType +gtk_ticker_get_type (void) +{ + static GtkType ticker_type = 0; + + if (!ticker_type) + { + static const GtkTypeInfo ticker_info = + { + "GtkTicker", + sizeof (GtkTicker), + sizeof (GtkTickerClass), + (GtkClassInitFunc) gtk_ticker_class_init, + (GtkObjectInitFunc) gtk_ticker_init, + /* reserved_1 */ NULL, + /* reserved_2 */ NULL, + (GtkClassInitFunc) NULL, + }; + + ticker_type = gtk_type_unique (GTK_TYPE_CONTAINER, &ticker_info); + } + + return ticker_type; +} + +static void +gtk_ticker_class_init (GtkTickerClass *class) +{ + GtkObjectClass *object_class; + GtkWidgetClass *widget_class; + GtkContainerClass *container_class; + + object_class = (GtkObjectClass*) class; + widget_class = (GtkWidgetClass*) class; + container_class = (GtkContainerClass*) class; + + parent_class = gtk_type_class (GTK_TYPE_CONTAINER); + + 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; + widget_class->draw = gtk_ticker_draw; + widget_class->expose_event = gtk_ticker_expose; + + 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) +{ + return GTK_TYPE_WIDGET; +} + +static void +gtk_ticker_init (GtkTicker *ticker) +{ + GTK_WIDGET_UNSET_FLAGS (ticker, GTK_NO_WINDOW); + + ticker->interval = (guint) 200; + ticker->scootch = (guint) 2; + ticker->children = NULL; + ticker->timer = 0; + ticker->dirty = TRUE; +} + +GtkWidget* +gtk_ticker_new (void) +{ + GtkTicker *ticker; + + ticker = gtk_type_new (GTK_TYPE_TICKER); + return GTK_WIDGET (ticker); +} + +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; + child_info->x = 0; + + 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_map (widget); + + 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)); + + if ( interval < 0 ) + interval = 200; + 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); + + return ticker->interval; +} + +void +gtk_ticker_set_scootch (GtkTicker *ticker, gint scootch ) +{ + g_return_if_fail (ticker != NULL); + g_return_if_fail (GTK_IS_TICKER (ticker)); + + if ( scootch <= 0 ) + scootch = 2; + ticker->scootch = scootch; + ticker->dirty = TRUE; +} + +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); + + return ticker->scootch; +} + +void +gtk_ticker_set_spacing (GtkTicker *ticker, gint spacing ) +{ + g_return_if_fail (ticker != NULL); + g_return_if_fail (GTK_IS_TICKER (ticker)); + + if ( spacing < 0 ) + spacing = 0; + ticker->spacing = spacing; + ticker->dirty = TRUE; + +} + +static int +ticker_timeout( gpointer data ) +{ + GtkTicker *ticker = (GtkTicker *) data; + + if (GTK_WIDGET_VISIBLE (ticker)) + gtk_widget_queue_resize (GTK_WIDGET (ticker)); + + return( TRUE ); +} + +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 ) + return; + ticker->timer = gtk_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 ) + return; + gtk_timeout_remove( ticker->timer ); + ticker->timer = 0; + +} + +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); + + return ticker->spacing; +} + +static void +gtk_ticker_map (GtkWidget *widget) +{ + GtkTicker *ticker; + GtkTickerChild *child; + GList *children; + + 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; + while (children) + { + child = children->data; + 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; + gint attributes_mask; + + 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) +{ + GtkTicker *ticker; + GtkTickerChild *child; + GList *children; + 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); + requisition->width = 0; + requisition->height = 0; + + children = ticker->children; + while (children) + { + child = children->data; + 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) +{ + GtkTickerChild *child; + GtkRequisition child_requisition; + GList *children; + guint16 border_width; + + 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; + ticker->total = 0; + children = ticker->children; + while (children) { + child = children->data; + + child->x = 0; + if (GTK_WIDGET_VISIBLE (child->widget)) { + gtk_widget_get_child_requisition (child->widget, &child_requisition); + child->offset = ticker->total; + ticker->total += + child_requisition.width + border_width + ticker->spacing; + } + children = children->next; + } + ticker->dirty = FALSE; +} + +static void +gtk_ticker_size_allocate (GtkWidget *widget, + GtkAllocation *allocation) +{ + GtkTicker *ticker; + GtkTickerChild *child; + GtkAllocation child_allocation; + GtkRequisition child_requisition; + GList *children; + guint16 border_width; + + 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 ) + ticker->dirty = TRUE; + + if ( ticker->dirty == TRUE ) { + gtk_ticker_compute_offsets( ticker ); + } + + widget->allocation = *allocation; + if (GTK_WIDGET_REALIZED (widget)) + gdk_window_move_resize (widget->window, + allocation->x, + allocation->y, + allocation->width, + allocation->height); + + border_width = GTK_CONTAINER (ticker)->border_width; + + children = ticker->children; + while (children) + { + child = children->data; + 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 ) ); + } + else { + 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; + } +} + +static void +gtk_ticker_paint (GtkWidget *widget, + GdkRectangle *area) +{ + g_return_if_fail (widget != NULL); + g_return_if_fail (GTK_IS_TICKER (widget)); + g_return_if_fail (area != NULL); + + if (GTK_WIDGET_DRAWABLE (widget)) + gdk_window_clear_area (widget->window, 0, 0, widget->allocation.width, + widget->allocation.height); +} + +static void +gtk_ticker_draw (GtkWidget *widget, + GdkRectangle *area) +{ + GtkTicker *ticker; + GtkTickerChild *child; + GdkRectangle child_area; + GList *children; + + g_return_if_fail (widget != NULL); + g_return_if_fail (GTK_IS_TICKER (widget)); + + if (GTK_WIDGET_DRAWABLE (widget)) + { + ticker = GTK_TICKER (widget); + gtk_ticker_paint (widget, area); + + children = ticker->children; + while (children) + { + child = children->data; + children = children->next; + gtk_widget_draw (child->widget, NULL); + } + } +} + +static gint +gtk_ticker_expose (GtkWidget *widget, GdkEventExpose *event) +{ + GtkTicker *ticker; + GtkTickerChild *child; + GdkEventExpose child_event; + GList *children; + + g_return_val_if_fail (widget != NULL, FALSE); + g_return_val_if_fail (GTK_IS_TICKER (widget), FALSE); + g_return_val_if_fail (event != NULL, FALSE); + + if (GTK_WIDGET_DRAWABLE (widget)) + { + ticker = GTK_TICKER (widget); + + child_event = *event; + + children = ticker->children; + while (children) + { + child = children->data; + children = children->next; + + if (GTK_WIDGET_NO_WINDOW (child->widget) && + gtk_widget_intersect (child->widget, &event->area, + &child_event.area)) + gtk_widget_event (child->widget, (GdkEvent*) &child_event); + } + } + + return FALSE; +} + +void +gtk_ticker_add(GtkTicker *ticker, GtkWidget *widget) +{ + gtk_ticker_add_real( GTK_CONTAINER( ticker ), widget ); + ticker->dirty = TRUE; +} + +void +gtk_ticker_remove(GtkTicker *ticker, GtkWidget *widget) +{ + gtk_ticker_remove_real( GTK_CONTAINER( ticker ), widget ); + ticker->dirty = TRUE; +} + +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) +{ + GtkTicker *ticker; + GtkTickerChild *child; + GList *children; + + 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; + while (children) + { + child = children->data; + + if (child->widget == widget) + { + gboolean was_visible = GTK_WIDGET_VISIBLE (widget); + + gtk_widget_unparent (widget); + + ticker->children = g_list_remove_link (ticker->children, children); + g_list_free (children); + g_free (child); + + if (was_visible && GTK_WIDGET_VISIBLE (container)) + gtk_widget_queue_resize (GTK_WIDGET (container)); + + break; + } + + children = children->next; + } +} + +static void +gtk_ticker_forall (GtkContainer *container, + gboolean include_internals, + GtkCallback callback, + gpointer callback_data) +{ + GtkTicker *ticker; + GtkTickerChild *child; + GList *children; + + 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; + while (children) + { + child = children->data; + children = children->next; + + (* callback) (child->widget, callback_data); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/gtkticker.h Sat Jun 24 23:15:48 2000 +0000 @@ -0,0 +1,98 @@ +/* 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., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/* + * Copyright 2000 Syd Logan + */ + +#ifndef __GTK_TICKER_H__ +#define __GTK_TICKER_H__ + + +#include <gdk/gdk.h> +#include <gtk/gtkcontainer.h> + + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#define GTK_TYPE_TICKER (gtk_ticker_get_type ()) +#define GTK_TICKER(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_TICKER, GtkTicker)) +#define GTK_TICKER_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_TICKER, GtkTickerClass)) +#define GTK_IS_TICKER(obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_TICKER)) +#define GTK_IS_TICKER_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_TICKER)) + + +typedef struct _GtkTicker GtkTicker; +typedef struct _GtkTickerClass GtkTickerClass; +typedef struct _GtkTickerChild GtkTickerChild; + +// XXX children move from right to left, should be able to go other way + +struct _GtkTicker +{ + GtkContainer container; + guint interval; // how often to scootch + guint spacing; // inter-child horizontal spacing + guint scootch; // how many pixels to move each scootch + gint timer; // timer object + guint total; // total width of widgets + guint width; // width of containing window + gboolean dirty; + GList *children; +}; + +struct _GtkTickerClass +{ + GtkContainerClass parent_class; +}; + +struct _GtkTickerChild +{ + GtkWidget *widget; + gint x; // current position + gint offset; // offset in list +}; + + +GtkType gtk_ticker_get_type (void); +GtkWidget* gtk_ticker_new (void); +void gtk_ticker_add (GtkTicker *ticker, + GtkWidget *widget); +void gtk_ticker_remove (GtkTicker *ticker, + GtkWidget *widget); +void gtk_ticker_set_interval (GtkTicker *ticker, + gint interval); +guint gtk_ticker_get_interval (GtkTicker *ticker); +void gtk_ticker_set_spacing (GtkTicker *ticker, + gint spacing); +guint gtk_ticker_get_spacing (GtkTicker *ticker); +void gtk_ticker_set_scootch (GtkTicker *ticker, + gint scootch); +guint gtk_ticker_get_scootch (GtkTicker *ticker); +void gtk_ticker_start_scroll (GtkTicker *ticker); +void gtk_ticker_stop_scroll (GtkTicker *ticker); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + + +#endif /* __GTK_TICKER_H__ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ticker.c Sat Jun 24 23:15:48 2000 +0000 @@ -0,0 +1,168 @@ +/* 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., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/* + * ticker.c -- Syd Logan, Summer 2000 + */ + +#include <gtk/gtk.h> +#include "gtkticker.h" + +GtkWidget *tickerwindow = NULL; +GtkWidget *ticker; + +typedef struct { + char buddy[ 128 ]; + GtkWidget *hbox; + GtkWidget *label; + GtkWidget *pix; +} TickerData; + +static GList *tickerbuds = (GList *) NULL; + +void BuddyTickerDestroyWindow( GtkWidget *window ); +void BuddyTickerCreateWindow( void ); +void BuddyTickerAddUser( char *name, GdkPixmap *pm, GdkBitmap *bm ); +void BuddyTickerRemoveUser( char *name ); +void BuddyTickerSetPixmap( char *name, GdkPixmap *pm, GdkBitmap *bm ); +GList * BuddyTickerFindUser( char *name ); + +void +BuddyTickerDestroyWindow( GtkWidget *window ) +{ + gtk_ticker_stop_scroll( GTK_TICKER( ticker ) ); + gtk_widget_destroy( window ); + ticker = tickerwindow = (GtkWidget *) NULL; +} + +void +BuddyTickerCreateWindow() +{ + if ( tickerwindow != (GtkWidget *) NULL ) + return; + tickerwindow = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_signal_connect (GTK_OBJECT(tickerwindow), "destroy", + GTK_SIGNAL_FUNC (BuddyTickerDestroyWindow), "WM destroy"); + gtk_window_set_title (GTK_WINDOW(tickerwindow), "Buddy Ticker"); + + ticker = gtk_ticker_new(); + gtk_container_add( GTK_CONTAINER( tickerwindow ), ticker ); + gtk_ticker_set_spacing( GTK_TICKER( ticker ), 20 ); + gtk_widget_set_usize( ticker, 200, -1 ); + gtk_widget_show (ticker); + + gtk_ticker_set_interval( GTK_TICKER( ticker ), 500 ); + gtk_ticker_set_scootch( GTK_TICKER( ticker ), 10 ); + gtk_ticker_start_scroll( GTK_TICKER( ticker ) ); +} + +void +BuddyTickerAddUser( char *name, GdkPixmap *pm, GdkBitmap *bm ) +{ + GtkWidget *hbox, *label, *pmap; + TickerData *p; + + BuddyTickerCreateWindow(); + p = (TickerData *) malloc( sizeof( TickerData ) ); + p->hbox = (GtkWidget *) NULL; + p->label = (GtkWidget *) NULL; + p->pix = (GtkWidget *) NULL; + strcpy( p->buddy, name ); + tickerbuds = g_list_append( tickerbuds, p ); + + p->hbox = gtk_hbox_new( FALSE, 0 ); + gtk_ticker_add( GTK_TICKER( ticker ), p->hbox ); + gtk_widget_show_all( p->hbox ); + + BuddyTickerSetPixmap( name, pm, bm ); + + p->label = gtk_label_new( name ); + gtk_box_pack_start_defaults( GTK_BOX( p->hbox ), p->label ); + gtk_widget_show( p->label ); + + gtk_widget_show( tickerwindow ); +} + +void +BuddyTickerRemoveUser( char *name ) +{ + GList *p = (GList *) BuddyTickerFindUser( name ); + TickerData *data = (TickerData *) p->data; + + if ( data ) { + gtk_ticker_remove( GTK_TICKER( ticker ), data->hbox ); + tickerbuds = g_list_remove( tickerbuds, data ); + free( data ); + } +} + +void +BuddyTickerSetPixmap( char *name, GdkPixmap *pm, GdkBitmap *bm ) +{ + GList *p = (GList *) BuddyTickerFindUser( name ); + TickerData *data = (TickerData *) p->data; + + if ( data->pix == (GtkWidget *) NULL ) { + data->pix = gtk_pixmap_new( pm, bm ); + gtk_box_pack_start_defaults( GTK_BOX( data->hbox ), data->pix ); + } else { + gtk_widget_hide( data->pix ); + gtk_pixmap_set(GTK_PIXMAP(data->pix), pm, bm); + } + gtk_widget_show( data->pix ); +} + +GList * +BuddyTickerFindUser( char *name ) +{ + GList *p = tickerbuds; + + while ( p ) { + TickerData *q = (TickerData *) p->data; + if ( !strcmp( name, q->buddy ) ) + return( p ); + p = p->next; + } + return (GList *) NULL; +} + +int +BuddyTickerLogonTimeout( gpointer data ) +{ + char *name = (char *) data; + + GList *p = (GList *) BuddyTickerFindUser( name ); + TickerData *q = (TickerData *) p->data; + + if ( q ) { + + } + + return FALSE; +} + +int +BuddyTickerLogoutTimeout( gpointer data ) +{ + char *name = (char *) data; + + BuddyTickerRemoveUser( name ); + + return FALSE; +}