view src/gtkcellrendererprogress.c @ 10789:0caa9827edf5

[gaim-migrate @ 12431] " The following log snippets should explain it: " --rlaager (20:24:00) rlaager: Regarding the signal handling conversation the other day... I've written a patch to stop calling signal handlers and return as soon as we find one signal handler that returns TRUE to indicate that it's handled the signal. Is this the right approach? (20:24:22) Ethan Blanton (Paco-Paco): the trouble is that it's documented to behave exactly the way it does (20:24:31) Ethan Blanton (Paco-Paco): so changing it is notbackwards compatible (20:24:31) rlaager: I'm talking for HEAD. (20:24:41) Ethan Blanton (Paco-Paco): oh, I think that's a good approach, yes (20:24:53) rlaager: The way I've described is how I *expected* it to work, having not read the documentation. (20:25:09) Ethan Blanton (Paco-Paco): I'm convinced (20:27:04) Stu Tomlinson (nosnilmot): rlaager: this, I assume, breaks the generic-ness of signals, by assuming that any that return values return booleans? (20:27:26) Ethan Blanton (Paco-Paco): please break it (20:27:33) Ethan Blanton (Paco-Paco): we already have out-parameters (20:27:42) rlaager: nosnilmot: from what I can see, the return type is handled as a (void *)... so I'm checking that ret_value != NULL (20:27:57) rlaager: nosnilmot: that's the correct way to do it, right? ... (20:29:01) Ethan Blanton (Paco-Paco): allowing a meaningful return value is an over-engineering (20:30:07) rlaager: even after this patch, you should be able to return meaningful return values (20:30:15) rlaager: it'll just short-circuit on the first handler that does committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Thu, 07 Apr 2005 14:55:02 +0000
parents ec140184437b
children e856f985a0b9
line wrap: on
line source

/*
 * @file gtkcellrendererprogress.c GTK+ Cell Renderer Progress
 * @ingroup gtkui
 *
 * gaim
 *
 * Gaim is the legal property of its developers, whose names are too numerous
 * to list here.  Please refer to the COPYRIGHT file distributed with this
 * source distribution.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

/* This is taken largely from GtkCellRenderer[Text|Pixbuf|Toggle] by 
 * Jonathon Blandford <jrb@redhat.com> for RedHat, Inc.
 */

#include "gtkcellrendererprogress.h"

static void gaim_gtk_cell_renderer_progress_get_property  (GObject                    *object,
						      guint                       param_id,
						      GValue                     *value,
						      GParamSpec                 *pspec);
static void gaim_gtk_cell_renderer_progress_set_property  (GObject                    *object,
						      guint                       param_id,
						      const GValue               *value,
						      GParamSpec                 *pspec);
static void gaim_gtk_cell_renderer_progress_init       (GaimGtkCellRendererProgress      *cellprogress);
static void gaim_gtk_cell_renderer_progress_class_init (GaimGtkCellRendererProgressClass *class);
static void gaim_gtk_cell_renderer_progress_get_size   (GtkCellRenderer            *cell,
						   GtkWidget                  *widget,
						   GdkRectangle               *cell_area,
						   gint                       *x_offset,
						   gint                       *y_offset,
						   gint                       *width,
						   gint                       *height);
static void gaim_gtk_cell_renderer_progress_render     (GtkCellRenderer            *cell,
						   GdkWindow                  *window,
						   GtkWidget                  *widget,
						   GdkRectangle               *background_area,
						   GdkRectangle               *cell_area,
						   GdkRectangle               *expose_area,
						   guint                       flags);
#if 0
static gboolean gaim_gtk_cell_renderer_progress_activate  (GtkCellRenderer            *cell,
						      GdkEvent                   *event,
						      GtkWidget                  *widget,
						      const gchar                *path,
						      GdkRectangle               *background_area,
						      GdkRectangle               *cell_area,
						      guint                       flags);
#endif
static void  gaim_gtk_cell_renderer_progress_finalize (GObject *gobject);

enum {
	LAST_SIGNAL
};

enum {
	PROP_0,
	PROP_PERCENTAGE,
	PROP_TEXT,
	PROP_SHOW_TEXT
};
     
static gpointer parent_class;
/* static guint progress_cell_renderer_signals [LAST_SIGNAL]; */

GType  gaim_gtk_cell_renderer_progress_get_type (void)
{
	static GType cell_progress_type = 0;
	
	if (!cell_progress_type)
		{
			static const GTypeInfo cell_progress_info =
				{
					sizeof (GaimGtkCellRendererProgressClass),
					NULL,           /* base_init */
					NULL,           /* base_finalize */
					(GClassInitFunc) gaim_gtk_cell_renderer_progress_class_init,
					NULL,           /* class_finalize */
					NULL,           /* class_data */
					sizeof (GaimGtkCellRendererProgress),
					0,              /* n_preallocs */
					(GInstanceInitFunc) gaim_gtk_cell_renderer_progress_init,
				};
			
			cell_progress_type =
				g_type_register_static (GTK_TYPE_CELL_RENDERER,
										"GaimGtkCellRendererProgress",
										&cell_progress_info, 0);
		}
	
	return cell_progress_type;
}

static void gaim_gtk_cell_renderer_progress_init (GaimGtkCellRendererProgress *cellprogress)
{
	GTK_CELL_RENDERER(cellprogress)->mode = GTK_CELL_RENDERER_MODE_INERT;
	GTK_CELL_RENDERER(cellprogress)->xpad = 2;
	GTK_CELL_RENDERER(cellprogress)->ypad = 2;
}

static void gaim_gtk_cell_renderer_progress_class_init (GaimGtkCellRendererProgressClass *class)
{
	GObjectClass *object_class = G_OBJECT_CLASS(class);
	GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS(class);
	
	parent_class = g_type_class_peek_parent (class);
	object_class->finalize = gaim_gtk_cell_renderer_progress_finalize;

	object_class->get_property = gaim_gtk_cell_renderer_progress_get_property;
	object_class->set_property = gaim_gtk_cell_renderer_progress_set_property;
	
	cell_class->get_size = gaim_gtk_cell_renderer_progress_get_size;
	cell_class->render   = gaim_gtk_cell_renderer_progress_render;
	
	g_object_class_install_property (object_class,
					 PROP_PERCENTAGE,
					 g_param_spec_double ("percentage",
							      "Percentage",
							      "The fractional progress to display",
							      0, 1, 0,
							      G_PARAM_READWRITE));
	g_object_class_install_property (object_class,
					 PROP_TEXT,
					 g_param_spec_string ("text",
							      "Text",
							      "Text to overlay over progress bar",
							      NULL,
							      G_PARAM_READWRITE));
	g_object_class_install_property(object_class,
					PROP_SHOW_TEXT,
					g_param_spec_string("text_set",
							    "Text set",
							    "Whether to overlay text on the progress bar",
							    FALSE,
							    G_PARAM_READABLE | G_PARAM_WRITABLE));
}

static void gaim_gtk_cell_renderer_progress_finalize (GObject *object)
{
/*
	GaimGtkCellRendererProgress *cellprogress = GAIM_GTK_CELL_RENDERER_PROGRESS(object);
*/

	(* G_OBJECT_CLASS (parent_class)->finalize) (object);
}

static void gaim_gtk_cell_renderer_progress_get_property (GObject    *object,
						     guint      param_id,
						     GValue     *value,
						     GParamSpec *psec)
{
	GaimGtkCellRendererProgress *cellprogress = GAIM_GTK_CELL_RENDERER_PROGRESS(object);

	switch (param_id)
		{
		case PROP_PERCENTAGE:
			g_value_set_double(value, cellprogress->progress);
			break;
		case PROP_TEXT:
			g_value_set_string(value, cellprogress->text);
			break;
		case PROP_SHOW_TEXT:
			g_value_set_boolean(value, cellprogress->text_set);
			break;
		default:
			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, psec);
			break;
		}
}

static void gaim_gtk_cell_renderer_progress_set_property (GObject      *object,
						     guint        param_id,
						     const GValue *value,
						     GParamSpec   *pspec)
{
	GaimGtkCellRendererProgress *cellprogress = GAIM_GTK_CELL_RENDERER_PROGRESS (object);

	switch (param_id)
		{
		case PROP_PERCENTAGE:
			cellprogress->progress = g_value_get_double(value);
			break;
		case PROP_TEXT:
			if (cellprogress->text)
				g_free(cellprogress->text);
			cellprogress->text = g_strdup(g_value_get_string(value));
			g_object_notify(object, "text");
			break;
		case PROP_SHOW_TEXT:
			cellprogress->text_set = g_value_get_boolean(value);
			break;
		default:
			G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec);
			break;
		}
}

GtkCellRenderer *gaim_gtk_cell_renderer_progress_new(void)
{
	return g_object_new(GAIM_TYPE_GTK_CELL_RENDERER_PROGRESS, NULL);
}

static void gaim_gtk_cell_renderer_progress_get_size (GtkCellRenderer *cell,
						 GtkWidget       *widget,
						 GdkRectangle    *cell_area,
						 gint            *x_offset,
						 gint            *y_offset,
						 gint            *width,
						 gint            *height)
{
	gint calc_width;
	gint calc_height;
	
	calc_width = (gint) cell->xpad * 2 + 50;
	calc_height = (gint) cell->ypad * 2 + 12;
	
	if (width)
		*width = calc_width;
	
	if (height)
		*height = calc_height;
	
	if (cell_area)
		{
			if (x_offset)
				{
					*x_offset = cell->xalign * (cell_area->width - calc_width);
					*x_offset = MAX (*x_offset, 0);
				}
			if (y_offset)
				{
					*y_offset = cell->yalign * (cell_area->height - calc_height);
					*y_offset = MAX (*y_offset, 0);
				}
		}
}


static void gaim_gtk_cell_renderer_progress_render (GtkCellRenderer *cell,
					       GdkWindow       *window,
					       GtkWidget       *widget,
					       GdkRectangle    *background_area,
					       GdkRectangle    *cell_area,
					       GdkRectangle    *expose_area,
					       guint            flags)
{
	GaimGtkCellRendererProgress *cellprogress = (GaimGtkCellRendererProgress *) cell;
	
	gint width, height;
	GtkStateType state;

	width = cell_area->width;
	height = cell_area->height;
	
	if (GTK_WIDGET_HAS_FOCUS (widget))
		state = GTK_STATE_ACTIVE;
	else
		state = GTK_STATE_NORMAL;

	width -= cell->xpad*2;
	height -= cell->ypad*2;

	gtk_paint_box (widget->style,
		       window,
		       GTK_STATE_NORMAL, GTK_SHADOW_IN, 
		       NULL, widget, "trough",
		       cell_area->x + cell->xpad,
		       cell_area->y + cell->ypad,
		       width - 1, height - 1);
	gtk_paint_box (widget->style,
		       window,
		       state, GTK_SHADOW_OUT,
		       NULL, widget, "bar",
		       cell_area->x + cell->xpad + 1,
		       cell_area->y + cell->ypad + 1,
		       (width - 3) * cellprogress->progress,
		       height - 3);
}