evolution-3.6.4/widgets/misc/e-printable.c

No issues found

  1 /*
  2  * This program is free software; you can redistribute it and/or
  3  * modify it under the terms of the GNU Lesser General Public
  4  * License as published by the Free Software Foundation; either
  5  * version 2 of the License, or (at your option) version 3.
  6  *
  7  * This program is distributed in the hope that it will be useful,
  8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 10  * Lesser General Public License for more details.
 11  *
 12  * You should have received a copy of the GNU Lesser General Public
 13  * License along with the program; if not, see <http://www.gnu.org/licenses/>
 14  *
 15  *
 16  * Authors:
 17  *		Chris Lahey <clahey@ximian.com>
 18  *
 19  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 20  *
 21  */
 22 
 23 #ifdef HAVE_CONFIG_H
 24 #include <config.h>
 25 #endif
 26 
 27 #include <gtk/gtk.h>
 28 
 29 #include "e-util/e-util.h"
 30 
 31 #include "e-printable.h"
 32 
 33 #define EP_CLASS(e) ((EPrintableClass *)((GObject *)e)->class)
 34 
 35 G_DEFINE_TYPE (
 36 	EPrintable,
 37 	e_printable,
 38 	G_TYPE_INITIALLY_UNOWNED)
 39 
 40 enum {
 41 	PRINT_PAGE,
 42 	DATA_LEFT,
 43 	RESET,
 44 	HEIGHT,
 45 	WILL_FIT,
 46 	LAST_SIGNAL
 47 };
 48 
 49 static guint e_printable_signals[LAST_SIGNAL] = { 0, };
 50 
 51 static void
 52 e_printable_class_init (EPrintableClass *class)
 53 {
 54 	GObjectClass *object_class = G_OBJECT_CLASS (class);
 55 
 56 	e_printable_signals[PRINT_PAGE] = g_signal_new (
 57 		"print_page",
 58 		G_OBJECT_CLASS_TYPE (object_class),
 59 		G_SIGNAL_RUN_LAST,
 60 		G_STRUCT_OFFSET (EPrintableClass, print_page),
 61 		NULL, NULL,
 62 		e_marshal_NONE__OBJECT_DOUBLE_DOUBLE_BOOLEAN,
 63 		G_TYPE_NONE, 4,
 64 		G_TYPE_OBJECT,
 65 		G_TYPE_DOUBLE,
 66 		G_TYPE_DOUBLE,
 67 		G_TYPE_BOOLEAN);
 68 
 69 	e_printable_signals[DATA_LEFT] = g_signal_new (
 70 		"data_left",
 71 		G_OBJECT_CLASS_TYPE (object_class),
 72 		G_SIGNAL_RUN_LAST,
 73 		G_STRUCT_OFFSET (EPrintableClass, data_left),
 74 		NULL, NULL,
 75 		e_marshal_BOOLEAN__NONE,
 76 		G_TYPE_BOOLEAN, 0,
 77 		G_TYPE_NONE);
 78 
 79 	e_printable_signals[RESET] = g_signal_new (
 80 		"reset",
 81 		G_OBJECT_CLASS_TYPE (object_class),
 82 		G_SIGNAL_RUN_LAST,
 83 		G_STRUCT_OFFSET (EPrintableClass, reset),
 84 		NULL, NULL,
 85 		g_cclosure_marshal_VOID__VOID,
 86 		G_TYPE_NONE, 0,
 87 		G_TYPE_NONE);
 88 
 89 	e_printable_signals[HEIGHT] = g_signal_new (
 90 		"height",
 91 		G_OBJECT_CLASS_TYPE (object_class),
 92 		G_SIGNAL_RUN_LAST,
 93 		G_STRUCT_OFFSET (EPrintableClass, height),
 94 		NULL, NULL,
 95 		e_marshal_DOUBLE__OBJECT_DOUBLE_DOUBLE_BOOLEAN,
 96 		G_TYPE_DOUBLE, 4,
 97 		G_TYPE_OBJECT,
 98 		G_TYPE_DOUBLE,
 99 		G_TYPE_DOUBLE,
100 		G_TYPE_BOOLEAN);
101 
102 	e_printable_signals[WILL_FIT] = g_signal_new (
103 		"will_fit",
104 		G_OBJECT_CLASS_TYPE (object_class),
105 		G_SIGNAL_RUN_LAST,
106 		G_STRUCT_OFFSET (EPrintableClass, will_fit),
107 		NULL, NULL,
108 		e_marshal_BOOLEAN__OBJECT_DOUBLE_DOUBLE_BOOLEAN,
109 		G_TYPE_BOOLEAN, 4,
110 		G_TYPE_OBJECT,
111 		G_TYPE_DOUBLE,
112 		G_TYPE_DOUBLE,
113 		G_TYPE_BOOLEAN);
114 
115 	class->print_page = NULL;
116 	class->data_left = NULL;
117 	class->reset = NULL;
118 	class->height = NULL;
119 	class->will_fit = NULL;
120 }
121 
122 static void
123 e_printable_init (EPrintable *e_printable)
124 {
125 	/* nothing to do */
126 }
127 
128 EPrintable *
129 e_printable_new (void)
130 {
131 	return E_PRINTABLE (g_object_new (E_PRINTABLE_TYPE, NULL));
132 }
133 
134 void
135 e_printable_print_page (EPrintable *e_printable,
136                         GtkPrintContext *context,
137                         gdouble width,
138                         gdouble height,
139                         gboolean quantized)
140 {
141 	g_return_if_fail (e_printable != NULL);
142 	g_return_if_fail (E_IS_PRINTABLE (e_printable));
143 
144 	g_signal_emit (
145 		e_printable,
146 		e_printable_signals[PRINT_PAGE], 0,
147 		context,
148 		width,
149 		height,
150 		quantized);
151 }
152 
153 gboolean
154 e_printable_data_left (EPrintable *e_printable)
155 {
156 	gboolean ret_val;
157 
158 	g_return_val_if_fail (e_printable != NULL, FALSE);
159 	g_return_val_if_fail (E_IS_PRINTABLE (e_printable), FALSE);
160 
161 	g_signal_emit (
162 		e_printable,
163 		e_printable_signals[DATA_LEFT], 0,
164 		&ret_val);
165 
166 	return ret_val;
167 }
168 
169 void
170 e_printable_reset (EPrintable *e_printable)
171 {
172 	g_return_if_fail (e_printable != NULL);
173 	g_return_if_fail (E_IS_PRINTABLE (e_printable));
174 
175 	g_signal_emit (
176 		e_printable,
177 		e_printable_signals[RESET], 0);
178 }
179 
180 gdouble
181 e_printable_height (EPrintable *e_printable,
182                     GtkPrintContext *context,
183                     gdouble width,
184                     gdouble max_height,
185                     gboolean quantized)
186 {
187 	gdouble ret_val;
188 
189 	g_return_val_if_fail (e_printable != NULL, -1);
190 	g_return_val_if_fail (E_IS_PRINTABLE (e_printable), -1);
191 
192 	g_signal_emit (
193 		e_printable,
194 		e_printable_signals[HEIGHT], 0,
195 		context,
196 		width,
197 		max_height,
198 		quantized,
199 		&ret_val);
200 
201 	return ret_val;
202 }
203 
204 gboolean
205 e_printable_will_fit (EPrintable *e_printable,
206                       GtkPrintContext *context,
207                       gdouble width,
208                       gdouble max_height,
209                       gboolean quantized)
210 {
211 	gboolean ret_val;
212 
213 	g_return_val_if_fail (e_printable != NULL, FALSE);
214 	g_return_val_if_fail (E_IS_PRINTABLE (e_printable), FALSE);
215 
216 	g_signal_emit (
217 		e_printable,
218 		e_printable_signals[WILL_FIT], 0,
219 		context,
220 		width,
221 		max_height,
222 		quantized,
223 		&ret_val);
224 
225 	return ret_val;
226 }