evolution-3.6.4/widgets/table/e-cell-checkbox.c

No issues found

  1 /*
  2  *
  3  * This program is free software; you can redistribute it and/or
  4  * modify it under the terms of the GNU Lesser General Public
  5  * License as published by the Free Software Foundation; either
  6  * version 2 of the License, or (at your option) version 3.
  7  *
  8  * This program is distributed in the hope that it will be useful,
  9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 11  * Lesser General Public License for more details.
 12  *
 13  * You should have received a copy of the GNU Lesser General Public
 14  * License along with the program; if not, see <http://www.gnu.org/licenses/>
 15  *
 16  *
 17  * Authors:
 18  *		Miguel de Icaza <miguel@ximian.com>
 19  *
 20  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 21  *
 22  */
 23 
 24 #ifdef HAVE_CONFIG_H
 25 #include <config.h>
 26 #endif
 27 
 28 #include <gdk/gdkkeysyms.h>
 29 #include <gtk/gtk.h>
 30 #include <libgnomecanvas/libgnomecanvas.h>
 31 
 32 #include "e-util/e-util.h"
 33 
 34 #include "e-table-item.h"
 35 #include "e-cell-checkbox.h"
 36 
 37 #include "check-empty.xpm"
 38 #include "check-filled.xpm"
 39 
 40 G_DEFINE_TYPE (ECellCheckbox, e_cell_checkbox, E_TYPE_CELL_TOGGLE)
 41 
 42 static GdkPixbuf *checks[2];
 43 
 44 static void
 45 ecc_print (ECellView *ecell_view,
 46            GtkPrintContext *context,
 47            gint model_col,
 48            gint view_col,
 49            gint row,
 50            gdouble width,
 51            gdouble height)
 52 {
 53 	cairo_t *cr = gtk_print_context_get_cairo_context (context);
 54 	const gint value = GPOINTER_TO_INT (
 55 		e_table_model_value_at (
 56 			ecell_view->e_table_model, model_col, row));
 57 	cairo_save (cr);
 58 
 59 	if (value == 1) {
 60 		cairo_set_line_width (cr, 2);
 61 		cairo_move_to (cr, 3, 11);
 62 		cairo_line_to (cr, 7, 14);
 63 		cairo_line_to (cr, 11, 5);
 64 		cairo_stroke (cr);
 65 	}
 66 
 67 	cairo_restore (cr);
 68 }
 69 
 70 static void
 71 e_cell_checkbox_class_init (ECellCheckboxClass *class)
 72 {
 73 	ECellClass *ecc = E_CELL_CLASS (class);
 74 
 75 	ecc->print = ecc_print;
 76 	checks[0] = gdk_pixbuf_new_from_xpm_data (check_empty_xpm);
 77 	checks[1] = gdk_pixbuf_new_from_xpm_data (check_filled_xpm);
 78 }
 79 
 80 static void
 81 e_cell_checkbox_init (ECellCheckbox *eccb)
 82 {
 83 	GPtrArray *pixbufs;
 84 
 85 	pixbufs = e_cell_toggle_get_pixbufs (E_CELL_TOGGLE (eccb));
 86 
 87 	g_ptr_array_add (pixbufs, g_object_ref (checks[0]));
 88 	g_ptr_array_add (pixbufs, g_object_ref (checks[1]));
 89 }
 90 
 91 /**
 92  * e_cell_checkbox_new:
 93  *
 94  * Creates a new ECell renderer that can be used to render check
 95  * boxes.  the data provided from the model is cast to an integer.
 96  * zero is used for the off display, and non-zero for checked status.
 97  *
 98  * Returns: an ECell object that can be used to render checkboxes.
 99  */
100 ECell *
101 e_cell_checkbox_new (void)
102 {
103 	return g_object_new (E_TYPE_CELL_CHECKBOX, NULL);
104 }