cellrenderericon.c

来自「Gqview,Linux下基于GTK+库写成的轻量级而能丰富的图像浏览程序。」· C语言 代码 · 共 644 行 · 第 1/2 页

C
644
字号
/* cellrenderericon.c, based on: * * gtkcellrendererpixbuf.c * Copyright (C) 2000  Red Hat, Inc.,  Jonathan Blandford <jrb@redhat.com> * * 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. */#include <stdlib.h>#include "cellrenderericon.h"#include "intl.h"#define FIXED_ICON_SIZE_MAX 512static void gqv_cell_renderer_icon_get_property(GObject		*object,					        guint		param_id,					        GValue		*value,					        GParamSpec	*pspec);static void gqv_cell_renderer_icon_set_property(GObject		*object,						guint		param_id,						const GValue	*value,						GParamSpec	*pspec);static void gqv_cell_renderer_icon_init(GQvCellRendererIcon *celltext);static void gqv_cell_renderer_icon_class_init(GQvCellRendererIconClass *class);static void gqv_cell_renderer_icon_finalize(GObject *object);static void gqv_cell_renderer_icon_get_size(GtkCellRenderer	*cell,					    GtkWidget		*widget,					    GdkRectangle	*rectangle,					    gint		*x_offset,					    gint		*y_offset,					    gint		*width,					    gint		*height);static void gqv_cell_renderer_icon_render(GtkCellRenderer	*cell,					   GdkWindow		*window,					   GtkWidget		*widget,					   GdkRectangle		*background_area,					   GdkRectangle		*cell_area,					   GdkRectangle		*expose_area,					   GtkCellRendererState	flags);enum {	PROP_ZERO,	PROP_PIXBUF,	PROP_TEXT,	PROP_BACKGROUND_GDK,	PROP_FOREGROUND_GDK,	PROP_FOCUSED,	PROP_FIXED_WIDTH,	PROP_FIXED_HEIGHT,	PROP_BACKGROUND_SET,	PROP_FOREGROUND_SET,	PROP_SHOW_TEXT};static gpointer parent_class;GTypegqv_cell_renderer_icon_get_type (void){	static GType cell_icon_type = 0;	if (!cell_icon_type)		{		static const GTypeInfo cell_icon_info =			{			sizeof (GQvCellRendererIconClass),			NULL,		/* base_init */			NULL,		/* base_finalize */			(GClassInitFunc) gqv_cell_renderer_icon_class_init,			NULL,		/* class_finalize */			NULL,		/* class_data */			sizeof (GQvCellRendererIcon),			0,		/* n_preallocs */		(GInstanceInitFunc) gqv_cell_renderer_icon_init,		};	cell_icon_type = g_type_register_static(GTK_TYPE_CELL_RENDERER,					        "GQvCellRendererIcon",						&cell_icon_info, 0);	}	return cell_icon_type;}static voidgqv_cell_renderer_icon_init (GQvCellRendererIcon *cellicon){	GTK_CELL_RENDERER(cellicon)->xpad = 2;	GTK_CELL_RENDERER(cellicon)->ypad = 2;}static voidgqv_cell_renderer_icon_class_init (GQvCellRendererIconClass *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 = gqv_cell_renderer_icon_finalize;	object_class->get_property = gqv_cell_renderer_icon_get_property;	object_class->set_property = gqv_cell_renderer_icon_set_property;	cell_class->get_size = gqv_cell_renderer_icon_get_size;	cell_class->render = gqv_cell_renderer_icon_render;	g_object_class_install_property(object_class,					PROP_PIXBUF,					g_param_spec_object("pixbuf",							_("Pixbuf Object"),							_("The pixbuf to render"),							GDK_TYPE_PIXBUF,							G_PARAM_READWRITE));	g_object_class_install_property(object_class,					PROP_TEXT,					g_param_spec_string("text",							_("Text"),							_("Text to render"),							NULL,							G_PARAM_READWRITE));	g_object_class_install_property(object_class,					PROP_BACKGROUND_GDK,					g_param_spec_boxed("background_gdk",							_("Background color"),							_("Background color as a GdkColor"),							GDK_TYPE_COLOR,							G_PARAM_READWRITE));	g_object_class_install_property(object_class,					PROP_FOREGROUND_GDK,					g_param_spec_boxed("foreground_gdk",							_("Foreground color"),							_("Foreground color as a GdkColor"),							GDK_TYPE_COLOR,							G_PARAM_READWRITE));	g_object_class_install_property(object_class,					PROP_FOCUSED,					g_param_spec_boolean ("has_focus",							_("Focus"),							_("Draw focus indicator"),							FALSE,							G_PARAM_READWRITE));	g_object_class_install_property(object_class,					PROP_FIXED_WIDTH,					g_param_spec_int("fixed_width",							_("Fixed width"),							_("Width of cell"),							-1, FIXED_ICON_SIZE_MAX,							-1,							G_PARAM_READWRITE));	g_object_class_install_property(object_class,					PROP_FIXED_HEIGHT,					g_param_spec_int("fixed_height",							_("Fixed height"),							_("Height of icon excluding text"),							-1, FIXED_ICON_SIZE_MAX,							-1,							G_PARAM_READWRITE));	g_object_class_install_property(object_class,					PROP_BACKGROUND_SET,					g_param_spec_boolean("background_set",							_("Background set"),							_("Whether this tag affects the background color"),							FALSE,							G_PARAM_READWRITE));	g_object_class_install_property(object_class,					PROP_FOREGROUND_SET,					g_param_spec_boolean ("foreground_set",							_("Foreground set"),							_("Whether this tag affects the foreground color"),							FALSE,							G_PARAM_READWRITE));	g_object_class_install_property(object_class,					PROP_SHOW_TEXT,					g_param_spec_boolean("show_text",							_("Show text"),							_("Whether the text is displayed"),							TRUE,							G_PARAM_READWRITE));}static voidgqv_cell_renderer_icon_finalize (GObject *object){	GQvCellRendererIcon *cellicon = GQV_CELL_RENDERER_ICON (object);	if (cellicon->pixbuf) g_object_unref (cellicon->pixbuf);	g_free(cellicon->text);	(* G_OBJECT_CLASS (parent_class)->finalize) (object);}static voidgqv_cell_renderer_icon_get_property(GObject	*object,				    guint	param_id,				    GValue	*value,				    GParamSpec	*pspec){	GQvCellRendererIcon *cellicon = GQV_CELL_RENDERER_ICON (object);  	switch (param_id)		{		case PROP_PIXBUF:		g_value_set_object(value,      				   cellicon->pixbuf ? G_OBJECT (cellicon->pixbuf) : NULL);		break;	case PROP_TEXT:		g_value_set_string (value, cellicon->text);		break;	case PROP_BACKGROUND_GDK:		{		GdkColor color;		color.red = cellicon->background.red;		color.green = cellicon->background.green;		color.blue = cellicon->background.blue;		g_value_set_boxed (value, &color);		}		break;	case PROP_FOREGROUND_GDK:		{		GdkColor color;		color.red = cellicon->foreground.red;		color.green = cellicon->foreground.green;		color.blue = cellicon->foreground.blue;		g_value_set_boxed (value, &color);		}		break;	case PROP_FOCUSED:		g_value_set_boolean (value, cellicon->focused);		break;	case PROP_FIXED_WIDTH:		g_value_set_int(value, cellicon->fixed_width);		break;	case PROP_FIXED_HEIGHT:		g_value_set_int(value, cellicon->fixed_height);		break;	case PROP_BACKGROUND_SET:		g_value_set_boolean(value, cellicon->background_set);		break;	case PROP_FOREGROUND_SET:		g_value_set_boolean(value, cellicon->foreground_set);		break;	case PROP_SHOW_TEXT:		g_value_set_boolean(value, cellicon->show_text);		break;	default:		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);		break;	}}static voidset_bg_color (GQvCellRendererIcon *cellicon,	      GdkColor		  *color){	if (color)		{		if (!cellicon->background_set)			{			cellicon->background_set = TRUE;			g_object_notify(G_OBJECT(cellicon), "background_set");			}		cellicon->background.red = color->red;		cellicon->background.green = color->green;		cellicon->background.blue = color->blue;		}	else		{		if (cellicon->background_set)			{			cellicon->background_set = FALSE;			g_object_notify(G_OBJECT(cellicon), "background_set");			}		}}static void set_fg_color (GQvCellRendererIcon *cellicon,			  GdkColor	      *color){	if (color)		{		if (!cellicon->foreground_set)			{			cellicon->foreground_set = TRUE;			g_object_notify(G_OBJECT(cellicon), "foreground_set");			}		cellicon->foreground.red = color->red;		cellicon->foreground.green = color->green;		cellicon->foreground.blue = color->blue;		}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?